junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
junov@chromium.org | baa0220 | 2013-01-24 14:38:23 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 4 | * |
| 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 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 11 | #include "SkChunkAlloc.h" |
| 12 | #include "SkColorFilter.h" |
| 13 | #include "SkDevice.h" |
| 14 | #include "SkDrawFilter.h" |
| 15 | #include "SkGPipe.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
junov@chromium.org | baa0220 | 2013-01-24 14:38:23 +0000 | [diff] [blame] | 17 | #include "SkPaintPriv.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 18 | #include "SkRRect.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 19 | #include "SkShader.h" |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 20 | #include "SkSurface.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 21 | |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 22 | enum { |
| 23 | // Deferred canvas will auto-flush when recording reaches this limit |
| 24 | kDefaultMaxRecordingStorageBytes = 64*1024*1024, |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 25 | kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 28 | enum PlaybackMode { |
| 29 | kNormal_PlaybackMode, |
| 30 | kSilent_PlaybackMode, |
| 31 | }; |
| 32 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 33 | namespace { |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 34 | bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint, |
| 35 | size_t bitmapSizeThreshold) { |
| 36 | if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) || |
| 37 | (bitmap->getSize() > bitmapSizeThreshold))) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 38 | return true; |
| 39 | } |
| 40 | if (paint) { |
| 41 | SkShader* shader = paint->getShader(); |
| 42 | // Here we detect the case where the shader is an SkBitmapProcShader |
| 43 | // with a gpu texture attached. Checking this without RTTI |
| 44 | // requires making the assumption that only gradient shaders |
| 45 | // and SkBitmapProcShader implement asABitmap(). The following |
| 46 | // code may need to be revised if that assumption is ever broken. |
| 47 | if (shader && !shader->asAGradient(NULL)) { |
| 48 | SkBitmap bm; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 49 | if (shader->asABitmap(&bm, NULL, NULL) && |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 50 | NULL != bm.getTexture()) { |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return false; |
junov@chromium.org | b10a6bd | 2012-07-25 17:27:13 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 59 | //----------------------------------------------------------------------------- |
| 60 | // DeferredPipeController |
| 61 | //----------------------------------------------------------------------------- |
| 62 | |
| 63 | class DeferredPipeController : public SkGPipeController { |
| 64 | public: |
| 65 | DeferredPipeController(); |
| 66 | void setPlaybackCanvas(SkCanvas*); |
| 67 | virtual ~DeferredPipeController(); |
| 68 | virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE; |
| 69 | virtual void notifyWritten(size_t bytes) SK_OVERRIDE; |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 70 | void playback(bool silent); |
junov@chromium.org | a38dfb6 | 2012-09-20 22:10:33 +0000 | [diff] [blame] | 71 | bool hasPendingCommands() const { return fAllocator.blockCount() != 0; } |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 72 | size_t storageAllocatedForRecording() const { return fAllocator.totalCapacity(); } |
| 73 | private: |
| 74 | enum { |
| 75 | kMinBlockSize = 4096 |
| 76 | }; |
| 77 | struct PipeBlock { |
| 78 | PipeBlock(void* block, size_t size) { fBlock = block, fSize = size; } |
| 79 | void* fBlock; |
| 80 | size_t fSize; |
| 81 | }; |
| 82 | void* fBlock; |
| 83 | size_t fBytesWritten; |
| 84 | SkChunkAlloc fAllocator; |
| 85 | SkTDArray<PipeBlock> fBlockList; |
| 86 | SkGPipeReader fReader; |
| 87 | }; |
| 88 | |
| 89 | DeferredPipeController::DeferredPipeController() : |
| 90 | fAllocator(kMinBlockSize) { |
| 91 | fBlock = NULL; |
| 92 | fBytesWritten = 0; |
| 93 | } |
| 94 | |
| 95 | DeferredPipeController::~DeferredPipeController() { |
| 96 | fAllocator.reset(); |
| 97 | } |
| 98 | |
| 99 | void DeferredPipeController::setPlaybackCanvas(SkCanvas* canvas) { |
| 100 | fReader.setCanvas(canvas); |
| 101 | } |
| 102 | |
| 103 | void* DeferredPipeController::requestBlock(size_t minRequest, size_t *actual) { |
| 104 | if (fBlock) { |
| 105 | // Save the previous block for later |
| 106 | PipeBlock previousBloc(fBlock, fBytesWritten); |
| 107 | fBlockList.push(previousBloc); |
| 108 | } |
| 109 | int32_t blockSize = SkMax32(minRequest, kMinBlockSize); |
| 110 | fBlock = fAllocator.allocThrow(blockSize); |
| 111 | fBytesWritten = 0; |
| 112 | *actual = blockSize; |
| 113 | return fBlock; |
| 114 | } |
| 115 | |
| 116 | void DeferredPipeController::notifyWritten(size_t bytes) { |
| 117 | fBytesWritten += bytes; |
| 118 | } |
| 119 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 120 | void DeferredPipeController::playback(bool silent) { |
| 121 | uint32_t flags = silent ? SkGPipeReader::kSilent_PlaybackFlag : 0; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 122 | for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) { |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 123 | fReader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock].fSize, |
| 124 | flags); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 125 | } |
| 126 | fBlockList.reset(); |
| 127 | |
| 128 | if (fBlock) { |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 129 | fReader.playback(fBlock, fBytesWritten, flags); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 130 | fBlock = NULL; |
| 131 | } |
| 132 | |
| 133 | // Release all allocated blocks |
| 134 | fAllocator.reset(); |
| 135 | } |
| 136 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 137 | //----------------------------------------------------------------------------- |
| 138 | // DeferredDevice |
| 139 | //----------------------------------------------------------------------------- |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 140 | class DeferredDevice : public SkDevice { |
| 141 | public: |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 142 | explicit DeferredDevice(SkDevice* immediateDevice); |
| 143 | explicit DeferredDevice(SkSurface* surface); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 144 | ~DeferredDevice(); |
| 145 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 146 | void setNotificationClient(SkDeferredCanvas::NotificationClient* notificationClient); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 147 | SkCanvas* recordingCanvas(); |
| 148 | SkCanvas* immediateCanvas() const {return fImmediateCanvas;} |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 149 | SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 150 | SkImage* newImageSnapshot(); |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 151 | void setSurface(SkSurface* surface); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 152 | bool isFreshFrame(); |
junov@chromium.org | a38dfb6 | 2012-09-20 22:10:33 +0000 | [diff] [blame] | 153 | bool hasPendingCommands(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 154 | size_t storageAllocatedForRecording() const; |
| 155 | size_t freeMemoryIfPossible(size_t bytesToFree); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 156 | size_t getBitmapSizeThreshold() const; |
| 157 | void setBitmapSizeThreshold(size_t sizeThreshold); |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 158 | void flushPendingCommands(PlaybackMode); |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 159 | void skipPendingCommands(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 160 | void setMaxRecordingStorage(size_t); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 161 | void recordedDrawCommand(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 162 | |
| 163 | virtual uint32_t getDeviceCapabilities() SK_OVERRIDE; |
| 164 | virtual int width() const SK_OVERRIDE; |
| 165 | virtual int height() const SK_OVERRIDE; |
commit-bot@chromium.org | b8d00db | 2013-06-26 19:18:23 +0000 | [diff] [blame] | 166 | virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 167 | |
| 168 | virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
| 169 | int width, int height, |
| 170 | bool isOpaque, |
| 171 | Usage usage) SK_OVERRIDE; |
| 172 | |
| 173 | virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
| 174 | SkCanvas::Config8888 config8888) SK_OVERRIDE; |
| 175 | |
| 176 | protected: |
| 177 | virtual const SkBitmap& onAccessBitmap(SkBitmap*) SK_OVERRIDE; |
| 178 | virtual bool onReadPixels(const SkBitmap& bitmap, |
| 179 | int x, int y, |
| 180 | SkCanvas::Config8888 config8888) SK_OVERRIDE; |
| 181 | |
| 182 | // The following methods are no-ops on a deferred device |
| 183 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) |
| 184 | SK_OVERRIDE |
| 185 | {return false;} |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 186 | |
| 187 | // None of the following drawing methods should ever get called on the |
| 188 | // deferred device |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 189 | virtual void clear(SkColor color) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 190 | {SkASSERT(0);} |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 191 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 192 | {SkASSERT(0);} |
| 193 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 194 | size_t count, const SkPoint[], |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 195 | const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 196 | {SkASSERT(0);} |
| 197 | virtual void drawRect(const SkDraw&, const SkRect& r, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 198 | const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 199 | {SkASSERT(0);} |
| 200 | virtual void drawPath(const SkDraw&, const SkPath& path, |
| 201 | const SkPaint& paint, |
| 202 | const SkMatrix* prePathMatrix = NULL, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 203 | bool pathIsMutable = false) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 204 | {SkASSERT(0);} |
| 205 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 206 | const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 207 | {SkASSERT(0);} |
| 208 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 209 | int x, int y, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 210 | {SkASSERT(0);} |
| 211 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 212 | SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 213 | {SkASSERT(0);} |
| 214 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 215 | const SkScalar pos[], SkScalar constY, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 216 | int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 217 | {SkASSERT(0);} |
| 218 | virtual void drawTextOnPath(const SkDraw&, const void* text, |
| 219 | size_t len, const SkPath& path, |
| 220 | const SkMatrix* matrix, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 221 | const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 222 | {SkASSERT(0);} |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 223 | #ifdef SK_BUILD_FOR_ANDROID |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 224 | virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, |
| 225 | size_t len, const SkPoint pos[], |
| 226 | const SkPaint& paint, |
| 227 | const SkPath& path, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 228 | const SkMatrix* matrix) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 229 | {SkASSERT(0);} |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 230 | #endif |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 231 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 232 | int vertexCount, const SkPoint verts[], |
| 233 | const SkPoint texs[], const SkColor colors[], |
| 234 | SkXfermode* xmode, const uint16_t indices[], |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 235 | int indexCount, const SkPaint& paint) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 236 | {SkASSERT(0);} |
| 237 | virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 238 | const SkPaint&) SK_OVERRIDE |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 239 | {SkASSERT(0);} |
| 240 | private: |
commit-bot@chromium.org | 3e2ea25 | 2013-07-23 11:28:45 +0000 | [diff] [blame] | 241 | virtual void flush() SK_OVERRIDE; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 242 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 243 | void beginRecording(); |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 244 | void init(); |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 245 | void aboutToDraw(); |
| 246 | void prepareForImmediatePixelWrite(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 247 | |
| 248 | DeferredPipeController fPipeController; |
| 249 | SkGPipeWriter fPipeWriter; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 250 | SkCanvas* fImmediateCanvas; |
| 251 | SkCanvas* fRecordingCanvas; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 252 | SkSurface* fSurface; |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 253 | SkDeferredCanvas::NotificationClient* fNotificationClient; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 254 | bool fFreshFrame; |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 255 | bool fCanDiscardCanvasContents; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 256 | size_t fMaxRecordingStorageBytes; |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 257 | size_t fPreviousStorageAllocated; |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 258 | size_t fBitmapSizeThreshold; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 259 | }; |
| 260 | |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 261 | DeferredDevice::DeferredDevice(SkDevice* immediateDevice) |
| 262 | : SkDevice(SkBitmap::kNo_Config, |
| 263 | immediateDevice->width(), immediateDevice->height(), |
| 264 | immediateDevice->isOpaque(), |
| 265 | immediateDevice->getDeviceProperties()) { |
| 266 | fSurface = NULL; |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 267 | fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 268 | fPipeController.setPlaybackCanvas(fImmediateCanvas); |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 269 | this->init(); |
| 270 | } |
| 271 | |
| 272 | DeferredDevice::DeferredDevice(SkSurface* surface) |
| 273 | : SkDevice(SkBitmap::kNo_Config, |
| 274 | surface->getCanvas()->getDevice()->width(), |
| 275 | surface->getCanvas()->getDevice()->height(), |
| 276 | surface->getCanvas()->getDevice()->isOpaque(), |
| 277 | surface->getCanvas()->getDevice()->getDeviceProperties()) { |
| 278 | fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
| 279 | fNotificationClient = NULL; |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 280 | fImmediateCanvas = NULL; |
| 281 | fSurface = NULL; |
| 282 | this->setSurface(surface); |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 283 | this->init(); |
| 284 | } |
| 285 | |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 286 | void DeferredDevice::setSurface(SkSurface* surface) { |
| 287 | SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); |
| 288 | SkRefCnt_SafeAssign(fSurface, surface); |
| 289 | fPipeController.setPlaybackCanvas(fImmediateCanvas); |
| 290 | } |
| 291 | |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 292 | void DeferredDevice::init() { |
| 293 | fRecordingCanvas = NULL; |
| 294 | fFreshFrame = true; |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 295 | fCanDiscardCanvasContents = false; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 296 | fPreviousStorageAllocated = 0; |
| 297 | fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; |
| 298 | fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
| 299 | fNotificationClient = NULL; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 300 | this->beginRecording(); |
| 301 | } |
| 302 | |
| 303 | DeferredDevice::~DeferredDevice() { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 304 | this->flushPendingCommands(kSilent_PlaybackMode); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 305 | SkSafeUnref(fImmediateCanvas); |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 306 | SkSafeUnref(fSurface); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void DeferredDevice::setMaxRecordingStorage(size_t maxStorage) { |
| 310 | fMaxRecordingStorageBytes = maxStorage; |
| 311 | this->recordingCanvas(); // Accessing the recording canvas applies the new limit. |
| 312 | } |
| 313 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 314 | void DeferredDevice::beginRecording() { |
junov@chromium.org | a8db8fe | 2012-08-15 19:49:22 +0000 | [diff] [blame] | 315 | SkASSERT(NULL == fRecordingCanvas); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 316 | fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 317 | immediateDevice()->width(), immediateDevice()->height()); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 318 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 319 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 320 | void DeferredDevice::setNotificationClient( |
| 321 | SkDeferredCanvas::NotificationClient* notificationClient) { |
junov@chromium.org | 5280548 | 2012-08-20 14:25:04 +0000 | [diff] [blame] | 322 | fNotificationClient = notificationClient; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 323 | } |
| 324 | |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 325 | void DeferredDevice::skipPendingCommands() { |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 326 | if (!fRecordingCanvas->isDrawingToLayer()) { |
| 327 | fCanDiscardCanvasContents = true; |
| 328 | if (fPipeController.hasPendingCommands()) { |
| 329 | fFreshFrame = true; |
| 330 | flushPendingCommands(kSilent_PlaybackMode); |
| 331 | if (fNotificationClient) { |
| 332 | fNotificationClient->skippedPendingDrawCommands(); |
| 333 | } |
junov@google.com | 52a00ca | 2012-10-01 15:27:14 +0000 | [diff] [blame] | 334 | } |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
| 338 | bool DeferredDevice::isFreshFrame() { |
| 339 | bool ret = fFreshFrame; |
| 340 | fFreshFrame = false; |
| 341 | return ret; |
| 342 | } |
| 343 | |
junov@chromium.org | a38dfb6 | 2012-09-20 22:10:33 +0000 | [diff] [blame] | 344 | bool DeferredDevice::hasPendingCommands() { |
| 345 | return fPipeController.hasPendingCommands(); |
| 346 | } |
| 347 | |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 348 | void DeferredDevice::aboutToDraw() |
| 349 | { |
| 350 | if (NULL != fNotificationClient) { |
| 351 | fNotificationClient->prepareForDraw(); |
| 352 | } |
| 353 | if (fCanDiscardCanvasContents) { |
| 354 | if (NULL != fSurface) { |
| 355 | fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 356 | } |
skia.committer@gmail.com | ea4b797 | 2013-08-06 07:01:27 +0000 | [diff] [blame^] | 357 | fCanDiscardCanvasContents = false; |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 361 | void DeferredDevice::flushPendingCommands(PlaybackMode playbackMode) { |
junov@chromium.org | a38dfb6 | 2012-09-20 22:10:33 +0000 | [diff] [blame] | 362 | if (!fPipeController.hasPendingCommands()) { |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 363 | return; |
| 364 | } |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 365 | if (playbackMode == kNormal_PlaybackMode) { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 366 | aboutToDraw(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 367 | } |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 368 | fPipeWriter.flushRecording(true); |
junov@chromium.org | d4501a0 | 2012-10-30 19:05:17 +0000 | [diff] [blame] | 369 | fPipeController.playback(kSilent_PlaybackMode == playbackMode); |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 370 | if (playbackMode == kNormal_PlaybackMode && fNotificationClient) { |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 371 | fNotificationClient->flushedDrawCommands(); |
| 372 | } |
| 373 | fPreviousStorageAllocated = storageAllocatedForRecording(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void DeferredDevice::flush() { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 377 | this->flushPendingCommands(kNormal_PlaybackMode); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 378 | fImmediateCanvas->flush(); |
| 379 | } |
| 380 | |
| 381 | size_t DeferredDevice::freeMemoryIfPossible(size_t bytesToFree) { |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 382 | size_t val = fPipeWriter.freeMemoryIfPossible(bytesToFree); |
| 383 | fPreviousStorageAllocated = storageAllocatedForRecording(); |
| 384 | return val; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 385 | } |
| 386 | |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 387 | size_t DeferredDevice::getBitmapSizeThreshold() const { |
| 388 | return fBitmapSizeThreshold; |
| 389 | } |
| 390 | |
| 391 | void DeferredDevice::setBitmapSizeThreshold(size_t sizeThreshold) { |
| 392 | fBitmapSizeThreshold = sizeThreshold; |
| 393 | } |
| 394 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 395 | size_t DeferredDevice::storageAllocatedForRecording() const { |
| 396 | return (fPipeController.storageAllocatedForRecording() |
| 397 | + fPipeWriter.storageAllocatedForRecording()); |
| 398 | } |
| 399 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 400 | void DeferredDevice::recordedDrawCommand() { |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 401 | size_t storageAllocated = this->storageAllocatedForRecording(); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 402 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 403 | if (storageAllocated > fMaxRecordingStorageBytes) { |
| 404 | // First, attempt to reduce cache without flushing |
| 405 | size_t tryFree = storageAllocated - fMaxRecordingStorageBytes; |
| 406 | if (this->freeMemoryIfPossible(tryFree) < tryFree) { |
| 407 | // Flush is necessary to free more space. |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 408 | this->flushPendingCommands(kNormal_PlaybackMode); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 409 | // Free as much as possible to avoid oscillating around fMaxRecordingStorageBytes |
| 410 | // which could cause a high flushing frequency. |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 411 | this->freeMemoryIfPossible(~0U); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 412 | } |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 413 | storageAllocated = this->storageAllocatedForRecording(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 414 | } |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 415 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 416 | if (fNotificationClient && |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 417 | storageAllocated != fPreviousStorageAllocated) { |
| 418 | fPreviousStorageAllocated = storageAllocated; |
| 419 | fNotificationClient->storageAllocatedForRecordingChanged(storageAllocated); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | SkCanvas* DeferredDevice::recordingCanvas() { |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 424 | return fRecordingCanvas; |
| 425 | } |
| 426 | |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 427 | SkImage* DeferredDevice::newImageSnapshot() { |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 428 | this->flush(); |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 429 | return fSurface ? fSurface->newImageSnapshot() : NULL; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 430 | } |
| 431 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 432 | uint32_t DeferredDevice::getDeviceCapabilities() { |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 433 | return immediateDevice()->getDeviceCapabilities(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 434 | } |
| 435 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 436 | int DeferredDevice::width() const { |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 437 | return immediateDevice()->width(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | int DeferredDevice::height() const { |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 441 | return immediateDevice()->height(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 442 | } |
| 443 | |
commit-bot@chromium.org | b8d00db | 2013-06-26 19:18:23 +0000 | [diff] [blame] | 444 | GrRenderTarget* DeferredDevice::accessRenderTarget() { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 445 | this->flushPendingCommands(kNormal_PlaybackMode); |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 446 | return immediateDevice()->accessRenderTarget(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 447 | } |
| 448 | |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 449 | void DeferredDevice::prepareForImmediatePixelWrite() { |
| 450 | // The purpose of the following code is to make sure commands are flushed, that |
| 451 | // aboutToDraw() is called and that notifyContentWillChange is called, without |
| 452 | // calling anything redundantly. |
| 453 | if (fPipeController.hasPendingCommands()) { |
| 454 | this->flushPendingCommands(kNormal_PlaybackMode); |
| 455 | } else { |
| 456 | bool mustNotifyDirectly = !fCanDiscardCanvasContents; |
| 457 | this->aboutToDraw(); |
| 458 | if (mustNotifyDirectly) { |
| 459 | fSurface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | fImmediateCanvas->flush(); |
| 464 | } |
| 465 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 466 | void DeferredDevice::writePixels(const SkBitmap& bitmap, |
| 467 | int x, int y, SkCanvas::Config8888 config8888) { |
| 468 | |
| 469 | if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() && |
| 470 | (y + bitmap.height()) >= height()) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 471 | this->skipPendingCommands(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | if (SkBitmap::kARGB_8888_Config == bitmap.config() && |
| 475 | SkCanvas::kNative_Premul_Config8888 != config8888 && |
| 476 | kPMColorAlias != config8888) { |
| 477 | //Special case config: no deferral |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 478 | prepareForImmediatePixelWrite(); |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 479 | immediateDevice()->writePixels(bitmap, x, y, config8888); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | |
| 483 | SkPaint paint; |
| 484 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 485 | if (shouldDrawImmediately(&bitmap, NULL, getBitmapSizeThreshold())) { |
junov@chromium.org | 44324fa | 2013-08-02 15:36:02 +0000 | [diff] [blame] | 486 | prepareForImmediatePixelWrite(); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 487 | fImmediateCanvas->drawSprite(bitmap, x, y, &paint); |
| 488 | } else { |
| 489 | this->recordingCanvas()->drawSprite(bitmap, x, y, &paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 490 | this->recordedDrawCommand(); |
| 491 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
| 495 | const SkBitmap& DeferredDevice::onAccessBitmap(SkBitmap*) { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 496 | this->flushPendingCommands(kNormal_PlaybackMode); |
junov@chromium.org | 9becf00 | 2013-04-15 18:15:23 +0000 | [diff] [blame] | 497 | return immediateDevice()->accessBitmap(false); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | SkDevice* DeferredDevice::onCreateCompatibleDevice( |
| 501 | SkBitmap::Config config, int width, int height, bool isOpaque, |
| 502 | Usage usage) { |
| 503 | |
| 504 | // Save layer usage not supported, and not required by SkDeferredCanvas. |
| 505 | SkASSERT(usage != kSaveLayer_Usage); |
| 506 | // Create a compatible non-deferred device. |
junov@chromium.org | b1c725a | 2013-05-21 20:16:17 +0000 | [diff] [blame] | 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). |
| 509 | // And connecting a DeferredDevice to non-deferred canvas can result |
| 510 | // in unpredictable behavior. |
| 511 | return immediateDevice()->createCompatibleDevice(config, width, height, isOpaque); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | bool DeferredDevice::onReadPixels( |
| 515 | const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 516 | this->flushPendingCommands(kNormal_PlaybackMode); |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 517 | return fImmediateCanvas->readPixels(const_cast<SkBitmap*>(&bitmap), |
| 518 | x, y, config8888); |
| 519 | } |
| 520 | |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 521 | class AutoImmediateDrawIfNeeded { |
| 522 | public: |
| 523 | AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap, |
| 524 | const SkPaint* paint) { |
| 525 | this->init(canvas, bitmap, paint); |
| 526 | } |
| 527 | |
| 528 | AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) { |
| 529 | this->init(canvas, NULL, paint); |
| 530 | } |
| 531 | |
| 532 | ~AutoImmediateDrawIfNeeded() { |
| 533 | if (fCanvas) { |
| 534 | fCanvas->setDeferredDrawing(true); |
| 535 | } |
| 536 | } |
| 537 | private: |
| 538 | void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint) |
| 539 | { |
| 540 | DeferredDevice* device = static_cast<DeferredDevice*>(canvas.getDevice()); |
| 541 | if (canvas.isDeferredDrawing() && (NULL != device) && |
| 542 | shouldDrawImmediately(bitmap, paint, device->getBitmapSizeThreshold())) { |
| 543 | canvas.setDeferredDrawing(false); |
| 544 | fCanvas = &canvas; |
| 545 | } else { |
| 546 | fCanvas = NULL; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | SkDeferredCanvas* fCanvas; |
| 551 | }; |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 552 | |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 553 | #if !SK_DEFERRED_CANVAS_USES_FACTORIES |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 554 | SkDeferredCanvas::SkDeferredCanvas() { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 555 | this->init(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 556 | } |
| 557 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 558 | SkDeferredCanvas::SkDeferredCanvas(SkDevice* device) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 559 | this->init(); |
| 560 | this->setDevice(device); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 561 | } |
| 562 | |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 563 | SkDeferredCanvas::SkDeferredCanvas(SkSurface* surface) { |
| 564 | this->init(); |
| 565 | this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref(); |
| 566 | } |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 567 | #endif |
| 568 | |
| 569 | SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { |
| 570 | SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surface))); |
| 571 | return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); |
| 572 | } |
| 573 | |
| 574 | #ifdef SK_DEVELOPER |
| 575 | SkDeferredCanvas* SkDeferredCanvas::Create(SkDevice* device) { |
| 576 | SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (device))); |
| 577 | return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); |
| 578 | } |
| 579 | #endif |
| 580 | |
| 581 | SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) { |
| 582 | this->init(); |
| 583 | } |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 584 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 585 | void SkDeferredCanvas::init() { |
junov@chromium.org | 5e5a095 | 2012-02-28 15:27:59 +0000 | [diff] [blame] | 586 | fDeferredDrawing = true; // On by default |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 587 | } |
| 588 | |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 589 | void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 590 | this->validate(); |
junov@chromium.org | bfeddae | 2012-07-23 13:35:14 +0000 | [diff] [blame] | 591 | this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); |
| 592 | } |
| 593 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 594 | size_t SkDeferredCanvas::storageAllocatedForRecording() const { |
| 595 | return this->getDeferredDevice()->storageAllocatedForRecording(); |
| 596 | } |
| 597 | |
| 598 | size_t SkDeferredCanvas::freeMemoryIfPossible(size_t bytesToFree) { |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 599 | return this->getDeferredDevice()->freeMemoryIfPossible(bytesToFree); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 600 | } |
| 601 | |
sugoi@google.com | 7775fd5 | 2012-11-21 15:47:04 +0000 | [diff] [blame] | 602 | void SkDeferredCanvas::setBitmapSizeThreshold(size_t sizeThreshold) { |
| 603 | DeferredDevice* deferredDevice = this->getDeferredDevice(); |
| 604 | SkASSERT(deferredDevice); |
| 605 | deferredDevice->setBitmapSizeThreshold(sizeThreshold); |
| 606 | } |
| 607 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 608 | void SkDeferredCanvas::recordedDrawCommand() { |
| 609 | if (fDeferredDrawing) { |
| 610 | this->getDeferredDevice()->recordedDrawCommand(); |
| 611 | } |
| 612 | } |
| 613 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 614 | void SkDeferredCanvas::validate() const { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 615 | SkASSERT(this->getDevice()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 616 | } |
| 617 | |
junov@chromium.org | 5e5a095 | 2012-02-28 15:27:59 +0000 | [diff] [blame] | 618 | SkCanvas* SkDeferredCanvas::drawingCanvas() const { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 619 | this->validate(); |
| 620 | return fDeferredDrawing ? this->getDeferredDevice()->recordingCanvas() : |
| 621 | this->getDeferredDevice()->immediateCanvas(); |
junov@chromium.org | 5e5a095 | 2012-02-28 15:27:59 +0000 | [diff] [blame] | 622 | } |
| 623 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 624 | SkCanvas* SkDeferredCanvas::immediateCanvas() const { |
| 625 | this->validate(); |
| 626 | return this->getDeferredDevice()->immediateCanvas(); |
| 627 | } |
| 628 | |
| 629 | DeferredDevice* SkDeferredCanvas::getDeferredDevice() const { |
| 630 | return static_cast<DeferredDevice*>(this->getDevice()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 631 | } |
| 632 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 633 | void SkDeferredCanvas::setDeferredDrawing(bool val) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 634 | this->validate(); // Must set device before calling this method |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 635 | if (val != fDeferredDrawing) { |
| 636 | if (fDeferredDrawing) { |
junov@chromium.org | 5e5a095 | 2012-02-28 15:27:59 +0000 | [diff] [blame] | 637 | // Going live. |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 638 | this->getDeferredDevice()->flushPendingCommands(kNormal_PlaybackMode); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 639 | } |
| 640 | fDeferredDrawing = val; |
| 641 | } |
| 642 | } |
| 643 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 644 | bool SkDeferredCanvas::isDeferredDrawing() const { |
junov@chromium.org | b10a6bd | 2012-07-25 17:27:13 +0000 | [diff] [blame] | 645 | return fDeferredDrawing; |
| 646 | } |
| 647 | |
junov@chromium.org | 88e2914 | 2012-08-07 16:48:22 +0000 | [diff] [blame] | 648 | bool SkDeferredCanvas::isFreshFrame() const { |
| 649 | return this->getDeferredDevice()->isFreshFrame(); |
| 650 | } |
| 651 | |
junov@chromium.org | a38dfb6 | 2012-09-20 22:10:33 +0000 | [diff] [blame] | 652 | bool SkDeferredCanvas::hasPendingCommands() const { |
| 653 | return this->getDeferredDevice()->hasPendingCommands(); |
| 654 | } |
| 655 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 656 | void SkDeferredCanvas::silentFlush() { |
| 657 | if (fDeferredDrawing) { |
junov@chromium.org | eeaf47f | 2012-09-20 20:42:44 +0000 | [diff] [blame] | 658 | this->getDeferredDevice()->flushPendingCommands(kSilent_PlaybackMode); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 662 | SkDeferredCanvas::~SkDeferredCanvas() { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 663 | } |
| 664 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 665 | SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 666 | #if SK_DEFERRED_CANVAS_USES_FACTORIES |
| 667 | SkASSERT(0); // setDevice is deprecated |
| 668 | #else |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 669 | this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 670 | #endif |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 671 | return device; |
| 672 | } |
| 673 | |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 674 | SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) { |
| 675 | DeferredDevice* deferredDevice = this->getDeferredDevice(); |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 676 | SkASSERT(NULL != deferredDevice); |
| 677 | // By swapping the surface into the existing device, we preserve |
| 678 | // all pending commands, which can help to seamlessly recover from |
| 679 | // a lost accelerated graphics context. |
| 680 | deferredDevice->setSurface(surface); |
junov@chromium.org | 7070f76 | 2013-05-24 17:13:00 +0000 | [diff] [blame] | 681 | return surface; |
| 682 | } |
| 683 | |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 684 | SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient( |
| 685 | NotificationClient* notificationClient) { |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 686 | |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 687 | DeferredDevice* deferredDevice = this->getDeferredDevice(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 688 | SkASSERT(deferredDevice); |
| 689 | if (deferredDevice) { |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 690 | deferredDevice->setNotificationClient(notificationClient); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 691 | } |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 692 | return notificationClient; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 693 | } |
| 694 | |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 695 | SkImage* SkDeferredCanvas::newImageSnapshot() { |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 696 | DeferredDevice* deferredDevice = this->getDeferredDevice(); |
| 697 | SkASSERT(deferredDevice); |
junov@chromium.org | 5ee449a | 2013-04-12 20:20:50 +0000 | [diff] [blame] | 698 | return deferredDevice ? deferredDevice->newImageSnapshot() : NULL; |
junov@chromium.org | 67d7422 | 2013-04-12 13:33:01 +0000 | [diff] [blame] | 699 | } |
| 700 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 701 | bool SkDeferredCanvas::isFullFrame(const SkRect* rect, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 702 | const SkPaint* paint) const { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 703 | SkCanvas* canvas = this->drawingCanvas(); |
| 704 | SkISize canvasSize = this->getDeviceSize(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 705 | if (rect) { |
| 706 | if (!canvas->getTotalMatrix().rectStaysRect()) { |
| 707 | return false; // conservative |
| 708 | } |
| 709 | |
| 710 | SkRect transformedRect; |
| 711 | canvas->getTotalMatrix().mapRect(&transformedRect, *rect); |
| 712 | |
| 713 | if (paint) { |
| 714 | SkPaint::Style paintStyle = paint->getStyle(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 715 | if (!(paintStyle == SkPaint::kFill_Style || |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 716 | paintStyle == SkPaint::kStrokeAndFill_Style)) { |
| 717 | return false; |
| 718 | } |
| 719 | if (paint->getMaskFilter() || paint->getLooper() |
| 720 | || paint->getPathEffect() || paint->getImageFilter()) { |
| 721 | return false; // conservative |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | // The following test holds with AA enabled, and is conservative |
| 726 | // by a 0.5 pixel margin with AA disabled |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 727 | if (transformedRect.fLeft > SkIntToScalar(0) || |
| 728 | transformedRect.fTop > SkIntToScalar(0) || |
junov@chromium.org | b1e218e | 2012-02-13 22:27:58 +0000 | [diff] [blame] | 729 | transformedRect.fRight < SkIntToScalar(canvasSize.fWidth) || |
| 730 | transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 731 | return false; |
| 732 | } |
| 733 | } |
| 734 | |
junov@chromium.org | 8f0ca06 | 2012-12-13 16:30:39 +0000 | [diff] [blame] | 735 | return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0, |
| 736 | SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 737 | } |
| 738 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 739 | int SkDeferredCanvas::save(SaveFlags flags) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 740 | this->drawingCanvas()->save(flags); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 741 | int val = this->INHERITED::save(flags); |
| 742 | this->recordedDrawCommand(); |
| 743 | |
| 744 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | int SkDeferredCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 748 | SaveFlags flags) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 749 | this->drawingCanvas()->saveLayer(bounds, paint, flags); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 750 | int count = this->INHERITED::save(flags); |
| 751 | this->clipRectBounds(bounds, flags, NULL); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 752 | this->recordedDrawCommand(); |
| 753 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 754 | return count; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 755 | } |
| 756 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 757 | void SkDeferredCanvas::restore() { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 758 | this->drawingCanvas()->restore(); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 759 | this->INHERITED::restore(); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 760 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 761 | } |
| 762 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 763 | bool SkDeferredCanvas::isDrawingToLayer() const { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 764 | return this->drawingCanvas()->isDrawingToLayer(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 765 | } |
| 766 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 767 | bool SkDeferredCanvas::translate(SkScalar dx, SkScalar dy) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 768 | this->drawingCanvas()->translate(dx, dy); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 769 | bool val = this->INHERITED::translate(dx, dy); |
| 770 | this->recordedDrawCommand(); |
| 771 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 772 | } |
| 773 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 774 | bool SkDeferredCanvas::scale(SkScalar sx, SkScalar sy) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 775 | this->drawingCanvas()->scale(sx, sy); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 776 | bool val = this->INHERITED::scale(sx, sy); |
| 777 | this->recordedDrawCommand(); |
| 778 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 779 | } |
| 780 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 781 | bool SkDeferredCanvas::rotate(SkScalar degrees) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 782 | this->drawingCanvas()->rotate(degrees); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 783 | bool val = this->INHERITED::rotate(degrees); |
| 784 | this->recordedDrawCommand(); |
| 785 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 786 | } |
| 787 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 788 | bool SkDeferredCanvas::skew(SkScalar sx, SkScalar sy) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 789 | this->drawingCanvas()->skew(sx, sy); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 790 | bool val = this->INHERITED::skew(sx, sy); |
| 791 | this->recordedDrawCommand(); |
| 792 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 793 | } |
| 794 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 795 | bool SkDeferredCanvas::concat(const SkMatrix& matrix) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 796 | this->drawingCanvas()->concat(matrix); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 797 | bool val = this->INHERITED::concat(matrix); |
| 798 | this->recordedDrawCommand(); |
| 799 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 800 | } |
| 801 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 802 | void SkDeferredCanvas::setMatrix(const SkMatrix& matrix) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 803 | this->drawingCanvas()->setMatrix(matrix); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 804 | this->INHERITED::setMatrix(matrix); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 805 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | bool SkDeferredCanvas::clipRect(const SkRect& rect, |
| 809 | SkRegion::Op op, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 810 | bool doAntiAlias) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 811 | this->drawingCanvas()->clipRect(rect, op, doAntiAlias); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 812 | bool val = this->INHERITED::clipRect(rect, op, doAntiAlias); |
| 813 | this->recordedDrawCommand(); |
| 814 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 815 | } |
| 816 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 817 | bool SkDeferredCanvas::clipRRect(const SkRRect& rrect, |
| 818 | SkRegion::Op op, |
| 819 | bool doAntiAlias) { |
| 820 | this->drawingCanvas()->clipRRect(rrect, op, doAntiAlias); |
| 821 | bool val = this->INHERITED::clipRRect(rrect, op, doAntiAlias); |
| 822 | this->recordedDrawCommand(); |
| 823 | return val; |
| 824 | } |
| 825 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 826 | bool SkDeferredCanvas::clipPath(const SkPath& path, |
| 827 | SkRegion::Op op, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 828 | bool doAntiAlias) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 829 | this->drawingCanvas()->clipPath(path, op, doAntiAlias); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 830 | bool val = this->INHERITED::clipPath(path, op, doAntiAlias); |
| 831 | this->recordedDrawCommand(); |
| 832 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | bool SkDeferredCanvas::clipRegion(const SkRegion& deviceRgn, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 836 | SkRegion::Op op) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 837 | this->drawingCanvas()->clipRegion(deviceRgn, op); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 838 | bool val = this->INHERITED::clipRegion(deviceRgn, op); |
| 839 | this->recordedDrawCommand(); |
| 840 | return val; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 841 | } |
| 842 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 843 | void SkDeferredCanvas::clear(SkColor color) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 844 | // purge pending commands |
| 845 | if (fDeferredDrawing) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 846 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 847 | } |
| 848 | |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 849 | this->drawingCanvas()->clear(color); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 850 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 851 | } |
| 852 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 853 | void SkDeferredCanvas::drawPaint(const SkPaint& paint) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 854 | if (fDeferredDrawing && this->isFullFrame(NULL, &paint) && |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 855 | isPaintOpaque(&paint)) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 856 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 857 | } |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 858 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 859 | this->drawingCanvas()->drawPaint(paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 860 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | void SkDeferredCanvas::drawPoints(PointMode mode, size_t count, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 864 | const SkPoint pts[], const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 865 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 866 | this->drawingCanvas()->drawPoints(mode, count, pts, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 867 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 868 | } |
| 869 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 870 | void SkDeferredCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 871 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
| 872 | this->drawingCanvas()->drawOval(rect, paint); |
| 873 | this->recordedDrawCommand(); |
| 874 | } |
| 875 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 876 | void SkDeferredCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 877 | if (fDeferredDrawing && this->isFullFrame(&rect, &paint) && |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 878 | isPaintOpaque(&paint)) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 879 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 880 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 881 | |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 882 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 883 | this->drawingCanvas()->drawRect(rect, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 884 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 885 | } |
| 886 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 887 | void SkDeferredCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 888 | if (rrect.isRect()) { |
| 889 | this->SkDeferredCanvas::drawRect(rrect.getBounds(), paint); |
| 890 | } else if (rrect.isOval()) { |
| 891 | this->SkDeferredCanvas::drawOval(rrect.getBounds(), paint); |
| 892 | } else { |
| 893 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
| 894 | this->drawingCanvas()->drawRRect(rrect, paint); |
| 895 | this->recordedDrawCommand(); |
| 896 | } |
| 897 | } |
| 898 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 899 | void SkDeferredCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 900 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 901 | this->drawingCanvas()->drawPath(path, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 902 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void SkDeferredCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 906 | SkScalar top, const SkPaint* paint) { |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 907 | SkRect bitmapRect = SkRect::MakeXYWH(left, top, |
| 908 | SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 909 | if (fDeferredDrawing && |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 910 | this->isFullFrame(&bitmapRect, paint) && |
junov@chromium.org | 87f982c | 2012-02-23 21:34:34 +0000 | [diff] [blame] | 911 | isPaintOpaque(paint, &bitmap)) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 912 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 913 | } |
| 914 | |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 915 | AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 916 | this->drawingCanvas()->drawBitmap(bitmap, left, top, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 917 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 918 | } |
| 919 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 920 | void SkDeferredCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
| 921 | const SkRect* src, |
| 922 | const SkRect& dst, |
| 923 | const SkPaint* paint) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 924 | if (fDeferredDrawing && |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 925 | this->isFullFrame(&dst, paint) && |
junov@chromium.org | 87f982c | 2012-02-23 21:34:34 +0000 | [diff] [blame] | 926 | isPaintOpaque(paint, &bitmap)) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 927 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 928 | } |
| 929 | |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 930 | AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 931 | this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 932 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | |
| 936 | void SkDeferredCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
| 937 | const SkMatrix& m, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 938 | const SkPaint* paint) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 939 | // TODO: reset recording canvas if paint+bitmap is opaque and clip rect |
| 940 | // covers canvas entirely and transformed bitmap covers canvas entirely |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 941 | AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 942 | this->drawingCanvas()->drawBitmapMatrix(bitmap, m, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 943 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | void SkDeferredCanvas::drawBitmapNine(const SkBitmap& bitmap, |
| 947 | const SkIRect& center, const SkRect& dst, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 948 | const SkPaint* paint) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 949 | // TODO: reset recording canvas if paint+bitmap is opaque and clip rect |
| 950 | // covers canvas entirely and dst covers canvas entirely |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 951 | AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 952 | this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 953 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | void SkDeferredCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 957 | const SkPaint* paint) { |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 958 | SkRect bitmapRect = SkRect::MakeXYWH( |
| 959 | SkIntToScalar(left), |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 960 | SkIntToScalar(top), |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 961 | SkIntToScalar(bitmap.width()), |
| 962 | SkIntToScalar(bitmap.height())); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 963 | if (fDeferredDrawing && |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 964 | this->isFullFrame(&bitmapRect, paint) && |
junov@chromium.org | 87f982c | 2012-02-23 21:34:34 +0000 | [diff] [blame] | 965 | isPaintOpaque(paint, &bitmap)) { |
junov@chromium.org | 0a67f96 | 2012-09-19 22:48:34 +0000 | [diff] [blame] | 966 | this->getDeferredDevice()->skipPendingCommands(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 967 | } |
| 968 | |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 969 | AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 970 | this->drawingCanvas()->drawSprite(bitmap, left, top, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 971 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | void SkDeferredCanvas::drawText(const void* text, size_t byteLength, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 975 | SkScalar x, SkScalar y, const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 976 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 977 | this->drawingCanvas()->drawText(text, byteLength, x, y, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 978 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | void SkDeferredCanvas::drawPosText(const void* text, size_t byteLength, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 982 | const SkPoint pos[], const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 983 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 984 | this->drawingCanvas()->drawPosText(text, byteLength, pos, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 985 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void SkDeferredCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 989 | const SkScalar xpos[], SkScalar constY, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 990 | const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 991 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 992 | this->drawingCanvas()->drawPosTextH(text, byteLength, xpos, constY, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 993 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | void SkDeferredCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 997 | const SkPath& path, |
| 998 | const SkMatrix* matrix, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 999 | const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 1000 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 1001 | this->drawingCanvas()->drawTextOnPath(text, byteLength, path, matrix, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 1002 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 1005 | void SkDeferredCanvas::drawPicture(SkPicture& picture) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 1006 | this->drawingCanvas()->drawPicture(picture); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 1007 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | void SkDeferredCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 1011 | const SkPoint vertices[], |
| 1012 | const SkPoint texs[], |
| 1013 | const SkColor colors[], SkXfermode* xmode, |
| 1014 | const uint16_t indices[], int indexCount, |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 1015 | const SkPaint& paint) { |
junov@chromium.org | 10f7f97 | 2012-07-31 21:01:51 +0000 | [diff] [blame] | 1016 | AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 1017 | this->drawingCanvas()->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode, |
| 1018 | indices, indexCount, paint); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 1019 | this->recordedDrawCommand(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 1022 | SkBounder* SkDeferredCanvas::setBounder(SkBounder* bounder) { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 1023 | this->drawingCanvas()->setBounder(bounder); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 1024 | this->INHERITED::setBounder(bounder); |
| 1025 | this->recordedDrawCommand(); |
| 1026 | return bounder; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
junov@chromium.org | c16ca92 | 2012-02-24 22:06:27 +0000 | [diff] [blame] | 1029 | SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1030 | this->drawingCanvas()->setDrawFilter(filter); |
junov@chromium.org | 9ed02b9 | 2012-08-14 13:36:26 +0000 | [diff] [blame] | 1031 | this->INHERITED::setDrawFilter(filter); |
| 1032 | this->recordedDrawCommand(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1033 | return filter; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
junov@chromium.org | 9060c9b | 2012-08-07 15:14:01 +0000 | [diff] [blame] | 1037 | return this->drawingCanvas(); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1038 | } |