From 810a20622124917792a0ea637fadf3994504c596 Mon Sep 17 00:00:00 2001 From: Erik De Rijcke Date: Tue, 17 Mar 2015 11:50:44 +0100 Subject: properly create & destroy bufferpools --- .../src/main/java/examples/BufferPoolFactory.java | 31 +++++++++++----------- examples/src/main/java/examples/Window.java | 13 ++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/src/main/java/examples/BufferPoolFactory.java b/examples/src/main/java/examples/BufferPoolFactory.java index 40c6366..0b00775 100644 --- a/examples/src/main/java/examples/BufferPoolFactory.java +++ b/examples/src/main/java/examples/BufferPoolFactory.java @@ -15,33 +15,32 @@ public class BufferPoolFactory { this.display = display; } - public WlShmPoolProxy create(int width, int height, int size) throws IOException { - final int bufferSize = width * height * 4; - final ShmPool shmPool = new ShmPool(bufferSize *size); + public BufferPool create(int width, int height, int size, WlShmFormat shmFormat) throws IOException { + final BufferPool bufferPool = new BufferPool(); - final WlShmPoolProxy - wlShmPoolProxy = - this.display.getShmProxy() - .createPool(bufferPool, - shmPool.getFileDescriptor(), - bufferSize * size); for(int i = 0; i < size; i++){ - final int offset = i * bufferSize; - final ByteBuffer poolByteBuffer = shmPool.asByteBuffer(); - poolByteBuffer.position(offset); - final ByteBuffer byteBuffer = poolByteBuffer.slice(); + final int bufferSize = width * height * 4; + final ShmPool shmPool = new ShmPool(bufferSize); + final WlShmPoolProxy + wlShmPoolProxy = + this.display.getShmProxy() + .createPool(bufferPool, + shmPool.getFileDescriptor(), + bufferSize); + final ByteBuffer byteBuffer = shmPool.asByteBuffer(); final WlBufferProxy buffer = wlShmPoolProxy.createBuffer(new Buffer(bufferPool, byteBuffer, width, height), - offset, + 0, width, height, width * 4, - WlShmFormat.XRGB8888.getValue()); + shmFormat.getValue()); bufferPool.queueBuffer(buffer); + wlShmPoolProxy.destroy(); } - return wlShmPoolProxy; + return bufferPool; } } diff --git a/examples/src/main/java/examples/Window.java b/examples/src/main/java/examples/Window.java index d137318..57ba108 100644 --- a/examples/src/main/java/examples/Window.java +++ b/examples/src/main/java/examples/Window.java @@ -16,12 +16,15 @@ package examples; import org.freedesktop.wayland.client.*; import org.freedesktop.wayland.shared.WlPointerButtonState; import org.freedesktop.wayland.shared.WlShellSurfaceResize; +import org.freedesktop.wayland.shared.WlShmFormat; import org.freedesktop.wayland.util.Fixed; import javax.annotation.Nonnull; import java.io.IOException; import java.nio.IntBuffer; +import static org.freedesktop.wayland.shared.WlShmFormat.XRGB8888; + public class Window { private final WlShellSurfaceProxy shellSurface; @@ -156,12 +159,10 @@ public class Window { } private BufferPool createBufferPool(Display display, int width, int height, int size) throws IOException { - final WlShmPoolProxy wlShmPoolProxy = new BufferPoolFactory(display).create(width, - height, - 2); - final BufferPool bufferPool = (BufferPool) wlShmPoolProxy.getImplementation(); - wlShmPoolProxy.destroy(); - return bufferPool; + return new BufferPoolFactory(display).create(width, + height, + 2, + XRGB8888); } public void destroy() { -- cgit v1.2.3