Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qopenglpaintdevice.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 <qpaintengine.h>
6#include <qthreadstorage.h>
7
8#include <private/qopenglpaintdevice_p.h>
9#include <private/qobject_p.h>
10#include <private/qopenglcontext_p.h>
11#include <private/qopenglframebufferobject_p.h>
12#include <private/qopenglpaintengine_p.h>
13
14// for qt_defaultDpiX/Y
15#include <private/qfont_p.h>
16
17#include <qopenglfunctions.h>
18
20
83
95
107
115
124
132 : size(sz)
133 , ctx(QOpenGLContext::currentContext())
134 , dpmx(qt_defaultDpiX() * 100. / 2.54)
135 , dpmy(qt_defaultDpiY() * 100. / 2.54)
136 , devicePixelRatio(1.0)
137 , flipped(false)
138 , engine(nullptr)
139{
140}
141
145
147{
148public:
150 QPaintEngine *&localEngine = storage.localData();
151 if (!localEngine)
152 localEngine = new QOpenGL2PaintEngineEx;
153 return localEngine;
154 }
155
156private:
157 QThreadStorage<QPaintEngine *> storage;
158};
159
161
162
166QPaintEngine *QOpenGLPaintDevice::paintEngine() const
167{
168 if (d_ptr->engine)
169 return d_ptr->engine;
170
171 QPaintEngine *engine = qt_opengl_engine()->engine();
172 if (engine->isActive() && engine->paintDevice() != this) {
173 d_ptr->engine = new QOpenGL2PaintEngineEx;
174 return d_ptr->engine;
175 }
176
177 return engine;
178}
179
185{
186 return d_ptr->ctx;
187}
188
196{
197 return d_ptr->size;
198}
199
207{
208 d_ptr->size = size;
209}
210
218
224{
225 switch (metric) {
226 case PdmWidth:
227 return d_ptr->size.width();
228 case PdmHeight:
229 return d_ptr->size.height();
230 case PdmDepth:
231 return 32;
232 case PdmWidthMM:
233 return qRound(d_ptr->size.width() * 1000 / d_ptr->dpmx);
234 case PdmHeightMM:
235 return qRound(d_ptr->size.height() * 1000 / d_ptr->dpmy);
236 case PdmNumColors:
237 return 0;
238 case PdmDpiX:
239 return qRound(d_ptr->dpmx * 0.0254);
240 case PdmDpiY:
241 return qRound(d_ptr->dpmy * 0.0254);
242 case PdmPhysicalDpiX:
243 return qRound(d_ptr->dpmx * 0.0254);
244 case PdmPhysicalDpiY:
245 return qRound(d_ptr->dpmy * 0.0254);
247 return d_ptr->devicePixelRatio;
250
251 default:
252 qWarning("QOpenGLPaintDevice::metric() - metric %d not known", metric);
253 return 0;
254 }
255}
256
264{
265 return d_ptr->dpmx;
266}
267
275{
276 return d_ptr->dpmy;
277}
278
286{
287 d_ptr->dpmx = dpmx;
288}
289
297{
298 d_ptr->dpmy = dpmy;
299}
300
307{
308 d_ptr->flipped = flipped;
309}
310
318{
319 return d_ptr->flipped;
320}
321
335
\inmodule QtGui
QOpenGLPaintDevicePrivate(const QSize &size)
The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter.
QScopedPointer< QOpenGLPaintDevicePrivate > d_ptr
void setDotsPerMeterX(qreal)
Sets the number of pixels per meter horizontally to dpmx.
bool paintFlipped() const
Returns true if painting is flipped around the Y-axis.
int metric(QPaintDevice::PaintDeviceMetric metric) const override
\reimp
void setDotsPerMeterY(qreal)
Sets the number of pixels per meter vertically to dpmy.
qreal dotsPerMeterX() const
Returns the number of pixels per meter horizontally.
QOpenGLPaintDevice()
Constructs a QOpenGLPaintDevice.
void setPaintFlipped(bool flipped)
Sets whether painting should be flipped around the Y-axis or not to flipped.
QOpenGLContext * context() const
Returns the OpenGL context associated with the paint device.
void setDevicePixelRatio(qreal devicePixelRatio)
Sets the device pixel ratio for the paint device to devicePixelRatio.
qreal dotsPerMeterY() const
Returns the number of pixels per meter vertically.
void setSize(const QSize &size)
Sets the pixel size of the paint device to size.
~QOpenGLPaintDevice()
Destroys the QOpenGLPaintDevice.
virtual void ensureActiveTarget()
This virtual method is provided as a callback to allow re-binding a target frame buffer object or con...
QSize size() const
Returns the pixel size of the paint device.
qreal devicePixelRatio() const
@ PdmDevicePixelRatioScaled
static qreal devicePixelRatioFScale()
\inmodule QtGui
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
T & localData()
Returns a reference to the data that was set by the calling thread.
EGLContext ctx
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:110
Q_GUI_EXPORT int qt_defaultDpiY()
Definition qfont.cpp:125
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qWarning
Definition qlogging.h:166
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QJSEngine engine
[0]