Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 2 | * Copyright 2009-2019 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 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 Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 28 | #include <rfb/ScreenSet.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | |
| 30 | namespace rdr { class OutStream; } |
| 31 | |
| 32 | namespace rfb { |
| 33 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 34 | class ClientParams; |
Pierre Ossman | 9672835 | 2018-06-20 11:35:05 +0200 | [diff] [blame] | 35 | class PixelFormat; |
Steve Kondik | 1f5d4b1 | 2017-07-08 02:00:49 -0700 | [diff] [blame] | 36 | struct ScreenSet; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 37 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 38 | class SMsgWriter { |
| 39 | public: |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 40 | SMsgWriter(ClientParams* client, rdr::OutStream* os); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | virtual ~SMsgWriter(); |
| 42 | |
| 43 | // writeServerInit() must only be called at the appropriate time in the |
| 44 | // protocol initialisation. |
Pierre Ossman | 9672835 | 2018-06-20 11:35:05 +0200 | [diff] [blame] | 45 | void writeServerInit(rdr::U16 width, rdr::U16 height, |
| 46 | const PixelFormat& pf, const char* name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 47 | |
| 48 | // Methods to write normal protocol messages |
| 49 | |
| 50 | // writeSetColourMapEntries() writes a setColourMapEntries message, using |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 51 | // the given colour entries. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 52 | void writeSetColourMapEntries(int firstColour, int nColours, |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 53 | const rdr::U16 red[], |
| 54 | const rdr::U16 green[], |
| 55 | const rdr::U16 blue[]); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 57 | // writeBell() does the obvious thing. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 58 | void writeBell(); |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 59 | |
Pierre Ossman | 66f1db5 | 2019-05-02 12:32:03 +0200 | [diff] [blame] | 60 | void writeServerCutText(const char* str); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 61 | |
Pierre Ossman | 0ff2655 | 2016-02-05 10:26:56 +0100 | [diff] [blame] | 62 | void writeClipboardCaps(rdr::U32 caps, const rdr::U32* lengths); |
| 63 | void writeClipboardRequest(rdr::U32 flags); |
| 64 | void writeClipboardPeek(rdr::U32 flags); |
| 65 | void writeClipboardNotify(rdr::U32 flags); |
| 66 | void writeClipboardProvide(rdr::U32 flags, const size_t* lengths, |
| 67 | const rdr::U8* const* data); |
| 68 | |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 69 | // writeFence() sends a new fence request or response to the client. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 70 | void writeFence(rdr::U32 flags, unsigned len, const char data[]); |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 71 | |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 72 | // writeEndOfContinuousUpdates() indicates that we have left continuous |
| 73 | // updates mode. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 74 | void writeEndOfContinuousUpdates(); |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 75 | |
Pierre Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 76 | // writeDesktopSize() won't actually write immediately, but will |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 77 | // write the relevant pseudo-rectangle as part of the next update. |
Pierre Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 78 | void writeDesktopSize(rdr::U16 reason, rdr::U16 result=0); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | |
Pierre Ossman | 7b8bc43 | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 80 | void writeSetDesktopName(); |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 81 | |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 82 | // Like setDesktopSize, we can't just write out a cursor message |
| 83 | // immediately. |
Pierre Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 84 | void writeCursor(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 85 | |
Pierre Ossman | b45a84f | 2016-12-12 16:59:15 +0100 | [diff] [blame] | 86 | // Same for LED state message |
Pierre Ossman | 7b8bc43 | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 87 | void writeLEDState(); |
Pierre Ossman | b45a84f | 2016-12-12 16:59:15 +0100 | [diff] [blame] | 88 | |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 89 | // And QEMU keyboard event handshake |
Pierre Ossman | 7b8bc43 | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 90 | void writeQEMUKeyEvent(); |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 91 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 92 | // needFakeUpdate() returns true when an immediate update is needed in |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 93 | // order to flush out pseudo-rectangles to the client. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 94 | bool needFakeUpdate(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 95 | |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 96 | // needNoDataUpdate() returns true when an update without any |
| 97 | // framebuffer changes need to be sent (using writeNoDataUpdate()). |
| 98 | // Commonly this is an update that modifies the size of the framebuffer |
| 99 | // or the screen layout. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 100 | bool needNoDataUpdate(); |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 101 | |
| 102 | // writeNoDataUpdate() write a framebuffer update containing only |
| 103 | // pseudo-rectangles. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 104 | void writeNoDataUpdate(); |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 105 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 106 | // writeFramebufferUpdateStart() initiates an update which you can fill |
| 107 | // in using writeCopyRect() and encoders. Finishing the update by calling |
| 108 | // writeFramebufferUpdateEnd(). |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 109 | void writeFramebufferUpdateStart(int nRects); |
| 110 | void writeFramebufferUpdateEnd(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 111 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 112 | // There is no explicit encoder for CopyRect rects. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 113 | void writeCopyRect(const Rect& r, int srcX, int srcY); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 114 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 115 | // Encoders should call these to mark the start and stop of individual |
| 116 | // rects. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 117 | void startRect(const Rect& r, int enc); |
| 118 | void endRect(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 119 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 120 | protected: |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 121 | void startMsg(int type); |
| 122 | void endMsg(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 123 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 124 | void writePseudoRects(); |
| 125 | void writeNoDataRects(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 126 | |
Pierre Ossman | c0b1aa0 | 2014-01-16 13:39:05 +0100 | [diff] [blame] | 127 | void writeSetDesktopSizeRect(int width, int height); |
| 128 | void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result, |
| 129 | int fb_width, int fb_height, |
| 130 | const ScreenSet& layout); |
| 131 | void writeSetDesktopNameRect(const char *name); |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 132 | void writeSetCursorRect(int width, int height, |
| 133 | int hotspotX, int hotspotY, |
| 134 | const void* data, const void* mask); |
| 135 | void writeSetXCursorRect(int width, int height, |
| 136 | int hotspotX, int hotspotY, |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 137 | const void* data, const void* mask); |
Pierre Ossman | 8053c8e | 2017-02-21 12:59:04 +0100 | [diff] [blame] | 138 | void writeSetCursorWithAlphaRect(int width, int height, |
| 139 | int hotspotX, int hotspotY, |
| 140 | const rdr::U8* data); |
Pierre Ossman | 4a6266f | 2018-11-05 16:28:18 +0100 | [diff] [blame] | 141 | void writeSetVMwareCursorRect(int width, int height, |
| 142 | int hotspotX, int hotspotY, |
| 143 | const rdr::U8* data); |
Pierre Ossman | b45a84f | 2016-12-12 16:59:15 +0100 | [diff] [blame] | 144 | void writeLEDStateRect(rdr::U8 state); |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 145 | void writeQEMUKeyEventRect(); |
Pierre Ossman | c0b1aa0 | 2014-01-16 13:39:05 +0100 | [diff] [blame] | 146 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame] | 147 | ClientParams* client; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 148 | rdr::OutStream* os; |
| 149 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 150 | int nRectsInUpdate; |
| 151 | int nRectsInHeader; |
| 152 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 153 | bool needSetDesktopName; |
Pierre Ossman | 2daba9b | 2018-10-29 10:03:37 +0100 | [diff] [blame] | 154 | bool needCursor; |
Pierre Ossman | b45a84f | 2016-12-12 16:59:15 +0100 | [diff] [blame] | 155 | bool needLEDState; |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 156 | bool needQEMUKeyEvent; |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 157 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 158 | typedef struct { |
| 159 | rdr::U16 reason, result; |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 160 | } ExtendedDesktopSizeMsg; |
| 161 | |
| 162 | std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 163 | }; |
| 164 | } |
| 165 | #endif |