blob: d792688093663adb0b93bb8724a5f2b99333cd38 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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
22#ifndef __RFB_SMSGWRITER_H__
23#define __RFB_SMSGWRITER_H__
24
25#include <rdr/types.h>
26#include <rfb/encodings.h>
Pierre Ossmanc5e25602009-03-20 12:59:05 +000027#include <rfb/screenTypes.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000028#include <rfb/Encoder.h>
Constantin Kaplinsky46ba45a2007-08-31 21:31:34 +000029#include <rfb/PixelBuffer.h>
Pierre Ossman04e62db2009-03-23 16:57:07 +000030#include <rfb/ScreenSet.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000031
32namespace rdr { class OutStream; }
33
34namespace rfb {
35
36 class PixelFormat;
37 class ConnParams;
38 class ImageGetter;
39 class ColourMap;
40 class Region;
41 class UpdateInfo;
42
43 class WriteSetCursorCallback {
44 public:
45 virtual void writeSetCursorCallback() = 0;
46 };
47
48 class SMsgWriter {
49 public:
50 virtual ~SMsgWriter();
51
52 // writeServerInit() must only be called at the appropriate time in the
53 // protocol initialisation.
54 virtual void writeServerInit()=0;
55
56 // Methods to write normal protocol messages
57
58 // writeSetColourMapEntries() writes a setColourMapEntries message, using
59 // the given ColourMap object to lookup the RGB values of the given range
60 // of colours.
61 virtual void writeSetColourMapEntries(int firstColour, int nColours,
62 ColourMap* cm);
63
64 // writeBell() and writeServerCutText() do the obvious thing.
65 virtual void writeBell();
66 virtual void writeServerCutText(const char* str, int len);
67
68 // setupCurrentEncoder() should be called before each framebuffer update,
69 // prior to calling getNumRects() or writeFramebufferUpdateStart().
70 void setupCurrentEncoder();
71
72 // getNumRects() computes the number of sub-rectangles that will compose a
73 // given rectangle, for current encoder.
74 int getNumRects(const Rect &r);
75
76 // writeSetDesktopSize() on a V3 writer won't actually write immediately,
77 // but will write the relevant pseudo-rectangle as part of the next update.
78 virtual bool writeSetDesktopSize()=0;
Pierre Ossman04e62db2009-03-23 16:57:07 +000079 // Same thing for the extended version. The first version queues up a
80 // generic update of the current server state, but the second queues a
81 // specific message.
82 virtual bool writeExtendedDesktopSize()=0;
83 virtual bool writeExtendedDesktopSize(rdr::U16 reason, rdr::U16 result,
84 int fb_width, int fb_height,
85 const ScreenSet& layout)=0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000086
Peter Åstrandc39e0782009-01-15 12:21:42 +000087 virtual bool writeSetDesktopName()=0;
88
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000089 // Like setDesktopSize, we can't just write out a setCursor message
90 // immediately on a V3 writer. Instead of calling writeSetCursor()
91 // directly, you must call cursorChange(), and then invoke writeSetCursor()
92 // in response to the writeSetCursorCallback() callback. For a V3 writer
93 // this will happen when the next update is sent.
94 virtual void cursorChange(WriteSetCursorCallback* cb)=0;
95 virtual void writeSetCursor(int width, int height, const Point& hotspot,
96 void* data, void* mask)=0;
97 virtual void writeSetXCursor(int width, int height, int hotspotX,
98 int hotspotY, void* data, void* mask)=0;
99
100 // needFakeUpdate() returns true when an immediate update is needed in
Pierre Ossmane9962f72009-04-23 12:31:42 +0000101 // order to flush out pseudo-rectangles to the client.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000102 virtual bool needFakeUpdate();
103
104 // writeFramebufferUpdate() writes a framebuffer update using the given
105 // UpdateInfo and ImageGetter. On a V3 writer this may have
106 // pseudo-rectangles for setDesktopSize and setCursor added to it, and so
107 // may invoke writeSetCursorCallback().
Constantin Kaplinskyfe6b5692007-08-31 15:44:12 +0000108 //
Constantin Kaplinskyfe0db842007-08-31 21:14:45 +0000109 // FIXME: This function is not used because it incorrectly computes
Constantin Kaplinskyfe6b5692007-08-31 15:44:12 +0000110 // the number of rectangles if the Tight encoder is used.
111 /*
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000112 virtual void writeFramebufferUpdate(const UpdateInfo& ui, ImageGetter* ig,
113 Region* updatedRegion);
Constantin Kaplinskyfe6b5692007-08-31 15:44:12 +0000114 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000115
Pierre Ossmane9962f72009-04-23 12:31:42 +0000116 // needNoDataUpdate() returns true when an update without any
117 // framebuffer changes need to be sent (using writeNoDataUpdate()).
118 // Commonly this is an update that modifies the size of the framebuffer
119 // or the screen layout.
120 virtual bool needNoDataUpdate();
121
122 // writeNoDataUpdate() write a framebuffer update containing only
123 // pseudo-rectangles.
124 virtual void writeNoDataUpdate();
125
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000126 // writeRects() accepts an UpdateInfo (changed & copied regions) and an
127 // ImageGetter to fetch pixels from. It then calls writeCopyRect() and
128 // writeRect() as appropriate. writeFramebufferUpdateStart() must be used
129 // before the first writeRects() call and writeFrameBufferUpdateEnd() after
130 // the last one. It returns the actual region sent to the client, which
131 // may be smaller than the update passed in.
DRCffe09d62011-08-17 02:27:59 +0000132 virtual void writeRects(const UpdateInfo& update, TransImageGetter* ig,
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000133 Region* updatedRegion);
134
135 // To construct a framebuffer update you can call
136 // writeFramebufferUpdateStart(), followed by a number of writeCopyRect()s
137 // and writeRect()s, finishing with writeFramebufferUpdateEnd(). If you
138 // know the exact number of rectangles ahead of time you can specify it to
139 // writeFramebufferUpdateStart() which can be more efficient.
140 virtual void writeFramebufferUpdateStart(int nRects)=0;
141 virtual void writeFramebufferUpdateStart()=0;
142 virtual void writeFramebufferUpdateEnd()=0;
143
144 // writeRect() tries to write the given rectangle. If it is unable to
145 // write the whole rectangle it returns false and sets actual to the actual
146 // rectangle which was updated.
DRCffe09d62011-08-17 02:27:59 +0000147 virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
Peter Åstrand98fe98c2010-02-10 07:43:02 +0000148 virtual bool writeRect(const Rect& r, int encoding,
DRCffe09d62011-08-17 02:27:59 +0000149 TransImageGetter* ig, Rect* actual);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000150
151 virtual void writeCopyRect(const Rect& r, int srcX, int srcY);
152
Peter Åstrand98fe98c2010-02-10 07:43:02 +0000153 virtual void startRect(const Rect& r, int enc)=0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000154 virtual void endRect()=0;
155
156 ConnParams* getConnParams() { return cp; }
157 rdr::OutStream* getOutStream() { return os; }
158 rdr::U8* getImageBuf(int required, int requested=0, int* nPixels=0);
159 int bpp();
160
161 int getUpdatesSent() { return updatesSent; }
162 int getRectsSent(int encoding) { return rectsSent[encoding]; }
163 int getBytesSent(int encoding) { return bytesSent[encoding]; }
DRC887c5fd2011-08-19 03:13:47 +0000164 rdr::U64 getRawBytesEquivalent() { return rawBytesEquivalent; }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000165
166 int imageBufIdealSize;
167
168 protected:
169 SMsgWriter(ConnParams* cp, rdr::OutStream* os);
170
171 virtual void startMsg(int type)=0;
172 virtual void endMsg()=0;
173
174 ConnParams* cp;
175 rdr::OutStream* os;
176
177 Encoder* encoders[encodingMax+1];
178 int lenBeforeRect;
Peter Åstrand98fe98c2010-02-10 07:43:02 +0000179 int currentEncoding;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000180 int updatesSent;
181 int bytesSent[encodingMax+1];
182 int rectsSent[encodingMax+1];
DRC887c5fd2011-08-19 03:13:47 +0000183 rdr::U64 rawBytesEquivalent;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000184
185 rdr::U8* imageBuf;
186 int imageBufSize;
187 };
188}
189#endif