Qt 4.8
Public Functions | Properties | List of all members
QX11GLWindowSurface Class Reference

#include <qwindowsurface_x11gl_p.h>

Inheritance diagram for QX11GLWindowSurface:
QWindowSurface

Public Functions

void flush (QWidget *widget, const QRegion &region, const QPoint &offset)
 Flushes the given region from the specified widget onto the screen. More...
 
QPixmap grabWidget (const QWidget *widget, const QRect &rectangle=QRect()) const
 Returns a QPixmap generated from the part of the backing store corresponding to widget. More...
 
QPaintDevicepaintDevice ()
 Implement this function to return the appropriate paint device. More...
 
 QX11GLWindowSurface (QWidget *window)
 
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. More...
 
void setGeometry (const QRect &rect)
 Sets the currently allocated area to be the given rect. More...
 
virtual ~QX11GLWindowSurface ()
 
- Public Functions inherited from QWindowSurface
virtual void beginPaint (const QRegion &)
 This function is called before painting onto the surface begins, with the region in which the painting will occur. More...
 
virtual QImagebuffer (const QWidget *widget)
 Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is unavailable. More...
 
virtual void endPaint (const QRegion &)
 This function is called after painting onto the surface has ended, with the region in which the painting was performed. More...
 
virtual WindowSurfaceFeatures features () const
 
QRect geometry () const
 Returns the currently allocated area on the screen. More...
 
bool hasFeature (WindowSurfaceFeature feature) const
 
virtual QPoint offset (const QWidget *widget) const
 Returns the offset of widget in the coordinates of this window surface. More...
 
 QWindowSurface (QWidget *window, bool setDefaultSurface=true)
 Constructs an empty surface for the given top-level window. More...
 
QRect rect (const QWidget *widget) const
 Returns the rectangle for widget in the coordinates of this window surface. More...
 
void setStaticContents (const QRegion &region)
 
QRegion staticContents () const
 
QWidgetwindow () const
 Returns a pointer to the top-level window associated with this surface. More...
 
virtual ~QWindowSurface ()
 Destroys this surface. More...
 

Properties

QPixmap m_backBuffer
 
GC m_pixmapGC
 
QWidgetm_window
 
GC m_windowGC
 

Additional Inherited Members

- Public Types inherited from QWindowSurface
enum  WindowSurfaceFeature { PartialUpdates = 0x00000001, PreservedContents = 0x00000002, StaticContents = 0x00000004, AllFeatures = 0xffffffff }
 
- Protected Functions inherited from QWindowSurface
bool hasStaticContents () const
 

Detailed Description

Definition at line 60 of file qwindowsurface_x11gl_p.h.

Constructors and Destructors

◆ QX11GLWindowSurface()

QX11GLWindowSurface::QX11GLWindowSurface ( QWidget window)

Definition at line 53 of file qwindowsurface_x11gl.cpp.

54  : QWindowSurface(window), m_windowGC(0), m_pixmapGC(0), m_window(window)
55 {
56 }
QWindowSurface(QWidget *window, bool setDefaultSurface=true)
Constructs an empty surface for the given top-level window.

◆ ~QX11GLWindowSurface()

QX11GLWindowSurface::~QX11GLWindowSurface ( )
virtual

Definition at line 58 of file qwindowsurface_x11gl.cpp.

59 {
60  if (m_windowGC)
61  XFree(m_windowGC);
62  if (m_pixmapGC)
63  XFree(m_pixmapGC);
64 }

Functions

◆ flush()

void QX11GLWindowSurface::flush ( QWidget widget,
const QRegion region,
const QPoint offset 
)
virtual

Flushes the given region from the specified widget onto the screen.

Note that the offset parameter is currently unused.

Implements QWindowSurface.

Definition at line 73 of file qwindowsurface_x11gl.cpp.

74 {
75  // We don't need to know the widget which initiated the flush. Instead we just use the offset
76  // to translate the widgetRegion:
77  Q_UNUSED(widget);
78 
79  if (m_backBuffer.isNull()) {
80  qDebug("QX11GLWindowSurface::flush() - backBuffer is null, not flushing anything");
81  return;
82  }
83 
84  Q_ASSERT(window()->size() != m_backBuffer.size());
85 
86  // Wait for all GL rendering to the back buffer pixmap to complete before trying to
87  // copy it to the window. We do this by making sure the pixmap's context is current
88  // and then call eglWaitClient. The EGL 1.4 spec says eglWaitClient doesn't have to
89  // block, just that "All rendering calls...are guaranteed to be executed before native
90  // rendering calls". This makes it potentially less expensive than glFinish.
91  QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.data_ptr().data())->context();
92  if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
93  ctx->makeCurrent();
94  eglWaitClient();
95 
96  if (m_windowGC == 0) {
97  XGCValues attribs;
98  attribs.graphics_exposures = False;
99  m_windowGC = XCreateGC(X11->display, m_window->handle(), GCGraphicsExposures, &attribs);
100  }
101 
102  int rectCount;
103  XRectangle *rects = (XRectangle *)qt_getClipRects(widgetRegion, rectCount);
104  if (rectCount <= 0)
105  return;
106 
107  XSetClipRectangles(X11->display, m_windowGC, 0, 0, rects, rectCount, YXBanded);
108 
109  QRect dirtyRect = widgetRegion.boundingRect().translated(-offset);
110  XCopyArea(X11->display, m_backBuffer.handle(), m_window->handle(), m_windowGC,
111  dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height(),
112  dirtyRect.x(), dirtyRect.y());
113 
114  // Make sure the blit of the update from the back buffer to the window completes
115  // before allowing rendering to start again to the back buffer. Otherwise the GPU
116  // might start rendering to the back buffer again while the blit takes place.
117  eglWaitNative(EGL_CORE_NATIVE_ENGINE);
118 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
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...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
Q_CORE_EXPORT void qDebug(const char *,...)
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
void * qt_getClipRects(const QRegion &r, int &num)
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
#define ctx
Definition: qgl.cpp:6094
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
#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.

◆ grabWidget()

QPixmap QX11GLWindowSurface::grabWidget ( const QWidget widget,
const QRect rectangle = QRect() 
) const
virtual

Returns a QPixmap generated from the part of the backing store corresponding to widget.

Returns a null QPixmap if an error occurs. The contents of the pixmap are only defined for the regions of widget that have received paint events since the last resize of the backing store.

If rectangle is a null rectangle (the default), the entire widget is grabbed. Otherwise, the grabbed area is limited to rectangle.

The default implementation uses QWindowSurface::buffer().

See also
QPixmap::grabWidget()

Reimplemented from QWindowSurface.

Definition at line 167 of file qwindowsurface_x11gl.cpp.

168 {
169  if (!widget || m_backBuffer.isNull())
170  return QPixmap();
171 
172  QRect srcRect;
173 
174  // make sure the rect is inside the widget & clip to widget's rect
175  if (!rect.isEmpty())
176  srcRect = rect & widget->rect();
177  else
178  srcRect = widget->rect();
179 
180  if (srcRect.isEmpty())
181  return QPixmap();
182 
183  // If it's a child widget we have to translate the coordinates
184  if (widget != window())
185  srcRect.translate(widget->mapTo(window(), QPoint(0, 0)));
186 
187  QPixmap::x11SetDefaultScreen(widget->x11Info().screen());
188 
190  pmd->resize(srcRect.width(), srcRect.height());
191  QPixmap px(pmd);
192 
193  GC tmpGc = XCreateGC(X11->display, m_backBuffer.handle(), 0, 0);
194 
195  // Make sure all GL rendering is complete before copying the window
196  QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.pixmapData())->context();
197  if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
198  ctx->makeCurrent();
199  eglWaitClient();
200 
201  // Copy srcRect from the backing store to the new pixmap
202  XSetGraphicsExposures(X11->display, tmpGc, False);
203  XCopyArea(X11->display, m_backBuffer.handle(), px.handle(), tmpGc,
204  srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0);
205  XFreeGC(X11->display, tmpGc);
206 
207  // Wait until the copy has finised before allowing more rendering into the back buffer
208  eglWaitNative(EGL_CORE_NATIVE_ENGINE);
209 
210  return px;
211 }
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define X11
Definition: qt_x11_p.h:724
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
#define ctx
Definition: qgl.cpp:6094
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
struct _XGC * GC
Definition: qwindowdefs.h:117
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
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...
Definition: qrect.h:312
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
int screen() const
Returns the number of the screen currently in use.
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ paintDevice()

QPaintDevice * QX11GLWindowSurface::paintDevice ( )
virtual

Implement this function to return the appropriate paint device.

Implements QWindowSurface.

Definition at line 66 of file qwindowsurface_x11gl.cpp.

67 {
68  return &m_backBuffer;
69 }

◆ scroll()

bool QX11GLWindowSurface::scroll ( const QRegion area,
int  dx,
int  dy 
)
virtual

Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative.

Returns true if the area was scrolled successfully; false otherwise.

Reimplemented from QWindowSurface.

Definition at line 138 of file qwindowsurface_x11gl.cpp.

139 {
140  if (m_backBuffer.isNull())
141  return false;
142 
144 
145  // Make sure all GL rendering is complete before starting the scroll operation:
146  QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.data_ptr().data())->context();
147  if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
148  ctx->makeCurrent();
149  eglWaitClient();
150 
151  if (!m_pixmapGC)
152  m_pixmapGC = XCreateGC(X11->display, m_backBuffer.handle(), 0, 0);
153 
154  foreach (const QRect& rect, area.rects()) {
155  XCopyArea(X11->display, m_backBuffer.handle(), m_backBuffer.handle(), m_pixmapGC,
156  rect.x(), rect.y(), rect.width(), rect.height(),
157  rect.x()+dx, rect.y()+dy);
158  }
159 
160  // Make sure the scroll operation is complete before allowing GL rendering to resume
161  eglWaitNative(EGL_CORE_NATIVE_ENGINE);
162 
163  return true;
164 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
ClassId classId() const
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
Definition: qgl.cpp:3477
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
#define ctx
Definition: qgl.cpp:6094
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ setGeometry()

void QX11GLWindowSurface::setGeometry ( const QRect rect)
virtual

Sets the currently allocated area to be the given rect.

This function is called whenever area covered by the top-level window changes.

See also
geometry()

Reimplemented from QWindowSurface.

Definition at line 120 of file qwindowsurface_x11gl.cpp.

121 {
122  if (rect.width() > m_backBuffer.size().width() || rect.height() > m_backBuffer.size().height()) {
124  QSize newSize = rect.size();
125  pd->resize(newSize.width(), newSize.height());
126  m_backBuffer = QPixmap(pd);
127  if (window()->testAttribute(Qt::WA_TranslucentBackground))
129  if (m_pixmapGC) {
130  XFreeGC(X11->display, m_pixmapGC);
131  m_pixmapGC = 0;
132  }
133  }
134 
136 }
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
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.
Definition: qrect.h:303
void resize(int width, int height)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define X11
Definition: qt_x11_p.h:724
int width() const
Returns the width.
Definition: qsize.h:126
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
int height() const
Returns the height.
Definition: qsize.h:129
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.

Properties

◆ m_backBuffer

QPixmap QX11GLWindowSurface::m_backBuffer
private

Definition at line 76 of file qwindowsurface_x11gl_p.h.

Referenced by flush(), grabWidget(), paintDevice(), scroll(), and setGeometry().

◆ m_pixmapGC

GC QX11GLWindowSurface::m_pixmapGC
private

Definition at line 75 of file qwindowsurface_x11gl_p.h.

Referenced by scroll(), setGeometry(), and ~QX11GLWindowSurface().

◆ m_window

QWidget* QX11GLWindowSurface::m_window
private

Definition at line 77 of file qwindowsurface_x11gl_p.h.

Referenced by flush().

◆ m_windowGC

GC QX11GLWindowSurface::m_windowGC
private

Definition at line 74 of file qwindowsurface_x11gl_p.h.

Referenced by flush(), and ~QX11GLWindowSurface().


The documentation for this class was generated from the following files: