[MacViews] Frameless app windows: make content view cover title bar.
[chromium-blink-merge.git] / cc / test / layer_tree_pixel_resource_test.cc
blob6b6c00bbc3e22b56046f4f1865a621101baaa7e2
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/software_rasterizer.h"
15 #include "cc/resources/tile_task_worker_pool.h"
16 #include "cc/resources/zero_copy_tile_task_worker_pool.h"
17 #include "cc/test/fake_output_surface.h"
18 #include "gpu/GLES2/gl2extchromium.h"
20 namespace cc {
22 namespace {
24 bool IsTestCaseSupported(PixelResourceTestCase test_case) {
25 switch (test_case) {
26 case SOFTWARE:
27 case GL_GPU_RASTER_2D_DRAW:
28 case GL_ZERO_COPY_2D_DRAW:
29 case GL_ZERO_COPY_RECT_DRAW:
30 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
31 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
32 case GL_ASYNC_UPLOAD_2D_DRAW:
33 return true;
34 case GL_ZERO_COPY_EXTERNAL_DRAW:
35 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
36 // These should all be enabled in practice.
37 // TODO(enne): look into getting texture external oes enabled.
38 return false;
41 NOTREACHED();
42 return false;
45 } // namespace
47 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
48 PixelResourceTestCase test_case)
49 : staging_texture_target_(GL_INVALID_VALUE),
50 draw_texture_target_(GL_INVALID_VALUE),
51 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
52 initialized_(false),
53 test_case_(test_case) {
54 InitializeFromTestCase(test_case);
57 LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
58 : staging_texture_target_(GL_INVALID_VALUE),
59 draw_texture_target_(GL_INVALID_VALUE),
60 resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
61 initialized_(false),
62 test_case_(SOFTWARE) {
65 void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
66 PixelResourceTestCase test_case) {
67 DCHECK(!initialized_);
68 initialized_ = true;
69 switch (test_case) {
70 case SOFTWARE:
71 test_type_ = PIXEL_TEST_SOFTWARE;
72 staging_texture_target_ = GL_INVALID_VALUE;
73 draw_texture_target_ = GL_INVALID_VALUE;
74 resource_pool_option_ = BITMAP_TILE_TASK_WORKER_POOL;
75 return;
76 case GL_GPU_RASTER_2D_DRAW:
77 test_type_ = PIXEL_TEST_GL;
78 staging_texture_target_ = GL_INVALID_VALUE;
79 draw_texture_target_ = GL_TEXTURE_2D;
80 resource_pool_option_ = GPU_TILE_TASK_WORKER_POOL;
81 return;
82 case GL_ONE_COPY_2D_STAGING_2D_DRAW:
83 test_type_ = PIXEL_TEST_GL;
84 staging_texture_target_ = GL_TEXTURE_2D;
85 draw_texture_target_ = GL_TEXTURE_2D;
86 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
87 return;
88 case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
89 test_type_ = PIXEL_TEST_GL;
90 staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
91 draw_texture_target_ = GL_TEXTURE_2D;
92 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
93 return;
94 case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
95 test_type_ = PIXEL_TEST_GL;
96 staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
97 draw_texture_target_ = GL_TEXTURE_2D;
98 resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
99 return;
100 case GL_ZERO_COPY_2D_DRAW:
101 test_type_ = PIXEL_TEST_GL;
102 staging_texture_target_ = GL_INVALID_VALUE;
103 draw_texture_target_ = GL_TEXTURE_2D;
104 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
105 return;
106 case GL_ZERO_COPY_RECT_DRAW:
107 test_type_ = PIXEL_TEST_GL;
108 staging_texture_target_ = GL_INVALID_VALUE;
109 draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
110 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
111 return;
112 case GL_ZERO_COPY_EXTERNAL_DRAW:
113 test_type_ = PIXEL_TEST_GL;
114 staging_texture_target_ = GL_INVALID_VALUE;
115 draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
116 resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
117 return;
118 case GL_ASYNC_UPLOAD_2D_DRAW:
119 test_type_ = PIXEL_TEST_GL;
120 staging_texture_target_ = GL_INVALID_VALUE;
121 draw_texture_target_ = GL_TEXTURE_2D;
122 resource_pool_option_ = PIXEL_BUFFER_TILE_TASK_WORKER_POOL;
123 return;
125 NOTREACHED();
128 scoped_ptr<Rasterizer> LayerTreeHostPixelResourceTest::CreateRasterizer(
129 LayerTreeHostImpl* host_impl) {
130 bool use_distance_field_text = false;
131 ContextProvider* context_provider =
132 host_impl->output_surface()->context_provider();
133 ResourceProvider* resource_provider = host_impl->resource_provider();
134 switch (resource_pool_option_) {
135 case BITMAP_TILE_TASK_WORKER_POOL:
136 case ZERO_COPY_TILE_TASK_WORKER_POOL:
137 case ONE_COPY_TILE_TASK_WORKER_POOL:
138 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
139 return SoftwareRasterizer::Create();
140 case GPU_TILE_TASK_WORKER_POOL:
141 EXPECT_TRUE(context_provider);
142 return GpuRasterizer::Create(context_provider, resource_provider,
143 use_distance_field_text, false, 0);
145 NOTREACHED();
146 return nullptr;
149 void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
150 LayerTreeHostImpl* host_impl,
151 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
152 scoped_ptr<ResourcePool>* resource_pool,
153 scoped_ptr<ResourcePool>* staging_resource_pool) {
154 base::SingleThreadTaskRunner* task_runner =
155 proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
156 : proxy()->MainThreadTaskRunner();
157 DCHECK(task_runner);
158 DCHECK(initialized_);
160 ContextProvider* context_provider =
161 host_impl->output_surface()->context_provider();
162 ResourceProvider* resource_provider = host_impl->resource_provider();
163 size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
165 switch (resource_pool_option_) {
166 case BITMAP_TILE_TASK_WORKER_POOL:
167 EXPECT_FALSE(context_provider);
168 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
169 *resource_pool =
170 ResourcePool::Create(resource_provider,
171 draw_texture_target_);
173 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
174 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
175 resource_provider);
176 break;
177 case GPU_TILE_TASK_WORKER_POOL:
178 EXPECT_TRUE(context_provider);
179 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
180 *resource_pool =
181 ResourcePool::Create(resource_provider,
182 draw_texture_target_);
184 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
185 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
186 static_cast<GpuRasterizer*>(host_impl->rasterizer()));
187 break;
188 case ZERO_COPY_TILE_TASK_WORKER_POOL:
189 EXPECT_TRUE(context_provider);
190 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
191 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
192 *resource_pool =
193 ResourcePool::Create(resource_provider, draw_texture_target_);
195 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
196 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
197 resource_provider);
198 break;
199 case ONE_COPY_TILE_TASK_WORKER_POOL:
200 EXPECT_TRUE(context_provider);
201 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
202 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
203 // We need to create a staging resource pool when using copy rasterizer.
204 *staging_resource_pool =
205 ResourcePool::Create(resource_provider, staging_texture_target_);
206 *resource_pool =
207 ResourcePool::Create(resource_provider, draw_texture_target_);
209 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
210 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
211 context_provider, resource_provider, staging_resource_pool->get());
212 break;
213 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
214 EXPECT_TRUE(context_provider);
215 EXPECT_EQ(PIXEL_TEST_GL, test_type_);
216 *resource_pool = ResourcePool::Create(
217 resource_provider, draw_texture_target_);
219 *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create(
220 task_runner, TileTaskWorkerPool::GetTaskGraphRunner(),
221 context_provider, resource_provider, max_transfer_buffer_usage_bytes);
222 break;
226 void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
227 scoped_refptr<Layer> content_root,
228 base::FilePath file_name) {
229 if (!IsTestCaseSupported(test_case_))
230 return;
231 RunPixelTest(test_type_, content_root, file_name);
233 if (layer_tree_host())
234 EXPECT_TRUE(layer_tree_host()->settings().impl_side_painting);
237 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
238 : LayerTreeHostPixelResourceTest(GetParam()) {
241 } // namespace cc