OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_simple_task_runner.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "cc/playback/raster_source.h" | 14 #include "cc/playback/raster_source.h" |
14 #include "cc/playback/recording_source.h" | 15 #include "cc/playback/recording_source.h" |
15 #include "cc/raster/raster_buffer.h" | 16 #include "cc/raster/raster_buffer.h" |
16 #include "cc/raster/synchronous_task_graph_runner.h" | 17 #include "cc/raster/synchronous_task_graph_runner.h" |
17 #include "cc/resources/resource_pool.h" | 18 #include "cc/resources/resource_pool.h" |
18 #include "cc/test/begin_frame_args_test.h" | 19 #include "cc/test/begin_frame_args_test.h" |
19 #include "cc/test/fake_compositor_frame_sink.h" | 20 #include "cc/test/fake_compositor_frame_sink.h" |
20 #include "cc/test/fake_compositor_frame_sink_client.h" | 21 #include "cc/test/fake_compositor_frame_sink_client.h" |
21 #include "cc/test/fake_impl_task_runner_provider.h" | 22 #include "cc/test/fake_impl_task_runner_provider.h" |
22 #include "cc/test/fake_layer_tree_host_impl.h" | 23 #include "cc/test/fake_layer_tree_host_impl.h" |
23 #include "cc/test/fake_picture_layer_impl.h" | 24 #include "cc/test/fake_picture_layer_impl.h" |
24 #include "cc/test/fake_picture_layer_tiling_client.h" | 25 #include "cc/test/fake_picture_layer_tiling_client.h" |
25 #include "cc/test/fake_raster_source.h" | 26 #include "cc/test/fake_raster_source.h" |
26 #include "cc/test/fake_recording_source.h" | 27 #include "cc/test/fake_recording_source.h" |
27 #include "cc/test/fake_tile_manager.h" | 28 #include "cc/test/fake_tile_manager.h" |
28 #include "cc/test/fake_tile_task_manager.h" | 29 #include "cc/test/fake_tile_task_manager.h" |
29 #include "cc/test/layer_tree_settings_for_testing.h" | 30 #include "cc/test/layer_tree_settings_for_testing.h" |
30 #include "cc/test/test_layer_tree_host_base.h" | 31 #include "cc/test/test_layer_tree_host_base.h" |
31 #include "cc/test/test_task_graph_runner.h" | 32 #include "cc/test/test_task_graph_runner.h" |
32 #include "cc/test/test_tile_priorities.h" | 33 #include "cc/test/test_tile_priorities.h" |
33 #include "cc/tiles/eviction_tile_priority_queue.h" | 34 #include "cc/tiles/eviction_tile_priority_queue.h" |
34 #include "cc/tiles/raster_tile_priority_queue.h" | 35 #include "cc/tiles/raster_tile_priority_queue.h" |
35 #include "cc/tiles/tile.h" | 36 #include "cc/tiles/tile.h" |
36 #include "cc/tiles/tile_priority.h" | 37 #include "cc/tiles/tile_priority.h" |
37 #include "cc/tiles/tiling_set_raster_queue_all.h" | 38 #include "cc/tiles/tiling_set_raster_queue_all.h" |
38 #include "cc/trees/layer_tree_impl.h" | 39 #include "cc/trees/layer_tree_impl.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "third_party/skia/include/core/SkImageGenerator.h" |
41 #include "third_party/skia/include/core/SkRefCnt.h" | 43 #include "third_party/skia/include/core/SkRefCnt.h" |
42 #include "third_party/skia/include/core/SkSurface.h" | 44 #include "third_party/skia/include/core/SkSurface.h" |
43 | 45 |
44 using testing::_; | 46 using testing::_; |
45 using testing::Invoke; | 47 using testing::Invoke; |
46 using testing::Return; | 48 using testing::Return; |
47 using testing::StrictMock; | 49 using testing::StrictMock; |
48 | 50 |
49 namespace cc { | 51 namespace cc { |
50 namespace { | 52 namespace { |
51 | 53 |
| 54 // A version of simple task runner that lets the user control if all tasks |
| 55 // posted should run synchronously. |
| 56 class SynchronousSimpleTaskRunner : public base::TestSimpleTaskRunner { |
| 57 public: |
| 58 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 59 const base::Closure& task, |
| 60 base::TimeDelta delay) override { |
| 61 TestSimpleTaskRunner::PostDelayedTask(from_here, task, delay); |
| 62 if (run_tasks_synchronously_) |
| 63 RunUntilIdle(); |
| 64 return true; |
| 65 } |
| 66 |
| 67 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 68 const base::Closure& task, |
| 69 base::TimeDelta delay) override { |
| 70 return PostDelayedTask(from_here, task, delay); |
| 71 } |
| 72 |
| 73 void set_run_tasks_synchronously(bool run_tasks_synchronously) { |
| 74 run_tasks_synchronously_ = run_tasks_synchronously; |
| 75 } |
| 76 |
| 77 protected: |
| 78 ~SynchronousSimpleTaskRunner() override = default; |
| 79 |
| 80 bool run_tasks_synchronously_ = false; |
| 81 }; |
| 82 |
52 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase { | 83 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase { |
53 public: | 84 public: |
54 LayerTreeSettings CreateSettings() override { | 85 LayerTreeSettings CreateSettings() override { |
55 LayerTreeSettingsForTesting settings; | 86 LayerTreeSettingsForTesting settings; |
56 settings.create_low_res_tiling = true; | 87 settings.create_low_res_tiling = true; |
57 settings.renderer_settings.buffer_to_texture_target_map = | 88 settings.renderer_settings.buffer_to_texture_target_map = |
58 DefaultBufferToTextureTargetMapForTesting(); | 89 DefaultBufferToTextureTargetMapForTesting(); |
59 return settings; | 90 return settings; |
60 } | 91 } |
61 | 92 |
(...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2287 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
2257 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate()) | 2288 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate()) |
2258 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); })); | 2289 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); })); |
2259 run_loop.Run(); | 2290 run_loop.Run(); |
2260 } | 2291 } |
2261 | 2292 |
2262 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); | 2293 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); |
2263 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); | 2294 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); |
2264 } | 2295 } |
2265 | 2296 |
| 2297 class CheckerImagingTileManagerTest : public TestLayerTreeHostBase { |
| 2298 public: |
| 2299 class MockImageGenerator : public SkImageGenerator { |
| 2300 public: |
| 2301 explicit MockImageGenerator(const gfx::Size& size) |
| 2302 : SkImageGenerator( |
| 2303 SkImageInfo::MakeN32Premul(size.width(), size.height())) {} |
| 2304 |
| 2305 protected: |
| 2306 MOCK_METHOD5(onGetPixels, |
| 2307 bool(const SkImageInfo&, void*, size_t, SkPMColor[], int*)); |
| 2308 }; |
| 2309 |
| 2310 void TearDown() override { |
| 2311 // Allow all tasks on the image worker to run now. Any scheduled decodes |
| 2312 // will be aborted. |
| 2313 image_worker_task_runner()->set_run_tasks_synchronously(true); |
| 2314 } |
| 2315 |
| 2316 LayerTreeSettings CreateSettings() override { |
| 2317 LayerTreeSettings settings; |
| 2318 settings.enable_checker_imaging = true; |
| 2319 settings.renderer_settings.buffer_to_texture_target_map = |
| 2320 DefaultBufferToTextureTargetMapForTesting(); |
| 2321 return settings; |
| 2322 } |
| 2323 |
| 2324 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( |
| 2325 const LayerTreeSettings& settings, |
| 2326 TaskRunnerProvider* task_runner_provider, |
| 2327 TaskGraphRunner* task_graph_runner) override { |
| 2328 task_runner_ = make_scoped_refptr(new SynchronousSimpleTaskRunner); |
| 2329 return base::MakeUnique<FakeLayerTreeHostImpl>( |
| 2330 settings, task_runner_provider, task_graph_runner, task_runner_); |
| 2331 } |
| 2332 |
| 2333 std::unique_ptr<TaskGraphRunner> CreateTaskGraphRunner() override { |
| 2334 return base::MakeUnique<SynchronousTaskGraphRunner>(); |
| 2335 } |
| 2336 |
| 2337 SynchronousSimpleTaskRunner* image_worker_task_runner() const { |
| 2338 return task_runner_.get(); |
| 2339 } |
| 2340 |
| 2341 private: |
| 2342 scoped_refptr<SynchronousSimpleTaskRunner> task_runner_; |
| 2343 }; |
| 2344 |
| 2345 TEST_F(CheckerImagingTileManagerTest, |
| 2346 NoImageDecodeDependencyForCheckeredTiles) { |
| 2347 const gfx::Size layer_bounds(512, 512); |
| 2348 SetupDefaultTrees(layer_bounds); |
| 2349 |
| 2350 std::unique_ptr<FakeRecordingSource> recording_source = |
| 2351 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
| 2352 recording_source->SetGenerateDiscardableImagesMetadata(true); |
| 2353 |
| 2354 sk_sp<SkImage> image = SkImage::MakeFromGenerator( |
| 2355 new testing::StrictMock<MockImageGenerator>(gfx::Size(512, 512))); |
| 2356 recording_source->add_draw_image(image, gfx::Point(0, 0)); |
| 2357 |
| 2358 recording_source->Rerecord(); |
| 2359 scoped_refptr<RasterSource> raster_source = |
| 2360 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
| 2361 |
| 2362 std::unique_ptr<PictureLayerImpl> layer_impl = PictureLayerImpl::Create( |
| 2363 host_impl()->active_tree(), 1, Layer::LayerMaskType::NOT_MASK); |
| 2364 layer_impl->set_is_drawn_render_surface_layer_list_member(true); |
| 2365 PictureLayerTilingSet* tiling_set = layer_impl->picture_layer_tiling_set(); |
| 2366 |
| 2367 PictureLayerTiling* tiling = tiling_set->AddTiling(1.0f, raster_source); |
| 2368 tiling->set_resolution(HIGH_RESOLUTION); |
| 2369 tiling->CreateAllTilesForTesting(); |
| 2370 tiling->SetTilePriorityRectsForTesting( |
| 2371 gfx::Rect(layer_bounds), // Visible rect. |
| 2372 gfx::Rect(layer_bounds), // Skewport rect. |
| 2373 gfx::Rect(layer_bounds), // Soon rect. |
| 2374 gfx::Rect(layer_bounds)); // Eventually rect. |
| 2375 |
| 2376 // PrepareTiles and synchronously run all tasks added to the TaskGraph. Since |
| 2377 // we are using a strict mock for the SkImageGenerator, if the decode runs as |
| 2378 // a part of raster tasks, the test should fail. |
| 2379 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 2380 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); |
| 2381 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner())->RunUntilIdle(); |
| 2382 base::RunLoop().RunUntilIdle(); |
| 2383 EXPECT_FALSE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); |
| 2384 } |
| 2385 |
2266 } // namespace | 2386 } // namespace |
2267 } // namespace cc | 2387 } // namespace cc |
OLD | NEW |