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"
23 bool IsTestCaseSupported(PixelResourceTestCase test_case
) {
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
:
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.
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
),
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
),
61 test_case_(SOFTWARE
) {
64 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
65 PixelResourceTestCase test_case
) {
66 DCHECK(!initialized_
);
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
127 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
128 LayerTreeHostImpl
* host_impl
,
129 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
130 scoped_ptr
<ResourcePool
>* resource_pool
,
131 scoped_ptr
<ResourcePool
>* staging_resource_pool
) {
132 base::SingleThreadTaskRunner
* task_runner
=
133 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
134 : proxy()->MainThreadTaskRunner();
136 DCHECK(initialized_
);
138 ContextProvider
* context_provider
=
139 host_impl
->output_surface()->context_provider();
140 ResourceProvider
* resource_provider
= host_impl
->resource_provider();
141 size_t max_transfer_buffer_usage_bytes
= 1024u * 1024u * 60u;
142 int max_bytes_per_copy_operation
= 1024 * 1024;
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_
);
149 ResourcePool::Create(resource_provider
,
150 draw_texture_target_
);
152 *tile_task_worker_pool
= BitmapTileTaskWorkerPool::Create(
153 task_runner
, task_graph_runner(), resource_provider
);
155 case GPU_TILE_TASK_WORKER_POOL
:
156 EXPECT_TRUE(context_provider
);
157 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
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
,
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
);
171 ResourcePool::Create(resource_provider
, draw_texture_target_
);
173 *tile_task_worker_pool
= ZeroCopyTileTaskWorkerPool::Create(
174 task_runner
, task_graph_runner(), resource_provider
);
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 // We need to create a staging resource pool when using copy rasterizer.
181 *staging_resource_pool
=
182 ResourcePool::Create(resource_provider
, staging_texture_target_
);
184 ResourcePool::Create(resource_provider
, draw_texture_target_
);
186 *tile_task_worker_pool
= OneCopyTileTaskWorkerPool::Create(
187 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
188 staging_resource_pool
->get(), max_bytes_per_copy_operation
, false);
190 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL
:
191 EXPECT_TRUE(context_provider
);
192 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
193 *resource_pool
= ResourcePool::Create(
194 resource_provider
, draw_texture_target_
);
196 *tile_task_worker_pool
= PixelBufferTileTaskWorkerPool::Create(
197 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
198 max_transfer_buffer_usage_bytes
);
203 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
204 scoped_refptr
<Layer
> content_root
,
205 base::FilePath file_name
) {
206 if (!IsTestCaseSupported(test_case_
))
208 RunPixelTest(test_type_
, content_root
, file_name
);
211 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
212 : LayerTreeHostPixelResourceTest(GetParam()) {