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 "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "base/win/scoped_gdi_object.h" | 10 #include "base/win/scoped_gdi_object.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return texture; | 123 return texture; |
124 } | 124 } |
125 | 125 |
126 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { | 126 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
127 if (!CheckIfDCSupported()) | 127 if (!CheckIfDCSupported()) |
128 return; | 128 return; |
129 | 129 |
130 TestImageTransportSurfaceDelegate delegate; | 130 TestImageTransportSurfaceDelegate delegate; |
131 | 131 |
132 scoped_refptr<DirectCompositionSurfaceWin> surface1( | 132 scoped_refptr<DirectCompositionSurfaceWin> surface1( |
133 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 133 new DirectCompositionSurfaceWin(nullptr, delegate.AsWeakPtr(), |
134 ui::GetHiddenWindow())); | 134 ui::GetHiddenWindow())); |
135 EXPECT_TRUE(surface1->Initialize()); | 135 EXPECT_TRUE(surface1->Initialize()); |
136 surface1->SetEnableDCLayers(true); | 136 surface1->SetEnableDCLayers(true); |
137 | 137 |
138 scoped_refptr<gl::GLContext> context1 = gl::init::CreateGLContext( | 138 scoped_refptr<gl::GLContext> context1 = gl::init::CreateGLContext( |
139 nullptr, surface1.get(), gl::GLContextAttribs()); | 139 nullptr, surface1.get(), gl::GLContextAttribs()); |
140 EXPECT_TRUE(surface1->Resize(gfx::Size(100, 100), 1.0, true)); | 140 EXPECT_TRUE(surface1->Resize(gfx::Size(100, 100), 1.0, true)); |
141 | 141 |
142 // First SetDrawRectangle must be full size of surface. | 142 // First SetDrawRectangle must be full size of surface. |
143 EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 143 EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
(...skipping 11 matching lines...) Expand all Loading... |
155 EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); | 155 EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 101, 101))); |
156 EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 156 EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
157 EXPECT_TRUE(context1->IsCurrent(surface1.get())); | 157 EXPECT_TRUE(context1->IsCurrent(surface1.get())); |
158 | 158 |
159 EXPECT_TRUE(surface1->Resize(gfx::Size(50, 50), 1.0, true)); | 159 EXPECT_TRUE(surface1->Resize(gfx::Size(50, 50), 1.0, true)); |
160 EXPECT_TRUE(context1->IsCurrent(surface1.get())); | 160 EXPECT_TRUE(context1->IsCurrent(surface1.get())); |
161 EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 161 EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
162 EXPECT_TRUE(context1->IsCurrent(surface1.get())); | 162 EXPECT_TRUE(context1->IsCurrent(surface1.get())); |
163 | 163 |
164 scoped_refptr<DirectCompositionSurfaceWin> surface2( | 164 scoped_refptr<DirectCompositionSurfaceWin> surface2( |
165 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 165 new DirectCompositionSurfaceWin(nullptr, delegate.AsWeakPtr(), |
166 ui::GetHiddenWindow())); | 166 ui::GetHiddenWindow())); |
167 EXPECT_TRUE(surface2->Initialize()); | 167 EXPECT_TRUE(surface2->Initialize()); |
168 | 168 |
169 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( | 169 scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( |
170 nullptr, surface2.get(), gl::GLContextAttribs()); | 170 nullptr, surface2.get(), gl::GLContextAttribs()); |
171 surface2->SetEnableDCLayers(true); | 171 surface2->SetEnableDCLayers(true); |
172 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); | 172 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); |
173 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); | 173 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); |
174 // The previous IDCompositionSurface should be suspended when another | 174 // The previous IDCompositionSurface should be suspended when another |
175 // surface is being drawn to. | 175 // surface is being drawn to. |
(...skipping 11 matching lines...) Expand all Loading... |
187 } | 187 } |
188 | 188 |
189 // Tests that switching using EnableDCLayers works. | 189 // Tests that switching using EnableDCLayers works. |
190 TEST(DirectCompositionSurfaceTest, DXGIDCLayerSwitch) { | 190 TEST(DirectCompositionSurfaceTest, DXGIDCLayerSwitch) { |
191 if (!CheckIfDCSupported()) | 191 if (!CheckIfDCSupported()) |
192 return; | 192 return; |
193 | 193 |
194 TestImageTransportSurfaceDelegate delegate; | 194 TestImageTransportSurfaceDelegate delegate; |
195 | 195 |
196 scoped_refptr<DirectCompositionSurfaceWin> surface( | 196 scoped_refptr<DirectCompositionSurfaceWin> surface( |
197 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 197 new DirectCompositionSurfaceWin(nullptr, delegate.AsWeakPtr(), |
198 ui::GetHiddenWindow())); | 198 ui::GetHiddenWindow())); |
199 EXPECT_TRUE(surface->Initialize()); | 199 EXPECT_TRUE(surface->Initialize()); |
200 | 200 |
201 scoped_refptr<gl::GLContext> context = | 201 scoped_refptr<gl::GLContext> context = |
202 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | 202 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
203 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | 203 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
204 EXPECT_FALSE(surface->swap_chain()); | 204 EXPECT_FALSE(surface->swap_chain()); |
205 | 205 |
206 // First SetDrawRectangle must be full size of surface for DXGI | 206 // First SetDrawRectangle must be full size of surface for DXGI |
207 // swapchain. | 207 // swapchain. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 241 } |
242 | 242 |
243 // Ensure that the swapchain's alpha is correct. | 243 // Ensure that the swapchain's alpha is correct. |
244 TEST(DirectCompositionSurfaceTest, SwitchAlpha) { | 244 TEST(DirectCompositionSurfaceTest, SwitchAlpha) { |
245 if (!CheckIfDCSupported()) | 245 if (!CheckIfDCSupported()) |
246 return; | 246 return; |
247 | 247 |
248 TestImageTransportSurfaceDelegate delegate; | 248 TestImageTransportSurfaceDelegate delegate; |
249 | 249 |
250 scoped_refptr<DirectCompositionSurfaceWin> surface( | 250 scoped_refptr<DirectCompositionSurfaceWin> surface( |
251 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 251 new DirectCompositionSurfaceWin(nullptr, delegate.AsWeakPtr(), |
252 ui::GetHiddenWindow())); | 252 ui::GetHiddenWindow())); |
253 EXPECT_TRUE(surface->Initialize()); | 253 EXPECT_TRUE(surface->Initialize()); |
254 | 254 |
255 scoped_refptr<gl::GLContext> context = | 255 scoped_refptr<gl::GLContext> context = |
256 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | 256 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
257 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | 257 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
258 EXPECT_FALSE(surface->swap_chain()); | 258 EXPECT_FALSE(surface->swap_chain()); |
259 | 259 |
260 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 260 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
261 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain = surface->swap_chain(); | 261 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain = surface->swap_chain(); |
(...skipping 20 matching lines...) Expand all Loading... |
282 DestroySurface(std::move(surface)); | 282 DestroySurface(std::move(surface)); |
283 } | 283 } |
284 | 284 |
285 // Ensure that the GLImage isn't presented again unless it changes. | 285 // Ensure that the GLImage isn't presented again unless it changes. |
286 TEST(DirectCompositionSurfaceTest, NoPresentTwice) { | 286 TEST(DirectCompositionSurfaceTest, NoPresentTwice) { |
287 if (!CheckIfDCSupported()) | 287 if (!CheckIfDCSupported()) |
288 return; | 288 return; |
289 | 289 |
290 TestImageTransportSurfaceDelegate delegate; | 290 TestImageTransportSurfaceDelegate delegate; |
291 scoped_refptr<DirectCompositionSurfaceWin> surface( | 291 scoped_refptr<DirectCompositionSurfaceWin> surface( |
292 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | 292 new DirectCompositionSurfaceWin(nullptr, delegate.AsWeakPtr(), |
293 ui::GetHiddenWindow())); | 293 ui::GetHiddenWindow())); |
294 EXPECT_TRUE(surface->Initialize()); | 294 EXPECT_TRUE(surface->Initialize()); |
295 surface->SetEnableDCLayers(true); | 295 surface->SetEnableDCLayers(true); |
296 gfx::Size window_size(100, 100); | 296 gfx::Size window_size(100, 100); |
297 | 297 |
298 scoped_refptr<gl::GLContext> context = | 298 scoped_refptr<gl::GLContext> context = |
299 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | 299 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
300 | 300 |
301 base::win::ScopedComPtr<ID3D11Device> d3d11_device = | 301 base::win::ScopedComPtr<ID3D11Device> d3d11_device = |
302 gl::QueryD3D11DeviceObjectFromANGLE(); | 302 gl::QueryD3D11DeviceObjectFromANGLE(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 class DirectCompositionPixelTest : public testing::Test { | 390 class DirectCompositionPixelTest : public testing::Test { |
391 public: | 391 public: |
392 DirectCompositionPixelTest() | 392 DirectCompositionPixelTest() |
393 : window_(&platform_delegate_, gfx::Rect(0, 0, 100, 100)) {} | 393 : window_(&platform_delegate_, gfx::Rect(0, 0, 100, 100)) {} |
394 | 394 |
395 protected: | 395 protected: |
396 void InitializeSurface() { | 396 void InitializeSurface() { |
397 static_cast<ui::PlatformWindow*>(&window_)->Show(); | 397 static_cast<ui::PlatformWindow*>(&window_)->Show(); |
398 | 398 |
399 surface_ = | 399 surface_ = new DirectCompositionSurfaceWin(nullptr, delegate_.AsWeakPtr(), |
400 new DirectCompositionSurfaceWin(delegate_.AsWeakPtr(), window_.hwnd()); | 400 window_.hwnd()); |
401 EXPECT_TRUE(surface_->Initialize()); | 401 EXPECT_TRUE(surface_->Initialize()); |
402 } | 402 } |
403 | 403 |
404 void PixelTestSwapChain(bool layers_enabled) { | 404 void PixelTestSwapChain(bool layers_enabled) { |
405 if (!CheckIfDCSupported()) | 405 if (!CheckIfDCSupported()) |
406 return; | 406 return; |
407 | 407 |
408 InitializeSurface(); | 408 InitializeSurface(); |
409 | 409 |
410 surface_->SetEnableDCLayers(layers_enabled); | 410 surface_->SetEnableDCLayers(layers_enabled); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) | 495 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) |
496 << std::hex << "Expected " << expected_color << " Actual " | 496 << std::hex << "Expected " << expected_color << " Actual " |
497 << actual_color; | 497 << actual_color; |
498 | 498 |
499 context = nullptr; | 499 context = nullptr; |
500 DestroySurface(std::move(surface_)); | 500 DestroySurface(std::move(surface_)); |
501 } | 501 } |
502 | 502 |
503 } // namespace | 503 } // namespace |
504 } // namespace gpu | 504 } // namespace gpu |
OLD | NEW |