=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-04-22 16:44:54 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-04-22 19:22:27 +0000 @@ -57,6 +57,7 @@ import java.io.*; import java.security.*; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jetty.websocket.api.annotations.WebSocket; @@ -110,11 +111,8 @@ /** Accumulator to track the total number of pending bytes on the drawing ops list. */ private int pendingBytes = 0; - /** Pending resize operations must not be cached */ - private List resizeOps = new ArrayList(); - - /** Pending resize operations in bytes */ - private int resizeOpsBytes = 0; + /** Pending resize operations counter */ + private AtomicInteger resizeOps = new AtomicInteger(0); /** * Accumulator to track the total number of pending bytes on the drawing ops list, including @@ -614,14 +612,7 @@ { allocateAndSend(PaintPrimitives.RESIZE_WINDOW, width, height); - byte[] message = new byte[9]; - message[0] = (byte) PaintPrimitives.RESIZE_WINDOW.ordinal(); - - writeMessageInt32(message, 1, width); - writeMessageInt32(message, 5, height); - - resizeOps.add(message); - resizeOpsBytes += message.length; + resizeOps.incrementAndGet(); } /** @@ -635,6 +626,8 @@ public void setWindowLocation(int x, int y) { allocateAndSend(PaintPrimitives.SET_LOCATION, x, y); + + resizeOps.incrementAndGet(); } /** @@ -653,16 +646,7 @@ { allocateAndSend(PaintPrimitives.SET_WINDOW_BOUNDS, x, y, width, height); - byte[] message = new byte[17]; - message[0] = (byte) PaintPrimitives.SET_WINDOW_BOUNDS.ordinal(); - - writeMessageInt32(message, 1, x); - writeMessageInt32(message, 5, y); - writeMessageInt32(message, 9, width); - writeMessageInt32(message, 13, height); - - resizeOps.add(message); - resizeOpsBytes += message.length; + resizeOps.incrementAndGet(); } /** @@ -1062,7 +1046,12 @@ pendingNoCacheBytes)); if (drawHash != null) { - if (Arrays.equals(drawHash, lastHash)) + if (resizeOps.getAndSet(0) > 0) + { + byte[] magic = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + System.arraycopy(magic, 0, total, 1, HASH_LENGTH); + } + else if (Arrays.equals(drawHash, lastHash)) { // do not send if duplicated message doSend = false; @@ -1099,17 +1088,6 @@ lastHash = drawHash; } - if (!resizeOps.isEmpty()) - { - byte[] resize = buildDrawingMessage(windowId, resizeOps, resizeOpsBytes); - // the magic value indicates that resize operations must not be cached - byte[] magic = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - System.arraycopy(magic, 0, resize, 1, HASH_LENGTH); - sendBinaryMessage(resize); - resizeOps.clear(); - resizeOpsBytes = 0; - } - if (doSend) { // send it to the javascript side