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.

CMsgReaderV3.cxx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #include <rfb/PixelFormat.h>
  20. #include <rfb/msgTypes.h>
  21. #include <rfb/Exception.h>
  22. #include <rdr/InStream.h>
  23. #include <rfb/CMsgReaderV3.h>
  24. #include <rfb/CMsgHandler.h>
  25. #include <rfb/util.h>
  26. #include <rfb/ScreenSet.h>
  27. #include <stdio.h>
  28. using namespace rfb;
  29. CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
  30. : CMsgReader(handler, is), nUpdateRectsLeft(0)
  31. {
  32. }
  33. CMsgReaderV3::~CMsgReaderV3()
  34. {
  35. }
  36. void CMsgReaderV3::readServerInit()
  37. {
  38. int width = is->readU16();
  39. int height = is->readU16();
  40. handler->setDesktopSize(width, height);
  41. PixelFormat pf;
  42. pf.read(is);
  43. handler->setPixelFormat(pf);
  44. CharArray name(is->readString());
  45. handler->setName(name.buf);
  46. handler->serverInit();
  47. }
  48. void CMsgReaderV3::readMsg()
  49. {
  50. if (nUpdateRectsLeft == 0) {
  51. int type = is->readU8();
  52. switch (type) {
  53. case msgTypeFramebufferUpdate: readFramebufferUpdate(); break;
  54. case msgTypeSetColourMapEntries: readSetColourMapEntries(); break;
  55. case msgTypeBell: readBell(); break;
  56. case msgTypeServerCutText: readServerCutText(); break;
  57. default:
  58. fprintf(stderr, "unknown message type %d\n", type);
  59. throw Exception("unknown message type");
  60. }
  61. } else {
  62. int x = is->readU16();
  63. int y = is->readU16();
  64. int w = is->readU16();
  65. int h = is->readU16();
  66. unsigned int encoding = is->readU32();
  67. switch (encoding) {
  68. case pseudoEncodingDesktopSize:
  69. handler->setDesktopSize(w, h);
  70. break;
  71. case pseudoEncodingExtendedDesktopSize:
  72. readExtendedDesktopSize(x, y, w, h);
  73. break;
  74. case pseudoEncodingDesktopName:
  75. readSetDesktopName(x, y, w, h);
  76. break;
  77. case pseudoEncodingCursor:
  78. readSetCursor(w, h, Point(x,y));
  79. break;
  80. case pseudoEncodingLastRect:
  81. nUpdateRectsLeft = 1; // this rectangle is the last one
  82. break;
  83. default:
  84. readRect(Rect(x, y, x+w, y+h), encoding);
  85. break;
  86. };
  87. nUpdateRectsLeft--;
  88. if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd();
  89. }
  90. }
  91. void CMsgReaderV3::readFramebufferUpdate()
  92. {
  93. is->skip(1);
  94. nUpdateRectsLeft = is->readU16();
  95. handler->framebufferUpdateStart();
  96. }
  97. void CMsgReaderV3::readSetDesktopName(int x, int y, int w, int h)
  98. {
  99. char* name = is->readString();
  100. if (x || y || w || h) {
  101. fprintf(stderr, "Ignoring DesktopName rect with non-zero position/size\n");
  102. } else {
  103. handler->setName(name);
  104. }
  105. delete [] name;
  106. }
  107. void CMsgReaderV3::readExtendedDesktopSize(int x, int y, int w, int h)
  108. {
  109. unsigned int screens, i;
  110. rdr::U32 id, flags;
  111. int sx, sy, sw, sh;
  112. ScreenSet layout;
  113. screens = is->readU8();
  114. is->skip(3);
  115. for (i = 0;i < screens;i++) {
  116. id = is->readU32();
  117. sx = is->readU16();
  118. sy = is->readU16();
  119. sw = is->readU16();
  120. sh = is->readU16();
  121. flags = is->readU32();
  122. layout.add_screen(Screen(id, sx, sy, sw, sh, flags));
  123. }
  124. handler->setExtendedDesktopSize(x, y, w, h, layout);
  125. }