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