OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/paint/HTMLCanvasPainter.h" |
| 6 |
| 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/Settings.h" |
| 9 #include "core/html/HTMLCanvasElement.h" |
| 10 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 11 #include "core/html/canvas/CanvasRenderingContext.h" |
| 12 #include "core/loader/EmptyClients.h" |
| 13 #include "core/paint/StubChromeClientForSPv2.h" |
| 14 #include "core/testing/DummyPageHolder.h" |
| 15 #include "platform/graphics/Canvas2DImageBufferSurface.h" |
| 16 #include "platform/graphics/Canvas2DLayerBridge.h" |
| 17 #include "platform/graphics/test/FakeGLES2Interface.h" |
| 18 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" |
| 19 #include "public/platform/WebLayer.h" |
| 20 #include "public/platform/WebSize.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 |
| 23 // Integration tests of canvas painting code (in SPv2 mode). |
| 24 |
| 25 namespace blink { |
| 26 |
| 27 class HTMLCanvasPainterTestForSPv2 : public ::testing::TestWithParam<WebLayerTre
eViewImplForTesting::LayerListPolicy> { |
| 28 protected: |
| 29 void SetUp() override |
| 30 { |
| 31 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
| 32 m_chromeClient = new StubChromeClientForSPv2(GetParam()); |
| 33 Page::PageClients clients; |
| 34 fillWithEmptyClients(clients); |
| 35 clients.chromeClient = m_chromeClient.get(); |
| 36 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients, null
ptr, |
| 37 [](Settings& settings) |
| 38 { |
| 39 settings.setAcceleratedCompositingEnabled(true); |
| 40 // LayoutHTMLCanvas doesn't exist if script is disabled. |
| 41 settings.setScriptEnabled(true); |
| 42 }); |
| 43 document().view()->setParentVisible(true); |
| 44 document().view()->setSelfVisible(true); |
| 45 } |
| 46 |
| 47 void TearDown() override |
| 48 { |
| 49 m_featuresBackup.restore(); |
| 50 } |
| 51 |
| 52 Document& document() { return m_pageHolder->document(); } |
| 53 bool hasLayerAttached(const WebLayer& layer) { return m_chromeClient->hasLay
er(layer); } |
| 54 |
| 55 PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size) |
| 56 { |
| 57 return adoptRef(new Canvas2DLayerBridge( |
| 58 wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)), |
| 59 size, 0, NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting
)); |
| 60 } |
| 61 |
| 62 private: |
| 63 RuntimeEnabledFeatures::Backup m_featuresBackup; |
| 64 Persistent<StubChromeClientForSPv2> m_chromeClient; |
| 65 FakeGLES2Interface m_gl; |
| 66 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 67 }; |
| 68 |
| 69 INSTANTIATE_TEST_CASE_P(, HTMLCanvasPainterTestForSPv2, ::testing::Values( |
| 70 WebLayerTreeViewImplForTesting::DontUseLayerLists, |
| 71 WebLayerTreeViewImplForTesting::UseLayerLists)); |
| 72 |
| 73 TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree) |
| 74 { |
| 75 // Insert a <canvas> and force it into accelerated mode. |
| 76 document().body()->setInnerHTML("<canvas width=300 height=200>", ASSERT_NO_E
XCEPTION); |
| 77 HTMLCanvasElement* element = toHTMLCanvasElement(document().body()->firstChi
ld()); |
| 78 CanvasContextCreationAttributes attributes; |
| 79 attributes.setAlpha(true); |
| 80 CanvasRenderingContext* context = element->getCanvasRenderingContext("2d", a
ttributes); |
| 81 RefPtr<Canvas2DLayerBridge> bridge = makeCanvas2DLayerBridge(IntSize(300, 20
0)); |
| 82 element->createImageBufferUsingSurfaceForTesting( |
| 83 wrapUnique(new Canvas2DImageBufferSurface(bridge, IntSize(300, 200)))); |
| 84 ASSERT_EQ(context, element->renderingContext()); |
| 85 ASSERT_TRUE(context->isAccelerated()); |
| 86 |
| 87 // Force the page to paint. |
| 88 document().view()->updateAllLifecyclePhases(); |
| 89 |
| 90 // Fetch the layer associated with the <canvas>, and check that it was |
| 91 // correctly configured in the layer tree. |
| 92 const WebLayer* layer = context->platformLayer(); |
| 93 ASSERT_TRUE(layer); |
| 94 EXPECT_TRUE(hasLayerAttached(*layer)); |
| 95 EXPECT_EQ(WebSize(300, 200), layer->bounds()); |
| 96 } |
| 97 |
| 98 } // namespace blink |
OLD | NEW |