Commit 3e10f165 authored by eric@webkit.org's avatar eric@webkit.org

2009-10-02 Ben Murdoch <benm@google.com>

        Reviewed by David Kilzer.

        Stale database version persists through browser refresh (changeVersion doesn't work)
        https://bugs.webkit.org/show_bug.cgi?id=27836

        Scale the cairo surface of the video sink depending on the
        pixel-aspect-ratio of the video buffer to paint. Also
        destruct/re-create the surface when setSize() is called with a new
        size.

        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
        (WebCore::MediaPlayerPrivate::naturalSize):
        (WebCore::MediaPlayerPrivate::setSize):
        (WebCore::MediaPlayerPrivate::paint):
        * platform/graphics/gtk/VideoSinkGStreamer.cpp:
        (webkit_video_sink_idle_func):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49019 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7e0cd81
......@@ -5,6 +5,25 @@
Stale database version persists through browser refresh (changeVersion doesn't work)
https://bugs.webkit.org/show_bug.cgi?id=27836
Scale the cairo surface of the video sink depending on the
pixel-aspect-ratio of the video buffer to paint. Also
destruct/re-create the surface when setSize() is called with a new
size.
* platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivate::naturalSize):
(WebCore::MediaPlayerPrivate::setSize):
(WebCore::MediaPlayerPrivate::paint):
* platform/graphics/gtk/VideoSinkGStreamer.cpp:
(webkit_video_sink_idle_func):
2009-10-02 Philippe Normand <pnormand@igalia.com>
Reviewed by Gustavo Noronha.
[GTK] missing support for anamorphic PAR video size
https://bugs.webkit.org/show_bug.cgi?id=29717
Tests: storage/change-version-handle-reuse.html
storage/change-version.html
......@@ -334,13 +334,28 @@ IntSize MediaPlayerPrivate::naturalSize() const
if (!hasVideo())
return IntSize();
int x = 0, y = 0;
// TODO: handle possible clean aperture data. See
// https://bugzilla.gnome.org/show_bug.cgi?id=596571
// TODO: handle possible transformation matrix. See
// https://bugzilla.gnome.org/show_bug.cgi?id=596326
int width = 0, height = 0;
if (GstPad* pad = gst_element_get_static_pad(m_videoSink, "sink")) {
gst_video_get_size(GST_PAD(pad), &x, &y);
gst_video_get_size(GST_PAD(pad), &width, &height);
GstCaps* caps = GST_PAD_CAPS(pad);
gfloat pixelAspectRatio;
gint pixelAspectRatioNumerator, pixelAspectRatioDenominator;
if (!gst_video_parse_caps_pixel_aspect_ratio(caps, &pixelAspectRatioNumerator,
&pixelAspectRatioDenominator))
pixelAspectRatioNumerator = pixelAspectRatioDenominator = 1;
pixelAspectRatio = (gfloat) pixelAspectRatioNumerator / (gfloat) pixelAspectRatioDenominator;
width *= pixelAspectRatio;
height /= pixelAspectRatio;
gst_object_unref(GST_OBJECT(pad));
}
return IntSize(x, y);
return IntSize(width, height);
}
bool MediaPlayerPrivate::hasVideo() const
......@@ -624,7 +639,18 @@ void MediaPlayerPrivate::loadingFailed(MediaPlayer::NetworkState error)
void MediaPlayerPrivate::setSize(const IntSize& size)
{
// Destroy and re-create the cairo surface only if the size
// changed.
if (size != m_size) {
if (m_surface)
cairo_surface_destroy(m_surface);
m_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size.width(),
size.height());
g_object_set(m_videoSink, "surface", m_surface, 0);
}
m_size = size;
}
void MediaPlayerPrivate::setVisible(bool visible)
......@@ -645,11 +671,12 @@ void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& rect)
if (!m_visible)
return;
//TODO: m_size vs rect?
cairo_t* cr = context->platformContext();
cairo_save(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
// paint the rectangle on the context and draw the surface inside.
cairo_translate(cr, rect.x(), rect.y());
cairo_rectangle(cr, 0, 0, rect.width(), rect.height());
cairo_set_source_surface(cr, m_surface, 0, 0);
......
......@@ -111,6 +111,12 @@ webkit_video_sink_idle_func(gpointer data)
WebKitVideoSink* sink = reinterpret_cast<WebKitVideoSink*>(data);
WebKitVideoSinkPrivate* priv = sink->priv;
GstBuffer* buffer;
GstCaps* caps;
GstVideoFormat* format;
gint par_n, par_d;
gfloat par;
gint bwidth, bheight;
if (!priv->async_queue)
return FALSE;
......@@ -118,10 +124,27 @@ webkit_video_sink_idle_func(gpointer data)
if (!buffer || G_UNLIKELY(!GST_IS_BUFFER(buffer)))
return FALSE;
cairo_surface_t* src = cairo_image_surface_create_for_data(GST_BUFFER_DATA(buffer), CAIRO_FORMAT_RGB24, priv->width, priv->height, (4 * priv->width + 3) & ~3);
caps = GST_BUFFER_CAPS(buffer);
if (!gst_video_format_parse_caps(caps, format, &bwidth, &bheight)) {
GST_ERROR_OBJECT(sink, "Unknown video format in buffer caps '%s'",
gst_caps_to_string(caps));
return FALSE;
}
if (!gst_video_parse_caps_pixel_aspect_ratio(caps, &par_n, &par_d))
par_n = par_d = 1;
par = (gfloat) par_n / (gfloat) par_d;
// TODO: consider priv->rgb_ordering?
cairo_surface_t* src = cairo_image_surface_create_for_data(GST_BUFFER_DATA(buffer),
CAIRO_FORMAT_RGB24,
bwidth, bheight,
4 * bwidth);
// TODO: We copy the data twice right now. This could be easily improved.
cairo_t* cr = cairo_create(priv->surface);
cairo_scale(cr, par, 1.0 / par);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(cr, src, 0, 0);
cairo_surface_destroy(src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment