From 315327f3d6419d2689d3414d62012d65fe441f27 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Thu, 15 Mar 2018 16:33:20 +0100 Subject: xcb: rename two classes in qxcbbackingstore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QXcbShmImage to QXcbBackingStoreImage as it is an image that might or might not have SHM capability. The current name implies that it always uses SHM. QXcbShmGraphicsBuffer to QXcbGraphicsBuffer as it has nothing to do with SHM. Change-Id: I57ced75891e8b10515142769278a7f3f40da91ef Reviewed-by: Alexander Volkov Reviewed-by: Błażej Szczygieł Reviewed-by: Laszlo Agocs --- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 42 +++++++++++++------------- src/plugins/platforms/xcb/qxcbbackingstore.h | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/plugins/platforms/xcb') diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 70d1757af4..6efdb2d834 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -70,11 +70,11 @@ QT_BEGIN_NAMESPACE -class QXcbShmImage : public QXcbObject +class QXcbBackingStoreImage : public QXcbObject { public: - QXcbShmImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); - ~QXcbShmImage() { destroy(true); } + QXcbBackingStoreImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); + ~QXcbBackingStoreImage() { destroy(true); } void resize(const QSize &size); @@ -140,10 +140,10 @@ private: bool m_clientSideScroll; }; -class QXcbShmGraphicsBuffer : public QPlatformGraphicsBuffer +class QXcbGraphicsBuffer : public QPlatformGraphicsBuffer { public: - QXcbShmGraphicsBuffer(QImage *image) + QXcbGraphicsBuffer(QImage *image) : QPlatformGraphicsBuffer(image->size(), QImage::toPixelFormat(image->format())) , m_access_lock(QPlatformGraphicsBuffer::None) , m_image(image) @@ -175,7 +175,7 @@ static inline size_t imageDataSize(const xcb_image_t *image) return static_cast(image->stride) * image->height; } -QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) +QXcbBackingStoreImage::QXcbBackingStoreImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) : QXcbObject(screen->connection()) , m_screen_root(screen->screen()->root) , m_segmentSize(0) @@ -196,7 +196,7 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI create(size, fmt, format); } -void QXcbShmImage::resize(const QSize &size) +void QXcbBackingStoreImage::resize(const QSize &size) { xcb_format_t fmt; fmt.depth = m_xcb_image->depth; @@ -207,7 +207,7 @@ void QXcbShmImage::resize(const QSize &size) create(size, &fmt, m_qimage.format()); } -void QXcbShmImage::create(const QSize &size, const xcb_format_t *fmt, QImage::Format format) +void QXcbBackingStoreImage::create(const QSize &size, const xcb_format_t *fmt, QImage::Format format) { m_xcb_image = xcb_image_create(size.width(), size.height(), XCB_IMAGE_FORMAT_Z_PIXMAP, @@ -232,7 +232,7 @@ void QXcbShmImage::create(const QSize &size, const xcb_format_t *fmt, QImage::Fo m_xcb_image->data = m_shm_info.shmaddr ? m_shm_info.shmaddr : (uint8_t *)malloc(segmentSize); m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); - m_graphics_buffer = new QXcbShmGraphicsBuffer(&m_qimage); + m_graphics_buffer = new QXcbGraphicsBuffer(&m_qimage); m_xcb_pixmap = xcb_generate_id(xcb_connection()); xcb_create_pixmap(xcb_connection(), @@ -242,7 +242,7 @@ void QXcbShmImage::create(const QSize &size, const xcb_format_t *fmt, QImage::Fo m_xcb_image->width, m_xcb_image->height); } -void QXcbShmImage::destroy(bool destroyShm) +void QXcbBackingStoreImage::destroy(bool destroyShm) { if (m_xcb_image->data) { if (m_shm_info.shmaddr) { @@ -268,7 +268,7 @@ void QXcbShmImage::destroy(bool destroyShm) m_xcb_pixmap = 0; } -void QXcbShmImage::flushScrolledRegion(bool clientSideScroll) +void QXcbBackingStoreImage::flushScrolledRegion(bool clientSideScroll) { if (m_clientSideScroll == clientSideScroll) return; @@ -316,7 +316,7 @@ void QXcbShmImage::flushScrolledRegion(bool clientSideScroll) } } -void QXcbShmImage::createShmSegment(size_t segmentSize) +void QXcbBackingStoreImage::createShmSegment(size_t segmentSize) { Q_ASSERT(connection()->hasShm()); Q_ASSERT(m_segmentSize == 0); @@ -400,7 +400,7 @@ void QXcbShmImage::createShmSegment(size_t segmentSize) } } -void QXcbShmImage::destroyShmSegment(size_t segmentSize) +void QXcbBackingStoreImage::destroyShmSegment(size_t segmentSize) { #ifndef XCB_USE_SHM_FD Q_UNUSED(segmentSize) @@ -433,7 +433,7 @@ void QXcbShmImage::destroyShmSegment(size_t segmentSize) extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); -bool QXcbShmImage::scroll(const QRegion &area, int dx, int dy) +bool QXcbBackingStoreImage::scroll(const QRegion &area, int dx, int dy) { const QRect bounds(QPoint(), size()); const QRegion scrollArea(area & bounds); @@ -477,7 +477,7 @@ bool QXcbShmImage::scroll(const QRegion &area, int dx, int dy) return true; } -void QXcbShmImage::ensureGC(xcb_drawable_t dst) +void QXcbBackingStoreImage::ensureGC(xcb_drawable_t dst) { if (m_gc_drawable != dst) { if (m_gc) @@ -557,7 +557,7 @@ static inline quint32 round_up_scanline(quint32 base, quint32 pad) return (base + pad - 1) & -pad; } -void QXcbShmImage::shmPutImage(xcb_drawable_t drawable, const QRegion ®ion, const QPoint &offset) +void QXcbBackingStoreImage::shmPutImage(xcb_drawable_t drawable, const QRegion ®ion, const QPoint &offset) { for (const QRect &rect : region) { const QPoint source = rect.translated(offset).topLeft(); @@ -578,7 +578,7 @@ void QXcbShmImage::shmPutImage(xcb_drawable_t drawable, const QRegion ®ion, c m_dirtyShm |= region.translated(offset); } -void QXcbShmImage::flushPixmap(const QRegion ®ion, bool fullRegion) +void QXcbBackingStoreImage::flushPixmap(const QRegion ®ion, bool fullRegion) { if (!fullRegion) { auto actualRegion = m_pendingFlush.intersected(region); @@ -647,7 +647,7 @@ void QXcbShmImage::flushPixmap(const QRegion ®ion, bool fullRegion) } } -void QXcbShmImage::setClip(const QRegion ®ion) +void QXcbBackingStoreImage::setClip(const QRegion ®ion) { if (region.isEmpty()) { static const uint32_t mask = XCB_GC_CLIP_MASK; @@ -663,7 +663,7 @@ void QXcbShmImage::setClip(const QRegion ®ion) } } -void QXcbShmImage::put(xcb_drawable_t dst, const QRegion ®ion, const QPoint &offset) +void QXcbBackingStoreImage::put(xcb_drawable_t dst, const QRegion ®ion, const QPoint &offset) { Q_ASSERT(!m_clientSideScroll); @@ -704,7 +704,7 @@ void QXcbShmImage::put(xcb_drawable_t dst, const QRegion ®ion, const QPoint & setClip(QRegion()); } -void QXcbShmImage::preparePaint(const QRegion ®ion) +void QXcbBackingStoreImage::preparePaint(const QRegion ®ion) { if (hasShm()) { // to prevent X from reading from the image region while we're writing to it @@ -860,7 +860,7 @@ void QXcbBackingStore::resize(const QSize &size, const QRegion &) m_image->resize(size); } else { QXcbScreen *screen = static_cast(window()->screen()->handle()); - m_image = new QXcbShmImage(screen, size, win->depth(), win->imageFormat()); + m_image = new QXcbBackingStoreImage(screen, size, win->depth(), win->imageFormat()); } // Slow path for bgr888 VNC: Create an additional image, paint into that and diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.h b/src/plugins/platforms/xcb/qxcbbackingstore.h index 2e8fbfb7fa..f40030001b 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.h +++ b/src/plugins/platforms/xcb/qxcbbackingstore.h @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE -class QXcbShmImage; +class QXcbBackingStoreImage; class QXcbBackingStore : public QXcbObject, public QPlatformBackingStore { @@ -75,7 +75,7 @@ public: void endPaint() override; private: - QXcbShmImage *m_image; + QXcbBackingStoreImage *m_image; QStack m_paintRegions; QImage m_rgbImage; }; -- cgit v1.2.3 From 89ab15ac913de09ca46b123776dfb2cdbf84a13b Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Thu, 15 Mar 2018 17:45:02 +0100 Subject: xcb: various coding style cleanups in qxcbbackingstore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pass QXcbBackingStoreImage a pointer to QXcbBackingStore. This allow for simpler QXcbBackingStoreImage ctor. - Use member initializers. Change-Id: Ia992390060bb30e1184813cd0d115a8bf0fbc237 Reviewed-by: Błażej Szczygieł Reviewed-by: Laszlo Agocs --- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 68 ++++++++++++-------------- src/plugins/platforms/xcb/qxcbbackingstore.h | 2 +- 2 files changed, 33 insertions(+), 37 deletions(-) (limited to 'src/plugins/platforms/xcb') diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 6efdb2d834..659d1c53cb 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -70,10 +70,12 @@ QT_BEGIN_NAMESPACE +class QXcbBackingStore; + class QXcbBackingStoreImage : public QXcbObject { public: - QXcbBackingStoreImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); + QXcbBackingStoreImage(QXcbBackingStore *backingStore, const QSize &size); ~QXcbBackingStoreImage() { destroy(true); } void resize(const QSize &size); @@ -105,25 +107,24 @@ private: void flushPixmap(const QRegion ®ion, bool fullRegion = false); void setClip(const QRegion ®ion); - xcb_window_t m_screen_root; - xcb_shm_segment_info_t m_shm_info; - size_t m_segmentSize; + QXcbBackingStore *m_backingStore = nullptr; + size_t m_segmentSize = 0; - xcb_image_t *m_xcb_image; + xcb_image_t *m_xcb_image = nullptr; QImage m_qimage; - QPlatformGraphicsBuffer *m_graphics_buffer; + QPlatformGraphicsBuffer *m_graphics_buffer = nullptr; - xcb_gcontext_t m_gc; - xcb_drawable_t m_gc_drawable; + xcb_gcontext_t m_gc = 0; + xcb_drawable_t m_gc_drawable = 0; // When using shared memory these variables are used only for server-side scrolling. // When not using shared memory, we maintain a server-side pixmap with the backing // store as well as repainted content not yet flushed to the pixmap. We only flush // the regions we need and only when these are marked dirty. This way we can just // do a server-side copy on expose instead of sending the pixels every time - xcb_pixmap_t m_xcb_pixmap; + xcb_pixmap_t m_xcb_pixmap = 0; QRegion m_pendingFlush; // This is the scrolled region which is stored in server-side pixmap @@ -136,8 +137,8 @@ private: // as a pixmap region to server QByteArray m_flushBuffer; - bool m_hasAlpha; - bool m_clientSideScroll; + bool m_hasAlpha = false; + bool m_clientSideScroll = false; }; class QXcbGraphicsBuffer : public QPlatformGraphicsBuffer @@ -145,7 +146,6 @@ class QXcbGraphicsBuffer : public QPlatformGraphicsBuffer public: QXcbGraphicsBuffer(QImage *image) : QPlatformGraphicsBuffer(image->size(), QImage::toPixelFormat(image->format())) - , m_access_lock(QPlatformGraphicsBuffer::None) , m_image(image) { } @@ -165,9 +165,10 @@ public: int bytesPerLine() const override { return m_image->bytesPerLine(); } Origin origin() const override { return QPlatformGraphicsBuffer::OriginTopLeft; } + private: - AccessTypes m_access_lock; - QImage *m_image; + AccessTypes m_access_lock = QPlatformGraphicsBuffer::None; + QImage *m_image = nullptr; }; static inline size_t imageDataSize(const xcb_image_t *image) @@ -175,25 +176,22 @@ static inline size_t imageDataSize(const xcb_image_t *image) return static_cast(image->stride) * image->height; } -QXcbBackingStoreImage::QXcbBackingStoreImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) - : QXcbObject(screen->connection()) - , m_screen_root(screen->screen()->root) - , m_segmentSize(0) - , m_graphics_buffer(nullptr) - , m_gc(0) - , m_gc_drawable(0) - , m_xcb_pixmap(0) - , m_clientSideScroll(false) -{ - const xcb_format_t *fmt = connection()->formatForDepth(depth); +QXcbBackingStoreImage::QXcbBackingStoreImage(QXcbBackingStore *backingStore, const QSize &size) + : QXcbObject(backingStore->connection()) + , m_backingStore(backingStore) +{ + QXcbWindow *window = static_cast(backingStore->window()->handle()); + const xcb_format_t *fmt = connection()->formatForDepth(window->depth()); Q_ASSERT(fmt); + memset(&m_shm_info, 0, sizeof m_shm_info); + + QImage::Format format = window->imageFormat(); m_hasAlpha = QImage::toPixelFormat(format).alphaUsage() == QPixelFormat::UsesAlpha; if (!m_hasAlpha) - format = qt_maybeAlphaVersionWithSameDepth(format); - - memset(&m_shm_info, 0, sizeof m_shm_info); - create(size, fmt, format); + create(size, fmt, qt_maybeAlphaVersionWithSameDepth(format)); + else + create(size, fmt, format); } void QXcbBackingStoreImage::resize(const QSize &size) @@ -235,10 +233,11 @@ void QXcbBackingStoreImage::create(const QSize &size, const xcb_format_t *fmt, Q m_graphics_buffer = new QXcbGraphicsBuffer(&m_qimage); m_xcb_pixmap = xcb_generate_id(xcb_connection()); + auto xcbScreen = static_cast(m_backingStore->window()->screen()->handle()); xcb_create_pixmap(xcb_connection(), m_xcb_image->depth, m_xcb_pixmap, - m_screen_root, + xcbScreen->root(), m_xcb_image->width, m_xcb_image->height); } @@ -719,7 +718,6 @@ void QXcbBackingStoreImage::preparePaint(const QRegion ®ion) QXcbBackingStore::QXcbBackingStore(QWindow *window) : QPlatformBackingStore(window) - , m_image(0) { QXcbScreen *screen = static_cast(window->screen()->handle()); setConnection(screen->connection()); @@ -856,12 +854,10 @@ void QXcbBackingStore::resize(const QSize &size, const QRegion &) } QXcbWindow* win = static_cast(pw); - if (m_image) { + if (m_image) m_image->resize(size); - } else { - QXcbScreen *screen = static_cast(window()->screen()->handle()); - m_image = new QXcbBackingStoreImage(screen, size, win->depth(), win->imageFormat()); - } + else + m_image = new QXcbBackingStoreImage(this, size); // Slow path for bgr888 VNC: Create an additional image, paint into that and // swap R and B while copying to m_image after each paint. diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.h b/src/plugins/platforms/xcb/qxcbbackingstore.h index f40030001b..747626c213 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.h +++ b/src/plugins/platforms/xcb/qxcbbackingstore.h @@ -75,7 +75,7 @@ public: void endPaint() override; private: - QXcbBackingStoreImage *m_image; + QXcbBackingStoreImage *m_image = nullptr; QStack m_paintRegions; QImage m_rgbImage; }; -- cgit v1.2.3