diff src/main/java/com/glavsoft/rfb/protocol/Protocol.java @ 59:433c79184c05

merge version2.7.2
author Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Dec 2013 20:16:48 +0900
parents 17b702648079 913d0f663e74
children ac6f9e46566f
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java	Mon Dec 16 17:06:19 2013 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java	Tue Dec 17 20:16:48 2013 +0900
@@ -37,9 +37,15 @@
 import com.glavsoft.rfb.protocol.state.ProtocolState;
 import com.glavsoft.transport.Reader;
 import com.glavsoft.transport.Writer;
+import com.glavsoft.viewer.swing.ClipboardControllerImpl;
+import com.glavsoft.viewer.swing.Surface;
 
 import java.util.logging.Logger;
 
+import jp.ac.u_ryukyu.treevnc.MyRfbProto;
+import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy;
+import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
+
 public class Protocol implements ProtocolContext, IChangeSettingsListener {
 	private ProtocolState state;
 	private final Logger logger;
@@ -60,8 +66,10 @@
 	private PixelFormat serverPixelFormat;
 	private Thread senderThread;
 	private Thread receiverThread;
-    private boolean isTight;
-    private String protocolVersion;
+        private boolean isTight;
+        private String protocolVersion;
+	private byte[] initData;
+	private boolean isRetina = false;
 
     public Protocol(Reader reader, Writer writer,
 			IPasswordRetriever passwordRetriever, ProtocolSettings settings) {
@@ -87,7 +95,7 @@
 		}
 		this.messageQueue = new MessageQueue();
 	}
-
+	
 	@Override
 	public PixelFormat getPixelFormat() {
 		return pixelFormat;
@@ -118,7 +126,8 @@
 
 	@Override
 	public void setFbWidth(int fbWidth) {
-		this.fbWidth = fbWidth;
+		if(!isRetina)
+			this.fbWidth = fbWidth;
 	}
 
 	@Override
@@ -126,9 +135,20 @@
 		return fbHeight;
 	}
 
+	@Override 
+	public byte[] getInitData() {
+		return initData;
+	}
+	
+	@Override
+	public void setInitData(byte[] initData) {
+		this.initData = initData;
+	}
+	
 	@Override
 	public void setFbHeight(int fbHeight) {
-		this.fbHeight = fbHeight;
+		if(!isRetina)
+			this.fbHeight = fbHeight;
 	}
 
 	@Override
@@ -179,7 +199,6 @@
 		sendSupportedEncodingsMessage(settings);
 		settings.addListener(this); // to support pixel format (color depth), and encodings changes
 		settings.addListener(repaintController);
-
 		sendRefreshMessage();
 		senderTask = new SenderTask(messageQueue, writer, this);
 		senderThread = new Thread(senderTask, "RfbSenderTask");
@@ -308,4 +327,72 @@
         return protocolVersion;
     }
 
+	public void startNormalHandling(VncProxyService vncProxyService,
+			Surface surface, ClipboardControllerImpl clipboardController,
+			MyRfbProtoProxy rfb) 
+	{
+		this.rfbSessionListener = vncProxyService;
+		this.repaintController = surface;
+//		if (settings.getBitsPerPixel() == 0) {
+//			settings.setBitsPerPixel(pixelFormat.bitsPerPixel); // the same the server sent when not initialized yet
+//		}
+		serverPixelFormat = pixelFormat;
+		serverPixelFormat.trueColourFlag = 1; // correct flag - we don't support color maps
+		setPixelFormat(createPixelFormat(settings));
+		sendMessage(new SetPixelFormatMessage(pixelFormat));
+		logger.fine("sent: "+pixelFormat);
+
+		sendSupportedEncodingsMessage(settings);
+		settings.addListener(this); // to support pixel format (color depth), and encodings changes
+		settings.addListener(surface);
+		sendRefreshMessage();
+		senderTask = new SenderTask(messageQueue, writer, this);
+		senderThread = new Thread(senderTask);
+		senderThread.start();
+		decoders.resetDecoders();
+		receiverTask = new TreeTask(
+				reader, repaintController,
+				clipboardController,
+				decoders, this, rfb);
+		receiverThread = new Thread(receiverTask);
+		receiverThread.start();
+	}
+
+	
+	public void startTreeClientHandling(IRfbSessionListener rfbSessionListener,
+			IRepaintController repaintController, 
+			ClipboardController clipboardController, MyRfbProto rfb) {
+		this.rfbSessionListener = rfbSessionListener;
+		this.repaintController = repaintController;
+//		if (settings.getBitsPerPixel() == 0) {
+//			settings.setBitsPerPixel(pixelFormat.bitsPerPixel); // the same the server sent when not initialized yet
+//		}
+		serverPixelFormat = pixelFormat;
+		serverPixelFormat.trueColourFlag = 1; // correct flag - we don't support color maps
+		setPixelFormat(createPixelFormat(settings));
+		sendMessage(new SetPixelFormatMessage(pixelFormat));
+		logger.fine("sent: "+pixelFormat);
+
+		sendSupportedEncodingsMessage(settings);
+		settings.addListener(this); // to support pixel format (color depth), and encodings changes
+		settings.addListener(repaintController);
+
+		sendRefreshMessage();
+		senderTask = new SenderTask(messageQueue, writer, this);
+		senderThread = new Thread(senderTask);
+		senderThread.start();
+		decoders.resetDecoders();
+		receiverTask = new TreeTask(
+				reader, repaintController,
+				clipboardController,
+				decoders, this, rfb);
+		receiverThread = new Thread(receiverTask);
+		receiverThread.start();
+	}
+	
+	public void setScreenSizeRetina(int fbWidth, int fbHeight) {
+		isRetina = true;
+		this.fbWidth = fbWidth;
+		this.fbHeight = fbHeight;
+	}
 }