| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 University of Szeged | 2 * Copyright (C) 2010 University of Szeged |
| 3 * Copyright (C) 2010 Zoltan Herczeg | 3 * Copyright (C) 2010 Zoltan Herczeg |
| 4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "platform/graphics/filters/FELighting.h" | 29 #include "platform/graphics/filters/FELighting.h" |
| 30 | 30 |
| 31 #include "SkLightingImageFilter.h" | 31 #include "SkLightingImageFilter.h" |
| 32 #include "SkPoint3.h" |
| 32 #include "platform/graphics/filters/DistantLightSource.h" | 33 #include "platform/graphics/filters/DistantLightSource.h" |
| 33 #include "platform/graphics/filters/PointLightSource.h" | 34 #include "platform/graphics/filters/PointLightSource.h" |
| 34 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 35 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 35 #include "platform/graphics/filters/SpotLightSource.h" | 36 #include "platform/graphics/filters/SpotLightSource.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 FELighting::FELighting(Filter* filter, LightingType lightingType, const Color& l
ightingColor, float surfaceScale, | 40 FELighting::FELighting(Filter* filter, LightingType lightingType, const Color& l
ightingColor, float surfaceScale, |
| 40 float diffuseConstant, float specularConstant, float specularExponent, | 41 float diffuseConstant, float specularConstant, float specularExponent, |
| 41 float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> li
ghtSource) | 42 float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> li
ghtSource) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 PassRefPtr<SkImageFilter> FELighting::createImageFilter(SkiaImageFilterBuilder*
builder) | 64 PassRefPtr<SkImageFilter> FELighting::createImageFilter(SkiaImageFilterBuilder*
builder) |
| 64 { | 65 { |
| 65 SkImageFilter::CropRect rect = getCropRect(builder ? builder->cropOffset() :
FloatSize()); | 66 SkImageFilter::CropRect rect = getCropRect(builder ? builder->cropOffset() :
FloatSize()); |
| 66 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); | 67 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); |
| 67 RefPtr<SkImageFilter> input(builder ? builder->build(inputEffect(0), operati
ngColorSpace()) : nullptr); | 68 RefPtr<SkImageFilter> input(builder ? builder->build(inputEffect(0), operati
ngColorSpace()) : nullptr); |
| 68 switch (m_lightSource->type()) { | 69 switch (m_lightSource->type()) { |
| 69 case LS_DISTANT: { | 70 case LS_DISTANT: { |
| 70 DistantLightSource* distantLightSource = static_cast<DistantLightSource*
>(m_lightSource.get()); | 71 DistantLightSource* distantLightSource = static_cast<DistantLightSource*
>(m_lightSource.get()); |
| 71 float azimuthRad = deg2rad(distantLightSource->azimuth()); | 72 float azimuthRad = deg2rad(distantLightSource->azimuth()); |
| 72 float elevationRad = deg2rad(distantLightSource->elevation()); | 73 float elevationRad = deg2rad(distantLightSource->elevation()); |
| 73 SkPoint3 direction(cosf(azimuthRad) * cosf(elevationRad), | 74 const SkPoint3 direction = SkPoint3::Make(cosf(azimuthRad) * cosf(elevat
ionRad), sinf(azimuthRad) * cosf(elevationRad), sinf(elevationRad)); |
| 74 sinf(azimuthRad) * cosf(elevationRad), | |
| 75 sinf(elevationRad)); | |
| 76 if (m_specularConstant > 0) | 75 if (m_specularConstant > 0) |
| 77 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire
ction, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); | 76 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire
ction, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); |
| 78 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction
, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); | 77 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction
, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
| 79 } | 78 } |
| 80 case LS_POINT: { | 79 case LS_POINT: { |
| 81 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li
ghtSource.get()); | 80 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li
ghtSource.get()); |
| 82 FloatPoint3D position = pointLightSource->position(); | 81 const FloatPoint3D position = pointLightSource->position(); |
| 83 SkPoint3 skPosition(position.x(), position.y(), position.z()); | 82 const SkPoint3 skPosition = SkPoint3::Make(position.x(), position.y(), p
osition.z()); |
| 84 if (m_specularConstant > 0) | 83 if (m_specularConstant > 0) |
| 85 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi
tion, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); | 84 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi
tion, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); |
| 86 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition,
lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); | 85 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition,
lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
| 87 } | 86 } |
| 88 case LS_SPOT: { | 87 case LS_SPOT: { |
| 89 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light
Source.get()); | 88 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light
Source.get()); |
| 90 SkPoint3 location(spotLightSource->position().x(), spotLightSource->posi
tion().y(), spotLightSource->position().z()); | 89 const SkPoint3 location = SkPoint3::Make(spotLightSource->position().x()
, spotLightSource->position().y(), spotLightSource->position().z()); |
| 91 SkPoint3 target(spotLightSource->direction().x(), spotLightSource->direc
tion().y(), spotLightSource->direction().z()); | 90 const SkPoint3 target = SkPoint3::Make(spotLightSource->direction().x(),
spotLightSource->direction().y(), spotLightSource->direction().z()); |
| 92 float specularExponent = spotLightSource->specularExponent(); | 91 float specularExponent = spotLightSource->specularExponent(); |
| 93 float limitingConeAngle = spotLightSource->limitingConeAngle(); | 92 float limitingConeAngle = spotLightSource->limitingConeAngle(); |
| 94 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle <
-90) | 93 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle <
-90) |
| 95 limitingConeAngle = 90; | 94 limitingConeAngle = 90; |
| 96 if (m_specularConstant > 0) | 95 if (m_specularConstant > 0) |
| 97 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio
n, target, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale
, m_specularConstant, m_specularExponent, input.get(), &rect)); | 96 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio
n, target, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale
, m_specularConstant, m_specularExponent, input.get(), &rect)); |
| 98 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta
rget, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale, m_d
iffuseConstant, input.get(), &rect)); | 97 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta
rget, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale, m_d
iffuseConstant, input.get(), &rect)); |
| 99 } | 98 } |
| 100 default: | 99 default: |
| 101 ASSERT_NOT_REACHED(); | 100 ASSERT_NOT_REACHED(); |
| 102 return nullptr; | 101 return nullptr; |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 | 104 |
| 106 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |