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

Side by Side Diff: src/core/SkSpecialSurface.cpp

Issue 1705113002: Update SkSpecialImage API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix no-gpu build 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
« no previous file with comments | « src/core/SkSpecialSurface.h ('k') | tests/SpecialImageTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkSpecialImage.h" 9 #include "SkSpecialImage.h"
10 #include "SkSpecialSurface.h" 10 #include "SkSpecialSurface.h"
11 #include "SkSurfacePriv.h" 11 #include "SkSurfacePriv.h"
12 12
13 /////////////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////////////
14 class SkSpecialSurface_Base : public SkSpecialSurface { 14 class SkSpecialSurface_Base : public SkSpecialSurface {
15 public: 15 public:
16 SkSpecialSurface_Base(const SkIRect& subset, const SkSurfaceProps* props) 16 SkSpecialSurface_Base(SkImageFilter::Proxy* proxy,
17 : INHERITED(subset, props) 17 const SkIRect& subset, const SkSurfaceProps* props)
18 : INHERITED(proxy, subset, props)
18 , fCanvas(nullptr) { 19 , fCanvas(nullptr) {
19 } 20 }
20 21
21 virtual ~SkSpecialSurface_Base() { } 22 virtual ~SkSpecialSurface_Base() { }
22 23
23 // reset is called after an SkSpecialImage has been snapped 24 // reset is called after an SkSpecialImage has been snapped
24 void reset() { fCanvas.reset(); } 25 void reset() { fCanvas.reset(); }
25 26
26 // This can return nullptr if reset has already been called or something whe n wrong in the ctor 27 // This can return nullptr if reset has already been called or something whe n wrong in the ctor
27 SkCanvas* onGetCanvas() { return fCanvas; } 28 SkCanvas* onGetCanvas() { return fCanvas; }
28 29
29 virtual SkSpecialImage* onNewImageSnapshot() = 0; 30 virtual SkSpecialImage* onNewImageSnapshot() = 0;
30 31
31 protected: 32 protected:
32 SkAutoTUnref<SkCanvas> fCanvas; // initialized by derived classes in ctors 33 SkAutoTUnref<SkCanvas> fCanvas; // initialized by derived classes in ctors
33 34
34 private: 35 private:
35 typedef SkSpecialSurface INHERITED; 36 typedef SkSpecialSurface INHERITED;
36 }; 37 };
37 38
38 /////////////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////////////
39 static SkSpecialSurface_Base* as_SB(SkSpecialSurface* surface) { 40 static SkSpecialSurface_Base* as_SB(SkSpecialSurface* surface) {
40 return static_cast<SkSpecialSurface_Base*>(surface); 41 return static_cast<SkSpecialSurface_Base*>(surface);
41 } 42 }
42 43
43 SkSpecialSurface::SkSpecialSurface(const SkIRect& subset, const SkSurfaceProps* props) 44 SkSpecialSurface::SkSpecialSurface(SkImageFilter::Proxy* proxy,
45 const SkIRect& subset,
46 const SkSurfaceProps* props)
44 : fProps(SkSurfacePropsCopyOrDefault(props)) 47 : fProps(SkSurfacePropsCopyOrDefault(props))
45 , fSubset(subset) { 48 , fSubset(subset)
49 , fProxy(proxy) {
46 SkASSERT(fSubset.width() > 0); 50 SkASSERT(fSubset.width() > 0);
47 SkASSERT(fSubset.height() > 0); 51 SkASSERT(fSubset.height() > 0);
48 } 52 }
49 53
50 SkCanvas* SkSpecialSurface::getCanvas() { 54 SkCanvas* SkSpecialSurface::getCanvas() {
51 return as_SB(this)->onGetCanvas(); 55 return as_SB(this)->onGetCanvas();
52 } 56 }
53 57
54 SkSpecialImage* SkSpecialSurface::newImageSnapshot() { 58 SkSpecialImage* SkSpecialSurface::newImageSnapshot() {
55 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot(); 59 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot();
56 as_SB(this)->reset(); 60 as_SB(this)->reset();
57 return image; // the caller gets the creation ref 61 return image; // the caller gets the creation ref
58 } 62 }
59 63
60 /////////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////////
61 #include "SkMallocPixelRef.h" 65 #include "SkMallocPixelRef.h"
62 66
63 class SkSpecialSurface_Raster : public SkSpecialSurface_Base { 67 class SkSpecialSurface_Raster : public SkSpecialSurface_Base {
64 public: 68 public:
65 SkSpecialSurface_Raster(SkPixelRef* pr, const SkIRect& subset, const SkSurfa ceProps* props) 69 SkSpecialSurface_Raster(SkImageFilter::Proxy* proxy,
66 : INHERITED(subset, props) { 70 SkPixelRef* pr,
71 const SkIRect& subset,
72 const SkSurfaceProps* props)
73 : INHERITED(proxy, subset, props) {
67 const SkImageInfo& info = pr->info(); 74 const SkImageInfo& info = pr->info();
68 75
69 fBitmap.setInfo(info, info.minRowBytes()); 76 fBitmap.setInfo(info, info.minRowBytes());
70 fBitmap.setPixelRef(pr); 77 fBitmap.setPixelRef(pr);
71 78
72 fCanvas.reset(new SkCanvas(fBitmap)); 79 fCanvas.reset(new SkCanvas(fBitmap));
73 } 80 }
74 81
75 ~SkSpecialSurface_Raster() override { } 82 ~SkSpecialSurface_Raster() override { }
76 83
77 SkSpecialImage* onNewImageSnapshot() override { 84 SkSpecialImage* onNewImageSnapshot() override {
78 return SkSpecialImage::NewFromRaster(this->subset(), fBitmap); 85 return SkSpecialImage::NewFromRaster(this->proxy(), this->subset(), fBit map);
79 } 86 }
80 87
81 private: 88 private:
82 SkBitmap fBitmap; 89 SkBitmap fBitmap;
83 90
84 typedef SkSpecialSurface_Base INHERITED; 91 typedef SkSpecialSurface_Base INHERITED;
85 }; 92 };
86 93
87 SkSpecialSurface* SkSpecialSurface::NewFromBitmap(const SkIRect& subset, SkBitma p& bm, 94 SkSpecialSurface* SkSpecialSurface::NewFromBitmap(SkImageFilter::Proxy* proxy,
95 const SkIRect& subset, SkBitma p& bm,
88 const SkSurfaceProps* props) { 96 const SkSurfaceProps* props) {
89 return new SkSpecialSurface_Raster(bm.pixelRef(), subset, props); 97 return new SkSpecialSurface_Raster(proxy, bm.pixelRef(), subset, props);
90 } 98 }
91 99
92 SkSpecialSurface* SkSpecialSurface::NewRaster(const SkImageInfo& info, 100 SkSpecialSurface* SkSpecialSurface::NewRaster(SkImageFilter::Proxy* proxy,
101 const SkImageInfo& info,
93 const SkSurfaceProps* props) { 102 const SkSurfaceProps* props) {
94 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr)); 103 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
95 if (nullptr == pr.get()) { 104 if (nullptr == pr.get()) {
96 return nullptr; 105 return nullptr;
97 } 106 }
98 107
99 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ()); 108 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ());
100 109
101 return new SkSpecialSurface_Raster(pr, subset, props); 110 return new SkSpecialSurface_Raster(proxy, pr, subset, props);
102 } 111 }
103 112
104 #if SK_SUPPORT_GPU 113 #if SK_SUPPORT_GPU
105 /////////////////////////////////////////////////////////////////////////////// 114 ///////////////////////////////////////////////////////////////////////////////
106 #include "GrContext.h" 115 #include "GrContext.h"
107 #include "SkGpuDevice.h" 116 #include "SkGpuDevice.h"
108 117
109 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { 118 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
110 public: 119 public:
111 SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurf aceProps* props) 120 SkSpecialSurface_Gpu(SkImageFilter::Proxy* proxy,
112 : INHERITED(subset, props) 121 GrTexture* texture,
122 const SkIRect& subset,
123 const SkSurfaceProps* props)
124 : INHERITED(proxy, subset, props)
113 , fTexture(SkRef(texture)) { 125 , fTexture(SkRef(texture)) {
114 126
115 SkASSERT(fTexture->asRenderTarget()); 127 SkASSERT(fTexture->asRenderTarget());
116 128
117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props, 129 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props,
118 SkGpuDevice::kUnini t_InitContents)); 130 SkGpuDevice::kUnini t_InitContents));
119 if (!device) { 131 if (!device) {
120 return; 132 return;
121 } 133 }
122 134
123 fCanvas.reset(new SkCanvas(device)); 135 fCanvas.reset(new SkCanvas(device));
124 } 136 }
125 137
126 ~SkSpecialSurface_Gpu() override { } 138 ~SkSpecialSurface_Gpu() override { }
127 139
128 SkSpecialImage* onNewImageSnapshot() override { 140 SkSpecialImage* onNewImageSnapshot() override {
129 return SkSpecialImage::NewFromGpu(this->subset(), fTexture); 141 return SkSpecialImage::NewFromGpu(this->proxy(), this->subset(),
142 kNeedNewImageUniqueID_SpecialImage, fT exture);
130 } 143 }
131 144
132 private: 145 private:
133 SkAutoTUnref<GrTexture> fTexture; 146 SkAutoTUnref<GrTexture> fTexture;
134 147
135 typedef SkSpecialSurface_Base INHERITED; 148 typedef SkSpecialSurface_Base INHERITED;
136 }; 149 };
137 150
138 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText ure* texture, 151 SkSpecialSurface* SkSpecialSurface::NewFromTexture(SkImageFilter::Proxy* proxy,
152 const SkIRect& subset,
153 GrTexture* texture,
139 const SkSurfaceProps* props) { 154 const SkSurfaceProps* props) {
140 if (!texture->asRenderTarget()) { 155 if (!texture->asRenderTarget()) {
141 return nullptr; 156 return nullptr;
142 } 157 }
143 158
144 return new SkSpecialSurface_Gpu(texture, subset, props); 159 return new SkSpecialSurface_Gpu(proxy, texture, subset, props);
145 } 160 }
146 161
147 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, 162 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(SkImageFilter::Proxy* proxy,
163 GrContext* context,
148 const GrSurfaceDesc& desc, 164 const GrSurfaceDesc& desc,
149 const SkSurfaceProps* props) { 165 const SkSurfaceProps* props) {
150 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { 166 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
151 return nullptr; 167 return nullptr;
152 } 168 }
153 169
154 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc)); 170 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc));
155 if (!temp) { 171 if (!temp) {
156 return nullptr; 172 return nullptr;
157 } 173 }
158 174
159 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 175 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
160 176
161 return new SkSpecialSurface_Gpu(temp, subset, props); 177 return new SkSpecialSurface_Gpu(proxy, temp, subset, props);
162 } 178 }
163 179
164 #else 180 #else
165 181
166 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText ure*, 182 SkSpecialSurface* SkSpecialSurface::NewFromTexture(SkImageFilter::Proxy* proxy,
183 const SkIRect& subset,
184 GrTexture*,
167 const SkSurfaceProps*) { 185 const SkSurfaceProps*) {
168 return nullptr; 186 return nullptr;
169 } 187 }
170 188
171 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, 189 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(SkImageFilter::Proxy* proxy,
190 GrContext* context,
172 const GrSurfaceDesc& desc, 191 const GrSurfaceDesc& desc,
173 const SkSurfaceProps* props) { 192 const SkSurfaceProps* props) {
174 return nullptr; 193 return nullptr;
175 } 194 }
176 195
177 #endif 196 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialSurface.h ('k') | tests/SpecialImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698