Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/image/SkSurface_Base.h

Issue 1686163002: Allow client to force an SkImage snapshot to be unique (and uniquely own its backing store). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix enum to bool warning Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkImagePriv.h"
12 #include "SkSurface.h" 13 #include "SkSurface.h"
13 #include "SkSurfacePriv.h" 14 #include "SkSurfacePriv.h"
14 15
15 class SkSurface_Base : public SkSurface { 16 class SkSurface_Base : public SkSurface {
16 public: 17 public:
17 SkSurface_Base(int width, int height, const SkSurfaceProps*); 18 SkSurface_Base(int width, int height, const SkSurfaceProps*);
18 SkSurface_Base(const SkImageInfo&, const SkSurfaceProps*); 19 SkSurface_Base(const SkImageInfo&, const SkSurfaceProps*);
19 virtual ~SkSurface_Base(); 20 virtual ~SkSurface_Base();
20 21
21 virtual GrBackendObject onGetTextureHandle(BackendHandleAccess) { 22 virtual GrBackendObject onGetTextureHandle(BackendHandleAccess) {
(...skipping 13 matching lines...) Expand all
35 virtual SkCanvas* onNewCanvas() = 0; 36 virtual SkCanvas* onNewCanvas() = 0;
36 37
37 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; 38 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0;
38 39
39 /** 40 /**
40 * Allocate an SkImage that represents the current contents of the surface. 41 * Allocate an SkImage that represents the current contents of the surface.
41 * 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
42 * must faithfully represent the current contents, even if the surface 43 * must faithfully represent the current contents, even if the surface
43 * 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).
44 */ 45 */
45 virtual SkImage* onNewImageSnapshot(Budgeted) = 0; 46 virtual SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) = 0;
46 47
47 /** 48 /**
48 * Default implementation: 49 * Default implementation:
49 * 50 *
50 * image = this->newImageSnapshot(); 51 * image = this->newImageSnapshot();
51 * if (image) { 52 * if (image) {
52 * image->draw(canvas, ...); 53 * image->draw(canvas, ...);
53 * image->unref(); 54 * image->unref();
54 * } 55 * }
55 */ 56 */
(...skipping 12 matching lines...) Expand all
68 */ 69 */
69 virtual void onCopyOnWrite(ContentChangeMode) = 0; 70 virtual void onCopyOnWrite(ContentChangeMode) = 0;
70 71
71 /** 72 /**
72 * Signal the surface to remind its backing store that it's mutable again. 73 * Signal the surface to remind its backing store that it's mutable again.
73 * 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.
74 */ 75 */
75 virtual void onRestoreBackingMutability() {} 76 virtual void onRestoreBackingMutability() {}
76 77
77 inline SkCanvas* getCachedCanvas(); 78 inline SkCanvas* getCachedCanvas();
78 inline SkImage* getCachedImage(Budgeted); 79 inline SkImage* refCachedImage(Budgeted, ForceUnique);
79 80
80 bool hasCachedImage() const { return fCachedImage != nullptr; } 81 bool hasCachedImage() const { return fCachedImage != nullptr; }
81 82
82 // called by SkSurface to compute a new genID 83 // called by SkSurface to compute a new genID
83 uint32_t newGenerationID(); 84 uint32_t newGenerationID();
84 85
85 private: 86 private:
86 SkCanvas* fCachedCanvas; 87 SkCanvas* fCachedCanvas;
87 SkImage* fCachedImage; 88 SkImage* fCachedImage;
88 89
(...skipping 12 matching lines...) Expand all
101 SkCanvas* SkSurface_Base::getCachedCanvas() { 102 SkCanvas* SkSurface_Base::getCachedCanvas() {
102 if (nullptr == fCachedCanvas) { 103 if (nullptr == fCachedCanvas) {
103 fCachedCanvas = this->onNewCanvas(); 104 fCachedCanvas = this->onNewCanvas();
104 if (fCachedCanvas) { 105 if (fCachedCanvas) {
105 fCachedCanvas->setSurfaceBase(this); 106 fCachedCanvas->setSurfaceBase(this);
106 } 107 }
107 } 108 }
108 return fCachedCanvas; 109 return fCachedCanvas;
109 } 110 }
110 111
111 SkImage* SkSurface_Base::getCachedImage(Budgeted budgeted) { 112 SkImage* SkSurface_Base::refCachedImage(Budgeted budgeted, ForceUnique unique) {
112 if (nullptr == fCachedImage) { 113 SkImage* snap = fCachedImage;
113 fCachedImage = this->onNewImageSnapshot(budgeted); 114 if (kYes_ForceUnique == unique && snap && !snap->unique()) {
114 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); 115 snap = nullptr;
115 } 116 }
116 return fCachedImage; 117 if (snap) {
118 return SkRef(snap);
119 }
120 ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode :
121 kNo_ForceCopyMode;
122 snap = this->onNewImageSnapshot(budgeted, fcm);
123 if (kNo_ForceUnique == unique) {
124 SkASSERT(!fCachedImage);
125 fCachedImage = SkSafeRef(snap);
126 }
127 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
128 return snap;
117 } 129 }
118 130
119 #endif 131 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface.cpp ('k') | src/image/SkSurface_Gpu.h » ('j') | src/image/SkSurface_Gpu.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698