| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkComposeShader.h" | 10 #include "SkComposeShader.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 result += n; | 190 result += n; |
| 191 x += n; | 191 x += n; |
| 192 count -= n; | 192 count -= n; |
| 193 } while (count > 0); | 193 } while (count > 0); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 #if SK_SUPPORT_GPU | 197 #if SK_SUPPORT_GPU |
| 198 | 198 |
| 199 #include "SkGr.h" | |
| 200 #include "GrProcessor.h" | |
| 201 #include "gl/GrGLBlend.h" | 199 #include "gl/GrGLBlend.h" |
| 202 #include "gl/builders/GrGLProgramBuilder.h" | 200 #include "gl/builders/GrGLProgramBuilder.h" |
| 203 #include "effects/GrConstColorProcessor.h" | 201 #include "effects/GrConstColorProcessor.h" |
| 204 | 202 |
| 205 ///////////////////////////////////////////////////////////////////// | 203 ///////////////////////////////////////////////////////////////////// |
| 206 | 204 |
| 207 class GrComposeEffect : public GrFragmentProcessor { | |
| 208 public: | |
| 209 | |
| 210 static GrFragmentProcessor* Create(const GrFragmentProcessor* fpA, | |
| 211 const GrFragmentProcessor* fpB, SkXfermod
e::Mode mode) { | |
| 212 return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); | |
| 213 } | |
| 214 const char* name() const override { return "ComposeShader"; } | |
| 215 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | |
| 216 | |
| 217 SkXfermode::Mode getMode() const { return fMode; } | |
| 218 | |
| 219 protected: | |
| 220 bool onIsEqual(const GrFragmentProcessor&) const override; | |
| 221 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | |
| 222 | |
| 223 private: | |
| 224 GrComposeEffect(const GrFragmentProcessor* fpA, const GrFragmentProcessor* f
pB, | |
| 225 SkXfermode::Mode mode) | |
| 226 : fMode(mode) { | |
| 227 this->initClassID<GrComposeEffect>(); | |
| 228 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(fpA); | |
| 229 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(fpB); | |
| 230 SkASSERT(0 == shaderAChildIndex); | |
| 231 SkASSERT(1 == shaderBChildIndex); | |
| 232 } | |
| 233 | |
| 234 GrGLFragmentProcessor* onCreateGLInstance() const override; | |
| 235 | |
| 236 SkXfermode::Mode fMode; | |
| 237 | |
| 238 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | |
| 239 | |
| 240 typedef GrFragmentProcessor INHERITED; | |
| 241 }; | |
| 242 | |
| 243 ///////////////////////////////////////////////////////////////////// | |
| 244 | |
| 245 class GrGLComposeEffect : public GrGLFragmentProcessor { | 205 class GrGLComposeEffect : public GrGLFragmentProcessor { |
| 246 public: | 206 public: |
| 247 GrGLComposeEffect(const GrProcessor& processor) {} | 207 GrGLComposeEffect(const GrProcessor& processor) {} |
| 248 | 208 |
| 249 void emitCode(EmitArgs&) override; | 209 void emitCode(EmitArgs&) override; |
| 250 | 210 |
| 251 private: | 211 private: |
| 252 typedef GrGLFragmentProcessor INHERITED; | 212 typedef GrGLFragmentProcessor INHERITED; |
| 253 }; | 213 }; |
| 254 | 214 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 269 do { | 229 do { |
| 270 fpB.reset(GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); | 230 fpB.reset(GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); |
| 271 SkASSERT(fpB); | 231 SkASSERT(fpB); |
| 272 } while (fpB->numChildProcessors() != 0); | 232 } while (fpB->numChildProcessors() != 0); |
| 273 | 233 |
| 274 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 234 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 275 d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); | 235 d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); |
| 276 return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); | 236 return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); |
| 277 } | 237 } |
| 278 | 238 |
| 239 GrComposeEffect::GrComposeEffect(const GrFragmentProcessor* fpA, const GrFragmen
tProcessor* fpB, |
| 240 SkXfermode::Mode mode) |
| 241 : fMode(mode) { |
| 242 SkASSERT(SkXfermode::kLastCoeffMode >= mode); |
| 243 this->initClassID<GrComposeEffect>(); |
| 244 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(fpA); |
| 245 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(fpB); |
| 246 SkASSERT(0 == shaderAChildIndex); |
| 247 SkASSERT(1 == shaderBChildIndex); |
| 248 } |
| 249 |
| 279 bool GrComposeEffect::onIsEqual(const GrFragmentProcessor& other) const { | 250 bool GrComposeEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 280 const GrComposeEffect& cs = other.cast<GrComposeEffect>(); | 251 const GrComposeEffect& cs = other.cast<GrComposeEffect>(); |
| 281 return fMode == cs.fMode; | 252 return fMode == cs.fMode; |
| 282 } | 253 } |
| 283 | 254 |
| 284 void GrComposeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 255 void GrComposeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
| 285 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 256 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 286 } | 257 } |
| 287 | 258 |
| 288 void GrComposeEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { | 259 void GrComposeEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 SkAutoTUnref<const GrFragmentProcessor> fpA(fShaderA->asFragmentProc
essor(context, | 334 SkAutoTUnref<const GrFragmentProcessor> fpA(fShaderA->asFragmentProc
essor(context, |
| 364 viewM, localMatrix, fq,
procDataManager)); | 335 viewM, localMatrix, fq,
procDataManager)); |
| 365 if (!fpA.get()) { | 336 if (!fpA.get()) { |
| 366 return nullptr; | 337 return nullptr; |
| 367 } | 338 } |
| 368 SkAutoTUnref<const GrFragmentProcessor> fpB(fShaderB->asFragmentProc
essor(context, | 339 SkAutoTUnref<const GrFragmentProcessor> fpB(fShaderB->asFragmentProc
essor(context, |
| 369 viewM, localMatrix, fq,
procDataManager)); | 340 viewM, localMatrix, fq,
procDataManager)); |
| 370 if (!fpB.get()) { | 341 if (!fpB.get()) { |
| 371 return nullptr; | 342 return nullptr; |
| 372 } | 343 } |
| 373 return GrComposeEffect::Create(fpA, fpB, mode); | 344 return new GrComposeEffect(fpA, fpB, mode); |
| 374 } | 345 } |
| 375 } | 346 } |
| 376 #endif | 347 #endif |
| 377 | 348 |
| 378 #ifndef SK_IGNORE_TO_STRING | 349 #ifndef SK_IGNORE_TO_STRING |
| 379 void SkComposeShader::toString(SkString* str) const { | 350 void SkComposeShader::toString(SkString* str) const { |
| 380 str->append("SkComposeShader: ("); | 351 str->append("SkComposeShader: ("); |
| 381 | 352 |
| 382 str->append("ShaderA: "); | 353 str->append("ShaderA: "); |
| 383 fShaderA->toString(str); | 354 fShaderA->toString(str); |
| 384 str->append(" ShaderB: "); | 355 str->append(" ShaderB: "); |
| 385 fShaderB->toString(str); | 356 fShaderB->toString(str); |
| 386 if (fMode) { | 357 if (fMode) { |
| 387 str->append(" Xfermode: "); | 358 str->append(" Xfermode: "); |
| 388 fMode->toString(str); | 359 fMode->toString(str); |
| 389 } | 360 } |
| 390 | 361 |
| 391 this->INHERITED::toString(str); | 362 this->INHERITED::toString(str); |
| 392 | 363 |
| 393 str->append(")"); | 364 str->append(")"); |
| 394 } | 365 } |
| 395 #endif | 366 #endif |
| OLD | NEW |