Commit c7906cec authored by Cheng Sun's avatar Cheng Sun Committed by Jean-Baptiste Kempf

Add initial Windows windowless support

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 6a68ec05
......@@ -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 \
......
......@@ -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)
# define WINDOWLESS
......
/*****************************************************************************
* vlcwindowless_win.cpp: a VLC plugin for Mozilla (Windows windowless)
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Sergey Radionov <rsatom@gmail.com>
* Mark Lesha <mlesha(at)hotmail(dot)com>
* Cheng Sun <chengsun9@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)
{
unsigned r = 0, g = 0, b = 0;
HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b);
m_hBgBrush = CreateSolidBrush( RGB(r,g,b) );
}
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);
}
/*****************************************************************************
* vlcwindowless_win.h: a VLC plugin for Mozilla (Windows windowless)
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Cheng Sun <chengsun9@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__ */
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