1 /*****************************************************************************
2 * wingdi.c : Win32 / WinCE GDI video output plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Samuel Hocevar <sam@zoy.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_vout_display.h>
43 #ifndef WS_NONAVDONEBUTTON
44 # define WS_NONAVDONEBUTTON 0
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Open (vlc_object_t *);
51 static void Close(vlc_object_t *);
54 set_category(CAT_VIDEO)
55 set_subcategory(SUBCAT_VIDEO_VOUT)
56 #ifdef MODULE_NAME_IS_wingapi
58 set_description(N_("Windows GAPI video output"))
59 set_capability("vout display", 20)
62 set_description(N_("Windows GDI video output"))
63 set_capability("vout display", 10)
65 set_callbacks(Open, Close)
69 /*****************************************************************************
71 *****************************************************************************/
72 static picture_pool_t *Pool (vout_display_t *, unsigned);
73 static void Display(vout_display_t *, picture_t *);
74 static int Control(vout_display_t *, int, va_list);
75 static void Manage (vout_display_t *);
77 static int Init(vout_display_t *, video_format_t *, int, int);
78 static void Clean(vout_display_t *);
81 static int Open(vlc_object_t *object)
83 vout_display_t *vd = (vout_display_t *)object;
84 vout_display_sys_t *sys;
86 vd->sys = sys = calloc(1, sizeof(*sys));
90 #ifdef MODULE_NAME_IS_wingapi
92 sys->gapi_dll = LoadLibrary(_T("GX.DLL"));
94 msg_Warn(vd, "failed loading gx.dll");
99 GXOpenDisplay = (void *)GetProcAddress(sys->gapi_dll,
100 _T("?GXOpenDisplay@@YAHPAUHWND__@@K@Z"));
101 GXCloseDisplay = (void *)GetProcAddress(sys->gapi_dll,
102 _T("?GXCloseDisplay@@YAHXZ"));
103 GXBeginDraw = (void *)GetProcAddress(sys->gapi_dll,
104 _T("?GXBeginDraw@@YAPAXXZ"));
105 GXEndDraw = (void *)GetProcAddress(sys->gapi_dll,
106 _T("?GXEndDraw@@YAHXZ"));
107 GXGetDisplayProperties = (void *)GetProcAddress(sys->gapi_dll,
108 _T("?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ"));
109 GXSuspend = (void *)GetProcAddress(sys->gapi_dll,
110 _T("?GXSuspend@@YAHXZ"));
111 GXResume = GetProcAddress(sys->gapi_dll,
112 _T("?GXResume@@YAHXZ"));
114 if (!GXOpenDisplay || !GXCloseDisplay ||
115 !GXBeginDraw || !GXEndDraw ||
116 !GXGetDisplayProperties || !GXSuspend || !GXResume) {
117 msg_Err(vd, "failed GetProcAddress on gapi.dll");
122 msg_Dbg(vd, "GAPI DLL loaded");
129 video_format_t fmt = vd->fmt;
130 if (Init(vd, &fmt, fmt.i_width, fmt.i_height))
133 vout_display_info_t info = vd->info;
134 info.is_slow = false;
135 info.has_double_click = true;
136 info.has_hide_mouse = false;
137 info.has_pictures_invalid = true;
145 vd->display = Display;
147 vd->control = Control;
151 Close(VLC_OBJECT(vd));
156 static void Close(vlc_object_t *object)
158 vout_display_t *vd = (vout_display_t *)object;
164 #ifdef MODULE_NAME_IS_wingapi
165 FreeLibrary(vd->sys->gapi_dll);
172 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
175 return vd->sys->pool;
177 static void Display(vout_display_t *vd, picture_t *picture)
179 vout_display_sys_t *sys = vd->sys;
181 #ifdef MODULE_NAME_IS_wingapi
184 #define rect_src vd->sys->rect_src
185 #define rect_src_clipped vd->sys->rect_src_clipped
186 #define rect_dest vd->sys->rect_dest
187 #define rect_dest_clipped vd->sys->rect_dest_clipped
188 RECT rect_dst = rect_dest_clipped;
189 HDC hdc = GetDC(sys->hvideownd);
191 OffsetRect(&rect_dst, -rect_dest.left, -rect_dest.top);
192 SelectObject(sys->off_dc, sys->off_bitmap);
194 if (rect_dest_clipped.right - rect_dest_clipped.left !=
195 rect_src_clipped.right - rect_src_clipped.left ||
196 rect_dest_clipped.bottom - rect_dest_clipped.top !=
197 rect_src_clipped.bottom - rect_src_clipped.top) {
198 StretchBlt(hdc, rect_dst.left, rect_dst.top,
199 rect_dst.right, rect_dst.bottom,
201 rect_src_clipped.left, rect_src_clipped.top,
202 rect_src_clipped.right, rect_src_clipped.bottom,
205 BitBlt(hdc, rect_dst.left, rect_dst.top,
206 rect_dst.right, rect_dst.bottom,
208 rect_src_clipped.left, rect_src_clipped.top,
212 ReleaseDC(sys->hvideownd, hdc);
214 #undef rect_src_clipped
216 #undef rect_dest_clipped
219 picture_Release(picture);
223 static int Control(vout_display_t *vd, int query, va_list args)
226 case VOUT_DISPLAY_RESET_PICTURES:
230 return CommonControl(vd, query, args);
234 static void Manage(vout_display_t *vd)
239 #ifdef MODULE_NAME_IS_wingapi
240 struct picture_sys_t {
244 static int Lock(picture_t *picture)
246 vout_display_t *vd = picture->p_sys->vd;
247 vout_display_sys_t *sys = vd->sys;
250 if (sys->rect_dest_clipped.right - sys->rect_dest_clipped.left != vd->fmt.i_width ||
251 sys->rect_dest_clipped.bottom - sys->rect_dest_clipped.top != vd->fmt.i_height)
255 GXDisplayProperties gxdisplayprop = GXGetDisplayProperties();
256 uint8_t *p_pic_buffer = GXBeginDraw();
258 msg_Err(vd, "GXBeginDraw error %d ", GetLastError());
261 p_pic_buffer += sys->rect_dest.top * gxdisplayprop.cbyPitch +
262 sys->rect_dest.left * gxdisplayprop.cbxPitch;
265 picture->p[0].i_pitch = gxdisplayprop.cbyPitch;
266 picture->p[0].p_pixels = p_pic_buffer;
270 static void Unlock(picture_t *picture)
272 vout_display_t *vd = picture->p_sys->vd;
278 static int Init(vout_display_t *vd,
279 video_format_t *fmt, int width, int height)
281 vout_display_sys_t *sys = vd->sys;
284 RECT *display = &sys->rect_display;
287 #ifdef MODULE_NAME_IS_wingapi
288 display->right = GXGetDisplayProperties().cxWidth;
289 display->bottom = GXGetDisplayProperties().cyHeight;
291 display->right = GetSystemMetrics(SM_CXSCREEN);;
292 display->bottom = GetSystemMetrics(SM_CYSCREEN);;
295 /* Initialize an offscreen bitmap for direct buffer operations. */
298 HDC window_dc = GetDC(sys->hvideownd);
301 #ifdef MODULE_NAME_IS_wingapi
302 GXDisplayProperties gx_displayprop = GXGetDisplayProperties();
303 sys->i_depth = gx_displayprop.cBPP;
306 sys->i_depth = GetDeviceCaps(window_dc, PLANES) *
307 GetDeviceCaps(window_dc, BITSPIXEL);
311 msg_Dbg(vd, "GDI depth is %i", sys->i_depth);
312 switch (sys->i_depth) {
314 fmt->i_chroma = VLC_CODEC_RGB8;
317 fmt->i_chroma = VLC_CODEC_RGB15;
318 fmt->i_rmask = 0x7c00;
319 fmt->i_gmask = 0x03e0;
320 fmt->i_bmask = 0x001f;
323 fmt->i_chroma = VLC_CODEC_RGB16;
324 fmt->i_rmask = 0xf800;
325 fmt->i_gmask = 0x07e0;
326 fmt->i_bmask = 0x001f;
329 fmt->i_chroma = VLC_CODEC_RGB24;
330 fmt->i_rmask = 0x00ff0000;
331 fmt->i_gmask = 0x0000ff00;
332 fmt->i_bmask = 0x000000ff;
335 fmt->i_chroma = VLC_CODEC_RGB32;
336 fmt->i_rmask = 0x00ff0000;
337 fmt->i_gmask = 0x0000ff00;
338 fmt->i_bmask = 0x000000ff;
341 msg_Err(vd, "screen depth %i not supported", sys->i_depth);
344 fmt->i_width = width;
345 fmt->i_height = height;
347 uint8_t *p_pic_buffer;
349 #ifdef MODULE_NAME_IS_wingapi
350 GXOpenDisplay(sys->hvideownd, GX_FULLSCREEN);
351 EventThreadUpdateTitle(sys->event, VOUT_TITLE " (WinGAPI output)");
353 /* Filled by pool::lock() */
357 /* Initialize offscreen bitmap */
358 BITMAPINFO *bi = &sys->bitmapinfo;
359 memset(bi, 0, sizeof(BITMAPINFO) + 3 * sizeof(RGBQUAD));
360 if (sys->i_depth > 8) {
361 ((DWORD*)bi->bmiColors)[0] = fmt->i_rmask;
362 ((DWORD*)bi->bmiColors)[1] = fmt->i_gmask;
363 ((DWORD*)bi->bmiColors)[2] = fmt->i_bmask;;
366 BITMAPINFOHEADER *bih = &sys->bitmapinfo.bmiHeader;
367 bih->biSize = sizeof(BITMAPINFOHEADER);
368 bih->biSizeImage = 0;
370 bih->biCompression = (sys->i_depth == 15 ||
371 sys->i_depth == 16) ? BI_BITFIELDS : BI_RGB;
372 bih->biBitCount = sys->i_depth;
373 bih->biWidth = fmt->i_width;
374 bih->biHeight = -fmt->i_height;
375 bih->biClrImportant = 0;
377 bih->biXPelsPerMeter = 0;
378 bih->biYPelsPerMeter = 0;
380 i_pic_pitch = bih->biBitCount * bih->biWidth / 8;
381 sys->off_bitmap = CreateDIBSection(window_dc,
384 &p_pic_buffer, NULL, 0);
386 sys->off_dc = CreateCompatibleDC(window_dc);
388 SelectObject(sys->off_dc, sys->off_bitmap);
389 ReleaseDC(sys->hvideownd, window_dc);
391 EventThreadUpdateTitle(sys->event, VOUT_TITLE " (WinGDI output)");
395 picture_resource_t rsc;
396 memset(&rsc, 0, sizeof(rsc));
397 #ifdef MODULE_NAME_IS_wingapi
398 rsc.p_sys = malloc(sizeof(*rsc.p_sys));
403 rsc.p[0].p_pixels = p_pic_buffer;
404 rsc.p[0].i_lines = fmt->i_height;
405 rsc.p[0].i_pitch = i_pic_pitch;;
407 picture_t *picture = picture_NewFromResource(fmt, &rsc);
409 picture_pool_configuration_t cfg;
410 memset(&cfg, 0, sizeof(cfg));
411 cfg.picture_count = 1;
412 cfg.picture = &picture;
413 #ifdef MODULE_NAME_IS_wingapi
417 sys->pool = picture_pool_NewExtended(&cfg);
423 UpdateRects(vd, NULL, NULL, true);
428 static void Clean(vout_display_t *vd)
430 vout_display_sys_t *sys = vd->sys;
433 picture_pool_Delete(sys->pool);
436 #ifdef MODULE_NAME_IS_wingapi
440 DeleteDC(sys->off_dc);
442 DeleteObject(sys->off_bitmap);