1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrColorProcessor_DEFINED 9 #define GrColorProcessor_DEFINED 10 11 #include "GrFragmentProcessor.h" 12 13 /** 14 * This is a simple GrFragmentProcessor that outputs a constant color. It may do one of the 15 * following with its input color: ignore it, or multiply it by the constant color, multiply its 16 * alpha by the constant color and ignore the input color's r, g, and b. 17 */ 18 class GrConstColorProcessor : public GrFragmentProcessor { 19 public: 20 enum InputMode { 21 kIgnore_InputMode, 22 kModulateRGBA_InputMode, 23 kModulateA_InputMode, 24 25 kLastInputMode = kModulateA_InputMode 26 }; 27 static const int kInputModeCnt = kLastInputMode + 1; 28 29 static GrFragmentProcessor* Create(GrColor color, InputMode mode) { 30 return new GrConstColorProcessor(color, mode); 31 } 32 33 const char* name() const override { return "Color"; } 34 35 SkString dumpInfo() const override { 36 SkString str; 37 str.appendf("Color: 0x%08x", fColor); 38 return str; 39 } 40 41 GrColor color() const { return fColor; } 42 43 InputMode inputMode() const { return fMode; } 44 45 private: 46 GrConstColorProcessor(GrColor color, InputMode mode) : fColor(color), fMode(mode) { 47 this->initClassID<GrConstColorProcessor>(); 48 } 49 50 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 51 52 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; 53 54 bool onIsEqual(const GrFragmentProcessor&) const override; 55 56 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 57 58 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 59 60 GrColor fColor; 61 InputMode fMode; 62 63 typedef GrFragmentProcessor INHERITED; 64 }; 65 66 #endif 67