<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[183960] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183960">183960</a></dd>
<dt>Author</dt> <dd>said@apple.com</dd>
<dt>Date</dt> <dd>2015-05-07 16:32:45 -0700 (Thu, 07 May 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Applying a filter on an SVG element, which is larger than 4096 pixels, causes this element to be rendered shifted to the left
https://bugs.webkit.org/show_bug.cgi?id=144335
Reviewed by Daniel Bates.
Address comments raised by Darin Adler in review.
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::sizeNeedsClamping):
(WebCore::ImageBuffer::clampedSize):
(WebCore::ImageBuffer::isSizeClamped): Deleted.
* platform/graphics/ImageBuffer.h:
The condition for the negative width/height in isSizeClamped() was wrong. Use
FloatSize::isEmpty() instead and rename the function to sizeNeedsClamping().
The new function should return the opposite of the old function return value.
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::apply):
(WebCore::FilterEffect::asUnmultipliedImage):
(WebCore::FilterEffect::asPremultipliedImage):
(WebCore::FilterEffect::copyUnmultipliedImage):
(WebCore::FilterEffect::copyPremultipliedImage):
(WebCore::FilterEffect::createUnmultipliedImageResult):
(WebCore::FilterEffect::createPremultipliedImageResult):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::updateBackingStoreRect):
(WebCore::FilterEffectRendererHelper::beginFilterEffect):
* rendering/svg/RenderSVGResourceFilter.cpp:
(WebCore::RenderSVGResourceFilter::applyResource):
Call the new function and negate the condition for the return value.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageBuffercpp">trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageBufferh">trunk/Source/WebCore/platform/graphics/ImageBuffer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfiltersFilterEffectcpp">trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingFilterEffectRenderercpp">trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgRenderSVGResourceFiltercpp">trunk/Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/ChangeLog        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2015-05-07 Said Abou-Hallawa <sabouhallawa@apple.com>
+
+ Applying a filter on an SVG element, which is larger than 4096 pixels, causes this element to be rendered shifted to the left
+ https://bugs.webkit.org/show_bug.cgi?id=144335
+
+ Reviewed by Daniel Bates.
+
+ Address comments raised by Darin Adler in review.
+
+ * platform/graphics/ImageBuffer.cpp:
+ (WebCore::ImageBuffer::sizeNeedsClamping):
+ (WebCore::ImageBuffer::clampedSize):
+ (WebCore::ImageBuffer::isSizeClamped): Deleted.
+ * platform/graphics/ImageBuffer.h:
+ The condition for the negative width/height in isSizeClamped() was wrong. Use
+ FloatSize::isEmpty() instead and rename the function to sizeNeedsClamping().
+ The new function should return the opposite of the old function return value.
+
+ * platform/graphics/filters/FilterEffect.cpp:
+ (WebCore::FilterEffect::apply):
+ (WebCore::FilterEffect::asUnmultipliedImage):
+ (WebCore::FilterEffect::asPremultipliedImage):
+ (WebCore::FilterEffect::copyUnmultipliedImage):
+ (WebCore::FilterEffect::copyPremultipliedImage):
+ (WebCore::FilterEffect::createUnmultipliedImageResult):
+ (WebCore::FilterEffect::createPremultipliedImageResult):
+ * rendering/FilterEffectRenderer.cpp:
+ (WebCore::FilterEffectRenderer::updateBackingStoreRect):
+ (WebCore::FilterEffectRendererHelper::beginFilterEffect):
+ * rendering/svg/RenderSVGResourceFilter.cpp:
+ (WebCore::RenderSVGResourceFilter::applyResource):
+ Call the new function and negate the condition for the return value.
+
</ins><span class="cx"> 2015-05-07 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Build fix.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -36,29 +36,26 @@
</span><span class="cx"> static const float MaxClampedLength = 4096;
</span><span class="cx"> static const float MaxClampedArea = MaxClampedLength * MaxClampedLength;
</span><span class="cx">
</span><del>-bool ImageBuffer::isSizeClamped(const FloatSize& size)
</del><ins>+bool ImageBuffer::sizeNeedsClamping(const FloatSize& size)
</ins><span class="cx"> {
</span><del>- if (size.width() < 0 && size.height() < 0)
</del><ins>+ if (size.isEmpty())
</ins><span class="cx"> return false;
</span><span class="cx">
</span><del>- if (size.isEmpty())
- return true;
-
- return floorf(size.height()) * floorf(size.width()) <= MaxClampedArea;
</del><ins>+ return floorf(size.height()) * floorf(size.width()) > MaxClampedArea;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool ImageBuffer::isSizeClamped(const FloatSize& size, FloatSize& scale)
</del><ins>+bool ImageBuffer::sizeNeedsClamping(const FloatSize& size, FloatSize& scale)
</ins><span class="cx"> {
</span><span class="cx"> FloatSize scaledSize(size);
</span><span class="cx"> scaledSize.scale(scale.width(), scale.height());
</span><span class="cx">
</span><del>- if (isSizeClamped(scaledSize))
- return true;
</del><ins>+ if (!sizeNeedsClamping(scaledSize))
+ return false;
</ins><span class="cx">
</span><span class="cx"> // The area of scaled size is bigger than the upper limit, adjust the scale to fit.
</span><span class="cx"> scale.scale(sqrtf(MaxClampedArea / (scaledSize.width() * scaledSize.height())));
</span><del>- ASSERT(isSizeClamped(size, scale));
- return false;
</del><ins>+ ASSERT(!sizeNeedsClamping(size, scale));
+ return true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> FloatSize ImageBuffer::clampedSize(const FloatSize& size)
</span><span class="lines">@@ -73,8 +70,8 @@
</span><span class="cx">
</span><span class="cx"> FloatSize clampedSize = ImageBuffer::clampedSize(size);
</span><span class="cx"> scale = FloatSize(clampedSize.width() / size.width(), clampedSize.height() / size.height());
</span><del>- ASSERT(isSizeClamped(clampedSize));
- ASSERT(isSizeClamped(size, scale));
</del><ins>+ ASSERT(!sizeNeedsClamping(clampedSize));
+ ASSERT(!sizeNeedsClamping(size, scale));
</ins><span class="cx"> return clampedSize;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -126,8 +126,8 @@
</span><span class="cx"> void setSpaceSize(const FloatSize& space) { m_space = space; }
</span><span class="cx">
</span><span class="cx"> // These functions are used when clamping the ImageBuffer which is created for filter, masker or clipper.
</span><del>- static bool isSizeClamped(const FloatSize&);
- static bool isSizeClamped(const FloatSize&, FloatSize& scale);
</del><ins>+ static bool sizeNeedsClamping(const FloatSize&);
+ static bool sizeNeedsClamping(const FloatSize&, FloatSize& scale);
</ins><span class="cx"> static FloatSize clampedSize(const FloatSize&);
</span><span class="cx"> static FloatSize clampedSize(const FloatSize&, FloatSize& scale);
</span><span class="cx"> static FloatRect clampedRect(const FloatRect&);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfiltersFilterEffectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -147,7 +147,7 @@
</span><span class="cx"> determineAbsolutePaintRect();
</span><span class="cx"> setResultColorSpace(m_operatingColorSpace);
</span><span class="cx">
</span><del>- if (m_absolutePaintRect.isEmpty() || !ImageBuffer::isSizeClamped(m_absolutePaintRect.size()))
</del><ins>+ if (m_absolutePaintRect.isEmpty() || ImageBuffer::sizeNeedsClamping(m_absolutePaintRect.size()))
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> if (requiresValidPreMultipliedPixels()) {
</span><span class="lines">@@ -313,7 +313,7 @@
</span><span class="cx"> PassRefPtr<Uint8ClampedArray> FilterEffect::asUnmultipliedImage(const IntRect& rect)
</span><span class="cx"> {
</span><span class="cx"> IntSize scaledSize(rect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(scaledSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(scaledSize));
</ins><span class="cx"> scaledSize.scale(m_filter.filterScale());
</span><span class="cx"> RefPtr<Uint8ClampedArray> imageData = Uint8ClampedArray::createUninitialized(scaledSize.width() * scaledSize.height() * 4);
</span><span class="cx"> copyUnmultipliedImage(imageData.get(), rect);
</span><span class="lines">@@ -323,7 +323,7 @@
</span><span class="cx"> PassRefPtr<Uint8ClampedArray> FilterEffect::asPremultipliedImage(const IntRect& rect)
</span><span class="cx"> {
</span><span class="cx"> IntSize scaledSize(rect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(scaledSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(scaledSize));
</ins><span class="cx"> scaledSize.scale(m_filter.filterScale());
</span><span class="cx"> RefPtr<Uint8ClampedArray> imageData = Uint8ClampedArray::createUninitialized(scaledSize.width() * scaledSize.height() * 4);
</span><span class="cx"> copyPremultipliedImage(imageData.get(), rect);
</span><span class="lines">@@ -389,7 +389,7 @@
</span><span class="cx"> m_unmultipliedImageResult = m_imageBufferResult->getUnmultipliedImageData(IntRect(IntPoint(), m_absolutePaintRect.size()));
</span><span class="cx"> else {
</span><span class="cx"> IntSize inputSize(m_absolutePaintRect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(inputSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
</ins><span class="cx"> inputSize.scale(m_filter.filterScale());
</span><span class="cx"> m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized(inputSize.width() * inputSize.height() * 4);
</span><span class="cx"> unsigned char* sourceComponent = m_premultipliedImageResult->data();
</span><span class="lines">@@ -425,7 +425,7 @@
</span><span class="cx"> m_premultipliedImageResult = m_imageBufferResult->getPremultipliedImageData(IntRect(IntPoint(), m_absolutePaintRect.size()));
</span><span class="cx"> else {
</span><span class="cx"> IntSize inputSize(m_absolutePaintRect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(inputSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
</ins><span class="cx"> inputSize.scale(m_filter.filterScale());
</span><span class="cx"> m_premultipliedImageResult = Uint8ClampedArray::createUninitialized(inputSize.width() * inputSize.height() * 4);
</span><span class="cx"> unsigned char* sourceComponent = m_unmultipliedImageResult->data();
</span><span class="lines">@@ -469,7 +469,7 @@
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><span class="cx"> IntSize resultSize(m_absolutePaintRect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(resultSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
</ins><span class="cx"> resultSize.scale(m_filter.filterScale());
</span><span class="cx"> m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized(resultSize.width() * resultSize.height() * 4);
</span><span class="cx"> return m_unmultipliedImageResult.get();
</span><span class="lines">@@ -483,7 +483,7 @@
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><span class="cx"> IntSize resultSize(m_absolutePaintRect.size());
</span><del>- ASSERT(ImageBuffer::isSizeClamped(resultSize));
</del><ins>+ ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
</ins><span class="cx"> resultSize.scale(m_filter.filterScale());
</span><span class="cx"> m_premultipliedImageResult = Uint8ClampedArray::createUninitialized(resultSize.width() * resultSize.height() * 4);
</span><span class="cx"> return m_premultipliedImageResult.get();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingFilterEffectRenderercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -305,7 +305,7 @@
</span><span class="cx">
</span><span class="cx"> bool FilterEffectRenderer::updateBackingStoreRect(const FloatRect& filterRect)
</span><span class="cx"> {
</span><del>- if (filterRect.isEmpty() || !ImageBuffer::isSizeClamped(filterRect.size()))
</del><ins>+ if (filterRect.isEmpty() || ImageBuffer::sizeNeedsClamping(filterRect.size()))
</ins><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> if (filterRect == sourceImageRect())
</span><span class="lines">@@ -401,7 +401,7 @@
</span><span class="cx"> filter->allocateBackingStoreIfNeeded();
</span><span class="cx"> // Paint into the context that represents the SourceGraphic of the filter.
</span><span class="cx"> GraphicsContext* sourceGraphicsContext = filter->inputContext();
</span><del>- if (!sourceGraphicsContext || filter->filterRegion().isEmpty() || !ImageBuffer::isSizeClamped(filter->filterRegion().size())) {
</del><ins>+ if (!sourceGraphicsContext || filter->filterRegion().isEmpty() || ImageBuffer::sizeNeedsClamping(filter->filterRegion().size())) {
</ins><span class="cx"> // Disable the filters and continue.
</span><span class="cx"> m_haveFilterEffect = false;
</span><span class="cx"> return false;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgRenderSVGResourceFiltercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp (183959 => 183960)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp        2015-05-07 23:29:15 UTC (rev 183959)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp        2015-05-07 23:32:45 UTC (rev 183960)
</span><span class="lines">@@ -151,7 +151,7 @@
</span><span class="cx">
</span><span class="cx"> // Determine scale factor for filter. The size of intermediate ImageBuffers shouldn't be bigger than kMaxFilterSize.
</span><span class="cx"> FloatRect tempSourceRect = absoluteDrawingRegion;
</span><del>- ImageBuffer::isSizeClamped(tempSourceRect.size(), scale);
</del><ins>+ ImageBuffer::sizeNeedsClamping(tempSourceRect.size(), scale);
</ins><span class="cx"> tempSourceRect.scale(scale.width(), scale.height());
</span><span class="cx">
</span><span class="cx"> // Set the scale level in SVGFilter.
</span><span class="lines">@@ -166,7 +166,7 @@
</span><span class="cx"> FloatRect subRegion = lastEffect->maxEffectRect();
</span><span class="cx"> // At least one FilterEffect has a too big image size,
</span><span class="cx"> // recalculate the effect sizes with new scale factors.
</span><del>- if (!ImageBuffer::isSizeClamped(subRegion.size(), scale)) {
</del><ins>+ if (ImageBuffer::sizeNeedsClamping(subRegion.size(), scale)) {
</ins><span class="cx"> filterData->filter->setFilterResolution(scale);
</span><span class="cx"> RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(*lastEffect);
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>