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