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, | 79 SkFilterQuality) const overri
de; |
80 GrProcessorDataManager*) cons
t override; | |
81 #endif | 80 #endif |
82 | 81 |
83 size_t contextSize() const override; | 82 size_t contextSize() const override; |
84 | 83 |
85 class LightingShaderContext : public SkShader::Context { | 84 class LightingShaderContext : public SkShader::Context { |
86 public: | 85 public: |
87 // The context takes ownership of the states. It will call their destruc
tors | 86 // The context takes ownership of the states. It will call their destruc
tors |
88 // but will NOT free the memory. | 87 // but will NOT free the memory. |
89 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 88 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
90 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); | 89 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 129 |
131 #include "GrCoordTransform.h" | 130 #include "GrCoordTransform.h" |
132 #include "GrFragmentProcessor.h" | 131 #include "GrFragmentProcessor.h" |
133 #include "GrTextureAccess.h" | 132 #include "GrTextureAccess.h" |
134 #include "gl/GrGLProcessor.h" | 133 #include "gl/GrGLProcessor.h" |
135 #include "gl/builders/GrGLProgramBuilder.h" | 134 #include "gl/builders/GrGLProgramBuilder.h" |
136 #include "SkGr.h" | 135 #include "SkGr.h" |
137 | 136 |
138 class LightingFP : public GrFragmentProcessor { | 137 class LightingFP : public GrFragmentProcessor { |
139 public: | 138 public: |
140 LightingFP(GrProcessorDataManager* pdm, GrTexture* diffuse, GrTexture* norma
l, | 139 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, |
141 const SkMatrix& diffMatrix, const SkMatrix& normMatrix, | 140 const SkMatrix& normMatrix, const GrTextureParams& diffParams, |
142 const GrTextureParams& diffParams, const GrTextureParams& normPar
ams, | 141 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, |
143 const SkLightingShader::Lights* lights, const SkVector& invNormRo
tation) | 142 const SkVector& invNormRotation) |
144 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) | 143 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) |
145 , fNormDeviceTransform(kLocal_GrCoordSet, normMatrix, normal, normParams
.filterMode()) | 144 , fNormDeviceTransform(kLocal_GrCoordSet, normMatrix, normal, normParams
.filterMode()) |
146 , fDiffuseTextureAccess(diffuse, diffParams) | 145 , fDiffuseTextureAccess(diffuse, diffParams) |
147 , fNormalTextureAccess(normal, normParams) | 146 , fNormalTextureAccess(normal, normParams) |
148 , fInvNormRotation(invNormRotation) { | 147 , fInvNormRotation(invNormRotation) { |
149 this->addCoordTransform(&fDiffDeviceTransform); | 148 this->addCoordTransform(&fDiffDeviceTransform); |
150 this->addCoordTransform(&fNormDeviceTransform); | 149 this->addCoordTransform(&fNormDeviceTransform); |
151 this->addTextureAccess(&fDiffuseTextureAccess); | 150 this->addTextureAccess(&fDiffuseTextureAccess); |
152 this->addTextureAccess(&fNormalTextureAccess); | 151 this->addTextureAccess(&fNormalTextureAccess); |
153 | 152 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 341 } |
343 result->preConcat(lmInverse); | 342 result->preConcat(lmInverse); |
344 | 343 |
345 return true; | 344 return true; |
346 } | 345 } |
347 | 346 |
348 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( | 347 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( |
349 GrContext* context, | 348 GrContext* context, |
350 const SkMatrix& vie
wM, | 349 const SkMatrix& vie
wM, |
351 const SkMatrix* loc
alMatrix, | 350 const SkMatrix* loc
alMatrix, |
352 SkFilterQuality fil
terQuality, | 351 SkFilterQuality fil
terQuality) const { |
353 GrProcessorDataMana
ger* pdm) const { | |
354 // we assume diffuse and normal maps have same width and height | 352 // we assume diffuse and normal maps have same width and height |
355 // TODO: support different sizes | 353 // TODO: support different sizes |
356 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && | 354 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
357 fDiffuseMap.height() == fNormalMap.height()); | 355 fDiffuseMap.height() == fNormalMap.height()); |
358 SkMatrix diffM, normM; | 356 SkMatrix diffM, normM; |
359 | 357 |
360 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { | 358 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
361 return nullptr; | 359 return nullptr; |
362 } | 360 } |
363 | 361 |
(...skipping 27 matching lines...) Expand all Loading... |
391 | 389 |
392 GrTextureParams normParams(kClamp_TileMode, normFilterMode); | 390 GrTextureParams normParams(kClamp_TileMode, normFilterMode); |
393 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, | 391 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, |
394 fNormalMap, &
normParams)); | 392 fNormalMap, &
normParams)); |
395 if (!normalTexture) { | 393 if (!normalTexture) { |
396 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); | 394 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit
map to texture."); |
397 return nullptr; | 395 return nullptr; |
398 } | 396 } |
399 | 397 |
400 SkAutoTUnref<const GrFragmentProcessor> inner ( | 398 SkAutoTUnref<const GrFragmentProcessor> inner ( |
401 new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffPar
ams, normParams, | 399 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams,
normParams, fLights, |
402 fLights, fInvNormRotation)); | 400 fInvNormRotation)); |
403 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 401 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
404 } | 402 } |
405 | 403 |
406 #endif | 404 #endif |
407 | 405 |
408 //////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////// |
409 | 407 |
410 bool SkLightingShaderImpl::isOpaque() const { | 408 bool SkLightingShaderImpl::isOpaque() const { |
411 return fDiffuseMap.isOpaque(); | 409 return fDiffuseMap.isOpaque(); |
412 } | 410 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 normLocalM); | 711 normLocalM); |
714 } | 712 } |
715 | 713 |
716 /////////////////////////////////////////////////////////////////////////////// | 714 /////////////////////////////////////////////////////////////////////////////// |
717 | 715 |
718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 716 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
719 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 717 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
720 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
721 | 719 |
722 /////////////////////////////////////////////////////////////////////////////// | 720 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |