| 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 "base/test/null_task_runner.h" | 5 #include "base/test/null_task_runner.h" |
| 6 #include "cc/output/compositor_frame.h" | 6 #include "cc/output/compositor_frame.h" |
| 7 #include "cc/output/copy_output_result.h" | 7 #include "cc/output/copy_output_result.h" |
| 8 #include "cc/output/delegated_frame_data.h" | 8 #include "cc/output/delegated_frame_data.h" |
| 9 #include "cc/quads/render_pass.h" | 9 #include "cc/quads/render_pass.h" |
| 10 #include "cc/resources/shared_bitmap_manager.h" | 10 #include "cc/resources/shared_bitmap_manager.h" |
| 11 #include "cc/surfaces/display.h" | 11 #include "cc/surfaces/display.h" |
| 12 #include "cc/surfaces/display_client.h" | 12 #include "cc/surfaces/display_client.h" |
| 13 #include "cc/surfaces/surface.h" | 13 #include "cc/surfaces/surface.h" |
| 14 #include "cc/surfaces/surface_factory.h" | 14 #include "cc/surfaces/surface_factory.h" |
| 15 #include "cc/surfaces/surface_factory_client.h" | 15 #include "cc/surfaces/surface_factory_client.h" |
| 16 #include "cc/surfaces/surface_id_allocator.h" | 16 #include "cc/surfaces/surface_id_allocator.h" |
| 17 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
| 18 #include "cc/test/fake_output_surface.h" | 18 #include "cc/test/fake_output_surface.h" |
| 19 #include "cc/test/scheduler_test_common.h" | 19 #include "cc/test/scheduler_test_common.h" |
| 20 #include "cc/test/test_shared_bitmap_manager.h" | 20 #include "cc/test/test_shared_bitmap_manager.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using testing::AnyNumber; | 24 using testing::AnyNumber; |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 29 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { |
| 30 public: | 30 public: |
| 31 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {} |
| 32 |
| 31 void ReturnResources(const ReturnedResourceArray& resources) override {} | 33 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 34 |
| 35 void SetBeginFrameSource(SurfaceId surface_id, |
| 36 BeginFrameSource* begin_frame_source) override { |
| 37 begin_frame_source_ = begin_frame_source; |
| 38 } |
| 39 |
| 40 BeginFrameSource* begin_frame_source() { return begin_frame_source_; } |
| 41 |
| 42 private: |
| 43 BeginFrameSource* begin_frame_source_; |
| 32 }; | 44 }; |
| 33 | 45 |
| 34 class TestSoftwareOutputDevice : public SoftwareOutputDevice { | 46 class TestSoftwareOutputDevice : public SoftwareOutputDevice { |
| 35 public: | 47 public: |
| 36 TestSoftwareOutputDevice() {} | 48 TestSoftwareOutputDevice() {} |
| 37 | 49 |
| 38 gfx::Rect damage_rect() const { return damage_rect_; } | 50 gfx::Rect damage_rect() const { return damage_rect_; } |
| 39 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } | 51 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } |
| 40 }; | 52 }; |
| 41 | 53 |
| 42 class DisplayTest : public testing::Test { | 54 class DisplayTest : public testing::Test { |
| 43 public: | 55 public: |
| 44 DisplayTest() | 56 DisplayTest() |
| 45 : factory_(&manager_, &empty_client_), | 57 : factory_(&manager_, &surface_factory_client_), |
| 46 software_output_device_(nullptr), | 58 software_output_device_(nullptr), |
| 47 task_runner_(new base::NullTaskRunner) {} | 59 task_runner_(new base::NullTaskRunner) {} |
| 48 | 60 |
| 49 protected: | 61 protected: |
| 50 void SetUpContext(scoped_ptr<TestWebGraphicsContext3D> context) { | 62 void SetUpContext(scoped_ptr<TestWebGraphicsContext3D> context) { |
| 51 if (context) { | 63 if (context) { |
| 52 output_surface_ = FakeOutputSurface::Create3d( | 64 output_surface_ = FakeOutputSurface::Create3d( |
| 53 TestContextProvider::Create(context.Pass())); | 65 TestContextProvider::Create(context.Pass())); |
| 54 } else { | 66 } else { |
| 55 scoped_ptr<TestSoftwareOutputDevice> output_device( | 67 scoped_ptr<TestSoftwareOutputDevice> output_device( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 pass_list->swap(frame_data->render_pass_list); | 78 pass_list->swap(frame_data->render_pass_list); |
| 67 | 79 |
| 68 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 80 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 69 frame->delegated_frame_data = frame_data.Pass(); | 81 frame->delegated_frame_data = frame_data.Pass(); |
| 70 | 82 |
| 71 factory_.SubmitCompositorFrame(surface_id, frame.Pass(), | 83 factory_.SubmitCompositorFrame(surface_id, frame.Pass(), |
| 72 SurfaceFactory::DrawCallback()); | 84 SurfaceFactory::DrawCallback()); |
| 73 } | 85 } |
| 74 | 86 |
| 75 SurfaceManager manager_; | 87 SurfaceManager manager_; |
| 76 EmptySurfaceFactoryClient empty_client_; | 88 FakeSurfaceFactoryClient surface_factory_client_; |
| 77 SurfaceFactory factory_; | 89 SurfaceFactory factory_; |
| 78 TestSoftwareOutputDevice* software_output_device_; | 90 TestSoftwareOutputDevice* software_output_device_; |
| 79 scoped_ptr<FakeOutputSurface> output_surface_; | 91 scoped_ptr<FakeOutputSurface> output_surface_; |
| 80 FakeOutputSurface* output_surface_ptr_; | 92 FakeOutputSurface* output_surface_ptr_; |
| 81 FakeBeginFrameSource fake_begin_frame_source_; | 93 FakeBeginFrameSource fake_begin_frame_source_; |
| 82 scoped_refptr<base::NullTaskRunner> task_runner_; | 94 scoped_refptr<base::NullTaskRunner> task_runner_; |
| 83 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 95 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 84 }; | 96 }; |
| 85 | 97 |
| 86 class TestDisplayClient : public DisplayClient { | 98 class TestDisplayClient : public DisplayClient { |
| 87 public: | 99 public: |
| 88 TestDisplayClient() {} | 100 TestDisplayClient() {} |
| 89 ~TestDisplayClient() override {} | 101 ~TestDisplayClient() override {} |
| 90 | 102 |
| 91 void CommitVSyncParameters(base::TimeTicks timebase, | 103 void CommitVSyncParameters(base::TimeTicks timebase, |
| 92 base::TimeDelta interval) override {} | 104 base::TimeDelta interval) override {} |
| 93 void OutputSurfaceLost() override {} | 105 void OutputSurfaceLost() override {} |
| 94 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} | 106 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} |
| 95 }; | 107 }; |
| 96 | 108 |
| 97 class TestDisplayScheduler : public DisplayScheduler { | 109 class TestDisplayScheduler : public DisplayScheduler { |
| 98 public: | 110 public: |
| 99 TestDisplayScheduler(DisplaySchedulerClient* client, | 111 TestDisplayScheduler(DisplaySchedulerClient* client, |
| 100 BeginFrameSource* begin_frame_source, | 112 BeginFrameSource* begin_frame_source, |
| 101 base::NullTaskRunner* task_runner) | 113 base::NullTaskRunner* task_runner) |
| 102 : DisplayScheduler(client, begin_frame_source, task_runner, 1), | 114 : DisplayScheduler(client, begin_frame_source, task_runner, 1), |
| 103 damaged(false), | 115 damaged(false), |
| 104 display_resized_(false), | 116 display_resized_(false), |
| 105 has_new_root_surface(false), | 117 has_new_root_surface(false), |
| 106 swapped(false) {} | 118 swapped(false) { |
| 119 begin_frame_source_for_children_.reset(new FakeBeginFrameSource); |
| 120 } |
| 107 | 121 |
| 108 ~TestDisplayScheduler() override {} | 122 ~TestDisplayScheduler() override {} |
| 109 | 123 |
| 110 void DisplayResized() override { display_resized_ = true; } | 124 void DisplayResized() override { display_resized_ = true; } |
| 111 | 125 |
| 112 void SetNewRootSurface(SurfaceId root_surface_id) override { | 126 void SetNewRootSurface(SurfaceId root_surface_id) override { |
| 113 has_new_root_surface = true; | 127 has_new_root_surface = true; |
| 114 } | 128 } |
| 115 | 129 |
| 116 void SurfaceDamaged(SurfaceId surface_id) override { | 130 void SurfaceDamaged(SurfaceId surface_id) override { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 bool damaged; | 143 bool damaged; |
| 130 bool display_resized_; | 144 bool display_resized_; |
| 131 bool has_new_root_surface; | 145 bool has_new_root_surface; |
| 132 bool swapped; | 146 bool swapped; |
| 133 }; | 147 }; |
| 134 | 148 |
| 135 void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) { | 149 void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) { |
| 136 *called = true; | 150 *called = true; |
| 137 } | 151 } |
| 138 | 152 |
| 153 // Verify Display responds to SurfaceAggregatorClient methods properly. |
| 154 TEST_F(DisplayTest, DisplayAsSurfaceAggregatorClient) { |
| 155 SetUpContext(nullptr); |
| 156 TestDisplayClient client; |
| 157 RendererSettings settings; |
| 158 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, |
| 159 settings); |
| 160 |
| 161 TestDisplayScheduler scheduler(&display, &fake_begin_frame_source_, |
| 162 task_runner_.get()); |
| 163 display.Initialize(output_surface_.Pass(), &scheduler); |
| 164 |
| 165 SurfaceId surface_id(6); |
| 166 factory_.Create(surface_id); |
| 167 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 168 |
| 169 EXPECT_EQ(nullptr, surface_factory_client_.begin_frame_source()); |
| 170 display.AddSurface(surface); |
| 171 EXPECT_NE(nullptr, surface_factory_client_.begin_frame_source()); |
| 172 display.RemoveSurface(surface); |
| 173 EXPECT_EQ(nullptr, surface_factory_client_.begin_frame_source()); |
| 174 } |
| 175 |
| 139 // Check that frame is damaged and swapped only under correct conditions. | 176 // Check that frame is damaged and swapped only under correct conditions. |
| 140 TEST_F(DisplayTest, DisplayDamaged) { | 177 TEST_F(DisplayTest, DisplayDamaged) { |
| 141 SetUpContext(nullptr); | 178 SetUpContext(nullptr); |
| 142 TestDisplayClient client; | 179 TestDisplayClient client; |
| 143 RendererSettings settings; | 180 RendererSettings settings; |
| 144 settings.partial_swap_enabled = true; | 181 settings.partial_swap_enabled = true; |
| 145 settings.finish_rendering_on_resize = true; | 182 settings.finish_rendering_on_resize = true; |
| 146 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, | 183 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, |
| 147 settings); | 184 settings); |
| 148 | 185 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 469 |
| 433 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 470 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 434 display.Resize(gfx::Size(250, 250)); | 471 display.Resize(gfx::Size(250, 250)); |
| 435 testing::Mock::VerifyAndClearExpectations(context_ptr); | 472 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 436 | 473 |
| 437 factory_.Destroy(surface_id); | 474 factory_.Destroy(surface_id); |
| 438 } | 475 } |
| 439 | 476 |
| 440 } // namespace | 477 } // namespace |
| 441 } // namespace cc | 478 } // namespace cc |
| OLD | NEW |