Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: Source/platform/graphics/filters/FELighting.cpp

Issue 181943003: Scaling and offset fix for FELighting (software and skia paths) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/graphics/filters/FELighting.cpp
diff --git a/Source/platform/graphics/filters/FELighting.cpp b/Source/platform/graphics/filters/FELighting.cpp
index 4214ba9f4520448aaef9d6208b17cc1db0133189..f14f271db60122fd3202449da5ff6c59cbc8d167 100644
--- a/Source/platform/graphics/filters/FELighting.cpp
+++ b/Source/platform/graphics/filters/FELighting.cpp
@@ -187,7 +187,9 @@ inline void FELighting::LightingData::bottomRight(int offset, IntPoint& normalVe
inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSource::PaintingData& paintingData,
int lightX, int lightY, float factorX, float factorY, IntPoint& normal2DVector)
{
- m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale);
+ float transformedLightX = (static_cast<float>(lightX) + data.originOffset.width()) / data.worldScale.x();
+ float transformedLightY = (static_cast<float>(lightY) + data.originOffset.height()) / data.worldScale.y();
+ m_lightSource->updatePaintingData(paintingData, transformedLightX, transformedLightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale * data.worldScale.z());
float lightStrength;
if (!normal2DVector.x() && !normal2DVector.y()) {
@@ -302,6 +304,20 @@ inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD
#endif
}
+void FELighting::getTransform(FloatSize* offset, FloatPoint3D* scale) const
+{
+ FloatRect initialEffectRect = effectBoundaries();
+ FloatRect absoluteEffectRect = filter()->mapLocalRectToAbsoluteRect(initialEffectRect);
+ FloatPoint absoluteLocation(absolutePaintRect().location());
+ FloatSize positionOffset(absoluteLocation - absoluteEffectRect.location());
+ offset->setWidth(positionOffset.width());
+ offset->setHeight(positionOffset.height());
+ scale->setX(initialEffectRect.width() > 0.0f && initialEffectRect.width() > 0.0f ? absoluteEffectRect.width() / initialEffectRect.width() : 1.0f);
+ scale->setY(initialEffectRect.height() > 0.0f && initialEffectRect.height() > 0.0f ? absoluteEffectRect.height() / initialEffectRect.height() : 1.0f);
+ // X and Y scale should be the same, but, if not, do a best effort by averaging the 2 for Z scale
+ scale->setZ(0.5f * (scale->x() + scale->y()));
+}
+
bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
{
LightSource::PaintingData paintingData;
@@ -320,6 +336,7 @@ bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
data.widthMultipliedByPixelSize = width * cPixelSize;
data.widthDecreasedByOne = width - 1;
data.heightDecreasedByOne = height - 1;
+ getTransform(&data.originOffset, &data.worldScale);
Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor);
paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green(), lightColor.blue());
m_lightSource->initPaintingData(paintingData);
@@ -439,15 +456,21 @@ PassRefPtr<SkImageFilter> FELighting::createImageFilter(SkiaImageFilterBuilder*
case LS_POINT: {
PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_lightSource.get());
FloatPoint3D position = pointLightSource->position();
- SkPoint3 skPosition(position.x(), position.y(), position.z());
+ FloatSize offset;
+ FloatPoint3D scale;
+ getTransform(&offset, &scale);
+ SkPoint3 skPosition(position.x() * scale.x() - offset.width(), position.y() * scale.y() - offset.height(), position.z() * scale.z());
Stephen White 2014/03/03 17:55:09 I don't think we should do this. I think we should
sugoi1 2014/03/03 20:29:30 Done.
if (m_specularConstant > 0)
return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosition, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent, input.get(), &rect));
return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect));
}
case LS_SPOT: {
SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_lightSource.get());
- SkPoint3 location(spotLightSource->position().x(), spotLightSource->position().y(), spotLightSource->position().z());
- SkPoint3 target(spotLightSource->direction().x(), spotLightSource->direction().y(), spotLightSource->direction().z());
+ FloatSize offset;
+ FloatPoint3D scale;
+ getTransform(&offset, &scale);
+ SkPoint3 location(spotLightSource->position().x() * scale.x() - offset.width(), spotLightSource->position().y() * scale.y() - offset.height(), spotLightSource->position().z() * scale.z());
+ SkPoint3 target(spotLightSource->direction().x() * scale.x() - offset.width(), spotLightSource->direction().y() * scale.y() - offset.height(), spotLightSource->direction().z() * scale.z());
Stephen White 2014/03/03 17:55:09 Same here.
sugoi1 2014/03/03 20:29:30 Done.
float specularExponent = spotLightSource->specularExponent();
float limitingConeAngle = spotLightSource->limitingConeAngle();
if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle < -90)

Powered by Google App Engine
This is Rietveld 408576698