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

Side by Side Diff: src/core/SkNormalBevelSource.cpp

Issue 2114993002: GrFP can express distance vector field req., program builder declares variable for it (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-bevel-api-change
Patch Set: Fixed GrPaint unintialized bool Created 4 years, 4 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
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/core/SkNormalFlatSource.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkPoint3.h" 12 #include "SkPoint3.h"
12 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h" 14 #include "SkWriteBuffer.h"
14 15
15 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
16 #include "GrInvariantOutput.h" 17 #include "GrInvariantOutput.h"
17 #include "glsl/GrGLSLFragmentProcessor.h" 18 #include "glsl/GrGLSLFragmentProcessor.h"
18 #include "glsl/GrGLSLFragmentShaderBuilder.h" 19 #include "glsl/GrGLSLFragmentShaderBuilder.h"
19 #include "SkGr.h" 20 #include "SkGr.h"
20 21
21 class NormalBevelFP : public GrFragmentProcessor { 22 class NormalBevelFP : public GrFragmentProcessor {
22 public: 23 public:
23 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t) 24 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh t)
24 : fType(type) 25 : fType(type)
25 , fWidth(width) 26 , fWidth(width)
26 , fHeight(height) { 27 , fHeight(height) {
27 this->initClassID<NormalBevelFP>(); 28 this->initClassID<NormalBevelFP>();
29
30 fUsesDistanceVectorField = true;
28 } 31 }
29 32
30 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { 33 class GLSLNormalBevelFP : public GLSLNormalFP {
31 public: 34 public:
32 GLSLNormalBevelFP() { 35 GLSLNormalBevelFP() {
33 fPrevWidth = SkFloatToScalar(0.0f); 36 fPrevWidth = SkFloatToScalar(0.0f);
34 fPrevHeight = SkFloatToScalar(0.0f); 37 fPrevHeight = SkFloatToScalar(0.0f);
35 } 38 }
36 39
37 void emitCode(EmitArgs& args) override { 40 void onEmitCode(EmitArgs& args) override {
38 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 41 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
39 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 42 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
40 43
41 const char* widthUniName = nullptr; 44 const char* widthUniName = nullptr;
42 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloa t_GrSLType, 45 fWidthUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFloa t_GrSLType,
43 kDefault_GrSLPrecision, "Width", &widthUniName); 46 kDefault_GrSLPrecision, "Width", &widthUniName);
44 47
45 const char* heightUniName = nullptr; 48 const char* heightUniName = nullptr;
46 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFlo at_GrSLType, 49 fHeightUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kFlo at_GrSLType,
47 kDefault_GrSLPrecision, "Height", &heightUniName); 50 kDefault_GrSLPrecision, "Height", &heightUniName);
48 51
49 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); 52 fragBuilder->codeAppendf("%s = vec4(0.0, 0.0, 1.0, 0.0);", args.fOut putColor);
50 } 53 }
51 54
52 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 55 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
53 GrProcessorKeyBuilder* b) { 56 GrProcessorKeyBuilder* b) {
54 const NormalBevelFP& fp = proc.cast<NormalBevelFP>(); 57 const NormalBevelFP& fp = proc.cast<NormalBevelFP>();
55 b->add32(static_cast<int>(fp.fType)); 58 b->add32(static_cast<int>(fp.fType));
56 } 59 }
57 60
58 protected: 61 protected:
59 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { 62 void setNormalData(const GrGLSLProgramDataManager& pdman,
63 const GrProcessor& proc) override {
60 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); 64 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>();
61 65
62 if (fPrevWidth != normalBevelFP.fWidth) { 66 if (fPrevWidth != normalBevelFP.fWidth) {
63 pdman.set1f(fWidthUni, normalBevelFP.fWidth); 67 pdman.set1f(fWidthUni, normalBevelFP.fWidth);
64 fPrevWidth = normalBevelFP.fWidth; 68 fPrevWidth = normalBevelFP.fWidth;
65 } 69 }
66 if (fPrevHeight != normalBevelFP.fHeight) { 70 if (fPrevHeight != normalBevelFP.fHeight) {
67 pdman.set1f(fHeightUni, normalBevelFP.fHeight); 71 pdman.set1f(fHeightUni, normalBevelFP.fHeight);
68 fPrevHeight = normalBevelFP.fHeight; 72 fPrevHeight = normalBevelFP.fHeight;
69 } 73 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) { 160 sk_sp<SkNormalSource> SkNormalSource::MakeBevel(BevelType type, SkScalar width, SkScalar height) {
157 /* TODO make sure this checks are tolerant enough to account for loss of con version when GPUs 161 /* TODO make sure this checks are tolerant enough to account for loss of con version when GPUs
158 use 16-bit float types. We don't want to assume stuff is non-zero on the GPU and be wrong.*/ 162 use 16-bit float types. We don't want to assume stuff is non-zero on the GPU and be wrong.*/
159 SkASSERT(width > 0.0f && !SkScalarNearlyZero(width)); 163 SkASSERT(width > 0.0f && !SkScalarNearlyZero(width));
160 if (SkScalarNearlyZero(height)) { 164 if (SkScalarNearlyZero(height)) {
161 return SkNormalSource::MakeFlat(); 165 return SkNormalSource::MakeFlat();
162 } 166 }
163 167
164 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height); 168 return sk_make_sp<SkNormalBevelSourceImpl>(type, width, height);
165 } 169 }
OLDNEW
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/core/SkNormalFlatSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698