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 "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 // Surface switched to use IDXGISwapChain, so must draw to entire | 205 // Surface switched to use IDXGISwapChain, so must draw to entire |
206 // surface. | 206 // surface. |
207 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 207 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
208 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 208 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
209 EXPECT_TRUE(surface->swap_chain()); | 209 EXPECT_TRUE(surface->swap_chain()); |
210 | 210 |
211 context = nullptr; | 211 context = nullptr; |
212 DestroySurface(std::move(surface)); | 212 DestroySurface(std::move(surface)); |
213 } | 213 } |
214 | 214 |
215 // Ensure that the swapchain's alpha is correct. | |
216 TEST(DirectCompositionSurfaceTest, SwitchAlpha) { | |
217 if (!CheckIfDCSupported()) | |
218 return; | |
219 | |
220 TestImageTransportSurfaceDelegate delegate; | |
221 | |
222 scoped_refptr<DirectCompositionSurfaceWin> surface( | |
223 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), | |
224 ui::GetHiddenWindow())); | |
225 EXPECT_TRUE(surface->Initialize()); | |
226 | |
227 scoped_refptr<gl::GLContext> context = | |
228 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); | |
229 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | |
230 EXPECT_FALSE(surface->swap_chain()); | |
231 | |
232 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
233 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain = surface->swap_chain(); | |
234 ASSERT_TRUE(swap_chain); | |
sunnyps
2017/03/28 23:33:29
nit: Why ASSERT instead of EXPECT here and below?
jbauman
2017/03/28 23:40:58
If it's null then swap_chain->GetDesc1 will crash,
| |
235 DXGI_SWAP_CHAIN_DESC1 desc; | |
236 swap_chain->GetDesc1(&desc); | |
237 EXPECT_EQ(DXGI_ALPHA_MODE_PREMULTIPLIED, desc.AlphaMode); | |
238 | |
239 // Resize to the same parameters should have no effect. | |
240 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); | |
241 EXPECT_TRUE(surface->swap_chain()); | |
242 | |
243 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, false)); | |
244 EXPECT_FALSE(surface->swap_chain()); | |
245 | |
246 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | |
247 | |
248 swap_chain = surface->swap_chain(); | |
249 ASSERT_TRUE(swap_chain); | |
250 swap_chain->GetDesc1(&desc); | |
251 EXPECT_EQ(DXGI_ALPHA_MODE_IGNORE, desc.AlphaMode); | |
252 | |
253 context = nullptr; | |
254 DestroySurface(std::move(surface)); | |
255 } | |
256 | |
215 SkBitmap ReadBackWindow(HWND window, const gfx::Rect& snapshot_bounds) { | 257 SkBitmap ReadBackWindow(HWND window, const gfx::Rect& snapshot_bounds) { |
216 std::unique_ptr<SkCanvas> canvas = skia::CreatePlatformCanvas( | 258 std::unique_ptr<SkCanvas> canvas = skia::CreatePlatformCanvas( |
217 snapshot_bounds.right(), snapshot_bounds.bottom(), false); | 259 snapshot_bounds.right(), snapshot_bounds.bottom(), false); |
218 HDC mem_hdc = skia::GetNativeDrawingContext(canvas.get()); | 260 HDC mem_hdc = skia::GetNativeDrawingContext(canvas.get()); |
219 | 261 |
220 // Grab a copy of the window. Use PrintWindow because it works even when the | 262 // Grab a copy of the window. Use PrintWindow because it works even when the |
221 // window's partially occluded. The PW_RENDERFULLCONTENT flag is undocumented, | 263 // window's partially occluded. The PW_RENDERFULLCONTENT flag is undocumented, |
222 // but works starting in Windows 8.1. It allows for capturing the contents of | 264 // but works starting in Windows 8.1. It allows for capturing the contents of |
223 // the window that are drawn using DirectComposition. | 265 // the window that are drawn using DirectComposition. |
224 UINT flags = PW_CLIENTONLY | PW_RENDERFULLCONTENT; | 266 UINT flags = PW_CLIENTONLY | PW_RENDERFULLCONTENT; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) | 409 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) |
368 << std::hex << "Expected " << expected_color << " Actual " | 410 << std::hex << "Expected " << expected_color << " Actual " |
369 << actual_color; | 411 << actual_color; |
370 | 412 |
371 context = nullptr; | 413 context = nullptr; |
372 DestroySurface(std::move(surface_)); | 414 DestroySurface(std::move(surface_)); |
373 } | 415 } |
374 | 416 |
375 } // namespace | 417 } // namespace |
376 } // namespace gpu | 418 } // namespace gpu |
OLD | NEW |