1
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
3
// This file is part of the VNC system.
5
// The VNC system is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20
// TightVNC distribution homepage on the Web: http://www.tightvnc.com/
22
// If the source code for the VNC system is not available from the place
23
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
24
// the authors on vnc@uk.research.att.com for information on obtaining it.
29
// The vncDesktop object handles retrieval of data from the
30
// display buffer. It also uses the RFBLib DLL to supply
31
// information on mouse movements and screen updates to
36
#if !defined(_WINVNC_VNCDESKTOP)
37
#define _WINVNC_VNCDESKTOP
43
#include "vncServer.h"
44
#include "vncRegion.h"
46
#include "translate.h"
47
#include <omnithread.h>
48
#include "VideoDriver.h"
51
extern const UINT RFB_SCREEN_UPDATE;
52
extern const UINT RFB_COPYRECT_UPDATE;
53
extern const UINT RFB_MOUSE_UPDATE;
54
extern const char szDesktopSink[];
56
#define MAX_REG_ENTRY_LEN (80)
68
// Make the desktop thread & window proc friends
69
friend class vncDesktopThread;
70
friend LRESULT CALLBACK DesktopWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
72
// Create/Destroy methods
76
BOOL Init(vncServer *pSrv);
79
void TryActivateHooks();
80
BOOL DriverActive() { return m_videodriver != NULL; }
82
// Routine to signal a vncServer to trigger an update
85
// Screen translation, capture, info
86
void FillDisplayInfo(rfbServerInitMsg *scrInfo);
87
void SetLocalInputDisableHook(BOOL enable);
88
void SetLocalInputPriorityHook(BOOL enable);
89
void CaptureScreen(const RECT &UpdateArea, BYTE *scrBuff);
90
void CaptureScreenFromAdapterGeneral(RECT UpdateArea, BYTE *scrBuff);
91
void CaptureScreenFromMirage(RECT UpdateArea, BYTE *scrBuff);
93
HWND Window() { return m_hwnd; }
96
void CaptureMouse(BYTE *scrBuff, UINT scrBuffSize);
98
void CaptureMouseRect();
99
BOOL GetRichCursorData(BYTE *databuf, HCURSOR hcursor, int width, int height);
101
void SetCursor(HCURSOR cursor);
102
HCURSOR GetCursor() { return m_hcursor; }
104
// created for debug purposes. not used in normal builds.
105
bool bDbgDumpSurfBuffers(const RECT &rcl);
107
// Clipboard manipulation
108
static void ConvertClipText(char *dst, const char *src);
109
void SetClipText(LPSTR text);
111
// Method to obtain the DIBsection buffer if fast blits are enabled
112
// If they're disabled, it'll return NULL
113
inline BYTE *MainBuffer() { return m_mainbuff; }
114
inline RECT MainBufferRect() { return m_bmrect; }
115
void CopyRect(RECT const& dest, POINT source);
117
BOOL m_initialClipBoardSeen;
122
// Routines to hook and unhook us
125
void ActivateHooks();
126
void ShutdownHooks();
128
// Init routines called by the child thread
130
void KillScreenSaver();
132
RECT GetSourceRect();
133
BOOL GetSourceDisplayRect(RECT &rdisp_rect);
134
static BOOL IsMultiMonDesktop();
137
void SetupDisplayForConnection();
138
void ResetDisplayToNormal();
142
BOOL ThunkBitmapInfo();
148
void CopyToBuffer(RECT rect, BYTE *scrBuff);
149
void CopyToBuffer(RECT rect, BYTE *scrBuff, const BYTE *SourceBuff);
150
void CopyRectToBuffer(RECT dest, POINT source);
151
void CalcCopyRects();
153
// Routine to attempt enabling optimised DIBsection blits
154
BOOL CreateBuffers();
156
// Convert a bit mask eg. 00111000 to max=7, shift=3
157
static void MaskToMaxAndShift(DWORD mask, CARD16 &max, CARD8 &shift);
159
// Enabling & disabling clipboard handling
160
void SetClipboardActive(BOOL active) {m_clipboard_active = active;};
164
void SetPollingTimer();
165
void SetPollingFlag(BOOL set) { m_polling_flag = set; }
166
BOOL GetPollingFlag() { return m_polling_flag; }
167
void PerformPolling();
168
void PollWindow(HWND hwnd);
169
void PollArea(const RECT &rect);
170
void CheckRects(vncRegion &rgn, rectlist &rects);
171
void GetChangedRegion_Normal(vncRegion &rgn, const RECT &rect);
172
void GetChangedRegion_Dummy(vncRegion &rgn, const RECT &rect);
174
void GetChangedRegion(vncRegion &rgn, const RECT &rect)
177
GetChangedRegion_Normal(rgn, rect);
179
GetChangedRegion_Dummy(rgn, rect);
183
void UpdateChangedRect(vncRegion &rgn, const RECT &rect);
184
void UpdateChangedSubRect(vncRegion &rgn, const RECT &rect);
186
// Blank screen feature
187
void UpdateBlankScreenTimer();
188
void BlankScreen(BOOL set);
190
// Timer identifiers (the third one is not used in any real timer)
193
TIMER_BLANK_SCREEN = 2,
194
TIMER_RESTORE_SCREEN = 3
197
// Video driver stuff
198
BOOL InitVideoDriver();
199
void ShutdownVideoDriver();
203
// Generally useful stuff
205
omni_thread *m_thread;
208
UINT m_timer_polling;
209
UINT m_timer_blank_screen;
211
BOOL m_clipboard_active;
213
BOOL m_hooks_may_change;
215
// Video driver stuff
216
vncVideoDriver *m_videodriver;
218
// device contexts for memory and the screen
222
// New and old bitmaps
224
omni_mutex m_bitbltlock;
226
// frame buffer relative to the entire (virtual) desktop.
227
// NOTE: non-zero offsets possible
233
// Colormap info - comes straight after BITMAPINFO - **HACK**
238
rfbServerInitMsg m_scrinfo;
240
// These are the red, green & blue masks for a pixel
241
DWORD m_rMask, m_gMask, m_bMask;
243
// This is always handy to have
246
// Handle of the default cursor
248
// Handle of the basic arrow cursor
249
HCURSOR m_hdefcursor;
250
// The current mouse position
253
// Boolean flag to indicate when the display resolution has changed
254
BOOL m_displaychanged;
256
// Extra vars used for the DIBsection optimisation
263
// DevMode alteration
264
DEVMODE *m_lpAlternateDevMode; // *** used for res changes - Jeremy Peaks
265
long origPelsWidth; // *** To set the original resolution
266
long origPelsHeight; // *** - Jeremy Peaks
268
vncRegion m_changed_rgn;
270
RECT m_copyrect_rect;
271
POINT m_copyrect_src;
273
static const int m_pollingOrder[32];
274
static int m_pollingStep;
277
#endif // _WINVNC_VNCDESKTOP