diff options
author | Jørgen Lind <jorgen.lind@digia.com> | 2014-08-14 15:47:55 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar@sletta.org> | 2015-01-17 08:03:34 +0100 |
commit | 37956e6605dd5d5a714607a7e04217d293d9c25f (patch) | |
tree | 90651bfa41d2885f3d876cca382522d3dfbe46ff /src/plugins/platforms/xcb | |
parent | 517fb9026896f7ac20376f253babae5a7c57721d (diff) |
Introducing QPlatformGraphicsBuffer
Change-Id: Idcf8f75bd151a877c7097b79df998c1ffd56871c
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbbackingstore.cpp | 43 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbbackingstore.h | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 5c200b4058..74d73d7cdf 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -49,6 +49,7 @@ #include <qdebug.h> #include <qpainter.h> #include <qscreen.h> +#include <qpa/qplatformgraphicsbuffer.h> #include <algorithm> QT_BEGIN_NAMESPACE @@ -60,6 +61,8 @@ public: ~QXcbShmImage() { destroy(); } QImage *image() { return &m_qimage; } + QPlatformGraphicsBuffer *graphicsBuffer() { return m_graphics_buffer; } + QSize size() const { return m_qimage.size(); } void put(xcb_window_t window, const QPoint &dst, const QRect &source); @@ -73,6 +76,7 @@ private: xcb_image_t *m_xcb_image; QImage m_qimage; + QPlatformGraphicsBuffer *m_graphics_buffer; xcb_gcontext_t m_gc; xcb_window_t m_gc_window; @@ -80,8 +84,39 @@ private: QRegion m_dirty; }; +class QXcbShmGraphicsBuffer : public QPlatformGraphicsBuffer +{ +public: + QXcbShmGraphicsBuffer(QImage *image) + : QPlatformGraphicsBuffer(image->size(), QImage::toPixelFormat(image->format())) + , m_access_lock(QPlatformGraphicsBuffer::None) + , m_image(image) + { } + + bool doLock(AccessTypes access, const QRect &rect) Q_DECL_OVERRIDE + { + Q_UNUSED(rect); + if (access & ~(QPlatformGraphicsBuffer::SWReadAccess | QPlatformGraphicsBuffer::SWWriteAccess)) + return false; + + m_access_lock |= access; + return true; + } + void doUnlock() Q_DECL_OVERRIDE { m_access_lock = None; } + + const uchar *data() const Q_DECL_OVERRIDE { return m_image->bits(); } + uchar *data() Q_DECL_OVERRIDE { return m_image->bits(); } + int bytesPerLine() const Q_DECL_OVERRIDE { return m_image->bytesPerLine(); } + + Origin origin() const Q_DECL_OVERRIDE { return QPlatformGraphicsBuffer::OriginTopLeft; } +private: + AccessTypes m_access_lock; + QImage *m_image; +}; + QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) : QXcbObject(screen->connection()) + , m_graphics_buffer(Q_NULLPTR) , m_gc(0) , m_gc_window(0) { @@ -137,6 +172,7 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI } 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); } void QXcbShmImage::destroy() @@ -158,6 +194,8 @@ void QXcbShmImage::destroy() if (m_gc) Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); + delete m_graphics_buffer; + m_graphics_buffer = Q_NULLPTR; } void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source) @@ -294,6 +332,11 @@ QImage QXcbBackingStore::toImage() const } #endif +QPlatformGraphicsBuffer *QXcbBackingStore::graphicsBuffer() const +{ + return m_image ? m_image->graphicsBuffer() : Q_NULLPTR; +} + void QXcbBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) { if (!m_image || m_image->size().isEmpty()) diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.h b/src/plugins/platforms/xcb/qxcbbackingstore.h index 3a7e124b3f..aa2c953983 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.h +++ b/src/plugins/platforms/xcb/qxcbbackingstore.h @@ -58,6 +58,9 @@ public: bool translucentBackground) Q_DECL_OVERRIDE; QImage toImage() const Q_DECL_OVERRIDE; #endif + + QPlatformGraphicsBuffer *graphicsBuffer() const Q_DECL_OVERRIDE; + void resize(const QSize &size, const QRegion &staticContents) Q_DECL_OVERRIDE; bool scroll(const QRegion &area, int dx, int dy) Q_DECL_OVERRIDE; |