⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 202901 in webkit


Ignore:
Timestamp:
Jul 7, 2016, 6:04:00 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Painting a video into a canvas doesn't work when accelerated compositing is enabled
https://bugs.webkit.org/show_bug.cgi?id=159405

Patch by Miguel Gomez <magomez@igalia.com> on 2016-07-07
Reviewed by Xabier Rodriguez-Calvar.

Implement video frame painting to the canvas when accelerated compositing is enabled.

Already covered by existent tests.

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:

(WebCore::MediaPlayerPrivateGStreamer::handleMessage):
Replace custom enumeration for the video rotation with the ImageOrientation class.

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:

(WebCore::MediaPlayerPrivateGStreamerBase::naturalSize):
Replace the orientation value comparison with ImageOrientation::usesWidthAsHeight().
(WebCore::MediaPlayerPrivateGStreamerBase::paint):
Perform the frame painting taking into account the video orientation tag.
(WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
Rotate the native image before returning it.
(WebCore::MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation):
Replace custom enumeration for the video rotation with the ImageOrientation class.
(WebCore::MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase): Deleted.
Remove orientation initialization.

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:

Remove custom enumeration for the video orientation.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r202897 r202901  
     12016-07-07  Miguel Gomez  <magomez@igalia.com>
     2
     3        [GTK] Painting a video into a canvas doesn't work when accelerated compositing is enabled
     4        https://bugs.webkit.org/show_bug.cgi?id=159405
     5
     6        Reviewed by Xabier Rodriguez-Calvar.
     7
     8        Implement video frame painting to the canvas when accelerated compositing is enabled.
     9
     10        Already covered by existent tests.
     11
     12        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
     13        (WebCore::MediaPlayerPrivateGStreamer::handleMessage):
     14        Replace custom enumeration for the video rotation with the ImageOrientation class.
     15        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
     16        (WebCore::MediaPlayerPrivateGStreamerBase::naturalSize):
     17        Replace the orientation value comparison with ImageOrientation::usesWidthAsHeight().
     18        (WebCore::MediaPlayerPrivateGStreamerBase::paint):
     19        Perform the frame painting taking into account the video orientation tag.
     20        (WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
     21        Rotate the native image before returning it.
     22        (WebCore::MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation):
     23        Replace custom enumeration for the video rotation with the ImageOrientation class.
     24        (WebCore::MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase): Deleted.
     25        Remove orientation initialization.
     26        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
     27        Remove custom enumeration for the video orientation.
     28
    1292016-07-07  Philippe Normand  <pnormand@igalia.com>
    230
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

    r202857 r202901  
    10331033        if (gst_tag_list_get_string(tags, GST_TAG_IMAGE_ORIENTATION, &tag.outPtr())) {
    10341034            if (!g_strcmp0(tag.get(), "rotate-90"))
    1035                 setVideoSourceRotation(VideoSourceRotation90);
     1035                setVideoSourceOrientation(ImageOrientation(OriginRightTop));
    10361036            else if (!g_strcmp0(tag.get(), "rotate-180"))
    1037                 setVideoSourceRotation(VideoSourceRotation180);
     1037                setVideoSourceOrientation(ImageOrientation(OriginBottomRight));
    10381038            else if (!g_strcmp0(tag.get(), "rotate-270"))
    1039                 setVideoSourceRotation(VideoSourceRotation270);
     1039                setVideoSourceOrientation(ImageOrientation(OriginLeftBottom));
    10401040        }
    10411041        gst_tag_list_unref(tags);
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp

    r202897 r202901  
    4040#include <wtf/glib/GMutexLocker.h>
    4141#include <wtf/text/CString.h>
     42#include <wtf/MathExtras.h>
    4243
    4344#include <gst/audio/streamvolume.h>
     
    154155#endif
    155156    , m_usingFallbackVideoSink(false)
    156     , m_videoSourceRotation(NoVideoSourceRotation)
    157157#if USE(TEXTURE_MAPPER_GL)
    158158    , m_textureMapperRotationFlag(0)
     
    301301    // When using accelerated compositing, if the video is tagged as rotated 90 or 270 degrees, swap width and height.
    302302    if (m_player->client().mediaPlayerRenderingCanBeAccelerated(m_player)) {
    303         if (m_videoSourceRotation == VideoSourceRotation90 || m_videoSourceRotation == VideoSourceRotation270)
     303        if (m_videoSourceOrientation.usesWidthAsHeight())
    304304            originalSize = originalSize.transposedSize();
    305305    }
     
    609609void MediaPlayerPrivateGStreamerBase::paint(GraphicsContext& context, const FloatRect& rect)
    610610{
    611 #if USE(COORDINATED_GRAPHICS_THREADED)
    612     return;
    613 #elif USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
    614     if (client())
    615         return;
    616 #endif
    617 
    618611    if (context.paintingDisabled())
    619612        return;
     
    626619        return;
    627620
     621    ImagePaintingOptions paintingOptions(CompositeCopy);
     622    if (m_player->client().mediaPlayerRenderingCanBeAccelerated(m_player))
     623        paintingOptions.m_orientationDescription.setImageOrientationEnum(m_videoSourceOrientation);
     624
    628625    RefPtr<ImageGStreamer> gstImage = ImageGStreamer::createImage(m_sample.get());
    629626    if (!gstImage)
     
    631628
    632629    if (Image* image = reinterpret_cast<Image*>(gstImage->image().get()))
    633         context.drawImage(*image, rect, gstImage->rect(), CompositeCopy);
     630        context.drawImage(*image, rect, gstImage->rect(), paintingOptions);
    634631}
    635632
     
    713710    unsigned textureID = *reinterpret_cast<unsigned*>(videoFrame.data[0]);
    714711    IntSize size = IntSize(GST_VIDEO_INFO_WIDTH(&videoInfo), GST_VIDEO_INFO_HEIGHT(&videoInfo));
    715     cairo_surface_t* surface = cairo_gl_surface_create_for_texture(device, CAIRO_CONTENT_COLOR_ALPHA, textureID, size.width(), size.height());
     712    RefPtr<cairo_surface_t> surface = adoptRef(cairo_gl_surface_create_for_texture(device, CAIRO_CONTENT_COLOR_ALPHA, textureID, size.width(), size.height()));
     713
     714    IntSize rotatedSize = m_videoSourceOrientation.usesWidthAsHeight() ? size.transposedSize() : size;
     715    RefPtr<cairo_surface_t> rotatedSurface = adoptRef(cairo_gl_surface_create(device, CAIRO_CONTENT_COLOR_ALPHA, rotatedSize.width(), rotatedSize.height()));
     716    RefPtr<cairo_t> cr = adoptRef(cairo_create(rotatedSurface.get()));
     717
     718    switch (m_videoSourceOrientation) {
     719    case DefaultImageOrientation:
     720        break;
     721    case OriginRightTop:
     722        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
     723        cairo_rotate(cr.get(), piOverTwoDouble);
     724        cairo_translate(cr.get(), -rotatedSize.height() * 0.5, -rotatedSize.width() * 0.5);
     725        break;
     726    case OriginBottomRight:
     727        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
     728        cairo_rotate(cr.get(), piDouble);
     729        cairo_translate(cr.get(), -rotatedSize.width() * 0.5, -rotatedSize.height() * 0.5);
     730        break;
     731    case OriginLeftBottom:
     732        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
     733        cairo_rotate(cr.get(), 3 * piOverTwoDouble);
     734        cairo_translate(cr.get(), -rotatedSize.height() * 0.5, -rotatedSize.width() * 0.5);
     735        break;
     736    default:
     737        ASSERT_NOT_REACHED();
     738        break;
     739    }
     740    cairo_set_source_surface(cr.get(), surface.get(), 0, 0);
     741    cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE);
     742    cairo_paint(cr.get());
     743
    716744    gst_video_frame_unmap(&videoFrame);
    717745
    718     return adoptRef(surface);
    719 }
    720 #endif
    721 
    722 void MediaPlayerPrivateGStreamerBase::setVideoSourceRotation(VideoSourceRotation rotation)
    723 {
    724     if (m_videoSourceRotation == rotation)
    725         return;
    726 
    727     m_videoSourceRotation = rotation;
     746    return rotatedSurface;
     747}
     748#endif
     749
     750void MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation(const ImageOrientation& orientation)
     751{
     752    if (m_videoSourceOrientation == orientation)
     753        return;
     754
     755    m_videoSourceOrientation = orientation;
    728756
    729757#if USE(TEXTURE_MAPPER_GL)
    730     switch (m_videoSourceRotation) {
    731     case NoVideoSourceRotation:
     758    switch (m_videoSourceOrientation) {
     759    case DefaultImageOrientation:
    732760        m_textureMapperRotationFlag = 0;
    733761        break;
    734     case VideoSourceRotation90:
     762    case OriginRightTop:
    735763        m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture90;
    736764        break;
    737     case VideoSourceRotation180:
     765    case OriginBottomRight:
    738766        m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture180;
    739767        break;
    740     case VideoSourceRotation270:
     768    case OriginLeftBottom:
    741769        m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture270;
    742770        break;
     
    772800GstElement* MediaPlayerPrivateGStreamerBase::createVideoSinkGL()
    773801{
     802    // FIXME: Currently it's not possible to get the video frames and caps using this approach until
     803    // the pipeline gets into playing state. Due to this, trying to grab a frame and painting it by some
     804    // other mean (canvas or webgl) before playing state can result in a crash.
     805    // This is being handled in https://bugs.webkit.org/show_bug.cgi?id=159460.
    774806    if (!webkitGstCheckVersion(1, 8, 0))
    775807        return nullptr;
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h

    r202897 r202901  
    6363
    6464public:
    65     enum VideoSourceRotation {
    66         NoVideoSourceRotation,
    67         VideoSourceRotation90,
    68         VideoSourceRotation180,
    69         VideoSourceRotation270
    70     };
    71 
    7265    virtual ~MediaPlayerPrivateGStreamerBase();
    7366
     
    130123#endif
    131124
    132     void setVideoSourceRotation(VideoSourceRotation);
     125    void setVideoSourceOrientation(const ImageOrientation&);
    133126
    134127protected:
     
    209202#endif
    210203
    211     VideoSourceRotation m_videoSourceRotation;
     204    ImageOrientation m_videoSourceOrientation;
    212205#if USE(TEXTURE_MAPPER_GL)
    213206    TextureMapperGL::Flags m_textureMapperRotationFlag;
Note: See TracChangeset for help on using the changeset viewer.