Revert "Remove texture sampling from GrConfigConversionEffect"
This reverts commit 3bc9bfea5e31b697033e4f0e4c4e4710c34e0387.
Reason for revert: I broke something subtle.
Original change's description:
> 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>
>
TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: Icca2f435b30512305f3e483689320a5930dc1467
Reviewed-on: https://skia-review.googlesource.com/10052
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index ec5b861..56d8117 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -870,14 +870,14 @@
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(std::move(fp));
+ return GrFragmentProcessor::UnpremulOutput(
+ GrSimpleTextureEffect::Make(texture, nullptr, matrix));
} else {
GrConfigConversionEffect::PMConversion pmToUPM =
static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != pmToUPM) {
- return GrConfigConversionEffect::Make(std::move(fp), pmToUPM);
+ return GrConfigConversionEffect::Make(texture, pmToUPM, matrix);
} else {
return nullptr;
}
@@ -889,16 +889,16 @@
ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
- 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));
+ if (kRGBA_half_GrPixelConfig == proxy->config()) {
+ return GrFragmentProcessor::UnpremulOutput(
+ GrSimpleTextureEffect::Make(this->resourceProvider(), std::move(proxy),
+ nullptr, matrix));
} else {
GrConfigConversionEffect::PMConversion pmToUPM =
static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != pmToUPM) {
- return GrConfigConversionEffect::Make(std::move(fp), pmToUPM);
+ return GrConfigConversionEffect::Make(this->resourceProvider(), std::move(proxy),
+ pmToUPM, matrix);
} else {
return nullptr;
}
@@ -910,16 +910,16 @@
ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
- 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));
+ if (kRGBA_half_GrPixelConfig == proxy->config()) {
+ return GrFragmentProcessor::PremulOutput(
+ GrSimpleTextureEffect::Make(this->resourceProvider(), std::move(proxy),
+ nullptr, matrix));
} else {
GrConfigConversionEffect::PMConversion upmToPM =
static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
if (GrConfigConversionEffect::kPMConversionCnt != upmToPM) {
- return GrConfigConversionEffect::Make(std::move(fp), upmToPM);
+ return GrConfigConversionEffect::Make(this->resourceProvider(), std::move(proxy),
+ upmToPM, matrix);
} else {
return nullptr;
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 785e341..2c6589d 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -10,6 +10,7 @@
#include "GrClip.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
+#include "GrSimpleTextureEffect.h"
#include "SkMatrix.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -29,11 +30,10 @@
fragBuilder->codeAppendf("%s;", tmpDecl.c_str());
- 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);
+ fragBuilder->codeAppendf("%s = ", tmpVar.c_str());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].getType());
+ fragBuilder->codeAppend(";");
switch (pmConversion) {
case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
@@ -87,11 +87,29 @@
};
///////////////////////////////////////////////////////////////////////////////
-
-GrConfigConversionEffect::GrConfigConversionEffect(PMConversion pmConversion)
- : INHERITED(kNone_OptimizationFlags)
+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)
+ , 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 {
@@ -112,7 +130,10 @@
#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(pmConv));
+ return sk_sp<GrFragmentProcessor>(new GrConfigConversionEffect(
+ d->resourceProvider(),
+ d->textureProxy(GrProcessorUnitTest::kSkiaPMTextureIdx),
+ pmConv, GrTest::TestMatrix(d->fRandom)));
}
#endif
@@ -205,11 +226,14 @@
GrPaint paint1;
GrPaint paint2;
GrPaint paint3;
- sk_sp<GrFragmentProcessor> pmToUPM(new GrConfigConversionEffect(*pmToUPMRule));
- sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect(*upmToPMRule));
+ 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()));
- paint1.addColorTextureProcessor(resourceProvider, dataProxy, nullptr, SkMatrix::I());
- paint1.addColorFragmentProcessor(pmToUPM);
+ paint1.addColorFragmentProcessor(std::move(pmToUPM1));
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kDstRect,
@@ -219,17 +243,13 @@
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.addColorTextureProcessor(resourceProvider, tempRTC->asTextureProxyRef(), nullptr,
- SkMatrix::I());
- paint3.addColorFragmentProcessor(std::move(pmToUPM));
+ paint3.addColorFragmentProcessor(std::move(pmToUPM2));
paint3.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(GrNoClip(), std::move(paint3), GrAA::kNo, SkMatrix::I(), kDstRect,
@@ -255,12 +275,28 @@
}
}
-sk_sp<GrFragmentProcessor> GrConfigConversionEffect::Make(sk_sp<GrFragmentProcessor> fp,
- PMConversion pmConversion) {
- if (!fp) {
+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
return nullptr;
}
- sk_sp<GrFragmentProcessor> ccFP(new GrConfigConversionEffect(pmConversion));
- sk_sp<GrFragmentProcessor> fpPipeline[] = { fp, ccFP };
- return GrFragmentProcessor::RunInSeries(fpPipeline, 2);
+ 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));
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.h b/src/gpu/effects/GrConfigConversionEffect.h
index e5fa10c..d71b228 100644
--- a/src/gpu/effects/GrConfigConversionEffect.h
+++ b/src/gpu/effects/GrConfigConversionEffect.h
@@ -8,13 +8,15 @@
#ifndef GrConfigConversionEffect_DEFINED
#define GrConfigConversionEffect_DEFINED
-#include "GrFragmentProcessor.h"
+#include "GrSingleTextureEffect.h"
+
+class GrInvariantOutput;
/**
* This class is used to perform config conversions. Clients may want to read/write data that is
* unpremultiplied.
*/
-class GrConfigConversionEffect : public GrFragmentProcessor {
+class GrConfigConversionEffect : public GrSingleTextureEffect {
public:
/**
* The PM->UPM or UPM->PM conversions to apply.
@@ -28,11 +30,10 @@
kPMConversionCnt
};
- /**
- * 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);
+ static sk_sp<GrFragmentProcessor> Make(GrTexture*, PMConversion, const SkMatrix&);
+
+ static sk_sp<GrFragmentProcessor> Make(GrResourceProvider*, sk_sp<GrTextureProxy>,
+ PMConversion, const SkMatrix&);
const char* name() const override { return "Config Conversion"; }
@@ -47,7 +48,10 @@
PMConversion* PMToUPMRule,
PMConversion* UPMToPMRule);
private:
- GrConfigConversionEffect(PMConversion);
+ GrConfigConversionEffect(GrTexture*, PMConversion, const SkMatrix& matrix);
+
+ GrConfigConversionEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
+ PMConversion, const SkMatrix& matrix);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
@@ -59,7 +63,7 @@
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- typedef GrFragmentProcessor INHERITED;
+ typedef GrSingleTextureEffect INHERITED;
};
#endif