mac: Don't limit GL_MAX_TEXTURE_SIZE on 10.9.0+.
[chromium-blink-merge.git] / cc / test / layer_tree_pixel_resource_test.cc
blob1839643880b45ad4f95f3d6623ddf866dcc17782
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/layer_tree_pixel_resource_test.h"
7 #include "cc/layers/layer.h"
8 #include "cc/resources/bitmap_raster_worker_pool.h"
9 #include "cc/resources/gpu_raster_worker_pool.h"
10 #include "cc/resources/one_copy_raster_worker_pool.h"
11 #include "cc/resources/pixel_buffer_raster_worker_pool.h"
12 #include "cc/resources/raster_worker_pool.h"
13 #include "cc/resources/resource_pool.h"
14 #include "cc/resources/zero_copy_raster_worker_pool.h"
15 #include "cc/test/fake_output_surface.h"
16 #include "gpu/GLES2/gl2extchromium.h"
18 namespace cc {
20 namespace {
22 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
23 switch (test_case) {
24 case SOFTWARE:
25 case GL_GPU_RASTER_2D_DRAW:
26 case GL_ZERO_COPY_2D_DRAW:
27 case GL_ZERO_COPY_RECT_DRAW:
28 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
29 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
30 case GL_ASYNC_UPLOAD_2D_DRAW:
31 return true;
32 case GL_ZERO_COPY_EXTERNAL_DRAW:
33 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
34 // These should all be enabled in practice.
35 // TODO(enne): look into getting texture external oes enabled.
36 return false;
39 NOTREACHED();
40 return false;
43 } // namespace
45 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
46 PixelResourceTestCase test_case)
47 : staging_texture_target_(GL_INVALID_VALUE),
48 draw_texture_target_(GL_INVALID_VALUE),
49 resource_pool_option_(BITMAP_RASTER_WORKER_POOL),
50 test_case_(test_case) {
51 InitializeFromTestCase(test_case);
54 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
55 PixelResourceTestCase test_case) {
56 switch (test_case) {
57 case SOFTWARE:
58 test_type_ = PIXEL_TEST_SOFTWARE;
59 staging_texture_target_ = GL_INVALID_VALUE;
60 draw_texture_target_ = GL_INVALID_VALUE;
61 resource_pool_option_ = BITMAP_RASTER_WORKER_POOL;
62 return;
63 case GL_GPU_RASTER_2D_DRAW:
64 test_type_ = PIXEL_TEST_GL;
65 staging_texture_target_ = GL_INVALID_VALUE;
66 draw_texture_target_ = GL_TEXTURE_2D;
67 resource_pool_option_ = GPU_RASTER_WORKER_POOL;
68 return;
69 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
70 test_type_ = PIXEL_TEST_GL;
71 staging_texture_target_ = GL_TEXTURE_2D;
72 draw_texture_target_ = GL_TEXTURE_2D;
73 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
74 return;
75 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
76 test_type_ = PIXEL_TEST_GL;
77 staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
78 draw_texture_target_ = GL_TEXTURE_2D;
79 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
80 return;
81 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
82 test_type_ = PIXEL_TEST_GL;
83 staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
84 draw_texture_target_ = GL_TEXTURE_2D;
85 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
86 return;
87 case GL_ZERO_COPY_2D_DRAW:
88 test_type_ = PIXEL_TEST_GL;
89 staging_texture_target_ = GL_INVALID_VALUE;
90 draw_texture_target_ = GL_TEXTURE_2D;
91 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
92 return;
93 case GL_ZERO_COPY_RECT_DRAW:
94 test_type_ = PIXEL_TEST_GL;
95 staging_texture_target_ = GL_INVALID_VALUE;
96 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
97 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
98 return;
99 case GL_ZERO_COPY_EXTERNAL_DRAW:
100 test_type_ = PIXEL_TEST_GL;
101 staging_texture_target_ = GL_INVALID_VALUE;
102 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
103 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
104 return;
105 case GL_ASYNC_UPLOAD_2D_DRAW:
106 test_type_ = PIXEL_TEST_GL;
107 staging_texture_target_ = GL_INVALID_VALUE;
108 draw_texture_target_ = GL_TEXTURE_2D;
109 resource_pool_option_ = PIXEL_BUFFER_RASTER_WORKER_POOL;
110 return;
112 NOTREACHED();
115 void LayerTreeHostPixelResourceTest::CreateResourceAndRasterWorkerPool(
116 LayerTreeHostImpl* host_impl,
117 scoped_ptr<RasterWorkerPool>* raster_worker_pool,
118 scoped_ptr<ResourcePool>* resource_pool,
119 scoped_ptr<ResourcePool>* staging_resource_pool) {
120 base::SingleThreadTaskRunner* task_runner =
121 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
122 : proxy()->MainThreadTaskRunner();
123 DCHECK(task_runner);
125 ContextProvider* context_provider =
126 host_impl->output_surface()->context_provider();
127 ResourceProvider* resource_provider = host_impl->resource_provider();
128 bool use_distance_field_text = false;
129 size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
131 switch (resource_pool_option_) {
132 case BITMAP_RASTER_WORKER_POOL:
133 EXPECT_FALSE(context_provider);
134 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
135 *resource_pool =
136 ResourcePool::Create(resource_provider,
137 draw_texture_target_,
138 resource_provider->best_texture_format());
140 *raster_worker_pool =
141 BitmapRasterWorkerPool::Create(task_runner,
142 RasterWorkerPool::GetTaskGraphRunner(),
143 resource_provider);
144 break;
145 case GPU_RASTER_WORKER_POOL:
146 EXPECT_TRUE(context_provider);
147 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
148 *resource_pool =
149 ResourcePool::Create(resource_provider,
150 draw_texture_target_,
151 resource_provider->best_texture_format());
153 *raster_worker_pool =
154 GpuRasterWorkerPool::Create(task_runner,
155 context_provider,
156 resource_provider,
157 use_distance_field_text);
158 break;
159 case ZERO_COPY_RASTER_WORKER_POOL:
160 EXPECT_TRUE(context_provider);
161 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
162 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
163 *resource_pool =
164 ResourcePool::Create(resource_provider,
165 draw_texture_target_,
166 resource_provider->best_texture_format());
168 *raster_worker_pool = ZeroCopyRasterWorkerPool::Create(
169 task_runner,
170 RasterWorkerPool::GetTaskGraphRunner(),
171 resource_provider);
172 break;
173 case ONE_COPY_RASTER_WORKER_POOL:
174 EXPECT_TRUE(context_provider);
175 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
176 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
177 // We need to create a staging resource pool when using copy rasterizer.
178 *staging_resource_pool =
179 ResourcePool::Create(resource_provider,
180 staging_texture_target_,
181 resource_provider->best_texture_format());
182 *resource_pool =
183 ResourcePool::Create(resource_provider,
184 draw_texture_target_,
185 resource_provider->best_texture_format());
187 *raster_worker_pool = OneCopyRasterWorkerPool::Create(
188 task_runner,
189 RasterWorkerPool::GetTaskGraphRunner(),
190 context_provider,
191 resource_provider,
192 staging_resource_pool->get());
193 break;
194 case PIXEL_BUFFER_RASTER_WORKER_POOL:
195 EXPECT_TRUE(context_provider);
196 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
197 *resource_pool = ResourcePool::Create(
198 resource_provider,
199 draw_texture_target_,
200 resource_provider->memory_efficient_texture_format());
202 *raster_worker_pool = PixelBufferRasterWorkerPool::Create(
203 task_runner,
204 RasterWorkerPool::GetTaskGraphRunner(),
205 context_provider,
206 resource_provider,
207 max_transfer_buffer_usage_bytes);
208 break;
212 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
213 scoped_refptr<Layer> content_root,
214 base::FilePath file_name) {
215 if (!IsTestCaseSupported(test_case_))
216 return;
217 RunPixelTest(test_type_, content_root, file_name);
220 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
221 : LayerTreeHostPixelResourceTest(GetParam()) {
224 } // namespace cc