| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "gm.h" | 9 #include "gm.h" |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return new DCShader(matrix); | 57 return new DCShader(matrix); |
| 58 } | 58 } |
| 59 | 59 |
| 60 class DCFP : public GrFragmentProcessor { | 60 class DCFP : public GrFragmentProcessor { |
| 61 public: | 61 public: |
| 62 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { | 62 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { |
| 63 this->addCoordTransform(&fDeviceTransform); | 63 this->addCoordTransform(&fDeviceTransform); |
| 64 this->initClassID<DCFP>(); | 64 this->initClassID<DCFP>(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 GrGLSLFragmentProcessor* onCreateGLInstance() const override { | 67 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 68 class DCGLFP : public GrGLSLFragmentProcessor { | 68 class DCGLFP : public GrGLSLFragmentProcessor { |
| 69 void emitCode(EmitArgs& args) override { | 69 void emitCode(EmitArgs& args) override { |
| 70 GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBui
lder(); | 70 GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBui
lder(); |
| 71 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); | 71 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); |
| 72 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); | 72 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); |
| 73 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," | 73 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," |
| 74 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," | 74 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," |
| 75 "(r.x + r.y) / 20.0," | 75 "(r.x + r.y) / 20.0," |
| 76 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); | 76 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); |
| 77 fpb->codeAppendf("color.rgb *= color.a;" | 77 fpb->codeAppendf("color.rgb *= color.a;" |
| 78 "%s = color * %s;", | 78 "%s = color * %s;", |
| 79 args.fOutputColor, GrGLSLExpr4(args.fInputCo
lor).c_str()); | 79 args.fOutputColor, GrGLSLExpr4(args.fInputCo
lor).c_str()); |
| 80 } | 80 } |
| 81 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&)
override {} | 81 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&)
override {} |
| 82 }; | 82 }; |
| 83 return new DCGLFP; | 83 return new DCGLFP; |
| 84 } | 84 } |
| 85 | 85 |
| 86 const char* name() const override { return "DCFP"; } | 86 const char* name() const override { return "DCFP"; } |
| 87 | 87 |
| 88 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 88 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 89 inout->mulByUnknownFourComponents(); | 89 inout->mulByUnknownFourComponents(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 void onGetGLProcessorKey(const GrGLSLCaps& caps, | 93 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 94 GrProcessorKeyBuilder* b) const override {} | 94 GrProcessorKeyBuilder* b) const override {} |
| 95 | 95 |
| 96 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } | 96 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 97 | 97 |
| 98 GrCoordTransform fDeviceTransform; | 98 GrCoordTransform fDeviceTransform; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, | 101 const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, |
| 102 const SkMatrix& viewM, | 102 const SkMatrix& viewM, |
| 103 const SkMatrix* localMa
trix, | 103 const SkMatrix* localMa
trix, |
| 104 SkFilterQuality) const
{ | 104 SkFilterQuality) const
{ |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 SkTArray<Prim*> fPrims; | 292 SkTArray<Prim*> fPrims; |
| 293 | 293 |
| 294 typedef GM INHERITED; | 294 typedef GM INHERITED; |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 DEF_GM(return new DCShaderGM;) | 297 DEF_GM(return new DCShaderGM;) |
| 298 } | 298 } |
| 299 #endif | 299 #endif |
| OLD | NEW |