[WK2][CAIRO] Use cairo_format_stride_for_width() in ShareableBitmap
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2012 21:00:46 +0000 (21:00 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2012 21:00:46 +0000 (21:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99332

Patch by Christophe Dumez <christophe.dumez@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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@131354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ShareableBitmap.h
Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp

index 58607af..7b30ed2 100644 (file)
@@ -1,3 +1,39 @@
+2012-10-15  Christophe Dumez  <christophe.dumez@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.lee@samsung.com>
 
         [EFL][WK2] Refactoring initialization and shutdown codes of EFL libraries.
index e1ebc2e..2af228e 100644 (file)
@@ -143,7 +143,11 @@ private:
     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;
index 02e969e..7d2c441 100644 (file)
@@ -38,6 +38,19 @@ using namespace WebCore;
 
 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 @@ PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext()
 
 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 @@ void ShareableBitmap::paint(GraphicsContext& context, float scaleFactor, const I
 
 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;