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 | |
herb | b906daf | 2015-09-29 09:37:59 -0700 | [diff] [blame] | 11 | #include "SkAtomics.h" |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 12 | #include "SkImage.h" |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 13 | #include "SkSurface.h" |
| 14 | |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
| 16 | #include "GrTexture.h" |
| 17 | #endif |
| 18 | |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 19 | #include <new> |
| 20 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 21 | class GrSamplerParams; |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 22 | class SkImageCacherator; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 23 | |
reed | 80c772b | 2015-07-30 18:58:23 -0700 | [diff] [blame] | 24 | enum { |
| 25 | kNeedNewImageUniqueID = 0 |
| 26 | }; |
| 27 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 28 | class SkImage_Base : public SkImage { |
| 29 | public: |
reed | af3fbfc | 2015-10-04 11:28:36 -0700 | [diff] [blame] | 30 | SkImage_Base(int width, int height, uint32_t uniqueID); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 31 | virtual ~SkImage_Base(); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 32 | |
herb | a7c9d63 | 2016-04-19 12:30:22 -0700 | [diff] [blame] | 33 | // User: returns image info for this SkImage. |
| 34 | // Implementors: if you can not return the value, return an invalid ImageInfo with w=0 & h=0 |
| 35 | // & unknown color space. |
| 36 | virtual SkImageInfo onImageInfo() const = 0; |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame] | 37 | virtual SkAlphaType onAlphaType() const = 0; |
herb | a7c9d63 | 2016-04-19 12:30:22 -0700 | [diff] [blame] | 38 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 39 | virtual bool onPeekPixels(SkPixmap*) const { return false; } |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 40 | |
reed | f1ac182 | 2016-08-01 11:24:14 -0700 | [diff] [blame] | 41 | virtual const SkBitmap* onPeekBitmap() const { return nullptr; } |
| 42 | |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 43 | virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
Matt Sarett | e260959 | 2017-01-10 09:29:04 -0500 | [diff] [blame^] | 44 | int srcX, int srcY, CachingHint) const = 0; |
reed | 86e90fa | 2015-09-01 12:22:32 -0700 | [diff] [blame] | 45 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 46 | virtual GrTexture* peekTexture() const { return nullptr; } |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 47 | #if SK_SUPPORT_GPU |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 48 | virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return nullptr; } |
reed | 0e7bddf | 2016-08-17 13:24:05 -0700 | [diff] [blame] | 49 | #endif |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 50 | virtual SkImageCacherator* peekCacherator() const { return nullptr; } |
skia.committer@gmail.com | 3e50e99 | 2013-05-21 07:01:40 +0000 | [diff] [blame] | 51 | |
reed@google.com | 4b0757b | 2013-05-20 16:33:41 +0000 | [diff] [blame] | 52 | // return a read-only copy of the pixels. We promise to not modify them, |
| 53 | // but only inspect them (or encode them). |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 54 | virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 55 | CachingHint = kAllow_CachingHint) const = 0; |
reed | 746f31f | 2015-09-16 12:53:29 -0700 | [diff] [blame] | 56 | |
| 57 | // Caller must call unref when they are done. |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 58 | virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*, |
| 59 | sk_sp<SkColorSpace>*) const = 0; |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 60 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 61 | virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 62 | |
reed | 05dd251 | 2016-01-05 09:16:19 -0800 | [diff] [blame] | 63 | // If a ctx is specified, then only gpu-specific formats are requested. |
| 64 | virtual SkData* onRefEncoded(GrContext*) const { return nullptr; } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 65 | |
reed | 3c06511 | 2015-07-08 12:46:22 -0700 | [diff] [blame] | 66 | virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; |
| 67 | |
fmalita | ddbbdda | 2015-08-20 08:47:26 -0700 | [diff] [blame] | 68 | virtual bool onIsLazyGenerated() const { return false; } |
| 69 | |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 70 | // Call when this image is part of the key to a resourcecache entry. This allows the cache |
| 71 | // to know automatically those entries can be purged when this SkImage deleted. |
| 72 | void notifyAddedToCache() const { |
| 73 | fAddedToCache.store(true); |
| 74 | } |
| 75 | |
Derek Sollenberger | d3ea9b7 | 2016-11-09 11:25:13 -0500 | [diff] [blame] | 76 | virtual bool onPinAsTexture(GrContext*) const { return false; } |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 77 | virtual void onUnpinAsTexture(GrContext*) const {} |
| 78 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 79 | private: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 80 | // Set true by caches when they cache content that's derived from the current pixels. |
| 81 | mutable SkAtomic<bool> fAddedToCache; |
| 82 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 83 | typedef SkImage INHERITED; |
| 84 | }; |
| 85 | |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 86 | static inline SkImage_Base* as_IB(SkImage* image) { |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 87 | return static_cast<SkImage_Base*>(image); |
| 88 | } |
| 89 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 90 | static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) { |
| 91 | return static_cast<SkImage_Base*>(image.get()); |
| 92 | } |
| 93 | |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 94 | static inline const SkImage_Base* as_IB(const SkImage* image) { |
| 95 | return static_cast<const SkImage_Base*>(image); |
| 96 | } |
| 97 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 98 | #endif |