robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 7 | #include "SkSpecialImage.h" |
| 8 | |
| 9 | #if SK_SUPPORT_GPU |
| 10 | #include "GrTexture.h" |
| 11 | #include "GrTextureParams.h" |
| 12 | #include "SkGr.h" |
| 13 | #endif |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 14 | |
| 15 | #include "SkCanvas.h" |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 16 | #include "SkImage_Base.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 17 | #include "SkSpecialSurface.h" |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 18 | #include "SkSurfacePriv.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 19 | |
| 20 | /////////////////////////////////////////////////////////////////////////////// |
| 21 | class SkSpecialImage_Base : public SkSpecialImage { |
| 22 | public: |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 23 | SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint32_t uniqueID, |
| 24 | const SkSurfaceProps* props) |
| 25 | : INHERITED(proxy, subset, uniqueID, props) { |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 26 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 27 | virtual ~SkSpecialImage_Base() { } |
| 28 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 29 | virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 30 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 31 | virtual bool onPeekPixels(SkPixmap*) const { return false; } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 32 | |
| 33 | virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 34 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 35 | virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; |
| 36 | |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 37 | // Delete this entry point ASAP (see skbug.com/4965) |
robertphillips | ab01ccd | 2016-03-08 10:45:32 -0800 | [diff] [blame] | 38 | virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 39 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 40 | virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 41 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 42 | virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0; |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 43 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 44 | virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 45 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 46 | virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const = 0; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | typedef SkSpecialImage INHERITED; |
| 50 | }; |
| 51 | |
| 52 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 53 | static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 54 | return static_cast<const SkSpecialImage_Base*>(image); |
| 55 | } |
| 56 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 57 | SkSpecialImage::SkSpecialImage(SkImageFilter::Proxy* proxy, |
| 58 | const SkIRect& subset, |
| 59 | uint32_t uniqueID, |
| 60 | const SkSurfaceProps* props) |
| 61 | : fProps(SkSurfacePropsCopyOrDefault(props)) |
| 62 | , fSubset(subset) |
| 63 | , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::ImageID() : uniqueID) |
| 64 | , fProxy(proxy) { |
| 65 | } |
| 66 | |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 67 | sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(SkImageFilter::Proxy* proxy, |
| 68 | GrContext* context) { |
| 69 | #if SK_SUPPORT_GPU |
| 70 | if (!context) { |
| 71 | return nullptr; |
| 72 | } |
| 73 | if (GrTexture* peek = as_SIB(this)->peekTexture()) { |
| 74 | return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)) : nullptr; |
| 75 | } |
| 76 | |
| 77 | SkBitmap bmp; |
| 78 | if (!this->internal_getBM(&bmp)) { |
| 79 | return nullptr; |
| 80 | } |
| 81 | |
robertphillips | 83f2e5a | 2016-03-24 06:31:25 -0700 | [diff] [blame] | 82 | if (bmp.empty()) { |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 83 | return SkSpecialImage::MakeFromRaster(proxy, SkIRect::MakeEmpty(), bmp, &this->props()); |
robertphillips | 83f2e5a | 2016-03-24 06:31:25 -0700 | [diff] [blame] | 84 | } |
| 85 | |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 86 | SkAutoTUnref<GrTexture> resultTex( |
| 87 | GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter())); |
| 88 | if (!resultTex) { |
| 89 | return nullptr; |
| 90 | } |
| 91 | |
| 92 | SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 93 | |
| 94 | return SkSpecialImage::MakeFromGpu(proxy, |
| 95 | SkIRect::MakeWH(resultTex->width(), resultTex->height()), |
| 96 | this->uniqueID(), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 97 | resultTex, &this->props(), at); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 98 | #else |
| 99 | return nullptr; |
| 100 | #endif |
| 101 | } |
| 102 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 103 | void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const { |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 104 | return as_SIB(this)->onDraw(canvas, x, y, paint); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 105 | } |
| 106 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 107 | bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
| 108 | return as_SIB(this)->onPeekPixels(pixmap); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | GrTexture* SkSpecialImage::peekTexture() const { |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 112 | return as_SIB(this)->onPeekTexture(); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 113 | } |
| 114 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 115 | bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { |
| 116 | return as_SIB(this)->testingOnlyOnGetROPixels(result); |
| 117 | } |
| 118 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 119 | sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const { |
| 120 | return as_SIB(this)->onMakeSurface(info); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 121 | } |
| 122 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 123 | sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 124 | return as_SIB(this)->onMakeTightSurface(info); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 125 | } |
| 126 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 127 | sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
| 128 | return as_SIB(this)->onMakeSubset(subset); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 129 | } |
| 130 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 131 | sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
| 132 | return as_SIB(this)->onMakeTightSubset(subset); |
| 133 | } |
| 134 | |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 135 | #if SK_SUPPORT_GPU |
| 136 | #include "SkGr.h" |
| 137 | #include "SkGrPixelRef.h" |
| 138 | #endif |
| 139 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 140 | sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 141 | const SkBitmap& src, |
| 142 | const SkSurfaceProps* props) { |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 143 | // Need to test offset case! (see skbug.com/4967) |
| 144 | if (src.getTexture()) { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 145 | return SkSpecialImage::MakeFromGpu(proxy, |
| 146 | src.bounds(), |
| 147 | src.getGenerationID(), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 148 | src.getTexture(), |
| 149 | props); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 150 | } |
| 151 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 152 | return SkSpecialImage::MakeFromRaster(proxy, src.bounds(), src, props); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | bool SkSpecialImage::internal_getBM(SkBitmap* result) { |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 156 | const SkSpecialImage_Base* ib = as_SIB(this); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 157 | |
| 158 | // TODO: need to test offset case! (see skbug.com/4967) |
robertphillips | ab01ccd | 2016-03-08 10:45:32 -0800 | [diff] [blame] | 159 | return ib->getBitmapDeprecated(result); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 160 | } |
| 161 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 162 | SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() const { |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 163 | return fProxy; |
| 164 | } |
| 165 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 166 | /////////////////////////////////////////////////////////////////////////////// |
| 167 | #include "SkImage.h" |
| 168 | #if SK_SUPPORT_GPU |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 169 | #include "GrContext.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 170 | #include "SkGrPriv.h" |
| 171 | #endif |
| 172 | |
| 173 | class SkSpecialImage_Image : public SkSpecialImage_Base { |
| 174 | public: |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 175 | SkSpecialImage_Image(SkImageFilter::Proxy* proxy, |
| 176 | const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 177 | sk_sp<SkImage> image, |
| 178 | const SkSurfaceProps* props) |
| 179 | : INHERITED(proxy, subset, image->uniqueID(), props) |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 180 | , fImage(image) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | ~SkSpecialImage_Image() override { } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 184 | |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 185 | bool isOpaque() const override { return fImage->isOpaque(); } |
| 186 | |
| 187 | size_t getSize() const override { |
| 188 | #if SK_SUPPORT_GPU |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 189 | if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 190 | return texture->gpuMemorySize(); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 191 | } else |
| 192 | #endif |
| 193 | { |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 194 | SkPixmap pm; |
| 195 | if (fImage->peekPixels(&pm)) { |
| 196 | return pm.height() * pm.rowBytes(); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 202 | void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 203 | SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); |
| 204 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 205 | canvas->drawImageRect(fImage.get(), this->subset(), |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 206 | dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 207 | } |
| 208 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 209 | bool onPeekPixels(SkPixmap* pixmap) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 210 | return fImage->peekPixels(pixmap); |
| 211 | } |
| 212 | |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 213 | GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peekTexture(); } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 214 | |
robertphillips | ab01ccd | 2016-03-08 10:45:32 -0800 | [diff] [blame] | 215 | bool getBitmapDeprecated(SkBitmap* result) const override { |
robertphillips | 6ac97b7 | 2016-03-09 05:17:10 -0800 | [diff] [blame] | 216 | #if SK_SUPPORT_GPU |
| 217 | if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 218 | const SkImageInfo info = GrMakeInfoFromTexture(texture, |
robertphillips | 6ac97b7 | 2016-03-09 05:17:10 -0800 | [diff] [blame] | 219 | fImage->width(), fImage->height(), |
| 220 | fImage->isOpaque()); |
| 221 | if (!result->setInfo(info)) { |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
| 226 | return true; |
| 227 | } |
| 228 | #endif |
| 229 | |
| 230 | return as_IB(fImage.get())->asBitmapForImageFilters(result); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 231 | } |
| 232 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 233 | bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
robertphillips | 6ac97b7 | 2016-03-09 05:17:10 -0800 | [diff] [blame] | 234 | return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 235 | } |
| 236 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 237 | sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 238 | #if SK_SUPPORT_GPU |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 239 | GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 240 | if (texture) { |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 241 | GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *texture->getContext()->caps()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 242 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 243 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 244 | return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->getContext(), desc); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 245 | } |
| 246 | #endif |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 247 | return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 248 | } |
| 249 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 250 | sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 251 | sk_sp<SkImage> subsetImg(fImage->makeSubset(subset)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 252 | if (!subsetImg) { |
| 253 | return nullptr; |
| 254 | } |
| 255 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 256 | return SkSpecialImage::MakeFromImage(this->internal_getProxy(), |
| 257 | SkIRect::MakeWH(subset.width(), subset.height()), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 258 | subsetImg, |
| 259 | &this->props()); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 260 | } |
| 261 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 262 | sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 263 | return fImage->makeSubset(subset); |
| 264 | } |
| 265 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 266 | sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 267 | #if SK_SUPPORT_GPU |
| 268 | GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
| 269 | if (texture) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 270 | return SkSurface::MakeRenderTarget(texture->getContext(), SkBudgeted::kYes, info); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 271 | } |
| 272 | #endif |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 273 | return SkSurface::MakeRaster(info, nullptr); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 274 | } |
| 275 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 276 | private: |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 277 | sk_sp<SkImage> fImage; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 278 | |
| 279 | typedef SkSpecialImage_Base INHERITED; |
| 280 | }; |
| 281 | |
| 282 | #ifdef SK_DEBUG |
| 283 | static bool rect_fits(const SkIRect& rect, int width, int height) { |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 284 | if (0 == width && 0 == height) { |
| 285 | SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == rect.fBottom); |
| 286 | return true; |
| 287 | } |
| 288 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 289 | return rect.fLeft >= 0 && rect.fLeft < width && rect.fLeft < rect.fRight && |
| 290 | rect.fRight >= 0 && rect.fRight <= width && |
| 291 | rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && |
| 292 | rect.fBottom >= 0 && rect.fBottom <= height; |
| 293 | } |
| 294 | #endif |
| 295 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 296 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(SkImageFilter::Proxy* proxy, |
| 297 | const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 298 | sk_sp<SkImage> image, |
| 299 | const SkSurfaceProps* props) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 300 | SkASSERT(rect_fits(subset, image->width(), image->height())); |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 301 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 302 | return sk_make_sp<SkSpecialImage_Image>(proxy, subset, image, props); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /////////////////////////////////////////////////////////////////////////////// |
| 306 | #include "SkBitmap.h" |
| 307 | #include "SkImageInfo.h" |
| 308 | #include "SkPixelRef.h" |
| 309 | |
| 310 | class SkSpecialImage_Raster : public SkSpecialImage_Base { |
| 311 | public: |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 312 | SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, const SkIRect& subset, const SkBitmap& bm, |
| 313 | const SkSurfaceProps* props) |
| 314 | : INHERITED(proxy, subset, bm.getGenerationID(), props) |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 315 | , fBitmap(bm) { |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 316 | if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 317 | // we only preemptively lock if there is no chance of triggering something expensive |
| 318 | // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already. |
| 319 | fBitmap.lockPixels(); |
| 320 | } |
| 321 | } |
| 322 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 323 | SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, |
| 324 | const SkIRect& subset, |
| 325 | const SkPixmap& pixmap, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 326 | RasterReleaseProc releaseProc, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 327 | ReleaseContext context, |
| 328 | const SkSurfaceProps* props) |
| 329 | : INHERITED(proxy, subset, kNeedNewImageUniqueID_SpecialImage, props) { |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 330 | fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(), |
| 331 | pixmap.rowBytes(), pixmap.ctable(), |
| 332 | releaseProc, context); |
| 333 | } |
| 334 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 335 | ~SkSpecialImage_Raster() override { } |
| 336 | |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 337 | bool isOpaque() const override { return fBitmap.isOpaque(); } |
| 338 | |
| 339 | size_t getSize() const override { return fBitmap.getSize(); } |
| 340 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 341 | void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 342 | SkRect dst = SkRect::MakeXYWH(x, y, |
| 343 | this->subset().width(), this->subset().height()); |
| 344 | |
| 345 | canvas->drawBitmapRect(fBitmap, this->subset(), |
| 346 | dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 347 | } |
| 348 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 349 | bool onPeekPixels(SkPixmap* pixmap) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 350 | const SkImageInfo info = fBitmap.info(); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 351 | |
| 352 | if (kUnknown_SkColorType == info.colorType()) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 353 | return false; |
| 354 | } |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 355 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 356 | if (!fBitmap.peekPixels(pixmap)) { |
| 357 | fBitmap.lockPixels(); |
| 358 | } |
| 359 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 360 | return fBitmap.peekPixels(pixmap); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 361 | } |
| 362 | |
robertphillips | ab01ccd | 2016-03-08 10:45:32 -0800 | [diff] [blame] | 363 | bool getBitmapDeprecated(SkBitmap* result) const override { |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 364 | *result = fBitmap; |
| 365 | return true; |
| 366 | } |
| 367 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 368 | bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
| 369 | *result = fBitmap; |
| 370 | return true; |
| 371 | } |
| 372 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 373 | sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override { |
| 374 | return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 375 | } |
| 376 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 377 | sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 378 | SkBitmap subsetBM; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 379 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 380 | if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 381 | return nullptr; |
| 382 | } |
| 383 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 384 | return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), |
| 385 | SkIRect::MakeWH(subset.width(), subset.height()), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 386 | subsetBM, |
| 387 | &this->props()); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 388 | } |
| 389 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 390 | sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 391 | SkBitmap subsetBM; |
| 392 | |
| 393 | if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 394 | return nullptr; |
| 395 | } |
| 396 | |
| 397 | return SkImage::MakeFromBitmap(subsetBM); |
| 398 | } |
| 399 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 400 | sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { |
| 401 | return SkSurface::MakeRaster(info); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 402 | } |
| 403 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 404 | private: |
| 405 | SkBitmap fBitmap; |
| 406 | |
| 407 | typedef SkSpecialImage_Base INHERITED; |
| 408 | }; |
| 409 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 410 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy, |
| 411 | const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 412 | const SkBitmap& bm, |
| 413 | const SkSurfaceProps* props) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 414 | SkASSERT(nullptr == bm.getTexture()); |
| 415 | SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 416 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 417 | return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, bm, props); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 418 | } |
| 419 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 420 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(SkImageFilter::Proxy* proxy, |
| 421 | const SkIRect& subset, |
| 422 | const SkPixmap& src, |
| 423 | RasterReleaseProc releaseProc, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 424 | ReleaseContext context, |
| 425 | const SkSurfaceProps* props) { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 426 | if (!src.addr()) { |
| 427 | return nullptr; |
| 428 | } |
| 429 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 430 | return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, context, props); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 434 | #if SK_SUPPORT_GPU |
| 435 | /////////////////////////////////////////////////////////////////////////////// |
| 436 | #include "GrTexture.h" |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 437 | #include "SkImage_Gpu.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 438 | |
| 439 | class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 440 | public: |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 441 | SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 442 | uint32_t uniqueID, GrTexture* tex, SkAlphaType at, |
| 443 | const SkSurfaceProps* props) |
| 444 | : INHERITED(proxy, subset, uniqueID, props) |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 445 | , fTexture(SkRef(tex)) |
| 446 | , fAlphaType(at) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | ~SkSpecialImage_Gpu() override { } |
| 450 | |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 451 | bool isOpaque() const override { |
| 452 | return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_SkAlphaType; |
| 453 | } |
| 454 | |
| 455 | size_t getSize() const override { return fTexture->gpuMemorySize(); } |
| 456 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 457 | void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 458 | SkRect dst = SkRect::MakeXYWH(x, y, |
| 459 | this->subset().width(), this->subset().height()); |
| 460 | |
| 461 | SkBitmap bm; |
| 462 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 463 | GrWrapTextureInBitmap(fTexture, |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 464 | fTexture->width(), fTexture->height(), this->isOpaque(), &bm); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 465 | |
| 466 | canvas->drawBitmapRect(bm, this->subset(), |
| 467 | dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 468 | } |
| 469 | |
| 470 | GrTexture* onPeekTexture() const override { return fTexture; } |
| 471 | |
robertphillips | ab01ccd | 2016-03-08 10:45:32 -0800 | [diff] [blame] | 472 | bool getBitmapDeprecated(SkBitmap* result) const override { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 473 | const SkImageInfo info = GrMakeInfoFromTexture(fTexture, |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 474 | this->width(), this->height(), |
| 475 | this->isOpaque()); |
| 476 | if (!result->setInfo(info)) { |
| 477 | return false; |
| 478 | } |
| 479 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 480 | const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->height()); |
| 481 | |
| 482 | SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); |
| 483 | result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop); |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 484 | return true; |
| 485 | } |
| 486 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 487 | bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
| 488 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 489 | const SkImageInfo info = SkImageInfo::MakeN32(this->width(), |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 490 | this->height(), |
| 491 | this->isOpaque() ? kOpaque_SkAlphaType |
| 492 | : kPremul_SkAlphaType); |
| 493 | if (!result->tryAllocPixels(info)) { |
| 494 | return false; |
| 495 | } |
| 496 | |
| 497 | if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia8888_GrPixelConfig, |
| 498 | result->getPixels(), result->rowBytes())) { |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | result->pixelRef()->setImmutable(); |
| 503 | return true; |
| 504 | } |
| 505 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 506 | sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override { |
robertphillips | 090b762 | 2016-03-28 11:07:43 -0700 | [diff] [blame] | 507 | if (!fTexture->getContext()) { |
| 508 | return nullptr; |
| 509 | } |
| 510 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 511 | GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContext()->caps()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 512 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 513 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 514 | return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getContext(), desc); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 515 | } |
| 516 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 517 | sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 518 | return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), |
| 519 | subset, |
| 520 | this->uniqueID(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 521 | fTexture, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 522 | &this->props(), |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 523 | fAlphaType); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 524 | } |
| 525 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 526 | sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 527 | if (0 == subset.fLeft && 0 == subset.fTop && |
| 528 | fTexture->width() == subset.width() && |
| 529 | fTexture->height() == subset.height()) { |
| 530 | // The existing GrTexture is already tight so reuse it in the SkImage |
| 531 | return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height(), |
| 532 | kNeedNewImageUniqueID, |
| 533 | fAlphaType, fTexture, SkBudgeted::kYes); |
| 534 | } |
| 535 | |
| 536 | GrContext* ctx = fTexture->getContext(); |
| 537 | GrSurfaceDesc desc = fTexture->desc(); |
| 538 | desc.fWidth = subset.width(); |
| 539 | desc.fHeight = subset.height(); |
| 540 | |
robertphillips | d25d06b | 2016-03-22 09:56:58 -0700 | [diff] [blame] | 541 | SkAutoTUnref<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, |
| 542 | SkBudgeted::kYes)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 543 | if (!subTx) { |
| 544 | return nullptr; |
| 545 | } |
| 546 | ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
| 547 | return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, |
| 548 | fAlphaType, subTx, SkBudgeted::kYes); |
| 549 | } |
| 550 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 551 | sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { |
| 552 | return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 553 | } |
| 554 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 555 | private: |
| 556 | SkAutoTUnref<GrTexture> fTexture; |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 557 | const SkAlphaType fAlphaType; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 558 | |
| 559 | typedef SkSpecialImage_Base INHERITED; |
| 560 | }; |
| 561 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 562 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 563 | const SkIRect& subset, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 564 | uint32_t uniqueID, |
| 565 | GrTexture* tex, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 566 | const SkSurfaceProps* props, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 567 | SkAlphaType at) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 568 | SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 569 | return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at, props); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | #else |
| 573 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 574 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 575 | const SkIRect& subset, |
| 576 | uint32_t uniqueID, |
| 577 | GrTexture* tex, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame^] | 578 | const SkSurfaceProps* props, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 579 | SkAlphaType at) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 580 | return nullptr; |
| 581 | } |
| 582 | |
| 583 | #endif |