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 | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 3 | * Copyright 2014-2018 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 | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 23 | #include <rfb/ClientParams.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace rfb; |
| 26 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 27 | ClientParams::ClientParams() |
Adam Tkac | 3d0af20 | 2010-11-18 15:19:47 +0000 | [diff] [blame] | 28 | : majorVersion(0), minorVersion(0), |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 29 | compressLevel(2), qualityLevel(-1), fineQualityLevel(-1), |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 30 | subsampling(subsampleUndefined), |
| 31 | width_(0), height_(0), name_(0), |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 32 | ledState_(ledUnknown) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 33 | { |
| 34 | setName(""); |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 35 | cursor_ = new Cursor(0, 0, Point(), NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 38 | ClientParams::~ClientParams() |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | { |
| 40 | delete [] name_; |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 41 | delete cursor_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 44 | void ClientParams::setDimensions(int width, int height) |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 45 | { |
| 46 | ScreenSet layout; |
| 47 | layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0)); |
| 48 | setDimensions(width, height, layout); |
| 49 | } |
| 50 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 51 | void ClientParams::setDimensions(int width, int height, const ScreenSet& layout) |
Pierre Ossman | 9312b0e | 2018-06-20 12:25:14 +0200 | [diff] [blame] | 52 | { |
| 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 Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 61 | void ClientParams::setPF(const PixelFormat& pf) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | { |
| 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 Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 69 | void ClientParams::setName(const char* name) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | { |
| 71 | delete [] name_; |
Adam Tkac | d36b626 | 2009-09-04 10:57:20 +0000 | [diff] [blame] | 72 | name_ = strDup(name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 75 | void ClientParams::setCursor(const Cursor& other) |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 76 | { |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 77 | delete cursor_; |
| 78 | cursor_ = new Cursor(other); |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 81 | bool ClientParams::supportsEncoding(rdr::S32 encoding) const |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 82 | { |
| 83 | return encodings_.count(encoding) != 0; |
| 84 | } |
| 85 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 86 | void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 87 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 88 | compressLevel = -1; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 89 | qualityLevel = -1; |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 90 | fineQualityLevel = -1; |
Pierre Ossman | b948a91 | 2014-01-15 13:23:43 +0100 | [diff] [blame] | 91 | subsampling = subsampleUndefined; |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 92 | |
| 93 | encodings_.clear(); |
| 94 | encodings_.insert(encodingRaw); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 95 | |
| 96 | for (int i = nEncodings-1; i >= 0; i--) { |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 97 | switch (encodings[i]) { |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 98 | 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 120 | compressLevel = encodings[i] - pseudoEncodingCompressLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 121 | |
| 122 | if (encodings[i] >= pseudoEncodingQualityLevel0 && |
| 123 | encodings[i] <= pseudoEncodingQualityLevel9) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 124 | qualityLevel = encodings[i] - pseudoEncodingQualityLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 125 | |
| 126 | if (encodings[i] >= pseudoEncodingFineQualityLevel0 && |
| 127 | encodings[i] <= pseudoEncodingFineQualityLevel100) |
| 128 | fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0; |
| 129 | |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 130 | encodings_.insert(encodings[i]); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 131 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 132 | } |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 133 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 134 | void ClientParams::setLEDState(unsigned int state) |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 135 | { |
| 136 | ledState_ = state; |
| 137 | } |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 138 | |
| 139 | bool 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 Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 150 | bool ClientParams::supportsDesktopSize() const |
| 151 | { |
| 152 | if (supportsEncoding(pseudoEncodingExtendedDesktopSize)) |
| 153 | return true; |
| 154 | if (supportsEncoding(pseudoEncodingDesktopSize)) |
| 155 | return true; |
| 156 | return false; |
| 157 | } |
| 158 | |
Pierre Ossman | b114f5c | 2018-06-18 16:34:16 +0200 | [diff] [blame] | 159 | bool ClientParams::supportsLEDState() const |
| 160 | { |
| 161 | if (supportsEncoding(pseudoEncodingLEDState)) |
| 162 | return true; |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | bool ClientParams::supportsFence() const |
| 167 | { |
| 168 | if (supportsEncoding(pseudoEncodingFence)) |
| 169 | return true; |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | bool ClientParams::supportsContinuousUpdates() const |
| 174 | { |
| 175 | if (supportsEncoding(pseudoEncodingContinuousUpdates)) |
| 176 | return true; |
| 177 | return false; |
| 178 | } |