| 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "cc/test/fake_output_surface_client.h" | 8 #include "cc/test/fake_output_surface_client.h" |
| 9 #include "cc/test/test_context_provider.h" | 9 #include "cc/test/test_context_provider.h" |
| 10 #include "cc/test/test_web_graphics_context_3d.h" | 10 #include "cc/test/test_web_graphics_context_3d.h" |
| 11 #include "content/browser/compositor/browser_compositor_output_surface.h" | 11 #include "content/browser/compositor/browser_compositor_output_surface.h" |
| 12 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 12 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
| 13 #include "content/browser/compositor/reflector_impl.h" | 13 #include "content/browser/compositor/reflector_impl.h" |
| 14 #include "content/browser/compositor/reflector_texture.h" |
| 14 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 15 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
| 17 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/test/context_factories_for_test.h" | 19 #include "ui/compositor/test/context_factories_for_test.h" |
| 19 | 20 |
| 20 #if defined(USE_OZONE) | 21 #if defined(USE_OZONE) |
| 21 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_ozone.h" | 22 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor_ozone.h" |
| 22 #include "ui/ozone/public/overlay_candidates_ozone.h" | 23 #include "ui/ozone/public/overlay_candidates_ozone.h" |
| 23 #endif // defined(USE_OZONE) | 24 #endif // defined(USE_OZONE) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const scoped_refptr<cc::ContextProvider>& context_provider, | 74 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 74 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager) | 75 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager) |
| 75 : BrowserCompositorOutputSurface(context_provider, | 76 : BrowserCompositorOutputSurface(context_provider, |
| 76 vsync_manager, | 77 vsync_manager, |
| 77 CreateTestValidatorOzone().Pass()) {} | 78 CreateTestValidatorOzone().Pass()) {} |
| 78 | 79 |
| 79 void SetFlip(bool flip) { capabilities_.flipped_output_surface = flip; } | 80 void SetFlip(bool flip) { capabilities_.flipped_output_surface = flip; } |
| 80 | 81 |
| 81 void SwapBuffers(cc::CompositorFrame* frame) override {} | 82 void SwapBuffers(cc::CompositorFrame* frame) override {} |
| 82 | 83 |
| 84 void OnReflectorChanged() override { |
| 85 if (!reflector_) { |
| 86 reflector_texture_.reset(); |
| 87 } else { |
| 88 reflector_texture_.reset(new ReflectorTexture(context_provider())); |
| 89 reflector_->OnSourceTextureMailboxUpdated(reflector_texture_->mailbox()); |
| 90 } |
| 91 } |
| 92 |
| 83 #if defined(OS_MACOSX) | 93 #if defined(OS_MACOSX) |
| 84 void OnSurfaceDisplayed() override {} | 94 void OnSurfaceDisplayed() override {} |
| 85 void SetSurfaceSuspendedForRecycle(bool suspended) override {} | 95 void SetSurfaceSuspendedForRecycle(bool suspended) override {} |
| 86 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle() const override { | 96 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle() const override { |
| 87 return false; | 97 return false; |
| 88 } | 98 } |
| 89 #endif | 99 #endif |
| 90 | 100 |
| 91 gfx::Size SurfaceSize() const override { return gfx::Size(256, 256); } | 101 gfx::Size SurfaceSize() const override { return gfx::Size(256, 256); } |
| 102 |
| 103 private: |
| 104 scoped_ptr<ReflectorTexture> reflector_texture_; |
| 92 }; | 105 }; |
| 93 | 106 |
| 94 const gfx::Rect kSubRect(0, 0, 64, 64); | 107 const gfx::Rect kSubRect(0, 0, 64, 64); |
| 95 | 108 |
| 96 } // namespace | 109 } // namespace |
| 97 | 110 |
| 98 class ReflectorImplTest : public testing::Test { | 111 class ReflectorImplTest : public testing::Test { |
| 99 public: | 112 public: |
| 100 void SetUp() override { | 113 void SetUp() override { |
| 101 bool enable_pixel_output = false; | 114 bool enable_pixel_output = false; |
| 102 ui::ContextFactory* context_factory = | 115 ui::ContextFactory* context_factory = |
| 103 ui::InitializeContextFactoryForTests(enable_pixel_output); | 116 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 104 ImageTransportFactory::InitializeForUnitTests( | 117 ImageTransportFactory::InitializeForUnitTests( |
| 105 scoped_ptr<ImageTransportFactory>( | 118 scoped_ptr<ImageTransportFactory>( |
| 106 new NoTransportImageTransportFactory)); | 119 new NoTransportImageTransportFactory)); |
| 107 message_loop_.reset(new base::MessageLoop()); | 120 message_loop_.reset(new base::MessageLoop()); |
| 108 proxy_ = message_loop_->message_loop_proxy(); | 121 proxy_ = message_loop_->message_loop_proxy(); |
| 109 compositor_task_runner_ = new FakeTaskRunner(); | 122 compositor_task_runner_ = new FakeTaskRunner(); |
| 110 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, | 123 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
| 111 context_factory, | 124 context_factory, |
| 112 compositor_task_runner_.get())); | 125 compositor_task_runner_.get())); |
| 113 context_provider_ = cc::TestContextProvider::Create( | 126 context_provider_ = cc::TestContextProvider::Create( |
| 114 cc::TestWebGraphicsContext3D::Create().Pass()); | 127 cc::TestWebGraphicsContext3D::Create().Pass()); |
| 115 output_surface_ = | 128 output_surface_ = |
| 116 scoped_ptr<TestOutputSurface>( | 129 scoped_ptr<TestOutputSurface>( |
| 117 new TestOutputSurface(context_provider_, | 130 new TestOutputSurface(context_provider_, |
| 118 compositor_->vsync_manager())).Pass(); | 131 compositor_->vsync_manager())).Pass(); |
| 119 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 132 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 120 | 133 |
| 134 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 135 compositor_->SetRootLayer(root_layer_.get()); |
| 121 mirroring_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 136 mirroring_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 137 compositor_->root_layer()->Add(mirroring_layer_.get()); |
| 122 gfx::Size size = output_surface_->SurfaceSize(); | 138 gfx::Size size = output_surface_->SurfaceSize(); |
| 123 mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height())); | 139 mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height())); |
| 124 } | 140 } |
| 125 | 141 |
| 126 void SetUpReflector() { | 142 void SetUpReflector() { |
| 127 reflector_ = make_scoped_ptr( | 143 reflector_ = make_scoped_ptr( |
| 128 new ReflectorImpl(compositor_.get(), mirroring_layer_.get())); | 144 new ReflectorImpl(compositor_.get(), mirroring_layer_.get())); |
| 129 reflector_->OnSourceSurfaceReady(output_surface_.get()); | 145 reflector_->OnSourceSurfaceReady(output_surface_.get()); |
| 130 } | 146 } |
| 131 | 147 |
| 132 void TearDown() override { | 148 void TearDown() override { |
| 149 if (reflector_) |
| 150 reflector_->RemoveMirroringLayer(mirroring_layer_.get()); |
| 133 cc::TextureMailbox mailbox; | 151 cc::TextureMailbox mailbox; |
| 134 scoped_ptr<cc::SingleReleaseCallback> release; | 152 scoped_ptr<cc::SingleReleaseCallback> release; |
| 135 if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) { | 153 if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) { |
| 136 release->Run(0, false); | 154 release->Run(0, false); |
| 137 } | 155 } |
| 138 compositor_.reset(); | 156 compositor_.reset(); |
| 139 ui::TerminateContextFactoryForTests(); | 157 ui::TerminateContextFactoryForTests(); |
| 140 ImageTransportFactory::Terminate(); | 158 ImageTransportFactory::Terminate(); |
| 141 } | 159 } |
| 142 | 160 |
| 143 void UpdateTexture() { reflector_->OnSourcePostSubBuffer(kSubRect); } | 161 void UpdateTexture() { reflector_->OnSourcePostSubBuffer(kSubRect); } |
| 144 | 162 |
| 145 protected: | 163 protected: |
| 146 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 147 scoped_refptr<cc::ContextProvider> context_provider_; | 165 scoped_refptr<cc::ContextProvider> context_provider_; |
| 148 cc::FakeOutputSurfaceClient output_surface_client_; | 166 cc::FakeOutputSurfaceClient output_surface_client_; |
| 149 scoped_ptr<base::MessageLoop> message_loop_; | 167 scoped_ptr<base::MessageLoop> message_loop_; |
| 150 scoped_refptr<base::MessageLoopProxy> proxy_; | 168 scoped_refptr<base::MessageLoopProxy> proxy_; |
| 151 scoped_ptr<ui::Compositor> compositor_; | 169 scoped_ptr<ui::Compositor> compositor_; |
| 170 scoped_ptr<ui::Layer> root_layer_; |
| 152 scoped_ptr<ui::Layer> mirroring_layer_; | 171 scoped_ptr<ui::Layer> mirroring_layer_; |
| 153 scoped_ptr<ReflectorImpl> reflector_; | 172 scoped_ptr<ReflectorImpl> reflector_; |
| 154 scoped_ptr<TestOutputSurface> output_surface_; | 173 scoped_ptr<TestOutputSurface> output_surface_; |
| 155 }; | 174 }; |
| 156 | 175 |
| 157 namespace { | 176 namespace { |
| 158 TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { | 177 TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { |
| 159 output_surface_->SetFlip(false); | 178 output_surface_->SetFlip(false); |
| 160 SetUpReflector(); | 179 SetUpReflector(); |
| 161 UpdateTexture(); | 180 UpdateTexture(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 plane_2.plane_z_order = 1; | 213 plane_2.plane_z_order = 1; |
| 195 list.push_back(plane_1); | 214 list.push_back(plane_1); |
| 196 list.push_back(plane_2); | 215 list.push_back(plane_2); |
| 197 output_surface_->GetOverlayCandidateValidator()->CheckOverlaySupport(&list); | 216 output_surface_->GetOverlayCandidateValidator()->CheckOverlaySupport(&list); |
| 198 EXPECT_FALSE(list[0].overlay_handled); | 217 EXPECT_FALSE(list[0].overlay_handled); |
| 199 } | 218 } |
| 200 #endif // defined(USE_OZONE) | 219 #endif // defined(USE_OZONE) |
| 201 | 220 |
| 202 } // namespace | 221 } // namespace |
| 203 } // namespace content | 222 } // namespace content |
| OLD | NEW |