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>
13#include <qohosplatformscreen.h>
14#include <qohosplatformwindow.h>
15#include <render/qohosview.h>
24 auto bottomLeftOffset = QPointF(
26 srcTextureSize.height() - targetSubTexture.bottomRight().y() - 1.0f);
27 auto normalizedOffset = QPointF(
28 bottomLeftOffset.x() / srcTextureSize.width(),
29 bottomLeftOffset.y() / srcTextureSize.height());
32 result(0, 2) =
static_cast<
float>(normalizedOffset.x());
33 result(1, 2) =
static_cast<
float>(normalizedOffset.y());
35 QSizeF textureScaleUv{
36 targetSubTexture.width() / srcTextureSize.width(),
37 targetSubTexture.height() / srcTextureSize.height()};
39 result(0, 0) =
static_cast<
float>(textureScaleUv.width());
40 result(1, 1) =
static_cast<
float>(textureScaleUv.height());
61 auto *glFuncs = glCtx.functions();
62 glFuncs->glClearColor(
63 static_cast<
float>(clearColor.redF()),
64 static_cast<
float>(clearColor.greenF()),
65 static_cast<
float>(clearColor.blueF()),
66 static_cast<
float>(clearColor.alphaF()));
67 glFuncs->glViewport(0, 0, viewportSize.width(), viewportSize.height());
68 glFuncs->glClear(GL_COLOR_BUFFER_BIT);
72 QOpenGLTextureBlitter &blitter,
73 QOpenGLFramebufferObject &framebuffer,
76 static const QMatrix4x4 identityMatrix = {};
78 auto dstTransform = identityMatrix;
79 auto srcTransform = makeSourceTransform(srcRect, framebuffer.size());
82 blitter.blit(framebuffer.texture(), dstTransform, srcTransform);
83 unbindTextureBlitter(blitter);
99 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(window);
100 if (platformWindow ==
nullptr)
103 auto *view = platformWindow->ownedViewOrNull();
107 auto optSurfaceResolution = view->surfaceResolution();
108 return optSurfaceResolution.hasValue()
112 .platformWindow = platformWindow,
114 .unscaledWindowGeometry = platformWindow->windowGeometry(),
115 .surfaceResolution = optSurfaceResolution.value(),
128 QWindow *targetWindow,
const QRegion &relToParentWindowRegion,
129 const QPoint &relToRootWindowOffset)
override;
130 void resize(
const QSize &size,
const QRegion &staticContents)
override;
137 void tryRecreatePaintDeviceIfNeeded();
139 std::unique_ptr<QPaintDevice> m_dummyPaintDevice;
140 std::unique_ptr<QOpenGLPaintDevice> m_paintDevice;
141 std::unique_ptr<QOpenGLContext> m_glContext;
142 std::unique_ptr<QOpenGLFramebufferObject> m_framebuffer;
143 std::unique_ptr<QOpenGLTextureBlitter> m_blitter;
144 QOhosOptional<QSize> m_pendingResizeRequest;
156 return m_paintDevice ? m_paintDevice.get() : m_dummyPaintDevice.get();
160 QWindow *targetWindow,
const QRegion &relToParentWindowRegion,
161 const QPoint &relToRootWindowOffset)
163 Q_UNUSED(relToParentWindowRegion);
165 auto optSrcWindowCtxData = RenderContextData::tryCreateForQWindow(window());
166 auto optDstWidnowCtxData = RenderContextData::tryCreateForQWindow(targetWindow);
168 if (!optSrcWindowCtxData.hasValue() || !optDstWidnowCtxData.hasValue())
174 auto dstWindowCtxData = optDstWidnowCtxData.value();
176 unbindFrameBufferObject(*m_framebuffer);
177 m_glContext->makeCurrent(dstWindowCtxData.qWindow);
180 m_blitter = std::make_unique<QOpenGLTextureBlitter>();
184 auto dstSize = dstWindowCtxData.unscaledWindowGeometry.size();
186 auto srcRect = QRect(
187 relToRootWindowOffset, dstWindowCtxData.platformWindow->windowGeometry().size());
189 setViewportAndClearColorBuffer(*m_glContext, dstSize, QColor(Qt::transparent));
191 blitFramebufferToWindow(*m_blitter, *m_framebuffer, srcRect);
193 m_glContext->swapBuffers(dstWindowCtxData.qWindow);
198 m_pendingResizeRequest = targetSize;
203 auto optRootWindowCtxData = RenderContextData::tryCreateForQWindow(window());
204 if (!optRootWindowCtxData.hasValue())
207 auto rootWindowCtxData = optRootWindowCtxData.value();
210 m_glContext = std::make_unique<QOpenGLContext>(rootWindowCtxData.qWindow);
211 m_glContext->setFormat(rootWindowCtxData.qWindow->format());
212 m_glContext->create();
215 m_glContext->makeCurrent(rootWindowCtxData.qWindow);
217 auto targetFramebufferResolution = m_pendingResizeRequest.valueOr(
218 rootWindowCtxData.platformWindow->windowGeometry().size());
219 if (!m_framebuffer || m_framebuffer->size() != targetFramebufferResolution) {
220 m_framebuffer = std::make_unique<QOpenGLFramebufferObject>(targetFramebufferResolution);
221 m_paintDevice = std::make_unique<QOpenGLPaintDevice>(targetFramebufferResolution);
222 if (QHighDpiScaling::isActive()) {
223 auto pixelDensity =
static_cast<
QOhosPlatformScreen *>(rootWindowCtxData.platformWindow->screen())->pixelScalingCoefficient();
224 m_paintDevice->setDevicePixelRatio(pixelDensity);
227 m_framebuffer->bind();
228 setViewportAndClearColorBuffer(*m_glContext, targetFramebufferResolution, QColor(Qt::transparent));
234 if (!m_framebuffer || m_pendingResizeRequest.hasValue())
235 tryRecreatePaintDeviceIfNeeded();
240 m_pendingResizeRequest = makeEmptyQOhosOptional();
242 m_glContext->makeCurrent(window());
243 m_framebuffer->bind();
254 ? m_framebuffer->toImage()
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
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)
QOhosOptional< void > makeEmptyQOhosOptional()
static QOhosOptional< RenderContextData > tryCreateForQWindow(QWindow *window)
QRect unscaledWindowGeometry
QOhosPlatformWindow * platformWindow