Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 2 | * Copyright 2009-2014 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 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | class ConnParams; |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 35 | class ScreenSet; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 37 | class SMsgWriter { |
| 38 | public: |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 39 | SMsgWriter(ConnParams* cp, rdr::OutStream* os); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 40 | virtual ~SMsgWriter(); |
| 41 | |
| 42 | // writeServerInit() must only be called at the appropriate time in the |
| 43 | // protocol initialisation. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 44 | void writeServerInit(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 45 | |
| 46 | // Methods to write normal protocol messages |
| 47 | |
| 48 | // writeSetColourMapEntries() writes a setColourMapEntries message, using |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 49 | // the given colour entries. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 50 | void writeSetColourMapEntries(int firstColour, int nColours, |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 51 | const rdr::U16 red[], |
| 52 | const rdr::U16 green[], |
| 53 | const rdr::U16 blue[]); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | |
| 55 | // writeBell() and writeServerCutText() do the obvious thing. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 56 | void writeBell(); |
| 57 | void writeServerCutText(const char* str, int len); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 58 | |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 59 | // writeFence() sends a new fence request or response to the client. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 60 | void writeFence(rdr::U32 flags, unsigned len, const char data[]); |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 61 | |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 62 | // writeEndOfContinuousUpdates() indicates that we have left continuous |
| 63 | // updates mode. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 64 | void writeEndOfContinuousUpdates(); |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 65 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 66 | // writeSetDesktopSize() won't actually write immediately, but will |
| 67 | // write the relevant pseudo-rectangle as part of the next update. |
| 68 | bool writeSetDesktopSize(); |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 69 | // 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 Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 72 | bool writeExtendedDesktopSize(); |
| 73 | bool writeExtendedDesktopSize(rdr::U16 reason, rdr::U16 result, |
| 74 | int fb_width, int fb_height, |
| 75 | const ScreenSet& layout); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 76 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 77 | bool writeSetDesktopName(); |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 78 | |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 79 | // Like setDesktopSize, we can't just write out a cursor message |
| 80 | // immediately. |
| 81 | bool writeSetCursor(); |
| 82 | bool writeSetXCursor(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 83 | |
| 84 | // needFakeUpdate() returns true when an immediate update is needed in |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 85 | // order to flush out pseudo-rectangles to the client. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 86 | bool needFakeUpdate(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 87 | |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 88 | // needNoDataUpdate() returns true when an update without any |
| 89 | // framebuffer changes need to be sent (using writeNoDataUpdate()). |
| 90 | // Commonly this is an update that modifies the size of the framebuffer |
| 91 | // or the screen layout. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 92 | bool needNoDataUpdate(); |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 93 | |
| 94 | // writeNoDataUpdate() write a framebuffer update containing only |
| 95 | // pseudo-rectangles. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 96 | void writeNoDataUpdate(); |
Pierre Ossman | e9962f7 | 2009-04-23 12:31:42 +0000 | [diff] [blame] | 97 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 98 | // writeFramebufferUpdateStart() initiates an update which you can fill |
| 99 | // in using writeCopyRect() and encoders. Finishing the update by calling |
| 100 | // writeFramebufferUpdateEnd(). |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 101 | void writeFramebufferUpdateStart(int nRects); |
| 102 | void writeFramebufferUpdateEnd(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 103 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 104 | // There is no explicit encoder for CopyRect rects. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 105 | void writeCopyRect(const Rect& r, int srcX, int srcY); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 107 | // Encoders should call these to mark the start and stop of individual |
| 108 | // rects. |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 109 | void startRect(const Rect& r, int enc); |
| 110 | void endRect(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 111 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 112 | protected: |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 113 | void startMsg(int type); |
| 114 | void endMsg(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 115 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 116 | void writePseudoRects(); |
| 117 | void writeNoDataRects(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 118 | |
Pierre Ossman | c0b1aa0 | 2014-01-16 13:39:05 +0100 | [diff] [blame] | 119 | void writeSetDesktopSizeRect(int width, int height); |
| 120 | void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result, |
| 121 | int fb_width, int fb_height, |
| 122 | const ScreenSet& layout); |
| 123 | void writeSetDesktopNameRect(const char *name); |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 124 | void writeSetCursorRect(int width, int height, |
| 125 | int hotspotX, int hotspotY, |
| 126 | const void* data, const void* mask); |
| 127 | void writeSetXCursorRect(int width, int height, |
| 128 | int hotspotX, int hotspotY, |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 129 | const void* data, const void* mask); |
Pierre Ossman | c0b1aa0 | 2014-01-16 13:39:05 +0100 | [diff] [blame] | 130 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 131 | ConnParams* cp; |
| 132 | rdr::OutStream* os; |
| 133 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 134 | int nRectsInUpdate; |
| 135 | int nRectsInHeader; |
| 136 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 137 | bool needSetDesktopSize; |
| 138 | bool needExtendedDesktopSize; |
| 139 | bool needSetDesktopName; |
| 140 | bool needLastRect; |
Pierre Ossman | 126e564 | 2014-02-13 14:40:25 +0100 | [diff] [blame] | 141 | bool needSetCursor; |
| 142 | bool needSetXCursor; |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 143 | |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 144 | typedef struct { |
| 145 | rdr::U16 reason, result; |
| 146 | int fb_width, fb_height; |
| 147 | ScreenSet layout; |
| 148 | } ExtendedDesktopSizeMsg; |
| 149 | |
| 150 | std::list<ExtendedDesktopSizeMsg> extendedDesktopSizeMsgs; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 151 | }; |
| 152 | } |
| 153 | #endif |