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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. 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. bool ClientParams::supportsEncoding(rdr::S32 encoding) const
  76. {
  77. return encodings_.count(encoding) != 0;
  78. }
  79. void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  80. {
  81. compressLevel = -1;
  82. qualityLevel = -1;
  83. fineQualityLevel = -1;
  84. subsampling = subsampleUndefined;
  85. encodings_.clear();
  86. encodings_.insert(encodingRaw);
  87. for (int i = nEncodings-1; i >= 0; i--) {
  88. switch (encodings[i]) {
  89. case pseudoEncodingSubsamp1X:
  90. subsampling = subsampleNone;
  91. break;
  92. case pseudoEncodingSubsampGray:
  93. subsampling = subsampleGray;
  94. break;
  95. case pseudoEncodingSubsamp2X:
  96. subsampling = subsample2X;
  97. break;
  98. case pseudoEncodingSubsamp4X:
  99. subsampling = subsample4X;
  100. break;
  101. case pseudoEncodingSubsamp8X:
  102. subsampling = subsample8X;
  103. break;
  104. case pseudoEncodingSubsamp16X:
  105. subsampling = subsample16X;
  106. break;
  107. }
  108. if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  109. encodings[i] <= pseudoEncodingCompressLevel9)
  110. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  111. if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  112. encodings[i] <= pseudoEncodingQualityLevel9)
  113. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  114. if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
  115. encodings[i] <= pseudoEncodingFineQualityLevel100)
  116. fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
  117. encodings_.insert(encodings[i]);
  118. }
  119. }
  120. void ClientParams::setLEDState(unsigned int state)
  121. {
  122. ledState_ = state;
  123. }
  124. void ClientParams::setClipboardCaps(rdr::U32 flags, const rdr::U32* lengths)
  125. {
  126. int i, num;
  127. clipFlags = flags;
  128. num = 0;
  129. for (i = 0;i < 16;i++) {
  130. if (!(flags & (1 << i)))
  131. continue;
  132. clipSizes[i] = lengths[num++];
  133. }
  134. }
  135. bool ClientParams::supportsLocalCursor() const
  136. {
  137. if (supportsEncoding(pseudoEncodingCursorWithAlpha))
  138. return true;
  139. if (supportsEncoding(pseudoEncodingVMwareCursor))
  140. return true;
  141. if (supportsEncoding(pseudoEncodingCursor))
  142. return true;
  143. if (supportsEncoding(pseudoEncodingXCursor))
  144. return true;
  145. return false;
  146. }
  147. bool ClientParams::supportsDesktopSize() const
  148. {
  149. if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
  150. return true;
  151. if (supportsEncoding(pseudoEncodingDesktopSize))
  152. return true;
  153. return false;
  154. }
  155. bool ClientParams::supportsLEDState() const
  156. {
  157. if (supportsEncoding(pseudoEncodingLEDState))
  158. return true;
  159. if (supportsEncoding(pseudoEncodingVMwareLEDState))
  160. return true;
  161. return false;
  162. }
  163. bool ClientParams::supportsFence() const
  164. {
  165. if (supportsEncoding(pseudoEncodingFence))
  166. return true;
  167. return false;
  168. }
  169. bool ClientParams::supportsContinuousUpdates() const
  170. {
  171. if (supportsEncoding(pseudoEncodingContinuousUpdates))
  172. return true;
  173. return false;
  174. }