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 "web/PageOverlay.h" | 5 #include "web/PageOverlay.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "platform/graphics/Color.h" | 8 #include "platform/graphics/Color.h" |
9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
10 #include "platform/graphics/paint/DrawingRecorder.h" | 10 #include "platform/graphics/paint/DrawingRecorder.h" |
11 #include "platform/graphics/paint/PaintController.h" | 11 #include "platform/graphics/paint/PaintController.h" |
12 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
13 #include "public/platform/WebCanvas.h" | 13 #include "public/platform/WebCanvas.h" |
14 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
15 #include "public/web/WebSettings.h" | 15 #include "public/web/WebSettings.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.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/WebLocalFrameImpl.h" | 22 #include "web/WebLocalFrameImpl.h" |
23 #include "web/WebViewImpl.h" | 23 #include "web/WebViewImpl.h" |
24 #include "web/tests/FrameTestHelpers.h" | 24 #include "web/tests/FrameTestHelpers.h" |
25 #include <memory> | |
26 | 25 |
27 using testing::_; | 26 using testing::_; |
28 using testing::AtLeast; | 27 using testing::AtLeast; |
29 using testing::Property; | 28 using testing::Property; |
30 | 29 |
31 namespace blink { | 30 namespace blink { |
32 namespace { | 31 namespace { |
33 | 32 |
34 static const int viewportWidth = 800; | 33 static const int viewportWidth = 800; |
35 static const int viewportHeight = 600; | 34 static const int viewportHeight = 600; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 m_helper.initialize( | 72 m_helper.initialize( |
74 false /* enableJavascript */, nullptr /* webFrameClient */, nullptr
/* webViewClient */, nullptr /* webWidgetClient */, | 73 false /* enableJavascript */, nullptr /* webFrameClient */, nullptr
/* webViewClient */, nullptr /* webWidgetClient */, |
75 compositingMode == AcceleratedCompositing ? enableAcceleratedComposi
ting : disableAcceleratedCompositing); | 74 compositingMode == AcceleratedCompositing ? enableAcceleratedComposi
ting : disableAcceleratedCompositing); |
76 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); | 75 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); |
77 webViewImpl()->updateAllLifecyclePhases(); | 76 webViewImpl()->updateAllLifecyclePhases(); |
78 ASSERT_EQ(compositingMode == AcceleratedCompositing, webViewImpl()->isAc
celeratedCompositingActive()); | 77 ASSERT_EQ(compositingMode == AcceleratedCompositing, webViewImpl()->isAc
celeratedCompositingActive()); |
79 } | 78 } |
80 | 79 |
81 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } | 80 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } |
82 | 81 |
83 std::unique_ptr<PageOverlay> createSolidYellowOverlay() | 82 PassOwnPtr<PageOverlay> createSolidYellowOverlay() |
84 { | 83 { |
85 return PageOverlay::create(webViewImpl(), new SolidColorOverlay(SK_Color
YELLOW)); | 84 return PageOverlay::create(webViewImpl(), new SolidColorOverlay(SK_Color
YELLOW)); |
86 } | 85 } |
87 | 86 |
88 template <typename OverlayType> | 87 template <typename OverlayType> |
89 void runPageOverlayTestWithAcceleratedCompositing(); | 88 void runPageOverlayTestWithAcceleratedCompositing(); |
90 | 89 |
91 private: | 90 private: |
92 FrameTestHelpers::WebViewHelper m_helper; | 91 FrameTestHelpers::WebViewHelper m_helper; |
93 }; | 92 }; |
(...skipping 11 matching lines...) Expand all Loading... |
105 public: | 104 public: |
106 MockCanvas(int width, int height) : SkCanvas(width, height) { } | 105 MockCanvas(int width, int height) : SkCanvas(width, height) { } |
107 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); | 106 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); |
108 }; | 107 }; |
109 | 108 |
110 TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) | 109 TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) |
111 { | 110 { |
112 initialize(AcceleratedCompositing); | 111 initialize(AcceleratedCompositing); |
113 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp
ortHeight)); | 112 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp
ortHeight)); |
114 | 113 |
115 std::unique_ptr<PageOverlay> pageOverlay = createSolidYellowOverlay(); | 114 OwnPtr<PageOverlay> pageOverlay = createSolidYellowOverlay(); |
116 pageOverlay->update(); | 115 pageOverlay->update(); |
117 webViewImpl()->updateAllLifecyclePhases(); | 116 webViewImpl()->updateAllLifecyclePhases(); |
118 | 117 |
119 // Ideally, we would get results from the compositor that showed that this | 118 // Ideally, we would get results from the compositor that showed that this |
120 // page overlay actually winds up getting drawn on top of the rest. | 119 // page overlay actually winds up getting drawn on top of the rest. |
121 // For now, we just check that the GraphicsLayer will draw the right thing. | 120 // For now, we just check that the GraphicsLayer will draw the right thing. |
122 | 121 |
123 MockCanvas canvas(viewportWidth, viewportHeight); | 122 MockCanvas canvas(viewportWidth, viewportHeight); |
124 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); | 123 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); |
125 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight)
, Property(&SkPaint::getColor, SK_ColorYELLOW))); | 124 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight)
, Property(&SkPaint::getColor, SK_ColorYELLOW))); |
126 | 125 |
127 GraphicsLayer* graphicsLayer = pageOverlay->graphicsLayer(); | 126 GraphicsLayer* graphicsLayer = pageOverlay->graphicsLayer(); |
128 WebRect rect(0, 0, viewportWidth, viewportHeight); | 127 WebRect rect(0, 0, viewportWidth, viewportHeight); |
129 | 128 |
130 // Paint the layer with a null canvas to get a display list, and then | 129 // Paint the layer with a null canvas to get a display list, and then |
131 // replay that onto the mock canvas for examination. | 130 // replay that onto the mock canvas for examination. |
132 IntRect intRect = rect; | 131 IntRect intRect = rect; |
133 graphicsLayer->paint(&intRect); | 132 graphicsLayer->paint(&intRect); |
134 | 133 |
135 PaintController& paintController = graphicsLayer->getPaintController(); | 134 PaintController& paintController = graphicsLayer->getPaintController(); |
136 GraphicsContext graphicsContext(paintController); | 135 GraphicsContext graphicsContext(paintController); |
137 graphicsContext.beginRecording(intRect); | 136 graphicsContext.beginRecording(intRect); |
138 paintController.paintArtifact().replay(graphicsContext); | 137 paintController.paintArtifact().replay(graphicsContext); |
139 graphicsContext.endRecording()->playback(&canvas); | 138 graphicsContext.endRecording()->playback(&canvas); |
140 } | 139 } |
141 | 140 |
142 TEST_F(PageOverlayTest, PageOverlay_VisualRect) | 141 TEST_F(PageOverlayTest, PageOverlay_VisualRect) |
143 { | 142 { |
144 initialize(AcceleratedCompositing); | 143 initialize(AcceleratedCompositing); |
145 std::unique_ptr<PageOverlay> pageOverlay = createSolidYellowOverlay(); | 144 OwnPtr<PageOverlay> pageOverlay = createSolidYellowOverlay(); |
146 pageOverlay->update(); | 145 pageOverlay->update(); |
147 webViewImpl()->updateAllLifecyclePhases(); | 146 webViewImpl()->updateAllLifecyclePhases(); |
148 EXPECT_EQ(LayoutRect(0, 0, viewportWidth, viewportHeight), pageOverlay->visu
alRect()); | 147 EXPECT_EQ(LayoutRect(0, 0, viewportWidth, viewportHeight), pageOverlay->visu
alRect()); |
149 } | 148 } |
150 | 149 |
151 } // namespace | 150 } // namespace |
152 } // namespace blink | 151 } // namespace blink |
OLD | NEW |