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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 void* storage) const { | 458 void* storage) const { |
459 | 459 |
460 size_t heapRequired = fDiffuseShader->contextSize(rec) + fNormalSource->prov
iderSize(rec); | 460 size_t heapRequired = fDiffuseShader->contextSize(rec) + fNormalSource->prov
iderSize(rec); |
461 void* heapAllocated = malloc(heapRequired); // Freed on ~LightingShaderConte
xt() | 461 void* heapAllocated = malloc(heapRequired); // Freed on ~LightingShaderConte
xt() |
462 | 462 |
463 void* diffuseContextStorage = (char*)heapAllocated; | 463 void* diffuseContextStorage = (char*)heapAllocated; |
464 | 464 |
465 SkShader::Context* diffuseContext = fDiffuseShader->createContext(rec, diffu
seContextStorage); | 465 SkShader::Context* diffuseContext = fDiffuseShader->createContext(rec, diffu
seContextStorage); |
466 | 466 |
467 void* normalProviderStorage = (char*)heapAllocated + fDiffuseShader->context
Size(rec); | 467 void* normalProviderStorage = (char*)heapAllocated + fDiffuseShader->context
Size(rec); |
468 SkNormalSource::Provider* normalProvider = | 468 SkNormalSource::Provider* normalProvider = fNormalSource->asProvider(rec, |
469 fNormalSource->asProvider(rec, normalProviderStorage); | 469 normalP
roviderStorage); |
470 if (!normalProvider) { | 470 if (!normalProvider) { |
471 diffuseContext->~Context(); | 471 diffuseContext->~Context(); |
472 free(heapAllocated); | 472 free(heapAllocated); |
473 return nullptr; | 473 return nullptr; |
474 } | 474 } |
475 | 475 |
476 return new (storage) LightingShaderContext(*this, rec, diffuseContext, norma
lProvider, | 476 return new (storage) LightingShaderContext(*this, rec, diffuseContext, norma
lProvider, |
477 heapAllocated); | 477 heapAllocated); |
478 } | 478 } |
479 | 479 |
480 /////////////////////////////////////////////////////////////////////////////// | 480 /////////////////////////////////////////////////////////////////////////////// |
481 | 481 |
482 sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse, sk_sp<SkLights>
lights, | 482 sk_sp<SkShader> SkLightingShader::Make(sk_sp<SkShader> diffuseShader, |
483 const SkMatrix* diffLocalM, sk_sp<SkNormalSource> normalSource) { | 483 sk_sp<SkNormalSource> normalSource, sk_sp<SkLights> lights) { |
484 if (diffuse.isNull() || SkBitmapProcShader::BitmapIsTooBig(diffuse)) { | 484 if (!diffuseShader || !normalSource) { |
485 return nullptr; | 485 // TODO: Use paint's color in absence of a diffuseShader |
486 } | |
487 | |
488 if (!normalSource) { | |
489 // TODO: Use a default implementation of normalSource instead | 486 // TODO: Use a default implementation of normalSource instead |
490 return nullptr; | 487 return nullptr; |
491 } | 488 } |
492 | 489 |
493 // TODO: support other tile modes | |
494 sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(diffuse
, | |
495 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, diffLocalM); | |
496 | |
497 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move(
normalSource), | 490 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move(
normalSource), |
498 std::move(lights)); | 491 std::move(lights)); |
499 } | 492 } |
500 | 493 |
501 /////////////////////////////////////////////////////////////////////////////// | 494 /////////////////////////////////////////////////////////////////////////////// |
502 | 495 |
503 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 496 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
504 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 497 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
505 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 498 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
506 | 499 |
507 /////////////////////////////////////////////////////////////////////////////// | 500 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |