comparison libvo/vo_directx.c @ 33808:b69bf18ef92c

Apply uncrustify to vo_directx.c. The vast majority of changes are whitespace changes, but in some cases {} was merged with other lines or a ; was removed after a } from a switch and similar minor and obviously correct changes.
author reimar
date Sun, 24 Jul 2011 18:11:39 +0000
parents fb9eaa0ab770
children ad332c21f549
comparison
equal deleted inserted replaced
33807:fb9eaa0ab770 33808:b69bf18ef92c
35 #include "mp_msg.h" 35 #include "mp_msg.h"
36 #include "aspect.h" 36 #include "aspect.h"
37 #include "sub/sub.h" 37 #include "sub/sub.h"
38 #include "w32_common.h" 38 #include "w32_common.h"
39 39
40 static LPDIRECTDRAWCOLORCONTROL g_cc = NULL; //color control interface 40 static LPDIRECTDRAWCOLORCONTROL g_cc = NULL; //color control interface
41 static LPDIRECTDRAW7 g_lpdd = NULL; //DirectDraw Object 41 static LPDIRECTDRAW7 g_lpdd = NULL; //DirectDraw Object
42 static LPDIRECTDRAWSURFACE7 g_lpddsPrimary = NULL; //Primary Surface: viewport through the Desktop 42 static LPDIRECTDRAWSURFACE7 g_lpddsPrimary = NULL; //Primary Surface: viewport through the Desktop
43 static LPDIRECTDRAWSURFACE7 g_lpddsOverlay = NULL; //Overlay Surface 43 static LPDIRECTDRAWSURFACE7 g_lpddsOverlay = NULL; //Overlay Surface
44 static LPDIRECTDRAWSURFACE7 g_lpddsBack = NULL; //Back surface 44 static LPDIRECTDRAWSURFACE7 g_lpddsBack = NULL; //Back surface
45 static LPDIRECTDRAWCLIPPER g_lpddclipper; //clipper object, can only be used without overlay 45 static LPDIRECTDRAWCLIPPER g_lpddclipper; //clipper object, can only be used without overlay
46 static DDSURFACEDESC2 ddsdsf; //surface descripiton needed for locking 46 static DDSURFACEDESC2 ddsdsf; //surface descripiton needed for locking
47 static HINSTANCE hddraw_dll; //handle to ddraw.dll 47 static HINSTANCE hddraw_dll; //handle to ddraw.dll
48 static RECT rd; //rect of our stretched image 48 static RECT rd; //rect of our stretched image
49 static RECT rs; //rect of our source image 49 static RECT rs; //rect of our source image
50 static HBRUSH colorbrush = NULL; // Handle to colorkey brush 50 static HBRUSH colorbrush = NULL; // Handle to colorkey brush
51 static HBRUSH blackbrush = NULL; // Handle to black brush 51 static HBRUSH blackbrush = NULL; // Handle to black brush
52 static uint32_t image_width, image_height; //image width and height 52 static uint32_t image_width, image_height; //image width and height
53 static uint8_t *image=NULL; //image data 53 static uint8_t *image = NULL; //image data
54 static void* tmp_image = NULL; 54 static void *tmp_image = NULL;
55 static uint32_t image_format=0; //image format 55 static uint32_t image_format = 0; //image format
56 static uint32_t primary_image_format; 56 static uint32_t primary_image_format;
57 static uint32_t vm_height=0; 57 static uint32_t vm_height = 0;
58 static uint32_t vm_width=0; 58 static uint32_t vm_width = 0;
59 static uint32_t vm_bpp=0; 59 static uint32_t vm_bpp = 0;
60 static uint32_t dstride; //surface stride 60 static uint32_t dstride; //surface stride
61 static uint32_t nooverlay = 0; //NonOverlay mode 61 static uint32_t nooverlay = 0; //NonOverlay mode
62 static DWORD destcolorkey; //colorkey for our surface 62 static DWORD destcolorkey; //colorkey for our surface
63 static COLORREF windowcolor = RGB(0,0,16); //windowcolor == colorkey 63 static COLORREF windowcolor = RGB(0, 0, 16); //windowcolor == colorkey
64 static int adapter_count=0; 64 static int adapter_count = 0;
65 static GUID selected_guid; 65 static GUID selected_guid;
66 static GUID *selected_guid_ptr = NULL; 66 static GUID *selected_guid_ptr = NULL;
67 67
68 /***************************************************************************** 68 /*****************************************************************************
69 * DirectDraw GUIDs. 69 * DirectDraw GUIDs.
70 * Defining them here allows us to get rid of the dxguid library during 70 * Defining them here allows us to get rid of the dxguid library during
71 * the linking stage. 71 * the linking stage.
72 *****************************************************************************/ 72 *****************************************************************************/
73 #define IID_IDirectDraw7 MP_IID_IDirectDraw7 73 #define IID_IDirectDraw7 MP_IID_IDirectDraw7
74 static const GUID MP_IID_IDirectDraw7 = 74 static const GUID MP_IID_IDirectDraw7 = {
75 { 75 0x15e65ec0, 0x3b9c, 0x11d2, { 0xb9, 0x2f, 0x00, 0x60, 0x97, 0x97, 0xea, 0x5b }
76 0x15e65ec0,0x3b9c,0x11d2,{0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b}
77 }; 76 };
78 77
79 #define IID_IDirectDrawColorControl MP_IID_IDirectDrawColorControl 78 #define IID_IDirectDrawColorControl MP_IID_IDirectDrawColorControl
80 static const GUID MP_IID_IDirectDrawColorControl = 79 static const GUID MP_IID_IDirectDrawColorControl = {
81 { 80 0x4b9f0ee0, 0x0d7e, 0x11d0, { 0x9b, 0x06, 0x00, 0xa0, 0xc9, 0x03, 0xa3, 0xb8 }
82 0x4b9f0ee0,0x0d7e,0x11d0,{0x9b,0x06,0x00,0xa0,0xc9,0x03,0xa3,0xb8}
83 }; 81 };
84 82
85 83 typedef struct directx_fourcc_caps {
86 typedef struct directx_fourcc_caps 84 char *img_format_name; //human readable name
87 { 85 uint32_t img_format; //as MPlayer image format
88 char* img_format_name; //human readable name 86 uint32_t drv_caps; //what hw supports with this format
89 uint32_t img_format; //as MPlayer image format 87 DDPIXELFORMAT g_ddpfOverlay; //as Directx Sourface description
90 uint32_t drv_caps; //what hw supports with this format
91 DDPIXELFORMAT g_ddpfOverlay; //as Directx Sourface description
92 } directx_fourcc_caps; 88 } directx_fourcc_caps;
93 89
94 90 static directx_fourcc_caps g_ddpf[] = {
95 static directx_fourcc_caps g_ddpf[] = 91 { "YV12 ", IMGFMT_YV12, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'V', '1', '2'), 0, 0, 0, 0, 0 } },
96 { 92 { "I420 ", IMGFMT_I420, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('I', '4', '2', '0'), 0, 0, 0, 0, 0 } }, //yv12 with swapped uv
97 {"YV12 ",IMGFMT_YV12 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','1','2'),0,0,0,0,0}}, 93 { "IYUV ", IMGFMT_IYUV, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('I', 'Y', 'U', 'V'), 0, 0, 0, 0, 0 } }, //same as i420
98 {"I420 ",IMGFMT_I420 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','4','2','0'),0,0,0,0,0}}, //yv12 with swapped uv 94 { "YVU9 ", IMGFMT_YVU9, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'V', 'U', '9'), 0, 0, 0, 0, 0 } },
99 {"IYUV ",IMGFMT_IYUV ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','Y','U','V'),0,0,0,0,0}}, //same as i420 95 { "YUY2 ", IMGFMT_YUY2, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'), 0, 0, 0, 0, 0 } },
100 {"YVU9 ",IMGFMT_YVU9 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','U','9'),0,0,0,0,0}}, 96 { "UYVY ", IMGFMT_UYVY, 0, { sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'), 0, 0, 0, 0, 0 } },
101 {"YUY2 ",IMGFMT_YUY2 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','U','Y','2'),0,0,0,0,0}}, 97 { "BGR8 ", IMGFMT_BGR8, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0x00000000, 0x00000000, 0x00000000, 0 } },
102 {"UYVY ",IMGFMT_UYVY ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('U','Y','V','Y'),0,0,0,0,0}}, 98 { "RGB15", IMGFMT_RGB15, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000003E0, 0x00007C00, 0 } }, //RGB 5:5:5
103 {"BGR8 ",IMGFMT_BGR8 ,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0x00000000, 0x00000000, 0x00000000, 0}}, 99 { "BGR15", IMGFMT_BGR15, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00007C00, 0x000003E0, 0x0000001F, 0 } },
104 {"RGB15",IMGFMT_RGB15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000003E0, 0x00007C00, 0}}, //RGB 5:5:5 100 { "RGB16", IMGFMT_RGB16, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000007E0, 0x0000F800, 0 } }, //RGB 5:6:5
105 {"BGR15",IMGFMT_BGR15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00007C00, 0x000003E0, 0x0000001F, 0}}, 101 { "BGR16", IMGFMT_BGR16, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000F800, 0x000007E0, 0x0000001F, 0 } },
106 {"RGB16",IMGFMT_RGB16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000007E0, 0x0000F800, 0}}, //RGB 5:6:5 102 { "RGB24", IMGFMT_RGB24, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0 } },
107 {"BGR16",IMGFMT_BGR16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000F800, 0x000007E0, 0x0000001F, 0}}, 103 { "BGR24", IMGFMT_BGR24, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0 } },
108 {"RGB24",IMGFMT_RGB24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}}, 104 { "RGB32", IMGFMT_RGB32, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0 } },
109 {"BGR24",IMGFMT_BGR24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}}, 105 { "BGR32", IMGFMT_BGR32, 0, { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0 } }
110 {"RGB32",IMGFMT_RGB32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
111 {"BGR32",IMGFMT_BGR32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}}
112 }; 106 };
113 #define NUM_FORMATS (sizeof(g_ddpf) / sizeof(g_ddpf[0])) 107 #define NUM_FORMATS (sizeof(g_ddpf) / sizeof(g_ddpf[0]))
114 108
115 static const vo_info_t info = 109 static const vo_info_t info = {
116 { 110 "Directx DDraw YUV/RGB/BGR renderer",
117 "Directx DDraw YUV/RGB/BGR renderer", 111 "directx",
118 "directx", 112 "Sascha Sommer <saschasommer@freenet.de>",
119 "Sascha Sommer <saschasommer@freenet.de>", 113 ""
120 ""
121 }; 114 };
122 115
123 const LIBVO_EXTERN(directx) 116 const LIBVO_EXTERN(directx)
124 117
125 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, 118 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
126 unsigned char *srca, int stride) 119 unsigned char *srca, int stride)
127 { 120 {
128 switch(image_format) { 121 switch (image_format) {
129 case IMGFMT_YV12 : 122 case IMGFMT_YV12:
130 case IMGFMT_I420 : 123 case IMGFMT_I420:
131 case IMGFMT_IYUV : 124 case IMGFMT_IYUV:
132 case IMGFMT_YVU9 : 125 case IMGFMT_YVU9:
133 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + x0,dstride); 126 vo_draw_alpha_yv12(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + x0, dstride);
134 break; 127 break;
135 case IMGFMT_YUY2 : 128 case IMGFMT_YUY2:
136 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image)+ dstride*y0 + 2*x0 ,dstride); 129 vo_draw_alpha_yuy2(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 2 * x0, dstride);
137 break; 130 break;
138 case IMGFMT_UYVY : 131 case IMGFMT_UYVY:
139 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + 2*x0 + 1,dstride); 132 vo_draw_alpha_yuy2(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 2 * x0 + 1, dstride);
140 break; 133 break;
141 case IMGFMT_RGB15: 134 case IMGFMT_RGB15:
142 case IMGFMT_BGR15: 135 case IMGFMT_BGR15:
143 vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride); 136 vo_draw_alpha_rgb15(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 2 * x0, dstride);
144 break; 137 break;
145 case IMGFMT_RGB16: 138 case IMGFMT_RGB16:
146 case IMGFMT_BGR16: 139 case IMGFMT_BGR16:
147 vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride); 140 vo_draw_alpha_rgb16(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 2 * x0, dstride);
148 break; 141 break;
149 case IMGFMT_RGB24: 142 case IMGFMT_RGB24:
150 case IMGFMT_BGR24: 143 case IMGFMT_BGR24:
151 vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride); 144 vo_draw_alpha_rgb24(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 4 * x0, dstride);
152 break; 145 break;
153 case IMGFMT_RGB32: 146 case IMGFMT_RGB32:
154 case IMGFMT_BGR32: 147 case IMGFMT_BGR32:
155 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride); 148 vo_draw_alpha_rgb32(w, h, src, srca, stride, ((uint8_t *)image) + dstride * y0 + 4 * x0, dstride);
156 break; 149 break;
157 } 150 }
158 } 151 }
159 152
160 static void draw_osd(void) 153 static void draw_osd(void)
161 { 154 {
162 vo_draw_text(image_width,image_height,draw_alpha); 155 vo_draw_text(image_width, image_height, draw_alpha);
163 } 156 }
164 157
165 static int 158 static int query_format(uint32_t format)
166 query_format(uint32_t format) 159 {
167 { 160 uint32_t i = 0;
168 uint32_t i=0; 161 while (i < NUM_FORMATS) {
169 while ( i < NUM_FORMATS ) 162 if (g_ddpf[i].img_format == format)
170 { 163 return g_ddpf[i].drv_caps;
171 if (g_ddpf[i].img_format == format) 164 i++;
172 return g_ddpf[i].drv_caps;
173 i++;
174 } 165 }
175 return 0; 166 return 0;
176 } 167 }
177 168
178 static uint32_t Directx_CreatePrimarySurface(void) 169 static uint32_t Directx_CreatePrimarySurface(void)
179 { 170 {
180 DDSURFACEDESC2 ddsd; 171 DDSURFACEDESC2 ddsd;
181 //cleanup 172 //cleanup
182 if(g_lpddsPrimary)g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); 173 if (g_lpddsPrimary)
183 g_lpddsPrimary=NULL; 174 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
184 175 g_lpddsPrimary = NULL;
185 if(vidmode)g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width,vm_height,vm_bpp,vo_refresh_rate,0); 176
177 if (vidmode)
178 g_lpdd->lpVtbl->SetDisplayMode(g_lpdd, vm_width, vm_height, vm_bpp, vo_refresh_rate, 0);
186 ZeroMemory(&ddsd, sizeof(ddsd)); 179 ZeroMemory(&ddsd, sizeof(ddsd));
187 ddsd.dwSize = sizeof(ddsd); 180 ddsd.dwSize = sizeof(ddsd);
188 //set flags and create a primary surface. 181 //set flags and create a primary surface.
189 ddsd.dwFlags = DDSD_CAPS; 182 ddsd.dwFlags = DDSD_CAPS;
190 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; 183 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
191 if(g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsd, &g_lpddsPrimary, NULL )== DD_OK) 184 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsPrimary, NULL) == DD_OK)
192 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary surface created\n"); 185 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>primary surface created\n");
193 else 186 else {
194 { 187 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>could not create primary surface\n");
195 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not create primary surface\n"); 188 return 1;
196 return 1; 189 }
197 } 190 return 0;
198 return 0;
199 } 191 }
200 192
201 static uint32_t Directx_CreateOverlay(uint32_t imgfmt) 193 static uint32_t Directx_CreateOverlay(uint32_t imgfmt)
202 { 194 {
203 HRESULT ddrval; 195 HRESULT ddrval;
204 DDSURFACEDESC2 ddsdOverlay; 196 DDSURFACEDESC2 ddsdOverlay;
205 uint32_t i=0; 197 uint32_t i = 0;
206 while ( i < NUM_FORMATS && imgfmt != g_ddpf[i].img_format) 198 while (i < NUM_FORMATS && imgfmt != g_ddpf[i].img_format)
207 { 199 i++;
208 i++; 200 if (!g_lpdd || !g_lpddsPrimary || i == NUM_FORMATS)
209 }
210 if (!g_lpdd || !g_lpddsPrimary || i == NUM_FORMATS)
211 return 1; 201 return 1;
212 //cleanup 202 //cleanup
213 if (g_lpddsOverlay)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay); 203 if (g_lpddsOverlay)
214 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack); 204 g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
215 g_lpddsOverlay= NULL; 205 if (g_lpddsBack)
216 g_lpddsBack = NULL; 206 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
217 //create our overlay 207 g_lpddsOverlay = NULL;
208 g_lpddsBack = NULL;
209 //create our overlay
218 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay)); 210 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
219 ddsdOverlay.dwSize = sizeof(ddsdOverlay); 211 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
220 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY; 212 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
221 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT| DDSD_PIXELFORMAT; 213 ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_BACKBUFFERCOUNT | DDSD_PIXELFORMAT;
222 ddsdOverlay.dwWidth=image_width; 214 ddsdOverlay.dwWidth = image_width;
223 ddsdOverlay.dwHeight=image_height; 215 ddsdOverlay.dwHeight = image_height;
224 ddsdOverlay.dwBackBufferCount=2; 216 ddsdOverlay.dwBackBufferCount = 2;
225 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay; 217 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay;
226 if(vo_doublebuffering) //tribblebuffering 218 if (vo_doublebuffering) { //tribblebuffering
227 { 219 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL) == DD_OK) {
228 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL)== DD_OK) 220 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>overlay with format %s created\n", g_ddpf[i].img_format_name);
229 {
230 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>overlay with format %s created\n",g_ddpf[i].img_format_name);
231 //get the surface directly attached to the primary (the back buffer) 221 //get the surface directly attached to the primary (the back buffer)
232 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; 222 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
233 if(g_lpddsOverlay->lpVtbl->GetAttachedSurface(g_lpddsOverlay,&ddsdOverlay.ddsCaps, &g_lpddsBack) != DD_OK) 223 if (g_lpddsOverlay->lpVtbl->GetAttachedSurface(g_lpddsOverlay, &ddsdOverlay.ddsCaps, &g_lpddsBack) != DD_OK) {
234 { 224 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't get attached surface\n");
235 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get attached surface\n"); 225 return 1;
236 return 1; 226 }
237 } 227 return 0;
238 return 0; 228 }
239 } 229 vo_doublebuffering = 0; //disable tribblebuffering
240 vo_doublebuffering=0; //disable tribblebuffering 230 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><WARN>cannot create tribblebuffer overlay with format %s\n", g_ddpf[i].img_format_name);
241 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>cannot create tribblebuffer overlay with format %s\n",g_ddpf[i].img_format_name); 231 }
242 } 232 //single buffer
243 //single buffer 233 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>using singlebuffer overlay\n");
244 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using singlebuffer overlay\n"); 234 ddsdOverlay.dwBackBufferCount = 0;
245 ddsdOverlay.dwBackBufferCount=0; 235 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
246 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; 236 ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
247 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; 237 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay;
248 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay; 238 // try to create the overlay surface
249 // try to create the overlay surface 239 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL);
250 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL); 240 if (ddrval != DD_OK) {
251 if(ddrval != DD_OK) 241 if (ddrval == DDERR_INVALIDPIXELFORMAT)
252 { 242 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><ERROR> invalid pixelformat: %s\n", g_ddpf[i].img_format_name);
253 if(ddrval == DDERR_INVALIDPIXELFORMAT)mp_msg(MSGT_VO,MSGL_V,"<vo_directx><ERROR> invalid pixelformat: %s\n",g_ddpf[i].img_format_name); 243 else
254 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>"); 244 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>");
255 switch(ddrval) 245 switch (ddrval) {
256 { 246 case DDERR_INCOMPATIBLEPRIMARY:
257 case DDERR_INCOMPATIBLEPRIMARY: 247 { mp_msg(MSGT_VO, MSGL_ERR, "incompatible primary surface\n");
258 {mp_msg(MSGT_VO, MSGL_ERR,"incompatible primary surface\n");break;} 248 break;
259 case DDERR_INVALIDCAPS: 249 }
260 {mp_msg(MSGT_VO, MSGL_ERR,"invalid caps\n");break;} 250 case DDERR_INVALIDCAPS:
261 case DDERR_INVALIDOBJECT: 251 { mp_msg(MSGT_VO, MSGL_ERR, "invalid caps\n");
262 {mp_msg(MSGT_VO, MSGL_ERR,"invalid object\n");break;} 252 break;
263 case DDERR_INVALIDPARAMS: 253 }
264 {mp_msg(MSGT_VO, MSGL_ERR,"invalid parameters\n");break;} 254 case DDERR_INVALIDOBJECT:
265 case DDERR_NODIRECTDRAWHW: 255 { mp_msg(MSGT_VO, MSGL_ERR, "invalid object\n");
266 {mp_msg(MSGT_VO, MSGL_ERR,"no directdraw hardware\n");break;} 256 break;
267 case DDERR_NOEMULATION: 257 }
268 {mp_msg(MSGT_VO, MSGL_ERR,"can't emulate\n");break;} 258 case DDERR_INVALIDPARAMS:
269 case DDERR_NOFLIPHW: 259 { mp_msg(MSGT_VO, MSGL_ERR, "invalid parameters\n");
270 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do flip\n");break;} 260 break;
271 case DDERR_NOOVERLAYHW: 261 }
272 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do overlay\n");break;} 262 case DDERR_NODIRECTDRAWHW:
273 case DDERR_OUTOFMEMORY: 263 { mp_msg(MSGT_VO, MSGL_ERR, "no directdraw hardware\n");
274 {mp_msg(MSGT_VO, MSGL_ERR,"not enough system memory\n");break;} 264 break;
275 case DDERR_UNSUPPORTEDMODE: 265 }
276 {mp_msg(MSGT_VO, MSGL_ERR,"unsupported mode\n");break;} 266 case DDERR_NOEMULATION:
277 case DDERR_OUTOFVIDEOMEMORY: 267 { mp_msg(MSGT_VO, MSGL_ERR, "can't emulate\n");
278 {mp_msg(MSGT_VO, MSGL_ERR,"not enough video memory\n");break;} 268 break;
279 default: 269 }
280 mp_msg(MSGT_VO, MSGL_ERR,"create surface failed with 0x%x\n",ddrval); 270 case DDERR_NOFLIPHW:
281 } 271 { mp_msg(MSGT_VO, MSGL_ERR, "hardware can't do flip\n");
282 return 1; 272 break;
283 } 273 }
274 case DDERR_NOOVERLAYHW:
275 { mp_msg(MSGT_VO, MSGL_ERR, "hardware can't do overlay\n");
276 break;
277 }
278 case DDERR_OUTOFMEMORY:
279 { mp_msg(MSGT_VO, MSGL_ERR, "not enough system memory\n");
280 break;
281 }
282 case DDERR_UNSUPPORTEDMODE:
283 { mp_msg(MSGT_VO, MSGL_ERR, "unsupported mode\n");
284 break;
285 }
286 case DDERR_OUTOFVIDEOMEMORY:
287 { mp_msg(MSGT_VO, MSGL_ERR, "not enough video memory\n");
288 break;
289 }
290 default:
291 mp_msg(MSGT_VO, MSGL_ERR, "create surface failed with 0x%x\n", ddrval);
292 }
293 return 1;
294 }
284 g_lpddsBack = g_lpddsOverlay; 295 g_lpddsBack = g_lpddsOverlay;
285 return 0; 296 return 0;
286 } 297 }
287 298
288 static uint32_t Directx_CreateBackpuffer(void) 299 static uint32_t Directx_CreateBackpuffer(void)
289 { 300 {
290 DDSURFACEDESC2 ddsd; 301 DDSURFACEDESC2 ddsd;
291 //cleanup 302 //cleanup
292 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack); 303 if (g_lpddsBack)
293 g_lpddsBack=NULL; 304 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
294 ZeroMemory(&ddsd, sizeof(ddsd)); 305 g_lpddsBack = NULL;
306 ZeroMemory(&ddsd, sizeof(ddsd));
295 ddsd.dwSize = sizeof(ddsd); 307 ddsd.dwSize = sizeof(ddsd);
296 ddsd.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; 308 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
297 ddsd.dwFlags= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; 309 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
298 ddsd.dwWidth=image_width; 310 ddsd.dwWidth = image_width;
299 ddsd.dwHeight=image_height; 311 ddsd.dwHeight = image_height;
300 if(g_lpdd->lpVtbl->CreateSurface( g_lpdd, &ddsd, &g_lpddsBack, 0 ) != DD_OK ) 312 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsBack, 0) != DD_OK) {
301 { 313 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't create backpuffer\n");
302 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create backpuffer\n"); 314 return 1;
303 return 1; 315 }
304 } 316 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>backbuffer created\n");
305 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>backbuffer created\n"); 317 return 0;
306 return 0;
307 } 318 }
308 319
309 static void uninit(void) 320 static void uninit(void)
310 { 321 {
311 if (g_cc != NULL) 322 if (g_cc != NULL) {
312 { 323 g_cc->lpVtbl->Release(g_cc);
313 g_cc->lpVtbl->Release(g_cc); 324 }
314 } 325 g_cc = NULL;
315 g_cc=NULL; 326 if (g_lpddclipper != NULL)
316 if (g_lpddclipper != NULL) g_lpddclipper->lpVtbl->Release(g_lpddclipper); 327 g_lpddclipper->lpVtbl->Release(g_lpddclipper);
317 g_lpddclipper = NULL; 328 g_lpddclipper = NULL;
318 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper released\n"); 329 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>clipper released\n");
319 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack); 330 if (g_lpddsBack != NULL)
320 g_lpddsBack = NULL; 331 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
321 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>back surface released\n"); 332 g_lpddsBack = NULL;
322 if(vo_doublebuffering && !nooverlay) 333 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>back surface released\n");
323 { 334 if (vo_doublebuffering && !nooverlay) {
324 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay); 335 if (g_lpddsOverlay != NULL)
336 g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
325 g_lpddsOverlay = NULL; 337 g_lpddsOverlay = NULL;
326 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surface released\n"); 338 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>overlay surface released\n");
327 } 339 }
328 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); 340 if (g_lpddsPrimary != NULL)
341 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
329 g_lpddsPrimary = NULL; 342 g_lpddsPrimary = NULL;
330 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary released\n"); 343 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>primary released\n");
331 if (colorbrush) DeleteObject(colorbrush); 344 if (colorbrush)
332 colorbrush = NULL; 345 DeleteObject(colorbrush);
333 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>GDI resources deleted\n"); 346 colorbrush = NULL;
334 if (g_lpdd != NULL){ 347 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>GDI resources deleted\n");
335 if(vidmode)g_lpdd->lpVtbl->RestoreDisplayMode(g_lpdd); 348 if (g_lpdd != NULL) {
336 g_lpdd->lpVtbl->Release(g_lpdd); 349 if (vidmode)
337 } 350 g_lpdd->lpVtbl->RestoreDisplayMode(g_lpdd);
338 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>directdrawobject released\n"); 351 g_lpdd->lpVtbl->Release(g_lpdd);
339 FreeLibrary( hddraw_dll); 352 }
340 hddraw_dll= NULL; 353 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>directdrawobject released\n");
341 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>ddraw.dll freed\n"); 354 FreeLibrary(hddraw_dll);
342 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>uninitialized\n"); 355 hddraw_dll = NULL;
343 vo_w32_uninit(); 356 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>ddraw.dll freed\n");
344 } 357 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>uninitialized\n");
345 358 vo_w32_uninit();
346 static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) 359 }
360
361 static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
347 { 362 {
348 if (!lpGUID) 363 if (!lpGUID)
349 lpDriverDescription = "Primary Display Adapter"; 364 lpDriverDescription = "Primary Display Adapter";
350 mp_msg(MSGT_VO, MSGL_INFO ,"<vo_directx> adapter %d: %s", adapter_count, lpDriverDescription); 365 mp_msg(MSGT_VO, MSGL_INFO, "<vo_directx> adapter %d: %s", adapter_count, lpDriverDescription);
351 366
352 if(adapter_count == vo_adapter_num){ 367 if (adapter_count == vo_adapter_num) {
353 if (!lpGUID) 368 if (!lpGUID)
354 selected_guid_ptr = NULL; 369 selected_guid_ptr = NULL;
355 else 370 else {
356 { 371 selected_guid = *lpGUID;
357 selected_guid = *lpGUID;
358 selected_guid_ptr = &selected_guid; 372 selected_guid_ptr = &selected_guid;
359 } 373 }
360 374
361 mp_msg(MSGT_VO, MSGL_INFO ,"\t\t<--"); 375 mp_msg(MSGT_VO, MSGL_INFO, "\t\t<--");
362 } 376 }
363 mp_msg(MSGT_VO, MSGL_INFO ,"\n"); 377 mp_msg(MSGT_VO, MSGL_INFO, "\n");
364 378
365 adapter_count++; 379 adapter_count++;
366 380
367 return 1; // list all adapters 381 return 1; // list all adapters
368 } 382 }
369 383
370 static uint32_t Directx_InitDirectDraw(void) 384 static uint32_t Directx_InitDirectDraw(void)
371 { 385 {
372 HRESULT (WINAPI *OurDirectDrawCreateEx)(GUID *,LPVOID *, REFIID,IUnknown FAR *); 386 HRESULT (WINAPI *OurDirectDrawCreateEx)(GUID *, LPVOID *, REFIID, IUnknown FAR *);
373 DDSURFACEDESC2 ddsd; 387 DDSURFACEDESC2 ddsd;
374 LPDIRECTDRAWENUMERATEEX OurDirectDrawEnumerateEx; 388 LPDIRECTDRAWENUMERATEEX OurDirectDrawEnumerateEx;
375 389
376 adapter_count = 0; 390 adapter_count = 0;
377 391
378 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>Initing DirectDraw\n" ); 392 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Initing DirectDraw\n");
379 393
380 //load direct draw DLL: based on videolans code 394 //load direct draw DLL: based on videolans code
381 hddraw_dll = LoadLibrary("DDRAW.DLL"); 395 hddraw_dll = LoadLibrary("DDRAW.DLL");
382 if( hddraw_dll == NULL ) 396 if (hddraw_dll == NULL) {
383 { 397 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>failed loading ddraw.dll\n");
384 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed loading ddraw.dll\n" ); 398 return 1;
385 return 1; 399 }
386 } 400
387 401 if (vo_adapter_num) { //display other than default
388 if(vo_adapter_num){ //display other than default 402 OurDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX)GetProcAddress(hddraw_dll, "DirectDrawEnumerateExA");
389 OurDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(hddraw_dll,"DirectDrawEnumerateExA"); 403 if (!OurDirectDrawEnumerateEx) {
390 if (!OurDirectDrawEnumerateEx){ 404 FreeLibrary(hddraw_dll);
391 FreeLibrary( hddraw_dll );
392 hddraw_dll = NULL; 405 hddraw_dll = NULL;
393 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawEnumerateEx\n"); 406 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawEnumerateEx\n");
394 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>no directx 7 or higher installed\n"); 407 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>no directx 7 or higher installed\n");
395 return 1; 408 return 1;
396 } 409 }
397 410
398 // enumerate all display devices attached to the desktop 411 // enumerate all display devices attached to the desktop
399 OurDirectDrawEnumerateEx(EnumCallbackEx, NULL, DDENUM_ATTACHEDSECONDARYDEVICES ); 412 OurDirectDrawEnumerateEx(EnumCallbackEx, NULL, DDENUM_ATTACHEDSECONDARYDEVICES);
400 413
401 if(vo_adapter_num >= adapter_count) 414 if (vo_adapter_num >= adapter_count)
402 mp_msg(MSGT_VO, MSGL_ERR,"Selected adapter (%d) doesn't exist: Default Display Adapter selected\n",vo_adapter_num); 415 mp_msg(MSGT_VO, MSGL_ERR, "Selected adapter (%d) doesn't exist: Default Display Adapter selected\n", vo_adapter_num);
403 } 416 }
404 417
405 OurDirectDrawCreateEx = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreateEx"); 418 OurDirectDrawCreateEx = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreateEx");
406 if ( OurDirectDrawCreateEx == NULL ) 419 if (OurDirectDrawCreateEx == NULL) {
407 { 420 FreeLibrary(hddraw_dll);
408 FreeLibrary( hddraw_dll );
409 hddraw_dll = NULL;
410 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawCreateEx\n");
411 return 1;
412 }
413
414 // initialize DirectDraw and create directx v7 object
415 if (OurDirectDrawCreateEx(selected_guid_ptr, (VOID**)&g_lpdd, &IID_IDirectDraw7, NULL ) != DD_OK )
416 {
417 FreeLibrary( hddraw_dll );
418 hddraw_dll = NULL; 421 hddraw_dll = NULL;
419 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't initialize ddraw\n"); 422 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawCreateEx\n");
420 return 1; 423 return 1;
421 } 424 }
422 425
423 //get current screen siz for selected monitor ... 426 // initialize DirectDraw and create directx v7 object
424 ddsd.dwSize=sizeof(ddsd); 427 if (OurDirectDrawCreateEx(selected_guid_ptr, (VOID **)&g_lpdd, &IID_IDirectDraw7, NULL) != DD_OK) {
425 ddsd.dwFlags=DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT; 428 FreeLibrary(hddraw_dll);
426 g_lpdd->lpVtbl->GetDisplayMode(g_lpdd, &ddsd); 429 hddraw_dll = NULL;
427 if(vo_screenwidth && vo_screenheight) 430 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't initialize ddraw\n");
428 { 431 return 1;
429 vm_height=vo_screenheight; 432 }
430 vm_width=vo_screenwidth; 433
431 } 434 //get current screen siz for selected monitor ...
435 ddsd.dwSize = sizeof(ddsd);
436 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
437 g_lpdd->lpVtbl->GetDisplayMode(g_lpdd, &ddsd);
438 if (vo_screenwidth && vo_screenheight) {
439 vm_height = vo_screenheight;
440 vm_width = vo_screenwidth;
441 } else {
442 vm_height = ddsd.dwHeight;
443 vm_width = ddsd.dwWidth;
444 }
445
446 if (vo_dbpp)
447 vm_bpp = vo_dbpp;
432 else 448 else
433 { 449 vm_bpp = ddsd.ddpfPixelFormat.dwRGBBitCount;
434 vm_height=ddsd.dwHeight; 450
435 vm_width=ddsd.dwWidth; 451 if (vidmode) {
436 } 452 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, vo_w32_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) != DD_OK) {
437 453 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode\n");
438
439 if(vo_dbpp)vm_bpp=vo_dbpp;
440 else vm_bpp=ddsd.ddpfPixelFormat.dwRGBBitCount;
441
442 if(vidmode){
443 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, vo_w32_window, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK)
444 {
445 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode\n");
446 return 1; 454 return 1;
447 } 455 }
448 /*SetDisplayMode(ddobject,width,height,bpp,refreshrate,aditionalflags)*/ 456 /*SetDisplayMode(ddobject,width,height,bpp,refreshrate,aditionalflags)*/
449 if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width, vm_height, vm_bpp,0,0) != DD_OK) 457 if (g_lpdd->lpVtbl->SetDisplayMode(g_lpdd, vm_width, vm_height, vm_bpp, 0, 0) != DD_OK) {
450 { 458 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't set displaymode\n");
451 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n"); 459 return 1;
452 return 1; 460 }
453 } 461 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>Initialized adapter %i for %i x %i @ %i \n", vo_adapter_num, vm_width, vm_height, vm_bpp);
454 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>Initialized adapter %i for %i x %i @ %i \n",vo_adapter_num,vm_width,vm_height,vm_bpp); 462 return 0;
455 return 0; 463 }
456 } 464 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, vo_w32_window, DDSCL_NORMAL) != DD_OK) { // or DDSCL_SETFOCUSWINDOW
457 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, vo_w32_window, DDSCL_NORMAL) != DD_OK) // or DDSCL_SETFOCUSWINDOW 465 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n");
458 { 466 return 1;
459 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n"); 467 }
460 return 1; 468 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>DirectDraw Initialized\n");
461 } 469 return 0;
462 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>DirectDraw Initialized\n");
463 return 0;
464 } 470 }
465 471
466 static uint32_t Directx_ManageDisplay(void) 472 static uint32_t Directx_ManageDisplay(void)
467 { 473 {
468 HRESULT ddrval; 474 HRESULT ddrval;
469 DDCAPS capsDrv; 475 DDCAPS capsDrv;
470 DDOVERLAYFX ovfx; 476 DDOVERLAYFX ovfx;
471 DWORD dwUpdateFlags=0; 477 DWORD dwUpdateFlags = 0;
472 int width,height; 478 int width, height;
473 479
474 rd.left = vo_dx - xinerama_x; 480 rd.left = vo_dx - xinerama_x;
475 rd.top = vo_dy - xinerama_y; 481 rd.top = vo_dy - xinerama_y;
476 width = vo_dwidth; 482 width = vo_dwidth;
477 height = vo_dheight; 483 height = vo_dheight;
478 484
479 aspect(&width, &height, A_WINZOOM); 485 aspect(&width, &height, A_WINZOOM);
480 panscan_calc_windowed(); 486 panscan_calc_windowed();
481 width += vo_panscan_x; 487 width += vo_panscan_x;
482 height += vo_panscan_y; 488 height += vo_panscan_y;
483 width = FFMIN(width, vo_screenwidth); 489 width = FFMIN(width, vo_screenwidth);
484 height = FFMIN(height, vo_screenheight); 490 height = FFMIN(height, vo_screenheight);
485 rd.left += (vo_dwidth - width ) / 2; 491 rd.left += (vo_dwidth - width) / 2;
486 rd.top += (vo_dheight - height) / 2; 492 rd.top += (vo_dheight - height) / 2;
487 493
488 rd.right=rd.left+width; 494 rd.right = rd.left + width;
489 rd.bottom=rd.top+height; 495 rd.bottom = rd.top + height;
490 496
491 /*ok, let's workaround some overlay limitations*/ 497 /*ok, let's workaround some overlay limitations*/
492 if(!nooverlay) 498 if (!nooverlay) {
493 { 499 uint32_t uStretchFactor1000; //minimum stretch
494 uint32_t uStretchFactor1000; //minimum stretch 500 uint32_t xstretch1000, ystretch1000;
495 uint32_t xstretch1000,ystretch1000;
496 501
497 if (!width || !height) { 502 if (!width || !height) {
498 // window is minimized, so we should hide the overlay in case 503 // window is minimized, so we should hide the overlay in case
499 // colorkeying is not used or working. 504 // colorkeying is not used or working.
500 // In addition trying to set width/height to 0 would crash 505 // In addition trying to set width/height to 0 would crash
501 g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); 506 g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
502 return 0; 507 return 0;
503 } 508 }
504 509
505 /*get driver capabilities*/ 510 /*get driver capabilities*/
506 ZeroMemory(&capsDrv, sizeof(capsDrv)); 511 ZeroMemory(&capsDrv, sizeof(capsDrv));
507 capsDrv.dwSize = sizeof(capsDrv); 512 capsDrv.dwSize = sizeof(capsDrv);
508 if(g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL) != DD_OK)return 1; 513 if (g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL) != DD_OK)
509 /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */ 514 return 1;
510 uStretchFactor1000 = capsDrv.dwMinOverlayStretch>1000 ? capsDrv.dwMinOverlayStretch : 1000; 515 /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */
511 rd.right = ((width+rd.left)*uStretchFactor1000+999)/1000; 516 uStretchFactor1000 = capsDrv.dwMinOverlayStretch > 1000 ? capsDrv.dwMinOverlayStretch : 1000;
512 rd.bottom = (height+rd.top)*uStretchFactor1000/1000; 517 rd.right = ((width + rd.left) * uStretchFactor1000 + 999) / 1000;
518 rd.bottom = (height + rd.top) * uStretchFactor1000 / 1000;
513 /*calculate xstretch1000 and ystretch1000*/ 519 /*calculate xstretch1000 and ystretch1000*/
514 xstretch1000 = ((rd.right - rd.left)* 1000)/image_width ; 520 xstretch1000 = ((rd.right - rd.left) * 1000) / image_width;
515 ystretch1000 = ((rd.bottom - rd.top)* 1000)/image_height; 521 ystretch1000 = ((rd.bottom - rd.top) * 1000) / image_height;
516 rs.left=0; 522 rs.left = 0;
517 rs.right=image_width; 523 rs.right = image_width;
518 rs.top=0; 524 rs.top = 0;
519 rs.bottom=image_height; 525 rs.bottom = image_height;
520 if(rd.left < 0)rs.left=(-rd.left*1000)/xstretch1000; 526 if (rd.left < 0)
521 if(rd.top < 0)rs.top=(-rd.top*1000)/ystretch1000; 527 rs.left = (-rd.left * 1000) / xstretch1000;
522 if(rd.right > vo_screenwidth)rs.right=((vo_screenwidth-rd.left)*1000)/xstretch1000; 528 if (rd.top < 0)
523 if(rd.bottom > vo_screenheight)rs.bottom=((vo_screenheight-rd.top)*1000)/ystretch1000; 529 rs.top = (-rd.top * 1000) / ystretch1000;
524 /*do not allow to zoom or shrink if hardware isn't able to do so*/ 530 if (rd.right > vo_screenwidth)
525 if((width < image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX)) 531 rs.right = ((vo_screenwidth - rd.left) * 1000) / xstretch1000;
526 { 532 if (rd.bottom > vo_screenheight)
527 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n"); 533 rs.bottom = ((vo_screenheight - rd.top) * 1000) / ystretch1000;
528 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink x\n"); 534 /*do not allow to zoom or shrink if hardware isn't able to do so*/
529 rd.right=rd.left+image_width; 535 if ((width < image_width) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX)) {
530 } 536 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)
531 else if((width > image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX)) 537 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can only shrinkN\n");
532 { 538 else
533 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n"); 539 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can't shrink x\n");
534 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch x\n"); 540 rd.right = rd.left + image_width;
535 rd.right = rd.left+image_width; 541 } else if ((width > image_width) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX)) {
536 } 542 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)
537 if((height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY)) 543 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can only stretchN\n");
538 { 544 else
539 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n"); 545 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can't stretch x\n");
540 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink y\n"); 546 rd.right = rd.left + image_width;
541 rd.bottom = rd.top + image_height; 547 }
542 } 548 if ((height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY)) {
543 else if((height > image_height ) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY)) 549 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)
544 { 550 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can only shrinkN\n");
545 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n"); 551 else
546 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch y\n"); 552 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can't shrink y\n");
547 rd.bottom = rd.top + image_height; 553 rd.bottom = rd.top + image_height;
548 } 554 } else if ((height > image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY)) {
549 /*the last thing to check are alignment restrictions 555 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)
550 these expressions (x & -y) just do alignment by dropping low order bits... 556 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can only stretchN\n");
551 so to round up, we add first, then truncate*/ 557 else
552 if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc) 558 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can't stretch y\n");
553 rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & -(signed)(capsDrv.dwAlignBoundarySrc); 559 rd.bottom = rd.top + image_height;
554 if((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc) 560 }
555 rs.right = rs.left + ((rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & -(signed) (capsDrv.dwAlignSizeSrc)); 561 /*the last thing to check are alignment restrictions
556 if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest) 562 * these expressions (x & -y) just do alignment by dropping low order bits...
557 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest); 563 * so to round up, we add first, then truncate*/
558 if((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest) 564 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc)
559 rd.right = rd.left + ((rd.right - rd.left) & -(signed) (capsDrv.dwAlignSizeDest)); 565 rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & - (signed)(capsDrv.dwAlignBoundarySrc);
560 /*create an overlay FX structure to specify a destination color key*/ 566 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc)
561 ZeroMemory(&ovfx, sizeof(ovfx)); 567 rs.right = rs.left + ((rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & - (signed)(capsDrv.dwAlignSizeSrc));
568 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest)
569 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & - (signed)(capsDrv.dwAlignBoundaryDest);
570 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest)
571 rd.right = rd.left + ((rd.right - rd.left) & - (signed)(capsDrv.dwAlignSizeDest));
572 /*create an overlay FX structure to specify a destination color key*/
573 ZeroMemory(&ovfx, sizeof(ovfx));
562 ovfx.dwSize = sizeof(ovfx); 574 ovfx.dwSize = sizeof(ovfx);
563 if(vo_fs||vidmode) 575 if (vo_fs || vidmode) {
564 { 576 ovfx.dckDestColorkey.dwColorSpaceLowValue = 0;
565 ovfx.dckDestColorkey.dwColorSpaceLowValue = 0;
566 ovfx.dckDestColorkey.dwColorSpaceHighValue = 0; 577 ovfx.dckDestColorkey.dwColorSpaceHighValue = 0;
567 } 578 } else {
568 else 579 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey;
569 {
570 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey;
571 ovfx.dckDestColorkey.dwColorSpaceHighValue = destcolorkey; 580 ovfx.dckDestColorkey.dwColorSpaceHighValue = destcolorkey;
572 } 581 }
573 // set the flags we'll send to UpdateOverlay //DDOVER_AUTOFLIP|DDOVERFX_MIRRORLEFTRIGHT|DDOVERFX_MIRRORUPDOWN could be useful?; 582 // set the flags we'll send to UpdateOverlay //DDOVER_AUTOFLIP|DDOVERFX_MIRRORLEFTRIGHT|DDOVERFX_MIRRORUPDOWN could be useful?;
574 dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX; 583 dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX;
575 /*if hardware can't do colorkeying set the window on top*/ 584 /*if hardware can't do colorkeying set the window on top*/
576 if(capsDrv.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY) dwUpdateFlags |= DDOVER_KEYDESTOVERRIDE; 585 if (capsDrv.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY)
577 else if (!tmp_image) vo_ontop = 1; 586 dwUpdateFlags |= DDOVER_KEYDESTOVERRIDE;
578 } 587 else if (!tmp_image)
579 else 588 vo_ontop = 1;
580 { 589 } else {
581 g_lpddclipper->lpVtbl->SetHWnd(g_lpddclipper, 0, vo_w32_window); 590 g_lpddclipper->lpVtbl->SetHWnd(g_lpddclipper, 0, vo_w32_window);
582 } 591 }
583 592
584 /*make sure the overlay is inside the screen*/ 593 /*make sure the overlay is inside the screen*/
585 if(rd.left<0)rd.left=0; 594 if (rd.left < 0)
586 if(rd.right>vo_screenwidth)rd.right=vo_screenwidth; 595 rd.left = 0;
587 if(rd.top<0)rd.top=0; 596 if (rd.right > vo_screenwidth)
588 if(rd.bottom>vo_screenheight)rd.bottom=vo_screenheight; 597 rd.right = vo_screenwidth;
589 598 if (rd.top < 0)
590 /*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/ 599 rd.top = 0;
591 if(nooverlay)return 0; 600 if (rd.bottom > vo_screenheight)
601 rd.bottom = vo_screenheight;
602
603 /*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/
604 if (nooverlay)
605 return 0;
592 606
593 // printf("overlay: %i %i %ix%i\n",rd.left,rd.top,rd.right - rd.left,rd.bottom - rd.top); 607 // printf("overlay: %i %i %ix%i\n",rd.left,rd.top,rd.right - rd.left,rd.bottom - rd.top);
594 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx); 608 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, &rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
595 if(FAILED(ddrval)) 609 if (FAILED(ddrval)) {
596 {
597 // one cause might be the driver lied about minimum stretch 610 // one cause might be the driver lied about minimum stretch
598 // we should try upping the destination size a bit, or 611 // we should try upping the destination size a bit, or
599 // perhaps shrinking the source size 612 // perhaps shrinking the source size
600 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>UpdateOverlay failed\n" ); 613 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>UpdateOverlay failed\n");
601 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 ); 614 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);
602 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>"); 615 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>");
603 switch (ddrval) 616 switch (ddrval) {
604 { 617 case DDERR_NOSTRETCHHW:
605 case DDERR_NOSTRETCHHW: 618 { mp_msg(MSGT_VO, MSGL_ERR, "hardware can't stretch: try to size the window back\n");
606 {mp_msg(MSGT_VO, MSGL_ERR ,"hardware can't stretch: try to size the window back\n");break;} 619 break;
607 case DDERR_INVALIDRECT: 620 }
608 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid rectangle\n");break;} 621 case DDERR_INVALIDRECT:
609 case DDERR_INVALIDPARAMS: 622 { mp_msg(MSGT_VO, MSGL_ERR, "invalid rectangle\n");
610 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid parameters\n");break;} 623 break;
611 case DDERR_HEIGHTALIGN: 624 }
612 {mp_msg(MSGT_VO, MSGL_ERR ,"height align\n");break;} 625 case DDERR_INVALIDPARAMS:
613 case DDERR_XALIGN: 626 { mp_msg(MSGT_VO, MSGL_ERR, "invalid parameters\n");
614 {mp_msg(MSGT_VO, MSGL_ERR ,"x align\n");break;} 627 break;
615 case DDERR_UNSUPPORTED: 628 }
616 {mp_msg(MSGT_VO, MSGL_ERR ,"unsupported\n");break;} 629 case DDERR_HEIGHTALIGN:
617 case DDERR_INVALIDSURFACETYPE: 630 { mp_msg(MSGT_VO, MSGL_ERR, "height align\n");
618 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid surfacetype\n");break;} 631 break;
619 case DDERR_INVALIDOBJECT: 632 }
620 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid object\n");break;} 633 case DDERR_XALIGN:
621 case DDERR_SURFACELOST: 634 { mp_msg(MSGT_VO, MSGL_ERR, "x align\n");
622 { 635 break;
623 mp_msg(MSGT_VO, MSGL_ERR ,"surfaces lost\n"); 636 }
624 g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); //restore and try again 637 case DDERR_UNSUPPORTED:
625 g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary ); 638 { mp_msg(MSGT_VO, MSGL_ERR, "unsupported\n");
626 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx); 639 break;
627 if(ddrval !=DD_OK)mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>UpdateOverlay failed again\n" ); 640 }
628 break; 641 case DDERR_INVALIDSURFACETYPE:
629 } 642 { mp_msg(MSGT_VO, MSGL_ERR, "invalid surfacetype\n");
630 default: 643 break;
631 mp_msg(MSGT_VO, MSGL_ERR ," 0x%x\n",ddrval); 644 }
632 } 645 case DDERR_INVALIDOBJECT:
633 /*ok we can't do anything about it -> hide overlay*/ 646 { mp_msg(MSGT_VO, MSGL_ERR, "invalid object\n");
634 if(ddrval != DD_OK) 647 break;
635 { 648 }
636 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); 649 case DDERR_SURFACELOST:
650 {
651 mp_msg(MSGT_VO, MSGL_ERR, "surfaces lost\n");
652 g_lpddsOverlay->lpVtbl->Restore(g_lpddsOverlay); //restore and try again
653 g_lpddsPrimary->lpVtbl->Restore(g_lpddsPrimary);
654 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, &rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
655 if (ddrval != DD_OK)
656 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>UpdateOverlay failed again\n");
657 break;
658 }
659 default:
660 mp_msg(MSGT_VO, MSGL_ERR, " 0x%x\n", ddrval);
661 }
662 /*ok we can't do anything about it -> hide overlay*/
663 if (ddrval != DD_OK) {
664 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
637 return 1; 665 return 1;
638 } 666 }
639 } 667 }
640 return 0; 668 return 0;
641 } 669 }
642 670
643 static void check_events(void) 671 static void check_events(void)
644 { 672 {
655 } 683 }
656 684
657 //find out supported overlay pixelformats 685 //find out supported overlay pixelformats
658 static uint32_t Directx_CheckOverlayPixelformats(void) 686 static uint32_t Directx_CheckOverlayPixelformats(void)
659 { 687 {
660 DDCAPS capsDrv; 688 DDCAPS capsDrv;
661 HRESULT ddrval; 689 HRESULT ddrval;
662 DDSURFACEDESC2 ddsdOverlay; 690 DDSURFACEDESC2 ddsdOverlay;
663 uint32_t i; 691 uint32_t i;
664 uint32_t formatcount = 0; 692 uint32_t formatcount = 0;
665 //get driver caps to determine overlay support 693 //get driver caps to determine overlay support
666 ZeroMemory(&capsDrv, sizeof(capsDrv)); 694 ZeroMemory(&capsDrv, sizeof(capsDrv));
667 capsDrv.dwSize = sizeof(capsDrv); 695 capsDrv.dwSize = sizeof(capsDrv);
668 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL); 696 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL);
669 if (FAILED(ddrval)) 697 if (FAILED(ddrval)) {
670 { 698 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>failed getting ddrawcaps\n");
671 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>failed getting ddrawcaps\n"); 699 return 1;
672 return 1; 700 }
673 } 701 if (!(capsDrv.dwCaps & DDCAPS_OVERLAY)) {
674 if (!(capsDrv.dwCaps & DDCAPS_OVERLAY)) 702 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>Your card doesn't support overlay\n");
675 { 703 return 1;
676 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Your card doesn't support overlay\n"); 704 }
677 return 1; 705 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>testing supported overlay pixelformats\n");
678 }
679 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>testing supported overlay pixelformats\n");
680 //it is not possible to query for pixel formats supported by the 706 //it is not possible to query for pixel formats supported by the
681 //overlay hardware: try out various formats till one works 707 //overlay hardware: try out various formats till one works
682 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay)); 708 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
683 ddsdOverlay.dwSize = sizeof(ddsdOverlay); 709 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
684 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; 710 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
685 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT; 711 ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
686 ddsdOverlay.dwWidth=300; 712 ddsdOverlay.dwWidth = 300;
687 ddsdOverlay.dwHeight=280; 713 ddsdOverlay.dwHeight = 280;
688 ddsdOverlay.dwBackBufferCount=0; 714 ddsdOverlay.dwBackBufferCount = 0;
689 //try to create an overlay surface using one of the pixel formats in our global list 715 //try to create an overlay surface using one of the pixel formats in our global list
690 i=0; 716 i = 0;
691 do 717 do {
692 { 718 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay;
693 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay; 719 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL);
694 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL); 720 if (ddrval == DD_OK) {
695 if (ddrval == DD_OK) 721 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><FORMAT OVERLAY>%i %s supported\n", i, g_ddpf[i].img_format_name);
696 { 722 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP;
697 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s supported\n",i,g_ddpf[i].img_format_name); 723 formatcount++;
698 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP; 724 } else
699 formatcount++;} 725 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><FORMAT OVERLAY>%i %s not supported\n", i, g_ddpf[i].img_format_name);
700 else mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s not supported\n",i,g_ddpf[i].img_format_name); 726 if (g_lpddsOverlay != NULL) {
701 if (g_lpddsOverlay != NULL) {g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);g_lpddsOverlay = NULL;} 727 g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
702 } while( ++i < NUM_FORMATS ); 728 g_lpddsOverlay = NULL;
703 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>Your card supports %i of %i overlayformats\n",formatcount, NUM_FORMATS); 729 }
704 if (formatcount == 0) 730 } while (++i < NUM_FORMATS);
705 { 731 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>Your card supports %i of %i overlayformats\n", formatcount, NUM_FORMATS);
706 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n"); 732 if (formatcount == 0) {
707 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>This can have the following reasons:\n"); 733 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n");
708 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you are already using an overlay with another app\n"); 734 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>This can have the following reasons:\n");
709 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you don't have enough videomemory\n"); 735 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>- you are already using an overlay with another app\n");
710 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n"); 736 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>- you don't have enough videomemory\n");
711 return 1; 737 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n");
712 } 738 return 1;
713 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 739 }
714 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 ;) 740 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORLEFTRIGHT)
715 return 0; 741 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>can mirror left right\n"); //I don't have hardware which
742 if (capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORUPDOWN)
743 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>can mirror up down\n"); //supports those send me one and I'll implement ;)
744 return 0;
716 } 745 }
717 746
718 //find out the Pixelformat of the Primary Surface 747 //find out the Pixelformat of the Primary Surface
719 static uint32_t Directx_CheckPrimaryPixelformat(void) 748 static uint32_t Directx_CheckPrimaryPixelformat(void)
720 { 749 {
721 uint32_t i=0; 750 uint32_t i = 0;
722 uint32_t formatcount = 0; 751 uint32_t formatcount = 0;
723 DDPIXELFORMAT ddpf; 752 DDPIXELFORMAT ddpf;
724 DDSURFACEDESC2 ddsd; 753 DDSURFACEDESC2 ddsd;
725 HDC hdc; 754 HDC hdc;
726 HRESULT hres; 755 HRESULT hres;
727 COLORREF rgbT=RGB(0,0,0); 756 COLORREF rgbT = RGB(0, 0, 0);
728 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>checking primary surface\n"); 757 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>checking primary surface\n");
729 memset( &ddpf, 0, sizeof( DDPIXELFORMAT )); 758 memset(&ddpf, 0, sizeof(DDPIXELFORMAT));
730 ddpf.dwSize = sizeof( DDPIXELFORMAT ); 759 ddpf.dwSize = sizeof(DDPIXELFORMAT);
731 //we have to create a primary surface first 760 //we have to create a primary surface first
732 if(Directx_CreatePrimarySurface()!=0)return 1; 761 if (Directx_CreatePrimarySurface() != 0)
733 if(g_lpddsPrimary->lpVtbl->GetPixelFormat( g_lpddsPrimary, &ddpf ) != DD_OK ) 762 return 1;
734 { 763 if (g_lpddsPrimary->lpVtbl->GetPixelFormat(g_lpddsPrimary, &ddpf) != DD_OK) {
735 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>can't get pixelformat\n"); 764 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't get pixelformat\n");
736 return 1; 765 return 1;
737 } 766 }
738 while ( i < NUM_FORMATS ) 767 while (i < NUM_FORMATS) {
739 { 768 if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount) {
740 if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount) 769 if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask) {
741 { 770 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><FORMAT PRIMARY>%i %s supported\n", i, g_ddpf[i].img_format_name);
742 if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask) 771 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED | VFCAP_OSD;
743 { 772 formatcount++;
744 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT PRIMARY>%i %s supported\n",i,g_ddpf[i].img_format_name); 773 primary_image_format = g_ddpf[i].img_format;
745 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD; 774 }
746 formatcount++; 775 }
747 primary_image_format=g_ddpf[i].img_format; 776 i++;
748 }
749 }
750 i++;
751 } 777 }
752 //get the colorkey for overlay mode 778 //get the colorkey for overlay mode
753 destcolorkey = CLR_INVALID; 779 destcolorkey = CLR_INVALID;
754 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK) 780 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary, &hdc) == DD_OK) {
755 {
756 rgbT = GetPixel(hdc, 0, 0); 781 rgbT = GetPixel(hdc, 0, 0);
757 SetPixel(hdc, 0, 0, windowcolor); 782 SetPixel(hdc, 0, 0, windowcolor);
758 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc); 783 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary, hdc);
759 } 784 }
760 // read back the converted color 785 // read back the converted color
761 ddsd.dwSize = sizeof(ddsd); 786 ddsd.dwSize = sizeof(ddsd);
762 while ((hres = g_lpddsPrimary->lpVtbl->Lock(g_lpddsPrimary,NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING) 787 while ((hres = g_lpddsPrimary->lpVtbl->Lock(g_lpddsPrimary, NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING)
763 ; 788 ;
764 if (hres == DD_OK) 789 if (hres == DD_OK) {
765 { 790 destcolorkey = *(DWORD *)ddsd.lpSurface;
766 destcolorkey = *(DWORD *) ddsd.lpSurface;
767 if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32) 791 if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
768 destcolorkey &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; 792 destcolorkey &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1;
769 g_lpddsPrimary->lpVtbl->Unlock(g_lpddsPrimary,NULL); 793 g_lpddsPrimary->lpVtbl->Unlock(g_lpddsPrimary, NULL);
770 } 794 }
771 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK) 795 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary, &hdc) == DD_OK) {
772 {
773 SetPixel(hdc, 0, 0, rgbT); 796 SetPixel(hdc, 0, 0, rgbT);
774 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc); 797 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary, hdc);
775 } 798 }
776 //release primary 799 //release primary
777 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); 800 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
778 g_lpddsPrimary = NULL; 801 g_lpddsPrimary = NULL;
779 if(formatcount==0) 802 if (formatcount == 0) {
780 { 803 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>Unknown Pixelformat\n");
781 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>Unknown Pixelformat\n"); 804 return 1;
782 return 1; 805 }
783 } 806 return 0;
784 return 0;
785 } 807 }
786 808
787 static int preinit(const char *arg) 809 static int preinit(const char *arg)
788 { 810 {
789 if(arg) 811 if (arg) {
790 { 812 if (strstr(arg, "noaccel")) {
791 if(strstr(arg,"noaccel")) 813 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>disabled overlay\n");
792 { 814 nooverlay = 1;
793 mp_msg(MSGT_VO,MSGL_V,"<vo_directx><INFO>disabled overlay\n"); 815 }
794 nooverlay = 1; 816 }
795 }
796 }
797 817
798 windowcolor = vo_colorkey; 818 windowcolor = vo_colorkey;
799 colorbrush = CreateSolidBrush(windowcolor); 819 colorbrush = CreateSolidBrush(windowcolor);
800 blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH); 820 blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
801 if (!vo_w32_init()) 821 if (!vo_w32_init())
802 return 1; 822 return 1;
803 if (!vo_w32_config(100, 100, VOFLAG_HIDDEN)) 823 if (!vo_w32_config(100, 100, VOFLAG_HIDDEN))
804 return 1; 824 return 1;
805 825
806 if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw 826 if (Directx_InitDirectDraw() != 0)
807 827 return 1; //init DirectDraw
808 if (Directx_CheckPrimaryPixelformat()!=0)return 1; 828
809 if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) //check for supported hardware 829 if (Directx_CheckPrimaryPixelformat() != 0)
810 { 830 return 1;
811 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n"); 831 if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) { //check for supported hardware
812 nooverlay = 0; 832 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>hardware supports overlay\n");
813 } 833 nooverlay = 0;
814 else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface 834 } else { //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface
815 { 835 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>using backpuffer\n");
816 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n"); 836 nooverlay = 1;
817 nooverlay = 1; 837 }
818 } 838 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>preinit succesfully finished\n");
819 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n"); 839 return 0;
820 return 0; 840 }
821 } 841
822 842 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
823 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) 843 {
824 { 844 uint8_t *s;
825 uint8_t *s;
826 uint8_t *d; 845 uint8_t *d;
827 uint32_t uvstride=dstride/2; 846 uint32_t uvstride = dstride / 2;
828 // copy Y 847 // copy Y
829 d=image+dstride*y+x; 848 d = image + dstride * y + x;
830 s=src[0]; 849 s = src[0];
831 mem2agpcpy_pic(d,s,w,h,dstride,stride[0]); 850 mem2agpcpy_pic(d, s, w, h, dstride, stride[0]);
832 851
833 w/=2;h/=2;x/=2;y/=2; 852 w /= 2;
834 853 h /= 2;
835 // copy U 854 x /= 2;
836 d=image+dstride*image_height + uvstride*y+x; 855 y /= 2;
837 if(image_format == IMGFMT_YV12)s=src[2]; 856
838 else s=src[1]; 857 // copy U
839 mem2agpcpy_pic(d,s,w,h,uvstride,stride[1]); 858 d = image + dstride * image_height + uvstride * y + x;
840 859 if (image_format == IMGFMT_YV12)
841 // copy V 860 s = src[2];
842 d=image+dstride*image_height +uvstride*(image_height/2) + uvstride*y+x; 861 else
843 if(image_format == IMGFMT_YV12)s=src[1]; 862 s = src[1];
844 else s=src[2]; 863 mem2agpcpy_pic(d, s, w, h, uvstride, stride[1]);
845 mem2agpcpy_pic(d,s,w,h,uvstride,stride[2]); 864
865 // copy V
866 d = image + dstride * image_height + uvstride * (image_height / 2) + uvstride * y + x;
867 if (image_format == IMGFMT_YV12)
868 s = src[1];
869 else
870 s = src[2];
871 mem2agpcpy_pic(d, s, w, h, uvstride, stride[2]);
846 return 0; 872 return 0;
847 } 873 }
848 874
849 static void flip_page(void) 875 static void flip_page(void)
850 { 876 {
851 HRESULT dxresult; 877 HRESULT dxresult;
852 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL); 878 g_lpddsBack->lpVtbl->Unlock(g_lpddsBack, NULL);
853 if (vo_doublebuffering) 879 if (vo_doublebuffering) {
854 { 880 // flip to the next image in the sequence
855 // flip to the next image in the sequence 881 dxresult = g_lpddsOverlay->lpVtbl->Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT);
856 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); 882 if (dxresult == DDERR_SURFACELOST) {
857 if(dxresult == DDERR_SURFACELOST) 883 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n");
858 { 884 g_lpddsBack->lpVtbl->Restore(g_lpddsBack);
859 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n"); 885 // restore overlay and primary before calling
860 g_lpddsBack->lpVtbl->Restore( g_lpddsBack ); 886 // Directx_ManageDisplay() to avoid error messages
861 // restore overlay and primary before calling 887 g_lpddsOverlay->lpVtbl->Restore(g_lpddsOverlay);
862 // Directx_ManageDisplay() to avoid error messages 888 g_lpddsPrimary->lpVtbl->Restore(g_lpddsPrimary);
863 g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); 889 // update overlay in case we return from screensaver
864 g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary ); 890 Directx_ManageDisplay();
865 // update overlay in case we return from screensaver 891 dxresult = g_lpddsOverlay->lpVtbl->Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT);
866 Directx_ManageDisplay(); 892 }
867 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); 893 if (dxresult != DD_OK)
868 } 894 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>can't flip page\n");
869 if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n"); 895 }
870 } 896 if (nooverlay) {
871 if(nooverlay) 897 DDBLTFX ddbltfx;
872 {
873 DDBLTFX ddbltfx;
874 // ask for the "NOTEARING" option 898 // ask for the "NOTEARING" option
875 memset( &ddbltfx, 0, sizeof(DDBLTFX) ); 899 memset(&ddbltfx, 0, sizeof(DDBLTFX));
876 ddbltfx.dwSize = sizeof(DDBLTFX); 900 ddbltfx.dwSize = sizeof(DDBLTFX);
877 ddbltfx.dwDDFX = DDBLTFX_NOTEARING; 901 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
878 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx); 902 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx);
879 } 903 }
880 if (g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL) == DD_OK) { 904 if (g_lpddsBack->lpVtbl->Lock(g_lpddsBack, NULL, &ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) == DD_OK) {
881 if(vo_directrendering && (dstride != ddsdsf.lPitch)){ 905 if (vo_directrendering && (dstride != ddsdsf.lPitch)) {
882 mp_msg(MSGT_VO,MSGL_WARN,"<vo_directx><WARN>stride changed !!!! disabling direct rendering\n"); 906 mp_msg(MSGT_VO, MSGL_WARN, "<vo_directx><WARN>stride changed !!!! disabling direct rendering\n");
883 vo_directrendering=0; 907 vo_directrendering = 0;
884 } 908 }
885 free(tmp_image); 909 free(tmp_image);
886 tmp_image = NULL; 910 tmp_image = NULL;
887 dstride = ddsdsf.lPitch; 911 dstride = ddsdsf.lPitch;
888 image = ddsdsf.lpSurface; 912 image = ddsdsf.lpSurface;
889 } else if (!tmp_image) { 913 } else if (!tmp_image) {
890 mp_msg(MSGT_VO, MSGL_WARN, "<vo_directx><WARN>Locking the surface failed, rendering to a hidden surface!\n"); 914 mp_msg(MSGT_VO, MSGL_WARN, "<vo_directx><WARN>Locking the surface failed, rendering to a hidden surface!\n");
891 tmp_image = image = calloc(1, image_height * dstride * 2); 915 tmp_image = image = calloc(1, image_height * dstride * 2);
892 } 916 }
893 } 917 }
894 918
895 static int draw_frame(uint8_t *src[]) 919 static int draw_frame(uint8_t *src[])
896 { 920 {
897 fast_memcpy( image, *src, dstride * image_height ); 921 fast_memcpy(image, *src, dstride * image_height);
898 return 0; 922 return 0;
899 } 923 }
900 924
901 static uint32_t get_image(mp_image_t *mpi) 925 static uint32_t get_image(mp_image_t *mpi)
902 { 926 {
903 if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;} 927 if (mpi->flags & MP_IMGFLAG_READABLE) {
904 if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;} 928 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><ERROR>slow video ram\n");
905 if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))) 929 return VO_FALSE;
906 { 930 }
907 if(mpi->flags&MP_IMGFLAG_PLANAR) 931 if (mpi->type == MP_IMGTYPE_STATIC) {
908 { 932 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><ERROR>not static\n");
909 if(image_format == IMGFMT_YV12) 933 return VO_FALSE;
910 { 934 }
911 mpi->planes[2]= image + dstride*image_height; 935 if ((mpi->width == dstride) || (mpi->flags & (MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_ACCEPT_WIDTH))) {
912 mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4; 936 if (mpi->flags & MP_IMGFLAG_PLANAR) {
913 mpi->stride[1]=mpi->stride[2]=dstride/2; 937 if (image_format == IMGFMT_YV12) {
914 } 938 mpi->planes[2] = image + dstride * image_height;
915 else if(image_format == IMGFMT_IYUV || image_format == IMGFMT_I420) 939 mpi->planes[1] = image + dstride * image_height + dstride * image_height / 4;
916 { 940 mpi->stride[1] = mpi->stride[2] = dstride / 2;
917 mpi->planes[1]= image + dstride*image_height; 941 } else if (image_format == IMGFMT_IYUV || image_format == IMGFMT_I420) {
918 mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4; 942 mpi->planes[1] = image + dstride * image_height;
919 mpi->stride[1]=mpi->stride[2]=dstride/2; 943 mpi->planes[2] = image + dstride * image_height + dstride * image_height / 4;
920 } 944 mpi->stride[1] = mpi->stride[2] = dstride / 2;
921 else if(image_format == IMGFMT_YVU9) 945 } else if (image_format == IMGFMT_YVU9) {
922 { 946 mpi->planes[2] = image + dstride * image_height;
923 mpi->planes[2] = image + dstride*image_height; 947 mpi->planes[1] = image + dstride * image_height + dstride * image_height / 16;
924 mpi->planes[1] = image + dstride*image_height+ dstride*image_height/16; 948 mpi->stride[1] = mpi->stride[2] = dstride / 4;
925 mpi->stride[1]=mpi->stride[2]=dstride/4; 949 }
926 } 950 }
927 } 951 mpi->planes[0] = image;
928 mpi->planes[0]=image; 952 mpi->stride[0] = dstride;
929 mpi->stride[0]=dstride; 953 mpi->width = image_width;
930 mpi->width=image_width; 954 mpi->height = image_height;
931 mpi->height=image_height; 955 mpi->flags |= MP_IMGFLAG_DIRECT;
932 mpi->flags|=MP_IMGFLAG_DIRECT;
933 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n"); 956 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n");
934 return VO_TRUE; 957 return VO_TRUE;
935 } 958 }
936 return VO_FALSE; 959 return VO_FALSE;
937 } 960 }
938 961
939 static uint32_t put_image(mp_image_t *mpi){ 962 static uint32_t put_image(mp_image_t *mpi)
940 963 {
941 uint8_t *d; 964 uint8_t *d;
942 uint8_t *s; 965 uint8_t *s;
943 uint32_t x = mpi->x; 966 uint32_t x = mpi->x;
944 uint32_t y = mpi->y; 967 uint32_t y = mpi->y;
945 uint32_t w = mpi->w; 968 uint32_t w = mpi->w;
946 uint32_t h = mpi->h; 969 uint32_t h = mpi->h;
947 970
948 if((mpi->flags&MP_IMGFLAG_DIRECT)||(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) 971 if ((mpi->flags & MP_IMGFLAG_DIRECT) || (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
949 { 972 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>put_image: nothing to do: drawslices\n");
950 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n"); 973 return VO_TRUE;
951 return VO_TRUE; 974 }
952 } 975
953 976 if (mpi->flags & MP_IMGFLAG_PLANAR) {
954 if (mpi->flags&MP_IMGFLAG_PLANAR) 977 if (image_format != IMGFMT_YVU9)
955 { 978 draw_slice(mpi->planes, mpi->stride, mpi->w, mpi->h, 0, 0);
956 979 else {
957 if(image_format!=IMGFMT_YVU9)draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0); 980 // copy Y
958 else 981 d = image + dstride * y + x;
959 { 982 s = mpi->planes[0];
960 // copy Y 983 mem2agpcpy_pic(d, s, w, h, dstride, mpi->stride[0]);
961 d=image+dstride*y+x; 984 w /= 4;
962 s=mpi->planes[0]; 985 h /= 4;
963 mem2agpcpy_pic(d,s,w,h,dstride,mpi->stride[0]); 986 x /= 4;
964 w/=4;h/=4;x/=4;y/=4; 987 y /= 4;
965 // copy V 988 // copy V
966 d=image+dstride*image_height + dstride*y/4+x; 989 d = image + dstride * image_height + dstride * y / 4 + x;
967 s=mpi->planes[2]; 990 s = mpi->planes[2];
968 mem2agpcpy_pic(d,s,w,h,dstride/4,mpi->stride[1]); 991 mem2agpcpy_pic(d, s, w, h, dstride / 4, mpi->stride[1]);
969 // copy U 992 // copy U
970 d=image+dstride*image_height + dstride*image_height/16 + dstride/4*y+x; 993 d = image + dstride * image_height + dstride * image_height / 16 + dstride / 4 * y + x;
971 s=mpi->planes[1]; 994 s = mpi->planes[1];
972 mem2agpcpy_pic(d,s,w,h,dstride/4,mpi->stride[2]); 995 mem2agpcpy_pic(d, s, w, h, dstride / 4, mpi->stride[2]);
973 } 996 }
974 } 997 } else { //packed
975 else //packed 998 mem2agpcpy_pic(image, mpi->planes[0], w * (mpi->bpp / 8), h, dstride, mpi->stride[0]);
976 { 999 }
977 mem2agpcpy_pic(image, mpi->planes[0], w * (mpi->bpp / 8), h, dstride, mpi->stride[0]); 1000 return VO_TRUE;
978 } 1001 }
979 return VO_TRUE; 1002
980 } 1003 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format)
981 1004 {
982 static int 1005 image_format = format;
983 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format) 1006 image_width = width;
984 { 1007 image_height = height;
985 image_format = format; 1008 if (format != primary_image_format)
986 image_width = width; 1009 nooverlay = 0;
987 image_height = height;
988 if(format != primary_image_format)nooverlay = 0;
989 1010
990 /*release all directx objects*/ 1011 /*release all directx objects*/
991 if (g_cc != NULL)g_cc->lpVtbl->Release(g_cc); 1012 if (g_cc != NULL)
992 g_cc=NULL; 1013 g_cc->lpVtbl->Release(g_cc);
993 if(g_lpddclipper)g_lpddclipper->lpVtbl->Release(g_lpddclipper); 1014 g_cc = NULL;
994 g_lpddclipper=NULL; 1015 if (g_lpddclipper)
995 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack); 1016 g_lpddclipper->lpVtbl->Release(g_lpddclipper);
1017 g_lpddclipper = NULL;
1018 if (g_lpddsBack != NULL)
1019 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
996 g_lpddsBack = NULL; 1020 g_lpddsBack = NULL;
997 if(vo_doublebuffering) 1021 if (vo_doublebuffering)
998 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay); 1022 if (g_lpddsOverlay != NULL)
1023 g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
999 g_lpddsOverlay = NULL; 1024 g_lpddsOverlay = NULL;
1000 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); 1025 if (g_lpddsPrimary != NULL)
1026 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
1001 g_lpddsPrimary = NULL; 1027 g_lpddsPrimary = NULL;
1002 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surfaces released\n"); 1028 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>overlay surfaces released\n");
1003 1029
1004 if (!vo_w32_config(d_width, d_height, options)) 1030 if (!vo_w32_config(d_width, d_height, options))
1005 return 1; 1031 return 1;
1006 1032
1007 if (WinID == -1) 1033 if (WinID == -1)
1008 SetWindowText(vo_w32_window,title); 1034 SetWindowText(vo_w32_window, title);
1009 1035
1010 1036 /*create the surfaces*/
1011 /*create the surfaces*/ 1037 if (Directx_CreatePrimarySurface())
1012 if(Directx_CreatePrimarySurface())return 1; 1038 return 1;
1013 1039
1014 //create palette for 256 color mode 1040 //create palette for 256 color mode
1015 if(image_format==IMGFMT_BGR8){ 1041 if (image_format == IMGFMT_BGR8) {
1016 LPDIRECTDRAWPALETTE ddpalette=NULL; 1042 LPDIRECTDRAWPALETTE ddpalette = NULL;
1017 LPPALETTEENTRY palette=calloc(256, sizeof(*palette)); 1043 LPPALETTEENTRY palette = calloc(256, sizeof(*palette));
1018 int i; 1044 int i;
1019 for(i=0; i<256; i++){ 1045 for (i = 0; i < 256; i++) {
1020 palette[i].peRed = ((i >> 5) & 0x07) * 255 / 7; 1046 palette[i].peRed = ((i >> 5) & 0x07) * 255 / 7;
1021 palette[i].peGreen = ((i >> 2) & 0x07) * 255 / 7; 1047 palette[i].peGreen = ((i >> 2) & 0x07) * 255 / 7;
1022 palette[i].peBlue = ((i >> 0) & 0x03) * 255 / 3; 1048 palette[i].peBlue = ((i >> 0) & 0x03) * 255 / 3;
1023 palette[i].peFlags = PC_NOCOLLAPSE; 1049 palette[i].peFlags = PC_NOCOLLAPSE;
1024 } 1050 }
1025 g_lpdd->lpVtbl->CreatePalette(g_lpdd,DDPCAPS_8BIT|DDPCAPS_INITIALIZE,palette,&ddpalette,NULL); 1051 g_lpdd->lpVtbl->CreatePalette(g_lpdd, DDPCAPS_8BIT | DDPCAPS_INITIALIZE, palette, &ddpalette, NULL);
1026 g_lpddsPrimary->lpVtbl->SetPalette(g_lpddsPrimary,ddpalette); 1052 g_lpddsPrimary->lpVtbl->SetPalette(g_lpddsPrimary, ddpalette);
1027 free(palette); 1053 free(palette);
1028 ddpalette->lpVtbl->Release(ddpalette); 1054 ddpalette->lpVtbl->Release(ddpalette);
1029 } 1055 }
1030 1056
1031 if (!nooverlay && Directx_CreateOverlay(image_format)) 1057 if (!nooverlay && Directx_CreateOverlay(image_format)) {
1032 { 1058 if (format == primary_image_format)
1033 if(format == primary_image_format)nooverlay=1; /*overlay creation failed*/ 1059 nooverlay = 1; /*overlay creation failed*/
1034 else { 1060 else {
1035 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't use overlay mode: please use -vo directx:noaccel\n"); 1061 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't use overlay mode: please use -vo directx:noaccel\n");
1036 return 1; 1062 return 1;
1037 } 1063 }
1038 } 1064 }
1039 if(nooverlay) 1065 if (nooverlay) {
1040 { 1066 if (Directx_CreateBackpuffer()) {
1041 if(Directx_CreateBackpuffer()) 1067 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't get the driver to work on your system :(\n");
1042 { 1068 return 1;
1043 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get the driver to work on your system :(\n"); 1069 }
1044 return 1; 1070 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>back surface created\n");
1045 } 1071 vo_doublebuffering = 0;
1046 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>back surface created\n"); 1072 /*create clipper for nonoverlay mode*/
1047 vo_doublebuffering = 0; 1073 if (g_lpdd->lpVtbl->CreateClipper(g_lpdd, 0, &g_lpddclipper, NULL) != DD_OK) {
1048 /*create clipper for nonoverlay mode*/ 1074 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't create clipper\n");
1049 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;} 1075 return 1;
1050 if(g_lpddclipper->lpVtbl->SetHWnd (g_lpddclipper, 0, vo_w32_window)!= DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't associate clipper with window\n");return 1;} 1076 }
1051 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;} 1077 if (g_lpddclipper->lpVtbl->SetHWnd(g_lpddclipper, 0, vo_w32_window) != DD_OK) {
1052 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper succesfully created\n"); 1078 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't associate clipper with window\n");
1053 }else{ 1079 return 1;
1054 if(DD_OK != g_lpddsOverlay->lpVtbl->QueryInterface(g_lpddsOverlay,&IID_IDirectDrawColorControl,(void**)&g_cc)) 1080 }
1055 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>unable to get DirectDraw ColorControl interface\n"); 1081 if (g_lpddsPrimary->lpVtbl->SetClipper(g_lpddsPrimary, g_lpddclipper) != DD_OK) {
1056 } 1082 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't associate primary surface with clipper\n");
1057 Directx_ManageDisplay(); 1083 return 1;
1058 memset(&ddsdsf, 0,sizeof(DDSURFACEDESC2)); 1084 }
1059 ddsdsf.dwSize = sizeof (DDSURFACEDESC2); 1085 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>clipper succesfully created\n");
1060 if (g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) == DD_OK) { 1086 } else {
1087 if (DD_OK != g_lpddsOverlay->lpVtbl->QueryInterface(g_lpddsOverlay, &IID_IDirectDrawColorControl, (void **)&g_cc))
1088 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><WARN>unable to get DirectDraw ColorControl interface\n");
1089 }
1090 Directx_ManageDisplay();
1091 memset(&ddsdsf, 0, sizeof(DDSURFACEDESC2));
1092 ddsdsf.dwSize = sizeof(DDSURFACEDESC2);
1093 if (g_lpddsBack->lpVtbl->Lock(g_lpddsBack, NULL, &ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) == DD_OK) {
1061 dstride = ddsdsf.lPitch; 1094 dstride = ddsdsf.lPitch;
1062 image = ddsdsf.lpSurface; 1095 image = ddsdsf.lpSurface;
1063 return 0; 1096 return 0;
1064 } 1097 }
1065 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><ERROR>Initial Lock on the Surface failed.\n"); 1098 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><ERROR>Initial Lock on the Surface failed.\n");
1066 return 1; 1099 return 1;
1067 } 1100 }
1068 1101
1069 //function to set color controls 1102 //function to set color controls
1070 // brightness [0, 10000] 1103 // brightness [0, 10000]
1071 // contrast [0, 20000] 1104 // contrast [0, 20000]
1072 // hue [-180, 180] 1105 // hue [-180, 180]
1073 // saturation [0, 20000] 1106 // saturation [0, 20000]
1074 static uint32_t color_ctrl_set(const char *what, int value) 1107 static uint32_t color_ctrl_set(const char *what, int value)
1075 { 1108 {
1076 uint32_t r = VO_NOTIMPL; 1109 uint32_t r = VO_NOTIMPL;
1077 DDCOLORCONTROL dcc; 1110 DDCOLORCONTROL dcc;
1078 //printf("\n*** %s = %d\n", what, value); 1111 //printf("\n*** %s = %d\n", what, value);
1079 if (!g_cc) { 1112 if (!g_cc) {
1080 //printf("\n *** could not get color control interface!!!\n"); 1113 //printf("\n *** could not get color control interface!!!\n");
1081 return VO_NOTIMPL; 1114 return VO_NOTIMPL;
1082 } 1115 }
1083 ZeroMemory(&dcc, sizeof(dcc)); 1116 ZeroMemory(&dcc, sizeof(dcc));
1084 dcc.dwSize = sizeof(dcc); 1117 dcc.dwSize = sizeof(dcc);
1085 1118
1086 if (!strcmp(what, "brightness")) { 1119 if (!strcmp(what, "brightness")) {
1087 dcc.dwFlags = DDCOLOR_BRIGHTNESS; 1120 dcc.dwFlags = DDCOLOR_BRIGHTNESS;
1088 dcc.lBrightness = (value + 100) * 10000 / 200; 1121 dcc.lBrightness = (value + 100) * 10000 / 200;
1089 r = VO_TRUE; 1122 r = VO_TRUE;
1090 } else if (!strcmp(what, "contrast")) { 1123 } else if (!strcmp(what, "contrast")) {
1091 dcc.dwFlags = DDCOLOR_CONTRAST; 1124 dcc.dwFlags = DDCOLOR_CONTRAST;
1092 dcc.lContrast = (value + 100) * 20000 / 200; 1125 dcc.lContrast = (value + 100) * 20000 / 200;
1093 r = VO_TRUE; 1126 r = VO_TRUE;
1094 } else if (!strcmp(what, "hue")) { 1127 } else if (!strcmp(what, "hue")) {
1095 dcc.dwFlags = DDCOLOR_HUE; 1128 dcc.dwFlags = DDCOLOR_HUE;
1096 dcc.lHue = value * 180 / 100; 1129 dcc.lHue = value * 180 / 100;
1097 r = VO_TRUE; 1130 r = VO_TRUE;
1098 } else if (!strcmp(what, "saturation")) { 1131 } else if (!strcmp(what, "saturation")) {
1099 dcc.dwFlags = DDCOLOR_SATURATION; 1132 dcc.dwFlags = DDCOLOR_SATURATION;
1100 dcc.lSaturation = (value + 100) * 20000 / 200; 1133 dcc.lSaturation = (value + 100) * 20000 / 200;
1101 r = VO_TRUE; 1134 r = VO_TRUE;
1102 } 1135 }
1103 1136
1104 if (r == VO_TRUE) { 1137 if (r == VO_TRUE) {
1105 g_cc->lpVtbl->SetColorControls(g_cc, &dcc); 1138 g_cc->lpVtbl->SetColorControls(g_cc, &dcc);
1106 } 1139 }
1107 return r; 1140 return r;
1108 } 1141 }
1109 1142
1110 //analoguous to color_ctrl_set 1143 //analoguous to color_ctrl_set
1111 static uint32_t color_ctrl_get(const char *what, int *value) 1144 static uint32_t color_ctrl_get(const char *what, int *value)
1112 { 1145 {
1113 uint32_t r = VO_NOTIMPL; 1146 uint32_t r = VO_NOTIMPL;
1114 DDCOLORCONTROL dcc; 1147 DDCOLORCONTROL dcc;
1115 if (!g_cc) { 1148 if (!g_cc) {
1116 //printf("\n *** could not get color control interface!!!\n"); 1149 //printf("\n *** could not get color control interface!!!\n");
1117 return VO_NOTIMPL; 1150 return VO_NOTIMPL;
1118 } 1151 }
1119 ZeroMemory(&dcc, sizeof(dcc)); 1152 ZeroMemory(&dcc, sizeof(dcc));
1120 dcc.dwSize = sizeof(dcc); 1153 dcc.dwSize = sizeof(dcc);
1121 1154
1122 if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) { 1155 if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) {
1123 return r; 1156 return r;
1124 } 1157 }
1125 1158
1126 if (!strcmp(what, "brightness") && (dcc.dwFlags & DDCOLOR_BRIGHTNESS)) { 1159 if (!strcmp(what, "brightness") && (dcc.dwFlags & DDCOLOR_BRIGHTNESS)) {
1127 *value = dcc.lBrightness * 200 / 10000 - 100; 1160 *value = dcc.lBrightness * 200 / 10000 - 100;
1128 r = VO_TRUE; 1161 r = VO_TRUE;
1129 } else if (!strcmp(what, "contrast") && (dcc.dwFlags & DDCOLOR_CONTRAST)) { 1162 } else if (!strcmp(what, "contrast") && (dcc.dwFlags & DDCOLOR_CONTRAST)) {
1130 *value = dcc.lContrast * 200 / 20000 - 100; 1163 *value = dcc.lContrast * 200 / 20000 - 100;
1131 r = VO_TRUE; 1164 r = VO_TRUE;
1132 } else if (!strcmp(what, "hue") && (dcc.dwFlags & DDCOLOR_HUE)) { 1165 } else if (!strcmp(what, "hue") && (dcc.dwFlags & DDCOLOR_HUE)) {
1133 *value = dcc.lHue * 100 / 180; 1166 *value = dcc.lHue * 100 / 180;
1134 r = VO_TRUE; 1167 r = VO_TRUE;
1135 } else if (!strcmp(what, "saturation") && (dcc.dwFlags & DDCOLOR_SATURATION)) { 1168 } else if (!strcmp(what, "saturation") && (dcc.dwFlags & DDCOLOR_SATURATION)) {
1136 *value = dcc.lSaturation * 200 / 20000 - 100; 1169 *value = dcc.lSaturation * 200 / 20000 - 100;
1137 r = VO_TRUE; 1170 r = VO_TRUE;
1138 } 1171 }
1139 // printf("\n*** %s = %d\n", what, *value); 1172 // printf("\n*** %s = %d\n", what, *value);
1140 1173
1141 return r; 1174 return r;
1142 } 1175 }
1143 1176
1144 static int control(uint32_t request, void *data) 1177 static int control(uint32_t request, void *data)
1145 { 1178 {
1146 switch (request) { 1179 switch (request) {
1147 1180 case VOCTRL_GET_IMAGE:
1148 case VOCTRL_GET_IMAGE: 1181 return get_image(data);
1149 return get_image(data);
1150 case VOCTRL_QUERY_FORMAT: 1182 case VOCTRL_QUERY_FORMAT:
1151 return query_format(*((uint32_t*)data)); 1183 return query_format(*((uint32_t *)data));
1152 case VOCTRL_DRAW_IMAGE: 1184 case VOCTRL_DRAW_IMAGE:
1153 return put_image(data); 1185 return put_image(data);
1154 case VOCTRL_BORDER: 1186 case VOCTRL_BORDER:
1155 vo_w32_border(); 1187 vo_w32_border();
1156 Directx_ManageDisplay(); 1188 Directx_ManageDisplay();
1157 return VO_TRUE; 1189 return VO_TRUE;
1158 case VOCTRL_ONTOP: 1190 case VOCTRL_ONTOP:
1159 vo_w32_ontop(); 1191 vo_w32_ontop();
1160 return VO_TRUE; 1192 return VO_TRUE;
1161 case VOCTRL_ROOTWIN: 1193 case VOCTRL_ROOTWIN:
1162 if(WinID != -1) return VO_TRUE; 1194 if (WinID != -1)
1163 if(vidmode) 1195 return VO_TRUE;
1164 { 1196 if (vidmode) {
1165 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>rootwin has no meaning in exclusive mode\n"); 1197 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx><ERROR>rootwin has no meaning in exclusive mode\n");
1166 } 1198 } else {
1167 else 1199 if (vo_rootwin)
1168 { 1200 vo_rootwin = 0;
1169 if(vo_rootwin) vo_rootwin = 0; 1201 else
1170 else vo_rootwin = 1; 1202 vo_rootwin = 1;
1171 Directx_ManageDisplay(); 1203 Directx_ManageDisplay();
1172 } 1204 }
1173 return VO_TRUE; 1205 return VO_TRUE;
1174 case VOCTRL_FULLSCREEN: 1206 case VOCTRL_FULLSCREEN:
1175 { 1207 {
1176 vo_w32_fullscreen(); 1208 vo_w32_fullscreen();
1177 Directx_ManageDisplay(); 1209 Directx_ManageDisplay();
1178 return VO_TRUE; 1210 return VO_TRUE;
1179 } 1211 }
1180 case VOCTRL_SET_EQUALIZER: { 1212 case VOCTRL_SET_EQUALIZER: {
1181 vf_equalizer_t *eq=data; 1213 vf_equalizer_t *eq = data;
1182 return color_ctrl_set(eq->item, eq->value); 1214 return color_ctrl_set(eq->item, eq->value);
1183 } 1215 }
1184 case VOCTRL_GET_EQUALIZER: { 1216 case VOCTRL_GET_EQUALIZER: {
1185 vf_equalizer_t *eq=data; 1217 vf_equalizer_t *eq = data;
1186 return color_ctrl_get(eq->item, &eq->value); 1218 return color_ctrl_get(eq->item, &eq->value);
1187 } 1219 }
1188 case VOCTRL_UPDATE_SCREENINFO: 1220 case VOCTRL_UPDATE_SCREENINFO:
1189 w32_update_xinerama_info(); 1221 w32_update_xinerama_info();
1190 return VO_TRUE; 1222 return VO_TRUE;
1191 }; 1223 }
1192 return VO_NOTIMPL; 1224 return VO_NOTIMPL;
1193 } 1225 }