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