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