MythTV  master
mythrender_d3d9.cpp
Go to the documentation of this file.
1 #define _WIN32_WINNT 0x500
2 
3 #include <algorithm>
4 using std::min;
5 
6 #include <QLibrary>
7 #include <QRect>
8 #include <QMap>
9 #include <QMutex>
10 
11 #include "mythlogging.h"
12 #include "mythrender_d3d9.h"
13 
14 #define DXVA2_E_NEW_VIDEO_DEVICE MAKE_HRESULT(1, 4, 4097)
15 
17 {
18  public:
19  explicit MythD3DVertexBuffer(IDirect3DTexture9* tex = nullptr) :
20  m_dest(QRect(QPoint(0,0),QSize(0,0))),
21  m_src(QRect(QPoint(0,0),QSize(0,0))), m_texture(tex)
22  {
23  }
24 
25  uint32_t m_color {0xFFFFFFFF};
26  QRect m_dest;
27  QRect m_src;
28  IDirect3DTexture9 *m_texture;
29 };
30 
32 {
33  public:
34  MythD3DSurface(QSize size = QSize(0,0), D3DFORMAT fmt = D3DFMT_UNKNOWN) :
35  m_size(size), m_fmt(fmt)
36  {
37  }
38 
39  QSize m_size;
40  D3DFORMAT m_fmt;
41 };
42 
44 {
45  FLOAT x;
46  FLOAT y;
47  FLOAT z;
48  FLOAT rhw;
49  D3DCOLOR diffuse;
50  FLOAT t1u;
51  FLOAT t1v;
52  FLOAT t2u;
53  FLOAT t2v;
54 };
55 
56 struct VERTEX
57 {
58  FLOAT x;
59  FLOAT y;
60  FLOAT z;
61  FLOAT rhw;
62  D3DCOLOR diffuse;
63 };
64 
65 D3D9Image::D3D9Image(MythRenderD3D9 *render, QSize size, bool video)
66  : m_size(size), m_render(render)
67 {
68  if (m_render)
69  {
73  }
75 }
76 
78 {
79  if (!m_render)
80  return;
81 
82  if (m_texture)
84  if (m_vertexbuffer)
86  if (m_surface)
88 }
89 
91 {
92  if (m_valid)
94  return m_valid;
95 }
96 
97 bool D3D9Image::UpdateImage(IDirect3DSurface9 *surface)
98 {
99  if (m_valid)
100  return m_render->StretchRect(m_texture, surface, false);
101  return false;
102 }
103 
105 {
106  bool result = true;
107  if (m_valid)
108  {
109  result &= m_render->UpdateSurface(m_surface, img);
111  }
112  return m_valid && result;
113 }
114 
115 bool D3D9Image::UpdateVertices(const QRect &dvr, const QRect &vr, int alpha,
116  bool video)
117 {
118  if (m_valid)
119  return m_render->UpdateVertexBuffer(m_vertexbuffer, dvr, vr,
120  alpha, video);
121  return m_valid;
122 }
123 
124 bool D3D9Image::Draw(void)
125 {
126  if (m_valid)
128  return m_valid;
129 }
130 
131 uint8_t* D3D9Image::GetBuffer(bool &hardware_conv, uint &pitch)
132 {
133  if (!m_valid)
134  return nullptr;
135 
136  hardware_conv = m_render->HardwareYUVConversion();
137  return m_render->GetBuffer(m_surface, pitch);
138 }
139 
141 {
142  if (!m_valid)
143  return;
146 }
147 
149 {
150  if (!m_valid)
151  return QRect();
153 }
154 
155 #define mD3DFMT_YV12 (D3DFORMAT)MAKEFOURCC('Y','V','1','2')
156 #define mD3DFMT_IYUV (D3DFORMAT)MAKEFOURCC('I','Y','U','V')
157 #define mD3DFMT_I420 (D3DFORMAT)MAKEFOURCC('I','4','2','0')
158 #define mD3DFMT_YV16 (D3DFORMAT)MAKEFOURCC('Y','V','1','6')
159 #define D3DFVF_TEXTUREVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1|D3DFVF_TEX2)
160 #define D3DFVF_VERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
161 #define D3DLOC QString("MythRenderD3D9: ")
162 
164 {
165  if (m_render)
167 }
168 
169 IDirect3DDevice9* D3D9Locker::Acquire(void)
170 {
171  IDirect3DDevice9* result = nullptr;
172  if (m_render)
173  result = m_render->AcquireDevice();
174  if (!result)
175  LOG(VB_GENERAL, LOG_ERR, "D3D9Locker: Failed to acquire device.");
176  return result;
177 }
178 
179 void* MythRenderD3D9::ResolveAddress(const char* lib, const char* proc)
180 {
181  return QLibrary::resolve(lib, proc);
182 }
183 
185 {
186  QMutexLocker locker(&m_lock);
187 
188  LOG(VB_GENERAL, LOG_INFO, D3DLOC + "Deleting D3D9 resources.");
189 
191  m_rect_vertexbuffer->Release();
192  if (m_current_surface)
193  m_current_surface->Release();
194  if (m_default_surface)
195  m_default_surface->Release();
196 
197  DeleteTextures();
199  DeleteSurfaces();
200 
202 
203  if (m_rootD3DDevice)
204  {
205  LOG(VB_GENERAL, LOG_INFO, D3DLOC + "Deleting D3D9 device.");
206  m_rootD3DDevice->Release();
207  }
208 
209  if (m_d3d)
210  {
211  LOG(VB_GENERAL, LOG_INFO, D3DLOC + "Deleting D3D9.");
212  m_d3d->Release();
213  }
214 }
215 
216 static const QString toString(D3DFORMAT fmt)
217 {
218  switch (fmt)
219  {
220  case D3DFMT_A8:
221  return "A8";
222  case D3DFMT_A8R8G8B8:
223  return "A8R8G8B8";
224  case D3DFMT_X8R8G8B8:
225  return "X8R8G8B8";
226  case D3DFMT_A8B8G8R8:
227  return "A8B8G8R8";
228  case D3DFMT_X8B8G8R8:
229  return "X8B8G8R8";
230  case mD3DFMT_YV12:
231  return "YV12";
232  case D3DFMT_UYVY:
233  return "UYVY";
234  case D3DFMT_YUY2:
235  return "YUY2";
236  case mD3DFMT_IYUV:
237  return "IYUV";
238  case mD3DFMT_I420:
239  return "I420";
240  case mD3DFMT_YV16:
241  return "YV16";
242  default:
243  break;
244  }
245  return QString().setNum((ulong)fmt,16);
246 }
247 
248 bool MythRenderD3D9::Create(QSize size, HWND window)
249 {
250  QMutexLocker locker(&m_lock);
251 
252  using LPFND3DC = LPDIRECT3D9 (WINAPI *)(UINT SDKVersion);
253  static LPFND3DC OurDirect3DCreate9 = nullptr;
254 
255  OurDirect3DCreate9 = (LPFND3DC)ResolveAddress("D3D9","Direct3DCreate9");
256  if (!OurDirect3DCreate9)
257  {
258  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
259  "FATAL: Failed to find Direct3DCreate9.");
260  return false;
261  }
262 
263  m_d3d = OurDirect3DCreate9(D3D_SDK_VERSION);
264  if (!m_d3d)
265  {
266  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
267  "Could not create Direct3D9 instance.");
268  return false;
269  }
270 
271  D3DCAPS9 d3dCaps;
272  ZeroMemory(&d3dCaps, sizeof(d3dCaps));
273  if (D3D_OK != m_d3d->GetDeviceCaps(
274  D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))
275  {
276  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
277  "Could not read adapter capabilities.");
278  }
279 
280  D3DDISPLAYMODE d3ddm;
281  if (D3D_OK != m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))
282  {
283  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
284  "Could not read adapter display mode.");
285  return false;
286  }
287 
288  // Check the adaptor format is reasonable
289  static const D3DFORMAT bfmt[] =
290  {
291  D3DFMT_A8R8G8B8,
292  D3DFMT_A8B8G8R8,
293  D3DFMT_X8R8G8B8,
294  D3DFMT_X8B8G8R8,
295  D3DFMT_R8G8B8
296  };
297 
298  m_adaptor_fmt = d3ddm.Format;
299  bool is_reasonable = false;
300  for (uint i = 0; i < sizeof(bfmt) / sizeof(bfmt[0]); i++)
301  if (bfmt[i] == m_adaptor_fmt)
302  is_reasonable = true;
303  LOG(VB_GENERAL, LOG_INFO, D3DLOC + QString("Default adaptor format %1.")
305  if (!is_reasonable)
306  {
307  LOG(VB_GENERAL, LOG_WARNING, D3DLOC +
308  "Warning: Default adaptor format may not work.");
309  }
310 
311  // Choose a surface format
312  for (unsigned i = 0; i < sizeof bfmt / sizeof bfmt[0]; ++i)
313  {
314  if (SUCCEEDED(m_d3d->CheckDeviceType(D3DADAPTER_DEFAULT,
315  D3DDEVTYPE_HAL, m_adaptor_fmt, bfmt[i], TRUE)))
316  {
317  m_surface_fmt = bfmt[i];
318  break;
319  }
320  }
321 
322  if (D3DFMT_UNKNOWN == m_surface_fmt)
323  {
324  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to choose surface format - "
325  "using default back buffer format.");
327  }
328 
330  LOG(VB_GENERAL, LOG_INFO, D3DLOC +
331  QString("Chosen surface and texture format: %1")
333 
334 
335  // Test whether a YV12 video surface is available
336  if (FAILED(m_d3d->CheckDeviceFormatConversion(D3DADAPTER_DEFAULT,
337  D3DDEVTYPE_HAL, D3DFMT_UNKNOWN, m_adaptor_fmt)) &&
338  SUCCEEDED(m_d3d->CheckDeviceFormatConversion(D3DADAPTER_DEFAULT,
339  D3DDEVTYPE_HAL, mD3DFMT_YV12, m_surface_fmt)))
340  {
342  }
343  else
344  {
346  }
347 
348  LOG(VB_GENERAL, LOG_INFO, D3DLOC +
349  QString("Chosen video surface format %1.")
351  LOG(VB_GENERAL, LOG_INFO, D3DLOC +
352  QString("Hardware YV12 to RGB conversion %1.")
354  "unavailable" : "available"));
355 
356  D3DPRESENT_PARAMETERS d3dpp;
357  ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
358  d3dpp.BackBufferFormat = m_adaptor_fmt;
359  d3dpp.hDeviceWindow = window;
360  d3dpp.Windowed = true;
361  d3dpp.BackBufferWidth = size.width();
362  d3dpp.BackBufferHeight = size.height();
363  d3dpp.BackBufferCount = 1;
364  d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
365  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
366  d3dpp.Flags = D3DPRESENTFLAG_VIDEO;
367  d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
368 
369  if (D3D_OK != m_d3d->CreateDevice(D3DADAPTER_DEFAULT,
370  D3DDEVTYPE_HAL, d3dpp.hDeviceWindow,
371  D3DCREATE_SOFTWARE_VERTEXPROCESSING |
372  D3DCREATE_MULTITHREADED,
373  &d3dpp, &m_rootD3DDevice))
374  {
375  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Could not create the D3D device.");
376  return false;
377  }
378 
379  static bool debugged = false;
380  if (!debugged)
381  {
382  debugged = true;
383  D3DADAPTER_IDENTIFIER9 ident;
384  if (D3D_OK == m_d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident))
385  {
386  LOG(VB_GENERAL, LOG_INFO, D3DLOC + QString("Device: %1")
387  .arg(ident.Description));
388  LOG(VB_GENERAL, LOG_INFO, D3DLOC +QString("Driver: %1.%2.%3.%4")
389  .arg(HIWORD(ident.DriverVersion.HighPart))
390  .arg(LOWORD(ident.DriverVersion.HighPart))
391  .arg(HIWORD(ident.DriverVersion.LowPart))
392  .arg(LOWORD(ident.DriverVersion.LowPart)));
393  }
394  }
395 
397  Init2DState();
398  return true;
399 }
400 
402 {
404 }
405 
406 bool MythRenderD3D9::Test(bool &reset)
407 {
408  D3D9Locker locker(this);
409  IDirect3DDevice9* dev = locker.Acquire();
410  if (!dev)
411  return false;
412 
413  bool result = true;
414  HRESULT hr = dev->TestCooperativeLevel();
415  if (FAILED(hr))
416  {
417  switch (hr)
418  {
419  case D3DERR_DEVICENOTRESET:
420  LOG(VB_GENERAL, LOG_NOTICE, D3DLOC +
421  "The device was lost and needs to be reset.");
422  result = false;
423  reset = true;
424  break;
425 
426  case D3DERR_DEVICELOST:
427  LOG(VB_GENERAL, LOG_NOTICE, D3DLOC +
428  "The device has been lost and cannot be reset "
429  "at this time.");
430  result = false;
431  break;
432 
433  case D3DERR_DRIVERINTERNALERROR:
434  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
435  "Internal driver error. "
436  "Please shut down the application.");
437  result = false;
438  break;
439 
440  default:
441  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
442  "TestCooperativeLevel() failed.");
443  result = false;
444  }
445  }
446  return result;
447 }
448 
450 {
451  D3D9Locker locker(this);
452  IDirect3DDevice9* dev = locker.Acquire();
453  if (!dev)
454  return false;
455 
456  HRESULT hr = dev->Clear(0, nullptr, D3DCLEAR_TARGET,
457  D3DCOLOR_ARGB(0, 0, 0, 0), 1.0F, 0);
458  if (FAILED(hr))
459  {
460  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Clear() failed.");
461  return false;
462  }
463  return true;
464 }
465 
467 {
468  D3D9Locker locker(this);
469  IDirect3DDevice9* dev = locker.Acquire();
470  if (!dev)
471  return false;
472 
473  HRESULT hr = dev->BeginScene();
474  if (FAILED(hr))
475  {
476  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "BeginScene() failed.");
477  return false;
478  }
479  return true;
480 }
481 
483 {
484  D3D9Locker locker(this);
485  IDirect3DDevice9* dev = locker.Acquire();
486  if (!dev)
487  return false;
488 
489  HRESULT hr = dev->EndScene();
490  if (FAILED(hr))
491  {
492  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "EndScene() failed.");
493  return false;
494  }
495  return true;
496 }
497 
498 void MythRenderD3D9::CopyFrame(void* surface, D3D9Image *img)
499 {
500  if (surface && img)
501  img->UpdateImage((IDirect3DSurface9*)surface);
502 }
503 
504 bool MythRenderD3D9::StretchRect(IDirect3DTexture9 *texture,
505  IDirect3DSurface9 *surface,
506  bool known_surface)
507 {
508  if (!m_textures.contains(texture) ||
509  (known_surface && !m_surfaces.contains(surface)))
510  return false;
511 
512  D3D9Locker locker(this);
513  IDirect3DDevice9* dev = locker.Acquire();
514  if (!dev)
515  return false;
516 
517  LPDIRECT3DSURFACE9 d3ddest;
518  HRESULT hr = texture->GetSurfaceLevel(0, &d3ddest);
519  if (FAILED(hr))
520  {
521  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "GetSurfaceLevel() failed");
522  return false;
523  }
524 
525  hr = dev->StretchRect(surface, nullptr, d3ddest,
526  nullptr, D3DTEXF_POINT);
527  d3ddest->Release();
528  if (FAILED(hr))
529  {
530  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "StretchRect() failed");
531  return false;
532  }
533  return true;
534 }
535 
536 bool MythRenderD3D9::DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer)
537 {
538  if (!m_vertexbuffers.contains(vertexbuffer))
539  return false;
540 
541  D3D9Locker locker(this);
542  IDirect3DDevice9* dev = locker.Acquire();
543  if (!dev)
544  return false;
545 
546  IDirect3DTexture9 *texture = m_vertexbuffers[vertexbuffer].m_texture;
547 
548  if (texture && !SetTexture(dev, texture))
549  return false;
550 
551  EnableBlending(dev, true);
552  SetTextureVertices(dev, true);
553  MultiTexturing(dev, false);
554 
555  HRESULT hr = dev->SetStreamSource(0, vertexbuffer,
556  0, sizeof(TEXTUREVERTEX));
557  if (FAILED(hr))
558  {
559  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "SetStreamSource() failed");
560  return false;
561  }
562 
563  hr = dev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
564  if (FAILED(hr))
565  {
566  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "DrawPrimitive() failed");
567  return false;
568  }
569 
570  return true;
571 }
572 
573 void MythRenderD3D9::DrawRect(const QRect &rect, const QColor &color, int alpha)
574 {
575  D3D9Locker locker(this);
576  IDirect3DDevice9* dev = locker.Acquire();
577  if (!dev)
578  return;
579 
580  if (!m_rect_vertexbuffer)
581  {
582  HRESULT hr = dev->CreateVertexBuffer(
583  sizeof(VERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
584  D3DFVF_VERTEX, D3DPOOL_DEFAULT,
585  &m_rect_vertexbuffer, nullptr);
586 
587  if (FAILED(hr))
588  {
589  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to create vertex buffer");
590  return;
591  }
592  }
593 
594  EnableBlending(dev, true);
595  SetTextureVertices(dev, false);
596  MultiTexturing(dev, false);
597  SetTexture(dev, nullptr, 0);
598 
599  int alphamod = (int)(color.alpha() * (alpha / 255.0));
600  D3DCOLOR clr = D3DCOLOR_ARGB(alphamod, color.red(),
601  color.green(), color.blue());
602  VERTEX *p_vertices;
603  HRESULT hr = m_rect_vertexbuffer->Lock(0, 0, (VOID **)(&p_vertices),
604  D3DLOCK_DISCARD);
605  if (FAILED(hr))
606  {
607  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to lock vertex buffer.");
608  return;
609  }
610 
611  p_vertices[0].x = (float)rect.left();
612  p_vertices[0].y = (float)rect.top();
613  p_vertices[0].z = 0.0F;
614  p_vertices[0].diffuse = clr;
615  p_vertices[0].rhw = 1.0F;
616  p_vertices[1].x = (float)(rect.left() + rect.width());
617  p_vertices[1].y = (float)rect.top();
618  p_vertices[1].z = 0.0F;
619  p_vertices[1].diffuse = clr;
620  p_vertices[1].rhw = 1.0F;
621  p_vertices[2].x = (float)(rect.left() + rect.width());
622  p_vertices[2].y = (float)(rect.top() + rect.height());
623  p_vertices[2].z = 0.0F;
624  p_vertices[2].diffuse = clr;
625  p_vertices[2].rhw = 1.0F;
626  p_vertices[3].x = (float)rect.left();
627  p_vertices[3].y = (float)(rect.top() + rect.height());
628  p_vertices[3].z = 0.0F;
629  p_vertices[3].diffuse = clr;
630  p_vertices[3].rhw = 1.0F;
631 
632  hr = m_rect_vertexbuffer->Unlock();
633  if (FAILED(hr))
634  {
635  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to unlock vertex buffer");
636  return;
637  }
638 
639  hr = dev->SetStreamSource(0, m_rect_vertexbuffer,
640  0, sizeof(VERTEX));
641  if (FAILED(hr))
642  {
643  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "SetStreamSource() failed");
644  return;
645  }
646 
647  hr = dev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
648  if (FAILED(hr))
649  {
650  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "DrawPrimitive() failed");
651  return;
652  }
653 }
654 
655 void MythRenderD3D9::MultiTexturing(IDirect3DDevice9* dev, bool enable,
656  IDirect3DTexture9 *texture)
657 {
658  if (m_multi_texturing == enable)
659  return;
660 
661  if (!dev)
662  return;
663 
664  if (enable)
665  {
666  SetTexture(dev, texture, 1);
667  dev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
668  dev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
669  dev->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
670  dev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
671  dev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
672  dev->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
673  dev->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
674  dev->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
675  }
676  else
677  {
678  dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
679  dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
680  dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
681  dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
682  dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
683  dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
684  dev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
685  dev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
686  SetTexture(dev, nullptr, 1);
687  }
688  m_multi_texturing = enable;
689 }
690 
692 {
693  D3D9Locker locker(this);
694  IDirect3DDevice9* dev = locker.Acquire();
695  if (!dev)
696  return false;
697 
698  HRESULT hr = dev->Present(nullptr, nullptr, win, nullptr);
699  if (FAILED(hr))
700  {
701  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Present() failed)");
702  return false;
703  }
704  SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
705  return true;
706 }
707 
708 QRect MythRenderD3D9::GetRect(IDirect3DVertexBuffer9 *vertexbuffer)
709 {
710  if (!m_vertexbuffers.contains(vertexbuffer))
711  return QRect();
712  return m_vertexbuffers[vertexbuffer].m_dest;
713 }
714 
715 bool MythRenderD3D9::SetRenderTarget(IDirect3DTexture9 *texture)
716 {
717  D3D9Locker locker(this);
718  IDirect3DDevice9* dev = locker.Acquire();
719  if (!dev)
720  return false;
721 
722  bool ret = true;
723  HRESULT hr;
724  if (texture && m_textures.contains(texture))
725  {
726  if (!m_default_surface)
727  {
728  hr = dev->GetRenderTarget(0, &m_default_surface);
729  if (FAILED(hr))
730  {
731  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
732  "Failed to get default surface.");
733  return false;
734  }
735  }
736 
737  IDirect3DSurface9 *new_surface = nullptr;
738  hr = texture->GetSurfaceLevel(0, &new_surface);
739  if (FAILED(hr))
740  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to get surface level.");
741  else
742  {
743  if (m_current_surface && m_current_surface != new_surface)
744  m_current_surface->Release();
745  m_current_surface = new_surface;
746  hr = dev->SetRenderTarget(0, m_current_surface);
747  if (FAILED(hr))
748  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
749  "Failed to set render target.");
750  }
751  }
752  else if (!texture)
753  {
754  if (m_default_surface)
755  {
756  hr = dev->SetRenderTarget(0, m_default_surface);
757  if (FAILED(hr))
758  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
759  "Failed to set render target.");
760  }
761  else
762  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
763  "No default surface for render target.");
764  }
765  else
766  ret = false;
767  return ret;
768 }
769 
770 bool MythRenderD3D9::SetTexture(IDirect3DDevice9* dev,
771  IDirect3DTexture9 *texture, int num)
772 {
773  if (!dev)
774  return false;
775 
776  HRESULT hr = dev->SetTexture(num, (LPDIRECT3DBASETEXTURE9)texture);
777  if (FAILED(hr))
778  {
779  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "SetTexture() failed");
780  return false;
781  }
782  return true;
783 }
784 
785 IDirect3DTexture9* MythRenderD3D9::CreateTexture(const QSize &size)
786 {
787  D3D9Locker locker(this);
788  IDirect3DDevice9* dev = locker.Acquire();
789  if (!dev)
790  return nullptr;
791 
792  IDirect3DTexture9* temp_texture = nullptr;
793 
794  HRESULT hr = dev->CreateTexture(
795  size.width(), size.height(), 1, D3DUSAGE_RENDERTARGET,
796  m_texture_fmt, D3DPOOL_DEFAULT, &temp_texture, nullptr);
797 
798  if (FAILED(hr) || !temp_texture)
799  {
800  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to create texture.");
801  return nullptr;
802  }
803 
804  m_textures[temp_texture] = size;;
805  return temp_texture;
806 }
807 
809 {
810  QMap<IDirect3DTexture9*,QSize>::iterator it;
811  for (it = m_textures.begin(); it != m_textures.end(); ++it)
812  it.key()->Release();
813  m_textures.clear();
814 }
815 
816 void MythRenderD3D9::DeleteTexture(IDirect3DTexture9* texture)
817 {
818  QMutexLocker locker(&m_lock);
819  if (m_textures.contains(texture))
820  {
821  texture->Release();
822  m_textures.remove(texture);
823  }
824 }
825 
826 IDirect3DSurface9* MythRenderD3D9::CreateSurface(const QSize &size, bool video)
827 {
828  D3D9Locker locker(this);
829  IDirect3DDevice9* dev = locker.Acquire();
830  if (!dev)
831  return nullptr;
832 
833  IDirect3DSurface9* temp_surface = nullptr;
834 
835  D3DFORMAT format = video ? m_videosurface_fmt : m_surface_fmt;
836 
837  HRESULT hr = dev->CreateOffscreenPlainSurface(
838  size.width(), size.height(), format,
839  D3DPOOL_DEFAULT, &temp_surface, nullptr);
840 
841  if (FAILED(hr)|| !temp_surface)
842  {
843  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to create surface.");
844  return nullptr;
845  }
846 
847  m_surfaces[temp_surface] = MythD3DSurface(size, format);
848  dev->ColorFill(temp_surface, nullptr, D3DCOLOR_ARGB(0xFF, 0, 0, 0) );
849 
850  return temp_surface;
851 }
852 
853 bool MythRenderD3D9::UpdateSurface(IDirect3DSurface9 *surface,
854  const MythImage *image)
855 {
856  if (!surface || !image || !m_surfaces.contains(surface))
857  return false;
858 
859  if (m_surfaces[surface].m_size.width() != image->width() ||
860  m_surfaces[surface].m_size.height() != image->height())
861  {
862  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
863  "Frame size does not equal surface size.");
864  return false;
865  }
866 
867  uint d3dpitch = 0;
868  uint8_t *buf = GetBuffer(surface, d3dpitch);
869 
870  if (!(buf && d3dpitch))
871  return false;
872 
873  D3DFORMAT format = m_surfaces[surface].m_fmt;
874  switch (format)
875  {
876  case D3DFMT_A8R8G8B8:
877  case D3DFMT_X8R8G8B8:
878  {
879  uint pitch = image->width() << 2;
880  uint8_t *dst = buf;
881  uint8_t *src = (uint8_t*)image->bits();
882  for (int i = 0; i < image->height(); i++)
883  {
884  memcpy(dst, src, pitch);
885  dst += d3dpitch;
886  src += pitch;
887  }
888  }
889  break;
890  default:
891  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Surface format not supported.");
892  break;
893  }
894 
895  ReleaseBuffer(surface);
896  return true;
897 }
898 
900 {
901  QMap<IDirect3DSurface9*, MythD3DSurface>::iterator it;
902  for (it = m_surfaces.begin(); it != m_surfaces.end(); ++it)
903  it.key()->Release();
904  m_surfaces.clear();
905 }
906 
907 void MythRenderD3D9::DeleteSurface(IDirect3DSurface9 *surface)
908 {
909  QMutexLocker locker(&m_lock);
910  if (m_surfaces.contains(surface))
911  {
912  surface->Release();
913  m_surfaces.remove(surface);
914  }
915 }
916 
917 uint8_t* MythRenderD3D9::GetBuffer(IDirect3DSurface9* surface, uint &pitch)
918 {
919  if (!m_surfaces.contains(surface))
920  return nullptr;
921 
922  m_lock.lock(); // unlocked in release buffer
923  D3DLOCKED_RECT d3drect;
924  HRESULT hr = surface->LockRect(&d3drect, nullptr, 0);
925 
926  if (FAILED(hr))
927  {
928  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to lock picture surface.");
929  m_lock.unlock();
930  return false;
931  }
932 
933  pitch = d3drect.Pitch;
934  return (uint8_t*)d3drect.pBits;
935 }
936 
937 void MythRenderD3D9::ReleaseBuffer(IDirect3DSurface9* surface)
938 {
939  if (!m_surfaces.contains(surface))
940  return;
941 
942  HRESULT hr = surface->UnlockRect();
943  if (FAILED(hr))
944  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to unlock picture surface.");
945  m_lock.unlock();
946 }
947 
948 IDirect3DVertexBuffer9* MythRenderD3D9::CreateVertexBuffer(IDirect3DTexture9* texture)
949 {
950  D3D9Locker locker(this);
951  IDirect3DDevice9* dev = locker.Acquire();
952  if (!dev)
953  return nullptr;
954 
955  if (texture && !m_textures.contains(texture))
956  return false;
957 
958  IDirect3DVertexBuffer9* temp_vbuf = nullptr;
959  HRESULT hr = dev->CreateVertexBuffer(
960  sizeof(TEXTUREVERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
961  D3DFVF_TEXTUREVERTEX, D3DPOOL_DEFAULT,
962  &temp_vbuf, nullptr);
963 
964  if (FAILED(hr))
965  {
966  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to create vertex buffer");
967  return false;
968  }
969 
970  m_vertexbuffers[temp_vbuf] = MythD3DVertexBuffer(texture);
971  return temp_vbuf;
972 }
973 
975 {
976  QMap<IDirect3DVertexBuffer9*,MythD3DVertexBuffer>::iterator it;
977  for (it = m_vertexbuffers.begin();
978  it != m_vertexbuffers.end(); ++it)
979  {
980  it.key()->Release();
981  }
982  m_vertexbuffers.clear();
983 }
984 
985 void MythRenderD3D9::DeleteVertexBuffer(IDirect3DVertexBuffer9 *vertexbuffer)
986 {
987  QMutexLocker locker(&m_lock);
988  if (m_vertexbuffers.contains(vertexbuffer))
989  {
990  vertexbuffer->Release();
991  m_vertexbuffers.remove(vertexbuffer);
992  }
993 }
994 
995 bool MythRenderD3D9::UpdateVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer,
996  const QRect &dst, const QRect &src,
997  int alpha, bool video)
998 {
999  if (!m_vertexbuffers.contains(vertexbuffer))
1000  return false;
1001 
1002  MythD3DVertexBuffer mythvb = m_vertexbuffers[vertexbuffer];
1003  uint32_t clr = (alpha << 24) + (255 << 16) + (255 << 8) + 255;
1004 
1005  int width = dst.width();
1006  int height = dst.height();
1007  if (!video)
1008  {
1009  width = min(src.width(), width);
1010  height = min(src.height(), height);
1011  }
1012  QRect dest(dst.left(), dst.top(), width, height);
1013 
1014  // FIXME - with alpha pulse, this updates far more textures than necessary
1015  if (dest == mythvb.m_dest &&
1016  src == mythvb.m_src &&
1017  clr == mythvb.m_color)
1018  return true;
1019 
1020  QSize norm = src.size();
1021  if (video && mythvb.m_texture)
1022  norm = m_textures[mythvb.m_texture];
1023 
1024  QMutexLocker locker(&m_lock);
1025  TEXTUREVERTEX *p_vertices;
1026  HRESULT hr = vertexbuffer->Lock(0, 0, (VOID **)(&p_vertices),
1027  D3DLOCK_DISCARD);
1028  D3DCOLOR color = D3DCOLOR_ARGB(alpha, 255, 255, 255);
1029  if (FAILED(hr))
1030  {
1031  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to lock vertex buffer.");
1032  return false;
1033  }
1034 
1035  p_vertices[0].x = (float)dest.left();
1036  p_vertices[0].y = (float)dest.top();
1037  p_vertices[0].z = 0.0F;
1038  p_vertices[0].diffuse = color;
1039  p_vertices[0].rhw = 1.0F;
1040  p_vertices[0].t1u = ((float)src.left() - 0.5F) / (float)norm.width();
1041  p_vertices[0].t1v = ((float)src.top() - 0.5F) / (float)norm.height();
1042 
1043  p_vertices[1].x = (float)(dest.left() + dest.width());
1044  p_vertices[1].y = (float)dest.top();
1045  p_vertices[1].z = 0.0F;
1046  p_vertices[1].diffuse = color;
1047  p_vertices[1].rhw = 1.0F;
1048  p_vertices[1].t1u = ((float)(src.left() + src.width()) - 0.5F) /
1049  (float)norm.width();
1050  p_vertices[1].t1v = ((float)src.top() - 0.5F) / (float)norm.height();
1051 
1052  p_vertices[2].x = (float)(dest.left() + dest.width());
1053  p_vertices[2].y = (float)(dest.top() + dest.height());
1054  p_vertices[2].z = 0.0F;
1055  p_vertices[2].diffuse = color;
1056  p_vertices[2].rhw = 1.0F;
1057  p_vertices[2].t1u = ((float)(src.left() + src.width()) - 0.5F) /
1058  (float)norm.width();
1059  p_vertices[2].t1v = ((float)(src.top() + src.height()) - 0.5F) /
1060  (float)norm.height();
1061 
1062  p_vertices[3].x = (float)dest.left();
1063  p_vertices[3].y = (float)(dest.top() + dest.height());
1064  p_vertices[3].z = 0.0F;
1065  p_vertices[3].diffuse = color;
1066  p_vertices[3].rhw = 1.0F;
1067  p_vertices[3].t1u = ((float)src.left() - 0.5F) / (float)norm.width();
1068  p_vertices[3].t1v = ((float)(src.top() + src.height()) - 0.5F) /
1069  (float)norm.height();
1070 
1071  p_vertices[0].t2u = p_vertices[0].t1u;
1072  p_vertices[0].t2v = p_vertices[0].t1v;
1073  p_vertices[1].t2u = p_vertices[1].t1u;
1074  p_vertices[1].t2v = p_vertices[1].t1v;
1075  p_vertices[2].t2u = p_vertices[2].t1u;
1076  p_vertices[2].t2v = p_vertices[2].t1v;
1077  p_vertices[3].t2u = p_vertices[3].t1u;
1078  p_vertices[3].t2v = p_vertices[3].t1v;
1079 
1080  hr = vertexbuffer->Unlock();
1081  if (FAILED(hr))
1082  {
1083  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to unlock vertex buffer");
1084  return false;
1085  }
1086 
1087  m_vertexbuffers[vertexbuffer].m_dest = dest;
1088  m_vertexbuffers[vertexbuffer].m_src = src;
1089  m_vertexbuffers[vertexbuffer].m_color = clr;
1090  return true;
1091 }
1092 
1094 {
1095  IDirect3DDevice9* dev = AcquireDevice();
1096  if (!dev)
1097  return;
1098 
1099  dev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
1100  dev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
1101  dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1102  dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1103  dev->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
1104  dev->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
1105  dev->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1106  dev->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1107  dev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255));
1108  dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
1109  dev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
1110  dev->SetRenderState(D3DRS_LIGHTING, FALSE);
1111  dev->SetRenderState(D3DRS_DITHERENABLE, TRUE);
1112  dev->SetRenderState(D3DRS_STENCILENABLE, FALSE);
1113  dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1114  dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1115  dev->SetVertexShader(nullptr);
1116  SetTextureVertices(dev, false);
1117  MultiTexturing(dev, false);
1118  EnableBlending(dev, false);
1119 
1120  ReleaseDevice();
1121 }
1122 
1123 void MythRenderD3D9::EnableBlending(IDirect3DDevice9* dev, bool enable)
1124 {
1125  if (m_blend == enable)
1126  return;
1127  m_blend = enable;
1128 
1129  if (dev)
1130  dev->SetRenderState(D3DRS_ALPHABLENDENABLE, enable);
1131 }
1132 
1133 void MythRenderD3D9::SetTextureVertices(IDirect3DDevice9* dev, bool enable)
1134 {
1135  if (m_texture_vertices == enable)
1136  return;
1137  m_texture_vertices = enable;
1138 
1139  if (dev)
1140  dev->SetFVF(enable ? D3DFVF_TEXTUREVERTEX : D3DFVF_VERTEX);
1141 }
1142 
1143 IDirect3DDevice9* MythRenderD3D9::AcquireDevice(void)
1144 {
1145  m_lock.lock();
1146 #ifdef USING_DXVA2
1147  if (m_deviceManager)
1148  {
1149  IDirect3DDevice9* result = nullptr;
1150 
1151  HRESULT hr = IDirect3DDeviceManager9_LockDevice(m_deviceManager, m_deviceHandle, &result, true);
1152 
1153  if (hr == DXVA2_E_NEW_VIDEO_DEVICE)
1154  {
1155  hr = IDirect3DDeviceManager9_CloseDeviceHandle(m_deviceManager, m_deviceHandle);
1156 
1157  if (SUCCEEDED(hr))
1158  hr = IDirect3DDeviceManager9_OpenDeviceHandle(m_deviceManager, &m_deviceHandle);
1159 
1160  if (SUCCEEDED(hr))
1161  hr = IDirect3DDeviceManager9_LockDevice(m_deviceManager, m_deviceHandle, &result, true);
1162  }
1163 
1164  if (SUCCEEDED(hr))
1165  return result;
1166 
1167  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to acquire D3D9 device.");
1168  m_lock.unlock();
1169  return nullptr;
1170  }
1171 #endif
1172  return m_rootD3DDevice;
1173 }
1174 
1176 {
1177 #ifdef USING_DXVA2
1178  if (m_deviceManager)
1179  {
1180  HRESULT hr = IDirect3DDeviceManager9_UnlockDevice(m_deviceManager, m_deviceHandle, false);
1181  if (!SUCCEEDED(hr))
1182  LOG(VB_GENERAL, LOG_ERR, D3DLOC + "Failed to release D3D9 device.");
1183  }
1184 #endif
1185  m_lock.unlock();
1186 }
1187 
1188 #ifdef USING_DXVA2
1189 using CreateDeviceManager9Ptr = HRESULT (WINAPI *)(UINT *pResetToken,
1190  IDirect3DDeviceManager9 **);
1191 #endif
1192 
1194 {
1195 #ifdef USING_DXVA2
1196  CreateDeviceManager9Ptr CreateDeviceManager9 =
1198  "DXVA2CreateDirect3DDeviceManager9");
1199  if (CreateDeviceManager9)
1200  {
1201  UINT resetToken = 0;
1202  HRESULT hr = CreateDeviceManager9(&resetToken, &m_deviceManager);
1203  if (SUCCEEDED(hr))
1204  {
1205  IDirect3DDeviceManager9_ResetDevice(m_deviceManager, m_rootD3DDevice, resetToken);
1206  IDirect3DDeviceManager9_AddRef(m_deviceManager);
1207  m_deviceManagerToken = resetToken;
1208  LOG(VB_GENERAL, LOG_INFO, D3DLOC + "Created DXVA2 device manager.");
1209  hr = IDirect3DDeviceManager9_OpenDeviceHandle(m_deviceManager, &m_deviceHandle);
1210  if (SUCCEEDED(hr))
1211  {
1212  LOG(VB_GENERAL, LOG_INFO, D3DLOC + "Retrieved device handle.");
1213  return;
1214  }
1215  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
1216  "Failed to retrieve device handle.");
1217  }
1218  else
1219  {
1220  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
1221  "Failed to create DXVA2 device manager.");
1222  }
1223  }
1224  else
1225  {
1226  LOG(VB_GENERAL, LOG_ERR, D3DLOC +
1227  "Failed to get DXVA2CreateDirect3DDeviceManager9 proc address.");
1228  }
1229 #endif
1230  m_deviceManager = nullptr;
1232  LOG(VB_GENERAL, LOG_NOTICE, D3DLOC +
1233  "DXVA2 support not available - not using device manager");
1234 }
1235 
1237 {
1238 #ifdef USING_DXVA2
1240  IDirect3DDeviceManager9_CloseDeviceHandle(m_deviceManager, m_deviceHandle);
1241  if (m_deviceManager)
1242  IDirect3DDeviceManager9_Release(m_deviceManager);
1243 #endif
1244  m_deviceHandle = nullptr;
1245  m_deviceManager = nullptr;
1246 }
MythRenderD3D9::m_lock
QMutex m_lock
Definition: mythrender_d3d9.h:130
MythD3DSurface::m_fmt
D3DFORMAT m_fmt
Definition: mythrender_d3d9.cpp:40
MythRenderD3D9::m_videosurface_fmt
D3DFORMAT m_videosurface_fmt
Definition: mythrender_d3d9.h:123
build_compdb.dest
dest
Definition: build_compdb.py:9
MythRenderD3D9::DeleteVertexBuffers
void DeleteVertexBuffers(void)
Definition: mythrender_d3d9.cpp:974
MythD3DVertexBuffer
Definition: mythrender_d3d9.cpp:17
MythRenderD3D9::m_surface_fmt
D3DFORMAT m_surface_fmt
Definition: mythrender_d3d9.h:124
MythD3DVertexBuffer::m_color
uint32_t m_color
Definition: mythrender_d3d9.cpp:25
MythRenderD3D9::m_rect_vertexbuffer
IDirect3DVertexBuffer9 * m_rect_vertexbuffer
Definition: mythrender_d3d9.h:126
D3D9Image::UpdateVertices
bool UpdateVertices(const QRect &dvr, const QRect &vr, int alpha=255, bool video=false)
Definition: mythrender_d3d9.cpp:115
D3DFVF_VERTEX
#define D3DFVF_VERTEX
Definition: mythrender_d3d9.cpp:160
D3D9Image::m_vertexbuffer
IDirect3DVertexBuffer9 * m_vertexbuffer
Definition: mythrender_d3d9.h:46
D3D9Image::SetAsRenderTarget
bool SetAsRenderTarget(void)
Definition: mythrender_d3d9.cpp:90
VERTEX
Definition: mythrender_d3d9.cpp:57
MythRenderD3D9::m_textures
QMap< IDirect3DTexture9 *, QSize > m_textures
Definition: mythrender_d3d9.h:116
MythRenderD3D9::DrawTexturedQuad
bool DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer)
Definition: mythrender_d3d9.cpp:536
TEXTUREVERTEX::diffuse
D3DCOLOR diffuse
Definition: mythrender_d3d9.cpp:49
TEXTUREVERTEX::t2v
FLOAT t2v
Definition: mythrender_d3d9.cpp:53
MythRenderD3D9::DeleteVertexBuffer
void DeleteVertexBuffer(IDirect3DVertexBuffer9 *vertexbuffer)
Definition: mythrender_d3d9.cpp:985
MythRenderD3D9::StretchRect
bool StretchRect(IDirect3DTexture9 *texture, IDirect3DSurface9 *surface, bool known_surface=true)
Definition: mythrender_d3d9.cpp:504
MythRenderD3D9::m_deviceManagerToken
uint m_deviceManagerToken
Definition: mythrender_d3d9.h:147
VERTEX::rhw
FLOAT rhw
Definition: mythrender_d3d9.cpp:61
arg
arg(title).arg(filename).arg(doDelete))
toString
static const QString toString(D3DFORMAT fmt)
Definition: mythrender_d3d9.cpp:216
MythRenderD3D9::DeleteTexture
void DeleteTexture(IDirect3DTexture9 *texture)
Definition: mythrender_d3d9.cpp:816
MythRenderD3D9::m_multi_texturing
bool m_multi_texturing
Definition: mythrender_d3d9.h:132
TEXTUREVERTEX::rhw
FLOAT rhw
Definition: mythrender_d3d9.cpp:48
MythD3DVertexBuffer::m_src
QRect m_src
Definition: mythrender_d3d9.cpp:27
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
D3D9Image::~D3D9Image
~D3D9Image()
Definition: mythrender_d3d9.cpp:77
MythRenderD3D9::m_blend
bool m_blend
Definition: mythrender_d3d9.h:131
MythRenderD3D9::CreateVertexBuffer
IDirect3DVertexBuffer9 * CreateVertexBuffer(IDirect3DTexture9 *texture=nullptr)
Definition: mythrender_d3d9.cpp:948
MythRenderD3D9::Create
bool Create(QSize size, HWND window)
Definition: mythrender_d3d9.cpp:248
MythD3DVertexBuffer::m_texture
IDirect3DTexture9 * m_texture
Definition: mythrender_d3d9.cpp:28
MythRenderD3D9::m_current_surface
IDirect3DSurface9 * m_current_surface
Definition: mythrender_d3d9.h:128
video
QDomElement video
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:658
CreateDeviceManager9Ptr
HRESULT(WINAPI *)(UINT *pResetToken, IDirect3DDeviceManager9 **) CreateDeviceManager9Ptr
Definition: mythrender_d3d9.cpp:1190
MythD3DVertexBuffer::m_dest
QRect m_dest
Definition: mythrender_d3d9.cpp:26
MythRenderD3D9::SetTexture
bool SetTexture(IDirect3DDevice9 *dev, IDirect3DTexture9 *texture, int num=0)
Definition: mythrender_d3d9.cpp:770
D3D9Locker::Acquire
IDirect3DDevice9 * Acquire(void)
Definition: mythrender_d3d9.cpp:169
MythRenderD3D9::End
bool End(void)
Definition: mythrender_d3d9.cpp:482
D3D9Image::m_valid
bool m_valid
Definition: mythrender_d3d9.h:44
mD3DFMT_YV12
#define mD3DFMT_YV12
Definition: mythrender_d3d9.cpp:155
MythRenderD3D9::UpdateVertexBuffer
bool UpdateVertexBuffer(IDirect3DVertexBuffer9 *vertexbuffer, const QRect &dvr, const QRect &vr, int alpha=255, bool video=false)
Definition: mythrender_d3d9.cpp:995
TEXTUREVERTEX
Definition: mythrender_d3d9.cpp:44
MythRenderD3D9::m_texture_fmt
D3DFORMAT m_texture_fmt
Definition: mythrender_d3d9.h:125
MythRenderD3D9::ClearBuffer
bool ClearBuffer(void)
Definition: mythrender_d3d9.cpp:449
VERTEX::z
FLOAT z
Definition: mythrender_d3d9.cpp:60
MythD3DSurface::MythD3DSurface
MythD3DSurface(QSize size=QSize(0, 0), D3DFORMAT fmt=D3DFMT_UNKNOWN)
Definition: mythrender_d3d9.cpp:34
mythlogging.h
MythRenderD3D9::CreateTexture
IDirect3DTexture9 * CreateTexture(const QSize &size)
Definition: mythrender_d3d9.cpp:785
MythRenderD3D9::GetBuffer
uint8_t * GetBuffer(IDirect3DSurface9 *surface, uint &pitch)
Definition: mythrender_d3d9.cpp:917
MythRenderD3D9::m_vertexbuffers
QMap< IDirect3DVertexBuffer9 *, MythD3DVertexBuffer > m_vertexbuffers
Definition: mythrender_d3d9.h:117
MythRenderD3D9::GetRect
QRect GetRect(IDirect3DVertexBuffer9 *vertexbuffer)
Definition: mythrender_d3d9.cpp:708
D3D9Image::GetBuffer
uint8_t * GetBuffer(bool &hardware_conv, uint &pitch)
Definition: mythrender_d3d9.cpp:131
MythRenderD3D9::ReleaseDevice
void ReleaseDevice(void)
Definition: mythrender_d3d9.cpp:1175
D3D9Image
Definition: mythrender_d3d9.h:24
MythRenderD3D9::EnableBlending
void EnableBlending(IDirect3DDevice9 *dev, bool enable)
Definition: mythrender_d3d9.cpp:1123
MythRenderD3D9::CreateDeviceManager
void CreateDeviceManager(void)
Definition: mythrender_d3d9.cpp:1193
MythRenderD3D9::m_adaptor_fmt
D3DFORMAT m_adaptor_fmt
Definition: mythrender_d3d9.h:122
MythRenderD3D9::DrawRect
void DrawRect(const QRect &rect, const QColor &color, int alpha)
Definition: mythrender_d3d9.cpp:573
MythRenderD3D9
Definition: mythrender_d3d9.h:63
MythRenderD3D9::Present
bool Present(HWND win)
Definition: mythrender_d3d9.cpp:691
MythD3DVertexBuffer::MythD3DVertexBuffer
MythD3DVertexBuffer(IDirect3DTexture9 *tex=nullptr)
Definition: mythrender_d3d9.cpp:19
MythRenderD3D9::~MythRenderD3D9
virtual ~MythRenderD3D9()
Definition: mythrender_d3d9.cpp:184
MythRenderD3D9::DeleteSurfaces
void DeleteSurfaces(void)
Definition: mythrender_d3d9.cpp:899
D3D9Image::m_texture
IDirect3DTexture9 * m_texture
Definition: mythrender_d3d9.h:47
MythRenderD3D9::m_default_surface
IDirect3DSurface9 * m_default_surface
Definition: mythrender_d3d9.h:127
MythRenderD3D9::ReleaseBuffer
void ReleaseBuffer(IDirect3DSurface9 *surface)
Definition: mythrender_d3d9.cpp:937
mD3DFMT_I420
#define mD3DFMT_I420
Definition: mythrender_d3d9.cpp:157
uint
unsigned int uint
Definition: compat.h:140
MythRenderD3D9::UpdateSurface
bool UpdateSurface(IDirect3DSurface9 *surface, const MythImage *image)
Definition: mythrender_d3d9.cpp:853
MythRenderD3D9::ResolveAddress
static void * ResolveAddress(const char *lib, const char *proc)
Definition: mythrender_d3d9.cpp:179
D3D9Image::GetRect
QRect GetRect(void)
Definition: mythrender_d3d9.cpp:148
MythRenderD3D9::m_surfaces
QMap< IDirect3DSurface9 *, MythD3DSurface > m_surfaces
Definition: mythrender_d3d9.h:118
VERTEX::diffuse
D3DCOLOR diffuse
Definition: mythrender_d3d9.cpp:62
TEXTUREVERTEX::t2u
FLOAT t2u
Definition: mythrender_d3d9.cpp:52
MythRenderD3D9::HardwareYUVConversion
bool HardwareYUVConversion(void)
Definition: mythrender_d3d9.cpp:401
MythRenderD3D9::SetRenderTarget
bool SetRenderTarget(IDirect3DTexture9 *texture)
Definition: mythrender_d3d9.cpp:715
MythRenderD3D9::DeleteTextures
void DeleteTextures(void)
Definition: mythrender_d3d9.cpp:808
MythRenderD3D9::CopyFrame
void CopyFrame(void *surface, D3D9Image *img)
Definition: mythrender_d3d9.cpp:498
MythRenderD3D9::AcquireDevice
IDirect3DDevice9 * AcquireDevice(void)
Definition: mythrender_d3d9.cpp:1143
D3D9Locker
Definition: mythrender_d3d9.h:52
MythRenderD3D9::Init2DState
void Init2DState(void)
Definition: mythrender_d3d9.cpp:1093
D3D9Image::D3D9Image
D3D9Image(MythRenderD3D9 *render, QSize size, bool video=false)
Definition: mythrender_d3d9.cpp:65
D3DLOC
#define D3DLOC
Definition: mythrender_d3d9.cpp:161
MythRenderD3D9::CreateSurface
IDirect3DSurface9 * CreateSurface(const QSize &size, bool video=false)
Definition: mythrender_d3d9.cpp:826
TEXTUREVERTEX::x
FLOAT x
Definition: mythrender_d3d9.cpp:45
MythRenderD3D9::Begin
bool Begin(void)
Definition: mythrender_d3d9.cpp:466
DXVA2_E_NEW_VIDEO_DEVICE
#define DXVA2_E_NEW_VIDEO_DEVICE
Definition: mythrender_d3d9.cpp:14
D3D9Image::UpdateImage
bool UpdateImage(IDirect3DSurface9 *surface)
Definition: mythrender_d3d9.cpp:97
mD3DFMT_YV16
#define mD3DFMT_YV16
Definition: mythrender_d3d9.cpp:158
MythD3DSurface::m_size
QSize m_size
Definition: mythrender_d3d9.cpp:39
MythRenderD3D9::m_deviceManager
IDirect3DDeviceManager9 * m_deviceManager
Definition: mythrender_d3d9.h:145
D3D9Image::Draw
bool Draw(void)
Definition: mythrender_d3d9.cpp:124
D3DFVF_TEXTUREVERTEX
#define D3DFVF_TEXTUREVERTEX
Definition: mythrender_d3d9.cpp:159
MythImage
Definition: mythimage.h:37
MythRenderD3D9::Test
bool Test(bool &reset)
Definition: mythrender_d3d9.cpp:406
TEXTUREVERTEX::z
FLOAT z
Definition: mythrender_d3d9.cpp:47
D3D9Image::m_size
QSize m_size
Definition: mythrender_d3d9.h:43
mythrender_d3d9.h
MythRenderD3D9::SetTextureVertices
void SetTextureVertices(IDirect3DDevice9 *dev, bool enable)
Definition: mythrender_d3d9.cpp:1133
VERTEX::x
FLOAT x
Definition: mythrender_d3d9.cpp:58
VERTEX::y
FLOAT y
Definition: mythrender_d3d9.cpp:59
MythRenderD3D9::m_texture_vertices
bool m_texture_vertices
Definition: mythrender_d3d9.h:133
mD3DFMT_IYUV
#define mD3DFMT_IYUV
Definition: mythrender_d3d9.cpp:156
MythRender::m_size
QSize m_size
Definition: mythrender_base.h:49
D3D9Locker::~D3D9Locker
~D3D9Locker()
Definition: mythrender_d3d9.cpp:163
D3D9Locker::m_render
MythRenderD3D9 * m_render
Definition: mythrender_d3d9.h:59
TEXTUREVERTEX::y
FLOAT y
Definition: mythrender_d3d9.cpp:46
MythRenderD3D9::MultiTexturing
void MultiTexturing(IDirect3DDevice9 *dev, bool enable, IDirect3DTexture9 *texture=nullptrptr)
Definition: mythrender_d3d9.cpp:655
MythRenderD3D9::m_rootD3DDevice
IDirect3DDevice9 * m_rootD3DDevice
Definition: mythrender_d3d9.h:121
TEXTUREVERTEX::t1u
FLOAT t1u
Definition: mythrender_d3d9.cpp:50
TEXTUREVERTEX::t1v
FLOAT t1v
Definition: mythrender_d3d9.cpp:51
MythRenderD3D9::m_d3d
IDirect3D9 * m_d3d
Definition: mythrender_d3d9.h:120
MythRenderD3D9::m_deviceHandle
HANDLE m_deviceHandle
Definition: mythrender_d3d9.h:146
MythD3DSurface
Definition: mythrender_d3d9.cpp:32
D3D9Image::m_surface
IDirect3DSurface9 * m_surface
Definition: mythrender_d3d9.h:48
D3D9Image::ReleaseBuffer
void ReleaseBuffer(void)
Definition: mythrender_d3d9.cpp:140
MythRenderD3D9::DestroyDeviceManager
void DestroyDeviceManager(void)
Definition: mythrender_d3d9.cpp:1236
D3D9Image::m_render
MythRenderD3D9 * m_render
Definition: mythrender_d3d9.h:45
MythRenderD3D9::DeleteSurface
void DeleteSurface(IDirect3DSurface9 *surface)
Definition: mythrender_d3d9.cpp:907