DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | package com.tigervnc.rfb; |
| 20 | |
| 21 | import com.tigervnc.rdr.*; |
| 22 | |
| 23 | public class CMsgReaderV3 extends CMsgReader { |
| 24 | |
| 25 | public CMsgReaderV3(CMsgHandler handler_, InStream is_) |
| 26 | { |
| 27 | super(handler_, is_); |
| 28 | nUpdateRectsLeft = 0; |
| 29 | } |
| 30 | |
| 31 | public void readServerInit() |
| 32 | { |
| 33 | int width = is.readU16(); |
| 34 | int height = is.readU16(); |
| 35 | handler.setDesktopSize(width, height); |
| 36 | PixelFormat pf = new PixelFormat(); |
| 37 | pf.read(is); |
| 38 | handler.setPixelFormat(pf); |
| 39 | String name = is.readString(); |
| 40 | handler.setName(name); |
| 41 | handler.serverInit(); |
| 42 | } |
| 43 | |
| 44 | public void readMsg() |
| 45 | { |
| 46 | if (nUpdateRectsLeft == 0) { |
| 47 | |
| 48 | int type = is.readU8(); |
| 49 | switch (type) { |
| 50 | case MsgTypes.msgTypeFramebufferUpdate: readFramebufferUpdate(); break; |
| 51 | case MsgTypes.msgTypeSetColourMapEntries: readSetColourMapEntries(); break; |
| 52 | case MsgTypes.msgTypeBell: readBell(); break; |
| 53 | case MsgTypes.msgTypeServerCutText: readServerCutText(); break; |
| 54 | default: |
| 55 | vlog.error("unknown message type "+type); |
| 56 | throw new Exception("unknown message type"); |
| 57 | } |
| 58 | |
| 59 | } else { |
| 60 | |
| 61 | int x = is.readU16(); |
| 62 | int y = is.readU16(); |
| 63 | int w = is.readU16(); |
| 64 | int h = is.readU16(); |
| 65 | int encoding = is.readU32(); |
| 66 | |
| 67 | switch (encoding) { |
| 68 | case Encodings.pseudoEncodingDesktopSize: |
| 69 | handler.setDesktopSize(w, h); |
| 70 | break; |
| 71 | case Encodings.pseudoEncodingExtendedDesktopSize: |
| 72 | readExtendedDesktopSize(x, y, w, h); |
| 73 | break; |
| 74 | case Encodings.pseudoEncodingDesktopName: |
| 75 | readSetDesktopName(x, y, w, h); |
| 76 | break; |
| 77 | case Encodings.pseudoEncodingCursor: |
| 78 | readSetCursor(w, h, new Point(x,y)); |
| 79 | break; |
| 80 | case Encodings.pseudoEncodingLastRect: |
| 81 | nUpdateRectsLeft = 1; // this rectangle is the last one |
| 82 | break; |
| 83 | default: |
| 84 | readRect(new Rect(x, y, x+w, y+h), encoding); |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | nUpdateRectsLeft--; |
| 89 | if (nUpdateRectsLeft == 0) handler.framebufferUpdateEnd(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void readFramebufferUpdate() |
| 94 | { |
| 95 | is.skip(1); |
| 96 | nUpdateRectsLeft = is.readU16(); |
| 97 | handler.framebufferUpdateStart(); |
| 98 | } |
| 99 | |
| 100 | void readSetDesktopName(int x, int y, int w, int h) |
| 101 | { |
| 102 | String name = is.readString(); |
| 103 | |
| 104 | if (x != 0 || y != 0 || w != 0 || h != 0) { |
| 105 | vlog.error("Ignoring DesktopName rect with non-zero position/size"); |
| 106 | } else { |
| 107 | handler.setName(name); |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | |
| 112 | void readExtendedDesktopSize(int x, int y, int w, int h) |
| 113 | { |
| 114 | int screens, i; |
| 115 | int id, flags; |
| 116 | int sx, sy, sw, sh; |
| 117 | ScreenSet layout = new ScreenSet(); |
| 118 | |
| 119 | screens = is.readU8(); |
| 120 | is.skip(3); |
| 121 | |
| 122 | for (i = 0;i < screens;i++) { |
| 123 | id = is.readU32(); |
| 124 | sx = is.readU16(); |
| 125 | sy = is.readU16(); |
| 126 | sw = is.readU16(); |
| 127 | sh = is.readU16(); |
| 128 | flags = is.readU32(); |
| 129 | |
| 130 | layout.add_screen(new Screen(id, sx, sy, sw, sh, flags)); |
| 131 | } |
| 132 | |
| 133 | handler.setExtendedDesktopSize(x, y, w, h, layout); |
| 134 | } |
| 135 | |
| 136 | int nUpdateRectsLeft; |
| 137 | |
| 138 | static LogWriter vlog = new LogWriter("CMsgReaderV3"); |
| 139 | } |