qopenglwindow.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qopenglwindow.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3class QOpenGLWindowPaintDevice : public QOpenGLPaintDevice-
4{-
5public:-
6 QOpenGLWindowPaintDevice(QOpenGLWindow *window) : m_window(window) { }
never executed: end of block
0
7 void ensureActiveTarget() override;-
8-
9 QOpenGLWindow *m_window;-
10};-
11-
12class QOpenGLWindowPrivate : public QPaintDeviceWindowPrivate-
13{-
14 inline QOpenGLWindow* q_func() { return static_cast<QOpenGLWindow *>(q_ptr); } inline const QOpenGLWindow* q_func() const { return static_cast<const QOpenGLWindow *>(q_ptr); } friend class QOpenGLWindow;-
15public:-
16 QOpenGLWindowPrivate(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior)-
17 : updateBehavior(updateBehavior)-
18 , hasFboBlit(false)-
19 , shareContext(shareContext)-
20 {-
21 if (!shareContext
!shareContextDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
22 this->shareContext = qt_gl_global_share_context();
never executed: this->shareContext = qt_gl_global_share_context();
0
23 }
never executed: end of block
0
24-
25 ~QOpenGLWindowPrivate();-
26-
27 static QOpenGLWindowPrivate *get(QOpenGLWindow *w) { return
never executed: return w->d_func();
w->d_func();
never executed: return w->d_func();
}
0
28-
29 void bindFBO();-
30 void initialize();-
31-
32 void beginPaint(const QRegion &region) override;-
33 void endPaint() override;-
34 void flush(const QRegion &region) override;-
35-
36 QOpenGLWindow::UpdateBehavior updateBehavior;-
37 bool hasFboBlit;-
38 QScopedPointer<QOpenGLContext> context;-
39 QOpenGLContext *shareContext;-
40 QScopedPointer<QOpenGLFramebufferObject> fbo;-
41 QScopedPointer<QOpenGLWindowPaintDevice> paintDevice;-
42 QOpenGLTextureBlitter blitter;-
43 QColor backgroundColor;-
44 QScopedPointer<QOffscreenSurface> offscreenSurface;-
45};-
46-
47QOpenGLWindowPrivate::~QOpenGLWindowPrivate()-
48{-
49 QOpenGLWindow * const q = q_func();-
50 if (q->isValid()
q->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
51 q->makeCurrent();-
52 paintDevice.reset(0);-
53 fbo.reset(0);-
54 blitter.destroy();-
55 q->doneCurrent();-
56 }
never executed: end of block
0
57}
never executed: end of block
0
58-
59void QOpenGLWindowPrivate::initialize()-
60{-
61 QOpenGLWindow * const q = q_func();-
62-
63 if (context
contextDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
64 return;
never executed: return;
0
65-
66 context.reset(new QOpenGLContext);-
67 context->setShareContext(shareContext);-
68 context->setFormat(q->requestedFormat());-
69 if (!context->create()
!context->create()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
70 QMessageLogger(__FILE__, 229, __PRETTY_FUNCTION__).warning("QOpenGLWindow::beginPaint: Failed to create context");
never executed: QMessageLogger(__FILE__, 229, __PRETTY_FUNCTION__).warning("QOpenGLWindow::beginPaint: Failed to create context");
0
71 if (!context->makeCurrent(q)
!context->makeCurrent(q)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
72 QMessageLogger(__FILE__, 231, __PRETTY_FUNCTION__).warning("QOpenGLWindow::beginPaint: Failed to make context current");
never executed: QMessageLogger(__FILE__, 231, __PRETTY_FUNCTION__).warning("QOpenGLWindow::beginPaint: Failed to make context current");
0
73-
74 paintDevice.reset(new QOpenGLWindowPaintDevice(q));-
75 if (updateBehavior == QOpenGLWindow::PartialUpdateBlit
updateBehavior...tialUpdateBlitDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
76 hasFboBlit = QOpenGLFramebufferObject::hasOpenGLFramebufferBlit();
never executed: hasFboBlit = QOpenGLFramebufferObject::hasOpenGLFramebufferBlit();
0
77-
78 q->initializeGL();-
79}
never executed: end of block
0
80-
81void QOpenGLWindowPrivate::beginPaint(const QRegion &region)-
82{-
83 (void)region;;-
84 QOpenGLWindow * const q = q_func();-
85-
86 initialize();-
87 context->makeCurrent(q);-
88-
89 const int deviceWidth = q->width() * q->devicePixelRatio();-
90 const int deviceHeight = q->height() * q->devicePixelRatio();-
91 const QSize deviceSize(deviceWidth, deviceHeight);-
92 if (updateBehavior > QOpenGLWindow::NoPartialUpdate
updateBehavior...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
93 if (!fbo
!fboDescription
TRUEnever evaluated
FALSEnever evaluated
|| fbo->size() != deviceSize
fbo->size() != deviceSizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 QOpenGLFramebufferObjectFormat fboFormat;-
95 fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);-
96 const int samples = q->requestedFormat().samples();-
97 if (samples > 0
samples > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
98 if (updateBehavior != QOpenGLWindow::PartialUpdateBlend
updateBehavior...ialUpdateBlendDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
99 fboFormat.setSamples(samples);
never executed: fboFormat.setSamples(samples);
0
100 else-
101 QMessageLogger(__FILE__, 260, __PRETTY_FUNCTION__).warning("QOpenGLWindow: PartialUpdateBlend does not support multisampling");
never executed: QMessageLogger(__FILE__, 260, __PRETTY_FUNCTION__).warning("QOpenGLWindow: PartialUpdateBlend does not support multisampling");
0
102 }-
103 fbo.reset(new QOpenGLFramebufferObject(deviceSize, fboFormat));-
104 markWindowAsDirty();-
105 }
never executed: end of block
0
106 }
never executed: end of block
else {
0
107 markWindowAsDirty();-
108 }
never executed: end of block
0
109-
110 paintDevice->setSize(QSize(deviceWidth, deviceHeight));-
111 paintDevice->setDevicePixelRatio(q->devicePixelRatio());-
112 context->functions()->glViewport(0, 0, deviceWidth, deviceHeight);-
113-
114 context->functions()->glBindFramebuffer(0x8D40, context->defaultFramebufferObject());-
115-
116 q->paintUnderGL();-
117-
118 if (updateBehavior > QOpenGLWindow::NoPartialUpdate
updateBehavior...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
119 fbo->bind();
never executed: fbo->bind();
0
120}
never executed: end of block
0
121-
122void QOpenGLWindowPrivate::endPaint()-
123{-
124 QOpenGLWindow * const q = q_func();-
125-
126 if (updateBehavior > QOpenGLWindow::NoPartialUpdate
updateBehavior...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
127 fbo->release();
never executed: fbo->release();
0
128-
129 context->functions()->glBindFramebuffer(0x8D40, context->defaultFramebufferObject());-
130-
131 if (updateBehavior == QOpenGLWindow::PartialUpdateBlit
updateBehavior...tialUpdateBlitDescription
TRUEnever evaluated
FALSEnever evaluated
&& hasFboBlit
hasFboBlitDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
132 const int deviceWidth = q->width() * q->devicePixelRatio();-
133 const int deviceHeight = q->height() * q->devicePixelRatio();-
134 QOpenGLExtensions extensions(context.data());-
135 extensions.glBindFramebuffer(0x8CA8, fbo->handle());-
136 extensions.glBindFramebuffer(0x8CA9, context->defaultFramebufferObject());-
137 extensions.glBlitFramebuffer(0, 0, deviceWidth, deviceHeight,-
138 0, 0, deviceWidth, deviceHeight,-
139 0x00004000, 0x2600);-
140 }
never executed: end of block
else if (updateBehavior > QOpenGLWindow::NoPartialUpdate
updateBehavior...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
141 if (updateBehavior == QOpenGLWindow::PartialUpdateBlend
updateBehavior...ialUpdateBlendDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
142 context->functions()->glEnable(0x0BE2);-
143 context->functions()->glBlendFunc(0x0302, 0x0303);-
144 }
never executed: end of block
0
145 if (!blitter.isCreated()
!blitter.isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
146 blitter.create();
never executed: blitter.create();
0
147-
148 QRect windowRect(QPoint(0, 0), fbo->size());-
149 QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(windowRect, windowRect);-
150 blitter.bind();-
151 blitter.blit(fbo->texture(), target, QOpenGLTextureBlitter::OriginBottomLeft);-
152 blitter.release();-
153-
154 if (updateBehavior == QOpenGLWindow::PartialUpdateBlend
updateBehavior...ialUpdateBlendDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
155 context->functions()->glDisable(0x0BE2);
never executed: context->functions()->glDisable(0x0BE2);
0
156 }
never executed: end of block
0
157-
158 q->paintOverGL();-
159}
never executed: end of block
0
160-
161void QOpenGLWindowPrivate::bindFBO()-
162{-
163 if (updateBehavior > QOpenGLWindow::NoPartialUpdate
updateBehavior...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
164 fbo->bind();
never executed: fbo->bind();
0
165 else-
166 QOpenGLFramebufferObject::bindDefault();
never executed: QOpenGLFramebufferObject::bindDefault();
0
167}-
168-
169void QOpenGLWindowPrivate::flush(const QRegion &region)-
170{-
171 (void)region;;-
172 QOpenGLWindow * const q = q_func();-
173 context->swapBuffers(q);-
174 q->frameSwapped();-
175}
never executed: end of block
0
176-
177void QOpenGLWindowPaintDevice::ensureActiveTarget()-
178{-
179 QOpenGLWindowPrivate::get(m_window)->bindFBO();-
180}
never executed: end of block
0
181-
182-
183-
184-
185-
186-
187QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior, QWindow *parent)-
188 : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(nullptr, updateBehavior)), parent)-
189{-
190 setSurfaceType(QSurface::OpenGLSurface);-
191}
never executed: end of block
0
192-
193-
194-
195-
196-
197-
198QOpenGLWindow::QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior, QWindow *parent)-
199 : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(shareContext, updateBehavior)), parent)-
200{-
201 setSurfaceType(QSurface::OpenGLSurface);-
202}
never executed: end of block
0
203QOpenGLWindow::~QOpenGLWindow()-
204{-
205 makeCurrent();-
206}
never executed: end of block
0
207-
208-
209-
210-
211QOpenGLWindow::UpdateBehavior QOpenGLWindow::updateBehavior() const-
212{-
213 const QOpenGLWindowPrivate * const d = d_func();-
214 return
never executed: return d->updateBehavior;
d->updateBehavior;
never executed: return d->updateBehavior;
0
215}-
216-
217-
218-
219-
220-
221-
222bool QOpenGLWindow::isValid() const-
223{-
224 const QOpenGLWindowPrivate * const d = d_func();-
225 return
never executed: return d->context && d->context->isValid();
d->context && d->context->isValid();
never executed: return d->context && d->context->isValid();
0
226}-
227void QOpenGLWindow::makeCurrent()-
228{-
229 QOpenGLWindowPrivate * const d = d_func();-
230-
231 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
232 return;
never executed: return;
0
233-
234-
235-
236 if (handle()
handle()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
237 d->context->makeCurrent(this);-
238 }
never executed: end of block
else {
0
239 if (!d->offscreenSurface
!d->offscreenSurfaceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
240 d->offscreenSurface.reset(new QOffscreenSurface);-
241 d->offscreenSurface->setFormat(d->context->format());-
242 d->offscreenSurface->create();-
243 }
never executed: end of block
0
244 d->context->makeCurrent(d->offscreenSurface.data());-
245 }
never executed: end of block
0
246-
247 d->bindFBO();-
248}
never executed: end of block
0
249void QOpenGLWindow::doneCurrent()-
250{-
251 QOpenGLWindowPrivate * const d = d_func();-
252-
253 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
254 return;
never executed: return;
0
255-
256 d->context->doneCurrent();-
257}
never executed: end of block
0
258-
259-
260-
261-
262QOpenGLContext *QOpenGLWindow::context() const-
263{-
264 const QOpenGLWindowPrivate * const d = d_func();-
265 return
never executed: return d->context.data();
d->context.data();
never executed: return d->context.data();
0
266}-
267-
268-
269-
270-
271QOpenGLContext *QOpenGLWindow::shareContext() const-
272{-
273 const QOpenGLWindowPrivate * const d = d_func();-
274 return
never executed: return d->shareContext;
d->shareContext;
never executed: return d->shareContext;
0
275}-
276GLuint QOpenGLWindow::defaultFramebufferObject() const-
277{-
278 const QOpenGLWindowPrivate * const d = d_func();-
279 if (d->updateBehavior > NoPartialUpdate
d->updateBehav...oPartialUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->fbo
d->fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
280 return
never executed: return d->fbo->handle();
d->fbo->handle();
never executed: return d->fbo->handle();
0
281 else if (QOpenGLContext *ctx = QOpenGLContext::currentContext()
QOpenGLContext...rrentContext()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
282 return
never executed: return ctx->defaultFramebufferObject();
ctx->defaultFramebufferObject();
never executed: return ctx->defaultFramebufferObject();
0
283 else-
284 return
never executed: return 0;
0;
never executed: return 0;
0
285}-
286-
287extern __attribute__((visibility("default"))) QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);-
288QImage QOpenGLWindow::grabFramebuffer()-
289{-
290 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
291 return
never executed: return QImage();
QImage();
never executed: return QImage();
0
292-
293 makeCurrent();-
294 return
never executed: return qt_gl_read_framebuffer(size() * devicePixelRatio(), false, false);
qt_gl_read_framebuffer(size() * devicePixelRatio(), false, false);
never executed: return qt_gl_read_framebuffer(size() * devicePixelRatio(), false, false);
0
295}-
296void QOpenGLWindow::initializeGL()-
297{-
298}-
299void QOpenGLWindow::resizeGL(int w, int h)-
300{-
301 (void)w;;-
302 (void)h;;-
303}
never executed: end of block
0
304void QOpenGLWindow::paintGL()-
305{-
306}-
307void QOpenGLWindow::paintUnderGL()-
308{-
309}-
310void QOpenGLWindow::paintOverGL()-
311{-
312}-
313-
314-
315-
316-
317-
318-
319void QOpenGLWindow::paintEvent(QPaintEvent *event)-
320{-
321 (void)event;;-
322 paintGL();-
323}
never executed: end of block
0
324-
325-
326-
327-
328-
329-
330void QOpenGLWindow::resizeEvent(QResizeEvent *event)-
331{-
332 (void)event;;-
333 QOpenGLWindowPrivate * const d = d_func();-
334 d->initialize();-
335 resizeGL(width(), height());-
336}
never executed: end of block
0
337-
338-
339-
340-
341int QOpenGLWindow::metric(PaintDeviceMetric metric) const-
342{-
343 const QOpenGLWindowPrivate * const d = d_func();-
344-
345 switch (metric) {-
346 case
never executed: case PdmDepth:
PdmDepth:
never executed: case PdmDepth:
0
347 if (d->paintDevice
d->paintDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
348 return
never executed: return d->paintDevice->depth();
d->paintDevice->depth();
never executed: return d->paintDevice->depth();
0
349 break;
never executed: break;
0
350 default
never executed: default:
:
never executed: default:
0
351 break;
never executed: break;
0
352 }-
353 return
never executed: return QPaintDeviceWindow::metric(metric);
QPaintDeviceWindow::metric(metric);
never executed: return QPaintDeviceWindow::metric(metric);
0
354}-
355-
356-
357-
358-
359QPaintDevice *QOpenGLWindow::redirected(QPoint *) const-
360{-
361 const QOpenGLWindowPrivate * const d = d_func();-
362 if (QOpenGLContext::currentContext() == d->context.data()
QOpenGLContext...context.data()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
363 return
never executed: return d->paintDevice.data();
d->paintDevice.data();
never executed: return d->paintDevice.data();
0
364 return
never executed: return 0;
0;
never executed: return 0;
0
365}-
366-
367-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9