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