Chromium Code Reviews| 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*, const SkMatrix& v iewM, |
|
robertphillips
2015/08/28 21:33:05
indent ?
bsalomon
2015/08/29 01:42:50
Done.
| |
| 77 GrProcessorDataManager*, GrFragmentProcessor** fp) const override; | 77 const SkMatrix* localMatrix, SkFilterQuality, GrProcessorDataManager*) c onst override; |
| 78 #endif | |
| 78 | 79 |
| 79 size_t contextSize() const override; | 80 size_t contextSize() const override; |
| 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; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 typedef SkShader INHERITED; | 121 typedef SkShader INHERITED; |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 //////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////// |
| 124 | 125 |
| 125 #if SK_SUPPORT_GPU | 126 #if SK_SUPPORT_GPU |
| 126 | 127 |
| 127 #include "GrCoordTransform.h" | 128 #include "GrCoordTransform.h" |
| 128 #include "GrFragmentProcessor.h" | 129 #include "GrFragmentProcessor.h" |
| 129 #include "GrTextureAccess.h" | 130 #include "GrTextureAccess.h" |
| 131 #include "effects/GrExtractAlphaFragmentProcessor.h" | |
| 130 #include "gl/GrGLProcessor.h" | 132 #include "gl/GrGLProcessor.h" |
| 131 #include "gl/builders/GrGLProgramBuilder.h" | 133 #include "gl/builders/GrGLProgramBuilder.h" |
| 132 #include "SkGr.h" | 134 #include "SkGr.h" |
| 133 | 135 |
| 134 class LightingFP : public GrFragmentProcessor { | 136 class LightingFP : public GrFragmentProcessor { |
| 135 public: | 137 public: |
| 136 LightingFP(GrProcessorDataManager* pdm, GrTexture* diffuse, GrTexture* norma l, | 138 LightingFP(GrProcessorDataManager* pdm, GrTexture* diffuse, GrTexture* norma l, |
| 137 const SkMatrix& diffMatrix, const SkMatrix& normMatrix, | 139 const SkMatrix& diffMatrix, const SkMatrix& normMatrix, |
| 138 const GrTextureParams& diffParams, const GrTextureParams& normPar ams, | 140 const GrTextureParams& diffParams, const GrTextureParams& normPar ams, |
| 139 const SkLightingShader::Lights* lights, const SkVector& invNormRo tation) | 141 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)) { | 336 if (!localMatrix2->invert(&inv)) { |
| 335 return false; | 337 return false; |
| 336 } | 338 } |
| 337 lmInverse.postConcat(inv); | 339 lmInverse.postConcat(inv); |
| 338 } | 340 } |
| 339 result->preConcat(lmInverse); | 341 result->preConcat(lmInverse); |
| 340 | 342 |
| 341 return true; | 343 return true; |
| 342 } | 344 } |
| 343 | 345 |
| 344 bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint & paint, | 346 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor(GrContext* context, |
|
robertphillips
2015/08/28 21:33:05
indent ?
bsalomon
2015/08/29 01:42:50
Done.
| |
| 345 const SkMatrix& viewM, const SkMa trix* localMatrix, | 347 const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality filterQu ality, |
| 346 GrColor* color, GrProcessorDataMa nager* pdm, | 348 GrProcessorDataManager* pdm) const { |
| 347 GrFragmentProcessor** fp) const { | |
| 348 // we assume diffuse and normal maps have same width and height | 349 // we assume diffuse and normal maps have same width and height |
| 349 // TODO: support different sizes | 350 // TODO: support different sizes |
| 350 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && | 351 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
| 351 fDiffuseMap.height() == fNormalMap.height()); | 352 fDiffuseMap.height() == fNormalMap.height()); |
| 352 SkMatrix diffM, normM; | 353 SkMatrix diffM, normM; |
| 353 | 354 |
| 354 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { | 355 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
| 355 return false; | 356 return nullptr; |
| 356 } | 357 } |
| 357 | 358 |
| 358 if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) { | 359 if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) { |
| 359 return false; | 360 return nullptr; |
| 360 } | 361 } |
| 361 | 362 |
| 362 bool doBicubic; | 363 bool doBicubic; |
| 363 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode ( | 364 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode ( |
| 364 SkTMin(paint.getFilterQuality(), kMedium _SkFilterQuality), | 365 SkTMin(filterQuality, kMedium_SkFilterQu ality), |
| 365 viewM, | 366 viewM, |
| 366 this->getLocalMatrix(), | 367 this->getLocalMatrix(), |
| 367 &doBicubic); | 368 &doBicubic); |
| 368 SkASSERT(!doBicubic); | 369 SkASSERT(!doBicubic); |
| 369 | 370 |
| 370 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode ( | 371 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode ( |
| 371 SkTMin(paint.getFilterQuality(), kMedium _SkFilterQuality), | 372 SkTMin(filterQuality, kMedium_SkFilterQu ality), |
| 372 viewM, | 373 viewM, |
| 373 fNormLocalMatrix, | 374 fNormLocalMatrix, |
| 374 &doBicubic); | 375 &doBicubic); |
| 375 SkASSERT(!doBicubic); | 376 SkASSERT(!doBicubic); |
| 376 | 377 |
| 377 // TODO: support other tile modes | 378 // TODO: support other tile modes |
| 378 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); | 379 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); |
| 379 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, | 380 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, |
| 380 fDiffuseMap, &diffParams)); | 381 fDiffuseMap, &diffParams)); |
| 381 if (!diffuseTexture) { | 382 if (!diffuseTexture) { |
| 382 SkErrorInternals::SetError(kInternalError_SkError, | 383 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture."); |
| 383 "Couldn't convert bitmap to texture."); | 384 return nullptr; |
| 384 return false; | |
| 385 } | 385 } |
| 386 | 386 |
| 387 GrTextureParams normParams(kClamp_TileMode, normFilterMode); | 387 GrTextureParams normParams(kClamp_TileMode, normFilterMode); |
| 388 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, | 388 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, |
| 389 fNormalMap, & normParams)); | 389 fNormalMap, & normParams)); |
| 390 if (!normalTexture) { | 390 if (!normalTexture) { |
| 391 SkErrorInternals::SetError(kInternalError_SkError, | 391 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture."); |
| 392 "Couldn't convert bitmap to texture."); | 392 return nullptr; |
| 393 return false; | |
| 394 } | 393 } |
| 395 | 394 |
| 396 *fp = new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffP arams, normParams, | 395 SkAutoTUnref<const GrFragmentProcessor> inner ( |
| 397 fLights, fInvNormRotation); | 396 new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffPar ams, normParams, |
| 398 | 397 fLights, fInvNormRotation)); |
| 399 *color = GrColorPackA4(paint.getAlpha()); | 398 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 } | 399 } |
| 411 | 400 |
| 412 #endif | 401 #endif |
| 413 | 402 |
| 414 //////////////////////////////////////////////////////////////////////////// | 403 //////////////////////////////////////////////////////////////////////////// |
| 415 | 404 |
| 416 bool SkLightingShaderImpl::isOpaque() const { | 405 bool SkLightingShaderImpl::isOpaque() const { |
| 417 return fDiffuseMap.isOpaque(); | 406 return fDiffuseMap.isOpaque(); |
| 418 } | 407 } |
| 419 | 408 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 normLocalM); | 714 normLocalM); |
| 726 } | 715 } |
| 727 | 716 |
| 728 /////////////////////////////////////////////////////////////////////////////// | 717 /////////////////////////////////////////////////////////////////////////////// |
| 729 | 718 |
| 730 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 719 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
| 731 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 720 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
| 732 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 733 | 722 |
| 734 /////////////////////////////////////////////////////////////////////////////// | 723 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |