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