author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui/QApplication> |
|
43 |
#include <QtGui/QColormap> |
|
44 |
#include <QtGui/QDesktopWidget> |
|
45 |
#include <QtGui/QPaintDevice> |
|
46 |
#include <QtGui/QWidget> |
|
47 |
||
48 |
#include <qglframebufferobject.h> |
|
49 |
#include <qglpixelbuffer.h> |
|
50 |
#include <qcolormap.h> |
|
51 |
#include <qdesktopwidget.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
#include <private/qwidget_p.h> |
0 | 53 |
#include "qdebug.h" |
54 |
||
55 |
#ifdef Q_WS_X11 |
|
56 |
#include <private/qt_x11_p.h> |
|
57 |
#include <qx11info_x11.h> |
|
58 |
||
59 |
#ifndef QT_OPENGL_ES |
|
60 |
#include <GL/glx.h> |
|
61 |
#include <X11/Xlib.h> |
|
62 |
#endif |
|
63 |
#endif //Q_WS_X11 |
|
64 |
||
65 |
#include <private/qglextensions_p.h> |
|
66 |
#include <private/qwindowsurface_gl_p.h> |
|
67 |
||
68 |
#include <private/qgl_p.h> |
|
69 |
||
70 |
#include <private/qglpixelbuffer_p.h> |
|
71 |
#include <private/qgraphicssystem_gl_p.h> |
|
72 |
||
73 |
#include <private/qpaintengineex_opengl2_p.h> |
|
74 |
#include <private/qpixmapdata_gl_p.h> |
|
75 |
||
76 |
#ifndef QT_OPENGL_ES_2 |
|
77 |
#include <private/qpaintengine_opengl_p.h> |
|
78 |
#endif |
|
79 |
||
80 |
#ifndef GLX_ARB_multisample |
|
81 |
#define GLX_SAMPLE_BUFFERS_ARB 100000 |
|
82 |
#define GLX_SAMPLES_ARB 100001 |
|
83 |
#endif |
|
84 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
85 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
86 |
#include <private/qeglcontext_p.h> |
0 | 87 |
#endif |
88 |
||
89 |
QT_BEGIN_NAMESPACE |
|
90 |
||
91 |
// |
|
92 |
// QGLGraphicsSystem |
|
93 |
// |
|
94 |
#ifdef Q_WS_WIN |
|
95 |
extern Q_GUI_EXPORT bool qt_win_owndc_required; |
|
96 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
97 |
QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
98 |
: QGraphicsSystem(), m_useX11GL(useX11GL) |
0 | 99 |
{ |
100 |
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES) |
|
101 |
// only override the system defaults if the user hasn't already |
|
102 |
// picked a visual |
|
103 |
if (X11->visual == 0 && X11->visual_id == -1 && X11->visual_class == -1) { |
|
104 |
// find a double buffered, RGBA visual that supports OpenGL |
|
105 |
// and set that as the default visual for windows in Qt |
|
106 |
int i = 0; |
|
107 |
int spec[16]; |
|
108 |
spec[i++] = GLX_RGBA; |
|
109 |
spec[i++] = GLX_DOUBLEBUFFER; |
|
110 |
||
111 |
if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) { |
|
112 |
spec[i++] = GLX_DEPTH_SIZE; |
|
113 |
spec[i++] = 8; |
|
114 |
spec[i++] = GLX_STENCIL_SIZE; |
|
115 |
spec[i++] = 8; |
|
116 |
spec[i++] = GLX_SAMPLE_BUFFERS_ARB; |
|
117 |
spec[i++] = 1; |
|
118 |
spec[i++] = GLX_SAMPLES_ARB; |
|
119 |
spec[i++] = 4; |
|
120 |
} |
|
121 |
||
122 |
spec[i++] = XNone; |
|
123 |
||
124 |
XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec); |
|
125 |
if (vi) { |
|
126 |
X11->visual_id = vi->visualid; |
|
127 |
X11->visual_class = vi->c_class; |
|
128 |
||
129 |
QGLFormat format; |
|
130 |
int res; |
|
131 |
glXGetConfig(X11->display, vi, GLX_LEVEL, &res); |
|
132 |
format.setPlane(res); |
|
133 |
glXGetConfig(X11->display, vi, GLX_DOUBLEBUFFER, &res); |
|
134 |
format.setDoubleBuffer(res); |
|
135 |
glXGetConfig(X11->display, vi, GLX_DEPTH_SIZE, &res); |
|
136 |
format.setDepth(res); |
|
137 |
if (format.depth()) |
|
138 |
format.setDepthBufferSize(res); |
|
139 |
glXGetConfig(X11->display, vi, GLX_RGBA, &res); |
|
140 |
format.setRgba(res); |
|
141 |
glXGetConfig(X11->display, vi, GLX_RED_SIZE, &res); |
|
142 |
format.setRedBufferSize(res); |
|
143 |
glXGetConfig(X11->display, vi, GLX_GREEN_SIZE, &res); |
|
144 |
format.setGreenBufferSize(res); |
|
145 |
glXGetConfig(X11->display, vi, GLX_BLUE_SIZE, &res); |
|
146 |
format.setBlueBufferSize(res); |
|
147 |
glXGetConfig(X11->display, vi, GLX_ALPHA_SIZE, &res); |
|
148 |
format.setAlpha(res); |
|
149 |
if (format.alpha()) |
|
150 |
format.setAlphaBufferSize(res); |
|
151 |
glXGetConfig(X11->display, vi, GLX_ACCUM_RED_SIZE, &res); |
|
152 |
format.setAccum(res); |
|
153 |
if (format.accum()) |
|
154 |
format.setAccumBufferSize(res); |
|
155 |
glXGetConfig(X11->display, vi, GLX_STENCIL_SIZE, &res); |
|
156 |
format.setStencil(res); |
|
157 |
if (format.stencil()) |
|
158 |
format.setStencilBufferSize(res); |
|
159 |
glXGetConfig(X11->display, vi, GLX_STEREO, &res); |
|
160 |
format.setStereo(res); |
|
161 |
glXGetConfig(X11->display, vi, GLX_SAMPLE_BUFFERS_ARB, &res); |
|
162 |
format.setSampleBuffers(res); |
|
163 |
if (format.sampleBuffers()) { |
|
164 |
glXGetConfig(X11->display, vi, GLX_SAMPLES_ARB, &res); |
|
165 |
format.setSamples(res); |
|
166 |
} |
|
167 |
||
168 |
QGLWindowSurface::surfaceFormat = format; |
|
169 |
XFree(vi); |
|
170 |
||
171 |
printf("using visual class %x, id %x\n", X11->visual_class, X11->visual_id); |
|
172 |
} |
|
173 |
} |
|
174 |
#elif defined(Q_WS_WIN) |
|
175 |
QGLWindowSurface::surfaceFormat.setDoubleBuffer(true); |
|
176 |
||
177 |
qt_win_owndc_required = true; |
|
178 |
#endif |
|
179 |
} |
|
180 |
||
181 |
// |
|
182 |
// QGLWindowSurface |
|
183 |
// |
|
184 |
||
185 |
class QGLGlobalShareWidget |
|
186 |
{ |
|
187 |
public: |
|
188 |
QGLGlobalShareWidget() : widget(0), initializing(false) {} |
|
189 |
||
190 |
QGLWidget *shareWidget() { |
|
191 |
if (!initializing && !widget && !cleanedUp) { |
|
192 |
initializing = true; |
|
193 |
widget = new QGLWidget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
// We dont need this internal widget to appear in QApplication::topLevelWidgets() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
if (QWidgetPrivate::allWidgets) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
QWidgetPrivate::allWidgets->remove(widget); |
0 | 197 |
initializing = false; |
198 |
} |
|
199 |
return widget; |
|
200 |
} |
|
201 |
||
202 |
void cleanup() { |
|
203 |
QGLWidget *w = widget; |
|
204 |
cleanedUp = true; |
|
205 |
widget = 0; |
|
206 |
delete w; |
|
207 |
} |
|
208 |
||
209 |
static bool cleanedUp; |
|
210 |
||
211 |
private: |
|
212 |
QGLWidget *widget; |
|
213 |
bool initializing; |
|
214 |
}; |
|
215 |
||
216 |
bool QGLGlobalShareWidget::cleanedUp = false; |
|
217 |
||
218 |
static void qt_cleanup_gl_share_widget(); |
|
219 |
Q_GLOBAL_STATIC_WITH_INITIALIZER(QGLGlobalShareWidget, _qt_gl_share_widget, |
|
220 |
{ |
|
221 |
qAddPostRoutine(qt_cleanup_gl_share_widget); |
|
222 |
}) |
|
223 |
||
224 |
static void qt_cleanup_gl_share_widget() |
|
225 |
{ |
|
226 |
_qt_gl_share_widget()->cleanup(); |
|
227 |
} |
|
228 |
||
229 |
QGLWidget* qt_gl_share_widget() |
|
230 |
{ |
|
231 |
if (QGLGlobalShareWidget::cleanedUp) |
|
232 |
return 0; |
|
233 |
return _qt_gl_share_widget()->shareWidget(); |
|
234 |
} |
|
235 |
||
236 |
||
237 |
struct QGLWindowSurfacePrivate |
|
238 |
{ |
|
239 |
QGLFramebufferObject *fbo; |
|
240 |
QGLPixelBuffer *pb; |
|
241 |
GLuint tex_id; |
|
242 |
GLuint pb_tex_id; |
|
243 |
||
244 |
int tried_fbo : 1; |
|
245 |
int tried_pb : 1; |
|
246 |
int destructive_swap_buffers : 1; |
|
247 |
int geometry_updated : 1; |
|
248 |
||
249 |
QGLContext *ctx; |
|
250 |
||
251 |
QList<QGLContext **> contexts; |
|
252 |
||
253 |
QRegion paintedRegion; |
|
254 |
QSize size; |
|
255 |
||
256 |
QList<QImage> buffers; |
|
257 |
QGLWindowSurfaceGLPaintDevice glDevice; |
|
258 |
QGLWindowSurface* q_ptr; |
|
259 |
}; |
|
260 |
||
261 |
QGLFormat QGLWindowSurface::surfaceFormat; |
|
262 |
||
263 |
void QGLWindowSurfaceGLPaintDevice::endPaint() |
|
264 |
{ |
|
265 |
glFlush(); |
|
266 |
QGLPaintDevice::endPaint(); |
|
267 |
} |
|
268 |
||
269 |
QSize QGLWindowSurfaceGLPaintDevice::size() const |
|
270 |
{ |
|
271 |
return d->size; |
|
272 |
} |
|
273 |
||
274 |
QGLContext* QGLWindowSurfaceGLPaintDevice::context() const |
|
275 |
{ |
|
276 |
return d->ctx; |
|
277 |
} |
|
278 |
||
279 |
||
280 |
int QGLWindowSurfaceGLPaintDevice::metric(PaintDeviceMetric m) const |
|
281 |
{ |
|
282 |
return qt_paint_device_metric(d->q_ptr->window(), m); |
|
283 |
} |
|
284 |
||
285 |
QPaintEngine *QGLWindowSurfaceGLPaintDevice::paintEngine() const |
|
286 |
{ |
|
287 |
return qt_qgl_paint_engine(); |
|
288 |
} |
|
289 |
||
290 |
QGLWindowSurface::QGLWindowSurface(QWidget *window) |
|
291 |
: QWindowSurface(window), d_ptr(new QGLWindowSurfacePrivate) |
|
292 |
{ |
|
293 |
Q_ASSERT(window->isTopLevel()); |
|
294 |
d_ptr->pb = 0; |
|
295 |
d_ptr->fbo = 0; |
|
296 |
d_ptr->ctx = 0; |
|
297 |
#if defined (QT_OPENGL_ES_2) |
|
298 |
d_ptr->tried_fbo = true; |
|
299 |
d_ptr->tried_pb = true; |
|
300 |
#else |
|
301 |
d_ptr->tried_fbo = false; |
|
302 |
d_ptr->tried_pb = false; |
|
303 |
#endif |
|
304 |
d_ptr->destructive_swap_buffers = qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull(); |
|
305 |
d_ptr->glDevice.d = d_ptr; |
|
306 |
d_ptr->q_ptr = this; |
|
307 |
d_ptr->geometry_updated = false; |
|
308 |
} |
|
309 |
||
310 |
QGLWindowSurface::~QGLWindowSurface() |
|
311 |
{ |
|
312 |
if (d_ptr->ctx) |
|
313 |
glDeleteTextures(1, &d_ptr->tex_id); |
|
314 |
foreach(QGLContext **ctx, d_ptr->contexts) { |
|
315 |
delete *ctx; |
|
316 |
*ctx = 0; |
|
317 |
} |
|
318 |
||
319 |
delete d_ptr->pb; |
|
320 |
delete d_ptr->fbo; |
|
321 |
delete d_ptr; |
|
322 |
} |
|
323 |
||
324 |
void QGLWindowSurface::deleted(QObject *object) |
|
325 |
{ |
|
326 |
// Make sure that the fbo is destroyed before destroying its context. |
|
327 |
delete d_ptr->fbo; |
|
328 |
d_ptr->fbo = 0; |
|
329 |
||
330 |
QWidget *widget = qobject_cast<QWidget *>(object); |
|
331 |
if (widget) { |
|
332 |
QWidgetPrivate *widgetPrivate = widget->d_func(); |
|
333 |
if (widgetPrivate->extraData()) { |
|
334 |
union { QGLContext **ctxPtr; void **voidPtr; }; |
|
335 |
voidPtr = &widgetPrivate->extraData()->glContext; |
|
336 |
int index = d_ptr->contexts.indexOf(ctxPtr); |
|
337 |
if (index != -1) { |
|
338 |
delete *ctxPtr; |
|
339 |
*ctxPtr = 0; |
|
340 |
d_ptr->contexts.removeAt(index); |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
void QGLWindowSurface::hijackWindow(QWidget *widget) |
|
347 |
{ |
|
348 |
QWidgetPrivate *widgetPrivate = widget->d_func(); |
|
349 |
widgetPrivate->createExtra(); |
|
350 |
if (widgetPrivate->extraData()->glContext) |
|
351 |
return; |
|
352 |
||
353 |
QGLContext *ctx = new QGLContext(surfaceFormat, widget); |
|
354 |
ctx->create(qt_gl_share_widget()->context()); |
|
355 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
356 |
#ifndef QT_NO_EGL |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
357 |
if (ctx->d_func()->eglContext->configAttrib(EGL_SWAP_BEHAVIOR) != EGL_BUFFER_PRESERVED) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
358 |
setPartialUpdateSupport(false); // Force full-screen updates |
0 | 359 |
#endif |
360 |
||
361 |
widgetPrivate->extraData()->glContext = ctx; |
|
362 |
||
363 |
union { QGLContext **ctxPtr; void **voidPtr; }; |
|
364 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*))); |
0 | 366 |
|
367 |
voidPtr = &widgetPrivate->extraData()->glContext; |
|
368 |
d_ptr->contexts << ctxPtr; |
|
369 |
qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size(); |
|
370 |
} |
|
371 |
||
372 |
QGLContext *QGLWindowSurface::context() const |
|
373 |
{ |
|
374 |
return d_ptr->ctx; |
|
375 |
} |
|
376 |
||
377 |
QPaintDevice *QGLWindowSurface::paintDevice() |
|
378 |
{ |
|
379 |
updateGeometry(); |
|
380 |
||
381 |
if (d_ptr->pb) |
|
382 |
return d_ptr->pb; |
|
383 |
||
384 |
if (d_ptr->ctx) |
|
385 |
return &d_ptr->glDevice; |
|
386 |
||
387 |
QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext); |
|
388 |
ctx->makeCurrent(); |
|
389 |
return d_ptr->fbo; |
|
390 |
} |
|
391 |
||
392 |
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src = QRectF()); |
|
393 |
||
394 |
void QGLWindowSurface::beginPaint(const QRegion &) |
|
395 |
{ |
|
396 |
} |
|
397 |
||
398 |
void QGLWindowSurface::endPaint(const QRegion &rgn) |
|
399 |
{ |
|
400 |
if (context()) |
|
401 |
d_ptr->paintedRegion |= rgn; |
|
402 |
||
403 |
d_ptr->buffers.clear(); |
|
404 |
} |
|
405 |
||
406 |
void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) |
|
407 |
{ |
|
408 |
if (context() && widget != window()) { |
|
409 |
qWarning("No native child widget support in GL window surface without FBOs or pixel buffers"); |
|
410 |
return; |
|
411 |
} |
|
412 |
||
413 |
//### Find out why d_ptr->geometry_updated isn't always false. |
|
414 |
// flush() should not be called when d_ptr->geometry_updated is true. It assumes that either |
|
415 |
// d_ptr->fbo or d_ptr->pb is allocated and has the correct size. |
|
416 |
if (d_ptr->geometry_updated) |
|
417 |
return; |
|
418 |
||
419 |
QWidget *parent = widget->internalWinId() ? widget : widget->nativeParentWidget(); |
|
420 |
Q_ASSERT(parent); |
|
421 |
||
422 |
if (!geometry().isValid()) |
|
423 |
return; |
|
424 |
||
425 |
// Needed to support native child-widgets... |
|
426 |
hijackWindow(parent); |
|
427 |
||
428 |
QRect br = rgn.boundingRect().translated(offset); |
|
429 |
br = br.intersected(window()->rect()); |
|
430 |
QPoint wOffset = qt_qwidget_data(parent)->wrect.topLeft(); |
|
431 |
QRect rect = br.translated(-offset - wOffset); |
|
432 |
||
433 |
const GLenum target = GL_TEXTURE_2D; |
|
434 |
Q_UNUSED(target); |
|
435 |
||
436 |
if (context()) { |
|
437 |
context()->makeCurrent(); |
|
438 |
||
439 |
if (context()->format().doubleBuffer()) { |
|
440 |
#if !defined(QT_OPENGL_ES_2) |
|
441 |
if (d_ptr->destructive_swap_buffers) { |
|
442 |
glBindTexture(target, d_ptr->tex_id); |
|
443 |
||
444 |
QVector<QRect> rects = d_ptr->paintedRegion.rects(); |
|
445 |
for (int i = 0; i < rects.size(); ++i) { |
|
446 |
QRect br = rects.at(i); |
|
447 |
if (br.isEmpty()) |
|
448 |
continue; |
|
449 |
||
450 |
const uint bottom = window()->height() - (br.y() + br.height()); |
|
451 |
glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height()); |
|
452 |
} |
|
453 |
||
454 |
glBindTexture(target, 0); |
|
455 |
||
456 |
QRegion dirtyRegion = QRegion(window()->rect()) - d_ptr->paintedRegion; |
|
457 |
||
458 |
if (!dirtyRegion.isEmpty()) { |
|
459 |
glMatrixMode(GL_MODELVIEW); |
|
460 |
glLoadIdentity(); |
|
461 |
||
462 |
glMatrixMode(GL_PROJECTION); |
|
463 |
glLoadIdentity(); |
|
464 |
#ifndef QT_OPENGL_ES |
|
465 |
glOrtho(0, window()->width(), window()->height(), 0, -999999, 999999); |
|
466 |
#else |
|
467 |
glOrthof(0, window()->width(), window()->height(), 0, -999999, 999999); |
|
468 |
#endif |
|
469 |
glViewport(0, 0, window()->width(), window()->height()); |
|
470 |
||
471 |
QVector<QRect> rects = dirtyRegion.rects(); |
|
472 |
glColor4f(1, 1, 1, 1); |
|
473 |
for (int i = 0; i < rects.size(); ++i) { |
|
474 |
QRect rect = rects.at(i); |
|
475 |
if (rect.isEmpty()) |
|
476 |
continue; |
|
477 |
||
478 |
drawTexture(rect, d_ptr->tex_id, window()->size(), rect); |
|
479 |
} |
|
480 |
} |
|
481 |
} |
|
482 |
#endif |
|
483 |
d_ptr->paintedRegion = QRegion(); |
|
484 |
context()->swapBuffers(); |
|
485 |
} else { |
|
486 |
glFlush(); |
|
487 |
} |
|
488 |
||
489 |
return; |
|
490 |
} |
|
491 |
||
492 |
QGLContext *previous_ctx = const_cast<QGLContext *>(QGLContext::currentContext()); |
|
493 |
QGLContext *ctx = reinterpret_cast<QGLContext *>(parent->d_func()->extraData()->glContext); |
|
494 |
||
495 |
// QPainter::end() should have unbound the fbo, otherwise something is very wrong... |
|
496 |
Q_ASSERT(!d_ptr->fbo || !d_ptr->fbo->isBound()); |
|
497 |
||
498 |
if (ctx != previous_ctx) { |
|
499 |
ctx->makeCurrent(); |
|
500 |
} |
|
501 |
||
502 |
QSize size = widget->rect().size(); |
|
503 |
if (d_ptr->destructive_swap_buffers && ctx->format().doubleBuffer()) { |
|
504 |
rect = parent->rect(); |
|
505 |
br = rect.translated(wOffset + offset); |
|
506 |
size = parent->size(); |
|
507 |
} |
|
508 |
||
509 |
glDisable(GL_SCISSOR_TEST); |
|
510 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
511 |
if (d_ptr->fbo && (QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit)) { |
0 | 512 |
const int h = d_ptr->fbo->height(); |
513 |
||
514 |
const int sx0 = br.left(); |
|
515 |
const int sx1 = br.left() + br.width(); |
|
516 |
const int sy0 = h - (br.top() + br.height()); |
|
517 |
const int sy1 = h - br.top(); |
|
518 |
||
519 |
const int tx0 = rect.left(); |
|
520 |
const int tx1 = rect.left() + rect.width(); |
|
521 |
const int ty0 = parent->height() - (rect.top() + rect.height()); |
|
522 |
const int ty1 = parent->height() - rect.top(); |
|
523 |
||
524 |
if (window() == parent || d_ptr->fbo->format().samples() <= 1) { |
|
525 |
// glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); |
|
526 |
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, d_ptr->fbo->handle()); |
|
527 |
||
528 |
glBlitFramebufferEXT(sx0, sy0, sx1, sy1, |
|
529 |
tx0, ty0, tx1, ty1, |
|
530 |
GL_COLOR_BUFFER_BIT, |
|
531 |
GL_NEAREST); |
|
532 |
||
533 |
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); |
|
534 |
} else { |
|
535 |
// can't do sub-region blits with multisample FBOs |
|
536 |
QGLFramebufferObject *temp = qgl_fbo_pool()->acquire(d_ptr->fbo->size(), QGLFramebufferObjectFormat()); |
|
537 |
||
538 |
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, temp->handle()); |
|
539 |
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, d_ptr->fbo->handle()); |
|
540 |
||
541 |
glBlitFramebufferEXT(0, 0, d_ptr->fbo->width(), d_ptr->fbo->height(), |
|
542 |
0, 0, d_ptr->fbo->width(), d_ptr->fbo->height(), |
|
543 |
GL_COLOR_BUFFER_BIT, |
|
544 |
GL_NEAREST); |
|
545 |
||
546 |
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, temp->handle()); |
|
547 |
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); |
|
548 |
||
549 |
glBlitFramebufferEXT(sx0, sy0, sx1, sy1, |
|
550 |
tx0, ty0, tx1, ty1, |
|
551 |
GL_COLOR_BUFFER_BIT, |
|
552 |
GL_NEAREST); |
|
553 |
||
554 |
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); |
|
555 |
||
556 |
qgl_fbo_pool()->release(temp); |
|
557 |
} |
|
558 |
} |
|
559 |
#if !defined(QT_OPENGL_ES_2) |
|
560 |
else { |
|
561 |
GLuint texture; |
|
562 |
if (d_ptr->fbo) { |
|
563 |
texture = d_ptr->fbo->texture(); |
|
564 |
} else { |
|
565 |
d_ptr->pb->makeCurrent(); |
|
566 |
glBindTexture(target, d_ptr->pb_tex_id); |
|
567 |
const uint bottom = window()->height() - (br.y() + br.height()); |
|
568 |
glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height()); |
|
569 |
texture = d_ptr->pb_tex_id; |
|
570 |
glBindTexture(target, 0); |
|
571 |
} |
|
572 |
||
573 |
glDisable(GL_DEPTH_TEST); |
|
574 |
||
575 |
if (d_ptr->fbo) { |
|
576 |
d_ptr->fbo->release(); |
|
577 |
} else { |
|
578 |
ctx->makeCurrent(); |
|
579 |
} |
|
580 |
||
581 |
glMatrixMode(GL_MODELVIEW); |
|
582 |
glLoadIdentity(); |
|
583 |
||
584 |
glMatrixMode(GL_PROJECTION); |
|
585 |
glLoadIdentity(); |
|
586 |
#ifndef QT_OPENGL_ES |
|
587 |
glOrtho(0, size.width(), size.height(), 0, -999999, 999999); |
|
588 |
#else |
|
589 |
glOrthof(0, size.width(), size.height(), 0, -999999, 999999); |
|
590 |
#endif |
|
591 |
glViewport(0, 0, size.width(), size.height()); |
|
592 |
||
593 |
glColor4f(1, 1, 1, 1); |
|
594 |
drawTexture(rect, texture, window()->size(), br); |
|
595 |
||
596 |
if (d_ptr->fbo) |
|
597 |
d_ptr->fbo->bind(); |
|
598 |
} |
|
599 |
#else |
|
600 |
// OpenGL/ES 2.0 version of the fbo blit. |
|
601 |
else if (d_ptr->fbo) { |
|
602 |
Q_UNUSED(target); |
|
603 |
||
604 |
GLuint texture = d_ptr->fbo->texture(); |
|
605 |
||
606 |
glDisable(GL_DEPTH_TEST); |
|
607 |
||
608 |
if (d_ptr->fbo->isBound()) |
|
609 |
d_ptr->fbo->release(); |
|
610 |
||
611 |
glViewport(0, 0, size.width(), size.height()); |
|
612 |
||
613 |
QGLShaderProgram *blitProgram = |
|
614 |
QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
blitProgram->bind(); |
0 | 616 |
blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); |
617 |
||
618 |
// The shader manager's blit program does not multiply the |
|
619 |
// vertices by the pmv matrix, so we need to do the effect |
|
620 |
// of the orthographic projection here ourselves. |
|
621 |
QRectF r; |
|
622 |
qreal w = size.width() ? size.width() : 1.0f; |
|
623 |
qreal h = size.height() ? size.height() : 1.0f; |
|
624 |
r.setLeft((rect.left() / w) * 2.0f - 1.0f); |
|
625 |
if (rect.right() == (size.width() - 1)) |
|
626 |
r.setRight(1.0f); |
|
627 |
else |
|
628 |
r.setRight((rect.right() / w) * 2.0f - 1.0f); |
|
629 |
r.setBottom((rect.top() / h) * 2.0f - 1.0f); |
|
630 |
if (rect.bottom() == (size.height() - 1)) |
|
631 |
r.setTop(1.0f); |
|
632 |
else |
|
633 |
r.setTop((rect.bottom() / w) * 2.0f - 1.0f); |
|
634 |
||
635 |
drawTexture(r, texture, window()->size(), br); |
|
636 |
} |
|
637 |
#endif |
|
638 |
||
639 |
if (ctx->format().doubleBuffer()) |
|
640 |
ctx->swapBuffers(); |
|
641 |
else |
|
642 |
glFlush(); |
|
643 |
} |
|
644 |
||
645 |
||
646 |
void QGLWindowSurface::setGeometry(const QRect &rect) |
|
647 |
{ |
|
648 |
QWindowSurface::setGeometry(rect); |
|
649 |
d_ptr->geometry_updated = true; |
|
650 |
} |
|
651 |
||
652 |
||
653 |
void QGLWindowSurface::updateGeometry() { |
|
654 |
if (!d_ptr->geometry_updated) |
|
655 |
return; |
|
656 |
d_ptr->geometry_updated = false; |
|
657 |
||
658 |
||
659 |
QRect rect = geometry(); |
|
660 |
hijackWindow(window()); |
|
661 |
QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext); |
|
662 |
||
663 |
#ifdef Q_WS_MAC |
|
664 |
ctx->updatePaintDevice(); |
|
665 |
#endif |
|
666 |
||
667 |
const GLenum target = GL_TEXTURE_2D; |
|
668 |
||
669 |
if (rect.width() <= 0 || rect.height() <= 0) |
|
670 |
return; |
|
671 |
||
672 |
if (d_ptr->size == rect.size()) |
|
673 |
return; |
|
674 |
||
675 |
d_ptr->size = rect.size(); |
|
676 |
||
677 |
if (d_ptr->ctx) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
678 |
#ifndef QT_OPENGL_ES_2 |
0 | 679 |
if (d_ptr->destructive_swap_buffers) { |
680 |
glBindTexture(target, d_ptr->tex_id); |
|
681 |
glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
|
682 |
glBindTexture(target, 0); |
|
683 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
#endif |
0 | 685 |
return; |
686 |
} |
|
687 |
||
688 |
if (d_ptr->destructive_swap_buffers |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
689 |
&& (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject) |
0 | 690 |
&& (d_ptr->fbo || !d_ptr->tried_fbo) |
691 |
&& qt_gl_preferGL2Engine()) |
|
692 |
{ |
|
693 |
d_ptr->tried_fbo = true; |
|
694 |
ctx->d_ptr->internal_context = true; |
|
695 |
ctx->makeCurrent(); |
|
696 |
delete d_ptr->fbo; |
|
697 |
||
698 |
QGLFramebufferObjectFormat format; |
|
699 |
format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
700 |
format.setInternalTextureFormat(GLenum(GL_RGBA)); |
|
701 |
format.setTextureTarget(target); |
|
702 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
703 |
if (QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit) |
0 | 704 |
format.setSamples(8); |
705 |
||
706 |
d_ptr->fbo = new QGLFramebufferObject(rect.size(), format); |
|
707 |
||
708 |
if (d_ptr->fbo->isValid()) { |
|
709 |
qDebug() << "Created Window Surface FBO" << rect.size() |
|
710 |
<< "with samples" << d_ptr->fbo->format().samples(); |
|
711 |
return; |
|
712 |
} else { |
|
713 |
qDebug() << "QGLWindowSurface: Failed to create valid FBO, falling back"; |
|
714 |
delete d_ptr->fbo; |
|
715 |
d_ptr->fbo = 0; |
|
716 |
} |
|
717 |
} |
|
718 |
||
719 |
#if !defined(QT_OPENGL_ES_2) |
|
720 |
if (d_ptr->destructive_swap_buffers && (d_ptr->pb || !d_ptr->tried_pb)) { |
|
721 |
d_ptr->tried_pb = true; |
|
722 |
||
723 |
if (d_ptr->pb) { |
|
724 |
d_ptr->pb->makeCurrent(); |
|
725 |
glDeleteTextures(1, &d_ptr->pb_tex_id); |
|
726 |
} |
|
727 |
||
728 |
delete d_ptr->pb; |
|
729 |
||
730 |
d_ptr->pb = new QGLPixelBuffer(rect.width(), rect.height(), |
|
731 |
QGLFormat(QGL::SampleBuffers | QGL::StencilBuffer | QGL::DepthBuffer), |
|
732 |
qt_gl_share_widget()); |
|
733 |
||
734 |
if (d_ptr->pb->isValid()) { |
|
735 |
qDebug() << "Created Window Surface Pixelbuffer, Sample buffers:" << d_ptr->pb->format().sampleBuffers(); |
|
736 |
d_ptr->pb->makeCurrent(); |
|
737 |
||
738 |
glGenTextures(1, &d_ptr->pb_tex_id); |
|
739 |
glBindTexture(target, d_ptr->pb_tex_id); |
|
740 |
glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
|
741 |
||
742 |
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
743 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
744 |
glBindTexture(target, 0); |
|
745 |
||
746 |
glMatrixMode(GL_PROJECTION); |
|
747 |
glLoadIdentity(); |
|
748 |
glOrtho(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); |
|
749 |
||
750 |
d_ptr->pb->d_ptr->qctx->d_func()->internal_context = true; |
|
751 |
return; |
|
752 |
} else { |
|
753 |
qDebug() << "QGLWindowSurface: Failed to create valid pixelbuffer, falling back"; |
|
754 |
delete d_ptr->pb; |
|
755 |
d_ptr->pb = 0; |
|
756 |
} |
|
757 |
} |
|
758 |
#endif // !defined(QT_OPENGL_ES_2) |
|
759 |
||
760 |
ctx->makeCurrent(); |
|
761 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
#ifndef QT_OPENGL_ES_2 |
0 | 763 |
if (d_ptr->destructive_swap_buffers) { |
764 |
glGenTextures(1, &d_ptr->tex_id); |
|
765 |
glBindTexture(target, d_ptr->tex_id); |
|
766 |
glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
|
767 |
||
768 |
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
769 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
770 |
glBindTexture(target, 0); |
|
771 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
#endif |
0 | 773 |
|
774 |
qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;; |
|
775 |
d_ptr->ctx = ctx; |
|
776 |
d_ptr->ctx->d_ptr->internal_context = true; |
|
777 |
} |
|
778 |
||
779 |
bool QGLWindowSurface::scroll(const QRegion &area, int dx, int dy) |
|
780 |
{ |
|
781 |
// this code randomly fails currently for unknown reasons |
|
782 |
return false; |
|
783 |
||
784 |
if (!d_ptr->pb) |
|
785 |
return false; |
|
786 |
||
787 |
d_ptr->pb->makeCurrent(); |
|
788 |
||
789 |
QRect br = area.boundingRect(); |
|
790 |
||
791 |
#if 0 |
|
792 |
// ## workaround driver issue (scrolling by these deltas is unbearably slow for some reason) |
|
793 |
// ## maybe we should use glCopyTexSubImage insteadk |
|
794 |
if (dx == 1 || dx == -1 || dy == 1 || dy == -1 || dy == 2) |
|
795 |
return false; |
|
796 |
||
797 |
glRasterPos2i(br.x() + dx, br.y() + br.height() + dy); |
|
798 |
glCopyPixels(br.x(), d_ptr->pb->height() - (br.y() + br.height()), br.width(), br.height(), GL_COLOR); |
|
799 |
return true; |
|
800 |
#endif |
|
801 |
||
802 |
const GLenum target = GL_TEXTURE_2D; |
|
803 |
||
804 |
glBindTexture(target, d_ptr->tex_id); |
|
805 |
glCopyTexImage2D(target, 0, GL_RGBA, br.x(), d_ptr->pb->height() - (br.y() + br.height()), br.width(), br.height(), 0); |
|
806 |
glBindTexture(target, 0); |
|
807 |
||
808 |
drawTexture(br.translated(dx, dy), d_ptr->tex_id, window()->size()); |
|
809 |
||
810 |
return true; |
|
811 |
} |
|
812 |
||
813 |
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &br) |
|
814 |
{ |
|
815 |
const GLenum target = GL_TEXTURE_2D; |
|
816 |
QRectF src = br.isEmpty() |
|
817 |
? QRectF(QPointF(), texSize) |
|
818 |
: QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size()); |
|
819 |
||
820 |
if (target == GL_TEXTURE_2D) { |
|
821 |
qreal width = texSize.width(); |
|
822 |
qreal height = texSize.height(); |
|
823 |
||
824 |
src.setLeft(src.left() / width); |
|
825 |
src.setRight(src.right() / width); |
|
826 |
src.setTop(src.top() / height); |
|
827 |
src.setBottom(src.bottom() / height); |
|
828 |
} |
|
829 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
830 |
const GLfloat tx1 = src.left(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
831 |
const GLfloat tx2 = src.right(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
832 |
const GLfloat ty1 = src.top(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
833 |
const GLfloat ty2 = src.bottom(); |
0 | 834 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
835 |
GLfloat texCoordArray[4*2] = { |
0 | 836 |
tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1 |
837 |
}; |
|
838 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
839 |
GLfloat vertexArray[4*2]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
840 |
extern void qt_add_rect_to_array(const QRectF &r, GLfloat *array); // qpaintengine_opengl.cpp |
0 | 841 |
qt_add_rect_to_array(rect, vertexArray); |
842 |
||
843 |
#if !defined(QT_OPENGL_ES_2) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
844 |
glVertexPointer(2, GL_FLOAT, 0, vertexArray); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
845 |
glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); |
0 | 846 |
|
847 |
glBindTexture(target, tex_id); |
|
848 |
glEnable(target); |
|
849 |
||
850 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
851 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
852 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
|
853 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
854 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
855 |
||
856 |
glDisable(target); |
|
857 |
glBindTexture(target, 0); |
|
858 |
#else |
|
859 |
glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexArray); |
|
860 |
glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, texCoordArray); |
|
861 |
||
862 |
glBindTexture(target, tex_id); |
|
863 |
||
864 |
glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); |
|
865 |
glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); |
|
866 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
|
867 |
glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); |
|
868 |
glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); |
|
869 |
||
870 |
glBindTexture(target, 0); |
|
871 |
#endif |
|
872 |
} |
|
873 |
||
874 |
QImage *QGLWindowSurface::buffer(const QWidget *widget) |
|
875 |
{ |
|
876 |
QImage image; |
|
877 |
||
878 |
if (d_ptr->pb) |
|
879 |
image = d_ptr->pb->toImage(); |
|
880 |
else if (d_ptr->fbo) |
|
881 |
image = d_ptr->fbo->toImage(); |
|
882 |
||
883 |
if (image.isNull()) |
|
884 |
return 0; |
|
885 |
||
886 |
QRect rect = widget->rect(); |
|
887 |
rect.translate(widget->mapTo(widget->window(), QPoint())); |
|
888 |
||
889 |
QImage subImage = image.copy(rect); |
|
890 |
d_ptr->buffers << subImage; |
|
891 |
return &d_ptr->buffers.last(); |
|
892 |
} |
|
893 |
||
894 |
||
895 |
||
896 |
QT_END_NAMESPACE |
|
897 |