blob: cc7011e683702cb0a41cadf28b1ab709b8288ed9 [file] [log] [blame]
junov@google.com4370aed2012-01-18 16:21:08 +00001
2/*
junov@chromium.orgbaa02202013-01-24 14:38:23 +00003 * Copyright 2013 Google Inc.
junov@google.com4370aed2012-01-18 16:21:08 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SkDeferredCanvas.h"
10
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000011#include "SkBitmapDevice.h"
junov@chromium.org88e29142012-08-07 16:48:22 +000012#include "SkChunkAlloc.h"
13#include "SkColorFilter.h"
junov@chromium.org88e29142012-08-07 16:48:22 +000014#include "SkDrawFilter.h"
15#include "SkGPipe.h"
junov@google.com4370aed2012-01-18 16:21:08 +000016#include "SkPaint.h"
junov@chromium.orgbaa02202013-01-24 14:38:23 +000017#include "SkPaintPriv.h"
reed@google.com4ed0fb72012-12-12 20:48:18 +000018#include "SkRRect.h"
junov@google.com4370aed2012-01-18 16:21:08 +000019#include "SkShader.h"
junov@chromium.org67d74222013-04-12 13:33:01 +000020#include "SkSurface.h"
junov@google.com4370aed2012-01-18 16:21:08 +000021
junov@chromium.orgbfeddae2012-07-23 13:35:14 +000022enum {
23 // Deferred canvas will auto-flush when recording reaches this limit
24 kDefaultMaxRecordingStorageBytes = 64*1024*1024,
reed@google.com140d7282013-01-07 20:25:04 +000025 kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature
junov@chromium.orgbfeddae2012-07-23 13:35:14 +000026};
27
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +000028enum PlaybackMode {
29 kNormal_PlaybackMode,
30 kSilent_PlaybackMode,
31};
32
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000033static bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint,
sugoi@google.com7775fd52012-11-21 15:47:04 +000034 size_t bitmapSizeThreshold) {
35 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
36 (bitmap->getSize() > bitmapSizeThreshold))) {
junov@chromium.org10f7f972012-07-31 21:01:51 +000037 return true;
38 }
39 if (paint) {
40 SkShader* shader = paint->getShader();
41 // Here we detect the case where the shader is an SkBitmapProcShader
42 // with a gpu texture attached. Checking this without RTTI
43 // requires making the assumption that only gradient shaders
44 // and SkBitmapProcShader implement asABitmap(). The following
45 // code may need to be revised if that assumption is ever broken.
46 if (shader && !shader->asAGradient(NULL)) {
47 SkBitmap bm;
rmistry@google.comd6176b02012-08-23 18:14:13 +000048 if (shader->asABitmap(&bm, NULL, NULL) &&
junov@chromium.org10f7f972012-07-31 21:01:51 +000049 NULL != bm.getTexture()) {
50 return true;
51 }
52 }
53 }
54 return false;
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +000055}
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +000056
junov@chromium.org88e29142012-08-07 16:48:22 +000057//-----------------------------------------------------------------------------
58// DeferredPipeController
59//-----------------------------------------------------------------------------
60
61class DeferredPipeController : public SkGPipeController {
62public:
63 DeferredPipeController();
64 void setPlaybackCanvas(SkCanvas*);
65 virtual ~DeferredPipeController();
66 virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE;
67 virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
junov@chromium.orgfb103892012-09-20 19:35:43 +000068 void playback(bool silent);
junov@chromium.orga38dfb62012-09-20 22:10:33 +000069 bool hasPendingCommands() const { return fAllocator.blockCount() != 0; }
junov@chromium.org88e29142012-08-07 16:48:22 +000070 size_t storageAllocatedForRecording() const { return fAllocator.totalCapacity(); }
71private:
72 enum {
73 kMinBlockSize = 4096
74 };
75 struct PipeBlock {
76 PipeBlock(void* block, size_t size) { fBlock = block, fSize = size; }
77 void* fBlock;
78 size_t fSize;
79 };
80 void* fBlock;
81 size_t fBytesWritten;
82 SkChunkAlloc fAllocator;
83 SkTDArray<PipeBlock> fBlockList;
84 SkGPipeReader fReader;
85};
86
87DeferredPipeController::DeferredPipeController() :
88 fAllocator(kMinBlockSize) {
89 fBlock = NULL;
90 fBytesWritten = 0;
91}
92
93DeferredPipeController::~DeferredPipeController() {
94 fAllocator.reset();
95}
96
97void DeferredPipeController::setPlaybackCanvas(SkCanvas* canvas) {
98 fReader.setCanvas(canvas);
99}
100
101void* DeferredPipeController::requestBlock(size_t minRequest, size_t *actual) {
102 if (fBlock) {
103 // Save the previous block for later
104 PipeBlock previousBloc(fBlock, fBytesWritten);
105 fBlockList.push(previousBloc);
106 }
robertphillips@google.comadacc702013-10-14 21:53:24 +0000107 size_t blockSize = SkTMax<size_t>(minRequest, kMinBlockSize);
junov@chromium.org88e29142012-08-07 16:48:22 +0000108 fBlock = fAllocator.allocThrow(blockSize);
109 fBytesWritten = 0;
110 *actual = blockSize;
111 return fBlock;
112}
113
114void DeferredPipeController::notifyWritten(size_t bytes) {
115 fBytesWritten += bytes;
116}
117
junov@chromium.orgfb103892012-09-20 19:35:43 +0000118void DeferredPipeController::playback(bool silent) {
119 uint32_t flags = silent ? SkGPipeReader::kSilent_PlaybackFlag : 0;
junov@chromium.org88e29142012-08-07 16:48:22 +0000120 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) {
junov@chromium.orgfb103892012-09-20 19:35:43 +0000121 fReader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock].fSize,
122 flags);
junov@chromium.org88e29142012-08-07 16:48:22 +0000123 }
124 fBlockList.reset();
125
126 if (fBlock) {
junov@chromium.orgfb103892012-09-20 19:35:43 +0000127 fReader.playback(fBlock, fBytesWritten, flags);
junov@chromium.org88e29142012-08-07 16:48:22 +0000128 fBlock = NULL;
129 }
130
131 // Release all allocated blocks
132 fAllocator.reset();
133}
134
junov@chromium.org88e29142012-08-07 16:48:22 +0000135//-----------------------------------------------------------------------------
reed@google.com9c135db2014-03-12 18:28:35 +0000136// SkDeferredDevice
junov@chromium.org88e29142012-08-07 16:48:22 +0000137//-----------------------------------------------------------------------------
reed@google.com9c135db2014-03-12 18:28:35 +0000138class SkDeferredDevice : public SkBaseDevice {
junov@chromium.org88e29142012-08-07 16:48:22 +0000139public:
reed@google.com9c135db2014-03-12 18:28:35 +0000140 explicit SkDeferredDevice(SkSurface* surface);
141 ~SkDeferredDevice();
junov@chromium.org88e29142012-08-07 16:48:22 +0000142
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000143 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificationClient);
junov@chromium.org88e29142012-08-07 16:48:22 +0000144 SkCanvas* recordingCanvas();
145 SkCanvas* immediateCanvas() const {return fImmediateCanvas;}
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000146 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();}
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000147 SkImage* newImageSnapshot();
junov@chromium.org7070f762013-05-24 17:13:00 +0000148 void setSurface(SkSurface* surface);
junov@chromium.org88e29142012-08-07 16:48:22 +0000149 bool isFreshFrame();
junov@chromium.orga38dfb62012-09-20 22:10:33 +0000150 bool hasPendingCommands();
junov@chromium.org88e29142012-08-07 16:48:22 +0000151 size_t storageAllocatedForRecording() const;
152 size_t freeMemoryIfPossible(size_t bytesToFree);
sugoi@google.com7775fd52012-11-21 15:47:04 +0000153 size_t getBitmapSizeThreshold() const;
154 void setBitmapSizeThreshold(size_t sizeThreshold);
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000155 void flushPendingCommands(PlaybackMode);
junov@chromium.org0a67f962012-09-19 22:48:34 +0000156 void skipPendingCommands();
junov@chromium.org88e29142012-08-07 16:48:22 +0000157 void setMaxRecordingStorage(size_t);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000158 void recordedDrawCommand();
junov@chromium.org88e29142012-08-07 16:48:22 +0000159
junov@chromium.org88e29142012-08-07 16:48:22 +0000160 virtual int width() const SK_OVERRIDE;
161 virtual int height() const SK_OVERRIDE;
reed@google.com284a84d2014-02-14 15:23:15 +0000162 virtual SkBitmap::Config config() const SK_OVERRIDE;
163 virtual bool isOpaque() const SK_OVERRIDE;
164 virtual SkImageInfo imageInfo() const SK_OVERRIDE;
165
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +0000166 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
junov@chromium.org88e29142012-08-07 16:48:22 +0000167
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000168 virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
junov@chromium.org88e29142012-08-07 16:48:22 +0000169
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000170#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
junov@chromium.org88e29142012-08-07 16:48:22 +0000171 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
172 SkCanvas::Config8888 config8888) SK_OVERRIDE;
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000173#endif
reed@google.com76f10a32014-02-05 15:32:21 +0000174 virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
175
junov@chromium.org88e29142012-08-07 16:48:22 +0000176protected:
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000177 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE;
junov@chromium.org88e29142012-08-07 16:48:22 +0000178 virtual bool onReadPixels(const SkBitmap& bitmap,
179 int x, int y,
180 SkCanvas::Config8888 config8888) SK_OVERRIDE;
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000181 virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y) SK_OVERRIDE;
junov@chromium.org88e29142012-08-07 16:48:22 +0000182
183 // The following methods are no-ops on a deferred device
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000184 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE {
185 return false;
186 }
junov@chromium.org88e29142012-08-07 16:48:22 +0000187
188 // None of the following drawing methods should ever get called on the
189 // deferred device
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000190 virtual void clear(SkColor color) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000191 {SkASSERT(0);}
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000192 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000193 {SkASSERT(0);}
194 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
195 size_t count, const SkPoint[],
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000196 const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000197 {SkASSERT(0);}
198 virtual void drawRect(const SkDraw&, const SkRect& r,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000199 const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000200 {SkASSERT(0);}
reed@google.com284a84d2014-02-14 15:23:15 +0000201 virtual void drawOval(const SkDraw&, const SkRect&, const SkPaint&) SK_OVERRIDE
202 {SkASSERT(0);}
scroggo@google.comcac8d012013-11-12 17:10:02 +0000203 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
204 const SkPaint& paint) SK_OVERRIDE
reed@google.com284a84d2014-02-14 15:23:15 +0000205 {SkASSERT(0);}
junov@chromium.org88e29142012-08-07 16:48:22 +0000206 virtual void drawPath(const SkDraw&, const SkPath& path,
207 const SkPaint& paint,
208 const SkMatrix* prePathMatrix = NULL,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000209 bool pathIsMutable = false) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000210 {SkASSERT(0);}
211 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000212 const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000213 {SkASSERT(0);}
reed@google.com284a84d2014-02-14 15:23:15 +0000214 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*,
215 const SkRect&, const SkPaint&,
216 SkCanvas::DrawBitmapRectFlags) SK_OVERRIDE
217 {SkASSERT(0);}
junov@chromium.org88e29142012-08-07 16:48:22 +0000218 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000219 int x, int y, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000220 {SkASSERT(0);}
221 virtual void drawText(const SkDraw&, const void* text, size_t len,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000222 SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000223 {SkASSERT(0);}
224 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
225 const SkScalar pos[], SkScalar constY,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000226 int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000227 {SkASSERT(0);}
228 virtual void drawTextOnPath(const SkDraw&, const void* text,
229 size_t len, const SkPath& path,
230 const SkMatrix* matrix,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000231 const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000232 {SkASSERT(0);}
junov@chromium.org88e29142012-08-07 16:48:22 +0000233 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode,
234 int vertexCount, const SkPoint verts[],
235 const SkPoint texs[], const SkColor colors[],
236 SkXfermode* xmode, const uint16_t indices[],
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000237 int indexCount, const SkPaint& paint) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000238 {SkASSERT(0);}
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000239 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000240 const SkPaint&) SK_OVERRIDE
junov@chromium.org88e29142012-08-07 16:48:22 +0000241 {SkASSERT(0);}
reed@google.com284a84d2014-02-14 15:23:15 +0000242
243 virtual void lockPixels() SK_OVERRIDE {}
244 virtual void unlockPixels() SK_OVERRIDE {}
245
246 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE {
247 return false;
248 }
249 virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE {
250 return false;
251 }
252 virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
253 const SkMatrix&, SkBitmap*, SkIPoint*) SK_OVERRIDE {
254 return false;
255 }
256
junov@chromium.org88e29142012-08-07 16:48:22 +0000257private:
commit-bot@chromium.org3e2ea252013-07-23 11:28:45 +0000258 virtual void flush() SK_OVERRIDE;
reed@google.com284a84d2014-02-14 15:23:15 +0000259 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE {}
junov@chromium.org88e29142012-08-07 16:48:22 +0000260
junov@chromium.org88e29142012-08-07 16:48:22 +0000261 void beginRecording();
junov@chromium.org67d74222013-04-12 13:33:01 +0000262 void init();
junov@chromium.org44324fa2013-08-02 15:36:02 +0000263 void aboutToDraw();
264 void prepareForImmediatePixelWrite();
junov@chromium.org88e29142012-08-07 16:48:22 +0000265
266 DeferredPipeController fPipeController;
267 SkGPipeWriter fPipeWriter;
junov@chromium.org88e29142012-08-07 16:48:22 +0000268 SkCanvas* fImmediateCanvas;
269 SkCanvas* fRecordingCanvas;
junov@chromium.org67d74222013-04-12 13:33:01 +0000270 SkSurface* fSurface;
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000271 SkDeferredCanvas::NotificationClient* fNotificationClient;
junov@chromium.org88e29142012-08-07 16:48:22 +0000272 bool fFreshFrame;
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000273 bool fCanDiscardCanvasContents;
junov@chromium.org88e29142012-08-07 16:48:22 +0000274 size_t fMaxRecordingStorageBytes;
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000275 size_t fPreviousStorageAllocated;
sugoi@google.com7775fd52012-11-21 15:47:04 +0000276 size_t fBitmapSizeThreshold;
junov@chromium.org88e29142012-08-07 16:48:22 +0000277};
278
reed@google.com9c135db2014-03-12 18:28:35 +0000279SkDeferredDevice::SkDeferredDevice(SkSurface* surface) {
junov@chromium.org67d74222013-04-12 13:33:01 +0000280 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
281 fNotificationClient = NULL;
junov@chromium.org7070f762013-05-24 17:13:00 +0000282 fImmediateCanvas = NULL;
283 fSurface = NULL;
284 this->setSurface(surface);
junov@chromium.org67d74222013-04-12 13:33:01 +0000285 this->init();
286}
287
reed@google.com9c135db2014-03-12 18:28:35 +0000288void SkDeferredDevice::setSurface(SkSurface* surface) {
junov@chromium.org7070f762013-05-24 17:13:00 +0000289 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas());
290 SkRefCnt_SafeAssign(fSurface, surface);
291 fPipeController.setPlaybackCanvas(fImmediateCanvas);
292}
293
reed@google.com9c135db2014-03-12 18:28:35 +0000294void SkDeferredDevice::init() {
junov@chromium.org67d74222013-04-12 13:33:01 +0000295 fRecordingCanvas = NULL;
296 fFreshFrame = true;
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000297 fCanDiscardCanvasContents = false;
junov@chromium.org67d74222013-04-12 13:33:01 +0000298 fPreviousStorageAllocated = 0;
299 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
300 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
301 fNotificationClient = NULL;
junov@chromium.org88e29142012-08-07 16:48:22 +0000302 this->beginRecording();
303}
304
reed@google.com9c135db2014-03-12 18:28:35 +0000305SkDeferredDevice::~SkDeferredDevice() {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000306 this->flushPendingCommands(kSilent_PlaybackMode);
junov@chromium.org88e29142012-08-07 16:48:22 +0000307 SkSafeUnref(fImmediateCanvas);
junov@chromium.org67d74222013-04-12 13:33:01 +0000308 SkSafeUnref(fSurface);
junov@chromium.org88e29142012-08-07 16:48:22 +0000309}
310
reed@google.com9c135db2014-03-12 18:28:35 +0000311void SkDeferredDevice::setMaxRecordingStorage(size_t maxStorage) {
junov@chromium.org88e29142012-08-07 16:48:22 +0000312 fMaxRecordingStorageBytes = maxStorage;
313 this->recordingCanvas(); // Accessing the recording canvas applies the new limit.
314}
315
reed@google.com9c135db2014-03-12 18:28:35 +0000316void SkDeferredDevice::beginRecording() {
junov@chromium.orga8db8fe2012-08-15 19:49:22 +0000317 SkASSERT(NULL == fRecordingCanvas);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000318 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0,
junov@chromium.org9becf002013-04-15 18:15:23 +0000319 immediateDevice()->width(), immediateDevice()->height());
junov@chromium.org88e29142012-08-07 16:48:22 +0000320}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000321
reed@google.com9c135db2014-03-12 18:28:35 +0000322void SkDeferredDevice::setNotificationClient(
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000323 SkDeferredCanvas::NotificationClient* notificationClient) {
junov@chromium.org52805482012-08-20 14:25:04 +0000324 fNotificationClient = notificationClient;
junov@chromium.org88e29142012-08-07 16:48:22 +0000325}
326
reed@google.com9c135db2014-03-12 18:28:35 +0000327void SkDeferredDevice::skipPendingCommands() {
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000328 if (!fRecordingCanvas->isDrawingToLayer()) {
329 fCanDiscardCanvasContents = true;
330 if (fPipeController.hasPendingCommands()) {
331 fFreshFrame = true;
332 flushPendingCommands(kSilent_PlaybackMode);
333 if (fNotificationClient) {
334 fNotificationClient->skippedPendingDrawCommands();
335 }
junov@google.com52a00ca2012-10-01 15:27:14 +0000336 }
junov@chromium.org88e29142012-08-07 16:48:22 +0000337 }
338}
339
reed@google.com9c135db2014-03-12 18:28:35 +0000340bool SkDeferredDevice::isFreshFrame() {
junov@chromium.org88e29142012-08-07 16:48:22 +0000341 bool ret = fFreshFrame;
342 fFreshFrame = false;
343 return ret;
344}
345
reed@google.com9c135db2014-03-12 18:28:35 +0000346bool SkDeferredDevice::hasPendingCommands() {
junov@chromium.orga38dfb62012-09-20 22:10:33 +0000347 return fPipeController.hasPendingCommands();
348}
349
reed@google.com9c135db2014-03-12 18:28:35 +0000350void SkDeferredDevice::aboutToDraw()
junov@chromium.org44324fa2013-08-02 15:36:02 +0000351{
352 if (NULL != fNotificationClient) {
353 fNotificationClient->prepareForDraw();
354 }
355 if (fCanDiscardCanvasContents) {
356 if (NULL != fSurface) {
357 fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
358 }
skia.committer@gmail.comea4b7972013-08-06 07:01:27 +0000359 fCanDiscardCanvasContents = false;
junov@chromium.org44324fa2013-08-02 15:36:02 +0000360 }
361}
362
reed@google.com9c135db2014-03-12 18:28:35 +0000363void SkDeferredDevice::flushPendingCommands(PlaybackMode playbackMode) {
junov@chromium.orga38dfb62012-09-20 22:10:33 +0000364 if (!fPipeController.hasPendingCommands()) {
junov@chromium.org88e29142012-08-07 16:48:22 +0000365 return;
366 }
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000367 if (playbackMode == kNormal_PlaybackMode) {
junov@chromium.org44324fa2013-08-02 15:36:02 +0000368 aboutToDraw();
junov@chromium.org88e29142012-08-07 16:48:22 +0000369 }
junov@chromium.org88e29142012-08-07 16:48:22 +0000370 fPipeWriter.flushRecording(true);
junov@chromium.orgd4501a02012-10-30 19:05:17 +0000371 fPipeController.playback(kSilent_PlaybackMode == playbackMode);
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000372 if (playbackMode == kNormal_PlaybackMode && fNotificationClient) {
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000373 fNotificationClient->flushedDrawCommands();
374 }
375 fPreviousStorageAllocated = storageAllocatedForRecording();
junov@chromium.org88e29142012-08-07 16:48:22 +0000376}
377
reed@google.com9c135db2014-03-12 18:28:35 +0000378void SkDeferredDevice::flush() {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000379 this->flushPendingCommands(kNormal_PlaybackMode);
junov@chromium.org88e29142012-08-07 16:48:22 +0000380 fImmediateCanvas->flush();
381}
382
reed@google.com9c135db2014-03-12 18:28:35 +0000383size_t SkDeferredDevice::freeMemoryIfPossible(size_t bytesToFree) {
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000384 size_t val = fPipeWriter.freeMemoryIfPossible(bytesToFree);
385 fPreviousStorageAllocated = storageAllocatedForRecording();
386 return val;
junov@chromium.org88e29142012-08-07 16:48:22 +0000387}
388
reed@google.com9c135db2014-03-12 18:28:35 +0000389size_t SkDeferredDevice::getBitmapSizeThreshold() const {
sugoi@google.com7775fd52012-11-21 15:47:04 +0000390 return fBitmapSizeThreshold;
391}
392
reed@google.com9c135db2014-03-12 18:28:35 +0000393void SkDeferredDevice::setBitmapSizeThreshold(size_t sizeThreshold) {
sugoi@google.com7775fd52012-11-21 15:47:04 +0000394 fBitmapSizeThreshold = sizeThreshold;
395}
396
reed@google.com9c135db2014-03-12 18:28:35 +0000397size_t SkDeferredDevice::storageAllocatedForRecording() const {
junov@chromium.org88e29142012-08-07 16:48:22 +0000398 return (fPipeController.storageAllocatedForRecording()
399 + fPipeWriter.storageAllocatedForRecording());
400}
401
reed@google.com9c135db2014-03-12 18:28:35 +0000402void SkDeferredDevice::recordedDrawCommand() {
junov@chromium.org88e29142012-08-07 16:48:22 +0000403 size_t storageAllocated = this->storageAllocatedForRecording();
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000404
junov@chromium.org88e29142012-08-07 16:48:22 +0000405 if (storageAllocated > fMaxRecordingStorageBytes) {
406 // First, attempt to reduce cache without flushing
407 size_t tryFree = storageAllocated - fMaxRecordingStorageBytes;
408 if (this->freeMemoryIfPossible(tryFree) < tryFree) {
409 // Flush is necessary to free more space.
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000410 this->flushPendingCommands(kNormal_PlaybackMode);
junov@chromium.org88e29142012-08-07 16:48:22 +0000411 // Free as much as possible to avoid oscillating around fMaxRecordingStorageBytes
412 // which could cause a high flushing frequency.
bsalomon@google.com100abf42012-09-05 17:40:04 +0000413 this->freeMemoryIfPossible(~0U);
junov@chromium.org88e29142012-08-07 16:48:22 +0000414 }
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000415 storageAllocated = this->storageAllocatedForRecording();
junov@chromium.org88e29142012-08-07 16:48:22 +0000416 }
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000417
rmistry@google.comd6176b02012-08-23 18:14:13 +0000418 if (fNotificationClient &&
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000419 storageAllocated != fPreviousStorageAllocated) {
420 fPreviousStorageAllocated = storageAllocated;
421 fNotificationClient->storageAllocatedForRecordingChanged(storageAllocated);
422 }
423}
424
reed@google.com9c135db2014-03-12 18:28:35 +0000425SkCanvas* SkDeferredDevice::recordingCanvas() {
junov@chromium.org88e29142012-08-07 16:48:22 +0000426 return fRecordingCanvas;
427}
428
reed@google.com9c135db2014-03-12 18:28:35 +0000429SkImage* SkDeferredDevice::newImageSnapshot() {
junov@chromium.org67d74222013-04-12 13:33:01 +0000430 this->flush();
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000431 return fSurface ? fSurface->newImageSnapshot() : NULL;
junov@chromium.org67d74222013-04-12 13:33:01 +0000432}
433
reed@google.com9c135db2014-03-12 18:28:35 +0000434int SkDeferredDevice::width() const {
junov@chromium.org9becf002013-04-15 18:15:23 +0000435 return immediateDevice()->width();
junov@chromium.org88e29142012-08-07 16:48:22 +0000436}
437
reed@google.com9c135db2014-03-12 18:28:35 +0000438int SkDeferredDevice::height() const {
junov@chromium.org9becf002013-04-15 18:15:23 +0000439 return immediateDevice()->height();
junov@chromium.org88e29142012-08-07 16:48:22 +0000440}
441
reed@google.com9c135db2014-03-12 18:28:35 +0000442SkBitmap::Config SkDeferredDevice::config() const {
reed@google.com284a84d2014-02-14 15:23:15 +0000443 return immediateDevice()->config();
444}
445
reed@google.com9c135db2014-03-12 18:28:35 +0000446bool SkDeferredDevice::isOpaque() const {
reed@google.com284a84d2014-02-14 15:23:15 +0000447 return immediateDevice()->isOpaque();
448}
449
reed@google.com9c135db2014-03-12 18:28:35 +0000450SkImageInfo SkDeferredDevice::imageInfo() const {
reed@google.com284a84d2014-02-14 15:23:15 +0000451 return immediateDevice()->imageInfo();
452}
453
reed@google.com9c135db2014-03-12 18:28:35 +0000454GrRenderTarget* SkDeferredDevice::accessRenderTarget() {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000455 this->flushPendingCommands(kNormal_PlaybackMode);
junov@chromium.org9becf002013-04-15 18:15:23 +0000456 return immediateDevice()->accessRenderTarget();
junov@chromium.org88e29142012-08-07 16:48:22 +0000457}
458
reed@google.com9c135db2014-03-12 18:28:35 +0000459void SkDeferredDevice::prepareForImmediatePixelWrite() {
junov@chromium.org44324fa2013-08-02 15:36:02 +0000460 // The purpose of the following code is to make sure commands are flushed, that
461 // aboutToDraw() is called and that notifyContentWillChange is called, without
462 // calling anything redundantly.
463 if (fPipeController.hasPendingCommands()) {
464 this->flushPendingCommands(kNormal_PlaybackMode);
465 } else {
466 bool mustNotifyDirectly = !fCanDiscardCanvasContents;
467 this->aboutToDraw();
468 if (mustNotifyDirectly) {
469 fSurface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode);
470 }
471 }
472
473 fImmediateCanvas->flush();
474}
475
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000476#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
reed@google.com9c135db2014-03-12 18:28:35 +0000477void SkDeferredDevice::writePixels(const SkBitmap& bitmap, int x, int y,
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000478 SkCanvas::Config8888 config8888) {
junov@chromium.org88e29142012-08-07 16:48:22 +0000479
480 if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() &&
481 (y + bitmap.height()) >= height()) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000482 this->skipPendingCommands();
junov@chromium.org88e29142012-08-07 16:48:22 +0000483 }
484
485 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
486 SkCanvas::kNative_Premul_Config8888 != config8888 &&
487 kPMColorAlias != config8888) {
488 //Special case config: no deferral
junov@chromium.org44324fa2013-08-02 15:36:02 +0000489 prepareForImmediatePixelWrite();
junov@chromium.org9becf002013-04-15 18:15:23 +0000490 immediateDevice()->writePixels(bitmap, x, y, config8888);
junov@chromium.org88e29142012-08-07 16:48:22 +0000491 return;
492 }
493
494 SkPaint paint;
495 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
sugoi@google.com7775fd52012-11-21 15:47:04 +0000496 if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) {
junov@chromium.org44324fa2013-08-02 15:36:02 +0000497 prepareForImmediatePixelWrite();
junov@chromium.org88e29142012-08-07 16:48:22 +0000498 fImmediateCanvas->drawSprite(bitmap, x, y, &paint);
499 } else {
500 this->recordingCanvas()->drawSprite(bitmap, x, y, &paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000501 this->recordedDrawCommand();
502
junov@chromium.org88e29142012-08-07 16:48:22 +0000503 }
504}
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000505#endif
506
reed@google.com9c135db2014-03-12 18:28:35 +0000507bool SkDeferredDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes,
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000508 int x, int y) {
509 SkASSERT(x >= 0 && y >= 0);
510 SkASSERT(x + info.width() <= width());
511 SkASSERT(y + info.height() <= height());
512
513 this->flushPendingCommands(kNormal_PlaybackMode);
514
515 const SkImageInfo deviceInfo = this->imageInfo();
516 if (info.width() == deviceInfo.width() && info.height() == deviceInfo.height()) {
517 this->skipPendingCommands();
518 }
skia.committer@gmail.come62513f2014-03-08 03:02:06 +0000519
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000520 this->prepareForImmediatePixelWrite();
521 return immediateDevice()->onWritePixels(info, pixels, rowBytes, x, y);
522}
junov@chromium.org88e29142012-08-07 16:48:22 +0000523
reed@google.com9c135db2014-03-12 18:28:35 +0000524const SkBitmap& SkDeferredDevice::onAccessBitmap() {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000525 this->flushPendingCommands(kNormal_PlaybackMode);
junov@chromium.org9becf002013-04-15 18:15:23 +0000526 return immediateDevice()->accessBitmap(false);
junov@chromium.org88e29142012-08-07 16:48:22 +0000527}
528
reed@google.com9c135db2014-03-12 18:28:35 +0000529SkBaseDevice* SkDeferredDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
junov@chromium.org88e29142012-08-07 16:48:22 +0000530 // Save layer usage not supported, and not required by SkDeferredCanvas.
531 SkASSERT(usage != kSaveLayer_Usage);
532 // Create a compatible non-deferred device.
junov@chromium.orgb1c725a2013-05-21 20:16:17 +0000533 // We do not create a deferred device because we know the new device
534 // will not be used with a deferred canvas (there is no API for that).
reed@google.com9c135db2014-03-12 18:28:35 +0000535 // And connecting a SkDeferredDevice to non-deferred canvas can result
junov@chromium.orgb1c725a2013-05-21 20:16:17 +0000536 // in unpredictable behavior.
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000537 return immediateDevice()->createCompatibleDevice(info);
junov@chromium.org88e29142012-08-07 16:48:22 +0000538}
539
reed@google.com9c135db2014-03-12 18:28:35 +0000540SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info) {
reed@google.com76f10a32014-02-05 15:32:21 +0000541 return this->immediateDevice()->newSurface(info);
542}
543
reed@google.com9c135db2014-03-12 18:28:35 +0000544bool SkDeferredDevice::onReadPixels(
junov@chromium.org88e29142012-08-07 16:48:22 +0000545 const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000546 this->flushPendingCommands(kNormal_PlaybackMode);
junov@chromium.org88e29142012-08-07 16:48:22 +0000547 return fImmediateCanvas->readPixels(const_cast<SkBitmap*>(&bitmap),
548 x, y, config8888);
549}
550
sugoi@google.com7775fd52012-11-21 15:47:04 +0000551class AutoImmediateDrawIfNeeded {
552public:
553 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap,
554 const SkPaint* paint) {
555 this->init(canvas, bitmap, paint);
556 }
557
558 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) {
559 this->init(canvas, NULL, paint);
560 }
561
562 ~AutoImmediateDrawIfNeeded() {
563 if (fCanvas) {
564 fCanvas->setDeferredDrawing(true);
565 }
566 }
567private:
568 void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint)
569 {
reed@google.com9c135db2014-03-12 18:28:35 +0000570 SkDeferredDevice* device = static_cast<SkDeferredDevice*>(canvas.getDevice());
sugoi@google.com7775fd52012-11-21 15:47:04 +0000571 if (canvas.isDeferredDrawing() && (NULL != device) &&
572 shouldDrawImmediately(bitmap, paint, device->getBitmapSizeThreshold())) {
573 canvas.setDeferredDrawing(false);
574 fCanvas = &canvas;
575 } else {
576 fCanvas = NULL;
577 }
578 }
579
580 SkDeferredCanvas* fCanvas;
581};
junov@chromium.org88e29142012-08-07 16:48:22 +0000582
junov@chromium.org66070a52013-05-28 17:39:08 +0000583SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) {
reed@google.com9c135db2014-03-12 18:28:35 +0000584 SkAutoTUnref<SkDeferredDevice> deferredDevice(SkNEW_ARGS(SkDeferredDevice, (surface)));
junov@chromium.org66070a52013-05-28 17:39:08 +0000585 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice));
586}
587
reed@google.com9c135db2014-03-12 18:28:35 +0000588SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device) {
junov@chromium.org66070a52013-05-28 17:39:08 +0000589 this->init();
590}
junov@chromium.org67d74222013-04-12 13:33:01 +0000591
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000592void SkDeferredCanvas::init() {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000593 fDeferredDrawing = true; // On by default
junov@google.com4370aed2012-01-18 16:21:08 +0000594}
595
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000596void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000597 this->validate();
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000598 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage);
599}
600
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000601size_t SkDeferredCanvas::storageAllocatedForRecording() const {
602 return this->getDeferredDevice()->storageAllocatedForRecording();
603}
604
605size_t SkDeferredCanvas::freeMemoryIfPossible(size_t bytesToFree) {
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000606 return this->getDeferredDevice()->freeMemoryIfPossible(bytesToFree);
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000607}
608
sugoi@google.com7775fd52012-11-21 15:47:04 +0000609void SkDeferredCanvas::setBitmapSizeThreshold(size_t sizeThreshold) {
reed@google.com9c135db2014-03-12 18:28:35 +0000610 SkDeferredDevice* deferredDevice = this->getDeferredDevice();
sugoi@google.com7775fd52012-11-21 15:47:04 +0000611 SkASSERT(deferredDevice);
612 deferredDevice->setBitmapSizeThreshold(sizeThreshold);
613}
614
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000615void SkDeferredCanvas::recordedDrawCommand() {
616 if (fDeferredDrawing) {
617 this->getDeferredDevice()->recordedDrawCommand();
618 }
619}
620
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000621void SkDeferredCanvas::validate() const {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000622 SkASSERT(this->getDevice());
junov@google.com4370aed2012-01-18 16:21:08 +0000623}
624
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000625SkCanvas* SkDeferredCanvas::drawingCanvas() const {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000626 this->validate();
627 return fDeferredDrawing ? this->getDeferredDevice()->recordingCanvas() :
628 this->getDeferredDevice()->immediateCanvas();
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000629}
630
junov@chromium.org88e29142012-08-07 16:48:22 +0000631SkCanvas* SkDeferredCanvas::immediateCanvas() const {
632 this->validate();
633 return this->getDeferredDevice()->immediateCanvas();
634}
635
reed@google.com9c135db2014-03-12 18:28:35 +0000636SkDeferredDevice* SkDeferredCanvas::getDeferredDevice() const {
637 return static_cast<SkDeferredDevice*>(this->getDevice());
junov@google.com4370aed2012-01-18 16:21:08 +0000638}
639
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000640void SkDeferredCanvas::setDeferredDrawing(bool val) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000641 this->validate(); // Must set device before calling this method
junov@google.com4370aed2012-01-18 16:21:08 +0000642 if (val != fDeferredDrawing) {
643 if (fDeferredDrawing) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000644 // Going live.
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000645 this->getDeferredDevice()->flushPendingCommands(kNormal_PlaybackMode);
junov@google.com4370aed2012-01-18 16:21:08 +0000646 }
647 fDeferredDrawing = val;
648 }
649}
650
junov@chromium.org88e29142012-08-07 16:48:22 +0000651bool SkDeferredCanvas::isDeferredDrawing() const {
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +0000652 return fDeferredDrawing;
653}
654
junov@chromium.org88e29142012-08-07 16:48:22 +0000655bool SkDeferredCanvas::isFreshFrame() const {
656 return this->getDeferredDevice()->isFreshFrame();
657}
658
junov@chromium.orga38dfb62012-09-20 22:10:33 +0000659bool SkDeferredCanvas::hasPendingCommands() const {
660 return this->getDeferredDevice()->hasPendingCommands();
661}
662
junov@chromium.orgfb103892012-09-20 19:35:43 +0000663void SkDeferredCanvas::silentFlush() {
664 if (fDeferredDrawing) {
junov@chromium.orgeeaf47f2012-09-20 20:42:44 +0000665 this->getDeferredDevice()->flushPendingCommands(kSilent_PlaybackMode);
junov@chromium.orgfb103892012-09-20 19:35:43 +0000666 }
667}
668
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000669SkDeferredCanvas::~SkDeferredCanvas() {
junov@google.com4370aed2012-01-18 16:21:08 +0000670}
671
junov@chromium.org7070f762013-05-24 17:13:00 +0000672SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) {
reed@google.com9c135db2014-03-12 18:28:35 +0000673 SkDeferredDevice* deferredDevice = this->getDeferredDevice();
junov@chromium.org66070a52013-05-28 17:39:08 +0000674 SkASSERT(NULL != deferredDevice);
675 // By swapping the surface into the existing device, we preserve
676 // all pending commands, which can help to seamlessly recover from
677 // a lost accelerated graphics context.
678 deferredDevice->setSurface(surface);
junov@chromium.org7070f762013-05-24 17:13:00 +0000679 return surface;
680}
681
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000682SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient(
683 NotificationClient* notificationClient) {
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000684
reed@google.com9c135db2014-03-12 18:28:35 +0000685 SkDeferredDevice* deferredDevice = this->getDeferredDevice();
junov@google.com4370aed2012-01-18 16:21:08 +0000686 SkASSERT(deferredDevice);
687 if (deferredDevice) {
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000688 deferredDevice->setNotificationClient(notificationClient);
junov@google.com4370aed2012-01-18 16:21:08 +0000689 }
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000690 return notificationClient;
junov@google.com4370aed2012-01-18 16:21:08 +0000691}
692
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000693SkImage* SkDeferredCanvas::newImageSnapshot() {
reed@google.com9c135db2014-03-12 18:28:35 +0000694 SkDeferredDevice* deferredDevice = this->getDeferredDevice();
junov@chromium.org67d74222013-04-12 13:33:01 +0000695 SkASSERT(deferredDevice);
junov@chromium.org5ee449a2013-04-12 20:20:50 +0000696 return deferredDevice ? deferredDevice->newImageSnapshot() : NULL;
junov@chromium.org67d74222013-04-12 13:33:01 +0000697}
698
junov@google.com4370aed2012-01-18 16:21:08 +0000699bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000700 const SkPaint* paint) const {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000701 SkCanvas* canvas = this->drawingCanvas();
702 SkISize canvasSize = this->getDeviceSize();
junov@google.com4370aed2012-01-18 16:21:08 +0000703 if (rect) {
704 if (!canvas->getTotalMatrix().rectStaysRect()) {
705 return false; // conservative
706 }
707
708 SkRect transformedRect;
709 canvas->getTotalMatrix().mapRect(&transformedRect, *rect);
710
711 if (paint) {
712 SkPaint::Style paintStyle = paint->getStyle();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000713 if (!(paintStyle == SkPaint::kFill_Style ||
junov@google.com4370aed2012-01-18 16:21:08 +0000714 paintStyle == SkPaint::kStrokeAndFill_Style)) {
715 return false;
716 }
717 if (paint->getMaskFilter() || paint->getLooper()
718 || paint->getPathEffect() || paint->getImageFilter()) {
719 return false; // conservative
720 }
721 }
722
723 // The following test holds with AA enabled, and is conservative
724 // by a 0.5 pixel margin with AA disabled
rmistry@google.comd6176b02012-08-23 18:14:13 +0000725 if (transformedRect.fLeft > SkIntToScalar(0) ||
726 transformedRect.fTop > SkIntToScalar(0) ||
junov@chromium.orgb1e218e2012-02-13 22:27:58 +0000727 transformedRect.fRight < SkIntToScalar(canvasSize.fWidth) ||
728 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) {
junov@google.com4370aed2012-01-18 16:21:08 +0000729 return false;
730 }
731 }
732
junov@chromium.org8f0ca062012-12-13 16:30:39 +0000733 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0,
734 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
junov@google.com4370aed2012-01-18 16:21:08 +0000735}
736
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000737void SkDeferredCanvas::willSave(SaveFlags flags) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000738 this->drawingCanvas()->save(flags);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000739 this->recordedDrawCommand();
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000740 this->INHERITED::willSave(flags);
junov@google.com4370aed2012-01-18 16:21:08 +0000741}
742
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000743SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds,
744 const SkPaint* paint, SaveFlags flags) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000745 this->drawingCanvas()->saveLayer(bounds, paint, flags);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000746 this->recordedDrawCommand();
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000747 this->INHERITED::willSaveLayer(bounds, paint, flags);
748 // No need for a full layer.
749 return kNoLayer_SaveLayerStrategy;
junov@google.com4370aed2012-01-18 16:21:08 +0000750}
751
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000752void SkDeferredCanvas::willRestore() {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000753 this->drawingCanvas()->restore();
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000754 this->recordedDrawCommand();
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000755 this->INHERITED::willRestore();
junov@google.com4370aed2012-01-18 16:21:08 +0000756}
757
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000758bool SkDeferredCanvas::isDrawingToLayer() const {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000759 return this->drawingCanvas()->isDrawingToLayer();
junov@google.com4370aed2012-01-18 16:21:08 +0000760}
761
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000762void SkDeferredCanvas::didTranslate(SkScalar dx, SkScalar dy) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000763 this->drawingCanvas()->translate(dx, dy);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000764 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000765 this->INHERITED::didTranslate(dx, dy);
junov@google.com4370aed2012-01-18 16:21:08 +0000766}
767
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000768void SkDeferredCanvas::didScale(SkScalar sx, SkScalar sy) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000769 this->drawingCanvas()->scale(sx, sy);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000770 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000771 this->INHERITED::didScale(sx, sy);
junov@google.com4370aed2012-01-18 16:21:08 +0000772}
773
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000774void SkDeferredCanvas::didRotate(SkScalar degrees) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000775 this->drawingCanvas()->rotate(degrees);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000776 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000777 this->INHERITED::didRotate(degrees);
junov@google.com4370aed2012-01-18 16:21:08 +0000778}
779
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000780void SkDeferredCanvas::didSkew(SkScalar sx, SkScalar sy) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000781 this->drawingCanvas()->skew(sx, sy);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000782 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000783 this->INHERITED::didSkew(sx, sy);
junov@google.com4370aed2012-01-18 16:21:08 +0000784}
785
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000786void SkDeferredCanvas::didConcat(const SkMatrix& matrix) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000787 this->drawingCanvas()->concat(matrix);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000788 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000789 this->INHERITED::didConcat(matrix);
junov@google.com4370aed2012-01-18 16:21:08 +0000790}
791
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000792void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000793 this->drawingCanvas()->setMatrix(matrix);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000794 this->recordedDrawCommand();
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000795 this->INHERITED::didSetMatrix(matrix);
junov@google.com4370aed2012-01-18 16:21:08 +0000796}
797
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000798void SkDeferredCanvas::onClipRect(const SkRect& rect,
799 SkRegion::Op op,
800 ClipEdgeStyle edgeStyle) {
801 this->drawingCanvas()->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
802 this->INHERITED::onClipRect(rect, op, edgeStyle);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000803 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000804}
805
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000806void SkDeferredCanvas::onClipRRect(const SkRRect& rrect,
807 SkRegion::Op op,
808 ClipEdgeStyle edgeStyle) {
809 this->drawingCanvas()->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
810 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000811 this->recordedDrawCommand();
reed@google.com4ed0fb72012-12-12 20:48:18 +0000812}
813
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000814void SkDeferredCanvas::onClipPath(const SkPath& path,
815 SkRegion::Op op,
816 ClipEdgeStyle edgeStyle) {
817 this->drawingCanvas()->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
818 this->INHERITED::onClipPath(path, op, edgeStyle);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000819 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000820}
821
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000822void SkDeferredCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000823 this->drawingCanvas()->clipRegion(deviceRgn, op);
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000824 this->INHERITED::onClipRegion(deviceRgn, op);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000825 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000826}
827
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000828void SkDeferredCanvas::clear(SkColor color) {
junov@google.com4370aed2012-01-18 16:21:08 +0000829 // purge pending commands
830 if (fDeferredDrawing) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000831 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000832 }
833
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000834 this->drawingCanvas()->clear(color);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000835 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000836}
837
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000838void SkDeferredCanvas::drawPaint(const SkPaint& paint) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000839 if (fDeferredDrawing && this->isFullFrame(NULL, &paint) &&
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000840 isPaintOpaque(&paint)) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000841 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000842 }
junov@chromium.org10f7f972012-07-31 21:01:51 +0000843 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000844 this->drawingCanvas()->drawPaint(paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000845 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000846}
847
848void SkDeferredCanvas::drawPoints(PointMode mode, size_t count,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000849 const SkPoint pts[], const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000850 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000851 this->drawingCanvas()->drawPoints(mode, count, pts, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000852 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000853}
854
reed@google.com4ed0fb72012-12-12 20:48:18 +0000855void SkDeferredCanvas::drawOval(const SkRect& rect, const SkPaint& paint) {
856 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
857 this->drawingCanvas()->drawOval(rect, paint);
858 this->recordedDrawCommand();
859}
860
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000861void SkDeferredCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000862 if (fDeferredDrawing && this->isFullFrame(&rect, &paint) &&
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000863 isPaintOpaque(&paint)) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000864 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000865 }
skia.committer@gmail.com306ab9d2012-12-13 02:01:33 +0000866
junov@chromium.org10f7f972012-07-31 21:01:51 +0000867 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000868 this->drawingCanvas()->drawRect(rect, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000869 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000870}
871
reed@google.com4ed0fb72012-12-12 20:48:18 +0000872void SkDeferredCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
873 if (rrect.isRect()) {
874 this->SkDeferredCanvas::drawRect(rrect.getBounds(), paint);
875 } else if (rrect.isOval()) {
876 this->SkDeferredCanvas::drawOval(rrect.getBounds(), paint);
877 } else {
878 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
879 this->drawingCanvas()->drawRRect(rrect, paint);
880 this->recordedDrawCommand();
881 }
882}
883
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000884void SkDeferredCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
885 const SkPaint& paint) {
886 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
887 this->drawingCanvas()->drawDRRect(outer, inner, paint);
888 this->recordedDrawCommand();
889}
890
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000891void SkDeferredCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000892 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000893 this->drawingCanvas()->drawPath(path, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000894 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000895}
896
897void SkDeferredCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000898 SkScalar top, const SkPaint* paint) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000899 SkRect bitmapRect = SkRect::MakeXYWH(left, top,
900 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
rmistry@google.comd6176b02012-08-23 18:14:13 +0000901 if (fDeferredDrawing &&
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000902 this->isFullFrame(&bitmapRect, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000903 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000904 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000905 }
906
junov@chromium.org10f7f972012-07-31 21:01:51 +0000907 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000908 this->drawingCanvas()->drawBitmap(bitmap, left, top, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000909 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000910}
911
reed@google.com71121732012-09-18 15:14:33 +0000912void SkDeferredCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
913 const SkRect* src,
914 const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000915 const SkPaint* paint,
916 DrawBitmapRectFlags flags) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000917 if (fDeferredDrawing &&
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000918 this->isFullFrame(&dst, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000919 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000920 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000921 }
922
junov@chromium.org10f7f972012-07-31 21:01:51 +0000923 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000924 this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000925 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000926}
927
928
929void SkDeferredCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
930 const SkMatrix& m,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000931 const SkPaint* paint) {
junov@google.com4370aed2012-01-18 16:21:08 +0000932 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
933 // covers canvas entirely and transformed bitmap covers canvas entirely
junov@chromium.org10f7f972012-07-31 21:01:51 +0000934 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000935 this->drawingCanvas()->drawBitmapMatrix(bitmap, m, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000936 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000937}
938
939void SkDeferredCanvas::drawBitmapNine(const SkBitmap& bitmap,
940 const SkIRect& center, const SkRect& dst,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000941 const SkPaint* paint) {
junov@google.com4370aed2012-01-18 16:21:08 +0000942 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
943 // covers canvas entirely and dst covers canvas entirely
junov@chromium.org10f7f972012-07-31 21:01:51 +0000944 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000945 this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000946 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000947}
948
949void SkDeferredCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000950 const SkPaint* paint) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000951 SkRect bitmapRect = SkRect::MakeXYWH(
952 SkIntToScalar(left),
rmistry@google.comd6176b02012-08-23 18:14:13 +0000953 SkIntToScalar(top),
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000954 SkIntToScalar(bitmap.width()),
955 SkIntToScalar(bitmap.height()));
rmistry@google.comd6176b02012-08-23 18:14:13 +0000956 if (fDeferredDrawing &&
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000957 this->isFullFrame(&bitmapRect, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000958 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org0a67f962012-09-19 22:48:34 +0000959 this->getDeferredDevice()->skipPendingCommands();
junov@google.com4370aed2012-01-18 16:21:08 +0000960 }
961
junov@chromium.org10f7f972012-07-31 21:01:51 +0000962 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000963 this->drawingCanvas()->drawSprite(bitmap, left, top, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000964 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000965}
966
967void SkDeferredCanvas::drawText(const void* text, size_t byteLength,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000968 SkScalar x, SkScalar y, const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000969 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000970 this->drawingCanvas()->drawText(text, byteLength, x, y, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000971 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000972}
973
974void SkDeferredCanvas::drawPosText(const void* text, size_t byteLength,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000975 const SkPoint pos[], const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000976 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000977 this->drawingCanvas()->drawPosText(text, byteLength, pos, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000978 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000979}
980
981void SkDeferredCanvas::drawPosTextH(const void* text, size_t byteLength,
982 const SkScalar xpos[], SkScalar constY,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000983 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000984 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000985 this->drawingCanvas()->drawPosTextH(text, byteLength, xpos, constY, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000986 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000987}
988
989void SkDeferredCanvas::drawTextOnPath(const void* text, size_t byteLength,
990 const SkPath& path,
991 const SkMatrix* matrix,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000992 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000993 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000994 this->drawingCanvas()->drawTextOnPath(text, byteLength, path, matrix, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +0000995 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +0000996}
997
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000998void SkDeferredCanvas::drawPicture(SkPicture& picture) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +0000999 this->drawingCanvas()->drawPicture(picture);
junov@chromium.org9ed02b92012-08-14 13:36:26 +00001000 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +00001001}
1002
1003void SkDeferredCanvas::drawVertices(VertexMode vmode, int vertexCount,
1004 const SkPoint vertices[],
1005 const SkPoint texs[],
1006 const SkColor colors[], SkXfermode* xmode,
1007 const uint16_t indices[], int indexCount,
junov@chromium.orgc16ca922012-02-24 22:06:27 +00001008 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +00001009 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org9060c9b2012-08-07 15:14:01 +00001010 this->drawingCanvas()->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
1011 indices, indexCount, paint);
junov@chromium.org9ed02b92012-08-14 13:36:26 +00001012 this->recordedDrawCommand();
junov@google.com4370aed2012-01-18 16:21:08 +00001013}
1014
junov@chromium.orgc16ca922012-02-24 22:06:27 +00001015SkBounder* SkDeferredCanvas::setBounder(SkBounder* bounder) {
junov@chromium.org9060c9b2012-08-07 15:14:01 +00001016 this->drawingCanvas()->setBounder(bounder);
junov@chromium.org9ed02b92012-08-14 13:36:26 +00001017 this->INHERITED::setBounder(bounder);
1018 this->recordedDrawCommand();
1019 return bounder;
junov@google.com4370aed2012-01-18 16:21:08 +00001020}
1021
junov@chromium.orgc16ca922012-02-24 22:06:27 +00001022SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
rmistry@google.comd6176b02012-08-23 18:14:13 +00001023 this->drawingCanvas()->setDrawFilter(filter);
junov@chromium.org9ed02b92012-08-14 13:36:26 +00001024 this->INHERITED::setDrawFilter(filter);
1025 this->recordedDrawCommand();
rmistry@google.comd6176b02012-08-23 18:14:13 +00001026 return filter;
junov@google.com4370aed2012-01-18 16:21:08 +00001027}
1028
1029SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
junov@chromium.org9060c9b2012-08-07 15:14:01 +00001030 return this->drawingCanvas();
junov@google.com4370aed2012-01-18 16:21:08 +00001031}