OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrCustomXfermodePriv_DEFINED | 8 #ifndef GrCustomXfermodePriv_DEFINED |
9 #define GrCustomXfermodePriv_DEFINED | 9 #define GrCustomXfermodePriv_DEFINED |
10 | 10 |
11 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
12 #include "GrDrawTargetCaps.h" | |
13 #include "GrFragmentProcessor.h" | 12 #include "GrFragmentProcessor.h" |
14 #include "GrTextureAccess.h" | 13 #include "GrTextureAccess.h" |
15 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
16 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
17 | 16 |
18 class GrGLCaps; | 17 class GrGLCaps; |
19 class GrGLFragmentProcessor; | 18 class GrGLFragmentProcessor; |
20 class GrInvariantOutput; | 19 class GrInvariantOutput; |
21 class GrProcessorKeyBuilder; | 20 class GrProcessorKeyBuilder; |
22 class GrTexture; | 21 class GrTexture; |
(...skipping 28 matching lines...) Expand all Loading... |
51 | 50 |
52 typedef GrFragmentProcessor INHERITED; | 51 typedef GrFragmentProcessor INHERITED; |
53 }; | 52 }; |
54 | 53 |
55 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
56 // Xfer Processor | 55 // Xfer Processor |
57 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
58 | 57 |
59 class GrCustomXP : public GrXferProcessor { | 58 class GrCustomXP : public GrXferProcessor { |
60 public: | 59 public: |
61 static GrXferProcessor* Create(SkXfermode::Mode mode, const GrDeviceCoordTex
ture* dstCopy, | 60 static GrXferProcessor* Create(SkXfermode::Mode mode) { |
62 bool willReadDstColor) { | |
63 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 61 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
64 return NULL; | 62 return NULL; |
65 } else { | 63 } else { |
66 return SkNEW_ARGS(GrCustomXP, (mode, dstCopy, willReadDstColor)); | 64 return SkNEW_ARGS(GrCustomXP, (mode)); |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 ~GrCustomXP() SK_OVERRIDE {}; | 68 ~GrCustomXP() SK_OVERRIDE {}; |
71 | 69 |
72 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; } | 70 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; } |
73 | 71 |
| 72 void getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const
SK_OVERRIDE; |
| 73 |
74 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; | 74 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE; |
75 | 75 |
76 bool hasSecondaryOutput() const SK_OVERRIDE { return false; } | 76 bool hasSecondaryOutput() const SK_OVERRIDE { return false; } |
77 | 77 |
78 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 78 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
79 const GrProcOptInfo& coveragePOI, | 79 const GrProcOptInfo& coveragePOI, |
80 bool doesStencilWrite, | 80 bool doesStencilWrite, |
81 GrColor* overrideColor, | 81 GrColor* overrideColor, |
82 const GrDrawTargetCaps& caps) SK_
OVERRIDE; | 82 const GrDrawTargetCaps& caps) SK_
OVERRIDE; |
83 | 83 |
84 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { | 84 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE { |
85 blendInfo->fSrcBlend = kOne_GrBlendCoeff; | 85 blendInfo->fSrcBlend = kOne_GrBlendCoeff; |
86 blendInfo->fDstBlend = kZero_GrBlendCoeff; | 86 blendInfo->fDstBlend = kZero_GrBlendCoeff; |
87 blendInfo->fBlendConstant = 0; | 87 blendInfo->fBlendConstant = 0; |
88 } | 88 } |
89 | 89 |
90 SkXfermode::Mode mode() const { return fMode; } | 90 SkXfermode::Mode mode() const { return fMode; } |
91 | 91 |
92 private: | 92 private: |
93 GrCustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool
willReadDstColor); | 93 GrCustomXP(SkXfermode::Mode mode); |
94 | |
95 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st SK_OVERRIDE; | |
96 | 94 |
97 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE; | 95 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE; |
98 | 96 |
99 SkXfermode::Mode fMode; | 97 SkXfermode::Mode fMode; |
100 | 98 |
101 typedef GrXferProcessor INHERITED; | 99 typedef GrXferProcessor INHERITED; |
102 }; | 100 }; |
103 | 101 |
104 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
105 | 103 |
106 class GrCustomXPFactory : public GrXPFactory { | 104 class GrCustomXPFactory : public GrXPFactory { |
107 public: | 105 public: |
108 GrCustomXPFactory(SkXfermode::Mode mode); | 106 GrCustomXPFactory(SkXfermode::Mode mode); |
109 | 107 |
| 108 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
| 109 const GrProcOptInfo& coveragePOI) const
SK_OVERRIDE { |
| 110 return GrCustomXP::Create(fMode); |
| 111 } |
| 112 |
110 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const
SK_OVERRIDE { | 113 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const
SK_OVERRIDE { |
111 return true; | 114 return true; |
112 } | 115 } |
113 | 116 |
114 bool canApplyCoverage(const GrProcOptInfo& colorPOI, | 117 bool canApplyCoverage(const GrProcOptInfo& colorPOI, |
115 const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { | 118 const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { |
116 return true; | 119 return true; |
117 } | 120 } |
118 | 121 |
119 bool canTweakAlphaForCoverage() const SK_OVERRIDE { | 122 bool canTweakAlphaForCoverage() const SK_OVERRIDE { |
120 return false; | 123 return false; |
121 } | 124 } |
122 | 125 |
123 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo&
coveragePOI, | 126 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo&
coveragePOI, |
124 GrXPFactory::InvariantOutput*) const SK_OVERRIDE; | 127 GrXPFactory::InvariantOutput*) const SK_OVERRIDE; |
125 | 128 |
| 129 bool willReadDst() const SK_OVERRIDE { return true; } |
| 130 |
126 private: | 131 private: |
127 GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI, | |
128 const GrProcOptInfo& coveragePOI, | |
129 const GrDeviceCoordTexture* dstCopy)
const SK_OVERRIDE { | |
130 return GrCustomXP::Create(fMode, dstCopy, this->willReadDstColor()); | |
131 } | |
132 | |
133 bool willReadDstColor() const SK_OVERRIDE { return true; } | |
134 | |
135 bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { | 132 bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { |
136 const GrCustomXPFactory& xpf = xpfBase.cast<GrCustomXPFactory>(); | 133 const GrCustomXPFactory& xpf = xpfBase.cast<GrCustomXPFactory>(); |
137 return fMode == xpf.fMode; | 134 return fMode == xpf.fMode; |
138 } | 135 } |
139 | 136 |
140 GR_DECLARE_XP_FACTORY_TEST; | 137 GR_DECLARE_XP_FACTORY_TEST; |
141 | 138 |
142 SkXfermode::Mode fMode; | 139 SkXfermode::Mode fMode; |
143 | 140 |
144 typedef GrXPFactory INHERITED; | 141 typedef GrXPFactory INHERITED; |
145 }; | 142 }; |
146 #endif | 143 #endif |
147 | 144 |
OLD | NEW |