| 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 "content/browser/compositor/software_browser_compositor_output_surface.
h" | 5 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/test/test_message_loop.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "cc/scheduler/delay_based_time_source.h" |
| 12 #include "cc/test/fake_output_surface_client.h" | 16 #include "cc/test/fake_output_surface_client.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
| 15 #include "ui/compositor/test/context_factories_for_test.h" | 19 #include "ui/compositor/test/context_factories_for_test.h" |
| 16 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 class FakeVSyncProvider : public gfx::VSyncProvider { | 24 class FakeVSyncProvider : public gfx::VSyncProvider { |
| 21 public: | 25 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 private: | 57 private: |
| 54 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; | 58 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; |
| 55 | 59 |
| 56 DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice); | 60 DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice); |
| 57 }; | 61 }; |
| 58 | 62 |
| 59 } // namespace | 63 } // namespace |
| 60 | 64 |
| 61 class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test { | 65 class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test { |
| 62 public: | 66 public: |
| 63 SoftwareBrowserCompositorOutputSurfaceTest(); | 67 SoftwareBrowserCompositorOutputSurfaceTest() |
| 64 ~SoftwareBrowserCompositorOutputSurfaceTest() override; | 68 : begin_frame_source_(base::MakeUnique<cc::DelayBasedTimeSource>( |
| 69 message_loop_.task_runner().get())) {} |
| 70 ~SoftwareBrowserCompositorOutputSurfaceTest() override = default; |
| 65 | 71 |
| 66 void SetUp() override; | 72 void SetUp() override; |
| 67 void TearDown() override; | 73 void TearDown() override; |
| 68 | 74 |
| 69 std::unique_ptr<content::BrowserCompositorOutputSurface> CreateSurface( | 75 std::unique_ptr<content::BrowserCompositorOutputSurface> CreateSurface( |
| 70 std::unique_ptr<cc::SoftwareOutputDevice> device); | 76 std::unique_ptr<cc::SoftwareOutputDevice> device); |
| 71 | 77 |
| 72 protected: | 78 protected: |
| 73 std::unique_ptr<content::BrowserCompositorOutputSurface> output_surface_; | 79 std::unique_ptr<content::BrowserCompositorOutputSurface> output_surface_; |
| 74 | 80 |
| 75 std::unique_ptr<base::MessageLoop> message_loop_; | 81 // TODO(crbug.com/616973): We shouldn't be using ThreadTaskRunnerHandle::Get() |
| 82 // inside the OutputSurface, so we shouldn't need a MessageLoop. The |
| 83 // OutputSurface should be using the TaskRunner given to the compositor. |
| 84 base::TestMessageLoop message_loop_; |
| 85 cc::DelayBasedBeginFrameSource begin_frame_source_; |
| 76 std::unique_ptr<ui::Compositor> compositor_; | 86 std::unique_ptr<ui::Compositor> compositor_; |
| 77 | 87 |
| 78 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest); | 88 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest); |
| 79 }; | 89 }; |
| 80 | 90 |
| 81 SoftwareBrowserCompositorOutputSurfaceTest:: | |
| 82 SoftwareBrowserCompositorOutputSurfaceTest() { | |
| 83 // |message_loop_| is not used, but the main thread still has to exist for the | |
| 84 // compositor to use. | |
| 85 message_loop_.reset(new base::MessageLoopForUI); | |
| 86 } | |
| 87 | |
| 88 SoftwareBrowserCompositorOutputSurfaceTest:: | |
| 89 ~SoftwareBrowserCompositorOutputSurfaceTest() {} | |
| 90 | |
| 91 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { | 91 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { |
| 92 bool enable_pixel_output = false; | 92 bool enable_pixel_output = false; |
| 93 ui::ContextFactory* context_factory = | 93 ui::ContextFactory* context_factory = |
| 94 ui::InitializeContextFactoryForTests(enable_pixel_output); | 94 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 95 | 95 |
| 96 compositor_.reset( | 96 compositor_.reset( |
| 97 new ui::Compositor(context_factory, base::ThreadTaskRunnerHandle::Get())); | 97 new ui::Compositor(context_factory, message_loop_.task_runner().get())); |
| 98 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 98 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() { | 101 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() { |
| 102 output_surface_.reset(); | 102 output_surface_.reset(); |
| 103 compositor_.reset(); | 103 compositor_.reset(); |
| 104 ui::TerminateContextFactoryForTests(); | 104 ui::TerminateContextFactoryForTests(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 std::unique_ptr<content::BrowserCompositorOutputSurface> | 107 std::unique_ptr<content::BrowserCompositorOutputSurface> |
| 108 SoftwareBrowserCompositorOutputSurfaceTest::CreateSurface( | 108 SoftwareBrowserCompositorOutputSurfaceTest::CreateSurface( |
| 109 std::unique_ptr<cc::SoftwareOutputDevice> device) { | 109 std::unique_ptr<cc::SoftwareOutputDevice> device) { |
| 110 return std::unique_ptr<content::BrowserCompositorOutputSurface>( | 110 return base::MakeUnique<content::SoftwareBrowserCompositorOutputSurface>( |
| 111 new content::SoftwareBrowserCompositorOutputSurface( | 111 std::move(device), compositor_->vsync_manager(), &begin_frame_source_); |
| 112 std::move(device), compositor_->vsync_manager(), | |
| 113 message_loop_->task_runner().get())); | |
| 114 } | 112 } |
| 115 | 113 |
| 116 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { | 114 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { |
| 117 cc::FakeOutputSurfaceClient output_surface_client; | 115 cc::FakeOutputSurfaceClient output_surface_client; |
| 118 std::unique_ptr<cc::SoftwareOutputDevice> software_device( | 116 std::unique_ptr<cc::SoftwareOutputDevice> software_device( |
| 119 new cc::SoftwareOutputDevice()); | 117 new cc::SoftwareOutputDevice()); |
| 120 output_surface_ = CreateSurface(std::move(software_device)); | 118 output_surface_ = CreateSurface(std::move(software_device)); |
| 121 CHECK(output_surface_->BindToClient(&output_surface_client)); | 119 CHECK(output_surface_->BindToClient(&output_surface_client)); |
| 122 | 120 |
| 123 cc::CompositorFrame frame; | 121 cc::CompositorFrame frame; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 137 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( | 135 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( |
| 138 output_surface_->software_device()->GetVSyncProvider()); | 136 output_surface_->software_device()->GetVSyncProvider()); |
| 139 EXPECT_EQ(0, vsync_provider->call_count()); | 137 EXPECT_EQ(0, vsync_provider->call_count()); |
| 140 | 138 |
| 141 cc::CompositorFrame frame; | 139 cc::CompositorFrame frame; |
| 142 output_surface_->SwapBuffers(&frame); | 140 output_surface_->SwapBuffers(&frame); |
| 143 | 141 |
| 144 EXPECT_EQ(1, output_surface_client.swap_count()); | 142 EXPECT_EQ(1, output_surface_client.swap_count()); |
| 145 EXPECT_EQ(1, vsync_provider->call_count()); | 143 EXPECT_EQ(1, vsync_provider->call_count()); |
| 146 } | 144 } |
| OLD | NEW |