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

#include <qwindowsurface_qws_p.h>

Inheritance diagram for QWSSharedMemSurface:
QWSMemorySurface QWSWindowSurface QWindowSurface

Public Functions

QString key () const
 Implement this function to return a string that uniquely identifies the class of this surface. More...
 
QByteArray permanentState () const
 Implement this function to return the data required for creating a server-side representation of the surface. More...
 
 QWSSharedMemSurface ()
 
 QWSSharedMemSurface (QWidget *widget)
 
virtual void releaseSurface ()
 
void setGeometry (const QRect &rect)
 Sets the currently allocated area to be the given rect. More...
 
void setPermanentState (const QByteArray &data)
 Implement this function to attach a server-side surface instance to the corresponding client side instance using the given data. More...
 
 ~QWSSharedMemSurface ()
 
- Public Functions inherited from QWSMemorySurface
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...
 
QImage image () const
 Implement this function to return an image of the top-level window. More...
 
bool isValid () const
 Implement this function to return true if the surface is a valid surface for the given top-level window; otherwise return false. More...
 
bool lock (int timeout=-1)
 
QPaintDevicepaintDevice ()
 Implement this function to return the appropriate paint device. More...
 
QPoint painterOffset () const
 Returns the offset to be used when painting. More...
 
 QWSMemorySurface ()
 
 QWSMemorySurface (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 unlock ()
 
 ~QWSMemorySurface ()
 
- Public Functions inherited from QWSWindowSurface
const QRegion clipRegion () const
 Returns the region currently visible on the screen. 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 void flush (QWidget *widget, const QRegion &region, const QPoint &offset)
 Flushes the given region from the specified widget onto the screen. More...
 
bool isBuffered () const
 Returns true if the QWSWindowSurface::Buffered is set; otherwise returns false. More...
 
bool isOpaque () const
 Returns true if the QWSWindowSurface::Opaque is set; otherwise returns false. More...
 
bool isRegionReserved () const
 Returns true if the QWSWindowSurface::RegionReserved is set; otherwise returns false. More...
 
virtual bool move (const QPoint &offset)
 Move the surface with the given offset. More...
 
virtual QRegion move (const QPoint &offset, const QRegion &newClip)
 Move the surface with the given offset. More...
 
 QWSWindowSurface ()
 Constructs an empty surface. More...
 
 QWSWindowSurface (QWidget *widget)
 Constructs an empty surface for the given top-level widget. More...
 
void setClipRegion (const QRegion &)
 Sets the region currently visible on the screen to be the given clip region. More...
 
virtual void setGeometry (const QRect &rect, const QRegion &mask)
 
virtual void setTransientState (const QByteArray &state)
 
SurfaceFlags surfaceFlags () const
 Returns the surface flags describing the contents of this surface. More...
 
virtual QByteArray transientState () const
 
int winId () const
 
 ~QWSWindowSurface ()
 
- 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...
 
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

bool setMemory (int memId)
 

Properties

QWSSharedMemory mem
 

Additional Inherited Members

- Public Types inherited from QWSWindowSurface
enum  SurfaceFlag { RegionReserved = 0x1, Buffered = 0x2, Opaque = 0x4 }
 This enum is used to describe the window surface's contents. More...
 
- Public Types inherited from QWindowSurface
enum  WindowSurfaceFeature { PartialUpdates = 0x00000001, PreservedContents = 0x00000002, StaticContents = 0x00000004, AllFeatures = 0xffffffff }
 
- Protected Functions inherited from QWSMemorySurface
QImage::Format preferredImageFormat (const QWidget *widget) const
 
void setLock (int lockId)
 
- Protected Functions inherited from QWSWindowSurface
void setSurfaceFlags (SurfaceFlags type)
 Sets the surface flags describing the contents of this surface, to be the given flags. More...
 
void setWinId (int id)
 
- Protected Functions inherited from QWindowSurface
bool hasStaticContents () const
 
- Protected Variables inherited from QWSMemorySurface
QImage img
 
QWSLockmemlock
 
QMutex threadLock
 

Detailed Description

Definition at line 218 of file qwindowsurface_qws_p.h.

Constructors and Destructors

◆ QWSSharedMemSurface() [1/2]

QWSSharedMemSurface::QWSSharedMemSurface ( )

Definition at line 1075 of file qwindowsurface_qws.cpp.

1076  : QWSMemorySurface()
1077 {
1078 }

◆ QWSSharedMemSurface() [2/2]

QWSSharedMemSurface::QWSSharedMemSurface ( QWidget widget)

Definition at line 1080 of file qwindowsurface_qws.cpp.

1081  : QWSMemorySurface(widget)
1082 {
1083 }

◆ ~QWSSharedMemSurface()

QWSSharedMemSurface::~QWSSharedMemSurface ( )

Definition at line 1085 of file qwindowsurface_qws.cpp.

1086 {
1087  // mem.detach() is done automatically by ~QSharedMemory
1088 }

Functions

◆ key()

QString QWSSharedMemSurface::key ( ) const
inlinevirtual

Implement this function to return a string that uniquely identifies the class of this surface.

See also
window(), isValid()

Implements QWSWindowSurface.

Definition at line 227 of file qwindowsurface_qws_p.h.

227 { return QLatin1String("shm"); }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ permanentState()

QByteArray QWSSharedMemSurface::permanentState ( ) const
virtual

Implement this function to return the data required for creating a server-side representation of the surface.

Since
4.3
See also
attach()

Reimplemented from QWSWindowSurface.

Definition at line 1192 of file qwindowsurface_qws.cpp.

1193 {
1194  QByteArray array(6 * sizeof(int), Qt::Uninitialized);
1195 
1196  int *ptr = reinterpret_cast<int*>(array.data());
1197 
1198  ptr[0] = mem.id();
1199  ptr[1] = img.width();
1200  ptr[2] = img.height();
1201  ptr[3] = (memlock ? memlock->id() : -1);
1202  ptr[4] = int(img.format());
1203  ptr[5] = int(surfaceFlags());
1204 
1205  return array;
1206 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
const T * ptr(const T &t)
SurfaceFlags surfaceFlags() const
Returns the surface flags describing the contents of this surface.
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
int id() const
Definition: qwslock_p.h:78

◆ releaseSurface()

void QWSSharedMemSurface::releaseSurface ( )
virtual

Reimplemented from QWSWindowSurface.

Definition at line 1208 of file qwindowsurface_qws.cpp.

1209 {
1210  mem.detach();
1211  img = QImage();
1212 }
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ setGeometry()

void QWSSharedMemSurface::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 QWSWindowSurface.

Definition at line 1155 of file qwindowsurface_qws.cpp.

1156 {
1157  const QSize size = rect.size();
1158  if (img.size() != size) {
1159  if (size.isEmpty()) {
1160  mem.detach();
1161  img = QImage();
1162  } else {
1163  QWidget *win = window();
1165  const int bpl = nextMulOf4(bytesPerPixel(format) * size.width());
1166 #ifdef QT_QWS_CLIENTBLIT
1167  const int imagesize = bpl * size.height() + sizeof(uint);
1168 #else
1169  const int imagesize = bpl * size.height();
1170 #endif
1171  if (mem.size() < imagesize) {
1172  mem.detach();
1173  if (!mem.create(imagesize)) {
1174  perror("QWSSharedMemSurface::setGeometry allocating shared memory");
1175  qFatal("Error creating shared memory of size %d", imagesize);
1176  }
1177  }
1178 #ifdef QT_QWS_CLIENTBLIT
1179  *((uint *)mem.address()) = 0;
1180  uchar *base = static_cast<uchar*>(mem.address()) + sizeof(uint);
1181 #else
1182  uchar *base = static_cast<uchar*>(mem.address());
1183 #endif
1184  img = QImage(base, size.width(), size.height(), bpl, format);
1185  setImageMetrics(img, win);
1186  }
1187  }
1188 
1190 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
bool create(int size)
void * address() const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static int bytesPerPixel(QImage::Format format)
static int nextMulOf4(int n)
static const uint base
Definition: qurl.cpp:268
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
QImage::Format preferredImageFormat(const QWidget *widget) const
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
Q_CORE_EXPORT void qFatal(const char *,...)
static void setImageMetrics(QImage &img, QWidget *window)
int height() const
Returns the height.
Definition: qsize.h:129
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.

◆ setMemory()

bool QWSSharedMemSurface::setMemory ( int  memId)
private

Definition at line 1090 of file qwindowsurface_qws.cpp.

Referenced by setPermanentState().

1091 {
1092  if (mem.id() == memId)
1093  return true;
1094 
1095  mem.detach();
1096 
1097  if (memId != -1 && !mem.attach(memId)) {
1098 #ifndef QT_NO_DEBUG
1099  perror("QWSSharedMemSurface: attaching to shared memory");
1100  qCritical("QWSSharedMemSurface: Error attaching to shared memory 0x%x", memId);
1101 #endif
1102  return false;
1103  }
1104 
1105  return true;
1106 }
bool attach(int id)
Q_CORE_EXPORT void qCritical(const char *,...)

◆ setPermanentState()

void QWSSharedMemSurface::setPermanentState ( const QByteArray data)
virtual

Implement this function to attach a server-side surface instance to the corresponding client side instance using the given data.

Since
4.3

Return true if successful; otherwise return false.

See also
data()

Reimplemented from QWSWindowSurface.

Definition at line 1124 of file qwindowsurface_qws.cpp.

1125 {
1126  int memId;
1127  int width;
1128  int height;
1129  int lockId;
1131  SurfaceFlags flags;
1132 
1133  const int *ptr = reinterpret_cast<const int*>(data.constData());
1134 
1135  memId = ptr[0];
1136  width = ptr[1];
1137  height = ptr[2];
1138  lockId = ptr[3];
1139  format = QImage::Format(ptr[4]);
1140  flags = SurfaceFlags(ptr[5]);
1141 
1142  setSurfaceFlags(flags);
1143  setMemory(memId);
1144  setLock(lockId);
1145 
1146 #ifdef QT_QWS_CLIENTBLIT
1147  uchar *base = static_cast<uchar*>(mem.address()) + sizeof(uint);
1148 #else
1149  uchar *base = static_cast<uchar*>(mem.address());
1150 #endif
1151  const int bpl = nextMulOf4(bytesPerPixel(format) * width);
1152  QWSMemorySurface::img = QImage(base, width, height, bpl, format);
1153 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
void * address() const
static int bytesPerPixel(QImage::Format format)
void setSurfaceFlags(SurfaceFlags type)
Sets the surface flags describing the contents of this surface, to be the given flags.
static int nextMulOf4(int n)
static const uint base
Definition: qurl.cpp:268
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
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void setLock(int lockId)

Properties

◆ mem

QWSSharedMemory QWSSharedMemSurface::mem
private

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