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

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: Changed fix to temporary light creation 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
« no previous file with comments | « Source/platform/graphics/filters/FELighting.h ('k') | Source/platform/graphics/filters/LightSource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..eba6e811226bec5f42cdb92d92b758883b6c72ac 100644
--- a/Source/platform/graphics/filters/FELighting.cpp
+++ b/Source/platform/graphics/filters/FELighting.cpp
@@ -187,7 +187,7 @@ 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);
+ data.lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale);
float lightStrength;
if (!normal2DVector.x() && !normal2DVector.y()) {
@@ -302,6 +302,20 @@ inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD
#endif
}
+void FELighting::getTransform(FloatPoint3D* scale, FloatSize* offset) 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,9 +334,14 @@ bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
data.widthMultipliedByPixelSize = width * cPixelSize;
data.widthDecreasedByOne = width - 1;
data.heightDecreasedByOne = height - 1;
+ FloatPoint3D worldScale;
+ FloatSize originOffset;
+ getTransform(&worldScale, &originOffset);
+ RefPtr<LightSource> lightSource = m_lightSource->create(worldScale, originOffset);
+ data.lightSource = lightSource.get();
Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor);
paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green(), lightColor.blue());
- m_lightSource->initPaintingData(paintingData);
+ data.lightSource->initPaintingData(paintingData);
// Top/Left corner.
IntPoint normalVector;
« no previous file with comments | « Source/platform/graphics/filters/FELighting.h ('k') | Source/platform/graphics/filters/LightSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698