8#include "private/qcapturablewindow_p.h"
9#include "private/qmemoryvideobuffer_p.h"
12#include <QtCore/qloggingcategory.h>
23 auto hdcWindow = GetDC(hWnd);
30 auto hdcMem = CreateCompatibleDC(hdcWindow);
38 std::unique_ptr<Grabber>
result(
new Grabber(capture, hWnd, hdcWindow, hdcMem));
51 DeleteObject(m_hBitmap);
57 ReleaseDC(m_hwnd, m_hdcWindow);
64 : m_hwnd(hWnd), m_hdcWindow(hdcWindow), m_hdcMem(hdcMem)
66 if (
auto rate = GetDeviceCaps(hdcWindow, VREFRESH);
rate > 0)
76 if (!GetWindowRect(m_hwnd, &windowRect)) {
82 const QSize size{ windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
88 DeleteObject(std::exchange(m_hBitmap,
nullptr));
97 m_hBitmap = CreateCompatibleBitmap(m_hdcWindow,
size.width(),
size.height());
117 const auto oldBitmap = SelectObject(m_hdcMem, m_hBitmap);
118 auto deselect =
qScopeGuard([&]() { SelectObject(m_hdcMem, oldBitmap); });
122 if (!BitBlt(m_hdcMem, 0, 0,
size.width(),
size.height(), m_hdcWindow, 0, 0, SRCCOPY)) {
130 header.biSize =
sizeof(BITMAPINFOHEADER);
135 header.biCompression = BI_RGB;
137 const auto bytesPerLine =
size.width() * 4;
141 const auto copiedHeight = GetDIBits(m_hdcMem, m_hBitmap, 0,
size.height(),
array.data(), &
info, DIB_RGB_COLORS);
142 if (copiedHeight !=
size.height()) {
143 qCWarning(qLcGdiWindowCapture) << copiedHeight <<
"lines have been copied, expected:" <<
size.height();
152 ||
header.biPlanes != 1 ||
header.biBitCount != 32 ||
header.biCompression != BI_RGB) {
164 HDC m_hdcWindow = {};
166 HBITMAP m_hBitmap = {};
180 if (active ==
static_cast<bool>(m_grabber))
186 auto window = source<WindowSource>();
192 return static_cast<bool>(m_grabber) == active;
static const QCapturableWindowPrivate * handle(const QCapturableWindow &window)
void setFrameRate(qreal rate)
void errorUpdated(QPlatformSurfaceCapture::Error error, const QString &description)
void addFrameCallback(Object &object, Method method)
void updateError(QPlatformSurfaceCapture::Error error, const QString &description={})
static std::unique_ptr< Grabber > create(QGdiWindowCapture &capture, HWND hWnd)
QVideoFrameFormat format() const
QVideoFrame grabFrame() override
QVideoFrameFormat frameFormat() const override
bool setActiveInternal(bool active) override
~QGdiWindowCapture() override
The QMemoryVideoBuffer class provides a system memory allocated video data buffer.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QVideoFrame class represents a frame of video data.
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
static QString header(const QString &name)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
QLatin1StringView QLatin1String