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