<!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>[224813] 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/224813">224813</a></dd>
<dt>Author</dt> <dd>zandobersek@gmail.com</dd>
<dt>Date</dt> <dd>2017-11-14 05:42:14 -0800 (Tue, 14 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cairo] Move native image drawing operation to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179660

Reviewed by Carlos Garcia Campos.

Unify the native image drawing operation behavior between the
Cairo-specific GraphicsContext and drawNativeImage() implementations and
then move the code into the Cairo::drawNativeImage() function, inside
the CairoOperations implementation file.

No new tests -- no change in behavior.

* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::cairoSurfaceHasAlpha):
(WebCore::Cairo::drawNativeImage):
* platform/graphics/cairo/CairoOperations.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::drawNativeImage):
* platform/graphics/cairo/NativeImageCairo.cpp:
(WebCore::drawNativeImage):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoCairoOperationscpp">trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoCairoOperationsh">trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoGraphicsContextCairocpp">trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoNativeImageCairocpp">trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224812 => 224813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-14 13:23:55 UTC (rev 224812)
+++ trunk/Source/WebCore/ChangeLog      2017-11-14 13:42:14 UTC (rev 224813)
</span><span class="lines">@@ -1,5 +1,28 @@
</span><span class="cx"> 2017-11-14  Zan Dobersek  <zdobersek@igalia.com>
</span><span class="cx"> 
</span><ins>+        [Cairo] Move native image drawing operation to CairoOperations
+        https://bugs.webkit.org/show_bug.cgi?id=179660
+
+        Reviewed by Carlos Garcia Campos.
+
+        Unify the native image drawing operation behavior between the
+        Cairo-specific GraphicsContext and drawNativeImage() implementations and
+        then move the code into the Cairo::drawNativeImage() function, inside
+        the CairoOperations implementation file.
+
+        No new tests -- no change in behavior.
+
+        * platform/graphics/cairo/CairoOperations.cpp:
+        (WebCore::Cairo::cairoSurfaceHasAlpha):
+        (WebCore::Cairo::drawNativeImage):
+        * platform/graphics/cairo/CairoOperations.h:
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawNativeImage):
+        * platform/graphics/cairo/NativeImageCairo.cpp:
+        (WebCore::drawNativeImage):
+
+2017-11-14  Zan Dobersek  <zdobersek@igalia.com>
+
</ins><span class="cx">         [Cairo] Perform GraphicsContextPlatformPrivate method calls from CairoOperations
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=179657
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoCairoOperationscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224812 => 224813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-14 13:23:55 UTC (rev 224812)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp    2017-11-14 13:42:14 UTC (rev 224813)
</span><span class="lines">@@ -231,6 +231,11 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool cairoSurfaceHasAlpha(cairo_surface_t* surface)
+{
+    return cairo_surface_get_content(surface) != CAIRO_CONTENT_COLOR;
+}
+
</ins><span class="cx"> namespace State {
</span><span class="cx"> 
</span><span class="cx"> void setStrokeThickness(PlatformContextCairo& platformContext, float strokeThickness)
</span><span class="lines">@@ -558,6 +563,41 @@
</span><span class="cx">     cairo_restore(cr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void drawNativeImage(PlatformContextCairo& platformContext, const NativeImagePtr& image, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation, GraphicsContext& targetContext)
+{
+    platformContext.save();
+
+    // Set the compositing operation.
+    if (compositeOperator == CompositeSourceOver && blendMode == BlendModeNormal && !cairoSurfaceHasAlpha(image.get()))
+        Cairo::State::setCompositeOperation(platformContext, CompositeCopy, BlendModeNormal);
+    else
+        Cairo::State::setCompositeOperation(platformContext, compositeOperator, blendMode);
+
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+    IntSize scaledSize = nativeImageSize(image);
+    FloatRect src = adjustSourceRectForDownSampling(srcRect, scaledSize);
+#else
+    FloatRect src(srcRect);
+#endif
+
+    FloatRect dst = destRect;
+
+    if (orientation != DefaultImageOrientation) {
+        // ImageOrientation expects the origin to be at (0, 0).
+        Cairo::translate(platformContext, dst.x(), dst.y());
+        dst.setLocation(FloatPoint());
+        Cairo::concatCTM(platformContext, orientation.transformFromDefault(dst.size()));
+        if (orientation.usesWidthAsHeight()) {
+            // The destination rectangle will have its width and height already reversed for the orientation of
+            // the image, as it was needed for page layout, so we need to reverse it back here.
+            dst = FloatRect(dst.x(), dst.y(), dst.height(), dst.width());
+        }
+    }
+
+    platformContext.drawSurfaceToContext(image.get(), dst, src, targetContext);
+    platformContext.restore();
+}
+
</ins><span class="cx"> void drawPattern(PlatformContextCairo& platformContext, Image& image, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator compositeOperator, BlendMode blendMode)
</span><span class="cx"> {
</span><span class="cx">     if (auto surface = image.nativeImageForCurrentFrame())
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoCairoOperationsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (224812 => 224813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h   2017-11-14 13:23:55 UTC (rev 224812)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h      2017-11-14 13:42:14 UTC (rev 224813)
</span><span class="lines">@@ -95,6 +95,7 @@
</span><span class="cx"> 
</span><span class="cx"> void drawGlyphs(GraphicsContext&, const GraphicsContextState&, bool, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, GraphicsContext&);
</span><span class="cx"> 
</span><ins>+void drawNativeImage(PlatformContextCairo&, const NativeImagePtr&, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, GraphicsContext&);
</ins><span class="cx"> void drawPattern(PlatformContextCairo&, Image&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
</span><span class="cx"> 
</span><span class="cx"> void drawRect(PlatformContextCairo&, const FloatRect&, float, const GraphicsContextState&);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoGraphicsContextCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224812 => 224813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp    2017-11-14 13:23:55 UTC (rev 224812)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp       2017-11-14 13:42:14 UTC (rev 224813)
</span><span class="lines">@@ -244,40 +244,18 @@
</span><span class="cx">     Cairo::drawRect(*platformContext(), rect, borderThickness, state());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
</del><ins>+void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation)
</ins><span class="cx"> {
</span><span class="cx">     if (paintingDisabled())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (m_impl) {
</span><del>-        m_impl->drawNativeImage(image, imageSize, destRect, srcRect, op, blendMode, orientation);
</del><ins>+        m_impl->drawNativeImage(image, imageSize, destRect, srcRect, compositeOperator, blendMode, orientation);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    platformContext()->save();
-
-    // Set the compositing operation.
-    if (op == CompositeSourceOver && blendMode == BlendModeNormal)
-        setCompositeOperation(CompositeCopy);
-    else
-        setCompositeOperation(op, blendMode);
-
-    FloatRect dst = destRect;
-
-    if (orientation != DefaultImageOrientation) {
-        // ImageOrientation expects the origin to be at (0, 0).
-        translate(dst.x(), dst.y());
-        dst.setLocation(FloatPoint());
-        concatCTM(orientation.transformFromDefault(dst.size()));
-        if (orientation.usesWidthAsHeight()) {
-            // The destination rectangle will have its width and height already reversed for the orientation of
-            // the image, as it was needed for page layout, so we need to reverse it back here.
-            dst = FloatRect(dst.x(), dst.y(), dst.height(), dst.width());
-        }
-    }
-
-    platformContext()->drawSurfaceToContext(image.get(), dst, srcRect, *this);
-    platformContext()->restore();
</del><ins>+    ASSERT(hasPlatformContext());
+    Cairo::drawNativeImage(*platformContext(), image, destRect, srcRect, compositeOperator, blendMode, orientation, *this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This is only used to draw borders, so we should not draw shadows.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoNativeImageCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp (224812 => 224813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp        2017-11-14 13:23:55 UTC (rev 224812)
+++ trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp   2017-11-14 13:42:14 UTC (rev 224813)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(CAIRO)
</span><span class="cx"> 
</span><ins>+#include "CairoOperations.h"
</ins><span class="cx"> #include "CairoUtilities.h"
</span><span class="cx"> #include "PlatformContextCairo.h"
</span><span class="cx"> #include <cairo.h>
</span><span class="lines">@@ -56,39 +57,12 @@
</span><span class="cx">     return colorFromPremultipliedARGB(*pixel);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
</del><ins>+void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& imageSize, CompositeOperator compositeOperator, BlendMode blendMode, const ImageOrientation& orientation)
</ins><span class="cx"> {
</span><del>-    context.save();
-    
-    // Set the compositing operation.
-    if (op == CompositeSourceOver && mode == BlendModeNormal && !nativeImageHasAlpha(image))
-        context.setCompositeOperation(CompositeCopy);
-    else
-        context.setCompositeOperation(op, mode);
-        
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
-    IntSize scaledSize = nativeImageSize(image);
-    FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(srcRect, scaledSize);
-#else
-    FloatRect adjustedSrcRect(srcRect);
-#endif
-        
-    FloatRect adjustedDestRect = destRect;
-        
-    if (orientation != DefaultImageOrientation) {
-        // ImageOrientation expects the origin to be at (0, 0).
-        context.translate(destRect.x(), destRect.y());
-        adjustedDestRect.setLocation(FloatPoint());
-        context.concatCTM(orientation.transformFromDefault(adjustedDestRect.size()));
-        if (orientation.usesWidthAsHeight()) {
-            // The destination rectangle will have it's width and height already reversed for the orientation of
-            // the image, as it was needed for page layout, so we need to reverse it back here.
-            adjustedDestRect.setSize(adjustedDestRect.size().transposedSize());
-        }
-    }
</del><ins>+    UNUSED_PARAM(imageSize);
</ins><span class="cx"> 
</span><del>-    context.platformContext()->drawSurfaceToContext(image.get(), adjustedDestRect, adjustedSrcRect, context);
-    context.restore();
</del><ins>+    ASSERT(hasPlatformContext());
+    Cairo::drawNativeImage(*context.platformContext(), image, destRect, srcRect, compositeOperator, blendMode, orientation, context);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void clearNativeImageSubimages(const NativeImagePtr&)
</span></span></pre>
</div>
</div>

</body>
</html>