Qt 4.8
qbbglwindowsurface.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion <blackberry-qt@qnx.com>
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //#define QBBGLWINDOWSURFACE_DEBUG
43 
44 
45 #include "qbbglwindowsurface.h"
46 #include "qbbglcontext.h"
47 #include "qbbwindow.h"
48 
49 #include <QtGui/QWidget>
50 #include <QtOpenGL/private/qgl_p.h>
51 #include <QGLContext>
52 #include <QDebug>
53 
54 #include <errno.h>
55 
57 
59  : mPlatformGlContext(platformGlContext)
60 {
61  // create GL context from platform GL context
62  mGlContext = QGLContext::fromPlatformGLContext(mPlatformGlContext);
63 }
64 
66 {
67  // cleanup GL context
68  delete mGlContext;
69 }
70 
72 {
73  // select a paint engine based on configued OpenGL version
74  return qt_qgl_paint_engine();
75 }
76 
78 {
79  // get size of EGL surface
81 }
82 
84  : QWindowSurface(window)
85 {
86 #if defined(QBBGLWINDOWSURFACE_DEBUG)
87  qDebug() << "QBBGLWindowSurface::QBBGLWindowSurface - w=" << window;
88 #endif
89 
90  // extract GL context associated with window
91  mPlatformGlContext = static_cast<QBBGLContext*>(window->platformWindow()->glContext());
92 
93  // create an OpenGL paint device
95 }
96 
98 {
99 #if defined(QBBGLWINDOWSURFACE_DEBUG)
100  qDebug() << "QBBGLWindowSurface::~QBBGLWindowSurface - w=" << window();
101 #endif
102 
103  // cleanup OpenGL paint device
104  delete mPaintDevice;
105 }
106 
108 {
109  Q_UNUSED(widget);
110  Q_UNUSED(region);
111  Q_UNUSED(offset);
112 
113 #if defined(QBBGLWINDOWSURFACE_DEBUG)
114  qDebug() << "QBBGLWindowSurface::flush - w=" << window();
115 #endif
116 
117  // update the display with newly rendered content
119 }
120 
122 {
123 #if defined(QBBGLWINDOWSURFACE_DEBUG)
124  qDebug() << "QBBGLWindowSurface::resize - w=" << window() << ", s=" << size;
125 #endif
126 
127  // call parent method
128  QWindowSurface::resize(size);
129 
130  // NOTE: defer resizing window buffers until next paint as
131  // resize() can be called multiple times before a paint occurs
132 }
133 
135 {
136  Q_UNUSED(region);
137 
138 #if defined(QBBGLWINDOWSURFACE_DEBUG)
139  qDebug() << "QBBGLWindowSurface::beginPaint - w=" << window();
140 #endif
141 
142  // resize EGL surface if window surface resized
143  QSize s = size();
144  if (s != mPlatformGlContext->surfaceSize()) {
146  }
147 }
148 
150 {
151  Q_UNUSED(region);
152 #if defined(QBBGLWINDOWSURFACE_DEBUG)
153  qDebug() << "QBBGLWindowSurface::endPaint - w=" << window();
154 #endif
155 }
156 
157 QWindowSurface::WindowSurfaceFeatures QBBGLWindowSurface::features() const
158 {
159  // force full frame updates on every paint
160  return 0;
161 }
162 
virtual void swapBuffers()
Reimplement in subclass to native swap buffers calls.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
virtual void flush(QWidget *widget, const QRegion &region, const QPoint &offset)
Flushes the given region from the specified widget onto the screen.
QSize surfaceSize() const
Definition: qbbglcontext.h:72
QBBGLContext * mPlatformGlContext
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
virtual void endPaint(const QRegion &region)
This function is called after painting onto the surface has ended, with the region in which the paint...
Q_CORE_EXPORT void qDebug(const char *,...)
NSWindow * window
virtual void resize(const QSize &size)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QBBGLWindowSurface(QWidget *window)
virtual QSize size() const
void resizeSurface(const QSize &size)
QGLContext * mGlContext
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QBBGLPaintDevice * mPaintDevice
Q_OPENGL_EXPORT QPaintEngine * qt_qgl_paint_engine()
Definition: qgl.cpp:5530
The QWindowSurface class provides the drawing area for top-level windows.
virtual QWindowSurface::WindowSurfaceFeatures features() const
QBBGLPaintDevice(QBBGLContext *platformGlContext)
virtual QPaintEngine * paintEngine() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void beginPaint(const QRegion &region)
This function is called before painting onto the surface begins, with the region in which the paintin...
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
QBBGLContext * mPlatformGlContext