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