Chromium Code Reviews| 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 }; | |
| 33 | |
| 34 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { | |
| 35 if (!gl::QueryDirectCompositionDevice( | |
| 36 gl::QueryD3D11DeviceObjectFromANGLE())) { | |
| 37 LOG(ERROR) << "GL implementation not using DirectComposition"; | |
|
dcheng
2017/02/15 06:57:05
Or just FAIL() in a unit test (the return won't be
| |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 TestImageTransportSurfaceDelegate delegate; | |
| 42 | |
| 43 scoped_refptr<DirectCompositionSurfaceWin> surface( | |
| 44 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | |
| 45 ui::GetHiddenWindow())); | |
| 46 EXPECT_TRUE(surface->Initialize()); | |
| 47 | |
| 48 scoped_refptr<gl::GLContext> context = | |
| 49 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | |
| 50 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | |
| 51 | |
| 52 // First SetDrawRectangle must be full size of surface. | |
| 53 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | |
| 54 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
| 55 | |
| 56 // SetDrawRectangle can't be called again until swap. | |
| 57 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
| 58 | |
| 59 EXPECT_TRUE(context->MakeCurrent(surface.get())); | |
| 60 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
| 61 | |
| 62 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
| 63 | |
| 64 // SetDrawRectangle must be contained within surface. | |
| 65 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); | |
| 66 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
| 67 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
| 68 | |
| 69 EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true)); | |
| 70 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | |
| 71 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
| 72 | |
| 73 scoped_refptr<DirectCompositionSurfaceWin> surface2( | |
| 74 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | |
| 75 ui::GetHiddenWindow())); | |
| 76 EXPECT_TRUE(surface2->Initialize()); | |
| 77 | |
| 78 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( | |
| 79 nullptr, surface2.get(), gl::GLContextAttribs()); | |
| 80 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); | |
| 81 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); | |
| 82 // The previous IDCompositionSurface should be suspended when another | |
| 83 // surface is being drawn to. | |
| 84 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
| 85 EXPECT_TRUE(context2->IsCurrent(surface2.get())); | |
| 86 | |
| 87 // It should be possible to switch back to the previous surface and | |
| 88 // unsuspend it. | |
| 89 EXPECT_TRUE(context->MakeCurrent(surface.get())); | |
| 90 | |
| 91 context2 = nullptr; | |
| 92 surface2 = nullptr; | |
| 93 context = nullptr; | |
| 94 surface = nullptr; | |
| 95 base::RunLoop run_loop; | |
| 96 run_loop.RunUntilIdle(); | |
|
dcheng
2017/02/15 06:57:05
Or just base::RunLoop().RunUntilIdle() to save a l
| |
| 97 } | |
| 98 | |
| 99 } // namespace | |
| 100 } // namespace gpu | |
| OLD | NEW |