📄 rfb.h
字号:
/* * rfb.h - header file for RFB DDX implementation. *//* * Copyright (C) 2000-2004 Const Kaplinsky. All Rights Reserved. * Copyright (C) 2000 Tridia Corporation. All Rights Reserved. * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */#include "scrnintstr.h"#include "colormapst.h"#include "gcstruct.h"#include "osdep.h"#include <rfbproto.h>#include <vncauth.h>#include <zlib.h>#include <stdarg.h>/* It's a good idea to keep these values a bit greater than required. */#define MAX_ENCODINGS 10#define MAX_SECURITY_TYPES 4#define MAX_TUNNELING_CAPS 16#define MAX_AUTH_CAPS 16extern char *display;/* * Per-screen (framebuffer) structure. There is only one of these, since we * don't allow the X server to have multiple screens. */typedef struct{ int width; int paddedWidthInBytes; int height; int depth; int bitsPerPixel; int sizeInBytes; char *pfbMemory; Pixel blackPixel; Pixel whitePixel; /* The following two members are used to minimise the amount of unnecessary drawing caused by cursor movement. Whenever any drawing affects the part of the screen where the cursor is, the cursor is removed first and then the drawing is done (this is what the sprite routines test for). Afterwards, however, we do not replace the cursor, even when the cursor is logically being moved across the screen. We only draw the cursor again just as we are about to send the client a framebuffer update. We need to be careful when removing and drawing the cursor because of their relationship with the normal drawing routines. The drawing routines can invoke the cursor routines, but also the cursor routines themselves end up invoking drawing routines. Removing the cursor (rfbSpriteRemoveCursor) is eventually achieved by doing a CopyArea from a pixmap to the screen, where the pixmap contains the saved contents of the screen under the cursor. Before doing this, however, we set cursorIsDrawn to FALSE. Then, when CopyArea is called, it sees that cursorIsDrawn is FALSE and so doesn't feel the need to (recursively!) remove the cursor before doing it. Putting up the cursor (rfbSpriteRestoreCursor) involves a call to PushPixels. While this is happening, cursorIsDrawn must be FALSE so that PushPixels doesn't think it has to remove the cursor first. Obviously cursorIsDrawn is set to TRUE afterwards. Another problem we face is that drawing routines sometimes cause a framebuffer update to be sent to the RFB client. When the RFB client is already waiting for a framebuffer update and some drawing to the framebuffer then happens, the drawing routine sees that the client is ready, so it calls rfbSendFramebufferUpdate. If the cursor is not drawn at this stage, it must be put up, and so rfbSpriteRestoreCursor is called. However, if the original drawing routine was actually called from within rfbSpriteRestoreCursor or rfbSpriteRemoveCursor we don't want this to happen. So both the cursor routines set dontSendFramebufferUpdate to TRUE, and all the drawing routines check this before calling rfbSendFramebufferUpdate. */ Bool cursorIsDrawn; /* TRUE if the cursor is currently drawn */ Bool dontSendFramebufferUpdate; /* TRUE while removing or drawing the cursor */ /* wrapped screen functions */ CloseScreenProcPtr CloseScreen; CreateGCProcPtr CreateGC; PaintWindowBackgroundProcPtr PaintWindowBackground; PaintWindowBorderProcPtr PaintWindowBorder; CopyWindowProcPtr CopyWindow; ClearToBackgroundProcPtr ClearToBackground; RestoreAreasProcPtr RestoreAreas;} rfbScreenInfo, *rfbScreenInfoPtr;/* * rfbTranslateFnType is the type of translation functions. */struct rfbClientRec;typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in, rfbPixelFormat *out, char *iptr, char *optr, int bytesBetweenInputLines, int width, int height);/* * Per-client structure. */typedef struct rfbClientRec { int sock; char *host; char *login; int protocol_minor_ver; /* RFB protocol minor version in use */ Bool protocol_tightvnc; /* TightVNC protocol extensions enabled */ /* Possible client states: */ enum { RFB_PROTOCOL_VERSION, /* establishing protocol version */ RFB_SECURITY_TYPE, /* negotiating security (RFB v.3.7) */ RFB_TUNNELING_TYPE, /* establishing tunneling (RFB v.3.7t) */ RFB_AUTH_TYPE, /* negotiating authentication (RFB v.3.7t) */ RFB_AUTHENTICATION, /* authenticating (VNC authentication) */ RFB_INITIALISATION, /* sending initialisation messages */ RFB_NORMAL /* normal protocol messages */ } state; Bool viewOnly; /* Do not accept input from this client. */ Bool reverseConnection; Bool readyForSetColourMapEntries; Bool useCopyRect; int preferredEncoding; int correMaxWidth, correMaxHeight; /* The list of security types sent to this client (protocol 3.7). Note that the first entry is the number of list items following. */ CARD8 securityTypes[MAX_SECURITY_TYPES + 1]; /* Lists of capability codes sent to clients. We remember these lists to restrict clients from choosing those tunneling and authentication types that were not advertised. */ int nAuthCaps; CARD32 authCaps[MAX_AUTH_CAPS]; /* This is not useful while we don't support tunneling: int nTunnelingCaps; CARD32 tunnelingCaps[MAX_TUNNELING_CAPS]; */ /* The following member is only used during VNC authentication */ CARD8 authChallenge[CHALLENGESIZE]; /* The following members represent the update needed to get the client's framebuffer from its present state to the current state of our framebuffer. If the client does not accept CopyRect encoding then the update is simply represented as the region of the screen which has been modified (modifiedRegion). If the client does accept CopyRect encoding, then the update consists of two parts. First we have a single copy from one region of the screen to another (the destination of the copy is copyRegion), and second we have the region of the screen which has been modified in some other way (modifiedRegion). Although the copy is of a single region, this region may have many rectangles. When sending an update, the copyRegion is always sent before the modifiedRegion. This is because the modifiedRegion may overlap parts of the screen which are in the source of the copy. In fact during normal processing, the modifiedRegion may even overlap the destination copyRegion. Just before an update is sent we remove from the copyRegion anything in the modifiedRegion. */ RegionRec copyRegion; /* the destination region of the copy */ int copyDX, copyDY; /* the translation by which the copy happens */ RegionRec modifiedRegion; /* the region of the screen modified in any other way */ /* As part of the FramebufferUpdateRequest, a client can express interest in a subrectangle of the whole framebuffer. This is stored in the requestedRegion member. In the normal case this is the whole framebuffer if the client is ready, empty if it's not. */ RegionRec requestedRegion; /* The following members represent the state of the "deferred update" timer - when the framebuffer is modified and the client is ready, in most cases it is more efficient to defer sending the update by a few milliseconds so that several changes to the framebuffer can be combined into a single update. */ Bool deferredUpdateScheduled; OsTimerPtr deferredUpdateTimer; /* translateFn points to the translation function which is used to copy and translate a rectangle from the framebuffer to an output buffer. */ rfbTranslateFnType translateFn; char *translateLookupTable; rfbPixelFormat format; /* statistics */ int rfbBytesSent[MAX_ENCODINGS]; int rfbRectanglesSent[MAX_ENCODINGS]; int rfbLastRectMarkersSent; int rfbLastRectBytesSent; int rfbCursorShapeBytesSent; int rfbCursorShapeUpdatesSent; int rfbCursorPosBytesSent; int rfbCursorPosUpdatesSent; int rfbFramebufferUpdateMessagesSent; int rfbRawBytesEquivalent; int rfbKeyEventsRcvd; int rfbPointerEventsRcvd; /* zlib encoding -- necessary compression state info per client */ struct z_stream_s compStream; Bool compStreamInited; CARD32 zlibCompressLevel; /* tight encoding -- preserve zlib streams' state for each client */ z_stream zsStruct[4]; Bool zsActive[4]; int zsLevel[4]; int tightCompressLevel; int tightQualityLevel; Bool enableLastRectEncoding; /* client supports LastRect encoding */ Bool enableCursorShapeUpdates; /* client supports cursor shape updates */ Bool enableCursorPosUpdates; /* client supports PointerPos updates */ Bool useRichCursorEncoding; /* rfbEncodingRichCursor is preferred */ Bool cursorWasChanged; /* cursor shape update should be sent */ Bool cursorWasMoved; /* cursor position update should be sent */ int cursorX, cursorY; /* client's cursor position */ struct rfbClientRec *next;} rfbClientRec, *rfbClientPtr;/* * This macro is used to test whether there is a framebuffer update needing to * be sent to the client. */#define FB_UPDATE_PENDING(cl) \ ((!(cl)->enableCursorShapeUpdates && !rfbScreen.cursorIsDrawn) || \ ((cl)->enableCursorShapeUpdates && (cl)->cursorWasChanged) || \ ((cl)->enableCursorPosUpdates && (cl)->cursorWasMoved) || \ REGION_NOTEMPTY((pScreen),&(cl)->copyRegion) || \ REGION_NOTEMPTY((pScreen),&(cl)->modifiedRegion))/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -