OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 virtual ~DitherEffect() {}; | 24 virtual ~DitherEffect() {}; |
25 | 25 |
26 const char* name() const override { return "Dither"; } | 26 const char* name() const override { return "Dither"; } |
27 | 27 |
28 private: | 28 private: |
29 DitherEffect() { | 29 DitherEffect() { |
30 this->initClassID<DitherEffect>(); | 30 this->initClassID<DitherEffect>(); |
31 this->setWillReadFragmentPosition(); | 31 this->setWillReadFragmentPosition(); |
32 } | 32 } |
33 | 33 |
34 GrGLSLFragmentProcessor* onCreateGLInstance() const override; | 34 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
35 | 35 |
36 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 36 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
37 | 37 |
38 // All dither effects are equal | 38 // All dither effects are equal |
39 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } | 39 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
40 | 40 |
41 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 41 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
42 | 42 |
43 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 43 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
44 | 44 |
45 typedef GrFragmentProcessor INHERITED; | 45 typedef GrFragmentProcessor INHERITED; |
46 }; | 46 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // it up or let it remain constant during quantization. | 85 // it up or let it remain constant during quantization. |
86 fsBuilder->codeAppendf("\t\tfloat r = " | 86 fsBuilder->codeAppendf("\t\tfloat r = " |
87 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758.
5453);\n", | 87 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758.
5453);\n", |
88 fsBuilder->fragmentPosition()); | 88 fsBuilder->fragmentPosition()); |
89 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", | 89 fsBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", |
90 args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_st
r()); | 90 args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_st
r()); |
91 } | 91 } |
92 | 92 |
93 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
94 | 94 |
95 void DitherEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 95 void DitherEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
96 GrProcessorKeyBuilder* b) const { | 96 GrProcessorKeyBuilder* b) const { |
97 GLDitherEffect::GenKey(*this, caps, b); | 97 GLDitherEffect::GenKey(*this, caps, b); |
98 } | 98 } |
99 | 99 |
100 GrGLSLFragmentProcessor* DitherEffect::onCreateGLInstance() const { | 100 GrGLSLFragmentProcessor* DitherEffect::onCreateGLSLInstance() const { |
101 return new GLDitherEffect(*this); | 101 return new GLDitherEffect(*this); |
102 } | 102 } |
103 | 103 |
104 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); } | 104 GrFragmentProcessor* GrDitherEffect::Create() { return DitherEffect::Create(); } |
OLD | NEW |