diff options
author | Erik De Rijcke <Erik.De.Rijcke@prodatamobility.com> | 2015-03-17 11:50:44 +0100 |
---|---|---|
committer | Erik De Rijcke <Erik.De.Rijcke@prodatamobility.com> | 2015-03-17 11:50:44 +0100 |
commit | 810a20622124917792a0ea637fadf3994504c596 (patch) | |
tree | 2e571b4bddf82fc793ab8245f7b9f410b7e5d0b5 | |
parent | 9f46e5503938060059b9cdd8aa3276097f058d5b (diff) |
properly create & destroy bufferpools
-rw-r--r-- | examples/src/main/java/examples/BufferPoolFactory.java | 31 | ||||
-rw-r--r-- | 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() { |