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 "libmythbase/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 #if defined (_WIN32)
15 #define CINTERFACE
16 #define COBJMACROS
17 #endif
18 #include "dxva2api.h"
19 #else
20 using IDirect3DDeviceManager9 = void*;
21 #endif
22 
23 class MythRenderD3D9;
24 
26 {
27  public:
28  D3D9Image(MythRenderD3D9 *render, QSize size, bool video = false);
29  ~D3D9Image();
30 
31  bool IsValid(void) const { return m_valid; }
32  QSize GetSize(void) const { return m_size; }
33  int GetDataSize(void) const { return m_size.width() * m_size.height() * 4; }
34  bool SetAsRenderTarget(void);
35  bool UpdateImage(IDirect3DSurface9 *surface);
36  bool UpdateImage(const MythImage *img);
37  bool UpdateVertices(const QRect &dvr, const QRect &vr, int alpha = 255,
38  bool video = false);
39  bool Draw(void);
40  uint8_t* GetBuffer(bool &hardware_conv, uint &pitch);
41  void ReleaseBuffer(void);
42  QRect GetRect(void);
43 
44  private:
45  QSize m_size;
46  bool m_valid {false};
47  MythRenderD3D9 *m_render {nullptr};
48  IDirect3DVertexBuffer9 *m_vertexbuffer {nullptr};
49  IDirect3DTexture9 *m_texture {nullptr};
50  IDirect3DSurface9 *m_surface {nullptr};
51 };
52 
54 {
55  public:
56  explicit D3D9Locker(MythRenderD3D9 *render)
57  : m_render(render) {}
58  ~D3D9Locker();
59  IDirect3DDevice9* Acquire(void);
60  private:
61  MythRenderD3D9 *m_render {nullptr};
62 };
63 
65 {
66  public:
67  explicit MythD3DVertexBuffer(IDirect3DTexture9* tex = nullptr) :
68  m_dest(QRect(QPoint(0,0),QSize(0,0))),
69  m_src(QRect(QPoint(0,0),QSize(0,0))), m_texture(tex)
70  {
71  }
72 
73  uint32_t m_color {0xFFFFFFFF};
74  QRect m_dest;
75  QRect m_src;
76  IDirect3DTexture9 *m_texture;
77 };
78 
80 {
81  public:
82  MythD3DSurface(QSize size = QSize(0,0), D3DFORMAT fmt = D3DFMT_UNKNOWN) :
83  m_size(size), m_fmt(fmt)
84  {
85  }
86 
87  QSize m_size;
88  D3DFORMAT m_fmt;
89 };
90 
92 {
93  public:
94  static void* ResolveAddress(const char* lib, const char* proc);
95 
97 
98  bool Create(QSize size, HWND window);
99  bool Test(bool &reset);
100 
101  bool ClearBuffer(void);
102  bool Begin(void);
103  bool End(void);
104  void CopyFrame(void* surface, D3D9Image *img);
105  bool StretchRect(IDirect3DTexture9 *texture, IDirect3DSurface9 *surface,
106  bool known_surface = true);
107  bool DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer);
108  void DrawRect(const QRect &rect, const QColor &color, int alpha);
109  bool Present(HWND win);
110  bool HardwareYUVConversion(void);
111  QRect GetRect(IDirect3DVertexBuffer9 *vertexbuffer);
112  bool SetRenderTarget(IDirect3DTexture9 *texture);
113 
114  IDirect3DTexture9* CreateTexture(const QSize &size);
115  void DeleteTexture(IDirect3DTexture9* texture);
116 
117  IDirect3DVertexBuffer9* CreateVertexBuffer(IDirect3DTexture9* texture = nullptr);
118  bool UpdateVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer,
119  const QRect &dvr, const QRect &vr,
120  int alpha = 255, bool video = false);
121  void DeleteVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer);
122 
123  IDirect3DSurface9* CreateSurface(const QSize &size, bool video = false);
124  bool UpdateSurface(IDirect3DSurface9* surface,
125  const MythImage *image);
126  void DeleteSurface(IDirect3DSurface9* surface);
127  uint8_t* GetBuffer(IDirect3DSurface9* surface, uint &pitch);
128  void ReleaseBuffer(IDirect3DSurface9* surface);
129 
130  private:
131  virtual ~MythRenderD3D9();
132  bool SetTexture(IDirect3DDevice9* dev,
133  IDirect3DTexture9 *texture,
134  int num = 0);
135  void DeleteTextures(void);
136  void DeleteVertexBuffers(void);
137  void DeleteSurfaces(void);
138  void Init2DState(void);
139  void EnableBlending(IDirect3DDevice9* dev, bool enable);
140  void MultiTexturing(IDirect3DDevice9* dev, bool enable,
141  IDirect3DTexture9 *texture = nullptr);
142  void SetTextureVertices(IDirect3DDevice9* dev, bool enable);
143 
144  private:
145  QMap<IDirect3DTexture9*, QSize> m_textures;
146  QMap<IDirect3DVertexBuffer9*, MythD3DVertexBuffer> m_vertexbuffers;
147  QMap<IDirect3DSurface9*, MythD3DSurface> m_surfaces;
148 
149  IDirect3D9 *m_d3d {nullptr};
150  IDirect3DDevice9 *m_rootD3DDevice {nullptr};
151  D3DFORMAT m_adaptor_fmt {D3DFMT_UNKNOWN};
152  D3DFORMAT m_videosurface_fmt {D3DFMT_UNKNOWN};
153  D3DFORMAT m_surface_fmt {D3DFMT_UNKNOWN};
154  D3DFORMAT m_texture_fmt {D3DFMT_UNKNOWN};
155  IDirect3DVertexBuffer9 *m_rect_vertexbuffer {nullptr};
156  IDirect3DSurface9 *m_default_surface {nullptr};
157  IDirect3DSurface9 *m_current_surface {nullptr};
158 
159  QRecursiveMutex m_lock;
160  bool m_blend {true};
161  bool m_multi_texturing {true};
162  bool m_texture_vertices {true};
163 
164  public:
165  IDirect3DDevice9* AcquireDevice(void);
166  void ReleaseDevice(void);
167  IDirect3DDeviceManager9* GetDeviceManager(void) { return m_deviceManager; }
168 
169  private:
170  void CreateDeviceManager(void);
171  void DestroyDeviceManager(void);
172 
173  private:
174  IDirect3DDeviceManager9 *m_deviceManager {nullptr};
175  HANDLE m_deviceHandle {nullptr};
176  uint m_deviceManagerToken {0};
177 };
178 
179 #endif // MYTHRENDER_D3D9_H
MythD3DSurface::m_fmt
D3DFORMAT m_fmt
Definition: mythrender_d3d9.h:88
MythD3DVertexBuffer
Definition: mythrender_d3d9.h:64
MythD3DVertexBuffer::m_color
uint32_t m_color
Definition: mythrender_d3d9.h:73
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythRenderD3D9::GetDeviceManager
IDirect3DDeviceManager9 * GetDeviceManager(void)
Definition: mythrender_d3d9.h:167
D3D9Locker::D3D9Locker
D3D9Locker(MythRenderD3D9 *render)
Definition: mythrender_d3d9.h:56
MythRenderD3D9::m_textures
QMap< IDirect3DTexture9 *, QSize > m_textures
Definition: mythrender_d3d9.h:145
MythD3DVertexBuffer::m_src
QRect m_src
Definition: mythrender_d3d9.h:75
MythD3DVertexBuffer::m_texture
IDirect3DTexture9 * m_texture
Definition: mythrender_d3d9.h:76
MythD3DVertexBuffer::m_dest
QRect m_dest
Definition: mythrender_d3d9.h:74
mythrender_base.h
MythD3DSurface::MythD3DSurface
MythD3DSurface(QSize size=QSize(0, 0), D3DFORMAT fmt=D3DFMT_UNKNOWN)
Definition: mythrender_d3d9.h:82
MythRenderD3D9::m_vertexbuffers
QMap< IDirect3DVertexBuffer9 *, MythD3DVertexBuffer > m_vertexbuffers
Definition: mythrender_d3d9.h:146
compat.h
D3D9Image
Definition: mythrender_d3d9.h:25
MythRenderD3D9
Definition: mythrender_d3d9.h:91
MythD3DVertexBuffer::MythD3DVertexBuffer
MythD3DVertexBuffer(IDirect3DTexture9 *tex=nullptr)
Definition: mythrender_d3d9.h:67
MythRenderD3D9::m_lock
QRecursiveMutex m_lock
Definition: mythrender_d3d9.h:159
uint
unsigned int uint
Definition: compat.h:81
D3D9Image::IsValid
bool IsValid(void) const
Definition: mythrender_d3d9.h:31
MythRenderD3D9::m_surfaces
QMap< IDirect3DSurface9 *, MythD3DSurface > m_surfaces
Definition: mythrender_d3d9.h:147
D3D9Locker
Definition: mythrender_d3d9.h:53
D3D9Image::GetSize
QSize GetSize(void) const
Definition: mythrender_d3d9.h:32
mythimage.h
MythD3DSurface::m_size
QSize m_size
Definition: mythrender_d3d9.h:87
MythRender
Definition: mythrender_base.h:23
MythImage
Definition: mythimage.h:36
D3D9Image::m_size
QSize m_size
Definition: mythrender_d3d9.h:45
D3D9Image::GetDataSize
int GetDataSize(void) const
Definition: mythrender_d3d9.h:33
MythRenderD3D9::MythRenderD3D9
MythRenderD3D9()
Definition: mythrender_d3d9.h:96
MythD3DSurface
Definition: mythrender_d3d9.h:79
kRenderDirect3D9
@ kRenderDirect3D9
Definition: mythrender_base.h:18
mythuiexp.h