blob: 6209f4d5d75399f6e0b39b4393d524d6802c2de4 [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 Ossman9312b0e2018-06-20 12:25:14 +020029 useCopyRect(false),
Pierre Ossmanc5e25602009-03-20 12:59:05 +000030 supportsLocalCursor(false), supportsLocalXCursor(false),
Pierre Ossman8053c8e2017-02-21 12:59:04 +010031 supportsLocalCursorWithAlpha(false),
Pierre Ossmanc5e25602009-03-20 12:59:05 +000032 supportsDesktopResize(false), supportsExtendedDesktopSize(false),
33 supportsDesktopRename(false), supportsLastRect(false),
Pierre Ossman5ae28212017-05-16 14:30:38 +020034 supportsLEDState(false), supportsQEMUKeyEvent(false),
35 supportsSetDesktopSize(false), supportsFence(false),
36 supportsContinuousUpdates(false),
Pierre Ossmana22459d2014-03-17 14:42:10 +010037 compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
Pierre Ossman9312b0e2018-06-20 12:25:14 +020038 subsampling(subsampleUndefined),
39 width_(0), height_(0), name_(0),
Pierre Ossman2fa63f82016-12-05 15:26:21 +010040 ledState_(ledUnknown)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041{
42 setName("");
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010043 cursor_ = new Cursor(0, 0, Point(), NULL);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000044}
45
Pierre Ossman0d3ce872018-06-18 15:59:00 +020046ClientParams::~ClientParams()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000047{
48 delete [] name_;
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010049 delete cursor_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000050}
51
Pierre Ossman0d3ce872018-06-18 15:59:00 +020052void ClientParams::setDimensions(int width, int height)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020053{
54 ScreenSet layout;
55 layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
56 setDimensions(width, height, layout);
57}
58
Pierre Ossman0d3ce872018-06-18 15:59:00 +020059void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020060{
61 if (!layout.validate(width, height))
62 throw Exception("Attempted to configure an invalid screen layout");
63
64 width_ = width;
65 height_ = height;
66 screenLayout_ = layout;
67}
68
Pierre Ossman0d3ce872018-06-18 15:59:00 +020069void ClientParams::setPF(const PixelFormat& pf)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070{
71 pf_ = pf;
72
73 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
74 throw Exception("setPF: not 8, 16 or 32 bpp?");
75}
76
Pierre Ossman0d3ce872018-06-18 15:59:00 +020077void ClientParams::setName(const char* name)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000078{
79 delete [] name_;
Adam Tkacd36b6262009-09-04 10:57:20 +000080 name_ = strDup(name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081}
82
Pierre Ossman0d3ce872018-06-18 15:59:00 +020083void ClientParams::setCursor(const Cursor& other)
Pierre Ossman126e5642014-02-13 14:40:25 +010084{
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010085 delete cursor_;
86 cursor_ = new Cursor(other);
Pierre Ossman126e5642014-02-13 14:40:25 +010087}
88
Pierre Ossman0d3ce872018-06-18 15:59:00 +020089bool ClientParams::supportsEncoding(rdr::S32 encoding) const
Pierre Ossmanc0397262014-03-14 15:59:46 +010090{
91 return encodings_.count(encoding) != 0;
92}
93
Pierre Ossman0d3ce872018-06-18 15:59:00 +020094void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000096 useCopyRect = false;
97 supportsLocalCursor = false;
Pierre Ossman8053c8e2017-02-21 12:59:04 +010098 supportsLocalCursorWithAlpha = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000099 supportsDesktopResize = false;
Pierre Ossmanc5e25602009-03-20 12:59:05 +0000100 supportsExtendedDesktopSize = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000101 supportsLocalXCursor = false;
102 supportsLastRect = false;
Pierre Ossman5ae28212017-05-16 14:30:38 +0200103 supportsQEMUKeyEvent = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000104 compressLevel = -1;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000105 qualityLevel = -1;
DRCb4a83232011-08-19 04:57:18 +0000106 fineQualityLevel = -1;
Pierre Ossmanb948a912014-01-15 13:23:43 +0100107 subsampling = subsampleUndefined;
Pierre Ossmanc0397262014-03-14 15:59:46 +0100108
109 encodings_.clear();
110 encodings_.insert(encodingRaw);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000111
112 for (int i = nEncodings-1; i >= 0; i--) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100113 switch (encodings[i]) {
114 case encodingCopyRect:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000115 useCopyRect = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100116 break;
117 case pseudoEncodingCursor:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000118 supportsLocalCursor = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100119 break;
120 case pseudoEncodingXCursor:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000121 supportsLocalXCursor = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100122 break;
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100123 case pseudoEncodingCursorWithAlpha:
124 supportsLocalCursorWithAlpha = true;
125 break;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100126 case pseudoEncodingDesktopSize:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000127 supportsDesktopResize = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100128 break;
129 case pseudoEncodingExtendedDesktopSize:
Pierre Ossmanc5e25602009-03-20 12:59:05 +0000130 supportsExtendedDesktopSize = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100131 break;
132 case pseudoEncodingDesktopName:
Peter Åstrandc39e0782009-01-15 12:21:42 +0000133 supportsDesktopRename = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100134 break;
135 case pseudoEncodingLastRect:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000136 supportsLastRect = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100137 break;
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100138 case pseudoEncodingLEDState:
139 supportsLEDState = true;
Pierre Ossman58a4c132018-03-28 12:33:22 +0200140 break;
Pierre Ossman5ae28212017-05-16 14:30:38 +0200141 case pseudoEncodingQEMUKeyEvent:
142 supportsQEMUKeyEvent = true;
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100143 break;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100144 case pseudoEncodingFence:
Pierre Ossmanc754cce2011-11-14 15:44:11 +0000145 supportsFence = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100146 break;
147 case pseudoEncodingContinuousUpdates:
Pierre Ossmanc898d9a2011-11-14 16:22:23 +0000148 supportsContinuousUpdates = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100149 break;
150 case pseudoEncodingSubsamp1X:
151 subsampling = subsampleNone;
152 break;
153 case pseudoEncodingSubsampGray:
154 subsampling = subsampleGray;
155 break;
156 case pseudoEncodingSubsamp2X:
157 subsampling = subsample2X;
158 break;
159 case pseudoEncodingSubsamp4X:
160 subsampling = subsample4X;
161 break;
162 case pseudoEncodingSubsamp8X:
163 subsampling = subsample8X;
164 break;
165 case pseudoEncodingSubsamp16X:
166 subsampling = subsample16X;
167 break;
168 }
169
170 if (encodings[i] >= pseudoEncodingCompressLevel0 &&
171 encodings[i] <= pseudoEncodingCompressLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000172 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100173
174 if (encodings[i] >= pseudoEncodingQualityLevel0 &&
175 encodings[i] <= pseudoEncodingQualityLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000176 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100177
178 if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
179 encodings[i] <= pseudoEncodingFineQualityLevel100)
180 fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
181
Pierre Ossmanc0397262014-03-14 15:59:46 +0100182 if (encodings[i] > 0)
183 encodings_.insert(encodings[i]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000184 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000185}
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100186
Pierre Ossman0d3ce872018-06-18 15:59:00 +0200187void ClientParams::setLEDState(unsigned int state)
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100188{
189 ledState_ = state;
190}