qglpixelbuffer.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
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 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: }
0
20 -
21void QGLPBufferGLPaintDevice::endPaint() -
22{ -
23 glFlush(); -
24 QGLPaintDevice::endPaint(); -
25}
never executed: }
0
26 -
27void QGLPBufferGLPaintDevice::setFbo(GLuint fbo) -
28{ -
29 m_thisFBO = fbo; -
30}
never executed: }
0
31 -
32void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) -
33{ -
34 pbuf = pb; -
35}
never executed: }
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)) {
never evaluated: init(size, format, shareWidget)
0
41 req_size = size; -
42 req_format = format; -
43 req_shareWidget = shareWidget; -
44 invalid = false; -
45 glDevice.setPBuffer(q); -
46 }
never executed: }
0
47}
never executed: }
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: }
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: }
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)
never evaluated: current != d->qctx
0
73 makeCurrent();
never executed: makeCurrent();
0
74 d->cleanup(); -
75 if (current && current != d->qctx)
never evaluated: current
never evaluated: current != d->qctx
0
76 current->makeCurrent();
never executed: current->makeCurrent();
0
77}
never executed: }
0
78bool QGLPixelBuffer::makeCurrent() -
79{ -
80 QGLPixelBufferPrivate * const d = d_func(); -
81 if (d->invalid)
never evaluated: d->invalid
0
82 return false;
never executed: return false;
0
83 d->qctx->makeCurrent(); -
84 if (!d->fbo) {
never evaluated: !d->fbo
0
85 QOpenGLFramebufferObjectFormat format; -
86 if (d->req_format.stencil())
never evaluated: d->req_format.stencil()
0
87 format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
never executed: format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
0
88 else if (d->req_format.depth())
never evaluated: d->req_format.depth()
0
89 format.setAttachment(QOpenGLFramebufferObject::Depth);
never executed: format.setAttachment(QOpenGLFramebufferObject::Depth);
0
90 if (d->req_format.sampleBuffers())
never evaluated: d->req_format.sampleBuffers()
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 glViewport(0, 0, d->req_size.width(), d->req_size.height()); -
96 }
never executed: }
0
97 return 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)
never evaluated: d->invalid
0
110 return false;
never executed: return false;
0
111 d->qctx->doneCurrent(); -
112 return 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 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->fbo)
never evaluated: d->invalid
never evaluated: !d->fbo
0
127 return;
never executed: return;
0
128 -
129 QOpenGLContext *ctx = QOpenGLContext::currentContext(); -
130 if (!ctx)
never evaluated: !ctx
0
131 return;
never executed: return;
0
132 QOpenGLExtensions extensions(ctx); -
133 -
134 if (d->blit_fbo) {
never evaluated: d->blit_fbo
0
135 QOpenGLFramebufferObject::blitFramebuffer(d->blit_fbo, d->fbo); -
136 extensions.glBindFramebuffer(0x8CA8, d->blit_fbo->handle()); -
137 }
never executed: }
0
138 -
139 glBindTexture(0x0DE1, texture_id); -
140 -
141 glCopyTexImage2D(0x0DE1, 0, 0x8058, 0, 0, d->req_size.width(), d->req_size.height(), 0); -
142 -
143 -
144 -
145 -
146 if (d->blit_fbo)
never evaluated: d->blit_fbo
0
147 extensions.glBindFramebuffer(0x8CA8, ctx->d_func()->current_fbo);
never executed: extensions.glBindFramebuffer(0x8CA8, ctx->d_func()->current_fbo);
0
148}
never executed: }
0
149 -
150 -
151 -
152 -
153QSize QGLPixelBuffer::size() const -
154{ -
155 const QGLPixelBufferPrivate * const d = d_func(); -
156 return d->req_size;
never executed: return d->req_size;
0
157} -
158 -
159 -
160 -
161 -
162QImage QGLPixelBuffer::toImage() const -
163{ -
164 const QGLPixelBufferPrivate * const d = d_func(); -
165 if (d->invalid)
never evaluated: d->invalid
0
166 return QImage();
never executed: return QImage();
0
167 -
168 const_cast<QGLPixelBuffer *>(this)->makeCurrent(); -
169 if (d->fbo)
never evaluated: d->fbo
0
170 d->fbo->bind();
never executed: d->fbo->bind();
0
171 return 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
172} -
173 -
174 -
175 -
176 -
177Qt::HANDLE QGLPixelBuffer::handle() const -
178{ -
179 const QGLPixelBufferPrivate * const d = d_func(); -
180 if (d->invalid)
never evaluated: d->invalid
0
181 return 0;
never executed: return 0;
0
182 return (Qt::HANDLE) d->pbuf;
never executed: return (Qt::HANDLE) d->pbuf;
0
183} -
184 -
185 -
186 -
187 -
188bool QGLPixelBuffer::isValid() const -
189{ -
190 const QGLPixelBufferPrivate * const d = d_func(); -
191 return !d->invalid;
never executed: return !d->invalid;
0
192} -
193 -
194static QGLEngineThreadStorage<QGL2PaintEngineEx> *qt_buffer_2_engine() { static QGlobalStatic<QGLEngineThreadStorage<QGL2PaintEngineEx> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QGLEngineThreadStorage<QGL2PaintEngineEx> *x = new QGLEngineThreadStorage<QGL2PaintEngineEx>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QGLEngineThreadStorage<QGL2PaintEngineEx> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
never executed: return thisGlobalStatic.pointer.load();
never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
never evaluated: !thisGlobalStatic.pointer.load()
never evaluated: !thisGlobalStatic.destroyed
0
195 -
196 -
197QPaintEngine *QGLPixelBuffer::paintEngine() const -
198{ -
199 return qt_buffer_2_engine()->engine();
never executed: return qt_buffer_2_engine()->engine();
0
200} -
201 -
202 -
203int QGLPixelBuffer::metric(PaintDeviceMetric metric) const -
204{ -
205 const QGLPixelBufferPrivate * const d = d_func(); -
206 -
207 float dpmx = qt_defaultDpiX()*100./2.54; -
208 float dpmy = qt_defaultDpiY()*100./2.54; -
209 int w = d->req_size.width(); -
210 int h = d->req_size.height(); -
211 switch (metric) { -
212 case PdmWidth: -
213 return w;
never executed: return w;
0
214 -
215 case PdmHeight: -
216 return h;
never executed: return h;
0
217 -
218 case PdmWidthMM: -
219 return qRound(w * 1000 / dpmx);
never executed: return qRound(w * 1000 / dpmx);
0
220 -
221 case PdmHeightMM: -
222 return qRound(h * 1000 / dpmy);
never executed: return qRound(h * 1000 / dpmy);
0
223 -
224 case PdmNumColors: -
225 return 0;
never executed: return 0;
0
226 -
227 case PdmDepth: -
228 return 32;
never executed: return 32;
0
229 -
230 case PdmDpiX: -
231 return qRound(dpmx * 0.0254);
never executed: return qRound(dpmx * 0.0254);
0
232 -
233 case PdmDpiY: -
234 return qRound(dpmy * 0.0254);
never executed: return qRound(dpmy * 0.0254);
0
235 -
236 case PdmPhysicalDpiX: -
237 return qRound(dpmx * 0.0254);
never executed: return qRound(dpmx * 0.0254);
0
238 -
239 case PdmPhysicalDpiY: -
240 return qRound(dpmy * 0.0254);
never executed: return qRound(dpmy * 0.0254);
0
241 -
242 default: -
243 QMessageLogger("qglpixelbuffer.cpp", 466, __PRETTY_FUNCTION__).warning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric); -
244 break;
never executed: break;
0
245 } -
246 return 0;
never executed: return 0;
0
247} -
248GLuint QGLPixelBuffer::bindTexture(const QImage &image, GLenum target) -
249{ -
250 QGLPixelBufferPrivate * const d = d_func(); -
251 -
252 return d->qctx->bindTexture(image, target, GLint(0x8058));
never executed: return d->qctx->bindTexture(image, target, GLint(0x8058));
0
253 -
254 -
255 -
256} -
257GLuint QGLPixelBuffer::bindTexture(const QPixmap &pixmap, GLenum target) -
258{ -
259 QGLPixelBufferPrivate * const d = d_func(); -
260 -
261 return d->qctx->bindTexture(pixmap, target, GLint(0x8058));
never executed: return d->qctx->bindTexture(pixmap, target, GLint(0x8058));
0
262 -
263 -
264 -
265} -
266GLuint QGLPixelBuffer::bindTexture(const QString &fileName) -
267{ -
268 QGLPixelBufferPrivate * const d = d_func(); -
269 return d->qctx->bindTexture(fileName);
never executed: return d->qctx->bindTexture(fileName);
0
270} -
271 -
272 -
273 -
274 -
275 -
276 -
277void QGLPixelBuffer::deleteTexture(GLuint texture_id) -
278{ -
279 QGLPixelBufferPrivate * const d = d_func(); -
280 d->qctx->deleteTexture(texture_id); -
281}
never executed: }
0
282void QGLPixelBuffer::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) -
283{ -
284 QGLPixelBufferPrivate * const d = d_func(); -
285 d->qctx->drawTexture(target, textureId, textureTarget); -
286}
never executed: }
0
287void QGLPixelBuffer::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) -
288{ -
289 QGLPixelBufferPrivate * const d = d_func(); -
290 d->qctx->drawTexture(point, textureId, textureTarget); -
291}
never executed: }
0
292 -
293 -
294 -
295 -
296 -
297QGLFormat QGLPixelBuffer::format() const -
298{ -
299 const QGLPixelBufferPrivate * const d = d_func(); -
300 return d->format;
never executed: return d->format;
0
301} -
302 -
303 -
304 -
305 -
306 -
307bool QGLPixelBufferPrivate::init(const QSize &, const QGLFormat &f, QGLWidget *shareWidget) -
308{ -
309 widget = new QGLWidget(f, 0, shareWidget); -
310 widget->resize(1, 1); -
311 qctx = const_cast<QGLContext *>(widget->context()); -
312 return widget->isValid();
never executed: return widget->isValid();
0
313} -
314 -
315bool QGLPixelBufferPrivate::cleanup() -
316{ -
317 delete fbo; -
318 fbo = 0; -
319 delete blit_fbo; -
320 blit_fbo = 0; -
321 delete widget; -
322 widget = 0; -
323 return true;
never executed: return true;
0
324} -
325 -
326bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id) -
327{ -
328 (void)texture_id;; -
329 return false;
never executed: return false;
0
330} -
331 -
332void QGLPixelBuffer::releaseFromDynamicTexture() -
333{ -
334} -
335 -
336GLuint QGLPixelBuffer::generateDynamicTexture() const -
337{ -
338 const QGLPixelBufferPrivate * const d = d_func(); -
339 if (!d->fbo)
never evaluated: !d->fbo
0
340 return 0;
never executed: return 0;
0
341 -
342 if (d->fbo->format().samples() > 0
never evaluated: d->fbo->format().samples() > 0
0
343 && QOpenGLExtensions(QOpenGLContext::currentContext()) 0
344 .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit))
never evaluated: QOpenGLExtensions(QOpenGLContext::currentContext()) .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)
0
345 { -
346 if (!d->blit_fbo)
never evaluated: !d->blit_fbo
0
347 const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
never executed: const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
0
348 } else {
never executed: }
0
349 return d->fbo->texture();
never executed: return d->fbo->texture();
0
350 } -
351 -
352 GLuint texture; -
353 -
354 glGenTextures(1, &texture); -
355 glBindTexture(0x0DE1, texture); -
356 -
357 glTexParameteri(0x0DE1, 0x2801, 0x2600); -
358 glTexParameteri(0x0DE1, 0x2800, 0x2600); -
359 glTexParameteri(0x0DE1, 0x2802, 0x812F); -
360 glTexParameteri(0x0DE1, 0x2803, 0x812F); -
361 -
362 glTexImage2D(0x0DE1, 0, 0x1908, d->req_size.width(), d->req_size.height(), 0, -
363 0x1908, 0x1401, 0); -
364 -
365 return texture;
never executed: return texture;
0
366} -
367 -
368bool QGLPixelBuffer::hasOpenGLPbuffers() -
369{ -
370 return QGLFramebufferObject::hasOpenGLFramebufferObjects();
never executed: return QGLFramebufferObject::hasOpenGLFramebufferObjects();
0
371} -
372 -
373 -
374 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial