Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +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 | */ |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 19 | #include <rdr/InStream.h> |
| 20 | #include <rdr/OutStream.h> |
| 21 | #include <rfb/Exception.h> |
| 22 | #include <rfb/encodings.h> |
| 23 | #include <rfb/Encoder.h> |
| 24 | #include <rfb/ConnParams.h> |
| 25 | #include <rfb/util.h> |
| 26 | |
| 27 | using namespace rfb; |
| 28 | |
| 29 | ConnParams::ConnParams() |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 30 | : majorVersion(0), minorVersion(0), tightExtensionsEnabled(false), |
| 31 | width(0), height(0), useCopyRect(false), |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 32 | supportsLocalCursor(false), supportsLocalXCursor(false), |
| 33 | supportsDesktopResize(false), supportsExtendedDesktopSize(false), |
| 34 | supportsDesktopRename(false), supportsLastRect(false), |
| 35 | customCompressLevel(false), compressLevel(6), |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | noJpeg(false), qualityLevel(-1), |
| 37 | name_(0), nEncodings_(0), encodings_(0), |
| 38 | currentEncoding_(encodingRaw), verStrPos(0) |
| 39 | { |
| 40 | setName(""); |
| 41 | } |
| 42 | |
| 43 | ConnParams::~ConnParams() |
| 44 | { |
| 45 | delete [] name_; |
| 46 | delete [] encodings_; |
| 47 | } |
| 48 | |
| 49 | bool ConnParams::readVersion(rdr::InStream* is, bool* done) |
| 50 | { |
| 51 | if (verStrPos >= 12) return false; |
| 52 | while (is->checkNoWait(1) && verStrPos < 12) { |
| 53 | verStr[verStrPos++] = is->readU8(); |
| 54 | } |
| 55 | |
| 56 | if (verStrPos < 12) { |
| 57 | *done = false; |
| 58 | return true; |
| 59 | } |
| 60 | *done = true; |
| 61 | verStr[12] = 0; |
| 62 | return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2); |
| 63 | } |
| 64 | |
| 65 | void ConnParams::writeVersion(rdr::OutStream* os) |
| 66 | { |
| 67 | char str[13]; |
| 68 | sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion); |
| 69 | os->writeBytes(str, 12); |
| 70 | os->flush(); |
| 71 | } |
| 72 | |
| 73 | void ConnParams::setPF(const PixelFormat& pf) |
| 74 | { |
| 75 | pf_ = pf; |
| 76 | |
| 77 | if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) |
| 78 | throw Exception("setPF: not 8, 16 or 32 bpp?"); |
| 79 | } |
| 80 | |
| 81 | void ConnParams::setName(const char* name) |
| 82 | { |
| 83 | delete [] name_; |
| 84 | name_ = strDup(name); |
| 85 | } |
| 86 | |
| 87 | void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings) |
| 88 | { |
| 89 | if (nEncodings > nEncodings_) { |
| 90 | delete [] encodings_; |
| 91 | encodings_ = new rdr::U32[nEncodings]; |
| 92 | } |
| 93 | nEncodings_ = nEncodings; |
| 94 | useCopyRect = false; |
| 95 | supportsLocalCursor = false; |
| 96 | supportsDesktopResize = false; |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 97 | supportsExtendedDesktopSize = false; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 98 | supportsLocalXCursor = false; |
| 99 | supportsLastRect = false; |
| 100 | customCompressLevel = false; |
| 101 | compressLevel = -1; |
| 102 | noJpeg = true; |
| 103 | qualityLevel = -1; |
| 104 | currentEncoding_ = encodingRaw; |
| 105 | |
| 106 | for (int i = nEncodings-1; i >= 0; i--) { |
| 107 | encodings_[i] = encodings[i]; |
| 108 | |
| 109 | if (encodings[i] == encodingCopyRect) |
| 110 | useCopyRect = true; |
| 111 | else if (encodings[i] == pseudoEncodingCursor) |
| 112 | supportsLocalCursor = true; |
| 113 | else if (encodings[i] == pseudoEncodingXCursor) |
| 114 | supportsLocalXCursor = true; |
| 115 | else if (encodings[i] == pseudoEncodingDesktopSize) |
| 116 | supportsDesktopResize = true; |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 117 | else if (encodings[i] == pseudoEncodingExtendedDesktopSize) |
| 118 | supportsExtendedDesktopSize = true; |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 119 | else if (encodings[i] == pseudoEncodingDesktopName) |
| 120 | supportsDesktopRename = true; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 121 | else if (encodings[i] == pseudoEncodingLastRect) |
| 122 | supportsLastRect = true; |
| 123 | else if (encodings[i] >= pseudoEncodingCompressLevel0 && |
| 124 | encodings[i] <= pseudoEncodingCompressLevel9) { |
| 125 | customCompressLevel = true; |
| 126 | compressLevel = encodings[i] - pseudoEncodingCompressLevel0; |
| 127 | } else if (encodings[i] >= pseudoEncodingQualityLevel0 && |
| 128 | encodings[i] <= pseudoEncodingQualityLevel9) { |
| 129 | noJpeg = false; |
| 130 | qualityLevel = encodings[i] - pseudoEncodingQualityLevel0; |
| 131 | } else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i])) |
| 132 | currentEncoding_ = encodings[i]; |
| 133 | } |
| 134 | } |