comparison libvo/vo_directx.c @ 33814:ccbef55f408c

Simplify struct initialization.
author reimar
date Sun, 24 Jul 2011 19:22:58 +0000
parents a214da7104e2
children 4d75b3bf9561
comparison
equal deleted inserted replaced
33813:a214da7104e2 33814:ccbef55f408c
166 return 0; 166 return 0;
167 } 167 }
168 168
169 static uint32_t Directx_CreatePrimarySurface(void) 169 static uint32_t Directx_CreatePrimarySurface(void)
170 { 170 {
171 DDSURFACEDESC2 ddsd; 171 DDSURFACEDESC2 ddsd = { .dwSize = sizeof(ddsd) };
172 //cleanup 172 //cleanup
173 if (g_lpddsPrimary) 173 if (g_lpddsPrimary)
174 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); 174 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
175 g_lpddsPrimary = NULL; 175 g_lpddsPrimary = NULL;
176 176
177 if (vidmode) 177 if (vidmode)
178 g_lpdd->lpVtbl->SetDisplayMode(g_lpdd, vm_width, vm_height, vm_bpp, vo_refresh_rate, 0); 178 g_lpdd->lpVtbl->SetDisplayMode(g_lpdd, vm_width, vm_height, vm_bpp, vo_refresh_rate, 0);
179 ZeroMemory(&ddsd, sizeof(ddsd));
180 ddsd.dwSize = sizeof(ddsd);
181 //set flags and create a primary surface. 179 //set flags and create a primary surface.
182 ddsd.dwFlags = DDSD_CAPS; 180 ddsd.dwFlags = DDSD_CAPS;
183 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; 181 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
184 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsPrimary, NULL) == DD_OK) 182 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsPrimary, NULL) == DD_OK)
185 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>primary surface created\n"); 183 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>primary surface created\n");
191 } 189 }
192 190
193 static uint32_t Directx_CreateOverlay(uint32_t imgfmt) 191 static uint32_t Directx_CreateOverlay(uint32_t imgfmt)
194 { 192 {
195 HRESULT ddrval; 193 HRESULT ddrval;
196 DDSURFACEDESC2 ddsdOverlay; 194 DDSURFACEDESC2 ddsdOverlay = {
195 .dwSize = sizeof(ddsdOverlay),
196 .ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
197 .dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_BACKBUFFERCOUNT | DDSD_PIXELFORMAT,
198 .dwWidth = image_width,
199 .dwHeight = image_height,
200 .dwBackBufferCount = 2,
201 };
197 uint32_t i = 0; 202 uint32_t i = 0;
198 while (i < NUM_FORMATS && imgfmt != g_ddpf[i].img_format) 203 while (i < NUM_FORMATS && imgfmt != g_ddpf[i].img_format)
199 i++; 204 i++;
200 if (!g_lpdd || !g_lpddsPrimary || i == NUM_FORMATS) 205 if (!g_lpdd || !g_lpddsPrimary || i == NUM_FORMATS)
201 return 1; 206 return 1;
205 if (g_lpddsBack) 210 if (g_lpddsBack)
206 g_lpddsBack->lpVtbl->Release(g_lpddsBack); 211 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
207 g_lpddsOverlay = NULL; 212 g_lpddsOverlay = NULL;
208 g_lpddsBack = NULL; 213 g_lpddsBack = NULL;
209 //create our overlay 214 //create our overlay
210 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
211 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
212 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
213 ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_BACKBUFFERCOUNT | DDSD_PIXELFORMAT;
214 ddsdOverlay.dwWidth = image_width;
215 ddsdOverlay.dwHeight = image_height;
216 ddsdOverlay.dwBackBufferCount = 2;
217 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay; 215 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay;
218 if (vo_doublebuffering) { //tribblebuffering 216 if (vo_doublebuffering) { //tribblebuffering
219 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL) == DD_OK) { 217 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); 218 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>overlay with format %s created\n", g_ddpf[i].img_format_name);
221 //get the surface directly attached to the primary (the back buffer) 219 //get the surface directly attached to the primary (the back buffer)
285 return 0; 283 return 0;
286 } 284 }
287 285
288 static uint32_t Directx_CreateBackpuffer(void) 286 static uint32_t Directx_CreateBackpuffer(void)
289 { 287 {
290 DDSURFACEDESC2 ddsd; 288 DDSURFACEDESC2 ddsd = {
289 .dwSize = sizeof(ddsd),
290 .ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
291 .dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT,
292 .dwWidth = image_width,
293 .dwHeight = image_height,
294 };
291 //cleanup 295 //cleanup
292 if (g_lpddsBack) 296 if (g_lpddsBack)
293 g_lpddsBack->lpVtbl->Release(g_lpddsBack); 297 g_lpddsBack->lpVtbl->Release(g_lpddsBack);
294 g_lpddsBack = NULL; 298 g_lpddsBack = NULL;
295 ZeroMemory(&ddsd, sizeof(ddsd));
296 ddsd.dwSize = sizeof(ddsd);
297 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
298 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
299 ddsd.dwWidth = image_width;
300 ddsd.dwHeight = image_height;
301 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsBack, 0) != DD_OK) { 299 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsd, &g_lpddsBack, 0) != DD_OK) {
302 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't create backpuffer\n"); 300 mp_msg(MSGT_VO, MSGL_FATAL, "<vo_directx><FATAL ERROR>can't create backpuffer\n");
303 return 1; 301 return 1;
304 } 302 }
305 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>backbuffer created\n"); 303 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>backbuffer created\n");
458 } 456 }
459 457
460 static uint32_t Directx_ManageDisplay(void) 458 static uint32_t Directx_ManageDisplay(void)
461 { 459 {
462 HRESULT ddrval; 460 HRESULT ddrval;
463 DDCAPS capsDrv; 461 DDCAPS capsDrv = { .dwSize = sizeof(capsDrv) };
464 DDOVERLAYFX ovfx; 462 DDOVERLAYFX ovfx = { .dwSize = sizeof(ovfx) };
465 DWORD dwUpdateFlags = 0; 463 DWORD dwUpdateFlags = 0;
466 int width, height; 464 int width, height;
467 465
468 rd.left = vo_dx - xinerama_x; 466 rd.left = vo_dx - xinerama_x;
469 rd.top = vo_dy - xinerama_y; 467 rd.top = vo_dy - xinerama_y;
494 g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); 492 g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay, NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
495 return 0; 493 return 0;
496 } 494 }
497 495
498 /*get driver capabilities*/ 496 /*get driver capabilities*/
499 ZeroMemory(&capsDrv, sizeof(capsDrv));
500 capsDrv.dwSize = sizeof(capsDrv);
501 if (g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL) != DD_OK) 497 if (g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL) != DD_OK)
502 return 1; 498 return 1;
503 /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */ 499 /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */
504 uStretchFactor1000 = capsDrv.dwMinOverlayStretch > 1000 ? capsDrv.dwMinOverlayStretch : 1000; 500 uStretchFactor1000 = capsDrv.dwMinOverlayStretch > 1000 ? capsDrv.dwMinOverlayStretch : 1000;
505 rd.right = ((width + rd.left) * uStretchFactor1000 + 999) / 1000; 501 rd.right = ((width + rd.left) * uStretchFactor1000 + 999) / 1000;
556 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest) 552 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest)
557 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & - (signed)(capsDrv.dwAlignBoundaryDest); 553 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & - (signed)(capsDrv.dwAlignBoundaryDest);
558 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest) 554 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest)
559 rd.right = rd.left + ((rd.right - rd.left) & - (signed)(capsDrv.dwAlignSizeDest)); 555 rd.right = rd.left + ((rd.right - rd.left) & - (signed)(capsDrv.dwAlignSizeDest));
560 /*create an overlay FX structure to specify a destination color key*/ 556 /*create an overlay FX structure to specify a destination color key*/
561 ZeroMemory(&ovfx, sizeof(ovfx));
562 ovfx.dwSize = sizeof(ovfx);
563 if (vo_fs || vidmode) { 557 if (vo_fs || vidmode) {
564 ovfx.dckDestColorkey.dwColorSpaceLowValue = 0; 558 ovfx.dckDestColorkey.dwColorSpaceLowValue = 0;
565 ovfx.dckDestColorkey.dwColorSpaceHighValue = 0; 559 ovfx.dckDestColorkey.dwColorSpaceHighValue = 0;
566 } else { 560 } else {
567 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey; 561 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey;
657 } 651 }
658 652
659 //find out supported overlay pixelformats 653 //find out supported overlay pixelformats
660 static uint32_t Directx_CheckOverlayPixelformats(void) 654 static uint32_t Directx_CheckOverlayPixelformats(void)
661 { 655 {
662 DDCAPS capsDrv; 656 DDCAPS capsDrv = { .dwSize = sizeof(capsDrv) };
663 HRESULT ddrval; 657 HRESULT ddrval;
664 DDSURFACEDESC2 ddsdOverlay; 658 DDSURFACEDESC2 ddsdOverlay = {
659 .dwSize = sizeof(ddsdOverlay),
660 .ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY,
661 .dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT,
662 .dwWidth = 300,
663 .dwHeight = 280,
664 .dwBackBufferCount = 0,
665 };
665 uint32_t i; 666 uint32_t i;
666 uint32_t formatcount = 0; 667 uint32_t formatcount = 0;
667 //get driver caps to determine overlay support 668 //get driver caps to determine overlay support
668 ZeroMemory(&capsDrv, sizeof(capsDrv));
669 capsDrv.dwSize = sizeof(capsDrv);
670 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL); 669 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd, &capsDrv, NULL);
671 if (FAILED(ddrval)) { 670 if (FAILED(ddrval)) {
672 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");
673 return 1; 672 return 1;
674 } 673 }
677 return 1; 676 return 1;
678 } 677 }
679 mp_msg(MSGT_VO, MSGL_V, "<vo_directx><INFO>testing supported overlay pixelformats\n"); 678 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 679 //it is not possible to query for pixel formats supported by the
681 //overlay hardware: try out various formats till one works 680 //overlay hardware: try out various formats till one works
682 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
683 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
684 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
685 ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
686 ddsdOverlay.dwWidth = 300;
687 ddsdOverlay.dwHeight = 280;
688 ddsdOverlay.dwBackBufferCount = 0;
689 //try to create an overlay surface using one of the pixel formats in our global list 681 //try to create an overlay surface using one of the pixel formats in our global list
690 i = 0; 682 i = 0;
691 do { 683 do {
692 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay; 684 ddsdOverlay.ddpfPixelFormat = g_ddpf[i].g_ddpfOverlay;
693 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL); 685 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd, &ddsdOverlay, &g_lpddsOverlay, NULL);
1079 // hue [-180, 180] 1071 // hue [-180, 180]
1080 // saturation [0, 20000] 1072 // saturation [0, 20000]
1081 static uint32_t color_ctrl_set(const char *what, int value) 1073 static uint32_t color_ctrl_set(const char *what, int value)
1082 { 1074 {
1083 uint32_t r = VO_NOTIMPL; 1075 uint32_t r = VO_NOTIMPL;
1084 DDCOLORCONTROL dcc; 1076 DDCOLORCONTROL dcc = { .dwSize = sizeof(dcc) };
1085 //printf("\n*** %s = %d\n", what, value); 1077 //printf("\n*** %s = %d\n", what, value);
1086 if (!g_cc) { 1078 if (!g_cc) {
1087 //printf("\n *** could not get color control interface!!!\n"); 1079 //printf("\n *** could not get color control interface!!!\n");
1088 return VO_NOTIMPL; 1080 return VO_NOTIMPL;
1089 } 1081 }
1090 ZeroMemory(&dcc, sizeof(dcc));
1091 dcc.dwSize = sizeof(dcc);
1092 1082
1093 if (!strcmp(what, "brightness")) { 1083 if (!strcmp(what, "brightness")) {
1094 dcc.dwFlags = DDCOLOR_BRIGHTNESS; 1084 dcc.dwFlags = DDCOLOR_BRIGHTNESS;
1095 dcc.lBrightness = (value + 100) * 10000 / 200; 1085 dcc.lBrightness = (value + 100) * 10000 / 200;
1096 r = VO_TRUE; 1086 r = VO_TRUE;
1116 1106
1117 //analoguous to color_ctrl_set 1107 //analoguous to color_ctrl_set
1118 static uint32_t color_ctrl_get(const char *what, int *value) 1108 static uint32_t color_ctrl_get(const char *what, int *value)
1119 { 1109 {
1120 uint32_t r = VO_NOTIMPL; 1110 uint32_t r = VO_NOTIMPL;
1121 DDCOLORCONTROL dcc; 1111 DDCOLORCONTROL dcc = { .dwSize = sizeof(dcc) };
1122 if (!g_cc) { 1112 if (!g_cc) {
1123 //printf("\n *** could not get color control interface!!!\n"); 1113 //printf("\n *** could not get color control interface!!!\n");
1124 return VO_NOTIMPL; 1114 return VO_NOTIMPL;
1125 } 1115 }
1126 ZeroMemory(&dcc, sizeof(dcc));
1127 dcc.dwSize = sizeof(dcc);
1128 1116
1129 if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) { 1117 if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) {
1130 return r; 1118 return r;
1131 } 1119 }
1132 1120