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