cc: Use worker context for one-copy tile initialization.
[chromium-blink-merge.git] / cc / test / layer_tree_pixel_resource_test.cc
blob1bd398921b3358d0a9e3cddb3ed4675bb7b63d88
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/raster/bitmap_tile_task_worker_pool.h"
9 #include "cc/raster/gpu_rasterizer.h"
10 #include "cc/raster/gpu_tile_task_worker_pool.h"
11 #include "cc/raster/one_copy_tile_task_worker_pool.h"
12 #include "cc/raster/pixel_buffer_tile_task_worker_pool.h"
13 #include "cc/raster/tile_task_worker_pool.h"
14 #include "cc/raster/zero_copy_tile_task_worker_pool.h"
15 #include "cc/resources/resource_pool.h"
16 #include "cc/test/fake_output_surface.h"
17 #include "gpu/GLES2/gl2extchromium.h"
19 namespace cc {
21 namespace {
23 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
24 switch (test_case) {
25 case SOFTWARE:
26 case GL_GPU_RASTER_2D_DRAW:
27 case GL_ZERO_COPY_2D_DRAW:
28 case GL_ZERO_COPY_RECT_DRAW:
29 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
30 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
31 case GL_ASYNC_UPLOAD_2D_DRAW:
32 return true;
33 case GL_ZERO_COPY_EXTERNAL_DRAW:
34 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
35 // These should all be enabled in practice.
36 // TODO(enne): look into getting texture external oes enabled.
37 return false;
40 NOTREACHED();
41 return false;
44 } // namespace
46 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
47 PixelResourceTestCase test_case)
48 : staging_texture_target_(GL_INVALID_VALUE),
49 draw_texture_target_(GL_INVALID_VALUE),
50 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
51 initialized_(false),
52 test_case_(test_case) {
53 InitializeFromTestCase(test_case);
56 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
57 : staging_texture_target_(GL_INVALID_VALUE),
58 draw_texture_target_(GL_INVALID_VALUE),
59 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
60 initialized_(false),
61 test_case_(SOFTWARE) {
64 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
65 PixelResourceTestCase test_case) {
66 DCHECK(!initialized_);
67 initialized_ = true;
68 switch (test_case) {
69 case SOFTWARE:
70 test_type_ = PIXEL_TEST_SOFTWARE;
71 staging_texture_target_ = GL_INVALID_VALUE;
72 draw_texture_target_ = GL_INVALID_VALUE;
73 resource_pool_option_ = BITMAP_TILE_TASK_WORKER_POOL;
74 return;
75 case GL_GPU_RASTER_2D_DRAW:
76 test_type_ = PIXEL_TEST_GL;
77 staging_texture_target_ = GL_INVALID_VALUE;
78 draw_texture_target_ = GL_TEXTURE_2D;
79 resource_pool_option_ = GPU_TILE_TASK_WORKER_POOL;
80 return;
81 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
82 test_type_ = PIXEL_TEST_GL;
83 staging_texture_target_ = GL_TEXTURE_2D;
84 draw_texture_target_ = GL_TEXTURE_2D;
85 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
86 return;
87 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
88 test_type_ = PIXEL_TEST_GL;
89 staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
90 draw_texture_target_ = GL_TEXTURE_2D;
91 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
92 return;
93 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
94 test_type_ = PIXEL_TEST_GL;
95 staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
96 draw_texture_target_ = GL_TEXTURE_2D;
97 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
98 return;
99 case GL_ZERO_COPY_2D_DRAW:
100 test_type_ = PIXEL_TEST_GL;
101 staging_texture_target_ = GL_INVALID_VALUE;
102 draw_texture_target_ = GL_TEXTURE_2D;
103 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
104 return;
105 case GL_ZERO_COPY_RECT_DRAW:
106 test_type_ = PIXEL_TEST_GL;
107 staging_texture_target_ = GL_INVALID_VALUE;
108 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
109 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
110 return;
111 case GL_ZERO_COPY_EXTERNAL_DRAW:
112 test_type_ = PIXEL_TEST_GL;
113 staging_texture_target_ = GL_INVALID_VALUE;
114 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
115 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
116 return;
117 case GL_ASYNC_UPLOAD_2D_DRAW:
118 test_type_ = PIXEL_TEST_GL;
119 staging_texture_target_ = GL_INVALID_VALUE;
120 draw_texture_target_ = GL_TEXTURE_2D;
121 resource_pool_option_ = PIXEL_BUFFER_TILE_TASK_WORKER_POOL;
122 return;
124 NOTREACHED();
127 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
128 LayerTreeHostImpl* host_impl,
129 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
130 scoped_ptr<ResourcePool>* resource_pool) {
131 base::SingleThreadTaskRunner* task_runner =
132 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
133 : proxy()->MainThreadTaskRunner();
134 DCHECK(task_runner);
135 DCHECK(initialized_);
137 ContextProvider* context_provider =
138 host_impl->output_surface()->context_provider();
139 ResourceProvider* resource_provider = host_impl->resource_provider();
140 size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
141 int max_bytes_per_copy_operation = 1024 * 1024;
142 int max_staging_buffers = 32;
144 switch (resource_pool_option_) {
145 case BITMAP_TILE_TASK_WORKER_POOL:
146 EXPECT_FALSE(context_provider);
147 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
148 *resource_pool =
149 ResourcePool::Create(resource_provider,
150 draw_texture_target_);
152 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
153 task_runner, task_graph_runner(), resource_provider);
154 break;
155 case GPU_TILE_TASK_WORKER_POOL:
156 EXPECT_TRUE(context_provider);
157 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
158 *resource_pool =
159 ResourcePool::Create(resource_provider,
160 draw_texture_target_);
162 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
163 task_runner, task_graph_runner(), context_provider, resource_provider,
164 false, 0);
165 break;
166 case ZERO_COPY_TILE_TASK_WORKER_POOL:
167 EXPECT_TRUE(context_provider);
168 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
169 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
170 *resource_pool =
171 ResourcePool::Create(resource_provider, draw_texture_target_);
173 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
174 task_runner, task_graph_runner(), resource_provider);
175 break;
176 case ONE_COPY_TILE_TASK_WORKER_POOL:
177 EXPECT_TRUE(context_provider);
178 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
179 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
180 *resource_pool =
181 ResourcePool::Create(resource_provider, draw_texture_target_);
183 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
184 task_runner, task_graph_runner(), context_provider, resource_provider,
185 max_bytes_per_copy_operation, false, staging_texture_target_,
186 max_staging_buffers);
187 break;
188 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
189 EXPECT_TRUE(context_provider);
190 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
191 *resource_pool = ResourcePool::Create(
192 resource_provider, draw_texture_target_);
194 *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create(
195 task_runner, task_graph_runner(), context_provider, resource_provider,
196 max_transfer_buffer_usage_bytes);
197 break;
201 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
202 scoped_refptr<Layer> content_root,
203 base::FilePath file_name) {
204 if (!IsTestCaseSupported(test_case_))
205 return;
206 RunPixelTest(test_type_, content_root, file_name);
209 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
210 : LayerTreeHostPixelResourceTest(GetParam()) {
213 } // namespace cc