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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Surface switched to use IDXGISwapChain, so must draw to entire | 206 // Surface switched to use IDXGISwapChain, so must draw to entire |
207 // surface. | 207 // surface. |
208 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); | 208 EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
209 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 209 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
210 EXPECT_TRUE(surface->swap_chain()); | 210 EXPECT_TRUE(surface->swap_chain()); |
211 | 211 |
212 context = nullptr; | 212 context = nullptr; |
213 DestroySurface(std::move(surface)); | 213 DestroySurface(std::move(surface)); |
214 } | 214 } |
215 | 215 |
| 216 // Ensure that the swapchain's alpha is correct. |
| 217 TEST(DirectCompositionSurfaceTest, SwitchAlpha) { |
| 218 if (!CheckIfDCSupported()) |
| 219 return; |
| 220 |
| 221 TestImageTransportSurfaceDelegate delegate; |
| 222 |
| 223 scoped_refptr<DirectCompositionSurfaceWin> surface( |
| 224 new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
| 225 ui::GetHiddenWindow())); |
| 226 EXPECT_TRUE(surface->Initialize()); |
| 227 |
| 228 scoped_refptr<gl::GLContext> context = |
| 229 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
| 230 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
| 231 EXPECT_FALSE(surface->swap_chain()); |
| 232 |
| 233 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 234 base::win::ScopedComPtr<IDXGISwapChain1> swap_chain = surface->swap_chain(); |
| 235 ASSERT_TRUE(swap_chain); |
| 236 DXGI_SWAP_CHAIN_DESC1 desc; |
| 237 swap_chain->GetDesc1(&desc); |
| 238 EXPECT_EQ(DXGI_ALPHA_MODE_PREMULTIPLIED, desc.AlphaMode); |
| 239 |
| 240 // Resize to the same parameters should have no effect. |
| 241 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
| 242 EXPECT_TRUE(surface->swap_chain()); |
| 243 |
| 244 EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, false)); |
| 245 EXPECT_FALSE(surface->swap_chain()); |
| 246 |
| 247 EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 248 |
| 249 swap_chain = surface->swap_chain(); |
| 250 ASSERT_TRUE(swap_chain); |
| 251 swap_chain->GetDesc1(&desc); |
| 252 EXPECT_EQ(DXGI_ALPHA_MODE_IGNORE, desc.AlphaMode); |
| 253 |
| 254 context = nullptr; |
| 255 DestroySurface(std::move(surface)); |
| 256 } |
| 257 |
216 COLORREF ReadBackWindowPixel(HWND window, const gfx::Point& point) { | 258 COLORREF ReadBackWindowPixel(HWND window, const gfx::Point& point) { |
217 base::win::ScopedCreateDC mem_hdc(::CreateCompatibleDC(nullptr)); | 259 base::win::ScopedCreateDC mem_hdc(::CreateCompatibleDC(nullptr)); |
218 void* bits = nullptr; | 260 void* bits = nullptr; |
219 BITMAPV4HEADER hdr; | 261 BITMAPV4HEADER hdr; |
220 gfx::CreateBitmapV4Header(point.x() + 1, point.y() + 1, &hdr); | 262 gfx::CreateBitmapV4Header(point.x() + 1, point.y() + 1, &hdr); |
221 DCHECK(mem_hdc.IsValid()); | 263 DCHECK(mem_hdc.IsValid()); |
222 base::win::ScopedBitmap bitmap( | 264 base::win::ScopedBitmap bitmap( |
223 ::CreateDIBSection(mem_hdc.Get(), reinterpret_cast<BITMAPINFO*>(&hdr), | 265 ::CreateDIBSection(mem_hdc.Get(), reinterpret_cast<BITMAPINFO*>(&hdr), |
224 DIB_RGB_COLORS, &bits, nullptr, 0)); | 266 DIB_RGB_COLORS, &bits, nullptr, 0)); |
225 DCHECK(bitmap.is_valid()); | 267 DCHECK(bitmap.is_valid()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) | 421 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) |
380 << std::hex << "Expected " << expected_color << " Actual " | 422 << std::hex << "Expected " << expected_color << " Actual " |
381 << actual_color; | 423 << actual_color; |
382 | 424 |
383 context = nullptr; | 425 context = nullptr; |
384 DestroySurface(std::move(surface_)); | 426 DestroySurface(std::move(surface_)); |
385 } | 427 } |
386 | 428 |
387 } // namespace | 429 } // namespace |
388 } // namespace gpu | 430 } // namespace gpu |
OLD | NEW |