Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
evrd3dpresentengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef EVRD3DPRESENTENGINE_H
5#define EVRD3DPRESENTENGINE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QMutex>
19#include <QSize>
20#include <QVideoFrameFormat>
21#include <QtCore/private/qcomptr_p.h>
22#include <qpointer.h>
23
24#include <d3d9.h>
25
26struct IDirect3D9Ex;
27struct IDirect3DDevice9Ex;
28struct IDirect3DDeviceManager9;
29struct IDirect3DSurface9;
30struct IDirect3DTexture9;
31struct IMFSample;
32struct IMFMediaType;
33
34QT_BEGIN_NAMESPACE
35class QVideoFrame;
36class QVideoSink;
37QT_END_NAMESPACE
38
39// Randomly generated GUIDs
40static const GUID MFSamplePresenter_SampleCounter =
41{ 0xb0bb83cc, 0xf10f, 0x4e2e, { 0xaa, 0x2b, 0x29, 0xea, 0x5e, 0x92, 0xef, 0x85 } };
42
43#if QT_CONFIG(opengl)
44# include <qopengl.h>
45#endif
46
47QT_BEGIN_NAMESPACE
48
49#ifdef MAYBE_ANGLE
50
51class OpenGLResources;
52
53class EGLWrapper
54{
55 Q_DISABLE_COPY(EGLWrapper)
56public:
57 EGLWrapper();
58
59 __eglMustCastToProperFunctionPointerType getProcAddress(const char *procname);
60 EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
61 EGLBoolean destroySurface(EGLDisplay dpy, EGLSurface surface);
62 EGLBoolean bindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
63 EGLBoolean releaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
64
65private:
66 typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRYP EglGetProcAddress)(const char *procname);
67 typedef EGLSurface (EGLAPIENTRYP EglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
68 typedef EGLBoolean (EGLAPIENTRYP EglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
69 typedef EGLBoolean (EGLAPIENTRYP EglBindTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
70 typedef EGLBoolean (EGLAPIENTRYP EglReleaseTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
71
72 EglGetProcAddress m_eglGetProcAddress;
73 EglCreatePbufferSurface m_eglCreatePbufferSurface;
74 EglDestroySurface m_eglDestroySurface;
75 EglBindTexImage m_eglBindTexImage;
76 EglReleaseTexImage m_eglReleaseTexImage;
77};
78
79#endif // MAYBE_ANGLE
80
81#if QT_CONFIG(opengl)
82
83struct WglNvDxInterop {
84 HANDLE (WINAPI* wglDXOpenDeviceNV) (void* dxDevice);
85 BOOL (WINAPI* wglDXCloseDeviceNV) (HANDLE hDevice);
86 HANDLE (WINAPI* wglDXRegisterObjectNV) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
87 BOOL (WINAPI* wglDXSetResourceShareHandleNV) (void *dxResource, HANDLE shareHandle);
88 BOOL (WINAPI* wglDXLockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
89 BOOL (WINAPI* wglDXUnlockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
90 BOOL (WINAPI* wglDXUnregisterObjectNV) (HANDLE hDevice, HANDLE hObject);
91
92 static const int WGL_ACCESS_READ_ONLY_NV = 0;
93};
94
95#endif
96
97class D3DPresentEngine
98{
99 Q_DISABLE_COPY(D3DPresentEngine)
100public:
101 D3DPresentEngine(QVideoSink *sink);
102 virtual ~D3DPresentEngine();
103
104 bool isValid() const;
105
106 HRESULT getService(REFGUID guidService, REFIID riid, void** ppv);
107 HRESULT checkFormat(D3DFORMAT format);
108 UINT refreshRate() const { return m_displayMode.RefreshRate; }
109
110 HRESULT createVideoSamples(IMFMediaType *format, QList<ComPtr<IMFSample>> &videoSampleQueue,
111 QSize frameSize);
112 QVideoFrameFormat videoSurfaceFormat() const { return m_surfaceFormat; }
113 QVideoFrame makeVideoFrame(const ComPtr<IMFSample> &sample, QtVideo::Rotation rotation);
114
115 void releaseResources();
116 void setSink(QVideoSink *sink);
117
118private:
119 static const int PRESENTER_BUFFER_COUNT = 3;
120
121 HRESULT initializeD3D();
122 HRESULT createD3DDevice();
123
124 std::pair<IMFSample *, HANDLE> m_sampleTextureHandle[PRESENTER_BUFFER_COUNT] = {};
125
126 UINT m_deviceResetToken;
127 D3DDISPLAYMODE m_displayMode;
128
129 ComPtr<IDirect3D9Ex> m_D3D9;
130 ComPtr<IDirect3DDevice9Ex> m_device;
131 ComPtr<IDirect3DDeviceManager9> m_devices;
132
133 QVideoFrameFormat m_surfaceFormat;
134
135 QPointer<QVideoSink> m_sink;
136 bool m_useTextureRendering = false;
137#if QT_CONFIG(opengl)
138 WglNvDxInterop m_wglNvDxInterop;
139#endif
140
141#ifdef MAYBE_ANGLE
142 unsigned int updateTexture(IDirect3DSurface9 *src);
143
144 OpenGLResources *m_glResources;
145 IDirect3DTexture9 *m_texture;
146#endif
147
148 friend class IMFSampleVideoBuffer;
149};
150
151QT_END_NAMESPACE
152
153#endif // EVRD3DPRESENTENGINE_H
STDMETHODIMP_(ULONG) AddRef() override
AsyncCallback(T *parent, InvokeFn fn)
STDMETHODIMP QueryInterface(REFIID iid, void **ppv) override
STDMETHODIMP GetDeviceID(IID *deviceID) override
STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override
STDMETHODIMP OnClockStop(MFTIME systemTime) override
STDMETHODIMP ReleaseServicePointers() override
STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override
STDMETHODIMP OnClockRestart(MFTIME systemTime) override
STDMETHODIMP InitServicePointers(IMFTopologyServiceLookup *lookup) override
STDMETHODIMP GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject) override
void setCropRect(QRect cropRect)
STDMETHODIMP_(ULONG) AddRef() override
STDMETHODIMP IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate) override
STDMETHODIMP OnClockSetRate(MFTIME systemTime, float rate) override
STDMETHODIMP GetCurrentMediaType(IMFVideoMediaType **mediaType) override
void setSink(QVideoSink *sink)
STDMETHODIMP GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override
void presentSample(const ComPtr< IMFSample > &sample)
STDMETHODIMP OnClockStart(MFTIME systemTime, LONGLONG clockStartOffset) override
STDMETHODIMP OnClockPause(MFTIME systemTime) override
STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param) override
EVRCustomPresenter(QVideoSink *sink=0)
ComPtr< IMFSample > sample() const
PresentSampleEvent(const ComPtr< IMFSample > &sample)
\inmodule QtCore
Definition qmutex.h:346
\inmodule QtCore
Definition qmutex.h:342
ComPtr< IMFSample > takeSample()
void returnSample(const ComPtr< IMFSample > &sample)
HRESULT initialize(QList< ComPtr< IMFSample > > &&samples)
HRESULT stopScheduler()
Scheduler(EVRCustomPresenter *presenter)
HRESULT startScheduler(ComPtr< IMFClock > clock)
void setFrameRate(const MFRatio &fps)
void setClockRate(float rate)
HRESULT processSamplesInQueue(LONG *nextSleep)
HRESULT scheduleSample(const ComPtr< IMFSample > &sample, bool presentNow)
static LONG MFTimeToMsec(const LONGLONG &time)
static QVideoFrameFormat::PixelFormat pixelFormatFromMediaType(IMFMediaType *type)
static HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect &nrcSource)
#define QMM_PRESENTATION_CURRENT_POSITION
static const DWORD SCHEDULER_TIMEOUT
bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter)
static const LONG ONE_MSEC
static const MFTIME ONE_SECOND
static const MFRatio g_DefaultFrameRate
D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
QVideoFrameFormat::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format)
bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
HRESULT qt_evr_validateVideoArea(const MFVideoArea &area, UINT32 width, UINT32 height)
MFOffset qt_evr_makeMFOffset(float v)
HRESULT qt_evr_getFrameRate(IMFMediaType *pType, MFRatio *pRatio)
MFVideoArea qt_evr_makeMFArea(float x, float y, DWORD width, DWORD height)
float qt_evr_MFOffsetToFloat(const MFOffset &offset)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)