reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | */ |
| 7 | |
| 8 | #ifndef SkImage_Base_DEFINED |
| 9 | #define SkImage_Base_DEFINED |
| 10 | |
| 11 | #include "SkImage.h" |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 12 | #include "SkSurface.h" |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 13 | #include <atomic> |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 14 | |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 16 | #include "GrTextureProxy.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 17 | |
| 18 | class GrTexture; |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 19 | #endif |
| 20 | |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 21 | #include <new> |
| 22 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 23 | class GrSamplerState; |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 24 | class SkImageCacherator; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 25 | |
reed | 80c772b | 2015-07-30 18:58:23 -0700 | [diff] [blame] | 26 | enum { |
| 27 | kNeedNewImageUniqueID = 0 |
| 28 | }; |
| 29 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 30 | class SkImage_Base : public SkImage { |
| 31 | public: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 32 | virtual ~SkImage_Base(); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 33 | |
herb | a7c9d63 | 2016-04-19 12:30:22 -0700 | [diff] [blame] | 34 | // User: returns image info for this SkImage. |
| 35 | // Implementors: if you can not return the value, return an invalid ImageInfo with w=0 & h=0 |
| 36 | // & unknown color space. |
| 37 | virtual SkImageInfo onImageInfo() const = 0; |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 38 | virtual SkColorType onColorType() const = 0; |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame] | 39 | virtual SkAlphaType onAlphaType() const = 0; |
herb | a7c9d63 | 2016-04-19 12:30:22 -0700 | [diff] [blame] | 40 | |
Mike Reed | f2c7364 | 2018-05-29 15:41:27 -0400 | [diff] [blame] | 41 | virtual SkIRect onGetSubset() const { |
| 42 | return { 0, 0, this->width(), this->height() }; |
| 43 | } |
| 44 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 45 | virtual bool onPeekPixels(SkPixmap*) const { return false; } |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 46 | |
reed | f1ac182 | 2016-08-01 11:24:14 -0700 | [diff] [blame] | 47 | virtual const SkBitmap* onPeekBitmap() const { return nullptr; } |
| 48 | |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 49 | virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
Matt Sarett | e260959 | 2017-01-10 09:29:04 -0500 | [diff] [blame] | 50 | int srcX, int srcY, CachingHint) const = 0; |
reed | 86e90fa | 2015-09-01 12:22:32 -0700 | [diff] [blame] | 51 | |
Robert Phillips | 8744405 | 2017-06-23 14:09:30 -0400 | [diff] [blame] | 52 | virtual GrContext* context() const { return nullptr; } |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 53 | #if SK_SUPPORT_GPU |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 54 | virtual GrTextureProxy* peekProxy() const { return nullptr; } |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 55 | virtual sk_sp<GrTextureProxy> asTextureProxyRef() const { return nullptr; } |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 56 | virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerState&, |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 57 | SkColorSpace*, sk_sp<SkColorSpace>*, |
| 58 | SkScalar scaleAdjust[2]) const = 0; |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 59 | virtual sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const { |
| 60 | return nullptr; |
| 61 | } |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 62 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 63 | virtual GrTexture* onGetTexture() const { return nullptr; } |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 64 | #endif |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 65 | virtual GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, |
| 66 | GrSurfaceOrigin* origin) const; |
| 67 | |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 68 | virtual SkImageCacherator* peekCacherator() const { return nullptr; } |
skia.committer@gmail.com | 3e50e99 | 2013-05-21 07:01:40 +0000 | [diff] [blame] | 69 | |
reed@google.com | 4b0757b | 2013-05-20 16:33:41 +0000 | [diff] [blame] | 70 | // return a read-only copy of the pixels. We promise to not modify them, |
| 71 | // but only inspect them (or encode them). |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 72 | virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 73 | CachingHint = kAllow_CachingHint) const = 0; |
reed | 746f31f | 2015-09-16 12:53:29 -0700 | [diff] [blame] | 74 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 75 | virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 76 | |
Ben Wagner | bdf5433 | 2018-05-15 14:12:14 -0400 | [diff] [blame] | 77 | virtual sk_sp<SkData> onRefEncoded() const { return nullptr; } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 78 | |
Cary Clark | 4f5a79c | 2018-02-07 15:51:00 -0500 | [diff] [blame] | 79 | virtual bool onAsLegacyBitmap(SkBitmap*) const; |
reed | 3c06511 | 2015-07-08 12:46:22 -0700 | [diff] [blame] | 80 | |
Mike Reed | 7f1d020 | 2017-05-08 16:13:39 -0400 | [diff] [blame] | 81 | // True for picture-backed and codec-backed |
fmalita | ddbbdda | 2015-08-20 08:47:26 -0700 | [diff] [blame] | 82 | virtual bool onIsLazyGenerated() const { return false; } |
| 83 | |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 84 | // Call when this image is part of the key to a resourcecache entry. This allows the cache |
| 85 | // to know automatically those entries can be purged when this SkImage deleted. |
Mike Reed | 30301c4 | 2018-07-19 09:39:21 -0400 | [diff] [blame] | 86 | void notifyAddedToRasterCache() const { |
| 87 | fAddedToRasterCache.store(true); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Brian Osman | 5bbd076 | 2017-05-08 11:07:42 -0400 | [diff] [blame] | 90 | virtual bool onIsValid(GrContext*) const = 0; |
| 91 | |
Derek Sollenberger | d3ea9b7 | 2016-11-09 11:25:13 -0500 | [diff] [blame] | 92 | virtual bool onPinAsTexture(GrContext*) const { return false; } |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 93 | virtual void onUnpinAsTexture(GrContext*) const {} |
| 94 | |
Brian Osman | b62f50c | 2018-07-12 14:44:27 -0400 | [diff] [blame] | 95 | virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const = 0; |
Florin Malita | f7beee7 | 2017-05-26 12:54:32 -0400 | [diff] [blame] | 96 | protected: |
| 97 | SkImage_Base(int width, int height, uint32_t uniqueID); |
Matt Sarett | 6de1310 | 2017-03-14 14:10:48 -0400 | [diff] [blame] | 98 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 99 | private: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 100 | // Set true by caches when they cache content that's derived from the current pixels. |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 101 | mutable std::atomic<bool> fAddedToRasterCache; |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 102 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 103 | typedef SkImage INHERITED; |
| 104 | }; |
| 105 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 106 | static inline SkImage_Base* as_IB(SkImage* image) { |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 107 | return static_cast<SkImage_Base*>(image); |
| 108 | } |
| 109 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 110 | static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) { |
| 111 | return static_cast<SkImage_Base*>(image.get()); |
| 112 | } |
| 113 | |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 114 | static inline const SkImage_Base* as_IB(const SkImage* image) { |
| 115 | return static_cast<const SkImage_Base*>(image); |
| 116 | } |
| 117 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 118 | #endif |