aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkImageCacherator.h
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-11-14 15:09:56 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-15 15:27:14 +0000
commitc73a1ecbed64652b3d7aa8dc6face9a2205ce830 (patch)
tree59e66c879ca0d1ab68720ccae740cecb2d5660ef /src/core/SkImageCacherator.h
parentfd01ce05ef7902c49b0272b3524a389693c72b35 (diff)
Support decoding images to multiple formats, depending on usage
Our codec generator will now preserve any asked-for color space, and convert the encoded data to that representation. Cacherator now allows decoding an image to both legacy (nullptr color space), and color-correct formats. In color-correct mode, we choose the best decoded format, based on the original properties, and our backend's capabilities. Preference is given to the native format, when it's already texturable (sRGB 8888 or F16 linear). Otherwise, we prefer linear F16, and fall back to sRGB when that's not an option. BUG=skia:5907 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4438 Change-Id: I847c243dcfb72d8c0f1f6fc73c09547adea933f0 Reviewed-on: https://skia-review.googlesource.com/4438 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/core/SkImageCacherator.h')
-rw-r--r--src/core/SkImageCacherator.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
index a8a05a1f90..fc03e8e5e9 100644
--- a/src/core/SkImageCacherator.h
+++ b/src/core/SkImageCacherator.h
@@ -12,6 +12,7 @@
#include "SkMutex.h"
#include "SkTemplates.h"
+class GrCaps;
class GrContext;
class GrTextureParams;
class GrUniqueKey;
@@ -29,7 +30,16 @@ public:
~SkImageCacherator();
const SkImageInfo& info() const { return fInfo; }
- uint32_t uniqueID() const { return fUniqueID; }
+ uint32_t uniqueID() const { return fUniqueIDs[kLegacy_CachedFormat]; }
+
+ enum CachedFormat {
+ kLegacy_CachedFormat, // The format from the generator, with any color space stripped out
+ kAsIs_CachedFormat, // The format from the generator, with no modification
+ kLinearF16_CachedFormat, // Half float RGBA with linear gamma
+ kSRGB8888_CachedFormat, // sRGB bytes
+
+ kNumCachedFormats,
+ };
/**
* On success (true), bitmap will point to the pixels for this generator. If this returns
@@ -38,7 +48,7 @@ public:
* If not NULL, the client will be notified (->notifyAddedToCache()) when resources are
* added to the cache on its behalf.
*/
- bool lockAsBitmap(SkBitmap*, const SkImage* client,
+ bool lockAsBitmap(SkBitmap*, const SkImage* client, SkDestinationSurfaceColorMode colorMode,
SkImage::CachingHint = SkImage::kAllow_CachingHint);
/**
@@ -64,7 +74,7 @@ public:
SkData* refEncoded(GrContext*);
// Only return true if the generate has already been cached.
- bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*);
+ bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*, CachedFormat);
// Call the underlying generator directly
bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY);
@@ -102,19 +112,22 @@ private:
SkImageCacherator(Validator*);
- bool generateBitmap(SkBitmap*);
- bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint);
+ bool generateBitmap(SkBitmap*, const SkImageInfo&);
+ bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint, CachedFormat,
+ const SkImageInfo&);
#if SK_SUPPORT_GPU
// Returns the texture. If the cacherator is generating the texture and wants to cache it,
// it should use the passed in key (if the key is valid).
GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* client,
SkImage::CachingHint, bool willBeMipped, SkDestinationSurfaceColorMode);
+ CachedFormat chooseCacheFormat(SkDestinationSurfaceColorMode, const GrCaps* = nullptr);
+ SkImageInfo buildCacheInfo(CachedFormat);
#endif
sk_sp<SharedGenerator> fSharedGenerator;
const SkImageInfo fInfo;
const SkIPoint fOrigin;
- const uint32_t fUniqueID;
+ uint32_t fUniqueIDs[kNumCachedFormats];
friend class GrImageTextureMaker;
friend class SkImage;