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