OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkCanvasDrawable_DEFINED | 8 #ifndef SkCanvasDrawable_DEFINED |
9 #define SkCanvasDrawable_DEFINED | 9 #define SkCanvasDrawable_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 | 12 |
13 class SkBBHFactory; | |
13 class SkCanvas; | 14 class SkCanvas; |
14 struct SkRect; | 15 struct SkRect; |
15 | 16 |
16 /** | 17 /** |
17 * Base-class for objects that draw into SkCanvas. | 18 * Base-class for objects that draw into SkCanvas. |
18 * | 19 * |
19 * The object has a generation ID, which is guaranteed to be unique across all drawables. To | 20 * The object has a generation ID, which is guaranteed to be unique across all drawables. To |
20 * allow for clients of the drawable that may want to cache the results, the dr awable must | 21 * allow for clients of the drawable that may want to cache the results, the dr awable must |
21 * change its generation ID whenever its internal state changes such that it wi ll draw differently. | 22 * change its generation ID whenever its internal state changes such that it wi ll draw differently. |
22 */ | 23 */ |
23 class SkCanvasDrawable : public SkRefCnt { | 24 class SkCanvasDrawable : public SkRefCnt { |
24 public: | 25 public: |
25 SkCanvasDrawable(); | 26 SkCanvasDrawable(); |
26 | 27 |
27 /** | 28 /** |
28 * Draws into the specified content. The drawing sequence will be balanced upon return | 29 * Draws into the specified content. The drawing sequence will be balanced upon return |
29 * (i.e. the saveLevel() on the canvas will match what it was when draw() w as called, | 30 * (i.e. the saveLevel() on the canvas will match what it was when draw() w as called, |
30 * and the current matrix and clip settings will not be changed. | 31 * and the current matrix and clip settings will not be changed. |
31 */ | 32 */ |
32 void draw(SkCanvas*); | 33 void draw(SkCanvas*); |
33 | 34 |
35 SkPicture* newPictureSnapshot(SkBBHFactory* bbhFactory, uint32_t recordFlags ); | |
36 SkPicture* newPictureSnapshot() { | |
37 return this->newPictureSnapshot(NULL, 0); | |
38 } | |
39 | |
34 /** | 40 /** |
35 * Return a unique value for this instance. If two calls to this return the same value, | 41 * Return a unique value for this instance. If two calls to this return the same value, |
36 * it is presumed that calling the draw() method will render the same thing as well. | 42 * it is presumed that calling the draw() method will render the same thing as well. |
37 * | 43 * |
38 * Subclasses that change their state should call notifyDrawingChanged() to ensure that | 44 * Subclasses that change their state should call notifyDrawingChanged() to ensure that |
39 * a new value will be returned the next time it is called. | 45 * a new value will be returned the next time it is called. |
40 */ | 46 */ |
41 uint32_t getGenerationID(); | 47 uint32_t getGenerationID(); |
42 | 48 |
43 /** | 49 /** |
44 * If the drawable knows a bounds that will contains all of its drawing, re turn true and | 50 * If the drawable knows a bounds that will contains all of its drawing, re turn true and |
45 * set the parameter to that rectangle. If one is not known, ignore the par ameter and | 51 * set the parameter to that rectangle. If one is not known, ignore the par ameter and |
46 * return false. | 52 * return false. |
mtklein
2014/11/17 20:23:21
Update docs?
reed1
2014/11/17 20:35:58
Done.
| |
47 */ | 53 */ |
48 bool getBounds(SkRect*); | 54 SkRect getBounds(); |
49 | 55 |
50 /** | 56 /** |
51 * Calling this invalidates the previous generation ID, and causes a new on e to be computed | 57 * Calling this invalidates the previous generation ID, and causes a new on e to be computed |
52 * the next time getGenerationID() is called. Typically this is called by t he object itself, | 58 * the next time getGenerationID() is called. Typically this is called by t he object itself, |
53 * in response to its internal state changing. | 59 * in response to its internal state changing. |
54 */ | 60 */ |
55 void notifyDrawingChanged(); | 61 void notifyDrawingChanged(); |
56 | 62 |
57 protected: | 63 protected: |
64 virtual SkRect onGetBounds() = 0; | |
58 virtual void onDraw(SkCanvas*) = 0; | 65 virtual void onDraw(SkCanvas*) = 0; |
59 | 66 virtual SkPicture* onNewPictureSnapshot(SkBBHFactory*, uint32_t recordFlags) ; |
60 virtual bool onGetBounds(SkRect*) { return false; } | |
61 | 67 |
62 private: | 68 private: |
63 int32_t fGenerationID; | 69 int32_t fGenerationID; |
64 }; | 70 }; |
65 | 71 |
66 #endif | 72 #endif |
OLD | NEW |