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" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/test/test_message_loop.h" | 11 #include "base/test/test_message_loop.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/output_surface_frame.h" |
14 #include "cc/scheduler/begin_frame_source.h" | 14 #include "cc/scheduler/begin_frame_source.h" |
15 #include "cc/scheduler/delay_based_time_source.h" | 15 #include "cc/scheduler/delay_based_time_source.h" |
16 #include "cc/test/fake_output_surface_client.h" | 16 #include "cc/test/fake_output_surface_client.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
19 #include "ui/compositor/test/context_factories_for_test.h" | 19 #include "ui/compositor/test/context_factories_for_test.h" |
20 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 protected: | 78 protected: |
79 std::unique_ptr<content::BrowserCompositorOutputSurface> output_surface_; | 79 std::unique_ptr<content::BrowserCompositorOutputSurface> output_surface_; |
80 | 80 |
81 // TODO(crbug.com/616973): We shouldn't be using ThreadTaskRunnerHandle::Get() | 81 // TODO(crbug.com/616973): We shouldn't be using ThreadTaskRunnerHandle::Get() |
82 // inside the OutputSurface, so we shouldn't need a MessageLoop. The | 82 // inside the OutputSurface, so we shouldn't need a MessageLoop. The |
83 // OutputSurface should be using the TaskRunner given to the compositor. | 83 // OutputSurface should be using the TaskRunner given to the compositor. |
84 base::TestMessageLoop message_loop_; | 84 base::TestMessageLoop message_loop_; |
85 cc::DelayBasedBeginFrameSource begin_frame_source_; | 85 cc::DelayBasedBeginFrameSource begin_frame_source_; |
86 std::unique_ptr<ui::Compositor> compositor_; | 86 std::unique_ptr<ui::Compositor> compositor_; |
87 | 87 |
| 88 private: |
88 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest); | 89 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest); |
89 }; | 90 }; |
90 | 91 |
91 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { | 92 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { |
92 bool enable_pixel_output = false; | 93 bool enable_pixel_output = false; |
93 ui::ContextFactory* context_factory = | 94 ui::ContextFactory* context_factory = |
94 ui::InitializeContextFactoryForTests(enable_pixel_output); | 95 ui::InitializeContextFactoryForTests(enable_pixel_output); |
95 | 96 |
96 compositor_.reset( | 97 compositor_.reset( |
97 new ui::Compositor(context_factory, message_loop_.task_runner().get())); | 98 new ui::Compositor(context_factory, message_loop_.task_runner().get())); |
(...skipping 13 matching lines...) Expand all Loading... |
111 std::move(device), compositor_->vsync_manager(), &begin_frame_source_); | 112 std::move(device), compositor_->vsync_manager(), &begin_frame_source_); |
112 } | 113 } |
113 | 114 |
114 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { | 115 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { |
115 cc::FakeOutputSurfaceClient output_surface_client; | 116 cc::FakeOutputSurfaceClient output_surface_client; |
116 std::unique_ptr<cc::SoftwareOutputDevice> software_device( | 117 std::unique_ptr<cc::SoftwareOutputDevice> software_device( |
117 new cc::SoftwareOutputDevice()); | 118 new cc::SoftwareOutputDevice()); |
118 output_surface_ = CreateSurface(std::move(software_device)); | 119 output_surface_ = CreateSurface(std::move(software_device)); |
119 CHECK(output_surface_->BindToClient(&output_surface_client)); | 120 CHECK(output_surface_->BindToClient(&output_surface_client)); |
120 | 121 |
121 cc::CompositorFrame frame; | 122 output_surface_->SwapBuffers(cc::OutputSurfaceFrame()); |
122 output_surface_->SwapBuffers(std::move(frame)); | |
123 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider()); | 123 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider()); |
124 } | 124 } |
125 | 125 |
126 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) { | 126 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) { |
127 cc::FakeOutputSurfaceClient output_surface_client; | 127 cc::FakeOutputSurfaceClient output_surface_client; |
128 std::unique_ptr<cc::SoftwareOutputDevice> software_device( | 128 std::unique_ptr<cc::SoftwareOutputDevice> software_device( |
129 new FakeSoftwareOutputDevice()); | 129 new FakeSoftwareOutputDevice()); |
130 output_surface_ = CreateSurface(std::move(software_device)); | 130 output_surface_ = CreateSurface(std::move(software_device)); |
131 CHECK(output_surface_->BindToClient(&output_surface_client)); | 131 CHECK(output_surface_->BindToClient(&output_surface_client)); |
132 | 132 |
133 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( | 133 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( |
134 output_surface_->software_device()->GetVSyncProvider()); | 134 output_surface_->software_device()->GetVSyncProvider()); |
135 EXPECT_EQ(0, vsync_provider->call_count()); | 135 EXPECT_EQ(0, vsync_provider->call_count()); |
136 | 136 |
137 cc::CompositorFrame frame; | 137 output_surface_->SwapBuffers(cc::OutputSurfaceFrame()); |
138 output_surface_->SwapBuffers(std::move(frame)); | |
139 EXPECT_EQ(1, vsync_provider->call_count()); | 138 EXPECT_EQ(1, vsync_provider->call_count()); |
140 } | 139 } |
OLD | NEW |