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