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.

ConnParams.cxx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014 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 <stdio.h>
  21. #include <rdr/InStream.h>
  22. #include <rdr/OutStream.h>
  23. #include <rfb/Exception.h>
  24. #include <rfb/encodings.h>
  25. #include <rfb/ledStates.h>
  26. #include <rfb/ConnParams.h>
  27. #include <rfb/util.h>
  28. using namespace rfb;
  29. ConnParams::ConnParams()
  30. : majorVersion(0), minorVersion(0),
  31. width(0), height(0), useCopyRect(false),
  32. supportsLocalCursor(false), supportsLocalXCursor(false),
  33. supportsLocalCursorWithAlpha(false),
  34. supportsDesktopResize(false), supportsExtendedDesktopSize(false),
  35. supportsDesktopRename(false), supportsLastRect(false),
  36. supportsLEDState(false), supportsQEMUKeyEvent(false),
  37. supportsSetDesktopSize(false), supportsFence(false),
  38. supportsContinuousUpdates(false),
  39. compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
  40. subsampling(subsampleUndefined), name_(0), verStrPos(0),
  41. ledState_(ledUnknown)
  42. {
  43. setName("");
  44. cursor_ = new Cursor(0, 0, Point(), NULL);
  45. }
  46. ConnParams::~ConnParams()
  47. {
  48. delete [] name_;
  49. delete cursor_;
  50. }
  51. bool ConnParams::readVersion(rdr::InStream* is, bool* done)
  52. {
  53. if (verStrPos >= 12) return false;
  54. while (is->checkNoWait(1) && verStrPos < 12) {
  55. verStr[verStrPos++] = is->readU8();
  56. }
  57. if (verStrPos < 12) {
  58. *done = false;
  59. return true;
  60. }
  61. *done = true;
  62. verStr[12] = 0;
  63. return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
  64. }
  65. void ConnParams::writeVersion(rdr::OutStream* os)
  66. {
  67. char str[13];
  68. sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
  69. os->writeBytes(str, 12);
  70. os->flush();
  71. }
  72. void ConnParams::setPF(const PixelFormat& pf)
  73. {
  74. pf_ = pf;
  75. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  76. throw Exception("setPF: not 8, 16 or 32 bpp?");
  77. }
  78. void ConnParams::setName(const char* name)
  79. {
  80. delete [] name_;
  81. name_ = strDup(name);
  82. }
  83. void ConnParams::setCursor(const Cursor& other)
  84. {
  85. delete cursor_;
  86. cursor_ = new Cursor(other);
  87. }
  88. bool ConnParams::supportsEncoding(rdr::S32 encoding) const
  89. {
  90. return encodings_.count(encoding) != 0;
  91. }
  92. void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  93. {
  94. useCopyRect = false;
  95. supportsLocalCursor = false;
  96. supportsLocalCursorWithAlpha = false;
  97. supportsDesktopResize = false;
  98. supportsExtendedDesktopSize = false;
  99. supportsLocalXCursor = false;
  100. supportsLastRect = false;
  101. supportsQEMUKeyEvent = false;
  102. compressLevel = -1;
  103. qualityLevel = -1;
  104. fineQualityLevel = -1;
  105. subsampling = subsampleUndefined;
  106. encodings_.clear();
  107. encodings_.insert(encodingRaw);
  108. for (int i = nEncodings-1; i >= 0; i--) {
  109. switch (encodings[i]) {
  110. case encodingCopyRect:
  111. useCopyRect = true;
  112. break;
  113. case pseudoEncodingCursor:
  114. supportsLocalCursor = true;
  115. break;
  116. case pseudoEncodingXCursor:
  117. supportsLocalXCursor = true;
  118. break;
  119. case pseudoEncodingCursorWithAlpha:
  120. supportsLocalCursorWithAlpha = true;
  121. break;
  122. case pseudoEncodingDesktopSize:
  123. supportsDesktopResize = true;
  124. break;
  125. case pseudoEncodingExtendedDesktopSize:
  126. supportsExtendedDesktopSize = true;
  127. break;
  128. case pseudoEncodingDesktopName:
  129. supportsDesktopRename = true;
  130. break;
  131. case pseudoEncodingLastRect:
  132. supportsLastRect = true;
  133. break;
  134. case pseudoEncodingLEDState:
  135. supportsLEDState = true;
  136. break;
  137. case pseudoEncodingQEMUKeyEvent:
  138. supportsQEMUKeyEvent = true;
  139. break;
  140. case pseudoEncodingFence:
  141. supportsFence = true;
  142. break;
  143. case pseudoEncodingContinuousUpdates:
  144. supportsContinuousUpdates = true;
  145. break;
  146. case pseudoEncodingSubsamp1X:
  147. subsampling = subsampleNone;
  148. break;
  149. case pseudoEncodingSubsampGray:
  150. subsampling = subsampleGray;
  151. break;
  152. case pseudoEncodingSubsamp2X:
  153. subsampling = subsample2X;
  154. break;
  155. case pseudoEncodingSubsamp4X:
  156. subsampling = subsample4X;
  157. break;
  158. case pseudoEncodingSubsamp8X:
  159. subsampling = subsample8X;
  160. break;
  161. case pseudoEncodingSubsamp16X:
  162. subsampling = subsample16X;
  163. break;
  164. }
  165. if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  166. encodings[i] <= pseudoEncodingCompressLevel9)
  167. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  168. if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  169. encodings[i] <= pseudoEncodingQualityLevel9)
  170. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  171. if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
  172. encodings[i] <= pseudoEncodingFineQualityLevel100)
  173. fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
  174. if (encodings[i] > 0)
  175. encodings_.insert(encodings[i]);
  176. }
  177. }
  178. void ConnParams::setLEDState(unsigned int state)
  179. {
  180. ledState_ = state;
  181. }