Images: bug fix (gst-1.0), improvement of includes 64/5864/1
authorJosé Bollo <jose.bollo@eurogiciel.fr>
Wed, 17 Jul 2013 12:37:13 +0000 (14:37 +0200)
committerJosé Bollo <jose.bollo@eurogiciel.fr>
Wed, 17 Jul 2013 12:37:49 +0000 (14:37 +0200)
Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h
Source/WebCore/platform/graphics/gstreamer/ImageGStreamerCairo.cpp
Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp

index 7a0e5ee..8b46cd6 100644 (file)
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
-#if PLATFORM(QT)
-#include <QImage>
-#endif
-
 namespace WebCore {
 class IntSize;
 
@@ -55,15 +51,19 @@ class ImageGStreamer : public RefCounted<ImageGStreamer> {
         {
             if (!m_cropRect.isEmpty())
                 return FloatRect(m_cropRect);
-
-            // Default rectangle used by GraphicsContext::drawImage().
-            return FloatRect(0, 0, -1, -1);
+            ASSERT(m_image);
+            return FloatRect(0, 0, m_image->size().width(), m_image->size().height());
         }
 
     private:
         ImageGStreamer(GstBuffer*, GstCaps*);
         RefPtr<BitmapImage> m_image;
         FloatRect m_cropRect;
+
+#if USE(CAIRO) && defined(GST_API_VERSION_1)
+        GRefPtr<GstBuffer> m_buffer;
+        GstMapInfo m_mapInfo;
+#endif
     };
 }
 
index d3f7fa7..a4e8628 100644 (file)
@@ -36,6 +36,9 @@ using namespace std;
 using namespace WebCore;
 
 ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
+#ifdef GST_API_VERSION_1
+    : m_buffer(buffer)
+#endif
 {
     GstVideoFormat format;
     IntSize size;
@@ -43,9 +46,8 @@ ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
     getVideoSizeAndFormatFromCaps(caps, size, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride);
 
 #ifdef GST_API_VERSION_1
-    GstMapInfo mapInfo;
-    gst_buffer_map(buffer, &mapInfo, GST_MAP_READ);
-    unsigned char* bufferData = reinterpret_cast<unsigned char*>(mapInfo.data);
+    gst_buffer_map(buffer, &m_mapInfo, GST_MAP_READ);
+    unsigned char* bufferData = reinterpret_cast<unsigned char*>(m_mapInfo.data);
 #else
     unsigned char* bufferData = reinterpret_cast<unsigned char*>(GST_BUFFER_DATA(buffer));
 #endif
@@ -64,8 +66,6 @@ ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
 #ifdef GST_API_VERSION_1
     if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))
         setCropRect(FloatRect(cropMeta->x, cropMeta->y, cropMeta->width, cropMeta->height));
-
-    gst_buffer_unmap(buffer, &mapInfo);
 #endif
 }
 
@@ -75,5 +75,11 @@ ImageGStreamer::~ImageGStreamer()
         m_image.clear();
 
     m_image = 0;
+
+#ifdef GST_API_VERSION_1
+    // We keep the buffer memory mapped until the image is destroyed because the internal
+    // cairo_surface_t was created using cairo_image_surface_create_for_data().
+    gst_buffer_unmap(m_buffer.get(), &m_mapInfo);
+#endif
 }
 #endif // USE(GSTREAMER)
index d6e6e2a..375026d 100644 (file)
@@ -67,8 +67,9 @@ ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
     image.invertPixels(invertMode);
 #endif
-
-    m_image = BitmapImage::create(new QImage(image));
+    QPixmap* surface = new QPixmap;
+    surface->convertFromImage(image);
+    m_image = BitmapImage::create(surface);
 
 #ifdef GST_API_VERSION_1
     if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))