reed | c536942 | 2014-11-11 04:56:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkCanvas.h" |
| 9 | #include "SkCanvasDrawable.h" |
| 10 | #include "SkThread.h" |
| 11 | |
| 12 | static int32_t next_generation_id() { |
| 13 | static int32_t gCanvasDrawableGenerationID; |
| 14 | |
| 15 | // do a loop in case our global wraps around, as we never want to |
| 16 | // return a 0 |
| 17 | int32_t genID; |
| 18 | do { |
| 19 | genID = sk_atomic_inc(&gCanvasDrawableGenerationID) + 1; |
| 20 | } while (0 == genID); |
| 21 | return genID; |
| 22 | } |
| 23 | |
| 24 | SkCanvasDrawable::SkCanvasDrawable() : fGenerationID(0) {} |
| 25 | |
| 26 | void SkCanvasDrawable::draw(SkCanvas* canvas) { |
| 27 | SkAutoCanvasRestore acr(canvas, true); |
| 28 | this->onDraw(canvas); |
| 29 | } |
| 30 | |
| 31 | uint32_t SkCanvasDrawable::getGenerationID() { |
| 32 | if (0 == fGenerationID) { |
| 33 | fGenerationID = next_generation_id(); |
| 34 | } |
| 35 | return fGenerationID; |
| 36 | } |
| 37 | |
| 38 | bool SkCanvasDrawable::getBounds(SkRect* boundsPtr) { |
| 39 | SkRect bounds; |
| 40 | if (!boundsPtr) { |
| 41 | boundsPtr = &bounds; |
| 42 | } |
| 43 | return this->onGetBounds(boundsPtr); |
| 44 | } |
| 45 | |
| 46 | void SkCanvasDrawable::notifyDrawingChanged() { |
| 47 | fGenerationID = 0; |
| 48 | } |
| 49 | |
| 50 | |