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 |
Greg Daniel | 2ad0820 | 2018-09-07 09:13:36 -0400 | [diff] [blame] | 16 | #include "GrTextureProxy.h" |
| 17 | #include "SkTDArray.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 18 | |
Greg Daniel | 2ad0820 | 2018-09-07 09:13:36 -0400 | [diff] [blame] | 19 | class GrTexture; |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 20 | #endif |
| 21 | |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 22 | #include <new> |
| 23 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 24 | class GrSamplerState; |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 25 | class SkCachedData; |
| 26 | struct SkYUVSizeInfo; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 27 | |
reed | 80c772b | 2015-07-30 18:58:23 -0700 | [diff] [blame] | 28 | enum { |
| 29 | kNeedNewImageUniqueID = 0 |
| 30 | }; |
| 31 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 32 | class SkImage_Base : public SkImage { |
| 33 | public: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 34 | virtual ~SkImage_Base(); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 35 | |
herb | a7c9d63 | 2016-04-19 12:30:22 -0700 | [diff] [blame] | 36 | // User: returns image info for this SkImage. |
| 37 | // Implementors: if you can not return the value, return an invalid ImageInfo with w=0 & h=0 |
| 38 | // & unknown color space. |
| 39 | virtual SkImageInfo onImageInfo() const = 0; |
| 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 | |
reed@google.com | 4b0757b | 2013-05-20 16:33:41 +0000 | [diff] [blame] | 68 | // return a read-only copy of the pixels. We promise to not modify them, |
| 69 | // but only inspect them (or encode them). |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 70 | virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 71 | CachingHint = kAllow_CachingHint) const = 0; |
reed | 746f31f | 2015-09-16 12:53:29 -0700 | [diff] [blame] | 72 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 73 | virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 74 | |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 75 | virtual sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*, const void* planes[3]); |
Ben Wagner | bdf5433 | 2018-05-15 14:12:14 -0400 | [diff] [blame] | 76 | virtual sk_sp<SkData> onRefEncoded() const { return nullptr; } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 77 | |
Cary Clark | 4f5a79c | 2018-02-07 15:51:00 -0500 | [diff] [blame] | 78 | virtual bool onAsLegacyBitmap(SkBitmap*) const; |
reed | 3c06511 | 2015-07-08 12:46:22 -0700 | [diff] [blame] | 79 | |
Mike Reed | 7f1d020 | 2017-05-08 16:13:39 -0400 | [diff] [blame] | 80 | // True for picture-backed and codec-backed |
fmalita | ddbbdda | 2015-08-20 08:47:26 -0700 | [diff] [blame] | 81 | virtual bool onIsLazyGenerated() const { return false; } |
| 82 | |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 83 | // Call when this image is part of the key to a resourcecache entry. This allows the cache |
| 84 | // to know automatically those entries can be purged when this SkImage deleted. |
Mike Reed | 30301c4 | 2018-07-19 09:39:21 -0400 | [diff] [blame] | 85 | void notifyAddedToRasterCache() const { |
| 86 | fAddedToRasterCache.store(true); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Brian Osman | 5bbd076 | 2017-05-08 11:07:42 -0400 | [diff] [blame] | 89 | virtual bool onIsValid(GrContext*) const = 0; |
| 90 | |
Derek Sollenberger | d3ea9b7 | 2016-11-09 11:25:13 -0500 | [diff] [blame] | 91 | virtual bool onPinAsTexture(GrContext*) const { return false; } |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 92 | virtual void onUnpinAsTexture(GrContext*) const {} |
| 93 | |
Brian Osman | 15f0f29 | 2018-10-01 14:14:46 -0400 | [diff] [blame] | 94 | virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const = 0; |
Florin Malita | f7beee7 | 2017-05-26 12:54:32 -0400 | [diff] [blame] | 95 | protected: |
| 96 | SkImage_Base(int width, int height, uint32_t uniqueID); |
Matt Sarett | 6de1310 | 2017-03-14 14:10:48 -0400 | [diff] [blame] | 97 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 98 | private: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 99 | // 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] | 100 | mutable std::atomic<bool> fAddedToRasterCache; |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 101 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 102 | typedef SkImage INHERITED; |
| 103 | }; |
| 104 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 105 | static inline SkImage_Base* as_IB(SkImage* image) { |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 106 | return static_cast<SkImage_Base*>(image); |
| 107 | } |
| 108 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 109 | static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) { |
| 110 | return static_cast<SkImage_Base*>(image.get()); |
| 111 | } |
| 112 | |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 113 | static inline const SkImage_Base* as_IB(const SkImage* image) { |
| 114 | return static_cast<const SkImage_Base*>(image); |
| 115 | } |
| 116 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 117 | #endif |