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

Side by Side Diff: src/effects/SkArithmeticMode_gpu.cpp

Issue 860383007: Move GrXferProcessor subclasses into cpp files (Closed) Base URL: https://skia.googlesource.com/skia.git@playDstCpy
Patch Set: Rebase Created 5 years, 10 months 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/effects/SkArithmeticMode_gpu.h ('k') | src/gpu/effects/GrCoverageSetOpXP.h » ('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 "SkArithmeticMode_gpu.h" 8 #include "SkArithmeticMode_gpu.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 return SkNEW_ARGS(GrArithmeticFP, (k1, k2, k3, k4, enforcePMColor, textures[ 0])); 152 return SkNEW_ARGS(GrArithmeticFP, (k1, k2, k3, k4, enforcePMColor, textures[ 0]));
153 } 153 }
154 154
155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); 155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP);
156 156
157 /////////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////////
158 // Xfer Processor 158 // Xfer Processor
159 /////////////////////////////////////////////////////////////////////////////// 159 ///////////////////////////////////////////////////////////////////////////////
160 160
161 class ArithmeticXP : public GrXferProcessor {
162 public:
163 static GrXferProcessor* Create(float k1, float k2, float k3, float k4, bool enforcePMColor,
164 const GrDeviceCoordTexture* dstCopy,
165 bool willReadDstColor) {
166 return SkNEW_ARGS(ArithmeticXP, (k1, k2, k3, k4, enforcePMColor, dstCopy ,
167 willReadDstColor));
168 }
169
170 ~ArithmeticXP() SK_OVERRIDE {};
171
172 const char* name() const SK_OVERRIDE { return "Arithmetic"; }
173
174 GrGLXferProcessor* createGLInstance() const SK_OVERRIDE;
175
176 bool hasSecondaryOutput() const SK_OVERRIDE { return false; }
177
178 GrXferProcessor::OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
179 const GrProcOptInfo& coveragePOI,
180 bool doesStencilWrite,
181 GrColor* overrideColor,
182 const GrDrawTargetCaps& caps) SK_ OVERRIDE;
183
184 void getBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const SK_OVERRIDE {
185 blendInfo->fSrcBlend = kOne_GrBlendCoeff;
186 blendInfo->fDstBlend = kZero_GrBlendCoeff;
187 blendInfo->fBlendConstant = 0;
188 }
189
190 float k1() const { return fK1; }
191 float k2() const { return fK2; }
192 float k3() const { return fK3; }
193 float k4() const { return fK4; }
194 bool enforcePMColor() const { return fEnforcePMColor; }
195
196 private:
197 ArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor,
198 const GrDeviceCoordTexture* dstCopy, bool willReadDstColor);
199
200 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con st SK_OVERRIDE;
201
202 bool onIsEqual(const GrXferProcessor& xpBase) const SK_OVERRIDE {
203 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>();
204 if (fK1 != xp.fK1 ||
205 fK2 != xp.fK2 ||
206 fK3 != xp.fK3 ||
207 fK4 != xp.fK4 ||
208 fEnforcePMColor != xp.fEnforcePMColor) {
209 return false;
210 }
211 return true;
212 }
213
214 float fK1, fK2, fK3, fK4;
215 bool fEnforcePMColor;
216
217 typedef GrXferProcessor INHERITED;
218 };
219
220 ///////////////////////////////////////////////////////////////////////////////
221
161 class GLArithmeticXP : public GrGLXferProcessor { 222 class GLArithmeticXP : public GrGLXferProcessor {
162 public: 223 public:
163 GLArithmeticXP(const GrProcessor&) 224 GLArithmeticXP(const GrProcessor&)
164 : fEnforcePMColor(true) { 225 : fEnforcePMColor(true) {
165 } 226 }
166 227
167 ~GLArithmeticXP() SK_OVERRIDE {} 228 ~GLArithmeticXP() SK_OVERRIDE {}
168 229
169 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, 230 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps,
170 GrProcessorKeyBuilder* b) { 231 GrProcessorKeyBuilder* b) {
171 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); 232 const ArithmeticXP& arith = processor.cast<ArithmeticXP>();
172 uint32_t key = arith.enforcePMColor() ? 1 : 0; 233 uint32_t key = arith.enforcePMColor() ? 1 : 0;
173 b->add32(key); 234 b->add32(key);
174 } 235 }
175 236
176 private: 237 private:
177 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { 238 void onEmitCode(const EmitArgs& args) SK_OVERRIDE {
178 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 239 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
179 240
180 const char* dstColor = fsBuilder->dstColor(); 241 const char* dstColor = fsBuilder->dstColor();
181 242
182 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, 243 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
183 kVec4f_GrSLType, kDefault_GrSLPrecision, 244 kVec4f_GrSLType, kDefault_GrSLPrecision,
184 "k"); 245 "k");
185 const char* kUni = args.fPB->getUniformCStr(fKUni); 246 const char* kUni = args.fPB->getUniformCStr(fKUni);
186 247
187 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP rimary, kUni, 248 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP rimary, kUni,
188 fEnforcePMColor); 249 fEnforcePMColor);
189 250
190 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", 251 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;",
191 args.fOutputPrimary, args.fOutputPrimary, args.fI nputCoverage, 252 args.fOutputPrimary, args.fOutputPrimary, args.fI nputCoverage,
192 args.fInputCoverage, dstColor); 253 args.fInputCoverage, dstColor);
193 } 254 }
194 255
195 void onSetData(const GrGLProgramDataManager& pdman, 256 void onSetData(const GrGLProgramDataManager& pdman,
196 const GrXferProcessor& processor) SK_OVERRIDE { 257 const GrXferProcessor& processor) SK_OVERRIDE {
197 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); 258 const ArithmeticXP& arith = processor.cast<ArithmeticXP>();
198 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); 259 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4());
199 fEnforcePMColor = arith.enforcePMColor(); 260 fEnforcePMColor = arith.enforcePMColor();
200 }; 261 };
201 262
202 GrGLProgramDataManager::UniformHandle fKUni; 263 GrGLProgramDataManager::UniformHandle fKUni;
203 bool fEnforcePMColor; 264 bool fEnforcePMColor;
204 265
205 typedef GrGLXferProcessor INHERITED; 266 typedef GrGLXferProcessor INHERITED;
206 }; 267 };
207 268
208 /////////////////////////////////////////////////////////////////////////////// 269 ///////////////////////////////////////////////////////////////////////////////
209 270
210 GrArithmeticXP::GrArithmeticXP(float k1, float k2, float k3, float k4, bool enfo rcePMColor, 271 ArithmeticXP::ArithmeticXP(float k1, float k2, float k3, float k4, bool enforceP MColor,
211 const GrDeviceCoordTexture* dstCopy, bool willRea dDstColor) 272 const GrDeviceCoordTexture* dstCopy, bool willReadDst Color)
212 : INHERITED(dstCopy, willReadDstColor) 273 : INHERITED(dstCopy, willReadDstColor)
213 , fK1(k1) 274 , fK1(k1)
214 , fK2(k2) 275 , fK2(k2)
215 , fK3(k3) 276 , fK3(k3)
216 , fK4(k4) 277 , fK4(k4)
217 , fEnforcePMColor(enforcePMColor) { 278 , fEnforcePMColor(enforcePMColor) {
218 this->initClassID<GrArithmeticXP>(); 279 this->initClassID<ArithmeticXP>();
219 } 280 }
220 281
221 void GrArithmeticXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBui lder* b) const { 282 void ArithmeticXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuild er* b) const {
222 GLArithmeticXP::GenKey(*this, caps, b); 283 GLArithmeticXP::GenKey(*this, caps, b);
223 } 284 }
224 285
225 GrGLXferProcessor* GrArithmeticXP::createGLInstance() const { 286 GrGLXferProcessor* ArithmeticXP::createGLInstance() const {
226 return SkNEW_ARGS(GLArithmeticXP, (*this)); 287 return SkNEW_ARGS(GLArithmeticXP, (*this));
227 } 288 }
228 289
229 GrXferProcessor::OptFlags GrArithmeticXP::getOptimizations(const GrProcOptInfo& colorPOI, 290 GrXferProcessor::OptFlags ArithmeticXP::getOptimizations(const GrProcOptInfo& co lorPOI,
230 const GrProcOptInfo& coveragePOI, 291 const GrProcOptInfo& co veragePOI,
231 bool doesStencilWrite , 292 bool doesStencilWrite,
232 GrColor* overrideColo r, 293 GrColor* overrideColor,
233 const GrDrawTargetCap s& caps) { 294 const GrDrawTargetCaps& caps) {
234 return GrXferProcessor::kNone_Opt; 295 return GrXferProcessor::kNone_Opt;
235 } 296 }
236 297
237 /////////////////////////////////////////////////////////////////////////////// 298 ///////////////////////////////////////////////////////////////////////////////
238 299
239 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float k4, 300 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float k4,
240 bool enforcePMColor) 301 bool enforcePMColor)
241 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { 302 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) {
242 this->initClassID<GrArithmeticXPFactory>(); 303 this->initClassID<GrArithmeticXPFactory>();
243 } 304 }
244 305
306 GrXferProcessor*
307 GrArithmeticXPFactory::onCreateXferProcessor(const GrProcOptInfo& colorPOI,
308 const GrProcOptInfo& coveragePOI,
309 const GrDeviceCoordTexture* dstCopy ) const {
310 return ArithmeticXP::Create(fK1, fK2, fK3, fK4, fEnforcePMColor, dstCopy,
311 this->willReadDstColor());
312 }
313
314
245 void GrArithmeticXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI, 315 void GrArithmeticXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
246 const GrProcOptInfo& coveragePOI, 316 const GrProcOptInfo& coveragePOI,
247 GrXPFactory::InvariantOutput* out put) const { 317 GrXPFactory::InvariantOutput* out put) const {
248 output->fWillBlendWithDst = true; 318 output->fWillBlendWithDst = true;
249 319
250 // TODO: We could try to optimize this more. For example if we have solid co verage and fK1 and 320 // TODO: We could try to optimize this more. For example if we have solid co verage and fK1 and
251 // fK3 are zero, then we won't be blending the color with dst at all so we c an know what the 321 // fK3 are zero, then we won't be blending the color with dst at all so we c an know what the
252 // output color is (up to the valid color components passed in). 322 // output color is (up to the valid color components passed in).
253 output->fBlendedColorFlags = 0; 323 output->fBlendedColorFlags = 0;
254 } 324 }
255 325
256 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); 326 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory);
257 327
258 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random, 328 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random,
259 GrContext*, 329 GrContext*,
260 const GrDrawTargetCaps&, 330 const GrDrawTargetCaps&,
261 GrTexture*[]) { 331 GrTexture*[]) {
262 float k1 = random->nextF(); 332 float k1 = random->nextF();
263 float k2 = random->nextF(); 333 float k2 = random->nextF();
264 float k3 = random->nextF(); 334 float k3 = random->nextF();
265 float k4 = random->nextF(); 335 float k4 = random->nextF();
266 bool enforcePMColor = random->nextBool(); 336 bool enforcePMColor = random->nextBool();
267 337
268 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); 338 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor);
269 } 339 }
270 340
271 #endif 341 #endif
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode_gpu.h ('k') | src/gpu/effects/GrCoverageSetOpXP.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698