Title: [213806] releases/WebKitGTK/webkit-2.16/Source/WebCore
Revision
213806
Author
[email protected]
Date
2017-03-13 03:31:43 -0700 (Mon, 13 Mar 2017)

Log Message

Merge r213404 - Clean up RenderImage and a RenderImageResource function
https://bugs.webkit.org/show_bug.cgi?id=169153

Reviewed by Zalan Bujtas.

Change all calls to imageResource().cachedImage() in RenderImage to use the inline
cachedImage() function.

In RenderImage::paintReplaced(), early return after the broken image block (and no need
to test imageResource().hasImage() again in the second condition). Convert height/width to size,
which also forces us to be explicit about using flooredIntSize() when fetching the image
(perhaps this should be a roundedIntSize, but I didn't want to change behavior).

Change RenderImageResource::image() to take an IntSize, rather than int height and width.

No behavior change.

* rendering/RenderImage.cpp:
(WebCore::RenderImage::styleDidChange):
(WebCore::RenderImage::imageChanged):
(WebCore::RenderImage::notifyFinished):
(WebCore::RenderImage::paintReplaced):
(WebCore::RenderImage::paintIntoRect):
(WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect):
(WebCore::RenderImage::embeddedContentBox):
* rendering/RenderImageResource.cpp:
(WebCore::RenderImageResource::image):
* rendering/RenderImageResource.h:
(WebCore::RenderImageResource::image):
* rendering/RenderImageResourceStyleImage.cpp:
(WebCore::RenderImageResourceStyleImage::image):
* rendering/RenderImageResourceStyleImage.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog	2017-03-13 10:31:43 UTC (rev 213806)
@@ -1,3 +1,38 @@
+2017-03-03  Simon Fraser  <[email protected]>
+
+        Clean up RenderImage and a RenderImageResource function
+        https://bugs.webkit.org/show_bug.cgi?id=169153
+
+        Reviewed by Zalan Bujtas.
+        
+        Change all calls to imageResource().cachedImage() in RenderImage to use the inline
+        cachedImage() function.
+
+        In RenderImage::paintReplaced(), early return after the broken image block (and no need
+        to test imageResource().hasImage() again in the second condition). Convert height/width to size,
+        which also forces us to be explicit about using flooredIntSize() when fetching the image
+        (perhaps this should be a roundedIntSize, but I didn't want to change behavior).
+
+        Change RenderImageResource::image() to take an IntSize, rather than int height and width.
+
+        No behavior change.
+
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::styleDidChange):
+        (WebCore::RenderImage::imageChanged):
+        (WebCore::RenderImage::notifyFinished):
+        (WebCore::RenderImage::paintReplaced):
+        (WebCore::RenderImage::paintIntoRect):
+        (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect):
+        (WebCore::RenderImage::embeddedContentBox):
+        * rendering/RenderImageResource.cpp:
+        (WebCore::RenderImageResource::image):
+        * rendering/RenderImageResource.h:
+        (WebCore::RenderImageResource::image):
+        * rendering/RenderImageResourceStyleImage.cpp:
+        (WebCore::RenderImageResourceStyleImage::image):
+        * rendering/RenderImageResourceStyleImage.h:
+
 2017-03-03  Alex Christensen  <[email protected]>
 
         [URLParser] Fix file: as a relative file URL

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImage.cpp (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImage.cpp	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImage.cpp	2017-03-13 10:31:43 UTC (rev 213806)
@@ -210,7 +210,7 @@
 {
     RenderReplaced::styleDidChange(diff, oldStyle);
     if (m_needsToSetSizeForAltText) {
-        if (!m_altText.isEmpty() && setImageSizeForAltText(imageResource().cachedImage()))
+        if (!m_altText.isEmpty() && setImageSizeForAltText(cachedImage()))
             repaintOrMarkForLayout(ImageSizeChangeForAltText);
         m_needsToSetSizeForAltText = false;
     }
@@ -257,7 +257,7 @@
             }
             return;
         }
-        imageSizeChange = setImageSizeForAltText(imageResource().cachedImage());
+        imageSizeChange = setImageSizeForAltText(cachedImage());
     }
 
     if (UNLIKELY(AXObjectCache::accessibilityEnabled())) {
@@ -342,7 +342,7 @@
 
     invalidateBackgroundObscurationStatus();
 
-    if (&newImage == imageResource().cachedImage()) {
+    if (&newImage == cachedImage()) {
         // tell any potential compositing layers
         // that the image is done and they can reference it directly.
         contentChanged(ImageChanged);
@@ -351,12 +351,7 @@
 
 void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
-    LayoutUnit cWidth = contentWidth();
-    LayoutUnit cHeight = contentHeight();
-    LayoutUnit leftBorder = borderLeft();
-    LayoutUnit topBorder = borderTop();
-    LayoutUnit leftPad = paddingLeft();
-    LayoutUnit topPad = paddingTop();
+    LayoutSize contentSize = this->contentSize();
 
     GraphicsContext& context = paintInfo.context();
     float deviceScaleFactor = document().deviceScaleFactor();
@@ -368,35 +363,39 @@
         if (paintInfo.phase == PaintPhaseForeground)
             page().addRelevantUnpaintedObject(this, visualOverflowRect());
 
-        if (cWidth > 2 && cHeight > 2) {
+        if (contentSize.width() > 2 && contentSize.height() > 2) {
             LayoutUnit borderWidth = LayoutUnit(1 / deviceScaleFactor);
 
+            LayoutUnit leftBorder = borderLeft();
+            LayoutUnit topBorder = borderTop();
+            LayoutUnit leftPad = paddingLeft();
+            LayoutUnit topPad = paddingTop();
+
             // Draw an outline rect where the image should be.
             context.setStrokeStyle(SolidStroke);
             context.setStrokeColor(Color::lightGray);
             context.setFillColor(Color::transparent);
-            context.drawRect(snapRectToDevicePixels(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight), deviceScaleFactor), borderWidth);
+            context.drawRect(snapRectToDevicePixels(LayoutRect({ paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad }, contentSize), deviceScaleFactor), borderWidth);
 
             bool errorPictureDrawn = false;
             LayoutSize imageOffset;
             // When calculating the usable dimensions, exclude the pixels of
             // the ouline rect so the error image/alt text doesn't draw on it.
-            LayoutUnit usableWidth = cWidth - 2 * borderWidth;
-            LayoutUnit usableHeight = cHeight - 2 * borderWidth;
+            LayoutSize usableSize = contentSize - LayoutSize(2 * borderWidth, 2 * borderWidth);
 
             RefPtr<Image> image = imageResource().image();
 
-            if (imageResource().errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
+            if (imageResource().errorOccurred() && !image->isNull() && usableSize.width() >= image->width() && usableSize.height() >= image->height()) {
                 // Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
-                std::pair<Image*, float> brokenImageAndImageScaleFactor = imageResource().cachedImage()->brokenImage(document().deviceScaleFactor());
+                std::pair<Image*, float> brokenImageAndImageScaleFactor = cachedImage()->brokenImage(document().deviceScaleFactor());
                 image = brokenImageAndImageScaleFactor.first;
                 FloatSize imageSize = image->size();
                 imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
                 // Center the error image, accounting for border and padding.
-                LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
+                LayoutUnit centerX = (usableSize.width() - imageSize.width()) / 2;
                 if (centerX < 0)
                     centerX = 0;
-                LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
+                LayoutUnit centerY = (usableSize.height() - imageSize.height()) / 2;
                 if (centerY < 0)
                     centerY = 0;
                 imageOffset = LayoutSize(leftBorder + leftPad + centerX + borderWidth, topBorder + topPad + centerY + borderWidth);
@@ -423,40 +422,44 @@
                 TextRun textRun = RenderBlock::constructTextRun(text, style());
                 LayoutUnit textWidth = font.width(textRun);
                 if (errorPictureDrawn) {
-                    if (usableWidth >= textWidth && fontMetrics.height() <= imageOffset.height())
+                    if (usableSize.width() >= textWidth && fontMetrics.height() <= imageOffset.height())
                         context.drawText(font, textRun, altTextOffset);
-                } else if (usableWidth >= textWidth && usableHeight >= fontMetrics.height())
+                } else if (usableSize.width() >= textWidth && usableSize.height() >= fontMetrics.height())
                     context.drawText(font, textRun, altTextOffset);
             }
         }
-    } else if (imageResource().hasImage() && cWidth > 0 && cHeight > 0) {
-        RefPtr<Image> img = imageResource().image(cWidth, cHeight);
-        if (!img || img->isNull()) {
-            if (paintInfo.phase == PaintPhaseForeground)
-                page().addRelevantUnpaintedObject(this, visualOverflowRect());
-            return;
-        }
+        return;
+    }
+    
+    if (contentSize.isEmpty())
+        return;
 
-        LayoutRect contentBoxRect = this->contentBoxRect();
-        contentBoxRect.moveBy(paintOffset);
-        LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize());
-        replacedContentRect.moveBy(paintOffset);
-        bool clip = !contentBoxRect.contains(replacedContentRect);
-        GraphicsContextStateSaver stateSaver(context, clip);
-        if (clip)
-            context.clip(contentBoxRect);
+    RefPtr<Image> img = imageResource().image(flooredIntSize(contentSize));
+    if (!img || img->isNull()) {
+        if (paintInfo.phase == PaintPhaseForeground)
+            page().addRelevantUnpaintedObject(this, visualOverflowRect());
+        return;
+    }
 
-        paintIntoRect(context, snapRectToDevicePixels(replacedContentRect, deviceScaleFactor));
-        
-        if (cachedImage() && paintInfo.phase == PaintPhaseForeground) {
-            // For now, count images as unpainted if they are still progressively loading. We may want 
-            // to refine this in the future to account for the portion of the image that has painted.
-            LayoutRect visibleRect = intersection(replacedContentRect, contentBoxRect);
-            if (cachedImage()->isLoading())
-                page().addRelevantUnpaintedObject(this, visibleRect);
-            else
-                page().addRelevantRepaintedObject(this, visibleRect);
-        }
+    LayoutRect contentBoxRect = this->contentBoxRect();
+    contentBoxRect.moveBy(paintOffset);
+    LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize());
+    replacedContentRect.moveBy(paintOffset);
+    bool clip = !contentBoxRect.contains(replacedContentRect);
+    GraphicsContextStateSaver stateSaver(context, clip);
+    if (clip)
+        context.clip(contentBoxRect);
+
+    paintIntoRect(context, snapRectToDevicePixels(replacedContentRect, deviceScaleFactor));
+    
+    if (cachedImage() && paintInfo.phase == PaintPhaseForeground) {
+        // For now, count images as unpainted if they are still progressively loading. We may want 
+        // to refine this in the future to account for the portion of the image that has painted.
+        LayoutRect visibleRect = intersection(replacedContentRect, contentBoxRect);
+        if (cachedImage()->isLoading())
+            page().addRelevantUnpaintedObject(this, visibleRect);
+        else
+            page().addRelevantRepaintedObject(this, visibleRect);
     }
 }
 
@@ -536,7 +539,7 @@
     if (!imageResource().hasImage() || imageResource().errorOccurred() || rect.width() <= 0 || rect.height() <= 0)
         return;
 
-    RefPtr<Image> img = imageResource().image(rect.width(), rect.height());
+    RefPtr<Image> img = imageResource().image(flooredIntSize(rect.size()));
     if (!img || img->isNull())
         return;
 
@@ -569,7 +572,7 @@
     UNUSED_PARAM(maxDepthToTest);
     if (!imageResource().hasImage() || imageResource().errorOccurred())
         return false;
-    if (imageResource().cachedImage() && !imageResource().cachedImage()->isLoaded())
+    if (cachedImage() && !cachedImage()->isLoaded())
         return false;
     if (!contentBoxRect().contains(localRect))
         return false;
@@ -590,7 +593,7 @@
         return false;
 
     // Check for image with alpha.
-    return imageResource().cachedImage() && imageResource().cachedImage()->currentFrameKnownToBeOpaque(this);
+    return cachedImage() && cachedImage()->currentFrameKnownToBeOpaque(this);
 }
 
 bool RenderImage::computeBackgroundIsKnownToBeObscured(const LayoutPoint& paintOffset)
@@ -741,7 +744,7 @@
 
 RenderBox* RenderImage::embeddedContentBox() const
 {
-    CachedImage* cachedImage = imageResource().cachedImage();
+    CachedImage* cachedImage = this->cachedImage();
     if (cachedImage && is<SVGImage>(cachedImage->image()))
         return downcast<SVGImage>(*cachedImage->image()).embeddedContentBox();
 

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.cpp (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.cpp	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.cpp	2017-03-13 10:31:43 UTC (rev 213806)
@@ -92,7 +92,7 @@
         m_renderer->repaint();
 }
 
-RefPtr<Image> RenderImageResource::image(int, int) const
+RefPtr<Image> RenderImageResource::image(const IntSize&) const
 {
     return m_cachedImage ? m_cachedImage->imageForRenderer(m_renderer) : Image::nullImage();
 }

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.h (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.h	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResource.h	2017-03-13 10:31:43 UTC (rev 213806)
@@ -49,7 +49,7 @@
 
     void resetAnimation();
 
-    virtual RefPtr<Image> image(int width = 0, int height = 0) const;
+    virtual RefPtr<Image> image(const IntSize& size = { }) const;
     virtual bool errorOccurred() const;
 
     virtual void setContainerSizeForRenderer(const IntSize&);

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.cpp (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.cpp	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.cpp	2017-03-13 10:31:43 UTC (rev 213806)
@@ -63,12 +63,12 @@
     }
 }
 
-RefPtr<Image> RenderImageResourceStyleImage::image(int width, int height) const
+RefPtr<Image> RenderImageResourceStyleImage::image(const IntSize& size) const
 {
     // Generated content may trigger calls to image() while we're still pending, don't assert but gracefully exit.
     if (m_styleImage->isPending())
         return nullptr;
-    return m_styleImage->image(m_renderer, IntSize(width, height));
+    return m_styleImage->image(m_renderer, size);
 }
 
 void RenderImageResourceStyleImage::setContainerSizeForRenderer(const IntSize& size)

Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.h (213805 => 213806)


--- releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.h	2017-03-13 10:28:29 UTC (rev 213805)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/rendering/RenderImageResourceStyleImage.h	2017-03-13 10:31:43 UTC (rev 213806)
@@ -43,7 +43,7 @@
     void shutdown() override;
 
     bool hasImage() const override { return true; }
-    RefPtr<Image> image(int width = 0, int height = 0) const override;
+    RefPtr<Image> image(const IntSize& = { }) const override;
     bool errorOccurred() const override { return m_styleImage->errorOccurred(); }
 
     void setContainerSizeForRenderer(const IntSize&) override;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to