Preserve colorType and alphaType in SkImage::makeColorSpace

Raster images were always converting to N32, and GPU images were
always converting to premul. These were unexpected and inconsistent.

Bug: skia:8382
Change-Id: I78fe6cff1208eef077a71d08e676cf8f8d5fed9a
Reviewed-on: https://skia-review.googlesource.com/156142
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Brian Osman 2018-09-21 10:25:04 -04:00 committed by Skia Commit-Bot
parent 7ca284b3e7
commit d842557c07
11 changed files with 20 additions and 35 deletions

View File

@ -53,6 +53,6 @@ void SkToSRGBColorFilter::flatten(SkWriteBuffer& buffer) const {
std::unique_ptr<GrFragmentProcessor> SkToSRGBColorFilter::asFragmentProcessor(
GrContext*, const GrColorSpaceInfo&) const {
return GrColorSpaceXformEffect::Make(fSrcColorSpace.get(), kPremul_SkAlphaType,
sk_srgb_singleton());
sk_srgb_singleton(), kPremul_SkAlphaType);
}
#endif

View File

@ -144,9 +144,10 @@ GrFragmentProcessor::OptimizationFlags GrColorSpaceXformEffect::OptFlags(
std::unique_ptr<GrFragmentProcessor> GrColorSpaceXformEffect::Make(SkColorSpace* src,
SkAlphaType srcAT,
SkColorSpace* dst) {
SkColorSpace* dst,
SkAlphaType dstAT) {
auto xform = GrColorSpaceXform::Make(src, srcAT,
dst, kPremul_SkAlphaType);
dst, dstAT);
if (!xform) {
return nullptr;
}

View File

@ -52,7 +52,7 @@ public:
* Returns a fragment processor that converts the input's color space from src to dst.
*/
static std::unique_ptr<GrFragmentProcessor> Make(SkColorSpace* src, SkAlphaType srcAT,
SkColorSpace* dst);
SkColorSpace* dst, SkAlphaType dstAT);
/**
* Returns a fragment processor that calls the passed in fragment processor, and then converts

View File

@ -141,7 +141,8 @@ sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrS
// If the caller expects the pixels in a different color space than the one from the image,
// apply a color conversion to do this.
std::unique_ptr<GrFragmentProcessor> colorConversionProcessor =
GrColorSpaceXformEffect::Make(srcColorSpace, kPremul_SkAlphaType, dstColorSpace);
GrColorSpaceXformEffect::Make(srcColorSpace, kOpaque_SkAlphaType,
dstColorSpace, kOpaque_SkAlphaType);
if (colorConversionProcessor) {
paint.addColorFragmentProcessor(std::move(colorConversionProcessor));
}

View File

@ -300,8 +300,7 @@ bool SkImage::isAlphaOnly() const {
}
sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target) const {
SkColorSpaceTransferFn fn;
if (!target || !target->isNumericalTransferFn(&fn)) {
if (!target) {
return nullptr;
}
@ -313,11 +312,8 @@ sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target) const {
return sk_ref_sp(const_cast<SkImage*>(this));
}
// TODO: Re-visit this! Keep existing color type?
SkColorType targetColorType = kN32_SkColorType;
// TODO: We might consider making this a deferred conversion?
return as_IB(this)->onMakeColorSpace(std::move(target), targetColorType);
return as_IB(this)->onMakeColorSpace(std::move(target));
}
sk_sp<SkImage> SkImage::makeNonTextureImage() const {

View File

@ -93,7 +93,7 @@ public:
virtual bool onPinAsTexture(GrContext*) const { return false; }
virtual void onUnpinAsTexture(GrContext*) const {}
virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const = 0;
virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const = 0;
protected:
SkImage_Base(int width, int height, uint32_t uniqueID);

View File

@ -1012,17 +1012,9 @@ bool SkImage::MakeBackendTextureFromSkImage(GrContext* ctx,
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target, SkColorType) const {
sk_sp<SkColorSpace> srcSpace = fColorSpace;
if (!fColorSpace) {
if (target->isSRGB()) {
return sk_ref_sp(const_cast<SkImage*>((SkImage*)this));
}
srcSpace = SkColorSpace::MakeSRGB();
}
auto xform = GrColorSpaceXformEffect::Make(srcSpace.get(), this->alphaType(), target.get());
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
auto xform = GrColorSpaceXformEffect::Make(fColorSpace.get(), this->alphaType(),
target.get(), this->alphaType());
if (!xform) {
return sk_ref_sp(const_cast<SkImage_Gpu*>(this));
}
@ -1048,13 +1040,10 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target, SkColor
return nullptr;
}
SkAlphaType newAlphaType = (kUnpremul_SkAlphaType == fAlphaType) ? kPremul_SkAlphaType
: fAlphaType;
// MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
newAlphaType, renderTargetContext->asTextureProxyRef(),
fAlphaType, renderTargetContext->asTextureProxyRef(),
std::move(target), fBudgeted);
}
bool SkImage_Gpu::onIsValid(GrContext* context) const {

View File

@ -59,7 +59,7 @@ public:
sk_sp<SkColorSpace> refColorSpace() { return fColorSpace; }
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const override;
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
typedef ReleaseContext TextureContext;
typedef void (*TextureFulfillProc)(TextureContext textureContext, GrBackendTexture* outTexture);

View File

@ -311,8 +311,7 @@ sk_sp<SkImage> SkImage_Lazy::onMakeSubset(const SkIRect& subset) const {
return validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr;
}
sk_sp<SkImage> SkImage_Lazy::onMakeColorSpace(sk_sp<SkColorSpace> target,
SkColorType targetColorType) const {
sk_sp<SkImage> SkImage_Lazy::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
SkAutoExclusive autoAquire(fOnMakeColorSpaceMutex);
if (target && fOnMakeColorSpaceTarget &&
SkColorSpace::Equals(target.get(), fOnMakeColorSpaceTarget.get())) {

View File

@ -61,7 +61,7 @@ public:
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
bool onIsLazyGenerated() const override { return true; }
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const override;
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
bool onIsValid(GrContext*) const override;

View File

@ -110,7 +110,7 @@ public:
SkASSERT(bitmapMayBeMutable || fBitmap.isImmutable());
}
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const override;
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
bool onIsValid(GrContext* context) const override { return true; }
@ -341,8 +341,7 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap) const {
///////////////////////////////////////////////////////////////////////////////
sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target,
SkColorType targetColorType) const {
sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
SkPixmap src;
SkAssertResult(fBitmap.peekPixels(&src));
@ -355,7 +354,7 @@ sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target,
src.setColorSpace(SkColorSpace::MakeSRGB());
}
SkImageInfo dstInfo = fBitmap.info().makeColorType(targetColorType).makeColorSpace(target);
SkImageInfo dstInfo = fBitmap.info().makeColorSpace(target);
SkBitmap dst;
dst.allocPixels(dstInfo);