Remove texture sampling from GrConfigConversionEffect

BUG=skia:

Change-Id: If5df087d3fe11098f468deab5f2fc8beb782cc83
Reviewed-on: https://skia-review.googlesource.com/10026
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-03-23 09:06:13 -04:00 committed by Skia Commit-Bot
parent 3849b64cbb
commit 3bc9bfea5e
3 changed files with 47 additions and 87 deletions

View File

@ -870,14 +870,14 @@ sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect(GrTexture* texture,
ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(texture, nullptr, matrix);
if (kRGBA_half_GrPixelConfig == texture->config()) {
return GrFragmentProcessor::UnpremulOutput(
GrSimpleTextureEffect::Make(texture, nullptr, matrix));
return GrFragmentProcessor::UnpremulOutput(std::move(fp));
} else {
GrConfigConversionEffect::PMConversion pmToUPM =
static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != pmToUPM) {
return GrConfigConversionEffect::Make(texture, pmToUPM, matrix);
return GrConfigConversionEffect::Make(std::move(fp), pmToUPM);
} else {
return nullptr;
}
@ -889,16 +889,16 @@ sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect(sk_sp<GrTextureProxy>
ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
if (kRGBA_half_GrPixelConfig == proxy->config()) {
return GrFragmentProcessor::UnpremulOutput(
GrSimpleTextureEffect::Make(this->resourceProvider(), std::move(proxy),
nullptr, matrix));
GrPixelConfig config = proxy->config();
sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(this->resourceProvider(),
std::move(proxy), nullptr, matrix);
if (kRGBA_half_GrPixelConfig == config) {
return GrFragmentProcessor::UnpremulOutput(std::move(fp));
} else {
GrConfigConversionEffect::PMConversion pmToUPM =
static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != pmToUPM) {
return GrConfigConversionEffect::Make(this->resourceProvider(), std::move(proxy),
pmToUPM, matrix);
return GrConfigConversionEffect::Make(std::move(fp), pmToUPM);
} else {
return nullptr;
}
@ -910,16 +910,16 @@ sk_sp<GrFragmentProcessor> GrContext::createUPMToPMEffect(sk_sp<GrTextureProxy>
ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
if (kRGBA_half_GrPixelConfig == proxy->config()) {
return GrFragmentProcessor::PremulOutput(
GrSimpleTextureEffect::Make(this->resourceProvider(), std::move(proxy),
nullptr, matrix));
GrPixelConfig config = proxy->config();
sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(this->resourceProvider(),
std::move(proxy), nullptr, matrix);
if (kRGBA_half_GrPixelConfig == config) {
return GrFragmentProcessor::PremulOutput(std::move(fp));
} else {
GrConfigConversionEffect::PMConversion upmToPM =
static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != upmToPM) {
return GrConfigConversionEffect::Make(this->resourceProvider(), std::move(proxy),
upmToPM, matrix);
return GrConfigConversionEffect::Make(std::move(fp), upmToPM);
} else {
return nullptr;
}

View File

@ -10,7 +10,6 @@
#include "GrClip.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
#include "GrSimpleTextureEffect.h"
#include "SkMatrix.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
@ -30,10 +29,11 @@ public:
fragBuilder->codeAppendf("%s;", tmpDecl.c_str());
fragBuilder->codeAppendf("%s = ", tmpVar.c_str());
fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fTransformedCoords[0].c_str(),
args.fTransformedCoords[0].getType());
fragBuilder->codeAppend(";");
if (nullptr == args.fInputColor) {
// could optimize this case, but we aren't for now.
args.fInputColor = "vec4(1)";
}
fragBuilder->codeAppendf("%s = %s;", tmpVar.c_str(), args.fInputColor);
switch (pmConversion) {
case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
@ -87,29 +87,11 @@ private:
};
///////////////////////////////////////////////////////////////////////////////
GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture,
PMConversion pmConversion,
const SkMatrix& matrix)
: INHERITED(texture, nullptr, matrix, kNone_OptimizationFlags)
, fPMConversion(pmConversion) {
this->initClassID<GrConfigConversionEffect>();
// We expect to get here with non-BGRA/RGBA only if we're doing not doing a premul/unpremul
// conversion.
SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() ||
kBGRA_8888_GrPixelConfig == texture->config());
}
GrConfigConversionEffect::GrConfigConversionEffect(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
PMConversion pmConversion,
const SkMatrix& matrix)
: INHERITED(resourceProvider, kNone_OptimizationFlags, proxy, nullptr, matrix)
GrConfigConversionEffect::GrConfigConversionEffect(PMConversion pmConversion)
: INHERITED(kNone_OptimizationFlags)
, fPMConversion(pmConversion) {
this->initClassID<GrConfigConversionEffect>();
// We expect to get here with non-BGRA/RGBA only if we're doing not doing a premul/unpremul
// conversion.
SkASSERT(kRGBA_8888_GrPixelConfig == proxy->config() ||
kBGRA_8888_GrPixelConfig == proxy->config());
}
bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& s) const {
@ -130,10 +112,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect);
#if GR_TEST_UTILS
sk_sp<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(GrProcessorTestData* d) {
PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kPMConversionCnt));
return sk_sp<GrFragmentProcessor>(new GrConfigConversionEffect(
d->resourceProvider(),
d->textureProxy(GrProcessorUnitTest::kSkiaPMTextureIdx),
pmConv, GrTest::TestMatrix(d->fRandom)));
return sk_sp<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv));
}
#endif
@ -226,14 +205,11 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
GrPaint paint1;
GrPaint paint2;
GrPaint paint3;
sk_sp<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect(
resourceProvider, dataProxy, *pmToUPMRule, SkMatrix::I()));
sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect(
resourceProvider, readRTC->asTextureProxyRef(), *upmToPMRule, SkMatrix::I()));
sk_sp<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect(
resourceProvider, tempRTC->asTextureProxyRef(), *pmToUPMRule, SkMatrix::I()));
sk_sp<GrFragmentProcessor> pmToUPM(new GrConfigConversionEffect(*pmToUPMRule));
sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect(*upmToPMRule));
paint1.addColorFragmentProcessor(std::move(pmToUPM1));
paint1.addColorTextureProcessor(resourceProvider, dataProxy, nullptr, SkMatrix::I());
paint1.addColorFragmentProcessor(pmToUPM);
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kDstRect,
@ -243,13 +219,17 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
continue;
}
paint2.addColorTextureProcessor(resourceProvider, readRTC->asTextureProxyRef(), nullptr,
SkMatrix::I());
paint2.addColorFragmentProcessor(std::move(upmToPM));
paint2.setPorterDuffXPFactory(SkBlendMode::kSrc);
tempRTC->fillRectToRect(GrNoClip(), std::move(paint2), GrAA::kNo, SkMatrix::I(), kDstRect,
kSrcRect);
paint3.addColorFragmentProcessor(std::move(pmToUPM2));
paint3.addColorTextureProcessor(resourceProvider, tempRTC->asTextureProxyRef(), nullptr,
SkMatrix::I());
paint3.addColorFragmentProcessor(std::move(pmToUPM));
paint3.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kDstRect,
@ -275,28 +255,12 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
}
}
sk_sp<GrFragmentProcessor> GrConfigConversionEffect::Make(GrTexture* texture,
PMConversion pmConversion,
const SkMatrix& matrix) {
if (kRGBA_8888_GrPixelConfig != texture->config() &&
kBGRA_8888_GrPixelConfig != texture->config()) {
// The PM conversions assume colors are 0..255
sk_sp<GrFragmentProcessor> GrConfigConversionEffect::Make(sk_sp<GrFragmentProcessor> fp,
PMConversion pmConversion) {
if (!fp) {
return nullptr;
}
return sk_sp<GrFragmentProcessor>(
new GrConfigConversionEffect(texture, pmConversion, matrix));
}
sk_sp<GrFragmentProcessor> GrConfigConversionEffect::Make(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
PMConversion pmConversion,
const SkMatrix& matrix) {
if (kRGBA_8888_GrPixelConfig != proxy->config() &&
kBGRA_8888_GrPixelConfig != proxy->config()) {
// The PM conversions assume colors are 0..255
return nullptr;
}
return sk_sp<GrFragmentProcessor>(new GrConfigConversionEffect(resourceProvider,
std::move(proxy),
pmConversion, matrix));
sk_sp<GrFragmentProcessor> ccFP(new GrConfigConversionEffect(pmConversion));
sk_sp<GrFragmentProcessor> fpPipeline[] = { fp, ccFP };
return GrFragmentProcessor::RunInSeries(fpPipeline, 2);
}

View File

@ -8,15 +8,13 @@
#ifndef GrConfigConversionEffect_DEFINED
#define GrConfigConversionEffect_DEFINED
#include "GrSingleTextureEffect.h"
class GrInvariantOutput;
#include "GrFragmentProcessor.h"
/**
* This class is used to perform config conversions. Clients may want to read/write data that is
* unpremultiplied.
*/
class GrConfigConversionEffect : public GrSingleTextureEffect {
class GrConfigConversionEffect : public GrFragmentProcessor {
public:
/**
* The PM->UPM or UPM->PM conversions to apply.
@ -30,10 +28,11 @@ public:
kPMConversionCnt
};
static sk_sp<GrFragmentProcessor> Make(GrTexture*, PMConversion, const SkMatrix&);
static sk_sp<GrFragmentProcessor> Make(GrResourceProvider*, sk_sp<GrTextureProxy>,
PMConversion, const SkMatrix&);
/**
* Returns a fragment processor that calls the passed in fragment processor, and then performs
* the requested premul or unpremul conversion.
*/
static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor>, PMConversion);
const char* name() const override { return "Config Conversion"; }
@ -48,10 +47,7 @@ public:
PMConversion* PMToUPMRule,
PMConversion* UPMToPMRule);
private:
GrConfigConversionEffect(GrTexture*, PMConversion, const SkMatrix& matrix);
GrConfigConversionEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
PMConversion, const SkMatrix& matrix);
GrConfigConversionEffect(PMConversion);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
@ -63,7 +59,7 @@ private:
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrSingleTextureEffect INHERITED;
typedef GrFragmentProcessor INHERITED;
};
#endif