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

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

Issue 648463003: FPs now use the correct builder types(just a rename) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months 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 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 GrTexture*[]) { 64 GrTexture*[]) {
65 return DitherEffect::Create(); 65 return DitherEffect::Create();
66 } 66 }
67 67
68 ////////////////////////////////////////////////////////////////////////////// 68 //////////////////////////////////////////////////////////////////////////////
69 69
70 class GLDitherEffect : public GrGLFragmentProcessor { 70 class GLDitherEffect : public GrGLFragmentProcessor {
71 public: 71 public:
72 GLDitherEffect(const GrBackendProcessorFactory&, const GrProcessor&); 72 GLDitherEffect(const GrBackendProcessorFactory&, const GrProcessor&);
73 73
74 virtual void emitCode(GrGLProgramBuilder* builder, 74 virtual void emitCode(GrGLFPBuilder* builder,
75 const GrFragmentProcessor& fp, 75 const GrFragmentProcessor& fp,
76 const GrProcessorKey& key, 76 const GrProcessorKey& key,
77 const char* outputColor, 77 const char* outputColor,
78 const char* inputColor, 78 const char* inputColor,
79 const TransformedCoordsArray&, 79 const TransformedCoordsArray&,
80 const TextureSamplerArray&) SK_OVERRIDE; 80 const TextureSamplerArray&) SK_OVERRIDE;
81 81
82 private: 82 private:
83 typedef GrGLFragmentProcessor INHERITED; 83 typedef GrGLFragmentProcessor INHERITED;
84 }; 84 };
85 85
86 GLDitherEffect::GLDitherEffect(const GrBackendProcessorFactory& factory, 86 GLDitherEffect::GLDitherEffect(const GrBackendProcessorFactory& factory,
87 const GrProcessor&) 87 const GrProcessor&)
88 : INHERITED (factory) { 88 : INHERITED (factory) {
89 } 89 }
90 90
91 void GLDitherEffect::emitCode(GrGLProgramBuilder* builder, 91 void GLDitherEffect::emitCode(GrGLFPBuilder* builder,
92 const GrFragmentProcessor& fp, 92 const GrFragmentProcessor& fp,
93 const GrProcessorKey& key, 93 const GrProcessorKey& key,
94 const char* outputColor, 94 const char* outputColor,
95 const char* inputColor, 95 const char* inputColor,
96 const TransformedCoordsArray&, 96 const TransformedCoordsArray&,
97 const TextureSamplerArray& samplers) { 97 const TextureSamplerArray& samplers) {
98 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 98 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
99 // Generate a random number based on the fragment position. For this 99 // Generate a random number based on the fragment position. For this
100 // random number generator, we use the "GLSL rand" function 100 // random number generator, we use the "GLSL rand" function
101 // that seems to be floating around on the internet. It works under 101 // that seems to be floating around on the internet. It works under
102 // the assumption that sin(<big number>) oscillates with high frequency 102 // the assumption that sin(<big number>) oscillates with high frequency
103 // and sampling it will generate "randomness". Since we're using this 103 // and sampling it will generate "randomness". Since we're using this
104 // for rendering and not cryptography it should be OK. 104 // for rendering and not cryptography it should be OK.
105 105
106 // For each channel c, add the random offset to the pixel to either bump 106 // For each channel c, add the random offset to the pixel to either bump
107 // it up or let it remain constant during quantization. 107 // it up or let it remain constant during quantization.
108 fsBuilder->codeAppendf("\t\tfloat r = " 108 fsBuilder->codeAppendf("\t\tfloat r = "
109 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n", 109 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n",
110 fsBuilder->fragmentPosition()); 110 fsBuilder->fragmentPosition());
111 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", 111 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
112 outputColor, GrGLSLExpr4(inputColor).c_str()); 112 outputColor, GrGLSLExpr4(inputColor).c_str());
113 } 113 }
114 114
115 ////////////////////////////////////////////////////////////////////////////// 115 //////////////////////////////////////////////////////////////////////////////
116 116
117 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); } 117 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