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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DCShader); | 31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DCShader); |
32 | 32 |
33 void flatten(SkWriteBuffer& buf) const override { | 33 void flatten(SkWriteBuffer& buf) const override { |
34 buf.writeMatrix(fDeviceMatrix); | 34 buf.writeMatrix(fDeviceMatrix); |
35 } | 35 } |
36 | 36 |
37 const GrFragmentProcessor* asFragmentProcessor(GrContext*, | 37 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
38 const SkMatrix& viewM, | 38 const SkMatrix& viewM, |
39 const SkMatrix* localMatrix, | 39 const SkMatrix* localMatrix, |
40 SkFilterQuality, | 40 SkFilterQuality) const overri
de; |
41 GrProcessorDataManager*) cons
t override; | |
42 | 41 |
43 #ifndef SK_IGNORE_TO_STRING | 42 #ifndef SK_IGNORE_TO_STRING |
44 void toString(SkString* str) const override { | 43 void toString(SkString* str) const override { |
45 str->appendf("DCShader: ()"); | 44 str->appendf("DCShader: ()"); |
46 } | 45 } |
47 #endif | 46 #endif |
48 | 47 |
49 private: | 48 private: |
50 const SkMatrix fDeviceMatrix; | 49 const SkMatrix fDeviceMatrix; |
51 }; | 50 }; |
52 | 51 |
53 SkFlattenable* DCShader::CreateProc(SkReadBuffer& buf) { | 52 SkFlattenable* DCShader::CreateProc(SkReadBuffer& buf) { |
54 SkMatrix matrix; | 53 SkMatrix matrix; |
55 buf.readMatrix(&matrix); | 54 buf.readMatrix(&matrix); |
56 return new DCShader(matrix); | 55 return new DCShader(matrix); |
57 } | 56 } |
58 | 57 |
59 class DCFP : public GrFragmentProcessor { | 58 class DCFP : public GrFragmentProcessor { |
60 public: | 59 public: |
61 DCFP(GrProcessorDataManager*, const SkMatrix& m) : fDeviceTransform(kDevice_
GrCoordSet, m) { | 60 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { |
62 this->addCoordTransform(&fDeviceTransform); | 61 this->addCoordTransform(&fDeviceTransform); |
63 this->initClassID<DCFP>(); | 62 this->initClassID<DCFP>(); |
64 } | 63 } |
65 | 64 |
66 GrGLFragmentProcessor* onCreateGLInstance() const override { | 65 GrGLFragmentProcessor* onCreateGLInstance() const override { |
67 class DCGLFP : public GrGLFragmentProcessor { | 66 class DCGLFP : public GrGLFragmentProcessor { |
68 void emitCode(EmitArgs& args) override { | 67 void emitCode(EmitArgs& args) override { |
69 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuild
er(); | 68 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuild
er(); |
70 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); | 69 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); |
71 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); | 70 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); |
(...skipping 18 matching lines...) Expand all Loading... |
90 | 89 |
91 private: | 90 private: |
92 void onGetGLProcessorKey(const GrGLSLCaps& caps, | 91 void onGetGLProcessorKey(const GrGLSLCaps& caps, |
93 GrProcessorKeyBuilder* b) const override {} | 92 GrProcessorKeyBuilder* b) const override {} |
94 | 93 |
95 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } | 94 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
96 | 95 |
97 GrCoordTransform fDeviceTransform; | 96 GrCoordTransform fDeviceTransform; |
98 }; | 97 }; |
99 | 98 |
100 const GrFragmentProcessor* DCShader::asFragmentProcessor( | 99 const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, |
101 GrContext*, | 100 const SkMatrix& viewM, |
102 const SkMatrix& viewM, | 101 const SkMatrix* localMa
trix, |
103 const SkMatrix* localMatrix, | 102 SkFilterQuality) const
{ |
104 SkFilterQuality, | 103 SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(fDeviceMatrix)); |
105 GrProcessorDataManager* procDat
aManager) const { | |
106 SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(procDataManager, fDev
iceMatrix)); | |
107 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 104 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
108 } | 105 } |
109 | 106 |
110 class DCShaderGM : public GM { | 107 class DCShaderGM : public GM { |
111 public: | 108 public: |
112 DCShaderGM() { | 109 DCShaderGM() { |
113 this->setBGColor(sk_tool_utils::color_to_565(0xFFAABBCC)); | 110 this->setBGColor(sk_tool_utils::color_to_565(0xFFAABBCC)); |
114 } | 111 } |
115 | 112 |
116 ~DCShaderGM() override { | 113 ~DCShaderGM() override { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 }; | 288 }; |
292 | 289 |
293 SkTArray<Prim*> fPrims; | 290 SkTArray<Prim*> fPrims; |
294 | 291 |
295 typedef GM INHERITED; | 292 typedef GM INHERITED; |
296 }; | 293 }; |
297 | 294 |
298 DEF_GM(return new DCShaderGM;) | 295 DEF_GM(return new DCShaderGM;) |
299 } | 296 } |
300 #endif | 297 #endif |
OLD | NEW |