42 #include <QtGui/QApplication> 43 #include <QtGui/QColormap> 44 #include <QtGui/QDesktopWidget> 45 #include <QtGui/QPaintDevice> 46 #include <QtGui/QWidget> 52 #include <private/qwidget_p.h> 56 #include <private/qt_x11_p.h> 65 #include <private/qglextensions_p.h> 66 #include <private/qwindowsurface_gl_p.h> 68 #include <private/qgl_p.h> 70 #include <private/qglpixelbuffer_p.h> 71 #include <private/qgraphicssystem_gl_p.h> 73 #include <private/qpaintengineex_opengl2_p.h> 74 #include <private/qpixmapdata_gl_p.h> 76 #ifndef QT_OPENGL_ES_2 77 #include <private/qpaintengine_opengl_p.h> 80 #ifndef GLX_ARB_multisample 81 #define GLX_SAMPLE_BUFFERS_ARB 100000 82 #define GLX_SAMPLES_ARB 100001 86 #include <private/qeglcontext_p.h> 100 #if defined(Q_WS_X11) && !defined(QT_OPENGL_ES) 103 if (
X11->visual == 0 &&
X11->visual_id == -1 &&
X11->visual_class == -1) {
108 spec[i++] = GLX_RGBA;
109 spec[i++] = GLX_DOUBLEBUFFER;
112 spec[i++] = GLX_DEPTH_SIZE;
114 spec[i++] = GLX_STENCIL_SIZE;
124 XVisualInfo *vi = glXChooseVisual(
X11->display,
X11->defaultScreen, spec);
126 X11->visual_id = vi->visualid;
127 X11->visual_class = vi->c_class;
131 glXGetConfig(
X11->display, vi, GLX_LEVEL, &res);
133 glXGetConfig(
X11->display, vi, GLX_DOUBLEBUFFER, &res);
135 glXGetConfig(
X11->display, vi, GLX_DEPTH_SIZE, &res);
139 glXGetConfig(
X11->display, vi, GLX_RGBA, &res);
141 glXGetConfig(
X11->display, vi, GLX_RED_SIZE, &res);
143 glXGetConfig(
X11->display, vi, GLX_GREEN_SIZE, &res);
145 glXGetConfig(
X11->display, vi, GLX_BLUE_SIZE, &res);
147 glXGetConfig(
X11->display, vi, GLX_ALPHA_SIZE, &res);
151 glXGetConfig(
X11->display, vi, GLX_ACCUM_RED_SIZE, &res);
155 glXGetConfig(
X11->display, vi, GLX_STENCIL_SIZE, &res);
159 glXGetConfig(
X11->display, vi, GLX_STEREO, &res);
171 printf(
"using visual class %x, id %x\n",
X11->visual_class,
X11->visual_id);
174 #elif defined(Q_WS_WIN) 196 if (!
widget->context()->isValid()) {
261 _qt_gl_share_widget()->cleanup();
268 return _qt_gl_share_widget()->shareWidget();
274 _qt_gl_share_widget()->destroy();
280 return _qt_gl_share_widget()->initializing();
353 #if defined (QT_OPENGL_ES_2) 372 #ifndef Q_WS_QPA // Don't delete the contexts. Destroying the window does that for us 402 #ifndef Q_WS_QPA //no need to specifically delete the QGLContext as it will be deleted by QWidget 405 union {
QGLContext **ctxPtrPtr;
void **voidPtrPtr; };
445 static bool checkedForNOKSwapRegion =
false;
446 static bool haveNOKSwapRegion =
false;
448 if (!checkedForNOKSwapRegion) {
450 checkedForNOKSwapRegion =
true;
452 if (haveNOKSwapRegion)
453 qDebug() <<
"Found EGL_NOK_swap_region2 extension. Using partial updates.";
457 if (ctx->d_func()->eglContext->configAttrib(EGL_SURFACE_TYPE)&EGL_SWAP_BEHAVIOR_PRESERVED_BIT) {
459 if (eglQuerySurface(ctx->d_func()->eglContext->display(), ctx->d_func()->eglSurface
470 union {
QGLContext **ctxPtrPtr;
void **voidPtrPtr; };
523 if (ctx->d_func()->workaround_needsFullClearOnEveryFrame)
532 glClearColor(0.0, 0.0, 0.0, 0.0);
554 glViewport(0, 0, viewport.
width(), viewport.
height());
559 blitProgram->setUniformValue(
"imageTexture", 0 );
568 if (targetRect.
right() == (viewport.
width() - 1))
612 #if !defined(Q_WS_QPA) 616 if (!size().isValid())
638 #if !defined(QT_OPENGL_ES_2) 643 for (
int i = 0; i < rects.
size(); ++i) {
649 glCopyTexSubImage2D(target, 0, br.
x(), bottom, br.
x(), bottom, br.
width(), br.
height());
652 glBindTexture(target, 0);
657 glMatrixMode(GL_MODELVIEW);
660 glMatrixMode(GL_PROJECTION);
663 glOrtho(0,
window()->width(),
window()->height(), 0, -999999, 999999);
665 glOrthof(0,
window()->width(),
window()->height(), 0, -999999, 999999);
667 glViewport(0, 0,
window()->width(),
window()->height());
670 glColor4f(1, 1, 1, 1);
671 for (
int i = 0; i < rects.
size(); ++i) {
681 bool doingPartialUpdate =
false;
686 doingPartialUpdate =
true;
697 qWarning() <<
"QGLWindowSurface: Flushing to native child widget, may lead to significant performance loss";
701 glCopyTexSubImage2D(target, 0, br.
x(), bottom, br.
x(), bottom, br.
width(), br.
height());
703 glBindTexture(target, 0);
706 if (doingPartialUpdate)
712 if (doingPartialUpdate)
713 ctx->d_func()->swapRegion(br);
734 if (ctx != previous_ctx) {
740 rect = parent->
rect();
742 size = parent->
size();
750 const int sx0 = br.
left();
752 const int sy0 = h - (br.
top() + br.
height());
753 const int sy1 = h - br.
top();
755 const int tx0 = rect.
left();
756 const int tx1 = rect.
left() + rect.
width();
758 const int ty1 = parent->
height() - rect.
top();
773 #ifndef Q_OS_SYMBIAN // We don't have FBO pool on Symbian 796 #endif // Q_OS_SYMBIAN 801 #if !defined(QT_OPENGL_ES_2) 810 glCopyTexSubImage2D(target, 0, br.
x(), bottom, br.
x(), bottom, br.
width(), br.
height());
812 glBindTexture(target, 0);
823 glMatrixMode(GL_MODELVIEW);
826 glMatrixMode(GL_PROJECTION);
829 glOrtho(0, size.
width(), size.
height(), 0, -999999, 999999);
831 glOrthof(0, size.
width(), size.
height(), 0, -999999, 999999);
835 glColor4f(1, 1, 1, 1);
862 #if !defined(Q_WS_QPA) 869 void QGLWindowSurface::resize(
const QSize &size)
871 QWindowSurface::resize(size);
884 #ifdef Q_OS_SYMBIAN // Symbian needs to recreate the context when native window size changes 891 ctx->d_func()->destroyEglSurfaceForDevice();
896 if ((*ctxPtrPtr) != ctx)
899 union {
QGLContext **ctxPtrPtr;
void **voidPtrPtr; };
903 ctx->d_func()->eglSurface = ctx->d_func()->eglContext->createSurface(
window());
908 eglSurfaceAttrib(
QEgl::display(), ctx->d_func()->eglSurfaceForDevice(),
909 EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
911 if (eglGetError() != EGL_SUCCESS)
912 qWarning(
"QGLWindowSurface::updateGeometry() - could not re-enable destroyed swap behaviour");
914 eglSurfaceAttrib(
QEgl::display(), ctx->d_func()->eglSurfaceForDevice(),
915 EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
917 if (eglGetError() != EGL_SUCCESS)
918 qWarning(
"QGLWindowSurface::updateGeometry() - could not re-enable preserved swap behaviour");
939 if (surfSize.
width() <= 0 || surfSize.
height() <= 0)
948 #ifndef QT_OPENGL_ES_2 977 qDebug() <<
"Created Window Surface FBO" << surfSize
981 qDebug() <<
"QGLWindowSurface: Failed to create valid FBO, falling back";
987 #if !defined(QT_OPENGL_ES_2) && !defined(Q_WS_QPA) //QPA doesn't support pixelbuffers 1012 glBindTexture(target, 0);
1014 glMatrixMode(GL_PROJECTION);
1021 qDebug() <<
"QGLWindowSurface: Failed to create valid pixelbuffer, falling back";
1026 #endif // !defined(QT_OPENGL_ES_2) !defined(Q_WS_QPA) 1030 #ifndef QT_OPENGL_ES_2 1034 #ifndef Q_OS_SYMBIAN 1035 qDebug() <<
"QGLWindowSurface: Using plain widget as window surface" <<
this;
1073 if (dx == 1 || dx == -1 || dy == 1 || dy == -1 || dy == 2)
1076 glRasterPos2i(br.
x() + dx, br.
y() + br.
height() + dy);
1085 glBindTexture(target, 0);
1109 const GLfloat tx1 = src.
left();
1110 const GLfloat tx2 = src.
right();
1111 const GLfloat ty1 = src.
top();
1112 const GLfloat ty2 = src.
bottom();
1114 GLfloat texCoordArray[4*2] = {
1115 tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1
1118 GLfloat vertexArray[4*2];
1122 #if !defined(QT_OPENGL_ES_2) 1123 glVertexPointer(2,
GL_FLOAT, 0, vertexArray);
1124 glTexCoordPointer(2,
GL_FLOAT, 0, texCoordArray);
1126 glBindTexture(target, tex_id);
1129 glEnableClientState(GL_VERTEX_ARRAY);
1130 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1132 glDisableClientState(GL_VERTEX_ARRAY);
1133 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1136 glBindTexture(target, 0);
1141 glBindTexture(target, tex_id);
1149 glBindTexture(target, 0);
1175 WindowSurfaceFeatures
features = 0;
QGLFormat format() const
Returns the format of the pbuffer.
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
virtual void swapBuffers() const
Swaps the screen contents with an off-screen buffer.
QSize size() const
Returns the size of the texture attached to this framebuffer object.
QRect geometry() const
Returns the currently allocated area on the screen.
bool initializeOffscreenTexture(const QSize &size)
QGLFramebufferObjectPool * qgl_fbo_pool()
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
QScopedPointer< QGLContextPrivate > d_ptr
qreal right() const
Returns the x-coordinate of the rectangle's right edge.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
#define GL_TEXTURE_MIN_FILTER
const QGLContext * qt_gl_share_context()
#define QT_END_NAMESPACE
This macro expands to.
Q_GUI_EXPORT bool qt_win_owndc_required
void deleted(QObject *object)
QPointer< QWidget > widget
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
void qAddPostRoutine(QtCleanUpFunction p)
QGLWindowSurface(QWidget *window)
QImage toImage() const
Returns the contents of this framebuffer object as a QImage.
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
#define GL_STENCIL_BUFFER_BIT
bool isValid() const
Returns true if the framebuffer object is valid.
bool remove(const T &value)
The QPointF class defines a point in the plane using floating point precision.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
int left() const
Returns the x-coordinate of the rectangle's left edge.
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
int width() const
Returns the width of the rectangle.
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
QGLContext * context() const
QGLShaderProgram * blitProgram()
#define glVertexAttribPointer
bool qt_initializing_gl_share_widget()
void setBottom(qreal pos)
Sets the bottom edge of the rectangle to the given y coordinate.
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
QRect boundingRect() const
Returns the bounding rectangle of this region.
void endPaint(const QRegion ®ion)
This function is called after painting onto the surface has ended, with the region in which the paint...
int height() const
Returns the height of the rectangle.
QList< QGLContext ** > contexts
#define glEnableVertexAttribArray
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
T * qobject_cast(QObject *object)
The QObject class is the base class of all Qt objects.
#define glBindFramebuffer
static QGLEngineSharedShaders * shadersForContext(const QGLContext *context)
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
static const QGLContext * currentContext()
Returns the current context, i.e.
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
#define glBlitFramebufferEXT
Q_CORE_EXPORT void qDebug(const char *,...)
QGLGraphicsSystem(bool useX11GL)
QPaintEngine * paintEngine() const
int width() const
Returns the width.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Q_GUI_EXPORT EGLDisplay display()
static SwapMode swapBehavior
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
#define GLX_SAMPLE_BUFFERS_ARB
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
virtual bool create(const QGLContext *shareContext=0)
Creates the GL context.
T takeFirst()
Removes the first item in the list and returns it.
The QGLContext class encapsulates an OpenGL rendering context.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset)
Flushes the given region from the specified widget onto the screen.
QSize size() const
Returns the size of the rectangle.
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
void release(QGLFramebufferObject *fbo)
static QGLFormat surfaceFormat
Q_CORE_EXPORT void qWarning(const char *,...)
#define GL_COLOR_BUFFER_BIT
The QImage class provides a hardware-independent image representation that allows direct access to th...
QImage toImage() const
Returns the contents of the pbuffer as a QImage.
bool isValid() const
Returns true if this pbuffer is valid; otherwise returns false.
static void blitTexture(QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect)
The QRegion class specifies a clip region for a painter.
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
void clear()
Removes all items from the list.
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
static void qt_cleanup_gl_share_widget()
int metric(PaintDeviceMetric m) const
#define GL_DRAW_FRAMEBUFFER_EXT
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
bool qt_gl_preferGL2Engine()
Q_OPENGL_EXPORT QPaintEngine * qt_qgl_paint_engine()
The QWindowSurface class provides the drawing area for top-level windows.
#define GL_READ_FRAMEBUFFER_EXT
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
QScopedPointer< QGLPixelBufferPrivate > d_ptr
const T & at(int i) const
Returns the item at index position i in the vector.
#define GL_DEPTH_BUFFER_BIT
Q_GLOBAL_STATIC_WITH_INITIALIZER(QGLGlobalShareWidget, _qt_gl_share_widget, { qAddPostRoutine(qt_cleanup_gl_share_widget);}) static void qt_cleanup_gl_share_widget()
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
void beginPaint(const QRegion ®ion)
This function is called before painting onto the surface begins, with the region in which the paintin...
int top() const
Returns the y-coordinate of the rectangle's top edge.
void qt_destroy_gl_share_widget()
int destructive_swap_buffers
int right() const
Returns the x-coordinate of the rectangle's right edge.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
int y() const
Returns the y-coordinate of the rectangle's top edge.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
void hijackWindow(QWidget *widget)
#define glDisableVertexAttribArray
QGLContext * context() const
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
virtual void doneCurrent()
Makes no GL context the current context.
The QPoint class defines a point in the plane using integer precision.
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
T & last()
Returns a reference to the last item in the list.
int size() const
Returns the number of items in the list.
int height() const
Returns the height.
static const GLuint QT_TEXTURE_COORDS_ATTR
The QRect class defines a rectangle in the plane using integer precision.
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
QGLFramebufferObject * fbo
QGLWindowSurfacePrivate * d
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
QSizeF size() const
Returns the size of the rectangle.
static Extensions glExtensions()
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
WindowSurfaceFeatures features() const
The QSize class defines the size of a two-dimensional object using integer point precision.
bool scroll(const QRegion &area, int dx, int dy)
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative...
QImage * buffer(const QWidget *widget)
Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is ...
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
#define GL_TEXTURE_MAG_FILTER
QGLWidget * qt_gl_share_widget()
static const GLuint QT_VERTEX_COORDS_ATTR
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
QGLWindowSurfacePrivate * d_ptr
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int size() const
Returns the number of items in the vector.
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric)
QGLWindowSurfaceGLPaintDevice glDevice
static bool isNull(const QVariant::Private *d)
void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
The QList class is a template class that provides lists.
static int area(const QSize &s)
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
void removeAt(int i)
Removes the item at index position i.