| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/test/layer_tree_pixel_resource_test.h" | |
| 6 | |
| 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" | |
| 19 | |
| 20 namespace cc { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 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; | |
| 39 } | |
| 40 | |
| 41 NOTREACHED(); | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 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); | |
| 55 } | |
| 56 | |
| 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) { | |
| 63 } | |
| 64 | |
| 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; | |
| 124 } | |
| 125 NOTREACHED(); | |
| 126 } | |
| 127 | |
| 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); | |
| 144 } | |
| 145 NOTREACHED(); | |
| 146 return nullptr; | |
| 147 } | |
| 148 | |
| 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_); | |
| 159 | |
| 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; | |
| 164 | |
| 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_); | |
| 172 | |
| 173 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create( | |
| 174 task_runner, task_graph_runner(), resource_provider); | |
| 175 break; | |
| 176 case GPU_TILE_TASK_WORKER_POOL: | |
| 177 EXPECT_TRUE(context_provider); | |
| 178 EXPECT_EQ(PIXEL_TEST_GL, test_type_); | |
| 179 *resource_pool = | |
| 180 ResourcePool::Create(resource_provider, | |
| 181 draw_texture_target_); | |
| 182 | |
| 183 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create( | |
| 184 task_runner, task_graph_runner(), | |
| 185 static_cast<GpuRasterizer*>(host_impl->rasterizer())); | |
| 186 break; | |
| 187 case ZERO_COPY_TILE_TASK_WORKER_POOL: | |
| 188 EXPECT_TRUE(context_provider); | |
| 189 EXPECT_EQ(PIXEL_TEST_GL, test_type_); | |
| 190 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image); | |
| 191 *resource_pool = | |
| 192 ResourcePool::Create(resource_provider, draw_texture_target_); | |
| 193 | |
| 194 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( | |
| 195 task_runner, task_graph_runner(), resource_provider); | |
| 196 break; | |
| 197 case ONE_COPY_TILE_TASK_WORKER_POOL: | |
| 198 EXPECT_TRUE(context_provider); | |
| 199 EXPECT_EQ(PIXEL_TEST_GL, test_type_); | |
| 200 EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image); | |
| 201 // We need to create a staging resource pool when using copy rasterizer. | |
| 202 *staging_resource_pool = | |
| 203 ResourcePool::Create(resource_provider, staging_texture_target_); | |
| 204 *resource_pool = | |
| 205 ResourcePool::Create(resource_provider, draw_texture_target_); | |
| 206 | |
| 207 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( | |
| 208 task_runner, task_graph_runner(), context_provider, resource_provider, | |
| 209 staging_resource_pool->get()); | |
| 210 break; | |
| 211 case PIXEL_BUFFER_TILE_TASK_WORKER_POOL: | |
| 212 EXPECT_TRUE(context_provider); | |
| 213 EXPECT_EQ(PIXEL_TEST_GL, test_type_); | |
| 214 *resource_pool = ResourcePool::Create( | |
| 215 resource_provider, draw_texture_target_); | |
| 216 | |
| 217 *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create( | |
| 218 task_runner, task_graph_runner(), context_provider, resource_provider, | |
| 219 max_transfer_buffer_usage_bytes); | |
| 220 break; | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 void LayerTreeHostPixelResourceTest::RunPixelResourceTest( | |
| 225 scoped_refptr<Layer> content_root, | |
| 226 base::FilePath file_name) { | |
| 227 if (!IsTestCaseSupported(test_case_)) | |
| 228 return; | |
| 229 RunPixelTest(test_type_, content_root, file_name); | |
| 230 | |
| 231 if (layer_tree_host()) | |
| 232 EXPECT_TRUE(layer_tree_host()->settings().impl_side_painting); | |
| 233 } | |
| 234 | |
| 235 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest() | |
| 236 : LayerTreeHostPixelResourceTest(GetParam()) { | |
| 237 } | |
| 238 | |
| 239 } // namespace cc | |
| OLD | NEW |