Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QXcbShmImage Class Reference
Inheritance diagram for QXcbShmImage:
QXcbObject

Public Functions

QImageimage ()
 
void preparePaint (const QRegion &region)
 
void put (xcb_window_t window, const QPoint &dst, const QRect &source)
 
 QXcbShmImage (QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format)
 
 ~QXcbShmImage ()
 
- Public Functions inherited from QXcbObject
xcb_atom_t atom (QXcbAtom::Atom atom) const
 
QXcbConnectionconnection () const
 
 QXcbObject (QXcbConnection *connection=0)
 
void setConnection (QXcbConnection *connection)
 
xcb_connection_t * xcb_connection () const
 

Private Functions

void destroy ()
 

Properties

QRegion m_dirty
 
xcb_gcontext_t m_gc
 
xcb_window_t m_gc_window
 
QImage m_qimage
 
xcb_shm_segment_info_t m_shm_info
 
xcb_image_t * m_xcb_image
 

Detailed Description

Definition at line 59 of file qxcbwindowsurface.cpp.

Constructors and Destructors

◆ QXcbShmImage()

QXcbShmImage::QXcbShmImage ( QXcbScreen connection,
const QSize size,
uint  depth,
QImage::Format  format 
)

Definition at line 85 of file qxcbwindowsurface.cpp.

86  : QXcbObject(screen->connection())
87  , m_gc(0)
88  , m_gc_window(0)
89 {
91  m_xcb_image = xcb_image_create_native(xcb_connection(),
92  size.width(),
93  size.height(),
94  XCB_IMAGE_FORMAT_Z_PIXMAP,
95  depth,
96  0,
97  ~0,
98  0);
99 
100  m_shm_info.shmid = shmget (IPC_PRIVATE,
101  m_xcb_image->stride * m_xcb_image->height, IPC_CREAT|0600);
102 
103  m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0);
104  m_shm_info.shmseg = xcb_generate_id(xcb_connection());
105 
106  xcb_generic_error_t *error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false));
107  if (error) {
108  qWarning() << "QXcbWindowSurface: Unable to attach to shared memory segment";
109  free(error);
110  }
111 
112  if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1)
113  qWarning() << "QXcbWindowSurface: Error while marking the shared memory segment to be destroyed";
114 
115  m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format);
116 }
xcb_gcontext_t m_gc
#define error(msg)
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
unsigned char quint8
Definition: qglobal.h:934
QXcbConnection * connection() const
Definition: qxcbobject.h:53
xcb_shm_segment_info_t m_shm_info
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
xcb_image_t * m_xcb_image
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
xcb_window_t m_gc_window
#define Q_XCB_NOOP(c)
int height() const
Returns the height.
Definition: qsize.h:129
QXcbObject(QXcbConnection *connection=0)
Definition: qxcbobject.h:50

◆ ~QXcbShmImage()

QXcbShmImage::~QXcbShmImage ( )
inline

Definition at line 63 of file qxcbwindowsurface.cpp.

63 { destroy(); }

Functions

◆ destroy()

void QXcbShmImage::destroy ( )
private

Definition at line 118 of file qxcbwindowsurface.cpp.

Referenced by image(), and ~QXcbShmImage().

119 {
120  Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg));
121  xcb_image_destroy(m_xcb_image);
122  shmdt(m_shm_info.shmaddr);
123  shmctl(m_shm_info.shmid, IPC_RMID, 0);
124  if (m_gc)
125  Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
126 }
xcb_gcontext_t m_gc
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
xcb_shm_segment_info_t m_shm_info
xcb_image_t * m_xcb_image
#define Q_XCB_CALL(x)

◆ image()

QImage* QXcbShmImage::image ( )
inline

◆ preparePaint()

void QXcbShmImage::preparePaint ( const QRegion region)

Definition at line 162 of file qxcbwindowsurface.cpp.

Referenced by QXcbWindowSurface::beginPaint(), image(), and QXcbWindowSurface::scroll().

163 {
164  // to prevent X from reading from the image region while we're writing to it
165  if (m_dirty.intersects(region)) {
166  connection()->sync();
167  m_dirty = QRegion();
168  }
169 }
QXcbConnection * connection() const
Definition: qxcbobject.h:53
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
bool intersects(const QRegion &r) const
Returns true if this region intersects with region, otherwise returns false.
Definition: qregion.cpp:766

◆ put()

void QXcbShmImage::put ( xcb_window_t  window,
const QPoint dst,
const QRect source 
)

Definition at line 128 of file qxcbwindowsurface.cpp.

Referenced by QXcbWindowSurface::flush(), and image().

129 {
131  if (m_gc_window != window) {
132  if (m_gc)
133  Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
134 
135  m_gc = xcb_generate_id(xcb_connection());
136  Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0));
137 
139  }
140 
142  xcb_image_shm_put(xcb_connection(),
143  window,
144  m_gc,
145  m_xcb_image,
146  m_shm_info,
147  source.x(),
148  source.y(),
149  target.x(),
150  target.y(),
151  source.width(),
152  source.height(),
153  false);
155 
156  m_dirty = m_dirty | source;
157 
158  xcb_flush(xcb_connection());
160 }
xcb_gcontext_t m_gc
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QXcbConnection * connection() const
Definition: qxcbobject.h:53
xcb_shm_segment_info_t m_shm_info
NSWindow * window
xcb_image_t * m_xcb_image
xcb_window_t m_gc_window
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
#define Q_XCB_CALL(x)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
#define Q_XCB_NOOP(c)

Properties

◆ m_dirty

QRegion QXcbShmImage::m_dirty
private

Definition at line 82 of file qxcbwindowsurface.cpp.

Referenced by preparePaint(), and put().

◆ m_gc

xcb_gcontext_t QXcbShmImage::m_gc
private

Definition at line 79 of file qxcbwindowsurface.cpp.

Referenced by destroy(), and put().

◆ m_gc_window

xcb_window_t QXcbShmImage::m_gc_window
private

Definition at line 80 of file qxcbwindowsurface.cpp.

Referenced by put().

◆ m_qimage

QImage QXcbShmImage::m_qimage
private

Definition at line 77 of file qxcbwindowsurface.cpp.

Referenced by image(), and QXcbShmImage().

◆ m_shm_info

xcb_shm_segment_info_t QXcbShmImage::m_shm_info
private

Definition at line 73 of file qxcbwindowsurface.cpp.

Referenced by destroy(), put(), and QXcbShmImage().

◆ m_xcb_image

xcb_image_t* QXcbShmImage::m_xcb_image
private

Definition at line 75 of file qxcbwindowsurface.cpp.

Referenced by destroy(), put(), and QXcbShmImage().


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