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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <stdio.h>
  19. #include <rdr/InStream.h>
  20. #include <rdr/OutStream.h>
  21. #include <rfb/Exception.h>
  22. #include <rfb/encodings.h>
  23. #include <rfb/Encoder.h>
  24. #include <rfb/ConnParams.h>
  25. #include <rfb/util.h>
  26. using namespace rfb;
  27. ConnParams::ConnParams()
  28. : majorVersion(0), minorVersion(0), tightExtensionsEnabled(false),
  29. width(0), height(0), useCopyRect(false),
  30. supportsLocalCursor(false), supportsLocalXCursor(false),
  31. supportsDesktopResize(false), supportsExtendedDesktopSize(false),
  32. supportsDesktopRename(false), supportsLastRect(false),
  33. supportsSetDesktopSize(false),
  34. customCompressLevel(false), compressLevel(6),
  35. noJpeg(false), qualityLevel(-1),
  36. name_(0), nEncodings_(0), encodings_(0),
  37. currentEncoding_(encodingRaw), verStrPos(0)
  38. {
  39. setName("");
  40. }
  41. ConnParams::~ConnParams()
  42. {
  43. delete [] name_;
  44. delete [] encodings_;
  45. }
  46. bool ConnParams::readVersion(rdr::InStream* is, bool* done)
  47. {
  48. if (verStrPos >= 12) return false;
  49. while (is->checkNoWait(1) && verStrPos < 12) {
  50. verStr[verStrPos++] = is->readU8();
  51. }
  52. if (verStrPos < 12) {
  53. *done = false;
  54. return true;
  55. }
  56. *done = true;
  57. verStr[12] = 0;
  58. return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
  59. }
  60. void ConnParams::writeVersion(rdr::OutStream* os)
  61. {
  62. char str[13];
  63. sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
  64. os->writeBytes(str, 12);
  65. os->flush();
  66. }
  67. void ConnParams::setPF(const PixelFormat& pf)
  68. {
  69. pf_ = pf;
  70. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  71. throw Exception("setPF: not 8, 16 or 32 bpp?");
  72. }
  73. void ConnParams::setName(const char* name)
  74. {
  75. delete [] name_;
  76. name_ = strDup(name);
  77. }
  78. void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  79. {
  80. if (nEncodings > nEncodings_) {
  81. delete [] encodings_;
  82. encodings_ = new rdr::S32[nEncodings];
  83. }
  84. nEncodings_ = nEncodings;
  85. useCopyRect = false;
  86. supportsLocalCursor = false;
  87. supportsDesktopResize = false;
  88. supportsExtendedDesktopSize = false;
  89. supportsLocalXCursor = false;
  90. supportsLastRect = false;
  91. customCompressLevel = false;
  92. compressLevel = -1;
  93. noJpeg = true;
  94. qualityLevel = -1;
  95. currentEncoding_ = encodingRaw;
  96. for (int i = nEncodings-1; i >= 0; i--) {
  97. encodings_[i] = encodings[i];
  98. if (encodings[i] == encodingCopyRect)
  99. useCopyRect = true;
  100. else if (encodings[i] == pseudoEncodingCursor)
  101. supportsLocalCursor = true;
  102. else if (encodings[i] == pseudoEncodingXCursor)
  103. supportsLocalXCursor = true;
  104. else if (encodings[i] == pseudoEncodingDesktopSize)
  105. supportsDesktopResize = true;
  106. else if (encodings[i] == pseudoEncodingExtendedDesktopSize)
  107. supportsExtendedDesktopSize = true;
  108. else if (encodings[i] == pseudoEncodingDesktopName)
  109. supportsDesktopRename = true;
  110. else if (encodings[i] == pseudoEncodingLastRect)
  111. supportsLastRect = true;
  112. else if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  113. encodings[i] <= pseudoEncodingCompressLevel9) {
  114. customCompressLevel = true;
  115. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  116. } else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  117. encodings[i] <= pseudoEncodingQualityLevel9) {
  118. noJpeg = false;
  119. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  120. } else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
  121. currentEncoding_ = encodings[i];
  122. }
  123. }