OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 sk_free(heapAllocated); | 481 sk_free(heapAllocated); |
482 return nullptr; | 482 return nullptr; |
483 } | 483 } |
484 | 484 |
485 return new (storage) LightingShaderContext(*this, rec, diffuseContext, norma
lProvider, | 485 return new (storage) LightingShaderContext(*this, rec, diffuseContext, norma
lProvider, |
486 heapAllocated); | 486 heapAllocated); |
487 } | 487 } |
488 | 488 |
489 /////////////////////////////////////////////////////////////////////////////// | 489 /////////////////////////////////////////////////////////////////////////////// |
490 | 490 |
491 sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse, | 491 sk_sp<SkShader> SkLightingShader::Make(sk_sp<SkShader> diffuseShader, |
492 sk_sp<SkLights> lights, | 492 sk_sp<SkNormalSource> normalSource, |
493 const SkMatrix* diffLocalM, | 493 sk_sp<SkLights> lights) { |
494 sk_sp<SkNormalSource> normalSource) { | 494 if (!diffuseShader || !normalSource) { |
495 if (diffuse.isNull() || SkBitmapProcShader::BitmapIsTooBig(diffuse)) { | 495 // TODO: Use paint's color in absence of a diffuseShader |
496 return nullptr; | |
497 } | |
498 | |
499 if (!normalSource) { | |
500 // TODO: Use a default implementation of normalSource instead | 496 // TODO: Use a default implementation of normalSource instead |
501 return nullptr; | 497 return nullptr; |
502 } | 498 } |
503 | 499 |
504 // TODO: support other tile modes | |
505 sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(diffuse
, | |
506 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, diffLocalM); | |
507 | |
508 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move(
normalSource), | 500 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move(
normalSource), |
509 std::move(lights)); | 501 std::move(lights)); |
510 } | 502 } |
511 | 503 |
512 /////////////////////////////////////////////////////////////////////////////// | 504 /////////////////////////////////////////////////////////////////////////////// |
513 | 505 |
514 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 506 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
515 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 507 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
516 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 508 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
517 | 509 |
518 /////////////////////////////////////////////////////////////////////////////// | 510 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |