Replace GrExtractAlphaFragmentProcessor with DstIn compose processor
Review URL: https://codereview.chromium.org/1347943003
This commit is contained in:
parent
106b12427e
commit
87ba62e67c
@ -10,7 +10,7 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrFragmentProcessor.h"
|
||||
#include "GrCoordTransform.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "effects/GrXfermodeFragmentProcessor.h"
|
||||
#include "gl/GrGLProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
#include "Resources.h"
|
||||
@ -104,7 +104,7 @@ const GrFragmentProcessor* DCShader::asFragmentProcessor(
|
||||
SkFilterQuality,
|
||||
GrProcessorDataManager* procDataManager) const {
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(procDataManager, fDeviceMatrix));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
class DCShaderGM : public GM {
|
||||
|
@ -46,7 +46,6 @@
|
||||
'<(skia_include_path)/gpu/effects/GrConstColorProcessor.h',
|
||||
'<(skia_include_path)/gpu/effects/GrCoverageSetOpXP.h',
|
||||
'<(skia_include_path)/gpu/effects/GrCustomXfermode.h',
|
||||
'<(skia_include_path)/gpu/effects/GrExtractAlphaFragmentProcessor.h',
|
||||
'<(skia_include_path)/gpu/effects/GrPorterDuffXferProcessor.h',
|
||||
'<(skia_include_path)/gpu/effects/GrXfermodeFragmentProcessor.h',
|
||||
|
||||
@ -243,7 +242,6 @@
|
||||
'<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp',
|
||||
'<(skia_src_path)/gpu/effects/GrConfigConversionEffect.h',
|
||||
'<(skia_src_path)/gpu/effects/GrConstColorProcessor.cpp',
|
||||
'<(skia_src_path)/gpu/effects/GrExtractAlphaFragmentProcessor.cpp',
|
||||
'<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.cpp',
|
||||
'<(skia_src_path)/gpu/effects/GrCustomXfermode.cpp',
|
||||
'<(skia_src_path)/gpu/effects/GrBezierEffect.cpp',
|
||||
|
@ -23,6 +23,16 @@ class GrProcessorKeyBuilder;
|
||||
*/
|
||||
class GrFragmentProcessor : public GrProcessor {
|
||||
public:
|
||||
/**
|
||||
* In many instances (e.g. SkShader::asFragmentProcessor() implementations) it is desirable to
|
||||
* only consider the input color's alpha. However, there is a competing desire to have reusable
|
||||
* GrFragmentProcessor subclasses that can be used in other scenarios where the entire input
|
||||
* color is considered. This function exists to filter the input color and pass it to a FP. It
|
||||
* does so by returning a parent FP that multiplies the passed in FPs output by the parent's
|
||||
* input alpha. The passed in FP will not receive an input color.
|
||||
*/
|
||||
static const GrFragmentProcessor* MulOuputByInputAlpha(const GrFragmentProcessor*);
|
||||
|
||||
GrFragmentProcessor()
|
||||
: INHERITED()
|
||||
, fUsesLocalCoords(false)
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrExtractAlphaFragmentProcessor_DEFINED
|
||||
#define GrExtractAlphaFragmentProcessor_DEFINED
|
||||
|
||||
#include "GrFragmentProcessor.h"
|
||||
|
||||
/** This processor extracts the incoming color's alpha, ignores r, g, and b, and feeds
|
||||
the replicated alpha to it's inner processor. */
|
||||
class GrExtractAlphaFragmentProcessor : public GrFragmentProcessor {
|
||||
public:
|
||||
static GrFragmentProcessor* Create(const GrFragmentProcessor* processor) {
|
||||
if (!processor) {
|
||||
return nullptr;
|
||||
}
|
||||
return new GrExtractAlphaFragmentProcessor(processor);
|
||||
}
|
||||
|
||||
~GrExtractAlphaFragmentProcessor() override {}
|
||||
|
||||
const char* name() const override { return "Extract Alpha"; }
|
||||
|
||||
private:
|
||||
GrExtractAlphaFragmentProcessor(const GrFragmentProcessor* processor) {
|
||||
this->initClassID<GrExtractAlphaFragmentProcessor>();
|
||||
this->registerChildProcessor(processor);
|
||||
}
|
||||
|
||||
GrGLFragmentProcessor* onCreateGLInstance() const override;
|
||||
|
||||
void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
|
||||
void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
|
||||
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
@ -16,7 +16,6 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "effects/GrBicubicEffect.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "effects/GrSimpleTextureEffect.h"
|
||||
#endif
|
||||
|
||||
@ -411,7 +410,7 @@ const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co
|
||||
if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
|
||||
return SkRef(inner.get());
|
||||
}
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -131,7 +131,6 @@ private:
|
||||
#include "GrCoordTransform.h"
|
||||
#include "GrFragmentProcessor.h"
|
||||
#include "GrTextureAccess.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/GrGLProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
#include "SkGr.h"
|
||||
@ -401,7 +400,7 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor(
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner (
|
||||
new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffParams, normParams,
|
||||
fLights, fInvNormRotation));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "GrInvariantOutput.h"
|
||||
#include "SkGr.h"
|
||||
#include "effects/GrConstColorProcessor.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/GrGLFragmentProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
#endif
|
||||
@ -935,7 +934,7 @@ const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor(
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(
|
||||
GrConstColorProcessor::Create(0x80404040,
|
||||
GrConstColorProcessor::kModulateRGBA_InputMode));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
// Emit zero.
|
||||
return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode);
|
||||
@ -963,7 +962,7 @@ const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor(
|
||||
paintingData,
|
||||
permutationsTexture, noiseTexture,
|
||||
m));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
delete paintingData;
|
||||
return nullptr;
|
||||
|
@ -439,7 +439,6 @@ void SkLinearGradient::LinearGradientContext::shadeSpan16(int x, int y,
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
#include "SkGr.h"
|
||||
|
||||
@ -562,7 +561,7 @@ const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor(
|
||||
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(
|
||||
GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileMode));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
|
||||
|
@ -415,7 +415,6 @@ void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y,
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "SkGr.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
|
||||
class GrGLRadialGradient : public GrGLGradientEffect {
|
||||
@ -534,7 +533,7 @@ const GrFragmentProcessor* SkRadialGradient::asFragmentProcessor(
|
||||
matrix.postConcat(fPtsToUnit);
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(
|
||||
GrRadialGradient::Create(context, procDataManager, *this, matrix, fTileMode));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -167,7 +167,6 @@ void SkSweepGradient::SweepGradientContext::shadeSpan16(int x, int y, uint16_t*
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "SkGr.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
|
||||
class GrGLSweepGradient : public GrGLGradientEffect {
|
||||
@ -292,7 +291,7 @@ const GrFragmentProcessor* SkSweepGradient::asFragmentProcessor(
|
||||
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(
|
||||
GrSweepGradient::Create(context, procDataManager, *this, matrix));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -359,7 +359,6 @@ void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const {
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "SkGr.h"
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
|
||||
const GrFragmentProcessor* SkTwoPointConicalGradient::asFragmentProcessor(
|
||||
GrContext* context,
|
||||
@ -372,7 +371,7 @@ const GrFragmentProcessor* SkTwoPointConicalGradient::asFragmentProcessor(
|
||||
SkAutoTUnref<const GrFragmentProcessor> inner(
|
||||
Gr2PtConicalGradientEffect::Create(context, procDataManager, *this, fTileMode,
|
||||
localMatrix));
|
||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
||||
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -241,6 +241,13 @@ bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "effects/GrXfermodeFragmentProcessor.h"
|
||||
|
||||
const GrFragmentProcessor* GrFragmentProcessor::MulOuputByInputAlpha(
|
||||
const GrFragmentProcessor* fp) {
|
||||
return GrXfermodeFragmentProcessor::CreateFromDstProcessor(fp, SkXfermode::kDstIn_Mode);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Initial static variable from GrXPFactory
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
||||
#include "gl/GrGLFragmentProcessor.h"
|
||||
#include "gl/builders/GrGLProgramBuilder.h"
|
||||
|
||||
class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor {
|
||||
public:
|
||||
GLExtractAlphaFragmentProcessor() {}
|
||||
|
||||
void emitCode(EmitArgs& args) override {
|
||||
if (args.fInputColor) {
|
||||
GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
|
||||
fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor);
|
||||
this->emitChild(0, "alpha4", args.fOutputColor, args);
|
||||
} else {
|
||||
this->emitChild(0, nullptr, args.fOutputColor, args);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GrGLFragmentProcessor INHERITED;
|
||||
};
|
||||
|
||||
GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() const {
|
||||
return new GLExtractAlphaFragmentProcessor;
|
||||
}
|
||||
|
||||
void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&,
|
||||
GrProcessorKeyBuilder*) const {
|
||||
}
|
||||
|
||||
bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) const { return true; }
|
||||
|
||||
void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const {
|
||||
if (inout->validFlags() & kA_GrColorComponentFlag) {
|
||||
GrColor color = GrColorPackA4(GrColorUnpackA(inout->color()));
|
||||
inout->setToOther(kRGBA_GrColorComponentFlags, color,
|
||||
GrInvariantOutput::kWill_ReadInput);
|
||||
} else {
|
||||
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
|
||||
}
|
||||
this->childProcessor(0).computeInvariantOutput(inout);
|
||||
}
|
||||
|
||||
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrExtractAlphaFragmentProcessor);
|
||||
|
||||
const GrFragmentProcessor* GrExtractAlphaFragmentProcessor::TestCreate(GrProcessorTestData* d) {
|
||||
SkAutoTUnref<const GrFragmentProcessor> child(GrProcessorUnitTest::CreateChildFP(d));
|
||||
return new GrExtractAlphaFragmentProcessor(child);
|
||||
}
|
Loading…
Reference in New Issue
Block a user