Reland "Add support for unpremul image sources in the GPU backend"

This reverts commit cbf64e3634.

Reason for revert: Ancestral CLs have re-landed.

Original change's description:
> Revert "Add support for unpremul image sources in the GPU backend"
> 
> This reverts commit f06240de2c.
> 
> Reason for revert: I think this requires the skcms codec change to re-land,
> 
> Original change's description:
> > Add support for unpremul image sources in the GPU backend
> > 
> > Change-Id: Ib940fa0d658fff0b2dd923abfcc5ca4a49b2b38b
> > Reviewed-on: https://skia-review.googlesource.com/148397
> > Commit-Queue: Brian Osman <brianosman@google.com>
> > Reviewed-by: Mike Klein <mtklein@google.com>
> 
> TBR=mtklein@google.com,bsalomon@google.com,brianosman@google.com
> 
> Change-Id: Ib9358cf858c3c0887322503a4b021e08a0ac4cd5
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/148861
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>

TBR=mtklein@google.com,bsalomon@google.com,brianosman@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I20d8d17f5cc6ed1a359c0f7af1c96bf5304f6885
Reviewed-on: https://skia-review.googlesource.com/149804
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-08-27 20:36:19 +00:00 committed by Skia Commit-Bot
parent da6289c5f3
commit 21fc5ce7f8
16 changed files with 32 additions and 21 deletions

View File

@ -316,7 +316,7 @@ sk_sp<SkSpecialImage> SkImageFilter::ImageToColorSpace(SkSpecialImage* src,
// object. If that produces something, then both are tagged, and the source is in a different
// gamut than the dest. There is some overhead to making the xform, but those are cached, and
// if we get one back, that means we're about to use it during the conversion anyway.
auto colorSpaceXform = GrColorSpaceXform::Make(src->getColorSpace(), kPremul_SkAlphaType,
auto colorSpaceXform = GrColorSpaceXform::Make(src->getColorSpace(), src->alphaType(),
outProps.colorSpace(), kPremul_SkAlphaType);
if (!colorSpaceXform) {

View File

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

View File

@ -176,7 +176,7 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
const OutputProperties& outProps = ctx.outputProperties();
auto textureFP = GrSimpleTextureEffect::Make(std::move(inputProxy), SkMatrix::I());
textureFP = GrColorSpaceXformEffect::Make(std::move(textureFP), input->getColorSpace(),
outProps.colorSpace());
input->alphaType(), outProps.colorSpace());
if (!textureFP) {
return nullptr;
}

View File

@ -316,6 +316,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
GrTextureDomain::MakeTexelDomain(background->subset()),
GrTextureDomain::kDecal_Mode, GrSamplerState::Filter::kNearest);
bgFP = GrColorSpaceXformEffect::Make(std::move(bgFP), background->getColorSpace(),
background->alphaType(),
outputProperties.colorSpace());
} else {
bgFP = GrConstColorProcessor::Make(GrColor4f::TransparentBlack(),
@ -331,6 +332,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
GrTextureDomain::kDecal_Mode, GrSamplerState::Filter::kNearest);
foregroundFP = GrColorSpaceXformEffect::Make(std::move(foregroundFP),
foreground->getColorSpace(),
foreground->alphaType(),
outputProperties.colorSpace());
paint.addColorFragmentProcessor(std::move(foregroundFP));

View File

@ -306,7 +306,8 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
offsetMatrix,
std::move(colorProxy),
SkISize::Make(color->width(), color->height()));
fp = GrColorSpaceXformEffect::Make(std::move(fp), color->getColorSpace(), colorSpace);
fp = GrColorSpaceXformEffect::Make(std::move(fp), color->getColorSpace(),
color->alphaType(), colorSpace);
GrPaint paint;
paint.addColorFragmentProcessor(std::move(fp));

View File

@ -115,7 +115,7 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour
bounds.width() * invInset,
bounds.height() * invInset);
fp = GrColorSpaceXformEffect::Make(std::move(fp), input->getColorSpace(),
ctx.outputProperties().colorSpace());
input->alphaType(), ctx.outputProperties().colorSpace());
if (!fp) {
return nullptr;
}

View File

@ -286,6 +286,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
GrTextureDomain::kDecal_Mode,
GrSamplerState::Filter::kNearest);
bgFP = GrColorSpaceXformEffect::Make(std::move(bgFP), background->getColorSpace(),
background->alphaType(),
outputProperties.colorSpace());
} else {
bgFP = GrConstColorProcessor::Make(GrColor4f::TransparentBlack(),
@ -301,6 +302,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
GrTextureDomain::kDecal_Mode, GrSamplerState::Filter::kNearest);
foregroundFP = GrColorSpaceXformEffect::Make(std::move(foregroundFP),
foreground->getColorSpace(),
foreground->alphaType(),
outputProperties.colorSpace());
paint.addColorFragmentProcessor(std::move(foregroundFP));

View File

@ -146,8 +146,9 @@ GrFragmentProcessor::OptimizationFlags GrColorSpaceXformEffect::OptFlags(
}
std::unique_ptr<GrFragmentProcessor> GrColorSpaceXformEffect::Make(SkColorSpace* src,
SkAlphaType srcAT,
SkColorSpace* dst) {
auto xform = GrColorSpaceXform::Make(src, kPremul_SkAlphaType,
auto xform = GrColorSpaceXform::Make(src, srcAT,
dst, kPremul_SkAlphaType);
if (!xform) {
return nullptr;
@ -159,12 +160,12 @@ std::unique_ptr<GrFragmentProcessor> GrColorSpaceXformEffect::Make(SkColorSpace*
std::unique_ptr<GrFragmentProcessor> GrColorSpaceXformEffect::Make(
std::unique_ptr<GrFragmentProcessor> child,
SkColorSpace* src, SkColorSpace* dst) {
SkColorSpace* src, SkAlphaType srcAT, SkColorSpace* dst) {
if (!child) {
return nullptr;
}
auto xform = GrColorSpaceXform::Make(src, kPremul_SkAlphaType,
auto xform = GrColorSpaceXform::Make(src, srcAT,
dst, kPremul_SkAlphaType);
if (!xform) {
return child;

View File

@ -51,14 +51,16 @@ public:
/**
* Returns a fragment processor that converts the input's color space from src to dst.
*/
static std::unique_ptr<GrFragmentProcessor> Make(SkColorSpace* src, SkColorSpace* dst);
static std::unique_ptr<GrFragmentProcessor> Make(SkColorSpace* src, SkAlphaType srcAT,
SkColorSpace* dst);
/**
* Returns a fragment processor that calls the passed in fragment processor, and then converts
* the color space of the output from src to dst.
*/
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child,
SkColorSpace* src, SkColorSpace* dst);
SkColorSpace* src, SkAlphaType srcAT,
SkColorSpace* dst);
const char* name() const override { return "ColorSpaceXform"; }
std::unique_ptr<GrFragmentProcessor> clone() const override;

View File

@ -162,5 +162,5 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
(domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), textureMatrix,
domainMode, domain, filterOrNullForBicubic);
return GrColorSpaceXformEffect::Make(std::move(fp), fColorSpace, dstColorSpace);
return GrColorSpaceXformEffect::Make(std::move(fp), fColorSpace, fAlphaType, dstColorSpace);
}

View File

@ -152,5 +152,6 @@ std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
SkASSERT(kTightCopy_DomainMode != domainMode);
auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), adjustedMatrix,
domainMode, domain, filterOrNullForBicubic);
return GrColorSpaceXformEffect::Make(std::move(fp), texColorSpace.get(), dstColorSpace);
return GrColorSpaceXformEffect::Make(std::move(fp), texColorSpace.get(), this->alphaType(),
dstColorSpace);
}

View File

@ -130,7 +130,7 @@ 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, dstColorSpace);
GrColorSpaceXformEffect::Make(srcColorSpace, kPremul_SkAlphaType, dstColorSpace);
if (colorConversionProcessor) {
paint.addColorFragmentProcessor(std::move(colorConversionProcessor));
}

View File

@ -1010,7 +1010,7 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap,
fp = GrSimpleTextureEffect::Make(std::move(proxy), texMatrix, samplerState);
}
fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(),
fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(), bitmap.alphaType(),
fRenderTargetContext->colorSpaceInfo().colorSpace());
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext->colorSpaceInfo(), paint,
@ -1083,7 +1083,7 @@ void SkGpuDevice::drawSpecial(SkSpecialImage* special, int left, int top, const
tmpUnfiltered.setImageFilter(nullptr);
auto fp = GrSimpleTextureEffect::Make(std::move(proxy), SkMatrix::I());
fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(),
fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(), result->alphaType(),
fRenderTargetContext->colorSpaceInfo().colorSpace());
if (GrPixelConfigIsAlphaOnly(config)) {
fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp));
@ -1406,7 +1406,7 @@ void SkGpuDevice::drawProducerLattice(GrTextureProducer* producer,
if (!proxy) {
return;
}
auto csxf = GrColorSpaceXform::Make(proxyColorSpace.get(), kPremul_SkAlphaType,
auto csxf = GrColorSpaceXform::Make(proxyColorSpace.get(), producer->alphaType(),
dstColorSpace, kPremul_SkAlphaType);
fRenderTargetContext->drawImageLattice(this->clip(), std::move(grPaint), this->ctm(),

View File

@ -99,7 +99,7 @@ static bool can_use_draw_texture(const SkPaint& paint) {
static void draw_texture(const SkPaint& paint, const SkMatrix& ctm, const SkRect* src,
const SkRect* dst, GrAA aa, SkCanvas::SrcRectConstraint constraint,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrTextureProxy> proxy, SkAlphaType alphaType,
SkColorSpace* colorSpace, const GrClip& clip, GrRenderTargetContext* rtc) {
SkASSERT(!(SkToBool(src) && !SkToBool(dst)));
SkRect srcRect = src ? *src : SkRect::MakeWH(proxy->width(), proxy->height());
@ -112,7 +112,7 @@ static void draw_texture(const SkPaint& paint, const SkMatrix& ctm, const SkRect
srcToDst.mapRect(&dstRect, srcRect);
}
auto textureXform =
GrColorSpaceXform::Make(colorSpace , kPremul_SkAlphaType,
GrColorSpaceXform::Make(colorSpace , alphaType,
rtc->colorSpaceInfo().colorSpace(), kPremul_SkAlphaType);
GrSamplerState::Filter filter;
switch (paint.getFilterQuality()) {
@ -150,7 +150,7 @@ void SkGpuDevice::drawPinnedTextureProxy(sk_sp<GrTextureProxy> proxy, uint32_t p
GrAA aa = GrAA(paint.isAntiAlias());
if (can_use_draw_texture(paint)) {
draw_texture(paint, viewMatrix, srcRect, dstRect, aa, constraint, std::move(proxy),
colorSpace, this->clip(), fRenderTargetContext.get());
alphaType, colorSpace, this->clip(), fRenderTargetContext.get());
return;
}
GrTextureAdjuster adjuster(this->context(), std::move(proxy), alphaType, pinnedUniqueID,
@ -174,7 +174,7 @@ void SkGpuDevice::drawTextureMaker(GrTextureMaker* maker, int imageW, int imageH
return;
}
draw_texture(paint, viewMatrix, srcRect, dstRect, aa, constraint, std::move(proxy),
cs.get(), this->clip(), fRenderTargetContext.get());
maker->alphaType(), cs.get(), this->clip(), fRenderTargetContext.get());
return;
}
this->drawTextureProducer(maker, srcRect, dstRect, constraint, viewMatrix, paint);

View File

@ -944,7 +944,7 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target, SkColor
srcSpace = SkColorSpace::MakeSRGB();
}
auto xform = GrColorSpaceXformEffect::Make(srcSpace.get(), target.get());
auto xform = GrColorSpaceXformEffect::Make(srcSpace.get(), this->alphaType(), target.get());
if (!xform) {
return sk_ref_sp(const_cast<SkImage_Gpu*>(this));
}

View File

@ -242,6 +242,7 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
inner = GrSimpleTextureEffect::Make(std::move(proxy), lmInverse, samplerState);
}
inner = GrColorSpaceXformEffect::Make(std::move(inner), texColorSpace.get(),
fImage->alphaType(),
args.fDstColorSpaceInfo->colorSpace());
if (isAlphaOnly) {
return inner;