OLD | NEW |
(Empty) | |
| 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 #ifndef SkCanvasDrawable_DEFINED |
| 9 #define SkCanvasDrawable_DEFINED |
| 10 |
| 11 #include "SkRefCnt.h" |
| 12 |
| 13 class SkCanvas; |
| 14 class SkPicture; |
| 15 struct SkRect; |
| 16 |
| 17 /** |
| 18 * Base-class for objects that draw into SkCanvas. |
| 19 * |
| 20 * 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 * change its generation ID whenever its internal state changes such that it wi
ll draw differently. |
| 23 */ |
| 24 class SkCanvasDrawable : public SkRefCnt { |
| 25 public: |
| 26 SkCanvasDrawable(); |
| 27 |
| 28 /** |
| 29 * 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 * and the current matrix and clip settings will not be changed. |
| 32 */ |
| 33 void draw(SkCanvas*); |
| 34 |
| 35 SkPicture* newPictureSnapshot(); |
| 36 |
| 37 /** |
| 38 * Return a unique value for this instance. If two calls to this return the
same value, |
| 39 * it is presumed that calling the draw() method will render the same thing
as well. |
| 40 * |
| 41 * Subclasses that change their state should call notifyDrawingChanged() to
ensure that |
| 42 * a new value will be returned the next time it is called. |
| 43 */ |
| 44 uint32_t getGenerationID(); |
| 45 |
| 46 /** |
| 47 * Return the (conservative) bounds of what the drawable will draw. If the
drawable can |
| 48 * change what it draws (e.g. animation or in response to some external cha
nge), then this |
| 49 * must return a bounds that is always valid for all possible states. |
| 50 */ |
| 51 SkRect getBounds(); |
| 52 |
| 53 /** |
| 54 * Calling this invalidates the previous generation ID, and causes a new on
e to be computed |
| 55 * the next time getGenerationID() is called. Typically this is called by t
he object itself, |
| 56 * in response to its internal state changing. |
| 57 */ |
| 58 void notifyDrawingChanged(); |
| 59 |
| 60 protected: |
| 61 virtual SkRect onGetBounds() = 0; |
| 62 virtual void onDraw(SkCanvas*) = 0; |
| 63 virtual SkPicture* onNewPictureSnapshot(); |
| 64 |
| 65 private: |
| 66 int32_t fGenerationID; |
| 67 }; |
| 68 |
| 69 #endif |
OLD | NEW |