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 14 matching lines...) Expand all Loading... |
25 * scope. | 25 * scope. |
26 */ | 26 */ |
27 virtual SkCanvas* onNewCanvas() = 0; | 27 virtual SkCanvas* onNewCanvas() = 0; |
28 | 28 |
29 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; | 29 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; |
30 | 30 |
31 /** | 31 /** |
32 * Allocate an SkImage that represents the current contents of the surface. | 32 * Allocate an SkImage that represents the current contents of the surface. |
33 * This needs to be able to outlive the surface itself (if need be), and | 33 * This needs to be able to outlive the surface itself (if need be), and |
34 * must faithfully represent the current contents, even if the surface | 34 * must faithfully represent the current contents, even if the surface |
35 * is chaged after this calle (e.g. it is drawn to via its canvas). | 35 * is changed after this called (e.g. it is drawn to via its canvas). |
36 */ | 36 */ |
37 virtual SkImage* onNewImageSnapshot() = 0; | 37 virtual SkImage* onNewImageSnapshot(Budgeted) = 0; |
38 | 38 |
39 /** | 39 /** |
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 /** |
51 * Called as a performance hint when the Surface is allowed to make it's con
tents | 51 * Called as a performance hint when the Surface is allowed to make it's con
tents |
52 * undefined. | 52 * undefined. |
53 */ | 53 */ |
54 virtual void onDiscard() {} | 54 virtual void onDiscard() {} |
55 | 55 |
56 /** | 56 /** |
57 * If the surface is about to change, we call this so that our subclass | 57 * If the surface is about to change, we call this so that our subclass |
58 * can optionally fork their backend (copy-on-write) in case it was | 58 * can optionally fork their backend (copy-on-write) in case it was |
59 * being shared with the cachedImage. | 59 * being shared with the cachedImage. |
60 */ | 60 */ |
61 virtual void onCopyOnWrite(ContentChangeMode) = 0; | 61 virtual void onCopyOnWrite(ContentChangeMode) = 0; |
62 | 62 |
63 inline SkCanvas* getCachedCanvas(); | 63 inline SkCanvas* getCachedCanvas(); |
64 inline SkImage* getCachedImage(); | 64 inline SkImage* getCachedImage(Budgeted); |
65 | 65 |
66 // called by SkSurface to compute a new genID | 66 // called by SkSurface to compute a new genID |
67 uint32_t newGenerationID(); | 67 uint32_t newGenerationID(); |
68 | 68 |
69 private: | 69 private: |
70 SkCanvas* fCachedCanvas; | 70 SkCanvas* fCachedCanvas; |
71 SkImage* fCachedImage; | 71 SkImage* fCachedImage; |
72 | 72 |
73 void aboutToDraw(ContentChangeMode mode); | 73 void aboutToDraw(ContentChangeMode mode); |
74 friend class SkCanvas; | 74 friend class SkCanvas; |
75 friend class SkSurface; | 75 friend class SkSurface; |
76 | 76 |
77 typedef SkSurface INHERITED; | 77 typedef SkSurface INHERITED; |
78 }; | 78 }; |
79 | 79 |
80 SkCanvas* SkSurface_Base::getCachedCanvas() { | 80 SkCanvas* SkSurface_Base::getCachedCanvas() { |
81 if (NULL == fCachedCanvas) { | 81 if (NULL == fCachedCanvas) { |
82 fCachedCanvas = this->onNewCanvas(); | 82 fCachedCanvas = this->onNewCanvas(); |
83 if (fCachedCanvas) { | 83 if (fCachedCanvas) { |
84 fCachedCanvas->setSurfaceBase(this); | 84 fCachedCanvas->setSurfaceBase(this); |
85 } | 85 } |
86 } | 86 } |
87 return fCachedCanvas; | 87 return fCachedCanvas; |
88 } | 88 } |
89 | 89 |
90 SkImage* SkSurface_Base::getCachedImage() { | 90 SkImage* SkSurface_Base::getCachedImage(Budgeted budgeted) { |
91 if (NULL == fCachedImage) { | 91 if (NULL == fCachedImage) { |
92 fCachedImage = this->onNewImageSnapshot(); | 92 fCachedImage = this->onNewImageSnapshot(budgeted); |
93 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | 93 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
94 } | 94 } |
95 return fCachedImage; | 95 return fCachedImage; |
96 } | 96 } |
97 | 97 |
98 #endif | 98 #endif |
OLD | NEW |