| 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 SkDrawable_DEFINED | 8 #ifndef SkDrawable_DEFINED |
| 9 #define SkDrawable_DEFINED | 9 #define SkDrawable_DEFINED |
| 10 | 10 |
| 11 #include "SkRefCnt.h" | 11 #include "SkFlattenable.h" |
| 12 | 12 |
| 13 class SkCanvas; | 13 class SkCanvas; |
| 14 class SkMatrix; |
| 14 class SkPicture; | 15 class SkPicture; |
| 15 struct SkRect; | 16 struct SkRect; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Base-class for objects that draw into SkCanvas. | 19 * Base-class for objects that draw into SkCanvas. |
| 19 * | 20 * |
| 20 * The object has a generation ID, which is guaranteed to be unique across all
drawables. To | 21 * The object has a generation ID, which is guaranteed to be unique across all
drawables. To |
| 21 * allow for clients of the drawable that may want to cache the results, the dr
awable must | 22 * allow for clients of the drawable that may want to cache the results, the dr
awable must |
| 22 * change its generation ID whenever its internal state changes such that it wi
ll draw differently. | 23 * change its generation ID whenever its internal state changes such that it wi
ll draw differently. |
| 23 */ | 24 */ |
| 24 class SkDrawable : public SkRefCnt { | 25 class SkDrawable : public SkFlattenable { |
| 25 public: | 26 public: |
| 26 SkDrawable(); | 27 SkDrawable(); |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Draws into the specified content. The drawing sequence will be balanced
upon return | 30 * Draws into the specified content. The drawing sequence will be balanced
upon return |
| 30 * (i.e. the saveLevel() on the canvas will match what it was when draw() w
as called, | 31 * (i.e. the saveLevel() on the canvas will match what it was when draw() w
as called, |
| 31 * and the current matrix and clip settings will not be changed. | 32 * and the current matrix and clip settings will not be changed. |
| 32 */ | 33 */ |
| 33 void draw(SkCanvas*, const SkMatrix* = NULL); | 34 void draw(SkCanvas*, const SkMatrix* = NULL); |
| 34 void draw(SkCanvas*, SkScalar x, SkScalar y); | 35 void draw(SkCanvas*, SkScalar x, SkScalar y); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 */ | 52 */ |
| 52 SkRect getBounds(); | 53 SkRect getBounds(); |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Calling this invalidates the previous generation ID, and causes a new on
e to be computed | 56 * Calling this invalidates the previous generation ID, and causes a new on
e to be computed |
| 56 * the next time getGenerationID() is called. Typically this is called by t
he object itself, | 57 * the next time getGenerationID() is called. Typically this is called by t
he object itself, |
| 57 * in response to its internal state changing. | 58 * in response to its internal state changing. |
| 58 */ | 59 */ |
| 59 void notifyDrawingChanged(); | 60 void notifyDrawingChanged(); |
| 60 | 61 |
| 62 SK_DEFINE_FLATTENABLE_TYPE(SkDrawable) |
| 63 Factory getFactory() const override { return nullptr; } |
| 64 |
| 61 protected: | 65 protected: |
| 62 virtual SkRect onGetBounds() = 0; | 66 virtual SkRect onGetBounds() = 0; |
| 63 virtual void onDraw(SkCanvas*) = 0; | 67 virtual void onDraw(SkCanvas*) = 0; |
| 64 | 68 |
| 65 /** | 69 /** |
| 66 * Default implementation calls onDraw() with a canvas that records into a
picture. Subclasses | 70 * Default implementation calls onDraw() with a canvas that records into a
picture. Subclasses |
| 67 * may override if they have a more efficient way to return a picture for t
he current state | 71 * may override if they have a more efficient way to return a picture for t
he current state |
| 68 * of their drawable. Note: this picture must draw the same as what would b
e drawn from | 72 * of their drawable. Note: this picture must draw the same as what would b
e drawn from |
| 69 * onDraw(). | 73 * onDraw(). |
| 70 */ | 74 */ |
| 71 virtual SkPicture* onNewPictureSnapshot(); | 75 virtual SkPicture* onNewPictureSnapshot(); |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 int32_t fGenerationID; | 78 int32_t fGenerationID; |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 #endif | 81 #endif |
| OLD | NEW |