<!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>[201424] 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/201424">201424</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-05-26 11:46:02 -0700 (Thu, 26 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>BitmapImage::checkForSolidColor() cleanup
https://bugs.webkit.org/show_bug.cgi?id=157750

Patch by Said Abou-Hallawa &lt;sabouhallawa@apple,com&gt; on 2016-05-26
Reviewed by Darin Adler.

Have a single implementation for BitmapImage::checkForSolidColor(). Create
a new function named NativeImage::solidColor() and call it from the former
one. The goal is to have the platform files contain only the platform dependent
code rather than repeating the platform independent code multiple times.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::destroyMetadataAndNotify): Invalidate m_solidColor.
(WebCore::BitmapImage::singlePixelSolidColor): Combine mayFillWithSolidColor(),
checkForSolidColor() and solidColor() in one function to guarantee the validity
of the returned value. Before, if solidColor() is called without calling
mayFillWithSolidColor() or checkForSolidColor(), the returned value would be
incorrect.

(WebCore::BitmapImage::dump): Use the m_solidColor Optional and Color states.
(WebCore::BitmapImage::mayFillWithSolidColor): Deleted.
(WebCore::BitmapImage::solidColor): Deleted.

* platform/graphics/BitmapImage.h: Delete m_checkedForSolidColor and
m_isSolidColor and change m_solidColor to be Optional&lt;Color&gt;.

* platform/graphics/Image.cpp:
(WebCore::Image::drawTiled): Use singlePixelSolidColor() and check the returned
value to know whether the singe pixel solid color optimization applies or not.

* platform/graphics/Image.h:
(WebCore::Image::singlePixelSolidColor):
(WebCore::Image::mayFillWithSolidColor): Deleted.
(WebCore::Image::solidColor): Deleted.
Replace mayFillWithSolidColor() and solidColor() with a single function named
singlePixelSolidColor(). isValid() of the returned Color can be used to tell
whether the singe pixel solid color optimization applies or not.

* platform/graphics/cairo/BitmapImageCairo.cpp:
(WebCore::NativeImage::singlePixelSolidColor):
(WebCore::BitmapImage::draw):
(WebCore::BitmapImage::checkForSolidColor): Deleted.
Delete the platform dependent BitmapImage::checkForSolidColor() and add
the new platform dependent function NativeImage::singlePixelSolidColor() and
use to know whether the singe pixel solid color optimization applies or not.

* platform/graphics/cg/BitmapImageCG.cpp:
(WebCore::NativeImage::singlePixelSolidColor):
(WebCore::BitmapImage::draw):
(WebCore::BitmapImage::checkForSolidColor): Deleted.
Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsBitmapImagecpp">trunk/Source/WebCore/platform/graphics/BitmapImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsBitmapImageh">trunk/Source/WebCore/platform/graphics/BitmapImage.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImagecpp">trunk/Source/WebCore/platform/graphics/Image.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageh">trunk/Source/WebCore/platform/graphics/Image.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoBitmapImageCairocpp">trunk/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgBitmapImageCGcpp">trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/ChangeLog        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2016-05-26  Said Abou-Hallawa  &lt;sabouhallawa@apple,com&gt;
+
+        BitmapImage::checkForSolidColor() cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=157750
+
+        Reviewed by Darin Adler.
+
+        Have a single implementation for BitmapImage::checkForSolidColor(). Create
+        a new function named NativeImage::solidColor() and call it from the former
+        one. The goal is to have the platform files contain only the platform dependent
+        code rather than repeating the platform independent code multiple times.
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::destroyMetadataAndNotify): Invalidate m_solidColor.
+        (WebCore::BitmapImage::singlePixelSolidColor): Combine mayFillWithSolidColor(),
+        checkForSolidColor() and solidColor() in one function to guarantee the validity
+        of the returned value. Before, if solidColor() is called without calling
+        mayFillWithSolidColor() or checkForSolidColor(), the returned value would be
+        incorrect.
+        
+        (WebCore::BitmapImage::dump): Use the m_solidColor Optional and Color states.
+        (WebCore::BitmapImage::mayFillWithSolidColor): Deleted.
+        (WebCore::BitmapImage::solidColor): Deleted.
+        
+        * platform/graphics/BitmapImage.h: Delete m_checkedForSolidColor and
+        m_isSolidColor and change m_solidColor to be Optional&lt;Color&gt;.
+        
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::drawTiled): Use singlePixelSolidColor() and check the returned
+        value to know whether the singe pixel solid color optimization applies or not.
+        
+        * platform/graphics/Image.h:
+        (WebCore::Image::singlePixelSolidColor):
+        (WebCore::Image::mayFillWithSolidColor): Deleted.
+        (WebCore::Image::solidColor): Deleted.
+        Replace mayFillWithSolidColor() and solidColor() with a single function named
+        singlePixelSolidColor(). isValid() of the returned Color can be used to tell
+        whether the singe pixel solid color optimization applies or not.
+        
+        * platform/graphics/cairo/BitmapImageCairo.cpp:
+        (WebCore::NativeImage::singlePixelSolidColor):
+        (WebCore::BitmapImage::draw):
+        (WebCore::BitmapImage::checkForSolidColor): Deleted.
+        Delete the platform dependent BitmapImage::checkForSolidColor() and add
+        the new platform dependent function NativeImage::singlePixelSolidColor() and
+        use to know whether the singe pixel solid color optimization applies or not.
+        
+        * platform/graphics/cg/BitmapImageCG.cpp:
+        (WebCore::NativeImage::singlePixelSolidColor):
+        (WebCore::BitmapImage::draw):
+        (WebCore::BitmapImage::checkForSolidColor): Deleted.
+        Ditto.
+
</ins><span class="cx"> 2016-05-26  Pranjal Jumde  &lt;pjumde@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Sites served over insecure connections should not be allowed to use geolocation.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsBitmapImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -48,8 +48,6 @@
</span><span class="cx"> 
</span><span class="cx"> BitmapImage::BitmapImage(ImageObserver* observer)
</span><span class="cx">     : Image(observer)
</span><del>-    , m_isSolidColor(false)
-    , m_checkedForSolidColor(false)
</del><span class="cx">     , m_animationFinished(false)
</span><span class="cx">     , m_allDataReceived(false)
</span><span class="cx">     , m_haveSize(false)
</span><span class="lines">@@ -63,8 +61,6 @@
</span><span class="cx">     : Image(observer)
</span><span class="cx">     , m_source(image)
</span><span class="cx">     , m_frameCount(1)
</span><del>-    , m_isSolidColor(false)
-    , m_checkedForSolidColor(false)
</del><span class="cx">     , m_animationFinished(true)
</span><span class="cx">     , m_allDataReceived(true)
</span><span class="cx">     , m_haveSize(true)
</span><span class="lines">@@ -81,8 +77,6 @@
</span><span class="cx">     m_frames[0].m_hasAlpha = NativeImage::hasAlpha(image);
</span><span class="cx">     m_frames[0].m_haveMetadata = true;
</span><span class="cx">     m_frames[0].m_image = WTFMove(image);
</span><del>-    
-    checkForSolidColor();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> BitmapImage::~BitmapImage()
</span><span class="lines">@@ -167,8 +161,7 @@
</span><span class="cx"> 
</span><span class="cx"> void BitmapImage::destroyMetadataAndNotify(unsigned frameBytesCleared, ClearedSource clearedSource)
</span><span class="cx"> {
</span><del>-    m_isSolidColor = false;
-    m_checkedForSolidColor = false;
</del><ins>+    m_solidColor = Nullopt;
</ins><span class="cx">     invalidatePlatformData();
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_decodedSize &gt;= frameBytesCleared);
</span><span class="lines">@@ -195,8 +188,6 @@
</span><span class="cx">     if (frameCaching == CacheMetadataAndFrame) {
</span><span class="cx">         m_frames[index].m_image = m_source.createFrameImageAtIndex(index, subsamplingLevel);
</span><span class="cx">         m_frames[index].m_subsamplingLevel = subsamplingLevel;
</span><del>-        if (numFrames == 1 &amp;&amp; m_frames[index].m_image)
-            checkForSolidColor();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_frames[index].m_orientation = m_source.orientationAtIndex(index);
</span><span class="lines">@@ -689,18 +680,30 @@
</span><span class="cx">     return advancedAnimation;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool BitmapImage::mayFillWithSolidColor()
</del><ins>+Color BitmapImage::singlePixelSolidColor()
</ins><span class="cx"> {
</span><del>-    if (!m_checkedForSolidColor &amp;&amp; frameCount() &gt; 0) {
-        checkForSolidColor();
-        ASSERT(m_checkedForSolidColor);
</del><ins>+    // If the image size is not available yet or if the image will be animating don't use the solid color optimization.
+    if (frameCount() != 1)
+        return Color();
+    
+    if (m_solidColor)
+        return m_solidColor.value();
+
+    // If the frame image is not loaded, first use the decoder to get the size of the image.
+    if (!haveFrameImageAtIndex(0) &amp;&amp; m_source.frameSizeAtIndex(0, 0) != IntSize(1, 1)) {
+        m_solidColor = Color();
+        return m_solidColor.value();
</ins><span class="cx">     }
</span><del>-    return m_isSolidColor &amp;&amp; !m_currentFrame;
-}
</del><span class="cx"> 
</span><del>-Color BitmapImage::solidColor() const
-{
-    return m_solidColor;
</del><ins>+    // Cache the frame image. The size will be calculated from the NativeImagePtr.
+    if (!ensureFrameIsCached(0))
+        return Color();
+    
+    ASSERT(m_frames.size());
+    m_solidColor = NativeImage::singlePixelSolidColor(m_frames[0].m_image.get());
+    
+    ASSERT(m_solidColor);
+    return m_solidColor.value();
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> bool BitmapImage::canAnimate()
</span><span class="lines">@@ -720,8 +723,8 @@
</span><span class="cx">         ts.dumpProperty(&quot;current-frame&quot;, m_currentFrame);
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    if (m_isSolidColor)
-        ts.dumpProperty(&quot;solid-color&quot;, m_isSolidColor);
</del><ins>+    if (m_solidColor)
+        ts.dumpProperty(&quot;solid-color&quot;, m_solidColor.value());
</ins><span class="cx">     
</span><span class="cx">     m_source.dump(ts);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsBitmapImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/BitmapImage.h        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx"> namespace NativeImage {
</span><span class="cx">     IntSize size(const NativeImagePtr&amp;);
</span><span class="cx">     bool hasAlpha(const NativeImagePtr&amp;);
</span><ins>+    Color singlePixelSolidColor(const NativeImagePtr&amp;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ================================================
</span><span class="lines">@@ -274,14 +275,8 @@
</span><span class="cx">     // Handle platform-specific data
</span><span class="cx">     void invalidatePlatformData();
</span><span class="cx"> 
</span><del>-    // Checks to see if the image is a 1x1 solid color. We optimize these images and just do a fill rect instead.
-    // This check should happen regardless whether m_checkedForSolidColor is already set, as the frame may have
-    // changed.
-    void checkForSolidColor();
</del><ins>+    Color singlePixelSolidColor() override;
</ins><span class="cx"> 
</span><del>-    bool mayFillWithSolidColor() override;
-    Color solidColor() const override;
-
</del><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx">     bool notSolidColor() override;
</span><span class="cx"> #endif
</span><span class="lines">@@ -312,7 +307,10 @@
</span><span class="cx">     mutable RetainPtr&lt;CFDataRef&gt; m_tiffRep; // Cached TIFF rep for frame 0. Only built lazily if someone queries for one.
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    Color m_solidColor;  // If we're a 1x1 solid color, this is the color to use to fill.
</del><ins>+    // The value of this data member is a missing value if we haven’t analyzed to check for a solid color or not, but an invalid
+    // color if we have analyzed and decided it’s not a solid color, and a valid color if we have analyzed and decide that the
+    // solid color optimization applies. The analysis, we do, handles only the case of 1x1 solid color images.
+    Optional&lt;Color&gt; m_solidColor;
</ins><span class="cx"> 
</span><span class="cx">     unsigned m_decodedSize { 0 }; // The current size of all decoded frames.
</span><span class="cx">     mutable unsigned m_decodedPropertiesSize { 0 }; // The size of data decoded by the source to determine image properties (e.g. size, frame count, etc).
</span><span class="lines">@@ -323,9 +321,6 @@
</span><span class="cx">     double m_progressiveLoadChunkTime { 0 };
</span><span class="cx">     uint16_t m_progressiveLoadChunkCount { 0 };
</span><span class="cx"> #endif
</span><del>-    bool m_isSolidColor : 1; // Whether or not we are a 1x1 solid image.
-    bool m_checkedForSolidColor : 1; // Whether we've checked the frame for solid color.
-
</del><span class="cx">     bool m_animationFinished : 1; // Whether or not we've completed the entire animation.
</span><span class="cx"> 
</span><span class="cx">     bool m_allDataReceived : 1; // Whether or not we've received all our data.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Image.cpp        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -91,9 +91,10 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Image::drawTiled(GraphicsContext&amp; ctxt, const FloatRect&amp; destRect, const FloatPoint&amp; srcPoint, const FloatSize&amp; scaledTileSize, const FloatSize&amp; spacing, CompositeOperator op, BlendMode blendMode)
</span><del>-{    
-    if (mayFillWithSolidColor()) {
-        fillWithSolidColor(ctxt, destRect, solidColor(), op);
</del><ins>+{
+    Color color = singlePixelSolidColor();
+    if (color.isValid()) {
+        fillWithSolidColor(ctxt, destRect, color, op);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -204,8 +205,9 @@
</span><span class="cx"> void Image::drawTiled(GraphicsContext&amp; ctxt, const FloatRect&amp; dstRect, const FloatRect&amp; srcRect,
</span><span class="cx">     const FloatSize&amp; tileScaleFactor, TileRule hRule, TileRule vRule, CompositeOperator op)
</span><span class="cx"> {    
</span><del>-    if (mayFillWithSolidColor()) {
-        fillWithSolidColor(ctxt, dstRect, solidColor(), op);
</del><ins>+    Color color = singlePixelSolidColor();
+    if (color.isValid()) {
+        fillWithSolidColor(ctxt, dstRect, color, op);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Image.h (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Image.h        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/Image.h        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -194,8 +194,7 @@
</span><span class="cx">     void drawTiled(GraphicsContext&amp;, const FloatRect&amp; dstRect, const FloatRect&amp; srcRect, const FloatSize&amp; tileScaleFactor, TileRule hRule, TileRule vRule, CompositeOperator);
</span><span class="cx"> 
</span><span class="cx">     // Supporting tiled drawing
</span><del>-    virtual bool mayFillWithSolidColor() { return false; }
-    virtual Color solidColor() const { return Color(); }
</del><ins>+    virtual Color singlePixelSolidColor() { return Color(); }
</ins><span class="cx">     
</span><span class="cx"> private:
</span><span class="cx">     RefPtr&lt;SharedBuffer&gt; m_encodedImageData;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoBitmapImageCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -50,8 +50,22 @@
</span><span class="cx">     return cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Color singlePixelSolidColor(const RefPtr&lt;cairo_surface_t&gt;&amp; image)
+{
+    ASSERT(image);
+    
+    if (NativeImage::size(image) != IntSize(1, 1))
+        return Color();
+
+    if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
+        return Color();
+
+    RGBA32* pixel = reinterpret_cast_ptr&lt;RGBA32*&gt;(cairo_image_surface_get_data(image.get()));
+    return colorFromPremultipliedARGB(*pixel);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> void BitmapImage::draw(GraphicsContext&amp; context, const FloatRect&amp; dst, const FloatRect&amp; src, CompositeOperator op,
</span><span class="cx">     BlendMode blendMode, ImageOrientationDescription description)
</span><span class="cx"> {
</span><span class="lines">@@ -64,8 +78,9 @@
</span><span class="cx">     if (!surface) // If it's too early we won't have an image yet.
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (mayFillWithSolidColor()) {
-        fillWithSolidColor(context, dst, solidColor(), op);
</del><ins>+    Color color = singlePixelSolidColor();
+    if (color.isValid()) {
+        fillWithSolidColor(context, dst, color, op);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -110,32 +125,6 @@
</span><span class="cx">         imageObserver()-&gt;didDraw(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void BitmapImage::checkForSolidColor()
-{
-    m_isSolidColor = false;
-    m_checkedForSolidColor = true;
-
-    if (frameCount() &gt; 1)
-        return;
-
-    auto surface = frameImageAtIndex(m_currentFrame);
-    if (!surface) // If it's too early we won't have an image yet.
-        return;
-
-    if (cairo_surface_get_type(surface.get()) != CAIRO_SURFACE_TYPE_IMAGE)
-        return;
-
-    IntSize size = cairoSurfaceSize(surface.get());
-
-    if (size.width() != 1 || size.height() != 1)
-        return;
-
-    unsigned* pixelColor = reinterpret_cast_ptr&lt;unsigned*&gt;(cairo_image_surface_get_data(surface.get()));
-    m_solidColor = colorFromPremultipliedARGB(*pixelColor);
-
-    m_isSolidColor = true;
-}
-
</del><span class="cx"> bool FrameData::clear(bool clearMetadata)
</span><span class="cx"> {
</span><span class="cx">     if (clearMetadata)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgBitmapImageCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp (201423 => 201424)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp        2016-05-26 18:19:30 UTC (rev 201423)
+++ trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp        2016-05-26 18:46:02 UTC (rev 201424)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> 
</span><span class="cx"> IntSize size(const RetainPtr&lt;CGImageRef&gt;&amp; image)
</span><span class="cx"> {
</span><ins>+    ASSERT(image);
</ins><span class="cx">     return IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -62,9 +63,32 @@
</span><span class="cx">     // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><ins>+    
+Color singlePixelSolidColor(const RetainPtr&lt;CGImageRef&gt;&amp; image)
+{
+    ASSERT(image);
+    
+    if (NativeImage::size(image) != IntSize(1, 1))
+        return Color();
+    
+    unsigned char pixel[4]; // RGBA
+    auto bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(),
+        kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
</ins><span class="cx"> 
</span><ins>+    if (!bitmapContext)
+        return Color();
+    
+    CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
+    CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, 1, 1), image.get());
+    
+    if (!pixel[3])
+        return Color(0, 0, 0, 0);
+
+    return Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> bool FrameData::clear(bool clearMetadata)
</span><span class="cx"> {
</span><span class="cx">     if (clearMetadata)
</span><span class="lines">@@ -82,49 +106,6 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void BitmapImage::checkForSolidColor()
-{
-    m_checkedForSolidColor = true;
-    m_isSolidColor = false;
-
-    if (frameCount() &gt; 1)
-        return;
-
-    if (!haveFrameImageAtIndex(0)) {
-        IntSize size = m_source.frameSizeAtIndex(0, 0);
-        if (size.width() != 1 || size.height() != 1)
-            return;
-
-        if (!ensureFrameIsCached(0))
-            return;
-    }
-
-    CGImageRef image = nullptr;
-    if (m_frames.size())
-        image = m_frames[0].m_image.get();
-
-    if (!image)
-        return;
-
-    // Currently we only check for solid color in the important special case of a 1x1 image.
-    if (CGImageGetWidth(image) == 1 &amp;&amp; CGImageGetHeight(image) == 1) {
-        unsigned char pixel[4]; // RGBA
-        RetainPtr&lt;CGContextRef&gt; bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(),
-            kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
-        if (!bitmapContext)
-            return;
-        GraphicsContext(bitmapContext.get()).setCompositeOperation(CompositeCopy);
-        CGRect destinationRect = CGRectMake(0, 0, 1, 1);
-        CGContextDrawImage(bitmapContext.get(), destinationRect, image);
-        if (!pixel[3])
-            m_solidColor = Color(0, 0, 0, 0);
-        else
-            m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
-
-        m_isSolidColor = true;
-    }
-}
-
</del><span class="cx"> CGImageRef BitmapImage::getCGImageRef()
</span><span class="cx"> {
</span><span class="cx">     return frameImageAtIndex(0).get();
</span><span class="lines">@@ -179,8 +160,9 @@
</span><span class="cx">     if (!image) // If it's too early we won't have an image yet.
</span><span class="cx">         return;
</span><span class="cx">     
</span><del>-    if (mayFillWithSolidColor()) {
-        fillWithSolidColor(ctxt, destRect, solidColor(), compositeOp);
</del><ins>+    Color color = singlePixelSolidColor();
+    if (color.isValid()) {
+        fillWithSolidColor(ctxt, destRect, color, compositeOp);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>