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