Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: src/gpu/effects/GrIndex8toRGBEffect.cpp

Issue 1495693003: Index8 GPU and CPU raster support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: revert SkImageGenerator&SkImageCacherator changes. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrIndex8toRGBEffect.h ('k') | tests/Index8Test.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « src/gpu/effects/GrIndex8toRGBEffect.h ('k') | tests/Index8Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698