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 25 matching lines...) Expand all Loading... |
36 virtual SkCanvas* onNewCanvas() = 0; | 36 virtual SkCanvas* onNewCanvas() = 0; |
37 | 37 |
38 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; | 38 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; |
39 | 39 |
40 /** | 40 /** |
41 * Allocate an SkImage that represents the current contents of the surface. | 41 * Allocate an SkImage that represents the current contents of the surface. |
42 * This needs to be able to outlive the surface itself (if need be), and | 42 * This needs to be able to outlive the surface itself (if need be), and |
43 * must faithfully represent the current contents, even if the surface | 43 * must faithfully represent the current contents, even if the surface |
44 * is changed after this called (e.g. it is drawn to via its canvas). | 44 * is changed after this called (e.g. it is drawn to via its canvas). |
45 */ | 45 */ |
46 virtual SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0; | 46 virtual SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) = 0; |
47 | 47 |
48 /** | 48 /** |
49 * Default implementation: | 49 * Default implementation: |
50 * | 50 * |
51 * image = this->newImageSnapshot(); | 51 * image = this->newImageSnapshot(); |
52 * if (image) { | 52 * if (image) { |
53 * image->draw(canvas, ...); | 53 * image->draw(canvas, ...); |
54 * image->unref(); | 54 * image->unref(); |
55 * } | 55 * } |
56 */ | 56 */ |
(...skipping 17 matching lines...) Expand all Loading... |
74 * Called only when we _didn't_ copy-on-write; we assume the copies start m
utable. | 74 * Called only when we _didn't_ copy-on-write; we assume the copies start m
utable. |
75 */ | 75 */ |
76 virtual void onRestoreBackingMutability() {} | 76 virtual void onRestoreBackingMutability() {} |
77 | 77 |
78 /** | 78 /** |
79 * Issue any pending surface IO to the current backend 3D API and resolve an
y surface MSAA. | 79 * Issue any pending surface IO to the current backend 3D API and resolve an
y surface MSAA. |
80 */ | 80 */ |
81 virtual void onPrepareForExternalIO() {} | 81 virtual void onPrepareForExternalIO() {} |
82 | 82 |
83 inline SkCanvas* getCachedCanvas(); | 83 inline SkCanvas* getCachedCanvas(); |
84 inline SkImage* refCachedImage(SkBudgeted, ForceUnique); | 84 inline SkImage* refCachedImage(Budgeted, ForceUnique); |
85 | 85 |
86 bool hasCachedImage() const { return fCachedImage != nullptr; } | 86 bool hasCachedImage() const { return fCachedImage != nullptr; } |
87 | 87 |
88 // called by SkSurface to compute a new genID | 88 // called by SkSurface to compute a new genID |
89 uint32_t newGenerationID(); | 89 uint32_t newGenerationID(); |
90 | 90 |
91 private: | 91 private: |
92 SkCanvas* fCachedCanvas; | 92 SkCanvas* fCachedCanvas; |
93 SkImage* fCachedImage; | 93 SkImage* fCachedImage; |
94 | 94 |
(...skipping 12 matching lines...) Expand all Loading... |
107 SkCanvas* SkSurface_Base::getCachedCanvas() { | 107 SkCanvas* SkSurface_Base::getCachedCanvas() { |
108 if (nullptr == fCachedCanvas) { | 108 if (nullptr == fCachedCanvas) { |
109 fCachedCanvas = this->onNewCanvas(); | 109 fCachedCanvas = this->onNewCanvas(); |
110 if (fCachedCanvas) { | 110 if (fCachedCanvas) { |
111 fCachedCanvas->setSurfaceBase(this); | 111 fCachedCanvas->setSurfaceBase(this); |
112 } | 112 } |
113 } | 113 } |
114 return fCachedCanvas; | 114 return fCachedCanvas; |
115 } | 115 } |
116 | 116 |
117 SkImage* SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique unique)
{ | 117 SkImage* SkSurface_Base::refCachedImage(Budgeted budgeted, ForceUnique unique) { |
118 SkImage* snap = fCachedImage; | 118 SkImage* snap = fCachedImage; |
119 if (kYes_ForceUnique == unique && snap && !snap->unique()) { | 119 if (kYes_ForceUnique == unique && snap && !snap->unique()) { |
120 snap = nullptr; | 120 snap = nullptr; |
121 } | 121 } |
122 if (snap) { | 122 if (snap) { |
123 return SkRef(snap); | 123 return SkRef(snap); |
124 } | 124 } |
125 ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : | 125 ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : |
126 kNo_ForceCopyMode; | 126 kNo_ForceCopyMode; |
127 snap = this->onNewImageSnapshot(budgeted, fcm); | 127 snap = this->onNewImageSnapshot(budgeted, fcm); |
128 if (kNo_ForceUnique == unique) { | 128 if (kNo_ForceUnique == unique) { |
129 SkASSERT(!fCachedImage); | 129 SkASSERT(!fCachedImage); |
130 fCachedImage = SkSafeRef(snap); | 130 fCachedImage = SkSafeRef(snap); |
131 } | 131 } |
132 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | 132 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
133 return snap; | 133 return snap; |
134 } | 134 } |
135 | 135 |
136 #endif | 136 #endif |
OLD | NEW |