Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "cc/surfaces/surface.h" | 5 #include "cc/surfaces/surface.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "cc/output/copy_output_result.h" | |
| 7 #include "cc/surfaces/local_surface_id_allocator.h" | 8 #include "cc/surfaces/local_surface_id_allocator.h" |
| 8 #include "cc/surfaces/surface_dependency_tracker.h" | 9 #include "cc/surfaces/surface_dependency_tracker.h" |
| 9 #include "cc/surfaces/surface_factory.h" | 10 #include "cc/surfaces/surface_factory.h" |
| 10 #include "cc/surfaces/surface_factory_client.h" | 11 #include "cc/surfaces/surface_factory_client.h" |
| 11 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 12 #include "cc/test/begin_frame_args_test.h" | 13 #include "cc/test/begin_frame_args_test.h" |
| 13 #include "cc/test/fake_external_begin_frame_source.h" | 14 #include "cc/test/fake_external_begin_frame_source.h" |
| 14 #include "cc/test/scheduler_test_common.h" | 15 #include "cc/test/scheduler_test_common.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 55 |
| 55 TEST(SurfaceTest, SurfaceIds) { | 56 TEST(SurfaceTest, SurfaceIds) { |
| 56 for (size_t i = 0; i < 3; ++i) { | 57 for (size_t i = 0; i < 3; ++i) { |
| 57 LocalSurfaceIdAllocator allocator; | 58 LocalSurfaceIdAllocator allocator; |
| 58 LocalSurfaceId id1 = allocator.GenerateId(); | 59 LocalSurfaceId id1 = allocator.GenerateId(); |
| 59 LocalSurfaceId id2 = allocator.GenerateId(); | 60 LocalSurfaceId id2 = allocator.GenerateId(); |
| 60 EXPECT_NE(id1, id2); | 61 EXPECT_NE(id1, id2); |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 65 void TestCopyResultCallback(bool* called, | |
| 66 std::unique_ptr<CopyOutputResult> result) { | |
| 67 *called = true; | |
| 68 } | |
| 69 | |
| 70 // Test that CopyOutputRequests can outlive the current frame and be | |
| 71 // aggregated on the next frame. | |
| 72 TEST(SurfaceTest, CopyRequestLifetime) { | |
| 73 SurfaceManager manager; | |
| 74 FakeSurfaceFactoryClient surface_factory_client; | |
| 75 SurfaceFactory factory(kArbitraryFrameSinkId, &manager, | |
| 76 &surface_factory_client); | |
| 77 | |
| 78 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); | |
| 79 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); | |
| 80 CompositorFrame frame; | |
| 81 frame.render_pass_list.push_back(RenderPass::Create()); | |
| 82 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), | |
| 83 SurfaceFactory::DrawCallback()); | |
| 84 Surface* surface = manager.GetSurfaceForId(surface_id); | |
| 85 ASSERT_TRUE(!!surface); | |
| 86 | |
| 87 bool copy_called = false; | |
| 88 factory.RequestCopyOfSurface(CopyOutputRequest::CreateRequest( | |
| 89 base::Bind(&TestCopyResultCallback, ©_called))); | |
| 90 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); | |
| 91 EXPECT_FALSE(copy_called); | |
| 92 | |
| 93 CompositorFrame frame2; | |
| 94 frame2.render_pass_list.push_back(RenderPass::Create()); | |
| 95 frame2.render_pass_list.back()->id = 1; | |
| 96 frame2.render_pass_list.push_back(RenderPass::Create()); | |
| 97 frame2.render_pass_list.back()->id = 2; | |
| 98 factory.SubmitCompositorFrame(local_surface_id, std::move(frame2), | |
| 99 SurfaceFactory::DrawCallback()); | |
| 100 | |
| 101 // The copy request should stay on the Surface after a new frame is created. | |
| 102 EXPECT_FALSE(copy_called); | |
| 103 EXPECT_EQ( | |
| 104 1u, | |
| 105 surface->GetActiveFrame().render_pass_list.back()->copy_requests.size()); | |
|
danakj
2017/02/28 17:33:15
This is some serious pointer travelling, and I thi
| |
| 106 | |
| 107 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; | |
| 108 surface->TakeCopyOutputRequests(©_requests); | |
| 109 EXPECT_EQ(1u, copy_requests.size()); | |
| 110 // Last (root) pass should receive copy request. | |
| 111 ASSERT_EQ(1u, copy_requests.count(2)); | |
| 112 EXPECT_FALSE(copy_called); | |
| 113 copy_requests.find(2)->second->SendEmptyResult(); | |
| 114 EXPECT_TRUE(copy_called); | |
| 115 | |
| 116 factory.EvictSurface(); | |
| 117 } | |
| 118 | |
| 64 } // namespace | 119 } // namespace |
| 65 } // namespace cc | 120 } // namespace cc |
| OLD | NEW |