qglpixelbuffer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/opengl/qglpixelbuffer.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7extern QImage qt_gl_read_frame_buffer(const QSize&, bool, bool);-
8-
9-
10QGLContext* QGLPBufferGLPaintDevice::context() const-
11{-
12 return
never executed: return pbuf->d_func()->qctx;
pbuf->d_func()->qctx;
never executed: return pbuf->d_func()->qctx;
0
13}-
14-
15void QGLPBufferGLPaintDevice::beginPaint()-
16{-
17 pbuf->makeCurrent();-
18 QGLPaintDevice::beginPaint();-
19}
never executed: end of block
0
20-
21void QGLPBufferGLPaintDevice::endPaint()-
22{-
23 QOpenGLContext::currentContext()->functions()->glFlush();-
24 QGLPaintDevice::endPaint();-
25}
never executed: end of block
0
26-
27void QGLPBufferGLPaintDevice::setFbo(GLuint fbo)-
28{-
29 m_thisFBO = fbo;-
30}
never executed: end of block
0
31-
32void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb)-
33{-
34 pbuf = pb;-
35}
never executed: end of block
0
36-
37void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget)-
38{-
39 QGLPixelBuffer * const q = q_func();-
40 if(init(size, format, shareWidget)
init(size, for..., shareWidget)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
41 req_size = size;-
42 req_format = format;-
43 req_shareWidget = shareWidget;-
44 invalid = false;-
45 glDevice.setPBuffer(q);-
46 }
never executed: end of block
0
47}
never executed: end of block
0
48QGLPixelBuffer::QGLPixelBuffer(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget)-
49 : d_ptr(new QGLPixelBufferPrivate(this))-
50{-
51 QGLPixelBufferPrivate * const d = d_func();-
52 d->common_init(size, format, shareWidget);-
53}
never executed: end of block
0
54QGLPixelBuffer::QGLPixelBuffer(int width, int height, const QGLFormat &format, QGLWidget *shareWidget)-
55 : d_ptr(new QGLPixelBufferPrivate(this))-
56{-
57 QGLPixelBufferPrivate * const d = d_func();-
58 d->common_init(QSize(width, height), format, shareWidget);-
59}
never executed: end of block
0
60-
61-
62-
63-
64-
65-
66QGLPixelBuffer::~QGLPixelBuffer()-
67{-
68 QGLPixelBufferPrivate * const d = d_func();-
69-
70-
71 QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext());-
72 if (current != d->qctx
current != d->qctxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
73 makeCurrent();
never executed: makeCurrent();
0
74 d->cleanup();-
75 if (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
&& current != d->qctx
current != d->qctxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
76 current->makeCurrent();
never executed: current->makeCurrent();
0
77}
never executed: end of block
0
78bool QGLPixelBuffer::makeCurrent()-
79{-
80 QGLPixelBufferPrivate * const d = d_func();-
81 if (d->invalid
d->invalidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
82 return
never executed: return false;
false;
never executed: return false;
0
83 d->qctx->makeCurrent();-
84 if (!d->fbo
!d->fboDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
85 QOpenGLFramebufferObjectFormat format;-
86 if (d->req_format.stencil()
d->req_format.stencil()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
87 format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
never executed: format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
0
88 else if (d->req_format.depth()
d->req_format.depth()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
89 format.setAttachment(QOpenGLFramebufferObject::Depth);
never executed: format.setAttachment(QOpenGLFramebufferObject::Depth);
0
90 if (d->req_format.sampleBuffers()
d->req_format.sampleBuffers()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
91 format.setSamples(d->req_format.samples());
never executed: format.setSamples(d->req_format.samples());
0
92 d->fbo = new QOpenGLFramebufferObject(d->req_size, format);-
93 d->fbo->bind();-
94 d->glDevice.setFbo(d->fbo->handle());-
95 QOpenGLContext::currentContext()->functions()->glViewport(0, 0, d->req_size.width(), d->req_size.height());-
96 }
never executed: end of block
0
97 return
never executed: return true;
true;
never executed: return true;
0
98}-
99-
100-
101-
102-
103-
104-
105-
106bool QGLPixelBuffer::doneCurrent()-
107{-
108 QGLPixelBufferPrivate * const d = d_func();-
109 if (d->invalid
d->invalidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
110 return
never executed: return false;
false;
never executed: return false;
0
111 d->qctx->doneCurrent();-
112 return
never executed: return true;
true;
never executed: return true;
0
113}-
114-
115-
116-
117-
118QGLContext *QGLPixelBuffer::context() const-
119{-
120 const QGLPixelBufferPrivate * const d = d_func();-
121 return
never executed: return d->qctx;
d->qctx;
never executed: return d->qctx;
0
122}-
123void QGLPixelBuffer::updateDynamicTexture(GLuint texture_id) const-
124{-
125 const QGLPixelBufferPrivate * const d = d_func();-
126 if (d->invalid
d->invalidDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->fbo
!d->fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
127 return;
never executed: return;
0
128-
129 const QGLContext *ctx = QGLContext::currentContext();-
130 if (!ctx
!ctxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
131 return;
never executed: return;
0
132 QOpenGLExtensions extensions(ctx->contextHandle());-
133-
134 ctx->d_ptr->refreshCurrentFbo();-
135-
136 if (d->blit_fbo
d->blit_fboDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
137 QOpenGLFramebufferObject::blitFramebuffer(d->blit_fbo, d->fbo);-
138 extensions.glBindFramebuffer(0x8CA8, d->blit_fbo->handle());-
139 }
never executed: end of block
0
140-
141 extensions.glBindTexture(0x0DE1, texture_id);-
142-
143 GLenum format = ctx->contextHandle()->isOpenGLES()
ctx->contextHa...->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
? 0x1908 : 0x8058;
0
144 extensions.glCopyTexImage2D(0x0DE1, 0, format, 0, 0, d->req_size.width(), d->req_size.height(), 0);-
145-
146-
147-
148-
149 if (d->blit_fbo
d->blit_fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 extensions.glBindFramebuffer(0x8CA8, ctx->d_func()->current_fbo);
never executed: extensions.glBindFramebuffer(0x8CA8, ctx->d_func()->current_fbo);
0
151}
never executed: end of block
0
152-
153-
154-
155-
156QSize QGLPixelBuffer::size() const-
157{-
158 const QGLPixelBufferPrivate * const d = d_func();-
159 return
never executed: return d->req_size;
d->req_size;
never executed: return d->req_size;
0
160}-
161-
162-
163-
164-
165QImage QGLPixelBuffer::toImage() const-
166{-
167 const QGLPixelBufferPrivate * const d = d_func();-
168 if (d->invalid
d->invalidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
169 return
never executed: return QImage();
QImage();
never executed: return QImage();
0
170-
171 const_cast<QGLPixelBuffer *>(this)->makeCurrent();-
172 if (d->fbo
d->fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
173 d->fbo->bind();
never executed: d->fbo->bind();
0
174 return
never executed: return qt_gl_read_frame_buffer(d->req_size, d->format.alpha(), true);
qt_gl_read_frame_buffer(d->req_size, d->format.alpha(), true);
never executed: return qt_gl_read_frame_buffer(d->req_size, d->format.alpha(), true);
0
175}-
176-
177-
178-
179-
180Qt::HANDLE QGLPixelBuffer::handle() const-
181{-
182 const QGLPixelBufferPrivate * const d = d_func();-
183 if (d->invalid
d->invalidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
184 return
never executed: return 0;
0;
never executed: return 0;
0
185 return
never executed: return (Qt::HANDLE) d->pbuf;
(Qt::HANDLE) d->pbuf;
never executed: return (Qt::HANDLE) d->pbuf;
0
186}-
187-
188-
189-
190-
191bool QGLPixelBuffer::isValid() const-
192{-
193 const QGLPixelBufferPrivate * const d = d_func();-
194 return
never executed: return !d->invalid;
!d->invalid;
never executed: return !d->invalid;
0
195}-
196-
197namespace { namespace Q_QGS_qt_buffer_2_engine { typedef QGLEngineThreadStorage<QGL2PaintEngineEx> Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QGLEngineThreadStorage<QGL2PaintEngineEx>, Q_QGS_qt_buffer_2_engine::innerFunction, Q_QGS_qt_buffer_2_engine::guard> qt_buffer_2_engine;
0
198-
199-
200QPaintEngine *QGLPixelBuffer::paintEngine() const-
201{-
202 return
never executed: return qt_buffer_2_engine()->engine();
qt_buffer_2_engine()->engine();
never executed: return qt_buffer_2_engine()->engine();
0
203}-
204-
205-
206int QGLPixelBuffer::metric(PaintDeviceMetric metric) const-
207{-
208 const QGLPixelBufferPrivate * const d = d_func();-
209-
210 float dpmx = qt_defaultDpiX()*100./2.54;-
211 float dpmy = qt_defaultDpiY()*100./2.54;-
212 int w = d->req_size.width();-
213 int h = d->req_size.height();-
214 switch (metric) {-
215 case
never executed: case PdmWidth:
PdmWidth:
never executed: case PdmWidth:
0
216 return
never executed: return w;
w;
never executed: return w;
0
217-
218 case
never executed: case PdmHeight:
PdmHeight:
never executed: case PdmHeight:
0
219 return
never executed: return h;
h;
never executed: return h;
0
220-
221 case
never executed: case PdmWidthMM:
PdmWidthMM:
never executed: case PdmWidthMM:
0
222 return
never executed: return qRound(w * 1000 / dpmx);
qRound(w * 1000 / dpmx);
never executed: return qRound(w * 1000 / dpmx);
0
223-
224 case
never executed: case PdmHeightMM:
PdmHeightMM:
never executed: case PdmHeightMM:
0
225 return
never executed: return qRound(h * 1000 / dpmy);
qRound(h * 1000 / dpmy);
never executed: return qRound(h * 1000 / dpmy);
0
226-
227 case
never executed: case PdmNumColors:
PdmNumColors:
never executed: case PdmNumColors:
0
228 return
never executed: return 0;
0;
never executed: return 0;
0
229-
230 case
never executed: case PdmDepth:
PdmDepth:
never executed: case PdmDepth:
0
231 return
never executed: return 32;
32;
never executed: return 32;
0
232-
233 case
never executed: case PdmDpiX:
PdmDpiX:
never executed: case PdmDpiX:
0
234 return
never executed: return qRound(dpmx * 0.0254);
qRound(dpmx * 0.0254);
never executed: return qRound(dpmx * 0.0254);
0
235-
236 case
never executed: case PdmDpiY:
PdmDpiY:
never executed: case PdmDpiY:
0
237 return
never executed: return qRound(dpmy * 0.0254);
qRound(dpmy * 0.0254);
never executed: return qRound(dpmy * 0.0254);
0
238-
239 case
never executed: case PdmPhysicalDpiX:
PdmPhysicalDpiX:
never executed: case PdmPhysicalDpiX:
0
240 return
never executed: return qRound(dpmx * 0.0254);
qRound(dpmx * 0.0254);
never executed: return qRound(dpmx * 0.0254);
0
241-
242 case
never executed: case PdmPhysicalDpiY:
PdmPhysicalDpiY:
never executed: case PdmPhysicalDpiY:
0
243 return
never executed: return qRound(dpmy * 0.0254);
qRound(dpmy * 0.0254);
never executed: return qRound(dpmy * 0.0254);
0
244-
245 case
never executed: case QPaintDevice::PdmDevicePixelRatio:
QPaintDevice::PdmDevicePixelRatio:
never executed: case QPaintDevice::PdmDevicePixelRatio:
0
246 return
never executed: return 1;
1;
never executed: return 1;
0
247-
248 case
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
QPaintDevice::PdmDevicePixelRatioScaled:
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
0
249 return
never executed: return QPaintDevice::devicePixelRatioFScale();
QPaintDevice::devicePixelRatioFScale();
never executed: return QPaintDevice::devicePixelRatioFScale();
0
250-
251 default
never executed: default:
:
never executed: default:
0
252 QMessageLogger(__FILE__, 471, __PRETTY_FUNCTION__).warning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric);-
253 break;
never executed: break;
0
254 }-
255 return
never executed: return 0;
0;
never executed: return 0;
0
256}-
257GLuint QGLPixelBuffer::bindTexture(const QImage &image, GLenum target)-
258{-
259 QGLPixelBufferPrivate * const d = d_func();-
260-
261 GLenum format = QOpenGLContext::currentContext()->isOpenGLES()
QOpenGLContext...->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
? 0x1908 : 0x8058;
0
262 return
never executed: return d->qctx->bindTexture(image, target, GLint(format));
d->qctx->bindTexture(image, target, GLint(format));
never executed: return d->qctx->bindTexture(image, target, GLint(format));
0
263-
264-
265-
266}-
267GLuint QGLPixelBuffer::bindTexture(const QPixmap &pixmap, GLenum target)-
268{-
269 QGLPixelBufferPrivate * const d = d_func();-
270-
271 GLenum format = QOpenGLContext::currentContext()->isOpenGLES()
QOpenGLContext...->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
? 0x1908 : 0x8058;
0
272 return
never executed: return d->qctx->bindTexture(pixmap, target, GLint(format));
d->qctx->bindTexture(pixmap, target, GLint(format));
never executed: return d->qctx->bindTexture(pixmap, target, GLint(format));
0
273-
274-
275-
276}-
277GLuint QGLPixelBuffer::bindTexture(const QString &fileName)-
278{-
279 QGLPixelBufferPrivate * const d = d_func();-
280 return
never executed: return d->qctx->bindTexture(fileName);
d->qctx->bindTexture(fileName);
never executed: return d->qctx->bindTexture(fileName);
0
281}-
282-
283-
284-
285-
286-
287-
288void QGLPixelBuffer::deleteTexture(GLuint texture_id)-
289{-
290 QGLPixelBufferPrivate * const d = d_func();-
291 d->qctx->deleteTexture(texture_id);-
292}
never executed: end of block
0
293void QGLPixelBuffer::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget)-
294{-
295 QGLPixelBufferPrivate * const d = d_func();-
296 d->qctx->drawTexture(target, textureId, textureTarget);-
297}
never executed: end of block
0
298void QGLPixelBuffer::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget)-
299{-
300 QGLPixelBufferPrivate * const d = d_func();-
301 d->qctx->drawTexture(point, textureId, textureTarget);-
302}
never executed: end of block
0
303-
304-
305-
306-
307-
308QGLFormat QGLPixelBuffer::format() const-
309{-
310 const QGLPixelBufferPrivate * const d = d_func();-
311 return
never executed: return d->format;
d->format;
never executed: return d->format;
0
312}-
313-
314-
315-
316-
317-
318bool QGLPixelBufferPrivate::init(const QSize &, const QGLFormat &f, QGLWidget *shareWidget)-
319{-
320 widget = new QGLWidget(f, 0, shareWidget);-
321 widget->resize(1, 1);-
322 qctx = const_cast<QGLContext *>(widget->context());-
323 return
never executed: return widget->isValid();
widget->isValid();
never executed: return widget->isValid();
0
324}-
325-
326bool QGLPixelBufferPrivate::cleanup()-
327{-
328 delete fbo;-
329 fbo = 0;-
330 delete blit_fbo;-
331 blit_fbo = 0;-
332 delete widget;-
333 widget = 0;-
334 return
never executed: return true;
true;
never executed: return true;
0
335}-
336-
337bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id)-
338{-
339 (void)texture_id;;-
340 return
never executed: return false;
false;
never executed: return false;
0
341}-
342-
343void QGLPixelBuffer::releaseFromDynamicTexture()-
344{-
345}-
346-
347GLuint QGLPixelBuffer::generateDynamicTexture() const-
348{-
349 const QGLPixelBufferPrivate * const d = d_func();-
350 if (!d->fbo
!d->fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
351 return
never executed: return 0;
0;
never executed: return 0;
0
352-
353 if (d->fbo->format().samples() > 0
d->fbo->format().samples() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
354 && QOpenGLExtensions(QOpenGLContext::currentContext())
QOpenGLExtensi...amebufferBlit)Description
TRUEnever evaluated
FALSEnever evaluated
0
355 .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)
QOpenGLExtensi...amebufferBlit)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
356 {-
357 if (!d->blit_fbo
!d->blit_fboDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
358 const_cast<
never executed: const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
never executed: const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
0
359 }
never executed: end of block
else {
0
360 return
never executed: return d->fbo->texture();
d->fbo->texture();
never executed: return d->fbo->texture();
0
361 }-
362-
363 GLuint texture;-
364 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
365-
366 funcs->glGenTextures(1, &texture);-
367 funcs->glBindTexture(0x0DE1, texture);-
368-
369 funcs->glTexParameteri(0x0DE1, 0x2801, 0x2600);-
370 funcs->glTexParameteri(0x0DE1, 0x2800, 0x2600);-
371 funcs->glTexParameteri(0x0DE1, 0x2802, 0x812F);-
372 funcs->glTexParameteri(0x0DE1, 0x2803, 0x812F);-
373-
374 funcs->glTexImage2D(0x0DE1, 0, 0x1908, d->req_size.width(), d->req_size.height(), 0,-
375 0x1908, 0x1401, 0);-
376-
377 return
never executed: return texture;
texture;
never executed: return texture;
0
378}-
379-
380bool QGLPixelBuffer::hasOpenGLPbuffers()-
381{-
382 return
never executed: return QGLFramebufferObject::hasOpenGLFramebufferObjects();
QGLFramebufferObject::hasOpenGLFramebufferObjects();
never executed: return QGLFramebufferObject::hasOpenGLFramebufferObjects();
0
383}-
384-
385-
Switch to Source codePreprocessed file

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