| 1 | /******************************************************************************
|
|---|
| 2 | * vo_directx.c: Directx v2 or later DirectDraw interface for MPlayer
|
|---|
| 3 | * Copyright (c) 2002 - 2005 Sascha Sommer <saschasommer@freenet.de>.
|
|---|
| 4 | *
|
|---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 6 | * it under the terms of the GNU General Public License as published by
|
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 8 | * (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 10 | * This program is distributed in the hope that it will be useful,
|
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | * GNU General Public License for more details.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU General Public License
|
|---|
| 16 | * along with this program; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
|---|
| 18 | *
|
|---|
| 19 | *****************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | #include <windows.h>
|
|---|
| 22 | #include <windowsx.h>
|
|---|
| 23 | #include <ddraw.h>
|
|---|
| 24 | #include <stdio.h>
|
|---|
| 25 | #include <stdlib.h>
|
|---|
| 26 | #include <errno.h>
|
|---|
| 27 | #include "config.h"
|
|---|
| 28 | #include "video_out.h"
|
|---|
| 29 | #include "video_out_internal.h"
|
|---|
| 30 | #include "fastmemcpy.h"
|
|---|
| 31 | #include "input/input.h"
|
|---|
| 32 | #include "osdep/keycodes.h"
|
|---|
| 33 | #include "input/mouse.h"
|
|---|
| 34 | #include "mp_msg.h"
|
|---|
| 35 | #include "aspect.h"
|
|---|
| 36 | #include "geometry.h"
|
|---|
| 37 |
|
|---|
| 38 | #ifndef WM_XBUTTONDOWN
|
|---|
| 39 | # define WM_XBUTTONDOWN 0x020B
|
|---|
| 40 | # define WM_XBUTTONUP 0x020C
|
|---|
| 41 | # define WM_XBUTTONDBLCLK 0x020D
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | #define WNDCLASSNAME_WINDOWED "MPlayer - The Movie Player"
|
|---|
| 45 | #define WNDCLASSNAME_FULLSCREEN "MPlayer - Fullscreen"
|
|---|
| 46 | #define WNDSTYLE WS_OVERLAPPEDWINDOW|WS_SIZEBOX
|
|---|
| 47 |
|
|---|
| 48 | static LPDIRECTDRAWCOLORCONTROL g_cc = NULL; //color control interface
|
|---|
| 49 | static LPDIRECTDRAW7 g_lpdd = NULL; //DirectDraw Object
|
|---|
| 50 | static LPDIRECTDRAWSURFACE7 g_lpddsPrimary = NULL; //Primary Surface: viewport through the Desktop
|
|---|
| 51 | static LPDIRECTDRAWSURFACE7 g_lpddsOverlay = NULL; //Overlay Surface
|
|---|
| 52 | static LPDIRECTDRAWSURFACE7 g_lpddsBack = NULL; //Back surface
|
|---|
| 53 | static LPDIRECTDRAWCLIPPER g_lpddclipper; //clipper object, can only be used without overlay
|
|---|
| 54 | static DDSURFACEDESC2 ddsdsf; //surface descripiton needed for locking
|
|---|
| 55 | static HINSTANCE hddraw_dll; //handle to ddraw.dll
|
|---|
| 56 | static RECT rd; //rect of our stretched image
|
|---|
| 57 | static RECT rs; //rect of our source image
|
|---|
| 58 | static HWND hWnd=NULL; //handle to the window
|
|---|
| 59 | static HWND hWndFS=NULL; //fullscreen window
|
|---|
| 60 | static HBRUSH colorbrush = NULL; // Handle to colorkey brush
|
|---|
| 61 | static HBRUSH blackbrush = NULL; // Handle to black brush
|
|---|
| 62 | static HICON mplayericon = NULL; // Handle to mplayer icon
|
|---|
| 63 | static HCURSOR mplayercursor = NULL; // Handle to mplayer cursor
|
|---|
| 64 | static uint32_t image_width, image_height; //image width and height
|
|---|
| 65 | static uint32_t d_image_width, d_image_height; //image width and height zoomed
|
|---|
| 66 | static uint8_t *image=NULL; //image data
|
|---|
| 67 | static uint32_t image_format=0; //image format
|
|---|
| 68 | static uint32_t primary_image_format;
|
|---|
| 69 | static uint32_t vm_height=0;
|
|---|
| 70 | static uint32_t vm_width=0;
|
|---|
| 71 | static uint32_t vm_bpp=0;
|
|---|
| 72 | static uint32_t dstride; //surface stride
|
|---|
| 73 | static uint32_t nooverlay = 0; //NonOverlay mode
|
|---|
| 74 | static DWORD destcolorkey; //colorkey for our surface
|
|---|
| 75 | static COLORREF windowcolor = RGB(0,0,16); //windowcolor == colorkey
|
|---|
| 76 | static int adapter_count=0;
|
|---|
| 77 | static GUID selected_guid;
|
|---|
| 78 | static GUID *selected_guid_ptr = NULL;
|
|---|
| 79 | static RECT monitor_rect; //monitor coordinates
|
|---|
| 80 | static float window_aspect;
|
|---|
| 81 | static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL;
|
|---|
| 82 |
|
|---|
| 83 | extern void mplayer_put_key(int code); //let mplayer handel the keyevents
|
|---|
| 84 | extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
|
|---|
| 85 | extern int vidmode;
|
|---|
| 86 |
|
|---|
| 87 | /*****************************************************************************
|
|---|
| 88 | * DirectDraw GUIDs.
|
|---|
| 89 | * Defining them here allows us to get rid of the dxguid library during
|
|---|
| 90 | * the linking stage.
|
|---|
| 91 | *****************************************************************************/
|
|---|
| 92 | const GUID IID_IDirectDraw7 =
|
|---|
| 93 | {
|
|---|
| 94 | 0x15e65ec0,0x3b9c,0x11d2,{0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b}
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | const GUID IID_IDirectDrawColorControl =
|
|---|
| 98 | {
|
|---|
| 99 | 0x4b9f0ee0,0x0d7e,0x11d0,{0x9b,0x06,0x00,0xa0,0xc9,0x03,0xa3,0xb8}
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | typedef struct directx_fourcc_caps
|
|---|
| 104 | {
|
|---|
| 105 | char* img_format_name; //human readable name
|
|---|
| 106 | uint32_t img_format; //as MPlayer image format
|
|---|
| 107 | uint32_t drv_caps; //what hw supports with this format
|
|---|
| 108 | DDPIXELFORMAT g_ddpfOverlay; //as Directx Sourface description
|
|---|
| 109 | } directx_fourcc_caps;
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | static directx_fourcc_caps g_ddpf[] =
|
|---|
| 113 | {
|
|---|
| 114 | {"YV12 ",IMGFMT_YV12 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','1','2'),0,0,0,0,0}},
|
|---|
| 115 | {"I420 ",IMGFMT_I420 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','4','2','0'),0,0,0,0,0}}, //yv12 with swapped uv
|
|---|
| 116 | {"IYUV ",IMGFMT_IYUV ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','Y','U','V'),0,0,0,0,0}}, //same as i420
|
|---|
| 117 | {"YVU9 ",IMGFMT_YVU9 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','U','9'),0,0,0,0,0}},
|
|---|
| 118 | {"YUY2 ",IMGFMT_YUY2 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','U','Y','2'),0,0,0,0,0}},
|
|---|
| 119 | {"UYVY ",IMGFMT_UYVY ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('U','Y','V','Y'),0,0,0,0,0}},
|
|---|
| 120 | {"BGR8 ",IMGFMT_BGR8 ,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0x00000000, 0x00000000, 0x00000000, 0}},
|
|---|
| 121 | {"RGB15",IMGFMT_RGB15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000003E0, 0x00007C00, 0}}, //RGB 5:5:5
|
|---|
| 122 | {"BGR15",IMGFMT_BGR15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00007C00, 0x000003E0, 0x0000001F, 0}},
|
|---|
| 123 | {"RGB16",IMGFMT_RGB16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000007E0, 0x0000F800, 0}}, //RGB 5:6:5
|
|---|
| 124 | {"BGR16",IMGFMT_BGR16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000F800, 0x000007E0, 0x0000001F, 0}},
|
|---|
| 125 | {"RGB24",IMGFMT_RGB24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
|
|---|
| 126 | {"BGR24",IMGFMT_BGR24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}},
|
|---|
| 127 | {"RGB32",IMGFMT_RGB32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
|
|---|
| 128 | {"BGR32",IMGFMT_BGR32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}}
|
|---|
| 129 | };
|
|---|
| 130 | #define NUM_FORMATS (sizeof(g_ddpf) / sizeof(g_ddpf[0]))
|
|---|
| 131 |
|
|---|
| 132 | static vo_info_t info =
|
|---|
| 133 | {
|
|---|
| 134 | "Directx DDraw YUV/RGB/BGR renderer",
|
|---|
| 135 | "directx",
|
|---|
| 136 | "Sascha Sommer <saschasommer@freenet.de>",
|
|---|
| 137 | ""
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 | LIBVO_EXTERN(directx)
|
|---|
| 141 |
|
|---|
| 142 | static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|---|
| 143 | unsigned char *srca, int stride)
|
|---|
| 144 | {
|
|---|
| 145 | switch(image_format) {
|
|---|
| 146 | case IMGFMT_YV12 :
|
|---|
| 147 | case IMGFMT_I420 :
|
|---|
| 148 | case IMGFMT_IYUV :
|
|---|
| 149 | case IMGFMT_YVU9 :
|
|---|
| 150 | vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + x0,dstride);
|
|---|
| 151 | break;
|
|---|
| 152 | case IMGFMT_YUY2 :
|
|---|
| 153 | vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image)+ dstride*y0 + 2*x0 ,dstride);
|
|---|
| 154 | break;
|
|---|
| 155 | case IMGFMT_UYVY :
|
|---|
| 156 | vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + 2*x0 + 1,dstride);
|
|---|
| 157 | break;
|
|---|
| 158 | case IMGFMT_RGB15:
|
|---|
| 159 | case IMGFMT_BGR15:
|
|---|
| 160 | vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
|
|---|
| 161 | break;
|
|---|
| 162 | case IMGFMT_RGB16:
|
|---|
| 163 | case IMGFMT_BGR16:
|
|---|
| 164 | vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
|
|---|
| 165 | break;
|
|---|
| 166 | case IMGFMT_RGB24:
|
|---|
| 167 | case IMGFMT_BGR24:
|
|---|
| 168 | vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
|
|---|
| 169 | break;
|
|---|
| 170 | case IMGFMT_RGB32:
|
|---|
| 171 | case IMGFMT_BGR32:
|
|---|
| 172 | vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
|
|---|
| 173 | break;
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | static void draw_osd(void)
|
|---|
| 178 | {
|
|---|
| 179 | vo_draw_text(image_width,image_height,draw_alpha);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | static int
|
|---|
| 183 | query_format(uint32_t format)
|
|---|
| 184 | {
|
|---|
| 185 | uint32_t i=0;
|
|---|
| 186 | while ( i < NUM_FORMATS )
|
|---|
| 187 | {
|
|---|
| 188 | if (g_ddpf[i].img_format == format)
|
|---|
| 189 | return g_ddpf[i].drv_caps;
|
|---|
| 190 | i++;
|
|---|
| 191 | }
|
|---|
| 192 | return 0;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | static uint32_t Directx_CreatePrimarySurface()
|
|---|
| 196 | {
|
|---|
| 197 | DDSURFACEDESC2 ddsd;
|
|---|
| 198 | //cleanup
|
|---|
| 199 | if(g_lpddsPrimary)g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|---|
| 200 | g_lpddsPrimary=NULL;
|
|---|
| 201 |
|
|---|
| 202 | if(vidmode)g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width,vm_height,vm_bpp,vo_refresh_rate,0);
|
|---|
| 203 | ZeroMemory(&ddsd, sizeof(ddsd));
|
|---|
| 204 | ddsd.dwSize = sizeof(ddsd);
|
|---|
| 205 | //set flags and create a primary surface.
|
|---|
| 206 | ddsd.dwFlags = DDSD_CAPS;
|
|---|
| 207 | ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
|---|
| 208 | if(g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsd, &g_lpddsPrimary, NULL )== DD_OK)
|
|---|
| 209 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary surface created\n");
|
|---|
| 210 | else
|
|---|
| 211 | {
|
|---|
| 212 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not create primary surface\n");
|
|---|
| 213 | return 1;
|
|---|
| 214 | }
|
|---|
| 215 | return 0;
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | static uint32_t Directx_CreateOverlay(uint32_t imgfmt)
|
|---|
| 219 | {
|
|---|
| 220 | HRESULT ddrval;
|
|---|
| 221 | DDSURFACEDESC2 ddsdOverlay;
|
|---|
| 222 | uint32_t i=0;
|
|---|
| 223 | while ( i < NUM_FORMATS +1 && imgfmt != g_ddpf[i].img_format)
|
|---|
| 224 | {
|
|---|
| 225 | i++;
|
|---|
| 226 | }
|
|---|
| 227 | if (!g_lpdd || !g_lpddsPrimary)
|
|---|
| 228 | return 1;
|
|---|
| 229 | //cleanup
|
|---|
| 230 | if (g_lpddsOverlay)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
|
|---|
| 231 | if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|---|
| 232 | g_lpddsOverlay= NULL;
|
|---|
| 233 | g_lpddsBack = NULL;
|
|---|
| 234 | //create our overlay
|
|---|
| 235 | ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
|
|---|
| 236 | ddsdOverlay.dwSize = sizeof(ddsdOverlay);
|
|---|
| 237 | ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
|
|---|
| 238 | ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT| DDSD_PIXELFORMAT;
|
|---|
| 239 | ddsdOverlay.dwWidth=image_width;
|
|---|
| 240 | ddsdOverlay.dwHeight=image_height;
|
|---|
| 241 | ddsdOverlay.dwBackBufferCount=2;
|
|---|
| 242 | ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|---|
| 243 | if(vo_doublebuffering) //tribblebuffering
|
|---|
| 244 | {
|
|---|
| 245 | if (g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL)== DD_OK)
|
|---|
| 246 | {
|
|---|
| 247 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>overlay with format %s created\n",g_ddpf[i].img_format_name);
|
|---|
| 248 | //get the surface directly attached to the primary (the back buffer)
|
|---|
| 249 | ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
|
|---|
| 250 | if(g_lpddsOverlay->lpVtbl->GetAttachedSurface(g_lpddsOverlay,&ddsdOverlay.ddsCaps, &g_lpddsBack) != DD_OK)
|
|---|
| 251 | {
|
|---|
| 252 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get attached surface\n");
|
|---|
| 253 | return 1;
|
|---|
| 254 | }
|
|---|
| 255 | return 0;
|
|---|
| 256 | }
|
|---|
| 257 | vo_doublebuffering=0; //disable tribblebuffering
|
|---|
| 258 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>cannot create tribblebuffer overlay with format %s\n",g_ddpf[i].img_format_name);
|
|---|
| 259 | }
|
|---|
| 260 | //single buffer
|
|---|
| 261 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using singlebuffer overlay\n");
|
|---|
| 262 | ddsdOverlay.dwBackBufferCount=0;
|
|---|
| 263 | ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
|
|---|
| 264 | ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT;
|
|---|
| 265 | ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|---|
| 266 | // try to create the overlay surface
|
|---|
| 267 | ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
|
|---|
| 268 | if(ddrval != DD_OK)
|
|---|
| 269 | {
|
|---|
| 270 | if(ddrval == DDERR_INVALIDPIXELFORMAT)mp_msg(MSGT_VO,MSGL_V,"<vo_directx><ERROR> invalid pixelformat: %s\n",g_ddpf[i].img_format_name);
|
|---|
| 271 | else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>");
|
|---|
| 272 | switch(ddrval)
|
|---|
| 273 | {
|
|---|
| 274 | case DDERR_INCOMPATIBLEPRIMARY:
|
|---|
| 275 | {mp_msg(MSGT_VO, MSGL_ERR,"incompatible primary surface\n");break;}
|
|---|
| 276 | case DDERR_INVALIDCAPS:
|
|---|
| 277 | {mp_msg(MSGT_VO, MSGL_ERR,"invalid caps\n");break;}
|
|---|
| 278 | case DDERR_INVALIDOBJECT:
|
|---|
| 279 | {mp_msg(MSGT_VO, MSGL_ERR,"invalid object\n");break;}
|
|---|
| 280 | case DDERR_INVALIDPARAMS:
|
|---|
| 281 | {mp_msg(MSGT_VO, MSGL_ERR,"invalid parameters\n");break;}
|
|---|
| 282 | case DDERR_NODIRECTDRAWHW:
|
|---|
| 283 | {mp_msg(MSGT_VO, MSGL_ERR,"no directdraw hardware\n");break;}
|
|---|
| 284 | case DDERR_NOEMULATION:
|
|---|
| 285 | {mp_msg(MSGT_VO, MSGL_ERR,"can't emulate\n");break;}
|
|---|
| 286 | case DDERR_NOFLIPHW:
|
|---|
| 287 | {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do flip\n");break;}
|
|---|
| 288 | case DDERR_NOOVERLAYHW:
|
|---|
| 289 | {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do overlay\n");break;}
|
|---|
| 290 | case DDERR_OUTOFMEMORY:
|
|---|
| 291 | {mp_msg(MSGT_VO, MSGL_ERR,"not enough system memory\n");break;}
|
|---|
| 292 | case DDERR_UNSUPPORTEDMODE:
|
|---|
| 293 | {mp_msg(MSGT_VO, MSGL_ERR,"unsupported mode\n");break;}
|
|---|
| 294 | case DDERR_OUTOFVIDEOMEMORY:
|
|---|
| 295 | {mp_msg(MSGT_VO, MSGL_ERR,"not enough video memory\n");break;}
|
|---|
| 296 | default:
|
|---|
| 297 | mp_msg(MSGT_VO, MSGL_ERR,"create surface failed with 0x%x\n",ddrval);
|
|---|
| 298 | }
|
|---|
| 299 | return 1;
|
|---|
| 300 | }
|
|---|
| 301 | g_lpddsBack = g_lpddsOverlay;
|
|---|
| 302 | return 0;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | static uint32_t Directx_CreateBackpuffer()
|
|---|
| 306 | {
|
|---|
| 307 | DDSURFACEDESC2 ddsd;
|
|---|
| 308 | //cleanup
|
|---|
| 309 | if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|---|
| 310 | g_lpddsBack=NULL;
|
|---|
| 311 | ZeroMemory(&ddsd, sizeof(ddsd));
|
|---|
| 312 | ddsd.dwSize = sizeof(ddsd);
|
|---|
| 313 | ddsd.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
|---|
| 314 | ddsd.dwFlags= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
|---|
| 315 | ddsd.dwWidth=image_width;
|
|---|
| 316 | ddsd.dwHeight=image_height;
|
|---|
| 317 | if(g_lpdd->lpVtbl->CreateSurface( g_lpdd, &ddsd, &g_lpddsBack, 0 ) != DD_OK )
|
|---|
| 318 | {
|
|---|
| 319 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create backpuffer\n");
|
|---|
| 320 | return 1;
|
|---|
| 321 | }
|
|---|
| 322 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>backbuffer created\n");
|
|---|
| 323 | return 0;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | static void uninit(void)
|
|---|
| 327 | {
|
|---|
| 328 | if (g_cc != NULL)
|
|---|
| 329 | {
|
|---|
| 330 | g_cc->lpVtbl->Release(g_cc);
|
|---|
| 331 | }
|
|---|
| 332 | g_cc=NULL;
|
|---|
| 333 | if (g_lpddclipper != NULL) g_lpddclipper->lpVtbl->Release(g_lpddclipper);
|
|---|
| 334 | g_lpddclipper = NULL;
|
|---|
| 335 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper released\n");
|
|---|
| 336 | if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|---|
| 337 | g_lpddsBack = NULL;
|
|---|
| 338 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>back surface released\n");
|
|---|
| 339 | if(vo_doublebuffering && !nooverlay)
|
|---|
| 340 | {
|
|---|
| 341 | if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
|
|---|
| 342 | g_lpddsOverlay = NULL;
|
|---|
| 343 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surface released\n");
|
|---|
| 344 | }
|
|---|
| 345 | if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|---|
| 346 | g_lpddsPrimary = NULL;
|
|---|
| 347 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary released\n");
|
|---|
| 348 | if(hWndFS)DestroyWindow(hWndFS);
|
|---|
| 349 | hWndFS = NULL;
|
|---|
| 350 | if((WinID == -1) && hWnd) DestroyWindow(hWnd);
|
|---|
| 351 | hWnd = NULL;
|
|---|
| 352 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>window destroyed\n");
|
|---|
| 353 | UnregisterClass(WNDCLASSNAME_WINDOWED, GetModuleHandle(NULL));
|
|---|
| 354 | UnregisterClass(WNDCLASSNAME_FULLSCREEN, GetModuleHandle(NULL));
|
|---|
| 355 | if (mplayericon) DestroyIcon(mplayericon);
|
|---|
| 356 | mplayericon = NULL;
|
|---|
| 357 | if (mplayercursor) DestroyCursor(mplayercursor);
|
|---|
| 358 | mplayercursor = NULL;
|
|---|
| 359 | if (blackbrush) DeleteObject(blackbrush);
|
|---|
| 360 | blackbrush = NULL;
|
|---|
| 361 | if (colorbrush) DeleteObject(colorbrush);
|
|---|
| 362 | colorbrush = NULL;
|
|---|
| 363 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>GDI resources deleted\n");
|
|---|
| 364 | if (g_lpdd != NULL){
|
|---|
| 365 | if(vidmode)g_lpdd->lpVtbl->RestoreDisplayMode(g_lpdd);
|
|---|
| 366 | g_lpdd->lpVtbl->Release(g_lpdd);
|
|---|
| 367 | }
|
|---|
| 368 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>directdrawobject released\n");
|
|---|
| 369 | FreeLibrary( hddraw_dll);
|
|---|
| 370 | hddraw_dll= NULL;
|
|---|
| 371 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>ddraw.dll freed\n");
|
|---|
| 372 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>uninited\n");
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
|
|---|
| 376 | {
|
|---|
| 377 | mp_msg(MSGT_VO, MSGL_INFO ,"<vo_directx> adapter %d: ", adapter_count);
|
|---|
| 378 |
|
|---|
| 379 | if (!lpGUID)
|
|---|
| 380 | {
|
|---|
| 381 | mp_msg(MSGT_VO, MSGL_INFO ,"%s", "Primary Display Adapter");
|
|---|
| 382 | }
|
|---|
| 383 | else
|
|---|
| 384 | {
|
|---|
| 385 | mp_msg(MSGT_VO, MSGL_INFO ,"%s", lpDriverDescription);
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | if(adapter_count == vo_adapter_num){
|
|---|
| 389 | MONITORINFO mi;
|
|---|
| 390 | if (!lpGUID)
|
|---|
| 391 | selected_guid_ptr = NULL;
|
|---|
| 392 | else
|
|---|
| 393 | {
|
|---|
| 394 | selected_guid = *lpGUID;
|
|---|
| 395 | selected_guid_ptr = &selected_guid;
|
|---|
| 396 | }
|
|---|
| 397 | mi.cbSize = sizeof(mi);
|
|---|
| 398 |
|
|---|
| 399 | if (myGetMonitorInfo(hm, &mi)) {
|
|---|
| 400 | monitor_rect = mi.rcMonitor;
|
|---|
| 401 | }
|
|---|
| 402 | mp_msg(MSGT_VO, MSGL_INFO ,"\t\t<--");
|
|---|
| 403 | }
|
|---|
| 404 | mp_msg(MSGT_VO, MSGL_INFO ,"\n");
|
|---|
| 405 |
|
|---|
| 406 | adapter_count++;
|
|---|
| 407 |
|
|---|
| 408 | return 1; // list all adapters
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | static uint32_t Directx_InitDirectDraw()
|
|---|
| 412 | {
|
|---|
| 413 | HRESULT (WINAPI *OurDirectDrawCreateEx)(GUID *,LPVOID *, REFIID,IUnknown FAR *);
|
|---|
| 414 | LPDIRECTDRAW lpDDraw;
|
|---|
| 415 | DDSURFACEDESC2 ddsd;
|
|---|
| 416 | LPDIRECTDRAWENUMERATEEX OurDirectDrawEnumerateEx;
|
|---|
| 417 | HINSTANCE user32dll=LoadLibrary("user32.dll");
|
|---|
| 418 |
|
|---|
| 419 | if(user32dll){
|
|---|
| 420 | myGetMonitorInfo=GetProcAddress(user32dll,"GetMonitorInfoA");
|
|---|
| 421 | if(!myGetMonitorInfo && vo_adapter_num){
|
|---|
| 422 | mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx> -adapter is not supported on Win95\n");
|
|---|
| 423 | vo_adapter_num = 0;
|
|---|
| 424 | }
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>Initing DirectDraw\n" );
|
|---|
| 428 |
|
|---|
| 429 | //load direct draw DLL: based on videolans code
|
|---|
| 430 | hddraw_dll = LoadLibrary("DDRAW.DLL");
|
|---|
| 431 | if( hddraw_dll == NULL )
|
|---|
| 432 | {
|
|---|
| 433 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed loading ddraw.dll\n" );
|
|---|
| 434 | return 1;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | if(vo_adapter_num){ //display other than default
|
|---|
| 438 | // patch to reset the adapter count each time a new file starts
|
|---|
| 439 | adapter_count=0;
|
|---|
| 440 | // patch ends
|
|---|
| 441 | OurDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(hddraw_dll,"DirectDrawEnumerateExA");
|
|---|
| 442 | if (!OurDirectDrawEnumerateEx){
|
|---|
| 443 | FreeLibrary( hddraw_dll );
|
|---|
| 444 | hddraw_dll = NULL;
|
|---|
| 445 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawEnumerateEx\n");
|
|---|
| 446 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>no directx 7 or higher installed\n");
|
|---|
| 447 | return 1;
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | // enumerate all display devices attached to the desktop
|
|---|
| 451 | OurDirectDrawEnumerateEx(EnumCallbackEx, NULL, DDENUM_ATTACHEDSECONDARYDEVICES );
|
|---|
| 452 |
|
|---|
| 453 | if(vo_adapter_num >= adapter_count)
|
|---|
| 454 | mp_msg(MSGT_VO, MSGL_ERR,"Selected adapter (%d) doesn't exist: Default Display Adapter selected\n",vo_adapter_num);
|
|---|
| 455 | }
|
|---|
| 456 | FreeLibrary(user32dll);
|
|---|
| 457 |
|
|---|
| 458 | OurDirectDrawCreateEx = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreateEx");
|
|---|
| 459 | if ( OurDirectDrawCreateEx == NULL )
|
|---|
| 460 | {
|
|---|
| 461 | FreeLibrary( hddraw_dll );
|
|---|
| 462 | hddraw_dll = NULL;
|
|---|
| 463 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawCreateEx\n");
|
|---|
| 464 | return 1;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | // initialize DirectDraw and create directx v7 object
|
|---|
| 468 | if (OurDirectDrawCreateEx(selected_guid_ptr, (VOID**)&g_lpdd, &IID_IDirectDraw7, NULL ) != DD_OK )
|
|---|
| 469 | {
|
|---|
| 470 | FreeLibrary( hddraw_dll );
|
|---|
| 471 | hddraw_dll = NULL;
|
|---|
| 472 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't initialize ddraw\n");
|
|---|
| 473 | return 1;
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | //get current screen siz for selected monitor ...
|
|---|
| 477 | ddsd.dwSize=sizeof(ddsd);
|
|---|
| 478 | ddsd.dwFlags=DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
|
|---|
| 479 | g_lpdd->lpVtbl->GetDisplayMode(g_lpdd, &ddsd);
|
|---|
| 480 | if(vo_screenwidth && vo_screenheight)
|
|---|
| 481 | {
|
|---|
| 482 | vm_height=vo_screenheight;
|
|---|
| 483 | vm_width=vo_screenwidth;
|
|---|
| 484 | }
|
|---|
| 485 | else
|
|---|
| 486 | {
|
|---|
| 487 | vm_height=ddsd.dwHeight;
|
|---|
| 488 | vm_width=ddsd.dwWidth;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 | if(vo_dbpp)vm_bpp=vo_dbpp;
|
|---|
| 493 | else vm_bpp=ddsd.ddpfPixelFormat.dwRGBBitCount;
|
|---|
| 494 |
|
|---|
| 495 | if(vidmode){
|
|---|
| 496 | if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK)
|
|---|
| 497 | {
|
|---|
| 498 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode\n");
|
|---|
| 499 | return 1;
|
|---|
| 500 | }
|
|---|
| 501 | /*SetDisplayMode(ddobject,width,height,bpp,refreshrate,aditionalflags)*/
|
|---|
| 502 | if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width, vm_height, vm_bpp,0,0) != DD_OK)
|
|---|
| 503 | {
|
|---|
| 504 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n");
|
|---|
| 505 | return 1;
|
|---|
| 506 | }
|
|---|
| 507 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>Inited adapter %i for %i x %i @ %i \n",vo_adapter_num,vm_width,vm_height,vm_bpp);
|
|---|
| 508 | return 0;
|
|---|
| 509 | }
|
|---|
| 510 | if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_NORMAL) != DD_OK) // or DDSCL_SETFOCUSWINDOW
|
|---|
| 511 | {
|
|---|
| 512 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n");
|
|---|
| 513 | return 1;
|
|---|
| 514 | }
|
|---|
| 515 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>DirectDraw Inited\n");
|
|---|
| 516 | return 0;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | static void check_events(void)
|
|---|
| 520 | {
|
|---|
| 521 | MSG msg;
|
|---|
| 522 | while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
|
|---|
| 523 | {
|
|---|
| 524 | TranslateMessage(&msg);
|
|---|
| 525 | DispatchMessage(&msg);
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | static uint32_t Directx_ManageDisplay()
|
|---|
| 530 | {
|
|---|
| 531 | HRESULT ddrval;
|
|---|
| 532 | DDCAPS capsDrv;
|
|---|
| 533 | DDOVERLAYFX ovfx;
|
|---|
| 534 | DWORD dwUpdateFlags=0;
|
|---|
| 535 | int width,height;
|
|---|
| 536 |
|
|---|
| 537 | if(vo_fs || vidmode){
|
|---|
| 538 | aspect(&width,&height,A_ZOOM);
|
|---|
| 539 | rd.left=(vo_screenwidth-width)/2;
|
|---|
| 540 | rd.top=(vo_screenheight-height)/2;
|
|---|
| 541 | if (WinID == -1)
|
|---|
| 542 | if(ShowCursor(FALSE)>=0)while(ShowCursor(FALSE)>=0){}
|
|---|
| 543 | }
|
|---|
| 544 | else if (WinID != -1 && vo_geometry) {
|
|---|
| 545 | POINT pt;
|
|---|
| 546 | pt.x = vo_dx;
|
|---|
| 547 | pt.y = vo_dy;
|
|---|
| 548 | ClientToScreen(hWnd,&pt);
|
|---|
| 549 | width=d_image_width;
|
|---|
| 550 | height=d_image_height;
|
|---|
| 551 | rd.left = pt.x;
|
|---|
| 552 | rd.top = pt.y;
|
|---|
| 553 | while(ShowCursor(TRUE)<=0){}
|
|---|
| 554 | }
|
|---|
| 555 | else {
|
|---|
| 556 | POINT pt;
|
|---|
| 557 | pt.x = 0; //overlayposition relative to the window
|
|---|
| 558 | pt.y = 0;
|
|---|
| 559 | ClientToScreen(hWnd,&pt);
|
|---|
| 560 | GetClientRect(hWnd, &rd);
|
|---|
| 561 | width=rd.right - rd.left;
|
|---|
| 562 | height=rd.bottom - rd.top;
|
|---|
| 563 | pt.x -= monitor_rect.left; /* move coordinates from global to local monitor space */
|
|---|
| 564 | pt.y -= monitor_rect.top;
|
|---|
| 565 | rd.right -= monitor_rect.left;
|
|---|
| 566 | rd.bottom -= monitor_rect.top;
|
|---|
| 567 | rd.left = pt.x;
|
|---|
| 568 | rd.top = pt.y;
|
|---|
| 569 | if(!nooverlay && (!width || !height)){
|
|---|
| 570 | /*window is minimized*/
|
|---|
| 571 | ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
|
|---|
| 572 | return 0;
|
|---|
| 573 | }
|
|---|
| 574 | if(vo_keepaspect){
|
|---|
| 575 | int tmpheight=((float)width/window_aspect);
|
|---|
| 576 | tmpheight+=tmpheight%2;
|
|---|
| 577 | if(tmpheight > height){
|
|---|
| 578 | width=((float)height*window_aspect);
|
|---|
| 579 | width+=width%2;
|
|---|
| 580 | }
|
|---|
| 581 | else height=tmpheight;
|
|---|
| 582 | }
|
|---|
| 583 | if (WinID == -1)
|
|---|
| 584 | while(ShowCursor(TRUE)<=0){}
|
|---|
| 585 | }
|
|---|
| 586 | rd.right=rd.left+width;
|
|---|
| 587 | rd.bottom=rd.top+height;
|
|---|
| 588 |
|
|---|
| 589 | /*ok, let's workaround some overlay limitations*/
|
|---|
| 590 | if(!nooverlay)
|
|---|
| 591 | {
|
|---|
| 592 | uint32_t uStretchFactor1000; //minimum stretch
|
|---|
| 593 | uint32_t xstretch1000,ystretch1000;
|
|---|
| 594 | /*get driver capabilities*/
|
|---|
| 595 | ZeroMemory(&capsDrv, sizeof(capsDrv));
|
|---|
| 596 | capsDrv.dwSize = sizeof(capsDrv);
|
|---|
| 597 | if(g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL) != DD_OK)return 1;
|
|---|
| 598 | /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */
|
|---|
| 599 | uStretchFactor1000 = capsDrv.dwMinOverlayStretch>1000 ? capsDrv.dwMinOverlayStretch : 1000;
|
|---|
| 600 | rd.right = ((width+rd.left)*uStretchFactor1000+999)/1000;
|
|---|
| 601 | rd.bottom = (height+rd.top)*uStretchFactor1000/1000;
|
|---|
| 602 | /*calculate xstretch1000 and ystretch1000*/
|
|---|
| 603 | xstretch1000 = ((rd.right - rd.left)* 1000)/image_width ;
|
|---|
| 604 | ystretch1000 = ((rd.bottom - rd.top)* 1000)/image_height;
|
|---|
| 605 | rs.left=0;
|
|---|
| 606 | rs.right=image_width;
|
|---|
| 607 | rs.top=0;
|
|---|
| 608 | rs.bottom=image_height;
|
|---|
| 609 | if(rd.left < 0)rs.left=(-rd.left*1000)/xstretch1000;
|
|---|
| 610 | if(rd.top < 0)rs.top=(-rd.top*1000)/ystretch1000;
|
|---|
| 611 | if(rd.right > vo_screenwidth)rs.right=((vo_screenwidth-rd.left)*1000)/xstretch1000;
|
|---|
| 612 | if(rd.bottom > vo_screenheight)rs.bottom=((vo_screenheight-rd.top)*1000)/ystretch1000;
|
|---|
| 613 | /*do not allow to zoom or shrink if hardware isn't able to do so*/
|
|---|
| 614 | if((width < image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX))
|
|---|
| 615 | {
|
|---|
| 616 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
|
|---|
| 617 | else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink x\n");
|
|---|
| 618 | rd.right=rd.left+image_width;
|
|---|
| 619 | }
|
|---|
| 620 | else if((width > image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX))
|
|---|
| 621 | {
|
|---|
| 622 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
|
|---|
| 623 | else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch x\n");
|
|---|
| 624 | rd.right = rd.left+image_width;
|
|---|
| 625 | }
|
|---|
| 626 | if((height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY))
|
|---|
| 627 | {
|
|---|
| 628 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
|
|---|
| 629 | else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink y\n");
|
|---|
| 630 | rd.bottom = rd.top + image_height;
|
|---|
| 631 | }
|
|---|
| 632 | else if((height > image_height ) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY))
|
|---|
| 633 | {
|
|---|
| 634 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
|
|---|
| 635 | else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch y\n");
|
|---|
| 636 | rd.bottom = rd.top + image_height;
|
|---|
| 637 | }
|
|---|
| 638 | /*the last thing to check are alignment restrictions
|
|---|
| 639 | these expressions (x & -y) just do alignment by dropping low order bits...
|
|---|
| 640 | so to round up, we add first, then truncate*/
|
|---|
| 641 | if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc)
|
|---|
| 642 | rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & -(signed)(capsDrv.dwAlignBoundarySrc);
|
|---|
| 643 | if((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc)
|
|---|
| 644 | rs.right = rs.left + ((rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & -(signed) (capsDrv.dwAlignSizeSrc));
|
|---|
| 645 | if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest)
|
|---|
| 646 | rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest);
|
|---|
| 647 | if((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest)
|
|---|
| 648 | rd.right = rd.left + ((rd.right - rd.left) & -(signed) (capsDrv.dwAlignSizeDest));
|
|---|
| 649 | /*create an overlay FX structure to specify a destination color key*/
|
|---|
| 650 | ZeroMemory(&ovfx, sizeof(ovfx));
|
|---|
| 651 | ovfx.dwSize = sizeof(ovfx);
|
|---|
| 652 | if(vo_fs||vidmode)
|
|---|
| 653 | {
|
|---|
| 654 | ovfx.dckDestColorkey.dwColorSpaceLowValue = 0;
|
|---|
| 655 | ovfx.dckDestColorkey.dwColorSpaceHighValue = 0;
|
|---|
| 656 | }
|
|---|
| 657 | else
|
|---|
| 658 | {
|
|---|
| 659 | ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey;
|
|---|
| 660 | ovfx.dckDestColorkey.dwColorSpaceHighValue = destcolorkey;
|
|---|
| 661 | }
|
|---|
| 662 | // set the flags we'll send to UpdateOverlay //DDOVER_AUTOFLIP|DDOVERFX_MIRRORLEFTRIGHT|DDOVERFX_MIRRORUPDOWN could be usefull?;
|
|---|
| 663 | dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX;
|
|---|
| 664 | /*if hardware can't do colorkeying set the window on top*/
|
|---|
| 665 | if(capsDrv.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY) dwUpdateFlags |= DDOVER_KEYDESTOVERRIDE;
|
|---|
| 666 | else vo_ontop = 1;
|
|---|
| 667 | }
|
|---|
| 668 | else
|
|---|
| 669 | {
|
|---|
| 670 | g_lpddclipper->lpVtbl->SetHWnd(g_lpddclipper, 0,(vo_fs && !vidmode)?hWndFS: hWnd);
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | if(!vidmode && !vo_fs){
|
|---|
| 674 | if(WinID == -1) {
|
|---|
| 675 | RECT rdw=rd;
|
|---|
| 676 | if (vo_border)
|
|---|
| 677 | AdjustWindowRect(&rdw,WNDSTYLE,FALSE);
|
|---|
| 678 | // printf("window: %i %i %ix%i\n",rdw.left,rdw.top,rdw.right - rdw.left,rdw.bottom - rdw.top);
|
|---|
| 679 | rdw.left += monitor_rect.left; /* move to global coordinate space */
|
|---|
| 680 | rdw.top += monitor_rect.top;
|
|---|
| 681 | rdw.right += monitor_rect.left;
|
|---|
| 682 | rdw.bottom += monitor_rect.top;
|
|---|
| 683 | SetWindowPos(hWnd,(vo_ontop)?HWND_TOPMOST:(vo_rootwin?HWND_BOTTOM:HWND_NOTOPMOST),rdw.left,rdw.top,rdw.right-rdw.left,rdw.bottom-rdw.top,SWP_NOOWNERZORDER);
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 | else SetWindowPos(vidmode?hWnd:hWndFS,vo_rootwin?HWND_BOTTOM:HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_NOCOPYBITS);
|
|---|
| 687 |
|
|---|
| 688 | /*make sure the overlay is inside the screen*/
|
|---|
| 689 | if(rd.left<0)rd.left=0;
|
|---|
| 690 | if(rd.right>vo_screenwidth)rd.right=vo_screenwidth;
|
|---|
| 691 | if(rd.top<0)rd.top=0;
|
|---|
| 692 | if(rd.bottom>vo_screenheight)rd.bottom=vo_screenheight;
|
|---|
| 693 |
|
|---|
| 694 | /*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/
|
|---|
| 695 | if(nooverlay)return 0;
|
|---|
| 696 |
|
|---|
| 697 | // printf("overlay: %i %i %ix%i\n",rd.left,rd.top,rd.right - rd.left,rd.bottom - rd.top);
|
|---|
| 698 | ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
|
|---|
| 699 | if(FAILED(ddrval))
|
|---|
| 700 | {
|
|---|
| 701 | // one cause might be the driver lied about minimum stretch
|
|---|
| 702 | // we should try upping the destination size a bit, or
|
|---|
| 703 | // perhaps shrinking the source size
|
|---|
| 704 | mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>UpdateOverlay failed\n" );
|
|---|
| 705 | mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Overlay:x1:%i,y1:%i,x2:%i,y2:%i,w:%i,h:%i\n",rd.left,rd.top,rd.right,rd.bottom,rd.right - rd.left,rd.bottom - rd.top );
|
|---|
| 706 | mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>");
|
|---|
| 707 | switch (ddrval)
|
|---|
| 708 | {
|
|---|
| 709 | case DDERR_NOSTRETCHHW:
|
|---|
| 710 | {mp_msg(MSGT_VO, MSGL_ERR ,"hardware can't stretch: try to size the window back\n");break;}
|
|---|
| 711 | case DDERR_INVALIDRECT:
|
|---|
| 712 | {mp_msg(MSGT_VO, MSGL_ERR ,"invalid rectangle\n");break;}
|
|---|
| 713 | case DDERR_INVALIDPARAMS:
|
|---|
| 714 | {mp_msg(MSGT_VO, MSGL_ERR ,"invalid parameters\n");break;}
|
|---|
| 715 | case DDERR_HEIGHTALIGN:
|
|---|
| 716 | {mp_msg(MSGT_VO, MSGL_ERR ,"height align\n");break;}
|
|---|
| 717 | case DDERR_XALIGN:
|
|---|
| 718 | {mp_msg(MSGT_VO, MSGL_ERR ,"x align\n");break;}
|
|---|
| 719 | case DDERR_UNSUPPORTED:
|
|---|
| 720 | {mp_msg(MSGT_VO, MSGL_ERR ,"unsupported\n");break;}
|
|---|
| 721 | case DDERR_INVALIDSURFACETYPE:
|
|---|
| 722 | {mp_msg(MSGT_VO, MSGL_ERR ,"invalid surfacetype\n");break;}
|
|---|
| 723 | case DDERR_INVALIDOBJECT:
|
|---|
| 724 | {mp_msg(MSGT_VO, MSGL_ERR ,"invalid object\n");break;}
|
|---|
| 725 | case DDERR_SURFACELOST:
|
|---|
| 726 | {
|
|---|
| 727 | mp_msg(MSGT_VO, MSGL_ERR ,"surfaces lost\n");
|
|---|
| 728 | g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); //restore and try again
|
|---|
| 729 | g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary );
|
|---|
| 730 | ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
|
|---|
| 731 | if(ddrval !=DD_OK)mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>UpdateOverlay failed again\n" );
|
|---|
| 732 | break;
|
|---|
| 733 | }
|
|---|
| 734 | default:
|
|---|
| 735 | mp_msg(MSGT_VO, MSGL_ERR ," 0x%x\n",ddrval);
|
|---|
| 736 | }
|
|---|
| 737 | /*ok we can't do anything about it -> hide overlay*/
|
|---|
| 738 | if(ddrval != DD_OK)
|
|---|
| 739 | {
|
|---|
| 740 | ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
|
|---|
| 741 | return 1;
|
|---|
| 742 | }
|
|---|
| 743 | }
|
|---|
| 744 | return 0;
|
|---|
| 745 | }
|
|---|
| 746 |
|
|---|
| 747 | //find out supported overlay pixelformats
|
|---|
| 748 | static uint32_t Directx_CheckOverlayPixelformats()
|
|---|
| 749 | {
|
|---|
| 750 | DDCAPS capsDrv;
|
|---|
| 751 | HRESULT ddrval;
|
|---|
| 752 | DDSURFACEDESC2 ddsdOverlay;
|
|---|
| 753 | uint32_t i;
|
|---|
| 754 | uint32_t formatcount = 0;
|
|---|
| 755 | //get driver caps to determine overlay support
|
|---|
| 756 | ZeroMemory(&capsDrv, sizeof(capsDrv));
|
|---|
| 757 | capsDrv.dwSize = sizeof(capsDrv);
|
|---|
| 758 | ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL);
|
|---|
| 759 | if (FAILED(ddrval))
|
|---|
| 760 | {
|
|---|
| 761 | mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>failed getting ddrawcaps\n");
|
|---|
| 762 | return 1;
|
|---|
| 763 | }
|
|---|
| 764 | if (!(capsDrv.dwCaps & DDCAPS_OVERLAY))
|
|---|
| 765 | {
|
|---|
| 766 | mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Your card doesn't support overlay\n");
|
|---|
| 767 | return 1;
|
|---|
| 768 | }
|
|---|
| 769 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>testing supported overlay pixelformats\n");
|
|---|
| 770 | //it is not possible to query for pixel formats supported by the
|
|---|
| 771 | //overlay hardware: try out various formats till one works
|
|---|
| 772 | ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
|
|---|
| 773 | ddsdOverlay.dwSize = sizeof(ddsdOverlay);
|
|---|
| 774 | ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
|
|---|
| 775 | ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT;
|
|---|
| 776 | ddsdOverlay.dwWidth=300;
|
|---|
| 777 | ddsdOverlay.dwHeight=280;
|
|---|
| 778 | ddsdOverlay.dwBackBufferCount=0;
|
|---|
| 779 | //try to create an overlay surface using one of the pixel formats in our global list
|
|---|
| 780 | i=0;
|
|---|
| 781 | do
|
|---|
| 782 | {
|
|---|
| 783 | ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|---|
| 784 | ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
|
|---|
| 785 | if (ddrval == DD_OK)
|
|---|
| 786 | {
|
|---|
| 787 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s supported\n",i,g_ddpf[i].img_format_name);
|
|---|
| 788 | g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP;
|
|---|
| 789 | formatcount++;}
|
|---|
| 790 | else mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s not supported\n",i,g_ddpf[i].img_format_name);
|
|---|
| 791 | if (g_lpddsOverlay != NULL) {g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);g_lpddsOverlay = NULL;}
|
|---|
| 792 | } while( ++i < NUM_FORMATS );
|
|---|
| 793 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>Your card supports %i of %i overlayformats\n",formatcount, NUM_FORMATS);
|
|---|
| 794 | if (formatcount == 0)
|
|---|
| 795 | {
|
|---|
| 796 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n");
|
|---|
| 797 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>This can have the following reasons:\n");
|
|---|
| 798 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you are already using an overlay with another app\n");
|
|---|
| 799 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you don't have enough videomemory\n");
|
|---|
| 800 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n");
|
|---|
| 801 | return 1;
|
|---|
| 802 | }
|
|---|
| 803 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORLEFTRIGHT)mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>can mirror left right\n"); //I don't have hardware which
|
|---|
| 804 | if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORUPDOWN )mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>can mirror up down\n"); //supports those send me one and I'll implement ;)
|
|---|
| 805 | return 0;
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | //find out the Pixelformat of the Primary Surface
|
|---|
| 809 | static uint32_t Directx_CheckPrimaryPixelformat()
|
|---|
| 810 | {
|
|---|
| 811 | uint32_t i=0;
|
|---|
| 812 | uint32_t formatcount = 0;
|
|---|
| 813 | DDPIXELFORMAT ddpf;
|
|---|
| 814 | DDSURFACEDESC2 ddsd;
|
|---|
| 815 | HDC hdc;
|
|---|
| 816 | HRESULT hres;
|
|---|
| 817 | COLORREF rgbT=RGB(0,0,0);
|
|---|
| 818 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>checking primary surface\n");
|
|---|
| 819 | memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
|
|---|
| 820 | ddpf.dwSize = sizeof( DDPIXELFORMAT );
|
|---|
| 821 | //we have to create a primary surface first
|
|---|
| 822 | if(Directx_CreatePrimarySurface()!=0)return 1;
|
|---|
| 823 | if(g_lpddsPrimary->lpVtbl->GetPixelFormat( g_lpddsPrimary, &ddpf ) != DD_OK )
|
|---|
| 824 | {
|
|---|
| 825 | mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>can't get pixelformat\n");
|
|---|
| 826 | return 1;
|
|---|
| 827 | }
|
|---|
| 828 | while ( i < NUM_FORMATS )
|
|---|
| 829 | {
|
|---|
| 830 | if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount)
|
|---|
| 831 | {
|
|---|
| 832 | if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask)
|
|---|
| 833 | {
|
|---|
| 834 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT PRIMARY>%i %s supported\n",i,g_ddpf[i].img_format_name);
|
|---|
| 835 | g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD;
|
|---|
| 836 | formatcount++;
|
|---|
| 837 | primary_image_format=g_ddpf[i].img_format;
|
|---|
| 838 | }
|
|---|
| 839 | }
|
|---|
| 840 | i++;
|
|---|
| 841 | }
|
|---|
| 842 | //get the colorkey for overlay mode
|
|---|
| 843 | destcolorkey = CLR_INVALID;
|
|---|
| 844 | if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK)
|
|---|
| 845 | {
|
|---|
| 846 | rgbT = GetPixel(hdc, 0, 0);
|
|---|
| 847 | SetPixel(hdc, 0, 0, windowcolor);
|
|---|
| 848 | g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc);
|
|---|
| 849 | }
|
|---|
| 850 | // read back the converted color
|
|---|
| 851 | ddsd.dwSize = sizeof(ddsd);
|
|---|
| 852 | while ((hres = g_lpddsPrimary->lpVtbl->Lock(g_lpddsPrimary,NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING)
|
|---|
| 853 | ;
|
|---|
| 854 | if (hres == DD_OK)
|
|---|
| 855 | {
|
|---|
| 856 | destcolorkey = *(DWORD *) ddsd.lpSurface;
|
|---|
| 857 | if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
|
|---|
| 858 | destcolorkey &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1;
|
|---|
| 859 | g_lpddsPrimary->lpVtbl->Unlock(g_lpddsPrimary,NULL);
|
|---|
| 860 | }
|
|---|
| 861 | if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK)
|
|---|
| 862 | {
|
|---|
| 863 | SetPixel(hdc, 0, 0, rgbT);
|
|---|
| 864 | g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc);
|
|---|
| 865 | }
|
|---|
| 866 | //release primary
|
|---|
| 867 | g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|---|
| 868 | g_lpddsPrimary = NULL;
|
|---|
| 869 | if(formatcount==0)
|
|---|
| 870 | {
|
|---|
| 871 | mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>Unknown Pixelformat\n");
|
|---|
| 872 | return 1;
|
|---|
| 873 | }
|
|---|
| 874 | return 0;
|
|---|
| 875 | }
|
|---|
| 876 |
|
|---|
| 877 | //function handles input
|
|---|
| 878 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|---|
| 879 | {
|
|---|
| 880 | switch (message)
|
|---|
| 881 | {
|
|---|
| 882 | case WM_MOUSEACTIVATE:
|
|---|
| 883 | return MA_ACTIVATEANDEAT;
|
|---|
| 884 | case WM_NCACTIVATE:
|
|---|
| 885 | {
|
|---|
| 886 | if(vidmode && adapter_count > 2) //only disable if more than one adapter.
|
|---|
| 887 | return 0;
|
|---|
| 888 | break;
|
|---|
| 889 | }
|
|---|
| 890 | case WM_DESTROY:
|
|---|
| 891 | {
|
|---|
| 892 | PostQuitMessage(0);
|
|---|
| 893 | return 0;
|
|---|
| 894 | }
|
|---|
| 895 | case WM_CLOSE:
|
|---|
| 896 | {
|
|---|
| 897 | mplayer_put_key(KEY_CLOSE_WIN);
|
|---|
| 898 | return 0;
|
|---|
| 899 | }
|
|---|
| 900 | case WM_WINDOWPOSCHANGED:
|
|---|
| 901 | {
|
|---|
| 902 | //printf("Windowposchange\n");
|
|---|
| 903 | if(g_lpddsBack != NULL) //or it will crash with -vm
|
|---|
| 904 | {
|
|---|
| 905 | Directx_ManageDisplay();
|
|---|
| 906 | }
|
|---|
| 907 | break;
|
|---|
| 908 | }
|
|---|
| 909 | case WM_SYSCOMMAND:
|
|---|
| 910 | {
|
|---|
| 911 | switch (wParam)
|
|---|
| 912 | { //kill screensaver etc.
|
|---|
| 913 | //note: works only when the window is active
|
|---|
| 914 | //you can workaround this by disabling the allow screensaver option in
|
|---|
| 915 | //the link to the app
|
|---|
| 916 | case SC_SCREENSAVE:
|
|---|
| 917 | case SC_MONITORPOWER:
|
|---|
| 918 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" );
|
|---|
| 919 | return 0;
|
|---|
| 920 | case SC_MAXIMIZE:
|
|---|
| 921 | if (!vo_fs) control(VOCTRL_FULLSCREEN, NULL);
|
|---|
| 922 | return 0;
|
|---|
| 923 | }
|
|---|
| 924 | break;
|
|---|
| 925 | }
|
|---|
| 926 | case WM_KEYDOWN:
|
|---|
| 927 | {
|
|---|
| 928 | switch (wParam)
|
|---|
| 929 | {
|
|---|
| 930 | case VK_LEFT:
|
|---|
| 931 | {mplayer_put_key(KEY_LEFT);break;}
|
|---|
| 932 | case VK_UP:
|
|---|
| 933 | {mplayer_put_key(KEY_UP);break;}
|
|---|
| 934 | case VK_RIGHT:
|
|---|
| 935 | {mplayer_put_key(KEY_RIGHT);break;}
|
|---|
| 936 | case VK_DOWN:
|
|---|
| 937 | {mplayer_put_key(KEY_DOWN);break;}
|
|---|
| 938 | case VK_TAB:
|
|---|
| 939 | {mplayer_put_key(KEY_TAB);break;}
|
|---|
| 940 | case VK_BACK:
|
|---|
| 941 | {mplayer_put_key(KEY_BS);break;}
|
|---|
| 942 | case VK_DELETE:
|
|---|
| 943 | {mplayer_put_key(KEY_DELETE);break;}
|
|---|
| 944 | case VK_INSERT:
|
|---|
| 945 | {mplayer_put_key(KEY_INSERT);break;}
|
|---|
| 946 | case VK_HOME:
|
|---|
| 947 | {mplayer_put_key(KEY_HOME);break;}
|
|---|
| 948 | case VK_END:
|
|---|
| 949 | {mplayer_put_key(KEY_END);break;}
|
|---|
| 950 | case VK_PRIOR:
|
|---|
| 951 | {mplayer_put_key(KEY_PAGE_UP);break;}
|
|---|
| 952 | case VK_NEXT:
|
|---|
| 953 | {mplayer_put_key(KEY_PAGE_DOWN);break;}
|
|---|
| 954 | case VK_ESCAPE:
|
|---|
| 955 | {mplayer_put_key(KEY_ESC);break;}
|
|---|
| 956 | }
|
|---|
| 957 | break;
|
|---|
| 958 | }
|
|---|
| 959 | case WM_CHAR:
|
|---|
| 960 | {
|
|---|
| 961 | mplayer_put_key(wParam);
|
|---|
| 962 | break;
|
|---|
| 963 | }
|
|---|
| 964 | case WM_LBUTTONDOWN:
|
|---|
| 965 | {
|
|---|
| 966 | if (!vo_nomouse_input)
|
|---|
| 967 | mplayer_put_key(MOUSE_BTN0);
|
|---|
| 968 | break;
|
|---|
| 969 | }
|
|---|
| 970 | case WM_MBUTTONDOWN:
|
|---|
| 971 | {
|
|---|
| 972 | if (!vo_nomouse_input)
|
|---|
| 973 | mplayer_put_key(MOUSE_BTN1);
|
|---|
| 974 | break;
|
|---|
| 975 | }
|
|---|
| 976 | case WM_RBUTTONDOWN:
|
|---|
| 977 | {
|
|---|
| 978 | if (!vo_nomouse_input)
|
|---|
| 979 | mplayer_put_key(MOUSE_BTN2);
|
|---|
| 980 | break;
|
|---|
| 981 | }
|
|---|
| 982 | case WM_LBUTTONDBLCLK:
|
|---|
| 983 | {
|
|---|
| 984 | if(!vo_nomouse_input)
|
|---|
| 985 | mplayer_put_key(MOUSE_BTN0_DBL);
|
|---|
| 986 | break;
|
|---|
| 987 | }
|
|---|
| 988 | case WM_MBUTTONDBLCLK:
|
|---|
| 989 | {
|
|---|
| 990 | if(!vo_nomouse_input)
|
|---|
| 991 | mplayer_put_key(MOUSE_BTN1_DBL);
|
|---|
| 992 | break;
|
|---|
| 993 | }
|
|---|
| 994 | case WM_RBUTTONDBLCLK:
|
|---|
| 995 | {
|
|---|
| 996 | if(!vo_nomouse_input)
|
|---|
| 997 | mplayer_put_key(MOUSE_BTN2_DBL);
|
|---|
| 998 | break;
|
|---|
| 999 | }
|
|---|
| 1000 | case WM_MOUSEWHEEL:
|
|---|
| 1001 | {
|
|---|
| 1002 | if (vo_nomouse_input)
|
|---|
| 1003 | break;
|
|---|
| 1004 | int x = GET_WHEEL_DELTA_WPARAM(wParam);
|
|---|
| 1005 | if (x > 0)
|
|---|
| 1006 | mplayer_put_key(MOUSE_BTN3);
|
|---|
| 1007 | else
|
|---|
| 1008 | mplayer_put_key(MOUSE_BTN4);
|
|---|
| 1009 | break;
|
|---|
| 1010 | }
|
|---|
| 1011 | case WM_XBUTTONDOWN:
|
|---|
| 1012 | {
|
|---|
| 1013 | if (vo_nomouse_input)
|
|---|
| 1014 | break;
|
|---|
| 1015 | if (HIWORD(wParam) == 1)
|
|---|
| 1016 | mplayer_put_key(MOUSE_BTN5);
|
|---|
| 1017 | else
|
|---|
| 1018 | mplayer_put_key(MOUSE_BTN6);
|
|---|
| 1019 | break;
|
|---|
| 1020 | }
|
|---|
| 1021 | case WM_XBUTTONDBLCLK:
|
|---|
| 1022 | {
|
|---|
| 1023 | if (vo_nomouse_input)
|
|---|
| 1024 | break;
|
|---|
| 1025 | if (HIWORD(wParam) == 1)
|
|---|
| 1026 | mplayer_put_key(MOUSE_BTN5_DBL);
|
|---|
| 1027 | else
|
|---|
| 1028 | mplayer_put_key(MOUSE_BTN6_DBL);
|
|---|
| 1029 | break;
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | }
|
|---|
| 1033 | return DefWindowProc(hWnd, message, wParam, lParam);
|
|---|
| 1034 | }
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 | static int preinit(const char *arg)
|
|---|
| 1038 | {
|
|---|
| 1039 | HINSTANCE hInstance = GetModuleHandle(NULL);
|
|---|
| 1040 | char exedir[MAX_PATH];
|
|---|
| 1041 | WNDCLASS wc;
|
|---|
| 1042 | if(arg)
|
|---|
| 1043 | {
|
|---|
| 1044 | if(strstr(arg,"noaccel"))
|
|---|
| 1045 | {
|
|---|
| 1046 | mp_msg(MSGT_VO,MSGL_V,"<vo_directx><INFO>disabled overlay\n");
|
|---|
| 1047 | nooverlay = 1;
|
|---|
| 1048 | }
|
|---|
| 1049 | }
|
|---|
| 1050 | /*load icon from the main app*/
|
|---|
| 1051 | if(GetModuleFileName(NULL,exedir,MAX_PATH))
|
|---|
| 1052 | {
|
|---|
| 1053 | mplayericon = ExtractIcon( hInstance, exedir, 0 );
|
|---|
| 1054 | }
|
|---|
| 1055 | if(!mplayericon)mplayericon=LoadIcon(NULL,IDI_APPLICATION);
|
|---|
| 1056 | mplayercursor = LoadCursor(NULL, IDC_ARROW);
|
|---|
| 1057 | monitor_rect.right=GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 1058 | monitor_rect.bottom=GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 1059 |
|
|---|
| 1060 | windowcolor = vo_colorkey;
|
|---|
| 1061 | colorbrush = CreateSolidBrush(windowcolor);
|
|---|
| 1062 | blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|---|
| 1063 | wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
|---|
| 1064 | wc.lpfnWndProc = WndProc;
|
|---|
| 1065 | wc.cbClsExtra = 0;
|
|---|
| 1066 | wc.cbWndExtra = 0;
|
|---|
| 1067 | wc.hInstance = hInstance;
|
|---|
| 1068 | wc.hCursor = mplayercursor;
|
|---|
| 1069 | wc.hIcon = mplayericon;
|
|---|
| 1070 | wc.hbrBackground = vidmode ? blackbrush : colorbrush;
|
|---|
| 1071 | wc.lpszClassName = WNDCLASSNAME_WINDOWED;
|
|---|
| 1072 | wc.lpszMenuName = NULL;
|
|---|
| 1073 | RegisterClass(&wc);
|
|---|
| 1074 | if (WinID != -1) hWnd = WinID;
|
|---|
| 1075 | else
|
|---|
| 1076 | hWnd = CreateWindowEx(vidmode?WS_EX_TOPMOST:0,
|
|---|
| 1077 | WNDCLASSNAME_WINDOWED,"",(vidmode || !vo_border)?WS_POPUP:WNDSTYLE,
|
|---|
| 1078 | CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,NULL,NULL,hInstance,NULL);
|
|---|
| 1079 | wc.hbrBackground = blackbrush;
|
|---|
| 1080 | wc.lpszClassName = WNDCLASSNAME_FULLSCREEN;
|
|---|
| 1081 | RegisterClass(&wc);
|
|---|
| 1082 |
|
|---|
| 1083 | if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw
|
|---|
| 1084 |
|
|---|
| 1085 | if(!vidmode)hWndFS = CreateWindow(WNDCLASSNAME_FULLSCREEN,"MPlayer Fullscreen",WS_POPUP,monitor_rect.left,monitor_rect.top,monitor_rect.right-monitor_rect.left,monitor_rect.bottom-monitor_rect.top,hWnd,NULL,hInstance,NULL);
|
|---|
| 1086 | mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>initial mplayer windows created\n");
|
|---|
| 1087 |
|
|---|
| 1088 | if (Directx_CheckPrimaryPixelformat()!=0)return 1;
|
|---|
| 1089 | if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) //check for supported hardware
|
|---|
| 1090 | {
|
|---|
| 1091 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n");
|
|---|
| 1092 | nooverlay = 0;
|
|---|
| 1093 | }
|
|---|
| 1094 | else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface
|
|---|
| 1095 | {
|
|---|
| 1096 | mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n");
|
|---|
| 1097 | nooverlay = 1;
|
|---|
| 1098 | }
|
|---|
| 1099 | mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n");
|
|---|
| 1100 | return 0;
|
|---|
| 1101 | }
|
|---|
| 1102 |
|
|---|
| 1103 | static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
|
|---|
| 1104 | {
|
|---|
| 1105 | uint8_t *s;
|
|---|
| 1106 | uint8_t *d;
|
|---|
| 1107 | uint32_t i=0, uvstride=dstride/2;
|
|---|
| 1108 | // copy Y
|
|---|
| 1109 | d=image+dstride*y+x;
|
|---|
| 1110 | s=src[0];
|
|---|
| 1111 | for(i=0;i<h;i++){
|
|---|
| 1112 | memcpy(d,s,w);
|
|---|
| 1113 | s+=stride[0];
|
|---|
| 1114 | d+=dstride;
|
|---|
| 1115 | }
|
|---|
| 1116 |
|
|---|
| 1117 | w/=2;h/=2;x/=2;y/=2;
|
|---|
| 1118 |
|
|---|
| 1119 | // copy U
|
|---|
| 1120 | d=image+dstride*image_height + uvstride*y+x;
|
|---|
| 1121 | if(image_format == IMGFMT_YV12)s=src[2];
|
|---|
| 1122 | else s=src[1];
|
|---|
| 1123 | for(i=0;i<h;i++){
|
|---|
| 1124 | memcpy(d,s,w);
|
|---|
| 1125 | s+=stride[1];
|
|---|
| 1126 | d+=uvstride;
|
|---|
| 1127 | }
|
|---|
| 1128 |
|
|---|
| 1129 | // copy V
|
|---|
| 1130 | d=image+dstride*image_height +uvstride*(image_height/2) + uvstride*y+x;
|
|---|
| 1131 | if(image_format == IMGFMT_YV12)s=src[1];
|
|---|
| 1132 | else s=src[2];
|
|---|
| 1133 | for(i=0;i<h;i++){
|
|---|
| 1134 | memcpy(d,s,w);
|
|---|
| 1135 | s+=stride[2];
|
|---|
| 1136 | d+=uvstride;
|
|---|
| 1137 | }
|
|---|
| 1138 | return 0;
|
|---|
| 1139 | }
|
|---|
| 1140 |
|
|---|
| 1141 | static void flip_page(void)
|
|---|
| 1142 | {
|
|---|
| 1143 | HRESULT dxresult;
|
|---|
| 1144 | g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL);
|
|---|
| 1145 | if (vo_doublebuffering)
|
|---|
| 1146 | {
|
|---|
| 1147 | // flip to the next image in the sequence
|
|---|
| 1148 | dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
|
|---|
| 1149 | if(dxresult == DDERR_SURFACELOST)
|
|---|
| 1150 | {
|
|---|
| 1151 | mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n");
|
|---|
| 1152 | g_lpddsBack->lpVtbl->Restore( g_lpddsBack );
|
|---|
| 1153 | dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
|
|---|
| 1154 | }
|
|---|
| 1155 | if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n");
|
|---|
| 1156 | }
|
|---|
| 1157 | if(nooverlay)
|
|---|
| 1158 | {
|
|---|
| 1159 | DDBLTFX ddbltfx;
|
|---|
| 1160 | // ask for the "NOTEARING" option
|
|---|
| 1161 | memset( &ddbltfx, 0, sizeof(DDBLTFX) );
|
|---|
| 1162 | ddbltfx.dwSize = sizeof(DDBLTFX);
|
|---|
| 1163 | ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
|
|---|
| 1164 | g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx);
|
|---|
| 1165 | }
|
|---|
| 1166 | g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL);
|
|---|
| 1167 | if(vo_directrendering && (dstride != ddsdsf.lPitch)){
|
|---|
| 1168 | mp_msg(MSGT_VO,MSGL_WARN,"<vo_directx><WARN>stride changed !!!! disabling direct rendering\n");
|
|---|
| 1169 | vo_directrendering=0;
|
|---|
| 1170 | }
|
|---|
| 1171 | dstride = ddsdsf.lPitch;
|
|---|
| 1172 | image = ddsdsf.lpSurface;
|
|---|
| 1173 | }
|
|---|
| 1174 |
|
|---|
| 1175 | static int draw_frame(uint8_t *src[])
|
|---|
| 1176 | {
|
|---|
| 1177 | memcpy( image, *src, dstride * image_height );
|
|---|
| 1178 | return 0;
|
|---|
| 1179 | }
|
|---|
| 1180 |
|
|---|
| 1181 | static uint32_t get_image(mp_image_t *mpi)
|
|---|
| 1182 | {
|
|---|
| 1183 | if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;}
|
|---|
| 1184 | if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;}
|
|---|
| 1185 | if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)))
|
|---|
| 1186 | {
|
|---|
| 1187 | if(mpi->flags&MP_IMGFLAG_PLANAR)
|
|---|
| 1188 | {
|
|---|
| 1189 | if(image_format == IMGFMT_YV12)
|
|---|
| 1190 | {
|
|---|
| 1191 | mpi->planes[2]= image + dstride*image_height;
|
|---|
| 1192 | mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4;
|
|---|
| 1193 | mpi->stride[1]=mpi->stride[2]=dstride/2;
|
|---|
| 1194 | }
|
|---|
| 1195 | else if(image_format == IMGFMT_IYUV || image_format == IMGFMT_I420)
|
|---|
| 1196 | {
|
|---|
| 1197 | mpi->planes[1]= image + dstride*image_height;
|
|---|
| 1198 | mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4;
|
|---|
| 1199 | mpi->stride[1]=mpi->stride[2]=dstride/2;
|
|---|
| 1200 | }
|
|---|
| 1201 | else if(image_format == IMGFMT_YVU9)
|
|---|
| 1202 | {
|
|---|
| 1203 | mpi->planes[2] = image + dstride*image_height;
|
|---|
| 1204 | mpi->planes[1] = image + dstride*image_height+ dstride*image_height/16;
|
|---|
| 1205 | mpi->stride[1]=mpi->stride[2]=dstride/4;
|
|---|
| 1206 | }
|
|---|
| 1207 | }
|
|---|
| 1208 | mpi->planes[0]=image;
|
|---|
| 1209 | mpi->stride[0]=dstride;
|
|---|
| 1210 | mpi->width=image_width;
|
|---|
| 1211 | mpi->height=image_height;
|
|---|
| 1212 | mpi->flags|=MP_IMGFLAG_DIRECT;
|
|---|
| 1213 | mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n");
|
|---|
| 1214 | return VO_TRUE;
|
|---|
| 1215 | }
|
|---|
| 1216 | return VO_FALSE;
|
|---|
| 1217 | }
|
|---|
| 1218 |
|
|---|
| 1219 | static uint32_t put_image(mp_image_t *mpi){
|
|---|
| 1220 |
|
|---|
| 1221 | uint32_t i = 0;
|
|---|
| 1222 | uint8_t *d;
|
|---|
| 1223 | uint8_t *s;
|
|---|
| 1224 | uint32_t x = mpi->x;
|
|---|
| 1225 | uint32_t y = mpi->y;
|
|---|
| 1226 | uint32_t w = mpi->w;
|
|---|
| 1227 | uint32_t h = mpi->h;
|
|---|
| 1228 |
|
|---|
| 1229 | if (WinID != -1) Directx_ManageDisplay();
|
|---|
| 1230 |
|
|---|
| 1231 | if((mpi->flags&MP_IMGFLAG_DIRECT)||(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK))
|
|---|
| 1232 | {
|
|---|
| 1233 | mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n");
|
|---|
| 1234 | return VO_TRUE;
|
|---|
| 1235 | }
|
|---|
| 1236 |
|
|---|
| 1237 | if (mpi->flags&MP_IMGFLAG_PLANAR)
|
|---|
| 1238 | {
|
|---|
| 1239 |
|
|---|
| 1240 | if(image_format!=IMGFMT_YVU9)draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0);
|
|---|
| 1241 | else
|
|---|
| 1242 | {
|
|---|
| 1243 | // copy Y
|
|---|
| 1244 | d=image+dstride*y+x;
|
|---|
| 1245 | s=mpi->planes[0];
|
|---|
| 1246 | for(i=0;i<h;i++){
|
|---|
| 1247 | memcpy(d,s,w);
|
|---|
| 1248 | s+=mpi->stride[0];
|
|---|
| 1249 | d+=dstride;
|
|---|
| 1250 | }
|
|---|
| 1251 | w/=4;h/=4;x/=4;y/=4;
|
|---|
| 1252 | // copy V
|
|---|
| 1253 | d=image+dstride*image_height + dstride*y/4+x;
|
|---|
| 1254 | s=mpi->planes[2];
|
|---|
| 1255 | for(i=0;i<h;i++){
|
|---|
| 1256 | memcpy(d,s,w);
|
|---|
| 1257 | s+=mpi->stride[1];
|
|---|
| 1258 | d+=dstride/4;
|
|---|
| 1259 | }
|
|---|
| 1260 | // copy U
|
|---|
| 1261 | d=image+dstride*image_height + dstride*image_height/16 + dstride/4*y+x;
|
|---|
| 1262 | s=mpi->planes[1];
|
|---|
| 1263 | for(i=0;i<h;i++){
|
|---|
| 1264 | memcpy(d,s,w);
|
|---|
| 1265 | s+=mpi->stride[2];
|
|---|
| 1266 | d+=dstride/4;
|
|---|
| 1267 | }
|
|---|
| 1268 | }
|
|---|
| 1269 | }
|
|---|
| 1270 | else //packed
|
|---|
| 1271 | {
|
|---|
| 1272 | memcpy( image, mpi->planes[0], image_height * dstride);
|
|---|
| 1273 | }
|
|---|
| 1274 | return VO_TRUE;
|
|---|
| 1275 | }
|
|---|
| 1276 |
|
|---|
| 1277 | static int
|
|---|
| 1278 | config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format)
|
|---|
| 1279 | {
|
|---|
| 1280 | RECT rd;
|
|---|
| 1281 | vo_screenwidth = monitor_rect.right - monitor_rect.left;
|
|---|
| 1282 | vo_screenheight = monitor_rect.bottom - monitor_rect.top;
|
|---|
| 1283 | vo_fs = options & 0x01;
|
|---|
| 1284 | image_format = format;
|
|---|
| 1285 | image_width = width;
|
|---|
| 1286 | image_height = height;
|
|---|
| 1287 | d_image_width = d_width;
|
|---|
| 1288 | d_image_height = d_height;
|
|---|
| 1289 | if(format != primary_image_format)nooverlay = 0;
|
|---|
| 1290 | aspect_save_orig(image_width,image_height);
|
|---|
| 1291 | aspect_save_prescale(d_image_width,d_image_height);
|
|---|
| 1292 | if(vidmode){
|
|---|
| 1293 | vo_screenwidth=vm_width;
|
|---|
| 1294 | vo_screenheight=vm_height;
|
|---|
| 1295 | }
|
|---|
| 1296 | aspect_save_screenres(vo_screenwidth,vo_screenheight);
|
|---|
| 1297 | aspect(&d_image_width, &d_image_height, A_NOZOOM);
|
|---|
| 1298 | window_aspect= (float)d_image_width / (float)d_image_height;
|
|---|
| 1299 | vo_dx = 0;
|
|---|
| 1300 | vo_dy = 0;
|
|---|
| 1301 |
|
|---|
| 1302 | /*release all directx objects*/
|
|---|
| 1303 | if (g_cc != NULL)g_cc->lpVtbl->Release(g_cc);
|
|---|
| 1304 | g_cc=NULL;
|
|---|
| 1305 | if(g_lpddclipper)g_lpddclipper->lpVtbl->Release(g_lpddclipper);
|
|---|
| 1306 | g_lpddclipper=NULL;
|
|---|
| 1307 | if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|---|
| 1308 | g_lpddsBack = NULL;
|
|---|
| 1309 | if(vo_doublebuffering)
|
|---|
| 1310 | if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
|
|---|
| 1311 | g_lpddsOverlay = NULL;
|
|---|
| 1312 | if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|---|
| 1313 | g_lpddsPrimary = NULL;
|
|---|
| 1314 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surfaces released\n");
|
|---|
| 1315 |
|
|---|
| 1316 | if(!vidmode){
|
|---|
| 1317 | if(vo_geometry){
|
|---|
| 1318 | vo_dx= ( vo_screenwidth - d_image_width ) / 2; vo_dy=( vo_screenheight - d_image_height ) / 2;
|
|---|
| 1319 | geometry(&vo_dx, &vo_dy, &d_image_width, &d_image_height, vo_screenwidth, vo_screenheight);
|
|---|
| 1320 | }
|
|---|
| 1321 | else {
|
|---|
| 1322 | GetWindowRect(hWnd,&rd);
|
|---|
| 1323 | vo_dx=rd.left;
|
|---|
| 1324 | vo_dy=rd.top;
|
|---|
| 1325 | }
|
|---|
| 1326 | vo_dx += monitor_rect.left; /* move position to global window space */
|
|---|
| 1327 | vo_dy += monitor_rect.top;
|
|---|
| 1328 | rd.left = vo_dx;
|
|---|
| 1329 | rd.top = vo_dy;
|
|---|
| 1330 | rd.right = rd.left + d_image_width;
|
|---|
| 1331 | rd.bottom = rd.top + d_image_height;
|
|---|
| 1332 | if (WinID == -1) {
|
|---|
| 1333 | if (vo_border)
|
|---|
| 1334 | AdjustWindowRect(&rd,WNDSTYLE,FALSE);
|
|---|
| 1335 | SetWindowPos(hWnd,NULL, vo_dx, vo_dy,rd.right-rd.left,rd.bottom-rd.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
|
|---|
| 1336 | }
|
|---|
| 1337 | }
|
|---|
| 1338 | else ShowWindow(hWnd,SW_SHOW);
|
|---|
| 1339 |
|
|---|
| 1340 | if(vo_fs && !vidmode)ShowWindow(hWndFS,SW_SHOW);
|
|---|
| 1341 | if (WinID == -1)
|
|---|
| 1342 | SetWindowText(hWnd,title);
|
|---|
| 1343 |
|
|---|
| 1344 |
|
|---|
| 1345 | if(vidmode)vo_fs=0;
|
|---|
| 1346 |
|
|---|
| 1347 |
|
|---|
| 1348 | /*create the surfaces*/
|
|---|
| 1349 | if(Directx_CreatePrimarySurface())return 1;
|
|---|
| 1350 |
|
|---|
| 1351 | //create palette for 256 color mode
|
|---|
| 1352 | if(image_format==IMGFMT_BGR8){
|
|---|
| 1353 | LPDIRECTDRAWPALETTE ddpalette=NULL;
|
|---|
| 1354 | char* palette=malloc(4*256);
|
|---|
| 1355 | int i;
|
|---|
| 1356 | for(i=0; i<256; i++){
|
|---|
| 1357 | palette[4*i+0] = ((i >> 5) & 0x07) * 255 / 7;
|
|---|
| 1358 | palette[4*i+1] = ((i >> 2) & 0x07) * 255 / 7;
|
|---|
| 1359 | palette[4*i+2] = ((i >> 0) & 0x03) * 255 / 3;
|
|---|
| 1360 | palette[4*i+3] = PC_NOCOLLAPSE;
|
|---|
| 1361 | }
|
|---|
| 1362 | g_lpdd->lpVtbl->CreatePalette(g_lpdd,DDPCAPS_8BIT|DDPCAPS_INITIALIZE,palette,&ddpalette,NULL);
|
|---|
| 1363 | g_lpddsPrimary->lpVtbl->SetPalette(g_lpddsPrimary,ddpalette);
|
|---|
| 1364 | free(palette);
|
|---|
| 1365 | ddpalette->lpVtbl->Release(ddpalette);
|
|---|
| 1366 | }
|
|---|
| 1367 |
|
|---|
| 1368 | if (!nooverlay && Directx_CreateOverlay(image_format))
|
|---|
| 1369 | {
|
|---|
| 1370 | if(format == primary_image_format)nooverlay=1; /*overlay creation failed*/
|
|---|
| 1371 | else {
|
|---|
| 1372 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't use overlay mode: please use -vo directx:noaccel\n");
|
|---|
| 1373 | return 1;
|
|---|
| 1374 | }
|
|---|
| 1375 | }
|
|---|
| 1376 | if(nooverlay)
|
|---|
| 1377 | {
|
|---|
| 1378 | if(Directx_CreateBackpuffer())
|
|---|
| 1379 | {
|
|---|
| 1380 | mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get the driver to work on your system :(\n");
|
|---|
| 1381 | return 1;
|
|---|
| 1382 | }
|
|---|
| 1383 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>back surface created\n");
|
|---|
| 1384 | vo_doublebuffering = 0;
|
|---|
| 1385 | /*create clipper for nonoverlay mode*/
|
|---|
| 1386 | if(g_lpdd->lpVtbl->CreateClipper(g_lpdd, 0, &g_lpddclipper,NULL)!= DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create clipper\n");return 1;}
|
|---|
| 1387 | if(g_lpddclipper->lpVtbl->SetHWnd (g_lpddclipper, 0, hWnd)!= DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't associate clipper with window\n");return 1;}
|
|---|
| 1388 | if(g_lpddsPrimary->lpVtbl->SetClipper (g_lpddsPrimary,g_lpddclipper)!=DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't associate primary surface with clipper\n");return 1;}
|
|---|
| 1389 | mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper succesfully created\n");
|
|---|
| 1390 | }else{
|
|---|
| 1391 | if(DD_OK != g_lpddsOverlay->lpVtbl->QueryInterface(g_lpddsOverlay,&IID_IDirectDrawColorControl,(void**)&g_cc))
|
|---|
| 1392 | mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>unable to get DirectDraw ColorControl interface\n");
|
|---|
| 1393 | }
|
|---|
| 1394 | Directx_ManageDisplay();
|
|---|
| 1395 | memset(&ddsdsf, 0,sizeof(DDSURFACEDESC2));
|
|---|
| 1396 | ddsdsf.dwSize = sizeof (DDSURFACEDESC2);
|
|---|
| 1397 | g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
|
|---|
| 1398 | dstride = ddsdsf.lPitch;
|
|---|
| 1399 | image = ddsdsf.lpSurface;
|
|---|
| 1400 | return 0;
|
|---|
| 1401 | }
|
|---|
| 1402 |
|
|---|
| 1403 | //function to set color controls
|
|---|
| 1404 | // brightness [0, 10000]
|
|---|
| 1405 | // contrast [0, 20000]
|
|---|
| 1406 | // hue [-180, 180]
|
|---|
| 1407 | // saturation [0, 20000]
|
|---|
| 1408 | static uint32_t color_ctrl_set(char *what, int value)
|
|---|
| 1409 | {
|
|---|
| 1410 | uint32_t r = VO_NOTIMPL;
|
|---|
| 1411 | DDCOLORCONTROL dcc;
|
|---|
| 1412 | //printf("\n*** %s = %d\n", what, value);
|
|---|
| 1413 | if (!g_cc) {
|
|---|
| 1414 | //printf("\n *** could not get color control interface!!!\n");
|
|---|
| 1415 | return VO_NOTIMPL;
|
|---|
| 1416 | }
|
|---|
| 1417 | ZeroMemory(&dcc, sizeof(dcc));
|
|---|
| 1418 | dcc.dwSize = sizeof(dcc);
|
|---|
| 1419 |
|
|---|
| 1420 | if (!strcmp(what, "brightness")) {
|
|---|
| 1421 | dcc.dwFlags = DDCOLOR_BRIGHTNESS;
|
|---|
| 1422 | dcc.lBrightness = (value + 100) * 10000 / 200;
|
|---|
| 1423 | r = VO_TRUE;
|
|---|
| 1424 | } else if (!strcmp(what, "contrast")) {
|
|---|
| 1425 | dcc.dwFlags = DDCOLOR_CONTRAST;
|
|---|
| 1426 | dcc.lContrast = (value + 100) * 20000 / 200;
|
|---|
| 1427 | r = VO_TRUE;
|
|---|
| 1428 | } else if (!strcmp(what, "hue")) {
|
|---|
| 1429 | dcc.dwFlags = DDCOLOR_HUE;
|
|---|
| 1430 | dcc.lHue = value * 180 / 100;
|
|---|
| 1431 | r = VO_TRUE;
|
|---|
| 1432 | } else if (!strcmp(what, "saturation")) {
|
|---|
| 1433 | dcc.dwFlags = DDCOLOR_SATURATION;
|
|---|
| 1434 | dcc.lSaturation = (value + 100) * 20000 / 200;
|
|---|
| 1435 | r = VO_TRUE;
|
|---|
| 1436 | }
|
|---|
| 1437 |
|
|---|
| 1438 | if (r == VO_TRUE) {
|
|---|
| 1439 | g_cc->lpVtbl->SetColorControls(g_cc, &dcc);
|
|---|
| 1440 | }
|
|---|
| 1441 | return r;
|
|---|
| 1442 | }
|
|---|
| 1443 |
|
|---|
| 1444 | //analoguous to color_ctrl_set
|
|---|
| 1445 | static uint32_t color_ctrl_get(char *what, int *value)
|
|---|
| 1446 | {
|
|---|
| 1447 | uint32_t r = VO_NOTIMPL;
|
|---|
| 1448 | DDCOLORCONTROL dcc;
|
|---|
| 1449 | if (!g_cc) {
|
|---|
| 1450 | //printf("\n *** could not get color control interface!!!\n");
|
|---|
| 1451 | return VO_NOTIMPL;
|
|---|
| 1452 | }
|
|---|
| 1453 | ZeroMemory(&dcc, sizeof(dcc));
|
|---|
| 1454 | dcc.dwSize = sizeof(dcc);
|
|---|
| 1455 |
|
|---|
| 1456 | if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) {
|
|---|
| 1457 | return r;
|
|---|
| 1458 | }
|
|---|
| 1459 |
|
|---|
| 1460 | if (!strcmp(what, "brightness") && (dcc.dwFlags & DDCOLOR_BRIGHTNESS)) {
|
|---|
| 1461 | *value = dcc.lBrightness * 200 / 10000 - 100;
|
|---|
| 1462 | r = VO_TRUE;
|
|---|
| 1463 | } else if (!strcmp(what, "contrast") && (dcc.dwFlags & DDCOLOR_CONTRAST)) {
|
|---|
| 1464 | *value = dcc.lContrast * 200 / 20000 - 100;
|
|---|
| 1465 | r = VO_TRUE;
|
|---|
| 1466 | } else if (!strcmp(what, "hue") && (dcc.dwFlags & DDCOLOR_HUE)) {
|
|---|
| 1467 | *value = dcc.lHue * 100 / 180;
|
|---|
| 1468 | r = VO_TRUE;
|
|---|
| 1469 | } else if (!strcmp(what, "saturation") && (dcc.dwFlags & DDCOLOR_SATURATION)) {
|
|---|
| 1470 | *value = dcc.lSaturation * 200 / 20000 - 100;
|
|---|
| 1471 | r = VO_TRUE;
|
|---|
| 1472 | }
|
|---|
| 1473 | // printf("\n*** %s = %d\n", what, *value);
|
|---|
| 1474 |
|
|---|
| 1475 | return r;
|
|---|
| 1476 | }
|
|---|
| 1477 |
|
|---|
| 1478 | static int control(uint32_t request, void *data, ...)
|
|---|
| 1479 | {
|
|---|
| 1480 | switch (request) {
|
|---|
| 1481 |
|
|---|
| 1482 | case VOCTRL_GET_IMAGE:
|
|---|
| 1483 | return get_image(data);
|
|---|
| 1484 | case VOCTRL_QUERY_FORMAT:
|
|---|
| 1485 | return query_format(*((uint32_t*)data));
|
|---|
| 1486 | case VOCTRL_DRAW_IMAGE:
|
|---|
| 1487 | return put_image(data);
|
|---|
| 1488 | case VOCTRL_BORDER:
|
|---|
| 1489 | if(WinID != -1) return VO_TRUE;
|
|---|
| 1490 | if(vidmode)
|
|---|
| 1491 | {
|
|---|
| 1492 | mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>border has no meaning in exclusive mode\n");
|
|---|
| 1493 | }
|
|---|
| 1494 | else
|
|---|
| 1495 | {
|
|---|
| 1496 | if(vo_border) {
|
|---|
| 1497 | vo_border = 0;
|
|---|
| 1498 | SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
|
|---|
| 1499 | } else {
|
|---|
| 1500 | vo_border = 1;
|
|---|
| 1501 | SetWindowLong(hWnd, GWL_STYLE, WNDSTYLE);
|
|---|
| 1502 | }
|
|---|
| 1503 | // needed AFAICT to force the window to
|
|---|
| 1504 | // redisplay with the new style. --Joey
|
|---|
| 1505 | if (!vo_fs) {
|
|---|
| 1506 | ShowWindow(hWnd,SW_HIDE);
|
|---|
| 1507 | ShowWindow(hWnd,SW_SHOW);
|
|---|
| 1508 | }
|
|---|
| 1509 | Directx_ManageDisplay();
|
|---|
| 1510 | }
|
|---|
| 1511 | return VO_TRUE;
|
|---|
| 1512 | case VOCTRL_ONTOP:
|
|---|
| 1513 | if(WinID != -1) return VO_TRUE;
|
|---|
| 1514 | if(vidmode)
|
|---|
| 1515 | {
|
|---|
| 1516 | mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>ontop has no meaning in exclusive mode\n");
|
|---|
| 1517 | }
|
|---|
| 1518 | else
|
|---|
| 1519 | {
|
|---|
| 1520 | if(vo_ontop) vo_ontop = 0;
|
|---|
| 1521 | else vo_ontop = 1;
|
|---|
| 1522 | Directx_ManageDisplay();
|
|---|
| 1523 | }
|
|---|
| 1524 | return VO_TRUE;
|
|---|
| 1525 | case VOCTRL_ROOTWIN:
|
|---|
| 1526 | if(WinID != -1) return VO_TRUE;
|
|---|
| 1527 | if(vidmode)
|
|---|
| 1528 | {
|
|---|
| 1529 | mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>rootwin has no meaning in exclusive mode\n");
|
|---|
| 1530 | }
|
|---|
| 1531 | else
|
|---|
| 1532 | {
|
|---|
| 1533 | if(vo_rootwin) vo_rootwin = 0;
|
|---|
| 1534 | else vo_rootwin = 1;
|
|---|
| 1535 | Directx_ManageDisplay();
|
|---|
| 1536 | }
|
|---|
| 1537 | return VO_TRUE;
|
|---|
| 1538 | case VOCTRL_FULLSCREEN:
|
|---|
| 1539 | {
|
|---|
| 1540 | if(vidmode)
|
|---|
| 1541 | {
|
|---|
| 1542 | mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>currently we do not allow to switch from exclusive to windowed mode\n");
|
|---|
| 1543 | }
|
|---|
| 1544 | else
|
|---|
| 1545 | {
|
|---|
| 1546 | if(!vo_fs)
|
|---|
| 1547 | {
|
|---|
| 1548 | vo_fs=1;
|
|---|
| 1549 | ShowWindow(hWndFS,SW_SHOW);
|
|---|
| 1550 | ShowWindow(hWnd,SW_HIDE);
|
|---|
| 1551 | SetForegroundWindow(hWndFS);
|
|---|
| 1552 | }
|
|---|
| 1553 | else
|
|---|
| 1554 | {
|
|---|
| 1555 | vo_fs=0;
|
|---|
| 1556 | ShowWindow(hWndFS,SW_HIDE);
|
|---|
| 1557 | ShowWindow(hWnd,SW_SHOW);
|
|---|
| 1558 | }
|
|---|
| 1559 | Directx_ManageDisplay();
|
|---|
| 1560 | break;
|
|---|
| 1561 | }
|
|---|
| 1562 | return VO_TRUE;
|
|---|
| 1563 | }
|
|---|
| 1564 | case VOCTRL_SET_EQUALIZER: {
|
|---|
| 1565 | va_list ap;
|
|---|
| 1566 | int value;
|
|---|
| 1567 |
|
|---|
| 1568 | va_start(ap, data);
|
|---|
| 1569 | value = va_arg(ap, int);
|
|---|
| 1570 | va_end(ap);
|
|---|
| 1571 | return color_ctrl_set(data, value);
|
|---|
| 1572 | }
|
|---|
| 1573 | case VOCTRL_GET_EQUALIZER: {
|
|---|
| 1574 | va_list ap;
|
|---|
| 1575 | int *value;
|
|---|
| 1576 |
|
|---|
| 1577 | va_start(ap, data);
|
|---|
| 1578 | value = va_arg(ap, int*);
|
|---|
| 1579 | va_end(ap);
|
|---|
| 1580 | return color_ctrl_get(data, value);
|
|---|
| 1581 | }
|
|---|
| 1582 | };
|
|---|
| 1583 | return VO_NOTIMPL;
|
|---|
| 1584 | }
|
|---|