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 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014-2018 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/ClientParams.h>
  24. using namespace rfb;
  25. ClientParams::ClientParams()
  26. : majorVersion(0), minorVersion(0),
  27. compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
  28. subsampling(subsampleUndefined),
  29. width_(0), height_(0), name_(0),
  30. ledState_(ledUnknown)
  31. {
  32. setName("");
  33. cursor_ = new Cursor(0, 0, Point(), NULL);
  34. }
  35. ClientParams::~ClientParams()
  36. {
  37. delete [] name_;
  38. delete cursor_;
  39. }
  40. void ClientParams::setDimensions(int width, int height)
  41. {
  42. ScreenSet layout;
  43. layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
  44. setDimensions(width, height, layout);
  45. }
  46. void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
  47. {
  48. if (!layout.validate(width, height))
  49. throw Exception("Attempted to configure an invalid screen layout");
  50. width_ = width;
  51. height_ = height;
  52. screenLayout_ = layout;
  53. }
  54. void ClientParams::setPF(const PixelFormat& pf)
  55. {
  56. pf_ = pf;
  57. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  58. throw Exception("setPF: not 8, 16 or 32 bpp?");
  59. }
  60. void ClientParams::setName(const char* name)
  61. {
  62. delete [] name_;
  63. name_ = strDup(name);
  64. }
  65. void ClientParams::setCursor(const Cursor& other)
  66. {
  67. delete cursor_;
  68. cursor_ = new Cursor(other);
  69. }
  70. bool ClientParams::supportsEncoding(rdr::S32 encoding) const
  71. {
  72. return encodings_.count(encoding) != 0;
  73. }
  74. void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  75. {
  76. compressLevel = -1;
  77. qualityLevel = -1;
  78. fineQualityLevel = -1;
  79. subsampling = subsampleUndefined;
  80. encodings_.clear();
  81. encodings_.insert(encodingRaw);
  82. for (int i = nEncodings-1; i >= 0; i--) {
  83. switch (encodings[i]) {
  84. case pseudoEncodingSubsamp1X:
  85. subsampling = subsampleNone;
  86. break;
  87. case pseudoEncodingSubsampGray:
  88. subsampling = subsampleGray;
  89. break;
  90. case pseudoEncodingSubsamp2X:
  91. subsampling = subsample2X;
  92. break;
  93. case pseudoEncodingSubsamp4X:
  94. subsampling = subsample4X;
  95. break;
  96. case pseudoEncodingSubsamp8X:
  97. subsampling = subsample8X;
  98. break;
  99. case pseudoEncodingSubsamp16X:
  100. subsampling = subsample16X;
  101. break;
  102. }
  103. if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  104. encodings[i] <= pseudoEncodingCompressLevel9)
  105. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  106. if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  107. encodings[i] <= pseudoEncodingQualityLevel9)
  108. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  109. if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
  110. encodings[i] <= pseudoEncodingFineQualityLevel100)
  111. fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
  112. encodings_.insert(encodings[i]);
  113. }
  114. }
  115. void ClientParams::setLEDState(unsigned int state)
  116. {
  117. ledState_ = state;
  118. }
  119. bool ClientParams::supportsLocalCursor() const
  120. {
  121. if (supportsEncoding(pseudoEncodingCursorWithAlpha))
  122. return true;
  123. if (supportsEncoding(pseudoEncodingCursor))
  124. return true;
  125. if (supportsEncoding(pseudoEncodingXCursor))
  126. return true;
  127. return false;
  128. }
  129. bool ClientParams::supportsDesktopSize() const
  130. {
  131. if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
  132. return true;
  133. if (supportsEncoding(pseudoEncodingDesktopSize))
  134. return true;
  135. return false;
  136. }
  137. bool ClientParams::supportsLEDState() const
  138. {
  139. if (supportsEncoding(pseudoEncodingLEDState))
  140. return true;
  141. return false;
  142. }
  143. bool ClientParams::supportsFence() const
  144. {
  145. if (supportsEncoding(pseudoEncodingFence))
  146. return true;
  147. return false;
  148. }
  149. bool ClientParams::supportsContinuousUpdates() const
  150. {
  151. if (supportsEncoding(pseudoEncodingContinuousUpdates))
  152. return true;
  153. return false;
  154. }