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.

SMsgWriter.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2019 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. //
  20. // SMsgWriter - class for writing RFB messages on the server side.
  21. //
  22. #ifndef __RFB_SMSGWRITER_H__
  23. #define __RFB_SMSGWRITER_H__
  24. #include <rdr/types.h>
  25. #include <rfb/encodings.h>
  26. #include <rfb/ScreenSet.h>
  27. namespace rdr { class OutStream; }
  28. namespace rfb {
  29. class ClientParams;
  30. class PixelFormat;
  31. struct ScreenSet;
  32. class SMsgWriter {
  33. public:
  34. SMsgWriter(ClientParams* client, rdr::OutStream* os);
  35. virtual ~SMsgWriter();
  36. // writeServerInit() must only be called at the appropriate time in the
  37. // protocol initialisation.
  38. void writeServerInit(rdr::U16 width, rdr::U16 height,
  39. const PixelFormat& pf, const char* name);
  40. // Methods to write normal protocol messages
  41. // writeSetColourMapEntries() writes a setColourMapEntries message, using
  42. // the given colour entries.
  43. void writeSetColourMapEntries(int firstColour, int nColours,
  44. const rdr::U16 red[],
  45. const rdr::U16 green[],
  46. const rdr::U16 blue[]);
  47. // writeBell() does the obvious thing.
  48. void writeBell();
  49. void writeServerCutText(const char* str);
  50. void writeClipboardCaps(rdr::U32 caps, const rdr::U32* lengths);
  51. void writeClipboardRequest(rdr::U32 flags);
  52. void writeClipboardPeek(rdr::U32 flags);
  53. void writeClipboardNotify(rdr::U32 flags);
  54. void writeClipboardProvide(rdr::U32 flags, const size_t* lengths,
  55. const rdr::U8* const* data);
  56. // writeFence() sends a new fence request or response to the client.
  57. void writeFence(rdr::U32 flags, unsigned len, const char data[]);
  58. // writeEndOfContinuousUpdates() indicates that we have left continuous
  59. // updates mode.
  60. void writeEndOfContinuousUpdates();
  61. // writeDesktopSize() won't actually write immediately, but will
  62. // write the relevant pseudo-rectangle as part of the next update.
  63. void writeDesktopSize(rdr::U16 reason, rdr::U16 result=0);
  64. void writeSetDesktopName();
  65. // Like setDesktopSize, we can't just write out a cursor message
  66. // immediately.
  67. void writeCursor();
  68. // Notifies the client that the cursor pointer was moved by the server.
  69. void writeCursorPos();
  70. // Same for LED state message
  71. void writeLEDState();
  72. // And QEMU keyboard event handshake
  73. void writeQEMUKeyEvent();
  74. // needFakeUpdate() returns true when an immediate update is needed in
  75. // order to flush out pseudo-rectangles to the client.
  76. bool needFakeUpdate();
  77. // needNoDataUpdate() returns true when an update without any
  78. // framebuffer changes need to be sent (using writeNoDataUpdate()).
  79. // Commonly this is an update that modifies the size of the framebuffer
  80. // or the screen layout.
  81. bool needNoDataUpdate();
  82. // writeNoDataUpdate() write a framebuffer update containing only
  83. // pseudo-rectangles.
  84. void writeNoDataUpdate();
  85. // writeFramebufferUpdateStart() initiates an update which you can fill
  86. // in using writeCopyRect() and encoders. Finishing the update by calling
  87. // writeFramebufferUpdateEnd().
  88. void writeFramebufferUpdateStart(int nRects);
  89. void writeFramebufferUpdateEnd();
  90. // There is no explicit encoder for CopyRect rects.
  91. void writeCopyRect(const Rect& r, int srcX, int srcY);
  92. // Encoders should call these to mark the start and stop of individual
  93. // rects.
  94. void startRect(const Rect& r, int enc);
  95. void endRect();
  96. protected:
  97. void startMsg(int type);
  98. void endMsg();
  99. void writePseudoRects();
  100. void writeNoDataRects();
  101. void writeSetDesktopSizeRect(int width, int height);
  102. void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result,
  103. int fb_width, int fb_height,
  104. const ScreenSet& layout);
  105. void writeSetDesktopNameRect(const char *name);
  106. void writeSetCursorRect(int width, int height,
  107. int hotspotX, int hotspotY,
  108. const void* data, const void* mask);
  109. void writeSetXCursorRect(int width, int height,
  110. int hotspotX, int hotspotY,
  111. const void* data, const void* mask);
  112. void writeSetCursorWithAlphaRect(int width, int height,
  113. int hotspotX, int hotspotY,
  114. const rdr::U8* data);
  115. void writeSetVMwareCursorRect(int width, int height,
  116. int hotspotX, int hotspotY,
  117. const rdr::U8* data);
  118. void writeSetVMwareCursorPositionRect(int hotspotX, int hotspotY);
  119. void writeLEDStateRect(rdr::U8 state);
  120. void writeQEMUKeyEventRect();
  121. ClientParams* client;
  122. rdr::OutStream* os;
  123. int nRectsInUpdate;
  124. int nRectsInHeader;
  125. bool needSetDesktopName;
  126. bool needCursor;
  127. bool needCursorPos;
  128. bool needLEDState;
  129. bool needQEMUKeyEvent;
  130. typedef struct {
  131. rdr::U16 reason, result;
  132. } ExtendedDesktopSizeMsg;
  133. std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs;
  134. };
  135. }
  136. #endif