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/tile_task_worker_pool.h"
15 #include "cc/resources/zero_copy_tile_task_worker_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;
143 switch (resource_pool_option_
) {
144 case BITMAP_TILE_TASK_WORKER_POOL
:
145 EXPECT_FALSE(context_provider
);
146 EXPECT_EQ(PIXEL_TEST_SOFTWARE
, test_type_
);
148 ResourcePool::Create(resource_provider
,
149 draw_texture_target_
);
151 *tile_task_worker_pool
= BitmapTileTaskWorkerPool::Create(
152 task_runner
, task_graph_runner(), resource_provider
);
154 case GPU_TILE_TASK_WORKER_POOL
:
155 EXPECT_TRUE(context_provider
);
156 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
158 ResourcePool::Create(resource_provider
,
159 draw_texture_target_
);
161 *tile_task_worker_pool
= GpuTileTaskWorkerPool::Create(
162 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
165 case ZERO_COPY_TILE_TASK_WORKER_POOL
:
166 EXPECT_TRUE(context_provider
);
167 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
168 EXPECT_TRUE(host_impl
->GetRendererCapabilities().using_image
);
170 ResourcePool::Create(resource_provider
, draw_texture_target_
);
172 *tile_task_worker_pool
= ZeroCopyTileTaskWorkerPool::Create(
173 task_runner
, task_graph_runner(), resource_provider
);
175 case ONE_COPY_TILE_TASK_WORKER_POOL
:
176 EXPECT_TRUE(context_provider
);
177 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
178 EXPECT_TRUE(host_impl
->GetRendererCapabilities().using_image
);
179 // We need to create a staging resource pool when using copy rasterizer.
180 *staging_resource_pool
=
181 ResourcePool::Create(resource_provider
, staging_texture_target_
);
183 ResourcePool::Create(resource_provider
, draw_texture_target_
);
185 *tile_task_worker_pool
= OneCopyTileTaskWorkerPool::Create(
186 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
187 staging_resource_pool
->get());
189 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL
:
190 EXPECT_TRUE(context_provider
);
191 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
192 *resource_pool
= ResourcePool::Create(
193 resource_provider
, draw_texture_target_
);
195 *tile_task_worker_pool
= PixelBufferTileTaskWorkerPool::Create(
196 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
197 max_transfer_buffer_usage_bytes
);
202 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
203 scoped_refptr
<Layer
> content_root
,
204 base::FilePath file_name
) {
205 if (!IsTestCaseSupported(test_case_
))
207 RunPixelTest(test_type_
, content_root
, file_name
);
209 if (layer_tree_host())
210 EXPECT_TRUE(layer_tree_host()->settings().impl_side_painting
);
213 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
214 : LayerTreeHostPixelResourceTest(GetParam()) {