Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2003 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 | #include <rdr/InStream.h> |
| 19 | #include <rdr/OutStream.h> |
| 20 | #include <rfb/Exception.h> |
| 21 | #include <rfb/encodings.h> |
| 22 | #include <rfb/Encoder.h> |
| 23 | #include <rfb/ConnParams.h> |
| 24 | #include <rfb/util.h> |
| 25 | |
| 26 | using namespace rfb; |
| 27 | |
| 28 | ConnParams::ConnParams() |
| 29 | : majorVersion(0), minorVersion(0), width(0), height(0), useCopyRect(false), |
| 30 | supportsLocalCursor(false), supportsDesktopResize(false), |
Peter Åstrand | 462753d | 2004-11-16 15:23:25 +0000 | [diff] [blame^] | 31 | supportsLastRect(false), qualityLevel(-1), |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 32 | name_(0), nEncodings_(0), encodings_(0), |
| 33 | currentEncoding_(encodingRaw), verStrPos(0) |
| 34 | { |
| 35 | setName(""); |
| 36 | } |
| 37 | |
| 38 | ConnParams::~ConnParams() |
| 39 | { |
| 40 | delete [] name_; |
| 41 | delete [] encodings_; |
| 42 | } |
| 43 | |
| 44 | bool ConnParams::readVersion(rdr::InStream* is, bool* done) |
| 45 | { |
| 46 | if (verStrPos >= 12) return false; |
| 47 | while (is->checkNoWait(1) && verStrPos < 12) { |
| 48 | verStr[verStrPos++] = is->readU8(); |
| 49 | } |
| 50 | |
| 51 | if (verStrPos < 12) { |
| 52 | *done = false; |
| 53 | return true; |
| 54 | } |
| 55 | *done = true; |
| 56 | verStr[12] = 0; |
| 57 | return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2); |
| 58 | } |
| 59 | |
| 60 | void ConnParams::writeVersion(rdr::OutStream* os) |
| 61 | { |
| 62 | char str[13]; |
| 63 | sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion); |
| 64 | os->writeBytes(str, 12); |
| 65 | os->flush(); |
| 66 | } |
| 67 | |
| 68 | void ConnParams::setPF(const PixelFormat& pf) |
| 69 | { |
| 70 | pf_ = pf; |
| 71 | |
| 72 | if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) |
| 73 | throw Exception("setPF: not 8, 16 or 32 bpp?"); |
| 74 | } |
| 75 | |
| 76 | void ConnParams::setName(const char* name) |
| 77 | { |
| 78 | delete [] name_; |
| 79 | name_ = strDup(name); |
| 80 | } |
| 81 | |
| 82 | void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings) |
| 83 | { |
| 84 | if (nEncodings > nEncodings_) { |
| 85 | delete [] encodings_; |
| 86 | encodings_ = new rdr::U32[nEncodings]; |
| 87 | } |
| 88 | nEncodings_ = nEncodings; |
| 89 | useCopyRect = false; |
| 90 | supportsLocalCursor = false; |
Peter Åstrand | 462753d | 2004-11-16 15:23:25 +0000 | [diff] [blame^] | 91 | supportsLastRect = false; |
| 92 | qualityLevel = -1; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 93 | currentEncoding_ = encodingRaw; |
| 94 | |
| 95 | for (int i = nEncodings-1; i >= 0; i--) { |
| 96 | encodings_[i] = encodings[i]; |
| 97 | |
| 98 | if (encodings[i] == encodingCopyRect) |
| 99 | useCopyRect = true; |
| 100 | else if (encodings[i] == pseudoEncodingCursor) |
| 101 | supportsLocalCursor = true; |
| 102 | else if (encodings[i] == pseudoEncodingDesktopSize) |
| 103 | supportsDesktopResize = true; |
Peter Åstrand | 462753d | 2004-11-16 15:23:25 +0000 | [diff] [blame^] | 104 | else if (encodings[i] == pseudoEncodingLastRect) |
| 105 | supportsLastRect = true; |
| 106 | else if (encodings[i] >= pseudoEncodingQualityLevel0 && |
| 107 | encodings[i] <= pseudoEncodingQualityLevel9) |
| 108 | qualityLevel = encodings[i] - pseudoEncodingQualityLevel0; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 109 | else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i])) |
| 110 | currentEncoding_ = encodings[i]; |
| 111 | } |
| 112 | } |