Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: src/gpu/effects/GrCustomXfermode.cpp

Issue 1471293003: Create a static instances of SrcOver XferProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "effects/GrCustomXfermode.h" 8 #include "effects/GrCustomXfermode.h"
9 9
10 #include "GrCoordTransform.h" 10 #include "GrCoordTransform.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 GrBlendEquation hwBlendEquation() const { 96 GrBlendEquation hwBlendEquation() const {
97 SkASSERT(this->hasHWBlendEquation()); 97 SkASSERT(this->hasHWBlendEquation());
98 return fHWBlendEquation; 98 return fHWBlendEquation;
99 } 99 }
100 100
101 private: 101 private:
102 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, 102 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI,
103 const GrProcOptInfo& coveragePO I, 103 const GrProcOptInfo& coveragePO I,
104 bool doesStencilWrite, 104 bool doesStencilWrite,
105 GrColor* overrideColor, 105 GrColor* overrideColor,
106 const GrCaps& caps) override; 106 const GrCaps& caps) const overr ide;
107 107
108 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; 108 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
109 109
110 GrXferBarrierType onXferBarrier(const GrRenderTarget*, const GrCaps&) const override; 110 GrXferBarrierType onXferBarrier(const GrRenderTarget*, const GrCaps&) const override;
111 111
112 void onGetBlendInfo(BlendInfo*) const override; 112 void onGetBlendInfo(BlendInfo*) const override;
113 113
114 bool onIsEqual(const GrXferProcessor& xpBase) const override; 114 bool onIsEqual(const GrXferProcessor& xpBase) const override;
115 115
116 const SkXfermode::Mode fMode; 116 const SkXfermode::Mode fMode;
117 const GrBlendEquation fHWBlendEquation; 117 const GrBlendEquation fHWBlendEquation;
118 118
119 typedef GrXferProcessor INHERITED; 119 typedef GrXferProcessor INHERITED;
120 }; 120 };
121 121
122 /////////////////////////////////////////////////////////////////////////////// 122 ///////////////////////////////////////////////////////////////////////////////
123 123
124 class GLCustomXP : public GrGLSLXferProcessor { 124 class GLCustomXP : public GrGLSLXferProcessor {
125 public: 125 public:
126 GLCustomXP(const GrXferProcessor&) {} 126 GLCustomXP(const GrXferProcessor&) {}
127 ~GLCustomXP() override {} 127 ~GLCustomXP() override {}
128 128
129 static void GenKey(const GrXferProcessor& p, const GrGLSLCaps& caps, GrProce ssorKeyBuilder* b) { 129 static void GenKey(const GrXferProcessor& p, const GrGLSLCaps& caps, GrProce ssorKeyBuilder* b) {
130 const CustomXP& xp = p.cast<CustomXP>(); 130 const CustomXP& xp = p.cast<CustomXP>();
131 uint32_t key = 0; 131 uint32_t key = 0;
132 if (xp.hasHWBlendEquation()) { 132 if (xp.hasHWBlendEquation()) {
133 SkASSERT(caps.advBlendEqInteraction() > 0); // 0 will mean !xp.hasH WBlendEquation(). 133 SkASSERT(caps.advBlendEqInteraction() > 0); // 0 will mean !xp.hasH WBlendEquation().
134 key |= caps.advBlendEqInteraction(); 134 key |= caps.advBlendEqInteraction();
135 key |= xp.readsCoverage() << 2;
136 GR_STATIC_ASSERT(GrGLSLCaps::kLast_AdvBlendEqInteraction < 4); 135 GR_STATIC_ASSERT(GrGLSLCaps::kLast_AdvBlendEqInteraction < 4);
137 } 136 }
138 if (!xp.hasHWBlendEquation() || caps.mustEnableSpecificAdvBlendEqs()) { 137 if (!xp.hasHWBlendEquation() || caps.mustEnableSpecificAdvBlendEqs()) {
139 key |= xp.mode() << 3; 138 key |= xp.mode() << 3;
140 } 139 }
141 b->add32(key); 140 b->add32(key);
142 } 141 }
143 142
144 private: 143 private:
145 void emitOutputsForBlendState(const EmitArgs& args) override { 144 void emitOutputsForBlendState(const EmitArgs& args) override {
146 const CustomXP& xp = args.fXP.cast<CustomXP>(); 145 const CustomXP& xp = args.fXP.cast<CustomXP>();
147 SkASSERT(xp.hasHWBlendEquation()); 146 SkASSERT(xp.hasHWBlendEquation());
148 147
149 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; 148 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
150 fragBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()); 149 fragBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation());
151 150
152 // Apply coverage by multiplying it into the src color before blending. Mixed samples will 151 // Apply coverage by multiplying it into the src color before blending. Mixed samples will
153 // "just work" automatically. (See onGetOptimizations()) 152 // "just work" automatically. (See onGetOptimizations())
154 if (xp.readsCoverage()) { 153 if (args.fInputCoverage) {
155 fragBuilder->codeAppendf("%s = %s * %s;", 154 fragBuilder->codeAppendf("%s = %s * %s;",
156 args.fOutputPrimary, args.fInputCoverage, a rgs.fInputColor); 155 args.fOutputPrimary, args.fInputCoverage, a rgs.fInputColor);
157 } else { 156 } else {
158 fragBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInpu tColor); 157 fragBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInpu tColor);
159 } 158 }
160 } 159 }
161 160
162 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, 161 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
163 GrGLSLXPFragmentBuilder* fragBuilder, 162 GrGLSLXPFragmentBuilder* fragBuilder,
164 const char* srcColor, 163 const char* srcColor,
(...skipping 24 matching lines...) Expand all
189 188
190 bool CustomXP::onIsEqual(const GrXferProcessor& other) const { 189 bool CustomXP::onIsEqual(const GrXferProcessor& other) const {
191 const CustomXP& s = other.cast<CustomXP>(); 190 const CustomXP& s = other.cast<CustomXP>();
192 return fMode == s.fMode && fHWBlendEquation == s.fHWBlendEquation; 191 return fMode == s.fMode && fHWBlendEquation == s.fHWBlendEquation;
193 } 192 }
194 193
195 GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrProcOptInfo& colo rPOI, 194 GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrProcOptInfo& colo rPOI,
196 const GrProcOptInfo& cove ragePOI, 195 const GrProcOptInfo& cove ragePOI,
197 bool doesStencilWrite, 196 bool doesStencilWrite,
198 GrColor* overrideColor, 197 GrColor* overrideColor,
199 const GrCaps& caps) { 198 const GrCaps& caps) const {
200 /* 199 /*
201 Most the optimizations we do here are based on tweaking alpha for coverage. 200 Most the optimizations we do here are based on tweaking alpha for coverage.
202 201
203 The general SVG blend equation is defined in the spec as follows: 202 The general SVG blend equation is defined in the spec as follows:
204 203
205 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa) 204 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa)
206 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa) 205 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa)
207 206
208 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha, 207 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha,
209 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied 208 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 390
392 /////////////////////////////////////////////////////////////////////////////// 391 ///////////////////////////////////////////////////////////////////////////////
393 392
394 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { 393 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) {
395 if (!GrCustomXfermode::IsSupportedMode(mode)) { 394 if (!GrCustomXfermode::IsSupportedMode(mode)) {
396 return nullptr; 395 return nullptr;
397 } else { 396 } else {
398 return new CustomXPFactory(mode); 397 return new CustomXPFactory(mode);
399 } 398 }
400 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698