Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Unified Diff: gpu/ipc/service/direct_composition_surface_win_unittest.cc

Issue 2743663006: Allow switching DirectCompositionSurfaceWin between drawing modes. (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/ipc/service/direct_composition_surface_win.cc ('k') | ui/gl/gl_surface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..862e1525bd58bc046dc165220d5ff1e9b75e7ead 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())) {
@@ -52,35 +67,37 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) {
TestImageTransportSurfaceDelegate delegate;
- scoped_refptr<DirectCompositionSurfaceWin> surface(
+ scoped_refptr<DirectCompositionSurfaceWin> surface1(
new DirectCompositionSurfaceWin(delegate.AsWeakPtr(),
ui::GetHiddenWindow()));
- EXPECT_TRUE(surface->Initialize());
+ EXPECT_TRUE(surface1->Initialize());
+ surface1->SetEnableDCLayers(true);
- scoped_refptr<gl::GLContext> context =
- gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs());
- EXPECT_TRUE(surface->Resize(gfx::Size(100, 100), 1.0, true));
+ scoped_refptr<gl::GLContext> context1 = gl::init::CreateGLContext(
+ nullptr, surface1.get(), gl::GLContextAttribs());
+ EXPECT_TRUE(surface1->Resize(gfx::Size(100, 100), 1.0, true));
// First SetDrawRectangle must be full size of surface.
- EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50)));
- EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
+ EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50)));
+ EXPECT_TRUE(surface1->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_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
- EXPECT_TRUE(context->MakeCurrent(surface.get()));
- EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
+ EXPECT_TRUE(context1->MakeCurrent(surface1.get()));
+ EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface1->SwapBuffers());
- EXPECT_TRUE(context->IsCurrent(surface.get()));
+ EXPECT_TRUE(context1->IsCurrent(surface1.get()));
// SetDrawRectangle must be contained within surface.
- EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 101, 101)));
- EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
- EXPECT_TRUE(context->IsCurrent(surface.get()));
+ EXPECT_FALSE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 101, 101)));
+ EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
+ EXPECT_TRUE(context1->IsCurrent(surface1.get()));
- EXPECT_TRUE(surface->Resize(gfx::Size(50, 50), 1.0, true));
- EXPECT_TRUE(surface->SetDrawRectangle(gfx::Rect(0, 0, 50, 50)));
- EXPECT_TRUE(context->IsCurrent(surface.get()));
+ EXPECT_TRUE(surface1->Resize(gfx::Size(50, 50), 1.0, true));
+ EXPECT_TRUE(context1->IsCurrent(surface1.get()));
+ EXPECT_TRUE(surface1->SetDrawRectangle(gfx::Rect(0, 0, 50, 50)));
+ EXPECT_TRUE(context1->IsCurrent(surface1.get()));
scoped_refptr<DirectCompositionSurfaceWin> surface2(
new DirectCompositionSurfaceWin(delegate.AsWeakPtr(),
@@ -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
@@ -98,25 +116,70 @@ TEST(DirectCompositionSurfaceTest, TestMakeCurrent) {
// It should be possible to switch back to the previous surface and
// unsuspend it.
+ EXPECT_TRUE(context1->MakeCurrent(surface1.get()));
+ context2 = nullptr;
+ context1 = nullptr;
+
+ DestroySurface(std::move(surface1));
+ 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));
+ EXPECT_FALSE(surface->swap_chain());
+
+ // 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)));
+ EXPECT_TRUE(surface->swap_chain());
+
+ // SetDrawRectangle can't be called again until swap.
+ EXPECT_FALSE(surface->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
+
EXPECT_TRUE(context->MakeCurrent(surface.get()));
- scoped_refptr<base::TaskRunner> task_runner1 =
- surface->GetWindowTaskRunnerForTesting();
- scoped_refptr<base::TaskRunner> task_runner2 =
- surface2->GetWindowTaskRunnerForTesting();
+ EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
- context2 = nullptr;
- surface2 = nullptr;
- context = nullptr;
- surface = nullptr;
+ EXPECT_TRUE(context->IsCurrent(surface.get()));
- // 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);
+ surface->SetEnableDCLayers(true);
- base::RunLoop().RunUntilIdle();
-}
+ // 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()));
+ EXPECT_FALSE(surface->swap_chain());
+
+ surface->SetEnableDCLayers(false);
+ EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
+
+ // Surface switched to use IDXGISwapChain, 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(surface->swap_chain());
+
+ context = nullptr;
+ DestroySurface(std::move(surface));
+}
} // namespace
} // namespace gpu
« no previous file with comments | « gpu/ipc/service/direct_composition_surface_win.cc ('k') | ui/gl/gl_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698