Title: [147683] trunk/Source
Revision
147683
Author
[email protected]
Date
2013-04-04 16:59:12 -0700 (Thu, 04 Apr 2013)

Log Message

[Cairo] Stop passing raw pointers to BitmapImage::create()
https://bugs.webkit.org/show_bug.cgi?id=113945

Reviewed by Martin Robinson.

Source/WebCore:

BitmapImage::create() was updated in r147643 to take a PassRefPtr<cairo_surface_t>
in argument instead of a cairo_surface_t*. This patch updates several call sites
so that they now pass in a smart pointer instead of a raw one to avoid silent
converting from cairo_surface_t* to PassRefPtr<cairo_surface_t>.

No new tests, no behavior change.

* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBufferData::ImageBufferData): Use RefPtr to m_surface to avoid manual
memory handling.
(WebCore::ImageBuffer::ImageBuffer):
(WebCore::ImageBuffer::~ImageBuffer):
(WebCore::ImageBuffer::copyImage):
(WebCore::ImageBuffer::clip):
(WebCore::ImageBuffer::platformTransformColorSpace):
(WebCore::getImageData):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/cairo/ImageBufferDataCairo.h:
(ImageBufferData):
* platform/graphics/gstreamer/ImageGStreamerCairo.cpp:
(ImageGStreamer::ImageGStreamer):
* platform/graphics/gtk/ImageBufferGtk.cpp:
(WebCore::ImageBuffer::toDataURL):

Source/WebKit2:

Pass a smart pointer in to BitmapImage::create() instead of a raw one
for the cairo surface. The factory method prototype was updated for
cairo in r147643.

* Shared/cairo/ShareableBitmapCairo.cpp:
(WebKit::ShareableBitmap::createImage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (147682 => 147683)


--- trunk/Source/WebCore/ChangeLog	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebCore/ChangeLog	2013-04-04 23:59:12 UTC (rev 147683)
@@ -1,3 +1,34 @@
+2013-04-04  Christophe Dumez  <[email protected]>
+
+        [Cairo] Stop passing raw pointers to BitmapImage::create()
+        https://bugs.webkit.org/show_bug.cgi?id=113945
+
+        Reviewed by Martin Robinson.
+
+        BitmapImage::create() was updated in r147643 to take a PassRefPtr<cairo_surface_t>
+        in argument instead of a cairo_surface_t*. This patch updates several call sites
+        so that they now pass in a smart pointer instead of a raw one to avoid silent
+        converting from cairo_surface_t* to PassRefPtr<cairo_surface_t>.
+
+        No new tests, no behavior change.
+
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBufferData::ImageBufferData): Use RefPtr to m_surface to avoid manual
+        memory handling.
+        (WebCore::ImageBuffer::ImageBuffer):
+        (WebCore::ImageBuffer::~ImageBuffer):
+        (WebCore::ImageBuffer::copyImage):
+        (WebCore::ImageBuffer::clip):
+        (WebCore::ImageBuffer::platformTransformColorSpace):
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/cairo/ImageBufferDataCairo.h:
+        (ImageBufferData):
+        * platform/graphics/gstreamer/ImageGStreamerCairo.cpp:
+        (ImageGStreamer::ImageGStreamer):
+        * platform/graphics/gtk/ImageBufferGtk.cpp:
+        (WebCore::ImageBuffer::toDataURL):
+
 2013-04-04  Simon Fraser  <[email protected]>
 
         Page content missing when flipping from an empty layer to a tiled layer

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (147682 => 147683)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2013-04-04 23:59:12 UTC (rev 147683)
@@ -49,8 +49,7 @@
 namespace WebCore {
 
 ImageBufferData::ImageBufferData(const IntSize&)
-    : m_surface(0)
-    , m_platformContext(0)
+    : m_platformContext(0)
 {
 }
 
@@ -60,13 +59,11 @@
     , m_logicalSize(size)
 {
     success = false;  // Make early return mean error.
-    m_data.m_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
-                                                  size.width(),
-                                                  size.height());
-    if (cairo_surface_status(m_data.m_surface) != CAIRO_STATUS_SUCCESS)
+    m_data.m_surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size.width(), size.height()));
+    if (cairo_surface_status(m_data.m_surface.get()) != CAIRO_STATUS_SUCCESS)
         return;  // create will notice we didn't set m_initialized and fail.
 
-    RefPtr<cairo_t> cr = adoptRef(cairo_create(m_data.m_surface));
+    RefPtr<cairo_t> cr = adoptRef(cairo_create(m_data.m_surface.get()));
     m_data.m_platformContext.setCr(cr.get());
     m_context = adoptPtr(new GraphicsContext(&m_data.m_platformContext));
     success = true;
@@ -74,7 +71,6 @@
 
 ImageBuffer::~ImageBuffer()
 {
-    cairo_surface_destroy(m_data.m_surface);
 }
 
 GraphicsContext* ImageBuffer::context() const
@@ -85,10 +81,10 @@
 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior) const
 {
     if (copyBehavior == CopyBackingStore)
-        return BitmapImage::create(copyCairoImageSurface(m_data.m_surface).leakRef());
+        return BitmapImage::create(copyCairoImageSurface(m_data.m_surface.get()));
 
     // BitmapImage will release the passed in surface on destruction
-    return BitmapImage::create(cairo_surface_reference(m_data.m_surface));
+    return BitmapImage::create(m_data.m_surface);
 }
 
 BackingStoreCopy ImageBuffer::fastCopyImageMode()
@@ -98,7 +94,7 @@
 
 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& maskRect) const
 {
-    context->platformContext()->pushImageMask(m_data.m_surface, maskRect);
+    context->platformContext()->pushImageMask(m_data.m_surface.get(), maskRect);
 }
 
 void ImageBuffer::draw(GraphicsContext* destinationContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
@@ -118,10 +114,10 @@
 
 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
 {
-    ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE);
+    ASSERT(cairo_surface_get_type(m_data.m_surface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
 
-    unsigned char* dataSrc = ""
-    int stride = cairo_image_surface_get_stride(m_data.m_surface);
+    unsigned char* dataSrc = ""
+    int stride = cairo_image_surface_get_stride(m_data.m_surface.get());
     for (int y = 0; y < m_size.height(); ++y) {
         unsigned* row = reinterpret_cast<unsigned*>(dataSrc + stride * y);
         for (int x = 0; x < m_size.width(); x++) {
@@ -134,16 +130,16 @@
             *pixel = premultipliedARGBFromColor(pixelColor);
         }
     }
-    cairo_surface_mark_dirty_rectangle (m_data.m_surface, 0, 0, m_size.width(), m_size.height());
+    cairo_surface_mark_dirty_rectangle(m_data.m_surface.get(), 0, 0, m_size.width(), m_size.height());
 }
 
 template <Multiply multiplied>
 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const ImageBufferData& data, const IntSize& size)
 {
-    ASSERT(cairo_surface_get_type(data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE);
+    ASSERT(cairo_surface_get_type(data.m_surface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
 
     RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
-    unsigned char* dataSrc = ""
+    unsigned char* dataSrc = ""
     unsigned char* dataDst = result->data();
 
     if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > size.width() || (rect.y() + rect.height()) > size.height())
@@ -171,7 +167,7 @@
         endy = size.height();
     int numRows = endy - originy;
 
-    int stride = cairo_image_surface_get_stride(data.m_surface);
+    int stride = cairo_image_surface_get_stride(data.m_surface.get());
     unsigned destBytesPerRow = 4 * rect.width();
 
     unsigned char* destRows = dataDst + desty * destBytesPerRow + destx * 4;
@@ -219,9 +215,9 @@
 
 void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem)
 {
-    ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE);
+    ASSERT(cairo_surface_get_type(m_data.m_surface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
 
-    unsigned char* dataDst = cairo_image_surface_get_data(m_data.m_surface);
+    unsigned char* dataDst = cairo_image_surface_get_data(m_data.m_surface.get());
 
     ASSERT(sourceRect.width() > 0);
     ASSERT(sourceRect.height() > 0);
@@ -250,7 +246,7 @@
     int numRows = endy - desty;
 
     unsigned srcBytesPerRow = 4 * sourceSize.width();
-    int stride = cairo_image_surface_get_stride(m_data.m_surface);
+    int stride = cairo_image_surface_get_stride(m_data.m_surface.get());
 
     unsigned char* srcRows = source->data() + originy * srcBytesPerRow + originx * 4;
     for (int y = 0; y < numRows; ++y) {
@@ -278,9 +274,7 @@
         }
         srcRows += srcBytesPerRow;
     }
-    cairo_surface_mark_dirty_rectangle(m_data.m_surface,
-                                        destx, desty,
-                                        numColumns, numRows);
+    cairo_surface_mark_dirty_rectangle(m_data.m_surface.get(), destx, desty, numColumns, numRows);
 }
 
 #if !PLATFORM(GTK)

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h (147682 => 147683)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h	2013-04-04 23:59:12 UTC (rev 147683)
@@ -24,9 +24,8 @@
  */
 
 #include "PlatformContextCairo.h"
+#include "RefPtrCairo.h"
 
-typedef struct _cairo_surface cairo_surface_t;
-
 namespace WebCore {
 
 class IntSize;
@@ -35,7 +34,7 @@
 public:
     ImageBufferData(const IntSize&);
 
-    cairo_surface_t* m_surface;
+    RefPtr<cairo_surface_t> m_surface;
     PlatformContextCairo m_platformContext;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerCairo.cpp (147682 => 147683)


--- trunk/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerCairo.cpp	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerCairo.cpp	2013-04-04 23:59:12 UTC (rev 147683)
@@ -59,9 +59,9 @@
     cairoFormat = (format == GST_VIDEO_FORMAT_ARGB) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
 #endif
 
-    cairo_surface_t* surface = cairo_image_surface_create_for_data(bufferData, cairoFormat, size.width(), size.height(), stride);
-    ASSERT(cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS);
-    m_image = BitmapImage::create(surface);
+    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create_for_data(bufferData, cairoFormat, size.width(), size.height(), stride));
+    ASSERT(cairo_surface_status(surface.get()) == CAIRO_STATUS_SUCCESS);
+    m_image = BitmapImage::create(surface.release());
 
 #ifdef GST_API_VERSION_1
     if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))

Modified: trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp (147682 => 147683)


--- trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2013-04-04 23:59:12 UTC (rev 147683)
@@ -71,7 +71,7 @@
 
     GOwnPtr<gchar> buffer(0);
     gsize bufferSize;
-    if (!encodeImage(m_data.m_surface, mimeType, quality, buffer, bufferSize))
+    if (!encodeImage(m_data.m_surface.get(), mimeType, quality, buffer, bufferSize))
         return "data:,";
 
     Vector<char> base64Data;

Modified: trunk/Source/WebKit2/ChangeLog (147682 => 147683)


--- trunk/Source/WebKit2/ChangeLog	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebKit2/ChangeLog	2013-04-04 23:59:12 UTC (rev 147683)
@@ -1,3 +1,17 @@
+2013-04-04  Christophe Dumez  <[email protected]>
+
+        [Cairo] Stop passing raw pointers to BitmapImage::create()
+        https://bugs.webkit.org/show_bug.cgi?id=113945
+
+        Reviewed by Martin Robinson.
+
+        Pass a smart pointer in to BitmapImage::create() instead of a raw one
+        for the cairo surface. The factory method prototype was updated for
+        cairo in r147643.
+
+        * Shared/cairo/ShareableBitmapCairo.cpp:
+        (WebKit::ShareableBitmap::createImage):
+
 2013-04-03  Dean Jackson  <[email protected]>
 
         Expose settings to disable plugin snapshotting autostart and primary detection

Modified: trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp (147682 => 147683)


--- trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp	2013-04-04 23:57:33 UTC (rev 147682)
+++ trunk/Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp	2013-04-04 23:59:12 UTC (rev 147683)
@@ -96,8 +96,7 @@
     if (!surface)
         return 0;
 
-    // BitmapImage::create adopts the cairo_surface_t that's passed in, which is why we need to leakRef here.
-    return BitmapImage::create(surface.release().leakRef());
+    return BitmapImage::create(surface.release());
 }
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to