26 if (m_directRendering)
30 D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
31 m_deviceContext.GetAddressOf());
33 qWarning(
"%s: Couldn't create Direct2D Device context: %#lx", __FUNCTION__, hr);
43 if (!m_directRendering)
45 else if (!m_swapChain)
55 return m_pixmap.
data();
61 if (m_directRendering) {
62 DXGI_SWAP_CHAIN_DESC1
desc;
66 if (FAILED(hr) || (
desc.Width != UINT(geom.
width()) || (
desc.Height != UINT(geom.
height())))) {
68 m_swapChain->GetDesc1(&
desc);
84 if (!m_needsFullFlush) {
90 dc->DrawBitmap(
bitmap->bitmap(),
93 D2D1_INTERPOLATION_MODE_LINEAR,
98 dc->DrawBitmap(
bitmap->bitmap(),
101 D2D1_INTERPOLATION_MODE_LINEAR,
103 m_needsFullFlush =
false;
112 if (m_directRendering) {
113 m_swapChain->Present(0, 0);
121 hr = bitmapSurface.As(&dxgiSurface);
125 hr = dxgiSurface->GetDC(FALSE, &hdc);
127 qErrnoWarning(hr,
"Failed to get DC for presenting the surface");
133 const POINT ptDst = { bounds.
x(), bounds.
y() };
134 const POINT ptSrc = { 0, 0 };
135 const BLENDFUNCTION blend = { AC_SRC_OVER, 0, BYTE(255.0 *
opacity()), AC_SRC_ALPHA };
137 const RECT dirty = {
r.
left(),
r.top(),
r.left() +
r.width(),
r.top() +
r.height() };
138 UPDATELAYEREDWINDOWINFO
info = {
sizeof(UPDATELAYEREDWINDOWINFO),
nullptr,
139 &ptDst, &
size, hdc, &ptSrc, 0, &blend, ULW_ALPHA, &dirty };
140 if (!UpdateLayeredWindowIndirect(
handle(), &
info))
141 qErrnoWarning(
int(GetLastError()),
"Failed to update the layered window");
143 hr = dxgiSurface->ReleaseDC(
nullptr);
145 qErrnoWarning(hr,
"Failed to release the DC for presentation");
150 DXGI_SWAP_CHAIN_DESC1
desc = {};
152 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
153 desc.SampleDesc.Count = 1;
154 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
155 desc.BufferCount = 1;
156 desc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
164 m_swapChain.ReleaseAndGetAddressOf());
167 qWarning(
"%s: Could not create swap chain: %#lx", __FUNCTION__, hr);
169 m_needsFullFlush =
true;
176 m_deviceContext->SetTarget(
nullptr);
177 m_needsFullFlush =
true;
182 HRESULT hr = m_swapChain->ResizeBuffers(0,
183 UINT(
size.width()), UINT(
size.height()),
187 qWarning(
"%s: Could not resize swap chain: %#lx", __FUNCTION__, hr);
197 D2D1_PIXEL_FORMAT
format = m_bitmap->
bitmap()->GetPixelFormat();
198 D2D1_SIZE_U
size = m_bitmap->
bitmap()->GetPixelSize();
201 m_bitmap->
bitmap()->GetDpi(&dpiX, &dpiY);
207 D2D1_BITMAP_OPTIONS_TARGET,
214 qWarning(
"%s: Could not create staging bitmap: %#lx", __FUNCTION__, hr);
218 hr =
copy.Get()->CopyFromBitmap(
nullptr, m_bitmap->
bitmap(),
nullptr);
220 qWarning(
"%s: Could not copy from bitmap! %#lx", __FUNCTION__, hr);
227void QWindowsDirect2DWindow::setupBitmap()
232 if (!m_deviceContext)
235 if (m_directRendering && !m_swapChain)
240 if (m_directRendering) {
241 hr = m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBufferSurface));
243 qWarning(
"%s: Could not query backbuffer for DXGI Surface: %#lx", __FUNCTION__, hr);
248 CD3D11_TEXTURE2D_DESC backBufferDesc(DXGI_FORMAT_B8G8R8A8_UNORM, UINT(
rect.width()), UINT(
rect.height()), 1, 1);
249 backBufferDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
250 backBufferDesc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
254 qErrnoWarning(hr,
"Failed to create backing texture for indirect rendering");
258 hr = backBufferTexture.As(&backBufferSurface);
260 qErrnoWarning(hr,
"Failed to cast back buffer surface to DXGI surface");
266 hr = m_deviceContext->CreateBitmapFromDxgiSurface(backBufferSurface.Get(),
nullptr, backBufferBitmap.GetAddressOf());
268 qWarning(
"%s: Could not create Direct2D Bitmap from DXGI Surface: %#lx", __FUNCTION__, hr);
275 if (!m_directRendering)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
The QRegion class specifies a clip region for a painter.
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QSurfaceFormat format() const override
Returns the actual format of this window.
QWindowsDirect2DDeviceContext * deviceContext() const
ID2D1Bitmap1 * bitmap() const
ID3D11Device * d3dDevice() const
ID2D1Device * d2dDevice() const
IDXGIFactory2 * dxgiFactory() const
static QWindowsDirect2DContext * instance()
ID2D1DeviceContext * get() const
@ TranslucentTopLevelWindow
QWindowsDirect2DWindow(QWindow *window, const QWindowsWindowData &data)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
~QWindowsDirect2DWindow()
void present(const QRegion ®ion)
QSharedPointer< QWindowsDirect2DBitmap > copyBackBuffer() const
void flush(QWindowsDirect2DBitmap *bitmap, const QRegion ®ion, const QPoint &offset)
void resizeSwapChain(const QSize &size)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
QSurfaceFormat format() const override
Returns the actual surface format of the window.
QRect geometry() const override
Returns the current geometry of a window.
HWND handle() const override
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
static const QCssKnownValue properties[NumProperties - 1]
#define SIZE(large, small, mini)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
static bool hasAlpha(const QImage &image)
D2D1_RECT_F to_d2d_rect_f(const QRectF &qrect)
QFileInfo info(fileName)
[8]