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 "SkBitmapProcState.h" | 8 #include "SkBitmapProcState.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkEmptyShader.h" | 10 #include "SkEmptyShader.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 (void)fNormLocalMatrix.getType(); | 68 (void)fNormLocalMatrix.getType(); |
69 | 69 |
70 } | 70 } |
71 | 71 |
72 bool isOpaque() const override; | 72 bool isOpaque() const override; |
73 | 73 |
74 #if SK_SUPPORT_GPU | 74 #if SK_SUPPORT_GPU |
75 const GrFragmentProcessor* asFragmentProcessor(GrContext*, | 75 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
76 const SkMatrix& viewM, | 76 const SkMatrix& viewM, |
77 const SkMatrix* localMatrix, | 77 const SkMatrix* localMatrix, |
78 SkFilterQuality) const overri
de; | 78 SkFilterQuality, |
| 79 SkSourceGammaTreatment) const
override; |
79 #endif | 80 #endif |
80 | 81 |
81 class LightingShaderContext : public SkShader::Context { | 82 class LightingShaderContext : public SkShader::Context { |
82 public: | 83 public: |
83 // The context takes ownership of the states. It will call their destruc
tors | 84 // The context takes ownership of the states. It will call their destruc
tors |
84 // but will NOT free the memory. | 85 // but will NOT free the memory. |
85 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 86 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
86 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); | 87 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); |
87 ~LightingShaderContext() override; | 88 ~LightingShaderContext() override; |
88 | 89 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 return false; | 344 return false; |
344 } | 345 } |
345 lmInverse.postConcat(inv); | 346 lmInverse.postConcat(inv); |
346 } | 347 } |
347 result->preConcat(lmInverse); | 348 result->preConcat(lmInverse); |
348 | 349 |
349 return true; | 350 return true; |
350 } | 351 } |
351 | 352 |
352 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( | 353 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( |
353 GrContext* context, | 354 GrContext* context, |
354 const SkMatrix& vie
wM, | 355 const SkMatrix& viewM, |
355 const SkMatrix* loc
alMatrix, | 356 const SkMatrix* localMatrix
, |
356 SkFilterQuality fil
terQuality) const { | 357 SkFilterQuality filterQuali
ty, |
| 358 SkSourceGammaTreatment gamm
aTreatment) const { |
357 // we assume diffuse and normal maps have same width and height | 359 // we assume diffuse and normal maps have same width and height |
358 // TODO: support different sizes | 360 // TODO: support different sizes |
359 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && | 361 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
360 fDiffuseMap.height() == fNormalMap.height()); | 362 fDiffuseMap.height() == fNormalMap.height()); |
361 SkMatrix diffM, normM; | 363 SkMatrix diffM, normM; |
362 | 364 |
363 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { | 365 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
364 return nullptr; | 366 return nullptr; |
365 } | 367 } |
366 | 368 |
(...skipping 12 matching lines...) Expand all Loading... |
379 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode
( | 381 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode
( |
380 SkTMin(filterQuality, kMedium_SkFilterQu
ality), | 382 SkTMin(filterQuality, kMedium_SkFilterQu
ality), |
381 viewM, | 383 viewM, |
382 fNormLocalMatrix, | 384 fNormLocalMatrix, |
383 &doBicubic); | 385 &doBicubic); |
384 SkASSERT(!doBicubic); | 386 SkASSERT(!doBicubic); |
385 | 387 |
386 // TODO: support other tile modes | 388 // TODO: support other tile modes |
387 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); | 389 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); |
388 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, | 390 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, |
389 fDiffuseMap,
diffParams)); | 391 fDiffuseMap,
diffParams, |
| 392 gammaTreatme
nt)); |
390 if (!diffuseTexture) { | 393 if (!diffuseTexture) { |
391 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); | 394 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
392 return nullptr; | 395 return nullptr; |
393 } | 396 } |
394 | 397 |
395 GrTextureParams normParams(kClamp_TileMode, normFilterMode); | 398 GrTextureParams normParams(kClamp_TileMode, normFilterMode); |
396 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, | 399 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, |
397 fNormalMap, n
ormParams)); | 400 fNormalMap, n
ormParams, |
| 401 gammaTreatmen
t)); |
398 if (!normalTexture) { | 402 if (!normalTexture) { |
399 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); | 403 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
400 return nullptr; | 404 return nullptr; |
401 } | 405 } |
402 | 406 |
403 SkAutoTUnref<const GrFragmentProcessor> inner ( | 407 SkAutoTUnref<const GrFragmentProcessor> inner ( |
404 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams,
normParams, fLights, | 408 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams,
normParams, fLights, |
405 fInvNormRotation)); | 409 fInvNormRotation)); |
406 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 410 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
407 } | 411 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 invNormRotation, diffLocalM, normLoc
alM); | 726 invNormRotation, diffLocalM, normLoc
alM); |
723 } | 727 } |
724 | 728 |
725 /////////////////////////////////////////////////////////////////////////////// | 729 /////////////////////////////////////////////////////////////////////////////// |
726 | 730 |
727 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 731 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
728 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 732 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
729 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 733 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
730 | 734 |
731 /////////////////////////////////////////////////////////////////////////////// | 735 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |