aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-12-09 14:51:59 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-09 20:31:23 +0000
commit61624f0c716b576706659750d87b6956f4c15722 (patch)
tree00122b478cf21327b70364fefc5f3f9a6169377e /src/image
parent073285c0595d46205d1482cc19af2d7d891bfeae (diff)
Plumb dst color space in many places, rather than "mode"
This is less to type in most cases, and gives us more information (for things like picture-backed images, where we need to know all about the destination surface). Additionally, strip out the plumbing entirely for bitmap sources, where we don't need to know anything. BUG=skia: Change-Id: I4deff6c7c345fcf62eb08b2aff0560adae4313da Reviewed-on: https://skia-review.googlesource.com/5748 Reviewed-by: Mike Klein <mtklein@chromium.org> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp19
-rw-r--r--src/image/SkImageShader.cpp11
-rw-r--r--src/image/SkImage_Base.h6
-rw-r--r--src/image/SkImage_Generator.cpp22
-rw-r--r--src/image/SkImage_Gpu.cpp11
-rw-r--r--src/image/SkImage_Gpu.h6
-rw-r--r--src/image/SkImage_Raster.cpp17
7 files changed, 39 insertions, 53 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index baabd56a34..21523fd513 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -66,11 +66,8 @@ bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH
// Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
// can scale more efficiently) we should take advantage of it here.
//
- SkDestinationSurfaceColorMode decodeColorMode = dst.info().colorSpace()
- ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
- : SkDestinationSurfaceColorMode::kLegacy;
SkBitmap bm;
- if (as_IB(this)->getROPixels(&bm, decodeColorMode, chint)) {
+ if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) {
bm.lockPixels();
SkPixmap pmap;
// Note: By calling the pixmap scaler, we never cache the final result, so the chint
@@ -87,7 +84,8 @@ void SkImage::preroll(GrContext* ctx) const {
// to produce a cached raster-bitmap form, so that drawing to a raster canvas should be fast.
//
SkBitmap bm;
- if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) {
+ SkColorSpace* legacyColorSpace = nullptr;
+ if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
bm.lockPixels();
bm.unlockPixels();
}
@@ -109,7 +107,8 @@ SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const {
// TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do,
// we should decode in "color space aware" mode, then re-encode that. For now, work around this
// by asking for a legacy decode (which gives us the raw data in N32).
- if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) {
+ SkColorSpace* legacyColorSpace = nullptr;
+ if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr;
}
@@ -128,7 +127,8 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const {
// TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do,
// we should decode in "color space aware" mode, then re-encode that. For now, work around this
// by asking for a legacy decode (which gives us the raw data in N32).
- if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy) &&
+ SkColorSpace* legacyColorSpace = nullptr;
+ if (as_IB(this)->getROPixels(&bm, legacyColorSpace) &&
bm.requestLock(&apu)) {
if (serializer) {
return serializer->encode(apu.pixmap());
@@ -327,11 +327,8 @@ sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec
return nullptr;
}
SkColorSpace* colorSpace = as_IB(this)->onImageInfo().colorSpace();
- SkDestinationSurfaceColorMode decodeColorMode = colorSpace
- ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
- : SkDestinationSurfaceColorMode::kLegacy;
sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
- subset, sk_ref_sp(const_cast<SkImage*>(this)), decodeColorMode);
+ subset, sk_ref_sp(const_cast<SkImage*>(this)), colorSpace);
if (!srcSpecialImage) {
return nullptr;
}
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 719bced4f5..528c5729d8 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -54,11 +54,8 @@ size_t SkImageShader::onContextSize(const ContextRec& rec) const {
}
SkShader::Context* SkImageShader::onCreateContext(const ContextRec& rec, void* storage) const {
- // TODO: This is wrong. We should be plumbing destination color space to context creation,
- // and use that to determine the decoding mode of the image.
- SkDestinationSurfaceColorMode decodeColorMode = SkMipMap::DeduceColorMode(rec);
return SkBitmapProcLegacyShader::MakeContext(*this, fTileModeX, fTileModeY,
- SkBitmapProvider(fImage.get(), decodeColorMode),
+ SkBitmapProvider(fImage.get(), rec.fDstColorSpace),
rec, storage);
}
@@ -218,7 +215,7 @@ sk_sp<GrFragmentProcessor> SkImageShader::asFragmentProcessor(const AsFPArgs& ar
&doBicubic);
GrSamplerParams params(tm, textureFilterMode);
sk_sp<SkColorSpace> texColorSpace;
- sk_sp<GrTexture> texture(as_IB(fImage)->asTextureRef(args.fContext, params, args.fColorMode,
+ sk_sp<GrTexture> texture(as_IB(fImage)->asTextureRef(args.fContext, params, args.fDstColorSpace,
&texColorSpace));
if (!texture) {
return nullptr;
@@ -281,9 +278,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal
}
auto quality = paint.getFilterQuality();
- auto mode = (dst == nullptr) ? SkDestinationSurfaceColorMode::kLegacy
- : SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware;
- SkBitmapProvider provider(fImage.get(), mode);
+ SkBitmapProvider provider(fImage.get(), dst);
SkDefaultBitmapController controller;
std::unique_ptr<SkBitmapController::State> state {
controller.requestBitmap(provider, matrix, quality)
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index c955d491f7..ebb38d4731 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -52,12 +52,12 @@ public:
// return a read-only copy of the pixels. We promise to not modify them,
// but only inspect them (or encode them).
- virtual bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode,
+ virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace,
CachingHint = kAllow_CachingHint) const = 0;
// Caller must call unref when they are done.
- virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
- SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const = 0;
+ virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
+ sk_sp<SkColorSpace>*) const = 0;
virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index efee134a81..45f04e4d9a 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -30,9 +30,9 @@ public:
SkImageCacherator* peekCacherator() const override { return &fCache; }
SkData* onRefEncoded(GrContext*) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
- bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
- GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
- SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
+ bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
+ GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
+ sk_sp<SkColorSpace>*) const override;
bool onIsLazyGenerated() const override { return true; }
private:
@@ -45,12 +45,10 @@ private:
bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint chint) const {
- SkDestinationSurfaceColorMode decodeColorMode = dstInfo.colorSpace()
- ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
- : SkDestinationSurfaceColorMode::kLegacy;
+ SkColorSpace* dstColorSpace = dstInfo.colorSpace();
SkBitmap bm;
if (kDisallow_CachingHint == chint) {
- SkImageCacherator::CachedFormat cacheFormat = fCache.chooseCacheFormat(decodeColorMode);
+ SkImageCacherator::CachedFormat cacheFormat = fCache.chooseCacheFormat(dstColorSpace);
if (fCache.lockAsBitmapOnlyIfAlreadyCached(&bm, cacheFormat)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
} else {
@@ -64,7 +62,7 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
}
}
- if (this->getROPixels(&bm, decodeColorMode, chint)) {
+ if (this->getROPixels(&bm, dstColorSpace, chint)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
}
return false;
@@ -74,15 +72,15 @@ SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const {
return fCache.refEncoded(ctx);
}
-bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkDestinationSurfaceColorMode colorMode,
+bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkColorSpace* dstColorSpace,
CachingHint chint) const {
- return fCache.lockAsBitmap(bitmap, this, colorMode, chint);
+ return fCache.lockAsBitmap(bitmap, this, dstColorSpace, chint);
}
GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
- SkDestinationSurfaceColorMode colorMode,
+ SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace) const {
- return fCache.lockAsTexture(ctx, params, colorMode, texColorSpace, this);
+ return fCache.lockAsTexture(ctx, params, dstColorSpace, texColorSpace, this);
}
sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 24e5c1df83..ffd3ae0ca9 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -63,7 +63,7 @@ static SkImageInfo make_info(int w, int h, SkAlphaType at, sk_sp<SkColorSpace> c
return SkImageInfo::MakeN32(w, h, at, std::move(colorSpace));
}
-bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode,
+bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace,
CachingHint chint) const {
if (SkBitmapCache::Find(this->uniqueID(), dst)) {
SkASSERT(dst->getGenerationID() == this->uniqueID());
@@ -90,14 +90,14 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode,
}
GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
- SkDestinationSurfaceColorMode colorMode,
+ SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace) const {
if (texColorSpace) {
*texColorSpace = this->fColorSpace;
}
GrTextureAdjuster adjuster(this->peekTexture(), this->alphaType(), this->bounds(),
this->uniqueID(), this->fColorSpace.get());
- return adjuster.refTextureSafeForParams(params, colorMode, nullptr);
+ return adjuster.refTextureSafeForParams(params, nullptr);
}
static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
@@ -463,11 +463,8 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
}
if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
// Generator backed image. Tweak info to trigger correct kind of decode.
- SkDestinationSurfaceColorMode decodeColorMode = dstColorSpace
- ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
- : SkDestinationSurfaceColorMode::kLegacy;
SkImageCacherator::CachedFormat cacheFormat = cacher->chooseCacheFormat(
- decodeColorMode, proxy.fCaps.get());
+ dstColorSpace, proxy.fCaps.get());
info = cacher->buildCacheInfo(cacheFormat).makeWH(scaledSize.width(),
scaledSize.height());
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index dcde00a8fc..2098864ae3 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -38,9 +38,9 @@ public:
}
}
- bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
- GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params,
- SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
+ bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
+ GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params, SkColorSpace*,
+ sk_sp<SkColorSpace>*) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
GrTexture* peekTexture() const override { return fTexture.get(); }
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index b781665126..b14a06e99d 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -87,9 +87,9 @@ public:
bool onPeekPixels(SkPixmap*) const override;
const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
- bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
- GrTexture* asTextureRef(GrContext*, const GrSamplerParams&,
- SkDestinationSurfaceColorMode, sk_sp<SkColorSpace>*) const override;
+ bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
+ GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
+ sk_sp<SkColorSpace>*) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
@@ -179,13 +179,13 @@ bool SkImage_Raster::onPeekPixels(SkPixmap* pm) const {
return fBitmap.peekPixels(pm);
}
-bool SkImage_Raster::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, CachingHint) const {
+bool SkImage_Raster::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, CachingHint) const {
*dst = fBitmap;
return true;
}
GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
- SkDestinationSurfaceColorMode colorMode,
+ SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace) const {
#if SK_SUPPORT_GPU
if (!ctx) {
@@ -201,10 +201,10 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& p
if (tex) {
GrTextureAdjuster adjuster(fPinnedTexture.get(), fBitmap.alphaType(), fBitmap.bounds(),
fPinnedUniqueID, fBitmap.colorSpace());
- return adjuster.refTextureSafeForParams(params, colorMode, nullptr);
+ return adjuster.refTextureSafeForParams(params, nullptr);
}
- return GrRefCachedBitmapTexture(ctx, fBitmap, params, colorMode);
+ return GrRefCachedBitmapTexture(ctx, fBitmap, params);
#endif
return nullptr;
@@ -231,8 +231,7 @@ bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const {
SkASSERT(fPinnedCount == 0);
SkASSERT(fPinnedUniqueID == 0);
fPinnedTexture.reset(
- GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter(),
- SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware));
+ GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter()));
if (!fPinnedTexture) {
return false;
}