OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrPorterDuffXferProcessor_DEFINED | 8 #ifndef GrPorterDuffXferProcessor_DEFINED |
9 #define GrPorterDuffXferProcessor_DEFINED | 9 #define GrPorterDuffXferProcessor_DEFINED |
10 | 10 |
11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
12 #include "GrXferProcessor.h" | 12 #include "GrXferProcessor.h" |
13 #include "SkXfermode.h" | 13 #include "SkXfermode.h" |
14 | 14 |
15 class GrDrawTargetCaps; | |
16 class GrProcOptInfo; | 15 class GrProcOptInfo; |
17 | 16 |
18 class GrPorterDuffXferProcessor : public GrXferProcessor { | |
19 public: | |
20 static GrXferProcessor* Create(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, | |
21 GrColor constant, const GrDeviceCoordTexture*
dstCopy, | |
22 bool willReadDstColor) { | |
23 return SkNEW_ARGS(GrPorterDuffXferProcessor, (srcBlend, dstBlend, consta
nt, dstCopy, | |
24 willReadDstColor)); | |
25 } | |
26 | |
27 ~GrPorterDuffXferProcessor() SK_OVERRIDE; | |
28 | |
29 const char* name() const SK_OVERRIDE { return "Porter Duff"; } | |
30 | |
31 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; | |
32 | |
33 bool hasSecondaryOutput() const SK_OVERRIDE; | |
34 | |
35 /////////////////////////////////////////////////////////////////////////// | |
36 /// @name Stage Output Types | |
37 //// | |
38 | |
39 enum PrimaryOutputType { | |
40 kNone_PrimaryOutputType, | |
41 kColor_PrimaryOutputType, | |
42 kCoverage_PrimaryOutputType, | |
43 // Modulate color and coverage, write result as the color output. | |
44 kModulate_PrimaryOutputType, | |
45 }; | |
46 | |
47 enum SecondaryOutputType { | |
48 // There is no secondary output | |
49 kNone_SecondaryOutputType, | |
50 // Writes coverage as the secondary output. Only set if dual source blen
ding is supported | |
51 // and primary output is kModulate. | |
52 kCoverage_SecondaryOutputType, | |
53 // Writes coverage * (1 - colorA) as the secondary output. Only set if d
ual source blending | |
54 // is supported and primary output is kModulate. | |
55 kCoverageISA_SecondaryOutputType, | |
56 // Writes coverage * (1 - colorRGBA) as the secondary output. Only set i
f dual source | |
57 // blending is supported and primary output is kModulate. | |
58 kCoverageISC_SecondaryOutputType, | |
59 | |
60 kSecondaryOutputTypeCnt, | |
61 }; | |
62 | |
63 PrimaryOutputType primaryOutputType() const { return fPrimaryOutputType; } | |
64 SecondaryOutputType secondaryOutputType() const { return fSecondaryOutputTyp
e; } | |
65 | |
66 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | |
67 const GrProcOptInfo& coveragePOI, | |
68 bool doesStencilWrite, | |
69 GrColor* overrideColor, | |
70 const GrDrawTargetCaps& caps) SK_
OVERRIDE; | |
71 | |
72 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { | |
73 blendInfo->fSrcBlend = fSrcBlend; | |
74 blendInfo->fDstBlend = fDstBlend; | |
75 blendInfo->fBlendConstant = fBlendConstant; | |
76 } | |
77 | |
78 private: | |
79 GrPorterDuffXferProcessor(GrBlendCoeff srcBlend, GrBlendCoeff dstBlend, GrCo
lor constant, | |
80 const GrDeviceCoordTexture* dstCopy, bool willRead
DstColor); | |
81 | |
82 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st SK_OVERRIDE; | |
83 | |
84 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE { | |
85 const GrPorterDuffXferProcessor& xp = xpBase.cast<GrPorterDuffXferProces
sor>(); | |
86 if (fSrcBlend != xp.fSrcBlend || | |
87 fDstBlend != xp.fDstBlend || | |
88 fBlendConstant != xp.fBlendConstant || | |
89 fPrimaryOutputType != xp.fPrimaryOutputType || | |
90 fSecondaryOutputType != xp.fSecondaryOutputType) { | |
91 return false; | |
92 } | |
93 return true; | |
94 } | |
95 | |
96 GrXferProcessor::OptFlags internalGetOptimizations(const GrProcOptInfo& colo
rPOI, | |
97 const GrProcOptInfo& cove
ragePOI, | |
98 bool doesStencilWrite); | |
99 | |
100 void calcOutputTypes(GrXferProcessor::OptFlags blendOpts, const GrDrawTarget
Caps& caps, | |
101 bool hasSolidCoverage); | |
102 | |
103 GrBlendCoeff fSrcBlend; | |
104 GrBlendCoeff fDstBlend; | |
105 GrColor fBlendConstant; | |
106 PrimaryOutputType fPrimaryOutputType; | |
107 SecondaryOutputType fSecondaryOutputType; | |
108 | |
109 typedef GrXferProcessor INHERITED; | |
110 }; | |
111 | |
112 /////////////////////////////////////////////////////////////////////////////// | |
113 | |
114 class GrPorterDuffXPFactory : public GrXPFactory { | 17 class GrPorterDuffXPFactory : public GrXPFactory { |
115 public: | 18 public: |
116 static GrXPFactory* Create(SkXfermode::Mode mode); | 19 static GrXPFactory* Create(SkXfermode::Mode mode); |
117 | 20 |
118 static GrXPFactory* Create(SkXfermode::Coeff src, SkXfermode::Coeff dst) { | 21 static GrXPFactory* Create(SkXfermode::Coeff src, SkXfermode::Coeff dst) { |
119 return SkNEW_ARGS(GrPorterDuffXPFactory, ((GrBlendCoeff)(src), (GrBlendC
oeff)(dst))); | 22 return SkNEW_ARGS(GrPorterDuffXPFactory, ((GrBlendCoeff)(src), (GrBlendC
oeff)(dst))); |
120 } | 23 } |
121 | 24 |
122 static GrXPFactory* Create(GrBlendCoeff src, GrBlendCoeff dst) { | 25 static GrXPFactory* Create(GrBlendCoeff src, GrBlendCoeff dst) { |
123 return SkNEW_ARGS(GrPorterDuffXPFactory, (src, dst)); | 26 return SkNEW_ARGS(GrPorterDuffXPFactory, (src, dst)); |
(...skipping 25 matching lines...) Expand all Loading... |
149 | 52 |
150 GR_DECLARE_XP_FACTORY_TEST; | 53 GR_DECLARE_XP_FACTORY_TEST; |
151 | 54 |
152 GrBlendCoeff fSrcCoeff; | 55 GrBlendCoeff fSrcCoeff; |
153 GrBlendCoeff fDstCoeff; | 56 GrBlendCoeff fDstCoeff; |
154 | 57 |
155 typedef GrXPFactory INHERITED; | 58 typedef GrXPFactory INHERITED; |
156 }; | 59 }; |
157 | 60 |
158 #endif | 61 #endif |
OLD | NEW |