blob: ddddb0952932188e04c866f13f4704fbd09a20f5 [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
Pierre Ossman0d3ce872018-06-18 15:59:00 +020034 class ClientParams;
Pierre Ossman96728352018-06-20 11:35:05 +020035 class PixelFormat;
Steve Kondik1f5d4b12017-07-08 02:00:49 -070036 struct ScreenSet;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000037
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000038 class SMsgWriter {
39 public:
Pierre Ossman0d3ce872018-06-18 15:59:00 +020040 SMsgWriter(ClientParams* client, rdr::OutStream* os);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 virtual ~SMsgWriter();
42
43 // writeServerInit() must only be called at the appropriate time in the
44 // protocol initialisation.
Pierre Ossman96728352018-06-20 11:35:05 +020045 void writeServerInit(rdr::U16 width, rdr::U16 height,
46 const PixelFormat& pf, const char* name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000047
48 // Methods to write normal protocol messages
49
50 // writeSetColourMapEntries() writes a setColourMapEntries message, using
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010051 // the given colour entries.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010052 void writeSetColourMapEntries(int firstColour, int nColours,
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010053 const rdr::U16 red[],
54 const rdr::U16 green[],
55 const rdr::U16 blue[]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056
57 // writeBell() and writeServerCutText() do the obvious thing.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010058 void writeBell();
59 void writeServerCutText(const char* str, int len);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060
Pierre Ossmanc754cce2011-11-14 15:44:11 +000061 // writeFence() sends a new fence request or response to the client.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010062 void writeFence(rdr::U32 flags, unsigned len, const char data[]);
Pierre Ossmanc754cce2011-11-14 15:44:11 +000063
Pierre Ossmanc898d9a2011-11-14 16:22:23 +000064 // writeEndOfContinuousUpdates() indicates that we have left continuous
65 // updates mode.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010066 void writeEndOfContinuousUpdates();
Pierre Ossmanc898d9a2011-11-14 16:22:23 +000067
Pierre Ossman7638e9c2014-01-16 13:12:40 +010068 // writeSetDesktopSize() won't actually write immediately, but will
69 // write the relevant pseudo-rectangle as part of the next update.
70 bool writeSetDesktopSize();
Pierre Ossman04e62db2009-03-23 16:57:07 +000071 // Same thing for the extended version. The first version queues up a
72 // generic update of the current server state, but the second queues a
73 // specific message.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010074 bool writeExtendedDesktopSize();
75 bool writeExtendedDesktopSize(rdr::U16 reason, rdr::U16 result,
76 int fb_width, int fb_height,
77 const ScreenSet& layout);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000078
Pierre Ossman7638e9c2014-01-16 13:12:40 +010079 bool writeSetDesktopName();
Peter Åstrandc39e0782009-01-15 12:21:42 +000080
Pierre Ossman126e5642014-02-13 14:40:25 +010081 // Like setDesktopSize, we can't just write out a cursor message
82 // immediately.
83 bool writeSetCursor();
84 bool writeSetXCursor();
Pierre Ossman8053c8e2017-02-21 12:59:04 +010085 bool writeSetCursorWithAlpha();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000086
Pierre Ossmanb45a84f2016-12-12 16:59:15 +010087 // Same for LED state message
88 bool writeLEDState();
89
Pierre Ossman5ae28212017-05-16 14:30:38 +020090 // And QEMU keyboard event handshake
91 bool writeQEMUKeyEvent();
92
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093 // needFakeUpdate() returns true when an immediate update is needed in
Pierre Ossmane9962f72009-04-23 12:31:42 +000094 // order to flush out pseudo-rectangles to the client.
Pierre Ossman7638e9c2014-01-16 13:12:40 +010095 bool needFakeUpdate();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000096
Pierre Ossmane9962f72009-04-23 12:31:42 +000097 // 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.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100101 bool needNoDataUpdate();
Pierre Ossmane9962f72009-04-23 12:31:42 +0000102
103 // writeNoDataUpdate() write a framebuffer update containing only
104 // pseudo-rectangles.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100105 void writeNoDataUpdate();
Pierre Ossmane9962f72009-04-23 12:31:42 +0000106
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +0100107 // writeFramebufferUpdateStart() initiates an update which you can fill
108 // in using writeCopyRect() and encoders. Finishing the update by calling
109 // writeFramebufferUpdateEnd().
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100110 void writeFramebufferUpdateStart(int nRects);
111 void writeFramebufferUpdateEnd();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000112
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +0100113 // There is no explicit encoder for CopyRect rects.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100114 void writeCopyRect(const Rect& r, int srcX, int srcY);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000115
Pierre Ossmanfdba3fe2014-01-31 13:12:18 +0100116 // Encoders should call these to mark the start and stop of individual
117 // rects.
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100118 void startRect(const Rect& r, int enc);
119 void endRect();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000120
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000121 protected:
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100122 void startMsg(int type);
123 void endMsg();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000124
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100125 void writePseudoRects();
126 void writeNoDataRects();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000127
Pierre Ossmanc0b1aa02014-01-16 13:39:05 +0100128 void writeSetDesktopSizeRect(int width, int height);
129 void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result,
130 int fb_width, int fb_height,
131 const ScreenSet& layout);
132 void writeSetDesktopNameRect(const char *name);
Pierre Ossman126e5642014-02-13 14:40:25 +0100133 void writeSetCursorRect(int width, int height,
134 int hotspotX, int hotspotY,
135 const void* data, const void* mask);
136 void writeSetXCursorRect(int width, int height,
137 int hotspotX, int hotspotY,
Pierre Ossman126e5642014-02-13 14:40:25 +0100138 const void* data, const void* mask);
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100139 void writeSetCursorWithAlphaRect(int width, int height,
140 int hotspotX, int hotspotY,
141 const rdr::U8* data);
Pierre Ossmanb45a84f2016-12-12 16:59:15 +0100142 void writeLEDStateRect(rdr::U8 state);
Pierre Ossman5ae28212017-05-16 14:30:38 +0200143 void writeQEMUKeyEventRect();
Pierre Ossmanc0b1aa02014-01-16 13:39:05 +0100144
Pierre Ossman0d3ce872018-06-18 15:59:00 +0200145 ClientParams* client;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000146 rdr::OutStream* os;
147
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100148 int nRectsInUpdate;
149 int nRectsInHeader;
150
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100151 bool needSetDesktopSize;
152 bool needExtendedDesktopSize;
153 bool needSetDesktopName;
Pierre Ossman126e5642014-02-13 14:40:25 +0100154 bool needSetCursor;
155 bool needSetXCursor;
Pierre Ossman8053c8e2017-02-21 12:59:04 +0100156 bool needSetCursorWithAlpha;
Pierre Ossmanb45a84f2016-12-12 16:59:15 +0100157 bool needLEDState;
Pierre Ossman5ae28212017-05-16 14:30:38 +0200158 bool needQEMUKeyEvent;
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100159
Pierre Ossman7638e9c2014-01-16 13:12:40 +0100160 typedef struct {
161 rdr::U16 reason, result;
162 int fb_width, fb_height;
163 ScreenSet layout;
164 } ExtendedDesktopSizeMsg;
165
166 std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000167 };
168}
169#endif