blob: 1fdf8f38c161f1058cd697333d2928ff3eb0cfea [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 Ossmanb948a912014-01-15 13:23:43 +01003 * Copyright 2014 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 */
Adam Tkac20e0d712008-11-14 14:48:21 +000020#include <stdio.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000021#include <rfb/Exception.h>
22#include <rfb/encodings.h>
Pierre Ossman2fa63f82016-12-05 15:26:21 +010023#include <rfb/ledStates.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000024#include <rfb/ConnParams.h>
25#include <rfb/util.h>
26
27using namespace rfb;
28
29ConnParams::ConnParams()
Adam Tkac3d0af202010-11-18 15:19:47 +000030 : majorVersion(0), minorVersion(0),
Pierre Ossman9312b0e2018-06-20 12:25:14 +020031 useCopyRect(false),
Pierre Ossmanc5e25602009-03-20 12:59:05 +000032 supportsLocalCursor(false), supportsLocalXCursor(false),
Pierre Ossman8053c8e2017-02-21 12:59:04 +010033 supportsLocalCursorWithAlpha(false),
Pierre Ossmanc5e25602009-03-20 12:59:05 +000034 supportsDesktopResize(false), supportsExtendedDesktopSize(false),
35 supportsDesktopRename(false), supportsLastRect(false),
Pierre Ossman5ae28212017-05-16 14:30:38 +020036 supportsLEDState(false), supportsQEMUKeyEvent(false),
37 supportsSetDesktopSize(false), supportsFence(false),
38 supportsContinuousUpdates(false),
Pierre Ossmana22459d2014-03-17 14:42:10 +010039 compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
Pierre Ossman9312b0e2018-06-20 12:25:14 +020040 subsampling(subsampleUndefined),
41 width_(0), height_(0), name_(0),
Pierre Ossman2fa63f82016-12-05 15:26:21 +010042 ledState_(ledUnknown)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043{
44 setName("");
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010045 cursor_ = new Cursor(0, 0, Point(), NULL);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046}
47
48ConnParams::~ConnParams()
49{
50 delete [] name_;
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010051 delete cursor_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000052}
53
Pierre Ossman9312b0e2018-06-20 12:25:14 +020054void ConnParams::setDimensions(int width, int height)
55{
56 ScreenSet layout;
57 layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
58 setDimensions(width, height, layout);
59}
60
61void ConnParams::setDimensions(int width, int height, const ScreenSet& layout)
62{
63 if (!layout.validate(width, height))
64 throw Exception("Attempted to configure an invalid screen layout");
65
66 width_ = width;
67 height_ = height;
68 screenLayout_ = layout;
69}
70
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071void ConnParams::setPF(const PixelFormat& pf)
72{
73 pf_ = pf;
74
75 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
76 throw Exception("setPF: not 8, 16 or 32 bpp?");
77}
78
79void ConnParams::setName(const char* name)
80{
81 delete [] name_;
Adam Tkacd36b6262009-09-04 10:57:20 +000082 name_ = strDup(name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000083}
84
Pierre Ossman126e5642014-02-13 14:40:25 +010085void ConnParams::setCursor(const Cursor& other)
86{
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010087 delete cursor_;
88 cursor_ = new Cursor(other);
Pierre Ossman126e5642014-02-13 14:40:25 +010089}
90
Pierre Ossmanf22d3502015-11-10 12:58:49 +010091bool ConnParams::supportsEncoding(rdr::S32 encoding) const
Pierre Ossmanc0397262014-03-14 15:59:46 +010092{
93 return encodings_.count(encoding) != 0;
94}
95
Peter Åstrand98fe98c2010-02-10 07:43:02 +000096void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000097{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098 useCopyRect = false;
99 supportsLocalCursor = false;
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100100 supportsLocalCursorWithAlpha = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000101 supportsDesktopResize = false;
Pierre Ossmanc5e25602009-03-20 12:59:05 +0000102 supportsExtendedDesktopSize = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000103 supportsLocalXCursor = false;
104 supportsLastRect = false;
Pierre Ossman5ae28212017-05-16 14:30:38 +0200105 supportsQEMUKeyEvent = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000106 compressLevel = -1;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000107 qualityLevel = -1;
DRCb4a83232011-08-19 04:57:18 +0000108 fineQualityLevel = -1;
Pierre Ossmanb948a912014-01-15 13:23:43 +0100109 subsampling = subsampleUndefined;
Pierre Ossmanc0397262014-03-14 15:59:46 +0100110
111 encodings_.clear();
112 encodings_.insert(encodingRaw);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000113
114 for (int i = nEncodings-1; i >= 0; i--) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100115 switch (encodings[i]) {
116 case encodingCopyRect:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000117 useCopyRect = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100118 break;
119 case pseudoEncodingCursor:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000120 supportsLocalCursor = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100121 break;
122 case pseudoEncodingXCursor:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000123 supportsLocalXCursor = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100124 break;
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100125 case pseudoEncodingCursorWithAlpha:
126 supportsLocalCursorWithAlpha = true;
127 break;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100128 case pseudoEncodingDesktopSize:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000129 supportsDesktopResize = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100130 break;
131 case pseudoEncodingExtendedDesktopSize:
Pierre Ossmanc5e25602009-03-20 12:59:05 +0000132 supportsExtendedDesktopSize = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100133 break;
134 case pseudoEncodingDesktopName:
Peter Åstrandc39e0782009-01-15 12:21:42 +0000135 supportsDesktopRename = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100136 break;
137 case pseudoEncodingLastRect:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000138 supportsLastRect = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100139 break;
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100140 case pseudoEncodingLEDState:
141 supportsLEDState = true;
Pierre Ossman58a4c132018-03-28 12:33:22 +0200142 break;
Pierre Ossman5ae28212017-05-16 14:30:38 +0200143 case pseudoEncodingQEMUKeyEvent:
144 supportsQEMUKeyEvent = true;
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100145 break;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100146 case pseudoEncodingFence:
Pierre Ossmanc754cce2011-11-14 15:44:11 +0000147 supportsFence = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100148 break;
149 case pseudoEncodingContinuousUpdates:
Pierre Ossmanc898d9a2011-11-14 16:22:23 +0000150 supportsContinuousUpdates = true;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100151 break;
152 case pseudoEncodingSubsamp1X:
153 subsampling = subsampleNone;
154 break;
155 case pseudoEncodingSubsampGray:
156 subsampling = subsampleGray;
157 break;
158 case pseudoEncodingSubsamp2X:
159 subsampling = subsample2X;
160 break;
161 case pseudoEncodingSubsamp4X:
162 subsampling = subsample4X;
163 break;
164 case pseudoEncodingSubsamp8X:
165 subsampling = subsample8X;
166 break;
167 case pseudoEncodingSubsamp16X:
168 subsampling = subsample16X;
169 break;
170 }
171
172 if (encodings[i] >= pseudoEncodingCompressLevel0 &&
173 encodings[i] <= pseudoEncodingCompressLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000174 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100175
176 if (encodings[i] >= pseudoEncodingQualityLevel0 &&
177 encodings[i] <= pseudoEncodingQualityLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000178 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100179
180 if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
181 encodings[i] <= pseudoEncodingFineQualityLevel100)
182 fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
183
Pierre Ossmanc0397262014-03-14 15:59:46 +0100184 if (encodings[i] > 0)
185 encodings_.insert(encodings[i]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000186 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000187}
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100188
189void ConnParams::setLEDState(unsigned int state)
190{
191 ledState_ = state;
192}