From c79a2be17d59530931e105b18edf7a8bab056862 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B8rgen=20Lind?= Date: Tue, 24 Apr 2012 14:25:36 +0200 Subject: [PATCH] Make SurfaceBuffer::handle return something sensible MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit take 2 Change-Id: I4acd03e8e1cb5d77c877ce49d5b9256c94aeb310 Reviewed-by: Andy Nichols Reviewed-by: Jørgen Lind --- src/compositor/wayland_wrapper/wlsurfacebuffer.cpp | 37 +++++++++++++++++++--- src/compositor/wayland_wrapper/wlsurfacebuffer.h | 4 ++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp index a729eb0..43b741f 100644 --- a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp +++ b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp @@ -62,6 +62,8 @@ SurfaceBuffer::SurfaceBuffer(Surface *surface) , m_page_flipper_has_buffer(false) , m_is_displayed(false) , m_texture(0) + , m_is_shm_resolved(false) + , m_is_shm(false) { } @@ -80,6 +82,9 @@ void SurfaceBuffer::initialize(wl_buffer *buffer) m_page_flipper_has_buffer = false; m_is_displayed = false; m_destroyed = false; + m_handle = 0; + m_is_shm_resolved = false; + m_is_shm = false; m_destroy_listener.surfaceBuffer = this; m_destroy_listener.listener.notify = destroy_listener_callback; if (buffer) @@ -90,20 +95,37 @@ void SurfaceBuffer::initialize(wl_buffer *buffer) void SurfaceBuffer::destructBufferState() { Q_ASSERT(!m_page_flipper_has_buffer); - if (m_handle) { - GraphicsHardwareIntegration *hwIntegration = m_compositor->graphicsHWIntegration(); - hwIntegration->unlockNativeBuffer(m_handle, m_compositor->directRenderContext()); - } + destroyTexture(); + if (m_buffer) { + if (m_handle) { + if (m_is_shm) { + delete static_cast(m_handle); + } else { + GraphicsHardwareIntegration *hwIntegration = m_compositor->graphicsHWIntegration(); + hwIntegration->unlockNativeBuffer(m_handle, m_compositor->directRenderContext()); + } + } wl_list_remove(&m_destroy_listener.listener.link); sendRelease(); } m_buffer = 0; + m_handle = 0; m_is_registered_for_buffer = false; m_is_displayed = false; } +bool SurfaceBuffer::isShmBuffer() const +{ + if (!m_is_shm_resolved) { + SurfaceBuffer *that = const_cast(this); + that->m_is_shm = wl_buffer_is_shm(m_buffer); + that->m_is_shm_resolved = true; + } + return m_is_shm; +} + void SurfaceBuffer::sendRelease() { Q_ASSERT(m_buffer); @@ -179,7 +201,12 @@ void *SurfaceBuffer::handle() const GraphicsHardwareIntegration *hwIntegration = m_compositor->graphicsHWIntegration(); SurfaceBuffer *that = const_cast(this); if (isShmBuffer()) { - that->m_handle = wl_shm_buffer_get_data(m_buffer); + const uchar *data = static_cast(wl_shm_buffer_get_data(m_buffer)); + int stride = wl_shm_buffer_get_stride(m_buffer); + int width = m_buffer->width; + int height = m_buffer->height; + QImage *image = new QImage(data,width,height,stride, QImage::Format_ARGB32_Premultiplied); + that->m_handle = image; } else { that->m_handle = hwIntegration->lockNativeBuffer(m_buffer, m_compositor->directRenderContext()); } diff --git a/src/compositor/wayland_wrapper/wlsurfacebuffer.h b/src/compositor/wayland_wrapper/wlsurfacebuffer.h index 44e32e6..fd01aff 100644 --- a/src/compositor/wayland_wrapper/wlsurfacebuffer.h +++ b/src/compositor/wayland_wrapper/wlsurfacebuffer.h @@ -74,7 +74,7 @@ public: inline int32_t width() const { return m_buffer->width; } inline int32_t height() const { return m_buffer->height; } - inline bool isShmBuffer() const { return wl_buffer_is_shm(m_buffer); } + bool isShmBuffer() const; inline bool isRegisteredWithBuffer() const { return m_is_registered_for_buffer; } @@ -121,6 +121,8 @@ private: uint m_texture; #endif void *m_handle; + bool m_is_shm_resolved; + bool m_is_shm; static void destroy_listener_callback(wl_listener *listener, void *data); }; -- 2.7.4