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