blob: 6c665b658d44aba547a517e612442199adb8fdec [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman7638e9c2014-01-16 13:12:40 +01002 * Copyright 2009-2014 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
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
23#ifndef __RFB_SMSGWRITER_H__
24#define __RFB_SMSGWRITER_H__
25
26#include <rdr/types.h>
27#include <rfb/encodings.h>
Pierre Ossman04e62db2009-03-23 16:57:07 +000028#include <rfb/ScreenSet.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029
30namespace rdr { class OutStream; }
31
32namespace rfb {
33
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034 class ConnParams;
Steve Kondik1f5d4b12017-07-08 02:00:49 -070035 struct ScreenSet;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000037 class SMsgWriter {
38 public:
Pierre Ossman7638e9c2014-01-16 13:12:40 +010039 SMsgWriter(ConnParams* cp, rdr::OutStream* os);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040 virtual ~SMsgWriter();
41
42 // writeServerInit() must only be called at the appropriate time in the
43 // protocol initialisation.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010044 void writeServerInit();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000045
46 // Methods to write normal protocol messages
47
48 // writeSetColourMapEntries() writes a setColourMapEntries message, using
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010049 // the given colour entries.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010050 void writeSetColourMapEntries(int firstColour, int nColours,
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010051 const rdr::U16 red[],
52 const rdr::U16 green[],
53 const rdr::U16 blue[]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054
55 // writeBell() and writeServerCutText() do the obvious thing.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010056 void writeBell();
57 void writeServerCutText(const char* str, int len);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000058
Pierre Ossmanc754cce2011-11-14 15:44:11 +000059 // writeFence() sends a new fence request or response to the client.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010060 void writeFence(rdr::U32 flags, unsigned len, const char data[]);
Pierre Ossmanc754cce2011-11-14 15:44:11 +000061
Pierre Ossmanc898d9a2011-11-14 16:22:23 +000062 // writeEndOfContinuousUpdates() indicates that we have left continuous
63 // updates mode.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010064 void writeEndOfContinuousUpdates();
Pierre Ossmanc898d9a2011-11-14 16:22:23 +000065
Pierre Ossman7638e9c2014-01-16 13:12:40 +010066 // writeSetDesktopSize() won't actually write immediately, but will
67 // write the relevant pseudo-rectangle as part of the next update.
68 bool writeSetDesktopSize();
Pierre Ossman04e62db2009-03-23 16:57:07 +000069 // Same thing for the extended version. The first version queues up a
70 // generic update of the current server state, but the second queues a
71 // specific message.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010072 bool writeExtendedDesktopSize();
73 bool writeExtendedDesktopSize(rdr::U16 reason, rdr::U16 result,
74 int fb_width, int fb_height,
75 const ScreenSet& layout);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000076
Pierre Ossman7638e9c2014-01-16 13:12:40 +010077 bool writeSetDesktopName();
Peter Åstrandc39e0782009-01-15 12:21:42 +000078
Pierre Ossman126e5642014-02-13 14:40:25 +010079 // Like setDesktopSize, we can't just write out a cursor message
80 // immediately.
81 bool writeSetCursor();
82 bool writeSetXCursor();
Pierre Ossman8053c8e2017-02-21 12:59:04 +010083 bool writeSetCursorWithAlpha();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000084
85 // needFakeUpdate() returns true when an immediate update is needed in
Pierre Ossmane9962f72009-04-23 12:31:42 +000086 // order to flush out pseudo-rectangles to the client.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010087 bool needFakeUpdate();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000088
Pierre Ossmane9962f72009-04-23 12:31:42 +000089 // needNoDataUpdate() returns true when an update without any
90 // framebuffer changes need to be sent (using writeNoDataUpdate()).
91 // Commonly this is an update that modifies the size of the framebuffer
92 // or the screen layout.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010093 bool needNoDataUpdate();
Pierre Ossmane9962f72009-04-23 12:31:42 +000094
95 // writeNoDataUpdate() write a framebuffer update containing only
96 // pseudo-rectangles.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010097 void writeNoDataUpdate();
Pierre Ossmane9962f72009-04-23 12:31:42 +000098
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +010099 // writeFramebufferUpdateStart() initiates an update which you can fill
100 // in using writeCopyRect() and encoders. Finishing the update by calling
101 // writeFramebufferUpdateEnd().
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100102 void writeFramebufferUpdateStart(int nRects);
103 void writeFramebufferUpdateEnd();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000104
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +0100105 // There is no explicit encoder for CopyRect rects.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100106 void writeCopyRect(const Rect& r, int srcX, int srcY);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000107
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +0100108 // Encoders should call these to mark the start and stop of individual
109 // rects.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100110 void startRect(const Rect& r, int enc);
111 void endRect();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000112
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000113 protected:
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100114 void startMsg(int type);
115 void endMsg();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000116
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100117 void writePseudoRects();
118 void writeNoDataRects();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000119
Pierre Ossmanc0b1aa02014-01-16 13:39:05 +0100120 void writeSetDesktopSizeRect(int width, int height);
121 void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result,
122 int fb_width, int fb_height,
123 const ScreenSet& layout);
124 void writeSetDesktopNameRect(const char *name);
Pierre Ossman126e5642014-02-13 14:40:25 +0100125 void writeSetCursorRect(int width, int height,
126 int hotspotX, int hotspotY,
127 const void* data, const void* mask);
128 void writeSetXCursorRect(int width, int height,
129 int hotspotX, int hotspotY,
Pierre Ossman126e5642014-02-13 14:40:25 +0100130 const void* data, const void* mask);
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100131 void writeSetCursorWithAlphaRect(int width, int height,
132 int hotspotX, int hotspotY,
133 const rdr::U8* data);
Pierre Ossmanc0b1aa02014-01-16 13:39:05 +0100134
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000135 ConnParams* cp;
136 rdr::OutStream* os;
137
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100138 int nRectsInUpdate;
139 int nRectsInHeader;
140
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100141 bool needSetDesktopSize;
142 bool needExtendedDesktopSize;
143 bool needSetDesktopName;
144 bool needLastRect;
Pierre Ossman126e5642014-02-13 14:40:25 +0100145 bool needSetCursor;
146 bool needSetXCursor;
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100147 bool needSetCursorWithAlpha;
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100148
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100149 typedef struct {
150 rdr::U16 reason, result;
151 int fb_width, fb_height;
152 ScreenSet layout;
153 } ExtendedDesktopSizeMsg;
154
155 std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000156 };
157}
158#endif