Title: [224813] trunk/Source/WebCore
Revision
224813
Author
zandober...@gmail.com
Date
2017-11-14 05:42:14 -0800 (Tue, 14 Nov 2017)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224812 => 224813)


--- 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)
@@ -1,5 +1,28 @@
 2017-11-14  Zan Dobersek  <zdober...@igalia.com>
 
+        [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  <zdober...@igalia.com>
+
         [Cairo] Perform GraphicsContextPlatformPrivate method calls from CairoOperations
         https://bugs.webkit.org/show_bug.cgi?id=179657
 

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224812 => 224813)


--- 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)
@@ -231,6 +231,11 @@
     }
 }
 
+static bool cairoSurfaceHasAlpha(cairo_surface_t* surface)
+{
+    return cairo_surface_get_content(surface) != CAIRO_CONTENT_COLOR;
+}
+
 namespace State {
 
 void setStrokeThickness(PlatformContextCairo& platformContext, float strokeThickness)
@@ -558,6 +563,41 @@
     cairo_restore(cr);
 }
 
+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 = "" 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();
+}
+
 void drawPattern(PlatformContextCairo& platformContext, Image& image, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator compositeOperator, BlendMode blendMode)
 {
     if (auto surface = image.nativeImageForCurrentFrame())

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (224812 => 224813)


--- 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)
@@ -95,6 +95,7 @@
 
 void drawGlyphs(GraphicsContext&, const GraphicsContextState&, bool, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, GraphicsContext&);
 
+void drawNativeImage(PlatformContextCairo&, const NativeImagePtr&, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, GraphicsContext&);
 void drawPattern(PlatformContextCairo&, Image&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
 
 void drawRect(PlatformContextCairo&, const FloatRect&, float, const GraphicsContextState&);

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224812 => 224813)


--- 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)
@@ -244,40 +244,18 @@
     Cairo::drawRect(*platformContext(), rect, borderThickness, state());
 }
 
-void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
+void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation)
 {
     if (paintingDisabled())
         return;
 
     if (m_impl) {
-        m_impl->drawNativeImage(image, imageSize, destRect, srcRect, op, blendMode, orientation);
+        m_impl->drawNativeImage(image, imageSize, destRect, srcRect, compositeOperator, blendMode, orientation);
         return;
     }
 
-    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();
+    ASSERT(hasPlatformContext());
+    Cairo::drawNativeImage(*platformContext(), image, destRect, srcRect, compositeOperator, blendMode, orientation, *this);
 }
 
 // This is only used to draw borders, so we should not draw shadows.

Modified: trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp (224812 => 224813)


--- 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)
@@ -28,6 +28,7 @@
 
 #if USE(CAIRO)
 
+#include "CairoOperations.h"
 #include "CairoUtilities.h"
 #include "PlatformContextCairo.h"
 #include <cairo.h>
@@ -56,39 +57,12 @@
     return colorFromPremultipliedARGB(*pixel);
 }
 
-void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
+void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& imageSize, CompositeOperator compositeOperator, BlendMode blendMode, const ImageOrientation& orientation)
 {
-    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());
-        }
-    }
+    UNUSED_PARAM(imageSize);
 
-    context.platformContext()->drawSurfaceToContext(image.get(), adjustedDestRect, adjustedSrcRect, context);
-    context.restore();
+    ASSERT(hasPlatformContext());
+    Cairo::drawNativeImage(*context.platformContext(), image, destRect, srcRect, compositeOperator, blendMode, orientation, context);
 }
 
 void clearNativeImageSubimages(const NativeImagePtr&)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to