Chromium Code Reviews| 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 TestSimpleTaskRunner::PostDelayedTask(from_here, task, delay); | |
|
vmpstr
2017/02/13 22:49:31
return PostDelayedTask(from_here, task, delay);
Khushal
2017/02/14 05:10:23
Done.
| |
| 71 if (run_tasks_synchronously_) | |
| 72 RunUntilIdle(); | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 void set_run_tasks_synchronously(bool run_tasks_synchronously) { | |
| 77 run_tasks_synchronously_ = run_tasks_synchronously; | |
| 78 } | |
| 79 | |
| 80 protected: | |
| 81 ~SynchronousSimpleTaskRunner() override = default; | |
| 82 | |
| 83 bool run_tasks_synchronously_ = false; | |
| 84 }; | |
| 85 | |
| 52 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase { | 86 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase { |
| 53 public: | 87 public: |
| 54 LayerTreeSettings CreateSettings() override { | 88 LayerTreeSettings CreateSettings() override { |
| 55 LayerTreeSettingsForTesting settings; | 89 LayerTreeSettingsForTesting settings; |
| 56 settings.create_low_res_tiling = true; | 90 settings.create_low_res_tiling = true; |
| 57 settings.renderer_settings.buffer_to_texture_target_map = | 91 settings.renderer_settings.buffer_to_texture_target_map = |
| 58 DefaultBufferToTextureTargetMapForTesting(); | 92 DefaultBufferToTextureTargetMapForTesting(); |
| 59 return settings; | 93 return settings; |
| 60 } | 94 } |
| 61 | 95 |
| (...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2256 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 2290 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 2257 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate()) | 2291 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate()) |
| 2258 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); })); | 2292 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); })); |
| 2259 run_loop.Run(); | 2293 run_loop.Run(); |
| 2260 } | 2294 } |
| 2261 | 2295 |
| 2262 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); | 2296 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); |
| 2263 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); | 2297 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); |
| 2264 } | 2298 } |
| 2265 | 2299 |
| 2300 class CheckerImagingTileManagerTest : public TestLayerTreeHostBase { | |
|
vmpstr
2017/02/13 22:49:31
I feel like tile manager unittest is getting a bit
Khushal
2017/02/14 05:10:23
I can move it to a different file in this patch it
| |
| 2301 public: | |
| 2302 class MockImageGenerator : public SkImageGenerator { | |
| 2303 public: | |
| 2304 explicit MockImageGenerator(const gfx::Size& size) | |
| 2305 : SkImageGenerator( | |
| 2306 SkImageInfo::MakeN32Premul(size.width(), size.height())) {} | |
| 2307 | |
| 2308 protected: | |
| 2309 MOCK_METHOD5(onGetPixels, | |
| 2310 bool(const SkImageInfo&, void*, size_t, SkPMColor[], int*)); | |
| 2311 }; | |
| 2312 | |
| 2313 void TearDown() override { | |
| 2314 // Allow all tasks on the image worker to run now. Any scheduled decodes | |
| 2315 // will be aborted. | |
| 2316 task_runner()->set_run_tasks_synchronously(true); | |
| 2317 } | |
| 2318 | |
| 2319 LayerTreeSettings CreateSettings() override { | |
| 2320 LayerTreeSettings settings; | |
| 2321 settings.enable_checker_imaging = true; | |
| 2322 settings.renderer_settings.buffer_to_texture_target_map = | |
| 2323 DefaultBufferToTextureTargetMapForTesting(); | |
| 2324 return settings; | |
| 2325 } | |
| 2326 | |
| 2327 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( | |
| 2328 const LayerTreeSettings& settings, | |
| 2329 TaskRunnerProvider* task_runner_provider, | |
| 2330 TaskGraphRunner* task_graph_runner) override { | |
| 2331 task_runner_ = make_scoped_refptr(new SynchronousSimpleTaskRunner); | |
| 2332 return base::MakeUnique<FakeLayerTreeHostImpl>( | |
| 2333 settings, task_runner_provider, task_graph_runner, task_runner_); | |
| 2334 } | |
| 2335 | |
| 2336 std::unique_ptr<TaskGraphRunner> CreateTaskGraphRunner() override { | |
| 2337 return base::MakeUnique<SynchronousTaskGraphRunner>(); | |
| 2338 } | |
| 2339 | |
| 2340 SynchronousSimpleTaskRunner* task_runner() const { | |
| 2341 return task_runner_.get(); | |
| 2342 } | |
| 2343 | |
| 2344 private: | |
| 2345 scoped_refptr<SynchronousSimpleTaskRunner> task_runner_; | |
| 2346 }; | |
| 2347 | |
| 2348 TEST_F(CheckerImagingTileManagerTest, | |
| 2349 NoImageDecodeDependencyForCheckeredTiles) { | |
|
vmpstr
2017/02/13 22:49:31
Add a few more tests for things like repeated sche
Khushal
2017/02/14 05:10:23
Could you give an example? I think the only thing
| |
| 2350 const gfx::Size layer_bounds(512, 512); | |
| 2351 SetupDefaultTrees(layer_bounds); | |
| 2352 | |
| 2353 std::unique_ptr<FakeRecordingSource> recording_source = | |
| 2354 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
| 2355 recording_source->SetGenerateDiscardableImagesMetadata(true); | |
| 2356 | |
| 2357 sk_sp<SkImage> image = SkImage::MakeFromGenerator( | |
| 2358 new testing::StrictMock<MockImageGenerator>(gfx::Size(512, 512))); | |
| 2359 recording_source->add_draw_image(image, gfx::Point(0, 0)); | |
| 2360 | |
| 2361 recording_source->Rerecord(); | |
| 2362 scoped_refptr<RasterSource> raster_source = | |
| 2363 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | |
| 2364 | |
| 2365 std::unique_ptr<PictureLayerImpl> layer_impl = | |
| 2366 PictureLayerImpl::Create(host_impl()->active_tree(), 1, false); | |
| 2367 layer_impl->set_is_drawn_render_surface_layer_list_member(true); | |
| 2368 PictureLayerTilingSet* tiling_set = layer_impl->picture_layer_tiling_set(); | |
| 2369 | |
| 2370 PictureLayerTiling* tiling = tiling_set->AddTiling(1.0f, raster_source); | |
| 2371 tiling->set_resolution(HIGH_RESOLUTION); | |
| 2372 tiling->CreateAllTilesForTesting(); | |
| 2373 tiling->SetTilePriorityRectsForTesting( | |
| 2374 gfx::Rect(layer_bounds), // Visible rect. | |
| 2375 gfx::Rect(layer_bounds), // Skewport rect. | |
| 2376 gfx::Rect(layer_bounds), // Soon rect. | |
| 2377 gfx::Rect(layer_bounds)); // Eventually rect. | |
| 2378 | |
| 2379 // PrepareTiles and synchronously run all tasks added to the TaskGraph. Since | |
| 2380 // we are using a strict mock for the SkImageGenerator, if the decode runs as | |
| 2381 // a part of raster tasks, the test should fail. | |
| 2382 { | |
| 2383 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | |
| 2384 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); | |
| 2385 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner()) | |
| 2386 ->RunUntilIdle(); | |
| 2387 base::RunLoop().RunUntilIdle(); | |
| 2388 EXPECT_FALSE( | |
| 2389 host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); | |
| 2390 } | |
| 2391 } | |
| 2392 | |
| 2266 } // namespace | 2393 } // namespace |
| 2267 } // namespace cc | 2394 } // namespace cc |
| OLD | NEW |