Chromium Code Reviews| Index: gpu/ipc/service/direct_composition_surface_win_unittest.cc |
| diff --git a/gpu/ipc/service/direct_composition_surface_win_unittest.cc b/gpu/ipc/service/direct_composition_surface_win_unittest.cc |
| index 19a1d2c52bcc3044e4f9446fe009104dbc9ba77b..865e1c93714135484a1c32d5ed1ffe2e730b71df 100644 |
| --- a/gpu/ipc/service/direct_composition_surface_win_unittest.cc |
| +++ b/gpu/ipc/service/direct_composition_surface_win_unittest.cc |
| @@ -42,6 +42,21 @@ void RunPendingTasks(scoped_refptr<base::TaskRunner> task_runner) { |
| done.Wait(); |
| } |
| +void DestroySurface(scoped_refptr<DirectCompositionSurfaceWin> surface) { |
| + scoped_refptr<base::TaskRunner> task_runner = |
| + surface->GetWindowTaskRunnerForTesting(); |
| + DCHECK(surface->HasOneRef()); |
| + |
| + surface = nullptr; |
| + |
| + // Ensure that the ChildWindowWin posts the task to delete the thread to the |
| + // main loop before doing RunUntilIdle. Otherwise the child threads could |
| + // outlive the main thread. |
| + RunPendingTasks(task_runner); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| if (!gl::QueryDirectCompositionDevice( |
| gl::QueryD3D11DeviceObjectFromANGLE())) { |
| @@ -56,6 +71,7 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
|
sunnyps
2017/03/20 23:38:57
nit: surface1
|
| ui::GetHiddenWindow())); |
| EXPECT_TRUE(surface->Initialize()); |
| + surface->SetEnableDCLayers(true); |
| scoped_refptr<gl::GLContext> context = |
|
sunnyps
2017/03/20 23:38:57
nit: context1
|
| gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
| @@ -79,6 +95,7 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| EXPECT_TRUE(context->IsCurrent(surface.get())); |
| EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true)); |
| + EXPECT_TRUE(context->IsCurrent(surface.get())); |
| EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| EXPECT_TRUE(context->IsCurrent(surface.get())); |
| @@ -89,6 +106,7 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext( |
| nullptr, surface2.get(), gl::GLContextAttribs()); |
| + surface2->SetEnableDCLayers(true); |
| EXPECT_TRUE(context2->MakeCurrent(surface2.get())); |
| EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); |
| // The previous IDCompositionSurface should be suspended when another |
| @@ -99,24 +117,65 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| // It should be possible to switch back to the previous surface and |
| // unsuspend it. |
| EXPECT_TRUE(context->MakeCurrent(surface.get())); |
| - scoped_refptr<base::TaskRunner> task_runner1 = |
| - surface->GetWindowTaskRunnerForTesting(); |
| - scoped_refptr<base::TaskRunner> task_runner2 = |
| - surface2->GetWindowTaskRunnerForTesting(); |
| - |
| context2 = nullptr; |
| - surface2 = nullptr; |
| context = nullptr; |
| - surface = nullptr; |
| - // Ensure that the ChildWindowWin posts the task to delete the thread to the |
| - // main loop before doing RunUntilIdle. Otherwise the child threads could |
| - // outlive the main thread. |
| - RunPendingTasks(task_runner1); |
| - RunPendingTasks(task_runner2); |
| - |
| - base::RunLoop().RunUntilIdle(); |
| + DestroySurface(std::move(surface)); |
| + DestroySurface(std::move(surface2)); |
| } |
| +// Tests that switching using EnableDCLayers works. |
| +TEST(DirectCompositionSurfaceTest, DXGIDCLayerSwitch) { |
| + if (!gl::QueryDirectCompositionDevice( |
| + gl::QueryD3D11DeviceObjectFromANGLE())) { |
| + LOG(WARNING) |
| + << "GL implementation not using DirectComposition, skipping test."; |
| + return; |
| + } |
| + |
| + TestImageTransportSurfaceDelegate delegate; |
| + |
| + scoped_refptr<DirectCompositionSurfaceWin> surface( |
| + new DirectCompositionSurfaceWin(delegate.AsWeakPtr(), |
| + ui::GetHiddenWindow())); |
| + EXPECT_TRUE(surface->Initialize()); |
| + |
| + scoped_refptr<gl::GLContext> context = |
| + gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); |
| + EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true)); |
| + |
| + // First SetDrawRectangle must be full size of surface for DXGI |
| + // swapchain. |
| + EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| + EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| + |
| + // SetDrawRectangle can't be called again until swap. |
| + EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| + |
| + EXPECT_TRUE(context->MakeCurrent(surface.get())); |
| + EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); |
| + |
| + EXPECT_TRUE(context->IsCurrent(surface.get())); |
| + |
| + surface->SetEnableDCLayers(true); |
| + |
| + // Surface switched to use IDCompositionSurface, so must draw to |
| + // entire surface. |
| + EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| + EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| + EXPECT_TRUE(context->IsCurrent(surface.get())); |
| + |
| + surface->SetEnableDCLayers(false); |
| + |
| + EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); |
| + |
| + // Surface switched to use IDXGISwapChain, so must draw to entire |
| + // surface. |
|
sunnyps
2017/03/20 23:38:57
nit: should we expose swap_chain_ and check that i
|
| + EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50))); |
| + EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| + |
| + context = nullptr; |
| + DestroySurface(std::move(surface)); |
| +} |
| } // namespace |
| } // namespace gpu |