Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: Source/web/PageOverlayTest.cpp

Issue 1264483002: PageOverlays: Remove PageOverlayList (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move WebPageOverlay to PageOverlay Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/DisplayItemList.h" 12 #include "platform/graphics/paint/DisplayItemList.h"
13 #include "platform/graphics/paint/DrawingRecorder.h" 13 #include "platform/graphics/paint/DrawingRecorder.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/WebPageOverlay.h"
18 #include "public/web/WebSettings.h" 17 #include "public/web/WebSettings.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "third_party/skia/include/core/SkCanvas.h" 19 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
22 #include "third_party/skia/include/core/SkPaint.h" 21 #include "third_party/skia/include/core/SkPaint.h"
23 #include "web/WebGraphicsContextImpl.h" 22 #include "web/WebGraphicsContextImpl.h"
24 #include "web/WebLocalFrameImpl.h" 23 #include "web/WebLocalFrameImpl.h"
25 #include "web/WebViewImpl.h" 24 #include "web/WebViewImpl.h"
26 #include "web/tests/FrameTestHelpers.h" 25 #include "web/tests/FrameTestHelpers.h"
27 #include <gmock/gmock.h> 26 #include <gmock/gmock.h>
(...skipping 26 matching lines...) Expand all
54 enum CompositingMode { AcceleratedCompositing, UnacceleratedCompositing }; 53 enum CompositingMode { AcceleratedCompositing, UnacceleratedCompositing };
55 54
56 void initialize(CompositingMode compositingMode) 55 void initialize(CompositingMode compositingMode)
57 { 56 {
58 m_helper.initialize( 57 m_helper.initialize(
59 false /* enableJavascript */, nullptr /* webFrameClient */, nullptr /* webViewClient */, 58 false /* enableJavascript */, nullptr /* webFrameClient */, nullptr /* webViewClient */,
60 compositingMode == AcceleratedCompositing ? enableAcceleratedComposi ting : disableAcceleratedCompositing); 59 compositingMode == AcceleratedCompositing ? enableAcceleratedComposi ting : disableAcceleratedCompositing);
61 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); 60 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight));
62 webViewImpl()->layout(); 61 webViewImpl()->layout();
63 ASSERT_EQ(compositingMode == AcceleratedCompositing, webViewImpl()->isAc celeratedCompositingActive()); 62 ASSERT_EQ(compositingMode == AcceleratedCompositing, webViewImpl()->isAc celeratedCompositingActive());
64 ASSERT_TRUE(!webViewImpl()->pageOverlays() || webViewImpl()->pageOverlay s()->empty());
65 } 63 }
66 64
67 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } 65 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); }
68 66
69 template <typename OverlayType> 67 template <typename OverlayType>
70 void runPageOverlayTestWithAcceleratedCompositing(); 68 void runPageOverlayTestWithAcceleratedCompositing();
71 69
72 private: 70 private:
73 FrameTestHelpers::WebViewHelper m_helper; 71 FrameTestHelpers::WebViewHelper m_helper;
74 }; 72 };
75 73
76 // WebPageOverlay that uses a WebCanvas to draw a solid color. 74 // PageOverlay that uses a WebCanvas to draw a solid color.
77 class SimpleCanvasOverlay : public WebPageOverlay { 75 class SimpleCanvasOverlay : public PageOverlay::Delegate {
78 public: 76 public:
79 SimpleCanvasOverlay(SkColor color) : m_color(color) { } 77 SimpleCanvasOverlay(SkColor color) : m_color(color) { }
80 78
81 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) over ride 79 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) over ride
82 { 80 {
83 WebFloatRect rect(0, 0, size.width, size.height); 81 WebFloatRect rect(0, 0, size.width, size.height);
84 WebCanvas* canvas = context->beginDrawing(rect); 82 WebCanvas* canvas = context->beginDrawing(rect);
85 SkPaint paint; 83 SkPaint paint;
86 paint.setColor(m_color); 84 paint.setColor(m_color);
87 paint.setStyle(SkPaint::kFill_Style); 85 paint.setStyle(SkPaint::kFill_Style);
88 canvas->drawRectCoords(0, 0, size.width, size.height, paint); 86 canvas->drawRectCoords(0, 0, size.width, size.height, paint);
89 context->endDrawing(); 87 context->endDrawing();
90 } 88 }
91 89
92 private: 90 private:
93 SkColor m_color; 91 SkColor m_color;
94 }; 92 };
95 93
96 // WebPageOverlay that uses the underlying blink::GraphicsContext to paint a 94 // PageOverlay that uses the underlying blink::GraphicsContext to paint a
97 // solid color. 95 // solid color.
98 class PrivateGraphicsContextOverlay : public WebPageOverlay { 96 class PrivateGraphicsContextOverlay : public PageOverlay::Delegate {
99 public: 97 public:
100 PrivateGraphicsContextOverlay(Color color) : m_color(color) { } 98 PrivateGraphicsContextOverlay(Color color) : m_color(color) { }
101 99
102 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) over ride 100 void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) over ride
103 { 101 {
104 GraphicsContext& graphicsContext = toWebGraphicsContextImpl(context)->gr aphicsContext(); 102 GraphicsContext& graphicsContext = toWebGraphicsContextImpl(context)->gr aphicsContext();
105 if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, *this, DisplayItem::PageOverlay)) 103 if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, *this, DisplayItem::PageOverlay))
106 return; 104 return;
107 FloatRect rect(0, 0, size.width, size.height); 105 FloatRect rect(0, 0, size.width, size.height);
108 DrawingRecorder drawingRecorder(graphicsContext, *this, DisplayItem::Pag eOverlay, rect); 106 DrawingRecorder drawingRecorder(graphicsContext, *this, DisplayItem::Pag eOverlay, rect);
(...skipping 22 matching lines...) Expand all
131 MockCanvas(int width, int height) : SkCanvas(width, height) { } 129 MockCanvas(int width, int height) : SkCanvas(width, height) { }
132 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&)); 130 MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&));
133 }; 131 };
134 132
135 template <typename OverlayType> 133 template <typename OverlayType>
136 void PageOverlayTest::runPageOverlayTestWithAcceleratedCompositing() 134 void PageOverlayTest::runPageOverlayTestWithAcceleratedCompositing()
137 { 135 {
138 initialize(AcceleratedCompositing); 136 initialize(AcceleratedCompositing);
139 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp ortHeight)); 137 webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewp ortHeight));
140 138
141 OverlayType overlay(SK_ColorYELLOW); 139 OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(webViewImpl(), adoptPt r(new OverlayType(SK_ColorYELLOW)));
142 webViewImpl()->addPageOverlay(&overlay, 0 /* zOrder */); 140 pageOverlay->update();
143 EXPECT_TRUE(webViewImpl()->pageOverlays() && !webViewImpl()->pageOverlays()- >empty());
144 webViewImpl()->layout(); 141 webViewImpl()->layout();
145 142
146 // Ideally, we would get results from the compositor that showed that this 143 // Ideally, we would get results from the compositor that showed that this
147 // page overlay actually winds up getting drawn on top of the rest. 144 // page overlay actually winds up getting drawn on top of the rest.
148 // For now, we just check that the GraphicsLayer will draw the right thing. 145 // For now, we just check that the GraphicsLayer will draw the right thing.
149 146
150 MockCanvas canvas(viewportWidth, viewportHeight); 147 MockCanvas canvas(viewportWidth, viewportHeight);
151 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0)); 148 EXPECT_CALL(canvas, onDrawRect(_, _)).Times(AtLeast(0));
152 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight) , Property(&SkPaint::getColor, SK_ColorYELLOW))); 149 EXPECT_CALL(canvas, onDrawRect(SkRect::MakeWH(viewportWidth, viewportHeight) , Property(&SkPaint::getColor, SK_ColorYELLOW)));
153 150
154 GraphicsLayer* graphicsLayer = webViewImpl()->pageOverlays()->graphicsLayerF orTesting(); 151 GraphicsLayer* graphicsLayer = pageOverlay->graphicsLayer();
155 WebRect rect(0, 0, viewportWidth, viewportHeight); 152 WebRect rect(0, 0, viewportWidth, viewportHeight);
156 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { 153 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
157 // If slimming paint is on, we paint the layer with a null canvas to get 154 // If slimming paint is on, we paint the layer with a null canvas to get
158 // a display list, and then replay that onto the mock canvas for 155 // a display list, and then replay that onto the mock canvas for
159 // examination. This is about as close to the real path as we can easily 156 // examination. This is about as close to the real path as we can easily
160 // get. 157 // get.
161 GraphicsContext graphicsContext(graphicsLayer->displayItemList()); 158 GraphicsContext graphicsContext(graphicsLayer->displayItemList());
162 graphicsLayer->paint(graphicsContext, rect); 159 graphicsLayer->paint(graphicsContext, rect);
163 160
164 graphicsContext.beginRecording(IntRect(rect)); 161 graphicsContext.beginRecording(IntRect(rect));
(...skipping 24 matching lines...) Expand all
189 } 186 }
190 187
191 TEST_F(PageOverlayTest, PrivateGraphicsContextOverlay_AcceleratedCompositing_Sli mmingPaint) 188 TEST_F(PageOverlayTest, PrivateGraphicsContextOverlay_AcceleratedCompositing_Sli mmingPaint)
192 { 189 {
193 SlimmingPaintScope slimmingPaintEnabled(true); 190 SlimmingPaintScope slimmingPaintEnabled(true);
194 runPageOverlayTestWithAcceleratedCompositing<PrivateGraphicsContextOverlay>( ); 191 runPageOverlayTestWithAcceleratedCompositing<PrivateGraphicsContextOverlay>( );
195 } 192 }
196 193
197 } // namespace 194 } // namespace
198 } // namespace blink 195 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698