| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 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 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } else { | 65 } else { |
| 66 fNormLocalMatrix.reset(); | 66 fNormLocalMatrix.reset(); |
| 67 } | 67 } |
| 68 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf
e. | 68 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf
e. |
| 69 (void)fNormLocalMatrix.getType(); | 69 (void)fNormLocalMatrix.getType(); |
| 70 | 70 |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool isOpaque() const override; | 73 bool isOpaque() const override; |
| 74 | 74 |
| 75 bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& v
iewM, | 75 #if SK_SUPPORT_GPU |
| 76 const SkMatrix* localMatrix, GrColor* color, | 76 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
| 77 GrProcessorDataManager*, GrFragmentProcessor** fp)
const override; | 77 const SkMatrix& viewM, |
| 78 const SkMatrix* localMatrix, |
| 79 SkFilterQuality, |
| 80 GrProcessorDataManager*) cons
t override; |
| 81 #endif |
| 78 | 82 |
| 79 size_t contextSize() const override; | 83 size_t contextSize() const override; |
| 80 | 84 |
| 81 class LightingShaderContext : public SkShader::Context { | 85 class LightingShaderContext : public SkShader::Context { |
| 82 public: | 86 public: |
| 83 // The context takes ownership of the states. It will call their destruc
tors | 87 // The context takes ownership of the states. It will call their destruc
tors |
| 84 // but will NOT free the memory. | 88 // but will NOT free the memory. |
| 85 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 89 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
| 86 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); | 90 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); |
| 87 ~LightingShaderContext() override; | 91 ~LightingShaderContext() override; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 typedef SkShader INHERITED; | 124 typedef SkShader INHERITED; |
| 121 }; | 125 }; |
| 122 | 126 |
| 123 //////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////// |
| 124 | 128 |
| 125 #if SK_SUPPORT_GPU | 129 #if SK_SUPPORT_GPU |
| 126 | 130 |
| 127 #include "GrCoordTransform.h" | 131 #include "GrCoordTransform.h" |
| 128 #include "GrFragmentProcessor.h" | 132 #include "GrFragmentProcessor.h" |
| 129 #include "GrTextureAccess.h" | 133 #include "GrTextureAccess.h" |
| 134 #include "effects/GrExtractAlphaFragmentProcessor.h" |
| 130 #include "gl/GrGLProcessor.h" | 135 #include "gl/GrGLProcessor.h" |
| 131 #include "gl/builders/GrGLProgramBuilder.h" | 136 #include "gl/builders/GrGLProgramBuilder.h" |
| 132 #include "SkGr.h" | 137 #include "SkGr.h" |
| 133 | 138 |
| 134 class LightingFP : public GrFragmentProcessor { | 139 class LightingFP : public GrFragmentProcessor { |
| 135 public: | 140 public: |
| 136 LightingFP(GrProcessorDataManager* pdm, GrTexture* diffuse, GrTexture* norma
l, | 141 LightingFP(GrProcessorDataManager* pdm, GrTexture* diffuse, GrTexture* norma
l, |
| 137 const SkMatrix& diffMatrix, const SkMatrix& normMatrix, | 142 const SkMatrix& diffMatrix, const SkMatrix& normMatrix, |
| 138 const GrTextureParams& diffParams, const GrTextureParams& normPar
ams, | 143 const GrTextureParams& diffParams, const GrTextureParams& normPar
ams, |
| 139 const SkLightingShader::Lights* lights, const SkVector& invNormRo
tation) | 144 const SkLightingShader::Lights* lights, const SkVector& invNormRo
tation) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (!localMatrix2->invert(&inv)) { | 339 if (!localMatrix2->invert(&inv)) { |
| 335 return false; | 340 return false; |
| 336 } | 341 } |
| 337 lmInverse.postConcat(inv); | 342 lmInverse.postConcat(inv); |
| 338 } | 343 } |
| 339 result->preConcat(lmInverse); | 344 result->preConcat(lmInverse); |
| 340 | 345 |
| 341 return true; | 346 return true; |
| 342 } | 347 } |
| 343 | 348 |
| 344 bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint
& paint, | 349 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( |
| 345 const SkMatrix& viewM, const SkMa
trix* localMatrix, | 350 GrContext* context, |
| 346 GrColor* color, GrProcessorDataMa
nager* pdm, | 351 const SkMatrix& vie
wM, |
| 347 GrFragmentProcessor** fp) const { | 352 const SkMatrix* loc
alMatrix, |
| 353 SkFilterQuality fil
terQuality, |
| 354 GrProcessorDataMana
ger* pdm) const { |
| 348 // we assume diffuse and normal maps have same width and height | 355 // we assume diffuse and normal maps have same width and height |
| 349 // TODO: support different sizes | 356 // TODO: support different sizes |
| 350 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && | 357 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
| 351 fDiffuseMap.height() == fNormalMap.height()); | 358 fDiffuseMap.height() == fNormalMap.height()); |
| 352 SkMatrix diffM, normM; | 359 SkMatrix diffM, normM; |
| 353 | 360 |
| 354 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { | 361 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
| 355 return false; | 362 return nullptr; |
| 356 } | 363 } |
| 357 | 364 |
| 358 if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) { | 365 if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) { |
| 359 return false; | 366 return nullptr; |
| 360 } | 367 } |
| 361 | 368 |
| 362 bool doBicubic; | 369 bool doBicubic; |
| 363 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode
( | 370 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode
( |
| 364 SkTMin(paint.getFilterQuality(), kMedium
_SkFilterQuality), | 371 SkTMin(filterQuality, kMedium_SkFilterQu
ality), |
| 365 viewM, | 372 viewM, |
| 366 this->getLocalMatrix(), | 373 this->getLocalMatrix(), |
| 367 &doBicubic); | 374 &doBicubic); |
| 368 SkASSERT(!doBicubic); | 375 SkASSERT(!doBicubic); |
| 369 | 376 |
| 370 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode
( | 377 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode
( |
| 371 SkTMin(paint.getFilterQuality(), kMedium
_SkFilterQuality), | 378 SkTMin(filterQuality, kMedium_SkFilterQu
ality), |
| 372 viewM, | 379 viewM, |
| 373 fNormLocalMatrix, | 380 fNormLocalMatrix, |
| 374 &doBicubic); | 381 &doBicubic); |
| 375 SkASSERT(!doBicubic); | 382 SkASSERT(!doBicubic); |
| 376 | 383 |
| 377 // TODO: support other tile modes | 384 // TODO: support other tile modes |
| 378 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); | 385 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); |
| 379 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, | 386 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, |
| 380 fDiffuseMap,
&diffParams)); | 387 fDiffuseMap,
&diffParams)); |
| 381 if (!diffuseTexture) { | 388 if (!diffuseTexture) { |
| 382 SkErrorInternals::SetError(kInternalError_SkError, | 389 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
| 383 "Couldn't convert bitmap to texture."); | 390 return nullptr; |
| 384 return false; | |
| 385 } | 391 } |
| 386 | 392 |
| 387 GrTextureParams normParams(kClamp_TileMode, normFilterMode); | 393 GrTextureParams normParams(kClamp_TileMode, normFilterMode); |
| 388 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, | 394 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, |
| 389 fNormalMap, &
normParams)); | 395 fNormalMap, &
normParams)); |
| 390 if (!normalTexture) { | 396 if (!normalTexture) { |
| 391 SkErrorInternals::SetError(kInternalError_SkError, | 397 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
| 392 "Couldn't convert bitmap to texture."); | 398 return nullptr; |
| 393 return false; | |
| 394 } | 399 } |
| 395 | 400 |
| 396 *fp = new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffP
arams, normParams, | 401 SkAutoTUnref<const GrFragmentProcessor> inner ( |
| 397 fLights, fInvNormRotation); | 402 new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffPar
ams, normParams, |
| 398 | 403 fLights, fInvNormRotation)); |
| 399 *color = GrColorPackA4(paint.getAlpha()); | 404 return GrExtractAlphaFragmentProcessor::Create(inner); |
| 400 return true; | |
| 401 } | |
| 402 #else | |
| 403 | |
| 404 bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint
& paint, | |
| 405 const SkMatrix& viewM, const SkMa
trix* localMatrix, | |
| 406 GrColor* color, GrProcessorDataMa
nager*, | |
| 407 GrFragmentProcessor** fp) const { | |
| 408 SkDEBUGFAIL("Should not call in GPU-less build"); | |
| 409 return false; | |
| 410 } | 405 } |
| 411 | 406 |
| 412 #endif | 407 #endif |
| 413 | 408 |
| 414 //////////////////////////////////////////////////////////////////////////// | 409 //////////////////////////////////////////////////////////////////////////// |
| 415 | 410 |
| 416 bool SkLightingShaderImpl::isOpaque() const { | 411 bool SkLightingShaderImpl::isOpaque() const { |
| 417 return fDiffuseMap.isOpaque(); | 412 return fDiffuseMap.isOpaque(); |
| 418 } | 413 } |
| 419 | 414 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 normLocalM); | 720 normLocalM); |
| 726 } | 721 } |
| 727 | 722 |
| 728 /////////////////////////////////////////////////////////////////////////////// | 723 /////////////////////////////////////////////////////////////////////////////// |
| 729 | 724 |
| 730 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
| 731 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 726 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
| 732 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 727 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 733 | 728 |
| 734 /////////////////////////////////////////////////////////////////////////////// | 729 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |