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 #ifndef SkNormalSource_DEFINED | 8 #ifndef SkNormalSource_DEFINED |
9 #define SkNormalSource_DEFINED | 9 #define SkNormalSource_DEFINED |
10 | 10 |
11 #include "SkFlattenable.h" | 11 #include "SkFlattenable.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 class SkMatrix; | 14 class SkMatrix; |
15 class SkPoint3; | 15 class SkPoint3; |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 class GrFragmentProcessor; | 18 #include "glsl/GrGLSLFragmentProcessor.h" |
19 class GrContext; | 19 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
20 enum SkFilterQuality; | |
21 enum SkSourceGammaTreatment; | |
22 #endif | 20 #endif |
23 | 21 |
24 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. | 22 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. |
25 */ | 23 */ |
26 class SK_API SkNormalSource : public SkFlattenable { | 24 class SK_API SkNormalSource : public SkFlattenable { |
27 public: | 25 public: |
28 virtual ~SkNormalSource() override; | 26 virtual ~SkNormalSource() override; |
29 | 27 |
30 #if SK_SUPPORT_GPU | 28 #if SK_SUPPORT_GPU |
31 /** Returns a fragment processor that takes no input and outputs a normal (a
lready rotated) | 29 /** Returns a fragment processor that takes no input and outputs a normal (a
lready rotated) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 * This bevel follows the only quadratic bezier curve whose start point
is at (w, 0, 0) and | 113 * This bevel follows the only quadratic bezier curve whose start point
is at (w, 0, 0) and |
116 * has a perpendicular normal vector of <0,0,1>, and whose end point is
at (0, 0, h) and has | 114 * has a perpendicular normal vector of <0,0,1>, and whose end point is
at (0, 0, h) and has |
117 * a perpendicular normal vector of <1,0,0>. | 115 * a perpendicular normal vector of <1,0,0>. |
118 */ | 116 */ |
119 kRoundedIn | 117 kRoundedIn |
120 }; | 118 }; |
121 /** Returns a normal source that generates a bevel for the given shape. UNIM
PLEMENTED: Will | 119 /** Returns a normal source that generates a bevel for the given shape. UNIM
PLEMENTED: Will |
122 return straight-up normals only. | 120 return straight-up normals only. |
123 | 121 |
124 @param type the type of bevel to add | 122 @param type the type of bevel to add |
125 @param width the width of the bevel, in source space. Must be positive
. | 123 @param width the width of the bevel, in source space |
126 @param height the height of the plateau, in source space. Can be positi
ve, negative, | 124 @param height the height of the plateau, in source space |
127 or zero. A negative height means the simulated bevels slo
pe downwards. | |
128 */ | 125 */ |
129 static sk_sp<SkNormalSource> MakeBevel(BevelType, SkScalar width, SkScalar h
eight); | 126 static sk_sp<SkNormalSource> MakeBevel(BevelType, SkScalar width, SkScalar h
eight); |
130 | 127 |
131 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) | 128 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) |
132 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 129 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
133 }; | 130 }; |
134 | 131 |
| 132 #if SK_SUPPORT_GPU |
| 133 /* GLSLFragmentProcessors for NormalSourceImpls must sub-class this class and ov
erride onEmitCode, |
| 134 * and setNormalData calls, as well as all other calls FPs normally override, ex
cept for the 2 |
| 135 * defined in this superclass. |
| 136 * This class exists to intercept emitCode calls and emit <0, 0, 1> if the FP re
quires a distance |
| 137 * vector but the GP doesn't provide it. onSetData calls need to be intercepted
too because |
| 138 * uniform handlers will be invalid in subclasses where onEmitCode isn't called. |
| 139 * We don't need to adjust the key here since the use of a given GP (through its
class ID already in |
| 140 * the key), will determine what code gets emitted here. |
| 141 */ |
| 142 class GLSLNormalFP : public GrGLSLFragmentProcessor { |
| 143 public: |
| 144 GLSLNormalFP() |
| 145 : fDidIntercept(false) {} |
| 146 |
| 147 void emitCode(EmitArgs& args) final override { |
| 148 if (args.fFp.usesDistanceVectorField() && !args.fGpImplementsDistanceVec
tor) { |
| 149 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 150 fragBuilder->codeAppendf("// GLSLNormalFP intercepted emitCode call,
GP does not " |
| 151 "implement required distance vector
feature\n"); |
| 152 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor
); |
| 153 |
| 154 fDidIntercept = true; |
| 155 } else { |
| 156 this->onEmitCode(args); |
| 157 } |
| 158 } |
| 159 |
| 160 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
c) final override { |
| 161 if (!fDidIntercept) { |
| 162 this->setNormalData(pdman, proc); |
| 163 } |
| 164 } |
| 165 |
| 166 protected: |
| 167 virtual void onEmitCode(EmitArgs& args) = 0; |
| 168 virtual void setNormalData(const GrGLSLProgramDataManager& pdman, const GrPr
ocessor& proc) = 0; |
| 169 |
| 170 private: |
| 171 bool fDidIntercept; |
| 172 }; |
135 #endif | 173 #endif |
| 174 |
| 175 #endif |
OLD | NEW |