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