Title: [160081] releases/WebKitGTK/webkit-2.2/Source/WebCore
Revision
160081
Author
[email protected]
Date
2013-12-04 01:56:14 -0800 (Wed, 04 Dec 2013)

Log Message

Merge r159314 - [Cairo] Avoid extra copy when drawing images
https://bugs.webkit.org/show_bug.cgi?id=124209

Patch by Aloisio Almeida Jr <[email protected]> on 2013-11-14
Reviewed by Martin Robinson.

To solve the bug #58309 a cairo subsurface is being used to limit the
source image boundaries.
In many cases, when a cairo subsurface is used for drawing an image,
it occurs an image copy, causing performance penalty. In the case of
the function PlatformContextCairo::drawSurfaceToContext, the image
copy always happens.
So, we should use the subsurface only when it's really necessary.
In cases where we're drawing the whole image, the subsurface is
unnecessary.

The proposed patch avoid the use of subsurfaces when sampling the whole
image.

No new tests. It's an enhancement. Already covered by existing tests.

* platform/graphics/cairo/PlatformContextCairo.cpp:
(WebCore::PlatformContextCairo::drawSurfaceToContext):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog (160080 => 160081)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog	2013-12-04 09:47:51 UTC (rev 160080)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog	2013-12-04 09:56:14 UTC (rev 160081)
@@ -1,3 +1,28 @@
+2013-11-14  Aloisio Almeida Jr  <[email protected]>
+
+        [Cairo] Avoid extra copy when drawing images
+        https://bugs.webkit.org/show_bug.cgi?id=124209
+
+        Reviewed by Martin Robinson.
+
+        To solve the bug #58309 a cairo subsurface is being used to limit the
+        source image boundaries.
+        In many cases, when a cairo subsurface is used for drawing an image,
+        it occurs an image copy, causing performance penalty. In the case of
+        the function PlatformContextCairo::drawSurfaceToContext, the image
+        copy always happens.
+        So, we should use the subsurface only when it's really necessary.
+        In cases where we're drawing the whole image, the subsurface is
+        unnecessary.
+
+        The proposed patch avoid the use of subsurfaces when sampling the whole
+        image.
+
+        No new tests. It's an enhancement. Already covered by existing tests.
+
+        * platform/graphics/cairo/PlatformContextCairo.cpp:
+        (WebCore::PlatformContextCairo::drawSurfaceToContext):
+
 2013-08-29  Arnaud Renevier  <[email protected]>
 
         [cairo] canvas drawing on itself doesn't work with accelerated canvas

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp (160080 => 160081)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-12-04 09:47:51 UTC (rev 160080)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-12-04 09:56:14 UTC (rev 160081)
@@ -168,15 +168,24 @@
         srcRect.setHeight(std::fabs(originalSrcRect.height()));
     }
 
-    // Cairo subsurfaces don't support floating point boundaries well, so we expand the rectangle.
-    IntRect expandedSrcRect(enclosingIntRect(srcRect));
+    RefPtr<cairo_surface_t> patternSurface = surface;
+    float leftPadding = 0;
+    float topPadding = 0;
+    if (srcRect.x() || srcRect.y() || srcRect.size() != cairoSurfaceSize(surface)) {
+        // Cairo subsurfaces don't support floating point boundaries well, so we expand the rectangle.
+        IntRect expandedSrcRect(enclosingIntRect(srcRect));
 
-    // We use a subsurface here so that we don't end up sampling outside the originalSrcRect rectangle.
-    // See https://bugs.webkit.org/show_bug.cgi?id=58309
-    RefPtr<cairo_surface_t> subsurface = adoptRef(cairo_surface_create_for_rectangle(
-        surface, expandedSrcRect.x(), expandedSrcRect.y(), expandedSrcRect.width(), expandedSrcRect.height()));
-    RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(subsurface.get()));
+        // We use a subsurface here so that we don't end up sampling outside the originalSrcRect rectangle.
+        // See https://bugs.webkit.org/show_bug.cgi?id=58309
+        patternSurface = adoptRef(cairo_surface_create_for_rectangle(surface, expandedSrcRect.x(),
+            expandedSrcRect.y(), expandedSrcRect.width(), expandedSrcRect.height()));
 
+        leftPadding = static_cast<float>(expandedSrcRect.x()) - floorf(srcRect.x());
+        topPadding = static_cast<float>(expandedSrcRect.y()) - floorf(srcRect.y());
+    }
+
+    RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(patternSurface.get()));
+
     ASSERT(m_state);
     switch (m_state->m_imageInterpolationQuality) {
     case InterpolationNone:
@@ -199,8 +208,6 @@
     // of the scale since the original width and height might be negative.
     float scaleX = std::fabs(srcRect.width() / destRect.width());
     float scaleY = std::fabs(srcRect.height() / destRect.height());
-    float leftPadding = static_cast<float>(expandedSrcRect.x()) - floorf(srcRect.x());
-    float topPadding = static_cast<float>(expandedSrcRect.y()) - floorf(srcRect.y());
     cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, leftPadding, topPadding };
     cairo_pattern_set_matrix(pattern.get(), &matrix);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to