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

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

Issue 1896383003: Begin removing deprecated (and now, unused) ImageFilter code paths (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 4 years, 8 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') | src/effects/SkAlphaThresholdFilter.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(SkImageFilter::Proxy* proxy, 16 SkSpecialSurface_Base(const SkIRect& subset, const SkSurfaceProps* props)
17 const SkIRect& subset, const SkSurfaceProps* props) 17 : INHERITED(subset, props)
18 : INHERITED(proxy, subset, props)
19 , fCanvas(nullptr) { 18 , fCanvas(nullptr) {
20 } 19 }
21 20
22 virtual ~SkSpecialSurface_Base() { } 21 virtual ~SkSpecialSurface_Base() { }
23 22
24 // reset is called after an SkSpecialImage has been snapped 23 // reset is called after an SkSpecialImage has been snapped
25 void reset() { fCanvas.reset(); } 24 void reset() { fCanvas.reset(); }
26 25
27 // This can return nullptr if reset has already been called or something whe n wrong in the ctor 26 // This can return nullptr if reset has already been called or something whe n wrong in the ctor
28 SkCanvas* onGetCanvas() { return fCanvas; } 27 SkCanvas* onGetCanvas() { return fCanvas; }
29 28
30 virtual sk_sp<SkSpecialImage> onMakeImageSnapshot() = 0; 29 virtual sk_sp<SkSpecialImage> onMakeImageSnapshot() = 0;
31 30
32 protected: 31 protected:
33 SkAutoTUnref<SkCanvas> fCanvas; // initialized by derived classes in ctors 32 SkAutoTUnref<SkCanvas> fCanvas; // initialized by derived classes in ctors
34 33
35 private: 34 private:
36 typedef SkSpecialSurface INHERITED; 35 typedef SkSpecialSurface INHERITED;
37 }; 36 };
38 37
39 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
40 static SkSpecialSurface_Base* as_SB(SkSpecialSurface* surface) { 39 static SkSpecialSurface_Base* as_SB(SkSpecialSurface* surface) {
41 return static_cast<SkSpecialSurface_Base*>(surface); 40 return static_cast<SkSpecialSurface_Base*>(surface);
42 } 41 }
43 42
44 SkSpecialSurface::SkSpecialSurface(SkImageFilter::Proxy* proxy, 43 SkSpecialSurface::SkSpecialSurface(const SkIRect& subset,
45 const SkIRect& subset,
46 const SkSurfaceProps* props) 44 const SkSurfaceProps* props)
47 : fProps(SkSurfacePropsCopyOrDefault(props).flags(), kUnknown_SkPixelGeometr y) 45 : fProps(SkSurfacePropsCopyOrDefault(props).flags(), kUnknown_SkPixelGeometr y)
48 , fSubset(subset) 46 , fSubset(subset) {
49 , fProxy(proxy) {
50 SkASSERT(fSubset.width() > 0); 47 SkASSERT(fSubset.width() > 0);
51 SkASSERT(fSubset.height() > 0); 48 SkASSERT(fSubset.height() > 0);
52 } 49 }
53 50
54 SkCanvas* SkSpecialSurface::getCanvas() { 51 SkCanvas* SkSpecialSurface::getCanvas() {
55 return as_SB(this)->onGetCanvas(); 52 return as_SB(this)->onGetCanvas();
56 } 53 }
57 54
58 sk_sp<SkSpecialImage> SkSpecialSurface::makeImageSnapshot() { 55 sk_sp<SkSpecialImage> SkSpecialSurface::makeImageSnapshot() {
59 sk_sp<SkSpecialImage> image(as_SB(this)->onMakeImageSnapshot()); 56 sk_sp<SkSpecialImage> image(as_SB(this)->onMakeImageSnapshot());
60 as_SB(this)->reset(); 57 as_SB(this)->reset();
61 return image; // the caller gets the creation ref 58 return image; // the caller gets the creation ref
62 } 59 }
63 60
64 /////////////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////////////
65 #include "SkMallocPixelRef.h" 62 #include "SkMallocPixelRef.h"
66 63
67 class SkSpecialSurface_Raster : public SkSpecialSurface_Base { 64 class SkSpecialSurface_Raster : public SkSpecialSurface_Base {
68 public: 65 public:
69 SkSpecialSurface_Raster(SkImageFilter::Proxy* proxy, 66 SkSpecialSurface_Raster(SkPixelRef* pr,
70 SkPixelRef* pr,
71 const SkIRect& subset, 67 const SkIRect& subset,
72 const SkSurfaceProps* props) 68 const SkSurfaceProps* props)
73 : INHERITED(proxy, subset, props) { 69 : INHERITED(subset, props) {
74 const SkImageInfo& info = pr->info(); 70 const SkImageInfo& info = pr->info();
75 71
76 fBitmap.setInfo(info, info.minRowBytes()); 72 fBitmap.setInfo(info, info.minRowBytes());
77 fBitmap.setPixelRef(pr); 73 fBitmap.setPixelRef(pr);
78 74
79 fCanvas.reset(new SkCanvas(fBitmap, this->props())); 75 fCanvas.reset(new SkCanvas(fBitmap, this->props()));
80 fCanvas->clipRect(SkRect::Make(subset)); 76 fCanvas->clipRect(SkRect::Make(subset));
81 } 77 }
82 78
83 ~SkSpecialSurface_Raster() override { } 79 ~SkSpecialSurface_Raster() override { }
84 80
85 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { 81 sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
86 return SkSpecialImage::MakeFromRaster(this->proxy(), this->subset(), fBi tmap, 82 return SkSpecialImage::MakeFromRaster(this->subset(), fBitmap, &this->pr ops());
87 &this->props());
88 } 83 }
89 84
90 private: 85 private:
91 SkBitmap fBitmap; 86 SkBitmap fBitmap;
92 87
93 typedef SkSpecialSurface_Base INHERITED; 88 typedef SkSpecialSurface_Base INHERITED;
94 }; 89 };
95 90
96 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(SkImageFilter::Proxy* p roxy, 91 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(const SkIRect& subset, SkBitmap& bm,
97 const SkIRect& subset, SkBitmap& bm,
98 const SkSurfaceProps* p rops) { 92 const SkSurfaceProps* p rops) {
99 return sk_make_sp<SkSpecialSurface_Raster>(proxy, bm.pixelRef(), subset, pro ps); 93 return sk_make_sp<SkSpecialSurface_Raster>(bm.pixelRef(), subset, props);
100 } 94 }
101 95
102 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(SkImageFilter::Proxy* proxy , 96 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
103 const SkImageInfo& info,
104 const SkSurfaceProps* props ) { 97 const SkSurfaceProps* props ) {
105 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr)); 98 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
106 if (nullptr == pr.get()) { 99 if (nullptr == pr.get()) {
107 return nullptr; 100 return nullptr;
108 } 101 }
109 102
110 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ()); 103 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ());
111 104
112 return sk_make_sp<SkSpecialSurface_Raster>(proxy, pr, subset, props); 105 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props);
113 } 106 }
114 107
115 #if SK_SUPPORT_GPU 108 #if SK_SUPPORT_GPU
116 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
117 #include "GrContext.h" 110 #include "GrContext.h"
118 #include "SkGpuDevice.h" 111 #include "SkGpuDevice.h"
119 112
120 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { 113 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
121 public: 114 public:
122 SkSpecialSurface_Gpu(SkImageFilter::Proxy* proxy, 115 SkSpecialSurface_Gpu(GrTexture* texture,
123 GrTexture* texture,
124 const SkIRect& subset, 116 const SkIRect& subset,
125 const SkSurfaceProps* props) 117 const SkSurfaceProps* props)
126 : INHERITED(proxy, subset, props) 118 : INHERITED(subset, props)
127 , fTexture(SkRef(texture)) { 119 , fTexture(SkRef(texture)) {
128 120
129 SkASSERT(fTexture->asRenderTarget()); 121 SkASSERT(fTexture->asRenderTarget());
130 122
131 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props, 123 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props,
132 SkGpuDevice::kUnini t_InitContents)); 124 SkGpuDevice::kUnini t_InitContents));
133 if (!device) { 125 if (!device) {
134 return; 126 return;
135 } 127 }
136 128
137 fCanvas.reset(new SkCanvas(device)); 129 fCanvas.reset(new SkCanvas(device));
138 fCanvas->clipRect(SkRect::Make(subset)); 130 fCanvas->clipRect(SkRect::Make(subset));
139 } 131 }
140 132
141 ~SkSpecialSurface_Gpu() override { } 133 ~SkSpecialSurface_Gpu() override { }
142 134
143 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { 135 sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
144 return SkSpecialImage::MakeFromGpu(this->proxy(), this->subset(), 136 return SkSpecialImage::MakeFromGpu(this->subset(),
145 kNeedNewImageUniqueID_SpecialImage, f Texture, 137 kNeedNewImageUniqueID_SpecialImage, f Texture,
146 &this->props()); 138 &this->props());
147 } 139 }
148 140
149 private: 141 private:
150 SkAutoTUnref<GrTexture> fTexture; 142 SkAutoTUnref<GrTexture> fTexture;
151 143
152 typedef SkSpecialSurface_Base INHERITED; 144 typedef SkSpecialSurface_Base INHERITED;
153 }; 145 };
154 146
155 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy, 147 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset,
156 const SkIRect& subset,
157 GrTexture* texture, 148 GrTexture* texture,
158 const SkSurfaceProps* props) { 149 const SkSurfaceProps* props) {
159 if (!texture->asRenderTarget()) { 150 if (!texture->asRenderTarget()) {
160 return nullptr; 151 return nullptr;
161 } 152 }
162 153
163 return sk_make_sp<SkSpecialSurface_Gpu>(proxy, texture, subset, props); 154 return sk_make_sp<SkSpecialSurface_Gpu>(texture, subset, props);
164 } 155 }
165 156
166 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy, 157 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
167 GrContext* context,
168 const GrSurfaceDesc& desc, 158 const GrSurfaceDesc& desc,
169 const SkSurfaceProps* props) { 159 const SkSurfaceProps* props) {
170 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { 160 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
171 return nullptr; 161 return nullptr;
172 } 162 }
173 163
174 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc)); 164 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc));
175 if (!temp) { 165 if (!temp) {
176 return nullptr; 166 return nullptr;
177 } 167 }
178 168
179 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 169 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
180 170
181 return sk_make_sp<SkSpecialSurface_Gpu>(proxy, temp, subset, props); 171 return sk_make_sp<SkSpecialSurface_Gpu>(temp, subset, props);
182 } 172 }
183 173
184 #else 174 #else
185 175
186 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy, 176 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset,
187 const SkIRect& subset,
188 GrTexture*, 177 GrTexture*,
189 const SkSurfaceProps*) { 178 const SkSurfaceProps*) {
190 return nullptr; 179 return nullptr;
191 } 180 }
192 181
193 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy, 182 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
194 GrContext* context,
195 const GrSurfaceDesc& desc, 183 const GrSurfaceDesc& desc,
196 const SkSurfaceProps* props) { 184 const SkSurfaceProps* props) {
197 return nullptr; 185 return nullptr;
198 } 186 }
199 187
200 #endif 188 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialSurface.h ('k') | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698