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

#include <qwindowsurface_x11_p.h>

Inheritance diagram for QX11WindowSurface:
QWindowSurface

Public Functions

void beginPaint (const QRegion &rgn)
 This function is called before painting onto the surface begins, with the region in which the painting will occur. More...
 
WindowSurfaceFeatures features () const
 
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...
 
 QX11WindowSurface (QWidget *widget)
 
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...
 
 ~QX11WindowSurface ()
 
- Public Functions inherited from QWindowSurface
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...
 
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

QX11WindowSurfacePrivated_ptr
 
GC gc
 

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 69 of file qwindowsurface_x11_p.h.

Constructors and Destructors

◆ QX11WindowSurface()

QX11WindowSurface::QX11WindowSurface ( QWidget widget)

Definition at line 66 of file qwindowsurface_x11.cpp.

68 {
69  d_ptr->widget = widget;
70 #ifndef QT_NO_XRENDER
71  d_ptr->translucentBackground = X11->use_xrender
72  && widget->x11Info().depth() == 32;
73 #endif
74 }
int depth() const
Returns the color depth (bits per pixel) of the X display.
QPointer< QWidget > widget
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
#define X11
Definition: qt_x11_p.h:724
QX11WindowSurfacePrivate * d_ptr
QWindowSurface(QWidget *window, bool setDefaultSurface=true)
Constructs an empty surface for the given top-level window.

◆ ~QX11WindowSurface()

QX11WindowSurface::~QX11WindowSurface ( )

Definition at line 77 of file qwindowsurface_x11.cpp.

78 {
79  delete d_ptr;
80  if (gc) {
81  XFreeGC(X11->display, gc);
82  gc = 0;
83  }
84 }
#define X11
Definition: qt_x11_p.h:724
QX11WindowSurfacePrivate * d_ptr

Functions

◆ beginPaint()

void QX11WindowSurface::beginPaint ( const QRegion region)
virtual

This function is called before painting onto the surface begins, with the region in which the painting will occur.

See also
endPaint(), paintDevice()

Reimplemented from QWindowSurface.

Definition at line 91 of file qwindowsurface_x11.cpp.

92 {
93 #ifndef QT_NO_XRENDER
95 
97  if (d_ptr->device.depth() != 32)
98  static_cast<QX11PixmapData *>(d_ptr->device.data_ptr().data())->convertToARGB32();
99  ::Picture src = X11->getSolidFill(d_ptr->device.x11Info().screen(), Qt::transparent);
100  ::Picture dst = d_ptr->device.x11PictureHandle();
101  const QVector<QRect> rects = rgn.rects();
102  const int w = d_ptr->device.width();
103  const int h = d_ptr->device.height();
104  for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it)
105  XRenderComposite(X11->display, PictOpSrc, src, 0, dst,
106  0, 0, w, h, it->x(), it->y(),
107  it->width(), it->height());
108  }
109 #endif
110 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
#define it(className, varName)
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QX11WindowSurfacePrivate * d_ptr
unsigned long Picture
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ features()

QWindowSurface::WindowSurfaceFeatures QX11WindowSurface::features ( ) const
virtual

Reimplemented from QWindowSurface.

Definition at line 253 of file qwindowsurface_x11.cpp.

254 {
256 #ifndef QT_NO_XRENDER
258  features |= QWindowSurface::StaticContents;
259 #else
260  features |= QWindowSurface::StaticContents;
261 #endif
262  return features;
263 }
WindowSurfaceFeatures features() const
QX11WindowSurfacePrivate * d_ptr

◆ flush()

void QX11WindowSurface::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 112 of file qwindowsurface_x11.cpp.

113 {
114  if (d_ptr->device.isNull())
115  return;
116 
117  QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();
118  QRegion wrgn(rgn);
119  QRect br = rgn.boundingRect();
120  if (!wOffset.isNull())
121  wrgn.translate(-wOffset);
122  QRect wbr = wrgn.boundingRect();
123 
124  int num;
125  XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num);
126  if (num <= 0)
127  return;
128 // qDebug() << "XSetClipRectangles";
129 // for (int i = 0; i < num; ++i)
130 // qDebug() << ' ' << i << rects[i].x << rects[i].x << rects[i].y << rects[i].width << rects[i].height;
131  if (num != 1)
132  XSetClipRectangles(X11->display, gc, 0, 0, rects, num, YXBanded);
133  XCopyArea(X11->display, d_ptr->device.handle(), widget->handle(), gc,
134  br.x() + offset.x(), br.y() + offset.y(), br.width(), br.height(), wbr.x(), wbr.y());
135  if (num != 1)
136  XSetClipMask(X11->display, gc, XNone);
137 }
void * qt_getClipRects(const QRegion &r, int &num)
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
bool isNull() const
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
Definition: qpoint.h:125
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QRect wrect
Definition: qwidget.h:145
QX11WindowSurfacePrivate * d_ptr
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
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
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
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
Q_GUI_EXPORT QWidgetData * qt_qwidget_data(QWidget *widget)
Definition: qwidget.cpp:12915
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ grabWidget()

QPixmap QX11WindowSurface::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 217 of file qwindowsurface_x11.cpp.

219 {
220  if (!widget || d_ptr->device.isNull())
221  return QPixmap();
222 
223  QRect srcRect;
224 
225  // make sure the rect is inside the widget & clip to widget's rect
226  if (!rect.isEmpty())
227  srcRect = rect & widget->rect();
228  else
229  srcRect = widget->rect();
230 
231  if (srcRect.isEmpty())
232  return QPixmap();
233 
234  // If it's a child widget we have to translate the coordinates
235  if (widget != window())
236  srcRect.translate(widget->mapTo(window(), QPoint(0, 0)));
237 
238  QPixmap::x11SetDefaultScreen(widget->x11Info().screen());
239  QPixmap px(srcRect.width(), srcRect.height());
240 
241  GC tmpGc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0);
242 
243  // Copy srcRect from the backing store to the new pixmap
244  XSetGraphicsExposures(X11->display, tmpGc, False);
245  XCopyArea(X11->display, d_ptr->device.handle(), px.handle(), tmpGc,
246  srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0);
247 
248  XFreeGC(X11->display, tmpGc);
249 
250  return px;
251 }
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
QX11WindowSurfacePrivate * d_ptr
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
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
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.

◆ paintDevice()

QPaintDevice * QX11WindowSurface::paintDevice ( )
virtual

Implement this function to return the appropriate paint device.

Implements QWindowSurface.

Definition at line 86 of file qwindowsurface_x11.cpp.

87 {
88  return &d_ptr->device;
89 }
QX11WindowSurfacePrivate * d_ptr

◆ scroll()

bool QX11WindowSurface::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 201 of file qwindowsurface_x11.cpp.

202 {
203  QRect rect = area.boundingRect();
204 
205  if (d_ptr->device.isNull())
206  return false;
207 
208  GC gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0);
209  XCopyArea(X11->display, d_ptr->device.handle(), d_ptr->device.handle(), gc,
210  rect.x(), rect.y(), rect.width(), rect.height(),
211  rect.x()+dx, rect.y()+dy);
212  XFreeGC(X11->display, gc);
213 
214  return true;
215 }
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
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define X11
Definition: qt_x11_p.h:724
QX11WindowSurfacePrivate * d_ptr
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
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
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

◆ setGeometry()

void QX11WindowSurface::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 139 of file qwindowsurface_x11.cpp.

140 {
142 
143  const QSize size = rect.size();
144 
145  if (d_ptr->device.size() == size || size.width() <= 0 || size.height() <= 0)
146  return;
147 #ifndef QT_NO_XRENDER
149  QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen());
150 
152  data->xinfo = d_ptr->widget->x11Info();
153  data->resize(size.width(), size.height());
154  d_ptr->device = QPixmap(data);
155  } else
156 #endif
157  {
158  QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen());
159 
160  QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData());
161 
162  if (oldData && !(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) {
163  // Copy the content of the old pixmap into the new one.
165  newData->resize(size.width(), size.height());
166  Q_ASSERT(oldData->d == newData->d);
167 
168  QRegion staticRegion(staticContents());
169  // Make sure we're inside the boundaries of the old pixmap.
170  staticRegion &= QRect(0, 0, oldData->w, oldData->h);
171  const QRect boundingRect(staticRegion.boundingRect());
172  const int dx = boundingRect.x();
173  const int dy = boundingRect.y();
174 
175  int num;
176  XRectangle *rects = (XRectangle *)qt_getClipRects(staticRegion, num);
177  GC tmpGc = XCreateGC(X11->display, oldData->hd, 0, 0);
178  XSetClipRectangles(X11->display, tmpGc, 0, 0, rects, num, YXBanded);
179  XCopyArea(X11->display, oldData->hd, newData->hd, tmpGc,
180  dx, dy, qMin(boundingRect.width(), size.width()),
181  qMin(boundingRect.height(), size.height()), dx, dy);
182  XFreeGC(X11->display, tmpGc);
184 
185  d_ptr->device = QPixmap(newData);
186  } else {
187  d_ptr->device = QPixmap(size);
188  }
189  }
190 
191  if (gc) {
192  XFreeGC(X11->display, gc);
193  gc = 0;
194  }
195  if (!d_ptr->device.isNull()) {
196  gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0);
197  XSetGraphicsExposures(X11->display, gc, False);
198  }
199 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void * qt_getClipRects(const QRegion &r, int &num)
Qt::HANDLE hd
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
void resize(int width, int height)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
static const QRectF boundingRect(const QPointF *points, int pointCount)
int width() const
Returns the width.
Definition: qsize.h:126
bool hasStaticContents() const
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
static const char * data(const QByteArray &arr)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QX11WindowSurfacePrivate * d_ptr
QRegion staticContents() const
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
int height() const
Returns the height.
Definition: qsize.h:129
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
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
int screen() const
Returns the number of the screen currently in use.
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

Properties

◆ d_ptr

QX11WindowSurfacePrivate* QX11WindowSurface::d_ptr
private

◆ gc

GC QX11WindowSurface::gc
private

Definition at line 87 of file qwindowsurface_x11_p.h.

Referenced by flush(), scroll(), setGeometry(), and ~QX11WindowSurface().


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