vid_overlay.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. #include "main.h"
  2. #include <windows.h>
  3. #include <multimon.h>
  4. #include "vid_overlay.h"
  5. #include "directdraw.h"
  6. #include <api.h>
  7. #include "../Winamp/wa_ipc.h"
  8. #include <assert.h>
  9. void getViewport(RECT *r, HWND wnd, int full, RECT *sr);
  10. void YV12_to_YUY2(unsigned char *output, const YV12_PLANES *planes, int pitch, int width, int height, int flip)
  11. {
  12. const unsigned char *yi = planes->y.baseAddr;
  13. const unsigned char *ui = planes->u.baseAddr;
  14. const unsigned char *vi = planes->v.baseAddr;
  15. if (flip)
  16. output += pitch * (height - 1);
  17. while (height > 0)
  18. {
  19. int x = width;
  20. unsigned char *oo = output;
  21. while (x > 0)
  22. {
  23. output[0] = *yi++; output[1] = *ui++; output[2] = *yi++; output[3] = *vi++;
  24. output += 4; x -= 2;
  25. }
  26. ui -= width / 2;
  27. vi -= width / 2;
  28. yi += planes->y.rowBytes - width;
  29. x = width;
  30. if (flip) output = oo - pitch;
  31. else output += pitch - width * 2;
  32. oo = output;
  33. while (x > 0)
  34. {
  35. output[0] = *yi++; output[1] = *ui++; output[2] = *yi++; output[3] = *vi++;
  36. output += 4; x -= 2;
  37. }
  38. if (flip) output = oo - pitch;
  39. else output += pitch - width * 2;
  40. ui += planes->u.rowBytes - (width / 2);
  41. vi += planes->v.rowBytes - (width / 2);
  42. yi += planes->y.rowBytes - width;
  43. height -= 2;
  44. }
  45. }
  46. void YV12_to_UYVY(unsigned char *output, const YV12_PLANES *planes, int pitch, int width, int height, int flip)
  47. {
  48. const unsigned char *yi = planes->y.baseAddr;
  49. const unsigned char *ui = planes->u.baseAddr;
  50. const unsigned char *vi = planes->v.baseAddr;
  51. if (flip) output += pitch * (height - 1);
  52. while (height > 0)
  53. {
  54. int x = width;
  55. unsigned char *oo = output;
  56. while (x > 0)
  57. {
  58. output[0] = *ui++; output[1] = *yi++; output[2] = *vi++; output[3] = *yi++;
  59. output += 4; x -= 2;
  60. }
  61. ui -= width / 2;
  62. vi -= width / 2;
  63. yi += planes->y.rowBytes - width;
  64. x = width;
  65. if (flip) output = oo - pitch;
  66. else output += pitch - width * 2;
  67. oo = output;
  68. while (x > 0)
  69. {
  70. output[0] = *ui++; output[1] = *yi++; output[2] = *vi++; output[3] = *yi++;
  71. output += 4; x -= 2;
  72. }
  73. if (flip) output = oo - pitch;
  74. else output += pitch - width * 2;
  75. ui += planes->u.rowBytes - (width / 2);
  76. vi += planes->v.rowBytes - (width / 2);
  77. yi += planes->y.rowBytes - width;
  78. height -= 2;
  79. }
  80. }
  81. void YV12_to_YV12(unsigned char *output, const YV12_PLANES *planes, int pitch, int width, int height, int flip)
  82. { // woo native YV12 copy
  83. int f = !!flip;
  84. unsigned char *o = output + (f * height * pitch);
  85. const char *i = (const char*)planes->y.baseAddr;
  86. int d_o = pitch;
  87. if (f) d_o = -d_o;
  88. else o -= d_o;
  89. int h2 = height;
  90. while (h2--)
  91. {
  92. o += d_o; memcpy(o, i, width); i += planes->y.rowBytes;
  93. }
  94. d_o /= 2;
  95. int w2 = width / 2;
  96. h2 = height / 2;
  97. i = (const char*)planes->v.baseAddr;
  98. o = output + (height * pitch * (f + 4)) / 4;
  99. if (!f) o -= d_o;
  100. while (h2--)
  101. {
  102. o += d_o; memcpy(o, i, w2); i += planes->v.rowBytes;
  103. }
  104. o = output + (height * pitch * (f + 5)) / 4;
  105. i = (const char*)planes->u.baseAddr;
  106. h2 = height / 2;
  107. if (!f) o -= d_o;
  108. while (h2--)
  109. {
  110. o += d_o; memcpy(o, i, w2);i += planes->u.rowBytes;
  111. }
  112. }
  113. void YUY2_to_YUY2(unsigned char *output, const char *buf, int pitch, int width, int height, int flip)
  114. {
  115. const char *a = buf;
  116. unsigned char *b = output;
  117. int l = width * 2, l2 = pitch;
  118. if (flip)
  119. {
  120. b += (height - 1) * l2;
  121. l2 = -l2;
  122. }
  123. //wee straight YUY2 copy
  124. for (int i = 0;i < height;i++)
  125. {
  126. memcpy(b, a, l);
  127. b += l2;
  128. a += l;
  129. }
  130. }
  131. void YUY2_to_UYVY(unsigned char *output, const char *buf, int pitch, int width, int height, int flip)
  132. {
  133. const char *a = buf;
  134. unsigned char *b = output;
  135. int l = width * 2, l2 = pitch;
  136. if (flip)
  137. {
  138. b += (height - 1) * l2;
  139. l2 = -l2;
  140. }
  141. for (int i = 0;i < height;i++)
  142. {
  143. int x = width / 2;
  144. while (x-- > 0)
  145. {
  146. b[0] = a[1];
  147. b[1] = a[0];
  148. b[2] = a[3];
  149. b[3] = a[2];
  150. a += 4;
  151. b += 4;
  152. }
  153. memcpy(b, a, l);
  154. b += l2;
  155. a += l;
  156. }
  157. }
  158. #define INIT_DIRECTDRAW_STRUCT(x) (ZeroMemory(&x, sizeof(x)), x.dwSize=sizeof(x))
  159. // I like to set these to 255,0,255 to test that we arent drawing this color too many playces
  160. #define OV_COL_R 16
  161. #define OV_COL_G 0
  162. #define OV_COL_B 16
  163. OverlayVideoOutput::OverlayVideoOutput() : frame(NULL), width(0), height(0),
  164. flip(0), type(0), uDestSizeAlign(0), uSrcSizeAlign(0), dwUpdateFlags(0)
  165. {
  166. lpDD = NULL;
  167. m_closed = 0;
  168. overlay_color = RGB(OV_COL_R, OV_COL_G, OV_COL_B);
  169. lpddsOverlay = NULL;
  170. lpddsPrimary = NULL;
  171. lpBackBuffer = NULL;
  172. yuy2_output = uyvy_output = 0;
  173. initing = false;
  174. needchange = 0;
  175. memset(&m_oldrd, 0, sizeof(m_oldrd));
  176. memset(&winRect, 0, sizeof(winRect));
  177. m_fontsize = 0;
  178. }
  179. OverlayVideoOutput::~OverlayVideoOutput()
  180. {
  181. OverlayVideoOutput::close();
  182. }
  183. static DWORD DD_ColorMatch(LPDIRECTDRAWSURFACE pdds, COLORREF rgb)
  184. {
  185. COLORREF rgbT;
  186. HDC hdc;
  187. DWORD dw = CLR_INVALID;
  188. DDSURFACEDESC ddsd;
  189. HRESULT hres;
  190. //
  191. // use GDI SetPixel to color match for us
  192. //
  193. if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
  194. {
  195. rgbT = GetPixel(hdc, 0, 0); // save current pixel value
  196. SetPixel(hdc, 0, 0, rgb); // set our value
  197. pdds->ReleaseDC(hdc);
  198. }
  199. // now lock the surface so we can read back the converted color
  200. ddsd.dwSize = sizeof(ddsd);
  201. while ((hres = pdds->Lock(NULL, &ddsd, 0, NULL)) ==
  202. DDERR_WASSTILLDRAWING)
  203. ;
  204. if (hres == DD_OK)
  205. {
  206. dw = *(DWORD *)ddsd.lpSurface; // get DWORD
  207. if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
  208. dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; // mask it to bpp
  209. pdds->Unlock(NULL);
  210. }
  211. // now put the color that was there back.
  212. if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
  213. {
  214. SetPixel(hdc, 0, 0, rgbT);
  215. pdds->ReleaseDC(hdc);
  216. }
  217. return dw;
  218. }
  219. int OverlayVideoOutput::create(HWND parent, VideoAspectAdjuster *_adjuster, int w, int h, unsigned int ptype, int flipit, double aspectratio)
  220. {
  221. OverlayVideoOutput::close();
  222. this->parent = parent;
  223. type = ptype;
  224. width = w;
  225. height = h;
  226. flip = flipit;
  227. adjuster = _adjuster;
  228. initing = true;
  229. HWND hwnd = this->parent;
  230. if (lpDD) lpDD->Release();
  231. lpDD = NULL;
  232. update_monitor_coords();
  233. if (!foundGUID) DDrawCreate(NULL, &lpDD, NULL);
  234. else DDrawCreate(&m_devguid, &lpDD, NULL);
  235. if (!lpDD)
  236. {
  237. initing = false;
  238. return 0;
  239. }
  240. lpDD->SetCooperativeLevel(hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_NORMAL);
  241. DDSURFACEDESC ddsd;
  242. INIT_DIRECTDRAW_STRUCT(ddsd);
  243. ddsd.dwFlags = DDSD_CAPS;
  244. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  245. lpDD->CreateSurface(&ddsd, &lpddsPrimary, NULL );
  246. if (!lpddsPrimary)
  247. {
  248. if (lpDD) lpDD->Release();
  249. lpDD = NULL;
  250. initing=false;
  251. return 0;
  252. }
  253. // init overlay
  254. DDSURFACEDESC ddsdOverlay;
  255. INIT_DIRECTDRAW_STRUCT(ddsdOverlay);
  256. //ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
  257. //ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH;
  258. //ddsdOverlay.dwBackBufferCount=0;
  259. ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
  260. ddsdOverlay.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_PITCH | DDSD_BACKBUFFERCOUNT;
  261. ddsdOverlay.dwBackBufferCount = 1;
  262. ddsdOverlay.dwWidth = w;
  263. ddsdOverlay.dwHeight = h;
  264. ddsdOverlay.lPitch = w * 4;
  265. DDPIXELFORMAT pf[] =
  266. {
  267. {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'), 0, 0, 0, 0, 0},
  268. {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'), 0, 0, 0, 0, 0}, // UYVY
  269. {sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'V', '1', '2'), 0, 0, 0, 0, 0},
  270. };
  271. int tab[5] = {0};
  272. if (type == VIDEO_MAKETYPE('Y', 'U', 'Y', '2'))
  273. {
  274. tab[0] = 0; // default is YUY2
  275. tab[1] = 1;
  276. tab[2] = -1;
  277. }
  278. else if (type == VIDEO_MAKETYPE('U', 'Y', 'V', 'Y'))
  279. {
  280. tab[0] = 1; // make UYVY default
  281. tab[1] = 0;
  282. tab[2] = -1;
  283. }
  284. else if (type == VIDEO_MAKETYPE('Y', 'V', '1', '2'))
  285. {
  286. if (config_video.yv12())
  287. {
  288. tab[0] = 2;
  289. tab[1] = 0;
  290. tab[2] = 1;
  291. tab[3] = -1;
  292. }
  293. else
  294. {
  295. //use YUY2
  296. tab[0] = 0; // default is YUY2
  297. tab[1] = 1;
  298. tab[2] = -1;
  299. }
  300. }
  301. else
  302. {
  303. tab[0] = -1; // default is RGB
  304. }
  305. int x = 4096;
  306. HRESULT v = -1;
  307. for (x = 0; x < sizeof(tab) / sizeof(tab[0]) && tab[x] >= 0; x ++)
  308. {
  309. ddsdOverlay.ddpfPixelFormat = pf[tab[x]];
  310. v = lpDD->CreateSurface(&ddsdOverlay, &lpddsOverlay, NULL);
  311. if (!FAILED(v)) break;
  312. }
  313. if (FAILED(v) || x >= sizeof(tab) / sizeof(tab[0]) || tab[x] < 0)
  314. {
  315. initing = false;
  316. return 0;
  317. }
  318. yuy2_output = (tab[x] == 0);
  319. uyvy_output = (tab[x] == 1);
  320. //get the backbuffer surface
  321. DDSCAPS ddscaps;
  322. ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  323. v = lpddsOverlay->GetAttachedSurface(&ddscaps, &lpBackBuffer);
  324. if (v != DD_OK || lpBackBuffer == 0)
  325. {
  326. // make it use normal vsync
  327. lpBackBuffer=0;
  328. initing = FALSE;
  329. return 0;
  330. }
  331. INIT_DIRECTDRAW_STRUCT(capsDrv);
  332. lpDD->GetCaps(&capsDrv, NULL);
  333. uDestSizeAlign = capsDrv.dwAlignSizeDest;
  334. uSrcSizeAlign = capsDrv.dwAlignSizeSrc;
  335. dwUpdateFlags = DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE;
  336. DEVMODE d;
  337. d.dmSize = sizeof(d);
  338. d.dmDriverExtra = 0;
  339. EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &d);
  340. int rv = OV_COL_R, gv = OV_COL_G, bv = OV_COL_B;
  341. overlay_color = RGB(rv, gv, bv);
  342. if (d.dmBitsPerPel == 8)
  343. {
  344. overlay_color = RGB(255, 0, 255);
  345. }
  346. INIT_DIRECTDRAW_STRUCT(ovfx);
  347. ovfx.dwDDFX = 0;
  348. switch (d.dmBitsPerPel)
  349. {
  350. case 8:
  351. ovfx.dckDestColorkey.dwColorSpaceLowValue = 253;
  352. break;
  353. case 16:
  354. ovfx.dckDestColorkey.dwColorSpaceLowValue = ((rv >> 3) << 11) | ((gv >> 2) << 5) | (bv >> 3);
  355. break;
  356. case 15:
  357. ovfx.dckDestColorkey.dwColorSpaceLowValue = ((rv >> 3) << 10) | ((gv >> 3) << 5) | (bv >> 3);
  358. break;
  359. case 24:
  360. case 32:
  361. ovfx.dckDestColorkey.dwColorSpaceLowValue = (rv << 16) | (gv << 8) | bv;
  362. break;
  363. }
  364. //try to get the correct bit depth thru directdraw (for fucked up 16 bits displays for ie.)
  365. {
  366. DDSURFACEDESC DDsd = {sizeof(DDsd), };
  367. lpddsPrimary->GetSurfaceDesc(&ddsd);
  368. DDsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; //create the surface at screen depth
  369. DDsd.dwWidth = 8;
  370. DDsd.dwHeight = 8;
  371. DDsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
  372. LPDIRECTDRAWSURFACE tempsurf;
  373. if (lpDD->CreateSurface(&DDsd, &tempsurf, NULL) == DD_OK)
  374. {
  375. int res = DD_ColorMatch(tempsurf, overlay_color);
  376. if (res != CLR_INVALID) ovfx.dckDestColorkey.dwColorSpaceLowValue = res;
  377. tempsurf->Release();
  378. }
  379. }
  380. ovfx.dckDestColorkey.dwColorSpaceHighValue = ovfx.dckDestColorkey.dwColorSpaceLowValue;
  381. getRects(&rs, &rd);
  382. if (FAILED(lpddsOverlay->UpdateOverlay(&rs, lpddsPrimary, &rd, dwUpdateFlags, &ovfx)))
  383. {
  384. initing = false;
  385. return 0;
  386. }
  387. initing = false;
  388. DDSURFACEDESC dd = {sizeof(dd), };
  389. if (lpddsOverlay->Lock(NULL, &dd, DDLOCK_WAIT, NULL) != DD_OK) return 0;
  390. unsigned char *o = (unsigned char*)dd.lpSurface;
  391. if (uyvy_output || yuy2_output)
  392. {
  393. int x = dd.lPitch * height / 2;
  394. while (x--)
  395. {
  396. if (uyvy_output)
  397. {
  398. *o++ = 128;
  399. *o++ = 0;
  400. }
  401. else
  402. {
  403. *o++ = 0;
  404. *o++ = -128;
  405. }
  406. }
  407. }
  408. else
  409. {
  410. memset(o, 0, dd.lPitch*height); o += dd.lPitch * height;
  411. memset(o, 128, dd.lPitch*height / 2);
  412. }
  413. lpddsOverlay->Unlock(&dd);
  414. m_closed=0;
  415. needchange = 0;
  416. InvalidateRect(hwnd, NULL, TRUE);
  417. return 1;
  418. }
  419. void OverlayVideoOutput::close()
  420. {
  421. m_closed = 1;
  422. if (lpddsOverlay) lpddsOverlay->UpdateOverlay(NULL, lpddsPrimary, NULL, DDOVER_HIDE , NULL);
  423. if (lpBackBuffer) lpBackBuffer->Release(); lpBackBuffer=0;
  424. if (lpddsOverlay) lpddsOverlay->Release(); lpddsOverlay=0;
  425. if (lpddsPrimary) lpddsPrimary->Release(); lpddsPrimary=0;
  426. if (lpDD) lpDD->Release(); lpDD=0; // BU added NULL check in response to talkback
  427. }
  428. void OverlayVideoOutput::getRects(RECT *drs, RECT *drd, int fixmultimon) const
  429. {
  430. //if(GetParent(hwnd)) hwnd=GetParent(hwnd);
  431. RECT rd, rs;
  432. GetClientRect(parent, &rd);
  433. ClientToScreen(parent, (LPPOINT)&rd);
  434. ClientToScreen(parent, ((LPPOINT)&rd) + 1);
  435. adjuster->adjustAspect(rd);
  436. rd.left -= m_mon_x;
  437. rd.right -= m_mon_x;
  438. rd.top -= m_mon_y;
  439. rd.bottom -= m_mon_y;
  440. memset(&rs, 0, sizeof(rs));
  441. rs.right = width;
  442. rs.bottom = height;
  443. if (fixmultimon)
  444. {
  445. //resize overlay for off-screen
  446. RECT rfull;
  447. getViewport(&rfull, parent, 1, NULL);
  448. rfull.left -= m_mon_x;
  449. rfull.right -= m_mon_x;
  450. rfull.top -= m_mon_y;
  451. rfull.bottom -= m_mon_y;
  452. if (rd.right > rfull.right)
  453. {
  454. int diff = rd.right - rfull.right;
  455. float sc = (float)(width) / (float)(rd.right - rd.left);
  456. rd.right = rfull.right;
  457. rs.right = width - (int)(diff * sc);
  458. }
  459. if (rd.left < rfull.left)
  460. {
  461. int diff = rfull.left - rd.left;
  462. float sc = (float)(width) / (float)(rd.right - rd.left);
  463. rd.left = rfull.left;
  464. rs.left = (int)(diff * sc);
  465. }
  466. if (rd.bottom > rfull.bottom)
  467. {
  468. int diff = rd.bottom - rfull.bottom;
  469. float sc = (float)(height) / (float)(rd.bottom - rd.top);
  470. rd.bottom = rfull.bottom;
  471. rs.bottom = height - (int)(diff * sc);
  472. }
  473. if (rd.top < rfull.top)
  474. {
  475. int diff = rfull.top - rd.top;
  476. float sc = (float)(height) / (float)(rd.bottom - rd.top);
  477. rd.top = rfull.top;
  478. rs.top = (int)(diff * sc);
  479. }
  480. }
  481. if (capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC && uDestSizeAlign)
  482. {
  483. rs.left = (int)((rs.left + uDestSizeAlign - 1) / uDestSizeAlign) * uDestSizeAlign;
  484. rs.right = (int)((rs.right + uDestSizeAlign - 1) / uDestSizeAlign) * uDestSizeAlign;
  485. }
  486. if (capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST && uDestSizeAlign)
  487. {
  488. rd.left = (int)((rd.left + uDestSizeAlign - 1) / uDestSizeAlign) * uDestSizeAlign;
  489. rd.right = (int)((rd.right + uDestSizeAlign - 1) / uDestSizeAlign) * uDestSizeAlign;
  490. }
  491. *drd = rd;
  492. *drs = rs;
  493. }
  494. void OverlayVideoOutput::timerCallback()
  495. {
  496. if (!adjuster)
  497. return;
  498. RECT rd, rs;
  499. getRects(&rs, &rd);
  500. if (memcmp(&m_oldrd, &rd, sizeof(RECT)))
  501. {
  502. m_oldrd = rd;
  503. if (!initing && lpddsOverlay)
  504. if (FAILED(lpddsOverlay->UpdateOverlay(&rs, lpddsPrimary, &rd, dwUpdateFlags, &ovfx)))
  505. {
  506. needchange = 1;
  507. }
  508. InvalidateRect(parent, NULL, FALSE);
  509. }
  510. }
  511. int OverlayVideoOutput::onPaint(HWND hwnd)
  512. {
  513. if (!adjuster)
  514. return 0;
  515. PAINTSTRUCT p;
  516. BeginPaint(hwnd, &p);
  517. if (!m_closed)
  518. {
  519. RECT r, rs, rfull, clientRect;
  520. RECT drawRect;
  521. getRects(&rs, &r, 0); // we don't just fill the entire client rect, cause that looks gross
  522. getViewport(&rfull, hwnd, 1, NULL);
  523. // go from this screen coords to global coords
  524. r.left += rfull.left;
  525. r.top += rfull.top;
  526. r.right += rfull.left;
  527. r.bottom += rfull.top;
  528. // go from global back to client
  529. ScreenToClient(hwnd, (LPPOINT)&r);
  530. ScreenToClient(hwnd, ((LPPOINT)&r) + 1);
  531. HBRUSH br = (HBRUSH) GetStockObject(BLACK_BRUSH);
  532. GetClientRect(hwnd, &clientRect);
  533. // left black box
  534. drawRect.left = clientRect.left;
  535. drawRect.right = r.left;
  536. drawRect.top = clientRect.top;
  537. drawRect.bottom = clientRect.bottom;
  538. FillRect(p.hdc, &drawRect, br);
  539. // right black box
  540. drawRect.left = r.right;
  541. drawRect.right = clientRect.right;
  542. drawRect.top = clientRect.top;
  543. drawRect.bottom = clientRect.bottom;
  544. FillRect(p.hdc, &drawRect, br);
  545. // top black box
  546. drawRect.left = clientRect.left;
  547. drawRect.right = clientRect.right;
  548. drawRect.top = clientRect.top;
  549. drawRect.bottom = r.top;
  550. FillRect(p.hdc, &drawRect, br);
  551. // bottom black box
  552. drawRect.left = clientRect.left;
  553. drawRect.right = clientRect.right;
  554. drawRect.top = r.bottom;
  555. drawRect.bottom = clientRect.bottom;
  556. FillRect(p.hdc, &drawRect, br);
  557. LOGBRUSH lb = {BS_SOLID, (COLORREF)overlay_color, };
  558. br = CreateBrushIndirect(&lb);
  559. FillRect(p.hdc, &r, br);
  560. DeleteObject(br);
  561. }
  562. EndPaint(hwnd, &p);
  563. return 1;
  564. }
  565. void OverlayVideoOutput::displayFrame(const char * /*buf*/, int size, int time)
  566. {
  567. if (m_closed)
  568. return;
  569. DDSURFACEDESC dd = {sizeof(dd), };
  570. //CT> vsync wait not used anymore
  571. //if (config_video.vsync()) lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN,0);
  572. HRESULT result;
  573. //if ((result=lpddsOverlay->Lock(NULL,&dd,DDLOCK_WAIT,NULL)) != DD_OK) {
  574. if ((result = lpBackBuffer->Lock(NULL, &dd, DDLOCK_WAIT, NULL)) != DD_OK)
  575. {
  576. if (result == DDERR_SURFACELOST) needchange = 1;
  577. return ;
  578. }
  579. if (type == VIDEO_MAKETYPE('Y', 'V', '1', '2'))
  580. {
  581. const YV12_PLANES *planes = (YV12_PLANES *)frame;
  582. if (uyvy_output)
  583. YV12_to_UYVY((unsigned char*)dd.lpSurface, planes, dd.lPitch, width, height, flip);
  584. else if (yuy2_output)
  585. YV12_to_YUY2((unsigned char*)dd.lpSurface, planes, dd.lPitch, width, height, flip);
  586. else
  587. YV12_to_YV12((unsigned char*)dd.lpSurface, planes, dd.lPitch, width, height, flip);
  588. }
  589. else if (type == VIDEO_MAKETYPE('Y', 'U', 'Y', '2'))
  590. {
  591. if (yuy2_output)
  592. YUY2_to_YUY2((unsigned char*)dd.lpSurface, (const char *)frame, dd.lPitch, width, height, flip);
  593. else if (uyvy_output)
  594. YUY2_to_UYVY((unsigned char*)dd.lpSurface, (const char *)frame, dd.lPitch, width, height, flip);
  595. else
  596. YUY2_to_YUY2((unsigned char*)dd.lpSurface, (const char *)frame, dd.lPitch, width, height, flip); // is this right?
  597. }
  598. else if (type == VIDEO_MAKETYPE('U', 'Y', 'V', 'Y'))
  599. {
  600. if (yuy2_output)
  601. YUY2_to_UYVY((unsigned char*)dd.lpSurface, (const char *)frame, dd.lPitch, width, height, flip);
  602. else
  603. YUY2_to_YUY2((unsigned char*)dd.lpSurface, (const char *)frame, dd.lPitch, width, height, flip);
  604. }
  605. lpBackBuffer->Unlock(&dd);
  606. lpddsOverlay->Flip(lpBackBuffer, DDFLIP_WAIT);
  607. }
  608. void OverlayVideoOutput::drawSubtitle(SubsItem *item)
  609. {
  610. }
  611. void OverlayVideoOutput::resetSubtitle()
  612. {
  613. }