OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/ipc/service/direct_composition_surface_win.h" |
| 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/base/win/hidden_window.h" |
| 10 #include "ui/gl/gl_angle_util_win.h" |
| 11 #include "ui/gl/gl_context.h" |
| 12 #include "ui/gl/init/gl_factory.h" |
| 13 |
| 14 namespace gpu { |
| 15 namespace { |
| 16 |
| 17 class TestImageTransportSurfaceDelegate |
| 18 : public ImageTransportSurfaceDelegate, |
| 19 public base::SupportsWeakPtr<TestImageTransportSurfaceDelegate> { |
| 20 public: |
| 21 ~TestImageTransportSurfaceDelegate() override {} |
| 22 |
| 23 // ImageTransportSurfaceDelegate implementation. |
| 24 void DidCreateAcceleratedSurfaceChildWindow( |
| 25 SurfaceHandle parent_window, |
| 26 SurfaceHandle child_window) override {} |
| 27 void DidSwapBuffersComplete(SwapBuffersCompleteParams params) override {} |
| 28 const gles2::FeatureInfo* GetFeatureInfo() const override { return nullptr; } |
| 29 void SetLatencyInfoCallback(const LatencyInfoCallback& callback) override {} |
| 30 void UpdateVSyncParameters(base::TimeTicks timebase, |
| 31 base::TimeDelta interval) override {} |
| 32 void AddFilter(IPC::MessageFilter* message_filter) override {} |
| 33 int32_t GetRouteID() const override { return 0; } |
| 34 }; |
| 35 |
| 36 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| 37 if (!gl::QueryDirectCompositionDevice( |
| 38 gl::QueryD3D11DeviceObjectFromANGLE())) { |
| 39 LOG(WARNING) |
| 40 << "GL implementation not using DirectComposition, skipping test."; |
| 41 return; |
| 42 } |
| 43 |
| 44 TestImageTransportSurfaceDelegate delegate; |
| 45 |
| 46 scoped_refptr<DirectCompositionSurfaceWin> surface( |
| 47 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
| 48 ui::GetHiddenWindow())); |
| 49 EXPECT_TRUE(surface->Initialize()); |
| 50 |
| 51 scoped_refptr<gl::GLContext> context = |
| 52 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
| 53 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
| 54 |
| 55 // First SetDrawRectangle must be full size of surface. |
| 56 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| 57 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 58 |
| 59 // SetDrawRectangle can't be called again until swap. |
| 60 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 61 |
| 62 EXPECT_TRUE(context->MakeCurrent(surface.get())); |
| 63 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); |
| 64 |
| 65 EXPECT_TRUE(context->IsCurrent(surface.get())); |
| 66 |
| 67 // SetDrawRectangle must be contained within surface. |
| 68 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); |
| 69 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 70 EXPECT_TRUE(context->IsCurrent(surface.get())); |
| 71 |
| 72 EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true)); |
| 73 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| 74 EXPECT_TRUE(context->IsCurrent(surface.get())); |
| 75 |
| 76 scoped_refptr<DirectCompositionSurfaceWin> surface2( |
| 77 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
| 78 ui::GetHiddenWindow())); |
| 79 EXPECT_TRUE(surface2->Initialize()); |
| 80 |
| 81 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( |
| 82 nullptr, surface2.get(), gl::GLContextAttribs()); |
| 83 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); |
| 84 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); |
| 85 // The previous IDCompositionSurface should be suspended when another |
| 86 // surface is being drawn to. |
| 87 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 88 EXPECT_TRUE(context2->IsCurrent(surface2.get())); |
| 89 |
| 90 // It should be possible to switch back to the previous surface and |
| 91 // unsuspend it. |
| 92 EXPECT_TRUE(context->MakeCurrent(surface.get())); |
| 93 |
| 94 context2 = nullptr; |
| 95 surface2 = nullptr; |
| 96 context = nullptr; |
| 97 surface = nullptr; |
| 98 base::RunLoop().RunUntilIdle(); |
| 99 } |
| 100 |
| 101 } // namespace |
| 102 } // namespace gpu |
OLD | NEW |