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 | |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 15 | #include <new> |
| 16 | |
reed | 80c772b | 2015-07-30 18:58:23 -0700 | [diff] [blame] | 17 | enum { |
| 18 | kNeedNewImageUniqueID = 0 |
| 19 | }; |
| 20 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 21 | class SkImage_Base : public SkImage { |
| 22 | public: |
reed | af3fbfc | 2015-10-04 11:28:36 -0700 | [diff] [blame^] | 23 | SkImage_Base(int width, int height, uint32_t uniqueID); |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 24 | virtual ~SkImage_Base(); |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 25 | |
reed | af3fbfc | 2015-10-04 11:28:36 -0700 | [diff] [blame^] | 26 | virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { return nullptr; } |
reed@google.com | 4f7c615 | 2014-02-06 14:11:56 +0000 | [diff] [blame] | 27 | |
reed | 96472de | 2014-12-10 09:53:42 -0800 | [diff] [blame] | 28 | // Default impl calls onDraw |
| 29 | virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 30 | int srcX, int srcY) const; |
reed | 86e90fa | 2015-09-01 12:22:32 -0700 | [diff] [blame] | 31 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 32 | virtual GrTexture* peekTexture() const { return nullptr; } |
skia.committer@gmail.com | 3e50e99 | 2013-05-21 07:01:40 +0000 | [diff] [blame] | 33 | |
reed@google.com | 4b0757b | 2013-05-20 16:33:41 +0000 | [diff] [blame] | 34 | // return a read-only copy of the pixels. We promise to not modify them, |
| 35 | // but only inspect them (or encode them). |
reed | 746f31f | 2015-09-16 12:53:29 -0700 | [diff] [blame] | 36 | virtual bool getROPixels(SkBitmap*) const = 0; |
| 37 | |
| 38 | // Caller must call unref when they are done. |
| 39 | virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0; |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 40 | |
reed | 476506d | 2015-09-28 10:26:51 -0700 | [diff] [blame] | 41 | virtual SkImage* onNewSubset(const SkIRect&) const = 0; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 42 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 43 | virtual SkData* onRefEncoded() const { return nullptr; } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 44 | |
reed | 3c06511 | 2015-07-08 12:46:22 -0700 | [diff] [blame] | 45 | virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; |
| 46 | |
fmalita | ddbbdda | 2015-08-20 08:47:26 -0700 | [diff] [blame] | 47 | virtual bool onIsLazyGenerated() const { return false; } |
| 48 | |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 49 | // Call when this image is part of the key to a resourcecache entry. This allows the cache |
| 50 | // to know automatically those entries can be purged when this SkImage deleted. |
| 51 | void notifyAddedToCache() const { |
| 52 | fAddedToCache.store(true); |
| 53 | } |
| 54 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 55 | private: |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 56 | // Set true by caches when they cache content that's derived from the current pixels. |
| 57 | mutable SkAtomic<bool> fAddedToCache; |
| 58 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 59 | typedef SkImage INHERITED; |
| 60 | }; |
| 61 | |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 62 | static inline SkImage_Base* as_IB(SkImage* image) { |
| 63 | return static_cast<SkImage_Base*>(image); |
| 64 | } |
| 65 | |
| 66 | static inline const SkImage_Base* as_IB(const SkImage* image) { |
| 67 | return static_cast<const SkImage_Base*>(image); |
| 68 | } |
| 69 | |
reed@google.com | 58b21ec | 2012-07-30 18:20:12 +0000 | [diff] [blame] | 70 | #endif |