You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xvnc.cc 33KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. /* Copyright (c) 1993 X Consortium
  2. Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  3. Copyright 2009 Pierre Ossman for Cendio AB
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  17. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  18. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  19. OTHER DEALINGS IN THE SOFTWARE.
  20. Except as contained in this notice, the name of the X Consortium shall
  21. not be used in advertising or otherwise to promote the sale, use or
  22. other dealings in this Software without prior written authorization
  23. from the X Consortium.
  24. */
  25. #ifdef HAVE_DIX_CONFIG_H
  26. #include <dix-config.h>
  27. #endif
  28. #include <rfb/Configuration.h>
  29. #include <rfb/Logger_stdio.h>
  30. #include <rfb/LogWriter.h>
  31. #include <network/TcpSocket.h>
  32. #include "vncExtInit.h"
  33. #include "xorg-version.h"
  34. extern "C" {
  35. #define class c_class
  36. #define public c_public
  37. #ifdef WIN32
  38. #include <X11/Xwinsock.h>
  39. #endif
  40. #include <stdio.h>
  41. #include <X11/X.h>
  42. #define NEED_EVENTS
  43. #include <X11/Xproto.h>
  44. #include <X11/Xos.h>
  45. #include "scrnintstr.h"
  46. #include "servermd.h"
  47. #include "fb.h"
  48. #include "mi.h"
  49. #include "mibstore.h"
  50. #include "colormapst.h"
  51. #include "gcstruct.h"
  52. #include "input.h"
  53. #include "mipointer.h"
  54. #define new New
  55. #include "micmap.h"
  56. #undef new
  57. #include <sys/types.h>
  58. #include <sys/stat.h>
  59. #include <errno.h>
  60. #ifndef WIN32
  61. #include <sys/param.h>
  62. #endif
  63. #include <X11/XWDFile.h>
  64. #ifdef HAS_SHM
  65. #include <sys/ipc.h>
  66. #include <sys/shm.h>
  67. #endif /* HAS_SHM */
  68. #include "dix.h"
  69. #include "miline.h"
  70. #include "inputstr.h"
  71. #ifdef RANDR
  72. #include "randrstr.h"
  73. #endif /* RANDR */
  74. #include <X11/keysym.h>
  75. extern char buildtime[];
  76. #if XORG >= 17
  77. #undef VENDOR_RELEASE
  78. #undef VENDOR_STRING
  79. #include "version-config.h"
  80. #include "site.h"
  81. #endif
  82. #undef class
  83. #undef public
  84. }
  85. #if XORG >= 110
  86. #define Xalloc malloc
  87. #define Xfree free
  88. #endif
  89. #define XVNCVERSION "TigerVNC 1.1.80"
  90. #define XVNCCOPYRIGHT ("Copyright (C) 1999-2011 TigerVNC Team and many others (see README.txt)\n" \
  91. "See http://www.tigervnc.org for information on TigerVNC.\n")
  92. extern char *display;
  93. extern int monitorResolution;
  94. #define VFB_DEFAULT_WIDTH 1024
  95. #define VFB_DEFAULT_HEIGHT 768
  96. #define VFB_DEFAULT_DEPTH 24
  97. #define VFB_DEFAULT_WHITEPIXEL 0xffffffff
  98. #define VFB_DEFAULT_BLACKPIXEL 0
  99. #define VFB_DEFAULT_LINEBIAS 0
  100. #define XWD_WINDOW_NAME_LEN 60
  101. typedef struct
  102. {
  103. int width;
  104. int height;
  105. int depth;
  106. /* Computed when allocated */
  107. int paddedBytesWidth;
  108. int paddedWidth;
  109. int bitsPerPixel;
  110. /* Private */
  111. int sizeInBytes;
  112. void *pfbMemory;
  113. #ifdef HAS_SHM
  114. int shmid;
  115. #endif
  116. } vfbFramebufferInfo, *vfbFramebufferInfoPtr;
  117. typedef struct
  118. {
  119. int scrnum;
  120. Pixel blackPixel;
  121. Pixel whitePixel;
  122. unsigned int lineBias;
  123. CloseScreenProcPtr closeScreen;
  124. vfbFramebufferInfo fb;
  125. Bool pixelFormatDefined;
  126. Bool rgbNotBgr;
  127. int redBits, greenBits, blueBits;
  128. } vfbScreenInfo, *vfbScreenInfoPtr;
  129. static int vfbNumScreens;
  130. static vfbScreenInfo vfbScreens[MAXSCREENS];
  131. static Bool vfbPixmapDepths[33];
  132. typedef enum { NORMAL_MEMORY_FB, SHARED_MEMORY_FB } fbMemType;
  133. static fbMemType fbmemtype = NORMAL_MEMORY_FB;
  134. static int lastScreen = -1;
  135. static Bool Render = TRUE;
  136. static bool displaySpecified = false;
  137. static char displayNumStr[16];
  138. char *listenaddr = NULL;
  139. static void
  140. vfbInitializePixmapDepths(void)
  141. {
  142. int i;
  143. vfbPixmapDepths[1] = TRUE; /* always need bitmaps */
  144. for (i = 2; i <= 32; i++)
  145. vfbPixmapDepths[i] = FALSE;
  146. }
  147. static void
  148. vfbInitializeDefaultScreens(void)
  149. {
  150. int i;
  151. for (i = 0; i < MAXSCREENS; i++)
  152. {
  153. vfbScreens[i].scrnum = i;
  154. vfbScreens[i].blackPixel = VFB_DEFAULT_BLACKPIXEL;
  155. vfbScreens[i].whitePixel = VFB_DEFAULT_WHITEPIXEL;
  156. vfbScreens[i].lineBias = VFB_DEFAULT_LINEBIAS;
  157. vfbScreens[i].fb.width = VFB_DEFAULT_WIDTH;
  158. vfbScreens[i].fb.height = VFB_DEFAULT_HEIGHT;
  159. vfbScreens[i].fb.pfbMemory = NULL;
  160. vfbScreens[i].fb.depth = VFB_DEFAULT_DEPTH;
  161. vfbScreens[i].pixelFormatDefined = FALSE;
  162. }
  163. vfbNumScreens = 1;
  164. }
  165. static int
  166. vfbBitsPerPixel(int depth)
  167. {
  168. if (depth == 1) return 1;
  169. else if (depth <= 8) return 8;
  170. else if (depth <= 16) return 16;
  171. else return 32;
  172. }
  173. static void vfbFreeFramebufferMemory(vfbFramebufferInfoPtr pfb);
  174. extern "C" {
  175. #ifdef DPMSExtension
  176. /* Why support DPMS? Because stupid modern desktop environments
  177. such as Unity 2D on Ubuntu 11.10 crashes if DPMS is not
  178. available. (DPMSSet is called by dpms.c, but the return value
  179. is ignored.) */
  180. int DPMSSet(ClientPtr client, int level)
  181. {
  182. return Success;
  183. }
  184. Bool DPMSSupported()
  185. {
  186. /* Causes DPMSCapable to return false, meaning no devices are DPMS
  187. capable */
  188. return FALSE;
  189. }
  190. #endif
  191. void ddxGiveUp()
  192. {
  193. int i;
  194. /* clean up the framebuffers */
  195. for (i = 0; i < vfbNumScreens; i++)
  196. vfbFreeFramebufferMemory(&vfbScreens[i].fb);
  197. }
  198. void
  199. AbortDDX()
  200. {
  201. ddxGiveUp();
  202. }
  203. #ifdef __DARWIN__
  204. void
  205. DarwinHandleGUI(int argc, char *argv[])
  206. {
  207. }
  208. void GlxExtensionInit();
  209. void GlxWrapInitVisuals(void *procPtr);
  210. void
  211. DarwinGlxExtensionInit()
  212. {
  213. GlxExtensionInit();
  214. }
  215. void
  216. DarwinGlxWrapInitVisuals(
  217. void *procPtr)
  218. {
  219. GlxWrapInitVisuals(procPtr);
  220. }
  221. #endif
  222. void
  223. OsVendorInit()
  224. {
  225. }
  226. void
  227. OsVendorFatalError()
  228. {
  229. }
  230. void ddxBeforeReset(void)
  231. {
  232. return;
  233. }
  234. void
  235. ddxUseMsg()
  236. {
  237. ErrorF("\nXvnc %s - built %s\n%s", XVNCVERSION, buildtime, XVNCCOPYRIGHT);
  238. ErrorF("Underlying X server release %d, %s\n\n", VENDOR_RELEASE,
  239. VENDOR_STRING);
  240. ErrorF("-screen scrn WxHxD set screen's width, height, depth\n");
  241. ErrorF("-pixdepths list-of-int support given pixmap depths\n");
  242. #ifdef RENDER
  243. ErrorF("+/-render turn on/off RENDER extension support"
  244. "(default on)\n");
  245. #endif
  246. ErrorF("-linebias n adjust thin line pixelization\n");
  247. ErrorF("-blackpixel n pixel value for black\n");
  248. ErrorF("-whitepixel n pixel value for white\n");
  249. #ifdef HAS_SHM
  250. ErrorF("-shmem put framebuffers in shared memory\n");
  251. #endif
  252. ErrorF("-geometry WxH set screen 0's width, height\n");
  253. ErrorF("-depth D set screen 0's depth\n");
  254. ErrorF("-pixelformat fmt set pixel format (rgbNNN or bgrNNN)\n");
  255. ErrorF("-inetd has been launched from inetd\n");
  256. ErrorF("-interface IP_address listen on specified interface\n");
  257. ErrorF("-noclipboard disable clipboard settings modification via vncconfig utility\n");
  258. ErrorF("\nVNC parameters:\n");
  259. fprintf(stderr,"\n"
  260. "Parameters can be turned on with -<param> or off with -<param>=0\n"
  261. "Parameters which take a value can be specified as "
  262. "-<param> <value>\n"
  263. "Other valid forms are <param>=<value> -<param>=<value> "
  264. "--<param>=<value>\n"
  265. "Parameter names are case-insensitive. The parameters are:\n\n");
  266. rfb::Configuration::listParams(79, 14);
  267. }
  268. }
  269. /* ddxInitGlobals - called by |InitGlobals| from os/util.c */
  270. void ddxInitGlobals(void)
  271. {
  272. }
  273. static
  274. bool displayNumFree(int num)
  275. {
  276. try {
  277. network::TcpListener l(NULL, 6000+num);
  278. } catch (rdr::Exception& e) {
  279. return false;
  280. }
  281. char file[256];
  282. sprintf(file, "/tmp/.X%d-lock", num);
  283. if (access(file, F_OK) == 0) return false;
  284. sprintf(file, "/tmp/.X11-unix/X%d", num);
  285. if (access(file, F_OK) == 0) return false;
  286. sprintf(file, "/usr/spool/sockets/X11/%d", num);
  287. if (access(file, F_OK) == 0) return false;
  288. return true;
  289. }
  290. int
  291. ddxProcessArgument(int argc, char *argv[], int i)
  292. {
  293. static Bool firstTime = TRUE;
  294. if (firstTime)
  295. {
  296. vfbInitializeDefaultScreens();
  297. vfbInitializePixmapDepths();
  298. firstTime = FALSE;
  299. rfb::initStdIOLoggers();
  300. rfb::LogWriter::setLogParams("*:stderr:30");
  301. rfb::Configuration::enableServerParams();
  302. }
  303. if (argv[i][0] == ':')
  304. displaySpecified = true;
  305. if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */
  306. {
  307. int screenNum;
  308. if (i + 2 >= argc) UseMsg();
  309. screenNum = atoi(argv[i+1]);
  310. if (screenNum < 0 || screenNum >= MAXSCREENS)
  311. {
  312. ErrorF("Invalid screen number %d\n", screenNum);
  313. UseMsg();
  314. }
  315. if (3 != sscanf(argv[i+2], "%dx%dx%d",
  316. &vfbScreens[screenNum].fb.width,
  317. &vfbScreens[screenNum].fb.height,
  318. &vfbScreens[screenNum].fb.depth))
  319. {
  320. ErrorF("Invalid screen configuration %s\n", argv[i+2]);
  321. UseMsg();
  322. }
  323. if (screenNum >= vfbNumScreens)
  324. vfbNumScreens = screenNum + 1;
  325. lastScreen = screenNum;
  326. return 3;
  327. }
  328. if (strcmp (argv[i], "-pixdepths") == 0) /* -pixdepths list-of-depth */
  329. {
  330. int depth, ret = 1;
  331. if (++i >= argc) UseMsg();
  332. while ((i < argc) && (depth = atoi(argv[i++])) != 0)
  333. {
  334. if (depth < 0 || depth > 32)
  335. {
  336. ErrorF("Invalid pixmap depth %d\n", depth);
  337. UseMsg();
  338. }
  339. vfbPixmapDepths[depth] = TRUE;
  340. ret++;
  341. }
  342. return ret;
  343. }
  344. if (strcmp (argv[i], "+render") == 0) /* +render */
  345. {
  346. Render = TRUE;
  347. return 1;
  348. }
  349. if (strcmp (argv[i], "-render") == 0) /* -render */
  350. {
  351. Render = FALSE;
  352. return 1;
  353. }
  354. if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */
  355. {
  356. Pixel pix;
  357. if (++i >= argc) UseMsg();
  358. pix = atoi(argv[i]);
  359. if (-1 == lastScreen)
  360. {
  361. int i;
  362. for (i = 0; i < MAXSCREENS; i++)
  363. {
  364. vfbScreens[i].blackPixel = pix;
  365. }
  366. }
  367. else
  368. {
  369. vfbScreens[lastScreen].blackPixel = pix;
  370. }
  371. return 2;
  372. }
  373. if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */
  374. {
  375. Pixel pix;
  376. if (++i >= argc) UseMsg();
  377. pix = atoi(argv[i]);
  378. if (-1 == lastScreen)
  379. {
  380. int i;
  381. for (i = 0; i < MAXSCREENS; i++)
  382. {
  383. vfbScreens[i].whitePixel = pix;
  384. }
  385. }
  386. else
  387. {
  388. vfbScreens[lastScreen].whitePixel = pix;
  389. }
  390. return 2;
  391. }
  392. if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */
  393. {
  394. unsigned int linebias;
  395. if (++i >= argc) UseMsg();
  396. linebias = atoi(argv[i]);
  397. if (-1 == lastScreen)
  398. {
  399. int i;
  400. for (i = 0; i < MAXSCREENS; i++)
  401. {
  402. vfbScreens[i].lineBias = linebias;
  403. }
  404. }
  405. else
  406. {
  407. vfbScreens[lastScreen].lineBias = linebias;
  408. }
  409. return 2;
  410. }
  411. #ifdef HAS_SHM
  412. if (strcmp (argv[i], "-shmem") == 0) /* -shmem */
  413. {
  414. fbmemtype = SHARED_MEMORY_FB;
  415. return 1;
  416. }
  417. #endif
  418. if (strcmp(argv[i], "-geometry") == 0)
  419. {
  420. if (++i >= argc) UseMsg();
  421. if (sscanf(argv[i],"%dx%d",&vfbScreens[0].fb.width,
  422. &vfbScreens[0].fb.height) != 2) {
  423. ErrorF("Invalid geometry %s\n", argv[i]);
  424. UseMsg();
  425. }
  426. return 2;
  427. }
  428. if (strcmp(argv[i], "-depth") == 0)
  429. {
  430. if (++i >= argc) UseMsg();
  431. vfbScreens[0].fb.depth = atoi(argv[i]);
  432. return 2;
  433. }
  434. if (strcmp(argv[i], "-pixelformat") == 0)
  435. {
  436. char rgbbgr[4];
  437. int bits1, bits2, bits3;
  438. if (++i >= argc) UseMsg();
  439. if (sscanf(argv[i], "%3s%1d%1d%1d", rgbbgr,&bits1,&bits2,&bits3) < 4) {
  440. ErrorF("Invalid pixel format %s\n", argv[i]);
  441. UseMsg();
  442. }
  443. #define SET_PIXEL_FORMAT(vfbScreen) \
  444. (vfbScreen).pixelFormatDefined = TRUE; \
  445. (vfbScreen).fb.depth = bits1 + bits2 + bits3; \
  446. (vfbScreen).greenBits = bits2; \
  447. if (strcasecmp(rgbbgr, "bgr") == 0) { \
  448. (vfbScreen).rgbNotBgr = FALSE; \
  449. (vfbScreen).redBits = bits3; \
  450. (vfbScreen).blueBits = bits1; \
  451. } else if (strcasecmp(rgbbgr, "rgb") == 0) { \
  452. (vfbScreen).rgbNotBgr = TRUE; \
  453. (vfbScreen).redBits = bits1; \
  454. (vfbScreen).blueBits = bits3; \
  455. } else { \
  456. ErrorF("Invalid pixel format %s\n", argv[i]); \
  457. UseMsg(); \
  458. }
  459. if (-1 == lastScreen)
  460. {
  461. int i;
  462. for (i = 0; i < MAXSCREENS; i++)
  463. {
  464. SET_PIXEL_FORMAT(vfbScreens[i]);
  465. }
  466. }
  467. else
  468. {
  469. SET_PIXEL_FORMAT(vfbScreens[lastScreen]);
  470. }
  471. return 2;
  472. }
  473. if (strcmp(argv[i], "-inetd") == 0)
  474. {
  475. dup2(0,3);
  476. vncInetdSock = 3;
  477. close(2);
  478. if (!displaySpecified) {
  479. int port = network::TcpSocket::getSockPort(vncInetdSock);
  480. int displayNum = port - 5900;
  481. if (displayNum < 0 || displayNum > 99 || !displayNumFree(displayNum)) {
  482. for (displayNum = 1; displayNum < 100; displayNum++)
  483. if (displayNumFree(displayNum)) break;
  484. if (displayNum == 100)
  485. FatalError("Xvnc error: no free display number for -inetd");
  486. }
  487. display = displayNumStr;
  488. sprintf(displayNumStr, "%d", displayNum);
  489. }
  490. return 1;
  491. }
  492. if (strcmp(argv[i], "-interface") == 0 ||
  493. strcmp(argv[i], "-i") == 0) {
  494. if (++i >= argc) {
  495. UseMsg();
  496. return 2;
  497. }
  498. if (listenaddr != NULL) /* Only first -interface is valid */
  499. return 2;
  500. listenaddr = strdup(argv[i]);
  501. if (listenaddr == NULL)
  502. FatalError("Not enough memory");
  503. return 2;
  504. }
  505. if (strcmp(argv[i], "-noclipboard") == 0) {
  506. noclipboard = true;
  507. return 1;
  508. }
  509. if (rfb::Configuration::setParam(argv[i]))
  510. return 1;
  511. if (argv[i][0] == '-' && i+1 < argc) {
  512. if (rfb::Configuration::setParam(&argv[i][1], argv[i+1]))
  513. return 2;
  514. }
  515. return 0;
  516. }
  517. #ifdef DDXTIME /* from ServerOSDefines */
  518. CARD32
  519. GetTimeInMillis()
  520. {
  521. struct timeval tp;
  522. X_GETTIMEOFDAY(&tp);
  523. return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
  524. }
  525. #endif
  526. static ColormapPtr InstalledMaps[MAXSCREENS];
  527. static int
  528. vfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
  529. {
  530. /* By the time we are processing requests, we can guarantee that there
  531. * is always a colormap installed */
  532. *pmaps = InstalledMaps[pScreen->myNum]->mid;
  533. return (1);
  534. }
  535. static void
  536. vfbInstallColormap(ColormapPtr pmap)
  537. {
  538. int index = pmap->pScreen->myNum;
  539. ColormapPtr oldpmap = InstalledMaps[index];
  540. if (pmap != oldpmap)
  541. {
  542. int entries;
  543. VisualPtr pVisual;
  544. Pixel * ppix;
  545. xrgb * prgb;
  546. xColorItem *defs;
  547. int i;
  548. if(oldpmap != (ColormapPtr)None)
  549. WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
  550. /* Install pmap */
  551. InstalledMaps[index] = pmap;
  552. WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
  553. entries = pmap->pVisual->ColormapEntries;
  554. pVisual = pmap->pVisual;
  555. ppix = (Pixel *)xalloc(entries * sizeof(Pixel));
  556. prgb = (xrgb *)xalloc(entries * sizeof(xrgb));
  557. defs = (xColorItem *)xalloc(entries * sizeof(xColorItem));
  558. for (i = 0; i < entries; i++) ppix[i] = i;
  559. /* XXX truecolor */
  560. #if XORG < 19
  561. QueryColors(pmap, entries, ppix, prgb);
  562. #else
  563. QueryColors(pmap, entries, ppix, prgb, serverClient);
  564. #endif
  565. for (i = 0; i < entries; i++) { /* convert xrgbs to xColorItems */
  566. defs[i].pixel = ppix[i] & 0xff; /* change pixel to index */
  567. defs[i].red = prgb[i].red;
  568. defs[i].green = prgb[i].green;
  569. defs[i].blue = prgb[i].blue;
  570. defs[i].flags = DoRed|DoGreen|DoBlue;
  571. }
  572. (*pmap->pScreen->StoreColors)(pmap, entries, defs);
  573. xfree(ppix);
  574. xfree(prgb);
  575. xfree(defs);
  576. }
  577. }
  578. static void
  579. vfbUninstallColormap(ColormapPtr pmap)
  580. {
  581. ColormapPtr curpmap = InstalledMaps[pmap->pScreen->myNum];
  582. if(pmap == curpmap)
  583. {
  584. if (pmap->mid != pmap->pScreen->defColormap)
  585. {
  586. curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
  587. RT_COLORMAP);
  588. (*pmap->pScreen->InstallColormap)(curpmap);
  589. }
  590. }
  591. }
  592. static Bool
  593. vfbSaveScreen(ScreenPtr pScreen, int on)
  594. {
  595. return TRUE;
  596. }
  597. #ifdef HAS_SHM
  598. static void
  599. vfbAllocateSharedMemoryFramebuffer(vfbFramebufferInfoPtr pfb)
  600. {
  601. /* create the shared memory segment */
  602. pfb->shmid = shmget(IPC_PRIVATE, pfb->sizeInBytes, IPC_CREAT|0777);
  603. if (pfb->shmid < 0) {
  604. perror("shmget");
  605. ErrorF("shmget %d bytes failed, errno %d", pfb->sizeInBytes, errno);
  606. return;
  607. }
  608. /* try to attach it */
  609. pfb->pfbMemory = shmat(pfb->shmid, 0, 0);
  610. if (-1 == (long)pfb->pfbMemory) {
  611. perror("shmat");
  612. ErrorF("shmat failed, errno %d", errno);
  613. pfb->pfbMemory = NULL;
  614. return;
  615. }
  616. }
  617. #endif /* HAS_SHM */
  618. static void *
  619. vfbAllocateFramebufferMemory(vfbFramebufferInfoPtr pfb)
  620. {
  621. if (pfb->pfbMemory != NULL)
  622. return pfb->pfbMemory; /* already done */
  623. /* Compute memory layout */
  624. pfb->paddedBytesWidth = PixmapBytePad(pfb->width, pfb->depth);
  625. pfb->bitsPerPixel = vfbBitsPerPixel(pfb->depth);
  626. pfb->paddedWidth = pfb->paddedBytesWidth * 8 / pfb->bitsPerPixel;
  627. pfb->sizeInBytes = pfb->paddedBytesWidth * pfb->height;
  628. /* And allocate buffer */
  629. switch (fbmemtype) {
  630. #ifdef HAS_SHM
  631. case SHARED_MEMORY_FB:
  632. vfbAllocateSharedMemoryFramebuffer(pfb);
  633. break;
  634. #else
  635. case SHARED_MEMORY_FB:
  636. break;
  637. #endif
  638. case NORMAL_MEMORY_FB:
  639. pfb->pfbMemory = Xalloc(pfb->sizeInBytes);
  640. break;
  641. }
  642. /* This will be NULL if any of the above failed */
  643. return pfb->pfbMemory;
  644. }
  645. static void
  646. vfbFreeFramebufferMemory(vfbFramebufferInfoPtr pfb)
  647. {
  648. if ((pfb == NULL) || (pfb->pfbMemory == NULL))
  649. return;
  650. switch (fbmemtype) {
  651. #ifdef HAS_SHM
  652. case SHARED_MEMORY_FB:
  653. if (-1 == shmdt(pfb->pfbMemory)) {
  654. perror("shmdt");
  655. ErrorF("shmdt failed, errno %d", errno);
  656. }
  657. break;
  658. #else /* HAS_SHM */
  659. case SHARED_MEMORY_FB:
  660. break;
  661. #endif /* HAS_SHM */
  662. case NORMAL_MEMORY_FB:
  663. Xfree(pfb->pfbMemory);
  664. break;
  665. }
  666. pfb->pfbMemory = NULL;
  667. }
  668. static Bool
  669. vfbCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y)
  670. {
  671. return FALSE;
  672. }
  673. static void
  674. vfbCrossScreen (ScreenPtr pScreen, Bool entering)
  675. {
  676. }
  677. static Bool vfbRealizeCursor(
  678. #if XORG >= 16
  679. DeviceIntPtr pDev,
  680. #endif
  681. ScreenPtr pScreen, CursorPtr pCursor) {
  682. return TRUE;
  683. }
  684. static Bool vfbUnrealizeCursor(
  685. #if XORG >= 16
  686. DeviceIntPtr pDev,
  687. #endif
  688. ScreenPtr pScreen, CursorPtr pCursor) {
  689. return TRUE;
  690. }
  691. static void vfbSetCursor(
  692. #if XORG >= 16
  693. DeviceIntPtr pDev,
  694. #endif
  695. ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
  696. {
  697. }
  698. static void vfbMoveCursor(
  699. #if XORG >= 16
  700. DeviceIntPtr pDev,
  701. #endif
  702. ScreenPtr pScreen, int x, int y)
  703. {
  704. }
  705. #if XORG >= 16
  706. static Bool
  707. vfbDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
  708. {
  709. return TRUE;
  710. }
  711. static void
  712. vfbDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
  713. {
  714. }
  715. #endif
  716. static miPointerSpriteFuncRec vfbPointerSpriteFuncs = {
  717. vfbRealizeCursor,
  718. vfbUnrealizeCursor,
  719. vfbSetCursor,
  720. vfbMoveCursor
  721. #if XORG >= 16
  722. , vfbDeviceCursorInitialize,
  723. vfbDeviceCursorCleanup
  724. #endif
  725. };
  726. static miPointerScreenFuncRec vfbPointerCursorFuncs = {
  727. vfbCursorOffScreen,
  728. vfbCrossScreen,
  729. miPointerWarpCursor
  730. };
  731. #ifdef RANDR
  732. static Bool vncRandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
  733. {
  734. Bool ret, gotCurrent = FALSE;
  735. int i;
  736. const int widths[] = { 1920, 1920, 1600, 1680, 1400, 1360, 1280, 1280, 1280, 1280, 1024, 800, 640 };
  737. const int heights[] = { 1200, 1080, 1200, 1050, 1050, 768, 1024, 960, 800, 720, 768, 600, 480 };
  738. for (i = 0;i < sizeof(widths)/sizeof(*widths);i++) {
  739. RRScreenSizePtr pSize;
  740. pSize = RRRegisterSize(pScreen, widths[i], heights[i],
  741. pScreen->mmWidth, pScreen->mmHeight);
  742. if (!pSize)
  743. return FALSE;
  744. ret = RRRegisterRate(pScreen, pSize, 60);
  745. if (!ret)
  746. return FALSE;
  747. if ((widths[i] == pScreen->width) && (heights[i] == pScreen->height)) {
  748. RRSetCurrentConfig(pScreen, RR_Rotate_0, 60, pSize);
  749. gotCurrent = TRUE;
  750. }
  751. }
  752. if (!gotCurrent) {
  753. RRScreenSizePtr pSize;
  754. pSize = RRRegisterSize(pScreen, pScreen->width, pScreen->height,
  755. pScreen->mmWidth, pScreen->mmHeight);
  756. if (!pSize)
  757. return FALSE;
  758. RRRegisterRate(pScreen, pSize, 60);
  759. RRSetCurrentConfig(pScreen, RR_Rotate_0, 60, pSize);
  760. }
  761. *rotations = RR_Rotate_0;
  762. return TRUE;
  763. }
  764. /* from hw/xfree86/common/xf86Helper.c */
  765. #include "mivalidate.h"
  766. static void
  767. xf86SetRootClip (ScreenPtr pScreen, Bool enable)
  768. {
  769. #if XORG < 19
  770. WindowPtr pWin = WindowTable[pScreen->myNum];
  771. #else
  772. WindowPtr pWin = pScreen->root;
  773. #endif
  774. WindowPtr pChild;
  775. Bool WasViewable = (Bool)(pWin->viewable);
  776. Bool anyMarked = FALSE;
  777. #if XORG < 110
  778. RegionPtr pOldClip = NULL, bsExposed;
  779. #ifdef DO_SAVE_UNDERS
  780. Bool dosave = FALSE;
  781. #endif
  782. #endif
  783. WindowPtr pLayerWin;
  784. BoxRec box;
  785. if (WasViewable)
  786. {
  787. for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
  788. {
  789. (void) (*pScreen->MarkOverlappedWindows)(pChild,
  790. pChild,
  791. &pLayerWin);
  792. }
  793. (*pScreen->MarkWindow) (pWin);
  794. anyMarked = TRUE;
  795. if (pWin->valdata)
  796. {
  797. if (HasBorder (pWin))
  798. {
  799. RegionPtr borderVisible;
  800. borderVisible = REGION_CREATE(pScreen, NullBox, 1);
  801. REGION_SUBTRACT(pScreen, borderVisible,
  802. &pWin->borderClip, &pWin->winSize);
  803. pWin->valdata->before.borderVisible = borderVisible;
  804. }
  805. pWin->valdata->before.resized = TRUE;
  806. }
  807. }
  808. /*
  809. * Use REGION_BREAK to avoid optimizations in ValidateTree
  810. * that assume the root borderClip can't change well, normally
  811. * it doesn't...)
  812. */
  813. if (enable)
  814. {
  815. box.x1 = 0;
  816. box.y1 = 0;
  817. box.x2 = pScreen->width;
  818. box.y2 = pScreen->height;
  819. REGION_INIT (pScreen, &pWin->winSize, &box, 1);
  820. REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
  821. if (WasViewable)
  822. REGION_RESET(pScreen, &pWin->borderClip, &box);
  823. pWin->drawable.width = pScreen->width;
  824. pWin->drawable.height = pScreen->height;
  825. REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
  826. }
  827. else
  828. {
  829. REGION_EMPTY(pScreen, &pWin->borderClip);
  830. REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
  831. }
  832. ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
  833. if (WasViewable)
  834. {
  835. #if XORG < 110
  836. if (pWin->backStorage)
  837. {
  838. pOldClip = REGION_CREATE(pScreen, NullBox, 1);
  839. REGION_COPY(pScreen, pOldClip, &pWin->clipList);
  840. }
  841. #endif
  842. if (pWin->firstChild)
  843. {
  844. anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
  845. pWin->firstChild,
  846. (WindowPtr *)NULL);
  847. }
  848. else
  849. {
  850. (*pScreen->MarkWindow) (pWin);
  851. anyMarked = TRUE;
  852. }
  853. #if XORG < 110 && defined(DO_SAVE_UNDERS)
  854. if (DO_SAVE_UNDERS(pWin))
  855. {
  856. dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin);
  857. }
  858. #endif /* DO_SAVE_UNDERS */
  859. if (anyMarked)
  860. (*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
  861. }
  862. #if XORG < 110
  863. if (pWin->backStorage &&
  864. ((pWin->backingStore == Always) || WasViewable))
  865. {
  866. if (!WasViewable)
  867. pOldClip = &pWin->clipList; /* a convenient empty region */
  868. bsExposed = (*pScreen->TranslateBackingStore)
  869. (pWin, 0, 0, pOldClip,
  870. pWin->drawable.x, pWin->drawable.y);
  871. if (WasViewable)
  872. REGION_DESTROY(pScreen, pOldClip);
  873. if (bsExposed)
  874. {
  875. RegionPtr valExposed = NullRegion;
  876. if (pWin->valdata)
  877. valExposed = &pWin->valdata->after.exposed;
  878. (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
  879. if (valExposed)
  880. REGION_EMPTY(pScreen, valExposed);
  881. REGION_DESTROY(pScreen, bsExposed);
  882. }
  883. }
  884. #endif
  885. if (WasViewable)
  886. {
  887. if (anyMarked)
  888. (*pScreen->HandleExposures)(pWin);
  889. #if XORG < 110 && defined(DO_SAVE_UNDERS)
  890. if (dosave)
  891. (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
  892. #endif /* DO_SAVE_UNDERS */
  893. if (anyMarked && pScreen->PostValidateTree)
  894. (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
  895. }
  896. if (pWin->realized)
  897. WindowsRestructured ();
  898. FlushAllOutput ();
  899. }
  900. static Bool vncRandRSetConfig (ScreenPtr pScreen, Rotation rotation,
  901. int rate, RRScreenSizePtr pSize)
  902. {
  903. vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
  904. vfbFramebufferInfo fb;
  905. PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
  906. void *pbits;
  907. Bool ret;
  908. int oldwidth, oldheight, oldmmWidth, oldmmHeight;
  909. int dpix, dpiy;
  910. /* Prevent updates while we fiddle */
  911. xf86SetRootClip(pScreen, FALSE);
  912. /* Store current state in case we fail */
  913. oldwidth = pScreen->width;
  914. oldheight = pScreen->height;
  915. oldmmWidth = pScreen->mmWidth;
  916. oldmmHeight = pScreen->mmHeight;
  917. /* Compute the current DPI (for use later) */
  918. dpix = (pScreen->width * 254 + pScreen->mmWidth * 5) / (pScreen->mmWidth * 10);
  919. dpiy = (pScreen->height * 254 + pScreen->mmHeight * 5) / (pScreen->mmHeight * 10);
  920. /* Then set the new dimensions */
  921. pScreen->width = pSize->width;
  922. pScreen->height = pSize->height;
  923. /* Try to keep the same DPI as we do not have a physical screen */
  924. pScreen->mmWidth = (pScreen->width * 254 + dpix * 5) / (dpix * 10);
  925. pScreen->mmHeight = (pScreen->height * 254 + dpiy * 5) / (dpiy * 10);
  926. /* Allocate a new framebuffer */
  927. memset(&fb, 0, sizeof(vfbFramebufferInfo));
  928. fb.width = pScreen->width;
  929. fb.height = pScreen->height;
  930. fb.depth = pvfb->fb.depth;
  931. pbits = vfbAllocateFramebufferMemory(&fb);
  932. if (!pbits) {
  933. /* Allocation failed. Restore old state */
  934. pScreen->width = oldwidth;
  935. pScreen->height = oldheight;
  936. pScreen->mmWidth = oldmmWidth;
  937. pScreen->mmHeight = oldmmHeight;
  938. xf86SetRootClip(pScreen, TRUE);
  939. return FALSE;
  940. }
  941. /* Update root pixmap with the new dimensions and buffer */
  942. ret = pScreen->ModifyPixmapHeader(rootPixmap, fb.width, fb.height,
  943. -1, -1, fb.paddedBytesWidth, pbits);
  944. if (!ret) {
  945. /* Update failed. Free the new framebuffer and restore old state */
  946. vfbFreeFramebufferMemory(&fb);
  947. pScreen->width = oldwidth;
  948. pScreen->height = oldheight;
  949. pScreen->mmWidth = oldmmWidth;
  950. pScreen->mmHeight = oldmmHeight;
  951. xf86SetRootClip(pScreen, TRUE);
  952. return FALSE;
  953. }
  954. /* Free the old framebuffer and keep the info about the new one */
  955. vfbFreeFramebufferMemory(&pvfb->fb);
  956. memcpy(&pvfb->fb, &fb, sizeof(vfbFramebufferInfo));
  957. /* Let VNC get the new framebuffer (actual update is in vncHooks.cc) */
  958. vncFbptr[pScreen->myNum] = pbits;
  959. vncFbstride[pScreen->myNum] = fb.paddedWidth;
  960. /* Restore ability to update screen, now with new dimensions */
  961. xf86SetRootClip(pScreen, TRUE);
  962. return TRUE;
  963. }
  964. #endif
  965. static Bool
  966. vfbCloseScreen(int index, ScreenPtr pScreen)
  967. {
  968. vfbScreenInfoPtr pvfb = &vfbScreens[index];
  969. int i;
  970. pScreen->CloseScreen = pvfb->closeScreen;
  971. /*
  972. * XXX probably lots of stuff to clean. For now,
  973. * clear InstalledMaps[] so that server reset works correctly.
  974. */
  975. for (i = 0; i < MAXSCREENS; i++)
  976. InstalledMaps[i] = NULL;
  977. return pScreen->CloseScreen(index, pScreen);
  978. }
  979. static Bool
  980. vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
  981. {
  982. vfbScreenInfoPtr pvfb = &vfbScreens[index];
  983. int dpi;
  984. int ret;
  985. void *pbits;
  986. /* 96 is the default used by most other systems */
  987. dpi = 96;
  988. if (monitorResolution)
  989. dpi = monitorResolution;
  990. pbits = vfbAllocateFramebufferMemory(&pvfb->fb);
  991. if (!pbits) return FALSE;
  992. vncFbptr[index] = pbits;
  993. vncFbstride[index] = pvfb->fb.paddedWidth;
  994. miSetPixmapDepths();
  995. switch (pvfb->fb.depth) {
  996. case 8:
  997. miSetVisualTypesAndMasks (8,
  998. ((1 << StaticGray) |
  999. (1 << GrayScale) |
  1000. (1 << StaticColor) |
  1001. (1 << PseudoColor) |
  1002. (1 << TrueColor) |
  1003. (1 << DirectColor)),
  1004. 8, PseudoColor, 0, 0, 0);
  1005. break;
  1006. case 16:
  1007. miSetVisualTypesAndMasks (16,
  1008. ((1 << TrueColor) |
  1009. (1 << DirectColor)),
  1010. 8, TrueColor, 0xf800, 0x07e0, 0x001f);
  1011. break;
  1012. case 24:
  1013. miSetVisualTypesAndMasks (24,
  1014. ((1 << TrueColor) |
  1015. (1 << DirectColor)),
  1016. 8, TrueColor, 0xff0000, 0x00ff00, 0x0000ff);
  1017. break;
  1018. case 32:
  1019. miSetVisualTypesAndMasks (32,
  1020. ((1 << TrueColor) |
  1021. (1 << DirectColor)),
  1022. 8, TrueColor, 0xff000000, 0x00ff0000, 0x0000ff00);
  1023. break;
  1024. default:
  1025. return FALSE;
  1026. }
  1027. ret = fbScreenInit(pScreen, pbits, pvfb->fb.width, pvfb->fb.height,
  1028. dpi, dpi, pvfb->fb.paddedWidth, pvfb->fb.bitsPerPixel);
  1029. #ifdef RENDER
  1030. if (ret && Render)
  1031. ret = fbPictureInit (pScreen, 0, 0);
  1032. #endif
  1033. if (!ret) return FALSE;
  1034. #if XORG < 110
  1035. miInitializeBackingStore(pScreen);
  1036. #endif
  1037. /*
  1038. * Circumvent the backing store that was just initialised. This amounts
  1039. * to a truely bizarre way of initialising SaveDoomedAreas and friends.
  1040. */
  1041. pScreen->InstallColormap = vfbInstallColormap;
  1042. pScreen->UninstallColormap = vfbUninstallColormap;
  1043. pScreen->ListInstalledColormaps = vfbListInstalledColormaps;
  1044. pScreen->SaveScreen = vfbSaveScreen;
  1045. miPointerInitialize(pScreen, &vfbPointerSpriteFuncs, &vfbPointerCursorFuncs,
  1046. FALSE);
  1047. pScreen->blackPixel = pvfb->blackPixel;
  1048. pScreen->whitePixel = pvfb->whitePixel;
  1049. if (!pvfb->pixelFormatDefined) {
  1050. switch (pvfb->fb.depth) {
  1051. case 16:
  1052. pvfb->pixelFormatDefined = TRUE;
  1053. pvfb->rgbNotBgr = TRUE;
  1054. pvfb->blueBits = pvfb->redBits = 5;
  1055. pvfb->greenBits = 6;
  1056. break;
  1057. case 24:
  1058. case 32:
  1059. pvfb->pixelFormatDefined = TRUE;
  1060. pvfb->rgbNotBgr = TRUE;
  1061. pvfb->blueBits = pvfb->redBits = pvfb->greenBits = 8;
  1062. break;
  1063. }
  1064. }
  1065. if (pvfb->pixelFormatDefined) {
  1066. VisualPtr vis = pScreen->visuals;
  1067. for (int i = 0; i < pScreen->numVisuals; i++) {
  1068. if (pvfb->rgbNotBgr) {
  1069. vis->offsetBlue = 0;
  1070. vis->blueMask = (1 << pvfb->blueBits) - 1;
  1071. vis->offsetGreen = pvfb->blueBits;
  1072. vis->greenMask = ((1 << pvfb->greenBits) - 1) << vis->offsetGreen;
  1073. vis->offsetRed = vis->offsetGreen + pvfb->greenBits;
  1074. vis->redMask = ((1 << pvfb->redBits) - 1) << vis->offsetRed;
  1075. } else {
  1076. vis->offsetRed = 0;
  1077. vis->redMask = (1 << pvfb->redBits) - 1;
  1078. vis->offsetGreen = pvfb->redBits;
  1079. vis->greenMask = ((1 << pvfb->greenBits) - 1) << vis->offsetGreen;
  1080. vis->offsetBlue = vis->offsetGreen + pvfb->greenBits;
  1081. vis->blueMask = ((1 << pvfb->blueBits) - 1) << vis->offsetBlue;
  1082. }
  1083. vis++;
  1084. }
  1085. }
  1086. ret = fbCreateDefColormap(pScreen);
  1087. if (!ret) return FALSE;
  1088. miSetZeroLineBias(pScreen, pvfb->lineBias);
  1089. pvfb->closeScreen = pScreen->CloseScreen;
  1090. pScreen->CloseScreen = vfbCloseScreen;
  1091. #ifdef RANDR
  1092. rrScrPrivPtr rp;
  1093. ret = RRScreenInit(pScreen);
  1094. if (!ret) return FALSE;
  1095. rp = rrGetScrPriv(pScreen);
  1096. rp->rrGetInfo = vncRandRGetInfo;
  1097. rp->rrSetConfig = vncRandRSetConfig;
  1098. #endif
  1099. return TRUE;
  1100. } /* end vfbScreenInit */
  1101. static void vfbClientStateChange(CallbackListPtr*, pointer, pointer) {
  1102. dispatchException &= ~DE_RESET;
  1103. }
  1104. void
  1105. InitOutput(ScreenInfo *screenInfo, int argc, char **argv)
  1106. {
  1107. ErrorF("\nXvnc %s - built %s\n%s", XVNCVERSION, buildtime, XVNCCOPYRIGHT);
  1108. ErrorF("Underlying X server release %d, %s\n\n", VENDOR_RELEASE,
  1109. VENDOR_STRING);
  1110. int i;
  1111. int NumFormats = 0;
  1112. /* initialize pixmap formats */
  1113. /* must have a pixmap depth to match every screen depth */
  1114. for (i = 0; i < vfbNumScreens; i++)
  1115. {
  1116. vfbPixmapDepths[vfbScreens[i].fb.depth] = TRUE;
  1117. }
  1118. /* RENDER needs a good set of pixmaps. */
  1119. if (Render) {
  1120. vfbPixmapDepths[1] = TRUE;
  1121. vfbPixmapDepths[4] = TRUE;
  1122. vfbPixmapDepths[8] = TRUE;
  1123. /* vfbPixmapDepths[15] = TRUE; */
  1124. vfbPixmapDepths[16] = TRUE;
  1125. vfbPixmapDepths[24] = TRUE;
  1126. vfbPixmapDepths[32] = TRUE;
  1127. }
  1128. for (i = 1; i <= 32; i++)
  1129. {
  1130. if (vfbPixmapDepths[i])
  1131. {
  1132. if (NumFormats >= MAXFORMATS)
  1133. FatalError ("MAXFORMATS is too small for this server\n");
  1134. screenInfo->formats[NumFormats].depth = i;
  1135. screenInfo->formats[NumFormats].bitsPerPixel = vfbBitsPerPixel(i);
  1136. screenInfo->formats[NumFormats].scanlinePad = BITMAP_SCANLINE_PAD;
  1137. NumFormats++;
  1138. }
  1139. }
  1140. screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  1141. screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  1142. screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  1143. screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  1144. screenInfo->numPixmapFormats = NumFormats;
  1145. /* initialize screens */
  1146. for (i = 0; i < vfbNumScreens; i++)
  1147. {
  1148. if (-1 == AddScreen(vfbScreenInit, argc, argv))
  1149. {
  1150. FatalError("Couldn't add screen %d", i);
  1151. }
  1152. }
  1153. if (!AddCallback(&ClientStateCallback, vfbClientStateChange, 0)) {
  1154. FatalError("AddCallback failed\n");
  1155. }
  1156. } /* end InitOutput */
  1157. /* this is just to get the server to link on AIX */
  1158. #ifdef AIXV3
  1159. int SelectWaitTime = 10000; /* usec */
  1160. #endif
  1161. void DDXRingBell(int percent, int pitch, int duration)
  1162. {
  1163. if (percent > 0)
  1164. vncBell();
  1165. }
  1166. Bool LegalModifier(unsigned int key, DeviceIntPtr pDev)
  1167. {
  1168. return TRUE;
  1169. }
  1170. void ProcessInputEvents()
  1171. {
  1172. mieqProcessInputEvents();
  1173. #if XORG == 15
  1174. miPointerUpdate();
  1175. #endif
  1176. }
  1177. // InitInput is called after InitExtensions, so we're guaranteed that
  1178. // vncExtensionInit() has already been called.
  1179. void InitInput(int argc, char *argv[])
  1180. {
  1181. mieqInit ();
  1182. }
  1183. #if XORG > 17
  1184. void CloseInput(void)
  1185. {
  1186. }
  1187. #endif