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

Side by Side Diff: Source/platform/graphics/RecordingImageBufferSurface.cpp

Issue 659873002: Making display list canvases fall back to gpu-accelerated when appropriate (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 6
7 #include "platform/graphics/RecordingImageBufferSurface.h" 7 #include "platform/graphics/RecordingImageBufferSurface.h"
8 8
9 #include "platform/graphics/GraphicsContext.h" 9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/ImageBuffer.h" 10 #include "platform/graphics/ImageBuffer.h"
11 #include "public/platform/Platform.h" 11 #include "public/platform/Platform.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkPictureRecorder.h" 13 #include "third_party/skia/include/core/SkPictureRecorder.h"
14 #include "wtf/PassOwnPtr.h" 14 #include "wtf/PassOwnPtr.h"
15 #include "wtf/PassRefPtr.h" 15 #include "wtf/PassRefPtr.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Op acityMode opacityMode) 19 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Pa ssOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMod e opacityMode)
20 : ImageBufferSurface(size, opacityMode) 20 : ImageBufferSurface(size, opacityMode)
21 , m_imageBuffer(0) 21 , m_imageBuffer(0)
22 , m_initialSaveCount(0) 22 , m_initialSaveCount(0)
23 , m_frameWasCleared(true) 23 , m_frameWasCleared(true)
24 , m_fallbackFactory(fallbackFactory)
24 { 25 {
25 initializeCurrentFrame(); 26 initializeCurrentFrame();
26 } 27 }
27 28
28 RecordingImageBufferSurface::~RecordingImageBufferSurface() 29 RecordingImageBufferSurface::~RecordingImageBufferSurface()
29 { } 30 { }
30 31
31 bool RecordingImageBufferSurface::initializeCurrentFrame() 32 bool RecordingImageBufferSurface::initializeCurrentFrame()
32 { 33 {
33 StateStack stateStack; 34 StateStack stateStack;
(...skipping 19 matching lines...) Expand all
53 return true; 54 return true;
54 } 55 }
55 56
56 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer) 57 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer)
57 { 58 {
58 m_imageBuffer = imageBuffer; 59 m_imageBuffer = imageBuffer;
59 if (m_currentFrame && m_imageBuffer) { 60 if (m_currentFrame && m_imageBuffer) {
60 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT rackingOverwrite); 61 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT rackingOverwrite);
61 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas ()); 62 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas ());
62 } 63 }
64 if (m_fallbackSurface) {
65 m_fallbackSurface->setImageBuffer(imageBuffer);
66 }
63 } 67 }
64 68
65 void RecordingImageBufferSurface::willAccessPixels() 69 void RecordingImageBufferSurface::willAccessPixels()
66 { 70 {
67 fallBackToRasterCanvas(); 71 if (m_fallbackSurface)
72 m_fallbackSurface->willAccessPixels();
73 else
74 fallBackToRasterCanvas();
68 } 75 }
69 76
70 void RecordingImageBufferSurface::fallBackToRasterCanvas() 77 void RecordingImageBufferSurface::fallBackToRasterCanvas()
71 { 78 {
72 if (m_rasterCanvas) { 79 if (m_fallbackSurface) {
73 ASSERT(!m_currentFrame); 80 ASSERT(!m_currentFrame);
74 return; 81 return;
75 } 82 }
76 83
77 m_rasterCanvas = adoptPtr(SkCanvas::NewRasterN32(size().width(), size().heig ht())); 84 m_fallbackSurface = m_fallbackFactory->createSurface(size(), opacityMode());
85 m_fallbackSurface->setImageBuffer(m_imageBuffer);
78 86
79 if (m_previousFrame) { 87 if (m_previousFrame) {
80 m_previousFrame->draw(m_rasterCanvas.get()); 88 m_previousFrame->draw(m_fallbackSurface->canvas());
81 m_previousFrame.clear(); 89 m_previousFrame.clear();
82 } 90 }
83 if (m_currentFrame) { 91 if (m_currentFrame) {
84 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording ()); 92 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording ());
85 currentPicture->draw(m_rasterCanvas.get()); 93 currentPicture->draw(m_fallbackSurface->canvas());
86 m_currentFrame.clear(); 94 m_currentFrame.clear();
87 } 95 }
88 96
89 if (m_imageBuffer) { 97 if (m_imageBuffer) {
90 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT rackingDisabled); 98 m_imageBuffer->context()->setRegionTrackingMode(GraphicsContext::RegionT rackingDisabled);
91 m_imageBuffer->context()->resetCanvas(m_rasterCanvas.get()); 99 m_imageBuffer->context()->resetCanvas(m_fallbackSurface->canvas());
92 } 100 }
93 } 101 }
94 102
95 SkCanvas* RecordingImageBufferSurface::canvas() const 103 SkCanvas* RecordingImageBufferSurface::canvas() const
96 { 104 {
97 if (m_rasterCanvas) 105 if (m_fallbackSurface)
98 return m_rasterCanvas.get(); 106 return m_fallbackSurface->canvas();
99 107
100 ASSERT(m_currentFrame->getRecordingCanvas()); 108 ASSERT(m_currentFrame->getRecordingCanvas());
101 return m_currentFrame->getRecordingCanvas(); 109 return m_currentFrame->getRecordingCanvas();
102 } 110 }
103 111
104 PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture() 112 PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture()
105 { 113 {
114 if (m_fallbackSurface)
115 return nullptr;
116
106 bool canUsePicture = finalizeFrameInternal(); 117 bool canUsePicture = finalizeFrameInternal();
107 m_imageBuffer->didFinalizeFrame(); 118 m_imageBuffer->didFinalizeFrame();
108 119
109 if (canUsePicture) { 120 if (canUsePicture) {
110 return m_previousFrame; 121 return m_previousFrame;
111 } 122 }
112 123
113 if (!m_rasterCanvas) 124 if (!m_fallbackSurface)
114 fallBackToRasterCanvas(); 125 fallBackToRasterCanvas();
115 return nullptr; 126 return nullptr;
116 } 127 }
117 128
118 void RecordingImageBufferSurface::finalizeFrame(const FloatRect &) 129 void RecordingImageBufferSurface::finalizeFrame(const FloatRect &dirtyRect)
119 { 130 {
120 if (!finalizeFrameInternal() && !m_rasterCanvas) { 131 if (m_fallbackSurface) {
132 m_fallbackSurface->finalizeFrame(dirtyRect);
Stephen White 2014/10/16 14:37:13 Nit: could be an early-return here.
133 } else if (!finalizeFrameInternal()) {
121 fallBackToRasterCanvas(); 134 fallBackToRasterCanvas();
122 } 135 }
123 } 136 }
124 137
125 void RecordingImageBufferSurface::didClearCanvas() 138 void RecordingImageBufferSurface::didClearCanvas()
126 { 139 {
127 m_frameWasCleared = true; 140 m_frameWasCleared = true;
141 if (m_fallbackSurface)
142 m_fallbackSurface->didClearCanvas();
Stephen White 2014/10/16 14:37:13 Since we don't care about setting m_frameWasCleare
128 } 143 }
129 144
130 bool RecordingImageBufferSurface::finalizeFrameInternal() 145 bool RecordingImageBufferSurface::finalizeFrameInternal()
131 { 146 {
147 ASSERT(!m_fallbackSurface);
148
132 if (!m_imageBuffer->isDirty()) { 149 if (!m_imageBuffer->isDirty()) {
133 if (m_currentFrame && !m_previousFrame) { 150 if (m_currentFrame && !m_previousFrame) {
134 // Create an initial blank frame 151 // Create an initial blank frame
135 m_previousFrame = adoptRef(m_currentFrame->endRecording()); 152 m_previousFrame = adoptRef(m_currentFrame->endRecording());
136 initializeCurrentFrame(); 153 initializeCurrentFrame();
137 } 154 }
138 return m_currentFrame; 155 return m_currentFrame;
139 } 156 }
140 157
141 if (!m_currentFrame) {
142 return false;
143 }
144
145 IntRect canvasRect(IntPoint(0, 0), size()); 158 IntRect canvasRect(IntPoint(0, 0), size());
146 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) { 159 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) {
147 return false; 160 return false;
148 } 161 }
149 162
150 m_previousFrame = adoptRef(m_currentFrame->endRecording()); 163 m_previousFrame = adoptRef(m_currentFrame->endRecording());
151 if (!initializeCurrentFrame()) 164 if (!initializeCurrentFrame())
152 return false; 165 return false;
153 166
154 167
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 dstCanvas->setMatrix(stateStack->peek().m_ctm); 200 dstCanvas->setMatrix(stateStack->peek().m_ctm);
188 dstCanvas->save(); 201 dstCanvas->save();
189 stateStack->pop(); 202 stateStack->pop();
190 } 203 }
191 204
192 dstCanvas->resetMatrix(); 205 dstCanvas->resetMatrix();
193 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); 206 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip));
194 dstCanvas->setMatrix(stateStack->peek().m_ctm); 207 dstCanvas->setMatrix(stateStack->peek().m_ctm);
195 } 208 }
196 209
210 // Fallback passthroughs
211
212 const SkBitmap& RecordingImageBufferSurface::bitmap()
213 {
214 if (m_fallbackSurface)
215 return m_fallbackSurface->bitmap();
216 return INHERITTED::bitmap();
Stephen White 2014/10/16 14:37:13 We don't use INHERITED (or INHERITTED :) ) in Blin
217 }
218
219 bool RecordingImageBufferSurface::restore()
220 {
221 if (m_fallbackSurface)
222 return m_fallbackSurface->restore();
223 return INHERITTED::restore();
224 }
225
226 WebLayer* RecordingImageBufferSurface::layer() const
227 {
228 if (m_fallbackSurface)
229 return m_fallbackSurface->layer();
230 return INHERITTED::layer();
231 }
232
233 bool RecordingImageBufferSurface::isAccelerated() const
234 {
235 if (m_fallbackSurface)
236 return m_fallbackSurface->isAccelerated();
237 return INHERITTED::isAccelerated();
238 }
239
240 Platform3DObject RecordingImageBufferSurface::getBackingTexture() const
241 {
242 if (m_fallbackSurface)
243 return m_fallbackSurface->getBackingTexture();
244 return INHERITTED::getBackingTexture();
245 }
246
247 bool RecordingImageBufferSurface::cachedBitmapEnabled() const
248 {
249 if (m_fallbackSurface)
250 return m_fallbackSurface->cachedBitmapEnabled();
251 return INHERITTED::cachedBitmapEnabled();
252 }
253
254 const SkBitmap& RecordingImageBufferSurface::cachedBitmap() const
255 {
256 if (m_fallbackSurface)
257 return m_fallbackSurface->cachedBitmap();
258 return INHERITTED::cachedBitmap();
259 }
260
261 void RecordingImageBufferSurface::invalidateCachedBitmap()
262 {
263 if (m_fallbackSurface)
264 m_fallbackSurface->invalidateCachedBitmap();
265 else
266 INHERITTED::invalidateCachedBitmap();
267 }
268
269 void RecordingImageBufferSurface::updateCachedBitmapIfNeeded()
270 {
271 if (m_fallbackSurface)
272 m_fallbackSurface->updateCachedBitmapIfNeeded();
273 else
274 INHERITTED::updateCachedBitmapIfNeeded();
275 }
276
277 void RecordingImageBufferSurface::setIsHidden(bool hidden)
278 {
279 if (m_fallbackSurface)
280 m_fallbackSurface->setIsHidden(hidden);
281 else
282 INHERITTED::setIsHidden(hidden);
283 }
284
197 } // namespace blink 285 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/RecordingImageBufferSurface.h ('k') | Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698