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