Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 3 | * Copyright 2014-2019 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 4 | * |
| 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 20 | #include <rfb/Exception.h> |
| 21 | #include <rfb/encodings.h> |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 22 | #include <rfb/ledStates.h> |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 23 | #include <rfb/clipboardTypes.h> |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 24 | #include <rfb/ClientParams.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace rfb; |
| 27 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 28 | ClientParams::ClientParams() |
Adam Tkac | 3d0af20 | 2010-11-18 15:19:47 +0000 | [diff] [blame] | 29 | : majorVersion(0), minorVersion(0), |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 30 | compressLevel(2), qualityLevel(-1), fineQualityLevel(-1), |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 31 | subsampling(subsampleUndefined), |
| 32 | width_(0), height_(0), name_(0), |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 33 | ledState_(ledUnknown) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | { |
| 35 | setName(""); |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 36 | |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 37 | cursor_ = new Cursor(0, 0, Point(), NULL); |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 38 | |
| 39 | clipFlags = clipboardUTF8 | clipboardRTF | clipboardHTML | |
| 40 | clipboardRequest | clipboardNotify | clipboardProvide; |
| 41 | memset(clipSizes, 0, sizeof(clipSizes)); |
| 42 | clipSizes[0] = 20 * 1024 * 1024; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 45 | ClientParams::~ClientParams() |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | { |
| 47 | delete [] name_; |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 48 | delete cursor_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 51 | void ClientParams::setDimensions(int width, int height) |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 52 | { |
| 53 | ScreenSet layout; |
| 54 | layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0)); |
| 55 | setDimensions(width, height, layout); |
| 56 | } |
| 57 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 58 | void ClientParams::setDimensions(int width, int height, const ScreenSet& layout) |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 59 | { |
| 60 | if (!layout.validate(width, height)) |
| 61 | throw Exception("Attempted to configure an invalid screen layout"); |
| 62 | |
| 63 | width_ = width; |
| 64 | height_ = height; |
| 65 | screenLayout_ = layout; |
| 66 | } |
| 67 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 68 | void ClientParams::setPF(const PixelFormat& pf) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 76 | void ClientParams::setName(const char* name) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 77 | { |
| 78 | delete [] name_; |
Adam Tkac | d36b626 | 2009-09-04 10:57:20 +0000 | [diff] [blame] | 79 | name_ = strDup(name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 82 | void ClientParams::setCursor(const Cursor& other) |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 83 | { |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 84 | delete cursor_; |
| 85 | cursor_ = new Cursor(other); |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 88 | bool ClientParams::supportsEncoding(rdr::S32 encoding) const |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 89 | { |
| 90 | return encodings_.count(encoding) != 0; |
| 91 | } |
| 92 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 93 | void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 94 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 95 | compressLevel = -1; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 96 | qualityLevel = -1; |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 97 | fineQualityLevel = -1; |
Pierre Ossman | b948a91 | 2014-01-15 13:23:43 +0100 | [diff] [blame] | 98 | subsampling = subsampleUndefined; |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 99 | |
| 100 | encodings_.clear(); |
| 101 | encodings_.insert(encodingRaw); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 102 | |
| 103 | for (int i = nEncodings-1; i >= 0; i--) { |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 104 | switch (encodings[i]) { |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 105 | case pseudoEncodingSubsamp1X: |
| 106 | subsampling = subsampleNone; |
| 107 | break; |
| 108 | case pseudoEncodingSubsampGray: |
| 109 | subsampling = subsampleGray; |
| 110 | break; |
| 111 | case pseudoEncodingSubsamp2X: |
| 112 | subsampling = subsample2X; |
| 113 | break; |
| 114 | case pseudoEncodingSubsamp4X: |
| 115 | subsampling = subsample4X; |
| 116 | break; |
| 117 | case pseudoEncodingSubsamp8X: |
| 118 | subsampling = subsample8X; |
| 119 | break; |
| 120 | case pseudoEncodingSubsamp16X: |
| 121 | subsampling = subsample16X; |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | if (encodings[i] >= pseudoEncodingCompressLevel0 && |
| 126 | encodings[i] <= pseudoEncodingCompressLevel9) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 127 | compressLevel = encodings[i] - pseudoEncodingCompressLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 128 | |
| 129 | if (encodings[i] >= pseudoEncodingQualityLevel0 && |
| 130 | encodings[i] <= pseudoEncodingQualityLevel9) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 131 | qualityLevel = encodings[i] - pseudoEncodingQualityLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 132 | |
| 133 | if (encodings[i] >= pseudoEncodingFineQualityLevel0 && |
| 134 | encodings[i] <= pseudoEncodingFineQualityLevel100) |
| 135 | fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0; |
| 136 | |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 137 | encodings_.insert(encodings[i]); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 138 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 139 | } |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 140 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 141 | void ClientParams::setLEDState(unsigned int state) |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 142 | { |
| 143 | ledState_ = state; |
| 144 | } |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 145 | |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 146 | void ClientParams::setClipboardCaps(rdr::U32 flags, const rdr::U32* lengths) |
| 147 | { |
| 148 | int i, num; |
| 149 | |
| 150 | clipFlags = flags; |
| 151 | |
| 152 | num = 0; |
| 153 | for (i = 0;i < 16;i++) { |
| 154 | if (!(flags & (1 << i))) |
| 155 | continue; |
| 156 | clipSizes[i] = lengths[num++]; |
| 157 | } |
| 158 | } |
| 159 | |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 160 | bool ClientParams::supportsLocalCursor() const |
| 161 | { |
| 162 | if (supportsEncoding(pseudoEncodingCursorWithAlpha)) |
| 163 | return true; |
Pierre Ossman | 4a6266f | 2018-11-05 16:28:18 +0100 | [diff] [blame] | 164 | if (supportsEncoding(pseudoEncodingVMwareCursor)) |
| 165 | return true; |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 166 | if (supportsEncoding(pseudoEncodingCursor)) |
| 167 | return true; |
| 168 | if (supportsEncoding(pseudoEncodingXCursor)) |
| 169 | return true; |
| 170 | return false; |
| 171 | } |
| 172 | |
Pierre Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 173 | bool ClientParams::supportsDesktopSize() const |
| 174 | { |
| 175 | if (supportsEncoding(pseudoEncodingExtendedDesktopSize)) |
| 176 | return true; |
| 177 | if (supportsEncoding(pseudoEncodingDesktopSize)) |
| 178 | return true; |
| 179 | return false; |
| 180 | } |
| 181 | |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 182 | bool ClientParams::supportsLEDState() const |
| 183 | { |
| 184 | if (supportsEncoding(pseudoEncodingLEDState)) |
| 185 | return true; |
Pierre Ossman | 62b0786 | 2018-11-05 16:28:57 +0100 | [diff] [blame] | 186 | if (supportsEncoding(pseudoEncodingVMwareLEDState)) |
| 187 | return true; |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 188 | return false; |
| 189 | } |
| 190 | |
| 191 | bool ClientParams::supportsFence() const |
| 192 | { |
| 193 | if (supportsEncoding(pseudoEncodingFence)) |
| 194 | return true; |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | bool ClientParams::supportsContinuousUpdates() const |
| 199 | { |
| 200 | if (supportsEncoding(pseudoEncodingContinuousUpdates)) |
| 201 | return true; |
| 202 | return false; |
| 203 | } |