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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 void TearDown() override { m_featuresBackup.restore(); } | 47 void TearDown() override { m_featuresBackup.restore(); } |
48 | 48 |
49 Document& document() { return m_pageHolder->document(); } | 49 Document& document() { return m_pageHolder->document(); } |
50 bool hasLayerAttached(const WebLayer& layer) { | 50 bool hasLayerAttached(const WebLayer& layer) { |
51 return m_chromeClient->hasLayer(layer); | 51 return m_chromeClient->hasLayer(layer); |
52 } | 52 } |
53 | 53 |
54 PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size) { | 54 PassRefPtr<Canvas2DLayerBridge> makeCanvas2DLayerBridge(const IntSize& size) { |
55 return adoptRef(new Canvas2DLayerBridge( | 55 return adoptRef(new Canvas2DLayerBridge( |
56 wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)), size, 0, | 56 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&m_gl)), size, 0, |
57 NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 57 NonOpaque, Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
58 kN32_SkColorType)); | 58 kN32_SkColorType)); |
59 } | 59 } |
60 | 60 |
61 private: | 61 private: |
62 RuntimeEnabledFeatures::Backup m_featuresBackup; | 62 RuntimeEnabledFeatures::Backup m_featuresBackup; |
63 Persistent<StubChromeClientForSPv2> m_chromeClient; | 63 Persistent<StubChromeClientForSPv2> m_chromeClient; |
64 FakeGLES2Interface m_gl; | 64 FakeGLES2Interface m_gl; |
65 std::unique_ptr<DummyPageHolder> m_pageHolder; | 65 std::unique_ptr<DummyPageHolder> m_pageHolder; |
66 }; | 66 }; |
67 | 67 |
68 INSTANTIATE_TEST_CASE_P(All, HTMLCanvasPainterTestForSPv2, ::testing::Bool()); | 68 INSTANTIATE_TEST_CASE_P(All, HTMLCanvasPainterTestForSPv2, ::testing::Bool()); |
69 | 69 |
70 TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree) { | 70 TEST_P(HTMLCanvasPainterTestForSPv2, Canvas2DLayerAppearsInLayerTree) { |
71 // Insert a <canvas> and force it into accelerated mode. | 71 // Insert a <canvas> and force it into accelerated mode. |
72 document().body()->setInnerHTML("<canvas width=300 height=200>"); | 72 document().body()->setInnerHTML("<canvas width=300 height=200>"); |
73 HTMLCanvasElement* element = | 73 HTMLCanvasElement* element = |
74 toHTMLCanvasElement(document().body()->firstChild()); | 74 toHTMLCanvasElement(document().body()->firstChild()); |
75 CanvasContextCreationAttributes attributes; | 75 CanvasContextCreationAttributes attributes; |
76 attributes.setAlpha(true); | 76 attributes.setAlpha(true); |
77 CanvasRenderingContext* context = | 77 CanvasRenderingContext* context = |
78 element->getCanvasRenderingContext("2d", attributes); | 78 element->getCanvasRenderingContext("2d", attributes); |
79 RefPtr<Canvas2DLayerBridge> bridge = | 79 RefPtr<Canvas2DLayerBridge> bridge = |
80 makeCanvas2DLayerBridge(IntSize(300, 200)); | 80 makeCanvas2DLayerBridge(IntSize(300, 200)); |
81 element->createImageBufferUsingSurfaceForTesting( | 81 element->createImageBufferUsingSurfaceForTesting(WTF::wrapUnique( |
82 wrapUnique(new Canvas2DImageBufferSurface(bridge, IntSize(300, 200)))); | 82 new Canvas2DImageBufferSurface(bridge, IntSize(300, 200)))); |
83 ASSERT_EQ(context, element->renderingContext()); | 83 ASSERT_EQ(context, element->renderingContext()); |
84 ASSERT_TRUE(context->isAccelerated()); | 84 ASSERT_TRUE(context->isAccelerated()); |
85 | 85 |
86 // Force the page to paint. | 86 // Force the page to paint. |
87 document().view()->updateAllLifecyclePhases(); | 87 document().view()->updateAllLifecyclePhases(); |
88 | 88 |
89 // Fetch the layer associated with the <canvas>, and check that it was | 89 // Fetch the layer associated with the <canvas>, and check that it was |
90 // correctly configured in the layer tree. | 90 // correctly configured in the layer tree. |
91 const WebLayer* layer = context->platformLayer(); | 91 const WebLayer* layer = context->platformLayer(); |
92 ASSERT_TRUE(layer); | 92 ASSERT_TRUE(layer); |
93 EXPECT_TRUE(hasLayerAttached(*layer)); | 93 EXPECT_TRUE(hasLayerAttached(*layer)); |
94 EXPECT_EQ(WebSize(300, 200), layer->bounds()); | 94 EXPECT_EQ(WebSize(300, 200), layer->bounds()); |
95 } | 95 } |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
OLD | NEW |