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

Side by Side Diff: src/gpu/effects/GrConstColorProcessor.cpp

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrConvexPolyEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "effects/GrConstColorProcessor.h" 8 #include "effects/GrConstColorProcessor.h"
9 #include "gl/GrGLFragmentProcessor.h" 9 #include "gl/GrGLFragmentProcessor.h"
10 #include "gl/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLProgramBuilder.h"
11 #include "glsl/GrGLSLProgramDataManager.h"
11 12
12 class GLConstColorProcessor : public GrGLFragmentProcessor { 13 class GLConstColorProcessor : public GrGLFragmentProcessor {
13 public: 14 public:
14 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {} 15 GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {}
15 16
16 void emitCode(EmitArgs& args) override { 17 void emitCode(EmitArgs& args) override {
17 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder (); 18 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder ();
18 const char* colorUni; 19 const char* colorUni;
19 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_ Visibility, 20 fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_ Visibility,
20 kVec4f_GrSLType, kMedium_GrSLPrecisi on, "constantColor", 21 kVec4f_GrSLType, kMedium_GrSLPrecisi on, "constantColor",
(...skipping 11 matching lines...) Expand all
32 colorUni); 33 colorUni);
33 break; 34 break;
34 case GrConstColorProcessor::kModulateA_InputMode: 35 case GrConstColorProcessor::kModulateA_InputMode:
35 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg s.fInputColor, 36 fsBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, arg s.fInputColor,
36 colorUni); 37 colorUni);
37 break; 38 break;
38 } 39 }
39 } 40 }
40 41
41 protected: 42 protected:
42 void onSetData(const GrGLProgramDataManager& pdm, const GrProcessor& process or) override { 43 void onSetData(const GrGLSLProgramDataManager& pdm, const GrProcessor& proce ssor) override {
43 GrColor color = processor.cast<GrConstColorProcessor>().color(); 44 GrColor color = processor.cast<GrConstColorProcessor>().color();
44 // We use the "illegal" color value as an uninit sentinel. However, ut i sn't inherently 45 // We use the "illegal" color value as an uninit sentinel. However, ut i sn't inherently
45 // illegal to use this processor with unpremul colors. So we correctly h andle the case 46 // illegal to use this processor with unpremul colors. So we correctly h andle the case
46 // when the "illegal" color is used but we will always upload it. 47 // when the "illegal" color is used but we will always upload it.
47 if (GrColor_ILLEGAL == color || fPrevColor != color) { 48 if (GrColor_ILLEGAL == color || fPrevColor != color) {
48 static const GrGLfloat scale = 1.f / 255.f; 49 static const float scale = 1.f / 255.f;
49 GrGLfloat floatColor[4] = { 50 float floatColor[4] = {
50 GrColorUnpackR(color) * scale, 51 GrColorUnpackR(color) * scale,
51 GrColorUnpackG(color) * scale, 52 GrColorUnpackG(color) * scale,
52 GrColorUnpackB(color) * scale, 53 GrColorUnpackB(color) * scale,
53 GrColorUnpackA(color) * scale, 54 GrColorUnpackA(color) * scale,
54 }; 55 };
55 pdm.set4fv(fColorUniform, 1, floatColor); 56 pdm.set4fv(fColorUniform, 1, floatColor);
56 fPrevColor = color; 57 fPrevColor = color;
57 } 58 }
58 } 59 }
59 60
60 private: 61 private:
61 GrGLProgramDataManager::UniformHandle fColorUniform; 62 GrGLSLProgramDataManager::UniformHandle fColorUniform;
62 GrColor fPrevColor; 63 GrColor fPrevColor;
63 64
64 typedef GrGLFragmentProcessor INHERITED; 65 typedef GrGLFragmentProcessor INHERITED;
65 }; 66 };
66 67
67 /////////////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////////////
68 69
69 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c onst { 70 void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) c onst {
70 if (kIgnore_InputMode == fMode) { 71 if (kIgnore_InputMode == fMode) {
71 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, 72 inout->setToOther(kRGBA_GrColorComponentFlags, fColor,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 color = 0; 124 color = 0;
124 break; 125 break;
125 case 2: 126 case 2:
126 color = d->fRandom->nextULessThan(0x100); 127 color = d->fRandom->nextULessThan(0x100);
127 color = color | (color << 8) | (color << 16) | (color << 24); 128 color = color | (color << 8) | (color << 16) | (color << 24);
128 break; 129 break;
129 } 130 }
130 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode Cnt)); 131 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputMode Cnt));
131 return GrConstColorProcessor::Create(color, mode); 132 return GrConstColorProcessor::Create(color, mode);
132 } 133 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrConvexPolyEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698