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 "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
19 #include "public/platform/WebLayer.h" | 20 #include "public/platform/WebLayer.h" |
20 #include "public/platform/WebSize.h" | 21 #include "public/platform/WebSize.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 // Integration tests of canvas painting code (in SPv2 mode). | 24 // Integration tests of canvas painting code (in SPv2 mode). |
24 | 25 |
25 namespace blink { | 26 namespace blink { |
26 | 27 |
27 class HTMLCanvasPainterTestForSPv2 : public ::testing::Test, | 28 class HTMLCanvasPainterTestForSPv2 : public ::testing::Test, |
28 public testing::WithParamInterface<bool> { | 29 public testing::WithParamInterface<bool>, |
| 30 private ScopedSlimmingPaintV2ForTest, |
| 31 private ScopedRootLayerScrollingForTest { |
| 32 public: |
| 33 HTMLCanvasPainterTestForSPv2() |
| 34 : ScopedSlimmingPaintV2ForTest(true), |
| 35 ScopedRootLayerScrollingForTest(GetParam()) {} |
| 36 |
29 protected: | 37 protected: |
30 void SetUp() override { | 38 void SetUp() override { |
31 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
32 RuntimeEnabledFeatures::setRootLayerScrollingEnabled(GetParam()); | |
33 m_chromeClient = new StubChromeClientForSPv2(); | 39 m_chromeClient = new StubChromeClientForSPv2(); |
34 Page::PageClients clients; | 40 Page::PageClients clients; |
35 fillWithEmptyClients(clients); | 41 fillWithEmptyClients(clients); |
36 clients.chromeClient = m_chromeClient.get(); | 42 clients.chromeClient = m_chromeClient.get(); |
37 m_pageHolder = DummyPageHolder::create( | 43 m_pageHolder = DummyPageHolder::create( |
38 IntSize(800, 600), &clients, nullptr, [](Settings& settings) { | 44 IntSize(800, 600), &clients, nullptr, [](Settings& settings) { |
39 settings.setAcceleratedCompositingEnabled(true); | 45 settings.setAcceleratedCompositingEnabled(true); |
40 // LayoutHTMLCanvas doesn't exist if script is disabled. | 46 // LayoutHTMLCanvas doesn't exist if script is disabled. |
41 settings.setScriptEnabled(true); | 47 settings.setScriptEnabled(true); |
42 }); | 48 }); |
43 document().view()->setParentVisible(true); | 49 document().view()->setParentVisible(true); |
44 document().view()->setSelfVisible(true); | 50 document().view()->setSelfVisible(true); |
45 } | 51 } |
46 | 52 |
47 void TearDown() override { m_featuresBackup.restore(); } | |
48 | |
49 Document& document() { return m_pageHolder->document(); } | 53 Document& document() { return m_pageHolder->document(); } |
50 bool hasLayerAttached(const WebLayer& layer) { | 54 bool hasLayerAttached(const WebLayer& layer) { |
51 return m_chromeClient->hasLayer(layer); | 55 return m_chromeClient->hasLayer(layer); |
52 } | 56 } |
53 | 57 |
54 PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size) { | 58 PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size) { |
55 return adoptRef(new Canvas2DLayerBridge( | 59 return adoptRef(new Canvas2DLayerBridge( |
56 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)), size, 0, | 60 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)), size, 0, |
57 NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 61 NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
58 kN32_SkColorType)); | 62 kN32_SkColorType)); |
59 } | 63 } |
60 | 64 |
61 private: | 65 private: |
62 RuntimeEnabledFeatures::Backup m_featuresBackup; | |
63 Persistent<StubChromeClientForSPv2> m_chromeClient; | 66 Persistent<StubChromeClientForSPv2> m_chromeClient; |
64 FakeGLES2Interface m_gl; | 67 FakeGLES2Interface m_gl; |
65 std::unique_ptr<DummyPageHolder> m_pageHolder; | 68 std::unique_ptr<DummyPageHolder> m_pageHolder; |
66 }; | 69 }; |
67 | 70 |
68 INSTANTIATE_TEST_CASE_P(All, HTMLCanvasPainterTestForSPv2, ::testing::Bool()); | 71 INSTANTIATE_TEST_CASE_P(All, HTMLCanvasPainterTestForSPv2, ::testing::Bool()); |
69 | 72 |
70 TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree) { | 73 TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree) { |
71 // Insert a <canvas> and force it into accelerated mode. | 74 // Insert a <canvas> and force it into accelerated mode. |
72 document().body()->setInnerHTML("<canvas width=300 height=200>"); | 75 document().body()->setInnerHTML("<canvas width=300 height=200>"); |
(...skipping 15 matching lines...) Expand all Loading... |
88 | 91 |
89 // Fetch the layer associated with the <canvas>, and check that it was | 92 // Fetch the layer associated with the <canvas>, and check that it was |
90 // correctly configured in the layer tree. | 93 // correctly configured in the layer tree. |
91 const WebLayer* layer = context->platformLayer(); | 94 const WebLayer* layer = context->platformLayer(); |
92 ASSERT_TRUE(layer); | 95 ASSERT_TRUE(layer); |
93 EXPECT_TRUE(hasLayerAttached(*layer)); | 96 EXPECT_TRUE(hasLayerAttached(*layer)); |
94 EXPECT_EQ(WebSize(300, 200), layer->bounds()); | 97 EXPECT_EQ(WebSize(300, 200), layer->bounds()); |
95 } | 98 } |
96 | 99 |
97 } // namespace blink | 100 } // namespace blink |
OLD | NEW |