OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "web/PageOverlay.h" | 6 #include "web/PageOverlay.h" |
7 | 7 |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/layout/LayoutView.h" | 9 #include "core/layout/LayoutView.h" |
10 #include "platform/graphics/Color.h" | 10 #include "platform/graphics/Color.h" |
11 #include "platform/graphics/GraphicsContext.h" | 11 #include "platform/graphics/GraphicsContext.h" |
12 #include "platform/graphics/paint/DrawingRecorder.h" | 12 #include "platform/graphics/paint/DrawingRecorder.h" |
13 #include "platform/graphics/paint/PaintController.h" | 13 #include "platform/graphics/paint/PaintController.h" |
14 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
15 #include "public/platform/WebCanvas.h" | 15 #include "public/platform/WebCanvas.h" |
16 #include "public/platform/WebThread.h" | 16 #include "public/platform/WebThread.h" |
17 #include "public/web/WebSettings.h" | 17 #include "public/web/WebSettings.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
20 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
21 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
22 #include "web/WebGraphicsContextImpl.h" | |
23 #include "web/WebLocalFrameImpl.h" | 22 #include "web/WebLocalFrameImpl.h" |
24 #include "web/WebViewImpl.h" | 23 #include "web/WebViewImpl.h" |
25 #include "web/tests/FrameTestHelpers.h" | 24 #include "web/tests/FrameTestHelpers.h" |
26 #include <gmock/gmock.h> | 25 #include <gmock/gmock.h> |
27 #include <gtest/gtest.h> | 26 #include <gtest/gtest.h> |
28 | 27 |
29 using testing::_; | 28 using testing::_; |
30 using testing::AtLeast; | 29 using testing::AtLeast; |
31 using testing::Property; | 30 using testing::Property; |
32 | 31 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 63 |
65 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } | 64 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } |
66 | 65 |
67 template <typename OverlayType> | 66 template <typename OverlayType> |
68 void runPageOverlayTestWithAcceleratedCompositing(); | 67 void runPageOverlayTestWithAcceleratedCompositing(); |
69 | 68 |
70 private: | 69 private: |
71 FrameTestHelpers::WebViewHelper m_helper; | 70 FrameTestHelpers::WebViewHelper m_helper; |
72 }; | 71 }; |
73 | 72 |
74 // PageOverlay that uses a WebCanvas to draw a solid color. | 73 // PageOverlay that paints a solid color. |
75 class SimpleCanvasOverlay : public PageOverlay::Delegate { | 74 class SolidColorOverlay : public PageOverlay::Delegate { |
76 public: | 75 public: |
77 SimpleCanvasOverlay(SkColor color) : m_color(color) { } | 76 SolidColorOverlay(Color color) : m_color(color) { } |
78 | 77 |
79 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) cons
t override | 78 void paintPageOverlay(const PageOverlay& pageOverlay, GraphicsContext& graph
icsContext, const WebSize& size) const override |
80 { | 79 { |
81 WebFloatRect rect(0, 0, size.width, size.height); | 80 if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, pageOve
rlay, DisplayItem::PageOverlay)) |
82 WebCanvas* canvas = context->beginDrawing(rect); | |
83 SkPaint paint; | |
84 paint.setColor(m_color); | |
85 paint.setStyle(SkPaint::kFill_Style); | |
86 canvas->drawRectCoords(0, 0, size.width, size.height, paint); | |
87 context->endDrawing(); | |
88 } | |
89 | |
90 private: | |
91 SkColor m_color; | |
92 }; | |
93 | |
94 // PageOverlay that uses the underlying blink::GraphicsContext to paint a | |
95 // solid color. | |
96 class PrivateGraphicsContextOverlay : public PageOverlay::Delegate { | |
97 public: | |
98 PrivateGraphicsContextOverlay(Color color) : m_color(color) { } | |
99 | |
100 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) cons
t override | |
101 { | |
102 GraphicsContext& graphicsContext = toWebGraphicsContextImpl(context)->gr
aphicsContext(); | |
103 if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, *this,
DisplayItem::PageOverlay)) | |
104 return; | 81 return; |
105 FloatRect rect(0, 0, size.width, size.height); | 82 FloatRect rect(0, 0, size.width, size.height); |
106 DrawingRecorder drawingRecorder(graphicsContext, *this, DisplayItem::Pag
eOverlay, rect); | 83 DrawingRecorder drawingRecorder(graphicsContext, pageOverlay, DisplayIte
m::PageOverlay, rect); |
107 graphicsContext.fillRect(rect, m_color); | 84 graphicsContext.fillRect(rect, m_color); |
108 } | 85 } |
109 | 86 |
110 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi
s); } | |
111 String debugName() const { return "PrivateGraphicsContextOverlay"; } | |
112 | |
113 private: | 87 private: |
114 Color m_color; | 88 Color m_color; |
115 }; | 89 }; |
116 | 90 |
117 template <bool(*getter)(), void(*setter)(bool)> | 91 template <bool(*getter)(), void(*setter)(bool)> |
118 class RuntimeFeatureChange { | 92 class RuntimeFeatureChange { |
119 public: | 93 public: |
120 RuntimeFeatureChange(bool newValue) : m_oldValue(getter()) { setter(newValue
); } | 94 RuntimeFeatureChange(bool newValue) : m_oldValue(getter()) { setter(newValue
); } |
121 ~RuntimeFeatureChange() { setter(m_oldValue); } | 95 ~RuntimeFeatureChange() { setter(m_oldValue); } |
122 private: | 96 private: |
123 bool m_oldValue; | 97 bool m_oldValue; |
124 }; | 98 }; |
125 | 99 |
126 class MockCanvas : public SkCanvas { | 100 class MockCanvas : public SkCanvas { |
127 public: | 101 public: |
128 MockCanvas(int width, int height) : SkCanvas(width, height) { } | 102 MockCanvas(int width, int height) : SkCanvas(width, height) { } |
129 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); | 103 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); |
130 }; | 104 }; |
131 | 105 |
132 template <typename OverlayType> | 106 TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) |
133 void PageOverlayTest::runPageOverlayTestWithAcceleratedCompositing() | |
134 { | 107 { |
135 initialize(AcceleratedCompositing); | 108 initialize(AcceleratedCompositing); |
136 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp
ortHeight)); | 109 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp
ortHeight)); |
137 | 110 |
138 OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(webViewImpl(), new Ove
rlayType(SK_ColorYELLOW)); | 111 OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(webViewImpl(), new Sol
idColorOverlay(SK_ColorYELLOW)); |
139 pageOverlay->update(); | 112 pageOverlay->update(); |
140 webViewImpl()->layout(); | 113 webViewImpl()->layout(); |
141 | 114 |
142 // Ideally, we would get results from the compositor that showed that this | 115 // Ideally, we would get results from the compositor that showed that this |
143 // page overlay actually winds up getting drawn on top of the rest. | 116 // page overlay actually winds up getting drawn on top of the rest. |
144 // For now, we just check that the GraphicsLayer will draw the right thing. | 117 // For now, we just check that the GraphicsLayer will draw the right thing. |
145 | 118 |
146 MockCanvas canvas(viewportWidth, viewportHeight); | 119 MockCanvas canvas(viewportWidth, viewportHeight); |
147 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); | 120 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); |
148 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight)
, Property(&SkPaint::getColor, SK_ColorYELLOW))); | 121 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight)
, Property(&SkPaint::getColor, SK_ColorYELLOW))); |
149 | 122 |
150 GraphicsLayer* graphicsLayer = pageOverlay->graphicsLayer(); | 123 GraphicsLayer* graphicsLayer = pageOverlay->graphicsLayer(); |
151 WebRect rect(0, 0, viewportWidth, viewportHeight); | 124 WebRect rect(0, 0, viewportWidth, viewportHeight); |
152 | 125 |
153 // Paint the layer with a null canvas to get a display list, and then | 126 // Paint the layer with a null canvas to get a display list, and then |
154 // replay that onto the mock canvas for examination. | 127 // replay that onto the mock canvas for examination. |
155 PaintController* paintController = graphicsLayer->paintController(); | 128 PaintController* paintController = graphicsLayer->paintController(); |
156 ASSERT(paintController); | 129 ASSERT(paintController); |
157 GraphicsContext graphicsContext(*paintController); | 130 GraphicsContext graphicsContext(*paintController); |
158 graphicsLayer->paint(graphicsContext, rect); | 131 graphicsLayer->paint(graphicsContext, rect); |
159 | 132 |
160 graphicsContext.beginRecording(IntRect(rect)); | 133 graphicsContext.beginRecording(IntRect(rect)); |
161 paintController->commitNewDisplayItems(); | 134 paintController->commitNewDisplayItems(); |
162 paintController->paintArtifact().replay(graphicsContext); | 135 paintController->paintArtifact().replay(graphicsContext); |
163 graphicsContext.endRecording()->playback(&canvas); | 136 graphicsContext.endRecording()->playback(&canvas); |
164 } | 137 } |
165 | 138 |
166 TEST_F(PageOverlayTest, SimpleCanvasOverlay_AcceleratedCompositing) | |
167 { | |
168 runPageOverlayTestWithAcceleratedCompositing<SimpleCanvasOverlay>(); | |
169 } | |
170 | |
171 TEST_F(PageOverlayTest, PrivateGraphicsContextOverlay_AcceleratedCompositing) | |
172 { | |
173 runPageOverlayTestWithAcceleratedCompositing<PrivateGraphicsContextOverlay>(
); | |
174 } | |
175 | |
176 } // namespace | 139 } // namespace |
177 } // namespace blink | 140 } // namespace blink |
OLD | NEW |