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

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: Fix Build 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
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.cpp ('k') | src/gpu/effects/GrDisableColorXP.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 96
97 GrBlendEquation hwBlendEquation() const { 97 GrBlendEquation hwBlendEquation() const {
98 SkASSERT(this->hasHWBlendEquation()); 98 SkASSERT(this->hasHWBlendEquation());
99 return fHWBlendEquation; 99 return fHWBlendEquation;
100 } 100 }
101 101
102 private: 102 private:
103 GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations& optimizations, 103 GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations& optimizations,
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 23 matching lines...) Expand all
188 } 187 }
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 GrPipelineOptimizat ions& optimizations, 194 GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrPipelineOptimizat ions& optimizations,
196 bool doesStencilWrite, 195 bool doesStencilWrite,
197 GrColor* overrideColor, 196 GrColor* overrideColor,
198 const GrCaps& caps) { 197 const GrCaps& caps) const {
199 /* 198 /*
200 Most the optimizations we do here are based on tweaking alpha for coverage. 199 Most the optimizations we do here are based on tweaking alpha for coverage.
201 200
202 The general SVG blend equation is defined in the spec as follows: 201 The general SVG blend equation is defined in the spec as follows:
203 202
204 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa) 203 Dca' = B(Sc, Dc) * Sa * Da + Y * Sca * (1-Da) + Z * Dca * (1-Sa)
205 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa) 204 Da' = X * Sa * Da + Y * Sa * (1-Da) + Z * Da * (1-Sa)
206 205
207 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha, 206 (Note that Sca, Dca indicate RGB vectors that are premultiplied by alpha,
208 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied 207 and that B(Sc, Dc) is a mode-specific function that accepts non-multiplied
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 385
387 /////////////////////////////////////////////////////////////////////////////// 386 ///////////////////////////////////////////////////////////////////////////////
388 387
389 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { 388 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) {
390 if (!GrCustomXfermode::IsSupportedMode(mode)) { 389 if (!GrCustomXfermode::IsSupportedMode(mode)) {
391 return nullptr; 390 return nullptr;
392 } else { 391 } else {
393 return new CustomXPFactory(mode); 392 return new CustomXPFactory(mode);
394 } 393 }
395 } 394 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCoverageSetOpXP.cpp ('k') | src/gpu/effects/GrDisableColorXP.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698