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

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

Issue 755363002: remove proc key (Closed) Base URL: https://skia.googlesource.com/skia.git@fixkey
Patch Set: address nit Created 6 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 unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrConvolutionEffect.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.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 2014 Google Inc. 2 * Copyright 2014 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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrDitherEffect.h" 9 #include "GrDitherEffect.h"
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 ////////////////////////////////////////////////////////////////////////////// 67 //////////////////////////////////////////////////////////////////////////////
68 68
69 class GLDitherEffect : public GrGLFragmentProcessor { 69 class GLDitherEffect : public GrGLFragmentProcessor {
70 public: 70 public:
71 GLDitherEffect(const GrBackendProcessorFactory&, const GrProcessor&); 71 GLDitherEffect(const GrBackendProcessorFactory&, const GrProcessor&);
72 72
73 virtual void emitCode(GrGLFPBuilder* builder, 73 virtual void emitCode(GrGLFPBuilder* builder,
74 const GrFragmentProcessor& fp, 74 const GrFragmentProcessor& fp,
75 const GrProcessorKey& key,
76 const char* outputColor, 75 const char* outputColor,
77 const char* inputColor, 76 const char* inputColor,
78 const TransformedCoordsArray&, 77 const TransformedCoordsArray&,
79 const TextureSamplerArray&) SK_OVERRIDE; 78 const TextureSamplerArray&) SK_OVERRIDE;
80 79
81 private: 80 private:
82 typedef GrGLFragmentProcessor INHERITED; 81 typedef GrGLFragmentProcessor INHERITED;
83 }; 82 };
84 83
85 GLDitherEffect::GLDitherEffect(const GrBackendProcessorFactory& factory, 84 GLDitherEffect::GLDitherEffect(const GrBackendProcessorFactory& factory,
86 const GrProcessor&) 85 const GrProcessor&)
87 : INHERITED (factory) { 86 : INHERITED (factory) {
88 } 87 }
89 88
90 void GLDitherEffect::emitCode(GrGLFPBuilder* builder, 89 void GLDitherEffect::emitCode(GrGLFPBuilder* builder,
91 const GrFragmentProcessor& fp, 90 const GrFragmentProcessor& fp,
92 const GrProcessorKey& key,
93 const char* outputColor, 91 const char* outputColor,
94 const char* inputColor, 92 const char* inputColor,
95 const TransformedCoordsArray&, 93 const TransformedCoordsArray&,
96 const TextureSamplerArray& samplers) { 94 const TextureSamplerArray& samplers) {
97 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 95 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
98 // Generate a random number based on the fragment position. For this 96 // Generate a random number based on the fragment position. For this
99 // random number generator, we use the "GLSL rand" function 97 // random number generator, we use the "GLSL rand" function
100 // that seems to be floating around on the internet. It works under 98 // that seems to be floating around on the internet. It works under
101 // the assumption that sin(<big number>) oscillates with high frequency 99 // the assumption that sin(<big number>) oscillates with high frequency
102 // and sampling it will generate "randomness". Since we're using this 100 // and sampling it will generate "randomness". Since we're using this
103 // for rendering and not cryptography it should be OK. 101 // for rendering and not cryptography it should be OK.
104 102
105 // For each channel c, add the random offset to the pixel to either bump 103 // For each channel c, add the random offset to the pixel to either bump
106 // it up or let it remain constant during quantization. 104 // it up or let it remain constant during quantization.
107 fsBuilder->codeAppendf("\t\tfloat r = " 105 fsBuilder->codeAppendf("\t\tfloat r = "
108 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n", 106 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n",
109 fsBuilder->fragmentPosition()); 107 fsBuilder->fragmentPosition());
110 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", 108 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
111 outputColor, GrGLSLExpr4(inputColor).c_str()); 109 outputColor, GrGLSLExpr4(inputColor).c_str());
112 } 110 }
113 111
114 ////////////////////////////////////////////////////////////////////////////// 112 //////////////////////////////////////////////////////////////////////////////
115 113
116 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); } 114 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvolutionEffect.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698