| 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 #include "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
| 9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 SkLightingShaderImpl(sk_sp<SkShader> diffuseShader, | 46 SkLightingShaderImpl(sk_sp<SkShader> diffuseShader, |
| 47 sk_sp<SkNormalSource> normalSource, | 47 sk_sp<SkNormalSource> normalSource, |
| 48 sk_sp<SkLights> lights) | 48 sk_sp<SkLights> lights) |
| 49 : fDiffuseShader(std::move(diffuseShader)) | 49 : fDiffuseShader(std::move(diffuseShader)) |
| 50 , fNormalSource(std::move(normalSource)) | 50 , fNormalSource(std::move(normalSource)) |
| 51 , fLights(std::move(lights)) {} | 51 , fLights(std::move(lights)) {} |
| 52 | 52 |
| 53 bool isOpaque() const override; | 53 bool isOpaque() const override; |
| 54 | 54 |
| 55 #if SK_SUPPORT_GPU | 55 #if SK_SUPPORT_GPU |
| 56 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, | 56 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri
de; |
| 57 const SkMatrix& viewM, | |
| 58 const SkMatrix* localMatrix, | |
| 59 SkFilterQuality, | |
| 60 SkSourceGammaTreatment) const
override; | |
| 61 #endif | 57 #endif |
| 62 | 58 |
| 63 class LightingShaderContext : public SkShader::Context { | 59 class LightingShaderContext : public SkShader::Context { |
| 64 public: | 60 public: |
| 65 // The context takes ownership of the states. It will call their destruc
tors | 61 // The context takes ownership of the states. It will call their destruc
tors |
| 66 // but will NOT free the memory. | 62 // but will NOT free the memory. |
| 67 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 63 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
| 68 SkShader::Context* diffuseContext, SkNormalSource:
:Provider*, | 64 SkShader::Context* diffuseContext, SkNormalSource:
:Provider*, |
| 69 void* heapAllocated); | 65 void* heapAllocated); |
| 70 | 66 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 fAmbientColor == lightingFP.fAmbientColor; | 254 fAmbientColor == lightingFP.fAmbientColor; |
| 259 } | 255 } |
| 260 | 256 |
| 261 SkVector3 fLightDir; | 257 SkVector3 fLightDir; |
| 262 SkColor3f fLightColor; | 258 SkColor3f fLightColor; |
| 263 SkColor3f fAmbientColor; | 259 SkColor3f fAmbientColor; |
| 264 }; | 260 }; |
| 265 | 261 |
| 266 //////////////////////////////////////////////////////////////////////////// | 262 //////////////////////////////////////////////////////////////////////////// |
| 267 | 263 |
| 268 sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor( | 264 sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor(const AsFPA
rgs& args) const { |
| 269 GrContext* context, | 265 sk_sp<GrFragmentProcessor> normalFP(fNormalSource->asFragmentProcessor(args)
); |
| 270 const SkMatrix& viewM, | |
| 271 const SkMatrix* localMatrix
, | |
| 272 SkFilterQuality filterQuali
ty, | |
| 273 SkSourceGammaTreatment gamm
aTreatment) const { | |
| 274 sk_sp<GrFragmentProcessor> normalFP( | |
| 275 fNormalSource->asFragmentProcessor(context, viewM, localMatrix, filt
erQuality, | |
| 276 gammaTreatment)); | |
| 277 if (!normalFP) { | 266 if (!normalFP) { |
| 278 return nullptr; | 267 return nullptr; |
| 279 } | 268 } |
| 280 | 269 |
| 281 if (fDiffuseShader) { | 270 if (fDiffuseShader) { |
| 282 sk_sp<GrFragmentProcessor> fpPipeline[] = { | 271 sk_sp<GrFragmentProcessor> fpPipeline[] = { |
| 283 fDiffuseShader->asFragmentProcessor(context, viewM, localMatrix, fil
terQuality, | 272 fDiffuseShader->asFragmentProcessor(args), |
| 284 gammaTreatment), | |
| 285 sk_make_sp<LightingFP>(std::move(normalFP), fLights) | 273 sk_make_sp<LightingFP>(std::move(normalFP), fLights) |
| 286 }; | 274 }; |
| 287 if(!fpPipeline[0]) { | 275 if(!fpPipeline[0]) { |
| 288 return nullptr; | 276 return nullptr; |
| 289 } | 277 } |
| 290 | 278 |
| 291 sk_sp<GrFragmentProcessor> innerLightFP = GrFragmentProcessor::RunInSeri
es(fpPipeline, 2); | 279 sk_sp<GrFragmentProcessor> innerLightFP = GrFragmentProcessor::RunInSeri
es(fpPipeline, 2); |
| 292 // FP is wrapped because paint's alpha needs to be applied to output | 280 // FP is wrapped because paint's alpha needs to be applied to output |
| 293 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(innerLightFP
)); | 281 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(innerLightFP
)); |
| 294 } else { | 282 } else { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 std::move(lights)); | 525 std::move(lights)); |
| 538 } | 526 } |
| 539 | 527 |
| 540 /////////////////////////////////////////////////////////////////////////////// | 528 /////////////////////////////////////////////////////////////////////////////// |
| 541 | 529 |
| 542 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 530 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
| 543 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 531 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
| 544 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 532 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 545 | 533 |
| 546 /////////////////////////////////////////////////////////////////////////////// | 534 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |