blob: 33cd21d8bc8817c78ee656fad8cdf8661e0b3233 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* 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
26using namespace rfb;
27
28ConnParams::ConnParams()
29 : majorVersion(0), minorVersion(0), width(0), height(0), useCopyRect(false),
30 supportsLocalCursor(false), supportsDesktopResize(false),
Peter Åstrand0b870262004-12-28 15:55:46 +000031 supportsLastRect(false), qualityLevel(-1), noJpeg(false),
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000032 name_(0), nEncodings_(0), encodings_(0),
33 currentEncoding_(encodingRaw), verStrPos(0)
34{
35 setName("");
36}
37
38ConnParams::~ConnParams()
39{
40 delete [] name_;
41 delete [] encodings_;
42}
43
44bool 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
60void 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
68void 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
76void ConnParams::setName(const char* name)
77{
78 delete [] name_;
79 name_ = strDup(name);
80}
81
82void 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 Åstrand462753d2004-11-16 15:23:25 +000091 supportsLastRect = false;
92 qualityLevel = -1;
Peter Åstrand0b870262004-12-28 15:55:46 +000093 noJpeg = false;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000094 currentEncoding_ = encodingRaw;
95
96 for (int i = nEncodings-1; i >= 0; i--) {
97 encodings_[i] = encodings[i];
98
99 if (encodings[i] == encodingCopyRect)
100 useCopyRect = true;
101 else if (encodings[i] == pseudoEncodingCursor)
102 supportsLocalCursor = true;
103 else if (encodings[i] == pseudoEncodingDesktopSize)
104 supportsDesktopResize = true;
Peter Åstrand462753d2004-11-16 15:23:25 +0000105 else if (encodings[i] == pseudoEncodingLastRect)
106 supportsLastRect = true;
107 else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
108 encodings[i] <= pseudoEncodingQualityLevel9)
Peter Åstrand0b870262004-12-28 15:55:46 +0000109 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000110 else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
111 currentEncoding_ = encodings[i];
112 }
113}