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 | b948a91 | 2014-01-15 13:23:43 +0100 | [diff] [blame] | 3 | * Copyright 2014 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 | */ |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 21 | #include <rfb/Exception.h> |
| 22 | #include <rfb/encodings.h> |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 23 | #include <rfb/ledStates.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | #include <rfb/ConnParams.h> |
| 25 | #include <rfb/util.h> |
| 26 | |
| 27 | using namespace rfb; |
| 28 | |
| 29 | ConnParams::ConnParams() |
Adam Tkac | 3d0af20 | 2010-11-18 15:19:47 +0000 | [diff] [blame] | 30 | : majorVersion(0), minorVersion(0), |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 31 | width(0), height(0), useCopyRect(false), |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 32 | supportsLocalCursor(false), supportsLocalXCursor(false), |
Pierre Ossman | 8053c8e | 2017-02-21 12:59:04 +0100 | [diff] [blame] | 33 | supportsLocalCursorWithAlpha(false), |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 34 | supportsDesktopResize(false), supportsExtendedDesktopSize(false), |
| 35 | supportsDesktopRename(false), supportsLastRect(false), |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 36 | supportsLEDState(false), supportsQEMUKeyEvent(false), |
| 37 | supportsSetDesktopSize(false), supportsFence(false), |
| 38 | supportsContinuousUpdates(false), |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 39 | compressLevel(2), qualityLevel(-1), fineQualityLevel(-1), |
Pierre Ossman | ea7ede9 | 2018-06-18 16:51:53 +0200 | [diff] [blame] | 40 | subsampling(subsampleUndefined), name_(0), |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 41 | ledState_(ledUnknown) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | { |
| 43 | setName(""); |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 44 | cursor_ = new Cursor(0, 0, Point(), NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ConnParams::~ConnParams() |
| 48 | { |
| 49 | delete [] name_; |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 50 | delete cursor_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 53 | void ConnParams::setPF(const PixelFormat& pf) |
| 54 | { |
| 55 | pf_ = pf; |
| 56 | |
| 57 | if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) |
| 58 | throw Exception("setPF: not 8, 16 or 32 bpp?"); |
| 59 | } |
| 60 | |
| 61 | void ConnParams::setName(const char* name) |
| 62 | { |
| 63 | delete [] name_; |
Adam Tkac | d36b626 | 2009-09-04 10:57:20 +0000 | [diff] [blame] | 64 | name_ = strDup(name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 67 | void ConnParams::setCursor(const Cursor& other) |
| 68 | { |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 69 | delete cursor_; |
| 70 | cursor_ = new Cursor(other); |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Pierre Ossman | f22d350 | 2015-11-10 12:58:49 +0100 | [diff] [blame] | 73 | bool ConnParams::supportsEncoding(rdr::S32 encoding) const |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 74 | { |
| 75 | return encodings_.count(encoding) != 0; |
| 76 | } |
| 77 | |
Peter Åstrand | 98fe98c | 2010-02-10 07:43:02 +0000 | [diff] [blame] | 78 | void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 80 | useCopyRect = false; |
| 81 | supportsLocalCursor = false; |
Pierre Ossman | 8053c8e | 2017-02-21 12:59:04 +0100 | [diff] [blame] | 82 | supportsLocalCursorWithAlpha = false; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 83 | supportsDesktopResize = false; |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 84 | supportsExtendedDesktopSize = false; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 85 | supportsLocalXCursor = false; |
| 86 | supportsLastRect = false; |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 87 | supportsQEMUKeyEvent = false; |
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]) { |
| 98 | case encodingCopyRect: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 99 | useCopyRect = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 100 | break; |
| 101 | case pseudoEncodingCursor: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 102 | supportsLocalCursor = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 103 | break; |
| 104 | case pseudoEncodingXCursor: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 105 | supportsLocalXCursor = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 106 | break; |
Pierre Ossman | 8053c8e | 2017-02-21 12:59:04 +0100 | [diff] [blame] | 107 | case pseudoEncodingCursorWithAlpha: |
| 108 | supportsLocalCursorWithAlpha = true; |
| 109 | break; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 110 | case pseudoEncodingDesktopSize: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 111 | supportsDesktopResize = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 112 | break; |
| 113 | case pseudoEncodingExtendedDesktopSize: |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 114 | supportsExtendedDesktopSize = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 115 | break; |
| 116 | case pseudoEncodingDesktopName: |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 117 | supportsDesktopRename = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 118 | break; |
| 119 | case pseudoEncodingLastRect: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 120 | supportsLastRect = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 121 | break; |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 122 | case pseudoEncodingLEDState: |
| 123 | supportsLEDState = true; |
Pierre Ossman | 58a4c13 | 2018-03-28 12:33:22 +0200 | [diff] [blame] | 124 | break; |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 125 | case pseudoEncodingQEMUKeyEvent: |
| 126 | supportsQEMUKeyEvent = true; |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 127 | break; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 128 | case pseudoEncodingFence: |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 129 | supportsFence = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 130 | break; |
| 131 | case pseudoEncodingContinuousUpdates: |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 132 | supportsContinuousUpdates = true; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 133 | break; |
| 134 | case pseudoEncodingSubsamp1X: |
| 135 | subsampling = subsampleNone; |
| 136 | break; |
| 137 | case pseudoEncodingSubsampGray: |
| 138 | subsampling = subsampleGray; |
| 139 | break; |
| 140 | case pseudoEncodingSubsamp2X: |
| 141 | subsampling = subsample2X; |
| 142 | break; |
| 143 | case pseudoEncodingSubsamp4X: |
| 144 | subsampling = subsample4X; |
| 145 | break; |
| 146 | case pseudoEncodingSubsamp8X: |
| 147 | subsampling = subsample8X; |
| 148 | break; |
| 149 | case pseudoEncodingSubsamp16X: |
| 150 | subsampling = subsample16X; |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | if (encodings[i] >= pseudoEncodingCompressLevel0 && |
| 155 | encodings[i] <= pseudoEncodingCompressLevel9) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 156 | compressLevel = encodings[i] - pseudoEncodingCompressLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 157 | |
| 158 | if (encodings[i] >= pseudoEncodingQualityLevel0 && |
| 159 | encodings[i] <= pseudoEncodingQualityLevel9) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 160 | qualityLevel = encodings[i] - pseudoEncodingQualityLevel0; |
Pierre Ossman | 6bcf137 | 2014-01-15 13:44:04 +0100 | [diff] [blame] | 161 | |
| 162 | if (encodings[i] >= pseudoEncodingFineQualityLevel0 && |
| 163 | encodings[i] <= pseudoEncodingFineQualityLevel100) |
| 164 | fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0; |
| 165 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 166 | if (encodings[i] > 0) |
| 167 | encodings_.insert(encodings[i]); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 168 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 169 | } |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 170 | |
| 171 | void ConnParams::setLEDState(unsigned int state) |
| 172 | { |
| 173 | ledState_ = state; |
| 174 | } |