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 571163002: removing GrDrawEffect (Closed) Base URL: https://skia.googlesource.com/skia.git@gp3
Patch Set: rebase after revert Created 6 years, 3 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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 GrContext*, 61 GrContext*,
62 const GrDrawTargetCaps&, 62 const GrDrawTargetCaps&,
63 GrTexture*[]) { 63 GrTexture*[]) {
64 return DitherEffect::Create(); 64 return DitherEffect::Create();
65 } 65 }
66 66
67 ////////////////////////////////////////////////////////////////////////////// 67 //////////////////////////////////////////////////////////////////////////////
68 68
69 class GLDitherEffect : public GrGLEffect { 69 class GLDitherEffect : public GrGLEffect {
70 public: 70 public:
71 GLDitherEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 71 GLDitherEffect(const GrBackendEffectFactory&, const GrEffect&);
72 72
73 virtual void emitCode(GrGLProgramBuilder* builder, 73 virtual void emitCode(GrGLProgramBuilder* builder,
74 const GrDrawEffect& drawEffect, 74 const GrEffect& effect,
75 const GrEffectKey& key, 75 const GrEffectKey& key,
76 const char* outputColor, 76 const char* outputColor,
77 const char* inputColor, 77 const char* inputColor,
78 const TransformedCoordsArray&, 78 const TransformedCoordsArray&,
79 const TextureSamplerArray&) SK_OVERRIDE; 79 const TextureSamplerArray&) SK_OVERRIDE;
80 80
81 private: 81 private:
82 typedef GrGLEffect INHERITED; 82 typedef GrGLEffect INHERITED;
83 }; 83 };
84 84
85 GLDitherEffect::GLDitherEffect(const GrBackendEffectFactory& factory, 85 GLDitherEffect::GLDitherEffect(const GrBackendEffectFactory& factory,
86 const GrDrawEffect& drawEffect) 86 const GrEffect& effect)
87 : INHERITED (factory) { 87 : INHERITED (factory) {
88 } 88 }
89 89
90 void GLDitherEffect::emitCode(GrGLProgramBuilder* builder, 90 void GLDitherEffect::emitCode(GrGLProgramBuilder* builder,
91 const GrDrawEffect& drawEffect, 91 const GrEffect& effect,
92 const GrEffectKey& key, 92 const GrEffectKey& key,
93 const char* outputColor, 93 const char* outputColor,
94 const char* inputColor, 94 const char* inputColor,
95 const TransformedCoordsArray&, 95 const TransformedCoordsArray&,
96 const TextureSamplerArray& samplers) { 96 const TextureSamplerArray& samplers) {
97 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 97 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
98 // Generate a random number based on the fragment position. For this 98 // Generate a random number based on the fragment position. For this
99 // random number generator, we use the "GLSL rand" function 99 // random number generator, we use the "GLSL rand" function
100 // that seems to be floating around on the internet. It works under 100 // that seems to be floating around on the internet. It works under
101 // the assumption that sin(<big number>) oscillates with high frequency 101 // the assumption that sin(<big number>) oscillates with high frequency
102 // and sampling it will generate "randomness". Since we're using this 102 // and sampling it will generate "randomness". Since we're using this
103 // for rendering and not cryptography it should be OK. 103 // for rendering and not cryptography it should be OK.
104 104
105 // For each channel c, add the random offset to the pixel to either bump 105 // For each channel c, add the random offset to the pixel to either bump
106 // it up or let it remain constant during quantization. 106 // it up or let it remain constant during quantization.
107 fsBuilder->codeAppendf("\t\tfloat r = " 107 fsBuilder->codeAppendf("\t\tfloat r = "
108 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n", 108 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758. 5453);\n",
109 fsBuilder->fragmentPosition()); 109 fsBuilder->fragmentPosition());
110 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", 110 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
111 outputColor, GrGLSLExpr4(inputColor).c_str()); 111 outputColor, GrGLSLExpr4(inputColor).c_str());
112 } 112 }
113 113
114 ////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////
115 115
116 GrEffect* GrDitherEffect::Create() { return DitherEffect::Create(); } 116 GrEffect* GrDitherEffect::Create() { return DitherEffect::Create(); }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698