8#include "private/qcapturablewindow_p.h"
9#include "private/qmemoryvideobuffer_p.h"
10#include "private/qvideoframe_p.h"
13#include <QtCore/qloggingcategory.h>
24 auto hdcWindow = GetDC(hWnd);
31 auto hdcMem = CreateCompatibleDC(hdcWindow);
39 std::unique_ptr<Grabber>
result(
new Grabber(capture, hWnd, hdcWindow, hdcMem));
52 DeleteObject(m_hBitmap);
58 ReleaseDC(m_hwnd, m_hdcWindow);
65 : m_hwnd(hWnd), m_hdcWindow(hdcWindow), m_hdcMem(hdcMem)
67 if (
auto rate = GetDeviceCaps(hdcWindow, VREFRESH);
rate > 0)
77 if (!GetWindowRect(m_hwnd, &windowRect)) {
83 const QSize size{ windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
89 DeleteObject(std::exchange(m_hBitmap,
nullptr));
98 m_hBitmap = CreateCompatibleBitmap(m_hdcWindow,
size.width(),
size.height());
118 const auto oldBitmap = SelectObject(m_hdcMem, m_hBitmap);
119 auto deselect =
qScopeGuard([&]() { SelectObject(m_hdcMem, oldBitmap); });
123 if (!BitBlt(m_hdcMem, 0, 0,
size.width(),
size.height(), m_hdcWindow, 0, 0, SRCCOPY)) {
131 header.biSize =
sizeof(BITMAPINFOHEADER);
136 header.biCompression = BI_RGB;
138 const auto bytesPerLine =
size.width() * 4;
142 const auto copiedHeight = GetDIBits(m_hdcMem, m_hBitmap, 0,
size.height(),
array.data(), &
info, DIB_RGB_COLORS);
143 if (copiedHeight !=
size.height()) {
144 qCWarning(qLcGdiWindowCapture) << copiedHeight <<
"lines have been copied, expected:" <<
size.height();
153 ||
header.biPlanes != 1 ||
header.biBitCount != 32 ||
header.biCompression != BI_RGB) {
160 std::make_unique<QMemoryVideoBuffer>(std::move(
array), bytesPerLine), m_format);
166 HDC m_hdcWindow = {};
168 HBITMAP m_hBitmap = {};
182 if (active ==
static_cast<bool>(m_grabber))
188 auto window = source<WindowSource>();
194 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
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static QVideoFrame createFrame(std::unique_ptr< Buffer > buffer, QVideoFrameFormat format)
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 qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
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