您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ClientParams.cxx 5.6KB

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