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 : draw_texture_target_(GL_INVALID_VALUE
),
49 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL
),
51 test_case_(test_case
) {
52 InitializeFromTestCase(test_case
);
55 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
56 : draw_texture_target_(GL_INVALID_VALUE
),
57 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL
),
59 test_case_(SOFTWARE
) {}
61 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
62 PixelResourceTestCase test_case
) {
63 DCHECK(!initialized_
);
67 test_type_
= PIXEL_TEST_SOFTWARE
;
68 draw_texture_target_
= GL_INVALID_VALUE
;
69 resource_pool_option_
= BITMAP_TILE_TASK_WORKER_POOL
;
71 case GL_GPU_RASTER_2D_DRAW
:
72 test_type_
= PIXEL_TEST_GL
;
73 draw_texture_target_
= GL_TEXTURE_2D
;
74 resource_pool_option_
= GPU_TILE_TASK_WORKER_POOL
;
76 case GL_ONE_COPY_2D_STAGING_2D_DRAW
:
77 test_type_
= PIXEL_TEST_GL
;
78 draw_texture_target_
= GL_TEXTURE_2D
;
79 resource_pool_option_
= ONE_COPY_TILE_TASK_WORKER_POOL
;
81 case GL_ONE_COPY_RECT_STAGING_2D_DRAW
:
82 test_type_
= PIXEL_TEST_GL
;
83 draw_texture_target_
= GL_TEXTURE_2D
;
84 resource_pool_option_
= ONE_COPY_TILE_TASK_WORKER_POOL
;
86 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW
:
87 test_type_
= PIXEL_TEST_GL
;
88 draw_texture_target_
= GL_TEXTURE_2D
;
89 resource_pool_option_
= ONE_COPY_TILE_TASK_WORKER_POOL
;
91 case GL_ZERO_COPY_2D_DRAW
:
92 test_type_
= PIXEL_TEST_GL
;
93 draw_texture_target_
= GL_TEXTURE_2D
;
94 resource_pool_option_
= ZERO_COPY_TILE_TASK_WORKER_POOL
;
96 case GL_ZERO_COPY_RECT_DRAW
:
97 test_type_
= PIXEL_TEST_GL
;
98 draw_texture_target_
= GL_TEXTURE_RECTANGLE_ARB
;
99 resource_pool_option_
= ZERO_COPY_TILE_TASK_WORKER_POOL
;
101 case GL_ZERO_COPY_EXTERNAL_DRAW
:
102 test_type_
= PIXEL_TEST_GL
;
103 draw_texture_target_
= GL_TEXTURE_EXTERNAL_OES
;
104 resource_pool_option_
= ZERO_COPY_TILE_TASK_WORKER_POOL
;
106 case GL_ASYNC_UPLOAD_2D_DRAW
:
107 test_type_
= PIXEL_TEST_GL
;
108 draw_texture_target_
= GL_TEXTURE_2D
;
109 resource_pool_option_
= PIXEL_BUFFER_TILE_TASK_WORKER_POOL
;
115 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
116 LayerTreeHostImpl
* host_impl
,
117 scoped_ptr
<TileTaskWorkerPool
>* tile_task_worker_pool
,
118 scoped_ptr
<ResourcePool
>* resource_pool
) {
119 base::SingleThreadTaskRunner
* task_runner
=
120 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
121 : proxy()->MainThreadTaskRunner();
123 DCHECK(initialized_
);
125 ContextProvider
* context_provider
=
126 host_impl
->output_surface()->context_provider();
127 ResourceProvider
* resource_provider
= host_impl
->resource_provider();
128 size_t max_transfer_buffer_usage_bytes
= 1024u * 1024u * 60u;
129 int max_bytes_per_copy_operation
= 1024 * 1024;
130 int max_staging_buffers
= 32;
132 switch (resource_pool_option_
) {
133 case BITMAP_TILE_TASK_WORKER_POOL
:
134 EXPECT_FALSE(context_provider
);
135 EXPECT_EQ(PIXEL_TEST_SOFTWARE
, test_type_
);
137 ResourcePool::Create(resource_provider
,
138 draw_texture_target_
);
140 *tile_task_worker_pool
= BitmapTileTaskWorkerPool::Create(
141 task_runner
, task_graph_runner(), resource_provider
);
143 case GPU_TILE_TASK_WORKER_POOL
:
144 EXPECT_TRUE(context_provider
);
145 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
147 ResourcePool::Create(resource_provider
,
148 draw_texture_target_
);
150 *tile_task_worker_pool
= GpuTileTaskWorkerPool::Create(
151 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
154 case ZERO_COPY_TILE_TASK_WORKER_POOL
:
155 EXPECT_TRUE(context_provider
);
156 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
157 EXPECT_TRUE(host_impl
->GetRendererCapabilities().using_image
);
159 ResourcePool::Create(resource_provider
, draw_texture_target_
);
161 *tile_task_worker_pool
= ZeroCopyTileTaskWorkerPool::Create(
162 task_runner
, task_graph_runner(), resource_provider
);
164 case ONE_COPY_TILE_TASK_WORKER_POOL
:
165 EXPECT_TRUE(context_provider
);
166 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
167 EXPECT_TRUE(host_impl
->GetRendererCapabilities().using_image
);
169 ResourcePool::Create(resource_provider
, draw_texture_target_
);
171 *tile_task_worker_pool
= OneCopyTileTaskWorkerPool::Create(
172 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
173 max_bytes_per_copy_operation
, false, max_staging_buffers
);
175 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL
:
176 EXPECT_TRUE(context_provider
);
177 EXPECT_EQ(PIXEL_TEST_GL
, test_type_
);
178 *resource_pool
= ResourcePool::Create(
179 resource_provider
, draw_texture_target_
);
181 *tile_task_worker_pool
= PixelBufferTileTaskWorkerPool::Create(
182 task_runner
, task_graph_runner(), context_provider
, resource_provider
,
183 max_transfer_buffer_usage_bytes
);
188 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
189 scoped_refptr
<Layer
> content_root
,
190 base::FilePath file_name
) {
191 if (!IsTestCaseSupported(test_case_
))
193 RunPixelTest(test_type_
, content_root
, file_name
);
196 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
197 : LayerTreeHostPixelResourceTest(GetParam()) {