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

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

Issue 2646243002: Use IDCompositionSurface to implement DirectCompositionSurfaceWin. (Closed)
Patch Set: more changes Created 3 years, 11 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..f2122c5ca3398fa0162bba910d7206c08494287d
--- /dev/null
+++ b/gpu/ipc/service/direct_composition_surface_win_unittest.cc
@@ -0,0 +1,96 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/weak_ptr.h"
+#include "base/test/test_message_loop.h"
+#include "gpu/ipc/service/direct_composition_surface_win.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/win/hidden_window.h"
+#include "ui/gl/gl_angle_util_win.h"
+#include "ui/gl/gl_context.h"
+#include "ui/gl/init/gl_factory.h"
+
+namespace gpu {
+namespace {
+
+class TestImageTransportSurfaceDelegate
+ : public ImageTransportSurfaceDelegate,
+ public base::SupportsWeakPtr<TestImageTransportSurfaceDelegate> {
+ public:
+ ~TestImageTransportSurfaceDelegate() override {}
+
+ // ImageTransportSurfaceDelegate implementation.
+ void DidCreateAcceleratedSurfaceChildWindow(
+ SurfaceHandle parent_window,
+ SurfaceHandle child_window) override {}
+ void DidSwapBuffersComplete(SwapBuffersCompleteParams params) override {}
+ const gles2::FeatureInfo* GetFeatureInfo() const override { return nullptr; }
+ void SetLatencyInfoCallback(const LatencyInfoCallback& callback) override {}
+ void UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) override {}
+};
+
+using DirectCompositionSurfaceTest = testing::Test;
sunnyps 2017/01/28 01:33:59 nit: you can use TEST instead of TEST_F and not ha
+
+TEST_F(DirectCompositionSurfaceTest, TestMakeCurrent) {
+ if (!gl::QueryDirectCompositionDevice(
+ gl::QueryD3D11DeviceObjectFromANGLE())) {
+ LOG(ERROR) << "GL implementation not using DirectComposition";
+ return;
+ }
+
+ base::TestMessageLoop message_loop;
+ 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.
+ 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()));
+
+ // 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_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()));
+
+ scoped_refptr<DirectCompositionSurfaceWin> surface2(
+ new DirectCompositionSurfaceWin(delegate.AsWeakPtr(),
+ ui::GetHiddenWindow()));
+ EXPECT_TRUE(surface2->Initialize());
+
+ scoped_refptr<gl::GLContext> context2 = gl::init::CreateGLContext(
+ nullptr, surface2.get(), gl::GLContextAttribs());
+ 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
+ // surface is being drawn to.
+ EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100)));
+ EXPECT_TRUE(context2->IsCurrent(surface2.get()));
+
+ // It should be possible to switch back to the previous surface and
+ // unsuspend it.
+ EXPECT_TRUE(context->MakeCurrent(surface.get()));
+}
+
+} // namespace
+} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698