4#include <qohosplatformbackingstoregl.h>
6#include <QtGui/private/qhighdpiscaling_p.h>
7#include <QtOpenGL/private/qopenglpaintdevice_p.h>
8#include <QtGui/qopenglcontext.h>
9#include <QtOpenGL/qopenglframebufferobject.h>
10#include <QtGui/qopenglfunctions.h>
11#include <QtOpenGL/qopengltextureblitter.h>
14#include <qohosplatformscreen.h>
15#include <qohosplatformwindow.h>
16#include <render/qohosview.h>
25 auto bottomLeftOffset = QPointF(
27 srcTextureSize.height() - targetSubTexture.bottomRight().y() - 1.0f);
28 auto normalizedOffset = QPointF(
29 bottomLeftOffset.x() / srcTextureSize.width(),
30 bottomLeftOffset.y() / srcTextureSize.height());
33 result(0, 2) =
static_cast<
float>(normalizedOffset.x());
34 result(1, 2) =
static_cast<
float>(normalizedOffset.y());
36 QSizeF textureScaleUv{
37 targetSubTexture.width() / srcTextureSize.width(),
38 targetSubTexture.height() / srcTextureSize.height()};
40 result(0, 0) =
static_cast<
float>(textureScaleUv.width());
41 result(1, 1) =
static_cast<
float>(textureScaleUv.height());
62 auto *glFuncs = glCtx.functions();
63 glFuncs->glClearColor(
64 static_cast<
float>(clearColor.redF()),
65 static_cast<
float>(clearColor.greenF()),
66 static_cast<
float>(clearColor.blueF()),
67 static_cast<
float>(clearColor.alphaF()));
68 glFuncs->glViewport(0, 0, viewportSize.width(), viewportSize.height());
69 glFuncs->glClear(GL_COLOR_BUFFER_BIT);
73 QOpenGLTextureBlitter &blitter,
74 QOpenGLFramebufferObject &framebuffer,
77 static const QMatrix4x4 identityMatrix = {};
79 auto dstTransform = identityMatrix;
80 auto srcTransform = makeSourceTransform(srcRect, framebuffer.size());
83 blitter.blit(framebuffer.texture(), dstTransform, srcTransform);
84 unbindTextureBlitter(blitter);
100 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(window);
101 if (platformWindow ==
nullptr)
104 auto *view = platformWindow->ownedViewOrNull();
108 auto optSurfaceResolution = view->surfaceResolution();
109 return optSurfaceResolution.has_value()
113 .platformWindow = platformWindow,
115 .unscaledWindowGeometry = platformWindow->windowGeometry(),
116 .surfaceResolution = optSurfaceResolution.value(),
129 QWindow *targetWindow,
const QRegion &relToParentWindowRegion,
130 const QPoint &relToRootWindowOffset)
override;
131 void resize(
const QSize &size,
const QRegion &staticContents)
override;
138 void tryRecreatePaintDeviceIfNeeded();
140 std::unique_ptr<QPaintDevice> m_dummyPaintDevice;
141 std::unique_ptr<QOpenGLPaintDevice> m_paintDevice;
142 std::unique_ptr<QOpenGLContext> m_glContext;
143 std::unique_ptr<QOpenGLFramebufferObject> m_framebuffer;
144 std::unique_ptr<QOpenGLTextureBlitter> m_blitter;
145 std::optional<QSize> m_pendingResizeRequest;
157 return m_paintDevice ? m_paintDevice.get() : m_dummyPaintDevice.get();
161 QWindow *targetWindow,
const QRegion &relToParentWindowRegion,
162 const QPoint &relToRootWindowOffset)
164 Q_UNUSED(relToParentWindowRegion);
166 auto optSrcWindowCtxData = RenderContextData::tryCreateForQWindow(window());
167 auto optDstWidnowCtxData = RenderContextData::tryCreateForQWindow(targetWindow);
169 if (!optSrcWindowCtxData.has_value() || !optDstWidnowCtxData.has_value())
175 auto dstWindowCtxData = optDstWidnowCtxData.value();
177 unbindFrameBufferObject(*m_framebuffer);
178 m_glContext->makeCurrent(dstWindowCtxData.qWindow);
181 m_blitter = std::make_unique<QOpenGLTextureBlitter>();
185 auto dstSize = dstWindowCtxData.unscaledWindowGeometry.size();
187 auto srcRect = QRect(
188 relToRootWindowOffset, dstWindowCtxData.platformWindow->windowGeometry().size());
190 setViewportAndClearColorBuffer(*m_glContext, dstSize, QColor(Qt::transparent));
192 blitFramebufferToWindow(*m_blitter, *m_framebuffer, srcRect);
194 m_glContext->swapBuffers(dstWindowCtxData.qWindow);
199 m_pendingResizeRequest = targetSize;
204 auto optRootWindowCtxData = RenderContextData::tryCreateForQWindow(window());
205 if (!optRootWindowCtxData.has_value())
208 auto rootWindowCtxData = optRootWindowCtxData.value();
211 m_glContext = std::make_unique<QOpenGLContext>(rootWindowCtxData.qWindow);
212 m_glContext->setFormat(rootWindowCtxData.qWindow->format());
213 m_glContext->create();
216 m_glContext->makeCurrent(rootWindowCtxData.qWindow);
218 auto targetFramebufferResolution = m_pendingResizeRequest.value_or(
219 rootWindowCtxData.platformWindow->windowGeometry().size());
220 if (!m_framebuffer || m_framebuffer->size() != targetFramebufferResolution) {
221 m_framebuffer = std::make_unique<QOpenGLFramebufferObject>(targetFramebufferResolution);
222 m_paintDevice = std::make_unique<QOpenGLPaintDevice>(targetFramebufferResolution);
223 if (QHighDpiScaling::isActive()) {
224 auto pixelDensity =
static_cast<
QOhosPlatformScreen *>(rootWindowCtxData.platformWindow->screen())->pixelScalingCoefficient();
225 m_paintDevice->setDevicePixelRatio(pixelDensity);
228 m_framebuffer->bind();
229 setViewportAndClearColorBuffer(*m_glContext, targetFramebufferResolution, QColor(Qt::transparent));
235 if (!m_framebuffer || m_pendingResizeRequest.has_value())
236 tryRecreatePaintDeviceIfNeeded();
241 m_pendingResizeRequest = {};
243 m_glContext->makeCurrent(window());
244 m_framebuffer->bind();
255 ? m_framebuffer->toImage()
Combined button and popup list for selecting options.
void blitFramebufferToWindow(QOpenGLTextureBlitter &blitter, QOpenGLFramebufferObject &framebuffer, const QRect &srcRect)
void unbindFrameBufferObject(QOpenGLFramebufferObject &fbo)
void unbindTextureBlitter(QOpenGLTextureBlitter &blitter)
void setViewportAndClearColorBuffer(QOpenGLContext &glCtx, const QSize &viewportSize, const QColor &clearColor)
QMatrix3x3 makeSourceTransform(const QRect &targetSubTexture, const QSizeF &srcTextureSize)
QRect unscaledWindowGeometry
QOhosPlatformWindow * platformWindow
static std::optional< RenderContextData > tryCreateForQWindow(QWindow *window)