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