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