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