OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "gpu/ipc/service/direct_composition_surface_win.h" | 5 #include "gpu/ipc/service/direct_composition_surface_win.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/win/hidden_window.h" | 10 #include "ui/base/win/hidden_window.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 }; | 35 }; |
36 | 36 |
37 void RunPendingTasks(scoped_refptr<base::TaskRunner> task_runner) { | 37 void RunPendingTasks(scoped_refptr<base::TaskRunner> task_runner) { |
38 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 38 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
39 base::WaitableEvent::InitialState::NOT_SIGNALED); | 39 base::WaitableEvent::InitialState::NOT_SIGNALED); |
40 task_runner->PostTask(FROM_HERE, | 40 task_runner->PostTask(FROM_HERE, |
41 Bind(&base::WaitableEvent::Signal, Unretained(&done))); | 41 Bind(&base::WaitableEvent::Signal, Unretained(&done))); |
42 done.Wait(); | 42 done.Wait(); |
43 } | 43 } |
44 | 44 |
45 void DestroySurface(scoped_refptr<DirectCompositionSurfaceWin> surface) { | |
46 scoped_refptr<base::TaskRunner> task_runner = | |
47 surface->GetWindowTaskRunnerForTesting(); | |
48 DCHECK(surface->HasOneRef()); | |
49 | |
50 surface = nullptr; | |
51 | |
52 // Ensure that the ChildWindowWin posts the task to delete the thread to the | |
53 // main loop before doing RunUntilIdle. Otherwise the child threads could | |
54 // outlive the main thread. | |
55 RunPendingTasks(task_runner); | |
56 | |
57 base::RunLoop().RunUntilIdle(); | |
58 } | |
59 | |
45 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { | 60 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
46 if (!gl::QueryDirectCompositionDevice( | 61 if (!gl::QueryDirectCompositionDevice( |
47 gl::QueryD3D11DeviceObjectFromANGLE())) { | 62 gl::QueryD3D11DeviceObjectFromANGLE())) { |
48 LOG(WARNING) | 63 LOG(WARNING) |
49 << "GL implementation not using DirectComposition, skipping test."; | 64 << "GL implementation not using DirectComposition, skipping test."; |
50 return; | 65 return; |
51 } | 66 } |
52 | 67 |
53 TestImageTransportSurfaceDelegate delegate; | 68 TestImageTransportSurfaceDelegate delegate; |
54 | 69 |
55 scoped_refptr<DirectCompositionSurfaceWin> surface( | 70 scoped_refptr<DirectCompositionSurfaceWin> surface( |
56 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 71 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
sunnyps
2017/03/20 23:38:57
nit: surface1
| |
57 ui::GetHiddenWindow())); | 72 ui::GetHiddenWindow())); |
58 EXPECT_TRUE(surface->Initialize()); | 73 EXPECT_TRUE(surface->Initialize()); |
74 surface->SetEnableDCLayers(true); | |
59 | 75 |
60 scoped_refptr<gl::GLContext> context = | 76 scoped_refptr<gl::GLContext> context = |
sunnyps
2017/03/20 23:38:57
nit: context1
| |
61 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | 77 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
62 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | 78 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
63 | 79 |
64 // First SetDrawRectangle must be full size of surface. | 80 // First SetDrawRectangle must be full size of surface. |
65 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 81 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
66 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 82 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
67 | 83 |
68 // SetDrawRectangle can't be called again until swap. | 84 // SetDrawRectangle can't be called again until swap. |
69 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 85 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
70 | 86 |
71 EXPECT_TRUE(context->MakeCurrent(surface.get())); | 87 EXPECT_TRUE(context->MakeCurrent(surface.get())); |
72 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | 88 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); |
73 | 89 |
74 EXPECT_TRUE(context->IsCurrent(surface.get())); | 90 EXPECT_TRUE(context->IsCurrent(surface.get())); |
75 | 91 |
76 // SetDrawRectangle must be contained within surface. | 92 // SetDrawRectangle must be contained within surface. |
77 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); | 93 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); |
78 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 94 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
79 EXPECT_TRUE(context->IsCurrent(surface.get())); | 95 EXPECT_TRUE(context->IsCurrent(surface.get())); |
80 | 96 |
81 EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true)); | 97 EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true)); |
98 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
82 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 99 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
83 EXPECT_TRUE(context->IsCurrent(surface.get())); | 100 EXPECT_TRUE(context->IsCurrent(surface.get())); |
84 | 101 |
85 scoped_refptr<DirectCompositionSurfaceWin> surface2( | 102 scoped_refptr<DirectCompositionSurfaceWin> surface2( |
86 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 103 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
87 ui::GetHiddenWindow())); | 104 ui::GetHiddenWindow())); |
88 EXPECT_TRUE(surface2->Initialize()); | 105 EXPECT_TRUE(surface2->Initialize()); |
89 | 106 |
90 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( | 107 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( |
91 nullptr, surface2.get(), gl::GLContextAttribs()); | 108 nullptr, surface2.get(), gl::GLContextAttribs()); |
109 surface2->SetEnableDCLayers(true); | |
92 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); | 110 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); |
93 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); | 111 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); |
94 // The previous IDCompositionSurface should be suspended when another | 112 // The previous IDCompositionSurface should be suspended when another |
95 // surface is being drawn to. | 113 // surface is being drawn to. |
96 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 114 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
97 EXPECT_TRUE(context2->IsCurrent(surface2.get())); | 115 EXPECT_TRUE(context2->IsCurrent(surface2.get())); |
98 | 116 |
99 // It should be possible to switch back to the previous surface and | 117 // It should be possible to switch back to the previous surface and |
100 // unsuspend it. | 118 // unsuspend it. |
101 EXPECT_TRUE(context->MakeCurrent(surface.get())); | 119 EXPECT_TRUE(context->MakeCurrent(surface.get())); |
102 scoped_refptr<base::TaskRunner> task_runner1 = | 120 context2 = nullptr; |
103 surface->GetWindowTaskRunnerForTesting(); | 121 context = nullptr; |
104 scoped_refptr<base::TaskRunner> task_runner2 = | |
105 surface2->GetWindowTaskRunnerForTesting(); | |
106 | 122 |
107 context2 = nullptr; | 123 DestroySurface(std::move(surface)); |
108 surface2 = nullptr; | 124 DestroySurface(std::move(surface2)); |
109 context = nullptr; | |
110 surface = nullptr; | |
111 | |
112 // Ensure that the ChildWindowWin posts the task to delete the thread to the | |
113 // main loop before doing RunUntilIdle. Otherwise the child threads could | |
114 // outlive the main thread. | |
115 RunPendingTasks(task_runner1); | |
116 RunPendingTasks(task_runner2); | |
117 | |
118 base::RunLoop().RunUntilIdle(); | |
119 } | 125 } |
120 | 126 |
127 // Tests that switching using EnableDCLayers works. | |
128 TEST(DirectCompositionSurfaceTest, DXGIDCLayerSwitch) { | |
129 if (!gl::QueryDirectCompositionDevice( | |
130 gl::QueryD3D11DeviceObjectFromANGLE())) { | |
131 LOG(WARNING) | |
132 << "GL implementation not using DirectComposition, skipping test."; | |
133 return; | |
134 } | |
135 | |
136 TestImageTransportSurfaceDelegate delegate; | |
137 | |
138 scoped_refptr<DirectCompositionSurfaceWin> surface( | |
139 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | |
140 ui::GetHiddenWindow())); | |
141 EXPECT_TRUE(surface->Initialize()); | |
142 | |
143 scoped_refptr<gl::GLContext> context = | |
144 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | |
145 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | |
146 | |
147 // First SetDrawRectangle must be full size of surface for DXGI | |
148 // swapchain. | |
149 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | |
150 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
151 | |
152 // SetDrawRectangle can't be called again until swap. | |
153 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
154 | |
155 EXPECT_TRUE(context->MakeCurrent(surface.get())); | |
156 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
157 | |
158 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
159 | |
160 surface->SetEnableDCLayers(true); | |
161 | |
162 // Surface switched to use IDCompositionSurface, so must draw to | |
163 // entire surface. | |
164 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | |
165 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
166 EXPECT_TRUE(context->IsCurrent(surface.get())); | |
167 | |
168 surface->SetEnableDCLayers(false); | |
169 | |
170 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
171 | |
172 // Surface switched to use IDXGISwapChain, so must draw to entire | |
173 // surface. | |
sunnyps
2017/03/20 23:38:57
nit: should we expose swap_chain_ and check that i
| |
174 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | |
175 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
176 | |
177 context = nullptr; | |
178 DestroySurface(std::move(surface)); | |
179 } | |
121 } // namespace | 180 } // namespace |
122 } // namespace gpu | 181 } // namespace gpu |
OLD | NEW |