Title: [131354] trunk/Source/WebKit2
Revision
131354
Author
commit-qu...@webkit.org
Date
2012-10-15 14:00:46 -0700 (Mon, 15 Oct 2012)

Log Message

[WK2][CAIRO] Use cairo_format_stride_for_width() in ShareableBitmap
https://bugs.webkit.org/show_bug.cgi?id=99332

Patch by Christophe Dumez <christophe.du...@intel.com> on 2012-10-15
Reviewed by Martin Robinson.

Cairo implementation of ShareableBitmap is calling
cairo_image_surface_create_for_data() to create an image surface for
the provided pixel data. However, it was passing "m_size.width() * 4"
for the stride argument instead of calling
cairo_format_stride_for_width().

The Cairo documentation states:
"Note that the stride may be larger than width*bytes_per_pixel to
provide proper alignment for each pixel and row. This alignment is
required to allow high-performance rendering within cairo. The correct
way to obtain a legal stride value is to call
cairo_format_stride_for_width() with the desired format and maximum
image width value, and then use the resulting stride value to allocate
the data and to create the image surface."

This patch calls cairo_format_stride_for_width() is ShareableBitmap
in order to obtain a legal stride value to make sure we provide proper
alignment for each pixel and row, and allow high-performance rendering
within cairo.

* Shared/ShareableBitmap.h:
(ShareableBitmap):
* Shared/cairo/ShareableBitmapCairo.cpp:
(WebKit):
(WebKit::ShareableBitmap::numBytesForSize):
(WebKit::createSurfaceFromData):
(WebKit::ShareableBitmap::paint):
(WebKit::ShareableBitmap::createCairoSurface):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (131353 => 131354)


--- trunk/Source/WebKit2/ChangeLog	2012-10-15 21:00:26 UTC (rev 131353)
+++ trunk/Source/WebKit2/ChangeLog	2012-10-15 21:00:46 UTC (rev 131354)
@@ -1,3 +1,39 @@
+2012-10-15  Christophe Dumez  <christophe.du...@intel.com>
+
+        [WK2][CAIRO] Use cairo_format_stride_for_width() in ShareableBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=99332
+
+        Reviewed by Martin Robinson.
+
+        Cairo implementation of ShareableBitmap is calling
+        cairo_image_surface_create_for_data() to create an image surface for
+        the provided pixel data. However, it was passing "m_size.width() * 4"
+        for the stride argument instead of calling
+        cairo_format_stride_for_width().
+
+        The Cairo documentation states:
+        "Note that the stride may be larger than width*bytes_per_pixel to
+        provide proper alignment for each pixel and row. This alignment is
+        required to allow high-performance rendering within cairo. The correct
+        way to obtain a legal stride value is to call
+        cairo_format_stride_for_width() with the desired format and maximum
+        image width value, and then use the resulting stride value to allocate
+        the data and to create the image surface."
+
+        This patch calls cairo_format_stride_for_width() is ShareableBitmap
+        in order to obtain a legal stride value to make sure we provide proper
+        alignment for each pixel and row, and allow high-performance rendering
+        within cairo.
+
+        * Shared/ShareableBitmap.h:
+        (ShareableBitmap):
+        * Shared/cairo/ShareableBitmapCairo.cpp:
+        (WebKit):
+        (WebKit::ShareableBitmap::numBytesForSize):
+        (WebKit::createSurfaceFromData):
+        (WebKit::ShareableBitmap::paint):
+        (WebKit::ShareableBitmap::createCairoSurface):
+
 2012-10-15  Eunmi Lee  <eunmi15....@samsung.com>
 
         [EFL][WK2] Refactoring initialization and shutdown codes of EFL libraries.

Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.h (131353 => 131354)


--- trunk/Source/WebKit2/Shared/ShareableBitmap.h	2012-10-15 21:00:26 UTC (rev 131353)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.h	2012-10-15 21:00:46 UTC (rev 131354)
@@ -143,7 +143,11 @@
     ShareableBitmap(const WebCore::IntSize&, Flags, void*);
     ShareableBitmap(const WebCore::IntSize&, Flags, PassRefPtr<SharedMemory>);
 
+#if USE(CAIRO)
+    static size_t numBytesForSize(const WebCore::IntSize&);
+#else
     static size_t numBytesForSize(const WebCore::IntSize& size) { return size.width() * size.height() * 4; }
+#endif
 
 #if USE(CG)
     RetainPtr<CGImageRef> createCGImage(CGDataProviderRef) const;

Modified: trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp (131353 => 131354)


--- trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp	2012-10-15 21:00:26 UTC (rev 131353)
+++ trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp	2012-10-15 21:00:46 UTC (rev 131354)
@@ -38,6 +38,19 @@
 
 namespace WebKit {
 
+static const cairo_format_t cairoFormat = CAIRO_FORMAT_ARGB32;
+
+size_t ShareableBitmap::numBytesForSize(const WebCore::IntSize& size)
+{
+    return cairo_format_stride_for_width(cairoFormat, size.width()) * size.height();
+}
+
+static inline PassRefPtr<cairo_surface_t> createSurfaceFromData(void* data, const WebCore::IntSize& size)
+{
+    const int stride = cairo_format_stride_for_width(cairoFormat, size.width());
+    return adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(data), cairoFormat, size.width(), size.height(), stride));
+}
+
 PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext()
 {
     RefPtr<cairo_surface_t> image = createCairoSurface();
@@ -47,10 +60,7 @@
 
 void ShareableBitmap::paint(GraphicsContext& context, const IntPoint& dstPoint, const IntRect& srcRect)
 {
-    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(data()),
-                                                                                   CAIRO_FORMAT_ARGB32,
-                                                                                   m_size.width(), m_size.height(),
-                                                                                   m_size.width() * 4));
+    RefPtr<cairo_surface_t> surface = createSurfaceFromData(data(), m_size);
     FloatRect destRect(dstPoint, srcRect.size());
     context.platformContext()->drawSurfaceToContext(surface.get(), destRect, srcRect, &context);
 }
@@ -67,10 +77,7 @@
 
 PassRefPtr<cairo_surface_t> ShareableBitmap::createCairoSurface()
 {
-    RefPtr<cairo_surface_t> image = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(data()),
-                                                                                 CAIRO_FORMAT_ARGB32,
-                                                                                 m_size.width(), m_size.height(),
-                                                                                 m_size.width() * 4));
+    RefPtr<cairo_surface_t> image = createSurfaceFromData(data(), m_size);
 
     ref(); // Balanced by deref in releaseSurfaceData.
     static cairo_user_data_key_t dataKey;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to