blob: 2f8783bbd0b0390f58ab47417027fe263ec5e40c [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCb4a83232011-08-19 04:57:18 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossman0d3ce872018-06-18 15:59:00 +02003 * Copyright 2014-2018 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/Exception.h>
21#include <rfb/encodings.h>
Pierre Ossman2fa63f82016-12-05 15:26:21 +010022#include <rfb/ledStates.h>
Pierre Ossman0d3ce872018-06-18 15:59:00 +020023#include <rfb/ClientParams.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000024
25using namespace rfb;
26
Pierre Ossman0d3ce872018-06-18 15:59:00 +020027ClientParams::ClientParams()
Adam Tkac3d0af202010-11-18 15:19:47 +000028 : majorVersion(0), minorVersion(0),
Pierre Ossmana22459d2014-03-17 14:42:10 +010029 compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
Pierre Ossman9312b0e2018-06-20 12:25:14 +020030 subsampling(subsampleUndefined),
31 width_(0), height_(0), name_(0),
Pierre Ossman2fa63f82016-12-05 15:26:21 +010032 ledState_(ledUnknown)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000033{
34 setName("");
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010035 cursor_ = new Cursor(0, 0, Point(), NULL);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036}
37
Pierre Ossman0d3ce872018-06-18 15:59:00 +020038ClientParams::~ClientParams()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039{
40 delete [] name_;
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010041 delete cursor_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042}
43
Pierre Ossman0d3ce872018-06-18 15:59:00 +020044void ClientParams::setDimensions(int width, int height)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020045{
46 ScreenSet layout;
47 layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
48 setDimensions(width, height, layout);
49}
50
Pierre Ossman0d3ce872018-06-18 15:59:00 +020051void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020052{
53 if (!layout.validate(width, height))
54 throw Exception("Attempted to configure an invalid screen layout");
55
56 width_ = width;
57 height_ = height;
58 screenLayout_ = layout;
59}
60
Pierre Ossman0d3ce872018-06-18 15:59:00 +020061void ClientParams::setPF(const PixelFormat& pf)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062{
63 pf_ = pf;
64
65 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
66 throw Exception("setPF: not 8, 16 or 32 bpp?");
67}
68
Pierre Ossman0d3ce872018-06-18 15:59:00 +020069void ClientParams::setName(const char* name)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070{
71 delete [] name_;
Adam Tkacd36b6262009-09-04 10:57:20 +000072 name_ = strDup(name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000073}
74
Pierre Ossman0d3ce872018-06-18 15:59:00 +020075void ClientParams::setCursor(const Cursor& other)
Pierre Ossman126e5642014-02-13 14:40:25 +010076{
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010077 delete cursor_;
78 cursor_ = new Cursor(other);
Pierre Ossman126e5642014-02-13 14:40:25 +010079}
80
Pierre Ossman0d3ce872018-06-18 15:59:00 +020081bool ClientParams::supportsEncoding(rdr::S32 encoding) const
Pierre Ossmanc0397262014-03-14 15:59:46 +010082{
83 return encodings_.count(encoding) != 0;
84}
85
Pierre Ossman0d3ce872018-06-18 15:59:00 +020086void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000088 compressLevel = -1;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000089 qualityLevel = -1;
DRCb4a83232011-08-19 04:57:18 +000090 fineQualityLevel = -1;
Pierre Ossmanb948a912014-01-15 13:23:43 +010091 subsampling = subsampleUndefined;
Pierre Ossmanc0397262014-03-14 15:59:46 +010092
93 encodings_.clear();
94 encodings_.insert(encodingRaw);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095
96 for (int i = nEncodings-1; i >= 0; i--) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +010097 switch (encodings[i]) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +010098 case pseudoEncodingSubsamp1X:
99 subsampling = subsampleNone;
100 break;
101 case pseudoEncodingSubsampGray:
102 subsampling = subsampleGray;
103 break;
104 case pseudoEncodingSubsamp2X:
105 subsampling = subsample2X;
106 break;
107 case pseudoEncodingSubsamp4X:
108 subsampling = subsample4X;
109 break;
110 case pseudoEncodingSubsamp8X:
111 subsampling = subsample8X;
112 break;
113 case pseudoEncodingSubsamp16X:
114 subsampling = subsample16X;
115 break;
116 }
117
118 if (encodings[i] >= pseudoEncodingCompressLevel0 &&
119 encodings[i] <= pseudoEncodingCompressLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000120 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100121
122 if (encodings[i] >= pseudoEncodingQualityLevel0 &&
123 encodings[i] <= pseudoEncodingQualityLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000124 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100125
126 if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
127 encodings[i] <= pseudoEncodingFineQualityLevel100)
128 fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
129
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200130 encodings_.insert(encodings[i]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000131 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000132}
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100133
Pierre Ossman0d3ce872018-06-18 15:59:00 +0200134void ClientParams::setLEDState(unsigned int state)
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100135{
136 ledState_ = state;
137}
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200138
139bool ClientParams::supportsLocalCursor() const
140{
141 if (supportsEncoding(pseudoEncodingCursorWithAlpha))
142 return true;
143 if (supportsEncoding(pseudoEncodingCursor))
144 return true;
145 if (supportsEncoding(pseudoEncodingXCursor))
146 return true;
147 return false;
148}
149
Pierre Ossman2daba9b2018-10-29 10:03:37 +0100150bool ClientParams::supportsDesktopSize() const
151{
152 if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
153 return true;
154 if (supportsEncoding(pseudoEncodingDesktopSize))
155 return true;
156 return false;
157}
158
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200159bool ClientParams::supportsLEDState() const
160{
161 if (supportsEncoding(pseudoEncodingLEDState))
162 return true;
163 return false;
164}
165
166bool ClientParams::supportsFence() const
167{
168 if (supportsEncoding(pseudoEncodingFence))
169 return true;
170 return false;
171}
172
173bool ClientParams::supportsContinuousUpdates() const
174{
175 if (supportsEncoding(pseudoEncodingContinuousUpdates))
176 return true;
177 return false;
178}