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 "content/browser/compositor/reflector_impl.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
5 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
6 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
7 #include "build/build_config.h" | 10 #include "build/build_config.h" |
8 #include "cc/test/fake_output_surface_client.h" | 11 #include "cc/test/fake_output_surface_client.h" |
9 #include "cc/test/test_context_provider.h" | 12 #include "cc/test/test_context_provider.h" |
10 #include "cc/test/test_web_graphics_context_3d.h" | 13 #include "cc/test/test_web_graphics_context_3d.h" |
11 #include "content/browser/compositor/browser_compositor_output_surface.h" | 14 #include "content/browser/compositor/browser_compositor_output_surface.h" |
12 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 15 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
13 #include "content/browser/compositor/reflector_impl.h" | |
14 #include "content/browser/compositor/reflector_texture.h" | 16 #include "content/browser/compositor/reflector_texture.h" |
15 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 17 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/compositor/compositor.h" | 19 #include "ui/compositor/compositor.h" |
18 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
19 #include "ui/compositor/test/context_factories_for_test.h" | 21 #include "ui/compositor/test/context_factories_for_test.h" |
20 | 22 |
21 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
22 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_ozone.h" | 24 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_ozone.h" |
23 #include "ui/ozone/public/overlay_candidates_ozone.h" | 25 #include "ui/ozone/public/overlay_candidates_ozone.h" |
(...skipping 26 matching lines...) Expand all Loading... |
50 public: | 52 public: |
51 TestOverlayCandidatesOzone() {} | 53 TestOverlayCandidatesOzone() {} |
52 ~TestOverlayCandidatesOzone() override {} | 54 ~TestOverlayCandidatesOzone() override {} |
53 | 55 |
54 void CheckOverlaySupport(OverlaySurfaceCandidateList* surfaces) override { | 56 void CheckOverlaySupport(OverlaySurfaceCandidateList* surfaces) override { |
55 (*surfaces)[0].overlay_handled = true; | 57 (*surfaces)[0].overlay_handled = true; |
56 } | 58 } |
57 }; | 59 }; |
58 #endif // defined(USE_OZONE) | 60 #endif // defined(USE_OZONE) |
59 | 61 |
60 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | 62 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> |
61 CreateTestValidatorOzone() { | 63 CreateTestValidatorOzone() { |
62 #if defined(USE_OZONE) | 64 #if defined(USE_OZONE) |
63 return scoped_ptr<BrowserCompositorOverlayCandidateValidator>( | 65 return std::unique_ptr<BrowserCompositorOverlayCandidateValidator>( |
64 new BrowserCompositorOverlayCandidateValidatorOzone( | 66 new BrowserCompositorOverlayCandidateValidatorOzone( |
65 0, scoped_ptr<ui::OverlayCandidatesOzone>( | 67 0, std::unique_ptr<ui::OverlayCandidatesOzone>( |
66 new TestOverlayCandidatesOzone()))); | 68 new TestOverlayCandidatesOzone()))); |
67 #else | 69 #else |
68 return nullptr; | 70 return nullptr; |
69 #endif // defined(USE_OZONE) | 71 #endif // defined(USE_OZONE) |
70 } | 72 } |
71 | 73 |
72 class TestOutputSurface : public BrowserCompositorOutputSurface { | 74 class TestOutputSurface : public BrowserCompositorOutputSurface { |
73 public: | 75 public: |
74 TestOutputSurface( | 76 TestOutputSurface( |
75 const scoped_refptr<cc::ContextProvider>& context_provider, | 77 const scoped_refptr<cc::ContextProvider>& context_provider, |
(...skipping 26 matching lines...) Expand all Loading... |
102 } | 104 } |
103 | 105 |
104 #if defined(OS_MACOSX) | 106 #if defined(OS_MACOSX) |
105 void SetSurfaceSuspendedForRecycle(bool suspended) override {} | 107 void SetSurfaceSuspendedForRecycle(bool suspended) override {} |
106 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle() const override { | 108 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle() const override { |
107 return false; | 109 return false; |
108 } | 110 } |
109 #endif | 111 #endif |
110 | 112 |
111 private: | 113 private: |
112 scoped_ptr<ReflectorTexture> reflector_texture_; | 114 std::unique_ptr<ReflectorTexture> reflector_texture_; |
113 }; | 115 }; |
114 | 116 |
115 const gfx::Rect kSubRect(0, 0, 64, 64); | 117 const gfx::Rect kSubRect(0, 0, 64, 64); |
116 | 118 |
117 } // namespace | 119 } // namespace |
118 | 120 |
119 class ReflectorImplTest : public testing::Test { | 121 class ReflectorImplTest : public testing::Test { |
120 public: | 122 public: |
121 void SetUp() override { | 123 void SetUp() override { |
122 bool enable_pixel_output = false; | 124 bool enable_pixel_output = false; |
123 ui::ContextFactory* context_factory = | 125 ui::ContextFactory* context_factory = |
124 ui::InitializeContextFactoryForTests(enable_pixel_output); | 126 ui::InitializeContextFactoryForTests(enable_pixel_output); |
125 ImageTransportFactory::InitializeForUnitTests( | 127 ImageTransportFactory::InitializeForUnitTests( |
126 scoped_ptr<ImageTransportFactory>( | 128 std::unique_ptr<ImageTransportFactory>( |
127 new NoTransportImageTransportFactory)); | 129 new NoTransportImageTransportFactory)); |
128 message_loop_.reset(new base::MessageLoop()); | 130 message_loop_.reset(new base::MessageLoop()); |
129 task_runner_ = message_loop_->task_runner(); | 131 task_runner_ = message_loop_->task_runner(); |
130 compositor_task_runner_ = new FakeTaskRunner(); | 132 compositor_task_runner_ = new FakeTaskRunner(); |
131 compositor_.reset( | 133 compositor_.reset( |
132 new ui::Compositor(context_factory, compositor_task_runner_.get())); | 134 new ui::Compositor(context_factory, compositor_task_runner_.get())); |
133 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 135 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
134 context_provider_ = | 136 context_provider_ = |
135 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); | 137 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); |
136 output_surface_ = scoped_ptr<TestOutputSurface>( | 138 output_surface_ = std::unique_ptr<TestOutputSurface>( |
137 new TestOutputSurface(context_provider_, compositor_->vsync_manager())); | 139 new TestOutputSurface(context_provider_, compositor_->vsync_manager())); |
138 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 140 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
139 | 141 |
140 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 142 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
141 compositor_->SetRootLayer(root_layer_.get()); | 143 compositor_->SetRootLayer(root_layer_.get()); |
142 mirroring_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 144 mirroring_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
143 compositor_->root_layer()->Add(mirroring_layer_.get()); | 145 compositor_->root_layer()->Add(mirroring_layer_.get()); |
144 gfx::Size size = output_surface_->SurfaceSize(); | 146 gfx::Size size = output_surface_->SurfaceSize(); |
145 mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height())); | 147 mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height())); |
146 } | 148 } |
147 | 149 |
148 void SetUpReflector() { | 150 void SetUpReflector() { |
149 reflector_ = make_scoped_ptr( | 151 reflector_ = base::WrapUnique( |
150 new ReflectorImpl(compositor_.get(), mirroring_layer_.get())); | 152 new ReflectorImpl(compositor_.get(), mirroring_layer_.get())); |
151 reflector_->OnSourceSurfaceReady(output_surface_.get()); | 153 reflector_->OnSourceSurfaceReady(output_surface_.get()); |
152 } | 154 } |
153 | 155 |
154 void TearDown() override { | 156 void TearDown() override { |
155 if (reflector_) | 157 if (reflector_) |
156 reflector_->RemoveMirroringLayer(mirroring_layer_.get()); | 158 reflector_->RemoveMirroringLayer(mirroring_layer_.get()); |
157 cc::TextureMailbox mailbox; | 159 cc::TextureMailbox mailbox; |
158 scoped_ptr<cc::SingleReleaseCallback> release; | 160 std::unique_ptr<cc::SingleReleaseCallback> release; |
159 if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) { | 161 if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) { |
160 release->Run(gpu::SyncToken(), false); | 162 release->Run(gpu::SyncToken(), false); |
161 } | 163 } |
162 compositor_.reset(); | 164 compositor_.reset(); |
163 ui::TerminateContextFactoryForTests(); | 165 ui::TerminateContextFactoryForTests(); |
164 ImageTransportFactory::Terminate(); | 166 ImageTransportFactory::Terminate(); |
165 } | 167 } |
166 | 168 |
167 void UpdateTexture() { reflector_->OnSourcePostSubBuffer(kSubRect); } | 169 void UpdateTexture() { reflector_->OnSourcePostSubBuffer(kSubRect); } |
168 | 170 |
169 protected: | 171 protected: |
170 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 172 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
171 scoped_refptr<cc::ContextProvider> context_provider_; | 173 scoped_refptr<cc::ContextProvider> context_provider_; |
172 cc::FakeOutputSurfaceClient output_surface_client_; | 174 cc::FakeOutputSurfaceClient output_surface_client_; |
173 scoped_ptr<base::MessageLoop> message_loop_; | 175 std::unique_ptr<base::MessageLoop> message_loop_; |
174 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 176 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
175 scoped_ptr<ui::Compositor> compositor_; | 177 std::unique_ptr<ui::Compositor> compositor_; |
176 scoped_ptr<ui::Layer> root_layer_; | 178 std::unique_ptr<ui::Layer> root_layer_; |
177 scoped_ptr<ui::Layer> mirroring_layer_; | 179 std::unique_ptr<ui::Layer> mirroring_layer_; |
178 scoped_ptr<ReflectorImpl> reflector_; | 180 std::unique_ptr<ReflectorImpl> reflector_; |
179 scoped_ptr<TestOutputSurface> output_surface_; | 181 std::unique_ptr<TestOutputSurface> output_surface_; |
180 }; | 182 }; |
181 | 183 |
182 namespace { | 184 namespace { |
183 TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { | 185 TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { |
184 output_surface_->SetFlip(false); | 186 output_surface_->SetFlip(false); |
185 SetUpReflector(); | 187 SetUpReflector(); |
186 UpdateTexture(); | 188 UpdateTexture(); |
187 EXPECT_TRUE(mirroring_layer_->TextureFlipped()); | 189 EXPECT_TRUE(mirroring_layer_->TextureFlipped()); |
188 gfx::Rect expected_rect = | 190 gfx::Rect expected_rect = |
189 kSubRect + gfx::Vector2d(0, output_surface_->SurfaceSize().height()) - | 191 kSubRect + gfx::Vector2d(0, output_surface_->SurfaceSize().height()) - |
(...skipping 29 matching lines...) Expand all Loading... |
219 plane_2.plane_z_order = 1; | 221 plane_2.plane_z_order = 1; |
220 list.push_back(plane_1); | 222 list.push_back(plane_1); |
221 list.push_back(plane_2); | 223 list.push_back(plane_2); |
222 output_surface_->GetOverlayCandidateValidator()->CheckOverlaySupport(&list); | 224 output_surface_->GetOverlayCandidateValidator()->CheckOverlaySupport(&list); |
223 EXPECT_FALSE(list[0].overlay_handled); | 225 EXPECT_FALSE(list[0].overlay_handled); |
224 } | 226 } |
225 #endif // defined(USE_OZONE) | 227 #endif // defined(USE_OZONE) |
226 | 228 |
227 } // namespace | 229 } // namespace |
228 } // namespace content | 230 } // namespace content |
OLD | NEW |