OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkNormalBevelSource.h" | 8 #include "SkNormalBevelSource.h" |
9 | 9 |
10 #include "SkNormalSource.h" | 10 #include "SkNormalSource.h" |
11 #include "SkPoint3.h" | 11 #include "SkPoint3.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 | 14 |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrInvariantOutput.h" | 16 #include "GrInvariantOutput.h" |
17 #include "glsl/GrGLSLFragmentProcessor.h" | 17 #include "glsl/GrGLSLFragmentProcessor.h" |
18 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 18 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
19 #include "SkGr.h" | 19 #include "SkGr.h" |
20 | 20 |
21 class NormalBevelFP : public GrFragmentProcessor { | 21 class NormalBevelFP : public GrFragmentProcessor { |
22 public: | 22 public: |
23 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh
t) | 23 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh
t) |
24 : fType(type) | 24 : fType(type) |
25 , fWidth(width) | 25 , fWidth(width) |
26 , fHeight(height) { | 26 , fHeight(height) { |
27 this->initClassID<NormalBevelFP>(); | 27 this->initClassID<NormalBevelFP>(); |
| 28 |
| 29 fUsesDistanceVectorField = true; |
28 } | 30 } |
29 | 31 |
30 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { | 32 class GLSLNormalBevelFP : public GLSLNormalFP { |
31 public: | 33 public: |
32 GLSLNormalBevelFP() { | 34 GLSLNormalBevelFP() { |
33 fPrevWidth = SkFloatToScalar(0.0f); | 35 fPrevWidth = SkFloatToScalar(0.0f); |
34 fPrevHeight = SkFloatToScalar(0.0f); | 36 fPrevHeight = SkFloatToScalar(0.0f); |
35 } | 37 } |
36 | 38 |
37 void emitCode(EmitArgs& args) override { | 39 void onEmitCode(EmitArgs& args) override { |
38 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 40 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
39 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 41 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
40 | 42 |
41 const char* widthUniName = nullptr; | 43 const char* widthUniName = nullptr; |
42 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloa
t_GrSLType, | 44 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloa
t_GrSLType, |
43 kDefault_GrSLPrecision, "Width", &widthUniName); | 45 kDefault_GrSLPrecision, "Width", &widthUniName); |
44 | 46 |
45 const char* heightUniName = nullptr; | 47 const char* heightUniName = nullptr; |
46 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFlo
at_GrSLType, | 48 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFlo
at_GrSLType, |
47 kDefault_GrSLPrecision, "Height", &heightUniName); | 49 kDefault_GrSLPrecision, "Height", &heightUniName); |
48 | 50 |
49 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor
); | 51 fragBuilder->codeAppendf("%s = vec4(0.0, 0.0, 1.0, 0.0);", args.fOut
putColor); |
50 } | 52 } |
51 | 53 |
52 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 54 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
53 GrProcessorKeyBuilder* b) { | 55 GrProcessorKeyBuilder* b) { |
54 const NormalBevelFP& fp = proc.cast<NormalBevelFP>(); | 56 const NormalBevelFP& fp = proc.cast<NormalBevelFP>(); |
55 b->add32(static_cast<int>(fp.fType)); | 57 b->add32(static_cast<int>(fp.fType)); |
56 } | 58 } |
57 | 59 |
58 protected: | 60 protected: |
59 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { | 61 void setNormalData(const GrGLSLProgramDataManager& pdman, |
| 62 const GrProcessor& proc) override { |
60 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | 63 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); |
61 | 64 |
62 if (fPrevWidth != normalBevelFP.fWidth) { | 65 if (fPrevWidth != normalBevelFP.fWidth) { |
63 pdman.set1f(fWidthUni, normalBevelFP.fWidth); | 66 pdman.set1f(fWidthUni, normalBevelFP.fWidth); |
64 fPrevWidth = normalBevelFP.fWidth; | 67 fPrevWidth = normalBevelFP.fWidth; |
65 } | 68 } |
66 if (fPrevHeight != normalBevelFP.fHeight) { | 69 if (fPrevHeight != normalBevelFP.fHeight) { |
67 pdman.set1f(fHeightUni, normalBevelFP.fHeight); | 70 pdman.set1f(fHeightUni, normalBevelFP.fHeight); |
68 fPrevHeight = normalBevelFP.fHeight; | 71 fPrevHeight = normalBevelFP.fHeight; |
69 } | 72 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width,
SkScalar height) { | 164 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width,
SkScalar height) { |
162 /* TODO make sure this checks are tolerant enough to account for loss of con
version when GPUs | 165 /* TODO make sure this checks are tolerant enough to account for loss of con
version when GPUs |
163 use 16-bit float types. We don't want to assume stuff is non-zero on the
GPU and be wrong.*/ | 166 use 16-bit float types. We don't want to assume stuff is non-zero on the
GPU and be wrong.*/ |
164 SkASSERT(width > 0.0f && !SkScalarNearlyZero(width)); | 167 SkASSERT(width > 0.0f && !SkScalarNearlyZero(width)); |
165 if (SkScalarNearlyZero(height)) { | 168 if (SkScalarNearlyZero(height)) { |
166 return SkNormalSource::MakeFlat(); | 169 return SkNormalSource::MakeFlat(); |
167 } | 170 } |
168 | 171 |
169 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height); | 172 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height); |
170 } | 173 } |
OLD | NEW |