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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2014 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() and writeServerCutText() do the obvious thing.
  48. void writeBell();
  49. void writeServerCutText(const char* str, int len);
  50. // writeFence() sends a new fence request or response to the client.
  51. void writeFence(rdr::U32 flags, unsigned len, const char data[]);
  52. // writeEndOfContinuousUpdates() indicates that we have left continuous
  53. // updates mode.
  54. void writeEndOfContinuousUpdates();
  55. // writeDesktopSize() won't actually write immediately, but will
  56. // write the relevant pseudo-rectangle as part of the next update.
  57. void writeDesktopSize(rdr::U16 reason, rdr::U16 result=0);
  58. void writeSetDesktopName();
  59. // Like setDesktopSize, we can't just write out a cursor message
  60. // immediately.
  61. void writeCursor();
  62. // Same for LED state message
  63. void writeLEDState();
  64. // And QEMU keyboard event handshake
  65. void writeQEMUKeyEvent();
  66. // needFakeUpdate() returns true when an immediate update is needed in
  67. // order to flush out pseudo-rectangles to the client.
  68. bool needFakeUpdate();
  69. // needNoDataUpdate() returns true when an update without any
  70. // framebuffer changes need to be sent (using writeNoDataUpdate()).
  71. // Commonly this is an update that modifies the size of the framebuffer
  72. // or the screen layout.
  73. bool needNoDataUpdate();
  74. // writeNoDataUpdate() write a framebuffer update containing only
  75. // pseudo-rectangles.
  76. void writeNoDataUpdate();
  77. // writeFramebufferUpdateStart() initiates an update which you can fill
  78. // in using writeCopyRect() and encoders. Finishing the update by calling
  79. // writeFramebufferUpdateEnd().
  80. void writeFramebufferUpdateStart(int nRects);
  81. void writeFramebufferUpdateEnd();
  82. // There is no explicit encoder for CopyRect rects.
  83. void writeCopyRect(const Rect& r, int srcX, int srcY);
  84. // Encoders should call these to mark the start and stop of individual
  85. // rects.
  86. void startRect(const Rect& r, int enc);
  87. void endRect();
  88. protected:
  89. void startMsg(int type);
  90. void endMsg();
  91. void writePseudoRects();
  92. void writeNoDataRects();
  93. void writeSetDesktopSizeRect(int width, int height);
  94. void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result,
  95. int fb_width, int fb_height,
  96. const ScreenSet& layout);
  97. void writeSetDesktopNameRect(const char *name);
  98. void writeSetCursorRect(int width, int height,
  99. int hotspotX, int hotspotY,
  100. const void* data, const void* mask);
  101. void writeSetXCursorRect(int width, int height,
  102. int hotspotX, int hotspotY,
  103. const void* data, const void* mask);
  104. void writeSetCursorWithAlphaRect(int width, int height,
  105. int hotspotX, int hotspotY,
  106. const rdr::U8* data);
  107. void writeLEDStateRect(rdr::U8 state);
  108. void writeQEMUKeyEventRect();
  109. ClientParams* client;
  110. rdr::OutStream* os;
  111. int nRectsInUpdate;
  112. int nRectsInHeader;
  113. bool needSetDesktopName;
  114. bool needCursor;
  115. bool needLEDState;
  116. bool needQEMUKeyEvent;
  117. typedef struct {
  118. rdr::U16 reason, result;
  119. } ExtendedDesktopSizeMsg;
  120. std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs;
  121. };
  122. }
  123. #endif