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

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: update 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
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 } 76 }
81 77
82 ~SkSpecialSurface_Raster() override { } 78 ~SkSpecialSurface_Raster() override { }
83 79
84 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { 80 sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
85 return SkSpecialImage::MakeFromRaster(this->proxy(), this->subset(), fBi tmap, 81 return SkSpecialImage::MakeFromRaster(this->subset(), fBitmap, &this->pr ops());
86 &this->props());
87 } 82 }
88 83
89 private: 84 private:
90 SkBitmap fBitmap; 85 SkBitmap fBitmap;
91 86
92 typedef SkSpecialSurface_Base INHERITED; 87 typedef SkSpecialSurface_Base INHERITED;
93 }; 88 };
94 89
95 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(SkImageFilter::Proxy* p roxy, 90 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(const SkIRect& subset, SkBitmap& bm,
96 const SkIRect& subset, SkBitmap& bm,
97 const SkSurfaceProps* p rops) { 91 const SkSurfaceProps* p rops) {
98 return sk_make_sp<SkSpecialSurface_Raster>(proxy, bm.pixelRef(), subset, pro ps); 92 return sk_make_sp<SkSpecialSurface_Raster>(bm.pixelRef(), subset, props);
99 } 93 }
100 94
101 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(SkImageFilter::Proxy* proxy , 95 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
102 const SkImageInfo& info,
103 const SkSurfaceProps* props ) { 96 const SkSurfaceProps* props ) {
104 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr)); 97 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
105 if (nullptr == pr.get()) { 98 if (nullptr == pr.get()) {
106 return nullptr; 99 return nullptr;
107 } 100 }
108 101
109 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ()); 102 const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height ());
110 103
111 return sk_make_sp<SkSpecialSurface_Raster>(proxy, pr, subset, props); 104 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props);
112 } 105 }
113 106
114 #if SK_SUPPORT_GPU 107 #if SK_SUPPORT_GPU
115 /////////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////////
116 #include "GrContext.h" 109 #include "GrContext.h"
117 #include "SkGpuDevice.h" 110 #include "SkGpuDevice.h"
118 111
119 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { 112 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
120 public: 113 public:
121 SkSpecialSurface_Gpu(SkImageFilter::Proxy* proxy, 114 SkSpecialSurface_Gpu(GrTexture* texture,
122 GrTexture* texture,
123 const SkIRect& subset, 115 const SkIRect& subset,
124 const SkSurfaceProps* props) 116 const SkSurfaceProps* props)
125 : INHERITED(proxy, subset, props) 117 : INHERITED(subset, props)
126 , fTexture(SkRef(texture)) { 118 , fTexture(SkRef(texture)) {
127 119
128 SkASSERT(fTexture->asRenderTarget()); 120 SkASSERT(fTexture->asRenderTarget());
129 121
130 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props, 122 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props,
131 SkGpuDevice::kUnini t_InitContents)); 123 SkGpuDevice::kUnini t_InitContents));
132 if (!device) { 124 if (!device) {
133 return; 125 return;
134 } 126 }
135 127
136 fCanvas.reset(new SkCanvas(device)); 128 fCanvas.reset(new SkCanvas(device));
137 } 129 }
138 130
139 ~SkSpecialSurface_Gpu() override { } 131 ~SkSpecialSurface_Gpu() override { }
140 132
141 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { 133 sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
142 return SkSpecialImage::MakeFromGpu(this->proxy(), this->subset(), 134 return SkSpecialImage::MakeFromGpu(this->subset(),
143 kNeedNewImageUniqueID_SpecialImage, f Texture, 135 kNeedNewImageUniqueID_SpecialImage, f Texture,
144 &this->props()); 136 &this->props());
145 } 137 }
146 138
147 private: 139 private:
148 SkAutoTUnref<GrTexture> fTexture; 140 SkAutoTUnref<GrTexture> fTexture;
149 141
150 typedef SkSpecialSurface_Base INHERITED; 142 typedef SkSpecialSurface_Base INHERITED;
151 }; 143 };
152 144
153 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy, 145 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset,
154 const SkIRect& subset,
155 GrTexture* texture, 146 GrTexture* texture,
156 const SkSurfaceProps* props) { 147 const SkSurfaceProps* props) {
157 if (!texture->asRenderTarget()) { 148 if (!texture->asRenderTarget()) {
158 return nullptr; 149 return nullptr;
159 } 150 }
160 151
161 return sk_make_sp<SkSpecialSurface_Gpu>(proxy, texture, subset, props); 152 return sk_make_sp<SkSpecialSurface_Gpu>(texture, subset, props);
162 } 153 }
163 154
164 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy, 155 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
165 GrContext* context,
166 const GrSurfaceDesc& desc, 156 const GrSurfaceDesc& desc,
167 const SkSurfaceProps* props) { 157 const SkSurfaceProps* props) {
168 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { 158 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
169 return nullptr; 159 return nullptr;
170 } 160 }
171 161
172 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc)); 162 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc));
173 if (!temp) { 163 if (!temp) {
174 return nullptr; 164 return nullptr;
175 } 165 }
176 166
177 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 167 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
178 168
179 return sk_make_sp<SkSpecialSurface_Gpu>(proxy, temp, subset, props); 169 return sk_make_sp<SkSpecialSurface_Gpu>(temp, subset, props);
180 } 170 }
181 171
182 #else 172 #else
183 173
184 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy, 174 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset,
185 const SkIRect& subset,
186 GrTexture*, 175 GrTexture*,
187 const SkSurfaceProps*) { 176 const SkSurfaceProps*) {
188 return nullptr; 177 return nullptr;
189 } 178 }
190 179
191 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy, 180 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
192 GrContext* context,
193 const GrSurfaceDesc& desc, 181 const GrSurfaceDesc& desc,
194 const SkSurfaceProps* props) { 182 const SkSurfaceProps* props) {
195 return nullptr; 183 return nullptr;
196 } 184 }
197 185
198 #endif 186 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698