| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 #if SK_SUPPORT_GPU | 75 #if SK_SUPPORT_GPU |
| 76 const GrFragmentProcessor* asFragmentProcessor(GrContext*, | 76 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
| 77 const SkMatrix& viewM, | 77 const SkMatrix& viewM, |
| 78 const SkMatrix* localMatrix, | 78 const SkMatrix* localMatrix, |
| 79 SkFilterQuality) const overri
de; | 79 SkFilterQuality, |
| 80 GrRenderTarget* dst) const ov
erride; |
| 80 #endif | 81 #endif |
| 81 | 82 |
| 82 size_t contextSize() const override; | 83 size_t contextSize() const override; |
| 83 | 84 |
| 84 class LightingShaderContext : public SkShader::Context { | 85 class LightingShaderContext : public SkShader::Context { |
| 85 public: | 86 public: |
| 86 // 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 |
| 87 // but will NOT free the memory. | 88 // but will NOT free the memory. |
| 88 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 89 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
| 89 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); | 90 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 #include "glsl/GrGLSLProgramBuilder.h" | 136 #include "glsl/GrGLSLProgramBuilder.h" |
| 136 #include "glsl/GrGLSLProgramDataManager.h" | 137 #include "glsl/GrGLSLProgramDataManager.h" |
| 137 #include "SkGr.h" | 138 #include "SkGr.h" |
| 138 #include "SkGrPriv.h" | 139 #include "SkGrPriv.h" |
| 139 | 140 |
| 140 class LightingFP : public GrFragmentProcessor { | 141 class LightingFP : public GrFragmentProcessor { |
| 141 public: | 142 public: |
| 142 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, | 143 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, |
| 143 const SkMatrix& normMatrix, const GrTextureParams& diffParams, | 144 const SkMatrix& normMatrix, const GrTextureParams& diffParams, |
| 144 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, | 145 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, |
| 145 const SkVector& invNormRotation) | 146 const SkVector& invNormRotation, GrRenderTarget* dst) |
| 146 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) | 147 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) |
| 147 , fNormDeviceTransform(kLocal_GrCoordSet, normMatrix, normal, normParams
.filterMode()) | 148 , fNormDeviceTransform(kLocal_GrCoordSet, normMatrix, normal, normParams
.filterMode()) |
| 148 , fDiffuseTextureAccess(diffuse, diffParams) | 149 , fDiffuseTextureAccess(diffuse, diffParams, dst) |
| 149 , fNormalTextureAccess(normal, normParams) | 150 , fNormalTextureAccess(normal, normParams, dst) |
| 150 , fInvNormRotation(invNormRotation) { | 151 , fInvNormRotation(invNormRotation) { |
| 151 this->addCoordTransform(&fDiffDeviceTransform); | 152 this->addCoordTransform(&fDiffDeviceTransform); |
| 152 this->addCoordTransform(&fNormDeviceTransform); | 153 this->addCoordTransform(&fNormDeviceTransform); |
| 153 this->addTextureAccess(&fDiffuseTextureAccess); | 154 this->addTextureAccess(&fDiffuseTextureAccess); |
| 154 this->addTextureAccess(&fNormalTextureAccess); | 155 this->addTextureAccess(&fNormalTextureAccess); |
| 155 | 156 |
| 156 // fuse all ambient lights into a single one | 157 // fuse all ambient lights into a single one |
| 157 fAmbientColor.set(0.0f, 0.0f, 0.0f); | 158 fAmbientColor.set(0.0f, 0.0f, 0.0f); |
| 158 for (int i = 0; i < lights->numLights(); ++i) { | 159 for (int i = 0; i < lights->numLights(); ++i) { |
| 159 if (SkLight::kAmbient_LightType == lights->light(i).type()) { | 160 if (SkLight::kAmbient_LightType == lights->light(i).type()) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 } | 345 } |
| 345 result->preConcat(lmInverse); | 346 result->preConcat(lmInverse); |
| 346 | 347 |
| 347 return true; | 348 return true; |
| 348 } | 349 } |
| 349 | 350 |
| 350 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( | 351 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( |
| 351 GrContext* context, | 352 GrContext* context, |
| 352 const SkMatrix& vie
wM, | 353 const SkMatrix& vie
wM, |
| 353 const SkMatrix* loc
alMatrix, | 354 const SkMatrix* loc
alMatrix, |
| 354 SkFilterQuality fil
terQuality) const { | 355 SkFilterQuality fil
terQuality, |
| 356 GrRenderTarget* dst
) const { |
| 355 // we assume diffuse and normal maps have same width and height | 357 // we assume diffuse and normal maps have same width and height |
| 356 // TODO: support different sizes | 358 // TODO: support different sizes |
| 357 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && | 359 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
| 358 fDiffuseMap.height() == fNormalMap.height()); | 360 fDiffuseMap.height() == fNormalMap.height()); |
| 359 SkMatrix diffM, normM; | 361 SkMatrix diffM, normM; |
| 360 | 362 |
| 361 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { | 363 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
| 362 return nullptr; | 364 return nullptr; |
| 363 } | 365 } |
| 364 | 366 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 393 GrTextureParams normParams(kClamp_TileMode, normFilterMode); | 395 GrTextureParams normParams(kClamp_TileMode, normFilterMode); |
| 394 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, | 396 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, |
| 395 fNormalMap, n
ormParams)); | 397 fNormalMap, n
ormParams)); |
| 396 if (!normalTexture) { | 398 if (!normalTexture) { |
| 397 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); | 399 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
| 398 return nullptr; | 400 return nullptr; |
| 399 } | 401 } |
| 400 | 402 |
| 401 SkAutoTUnref<const GrFragmentProcessor> inner ( | 403 SkAutoTUnref<const GrFragmentProcessor> inner ( |
| 402 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams,
normParams, fLights, | 404 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams,
normParams, fLights, |
| 403 fInvNormRotation)); | 405 fInvNormRotation, dst)); |
| 404 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 406 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
| 405 } | 407 } |
| 406 | 408 |
| 407 #endif | 409 #endif |
| 408 | 410 |
| 409 //////////////////////////////////////////////////////////////////////////// | 411 //////////////////////////////////////////////////////////////////////////// |
| 410 | 412 |
| 411 bool SkLightingShaderImpl::isOpaque() const { | 413 bool SkLightingShaderImpl::isOpaque() const { |
| 412 return fDiffuseMap.isOpaque(); | 414 return fDiffuseMap.isOpaque(); |
| 413 } | 415 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 normLocalM); | 716 normLocalM); |
| 715 } | 717 } |
| 716 | 718 |
| 717 /////////////////////////////////////////////////////////////////////////////// | 719 /////////////////////////////////////////////////////////////////////////////// |
| 718 | 720 |
| 719 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
| 720 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 722 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
| 721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 723 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 722 | 724 |
| 723 /////////////////////////////////////////////////////////////////////////////// | 725 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |