Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qbackingstoredefaultcompositor.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
5#include <QtGui/private/qwindow_p.h>
6#include <qpa/qplatformgraphicsbuffer.h>
7#include <QtCore/qfile.h>
8
10
11using namespace Qt::StringLiterals;
12
14{
15 reset();
16}
17
19{
20 m_rhi = nullptr;
21 delete m_psNoBlend;
22 m_psNoBlend = nullptr;
23 delete m_psBlend;
24 m_psBlend = nullptr;
25 delete m_psPremulBlend;
26 m_psPremulBlend = nullptr;
27 delete m_sampler;
28 m_sampler = nullptr;
29 delete m_vbuf;
30 m_vbuf = nullptr;
31 delete m_texture;
32 m_texture = nullptr;
33 m_widgetQuadData.reset();
34 for (PerQuadData &d : m_textureQuadData)
35 d.reset();
36}
37
39 QRhi *rhi,
40 QRhiResourceUpdateBatch *resourceUpdates,
41 const QRegion &dirtyRegion,
42 QPlatformBackingStore::TextureFlags *flags) const
43{
44 return toTexture(backingStore->toImage(), rhi, resourceUpdates, dirtyRegion, flags);
45}
46
48 QRhi *rhi,
49 QRhiResourceUpdateBatch *resourceUpdates,
50 const QRegion &dirtyRegion,
51 QPlatformBackingStore::TextureFlags *flags) const
52{
53 Q_ASSERT(rhi);
54 Q_ASSERT(resourceUpdates);
56
57 if (!m_rhi) {
58 m_rhi = rhi;
59 } else if (m_rhi != rhi) {
60 qWarning("QBackingStoreDefaultCompositor: the QRhi has changed unexpectedly, this should not happen");
61 return nullptr;
62 }
63
64 QImage image = sourceImage;
65
66 bool needsConversion = false;
67 *flags = {};
68
69 switch (image.format()) {
76 break;
82 break;
85 // no fast path atm
86 needsConversion = true;
87 break;
90 // no fast path atm
91 needsConversion = true;
92 break;
93 default:
94 needsConversion = true;
95 break;
96 }
97
98 if (image.size().isEmpty())
99 return nullptr;
100
101 const bool resized = !m_texture || m_texture->pixelSize() != image.size();
102 if (dirtyRegion.isEmpty() && !resized)
103 return m_texture;
104
105 if (needsConversion)
106 image = image.convertToFormat(QImage::Format_RGBA8888);
107 else
108 image.detach(); // if it was just wrapping data, that's no good, we need ownership, so detach
109
110 if (resized) {
111 if (!m_texture)
112 m_texture = rhi->newTexture(QRhiTexture::RGBA8, image.size());
113 else
114 m_texture->setPixelSize(image.size());
115 m_texture->create();
116 resourceUpdates->uploadTexture(m_texture, image);
117 } else {
118 QRect imageRect = image.rect();
119 QRect rect = dirtyRegion.boundingRect() & imageRect;
121 subresDesc.setSourceTopLeft(rect.topLeft());
122 subresDesc.setSourceSize(rect.size());
123 subresDesc.setDestinationTopLeft(rect.topLeft());
124 QRhiTextureUploadDescription uploadDesc(QRhiTextureUploadEntry(0, 0, subresDesc));
125 resourceUpdates->uploadTexture(m_texture, uploadDesc);
126 }
127
128 return m_texture;
129}
130
131static inline QRect scaledRect(const QRect &rect, qreal factor)
132{
133 return QRect(rect.topLeft() * factor, rect.size() * factor);
134}
135
136static inline QPoint scaledOffset(const QPoint &pt, qreal factor)
137{
138 return pt * factor;
139}
140
141static QRegion scaledRegion(const QRegion &region, qreal factor, const QPoint &offset)
142{
143 if (offset.isNull() && factor <= 1)
144 return region;
145
147 rects.reserve(region.rectCount());
148 for (const QRect &rect : region)
149 rects.append(scaledRect(rect.translated(offset), factor));
150
151 QRegion deviceRegion;
152 deviceRegion.setRects(rects.constData(), rects.size());
153 return deviceRegion;
154}
155
156static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport, bool invertY)
157{
158 qreal x_scale = target.width() / viewport.width();
159 qreal y_scale = target.height() / viewport.height();
160
161 const QPointF relative_to_viewport = target.topLeft() - viewport.topLeft();
162 qreal x_translate = x_scale - 1 + ((relative_to_viewport.x() / viewport.width()) * 2);
163 qreal y_translate;
164 if (invertY)
165 y_translate = y_scale - 1 + ((relative_to_viewport.y() / viewport.height()) * 2);
166 else
167 y_translate = -y_scale + 1 - ((relative_to_viewport.y() / viewport.height()) * 2);
168
170 matrix(0,3) = x_translate;
171 matrix(1,3) = y_translate;
172
173 matrix(0,0) = x_scale;
174 matrix(1,1) = y_scale;
175
176 return matrix;
177}
178
181 TopLeft
182};
183
184static QMatrix3x3 sourceTransform(const QRectF &subTexture,
185 const QSize &textureSize,
187{
188 qreal x_scale = subTexture.width() / textureSize.width();
189 qreal y_scale = subTexture.height() / textureSize.height();
190
191 const QPointF topLeft = subTexture.topLeft();
192 qreal x_translate = topLeft.x() / textureSize.width();
193 qreal y_translate = topLeft.y() / textureSize.height();
194
195 if (origin == SourceTransformOrigin::TopLeft) {
196 y_scale = -y_scale;
197 y_translate = 1 - y_translate;
198 }
199
201 matrix(0,2) = x_translate;
202 matrix(1,2) = y_translate;
203
204 matrix(0,0) = x_scale;
205 matrix(1,1) = y_scale;
206
207 return matrix;
208}
209
210static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
211{
212 return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1,
213 topLeftRect.width(), topLeftRect.height());
214}
215
217 int idx,
219 const QRect &deviceWindowRect,
220 const QPoint &offset,
221 bool invertTargetY,
222 bool invertSource,
225{
226 const QRect clipRect = textures->clipRect(idx);
227 if (clipRect.isEmpty())
228 return false;
229
230 QRect rectInWindow = textures->geometry(idx);
231 // relative to the TLW, not necessarily our window (if the flush is for a native child widget), have to adjust
232 rectInWindow.translate(-offset);
233
234 const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft());
235 const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height());
236
237 *target = targetTransform(scaledRect(clippedRectInWindow, window->devicePixelRatio()),
238 deviceWindowRect,
239 invertTargetY);
240
241 *source = sourceTransform(scaledRect(srcRect, window->devicePixelRatio()),
242 scaledRect(rectInWindow, window->devicePixelRatio()).size(),
244
245 return true;
246}
247
249{
250 QFile f(name);
251 if (f.open(QIODevice::ReadOnly))
252 return QShader::fromSerialized(f.readAll());
253
254 qWarning("QBackingStoreDefaultCompositor: Could not find built-in shader %s "
255 "(is something wrong with QtGui library resources?)",
257 return QShader();
258}
259
260static void updateMatrix3x3(QRhiResourceUpdateBatch *resourceUpdates, QRhiBuffer *ubuf, const QMatrix3x3 &m)
261{
262 // mat3 is still 4 floats per column in the uniform buffer (but there is no
263 // 4th column), so 48 bytes altogether, not 36 or 64.
264
265 float f[12];
266 const float *src = static_cast<const float *>(m.constData());
267 float *dst = f;
268 memcpy(dst, src, 3 * sizeof(float));
269 memcpy(dst + 4, src + 3, 3 * sizeof(float));
270 memcpy(dst + 8, src + 6, 3 * sizeof(float));
271
272 resourceUpdates->updateDynamicBuffer(ubuf, 64, 48, f);
273}
274
275enum class PipelineBlend {
276 None,
277 Alpha,
279};
280
283 QRhiSwapChain *swapchain,
284 PipelineBlend blend)
285{
287
288 switch (blend) {
290 {
292 blend.enable = true;
297 ps->setTargetBlends({ blend });
298 }
299 break;
301 {
303 blend.enable = true;
308 ps->setTargetBlends({ blend });
309 }
310 break;
311 default:
312 break;
313 }
314
315 ps->setShaderStages({
316 { QRhiShaderStage::Vertex, getShader(":/qt-project.org/gui/painting/shaders/backingstorecompose.vert.qsb"_L1) },
317 { QRhiShaderStage::Fragment, getShader(":/qt-project.org/gui/painting/shaders/backingstorecompose.frag.qsb"_L1) }
318 });
319 QRhiVertexInputLayout inputLayout;
320 inputLayout.setBindings({ { 5 * sizeof(float) } });
321 inputLayout.setAttributes({
323 { 0, 1, QRhiVertexInputAttribute::Float2, quint32(3 * sizeof(float)) }
324 });
325 ps->setVertexInputLayout(inputLayout);
328
329 if (!ps->create()) {
330 qWarning("QBackingStoreDefaultCompositor: Failed to build graphics pipeline");
331 delete ps;
332 return nullptr;
333 }
334 return ps;
335}
336
337static const int UBUF_SIZE = 120;
338
339QBackingStoreDefaultCompositor::PerQuadData QBackingStoreDefaultCompositor::createPerQuadData(QRhiTexture *texture, QRhiTexture *textureExtra)
340{
341 PerQuadData d;
342
344 if (!d.ubuf->create())
345 qWarning("QBackingStoreDefaultCompositor: Failed to create uniform buffer");
346
347 d.srb = m_rhi->newShaderResourceBindings();
348 d.srb->setBindings({
351 });
352 if (!d.srb->create())
353 qWarning("QBackingStoreDefaultCompositor: Failed to create srb");
354 d.lastUsedTexture = texture;
355
356 if (textureExtra) {
357 d.srbExtra = m_rhi->newShaderResourceBindings();
358 d.srbExtra->setBindings({
361 });
362 if (!d.srbExtra->create())
363 qWarning("QBackingStoreDefaultCompositor: Failed to create srb");
364 }
365
366 d.lastUsedTextureExtra = textureExtra;
367
368 return d;
369}
370
371void QBackingStoreDefaultCompositor::updatePerQuadData(PerQuadData *d, QRhiTexture *texture, QRhiTexture *textureExtra)
372{
373 // This whole check-if-texture-ptr-is-different is needed because there is
374 // nothing saying a QPlatformTextureList cannot return a different
375 // QRhiTexture* from the same index in a subsequent flush.
376
377 if (d->lastUsedTexture == texture || !d->srb)
378 return;
379
380 d->srb->setBindings({
383 });
384
386 d->lastUsedTexture = texture;
387
388 if (textureExtra) {
389 d->srbExtra->setBindings({
392 });
393
394 d->srbExtra->updateResources(QRhiShaderResourceBindings::BindingsAreSorted);
395 d->lastUsedTextureExtra = textureExtra;
396 }
397}
398
399void QBackingStoreDefaultCompositor::updateUniforms(PerQuadData *d, QRhiResourceUpdateBatch *resourceUpdates,
400 const QMatrix4x4 &target, const QMatrix3x3 &source, UpdateUniformOption option)
401{
402 resourceUpdates->updateDynamicBuffer(d->ubuf, 0, 64, target.constData());
403 updateMatrix3x3(resourceUpdates, d->ubuf, source);
404 float opacity = 1.0f;
405 resourceUpdates->updateDynamicBuffer(d->ubuf, 112, 4, &opacity);
406 qint32 textureSwizzle = static_cast<qint32>(option);
407 resourceUpdates->updateDynamicBuffer(d->ubuf, 116, 4, &textureSwizzle);
408}
409
410void QBackingStoreDefaultCompositor::ensureResources(QRhiSwapChain *swapchain, QRhiResourceUpdateBatch *resourceUpdates)
411{
412 static const float vertexData[] = {
413 -1, -1, 0, 0, 0,
414 -1, 1, 0, 0, 1,
415 1, -1, 0, 1, 0,
416 -1, 1, 0, 0, 1,
417 1, -1, 0, 1, 0,
418 1, 1, 0, 1, 1
419 };
420
421 if (!m_vbuf) {
422 m_vbuf = m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
423 if (m_vbuf->create())
424 resourceUpdates->uploadStaticBuffer(m_vbuf, vertexData);
425 else
426 qWarning("QBackingStoreDefaultCompositor: Failed to create vertex buffer");
427 }
428
429 if (!m_sampler) {
432 if (!m_sampler->create())
433 qWarning("QBackingStoreDefaultCompositor: Failed to create sampler");
434 }
435
436 if (!m_widgetQuadData.isValid())
437 m_widgetQuadData = createPerQuadData(m_texture);
438
439 QRhiShaderResourceBindings *srb = m_widgetQuadData.srb; // just for the layout
440 if (!m_psNoBlend)
441 m_psNoBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::None);
442 if (!m_psBlend)
443 m_psBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::Alpha);
444 if (!m_psPremulBlend)
445 m_psPremulBlend = createGraphicsPipeline(m_rhi, srb, swapchain, PipelineBlend::PremulAlpha);
446}
447
449 QRhi *rhi,
450 QRhiSwapChain *swapchain,
452 qreal sourceDevicePixelRatio,
453 const QRegion &region,
454 const QPoint &offset,
456 bool translucentBackground)
457{
458 Q_ASSERT(textures); // may be empty if there are no render-to-texture widgets at all, but null it cannot be
459
460 if (!m_rhi) {
461 m_rhi = rhi;
462 } else if (m_rhi != rhi) {
463 qWarning("QBackingStoreDefaultCompositor: the QRhi has changed unexpectedly, this should not happen");
465 }
466
467 if (!qt_window_private(window)->receivedExpose)
469
470 qCDebug(lcQpaBackingStore) << "Composing and flushing" << region << "of" << window
471 << "at offset" << offset << "with" << textures->count() << "texture(s) in" << textures
472 << "via swapchain" << swapchain;
473
475
476 if (swapchain->currentPixelSize() != swapchain->surfacePixelSize())
477 swapchain->createOrResize();
478
479 // Start recording a new frame.
480 QRhi::FrameOpResult frameResult = rhi->beginFrame(swapchain);
481 if (frameResult == QRhi::FrameOpSwapChainOutOfDate) {
482 if (!swapchain->createOrResize())
484 frameResult = rhi->beginFrame(swapchain);
485 }
486 if (frameResult == QRhi::FrameOpDeviceLost)
488 if (frameResult != QRhi::FrameOpSuccess)
490
491 // Prepare resource updates.
492 QRhiResourceUpdateBatch *resourceUpdates = rhi->nextResourceUpdateBatch();
493 QPlatformBackingStore::TextureFlags flags;
494
495 bool gotTextureFromGraphicsBuffer = false;
496 if (QPlatformGraphicsBuffer *graphicsBuffer = backingStore->graphicsBuffer()) {
497 if (graphicsBuffer->lock(QPlatformGraphicsBuffer::SWReadAccess)) {
498 const QImage::Format format = QImage::toImageFormat(graphicsBuffer->format());
499 const QSize size = graphicsBuffer->size();
500 QImage wrapperImage(graphicsBuffer->data(), size.width(), size.height(), graphicsBuffer->bytesPerLine(), format);
501 toTexture(wrapperImage, rhi, resourceUpdates, scaledRegion(region, sourceDevicePixelRatio, offset), &flags);
502 gotTextureFromGraphicsBuffer = true;
503 graphicsBuffer->unlock();
504 if (graphicsBuffer->origin() == QPlatformGraphicsBuffer::OriginBottomLeft)
506 }
507 }
508 if (!gotTextureFromGraphicsBuffer)
509 toTexture(backingStore, rhi, resourceUpdates, scaledRegion(region, sourceDevicePixelRatio, offset), &flags);
510
511 ensureResources(swapchain, resourceUpdates);
512
513#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
514 const UpdateUniformOption uniformOption = (flags & QPlatformBackingStore::TextureSwizzle) != 0? NeedsRedBlueSwap : NoOption;
515#else
516 const UpdateUniformOption uniformOption = (flags & QPlatformBackingStore::TextureSwizzle) != 0? NeedsAlphaRotate : NoOption;
517#endif
518 const bool premultiplied = (flags & QPlatformBackingStore::TexturePremultiplied) != 0;
522
523 const qreal dpr = window->devicePixelRatio();
524 const QRect deviceWindowRect = scaledRect(QRect(QPoint(), window->size()), dpr);
525
526 const bool invertTargetY = rhi->clipSpaceCorrMatrix().data()[5] < 0.0f;
527 const bool invertSource = rhi->isYUpInFramebuffer() != rhi->isYUpInNDC();
528 if (m_texture) {
529 // The backingstore is for the entire tlw. In case of native children, offset tells the position
530 // relative to the tlw. The window rect is scaled by the source device pixel ratio to get
531 // the source rect.
532 const QRect sourceWindowRect = scaledRect(QRect(QPoint(), window->size()), sourceDevicePixelRatio);
533 const QPoint sourceWindowOffset = scaledOffset(offset, sourceDevicePixelRatio);
534 const QRect srcRect = toBottomLeftRect(sourceWindowRect.translated(sourceWindowOffset), m_texture->pixelSize().height());
535 const QMatrix3x3 source = sourceTransform(srcRect, m_texture->pixelSize(), origin);
536 QMatrix4x4 target; // identity
537 if (invertTargetY)
538 target.data()[5] = -1.0f;
539 updateUniforms(&m_widgetQuadData, resourceUpdates, target, source, uniformOption);
540 }
541
542 const int textureWidgetCount = textures->count();
543 const int oldTextureQuadDataCount = m_textureQuadData.size();
544 if (oldTextureQuadDataCount != textureWidgetCount) {
545 for (int i = textureWidgetCount; i < oldTextureQuadDataCount; ++i)
546 m_textureQuadData[i].reset();
547 m_textureQuadData.resize(textureWidgetCount);
548 }
549
550 for (int i = 0; i < textureWidgetCount; ++i) {
553 if (!prepareDrawForRenderToTextureWidget(textures, i, window, deviceWindowRect,
554 offset, invertTargetY, invertSource, &target, &source))
555 {
556 m_textureQuadData[i].reset();
557 continue;
558 }
559 QRhiTexture *t = textures->texture(i);
560 QRhiTexture *tExtra = textures->textureExtra(i);
561 if (t) {
562 if (!m_textureQuadData[i].isValid()) {
563 m_textureQuadData[i] = createPerQuadData(t, tExtra);
564 }
565 else {
566 updatePerQuadData(&m_textureQuadData[i], t, tExtra);
567 }
568 updateUniforms(&m_textureQuadData[i], resourceUpdates, target, source, NoOption);
569 } else {
570 m_textureQuadData[i].reset();
571 }
572 }
573
574 // Record the render pass (with committing the resource updates).
576 const QSize outputSizeInPixels = swapchain->currentPixelSize();
577 QColor clearColor = translucentBackground ? Qt::transparent : Qt::black;
578
579 cb->resourceUpdate(resourceUpdates);
580
581 auto render = [&](std::optional<QRhiSwapChain::StereoTargetBuffer> buffer = std::nullopt) {
582 QRhiRenderTarget* target = nullptr;
583 if (buffer.has_value())
584 target = swapchain->currentFrameRenderTarget(buffer.value());
585 else
586 target = swapchain->currentFrameRenderTarget();
587
588 cb->beginPass(target, clearColor, { 1.0f, 0 });
589
590 cb->setGraphicsPipeline(m_psNoBlend);
591 cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
592 QRhiCommandBuffer::VertexInput vbufBinding(m_vbuf, 0);
593 cb->setVertexInput(0, 1, &vbufBinding);
594
595 // Textures for renderToTexture widgets.
596 for (int i = 0; i < textureWidgetCount; ++i) {
597 if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) {
598 if (m_textureQuadData[i].isValid()) {
599
600 QRhiShaderResourceBindings* srb = m_textureQuadData[i].srb;
601 if (buffer == QRhiSwapChain::RightBuffer && m_textureQuadData[i].srbExtra)
602 srb = m_textureQuadData[i].srbExtra;
603
604 cb->setShaderResources(srb);
605 cb->draw(6);
606 }
607 }
608 }
609
610 cb->setGraphicsPipeline(premultiplied ? m_psPremulBlend : m_psBlend);
611
612 // Backingstore texture with the normal widgets.
613 if (m_texture) {
614 cb->setShaderResources(m_widgetQuadData.srb);
615 cb->draw(6);
616 }
617
618 // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set.
619 for (int i = 0; i < textureWidgetCount; ++i) {
620 const QPlatformTextureList::Flags flags = textures->flags(i);
622 if (m_textureQuadData[i].isValid()) {
624 cb->setGraphicsPipeline(m_psPremulBlend);
625 else
626 cb->setGraphicsPipeline(m_psBlend);
627
628 QRhiShaderResourceBindings* srb = m_textureQuadData[i].srb;
629 if (buffer == QRhiSwapChain::RightBuffer && m_textureQuadData[i].srbExtra)
630 srb = m_textureQuadData[i].srbExtra;
631
632 cb->setShaderResources(srb);
633 cb->draw(6);
634 }
635 }
636 }
637
638 cb->endPass();
639 };
640
641 if (swapchain->window()->format().stereo()) {
644 } else
645 render();
646
647 rhi->endFrame(swapchain);
648
650}
651
QRhiTexture * toTexture(const QPlatformBackingStore *backingStore, QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates, const QRegion &dirtyRegion, QPlatformBackingStore::TextureFlags *flags) const
QPlatformBackingStore::FlushResult flush(QPlatformBackingStore *backingStore, QRhi *rhi, QRhiSwapChain *swapchain, QWindow *window, qreal sourceDevicePixelRatio, const QRegion &region, const QPoint &offset, QPlatformTextureList *textures, bool translucentBackground)
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void start() noexcept
Starts this timer.
\inmodule QtCore
Definition qfile.h:93
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGBA8888
Definition qimage.h:59
@ Format_RGB30
Definition qimage.h:63
@ Format_RGB32
Definition qimage.h:46
@ Format_RGBA8888_Premultiplied
Definition qimage.h:60
@ Format_A2BGR30_Premultiplied
Definition qimage.h:62
@ Format_BGR30
Definition qimage.h:61
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
@ Format_A2RGB30_Premultiplied
Definition qimage.h:64
@ Format_ARGB32
Definition qimage.h:47
@ Format_RGBX8888
Definition qimage.h:58
static QImage::Format toImageFormat(QPixelFormat format) noexcept
Converts format into a QImage::Format.
Definition qimage.cpp:5730
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
float * data()
Returns a pointer to the raw data of this matrix.
The QPlatformBackingStore class provides the drawing area for top-level windows.
virtual QImage toImage() const
Implemented in subclasses to return the content of the backingstore as a QImage.
virtual QPlatformGraphicsBuffer * graphicsBuffer() const
Accessor for a backingstores graphics buffer abstraction.
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:510
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:166
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:184
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:244
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:223
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:260
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
int rectCount() const noexcept
void setRects(const QRect *rect, int num)
Sets the region using the array of rectangles specified by rects and number.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
\inmodule QtGui
Definition qrhi.h:834
@ Immutable
Definition qrhi.h:837
@ Dynamic
Definition qrhi.h:839
@ VertexBuffer
Definition qrhi.h:843
@ UniformBuffer
Definition qrhi.h:845
virtual bool create()=0
Creates the corresponding native graphics resources.
\inmodule QtGui
Definition qrhi.h:1614
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
Definition qrhi.h:1643
\inmodule QtGui
Definition qrhi.h:1241
void setTargetBlends(std::initializer_list< TargetBlend > list)
Sets the list of render target blend settings.
Definition qrhi.h:1369
void setShaderResourceBindings(QRhiShaderResourceBindings *srb)
Associates with srb describing the resource binding layout and the resources (QRhiBuffer,...
Definition qrhi.h:1433
void setVertexInputLayout(const QRhiVertexInputLayout &layout)
Specifies the vertex input layout.
Definition qrhi.h:1430
void setShaderStages(std::initializer_list< QRhiShaderStage > list)
Sets the list of shader stages.
Definition qrhi.h:1417
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc)
Associates with the specified QRhiRenderPassDescriptor desc.
Definition qrhi.h:1436
virtual bool create()=0
Creates the corresponding native graphics resources.
\inmodule QtGui
Definition qrhi.h:1135
\inmodule QtGui
Definition qrhi.h:1694
void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
Enqueues updating a region of a QRhiBuffer buf created with the type QRhiBuffer::Dynamic.
Definition qrhi.cpp:8595
void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
Enqueues updating a region of a QRhiBuffer buf created with the type QRhiBuffer::Immutable or QRhiBuf...
Definition qrhi.cpp:8615
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
Enqueues uploading the image data for one or more mip levels in one or more layers of the texture tex...
Definition qrhi.cpp:8681
virtual bool create()=0
@ ClampToEdge
Definition qrhi.h:1017
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
Definition qrhi.cpp:5406
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
Definition qrhi.cpp:5292
\inmodule QtGui
Definition qrhi.h:1190
\inmodule QtGui
Definition qrhi.h:1513
QSize currentPixelSize() const
Definition qrhi.h:1559
virtual bool createOrResize()=0
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
virtual QRhiRenderTarget * currentFrameRenderTarget()=0
virtual QSize surfacePixelSize()=0
QRhiRenderPassDescriptor * renderPassDescriptor() const
Definition qrhi.h:1556
virtual QRhiCommandBuffer * currentFrameCommandBuffer()=0
QWindow * window() const
Definition qrhi.h:1538
\inmodule QtGui
Definition qrhi.h:704
\inmodule QtGui
Definition qrhi.h:681
\inmodule QtGui
Definition qrhi.h:883
virtual bool create()=0
Creates the corresponding native graphics resources.
QSize pixelSize() const
Definition qrhi.h:963
void setPixelSize(const QSize &sz)
Sets the texture size, specified in pixels, to sz.
Definition qrhi.h:964
\inmodule QtGui
Definition qrhi.h:313
void setBindings(std::initializer_list< QRhiVertexInputBinding > list)
Sets the bindings from the specified list.
Definition qrhi.h:317
void setAttributes(std::initializer_list< QRhiVertexInputAttribute > list)
Sets the attributes from the specified list.
Definition qrhi.h:329
\inmodule QtGui
Definition qrhi.h:1767
QRhiBuffer * newBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
Definition qrhi.cpp:10079
QMatrix4x4 clipSpaceCorrMatrix() const
Definition qrhi.cpp:9662
bool isYUpInFramebuffer() const
Definition qrhi.cpp:9601
bool isYUpInNDC() const
Definition qrhi.cpp:9615
QRhiShaderResourceBindings * newShaderResourceBindings()
Definition qrhi.cpp:10060
FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags={})
Starts a new frame targeting the next available buffer of swapChain.
Definition qrhi.cpp:10308
QRhiSampler * newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode addressU, QRhiSampler::AddressMode addressV, QRhiSampler::AddressMode addressW=QRhiSampler::Repeat)
Definition qrhi.cpp:10228
QRhiGraphicsPipeline * newGraphicsPipeline()
Definition qrhi.cpp:10037
FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags={})
Ends, commits, and presents a frame that was started in the last beginFrame() on swapChain.
Definition qrhi.cpp:10343
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
Definition qrhi.cpp:10133
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
Definition qrhi.cpp:8854
FrameOpResult
Describes the result of operations that can have a soft failure.
Definition qrhi.h:1786
@ FrameOpSuccess
Definition qrhi.h:1787
@ FrameOpSwapChainOutOfDate
Definition qrhi.h:1789
@ FrameOpDeviceLost
Definition qrhi.h:1790
\inmodule QtGui
Definition qshader.h:81
static QShader fromSerialized(const QByteArray &data)
Creates a new QShader instance from the given data.
Definition qshader.cpp:510
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
constexpr size_type size() const noexcept
void resize(qsizetype sz)
void append(const T &t)
const T * constData() const
void reserve(qsizetype sz)
static QWindowPrivate * get(QWindow *window)
Definition qwindow_p.h:94
QElapsedTimer lastComposeTime
Definition qwindow_p.h:147
\inmodule QtGui
Definition qwindow.h:63
QSurfaceFormat format() const override
Returns the actual format of this window.
Definition qwindow.cpp:888
rect
[4]
Combined button and popup list for selecting options.
@ transparent
Definition qnamespace.h:46
@ black
Definition qnamespace.h:29
Definition image.cpp:4
static QRegion scaledRegion(const QRegion &region, qreal factor, const QPoint &offset)
static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport, bool invertY)
static const int UBUF_SIZE
static QRect scaledRect(const QRect &rect, qreal factor)
static QMatrix3x3 sourceTransform(const QRectF &subTexture, const QSize &textureSize, SourceTransformOrigin origin)
static void updateMatrix3x3(QRhiResourceUpdateBatch *resourceUpdates, QRhiBuffer *ubuf, const QMatrix3x3 &m)
static QRhiGraphicsPipeline * createGraphicsPipeline(QRhi *rhi, QRhiShaderResourceBindings *srb, QRhiSwapChain *swapchain, PipelineBlend blend)
static QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
static QShader getShader(const QString &name)
static QPoint scaledOffset(const QPoint &pt, qreal factor)
static bool prepareDrawForRenderToTextureWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect, const QPoint &offset, bool invertTargetY, bool invertSource, QMatrix4x4 *target, QMatrix3x3 *source)
#define Q_FALLTHROUGH()
#define qWarning
Definition qlogging.h:162
#define qCDebug(category,...)
const GLfloat * m
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint const GLuint GLuint const GLuint * textures
GLfloat GLfloat f
GLenum src
GLenum GLuint buffer
GLenum GLenum dst
GLenum target
GLbitfield flags
GLenum GLuint texture
GLenum GLuint GLintptr offset
GLuint name
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
GLuint GLenum matrix
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint GLenum option
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define qPrintable(string)
Definition qstring.h:1391
unsigned int quint32
Definition qtypes.h:45
int qint32
Definition qtypes.h:44
double qreal
Definition qtypes.h:92
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2864
view viewport() -> scroll(dx, dy, deviceRect)
aWidget window() -> setWindowTitle("New Window Title")
[2]
myWidget render(this)