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

Unified Diff: third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp

Issue 2121933003: [SPv2] Paint accelerated canvases as foreign layers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add 'override' keyword to StubChromeClientForSPv2::didPaint Created 4 years, 5 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: third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp
diff --git a/third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp b/third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f80897dd062436fccbd543618ab2659efcea6a38
--- /dev/null
+++ b/third_party/WebKit/Source/core/paint/HTMLCanvasPainterTest.cpp
@@ -0,0 +1,98 @@
+// Copyright 2016 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 "core/paint/HTMLCanvasPainter.h"
+
+#include "core/frame/FrameView.h"
+#include "core/frame/Settings.h"
+#include "core/html/HTMLCanvasElement.h"
+#include "core/html/canvas/CanvasContextCreationAttributes.h"
+#include "core/html/canvas/CanvasRenderingContext.h"
+#include "core/loader/EmptyClients.h"
+#include "core/paint/StubChromeClientForSPv2.h"
+#include "core/testing/DummyPageHolder.h"
+#include "platform/graphics/Canvas2DImageBufferSurface.h"
+#include "platform/graphics/Canvas2DLayerBridge.h"
+#include "platform/graphics/test/FakeGLES2Interface.h"
+#include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h"
+#include "public/platform/WebLayer.h"
+#include "public/platform/WebSize.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Integration tests of canvas painting code (in SPv2 mode).
+
+namespace blink {
+
+class HTMLCanvasPainterTestForSPv2 : public ::testing::TestWithParam<WebLayerTreeViewImplForTesting::LayerListPolicy> {
+protected:
+ void SetUp() override
+ {
+ RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
+ m_chromeClient = new StubChromeClientForSPv2(GetParam());
+ Page::PageClients clients;
+ fillWithEmptyClients(clients);
+ clients.chromeClient = m_chromeClient.get();
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients, nullptr,
+ [](Settings& settings)
+ {
+ settings.setAcceleratedCompositingEnabled(true);
+ // LayoutHTMLCanvas doesn't exist if script is disabled.
+ settings.setScriptEnabled(true);
+ });
+ document().view()->setParentVisible(true);
+ document().view()->setSelfVisible(true);
+ }
+
+ void TearDown() override
+ {
+ m_featuresBackup.restore();
+ }
+
+ Document& document() { return m_pageHolder->document(); }
+ bool hasLayerAttached(const WebLayer& layer) { return m_chromeClient->hasLayer(layer); }
+
+ PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size)
+ {
+ return adoptRef(new Canvas2DLayerBridge(
+ wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)),
+ size, 0, NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting));
+ }
+
+private:
+ RuntimeEnabledFeatures::Backup m_featuresBackup;
+ Persistent<StubChromeClientForSPv2> m_chromeClient;
+ FakeGLES2Interface m_gl;
+ std::unique_ptr<DummyPageHolder> m_pageHolder;
+};
+
+INSTANTIATE_TEST_CASE_P(, HTMLCanvasPainterTestForSPv2, ::testing::Values(
+ WebLayerTreeViewImplForTesting::DontUseLayerLists,
+ WebLayerTreeViewImplForTesting::UseLayerLists));
+
+TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree)
+{
+ // Insert a <canvas> and force it into accelerated mode.
+ document().body()->setInnerHTML("<canvas width=300 height=200>", ASSERT_NO_EXCEPTION);
+ HTMLCanvasElement* element = toHTMLCanvasElement(document().body()->firstChild());
+ CanvasContextCreationAttributes attributes;
+ attributes.setAlpha(true);
+ CanvasRenderingContext* context = element->getCanvasRenderingContext("2d", attributes);
+ RefPtr<Canvas2DLayerBridge> bridge = makeCanvas2DLayerBridge(IntSize(300, 200));
+ element->createImageBufferUsingSurfaceForTesting(
+ wrapUnique(new Canvas2DImageBufferSurface(bridge, IntSize(300, 200))));
+ ASSERT_EQ(context, element->renderingContext());
+ ASSERT_TRUE(context->isAccelerated());
+
+ // Force the page to paint.
+ document().view()->updateAllLifecyclePhases();
+
+ // Fetch the layer associated with the <canvas>, and check that it was
+ // correctly configured in the layer tree.
+ const WebLayer* layer = context->platformLayer();
+ ASSERT_TRUE(layer);
+ EXPECT_TRUE(hasLayerAttached(*layer));
+ EXPECT_EQ(WebSize(300, 200), layer->bounds());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698