blob: e90c655a5824567bb64035da8643567ea77f73e1 [file] [log] [blame]
robertphillipsb6c65e92016-02-04 10:52:42 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file
6 */
7
8#include "SkCanvas.h"
bsalomon84a4e5a2016-02-29 11:41:52 -08009#include "SkImage_Base.h"
robertphillipsb6c65e92016-02-04 10:52:42 -080010#include "SkSpecialImage.h"
11#include "SkSpecialSurface.h"
12
13///////////////////////////////////////////////////////////////////////////////
14class SkSpecialImage_Base : public SkSpecialImage {
15public:
robertphillips3b087f42016-02-18 08:48:03 -080016 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint32_t uniqueID)
17 : INHERITED(proxy, subset, uniqueID) {
18 }
robertphillipsb6c65e92016-02-04 10:52:42 -080019 virtual ~SkSpecialImage_Base() { }
20
robertphillipse8c34972016-02-16 12:09:36 -080021 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0;
robertphillipsb6c65e92016-02-04 10:52:42 -080022
robertphillipsc5035e72016-03-17 06:58:39 -070023 virtual bool onPeekPixels(SkPixmap*) const { return false; }
robertphillipsb6c65e92016-02-04 10:52:42 -080024
25 virtual GrTexture* onPeekTexture() const { return nullptr; }
26
robertphillips4418dba2016-03-07 12:45:14 -080027 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0;
28
robertphillips3b087f42016-02-18 08:48:03 -080029 // Delete this entry point ASAP (see skbug.com/4965)
robertphillipsab01ccd2016-03-08 10:45:32 -080030 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0;
robertphillips3b087f42016-02-18 08:48:03 -080031
robertphillips37bd7c32016-03-17 14:31:39 -070032 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0;
robertphillipsc5035e72016-03-17 06:58:39 -070033
robertphillips37bd7c32016-03-17 14:31:39 -070034 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0;
robertphillipsb6c65e92016-02-04 10:52:42 -080035
36private:
37 typedef SkSpecialImage INHERITED;
38};
39
40///////////////////////////////////////////////////////////////////////////////
bsalomon84a4e5a2016-02-29 11:41:52 -080041static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) {
robertphillipsb6c65e92016-02-04 10:52:42 -080042 return static_cast<const SkSpecialImage_Base*>(image);
43}
44
robertphillipse8c34972016-02-16 12:09:36 -080045void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const {
bsalomon84a4e5a2016-02-29 11:41:52 -080046 return as_SIB(this)->onDraw(canvas, x, y, paint);
robertphillipsb6c65e92016-02-04 10:52:42 -080047}
48
robertphillipsc5035e72016-03-17 06:58:39 -070049bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const {
50 return as_SIB(this)->onPeekPixels(pixmap);
robertphillipsb6c65e92016-02-04 10:52:42 -080051}
52
53GrTexture* SkSpecialImage::peekTexture() const {
bsalomon84a4e5a2016-02-29 11:41:52 -080054 return as_SIB(this)->onPeekTexture();
robertphillipsb6c65e92016-02-04 10:52:42 -080055}
56
robertphillips4418dba2016-03-07 12:45:14 -080057bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const {
58 return as_SIB(this)->testingOnlyOnGetROPixels(result);
59}
60
robertphillips37bd7c32016-03-17 14:31:39 -070061sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const {
62 return as_SIB(this)->onMakeSurface(info);
robertphillipsb6c65e92016-02-04 10:52:42 -080063}
64
robertphillips37bd7c32016-03-17 14:31:39 -070065sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
66 return as_SIB(this)->onMakeSubset(subset);
robertphillipsc5035e72016-03-17 06:58:39 -070067}
68
robertphillips3b087f42016-02-18 08:48:03 -080069#if SK_SUPPORT_GPU
70#include "SkGr.h"
71#include "SkGrPixelRef.h"
72#endif
73
robertphillips37bd7c32016-03-17 14:31:39 -070074sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy,
75 const SkBitmap& src) {
robertphillips3b087f42016-02-18 08:48:03 -080076 // Need to test offset case! (see skbug.com/4967)
77 if (src.getTexture()) {
robertphillips37bd7c32016-03-17 14:31:39 -070078 return SkSpecialImage::MakeFromGpu(proxy,
79 src.bounds(),
80 src.getGenerationID(),
81 src.getTexture());
robertphillips3b087f42016-02-18 08:48:03 -080082 }
83
robertphillips37bd7c32016-03-17 14:31:39 -070084 return SkSpecialImage::MakeFromRaster(proxy, src.bounds(), src);
robertphillips3b087f42016-02-18 08:48:03 -080085}
86
87bool SkSpecialImage::internal_getBM(SkBitmap* result) {
bsalomon84a4e5a2016-02-29 11:41:52 -080088 const SkSpecialImage_Base* ib = as_SIB(this);
robertphillips3b087f42016-02-18 08:48:03 -080089
90 // TODO: need to test offset case! (see skbug.com/4967)
robertphillipsab01ccd2016-03-08 10:45:32 -080091 return ib->getBitmapDeprecated(result);
robertphillips3b087f42016-02-18 08:48:03 -080092}
93
robertphillipsc5035e72016-03-17 06:58:39 -070094SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() const {
robertphillips3b087f42016-02-18 08:48:03 -080095 return fProxy;
96}
97
robertphillipsb6c65e92016-02-04 10:52:42 -080098///////////////////////////////////////////////////////////////////////////////
99#include "SkImage.h"
100#if SK_SUPPORT_GPU
robertphillipsb6c65e92016-02-04 10:52:42 -0800101#include "SkGrPriv.h"
102#endif
103
104class SkSpecialImage_Image : public SkSpecialImage_Base {
105public:
robertphillips37bd7c32016-03-17 14:31:39 -0700106 SkSpecialImage_Image(SkImageFilter::Proxy* proxy,
107 const SkIRect& subset,
108 sk_sp<SkImage> image)
robertphillips3b087f42016-02-18 08:48:03 -0800109 : INHERITED(proxy, subset, image->uniqueID())
robertphillips37bd7c32016-03-17 14:31:39 -0700110 , fImage(image) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800111 }
112
113 ~SkSpecialImage_Image() override { }
robertphillips37bd7c32016-03-17 14:31:39 -0700114
robertphillips3b087f42016-02-18 08:48:03 -0800115 bool isOpaque() const override { return fImage->isOpaque(); }
116
117 size_t getSize() const override {
118#if SK_SUPPORT_GPU
bsalomon84a4e5a2016-02-29 11:41:52 -0800119 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) {
120 return texture->gpuMemorySize();
robertphillips3b087f42016-02-18 08:48:03 -0800121 } else
122#endif
123 {
reed6ceeebd2016-03-09 14:26:26 -0800124 SkPixmap pm;
125 if (fImage->peekPixels(&pm)) {
126 return pm.height() * pm.rowBytes();
robertphillips3b087f42016-02-18 08:48:03 -0800127 }
128 }
129 return 0;
130 }
131
robertphillipse8c34972016-02-16 12:09:36 -0800132 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800133 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height());
134
robertphillips37bd7c32016-03-17 14:31:39 -0700135 canvas->drawImageRect(fImage.get(), this->subset(),
robertphillipsb6c65e92016-02-04 10:52:42 -0800136 dst, paint, SkCanvas::kStrict_SrcRectConstraint);
137 }
138
robertphillipsc5035e72016-03-17 06:58:39 -0700139 bool onPeekPixels(SkPixmap* pixmap) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800140 return fImage->peekPixels(pixmap);
141 }
142
bsalomon84a4e5a2016-02-29 11:41:52 -0800143 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peekTexture(); }
robertphillipsb6c65e92016-02-04 10:52:42 -0800144
robertphillipsab01ccd2016-03-08 10:45:32 -0800145 bool getBitmapDeprecated(SkBitmap* result) const override {
robertphillips6ac97b72016-03-09 05:17:10 -0800146#if SK_SUPPORT_GPU
147 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) {
148 const SkImageInfo info = GrMakeInfoFromTexture(texture,
149 fImage->width(), fImage->height(),
150 fImage->isOpaque());
151 if (!result->setInfo(info)) {
152 return false;
153 }
154
155 result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
156 return true;
157 }
158#endif
159
160 return as_IB(fImage.get())->asBitmapForImageFilters(result);
robertphillips3b087f42016-02-18 08:48:03 -0800161 }
162
robertphillips4418dba2016-03-07 12:45:14 -0800163 bool testingOnlyOnGetROPixels(SkBitmap* result) const override {
robertphillips6ac97b72016-03-09 05:17:10 -0800164 return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
robertphillips4418dba2016-03-07 12:45:14 -0800165 }
166
robertphillips37bd7c32016-03-17 14:31:39 -0700167 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800168#if SK_SUPPORT_GPU
bsalomon84a4e5a2016-02-29 11:41:52 -0800169 GrTexture* texture = as_IB(fImage.get())->peekTexture();
robertphillipsb6c65e92016-02-04 10:52:42 -0800170 if (texture) {
brianosmanc571c002016-03-17 13:01:26 -0700171 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info);
robertphillipsb6c65e92016-02-04 10:52:42 -0800172 desc.fFlags = kRenderTarget_GrSurfaceFlag;
173
robertphillips37bd7c32016-03-17 14:31:39 -0700174 return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->getContext(), desc);
robertphillipsb6c65e92016-02-04 10:52:42 -0800175 }
176#endif
robertphillips37bd7c32016-03-17 14:31:39 -0700177 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr);
robertphillipsb6c65e92016-02-04 10:52:42 -0800178 }
179
robertphillips37bd7c32016-03-17 14:31:39 -0700180 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
181 sk_sp<SkImage> subsetImg(fImage->makeSubset(subset));
robertphillipsc5035e72016-03-17 06:58:39 -0700182 if (!subsetImg) {
183 return nullptr;
184 }
185
robertphillips37bd7c32016-03-17 14:31:39 -0700186 return SkSpecialImage::MakeFromImage(this->internal_getProxy(),
187 SkIRect::MakeWH(subset.width(), subset.height()),
188 subsetImg);
robertphillipsc5035e72016-03-17 06:58:39 -0700189 }
190
robertphillipsb6c65e92016-02-04 10:52:42 -0800191private:
robertphillips37bd7c32016-03-17 14:31:39 -0700192 sk_sp<SkImage> fImage;
robertphillipsb6c65e92016-02-04 10:52:42 -0800193
194 typedef SkSpecialImage_Base INHERITED;
195};
196
197#ifdef SK_DEBUG
198static bool rect_fits(const SkIRect& rect, int width, int height) {
robertphillips4418dba2016-03-07 12:45:14 -0800199 if (0 == width && 0 == height) {
200 SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == rect.fBottom);
201 return true;
202 }
203
robertphillipsb6c65e92016-02-04 10:52:42 -0800204 return rect.fLeft >= 0 && rect.fLeft < width && rect.fLeft < rect.fRight &&
205 rect.fRight >= 0 && rect.fRight <= width &&
206 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom &&
207 rect.fBottom >= 0 && rect.fBottom <= height;
208}
209#endif
210
robertphillips37bd7c32016-03-17 14:31:39 -0700211sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(SkImageFilter::Proxy* proxy,
212 const SkIRect& subset,
213 sk_sp<SkImage> image) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800214 SkASSERT(rect_fits(subset, image->width(), image->height()));
robertphillips37bd7c32016-03-17 14:31:39 -0700215
216 return sk_make_sp<SkSpecialImage_Image>(proxy, subset, image);
robertphillipsb6c65e92016-02-04 10:52:42 -0800217}
218
219///////////////////////////////////////////////////////////////////////////////
220#include "SkBitmap.h"
221#include "SkImageInfo.h"
222#include "SkPixelRef.h"
223
224class SkSpecialImage_Raster : public SkSpecialImage_Base {
225public:
robertphillips3b087f42016-02-18 08:48:03 -0800226 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, const SkIRect& subset, const SkBitmap& bm)
227 : INHERITED(proxy, subset, bm.getGenerationID())
robertphillipsb6c65e92016-02-04 10:52:42 -0800228 , fBitmap(bm) {
robertphillips4418dba2016-03-07 12:45:14 -0800229 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800230 // we only preemptively lock if there is no chance of triggering something expensive
231 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already.
232 fBitmap.lockPixels();
233 }
234 }
235
robertphillipsc5035e72016-03-17 06:58:39 -0700236 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy,
237 const SkIRect& subset,
238 const SkPixmap& pixmap,
robertphillips37bd7c32016-03-17 14:31:39 -0700239 RasterReleaseProc releaseProc,
240 ReleaseContext context)
robertphillipsc5035e72016-03-17 06:58:39 -0700241 : INHERITED(proxy, subset, kNeedNewImageUniqueID_SpecialImage) {
242 fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(),
243 pixmap.rowBytes(), pixmap.ctable(),
244 releaseProc, context);
245 }
246
robertphillipsb6c65e92016-02-04 10:52:42 -0800247 ~SkSpecialImage_Raster() override { }
248
robertphillips3b087f42016-02-18 08:48:03 -0800249 bool isOpaque() const override { return fBitmap.isOpaque(); }
250
251 size_t getSize() const override { return fBitmap.getSize(); }
252
robertphillipse8c34972016-02-16 12:09:36 -0800253 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800254 SkRect dst = SkRect::MakeXYWH(x, y,
255 this->subset().width(), this->subset().height());
256
257 canvas->drawBitmapRect(fBitmap, this->subset(),
258 dst, paint, SkCanvas::kStrict_SrcRectConstraint);
259 }
260
robertphillipsc5035e72016-03-17 06:58:39 -0700261 bool onPeekPixels(SkPixmap* pixmap) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800262 const SkImageInfo info = fBitmap.info();
263 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) {
264 return false;
265 }
robertphillipsc5035e72016-03-17 06:58:39 -0700266
267 return fBitmap.peekPixels(pixmap);
robertphillipsb6c65e92016-02-04 10:52:42 -0800268 }
269
robertphillipsab01ccd2016-03-08 10:45:32 -0800270 bool getBitmapDeprecated(SkBitmap* result) const override {
robertphillips3b087f42016-02-18 08:48:03 -0800271 *result = fBitmap;
272 return true;
273 }
274
robertphillips4418dba2016-03-07 12:45:14 -0800275 bool testingOnlyOnGetROPixels(SkBitmap* result) const override {
276 *result = fBitmap;
277 return true;
278 }
279
robertphillips37bd7c32016-03-17 14:31:39 -0700280 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
281 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr);
robertphillipsb6c65e92016-02-04 10:52:42 -0800282 }
283
robertphillips37bd7c32016-03-17 14:31:39 -0700284 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
robertphillipsc5035e72016-03-17 06:58:39 -0700285 SkBitmap subsetBM;
286
287 if (!fBitmap.extractSubset(&subsetBM, subset)) {
288 return nullptr;
289 }
290
robertphillips37bd7c32016-03-17 14:31:39 -0700291 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(),
292 SkIRect::MakeWH(subset.width(), subset.height()),
293 subsetBM);
robertphillipsc5035e72016-03-17 06:58:39 -0700294 }
295
robertphillipsb6c65e92016-02-04 10:52:42 -0800296private:
297 SkBitmap fBitmap;
298
299 typedef SkSpecialImage_Base INHERITED;
300};
301
robertphillips37bd7c32016-03-17 14:31:39 -0700302sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy,
303 const SkIRect& subset,
304 const SkBitmap& bm) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800305 SkASSERT(nullptr == bm.getTexture());
306 SkASSERT(rect_fits(subset, bm.width(), bm.height()));
robertphillips37bd7c32016-03-17 14:31:39 -0700307
308 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, bm);
robertphillipsb6c65e92016-02-04 10:52:42 -0800309}
310
robertphillips37bd7c32016-03-17 14:31:39 -0700311sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(SkImageFilter::Proxy* proxy,
312 const SkIRect& subset,
313 const SkPixmap& src,
314 RasterReleaseProc releaseProc,
315 ReleaseContext context) {
316 if (!src.addr()) {
317 return nullptr;
318 }
319
320 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, context);
robertphillipsc5035e72016-03-17 06:58:39 -0700321}
322
323
robertphillipsb6c65e92016-02-04 10:52:42 -0800324#if SK_SUPPORT_GPU
325///////////////////////////////////////////////////////////////////////////////
326#include "GrTexture.h"
327
328class SkSpecialImage_Gpu : public SkSpecialImage_Base {
robertphillips3b087f42016-02-18 08:48:03 -0800329public:
330 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset,
331 uint32_t uniqueID, GrTexture* tex, SkAlphaType at)
332 : INHERITED(proxy, subset, uniqueID)
333 , fTexture(SkRef(tex))
334 , fAlphaType(at) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800335 }
336
337 ~SkSpecialImage_Gpu() override { }
338
robertphillips3b087f42016-02-18 08:48:03 -0800339 bool isOpaque() const override {
340 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_SkAlphaType;
341 }
342
343 size_t getSize() const override { return fTexture->gpuMemorySize(); }
344
robertphillipse8c34972016-02-16 12:09:36 -0800345 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
robertphillipsb6c65e92016-02-04 10:52:42 -0800346 SkRect dst = SkRect::MakeXYWH(x, y,
347 this->subset().width(), this->subset().height());
348
349 SkBitmap bm;
350
robertphillipsb6c65e92016-02-04 10:52:42 -0800351 GrWrapTextureInBitmap(fTexture,
robertphillips3b087f42016-02-18 08:48:03 -0800352 fTexture->width(), fTexture->height(), this->isOpaque(), &bm);
robertphillipsb6c65e92016-02-04 10:52:42 -0800353
354 canvas->drawBitmapRect(bm, this->subset(),
355 dst, paint, SkCanvas::kStrict_SrcRectConstraint);
356 }
357
358 GrTexture* onPeekTexture() const override { return fTexture; }
359
robertphillipsab01ccd2016-03-08 10:45:32 -0800360 bool getBitmapDeprecated(SkBitmap* result) const override {
robertphillips3b087f42016-02-18 08:48:03 -0800361 const SkImageInfo info = GrMakeInfoFromTexture(fTexture,
362 this->width(), this->height(),
363 this->isOpaque());
364 if (!result->setInfo(info)) {
365 return false;
366 }
367
robertphillipsc5035e72016-03-17 06:58:39 -0700368 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->height());
369
370 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture));
371 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop);
robertphillips3b087f42016-02-18 08:48:03 -0800372 return true;
373 }
374
robertphillips4418dba2016-03-07 12:45:14 -0800375 bool testingOnlyOnGetROPixels(SkBitmap* result) const override {
376
377 const SkImageInfo info = SkImageInfo::MakeN32(this->width(),
378 this->height(),
379 this->isOpaque() ? kOpaque_SkAlphaType
380 : kPremul_SkAlphaType);
381 if (!result->tryAllocPixels(info)) {
382 return false;
383 }
384
385 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia8888_GrPixelConfig,
386 result->getPixels(), result->rowBytes())) {
387 return false;
388 }
389
390 result->pixelRef()->setImmutable();
391 return true;
392 }
393
robertphillips37bd7c32016-03-17 14:31:39 -0700394 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
brianosmanc571c002016-03-17 13:01:26 -0700395 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info);
robertphillipsb6c65e92016-02-04 10:52:42 -0800396 desc.fFlags = kRenderTarget_GrSurfaceFlag;
397
robertphillips37bd7c32016-03-17 14:31:39 -0700398 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getContext(), desc);
robertphillipsb6c65e92016-02-04 10:52:42 -0800399 }
400
robertphillips37bd7c32016-03-17 14:31:39 -0700401 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
402 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(),
403 subset,
404 this->uniqueID(),
405 fTexture,
406 fAlphaType);
robertphillipsc5035e72016-03-17 06:58:39 -0700407 }
408
robertphillipsb6c65e92016-02-04 10:52:42 -0800409private:
410 SkAutoTUnref<GrTexture> fTexture;
robertphillips3b087f42016-02-18 08:48:03 -0800411 const SkAlphaType fAlphaType;
robertphillipsb6c65e92016-02-04 10:52:42 -0800412
413 typedef SkSpecialImage_Base INHERITED;
414};
415
robertphillips37bd7c32016-03-17 14:31:39 -0700416sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy,
417 const SkIRect& subset,
418 uint32_t uniqueID,
419 GrTexture* tex,
420 SkAlphaType at) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800421 SkASSERT(rect_fits(subset, tex->width(), tex->height()));
robertphillips37bd7c32016-03-17 14:31:39 -0700422 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at);
robertphillipsb6c65e92016-02-04 10:52:42 -0800423}
424
425#else
426
robertphillips37bd7c32016-03-17 14:31:39 -0700427sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy,
428 const SkIRect& subset,
429 uint32_t uniqueID,
430 GrTexture* tex,
431 SkAlphaType at) {
robertphillipsb6c65e92016-02-04 10:52:42 -0800432 return nullptr;
433}
434
435#endif