| Index: src/gpu/effects/GrIndex8toRGBEffect.cpp
|
| diff --git a/src/gpu/effects/GrIndex8toRGBEffect.cpp b/src/gpu/effects/GrIndex8toRGBEffect.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..031526b1003d17d02ecdccb9c44d20fd92fb0ab4
|
| --- /dev/null
|
| +++ b/src/gpu/effects/GrIndex8toRGBEffect.cpp
|
| @@ -0,0 +1,85 @@
|
| +/*
|
| + * 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 "GrIndex8toRGBEffect.h"
|
| +
|
| +#include "GrCoordTransform.h"
|
| +#include "GrInvariantOutput.h"
|
| +#include "GrProcessor.h"
|
| +#include "gl/GrGLFragmentProcessor.h"
|
| +#include "gl/builders/GrGLProgramBuilder.h"
|
| +#include "glsl/GrGLSLProgramDataManager.h"
|
| +
|
| +namespace {
|
| +
|
| + class Index8toRGBEffect : public GrSingleTextureEffect {
|
| + public:
|
| + static GrFragmentProcessor* Create(GrTexture* tex, GrTexture* colorMapTexture,
|
| + const SkMatrix& matrix, GrCoordSet coordSet = kLocal_GrCoordSet) {
|
| + return new Index8toRGBEffect(tex, colorMapTexture, matrix, coordSet);
|
| + }
|
| +
|
| + const char* name() const override { return "Index8 to RGB"; }
|
| +
|
| + class GLProcessor : public GrGLFragmentProcessor {
|
| + public:
|
| + // this class always generates the same code.
|
| + static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) {}
|
| +
|
| + GLProcessor(const GrProcessor&) {}
|
| +
|
| + virtual void emitCode(EmitArgs& args) override {
|
| + GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
|
| + // float a = texture2D(sampler, texC).a;
|
| + // gl_FragColor = texture2D(paletteSampler, vec2(a, .5));
|
| + fsBuilder->codeAppend("\tfloat a = ");
|
| + fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str());
|
| + fsBuilder->codeAppend(".a;\n");
|
| +
|
| + fsBuilder->codeAppendf("\t%s = ", args.fOutputColor);
|
| + fsBuilder->appendTextureLookup(args.fSamplers[1], "vec2(a, .5)");
|
| + fsBuilder->codeAppend(";\n");
|
| + }
|
| +
|
| + private:
|
| + typedef GrGLFragmentProcessor INHERITED;
|
| + };
|
| +
|
| + private:
|
| + Index8toRGBEffect(GrTexture* tex, GrTexture* colorMapTexture,
|
| + const SkMatrix& matrix, GrCoordSet coordSet)
|
| + : GrSingleTextureEffect(tex, matrix, GrTextureParams::kNone_FilterMode, coordSet)
|
| + , fColorMapTextureAccess(colorMapTexture) {
|
| + this->initClassID<Index8toRGBEffect>();
|
| + this->addTextureAccess(&fColorMapTextureAccess);
|
| + }
|
| +
|
| + GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLProcessor(*this); }
|
| +
|
| + virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
|
| + GrProcessorKeyBuilder* b) const override {
|
| + GLProcessor::GenKey(*this, caps, b);
|
| + }
|
| +
|
| + void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
|
| + updateInvariantOutputForModulation(inout);
|
| + }
|
| +
|
| + bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
|
| +
|
| + GrTextureAccess fColorMapTextureAccess;
|
| +
|
| + typedef GrFragmentProcessor INHERITED;
|
| + };
|
| +}
|
| +//////////////////////////////////////////////////////////////////////////////
|
| +
|
| +GrFragmentProcessor* GrIndex8toRGBEffect::Create(GrTexture* tex, GrTexture* colorMapTexture,
|
| + const SkMatrix& matrix, GrCoordSet coordSet) {
|
| + SkASSERT(tex && colorMapTexture);
|
| + return Index8toRGBEffect::Create(tex, colorMapTexture, matrix, coordSet);
|
| +}
|
|
|