Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SMsgWriter.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. //
  19. // SMsgWriter - class for writing RFB messages on the server side.
  20. //
  21. #ifndef __RFB_SMSGWRITER_H__
  22. #define __RFB_SMSGWRITER_H__
  23. #include <rdr/types.h>
  24. #include <rfb/encodings.h>
  25. #include <rfb/screenTypes.h>
  26. #include <rfb/Encoder.h>
  27. #include <rfb/PixelBuffer.h>
  28. #include <rfb/ScreenSet.h>
  29. namespace rdr { class OutStream; }
  30. namespace rfb {
  31. class PixelFormat;
  32. class ConnParams;
  33. class ImageGetter;
  34. class ColourMap;
  35. class Region;
  36. class UpdateInfo;
  37. class WriteSetCursorCallback {
  38. public:
  39. virtual void writeSetCursorCallback() = 0;
  40. };
  41. class SMsgWriter {
  42. public:
  43. virtual ~SMsgWriter();
  44. // writeServerInit() must only be called at the appropriate time in the
  45. // protocol initialisation.
  46. virtual void writeServerInit()=0;
  47. // Methods to write normal protocol messages
  48. // writeSetColourMapEntries() writes a setColourMapEntries message, using
  49. // the given ColourMap object to lookup the RGB values of the given range
  50. // of colours.
  51. virtual void writeSetColourMapEntries(int firstColour, int nColours,
  52. ColourMap* cm);
  53. // writeBell() and writeServerCutText() do the obvious thing.
  54. virtual void writeBell();
  55. virtual void writeServerCutText(const char* str, int len);
  56. // setupCurrentEncoder() should be called before each framebuffer update,
  57. // prior to calling getNumRects() or writeFramebufferUpdateStart().
  58. void setupCurrentEncoder();
  59. // getNumRects() computes the number of sub-rectangles that will compose a
  60. // given rectangle, for current encoder.
  61. int getNumRects(const Rect &r);
  62. // writeSetDesktopSize() on a V3 writer won't actually write immediately,
  63. // but will write the relevant pseudo-rectangle as part of the next update.
  64. virtual bool writeSetDesktopSize()=0;
  65. // Same thing for the extended version. The first version queues up a
  66. // generic update of the current server state, but the second queues a
  67. // specific message.
  68. virtual bool writeExtendedDesktopSize()=0;
  69. virtual bool writeExtendedDesktopSize(rdr::U16 reason, rdr::U16 result,
  70. int fb_width, int fb_height,
  71. const ScreenSet& layout)=0;
  72. virtual bool writeSetDesktopName()=0;
  73. // Like setDesktopSize, we can't just write out a setCursor message
  74. // immediately on a V3 writer. Instead of calling writeSetCursor()
  75. // directly, you must call cursorChange(), and then invoke writeSetCursor()
  76. // in response to the writeSetCursorCallback() callback. For a V3 writer
  77. // this will happen when the next update is sent.
  78. virtual void cursorChange(WriteSetCursorCallback* cb)=0;
  79. virtual void writeSetCursor(int width, int height, const Point& hotspot,
  80. void* data, void* mask)=0;
  81. virtual void writeSetXCursor(int width, int height, int hotspotX,
  82. int hotspotY, void* data, void* mask)=0;
  83. // needFakeUpdate() returns true when an immediate update is needed in
  84. // order to flush out pseudo-rectangles to the client.
  85. virtual bool needFakeUpdate();
  86. // writeFramebufferUpdate() writes a framebuffer update using the given
  87. // UpdateInfo and ImageGetter. On a V3 writer this may have
  88. // pseudo-rectangles for setDesktopSize and setCursor added to it, and so
  89. // may invoke writeSetCursorCallback().
  90. //
  91. // FIXME: This function is not used because it incorrectly computes
  92. // the number of rectangles if the Tight encoder is used.
  93. /*
  94. virtual void writeFramebufferUpdate(const UpdateInfo& ui, ImageGetter* ig,
  95. Region* updatedRegion);
  96. */
  97. // needNoDataUpdate() returns true when an update without any
  98. // framebuffer changes need to be sent (using writeNoDataUpdate()).
  99. // Commonly this is an update that modifies the size of the framebuffer
  100. // or the screen layout.
  101. virtual bool needNoDataUpdate();
  102. // writeNoDataUpdate() write a framebuffer update containing only
  103. // pseudo-rectangles.
  104. virtual void writeNoDataUpdate();
  105. // writeRects() accepts an UpdateInfo (changed & copied regions) and an
  106. // ImageGetter to fetch pixels from. It then calls writeCopyRect() and
  107. // writeRect() as appropriate. writeFramebufferUpdateStart() must be used
  108. // before the first writeRects() call and writeFrameBufferUpdateEnd() after
  109. // the last one. It returns the actual region sent to the client, which
  110. // may be smaller than the update passed in.
  111. virtual void writeRects(const UpdateInfo& update, ImageGetter* ig,
  112. Region* updatedRegion);
  113. // To construct a framebuffer update you can call
  114. // writeFramebufferUpdateStart(), followed by a number of writeCopyRect()s
  115. // and writeRect()s, finishing with writeFramebufferUpdateEnd(). If you
  116. // know the exact number of rectangles ahead of time you can specify it to
  117. // writeFramebufferUpdateStart() which can be more efficient.
  118. virtual void writeFramebufferUpdateStart(int nRects)=0;
  119. virtual void writeFramebufferUpdateStart()=0;
  120. virtual void writeFramebufferUpdateEnd()=0;
  121. // writeRect() tries to write the given rectangle. If it is unable to
  122. // write the whole rectangle it returns false and sets actual to the actual
  123. // rectangle which was updated.
  124. virtual bool writeRect(const Rect& r, ImageGetter* ig, Rect* actual);
  125. virtual bool writeRect(const Rect& r, int encoding,
  126. ImageGetter* ig, Rect* actual);
  127. virtual void writeCopyRect(const Rect& r, int srcX, int srcY);
  128. virtual void startRect(const Rect& r, int enc)=0;
  129. virtual void endRect()=0;
  130. ConnParams* getConnParams() { return cp; }
  131. rdr::OutStream* getOutStream() { return os; }
  132. rdr::U8* getImageBuf(int required, int requested=0, int* nPixels=0);
  133. int bpp();
  134. int getUpdatesSent() { return updatesSent; }
  135. int getRectsSent(int encoding) { return rectsSent[encoding]; }
  136. int getBytesSent(int encoding) { return bytesSent[encoding]; }
  137. int getRawBytesEquivalent() { return rawBytesEquivalent; }
  138. int imageBufIdealSize;
  139. protected:
  140. SMsgWriter(ConnParams* cp, rdr::OutStream* os);
  141. virtual void startMsg(int type)=0;
  142. virtual void endMsg()=0;
  143. ConnParams* cp;
  144. rdr::OutStream* os;
  145. Encoder* encoders[encodingMax+1];
  146. int lenBeforeRect;
  147. int currentEncoding;
  148. int updatesSent;
  149. int bytesSent[encodingMax+1];
  150. int rectsSent[encodingMax+1];
  151. int rawBytesEquivalent;
  152. rdr::U8* imageBuf;
  153. int imageBufSize;
  154. };
  155. }
  156. #endif