Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / test / layer_tree_pixel_resource_test.cc
blob5d60795dbeb47e1c0314e82221d8ca40b03fa761
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/tile_task_worker_pool.h"
13 #include "cc/raster/zero_copy_tile_task_worker_pool.h"
14 #include "cc/resources/resource_pool.h"
15 #include "cc/test/fake_output_surface.h"
16 #include "gpu/GLES2/gl2extchromium.h"
18 namespace cc {
20 namespace {
22 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
23 switch (test_case) {
24 case SOFTWARE:
25 case GL_GPU_RASTER_2D_DRAW:
26 case GL_ZERO_COPY_2D_DRAW:
27 case GL_ZERO_COPY_RECT_DRAW:
28 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
29 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
30 return true;
31 case GL_ZERO_COPY_EXTERNAL_DRAW:
32 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
33 // These should all be enabled in practice.
34 // TODO(enne): look into getting texture external oes enabled.
35 return false;
38 NOTREACHED();
39 return false;
42 } // namespace
44 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
45 PixelResourceTestCase test_case)
46 : draw_texture_target_(GL_INVALID_VALUE),
47 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
48 initialized_(false),
49 test_case_(test_case) {
50 InitializeFromTestCase(test_case);
53 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
54 : draw_texture_target_(GL_INVALID_VALUE),
55 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
56 initialized_(false),
57 test_case_(SOFTWARE) {}
59 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
60 PixelResourceTestCase test_case) {
61 DCHECK(!initialized_);
62 initialized_ = true;
63 switch (test_case) {
64 case SOFTWARE:
65 test_type_ = PIXEL_TEST_SOFTWARE;
66 draw_texture_target_ = GL_INVALID_VALUE;
67 resource_pool_option_ = BITMAP_TILE_TASK_WORKER_POOL;
68 return;
69 case GL_GPU_RASTER_2D_DRAW:
70 test_type_ = PIXEL_TEST_GL;
71 draw_texture_target_ = GL_TEXTURE_2D;
72 resource_pool_option_ = GPU_TILE_TASK_WORKER_POOL;
73 return;
74 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
75 test_type_ = PIXEL_TEST_GL;
76 draw_texture_target_ = GL_TEXTURE_2D;
77 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
78 return;
79 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
80 test_type_ = PIXEL_TEST_GL;
81 draw_texture_target_ = GL_TEXTURE_2D;
82 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
83 return;
84 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
85 test_type_ = PIXEL_TEST_GL;
86 draw_texture_target_ = GL_TEXTURE_2D;
87 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
88 return;
89 case GL_ZERO_COPY_2D_DRAW:
90 test_type_ = PIXEL_TEST_GL;
91 draw_texture_target_ = GL_TEXTURE_2D;
92 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
93 return;
94 case GL_ZERO_COPY_RECT_DRAW:
95 test_type_ = PIXEL_TEST_GL;
96 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
97 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
98 return;
99 case GL_ZERO_COPY_EXTERNAL_DRAW:
100 test_type_ = PIXEL_TEST_GL;
101 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
102 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
103 return;
105 NOTREACHED();
108 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
109 LayerTreeHostImpl* host_impl,
110 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
111 scoped_ptr<ResourcePool>* resource_pool) {
112 base::SingleThreadTaskRunner* task_runner =
113 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
114 : proxy()->MainThreadTaskRunner();
115 DCHECK(task_runner);
116 DCHECK(initialized_);
118 ContextProvider* context_provider =
119 host_impl->output_surface()->context_provider();
120 ResourceProvider* resource_provider = host_impl->resource_provider();
121 int max_bytes_per_copy_operation = 1024 * 1024;
122 int max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024;
124 switch (resource_pool_option_) {
125 case BITMAP_TILE_TASK_WORKER_POOL:
126 EXPECT_FALSE(context_provider);
127 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
128 *resource_pool = ResourcePool::Create(resource_provider, task_runner,
129 draw_texture_target_);
131 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
132 task_runner, task_graph_runner(), resource_provider);
133 break;
134 case GPU_TILE_TASK_WORKER_POOL:
135 EXPECT_TRUE(context_provider);
136 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
137 *resource_pool = ResourcePool::Create(resource_provider, task_runner,
138 draw_texture_target_);
140 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
141 task_runner, task_graph_runner(), context_provider, resource_provider,
142 false, 0);
143 break;
144 case ZERO_COPY_TILE_TASK_WORKER_POOL:
145 EXPECT_TRUE(context_provider);
146 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
147 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
148 *resource_pool = ResourcePool::Create(resource_provider, task_runner,
149 draw_texture_target_);
151 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
152 task_runner, task_graph_runner(), resource_provider);
153 break;
154 case ONE_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);
158 *resource_pool = ResourcePool::Create(resource_provider, task_runner,
159 draw_texture_target_);
161 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
162 task_runner, task_graph_runner(), context_provider, resource_provider,
163 max_bytes_per_copy_operation, false,
164 max_staging_buffer_usage_in_bytes);
165 break;
169 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
170 scoped_refptr<Layer> content_root,
171 base::FilePath file_name) {
172 if (!IsTestCaseSupported(test_case_))
173 return;
174 RunPixelTest(test_type_, content_root, file_name);
177 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
178 : LayerTreeHostPixelResourceTest(GetParam()) {
181 } // namespace cc