ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
- GrPixelConfig config = texture->config();
- sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(texture, nullptr, matrix);
- if (kRGBA_half_GrPixelConfig == config) {
- return GrFragmentProcessor::UnpremulOutput(std::move(fp));
- } else if (kRGBA_8888_GrPixelConfig == config || kBGRA_8888_GrPixelConfig == config) {
+ if (kRGBA_half_GrPixelConfig == texture->config()) {
+ 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;
}
}
- return nullptr;
}
sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect(sk_sp<GrTextureProxy> proxy,
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));
- } else if (kRGBA_8888_GrPixelConfig == config || kBGRA_8888_GrPixelConfig == config) {
+ 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;
}
}
- return nullptr;
}
sk_sp<GrFragmentProcessor> GrContext::createUPMToPMEffect(sk_sp<GrTextureProxy> proxy,
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));
- } else if (kRGBA_8888_GrPixelConfig == config || kBGRA_8888_GrPixelConfig == config) {
+ 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;
}
}
- return nullptr;
}
bool GrContext::validPMUPMConversionExists(GrPixelConfig config) const {
#include "GrClip.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
+#include "GrSimpleTextureEffect.h"
#include "SkMatrix.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
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:
break;
}
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, tmpVar.c_str());
+
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppend(modulate.c_str());
}
static inline void GenKey(const GrProcessor& processor, const GrShaderCaps&,
};
///////////////////////////////////////////////////////////////////////////////
+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(PMConversion pmConversion)
- : INHERITED(kNone_OptimizationFlags)
+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 {
#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
GrPaint paint1;
GrPaint paint2;
GrPaint paint3;
- sk_sp<GrFragmentProcessor> pmToUPM(new GrConfigConversionEffect(*pmToUPMRule));
- sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect(*upmToPMRule));
-
- paint1.addColorTextureProcessor(resourceProvider, dataProxy, nullptr, SkMatrix::I());
- paint1.addColorFragmentProcessor(pmToUPM);
+ 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.addColorFragmentProcessor(std::move(pmToUPM1));
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(GrNoClip(), std::move(paint1), GrAA::kNo, SkMatrix::I(), kDstRect,
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,
}
}
-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;
+ }
+ 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;
}
- sk_sp<GrFragmentProcessor> ccFP(new GrConfigConversionEffect(pmConversion));
- sk_sp<GrFragmentProcessor> fpPipeline[] = { fp, ccFP };
- return GrFragmentProcessor::RunInSeries(fpPipeline, 2);
+ return sk_sp<GrFragmentProcessor>(new GrConfigConversionEffect(resourceProvider,
+ std::move(proxy),
+ pmConversion, matrix));
}
#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.
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"; }
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;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- typedef GrFragmentProcessor INHERITED;
+ typedef GrSingleTextureEffect INHERITED;
};
#endif