[WinCairo][MediaFoundation] Video is not rendered correctly on some graphics cards.
authorpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Dec 2015 19:46:26 +0000 (19:46 +0000)
committerpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Dec 2015 19:46:26 +0000 (19:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151757

Reviewed by Alex Christensen.

We need to make sure we use the same bitmap format as in the Direct3D surface
in video memory when copying surface data and rendering with Cairo.

* platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
(WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample):
(WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192951 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp

index f902de7..cd54ec7 100644 (file)
@@ -1,3 +1,17 @@
+2015-12-02  Per Arne Vollan  <peavo@outlook.com>
+
+        [WinCairo][MediaFoundation] Video is not rendered correctly on some graphics cards.
+        https://bugs.webkit.org/show_bug.cgi?id=151757
+
+        Reviewed by Alex Christensen.
+
+        We need to make sure we use the same bitmap format as in the Direct3D surface
+        in video memory when copying surface data and rendering with Cairo.
+
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
+        (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample):
+        (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame):
+
 2015-12-02  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Get rid of IDBExceptionCode.
index 8dcca43..77269d1 100644 (file)
@@ -2677,7 +2677,11 @@ HRESULT MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample(IMFS
 
         if (width > 0 && height > 0) {
             if (!m_memSurface || m_width != width || m_height != height) {
-                hr = m_device->CreateOffscreenPlainSurface(width, height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &m_memSurface, nullptr);
+                D3DFORMAT format = D3DFMT_A8R8G8B8;
+                D3DSURFACE_DESC desc;
+                if (SUCCEEDED(surface->GetDesc(&desc)))
+                    format = desc.Format;
+                hr = m_device->CreateOffscreenPlainSurface(width, height, format, D3DPOOL_SYSTEMMEM, &m_memSurface, nullptr);
                 m_width = width;
                 m_height = height;
             }
@@ -2728,11 +2732,34 @@ void MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame(Web
         void* data = lockedRect.pBits;
         int pitch = lockedRect.Pitch;
 #if USE(CAIRO)
-        WebCore::PlatformContextCairo* ctxt = context.platformContext();
-        cairo_surface_t* image = cairo_image_surface_create_for_data(static_cast<unsigned char*>(data), CAIRO_FORMAT_ARGB32, width, height, pitch);
+        D3DFORMAT format = D3DFMT_UNKNOWN;
+        D3DSURFACE_DESC desc;
+        if (SUCCEEDED(m_memSurface->GetDesc(&desc)))
+            format = desc.Format;
+
+        cairo_format_t cairoFormat = CAIRO_FORMAT_INVALID;
+
+        switch (format) {
+        case D3DFMT_A8R8G8B8:
+            cairoFormat = CAIRO_FORMAT_ARGB32;
+            break;
+        case D3DFMT_X8R8G8B8:
+            cairoFormat = CAIRO_FORMAT_RGB24;
+            break;
+        }
+
+        ASSERT(cairoFormat != CAIRO_FORMAT_INVALID);
+
+        cairo_surface_t* image = nullptr;
+        if (cairoFormat != CAIRO_FORMAT_INVALID)
+            image = cairo_image_surface_create_for_data(static_cast<unsigned char*>(data), cairoFormat, width, height, pitch);
+
         FloatRect srcRect(0, 0, width, height);
-        ctxt->drawSurfaceToContext(image, destRect, srcRect, context);
-        cairo_surface_destroy(image);
+        if (image) {
+            WebCore::PlatformContextCairo* ctxt = context.platformContext();
+            ctxt->drawSurfaceToContext(image, destRect, srcRect, context);
+            cairo_surface_destroy(image);
+        }
 #else
 #error "Platform needs to implement drawing of Direct3D surface to graphics context!"
 #endif