Roll src/buildtools ea47835:451dcd0
[chromium-blink-merge.git] / cc / test / layer_tree_pixel_resource_test.cc
blobe3df017489fa10d60968342c5f474d149859cb5e
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_tile_task_worker_pool.h"
9 #include "cc/resources/gpu_rasterizer.h"
10 #include "cc/resources/gpu_tile_task_worker_pool.h"
11 #include "cc/resources/one_copy_tile_task_worker_pool.h"
12 #include "cc/resources/pixel_buffer_tile_task_worker_pool.h"
13 #include "cc/resources/resource_pool.h"
14 #include "cc/resources/software_rasterizer.h"
15 #include "cc/resources/tile_task_worker_pool.h"
16 #include "cc/resources/zero_copy_tile_task_worker_pool.h"
17 #include "cc/test/fake_output_surface.h"
18 #include "gpu/GLES2/gl2extchromium.h"
20 namespace cc {
22 namespace {
24 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
25 switch (test_case) {
26 case SOFTWARE:
27 case GL_GPU_RASTER_2D_DRAW:
28 case GL_ZERO_COPY_2D_DRAW:
29 case GL_ZERO_COPY_RECT_DRAW:
30 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
31 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
32 case GL_ASYNC_UPLOAD_2D_DRAW:
33 return true;
34 case GL_ZERO_COPY_EXTERNAL_DRAW:
35 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
36 // These should all be enabled in practice.
37 // TODO(enne): look into getting texture external oes enabled.
38 return false;
41 NOTREACHED();
42 return false;
45 } // namespace
47 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
48 PixelResourceTestCase test_case)
49 : staging_texture_target_(GL_INVALID_VALUE),
50 draw_texture_target_(GL_INVALID_VALUE),
51 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
52 initialized_(false),
53 test_case_(test_case) {
54 InitializeFromTestCase(test_case);
57 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
58 : staging_texture_target_(GL_INVALID_VALUE),
59 draw_texture_target_(GL_INVALID_VALUE),
60 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
61 initialized_(false),
62 test_case_(SOFTWARE) {
65 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
66 PixelResourceTestCase test_case) {
67 DCHECK(!initialized_);
68 initialized_ = true;
69 switch (test_case) {
70 case SOFTWARE:
71 test_type_ = PIXEL_TEST_SOFTWARE;
72 staging_texture_target_ = GL_INVALID_VALUE;
73 draw_texture_target_ = GL_INVALID_VALUE;
74 resource_pool_option_ = BITMAP_TILE_TASK_WORKER_POOL;
75 return;
76 case GL_GPU_RASTER_2D_DRAW:
77 test_type_ = PIXEL_TEST_GL;
78 staging_texture_target_ = GL_INVALID_VALUE;
79 draw_texture_target_ = GL_TEXTURE_2D;
80 resource_pool_option_ = GPU_TILE_TASK_WORKER_POOL;
81 return;
82 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
83 test_type_ = PIXEL_TEST_GL;
84 staging_texture_target_ = GL_TEXTURE_2D;
85 draw_texture_target_ = GL_TEXTURE_2D;
86 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
87 return;
88 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
89 test_type_ = PIXEL_TEST_GL;
90 staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
91 draw_texture_target_ = GL_TEXTURE_2D;
92 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
93 return;
94 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
95 test_type_ = PIXEL_TEST_GL;
96 staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
97 draw_texture_target_ = GL_TEXTURE_2D;
98 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
99 return;
100 case GL_ZERO_COPY_2D_DRAW:
101 test_type_ = PIXEL_TEST_GL;
102 staging_texture_target_ = GL_INVALID_VALUE;
103 draw_texture_target_ = GL_TEXTURE_2D;
104 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
105 return;
106 case GL_ZERO_COPY_RECT_DRAW:
107 test_type_ = PIXEL_TEST_GL;
108 staging_texture_target_ = GL_INVALID_VALUE;
109 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
110 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
111 return;
112 case GL_ZERO_COPY_EXTERNAL_DRAW:
113 test_type_ = PIXEL_TEST_GL;
114 staging_texture_target_ = GL_INVALID_VALUE;
115 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
116 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
117 return;
118 case GL_ASYNC_UPLOAD_2D_DRAW:
119 test_type_ = PIXEL_TEST_GL;
120 staging_texture_target_ = GL_INVALID_VALUE;
121 draw_texture_target_ = GL_TEXTURE_2D;
122 resource_pool_option_ = PIXEL_BUFFER_TILE_TASK_WORKER_POOL;
123 return;
125 NOTREACHED();
128 scoped_ptr<Rasterizer> LayerTreeHostPixelResourceTest::CreateRasterizer(
129 LayerTreeHostImpl* host_impl) {
130 bool use_distance_field_text = false;
131 ContextProvider* context_provider =
132 host_impl->output_surface()->context_provider();
133 ResourceProvider* resource_provider = host_impl->resource_provider();
134 switch (resource_pool_option_) {
135 case BITMAP_TILE_TASK_WORKER_POOL:
136 case ZERO_COPY_TILE_TASK_WORKER_POOL:
137 case ONE_COPY_TILE_TASK_WORKER_POOL:
138 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
139 return SoftwareRasterizer::Create();
140 case GPU_TILE_TASK_WORKER_POOL:
141 EXPECT_TRUE(context_provider);
142 return GpuRasterizer::Create(context_provider, resource_provider,
143 use_distance_field_text, false);
145 NOTREACHED();
146 return nullptr;
149 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
150 LayerTreeHostImpl* host_impl,
151 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
152 scoped_ptr<ResourcePool>* resource_pool,
153 scoped_ptr<ResourcePool>* staging_resource_pool) {
154 base::SingleThreadTaskRunner* task_runner =
155 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
156 : proxy()->MainThreadTaskRunner();
157 DCHECK(task_runner);
158 DCHECK(initialized_);
160 ContextProvider* context_provider =
161 host_impl->output_surface()->context_provider();
162 ResourceProvider* resource_provider = host_impl->resource_provider();
163 size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
165 switch (resource_pool_option_) {
166 case BITMAP_TILE_TASK_WORKER_POOL:
167 EXPECT_FALSE(context_provider);
168 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
169 *resource_pool =
170 ResourcePool::Create(resource_provider,
171 draw_texture_target_,
172 resource_provider->best_texture_format());
174 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
175 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
176 resource_provider);
177 break;
178 case GPU_TILE_TASK_WORKER_POOL:
179 EXPECT_TRUE(context_provider);
180 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
181 *resource_pool =
182 ResourcePool::Create(resource_provider,
183 draw_texture_target_,
184 resource_provider->best_texture_format());
186 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
187 task_runner, TileTaskWorkerPool::GetTaskGraphRunner());
188 break;
189 case ZERO_COPY_TILE_TASK_WORKER_POOL:
190 EXPECT_TRUE(context_provider);
191 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
192 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
193 *resource_pool =
194 ResourcePool::Create(resource_provider,
195 draw_texture_target_,
196 resource_provider->best_texture_format());
198 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
199 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
200 resource_provider);
201 break;
202 case ONE_COPY_TILE_TASK_WORKER_POOL:
203 EXPECT_TRUE(context_provider);
204 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
205 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
206 // We need to create a staging resource pool when using copy rasterizer.
207 *staging_resource_pool =
208 ResourcePool::Create(resource_provider,
209 staging_texture_target_,
210 resource_provider->best_texture_format());
211 *resource_pool =
212 ResourcePool::Create(resource_provider,
213 draw_texture_target_,
214 resource_provider->best_texture_format());
216 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
217 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
218 context_provider, resource_provider, staging_resource_pool->get());
219 break;
220 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
221 EXPECT_TRUE(context_provider);
222 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
223 *resource_pool = ResourcePool::Create(
224 resource_provider,
225 draw_texture_target_,
226 resource_provider->memory_efficient_texture_format());
228 *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create(
229 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
230 context_provider, resource_provider, max_transfer_buffer_usage_bytes);
231 break;
235 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
236 scoped_refptr<Layer> content_root,
237 base::FilePath file_name) {
238 if (!IsTestCaseSupported(test_case_))
239 return;
240 RunPixelTest(test_type_, content_root, file_name);
242 if (layer_tree_host())
243 EXPECT_TRUE(layer_tree_host()->settings().impl_side_painting);
246 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
247 : LayerTreeHostPixelResourceTest(GetParam()) {
250 } // namespace cc