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

#include <qxlibwindowsurface.h>

Inheritance diagram for QXlibWindowSurface:
QWindowSurface

Public Functions

void beginPaint (const QRegion &region)
 This function is called before painting onto the surface begins, with the region in which the painting will occur. More...
 
void endPaint (const QRegion &region)
 This function is called after painting onto the surface has ended, with the region in which the painting was performed. More...
 
void flush (QWidget *widget, const QRegion &region, const QPoint &offset)
 Flushes the given region from the specified widget onto the screen. More...
 
QPaintDevicepaintDevice ()
 Implement this function to return the appropriate paint device. More...
 
 QXlibWindowSurface (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...
 
 ~QXlibWindowSurface ()
 
- 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 WindowSurfaceFeatures features () const
 
QRect geometry () const
 Returns the currently allocated area on the screen. More...
 
virtual 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...
 
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...
 
virtual void setGeometry (const QRect &rect)
 Sets the currently allocated area to be the given rect. 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...
 

Private Functions

QSize bufferSize () const
 
void resizeBuffer (QSize)
 
void resizeShmImage (int width, int height)
 

Properties

QXlibShmImageInfoimage_info
 
bool painted
 
QImage shm_img
 
QXlibWindowxw
 

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 55 of file qxlibwindowsurface.h.

Constructors and Destructors

◆ QXlibWindowSurface()

QXlibWindowSurface::QXlibWindowSurface ( QWidget window)

Definition at line 130 of file qxlibwindowsurface.cpp.

131  : QWindowSurface(window),
132  painted(false), image_info(0)
133 {
134  xw = static_cast<QXlibWindow*>(window->platformWindow());
135 // qDebug() << "QTestLiteWindowSurface::QTestLiteWindowSurface:" << xw->window;
136 }
QXlibShmImageInfo * image_info
QWindowSurface(QWidget *window, bool setDefaultSurface=true)
Constructs an empty surface for the given top-level window.

◆ ~QXlibWindowSurface()

QXlibWindowSurface::~QXlibWindowSurface ( )

Definition at line 138 of file qxlibwindowsurface.cpp.

139 {
140  delete image_info;
141 }
QXlibShmImageInfo * image_info

Functions

◆ beginPaint()

void QXlibWindowSurface::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 214 of file qxlibwindowsurface.cpp.

215 {
216  Q_UNUSED(region);
217  resizeBuffer(size());
218 
219  if (shm_img.hasAlphaChannel()) {
220  QPainter p(&shm_img);
221  p.setCompositionMode(QPainter::CompositionMode_Source);
222  const QVector<QRect> rects = region.rects();
223  const QColor blank = Qt::transparent;
224  for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
225  p.fillRect(*it, blank);
226  }
227  }
228 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
#define it(className, varName)
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
#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

◆ bufferSize()

QSize QXlibWindowSurface::bufferSize ( ) const
private

Definition at line 125 of file qxlibwindowsurface.cpp.

126 {
127  return shm_img.size();
128 }
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587

◆ endPaint()

void QXlibWindowSurface::endPaint ( const QRegion region)
virtual

This function is called after painting onto the surface has ended, with the region in which the painting was performed.

See also
beginPaint(), paintDevice()

Reimplemented from QWindowSurface.

Definition at line 230 of file qxlibwindowsurface.cpp.

231 {
232  Q_UNUSED(region);
233  painted = true; //there is content in the buffer
234 }
#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

◆ flush()

void QXlibWindowSurface::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 149 of file qxlibwindowsurface.cpp.

150 {
151  Q_UNUSED(widget);
152  Q_UNUSED(region);
153  Q_UNUSED(offset);
154 
155  if (!painted)
156  return;
157 
159  GC gc = xw->graphicsContext();
160  Window window = xw->xWindow();
161 #ifdef DONT_USE_MIT_SHM
162  // just convert the image every time...
163  if (!shm_img.isNull()) {
164  QXlibWindow *win = static_cast<QXlibWindow*>(window()->platformWindow());
165 
166  QImage image = shm_img;
167  //img.convertToFormat(
168  XImage *xi = XCreateImage(screen->display(), win->visual(), win->depth(), ZPixmap,
169  0, (char *) image.scanLine(0), image.width(), image.height(),
170  32, image.bytesPerLine());
171 
172  int x = 0;
173  int y = 0;
174 
175  /*int r =*/ XPutImage(screen->display(), window, gc, xi, 0, 0, x, y, image.width(), image.height());
176 
177  xi->data = 0; // QImage owns these bits
178  XDestroyImage(xi);
179  }
180 #else
181  // Use MIT_SHM
182  if (image_info && image_info->image) {
183  //qDebug() << "Here we go" << image_info->image->width << image_info->image->height;
184  int x = 0;
185  int y = 0;
186 
187  // We could set send_event to true, and then use the ShmCompletion to synchronize,
188  // but let's do like Qt/11 and just use XSync
189  XShmPutImage (screen->display()->nativeDisplay(), window, gc, image_info->image, 0, 0,
190  x, y, image_info->image->width, image_info->image->height,
191  /*send_event*/ False);
192 
193  screen->display()->sync();
194  }
195 #endif
196 }
uint depth() const
Definition: qxlibwindow.h:125
Window xWindow() const
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
Display * nativeDisplay() const
Visual * visual() const
Definition: qxlibwindow.h:127
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
static QXlibScreen * testLiteScreenForWidget(QWidget *widget)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QXlibShmImageInfo * image_info
GC graphicsContext() const
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
struct _XGC * GC
Definition: qwindowdefs.h:117
QXlibDisplay * display() const
#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
void sync() const
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ paintDevice()

QPaintDevice * QXlibWindowSurface::paintDevice ( )
virtual

Implement this function to return the appropriate paint device.

Implements QWindowSurface.

Definition at line 143 of file qxlibwindowsurface.cpp.

144 {
145  return &shm_img;
146 }

◆ resizeBuffer()

void QXlibWindowSurface::resizeBuffer ( QSize  s)
private

Definition at line 119 of file qxlibwindowsurface.cpp.

Referenced by beginPaint().

120 {
121  if (shm_img.size() != s)
122  resizeShmImage(s.width(), s.height());
123 }
void resizeShmImage(int width, int height)
int width() const
Returns the width.
Definition: qsize.h:126
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
int height() const
Returns the height.
Definition: qsize.h:129

◆ resizeShmImage()

void QXlibWindowSurface::resizeShmImage ( int  width,
int  height 
)
private

Definition at line 83 of file qxlibwindowsurface.cpp.

84 {
86  QXlibWindow *win = static_cast<QXlibWindow*>(window()->platformWindow());
87 
88 #ifdef DONT_USE_MIT_SHM
89  shm_img = QImage(width, height, win->format());
90 #else
91 
92  if (image_info)
94  else
96 
97  XImage *image = XShmCreateImage (screen->display()->nativeDisplay(), win->visual(), win->depth(), ZPixmap, 0,
98  &image_info->shminfo, width, height);
99 
100 
101  image_info->shminfo.shmid = shmget (IPC_PRIVATE,
102  image->bytes_per_line * image->height, IPC_CREAT|0700);
103 
104  image_info->shminfo.shmaddr = image->data = (char*)shmat (image_info->shminfo.shmid, 0, 0);
105  image_info->shminfo.readOnly = False;
106 
107  image_info->image = image;
108 
109  Status shm_attach_status = XShmAttach(screen->display()->nativeDisplay(), &image_info->shminfo);
110 
111  Q_ASSERT(shm_attach_status == True);
112 
113  shm_img = QImage( (uchar*) image->data, image->width, image->height, image->bytes_per_line, win->format() );
114 #endif
115  painted = false;
116 }
uint depth() const
Definition: qxlibwindow.h:125
Display * nativeDisplay() const
Visual * visual() const
Definition: qxlibwindow.h:127
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
XShmSegmentInfo shminfo
static QXlibScreen * testLiteScreenForWidget(QWidget *widget)
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QXlibShmImageInfo * image_info
QImage::Format format() const
Definition: qxlibwindow.h:126
QXlibDisplay * display() const
#define Status
Definition: qcursor_x11.cpp:59
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.

◆ scroll()

bool QXlibWindowSurface::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 qxlibwindowsurface.cpp.

202 {
203  if (shm_img.isNull())
204  return false;
205 
206  const QVector<QRect> rects = area.rects();
207  for (int i = 0; i < rects.size(); ++i)
208  qt_scrollRectInImage(shm_img, rects.at(i), QPoint(dx, dy));
209 
210  return true;
211 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)

Properties

◆ image_info

QXlibShmImageInfo* QXlibWindowSurface::image_info
private

Definition at line 77 of file qxlibwindowsurface.h.

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

◆ painted

bool QXlibWindowSurface::painted
private

Definition at line 69 of file qxlibwindowsurface.h.

Referenced by endPaint(), and flush().

◆ shm_img

QImage QXlibWindowSurface::shm_img
private

Definition at line 76 of file qxlibwindowsurface.h.

Referenced by beginPaint(), flush(), paintDevice(), and scroll().

◆ xw

QXlibWindow* QXlibWindowSurface::xw
private

Definition at line 79 of file qxlibwindowsurface.h.

Referenced by flush(), and QXlibWindowSurface().


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