You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClientParams.cxx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014-2019 Pierre Ossman for Cendio AB
  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. */
  20. #include <rfb/Exception.h>
  21. #include <rfb/encodings.h>
  22. #include <rfb/ledStates.h>
  23. #include <rfb/clipboardTypes.h>
  24. #include <rfb/ClientParams.h>
  25. using namespace rfb;
  26. ClientParams::ClientParams()
  27. : majorVersion(0), minorVersion(0),
  28. compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
  29. subsampling(subsampleUndefined),
  30. width_(0), height_(0), name_(0),
  31. cursorPos_(0, 0), ledState_(ledUnknown)
  32. {
  33. setName("");
  34. cursor_ = new Cursor(0, 0, Point(), NULL);
  35. clipFlags = clipboardUTF8 | clipboardRTF | clipboardHTML |
  36. clipboardRequest | clipboardNotify | clipboardProvide;
  37. memset(clipSizes, 0, sizeof(clipSizes));
  38. clipSizes[0] = 20 * 1024 * 1024;
  39. }
  40. ClientParams::~ClientParams()
  41. {
  42. delete [] name_;
  43. delete cursor_;
  44. }
  45. void ClientParams::setDimensions(int width, int height)
  46. {
  47. ScreenSet layout;
  48. layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
  49. setDimensions(width, height, layout);
  50. }
  51. void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
  52. {
  53. if (!layout.validate(width, height))
  54. throw Exception("Attempted to configure an invalid screen layout");
  55. width_ = width;
  56. height_ = height;
  57. screenLayout_ = layout;
  58. }
  59. void ClientParams::setPF(const PixelFormat& pf)
  60. {
  61. pf_ = pf;
  62. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  63. throw Exception("setPF: not 8, 16 or 32 bpp?");
  64. }
  65. void ClientParams::setName(const char* name)
  66. {
  67. delete [] name_;
  68. name_ = strDup(name);
  69. }
  70. void ClientParams::setCursor(const Cursor& other)
  71. {
  72. delete cursor_;
  73. cursor_ = new Cursor(other);
  74. }
  75. void ClientParams::setCursorPos(const Point& pos)
  76. {
  77. cursorPos_ = pos;
  78. }
  79. bool ClientParams::supportsEncoding(rdr::S32 encoding) const
  80. {
  81. return encodings_.count(encoding) != 0;
  82. }
  83. void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  84. {
  85. compressLevel = -1;
  86. qualityLevel = -1;
  87. fineQualityLevel = -1;
  88. subsampling = subsampleUndefined;
  89. encodings_.clear();
  90. encodings_.insert(encodingRaw);
  91. for (int i = nEncodings-1; i >= 0; i--) {
  92. switch (encodings[i]) {
  93. case pseudoEncodingSubsamp1X:
  94. subsampling = subsampleNone;
  95. break;
  96. case pseudoEncodingSubsampGray:
  97. subsampling = subsampleGray;
  98. break;
  99. case pseudoEncodingSubsamp2X:
  100. subsampling = subsample2X;
  101. break;
  102. case pseudoEncodingSubsamp4X:
  103. subsampling = subsample4X;
  104. break;
  105. case pseudoEncodingSubsamp8X:
  106. subsampling = subsample8X;
  107. break;
  108. case pseudoEncodingSubsamp16X:
  109. subsampling = subsample16X;
  110. break;
  111. }
  112. if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  113. encodings[i] <= pseudoEncodingCompressLevel9)
  114. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  115. if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  116. encodings[i] <= pseudoEncodingQualityLevel9)
  117. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  118. if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
  119. encodings[i] <= pseudoEncodingFineQualityLevel100)
  120. fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
  121. encodings_.insert(encodings[i]);
  122. }
  123. }
  124. void ClientParams::setLEDState(unsigned int state)
  125. {
  126. ledState_ = state;
  127. }
  128. rdr::U32 ClientParams::clipboardSize(unsigned int format) const
  129. {
  130. int i;
  131. for (i = 0;i < 16;i++) {
  132. if (((unsigned)1 << i) == format)
  133. return clipSizes[i];
  134. }
  135. throw Exception("Invalid clipboard format 0x%x", format);
  136. }
  137. void ClientParams::setClipboardCaps(rdr::U32 flags, const rdr::U32* lengths)
  138. {
  139. int i, num;
  140. clipFlags = flags;
  141. num = 0;
  142. for (i = 0;i < 16;i++) {
  143. if (!(flags & (1 << i)))
  144. continue;
  145. clipSizes[i] = lengths[num++];
  146. }
  147. }
  148. bool ClientParams::supportsLocalCursor() const
  149. {
  150. if (supportsEncoding(pseudoEncodingCursorWithAlpha))
  151. return true;
  152. if (supportsEncoding(pseudoEncodingVMwareCursor))
  153. return true;
  154. if (supportsEncoding(pseudoEncodingCursor))
  155. return true;
  156. if (supportsEncoding(pseudoEncodingXCursor))
  157. return true;
  158. return false;
  159. }
  160. bool ClientParams::supportsCursorPosition() const
  161. {
  162. if (supportsEncoding(pseudoEncodingVMwareCursorPosition))
  163. return true;
  164. return false;
  165. }
  166. bool ClientParams::supportsDesktopSize() const
  167. {
  168. if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
  169. return true;
  170. if (supportsEncoding(pseudoEncodingDesktopSize))
  171. return true;
  172. return false;
  173. }
  174. bool ClientParams::supportsLEDState() const
  175. {
  176. if (supportsEncoding(pseudoEncodingLEDState))
  177. return true;
  178. if (supportsEncoding(pseudoEncodingVMwareLEDState))
  179. return true;
  180. return false;
  181. }
  182. bool ClientParams::supportsFence() const
  183. {
  184. if (supportsEncoding(pseudoEncodingFence))
  185. return true;
  186. return false;
  187. }
  188. bool ClientParams::supportsContinuousUpdates() const
  189. {
  190. if (supportsEncoding(pseudoEncodingContinuousUpdates))
  191. return true;
  192. return false;
  193. }