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

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

Issue 1709153002: Add more specialized fragment builders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make MSVC happy Created 4 years, 10 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 "GrDitherEffect.h" 8 #include "GrDitherEffect.h"
9 #include "GrFragmentProcessor.h" 9 #include "GrFragmentProcessor.h"
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 class GLDitherEffect : public GrGLSLFragmentProcessor { 61 class GLDitherEffect : public GrGLSLFragmentProcessor {
62 public: 62 public:
63 void emitCode(EmitArgs& args) override; 63 void emitCode(EmitArgs& args) override;
64 64
65 private: 65 private:
66 typedef GrGLSLFragmentProcessor INHERITED; 66 typedef GrGLSLFragmentProcessor INHERITED;
67 }; 67 };
68 68
69 void GLDitherEffect::emitCode(EmitArgs& args) { 69 void GLDitherEffect::emitCode(EmitArgs& args) {
70 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
71 // Generate a random number based on the fragment position. For this 71 // Generate a random number based on the fragment position. For this
72 // random number generator, we use the "GLSL rand" function 72 // random number generator, we use the "GLSL rand" function
73 // that seems to be floating around on the internet. It works under 73 // that seems to be floating around on the internet. It works under
74 // the assumption that sin(<big number>) oscillates with high frequency 74 // the assumption that sin(<big number>) oscillates with high frequency
75 // and sampling it will generate "randomness". Since we're using this 75 // and sampling it will generate "randomness". Since we're using this
76 // for rendering and not cryptography it should be OK. 76 // for rendering and not cryptography it should be OK.
77 77
78 // For each channel c, add the random offset to the pixel to either bump 78 // For each channel c, add the random offset to the pixel to either bump
79 // it up or let it remain constant during quantization. 79 // it up or let it remain constant during quantization.
80 fragBuilder->codeAppendf("\t\tfloat r = " 80 fragBuilder->codeAppendf("\t\tfloat r = "
81 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 4375 8.5453);\n", 81 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 4375 8.5453);\n",
82 fragBuilder->fragmentPosition()); 82 fragBuilder->fragmentPosition());
83 fragBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", 83 fragBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
84 args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_ str()); 84 args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_ str());
85 } 85 }
86 86
87 ////////////////////////////////////////////////////////////////////////////// 87 //////////////////////////////////////////////////////////////////////////////
88 88
89 void DitherEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 89 void DitherEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
90 GrProcessorKeyBuilder* b) const { 90 GrProcessorKeyBuilder* b) const {
91 GLDitherEffect::GenKey(*this, caps, b); 91 GLDitherEffect::GenKey(*this, caps, b);
92 } 92 }
93 93
94 GrGLSLFragmentProcessor* DitherEffect::onCreateGLSLInstance() const { 94 GrGLSLFragmentProcessor* DitherEffect::onCreateGLSLInstance() const {
95 return new GLDitherEffect; 95 return new GLDitherEffect;
96 } 96 }
97 97
98 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); } 98 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDistanceFieldGeoProc.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698