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

Side by Side Diff: src/utils/SkDeferredCanvas.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updating to ToT (10994) Created 7 years, 3 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
« no previous file with comments | « src/pipe/utils/SamplePipeControllers.cpp ('k') | src/utils/SkPictureUtils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkDeferredCanvas.h" 9 #include "SkDeferredCanvas.h"
10 10
11 #include "SkBitmapDevice.h"
11 #include "SkChunkAlloc.h" 12 #include "SkChunkAlloc.h"
12 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
13 #include "SkDevice.h"
14 #include "SkDrawFilter.h" 14 #include "SkDrawFilter.h"
15 #include "SkGPipe.h" 15 #include "SkGPipe.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "SkPaintPriv.h" 17 #include "SkPaintPriv.h"
18 #include "SkRRect.h" 18 #include "SkRRect.h"
19 #include "SkShader.h" 19 #include "SkShader.h"
20 #include "SkSurface.h" 20 #include "SkSurface.h"
21 21
22 enum { 22 enum {
23 // Deferred canvas will auto-flush when recording reaches this limit 23 // Deferred canvas will auto-flush when recording reaches this limit
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 fBlock = NULL; 130 fBlock = NULL;
131 } 131 }
132 132
133 // Release all allocated blocks 133 // Release all allocated blocks
134 fAllocator.reset(); 134 fAllocator.reset();
135 } 135 }
136 136
137 //----------------------------------------------------------------------------- 137 //-----------------------------------------------------------------------------
138 // DeferredDevice 138 // DeferredDevice
139 //----------------------------------------------------------------------------- 139 //-----------------------------------------------------------------------------
140 class DeferredDevice : public SkDevice { 140 class DeferredDevice : public SkBitmapDevice {
141 public: 141 public:
142 explicit DeferredDevice(SkDevice* immediateDevice); 142 explicit DeferredDevice(SkBaseDevice* immediateDevice);
143 explicit DeferredDevice(SkSurface* surface); 143 explicit DeferredDevice(SkSurface* surface);
144 ~DeferredDevice(); 144 ~DeferredDevice();
145 145
146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio nClient); 146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio nClient);
147 SkCanvas* recordingCanvas(); 147 SkCanvas* recordingCanvas();
148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} 148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;}
149 SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} 149 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice ();}
150 SkImage* newImageSnapshot(); 150 SkImage* newImageSnapshot();
151 void setSurface(SkSurface* surface); 151 void setSurface(SkSurface* surface);
152 bool isFreshFrame(); 152 bool isFreshFrame();
153 bool hasPendingCommands(); 153 bool hasPendingCommands();
154 size_t storageAllocatedForRecording() const; 154 size_t storageAllocatedForRecording() const;
155 size_t freeMemoryIfPossible(size_t bytesToFree); 155 size_t freeMemoryIfPossible(size_t bytesToFree);
156 size_t getBitmapSizeThreshold() const; 156 size_t getBitmapSizeThreshold() const;
157 void setBitmapSizeThreshold(size_t sizeThreshold); 157 void setBitmapSizeThreshold(size_t sizeThreshold);
158 void flushPendingCommands(PlaybackMode); 158 void flushPendingCommands(PlaybackMode);
159 void skipPendingCommands(); 159 void skipPendingCommands();
160 void setMaxRecordingStorage(size_t); 160 void setMaxRecordingStorage(size_t);
161 void recordedDrawCommand(); 161 void recordedDrawCommand();
162 162
163 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE; 163 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
164 virtual int width() const SK_OVERRIDE; 164 virtual int width() const SK_OVERRIDE;
165 virtual int height() const SK_OVERRIDE; 165 virtual int height() const SK_OVERRIDE;
166 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; 166 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
167 167
168 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, 168 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
169 int width, int height, 169 int width, int height,
170 bool isOpaque, 170 bool isOpaque,
171 Usage usage) SK_OVERRIDE; 171 Usage usage) SK_OVERRIDE;
172 172
173 virtual void writePixels(const SkBitmap& bitmap, int x, int y, 173 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
174 SkCanvas::Config8888 config8888) SK_OVERRIDE; 174 SkCanvas::Config8888 config8888) SK_OVERRIDE;
175 175
176 protected: 176 protected:
177 virtual const SkBitmap& onAccessBitmap(SkBitmap*) SK_OVERRIDE; 177 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE;
178 virtual bool onReadPixels(const SkBitmap& bitmap, 178 virtual bool onReadPixels(const SkBitmap& bitmap,
179 int x, int y, 179 int x, int y,
180 SkCanvas::Config8888 config8888) SK_OVERRIDE; 180 SkCanvas::Config8888 config8888) SK_OVERRIDE;
181 181
182 // The following methods are no-ops on a deferred device 182 // The following methods are no-ops on a deferred device
183 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) 183 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE {
184 SK_OVERRIDE 184 return false;
185 {return false;} 185 }
186 186
187 // None of the following drawing methods should ever get called on the 187 // None of the following drawing methods should ever get called on the
188 // deferred device 188 // deferred device
189 virtual void clear(SkColor color) SK_OVERRIDE 189 virtual void clear(SkColor color) SK_OVERRIDE
190 {SkASSERT(0);} 190 {SkASSERT(0);}
191 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE 191 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE
192 {SkASSERT(0);} 192 {SkASSERT(0);}
193 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, 193 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
194 size_t count, const SkPoint[], 194 size_t count, const SkPoint[],
195 const SkPaint& paint) SK_OVERRIDE 195 const SkPaint& paint) SK_OVERRIDE
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 const SkPath& path, 227 const SkPath& path,
228 const SkMatrix* matrix) SK_OVERRIDE 228 const SkMatrix* matrix) SK_OVERRIDE
229 {SkASSERT(0);} 229 {SkASSERT(0);}
230 #endif 230 #endif
231 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, 231 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode,
232 int vertexCount, const SkPoint verts[], 232 int vertexCount, const SkPoint verts[],
233 const SkPoint texs[], const SkColor colors[], 233 const SkPoint texs[], const SkColor colors[],
234 SkXfermode* xmode, const uint16_t indices[], 234 SkXfermode* xmode, const uint16_t indices[],
235 int indexCount, const SkPaint& paint) SK_OVERRID E 235 int indexCount, const SkPaint& paint) SK_OVERRID E
236 {SkASSERT(0);} 236 {SkASSERT(0);}
237 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, 237 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
238 const SkPaint&) SK_OVERRIDE 238 const SkPaint&) SK_OVERRIDE
239 {SkASSERT(0);} 239 {SkASSERT(0);}
240 private: 240 private:
241 virtual void flush() SK_OVERRIDE; 241 virtual void flush() SK_OVERRIDE;
242 242
243 void beginRecording(); 243 void beginRecording();
244 void init(); 244 void init();
245 void aboutToDraw(); 245 void aboutToDraw();
246 void prepareForImmediatePixelWrite(); 246 void prepareForImmediatePixelWrite();
247 247
248 DeferredPipeController fPipeController; 248 DeferredPipeController fPipeController;
249 SkGPipeWriter fPipeWriter; 249 SkGPipeWriter fPipeWriter;
250 SkCanvas* fImmediateCanvas; 250 SkCanvas* fImmediateCanvas;
251 SkCanvas* fRecordingCanvas; 251 SkCanvas* fRecordingCanvas;
252 SkSurface* fSurface; 252 SkSurface* fSurface;
253 SkDeferredCanvas::NotificationClient* fNotificationClient; 253 SkDeferredCanvas::NotificationClient* fNotificationClient;
254 bool fFreshFrame; 254 bool fFreshFrame;
255 bool fCanDiscardCanvasContents; 255 bool fCanDiscardCanvasContents;
256 size_t fMaxRecordingStorageBytes; 256 size_t fMaxRecordingStorageBytes;
257 size_t fPreviousStorageAllocated; 257 size_t fPreviousStorageAllocated;
258 size_t fBitmapSizeThreshold; 258 size_t fBitmapSizeThreshold;
259 }; 259 };
260 260
261 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) 261 DeferredDevice::DeferredDevice(SkBaseDevice* immediateDevice)
262 : SkDevice(SkBitmap::kNo_Config, 262 : SkBitmapDevice(SkBitmap::kNo_Config,
263 immediateDevice->width(), immediateDevice->height(), 263 immediateDevice->width(), immediateDevice->height(),
264 immediateDevice->isOpaque(), 264 immediateDevice->isOpaque(),
265 immediateDevice->getDeviceProperties()) { 265 immediateDevice->getDeviceProperties()) {
266 fSurface = NULL; 266 fSurface = NULL;
267 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); 267 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice));
268 fPipeController.setPlaybackCanvas(fImmediateCanvas); 268 fPipeController.setPlaybackCanvas(fImmediateCanvas);
269 this->init(); 269 this->init();
270 } 270 }
271 271
272 DeferredDevice::DeferredDevice(SkSurface* surface) 272 DeferredDevice::DeferredDevice(SkSurface* surface)
273 : SkDevice(SkBitmap::kNo_Config, 273 : SkBitmapDevice(SkBitmap::kNo_Config,
274 surface->getCanvas()->getDevice()->width(), 274 surface->getCanvas()->getDevice()->width(),
275 surface->getCanvas()->getDevice()->height(), 275 surface->getCanvas()->getDevice()->height(),
276 surface->getCanvas()->getDevice()->isOpaque(), 276 surface->getCanvas()->getDevice()->isOpaque(),
277 surface->getCanvas()->getDevice()->getDeviceProperties()) { 277 surface->getCanvas()->getDevice()->getDeviceProperties()) {
278 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; 278 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
279 fNotificationClient = NULL; 279 fNotificationClient = NULL;
280 fImmediateCanvas = NULL; 280 fImmediateCanvas = NULL;
281 fSurface = NULL; 281 fSurface = NULL;
282 this->setSurface(surface); 282 this->setSurface(surface);
283 this->init(); 283 this->init();
284 } 284 }
285 285
286 void DeferredDevice::setSurface(SkSurface* surface) { 286 void DeferredDevice::setSurface(SkSurface* surface) {
287 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); 287 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas());
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) { 485 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) {
486 prepareForImmediatePixelWrite(); 486 prepareForImmediatePixelWrite();
487 fImmediateCanvas->drawSprite(bitmap, x, y, &paint); 487 fImmediateCanvas->drawSprite(bitmap, x, y, &paint);
488 } else { 488 } else {
489 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint); 489 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint);
490 this->recordedDrawCommand(); 490 this->recordedDrawCommand();
491 491
492 } 492 }
493 } 493 }
494 494
495 const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) { 495 const SkBitmap& DeferredDevice::onAccessBitmap() {
496 this->flushPendingCommands(kNormal_PlaybackMode); 496 this->flushPendingCommands(kNormal_PlaybackMode);
497 return immediateDevice()->accessBitmap(false); 497 return immediateDevice()->accessBitmap(false);
498 } 498 }
499 499
500 SkDevice* DeferredDevice::onCreateCompatibleDevice( 500 SkBaseDevice* DeferredDevice::onCreateCompatibleDevice(
501 SkBitmap::Config config, int width, int height, bool isOpaque, 501 SkBitmap::Config config, int width, int height, bool isOpaque,
502 Usage usage) { 502 Usage usage) {
503 503
504 // Save layer usage not supported, and not required by SkDeferredCanvas. 504 // Save layer usage not supported, and not required by SkDeferredCanvas.
505 SkASSERT(usage != kSaveLayer_Usage); 505 SkASSERT(usage != kSaveLayer_Usage);
506 // Create a compatible non-deferred device. 506 // Create a compatible non-deferred device.
507 // We do not create a deferred device because we know the new device 507 // We do not create a deferred device because we know the new device
508 // will not be used with a deferred canvas (there is no API for that). 508 // will not be used with a deferred canvas (there is no API for that).
509 // And connecting a DeferredDevice to non-deferred canvas can result 509 // And connecting a DeferredDevice to non-deferred canvas can result
510 // in unpredictable behavior. 510 // in unpredictable behavior.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 548 }
549 549
550 SkDeferredCanvas* fCanvas; 550 SkDeferredCanvas* fCanvas;
551 }; 551 };
552 552
553 SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { 553 SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) {
554 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surf ace))); 554 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surf ace)));
555 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); 555 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice));
556 } 556 }
557 557
558 SkDeferredCanvas* SkDeferredCanvas::Create(SkDevice* device) { 558 SkDeferredCanvas* SkDeferredCanvas::Create(SkBaseDevice* device) {
559 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (devi ce))); 559 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (devi ce)));
560 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); 560 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice));
561 } 561 }
562 562
563 SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) { 563 SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) {
564 this->init(); 564 this->init();
565 } 565 }
566 566
567 void SkDeferredCanvas::init() { 567 void SkDeferredCanvas::init() {
568 fDeferredDrawing = true; // On by default 568 fDeferredDrawing = true; // On by default
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 1003 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
1004 this->drawingCanvas()->setDrawFilter(filter); 1004 this->drawingCanvas()->setDrawFilter(filter);
1005 this->INHERITED::setDrawFilter(filter); 1005 this->INHERITED::setDrawFilter(filter);
1006 this->recordedDrawCommand(); 1006 this->recordedDrawCommand();
1007 return filter; 1007 return filter;
1008 } 1008 }
1009 1009
1010 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 1010 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
1011 return this->drawingCanvas(); 1011 return this->drawingCanvas();
1012 } 1012 }
OLDNEW
« no previous file with comments | « src/pipe/utils/SamplePipeControllers.cpp ('k') | src/utils/SkPictureUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698