MythTV  master
mythrender_d3d9.h
Go to the documentation of this file.
1 #ifndef MYTHRENDER_D3D9_H
2 #define MYTHRENDER_D3D9_H
3 
4 #include <QMap>
5 
6 #include "compat.h"
7 #include <d3d9.h>
8 
9 #include "mythimage.h"
10 #include "mythuiexp.h"
11 #include "mythrender_base.h"
12 
13 #ifdef USING_DXVA2
14 #include "dxva2api.h"
15 #else
16 using IDirect3DDeviceManager9 = void*;
17 #endif
18 
20 class MythD3DSurface;
21 class MythRenderD3D9;
22 
24 {
25  public:
26  D3D9Image(MythRenderD3D9 *render, QSize size, bool video = false);
27  ~D3D9Image();
28 
29  bool IsValid(void) const { return m_valid; }
30  QSize GetSize(void) const { return m_size; }
31  int GetDataSize(void) const { return m_size.width() * m_size.height() * 4; }
32  bool SetAsRenderTarget(void);
33  bool UpdateImage(IDirect3DSurface9 *surface);
34  bool UpdateImage(const MythImage *img);
35  bool UpdateVertices(const QRect &dvr, const QRect &vr, int alpha = 255,
36  bool video = false);
37  bool Draw(void);
38  uint8_t* GetBuffer(bool &hardware_conv, uint &pitch);
39  void ReleaseBuffer(void);
40  QRect GetRect(void);
41 
42  private:
43  QSize m_size;
44  bool m_valid {false};
45  MythRenderD3D9 *m_render {nullptr};
46  IDirect3DVertexBuffer9 *m_vertexbuffer {nullptr};
47  IDirect3DTexture9 *m_texture {nullptr};
48  IDirect3DSurface9 *m_surface {nullptr};
49 };
50 
52 {
53  public:
54  explicit D3D9Locker(MythRenderD3D9 *render)
55  : m_render(render) {}
56  ~D3D9Locker();
57  IDirect3DDevice9* Acquire(void);
58  private:
59  MythRenderD3D9 *m_render {nullptr};
60 };
61 
63 {
64  public:
65  static void* ResolveAddress(const char* lib, const char* proc);
66 
68 
69  bool Create(QSize size, HWND window);
70  bool Test(bool &reset);
71 
72  bool ClearBuffer(void);
73  bool Begin(void);
74  bool End(void);
75  void CopyFrame(void* surface, D3D9Image *img);
76  bool StretchRect(IDirect3DTexture9 *texture, IDirect3DSurface9 *surface,
77  bool known_surface = true);
78  bool DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer);
79  void DrawRect(const QRect &rect, const QColor &color, int alpha);
80  bool Present(HWND win);
81  bool HardwareYUVConversion(void);
82  QRect GetRect(IDirect3DVertexBuffer9 *vertexbuffer);
83  bool SetRenderTarget(IDirect3DTexture9 *texture);
84 
85  IDirect3DTexture9* CreateTexture(const QSize &size);
86  void DeleteTexture(IDirect3DTexture9* texture);
87 
88  IDirect3DVertexBuffer9* CreateVertexBuffer(IDirect3DTexture9* texture = nullptr);
89  bool UpdateVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer,
90  const QRect &dvr, const QRect &vr,
91  int alpha = 255, bool video = false);
92  void DeleteVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer);
93 
94  IDirect3DSurface9* CreateSurface(const QSize &size, bool video = false);
95  bool UpdateSurface(IDirect3DSurface9* surface,
96  const MythImage *image);
97  void DeleteSurface(IDirect3DSurface9* surface);
98  uint8_t* GetBuffer(IDirect3DSurface9* surface, uint &pitch);
99  void ReleaseBuffer(IDirect3DSurface9* surface);
100 
101  private:
102  virtual ~MythRenderD3D9();
103  bool SetTexture(IDirect3DDevice9* dev,
104  IDirect3DTexture9 *texture,
105  int num = 0);
106  void DeleteTextures(void);
107  void DeleteVertexBuffers(void);
108  void DeleteSurfaces(void);
109  void Init2DState(void);
110  void EnableBlending(IDirect3DDevice9* dev, bool enable);
111  void MultiTexturing(IDirect3DDevice9* dev, bool enable,
112  IDirect3DTexture9 *texture = nullptrptr);
113  void SetTextureVertices(IDirect3DDevice9* dev, bool enable);
114 
115  private:
116  QMap<IDirect3DTexture9*, QSize> m_textures;
117  QMap<IDirect3DVertexBuffer9*, MythD3DVertexBuffer> m_vertexbuffers;
118  QMap<IDirect3DSurface9*, MythD3DSurface> m_surfaces;
119 
120  IDirect3D9 *m_d3d {nullptr};
121  IDirect3DDevice9 *m_rootD3DDevice {nullptr};
122  D3DFORMAT m_adaptor_fmt {D3DFMT_UNKNOWN};
123  D3DFORMAT m_videosurface_fmt {D3DFMT_UNKNOWN};
124  D3DFORMAT m_surface_fmt {D3DFMT_UNKNOWN};
125  D3DFORMAT m_texture_fmt {D3DFMT_UNKNOWN};
126  IDirect3DVertexBuffer9 *m_rect_vertexbuffer {nullptr};
127  IDirect3DSurface9 *m_default_surface {nullptr};
128  IDirect3DSurface9 *m_current_surface {nullptr};
129 
130  QMutex m_lock {QMutex::Recursive};
131  bool m_blend {true};
132  bool m_multi_texturing {true};
133  bool m_texture_vertices {true};
134 
135  public:
136  IDirect3DDevice9* AcquireDevice(void);
137  void ReleaseDevice(void);
138  IDirect3DDeviceManager9* GetDeviceManager(void) { return m_deviceManager; }
139 
140  private:
141  void CreateDeviceManager(void);
142  void DestroyDeviceManager(void);
143 
144  private:
145  IDirect3DDeviceManager9 *m_deviceManager {nullptr};
146  HANDLE m_deviceHandle {nullptr};
147  uint m_deviceManagerToken {0};
148 };
149 
150 #endif // MYTHRENDER_D3D9_H
QMap< IDirect3DSurface9 *, MythD3DSurface > m_surfaces
bool IsValid(void) const
D3D9Locker(MythRenderD3D9 *render)
IDirect3DDeviceManager9 * GetDeviceManager(void)
QMap< IDirect3DVertexBuffer9 *, MythD3DVertexBuffer > m_vertexbuffers
unsigned int uint
Definition: compat.h:140
int GetDataSize(void) const
QSize GetSize(void) const
#define MUI_PUBLIC
Definition: mythuiexp.h:9
QMap< IDirect3DTexture9 *, QSize > m_textures