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 | */ |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 7 | |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 8 | #include "SkSpecialImage.h" |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 9 | #include "SkBitmap.h" |
| 10 | #include "SkImage.h" |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 11 | #include "SkBitmapCache.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 12 | #include "SkCanvas.h" |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 13 | #include "SkImage_Base.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 14 | #include "SkSpecialSurface.h" |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 15 | #include "SkSurfacePriv.h" |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 16 | #include "SkPixelRef.h" |
| 17 | |
| 18 | #if SK_SUPPORT_GPU |
| 19 | #include "GrContext.h" |
| 20 | #include "GrTexture.h" |
| 21 | #include "GrTextureParams.h" |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 22 | #include "GrTextureProxy.h" |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 23 | #include "SkGr.h" |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 24 | #include "SkGrPriv.h" |
| 25 | #endif |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 26 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 27 | // Currently the raster imagefilters can only handle certain imageinfos. Call this to know if |
| 28 | // a given info is supported. |
| 29 | static bool valid_for_imagefilters(const SkImageInfo& info) { |
| 30 | // no support for other swizzles/depths yet |
| 31 | return info.colorType() == kN32_SkColorType; |
| 32 | } |
| 33 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 34 | /////////////////////////////////////////////////////////////////////////////// |
| 35 | class SkSpecialImage_Base : public SkSpecialImage { |
| 36 | public: |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 37 | SkSpecialImage_Base(const SkIRect& subset, uint32_t uniqueID, const SkSurfaceProps* props) |
| 38 | : INHERITED(subset, uniqueID, props) { |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 39 | } |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 40 | ~SkSpecialImage_Base() override { } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 41 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 42 | virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 43 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 44 | virtual bool onGetROPixels(SkBitmap*) const = 0; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 45 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 46 | virtual GrContext* onGetContext() const { return nullptr; } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 47 | |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 48 | virtual SkColorSpace* onGetColorSpace() const = 0; |
| 49 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 50 | #if SK_SUPPORT_GPU |
| 51 | virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 52 | virtual sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const = 0; |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 53 | #endif |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 54 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 55 | virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 56 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 57 | virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, |
| 58 | const SkISize& size, SkAlphaType at) const = 0; |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 59 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 60 | virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 61 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 62 | virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, |
| 63 | const SkISize& size, SkAlphaType at) const = 0; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | typedef SkSpecialImage INHERITED; |
| 67 | }; |
| 68 | |
| 69 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 70 | static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 71 | return static_cast<const SkSpecialImage_Base*>(image); |
| 72 | } |
| 73 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 74 | SkSpecialImage::SkSpecialImage(const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 75 | uint32_t uniqueID, |
| 76 | const SkSurfaceProps* props) |
| 77 | : fProps(SkSurfacePropsCopyOrDefault(props)) |
| 78 | , fSubset(subset) |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 79 | , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::ImageID() : uniqueID) { |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 80 | } |
| 81 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 82 | sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) { |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 83 | #if SK_SUPPORT_GPU |
| 84 | if (!context) { |
| 85 | return nullptr; |
| 86 | } |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 87 | if (GrContext* curContext = as_SIB(this)->onGetContext()) { |
| 88 | return curContext == context ? sk_sp<SkSpecialImage>(SkRef(this)) : nullptr; |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | SkBitmap bmp; |
reed | cf5c846 | 2016-07-20 12:28:40 -0700 | [diff] [blame] | 92 | // At this point, we are definitely not texture-backed, so we must be raster or generator |
| 93 | // backed. If we remove the special-wrapping-an-image subclass, we may be able to assert that |
| 94 | // we are strictly raster-backed (i.e. generator images become raster when they are specialized) |
| 95 | // in which case getROPixels could turn into peekPixels... |
| 96 | if (!this->getROPixels(&bmp)) { |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 97 | return nullptr; |
| 98 | } |
| 99 | |
robertphillips | 83f2e5a | 2016-03-24 06:31:25 -0700 | [diff] [blame] | 100 | if (bmp.empty()) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 101 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->props()); |
robertphillips | 83f2e5a | 2016-03-24 06:31:25 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 104 | sk_sp<GrTexture> resultTex( |
| 105 | GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter(), |
| 106 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 107 | if (!resultTex) { |
| 108 | return nullptr; |
| 109 | } |
| 110 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 111 | return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resultTex->height()), |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 112 | this->uniqueID(), |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 113 | resultTex, sk_ref_sp(this->getColorSpace()), &this->props(), |
brianosman | 80e9608 | 2016-08-16 07:09:47 -0700 | [diff] [blame] | 114 | this->alphaType()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 115 | #else |
| 116 | return nullptr; |
| 117 | #endif |
| 118 | } |
| 119 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 120 | void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const { |
bsalomon | 84a4e5a | 2016-02-29 11:41:52 -0800 | [diff] [blame] | 121 | return as_SIB(this)->onDraw(canvas, x, y, paint); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 122 | } |
| 123 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 124 | bool SkSpecialImage::getROPixels(SkBitmap* bm) const { |
| 125 | return as_SIB(this)->onGetROPixels(bm); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 126 | } |
| 127 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 128 | bool SkSpecialImage::isTextureBacked() const { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 129 | return SkToBool(as_SIB(this)->onGetContext()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 130 | } |
| 131 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 132 | GrContext* SkSpecialImage::getContext() const { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 133 | return as_SIB(this)->onGetContext(); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 134 | } |
| 135 | |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 136 | SkColorSpace* SkSpecialImage::getColorSpace() const { |
| 137 | return as_SIB(this)->onGetColorSpace(); |
| 138 | } |
| 139 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 140 | #if SK_SUPPORT_GPU |
| 141 | sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 142 | return as_SIB(this)->onAsTextureRef(context); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 143 | } |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 144 | |
| 145 | sk_sp<GrTextureProxy> SkSpecialImage::asTextureProxy(GrContext* context) const { |
| 146 | return as_SIB(this)->onAsTextureProxy(context); |
| 147 | } |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 148 | #endif |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 149 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 150 | sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageFilter::OutputProperties& outProps, |
| 151 | const SkISize& size, SkAlphaType at) const { |
| 152 | return as_SIB(this)->onMakeSurface(outProps, size, at); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 153 | } |
| 154 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 155 | sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageFilter::OutputProperties& outProps, |
| 156 | const SkISize& size, SkAlphaType at) const { |
| 157 | return as_SIB(this)->onMakeTightSurface(outProps, size, at); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 158 | } |
| 159 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 160 | sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
| 161 | return as_SIB(this)->onMakeSubset(subset); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 162 | } |
| 163 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 164 | sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
| 165 | return as_SIB(this)->onMakeTightSubset(subset); |
| 166 | } |
| 167 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 168 | #ifdef SK_DEBUG |
| 169 | static bool rect_fits(const SkIRect& rect, int width, int height) { |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 170 | if (0 == width && 0 == height) { |
| 171 | SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == rect.fBottom); |
| 172 | return true; |
| 173 | } |
| 174 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 175 | return rect.fLeft >= 0 && rect.fLeft < width && rect.fLeft < rect.fRight && |
| 176 | rect.fRight >= 0 && rect.fRight <= width && |
| 177 | rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && |
| 178 | rect.fBottom >= 0 && rect.fBottom <= height; |
| 179 | } |
| 180 | #endif |
| 181 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 182 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 183 | sk_sp<SkImage> image, |
| 184 | const SkSurfaceProps* props) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 185 | SkASSERT(rect_fits(subset, image->width(), image->height())); |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 186 | |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 187 | #if SK_SUPPORT_GPU |
| 188 | if (GrTexture* texture = as_IB(image)->peekTexture()) { |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 189 | return MakeFromGpu(subset, image->uniqueID(), sk_ref_sp(texture), |
| 190 | sk_ref_sp(as_IB(image)->onImageInfo().colorSpace()), props); |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 191 | } else |
| 192 | #endif |
| 193 | { |
| 194 | SkBitmap bm; |
| 195 | if (as_IB(image)->getROPixels(&bm)) { |
| 196 | return MakeFromRaster(subset, bm, props); |
| 197 | } |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 198 | } |
reed | ad7604b | 2016-07-20 16:13:32 -0700 | [diff] [blame] | 199 | return nullptr; |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 203 | |
| 204 | class SkSpecialImage_Raster : public SkSpecialImage_Base { |
| 205 | public: |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 206 | SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSurfaceProps* props) |
| 207 | : INHERITED(subset, bm.getGenerationID(), props) |
reed | bd2bd5c | 2016-07-25 14:26:02 -0700 | [diff] [blame] | 208 | , fBitmap(bm) |
| 209 | { |
| 210 | SkASSERT(bm.pixelRef()); |
| 211 | |
| 212 | // We have to lock now, while bm is still in scope, since it may have come from our |
| 213 | // cache, which means we need to keep it locked until we (the special) are done, since |
| 214 | // we cannot re-generate the cache entry (if bm came from a generator). |
| 215 | fBitmap.lockPixels(); |
| 216 | SkASSERT(fBitmap.getPixels()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 217 | } |
| 218 | |
brianosman | 80e9608 | 2016-08-16 07:09:47 -0700 | [diff] [blame] | 219 | SkAlphaType alphaType() const override { return fBitmap.alphaType(); } |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 220 | |
| 221 | size_t getSize() const override { return fBitmap.getSize(); } |
| 222 | |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 223 | void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 224 | SkRect dst = SkRect::MakeXYWH(x, y, |
| 225 | this->subset().width(), this->subset().height()); |
| 226 | |
| 227 | canvas->drawBitmapRect(fBitmap, this->subset(), |
| 228 | dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 229 | } |
| 230 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 231 | bool onGetROPixels(SkBitmap* bm) const override { |
| 232 | *bm = fBitmap; |
robertphillips | 3b087f4 | 2016-02-18 08:48:03 -0800 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 236 | SkColorSpace* onGetColorSpace() const override { |
| 237 | return fBitmap.colorSpace(); |
| 238 | } |
| 239 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 240 | #if SK_SUPPORT_GPU |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 241 | sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 242 | if (context) { |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 243 | return sk_ref_sp( |
| 244 | GrRefCachedBitmapTexture(context, fBitmap, GrTextureParams::ClampNoFilter(), |
| 245 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 246 | } |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 247 | |
| 248 | return nullptr; |
| 249 | } |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 250 | |
| 251 | sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const override { |
| 252 | if (context) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 253 | sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture( |
| 254 | context, |
| 255 | fBitmap, |
| 256 | GrTextureParams::ClampNoFilter(), |
| 257 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware))); |
| 258 | sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(std::move(tex)); |
| 259 | return sk_ref_sp(sProxy->asTextureProxy()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | return nullptr; |
| 263 | } |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 264 | #endif |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 265 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 266 | // TODO: The raster implementations of image filters all currently assume that the pixels are |
| 267 | // legacy N32. Until they actually check the format and operate on sRGB or F16 data appropriately, |
| 268 | // we can't enable this. (They will continue to produce incorrect results, but less-so). |
| 269 | #define RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 0 |
| 270 | |
| 271 | sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, |
| 272 | const SkISize& size, SkAlphaType at) const override { |
| 273 | #if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 |
| 274 | SkColorSpace* colorSpace = outProps.colorSpace(); |
| 275 | #else |
| 276 | SkColorSpace* colorSpace = nullptr; |
| 277 | #endif |
| 278 | SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 279 | ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 280 | SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, |
| 281 | sk_ref_sp(colorSpace)); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 282 | return SkSpecialSurface::MakeRaster(info, nullptr); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 283 | } |
| 284 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 285 | sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 286 | SkBitmap subsetBM; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 287 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 288 | if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 289 | return nullptr; |
| 290 | } |
| 291 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 292 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(subset.width(), subset.height()), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 293 | subsetBM, |
| 294 | &this->props()); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 295 | } |
| 296 | |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 297 | sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 298 | SkBitmap subsetBM; |
| 299 | |
| 300 | if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 301 | return nullptr; |
| 302 | } |
| 303 | |
| 304 | return SkImage::MakeFromBitmap(subsetBM); |
| 305 | } |
| 306 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 307 | sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, |
| 308 | const SkISize& size, SkAlphaType at) const override { |
| 309 | #if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 |
| 310 | SkColorSpace* colorSpace = outProps.colorSpace(); |
| 311 | #else |
| 312 | SkColorSpace* colorSpace = nullptr; |
| 313 | #endif |
| 314 | SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 315 | ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 316 | SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, |
| 317 | sk_ref_sp(colorSpace)); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 318 | return SkSurface::MakeRaster(info); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 319 | } |
| 320 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 321 | private: |
| 322 | SkBitmap fBitmap; |
| 323 | |
| 324 | typedef SkSpecialImage_Base INHERITED; |
| 325 | }; |
| 326 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 327 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 328 | const SkBitmap& bm, |
| 329 | const SkSurfaceProps* props) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 330 | SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 331 | |
reed | bd2bd5c | 2016-07-25 14:26:02 -0700 | [diff] [blame] | 332 | if (!bm.pixelRef()) { |
| 333 | return nullptr; |
| 334 | } |
| 335 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 336 | const SkBitmap* srcBM = &bm; |
| 337 | SkBitmap tmpStorage; |
| 338 | // ImageFilters only handle N32 at the moment, so force our src to be that |
| 339 | if (!valid_for_imagefilters(bm.info())) { |
| 340 | if (!bm.copyTo(&tmpStorage, kN32_SkColorType)) { |
| 341 | return nullptr; |
| 342 | } |
| 343 | srcBM = &tmpStorage; |
| 344 | } |
| 345 | return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | #if SK_SUPPORT_GPU |
| 349 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 350 | #include "GrTexture.h" |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 351 | #include "SkImage_Gpu.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 352 | |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 353 | class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 354 | public: |
| 355 | SkSpecialImage_Gpu(const SkIRect& subset, |
| 356 | uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 357 | sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 358 | : INHERITED(subset, uniqueID, props) |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 359 | , fContext(tex->getContext()) |
| 360 | , fAlphaType(at) |
| 361 | , fColorSpace(std::move(colorSpace)) |
| 362 | , fAddedRasterVersionToCache(false) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 363 | fSurfaceProxy = GrSurfaceProxy::MakeWrapped(std::move(tex)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | SkSpecialImage_Gpu(GrContext* context, const SkIRect& subset, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 367 | uint32_t uniqueID, sk_sp<GrSurfaceProxy> proxy, SkAlphaType at, |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 368 | sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) |
| 369 | : INHERITED(subset, uniqueID, props) |
| 370 | , fContext(context) |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 371 | , fSurfaceProxy(std::move(proxy)) |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 372 | , fAlphaType(at) |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 373 | , fColorSpace(std::move(colorSpace)) |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 374 | , fAddedRasterVersionToCache(false) { |
| 375 | } |
| 376 | |
| 377 | ~SkSpecialImage_Gpu() override { |
| 378 | if (fAddedRasterVersionToCache.load()) { |
| 379 | SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 380 | } |
| 381 | } |
| 382 | |
brianosman | 80e9608 | 2016-08-16 07:09:47 -0700 | [diff] [blame] | 383 | SkAlphaType alphaType() const override { return fAlphaType; } |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 384 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 385 | size_t getSize() const override { return fSurfaceProxy->gpuMemorySize(); } |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 386 | |
| 387 | void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { |
| 388 | SkRect dst = SkRect::MakeXYWH(x, y, |
| 389 | this->subset().width(), this->subset().height()); |
| 390 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 391 | // TODO: add GrTextureProxy-backed SkImage_Gpus |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 392 | GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 393 | |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame^] | 394 | // TODO: In this instance we know we're going to draw a sub-portion of the backing |
| 395 | // texture into the canvas so it is okay to wrap it in an SkImage. This poses |
| 396 | // some problems for full deferral however in that when the deferred SkImage_Gpu |
| 397 | // instantiates itself it is going to have to either be okay with having a larger |
| 398 | // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs |
| 399 | // to be tightened (if it is deferred). |
| 400 | auto img = sk_sp<SkImage>(new SkImage_Gpu(surf->width(), surf->height(), |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 401 | this->uniqueID(), fAlphaType, |
| 402 | sk_ref_sp(surf->asTexture()), |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 403 | fColorSpace, SkBudgeted::kNo)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 404 | |
reed | 77d6f7d | 2016-07-13 12:24:48 -0700 | [diff] [blame] | 405 | canvas->drawImageRect(img, this->subset(), |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame^] | 406 | dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 409 | GrContext* onGetContext() const override { return fContext; } |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 410 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 411 | // This entry point should go away in favor of asTextureProxy |
| 412 | sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 413 | GrSurface* surf = fSurfaceProxy->instantiate(context->textureProvider()); |
| 414 | |
| 415 | return sk_ref_sp(surf->asTexture()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | sk_sp<GrTextureProxy> onAsTextureProxy(GrContext*) const override { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 419 | return sk_ref_sp(fSurfaceProxy->asTextureProxy()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 420 | } |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 421 | |
| 422 | bool onGetROPixels(SkBitmap* dst) const override { |
| 423 | if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 424 | SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 425 | SkASSERT(dst->isImmutable()); |
| 426 | SkASSERT(dst->getPixels()); |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), |
brianosman | 80e9608 | 2016-08-16 07:09:47 -0700 | [diff] [blame] | 431 | this->alphaType(), fColorSpace); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 432 | |
| 433 | if (!dst->tryAllocPixels(info)) { |
| 434 | return false; |
| 435 | } |
| 436 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 437 | // Reading back to an SkBitmap ends deferral |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 438 | GrSurface* surface = fSurfaceProxy->instantiate(fContext->textureProvider()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 439 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 440 | if (!surface->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 441 | dst->getPixels(), dst->rowBytes())) { |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 442 | return false; |
| 443 | } |
| 444 | |
| 445 | dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 446 | SkBitmapCache::Add(this->uniqueID(), *dst); |
| 447 | fAddedRasterVersionToCache.store(true); |
| 448 | return true; |
| 449 | } |
| 450 | |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 451 | SkColorSpace* onGetColorSpace() const override { |
| 452 | return fColorSpace.get(); |
| 453 | } |
| 454 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 455 | sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, |
| 456 | const SkISize& size, SkAlphaType at) const override { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 457 | if (!fContext) { |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 458 | return nullptr; |
| 459 | } |
| 460 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 461 | SkColorSpace* colorSpace = outProps.colorSpace(); |
| 462 | return SkSpecialSurface::MakeRenderTarget( |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 463 | fContext, size.width(), size.height(), |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 464 | GrRenderableConfigForColorSpace(colorSpace), sk_ref_sp(colorSpace)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 468 | return SkSpecialImage::MakeDeferredFromGpu(fContext, |
| 469 | subset, |
| 470 | this->uniqueID(), |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 471 | fSurfaceProxy, |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 472 | fColorSpace, |
| 473 | &this->props(), |
| 474 | fAlphaType); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 478 | // TODO: add GrTextureProxy-backed SkImage_Gpus |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 479 | GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 480 | |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 481 | if (0 == subset.fLeft && 0 == subset.fTop && |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 482 | fSurfaceProxy->width() == subset.width() && |
| 483 | fSurfaceProxy->height() == subset.height()) { |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 484 | // The existing GrTexture is already tight so reuse it in the SkImage |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 485 | return sk_make_sp<SkImage_Gpu>(surf->width(), surf->height(), |
| 486 | kNeedNewImageUniqueID, fAlphaType, |
| 487 | sk_ref_sp(surf->asTexture()), |
| 488 | fColorSpace, SkBudgeted::kYes); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 491 | GrSurfaceDesc desc = fSurfaceProxy->desc(); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 492 | desc.fWidth = subset.width(); |
| 493 | desc.fHeight = subset.height(); |
| 494 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 495 | sk_sp<GrTexture> subTx(fContext->textureProvider()->createTexture(desc, SkBudgeted::kYes)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 496 | if (!subTx) { |
| 497 | return nullptr; |
| 498 | } |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 499 | fContext->copySurface(subTx.get(), surf, subset, SkIPoint::Make(0, 0)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 500 | return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 501 | fAlphaType, std::move(subTx), fColorSpace, SkBudgeted::kYes); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 502 | } |
| 503 | |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 504 | sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, |
| 505 | const SkISize& size, SkAlphaType at) const override { |
| 506 | SkColorSpace* colorSpace = outProps.colorSpace(); |
| 507 | SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 508 | ? kRGBA_F16_SkColorType : kRGBA_8888_SkColorType; |
| 509 | SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, |
| 510 | sk_ref_sp(colorSpace)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 511 | return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kYes, info); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | private: |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 515 | GrContext* fContext; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 516 | sk_sp<GrSurfaceProxy> fSurfaceProxy; |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 517 | const SkAlphaType fAlphaType; |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 518 | sk_sp<SkColorSpace> fColorSpace; |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 519 | mutable SkAtomic<bool> fAddedRasterVersionToCache; |
| 520 | |
| 521 | typedef SkSpecialImage_Base INHERITED; |
| 522 | }; |
| 523 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 524 | sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 525 | uint32_t uniqueID, |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 526 | sk_sp<GrTexture> tex, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 527 | sk_sp<SkColorSpace> colorSpace, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 528 | const SkSurfaceProps* props, |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 529 | SkAlphaType at) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 530 | SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 531 | return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, |
| 532 | std::move(colorSpace), props); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 535 | sk_sp<SkSpecialImage> SkSpecialImage::MakeDeferredFromGpu(GrContext* context, |
| 536 | const SkIRect& subset, |
| 537 | uint32_t uniqueID, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 538 | sk_sp<GrSurfaceProxy> proxy, |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 539 | sk_sp<SkColorSpace> colorSpace, |
| 540 | const SkSurfaceProps* props, |
| 541 | SkAlphaType at) { |
| 542 | SkASSERT(rect_fits(subset, proxy->width(), proxy->height())); |
| 543 | return sk_make_sp<SkSpecialImage_Gpu>(context, subset, uniqueID, std::move(proxy), at, |
| 544 | std::move(colorSpace), props); |
| 545 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 546 | #endif |