blob: 7c01738dd60d74b0a4a8c41b544688a5b9614af6 [file] [log] [blame]
reedc5369422014-11-11 04:56:05 -08001/*
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
12static 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
24SkCanvasDrawable::SkCanvasDrawable() : fGenerationID(0) {}
25
26void SkCanvasDrawable::draw(SkCanvas* canvas) {
27 SkAutoCanvasRestore acr(canvas, true);
28 this->onDraw(canvas);
29}
30
31uint32_t SkCanvasDrawable::getGenerationID() {
32 if (0 == fGenerationID) {
33 fGenerationID = next_generation_id();
34 }
35 return fGenerationID;
36}
37
38bool SkCanvasDrawable::getBounds(SkRect* boundsPtr) {
39 SkRect bounds;
40 if (!boundsPtr) {
41 boundsPtr = &bounds;
42 }
43 return this->onGetBounds(boundsPtr);
44}
45
46void SkCanvasDrawable::notifyDrawingChanged() {
47 fGenerationID = 0;
48}
49
50