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