[vlc-devel] [PATCH 4/4] Add initial Windows windowless support

Cheng Sun chengsun9 at gmail.com
Sun Dec 30 21:51:55 CET 2012


---
 npapi/Makefile.am           |   2 +
 npapi/vlcplugin.h           |   4 ++
 npapi/vlcwindowless_win.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++++
 npapi/vlcwindowless_win.h   |  42 +++++++++++++++
 4 files changed, 170 insertions(+)
 create mode 100644 npapi/vlcwindowless_win.cpp
 create mode 100644 npapi/vlcwindowless_win.h

diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index 7ef1bf7..fa4d728 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -105,6 +105,8 @@ SOURCES_support = \
 	support/npwin.cpp \
 	vlcplugin_win.cpp \
 	vlcplugin_win.h \
+	vlcwindowless_win.cpp \
+	vlcwindowless_win.h \
 	../common/win32_fullscreen.cpp \
 	../common/win32_fullscreen.h \
 	../common/win32_vlcwnd.cpp \
diff --git a/npapi/vlcplugin.h b/npapi/vlcplugin.h
index 1bcc58a..defc012 100644
--- a/npapi/vlcplugin.h
+++ b/npapi/vlcplugin.h
@@ -51,6 +51,10 @@
 #elif defined(XP_WIN)
 #   include "vlcplugin_win.h"
     typedef class VlcPluginWin VlcPlugin;
+
+#   define WINDOWLESS
+#   include "vlcwindowless_win.h"
+    typedef class VlcWindowlessWin VlcWindowless;
 #elif defined(XP_MACOSX)
 #   include "vlcplugin_mac.h"
     typedef class VlcPluginMac VlcPlugin;
diff --git a/npapi/vlcwindowless_win.cpp b/npapi/vlcwindowless_win.cpp
new file mode 100644
index 0000000..7dd5829
--- /dev/null
+++ b/npapi/vlcwindowless_win.cpp
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ * vlcwindowless_win.cpp: a VLC plugin for Mozilla (Windows windowless)
+ *****************************************************************************
+ * Copyright (C) 2011 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Cheng Sun <chengsun9 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "vlcwindowless_win.h"
+#include <cstdio>
+
+VlcWindowlessWin::VlcWindowlessWin(NPP instance, NPuint16_t mode) :
+    VlcWindowlessBase(instance, mode)
+{
+    m_hBgBrush = CreateSolidBrush( RGB(255,0,255) );
+}
+
+VlcWindowlessWin::~VlcWindowlessWin()
+{
+    DeleteObject(m_hBgBrush);
+}
+
+bool VlcWindowlessWin::handle_event(void *event)
+{
+    NPEvent *npevent = reinterpret_cast<NPEvent *> (event);
+    switch (npevent->event) {
+    case WM_PAINT:
+        BOOL ret;
+        HDC hDC = reinterpret_cast<HDC> (npwindow.window);
+        if (!hDC) {
+            fprintf(stderr, "NULL HDC given by browser\n");
+            return false;
+        }
+        int savedID = SaveDC(hDC);
+
+        RECT *clipRect = reinterpret_cast<RECT *> (npevent->lParam);
+
+        ret = FillRect(hDC, clipRect, m_hBgBrush);
+        if (!ret) {
+            LPVOID lpMsgBuf;
+            FormatMessage( 
+                FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+                FORMAT_MESSAGE_FROM_SYSTEM | 
+                FORMAT_MESSAGE_IGNORE_INSERTS,
+                NULL,
+                GetLastError(),
+                0, // Default language
+                (LPTSTR) &lpMsgBuf,
+                0,
+                NULL 
+            );
+
+            fprintf(stderr, "Error in FillRect: %s\n", lpMsgBuf);
+            LocalFree( lpMsgBuf );
+        }
+
+        if ( m_frame_buf.size() &&
+             m_frame_buf.size() >= m_media_width * m_media_height * DEF_PIXEL_BYTES)
+        {
+            BITMAPINFO BmpInfo; ZeroMemory(&BmpInfo, sizeof(BmpInfo));
+            BITMAPINFOHEADER& BmpH = BmpInfo.bmiHeader;
+            BmpH.biSize = sizeof(BITMAPINFOHEADER);
+            BmpH.biWidth = m_media_width;
+            BmpH.biHeight = -((int)m_media_height);
+            BmpH.biPlanes = 1;
+            BmpH.biBitCount = DEF_PIXEL_BYTES*8;
+            BmpH.biCompression = BI_RGB;
+            //following members are already zeroed
+            //BmpH.biSizeImage = 0;
+            //BmpH.biXPelsPerMeter = 0;
+            //BmpH.biYPelsPerMeter = 0;
+            //BmpH.biClrUsed = 0;
+            //BmpH.biClrImportant = 0;
+
+
+            ret = SetDIBitsToDevice(hDC,
+                            npwindow.x + (npwindow.width - m_media_width)/2,
+                            npwindow.y + (npwindow.height - m_media_height)/2,
+                            m_media_width, m_media_height,
+                            0, 0,
+                            0, m_media_height,
+                            &m_frame_buf[0],
+                            &BmpInfo, DIB_RGB_COLORS);
+            if (!ret) {
+                LPVOID lpMsgBuf;
+                FormatMessage( 
+                    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+                    FORMAT_MESSAGE_FROM_SYSTEM | 
+                    FORMAT_MESSAGE_IGNORE_INSERTS,
+                    NULL,
+                    GetLastError(),
+                    0, // Default language
+                    (LPTSTR) &lpMsgBuf,
+                    0,
+                    NULL 
+                );
+
+                fprintf(stderr, "Error in SetDIBitsToDevice: %s\n", lpMsgBuf);
+                LocalFree( lpMsgBuf );
+            }
+
+        }
+        RestoreDC(hDC, savedID);
+        return true;
+    }
+    return VlcWindowlessBase::handle_event(event);
+}
diff --git a/npapi/vlcwindowless_win.h b/npapi/vlcwindowless_win.h
new file mode 100644
index 0000000..1707702
--- /dev/null
+++ b/npapi/vlcwindowless_win.h
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * vlcwindowless_win.h: a VLC plugin for Mozilla (Windows windowless)
+ *****************************************************************************
+ * Copyright (C) 2011 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Cheng Sun <chengsun9 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef __VLCWINDOWS_LINUX_H__
+#define __VLCWINDOWS_LINUX_H__
+
+#include "vlcwindowless_base.h"
+
+class VlcWindowlessWin : public VlcWindowlessBase
+{
+public:
+    VlcWindowlessWin(NPP instance, NPuint16_t mode);
+    virtual ~VlcWindowlessWin();
+
+    bool handle_event(void *event);
+
+private:
+    HBRUSH m_hBgBrush;
+};
+
+
+#endif /* __VLCWINDOWLESS_LINUX_H__ */
-- 
1.8.0.3




More information about the vlc-devel mailing list