OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkSurface_Base_DEFINED | 8 #ifndef SkSurface_Base_DEFINED |
9 #define SkSurface_Base_DEFINED | 9 #define SkSurface_Base_DEFINED |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 * Default implementation: | 40 * Default implementation: |
41 * | 41 * |
42 * image = this->newImageSnapshot(); | 42 * image = this->newImageSnapshot(); |
43 * if (image) { | 43 * if (image) { |
44 * image->draw(canvas, ...); | 44 * image->draw(canvas, ...); |
45 * image->unref(); | 45 * image->unref(); |
46 * } | 46 * } |
47 */ | 47 */ |
48 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); | 48 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); |
49 | 49 |
50 /** | 50 inline SkCanvas* getCachedCanvas(); |
51 * Called as a performance hint when the Surface is allowed to make it's con
tents | |
52 * undefined. | |
53 */ | |
54 virtual void onDiscard() {} | |
55 | 51 |
56 /** | 52 protected: |
57 * If the surface is about to change, we call this so that our subclass | 53 // Must be called by the subclasses to compute a new genID. |
58 * can optionally fork their backend (copy-on-write) in case it was | |
59 * being shared with the cachedImage. | |
60 */ | |
61 virtual void onCopyOnWrite(ContentChangeMode) = 0; | |
62 | |
63 inline SkCanvas* getCachedCanvas(); | |
64 inline SkImage* getCachedImage(Budgeted); | |
65 | |
66 // called by SkSurface to compute a new genID | |
67 uint32_t newGenerationID(); | 54 uint32_t newGenerationID(); |
68 | 55 |
69 private: | 56 private: |
70 SkCanvas* fCachedCanvas; | 57 SkCanvas* fCachedCanvas; |
71 SkImage* fCachedImage; | |
72 | 58 |
73 void aboutToDraw(ContentChangeMode mode); | |
74 friend class SkCanvas; | |
75 friend class SkSurface; | 59 friend class SkSurface; |
76 | |
77 typedef SkSurface INHERITED; | 60 typedef SkSurface INHERITED; |
78 }; | 61 }; |
79 | 62 |
80 SkCanvas* SkSurface_Base::getCachedCanvas() { | 63 SkCanvas* SkSurface_Base::getCachedCanvas() { |
81 if (NULL == fCachedCanvas) { | 64 if (NULL == fCachedCanvas) { |
82 fCachedCanvas = this->onNewCanvas(); | 65 fCachedCanvas = this->onNewCanvas(); |
83 if (fCachedCanvas) { | |
84 fCachedCanvas->setSurfaceBase(this); | |
85 } | |
86 } | 66 } |
87 return fCachedCanvas; | 67 return fCachedCanvas; |
88 } | 68 } |
89 | 69 |
90 SkImage* SkSurface_Base::getCachedImage(Budgeted budgeted) { | |
91 if (NULL == fCachedImage) { | |
92 fCachedImage = this->onNewImageSnapshot(budgeted); | |
93 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | |
94 } | |
95 return fCachedImage; | |
96 } | |
97 | |
98 #endif | 70 #endif |
OLD | NEW |