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_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" |
| 17 |
| 18 namespace cc { |
| 19 |
| 20 namespace { |
| 21 |
| 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_ASYNC_UPLOAD_2D_DRAW: |
| 29 return true; |
| 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. |
| 37 return false; |
| 38 } |
| 39 |
| 40 NOTREACHED(); |
| 41 return false; |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 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); |
| 53 } |
| 54 |
| 55 void LayerTreeHostPixelResourceTest::InitializeFromTestCase( |
| 56 PixelResourceTestCase test_case) { |
| 57 switch (test_case) { |
| 58 case SOFTWARE: |
| 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; |
| 63 return; |
| 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; |
| 69 return; |
| 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; |
| 75 return; |
| 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; |
| 81 return; |
| 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; |
| 87 return; |
| 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; |
| 93 return; |
| 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; |
| 99 return; |
| 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; |
| 105 return; |
| 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; |
| 111 return; |
| 112 } |
| 113 NOTREACHED(); |
| 114 } |
| 115 |
| 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(); |
| 124 DCHECK(task_runner); |
| 125 |
| 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; |
| 131 |
| 132 switch (resource_pool_option_) { |
| 133 case BITMAP_RASTER_WORKER_POOL: |
| 134 EXPECT_FALSE(context_provider); |
| 135 EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_); |
| 136 *resource_pool = |
| 137 ResourcePool::Create(resource_provider, |
| 138 draw_texture_target_, |
| 139 resource_provider->best_texture_format()); |
| 140 |
| 141 *raster_worker_pool = |
| 142 BitmapRasterWorkerPool::Create(task_runner, |
| 143 RasterWorkerPool::GetTaskGraphRunner(), |
| 144 resource_provider); |
| 145 break; |
| 146 case GPU_RASTER_WORKER_POOL: |
| 147 EXPECT_TRUE(context_provider); |
| 148 EXPECT_EQ(PIXEL_TEST_GL, test_type_); |
| 149 *resource_pool = |
| 150 ResourcePool::Create(resource_provider, |
| 151 draw_texture_target_, |
| 152 resource_provider->best_texture_format()); |
| 153 |
| 154 *raster_worker_pool = |
| 155 GpuRasterWorkerPool::Create(task_runner, |
| 156 context_provider, |
| 157 resource_provider, |
| 158 use_distance_field_text); |
| 159 break; |
| 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()); |
| 164 *resource_pool = |
| 165 ResourcePool::Create(resource_provider, |
| 166 draw_texture_target_, |
| 167 resource_provider->best_texture_format()); |
| 168 |
| 169 *raster_worker_pool = ZeroCopyRasterWorkerPool::Create( |
| 170 task_runner, |
| 171 RasterWorkerPool::GetTaskGraphRunner(), |
| 172 resource_provider); |
| 173 break; |
| 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()); |
| 183 *resource_pool = |
| 184 ResourcePool::Create(resource_provider, |
| 185 draw_texture_target_, |
| 186 resource_provider->best_texture_format()); |
| 187 |
| 188 *raster_worker_pool = OneCopyRasterWorkerPool::Create( |
| 189 task_runner, |
| 190 RasterWorkerPool::GetTaskGraphRunner(), |
| 191 context_provider, |
| 192 resource_provider, |
| 193 staging_resource_pool->get()); |
| 194 break; |
| 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( |
| 199 resource_provider, |
| 200 draw_texture_target_, |
| 201 resource_provider->memory_efficient_texture_format()); |
| 202 |
| 203 *raster_worker_pool = PixelBufferRasterWorkerPool::Create( |
| 204 task_runner, |
| 205 RasterWorkerPool::GetTaskGraphRunner(), |
| 206 context_provider, |
| 207 resource_provider, |
| 208 max_transfer_buffer_usage_bytes); |
| 209 break; |
| 210 } |
| 211 } |
| 212 |
| 213 void LayerTreeHostPixelResourceTest::RunPixelResourceTest( |
| 214 scoped_refptr<Layer> content_root, |
| 215 base::FilePath file_name) { |
| 216 if (!IsTestCaseSupported(test_case_)) |
| 217 return; |
| 218 RunPixelTest(test_type_, content_root, file_name); |
| 219 } |
| 220 |
| 221 ParameterizedPixelResourceTest::ParameterizedPixelResourceTest() |
| 222 : LayerTreeHostPixelResourceTest(GetParam()) { |
| 223 } |
| 224 |
| 225 } // namespace cc |
OLD | NEW |