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 typedef void* IDirect3DDeviceManager9;
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;
46  IDirect3DVertexBuffer9 *m_vertexbuffer;
47  IDirect3DTexture9 *m_texture;
48  IDirect3DSurface9 *m_surface;
49 };
50 
52 {
53  public:
54  explicit D3D9Locker(MythRenderD3D9 *render);
55  ~D3D9Locker();
56  IDirect3DDevice9* Acquire(void);
57  private:
59 };
60 
62 {
63  public:
64  static void* ResolveAddress(const char* lib, const char* proc);
65 
67 
68  bool Create(QSize size, HWND window);
69  bool Test(bool &reset);
70 
71  bool ClearBuffer(void);
72  bool Begin(void);
73  bool End(void);
74  void CopyFrame(void* surface, D3D9Image *img);
75  bool StretchRect(IDirect3DTexture9 *texture, IDirect3DSurface9 *surface,
76  bool known_surface = true);
77  bool DrawTexturedQuad(IDirect3DVertexBuffer9 *vertexbuffer);
78  void DrawRect(const QRect &rect, const QColor &color, int alpha);
79  bool Present(HWND win);
80  bool HardwareYUVConversion(void);
81  QRect GetRect(IDirect3DVertexBuffer9 *vertexbuffer);
82  bool SetRenderTarget(IDirect3DTexture9 *texture);
83 
84  IDirect3DTexture9* CreateTexture(const QSize &size);
85  void DeleteTexture(IDirect3DTexture9* texture);
86 
87  IDirect3DVertexBuffer9* CreateVertexBuffer(IDirect3DTexture9* texture = nullptr);
88  bool UpdateVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer,
89  const QRect &dvr, const QRect &vr,
90  int alpha = 255, bool video = false);
91  void DeleteVertexBuffer(IDirect3DVertexBuffer9* vertexbuffer);
92 
93  IDirect3DSurface9* CreateSurface(const QSize &size, bool video = false);
94  bool UpdateSurface(IDirect3DSurface9* surface,
95  const MythImage *image);
96  void DeleteSurface(IDirect3DSurface9* surface);
97  uint8_t* GetBuffer(IDirect3DSurface9* surface, uint &pitch);
98  void ReleaseBuffer(IDirect3DSurface9* surface);
99 
100  private:
101  virtual ~MythRenderD3D9();
102  bool SetTexture(IDirect3DDevice9* dev,
103  IDirect3DTexture9 *texture,
104  int num = 0);
105  void DeleteTextures(void);
106  void DeleteVertexBuffers(void);
107  void DeleteSurfaces(void);
108  void Init2DState(void);
109  void EnableBlending(IDirect3DDevice9* dev, bool enable);
110  void MultiTexturing(IDirect3DDevice9* dev, bool enable,
111  IDirect3DTexture9 *texture = nullptrptr);
112  void SetTextureVertices(IDirect3DDevice9* dev, bool enable);
113 
114  private:
115  QMap<IDirect3DTexture9*, QSize> m_textures;
116  QMap<IDirect3DVertexBuffer9*, MythD3DVertexBuffer> m_vertexbuffers;
117  QMap<IDirect3DSurface9*, MythD3DSurface> m_surfaces;
118 
119  IDirect3D9 *m_d3d;
120  IDirect3DDevice9 *m_rootD3DDevice;
121  D3DFORMAT m_adaptor_fmt;
123  D3DFORMAT m_surface_fmt;
124  D3DFORMAT m_texture_fmt;
125  IDirect3DVertexBuffer9 *m_rect_vertexbuffer;
126  IDirect3DSurface9 *m_default_surface;
127  IDirect3DSurface9 *m_current_surface;
128 
129  QMutex m_lock;
130  bool m_blend;
133 
134  public:
135  IDirect3DDevice9* AcquireDevice(void);
136  void ReleaseDevice(void);
137  IDirect3DDeviceManager9* GetDeviceManager(void) { return m_deviceManager; }
138 
139  private:
140  void CreateDeviceManager(void);
141  void DestroyDeviceManager(void);
142 
143  private:
144  IDirect3DDeviceManager9 *m_deviceManager;
147 };
148 
149 #endif // MYTHRENDER_D3D9_H
D3DFORMAT m_surface_fmt
IDirect3DVertexBuffer9 * m_rect_vertexbuffer
D3DFORMAT m_adaptor_fmt
QMap< IDirect3DSurface9 *, MythD3DSurface > m_surfaces
MythRenderD3D9 * m_render
IDirect3DSurface9 * m_default_surface
bool IsValid(void) const
unsigned int uint
Definition: compat.h:140
IDirect3DSurface9 * m_surface
IDirect3DDeviceManager9 * GetDeviceManager(void)
QMap< IDirect3DVertexBuffer9 *, MythD3DVertexBuffer > m_vertexbuffers
IDirect3D9 * m_d3d
IDirect3DDeviceManager9 * m_deviceManager
IDirect3DVertexBuffer9 * m_vertexbuffer
IDirect3DSurface9 * m_current_surface
IDirect3DTexture9 * m_texture
int GetDataSize(void) const
D3DFORMAT m_texture_fmt
QSize GetSize(void) const
#define MUI_PUBLIC
Definition: mythuiexp.h:9
D3DFORMAT m_videosurface_fmt
MythRenderD3D9 * m_render
IDirect3DDevice9 * m_rootD3DDevice
QMap< IDirect3DTexture9 *, QSize > m_textures