diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2015-01-06 13:45:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-01-09 11:47:58 +0100 |
commit | ffebd1be9dcc78847977d04af2521d43539b9b15 (patch) | |
tree | 42a480bcfd80ab17d99fc0ad1cd11449b7d67fca | |
parent | 4ecb913768ff0806c6efdff4567ef5907f597e4a (diff) |
Optimize HTML5 video painting on Linux
We were doing a needless inversion of image data, that gstreamer somehow
detected and corrected for. The inversion can be safely removed and we
can also avoid copying the image data by releasing the gstreamer buffer
later like the cairo implementation does.
Task-number: QTBUG-43520
Change-Id: I5910d5358d049abe3570dd5468e9e0bb56517639
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
-rw-r--r-- | Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h | 2 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp | 35 |
2 files changed, 15 insertions, 22 deletions
diff --git a/Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h b/Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h index 8b46cd688..87d3f95ba 100644 --- a/Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h +++ b/Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h @@ -60,7 +60,7 @@ class ImageGStreamer : public RefCounted<ImageGStreamer> { RefPtr<BitmapImage> m_image; FloatRect m_cropRect; -#if USE(CAIRO) && defined(GST_API_VERSION_1) +#if defined(GST_API_VERSION_1) GRefPtr<GstBuffer> m_buffer; GstMapInfo m_mapInfo; #endif diff --git a/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp b/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp index 375026d1f..ece3c3f27 100644 --- a/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/ImageGStreamerQt.cpp @@ -30,11 +30,12 @@ #include <wtf/gobject/GOwnPtr.h> -using namespace std; using namespace WebCore; ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps) - : m_image(0) +#ifdef GST_API_VERSION_1 + : m_buffer(buffer) +#endif { GstVideoFormat format; IntSize size; @@ -42,40 +43,26 @@ ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps) getVideoSizeAndFormatFromCaps(caps, size, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride); #ifdef GST_API_VERSION_1 - GstMapInfo info; - gst_buffer_map(buffer, &info, GST_MAP_READ); - uchar* bufferData = reinterpret_cast<uchar*>(info.data); + gst_buffer_map(buffer, &m_mapInfo, GST_MAP_READ); + uchar* bufferData = reinterpret_cast<uchar*>(m_mapInfo.data); #else uchar* bufferData = reinterpret_cast<uchar*>(GST_BUFFER_DATA(buffer)); #endif QImage::Format imageFormat; - QImage::InvertMode invertMode; #if G_BYTE_ORDER == G_LITTLE_ENDIAN - if (format == GST_VIDEO_FORMAT_BGRA) { - imageFormat = QImage::Format_ARGB32; - invertMode = QImage::InvertRgba; - } else { - imageFormat = QImage::Format_RGB32; - invertMode = QImage::InvertRgb; - } + imageFormat = (format == GST_VIDEO_FORMAT_BGRA) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; #else - imageFormat = (format == GST_VIDEO_FORMAT_ARGB) ? QImage::Format_ARGB32 : QImage::Format_RGB32; + imageFormat = (format == GST_VIDEO_FORMAT_ARGB) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; #endif QImage image(bufferData, size.width(), size.height(), imageFormat); -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - image.invertPixels(invertMode); -#endif - QPixmap* surface = new QPixmap; - surface->convertFromImage(image); + QPixmap *surface = new QPixmap(QPixmap::fromImage(qMove(image), Qt::NoFormatConversion)); m_image = BitmapImage::create(surface); #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, &info); #endif } @@ -85,6 +72,12 @@ 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 + // QImage/QPixmap was created using the buffer data directly. + gst_buffer_unmap(m_buffer.get(), &m_mapInfo); +#endif } #endif // USE(GSTREAMER) |