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

#include <qwaylandshmsurface.h>

Inheritance diagram for QWaylandShmBuffer:
QWaylandBuffer

Public Functions

QImageimage ()
 
 QWaylandShmBuffer (QWaylandDisplay *display, const QSize &size, QImage::Format format)
 
QSize size () const
 
 ~QWaylandShmBuffer ()
 
- Public Functions inherited from QWaylandBuffer
wl_buffer * buffer ()
 
 QWaylandBuffer ()
 
virtual ~QWaylandBuffer ()
 

Properties

QImage mImage
 

Additional Inherited Members

- Protected Variables inherited from QWaylandBuffer
struct wl_buffer * mBuffer
 

Detailed Description

Definition at line 54 of file qwaylandshmsurface.h.

Constructors and Destructors

◆ QWaylandShmBuffer()

QWaylandShmBuffer::QWaylandShmBuffer ( QWaylandDisplay display,
const QSize size,
QImage::Format  format 
)

Definition at line 58 of file qwaylandshmsurface.cpp.

60 {
61  int stride = size.width() * 4;
62  int alloc = stride * size.height();
63  char filename[] = "/tmp/wayland-shm-XXXXXX";
64  int fd = mkstemp(filename);
65  if (fd < 0)
66  qWarning("open %s failed: %s", filename, strerror(errno));
67  if (ftruncate(fd, alloc) < 0) {
68  qWarning("ftruncate failed: %s", strerror(errno));
69  close(fd);
70  return;
71  }
72  uchar *data = (uchar *)
73  mmap(NULL, alloc, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
74  unlink(filename);
75 
76  if (data == (uchar *) MAP_FAILED) {
77  qWarning("mmap /dev/zero failed: %s", strerror(errno));
78  close(fd);
79  return;
80  }
81 
82  mImage = QImage(data, size.width(), size.height(), stride, format);
83  mBuffer = display->createShmBuffer(fd, size.width(), size.height(),
84  stride, display->argbVisual());
85  close(fd);
86 }
#define MAP_FAILED
struct wl_visual * argbVisual()
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
int height() const
Returns the height.
Definition: qsize.h:129
struct wl_buffer * mBuffer
struct wl_buffer * createShmBuffer(int fd, int width, int height, uint32_t stride, struct wl_visual *visual)
int errno

◆ ~QWaylandShmBuffer()

QWaylandShmBuffer::~QWaylandShmBuffer ( void  )

Definition at line 88 of file qwaylandshmsurface.cpp.

89 {
90  munmap((void *) mImage.constBits(), mImage.byteCount());
91  wl_buffer_destroy(mBuffer);
92 }
int byteCount() const
Returns the number of bytes occupied by the image data.
Definition: qimage.cpp:1800
const uchar * constBits() const
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1985
struct wl_buffer * mBuffer

Functions

◆ image()

QImage* QWaylandShmBuffer::image ( )
inline

◆ size()

QSize QWaylandShmBuffer::size ( ) const
inlinevirtual

Implements QWaylandBuffer.

Definition at line 59 of file qwaylandshmsurface.h.

Referenced by QWaylandCursor::changeCursor(), and QWaylandShmWindowSurface::resize().

59 { return mImage.size(); }
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587

Properties

◆ mImage

QImage QWaylandShmBuffer::mImage
private

Definition at line 62 of file qwaylandshmsurface.h.

Referenced by image(), QWaylandShmBuffer(), size(), and ~QWaylandShmBuffer().


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