Mercurial > hg > Applications > TreeVNC
diff src/main/java/com/glavsoft/rfb/protocol/Protocol.java @ 57:17b702648079
version2.7.2 original version.
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Dec 2013 18:04:03 +0900 |
parents | 4689cc86d6cb |
children | 433c79184c05 |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Tue Jul 03 13:20:49 2012 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Sun Dec 15 18:04:03 2013 +0900 @@ -1,4 +1,4 @@ -// Copyright (C) 2010, 2011 GlavSoft LLC. +// Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. // All rights reserved. // //------------------------------------------------------------------------- @@ -42,7 +42,7 @@ public class Protocol implements ProtocolContext, IChangeSettingsListener { private ProtocolState state; - private final Logger logger = Logger.getLogger("com.glavsoft.rfb.protocol"); + private final Logger logger; private final IPasswordRetriever passwordRetriever; private final ProtocolSettings settings; private int fbWidth; @@ -50,7 +50,7 @@ private PixelFormat pixelFormat; private final Reader reader; private final Writer writer; - private String remoteDesctopName; + private String remoteDesktopName; private MessageQueue messageQueue; private final DecodersContainer decoders; private SenderTask senderTask; @@ -60,8 +60,10 @@ private PixelFormat serverPixelFormat; private Thread senderThread; private Thread receiverThread; + private boolean isTight; + private String protocolVersion; - public Protocol(Reader reader, Writer writer, + public Protocol(Reader reader, Writer writer, IPasswordRetriever passwordRetriever, ProtocolSettings settings) { this.reader = reader; this.writer = writer; @@ -70,7 +72,8 @@ decoders = new DecodersContainer(); decoders.instantiateDecodersWhenNeeded(settings.encodings); state = new HandshakeState(this); - } + logger = Logger.getLogger(getClass().getName()); + } @Override public void changeStateTo(ProtocolState state) { @@ -80,7 +83,7 @@ public void handshake() throws UnsupportedProtocolVersionException, UnsupportedSecurityTypeException, AuthenticationFailedException, TransportException, FatalException { while (state.next()) { - continue; + // continue; } this.messageQueue = new MessageQueue(); } @@ -100,12 +103,12 @@ @Override public String getRemoteDesktopName() { - return remoteDesctopName; + return remoteDesktopName; } @Override public void setRemoteDesktopName(String name) { - remoteDesctopName = name; + remoteDesktopName = name; } @Override @@ -138,12 +141,7 @@ return settings; } - @Override - public Logger getLogger() { - return logger; - } - - @Override + @Override public Writer getWriter() { return writer; } @@ -169,14 +167,14 @@ IRepaintController repaintController, ClipboardController clipboardController) { this.rfbSessionListener = rfbSessionListener; this.repaintController = repaintController; -// if (settings.getBitsPerPixel() == 0) { -// settings.setBitsPerPixel(pixelFormat.bitsPerPixel); // the same the server sent when not initialized yet +// if (settings.getColorDepth() == 0) { +// settings.setColorDepth(pixelFormat.depth); // the same the server sent when not initialized yet // } serverPixelFormat = pixelFormat; - serverPixelFormat.trueColourFlag = 1; // correct flag - we don't support color maps + correctServerPixelFormat(); setPixelFormat(createPixelFormat(settings)); sendMessage(new SetPixelFormatMessage(pixelFormat)); - logger.fine("sent: "+pixelFormat); + logger.fine("sent: " + pixelFormat); sendSupportedEncodingsMessage(settings); settings.addListener(this); // to support pixel format (color depth), and encodings changes @@ -184,18 +182,33 @@ sendRefreshMessage(); senderTask = new SenderTask(messageQueue, writer, this); - senderThread = new Thread(senderTask); + senderThread = new Thread(senderTask, "RfbSenderTask"); senderThread.start(); decoders.resetDecoders(); receiverTask = new ReceiverTask( reader, repaintController, clipboardController, decoders, this); - receiverThread = new Thread(receiverTask); + receiverThread = new Thread(receiverTask, "RfbReceiverTask"); receiverThread.start(); } - @Override + private void correctServerPixelFormat() { + // correct true color flag - we don't support color maps, so always set it up + serverPixelFormat.trueColourFlag = 1; + // correct .depth to use actual depth 24 instead of incorrect 32, used by ex. UltraVNC server, that cause + // protocol incompatibility in ZRLE encoding + final long significant = serverPixelFormat.redMax << serverPixelFormat.redShift | + serverPixelFormat.greenMax << serverPixelFormat.greenShift | + serverPixelFormat.blueMax << serverPixelFormat.blueShift; + if (32 == serverPixelFormat.bitsPerPixel && + ((significant & 0x00ff000000L) == 0 || (significant & 0x000000ffL) == 0) && + 32 == serverPixelFormat.depth) { + serverPixelFormat.depth = 24; + } + } + + @Override public void sendMessage(ClientToServerMessage message) { messageQueue.put(message); } @@ -212,22 +225,22 @@ */ private PixelFormat createPixelFormat(ProtocolSettings settings) { int serverBigEndianFlag = serverPixelFormat.bigEndianFlag; - switch (settings.getBitsPerPixel()) { - case ProtocolSettings.BPP_32: - return PixelFormat.create32bppPixelFormat(serverBigEndianFlag); - case ProtocolSettings.BPP_16: - return PixelFormat.create16bppPixelFormat(serverBigEndianFlag); - case ProtocolSettings.BPP_8: - return PixelFormat.create8bppBGRPixelFormat(serverBigEndianFlag); - case ProtocolSettings.BPP_6: - return PixelFormat.create6bppPixelFormat(serverBigEndianFlag); - case ProtocolSettings.BPP_3: + switch (settings.getColorDepth()) { + case ProtocolSettings.COLOR_DEPTH_24: + return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_16: + return PixelFormat.create16bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_8: + return PixelFormat.create8bitColorDepthBGRPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_6: + return PixelFormat.create6bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_3: return PixelFormat.create3bppPixelFormat(serverBigEndianFlag); - case ProtocolSettings.BPP_SERVER_SETTINGS: + case ProtocolSettings.COLOR_DEPTH_SERVER_SETTINGS: return serverPixelFormat; default: // unsupported bpp, use default - return PixelFormat.create32bppPixelFormat(serverBigEndianFlag); + return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); } } @@ -237,7 +250,7 @@ if (settings.isChangedEncodings()) { sendSupportedEncodingsMessage(settings); } - if (settings.changedBitsPerPixel() && receiverTask != null) { + if (settings.isChangedColorDepth() && receiverTask != null) { receiverTask.queueUpdatePixelFormat(createPixelFormat(settings)); } } @@ -275,4 +288,24 @@ } } + @Override + public void setTight(boolean isTight) { + this.isTight = isTight; + } + + @Override + public boolean isTight() { + return isTight; + } + + @Override + public void setProtocolVersion(String protocolVersion) { + this.protocolVersion = protocolVersion; + } + + @Override + public String getProtocolVersion() { + return protocolVersion; + } + }