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_raster_worker_pool.h"
9 #include "cc/resources/gpu_raster_worker_pool.h"
10 #include "cc/resources/one_copy_raster_worker_pool.h"
11 #include "cc/resources/pixel_buffer_raster_worker_pool.h"
12 #include "cc/resources/raster_worker_pool.h"
13 #include "cc/resources/resource_pool.h"
14 #include "cc/resources/zero_copy_raster_worker_pool.h"
15 #include "cc/test/fake_output_surface.h"
16 #include "gpu/GLES2/gl2extchromium.h"
22 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
25 case GL_GPU_RASTER_2D_DRAW:
26 case GL_ZERO_COPY_2D_DRAW:
27 case GL_ZERO_COPY_RECT_DRAW:
28 case GL_ASYNC_UPLOAD_2D_DRAW:
30 case GL_ZERO_COPY_EXTERNAL_DRAW:
31 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
32 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
33 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
34 // These should all be enabled in practice.
35 // TODO(reveman): one copy not supported in unit tests yet.
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_RASTER_WORKER_POOL),
51 test_case_(test_case) {
52 InitializeFromTestCase(test_case);
55 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
56 PixelResourceTestCase test_case) {
59 test_type_ = PIXEL_TEST_SOFTWARE;
60 staging_texture_target_ = GL_INVALID_VALUE;
61 draw_texture_target_ = GL_INVALID_VALUE;
62 resource_pool_option_ = BITMAP_RASTER_WORKER_POOL;
64 case GL_GPU_RASTER_2D_DRAW:
65 test_type_ = PIXEL_TEST_GL;
66 staging_texture_target_ = GL_INVALID_VALUE;
67 draw_texture_target_ = GL_TEXTURE_2D;
68 resource_pool_option_ = GPU_RASTER_WORKER_POOL;
70 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
71 test_type_ = PIXEL_TEST_GL;
72 staging_texture_target_ = GL_TEXTURE_2D;
73 draw_texture_target_ = GL_TEXTURE_2D;
74 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
76 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
77 test_type_ = PIXEL_TEST_GL;
78 staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
79 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
80 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
82 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
83 test_type_ = PIXEL_TEST_GL;
84 staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
85 draw_texture_target_ = GL_TEXTURE_2D;
86 resource_pool_option_ = ONE_COPY_RASTER_WORKER_POOL;
88 case GL_ZERO_COPY_2D_DRAW:
89 test_type_ = PIXEL_TEST_GL;
90 staging_texture_target_ = GL_INVALID_VALUE;
91 draw_texture_target_ = GL_TEXTURE_2D;
92 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
94 case GL_ZERO_COPY_RECT_DRAW:
95 test_type_ = PIXEL_TEST_GL;
96 staging_texture_target_ = GL_INVALID_VALUE;
97 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
98 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
100 case GL_ZERO_COPY_EXTERNAL_DRAW:
101 test_type_ = PIXEL_TEST_GL;
102 staging_texture_target_ = GL_INVALID_VALUE;
103 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
104 resource_pool_option_ = ZERO_COPY_RASTER_WORKER_POOL;
106 case GL_ASYNC_UPLOAD_2D_DRAW:
107 test_type_ = PIXEL_TEST_GL;
108 staging_texture_target_ = GL_INVALID_VALUE;
109 draw_texture_target_ = GL_TEXTURE_2D;
110 resource_pool_option_ = PIXEL_BUFFER_RASTER_WORKER_POOL;
116 void LayerTreeHostPixelResourceTest::CreateResourceAndRasterWorkerPool(
117 LayerTreeHostImpl* host_impl,
118 scoped_ptr<RasterWorkerPool>* raster_worker_pool,
119 scoped_ptr<ResourcePool>* resource_pool,
120 scoped_ptr<ResourcePool>* staging_resource_pool) {
121 base::SingleThreadTaskRunner* task_runner =
122 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
123 : proxy()->MainThreadTaskRunner();
126 ContextProvider* context_provider =
127 host_impl->output_surface()->context_provider();
128 ResourceProvider* resource_provider = host_impl->resource_provider();
129 bool use_distance_field_text = false;
130 size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
132 switch (resource_pool_option_) {
133 case BITMAP_RASTER_WORKER_POOL:
134 EXPECT_FALSE(context_provider);
135 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
137 ResourcePool::Create(resource_provider,
138 draw_texture_target_,
139 resource_provider->best_texture_format());
141 *raster_worker_pool =
142 BitmapRasterWorkerPool::Create(task_runner,
143 RasterWorkerPool::GetTaskGraphRunner(),
146 case GPU_RASTER_WORKER_POOL:
147 EXPECT_TRUE(context_provider);
148 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
150 ResourcePool::Create(resource_provider,
151 draw_texture_target_,
152 resource_provider->best_texture_format());
154 *raster_worker_pool =
155 GpuRasterWorkerPool::Create(task_runner,
158 use_distance_field_text);
160 case ZERO_COPY_RASTER_WORKER_POOL:
161 EXPECT_TRUE(context_provider);
162 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
163 EXPECT_TRUE(host_impl->CanUseZeroCopyRasterizer());
165 ResourcePool::Create(resource_provider,
166 draw_texture_target_,
167 resource_provider->best_texture_format());
169 *raster_worker_pool = ZeroCopyRasterWorkerPool::Create(
171 RasterWorkerPool::GetTaskGraphRunner(),
174 case ONE_COPY_RASTER_WORKER_POOL:
175 EXPECT_TRUE(context_provider);
176 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
177 EXPECT_TRUE(host_impl->CanUseOneCopyRasterizer());
178 // We need to create a staging resource pool when using copy rasterizer.
179 *staging_resource_pool =
180 ResourcePool::Create(resource_provider,
181 staging_texture_target_,
182 resource_provider->best_texture_format());
184 ResourcePool::Create(resource_provider,
185 draw_texture_target_,
186 resource_provider->best_texture_format());
188 *raster_worker_pool = OneCopyRasterWorkerPool::Create(
190 RasterWorkerPool::GetTaskGraphRunner(),
193 staging_resource_pool->get());
195 case PIXEL_BUFFER_RASTER_WORKER_POOL:
196 EXPECT_TRUE(context_provider);
197 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
198 *resource_pool = ResourcePool::Create(
200 draw_texture_target_,
201 resource_provider->memory_efficient_texture_format());
203 *raster_worker_pool = PixelBufferRasterWorkerPool::Create(
205 RasterWorkerPool::GetTaskGraphRunner(),
208 max_transfer_buffer_usage_bytes);
213 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
214 scoped_refptr<Layer> content_root,
215 base::FilePath file_name) {
216 if (!IsTestCaseSupported(test_case_))
218 RunPixelTest(test_type_, content_root, file_name);
221 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
222 : LayerTreeHostPixelResourceTest(GetParam()) {