| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 /** Create a new lighting shader that use the provided normal map, light | 45 /** Create a new lighting shader that use the provided normal map, light |
| 46 and ambient color to light the diffuse bitmap. | 46 and ambient color to light the diffuse bitmap. |
| 47 @param diffuse the diffuse bitmap | 47 @param diffuse the diffuse bitmap |
| 48 @param normal the normal map | 48 @param normal the normal map |
| 49 @param light the light applied to the normal map | 49 @param light the light applied to the normal map |
| 50 @param ambient the linear (unpremul) ambient light color | 50 @param ambient the linear (unpremul) ambient light color |
| 51 */ | 51 */ |
| 52 SkLightingShaderImpl(const SkBitmap& diffuse, const SkBitmap& normal, | 52 SkLightingShaderImpl(const SkBitmap& diffuse, const SkBitmap& normal, |
| 53 const SkLightingShader::Light& light, | 53 const SkLightingShader::Light& light, |
| 54 const SkColor ambient) | 54 const SkColor ambient, const SkMatrix* localMatrix) |
| 55 : fDiffuseMap(diffuse) | 55 : INHERITED(localMatrix) |
| 56 , fDiffuseMap(diffuse) |
| 56 , fNormalMap(normal) | 57 , fNormalMap(normal) |
| 57 , fLight(light) | 58 , fLight(light) |
| 58 , fAmbientColor(ambient) { | 59 , fAmbientColor(ambient) { |
| 59 if (!fLight.fDirection.normalize()) { | 60 if (!fLight.fDirection.normalize()) { |
| 60 fLight.fDirection = SkPoint3::Make(0.0f, 0.0f, 1.0f); | 61 fLight.fDirection = SkPoint3::Make(0.0f, 0.0f, 1.0f); |
| 61 } | 62 } |
| 62 SkColorSetA(fLight.fColor, 0xFF); | 63 SkColorSetA(fLight.fColor, 0xFF); |
| 63 SkColorSetA(fAmbientColor, 0xFF); | 64 SkColorSetA(fAmbientColor, 0xFF); |
| 64 } | 65 } |
| 65 | 66 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 474 |
| 474 //////////////////////////////////////////////////////////////////////////// | 475 //////////////////////////////////////////////////////////////////////////// |
| 475 | 476 |
| 476 #ifndef SK_IGNORE_TO_STRING | 477 #ifndef SK_IGNORE_TO_STRING |
| 477 void SkLightingShaderImpl::toString(SkString* str) const { | 478 void SkLightingShaderImpl::toString(SkString* str) const { |
| 478 str->appendf("LightingShader: ()"); | 479 str->appendf("LightingShader: ()"); |
| 479 } | 480 } |
| 480 #endif | 481 #endif |
| 481 | 482 |
| 482 SkFlattenable* SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) { | 483 SkFlattenable* SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) { |
| 484 SkMatrix localMatrix; |
| 485 buf.readMatrix(&localMatrix); |
| 486 |
| 483 SkBitmap diffuse; | 487 SkBitmap diffuse; |
| 484 if (!buf.readBitmap(&diffuse)) { | 488 if (!buf.readBitmap(&diffuse)) { |
| 485 return NULL; | 489 return NULL; |
| 486 } | 490 } |
| 487 diffuse.setImmutable(); | 491 diffuse.setImmutable(); |
| 488 | 492 |
| 489 SkBitmap normal; | 493 SkBitmap normal; |
| 490 if (!buf.readBitmap(&normal)) { | 494 if (!buf.readBitmap(&normal)) { |
| 491 return NULL; | 495 return NULL; |
| 492 } | 496 } |
| 493 normal.setImmutable(); | 497 normal.setImmutable(); |
| 494 | 498 |
| 495 SkLightingShader::Light light; | 499 SkLightingShader::Light light; |
| 496 if (!buf.readScalarArray(&light.fDirection.fX, 3)) { | 500 if (!buf.readScalarArray(&light.fDirection.fX, 3)) { |
| 497 return NULL; | 501 return NULL; |
| 498 } | 502 } |
| 499 light.fColor = buf.readColor(); | 503 light.fColor = buf.readColor(); |
| 500 | 504 |
| 501 SkColor ambient = buf.readColor(); | 505 SkColor ambient = buf.readColor(); |
| 502 | 506 |
| 503 // TODO: this would be nice to enable | 507 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient, &l
ocalMatrix)); |
| 504 // return SkCreateLightingShader(diffuse, normal, light, ambient, NULL); | |
| 505 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient)); | |
| 506 } | 508 } |
| 507 | 509 |
| 508 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { | 510 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { |
| 511 buf.writeMatrix(this->getLocalMatrix()); |
| 512 |
| 509 buf.writeBitmap(fDiffuseMap); | 513 buf.writeBitmap(fDiffuseMap); |
| 510 buf.writeBitmap(fNormalMap); | 514 buf.writeBitmap(fNormalMap); |
| 511 buf.writeScalarArray(&fLight.fDirection.fX, 3); | 515 buf.writeScalarArray(&fLight.fDirection.fX, 3); |
| 512 buf.writeColor(fLight.fColor); | 516 buf.writeColor(fLight.fColor); |
| 513 buf.writeColor(fAmbientColor); | 517 buf.writeColor(fAmbientColor); |
| 514 } | 518 } |
| 515 | 519 |
| 516 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, | 520 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, |
| 517 void* storage) const { | 521 void* storage) const { |
| 518 | 522 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // communicates between its matrix-proc and its sampler-proc. Until we can | 562 // communicates between its matrix-proc and its sampler-proc. Until we can |
| 559 // widen that, we have to reject bitmaps that are larger. | 563 // widen that, we have to reject bitmaps that are larger. |
| 560 // | 564 // |
| 561 static const int kMaxSize = 65535; | 565 static const int kMaxSize = 65535; |
| 562 | 566 |
| 563 return bm.width() > kMaxSize || bm.height() > kMaxSize; | 567 return bm.width() > kMaxSize || bm.height() > kMaxSize; |
| 564 } | 568 } |
| 565 | 569 |
| 566 SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm
al, | 570 SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm
al, |
| 567 const SkLightingShader::Light& light, | 571 const SkLightingShader::Light& light, |
| 568 const SkColor ambient) { | 572 const SkColor ambient, |
| 573 const SkMatrix* localMatrix) { |
| 569 if (diffuse.isNull() || bitmap_is_too_big(diffuse) || | 574 if (diffuse.isNull() || bitmap_is_too_big(diffuse) || |
| 570 normal.isNull() || bitmap_is_too_big(normal) || | 575 normal.isNull() || bitmap_is_too_big(normal) || |
| 571 diffuse.width() != normal.width() || | 576 diffuse.width() != normal.width() || |
| 572 diffuse.height() != normal.height()) { | 577 diffuse.height() != normal.height()) { |
| 573 return nullptr; | 578 return nullptr; |
| 574 } | 579 } |
| 575 | 580 |
| 576 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient)); | 581 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient, lo
calMatrix)); |
| 577 } | 582 } |
| 578 | 583 |
| 579 /////////////////////////////////////////////////////////////////////////////// | 584 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |