| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/display.h" | 5 #include "cc/surfaces/display.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/test/null_task_runner.h" | 9 #include "base/test/null_task_runner.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/copy_output_result.h" | 11 #include "cc/output/copy_output_result.h" |
| 12 #include "cc/output/delegated_frame_data.h" | 12 #include "cc/output/delegated_frame_data.h" |
| 13 #include "cc/output/texture_mailbox_deleter.h" | 13 #include "cc/output/texture_mailbox_deleter.h" |
| 14 #include "cc/quads/render_pass.h" | 14 #include "cc/quads/render_pass.h" |
| 15 #include "cc/resources/shared_bitmap_manager.h" | 15 #include "cc/resources/shared_bitmap_manager.h" |
| 16 #include "cc/scheduler/begin_frame_source.h" | 16 #include "cc/scheduler/begin_frame_source.h" |
| 17 #include "cc/surfaces/display_client.h" | 17 #include "cc/surfaces/display_client.h" |
| 18 #include "cc/surfaces/display_scheduler.h" | 18 #include "cc/surfaces/display_scheduler.h" |
| 19 #include "cc/surfaces/frame_sink_id.h" |
| 19 #include "cc/surfaces/surface.h" | 20 #include "cc/surfaces/surface.h" |
| 20 #include "cc/surfaces/surface_factory.h" | 21 #include "cc/surfaces/surface_factory.h" |
| 21 #include "cc/surfaces/surface_factory_client.h" | 22 #include "cc/surfaces/surface_factory_client.h" |
| 22 #include "cc/surfaces/surface_id_allocator.h" | 23 #include "cc/surfaces/surface_id_allocator.h" |
| 23 #include "cc/surfaces/surface_manager.h" | 24 #include "cc/surfaces/surface_manager.h" |
| 24 #include "cc/test/fake_output_surface.h" | 25 #include "cc/test/fake_output_surface.h" |
| 25 #include "cc/test/scheduler_test_common.h" | 26 #include "cc/test/scheduler_test_common.h" |
| 26 #include "cc/test/test_shared_bitmap_manager.h" | 27 #include "cc/test/test_shared_bitmap_manager.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using testing::AnyNumber; | 31 using testing::AnyNumber; |
| 31 | 32 |
| 32 namespace cc { | 33 namespace cc { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 36 static constexpr FrameSinkId kArbitraryFrameSinkId(3, 3); |
| 37 |
| 35 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { | 38 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { |
| 36 public: | 39 public: |
| 37 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {} | 40 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {} |
| 38 | 41 |
| 39 void ReturnResources(const ReturnedResourceArray& resources) override {} | 42 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 40 | 43 |
| 41 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { | 44 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { |
| 42 begin_frame_source_ = begin_frame_source; | 45 begin_frame_source_ = begin_frame_source; |
| 43 } | 46 } |
| 44 | 47 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 bool damaged; | 93 bool damaged; |
| 91 bool display_resized_; | 94 bool display_resized_; |
| 92 bool has_new_root_surface; | 95 bool has_new_root_surface; |
| 93 bool swapped; | 96 bool swapped; |
| 94 }; | 97 }; |
| 95 | 98 |
| 96 class DisplayTest : public testing::Test { | 99 class DisplayTest : public testing::Test { |
| 97 public: | 100 public: |
| 98 DisplayTest() | 101 DisplayTest() |
| 99 : factory_(&manager_, &surface_factory_client_), | 102 : factory_(&manager_, &surface_factory_client_), |
| 100 id_allocator_(kArbitraryClientId), | 103 id_allocator_(kArbitraryFrameSinkId), |
| 101 task_runner_(new base::NullTaskRunner) { | 104 task_runner_(new base::NullTaskRunner) { |
| 102 manager_.RegisterSurfaceClientId(id_allocator_.client_id()); | 105 manager_.RegisterFrameSinkId(id_allocator_.frame_sink_id()); |
| 103 } | 106 } |
| 104 | 107 |
| 105 ~DisplayTest() override { | 108 ~DisplayTest() override { |
| 106 manager_.InvalidateSurfaceClientId(id_allocator_.client_id()); | 109 manager_.InvalidateFrameSinkId(id_allocator_.frame_sink_id()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 void SetUpDisplay(const RendererSettings& settings, | 112 void SetUpDisplay(const RendererSettings& settings, |
| 110 std::unique_ptr<TestWebGraphicsContext3D> context) { | 113 std::unique_ptr<TestWebGraphicsContext3D> context) { |
| 111 std::unique_ptr<BeginFrameSource> begin_frame_source( | 114 std::unique_ptr<BeginFrameSource> begin_frame_source( |
| 112 new StubBeginFrameSource); | 115 new StubBeginFrameSource); |
| 113 | 116 |
| 114 std::unique_ptr<FakeOutputSurface> output_surface; | 117 std::unique_ptr<FakeOutputSurface> output_surface; |
| 115 if (context) { | 118 if (context) { |
| 116 output_surface = FakeOutputSurface::Create3d(std::move(context)); | 119 output_surface = FakeOutputSurface::Create3d(std::move(context)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 140 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 143 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 141 pass_list->swap(frame_data->render_pass_list); | 144 pass_list->swap(frame_data->render_pass_list); |
| 142 | 145 |
| 143 CompositorFrame frame; | 146 CompositorFrame frame; |
| 144 frame.delegated_frame_data = std::move(frame_data); | 147 frame.delegated_frame_data = std::move(frame_data); |
| 145 | 148 |
| 146 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 149 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 147 SurfaceFactory::DrawCallback()); | 150 SurfaceFactory::DrawCallback()); |
| 148 } | 151 } |
| 149 | 152 |
| 150 static constexpr int kArbitraryClientId = 3; | |
| 151 | |
| 152 SurfaceManager manager_; | 153 SurfaceManager manager_; |
| 153 FakeSurfaceFactoryClient surface_factory_client_; | 154 FakeSurfaceFactoryClient surface_factory_client_; |
| 154 SurfaceFactory factory_; | 155 SurfaceFactory factory_; |
| 155 SurfaceIdAllocator id_allocator_; | 156 SurfaceIdAllocator id_allocator_; |
| 156 scoped_refptr<base::NullTaskRunner> task_runner_; | 157 scoped_refptr<base::NullTaskRunner> task_runner_; |
| 157 TestSharedBitmapManager shared_bitmap_manager_; | 158 TestSharedBitmapManager shared_bitmap_manager_; |
| 158 std::unique_ptr<Display> display_; | 159 std::unique_ptr<Display> display_; |
| 159 TestSoftwareOutputDevice* software_output_device_ = nullptr; | 160 TestSoftwareOutputDevice* software_output_device_ = nullptr; |
| 160 FakeOutputSurface* output_surface_ = nullptr; | 161 FakeOutputSurface* output_surface_ = nullptr; |
| 161 TestDisplayScheduler* scheduler_ = nullptr; | 162 TestDisplayScheduler* scheduler_ = nullptr; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 } | 175 } |
| 175 | 176 |
| 176 // Check that frame is damaged and swapped only under correct conditions. | 177 // Check that frame is damaged and swapped only under correct conditions. |
| 177 TEST_F(DisplayTest, DisplayDamaged) { | 178 TEST_F(DisplayTest, DisplayDamaged) { |
| 178 RendererSettings settings; | 179 RendererSettings settings; |
| 179 settings.partial_swap_enabled = true; | 180 settings.partial_swap_enabled = true; |
| 180 settings.finish_rendering_on_resize = true; | 181 settings.finish_rendering_on_resize = true; |
| 181 SetUpDisplay(settings, nullptr); | 182 SetUpDisplay(settings, nullptr); |
| 182 | 183 |
| 183 StubDisplayClient client; | 184 StubDisplayClient client; |
| 184 display_->Initialize(&client, &manager_, id_allocator_.client_id()); | 185 display_->Initialize(&client, &manager_, id_allocator_.frame_sink_id()); |
| 185 | 186 |
| 186 SurfaceId surface_id(id_allocator_.GenerateId()); | 187 SurfaceId surface_id(id_allocator_.GenerateId()); |
| 187 EXPECT_FALSE(scheduler_->damaged); | 188 EXPECT_FALSE(scheduler_->damaged); |
| 188 EXPECT_FALSE(scheduler_->has_new_root_surface); | 189 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 189 display_->SetSurfaceId(surface_id, 1.f); | 190 display_->SetSurfaceId(surface_id, 1.f); |
| 190 EXPECT_FALSE(scheduler_->damaged); | 191 EXPECT_FALSE(scheduler_->damaged); |
| 191 EXPECT_FALSE(scheduler_->display_resized_); | 192 EXPECT_FALSE(scheduler_->display_resized_); |
| 192 EXPECT_TRUE(scheduler_->has_new_root_surface); | 193 EXPECT_TRUE(scheduler_->has_new_root_surface); |
| 193 | 194 |
| 194 scheduler_->ResetDamageForTest(); | 195 scheduler_->ResetDamageForTest(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 settings.partial_swap_enabled = true; | 438 settings.partial_swap_enabled = true; |
| 438 settings.finish_rendering_on_resize = true; | 439 settings.finish_rendering_on_resize = true; |
| 439 | 440 |
| 440 std::unique_ptr<MockedContext> context(new MockedContext()); | 441 std::unique_ptr<MockedContext> context(new MockedContext()); |
| 441 MockedContext* context_ptr = context.get(); | 442 MockedContext* context_ptr = context.get(); |
| 442 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 443 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 443 | 444 |
| 444 SetUpDisplay(settings, std::move(context)); | 445 SetUpDisplay(settings, std::move(context)); |
| 445 | 446 |
| 446 StubDisplayClient client; | 447 StubDisplayClient client; |
| 447 display_->Initialize(&client, &manager_, id_allocator_.client_id()); | 448 display_->Initialize(&client, &manager_, id_allocator_.frame_sink_id()); |
| 448 | 449 |
| 449 display_->SetSurfaceId(surface_id, 1.f); | 450 display_->SetSurfaceId(surface_id, 1.f); |
| 450 | 451 |
| 451 display_->Resize(gfx::Size(100, 100)); | 452 display_->Resize(gfx::Size(100, 100)); |
| 452 factory_.Create(surface_id); | 453 factory_.Create(surface_id); |
| 453 | 454 |
| 454 { | 455 { |
| 455 RenderPassList pass_list; | 456 RenderPassList pass_list; |
| 456 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 457 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 457 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 458 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 495 |
| 495 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 496 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 496 display_->Resize(gfx::Size(250, 250)); | 497 display_->Resize(gfx::Size(250, 250)); |
| 497 testing::Mock::VerifyAndClearExpectations(context_ptr); | 498 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 498 | 499 |
| 499 factory_.Destroy(surface_id); | 500 factory_.Destroy(surface_id); |
| 500 } | 501 } |
| 501 | 502 |
| 502 } // namespace | 503 } // namespace |
| 503 } // namespace cc | 504 } // namespace cc |
| OLD | NEW |