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" |
12 #include "GrFragmentProcessor.h" | 13 #include "GrFragmentProcessor.h" |
13 #include "GrTextureAccess.h" | 14 #include "GrTextureAccess.h" |
14 #include "GrXferProcessor.h" | 15 #include "GrXferProcessor.h" |
15 #include "SkXfermode.h" | 16 #include "SkXfermode.h" |
16 | 17 |
17 class GrGLCaps; | 18 class GrGLCaps; |
18 class GrGLFragmentProcessor; | 19 class GrGLFragmentProcessor; |
19 class GrInvariantOutput; | 20 class GrInvariantOutput; |
20 class GrProcessorKeyBuilder; | 21 class GrProcessorKeyBuilder; |
21 class GrTexture; | 22 class GrTexture; |
(...skipping 28 matching lines...) Expand all Loading... |
50 | 51 |
51 typedef GrFragmentProcessor INHERITED; | 52 typedef GrFragmentProcessor INHERITED; |
52 }; | 53 }; |
53 | 54 |
54 /////////////////////////////////////////////////////////////////////////////// | 55 /////////////////////////////////////////////////////////////////////////////// |
55 // Xfer Processor | 56 // Xfer Processor |
56 /////////////////////////////////////////////////////////////////////////////// | 57 /////////////////////////////////////////////////////////////////////////////// |
57 | 58 |
58 class GrCustomXP : public GrXferProcessor { | 59 class GrCustomXP : public GrXferProcessor { |
59 public: | 60 public: |
60 static GrXferProcessor* Create(SkXfermode::Mode mode) { | 61 static GrXferProcessor* Create(SkXfermode::Mode mode, const GrDeviceCoordTex
ture* dstCopy, |
| 62 bool willReadDstColor) { |
61 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 63 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
62 return NULL; | 64 return NULL; |
63 } else { | 65 } else { |
64 return SkNEW_ARGS(GrCustomXP, (mode)); | 66 return SkNEW_ARGS(GrCustomXP, (mode, dstCopy, willReadDstColor)); |
65 } | 67 } |
66 } | 68 } |
67 | 69 |
68 ~GrCustomXP() SK_OVERRIDE {}; | 70 ~GrCustomXP() SK_OVERRIDE {}; |
69 | 71 |
70 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; } | 72 const char* name() const SK_OVERRIDE { return "Custom Xfermode"; } |
71 | 73 |
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); | 93 GrCustomXP(SkXfermode::Mode mode, const GrDeviceCoordTexture* dstCopy, bool
willReadDstColor); |
| 94 |
| 95 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st SK_OVERRIDE; |
94 | 96 |
95 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE; | 97 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE; |
96 | 98 |
97 SkXfermode::Mode fMode; | 99 SkXfermode::Mode fMode; |
98 | 100 |
99 typedef GrXferProcessor INHERITED; | 101 typedef GrXferProcessor INHERITED; |
100 }; | 102 }; |
101 | 103 |
102 /////////////////////////////////////////////////////////////////////////////// | 104 /////////////////////////////////////////////////////////////////////////////// |
103 | 105 |
104 class GrCustomXPFactory : public GrXPFactory { | 106 class GrCustomXPFactory : public GrXPFactory { |
105 public: | 107 public: |
106 GrCustomXPFactory(SkXfermode::Mode mode); | 108 GrCustomXPFactory(SkXfermode::Mode mode); |
107 | 109 |
108 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, | |
109 const GrProcOptInfo& coveragePOI) const
SK_OVERRIDE { | |
110 return GrCustomXP::Create(fMode); | |
111 } | |
112 | |
113 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const
SK_OVERRIDE { | 110 bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const
SK_OVERRIDE { |
114 return true; | 111 return true; |
115 } | 112 } |
116 | 113 |
117 bool canApplyCoverage(const GrProcOptInfo& colorPOI, | 114 bool canApplyCoverage(const GrProcOptInfo& colorPOI, |
118 const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { | 115 const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { |
119 return true; | 116 return true; |
120 } | 117 } |
121 | 118 |
122 bool canTweakAlphaForCoverage() const SK_OVERRIDE { | 119 bool canTweakAlphaForCoverage() const SK_OVERRIDE { |
123 return false; | 120 return false; |
124 } | 121 } |
125 | 122 |
126 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo&
coveragePOI, | 123 void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo&
coveragePOI, |
127 GrXPFactory::InvariantOutput*) const SK_OVERRIDE; | 124 GrXPFactory::InvariantOutput*) const SK_OVERRIDE; |
128 | 125 |
129 bool willReadDst() const SK_OVERRIDE { return true; } | 126 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 } |
130 | 132 |
131 private: | 133 bool willReadDstColor() const SK_OVERRIDE { return true; } |
| 134 |
132 bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { | 135 bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { |
133 const GrCustomXPFactory& xpf = xpfBase.cast<GrCustomXPFactory>(); | 136 const GrCustomXPFactory& xpf = xpfBase.cast<GrCustomXPFactory>(); |
134 return fMode == xpf.fMode; | 137 return fMode == xpf.fMode; |
135 } | 138 } |
136 | 139 |
137 GR_DECLARE_XP_FACTORY_TEST; | 140 GR_DECLARE_XP_FACTORY_TEST; |
138 | 141 |
139 SkXfermode::Mode fMode; | 142 SkXfermode::Mode fMode; |
140 | 143 |
141 typedef GrXPFactory INHERITED; | 144 typedef GrXPFactory INHERITED; |
142 }; | 145 }; |
143 #endif | 146 #endif |
144 | 147 |
OLD | NEW |