Title: [95103] trunk/Source/WebCore
Revision
95103
Author
[email protected]
Date
2011-09-14 11:35:49 -0700 (Wed, 14 Sep 2011)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=68054
Return an image scale factor as well as an Image* from CachedImage::brokenImage()

Reviewed by Darin Adler.

CachedImage::brokenImage() now returns a pair<Image*, float> where the float 
represents the image's scale factor. This is important because currently, the 
broken image will either be only 1x or 2x, but a deviceScaleFactor could 
theoretically be something different (1.5, 3, etc). So it is not safe to assume 
that the image's scale factor is equivalent to the deviceScaleFactor, and 
hardcoding 2 for now is lame.
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::brokenImage):
(WebCore::CachedImage::image):
* loader/cache/CachedImage.h:
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageSizeForError):
(WebCore::RenderImage::paintReplaced):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (95102 => 95103)


--- trunk/Source/WebCore/ChangeLog	2011-09-14 18:27:23 UTC (rev 95102)
+++ trunk/Source/WebCore/ChangeLog	2011-09-14 18:35:49 UTC (rev 95103)
@@ -1,3 +1,24 @@
+2011-09-14  Beth Dakin  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=68054
+        Return an image scale factor as well as an Image* from CachedImage::brokenImage()
+
+        Reviewed by Darin Adler.
+
+        CachedImage::brokenImage() now returns a pair<Image*, float> where the float 
+        represents the image's scale factor. This is important because currently, the 
+        broken image will either be only 1x or 2x, but a deviceScaleFactor could 
+        theoretically be something different (1.5, 3, etc). So it is not safe to assume 
+        that the image's scale factor is equivalent to the deviceScaleFactor, and 
+        hardcoding 2 for now is lame.
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::brokenImage):
+        (WebCore::CachedImage::image):
+        * loader/cache/CachedImage.h:
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::imageSizeForError):
+        (WebCore::RenderImage::paintReplaced):
+
 2011-09-14  James Robinson  <[email protected]>
 
         [chromium] Move contents texture manager from LayerRendererChromium to CCLayerTreeHost

Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (95102 => 95103)


--- trunk/Source/WebCore/loader/cache/CachedImage.cpp	2011-09-14 18:27:23 UTC (rev 95102)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp	2011-09-14 18:35:49 UTC (rev 95103)
@@ -113,15 +113,15 @@
         m_decodedDataDeletionTimer.startOneShot(interval);
 }
 
-Image* CachedImage::brokenImage(float deviceScaleFactor) const
+pair<Image*, float> CachedImage::brokenImage(float deviceScaleFactor) const
 {
     if (deviceScaleFactor >= 2) {
         DEFINE_STATIC_LOCAL(Image*, brokenImageHiRes, (Image::loadPlatformResource("missingImage@2x").leakRef()));
-        return brokenImageHiRes;
+        return make_pair(brokenImageHiRes, 2);
     }
 
     DEFINE_STATIC_LOCAL(Image*, brokenImageLoRes, (Image::loadPlatformResource("missingImage").leakRef()));
-    return brokenImageLoRes;
+    return make_pair(brokenImageLoRes, 1);
 }
 
 bool CachedImage::willPaintBrokenImage() const
@@ -137,7 +137,7 @@
         // Returning the 1x broken image is non-ideal, but we cannot reliably access the appropriate
         // deviceScaleFactor from here. It is critical that callers use CachedImage::brokenImage() 
         // when they need the real, deviceScaleFactor-appropriate broken image icon. 
-        return brokenImage(1);
+        return brokenImage(1).first;
     }
 
     if (m_image)

Modified: trunk/Source/WebCore/loader/cache/CachedImage.h (95102 => 95103)


--- trunk/Source/WebCore/loader/cache/CachedImage.h	2011-09-14 18:27:23 UTC (rev 95102)
+++ trunk/Source/WebCore/loader/cache/CachedImage.h	2011-09-14 18:35:49 UTC (rev 95103)
@@ -47,7 +47,7 @@
     Image* image() const; // Returns the nullImage() if the image is not available yet.
     bool hasImage() const { return m_image.get(); }
 
-    Image* brokenImage(float deviceScaleFactor) const;
+    std::pair<Image*, float> brokenImage(float deviceScaleFactor) const; // Returns an image and the image's resolution scale factor.
     bool willPaintBrokenImage() const; 
 
     bool canRender(float multiplier) const { return !errorOccurred() && !imageSize(multiplier).isEmpty(); }

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (95102 => 95103)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2011-09-14 18:27:23 UTC (rev 95102)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2011-09-14 18:35:49 UTC (rev 95103)
@@ -87,16 +87,9 @@
     IntSize imageSize;
     if (newImage->willPaintBrokenImage()) {
         float deviceScaleFactor = Page::deviceScaleFactor(frame());
-        imageSize = newImage->brokenImage(deviceScaleFactor)->size();
-        if (deviceScaleFactor >= 2) {
-            // It is important to scale by 0.5 instead of the deviceScaleFactor because the
-            // high resolution broken image artwork is actually a 2x image. We should 
-            // consider adding functionality to Image to ask about the image's resolution,
-            // and then we could scale by 1 / resolution. This is a solution that would
-            // scale better since this hardcoded number will have to change if we ever get
-            // artwork at other, higher resolutions. 
-            imageSize.scale(0.5f);
-        }
+        pair<Image*, float> brokenImageAndImageScaleFactor = newImage->brokenImage(deviceScaleFactor);
+        imageSize = brokenImageAndImageScaleFactor.first->size();
+        imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
     } else
         imageSize = newImage->image()->size();
 
@@ -286,10 +279,10 @@
             if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
                 float deviceScaleFactor = Page::deviceScaleFactor(frame());
                 // Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
-                image = m_imageResource->cachedImage()->brokenImage(deviceScaleFactor);
+                pair<Image*, float> brokenImageAndImageScaleFactor = m_imageResource->cachedImage()->brokenImage(deviceScaleFactor);
+                image = brokenImageAndImageScaleFactor.first;
                 IntSize imageSize = image->size();
-                if (deviceScaleFactor >= 2)
-                    imageSize.scale(0.5f);
+                imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
                 // Center the error image, accounting for border and padding.
                 LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
                 if (centerX < 0)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to