home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Server / ddx.tbl.ms next >
Encoding:
Text File  |  1991-07-27  |  167.5 KB  |  4,719 lines

  1. .\" $XConsortium: ddx.tbl.ms,v 1.31 91/07/27 17:05:51 rws Exp $
  2. .EF 'Porting Layer Definition'- % -'April 22, 1991'
  3. .OF 'Porting Layer Definition'- % -'April 22, 1991'
  4. .EH '''
  5. .OH '''
  6. .TL
  7. Definition of the Porting Layer 
  8. for the X v11 Sample Server
  9. .AU
  10. Susan Angebranndt
  11. .AU
  12. Raymond Drewry
  13. .AU
  14. Philip Karlton
  15. .AU
  16. Todd Newman
  17. .AI
  18. Digital Equipment Corporation
  19. .sp
  20. minor revisions by
  21. .AU
  22. Bob Scheifler
  23. .AI
  24. Massachusetts Institute of Technology
  25. .sp
  26. Revised for Release 4 and Release 5 by
  27. .AU
  28. Keith Packard
  29. .AI
  30. MIT X Consortium
  31.  
  32. .LP
  33. The following document explains the
  34. structure of the X Window System display server and the interfaces among the larger pieces.
  35. It is intended as a reference for programmers who are implementing an X Display Server
  36. on their workstation hardware.
  37. It is included with the X Window System source tape,
  38. along with the document "Strategies for Porting the X v11 Sample Server."
  39. The order in which you should read these documents is:
  40.  
  41. .IP 1) 
  42. Read the first section 
  43. of the "Strategies for Porting" document (Overview of Porting Process).
  44.  
  45. .IP 2) 
  46. Skim over this document (the Definition document).
  47.  
  48. .IP 3) 
  49. Skim over the remainder of the Strategies document.
  50.  
  51. .IP 4) 
  52. Start planning and working, referring to the Strategies
  53. and Definition documents.
  54.  
  55. You may also want to look at the following documents:
  56. .IP \(bu 5
  57. "The X Window System"
  58. for an overview of X.
  59. .IP \(bu 5
  60. "Xlib - C Language X Interface"
  61. for a view of what the client programmer sees.
  62. .IP \(bu 5
  63. "X Window System Protocol"
  64. for a terse description of the byte stream protocol
  65. between the client and server.
  66. .LP
  67. UNIX is a trademark of AT&T.
  68. QVSS, LK201, ULTRIX, VMS, DEC, MicroVAX and VAX are trademarks of Digital Equipment Corporation.
  69. Macintosh and Apple are trademarks of Apple Computer, Inc.
  70. PostScript is a trademark of Adobe Systems, Inc.
  71. Ethernet is a trademark of Xerox Corporation.
  72. The X Window System is a trademark of Massachusetts Institute of Technology.
  73. Cray is a trademark of Cray Research, Inc.
  74.  
  75. .LP
  76. To understand this document and the accompanying source
  77. code, you should know the C language.
  78. You should be familiar with 2D graphics and windowing
  79. concepts such as clipping, bitmaps,
  80. fonts, etc.
  81. You should have a general knowledge of the X Window System.
  82. To implement the server code on your hardware,
  83. you need to know a lot about
  84. your hardware, its graphic display device(s),
  85. and (possibly) its networking and multitasking facilities.
  86.  
  87. This document depends a lot on the source code,
  88. so you should have a listing of the code handy.
  89. .LP
  90. Some source on the distribution tape is directly compilable
  91. on your machine.
  92. Some of it will require
  93. modification.
  94. Other parts may have to be completely written from scratch.
  95. .LP
  96. The tape also includes source for a sample implementation of a display
  97. server which runs on a variety of color and monochrome displays which you
  98. will find useful for implementing any type of X server.
  99.  
  100.  
  101. .NH 1
  102. The X Window System
  103. .XS
  104. The X Window System
  105. .XE
  106. .LP
  107. The X Window System, or simply "X," is a
  108. windowing system that provides high-performance, high-level,
  109. device-independent graphics.
  110.  
  111. X is a windowing system designed for bitmapped graphic displays.
  112. The display can have a
  113. simple, monochrome display or it can have a color display with up to 32 bits
  114. per pixel with a special graphics processor doing the work.  (In this
  115. document, monochrome means a black and white display with one bit per pixel.
  116. Even though the usual meaning of monochrome is more general, this special
  117. case is so common that we decided to reserve the word for this purpose.)
  118.  
  119. X is designed for a networking environment where 
  120. users can run applications on machines other than their own workstations.
  121. Sometimes, the connection is over an Ethernet network with a protocol such as TCP/IP;
  122. but, any "reliable" byte stream is allowable.
  123. A high-bandwidth byte stream is preferable; RS-232 at
  124. 9600 baud would be slow without compression techniques.
  125.  
  126. X by itself allows great freedom of design.
  127. For instance, it does not include any user interface standard.
  128. Its intent is to "provide mechanism, not policy."
  129. By making it general, it can be the foundation for a wide
  130. variety of interactive software.
  131.  
  132. For a more detailed overview, see the document "The X Window System."
  133. For details on the byte stream protocol, see "X Window System protocol."
  134.  
  135. .NH 1
  136. OVERVIEW OF THE SERVER
  137. .XS
  138. OVERVIEW OF THE SERVER
  139. .XE
  140. .LP
  141. The display server
  142. manages windows and simple graphics requests
  143. for the user on behalf of different client applications.
  144. The client applications can be running on any machine on the network.
  145. The server mainly does three things:
  146. .IP \(bu 5
  147. Responds to protocol requests from existing clients 
  148. (mostly graphic and text drawing commands)
  149. .IP \(bu 5
  150. Sends device input (keystrokes and mouse actions) and other events to existing clients
  151. .IP \(bu 5
  152. Maintains client connections
  153.  
  154. .LP
  155. The server code is organized into four major pieces:
  156.  
  157. .IP \(bu 5
  158. Device Independent (DIX) layer - code 
  159. shared among all implementations
  160. .IP \(bu 5
  161. Operating System (OS) layer - code 
  162. that is different for each operating system
  163. but is shared among all graphic 
  164. devices for this operating system
  165. .IP \(bu 5
  166. Device Dependent (DDX) layer - code that is (potentially)
  167. different for each combination of operating
  168. system and graphic device
  169. .IP \(bu 5
  170. Extension Interface - a standard way to add
  171. features to the X server
  172.  
  173. .LP
  174. The "porting layer" consists of the OS and DDX layers; these are
  175. actually parallel and neither one is on top of the other.
  176. The DIX layer is intended to be portable 
  177. without change to target systems and is not
  178. detailed here, although several routines 
  179. in DIX that are called by DDX are
  180. documented.
  181. Extensions incorporate new functionality into the server; and require
  182. additional functionality over a simple DDX.
  183. .LP
  184. The following sections outline the functions of the layers.
  185. Section 3 briefly tells what you need to know about the DIX layer.
  186. The OS layer is explained in Section 4.
  187. Section 5 gives the theory of operation and procedural interface for the
  188. DDX layer.
  189. Section 6 describes the functions which exist for the extension writer.
  190.  
  191. .NH 2
  192. Notes On Resources and Large Structs
  193. .XS
  194. Notes On Resources and Large Structs
  195. .XE
  196. .LP
  197. X resources are C structs inside the server.
  198. Client applications create and manipulate these objects 
  199. according to the rules of the X byte stream protocol.
  200. Client applications refer to resources with resource IDs, 
  201. which are 32-bit integers that are sent over the network.
  202. Within the server, of course, they are just C structs, and we refer to them
  203. by pointers.
  204.  
  205. The DDX layer has several kinds of resources:
  206. .IP \(bu 5
  207. Window 
  208. .IP \(bu 5
  209. Pixmap
  210. .IP \(bu 5
  211. Screen
  212. .IP \(bu 5
  213. Device
  214. .IP \(bu 5
  215. Colormap
  216. .IP \(bu 5
  217. Font
  218. .IP \(bu 5
  219. Cursor
  220. .IP \(bu 5
  221. Graphics Contexts
  222. .LP
  223. The type names of the more 
  224. important server 
  225. structs usually end in "Rec," such as "DeviceRec;"
  226. the pointer types usually end in "Ptr," such as "DevicePtr."
  227.  
  228. The structs and
  229. important defined constants are declared
  230. in .h files that have names that suggest the name of the object.
  231. For instance, there are two .h files for windows,
  232. window.h and windowstr.h.
  233. window.h defines only what needs to be defined in order to use windows 
  234. without peeking inside of them;
  235. windowstr.h defines the structs with all of their components in great detail
  236. for those who need it.
  237. .LP
  238. Three kinds of fields are in these structs:
  239. .IP \(bu 5
  240. Attribute fields - struct fields that contain values like normal structs
  241. .IP \(bu 5
  242. Pointers to procedures, or structures of procedures, that operate on the
  243. object
  244. .IP \(bu 5
  245. A private field (or two) used by your DDX code to keep private data
  246. (probably a pointer
  247. to another data structure), or an array of private fields, which is
  248. sized as the server initializes.
  249. .LP
  250. DIX calls through
  251. the struct's procedure pointers to do its tasks.
  252. These procedures are set either directly or indirectly by DDX procedures.
  253. Most of
  254. the procedures described in the remainder of this
  255. document are accessed through one of these structs.
  256. For example, the procedure to create a pixmap
  257. is attached to a ScreenRec and might be called by using the expression
  258. .nf
  259.  
  260.         (* pScreen->CreatePixmap)(pScreen, width, height, depth).
  261.  
  262. .fi
  263. All procedure pointers must be set to some routine unless noted otherwise;
  264. a null pointer will have unfortunate consequences.
  265.  
  266. Procedure routines will be indicated in the documentation by this convention:
  267. .nf
  268.  
  269.     void pScreen->MyScreenRoutine(arg, arg, ...)
  270.  
  271. .fi
  272. as opposed to a free routine, not in a data structure:
  273. .nf
  274.  
  275.     void MyFreeRoutine(arg, arg, ...)
  276.  
  277. .fi
  278.  
  279. The attribute fields are mostly set by DIX; DDX should not modify them 
  280. unless noted otherwise.
  281.  
  282. .NH 1
  283. DIX LAYER
  284. .XS
  285. DIX LAYER
  286. .XE
  287. .LP
  288. The DIX layer is the machine and device independent part of X.
  289. The source should be common to all operating systems and devices.
  290. The port process should not include changes to this part, therefore internal interfaces to DIX 
  291. modules are not discussed, except for public interfaces to the DDX and the OS layers.
  292.  
  293. In the process of getting your server to work, if
  294. you think that DIX must be modified for purposes other than bug fixes,
  295. you may be doing something wrong.
  296. Keep looking for a more compatible solution.
  297. When the next release of the X server code is available,
  298. you should be able to just drop in the new DIX code and compile it.
  299. If you change DIX,
  300. you will have to remember what changes you made and will have
  301. to change the new sources before you can update to the new version.
  302.  
  303. The heart of the DIX code is a loop called the dispatch loop.
  304. Each time the processor goes around the loop, it sends off accumulated input events
  305. from the input devices to the clients, and it processes requests from the clients.
  306. This loop is the most organized way for the server to
  307. process the asynchronous requests that
  308. it needs to process.
  309. Most of these operations are performed by OS and DDX routines that you must supply.
  310.  
  311. .NH 1
  312. OS LAYER
  313. .XS
  314. OS LAYER
  315. .XE
  316. .LP
  317. This part of the source consists of a few routines that you have to rewrite 
  318. for each operating system.
  319. These OS functions maintain the client connections and schedule work 
  320. to be done for clients.  
  321. They also provide an interface to font files,
  322. font name to file name translation, and
  323. low level memory management.
  324.  
  325. .nf
  326.     void OsInit()
  327. .fi
  328. OsInit initializes your OS code, performing whatever tasks need to be done.
  329. Frequently there is not much to be done.
  330. The sample server implementation is in server/os/4.2bsd/osinit.c.
  331.  
  332. .NH 2
  333. Scheduling and Request Delivery
  334. .XS
  335. Scheduling and Request Delivery
  336. .XE
  337. .LP
  338. The main dispatch loop in DIX creates the illusion of multitasking between 
  339. different windows, while the server is itself but a single process.
  340. The dispatch loop breaks up the work for each client into small digestible parts.
  341. Some parts are requests from a client, such as individual graphic commands.
  342. Some parts are events delivered to the client, such as keystrokes from the user.
  343. The processing of events and requests for different
  344. clients can be interleaved with one another so true multitasking
  345. is not needed in the server.
  346.  
  347. You must supply some of the pieces for proper scheduling between clients.
  348. .nf
  349.  
  350.     int WaitForSomething(pClientReady)
  351.         int *pClientReady;
  352. .fi
  353. .LP
  354. WaitForSomething is the scheduler procedure you must write that will
  355. suspend your server process until something needs to be done.   
  356. This call should
  357. make the server suspend until one or more of the following occurs:
  358. .IP \(bu 5
  359. There is an input event from the user or hardware (see SetInputCheck())
  360. .IP \(bu 5
  361. There are requests waiting from known clients, in which case 
  362. you should return a count of clients stored in pClientReady
  363. .IP \(bu 5
  364. A new client tries to connect, in which case you should create the
  365. client and  then continue waiting
  366. .LP
  367. Before WaitForSomething() computes the masks to pass to select, it needs to
  368. see if there is anything to do on the work queue; if so, it must call a DIX
  369. routine called ProcessWorkQueue.
  370. .nf
  371.     extern WorkQueuePtr    workQueue;
  372.  
  373.     if (workQueue)
  374.         ProcessWorkQueue ();
  375. .fi
  376. .LP
  377. If WaitForSomething() decides it is about to do something that might block
  378. (in the sample server,  before it calls select()) it must call a DIX
  379. routine called BlockHandler().
  380. .nf
  381.  
  382.     BlockHandler(pTimeout, pReadmask)
  383.         pointer pTimeout;
  384.         pointer pReadmask;
  385. .fi
  386. The types of the arguments are for agreement between the OS and DDX
  387. implementations,  but the pTimeout is a pointer to the information
  388. determining how long the block is allowed to last,  and the
  389. pReadmask is a pointer to the information describing the descriptors
  390. that will be waited on.
  391. .LP
  392. In the 4.2 case,  pTimeout is a struct timeval **,  and pReadmask is
  393. the address of the select mask for reading.
  394. .LP
  395. Immediately after it returns from the
  396. block,  even if it didn't actually block,  it must call the DIX routine
  397. WakeupHandler().
  398. .nf
  399.  
  400.     WakeupHandler(result, pReadmask)
  401.         unsigned long result;
  402.         pointer pReadmask;
  403. .fi
  404. .LP
  405. Once again,  the types are not specified by DIX.  The result is the
  406. success indicator for the thing that (may have) blocked,
  407. and the pReadmask is a mask of the descriptors that came active.
  408. .LP
  409. In the 4.2 case,  result is the result from select(),  and pReadmask is
  410. the address of the select mask for reading.
  411. .LP
  412. The DIX BlockHandler() iterates through the Screens,  for each one calling
  413. its BlockHandler.  A BlockHandler is declared thus:
  414. .nf
  415.  
  416.     void xxxBlockHandler(nscreen, pbdata, pptv, pReadmask)
  417.         int nscreen;
  418.         pointer pbdata;
  419.         pointer pptv;
  420.         pointer pReadmask;
  421. .fi
  422. The arguments are the index of the Screen,  the BlockData field
  423. of the Screen,  and the arguments to the DIX BlockHandler().
  424. .LP
  425. In addition to the per-screen BlockHandlers, any module may register
  426. block and wakeup handlers (only together) using:
  427. .nf
  428.  
  429.     Bool RegisterBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
  430.         void    (*blockHandler)();
  431.         void    (*wakeupHandler)();
  432.         pointer blockData;
  433. .fi
  434. A FALSE return code indicates that the registration failed for lack of
  435. memory.  To remove a registered Block handler at other than server reset time
  436. (when they are all removed automatically), use:
  437. .nf
  438.     RemoveBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
  439.         void    (*blockHandler)();
  440.         void    (*wakeupHandler)();
  441.         pointer blockData;
  442. .fi
  443. All three arguments must match the values passed to
  444. RegisterBlockAndWakeupHandlers.
  445. .LP
  446. These registered block handlers are called after the per-screen handlers:
  447. .nf
  448.  
  449.     void (*BlockHandler) (blockData, pptv, pReadmask)
  450.         pointer    blockData;
  451.         pointer    pptv;
  452.         pointer    pReadmask;
  453. .fi
  454. .LP
  455. The DIX WakeupHandler() does the same thing,  calling each Screen's
  456. WakeupHandler.  A WakeupHandler is declared thus:
  457. .nf
  458.  
  459.     void xxxWakeupHandler(nscreen, pbdata, err, pReadmask)
  460.         int nscreen;
  461.         pointer pbdata;
  462.         unsigned long err;
  463.         pointer pReadmask;
  464. .fi
  465. The arguments are the index of the Screen,  the BlockData field
  466. of the Screen,  and the arguments to the DIX BlockHandler().
  467. .LP
  468. Any wakeup handlers registered with RegisterBlockAndWakeupHandlers will
  469. be called before the Screen handlers:
  470. .nf
  471.  
  472.     void (*WakeupHandler) (blockData, err, pReadmask)
  473.         pointer    blockData;
  474.         unsigned long err;
  475.         pointer pReadmask;
  476. .fi
  477. .LP
  478. The WaitForSomething on the sample server also has a built
  479. in screen saver that darkens the screen if no input happens for a period of time.
  480. The sample server implementation is in server/os/4.2bsd/WaitFor.c.
  481. .LP
  482. Note that WaitForSomething() may be called when you already have several
  483. outstanding things (events, requests, or new clients) queued up.
  484. For instance, your server may have just done a large graphics request,
  485. and it may have been a long time since WaitForSomething() was last called.
  486. If many clients have lots of requests queued up, DIX will only service
  487. some of them for a given client
  488. before going on to the next client (see isItTimeToYield, below).
  489. Therefore, WaitForSomething() will have to report that these same clients
  490. still have requests queued up the next time around.
  491. .LP
  492. An implementation should return information on as
  493. many outstanding things as it can.
  494. For instance, if your implementation always checks for client data first and does not
  495. report any input events until there is no client data left,
  496. your mouse and keyboard might get locked out by an application that constantly
  497. barrages the server with graphics drawing requests.
  498. .LP
  499. A list of indexes (client->index) for clients with data ready to be read or
  500. processed should be returned in pClientReady, and the count of indexes
  501. returned as the result value of the call.
  502. This is not clients that have full requests ready, but any clients who have
  503. any data ready to be read or processed.
  504. The DIX dispatcher
  505. will process requests from each client in turn by calling 
  506. ReadRequestFromClient(), below.   
  507. .LP
  508. WaitForSomething() must create new clients as they are requested (by
  509. whatever mechanism at the transport level).  A new client is created
  510. by calling the DIX routine:
  511. .nf
  512.  
  513.     ClientPtr NextAvailableClient(ospriv)
  514.         pointer ospriv;
  515. .fi
  516. This routine returns NULL if a new client cannot be allocated (e.g. maximum
  517. number of clients reached).  The ospriv argument will be stored into the OS
  518. private field (pClient->osPrivate), to store OS private information about the 
  519. client.  In the sample server, the osPrivate field contains the 
  520. number of the socket for this client. See also "New Client Connections."
  521. NextAvailableClient() will call InsertFakeRequest(), so you must be
  522. prepared for this.
  523. .LP
  524. If there are outstanding input events,
  525. you should make sure that the two SetInputCheck() locations are unequal.
  526. The DIX dispatcher will call your implementation of ProcessInputEvents()
  527. until the SetInputCheck() locations are equal.
  528. .LP
  529. The sample server contains an implementation of WaitForSomething()
  530. that is portable to UNIX 4.2 systems and to other systems as well.
  531. In it, the
  532. following two routines indicate to WaitForSomething() what devices should
  533. be waited for.   FID is an OS dependent type; in the sample server
  534. it is an open file descriptor.
  535. .nf
  536.  
  537.     void AddEnabledDevice(fd)
  538.         FID fd;
  539.  
  540.     void RemoveEnabledDevice(fd)
  541.         FID fd;
  542. .fi
  543. These two routines are
  544. called from the initialize cases of the
  545. Input Procedures that are stored in the DeviceRec (the
  546. routine passed to AddInputDevice()).
  547. The sample server implementation is in server/os/4.2bsd/connection.c.
  548. .nf
  549.  
  550.     Bool isItTimeToYield;
  551. .fi
  552. .LP
  553. isItTimeToYield is a global variable you can set 
  554. if you want to tell
  555. DIX to end the client's "time slice" and start paying attention to the next client.
  556. After the current request is finished, DIX will move to the next client.
  557. .LP
  558. In the sample
  559. server, ReadRequestFromClient() sets isItTimeToYield after
  560. 10 requests packets in a row are read from the same client.
  561. .LP
  562. This scheduling algorithm can have a serious effect upon performance when two
  563. clients are drawing into their windows simultaneously.
  564. If it allows one client to run until its request 
  565. queue is empty by ignoring isItTimeToYield, the client's queue may
  566. in fact never empty and other clients will be blocked out.
  567. On the other hand, if it switchs between different clients too quickly,
  568. performance may suffer due to too much switching between contexts.
  569. For example, if a graphics processor needs to be set up with drawing modes
  570. before drawing, and two different clients are drawing with
  571. different modes into two different windows, you may 
  572. switch your graphics processor modes so often that performance is impacted.
  573. .LP
  574. See the Strategies document for 
  575. heuristics on setting isItTimeToYield.
  576.  
  577. .NH 2
  578. New Client Connections
  579. .XS
  580. New Client Connections
  581. .XE
  582. .LP
  583. The process whereby a new client-server connection starts up is 
  584. very dependent upon what your byte stream mechanism.
  585. This section describes byte stream initiation using examples from the TCP/IP
  586. implementation on the sample server.
  587. .LP
  588. The first thing that happens is a client initiates a connection with the server.
  589. How a client knows to do this depends upon your network facilities and the
  590. Xlib implementation.
  591. In a typical scenario, a user named Fred 
  592. on his X workstation is logged onto a Cray
  593. supercomputer running a UNIX shell in an X window.  Fred can type shell
  594. commands and have the Cray respond as though the X server were a dumb terminal.
  595. Fred types in a command to run an X client application that was linked with Xlib.
  596. Xlib looks at the UNIX environment variable DISPLAY, which has the 
  597. value "fredsbittube:0.0."
  598. The host name of Fred's workstation is "fredsbittube," and the 0s are 
  599. for multiple screens and multiple X server processes.
  600. (Precisely what 
  601. happens on your system depends upon how X and Xlib are implemented.)
  602. .LP
  603. The client application calls a TCP routine on the 
  604. Cray to open a TCP connection for X
  605. to communicate with the network node "fredsbittube."
  606. The TCP software on the Cray does this by looking up the TCP
  607. address of "fredsbittube" and sending an open request to TCP port 6000
  608. on fredsbittube.  
  609. .LP
  610. All X servers on TCP listen for new clients on port 6000;
  611. this is known as a "well-known port" in IP terminology.
  612. .LP
  613. The server receives this request from its port 6000
  614. and checks where it came from to see if it is on the server's list
  615. of "trustworthy" hosts to talk to.
  616. Then, it opens another port for communications with the client.
  617. This is the byte stream that all X communications will go over.
  618. .LP
  619. Actually, it is a bit more complicated than that.
  620. Each X server process running on the host machine is called a "display."
  621. Each display can have more than one screen that it manages.
  622. "corporatehydra:3.2" represents screen 2 on display 3 on 
  623. the multi-screened network node corporatehydra.
  624. The open request would be sent on well-known port number 6003.
  625. .LP
  626. Once the byte stream is set up, what goes on does not depend very much
  627. upon whether or not it is TCP.
  628. The client sends an xConnClientPrefix struct (see Xproto.h) that has the
  629. version numbers for the version of Xlib it is running, some byte-ordering information, 
  630. and two character strings used for authorization.
  631. If the server does not like the authorization strings
  632. or the version numbers do not match within the rules,
  633. or if anything else is wrong, it sends a failure 
  634. response with a reason string.
  635. .LP
  636. If the information never comes, or comes much too slowly, the connection will
  637. should be broken off.  You must implement the connection timeout.  The
  638. sample server implements this by keeping a timestamp for each still-connecting
  639. client and, each time just before it attempts to accept new connections, it
  640. closes any connection that are too old.
  641. The connection timeout can be set from the command line.
  642. .LP
  643. You must implement whatever authorization schemes you want to support.
  644. The sample server on the distribution tape supports a simple authorization
  645. scheme.  The only interface seen by DIX is:
  646. .nf
  647.  
  648.     char *
  649.     ClientAuthorized(client, proto_n, auth_proto, string_n, auth_string)
  650.         ClientPtr client;
  651.         char *auth_proto, *auth_string;
  652.         int proto_n, string_n;
  653. .fi
  654. .LP
  655. DIX will only call this once per client, once it has read the full initial
  656. connection data from the client.  If the connection should be
  657. accepted ClientAuthorized() should return NULL, and otherwise should
  658. return an error message string.
  659. .LP
  660. Accepting new connections happens internally to WaitForSomething().
  661. WaitForSomething() must call the DIX routine NextAvailableClient()
  662. to create a client object.
  663. Processing of the initial connection data will be handled by DIX.
  664. Your OS layer must be able to map from a client
  665. to whatever information your OS code needs to communicate
  666. on the given byte stream to the client.
  667. DIX uses this ClientPtr to refer to
  668. the client from now on.   The sample server uses the osPrivate field in
  669. the ClientPtr to store the file descriptor for the socket, the
  670. input and output buffers, and authorization information.
  671. .LP
  672. To initialize the methods you choose to allow clients to connect to
  673. your server, main() calls the routine
  674. .nf
  675.  
  676.     CreateWellKnownSockets()
  677. .fi
  678. .LP
  679. This routine is called only once, and not called when the server
  680. is reset.  To recreate any sockets during server resets, the following
  681. routine is called from the main loop:
  682. .nf
  683.  
  684.     ResetWellKnownSockets()
  685. .fi
  686. Sample implementations of both of these routines are found in 
  687. server/os/4.2bsd/connection.c.
  688. .LP
  689. For more details, see the section called "Connection Setup" in the X protocol specification.
  690.  
  691. .NH 2
  692. Reading Data from Clients
  693. .XS
  694. Reading Data from Clients
  695. .XE
  696. .LP
  697. Requests from the client are read in as a byte stream by the OS layer.
  698. They may be in the form of several blocks of bytes delivered in sequence; requests may
  699. be broken up over block boundaries or there may be many requests per block.
  700. Each request carries with it length information.
  701. It is the responsibility of the following routine to break it up into request blocks.
  702. .nf
  703.  
  704.     int ReadRequestFromClient(who)
  705.         ClientPtr who;
  706. .fi
  707. .LP
  708. You must write
  709. the routine ReadRequestFromClient() to get one request from the byte stream
  710. belonging to client "who."
  711. You must swap the third and fourth bytes (the second 16-bit word) according to the 
  712. byte-swap rules of
  713. the protocol to determine the length of the
  714. request.  
  715. This length is measured in 32-bit words, not in bytes.  Therefore, the 
  716. theoretical maximum request is 256K.
  717. (However, the maximum length allowed is dependent upon the server's input
  718. buffer.  This size is sent to the client upon connection.  The maximum 
  719. size is the constant MAX_REQUEST_SIZE in server/include/os.h)
  720. The rest of the request you return is
  721. assumed NOT to be correctly swapped for internal 
  722. use, because that is the responsibility of DIX.
  723. .LP
  724. 'who' is the ClientPtr returned from WaitForSomething.
  725. The return value indicating status should be set to the (positive) byte count if the read is successful, 
  726. 0 if the read was blocked, or a negative error code if an error happened.
  727. .LP
  728. You must then store a pointer to
  729. the bytes of the request in the client request buffer field;
  730. who->requestBuffer.  This can simply be a pointer into your buffer;
  731. DIX may modify it in place but will not otherwise cause damage.
  732. Of course, the request must be contiguous; you must 
  733. shuffle it around in your buffers if not.
  734.  
  735. The sample server implementation is in server/os/4.2bsd/io.c.
  736.  
  737. .XS
  738. Inserting Data for Clients
  739. .XE
  740. .LP
  741. DIX can insert data into the client stream, and can cause a "replay" of
  742. the current request.
  743. .nf
  744.  
  745.     Bool InsertFakeRequest(client, data, count)
  746.         ClientPtr client;
  747.         char *data;
  748.         int count;
  749.  
  750.     ResetCurrentRequest(client)
  751.         ClientPtr client;
  752. .fi
  753. .LP
  754. InsertFakeRequest() must insert the specified number of bytes of data
  755. into the head of the input buffer for the client.  This may be a
  756. complete request, or it might be a partial request.  For example,
  757. NextAvailableCient() will insert a partial request in order to read
  758. the initial connection data sent by the client.  The routine returns FALSE
  759. if memory could not be allocated.  ResetCurrentRequest()
  760. should "back up" the input buffer so that the currently executing request
  761. will be reexecuted.  DIX may have altered some values (e.g. the overall
  762. request length), so you must recheck to see if you still have a complete
  763. request.  ResetCurrentRequest() should always cause a yield (isItTimeToYield).
  764.  
  765. .NH 2
  766. Sending Events, Errors And Replies To Clients
  767. .XS
  768. Sending Events, Errors And Replies To Clients
  769. .XE
  770. .LP
  771. .nf
  772.  
  773.     int WriteToClient(who, n, buf)
  774.         ClientPtr who;
  775.         int n;
  776.         char *buf;
  777. .fi
  778. WriteToClient should write n bytes starting at buf to the 
  779. ClientPtr "who".
  780. It returns the number of bytes written, but for simplicity,
  781. the number returned must be either the same value as the number
  782. requested, or -1, signaling an error.
  783. The sample server implementation is in server/os/4.2bsd/io.c.
  784. .LP
  785. .nf
  786.     SendErrorToClient(client, majorCode, minorCode, resId, errorCode)
  787.         ClientPtr client;
  788.         unsigned majorCode;
  789.         unsigned short minorCode;
  790.         XID resId;
  791.         int errorCode;
  792. .fi
  793. SendErrorToClient can be used to send errors back to clients,
  794. although in most cases your request function should simply return
  795. the error code, having set client->errorValue to the appropriate
  796. error value to return to the client, and DIX will call this
  797. function with the correct opcodes for you.
  798. .LP
  799. .nf
  800.  
  801.     void FlushAllOutput()
  802.  
  803.     void FlushIfCriticalOutputPending()
  804.  
  805.     void SetCriticalOutputPending()
  806. .fi
  807. These three routines may be implemented to support buffered or delayed
  808. writes to clients, but at the very least, the stubs must exist.
  809. FlushAllOutput() unconditionally flushes all output to clients;
  810. FlushIfCriticalOutputPending() flushes output only if
  811. SetCriticalOutputPending() has be called since the last time output
  812. was flushed.
  813. The sample server implementation is in server/os/4.2bsd/io.c and
  814. actually ignores requests to flush output on a per-client basis
  815. if it knows that there
  816. are requests in that client's input queue.
  817. .NH 2
  818. Font Support
  819. .XS
  820. Font Support
  821. .XE
  822. .LP
  823. In the sample server, fonts are encoded in disk files or fetched from the
  824. font server.
  825. For disk fonts, there is one file per font, with a file name like
  826. "fixed.pcf".  Font server fonts are read over the network using the
  827. X Font Server Protocol.  The disk directories containing disk fonts and
  828. the names of the font servers are listed together in the current "font path."
  829.  
  830. In principle, you can put all your fonts in ROM or in RAM in your server.
  831. You can put them all in one library file on disk.
  832. You could generate them on the fly from stroke descriptions.  By placing the
  833. appropriate code in the Font Library, you will automatically export fonts in
  834. that format both through the X server and the Font server.
  835.  
  836. With the incorporation of font-server based fonts and the Speedo donation
  837. from Bitstream, the font interfaces have been moved into a separate
  838. library, now called the Font Library (../fonts/lib).  These routines are
  839. shared between the X server and the Font server, so instead of this document
  840. specifying what you must implement, simply refer to the font
  841. library interface specification for the details.  All of the interface code to the Font
  842. library is contained in dix/dixfonts.c
  843. .NH 2
  844. Memory Management
  845. .XS
  846. Memory Management
  847. .XE
  848. .LP
  849. Memory management is the same as in the UNIX runtime library.
  850. Xalloc(), Xrealloc(),  and Xfree() work just like malloc(), 
  851. realloc(), and free(),
  852. except that you can pass a null pointer to Xrealloc() to have it allocate
  853. anew or
  854. pass a null pointer to Xfree() and nothing will happen.
  855. The versions in the sample server also do some checking that is useful for debugging.
  856. Consult a C runtime library reference manual for more details.
  857.  
  858. The macros ALLOCATE_LOCAL and DEALLOCATE_LOCAL are provided in
  859. server/include/os.h.  These are useful if
  860. your compiler supports alloca() (or some
  861. method of allocating memory from the stack); and are defined appropriately
  862. on systems which support it.
  863.  
  864. Treat memory allocation carefully in your implementation.
  865. Memory leaks can be very hard to find and are frustrating
  866. to a user.  An X server could be running
  867. for days or weeks without being reset, just like a regular terminal.
  868. If you leak a few dozen k per day, that will add up and will cause problems
  869. for users that leave their workstations on.
  870.  
  871. .NH 2
  872. Client Scheduling
  873. .XS
  874. Client Scheduling
  875. .XE
  876. .LP
  877. To support the Multi-buffering extension, some OS routines were added
  878. which provide the ability to suspend request processing on a particular
  879. client, resuming it at some later time:
  880. .nf
  881.  
  882.     IgnoreClient (who)
  883.         ClientPtr who;
  884.  
  885.     AttendClient (who)
  886.         ClientPtr who;
  887. .fi
  888. Ignore client is responsible for pretending that the given client doesn't
  889. exist.  WaitForSomething should not return this client as ready for reading
  890. and should not return if only this client is ready.  AttendClient undoes
  891. whatever IgnoreClient did, setting it up for input again.
  892. .NH 2
  893. Other OS Functions
  894. .XS
  895. Other OS Functions
  896. .XE
  897. .LP
  898. .nf
  899.     void
  900.     ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)
  901.         char *f;
  902.         char *s0, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
  903.  
  904.     void
  905.     FatalError(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)
  906.         char *f;
  907.         char *s0, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
  908.  
  909.     void
  910.     Error(str)
  911.         char *str;
  912. .fi
  913. .LP
  914. You should write
  915. these three routines to provide for diagnostic output from the dix and
  916. ddx layers, although implementing them to produce no output will not
  917. affect the correctness of your server.
  918. ErrorF() and FatalError() take
  919. a printf() type of format specification in the first argument and
  920. up to ten format arguments following that.
  921. Normally, the formats passed to ErrorF() and FatalError() should be
  922. terminated with a newline.
  923. Error() provides an os interface for printing out the string passed
  924. as an argument followed by a meaningful explanation of the last
  925. system error.
  926. Normally the string does not contain a newline, and it is only called
  927. by the ddx layer.
  928. In the sample implementation, Error() uses the Unix routine perror().
  929. .LP
  930. After printing the message arguments, FatalError() must be implemented
  931. such that the server will call AbortDDX() to give the ddx layer
  932. a chance to reset the hardware, and then
  933. terminate the server; it must not return.
  934. .LP
  935. The sample server implementation for these routines
  936. is in server/os/4.2bsd/util.c.
  937.  
  938. .NH 1
  939. DDX LAYER
  940. .XS
  941. DDX LAYER
  942. .XE
  943. .LP
  944. This section describes the
  945. interface between DIX and DDX.
  946. While there may be an OS-dependent driver interface between DDX
  947. and the physical device, that interface is left to the DDX
  948. implementor and is not specified here.
  949. .LP
  950. The DDX layer does most of its work through procedures that are
  951. pointed to by different structs.
  952. As previously described, the behavior of these resources is largely determined by
  953. these procedure pointers.
  954. Most of these routines are for graphic display on the screen or support functions thereof.
  955. The rest are for user input from input devices.
  956.  
  957. .NH 2
  958. INPUT
  959. .XS
  960. INPUT
  961. .XE
  962. .LP
  963. In this document "input" refers to input from the user, 
  964. such as mouse, keyboard, and
  965. bar code readers.
  966. X input devices are of several: keyboard, pointing device, and
  967. many others.  The core server has support for extension devices as
  968. described by the X Input Extension document; the interfaces used by
  969. that extension are described elsewhere.  The core devices are actually
  970. implemented as two collections of devices, the mouse is a ButtonDevice,
  971. a ValuatorDevice and a PtrFeedbackDevice while the keyboard is a KeyDevice,
  972. a FocusDevice and a KbdFeedbackDevice.  Each part implements a portion of
  973. the functionality of the device.  This abstraction is hidden from view for
  974. core devices by DIX.
  975.  
  976. You, the DDX programmer, are
  977. responsible for some of the routines in this section.
  978. Others are DIX routines that you should call to do the things you need to do in these DDX routines.
  979. Pay attention to which is which.
  980.  
  981. .NH 3
  982. Input Device Data Structures
  983. .XS
  984. Input Device Data Structures
  985. .XE
  986. .LP
  987. DIX keeps a global directory of devices in a central data structure
  988. called InputInfo.
  989. For each device there is a device structure called a DeviceRec.
  990. DIX can locate any DeviceRec through InputInfo.
  991. In addition, it has a special pointer to identify the main pointing device
  992. and a special pointer to identify the main keyboard.
  993. .LP
  994. The DeviceRec (server/include/input.h) is a device-independent
  995. structure that contains the state of an input device.
  996. A DevicePtr is simply a pointer to a DeviceRec.
  997. .LP
  998. An xEvent describes an event the server reports to a client.
  999. Defined in Xproto.h, it is a huge struct of union of structs that have fields for
  1000. all kinds of events.
  1001. All of the variants overlap, so that the struct is actually very small in memory.
  1002.  
  1003. .NH 3
  1004. Processing Events
  1005. .XS
  1006. Processing Events
  1007. .XE
  1008. .LP
  1009. The main DDX input interface is the following routine:
  1010. .nf
  1011.  
  1012.     void ProcessInputEvents()
  1013. .fi
  1014. You must write this routine to deliver input events from the user.
  1015. DIX calls it when input is pending, and possibly 
  1016. even when it is not.  
  1017. You should write it to get events from each device and deliver
  1018. the events to DIX.
  1019. To deliver the events to DIX, you should call the following
  1020. routine:
  1021. .nf
  1022.  
  1023.     void DevicePtr->processInputProc(pEvent, device, count)
  1024. .fi
  1025. This is the "input proc" for the device, a DIX procedure.
  1026. DIX will fill in this procedure pointer to one of its own routines by 
  1027. the time ProcessInputEvents() is called the first time.
  1028. Call this input proc routine as many times as needed to
  1029. deliver as many events as should be delivered.
  1030. DIX will buffer them up and send them out as needed.  Count is set
  1031. to the number of event records which make up one atomic device event and
  1032. is always 1 for the core devices (see the X Input Extension for descriptions
  1033. of devices which may use count > 1).
  1034.  
  1035. For example, your ProcessInputEvents() routine might check the mouse and the
  1036. keyboard.
  1037. If the keyboard had several keystrokes queued up, it could just call
  1038. the keyboard's processInputProc as many times as needed to flush its internal queue.
  1039.  
  1040. event is an xEvent struct you pass to the input proc.
  1041. When the input proc returns, it is finished with the event rec, and you can fill
  1042. in new values and call the input proc again with it.
  1043.  
  1044. device is a DevicePtr.
  1045.  
  1046. You should deliver the events in the same order that they were generated.
  1047.  
  1048. For keyboard and pointing devices the xEvent variant should be keyButtonPointer.
  1049. Fill in the following fields in the xEvent record:
  1050. .nf
  1051.  
  1052.     type        is one of the following: KeyPress, KeyRelease, ButtonPress, 
  1053.                     ButtonRelease, or MotionNotify
  1054.     detail        for KeyPress or KeyRelease fields, this should be the 
  1055.                     key number (not the ASCII code); otherwise unused
  1056.     time        is the time that the event happened (32-bits, in milliseconds, arbitrary origin)
  1057.     rootX        is the x coordinate of cursor
  1058.     rootY        is the y coordinate of cursor
  1059.  
  1060. .fi
  1061. The rest of the fields are filled in by DIX.
  1062. .LP
  1063. The time stamp is maintained by your code in the DDX layer, and it is your responsibility to 
  1064. stamp all events correctly.
  1065. .LP
  1066. The x and y coordinates of the pointing device and the time must be filled in for all event types
  1067. including keyboard events.
  1068. .LP
  1069. The pointing device must report all button press and release events.
  1070. In addition, it should report a MotionNotify event every time it gets called 
  1071. if the pointing device has moved since the last notify.
  1072. Intermediate pointing device moves are stored in a special GetMotionEvents buffer,
  1073. because most client programs are not interested in them.
  1074.  
  1075. There are quite a collection of sample implementations of this routine,
  1076. one for each supported device.
  1077.  
  1078. .NH 3
  1079. Telling DIX When Input is Pending
  1080. .XS
  1081. Telling DIX When Input is Pending
  1082. .XE
  1083. .LP
  1084. In the server's dispatch loop, DIX checks to see
  1085. if there is any device input pending whenever WaitForSomething() returns.  
  1086. If the check says that input is pending, DIX calls the
  1087. DDX routine ProcessInputEvents().
  1088. .LP
  1089. This check for pending input must be very quick; a procedure call
  1090. is too slow.
  1091. The code that does the check is a hardwired IF 
  1092. statement in DIX code that simply compares the values
  1093. pointed to by two pointers.
  1094. If the values are different, then it assumes that input is pending and
  1095. ProcessInputEvents() is called by DIX.
  1096. .LP
  1097. You must pass pointers to DIX to tell it what values to compare.
  1098. The following procedure
  1099. is used to set these pointers:
  1100. .nf
  1101.  
  1102.     void SetInputCheck(p1, p2)
  1103.         long *p1, *p2;
  1104. .fi
  1105. .LP
  1106. You should call it sometime during initialization to indicate to DIX the
  1107. correct locations to check.
  1108. You should 
  1109. pay special attention to the size of what they actually point to, 
  1110. because the locations are assumed to be longs.
  1111.  
  1112. These two pointers are initialized by DIX
  1113. to point to arbitrary values that
  1114. are different.
  1115. In other words, if you forget to call this routine during initialization,
  1116. the worst thing that will happen is that
  1117. ProcessInputEvents will be called when 
  1118. there are no events to process.
  1119.  
  1120. p1 and p2 might
  1121. point at the head and tail of some shared
  1122. memory queue. 
  1123. Another use would be to have one point at a constant 0, with the
  1124. other pointing at some mask containing 1s
  1125. for each input device that has
  1126. something pending.
  1127.  
  1128. The DDX layer of the sample server calls SetInputCheck()
  1129. once when the
  1130. server's private internal queue is initialized.
  1131. It passes pointers to the queue's head and tail.
  1132.  
  1133. .nf
  1134.     long TimeSinceLastInputEvent()
  1135. .fi
  1136. DDX must time stamp all hardware input
  1137. events.  But DIX sometimes needs to know the
  1138. time and the OS layer needs to know the time since the last hardware
  1139. input event in
  1140. order for the screen saver to work.   TimeSinceLastEvent() returns
  1141. the this time in milliseconds.
  1142.  
  1143. .NH 3
  1144. Controlling Input Devices
  1145. .XS
  1146. Controlling Input Devices
  1147. .XE
  1148. .LP
  1149. You must write four routines to do various device-specific 
  1150. things with the keyboard and pointing device.
  1151. They can have any name you wish because 
  1152. you pass the procedure pointers to DIX routines.
  1153.  
  1154. .nf
  1155.  
  1156.     int pInternalDevice->GetMotionEvents(buff, start, stop)
  1157.         xTimecoord *buff;
  1158.         CARD32 start, stop;
  1159. .fi
  1160. You write this DDX routine to fill in buff with all the motion events that
  1161. have times (32-bit count of
  1162. milliseconds) between time start and time stop.
  1163. It should return the number of motion events returned.
  1164. If there is no motion events support, this routine should do nothing and return zero.
  1165. The maximum size is set in InitPointerDeviceStruct(), below.
  1166.  
  1167. When the user drags the pointing device,
  1168. the cursor position theoretically sweeps through an infinite
  1169. number of points.
  1170. Normally, a client that is concerned with points other than the starting and ending points
  1171. will receive a pointer-move event only as often as the 
  1172. server generates them. (Move events
  1173. do not queue up; each new one replaces the last in the queue.)
  1174. A server, if desired, can implement a scheme to save these intermediate events
  1175. in a motion buffer.
  1176. A client application, like a paint program, may then request that 
  1177. these events be delivered to it through this routine.
  1178. .nf
  1179.  
  1180.     void pInternalDevice->Bell(loud, pDevice)
  1181.         int loud;
  1182.         DevicePtr pDevice;
  1183. .fi
  1184. You need to write this routine to ring the bell on the keyboard. 
  1185. loud is a number from 0 to 100, with 100 being the loudest.
  1186. .nf
  1187.  
  1188.     void pInternalDevice->ControlProc(device, ctrl)
  1189.         DevicePtr device;
  1190.         SomethingCtrl *ctrl;
  1191.  
  1192. .fi
  1193. .LP
  1194. You write two versions of this procedure, one for the keyboard and one for the pointing device.
  1195. DIX calls it to inform DDX when a client has requested changes in the current
  1196. settings for the particular device.
  1197. For a keyboard, this might be the repeat threshold and rate.
  1198. For a pointing device, this might be a scaling factor (coarse or fine) for position reporting.
  1199. See input.h for the ctrl structures.
  1200.  
  1201. .NH 3
  1202. Input Initialization
  1203. .XS
  1204. Input Initialization
  1205. .XE
  1206. .LP
  1207. Input initialization is a bit complicated.
  1208. It all starts with InitInput(), a routine that you write to call 
  1209. AddInputDevice() twice
  1210. (once for pointing device and once for keyboard.)
  1211. You also want to call RegisterKeyboardDevice() and RegisterPointerDevice()
  1212. on them.
  1213.  
  1214. When you Add the devices, a routine you supply for each device
  1215. gets called to initialize them.
  1216. Your individual initialize routines must call InitKeyboardDeviceStruct()
  1217. or InitPointerDeviceStruct(), depending upon which it is.
  1218. In other words, you indicate twice that the keyboard is the keyboard and
  1219. the pointer is the pointer.
  1220. .nf
  1221.  
  1222.     void InitInput(argc, argv)
  1223.         int argc;
  1224.         char **argv;
  1225. .fi
  1226. .LP
  1227. InitInput is a DDX routine you must write to initialize the 
  1228. input subsystem in DDX.
  1229. It must call AddInputDevice() for each device that might generate events.
  1230. In addition, you must register the main keyboard and pointing devices by
  1231. calling RegisterPointerDevice() and RegisterKeyboardDevice().
  1232. .nf
  1233.  
  1234.     DevicePtr AddInputDevice(deviceProc, autoStart)
  1235.         DeviceProc deviceProc;
  1236.         Bool autoStart;
  1237. .fi
  1238. .LP
  1239. AddInputDevice is a DIX routine you call to create a device object.
  1240. deviceProc is a DDX routine that is called by DIX to do various operations.
  1241. AutoStart should be TRUE for devices that need to be turned on at
  1242. initialization time with a special call, as opposed to waiting for some 
  1243. client application to
  1244. turn them on.
  1245. This routine returns NULL if sufficient memory cannot be allocated to
  1246. install the device.
  1247.  
  1248. Note also that except for the main keyboard and pointing device, 
  1249. an extension is needed to provide for a client interface to a device.
  1250. .nf
  1251.  
  1252.     void RegisterPointerDevice(device)
  1253.         DevicePtr device;
  1254. .fi
  1255. .LP
  1256. RegisterPointerDevice is a DIX routine that your DDX code calls that
  1257. makes that device the main pointing device.  
  1258. This routine is called once upon initialization and cannot be called again.
  1259. .nf
  1260.  
  1261.     void RegisterKeyboardDevice(device)
  1262.         DevicePtr device;
  1263. .fi
  1264. .LP
  1265. RegisterKeyboardDevice makes the given device the main keyboard.
  1266. This routine is called once upon initialization and cannot be called again.
  1267.  
  1268. The following DIX
  1269. procedures return the specified DevicePtr. They may or may not be useful
  1270. to DDX implementors.
  1271. .nf
  1272.  
  1273.     DevicePtr LookupKeyboardDevice()
  1274. .fi
  1275. .LP
  1276. LookupKeyboardDevice returns pointer for current main keyboard device.
  1277. .nf
  1278.  
  1279.     DevicePtr LookupPointerDevice()
  1280. .fi
  1281. .LP
  1282. LookupPointerDevice returns pointer for current main pointing device.
  1283.  
  1284. .LP
  1285. A DeviceProc (the kind passed to AddInputDevice()) in the following form:
  1286. .nf
  1287.  
  1288.     Bool pInternalDevice->DeviceProc(device, action);
  1289.         DevicePtr device;
  1290.         int action;
  1291. .fi
  1292. .LP
  1293. You must write a DeviceProc for each device.
  1294. device points to the device record.
  1295. action tells what action to take;
  1296. it will be one of  these defined constants  (defined in input.h):
  1297. .IP \(bu 5
  1298. DEVICE_INIT -
  1299. At DEVICE_INIT time, the device should initialize itself by calling
  1300. InitPointerDeviceStruct(), InitKeyboardDeviceStruct(), or a similar 
  1301. routine (see below)
  1302. and "opening" the device if necessary.
  1303. If you return a non-zero (i.e., != Success) value from the DEVICE_INIT
  1304. call, that device will be considered unavailable. If either the main keyboard
  1305. or main pointing device cannot be initialized, the DIX code will refuse 
  1306. to continue booting up.
  1307. .IP \(bu 5
  1308. DEVICE_ON - If the DeviceProc is called with DEVICE_ON, then it is 
  1309. allowed to start
  1310. putting events into the client stream by calling through the ProcessInputProc
  1311. in the device.
  1312. .IP \(bu 5
  1313. DEVICE_OFF - If the DeviceProc is called with DEVICE_OFF, no further 
  1314. events from that
  1315. device should be given to the DIX layer.
  1316. The device will appear to be dead to the user.
  1317. .IP \(bu 5
  1318. DEVICE_CLOSE - At DEVICE_CLOSE (terminate or reset) time, the device should
  1319. be totally closed down.
  1320. .nf
  1321.  
  1322.     void InitPointerDeviceStruct(device, map, mapLength,
  1323.             GetMotionEvents, ControlProc, numMotionEvents)
  1324.         DevicePtr device;
  1325.         BYTE *map;
  1326.         int mapLength;
  1327.         void (*ControlProc)();
  1328.         int (*GetMotionEvents)();
  1329.         int numMotionEvents;
  1330. .fi
  1331. InitPointerDeviceStruct is a DIX routine you call at DEVICE_INIT time to declare
  1332. some operating routines and data structures for a pointing device.
  1333. map and mapLength are as described in the X Window 
  1334. System protocol specification.
  1335. ControlProc and GetMotionEvents are DDX routines, see above.
  1336.  
  1337. numMotionEvents is for the motion-buffer-size for the GetMotionEvents
  1338. request.
  1339. A typical length for a motion buffer would be 100 events.
  1340. A server that does not implement this capability should set 
  1341. numMotionEvents to zero.
  1342. .nf
  1343.  
  1344.     void InitKeyboardDeviceStruct(device, pKeySyms, pModifiers, Bell, ControlProc)
  1345.         DevicePtr device;
  1346.         KeySymsPtr pKeySyms;
  1347.         CARD8 *pModifiers;   
  1348.         void (*Bell)();
  1349.         void (*ControlProc)();
  1350.  
  1351. .fi
  1352. You call this DIX routine when a keyboard device is initialized and 
  1353. its device procedure is called with
  1354. DEVICE_INIT.
  1355. The formats of the keysyms and modifier maps are defined in 
  1356. server/include/input.h. 
  1357. They describe the layout of keys on the keyboards, and the glyphs 
  1358. associated with them.  ( See the next section for information on
  1359. setting up the modifier map and the keysym map.)
  1360. ControlProc and Bell are DDX routines, see above.
  1361.  
  1362. .NH 3
  1363. Keyboard Mapping and Keycodes
  1364. .XS
  1365. Keyboard Mapping and Keycodes
  1366. .XE
  1367. .LP
  1368. When you send a keyboard event, you send a report that a given key has either
  1369. been pressed or has been released.
  1370. There must be a keycode for each key that identifies the key;
  1371. the keycode-to-key mapping can be any mapping you desire, because you
  1372. specify the mapping in a table you set up for DIX.  However, you are
  1373. restricted by the protocol specification to keycode values in the range
  1374. 8 to 255 inclusive.
  1375.  
  1376. The keycode mapping information that you set up consists of the following:
  1377. .IP \(bu 5
  1378. A minimum and maximum keycode number
  1379. .IP \(bu 5
  1380. An array of sets of glyphs for each key, that is of length 
  1381. maxkeycode - minkeycode + 1.  
  1382. Each element of this array is a list of codes for glyphs that are on that key.
  1383. There is no limit to the number of glyphs that can be on a key.
  1384. .LP
  1385. The sample server sets up the keycode and modifier maps in 
  1386. server/ddx/dec/lk201/lk201.c.  This is the map passed to the routine
  1387. InitKeyboardDeviceStruct().   Once the map is set up, DIX keeps and
  1388. maintains the client's changes to it.  See also server/ddx/dec/lk201/keynames.h
  1389. for the association between lk201 keys and the keysyms in X11/keysym.h.
  1390.  
  1391. The X protocol defines standard keycap glyph markings to indicate the 
  1392. symbol(s) printed on
  1393. each keycap. (See X11/keysym.h)
  1394.  
  1395. For instance, one of the Apple Macintosh keyboards has keys numbered from 0 to 58.
  1396. Key 0 has on it the glyph "A."  Key 1 has on it the glyph "S."
  1397. Key 41 has the glyphs ";" on the bottom and ":" on the top.
  1398. Key 48 is "Tab."
  1399. Key 49 is the space bar.
  1400. Key 56 is the shift keys (both keys return the same keycode).
  1401. An optional keypad generates codes 66 through 92, with some gaps in the middle.
  1402.  
  1403. Normally, the Macintosh system software translates these into ASCII for the 
  1404. application program.
  1405. An X server implementation would ignore the ASCII and just use the 
  1406. raw key codes.
  1407.  
  1408. Each glyph code is two bytes.
  1409. Given a space of 64K glyphs, the designers have used as much of this space 
  1410. as possible.
  1411. Whatever glyph is on your keyboard, there should be an appropriate glyph code
  1412. for it.
  1413. Fourteen glyph codes are for modifiers, including shift, control, Meta, Alt,
  1414. Super, and Hyper in both left and right flavors.
  1415. There are glyphs codes for the usual Return, Backspace, Rubout, Tab, etc.
  1416. There are codes for the 0 through 9 on the keypad as distinct from on the the 
  1417. regular keyboard,
  1418. besides the other glyphs commonly found on keypads.
  1419. There are cursor arrows and other control glyphs, such as Page Up, End, Home, 
  1420. Select, 
  1421. Undo, Help.
  1422. There are codes for PF1 through PF4.
  1423. They are distinct from F1 through F20.
  1424. There are, of course, the glyphs for the capital letters A through Z and all of the
  1425. punctuation marks that you have ever seen on any keyboard, 
  1426. including the division sign, cents sign, copyright, yen, and angle quotes.
  1427. In addition, glyph codes exist for all lowercase letters
  1428. and a huge
  1429. selection of letters with diacritical marks, ranging 
  1430. from a pretty typical 
  1431. uppercase N with a ~ 
  1432. over it to the lowercase d with a caron (upside-down circumflex).
  1433. There are diphthongs like ae and oe,
  1434. the German sharp S, and the Icelandic letter "eth," 
  1435. all in uppercase and lowercase.
  1436. These are all defined in X11/keysym.h.
  1437.  
  1438. Legal modifier keys must generate both up and down transitions.  When 
  1439. a client tries to change a modifier key (for instance, to make "A" the
  1440. "Control" key), DIX calls the following routine (in server/ddx/dec/lk201/lk201.c)
  1441. .nf
  1442.  
  1443.     Bool LegalModifier(key)
  1444.         BYTE key;
  1445. .fi
  1446.  
  1447.  
  1448. .NH 2
  1449. Screens
  1450. .XS
  1451. Screens
  1452. .XE
  1453. .LP
  1454. Different computer graphics
  1455. displays have different capabilities.  
  1456. Some are simple monochrome
  1457. frame buffers that are just lying
  1458. there in memory, waiting to be written into.
  1459. Others are color displays with many bits per pixel using some color lookup table.
  1460. Still others have high-speed graphic processors that prefer to do all of the work 
  1461. themselves,
  1462. including maintaining their own high-level, graphic data structures.
  1463.  
  1464. .NH 3
  1465. Screen Hardware Requirements
  1466. .XS
  1467. Screen Hardware Requirements
  1468. .XE
  1469. .LP
  1470. The only requirement on screens is that you be able to both read
  1471. and write locations in the frame buffer.
  1472. All screens must have a depth of 32 or less (unless you use
  1473. an X extension to allow a greater depth).
  1474. All screens must fit into one of the classes listed in the section 
  1475. in this document on Visuals and Depths.
  1476. .LP
  1477. X uses the pixel as its fundamental unit of distance on the screen.
  1478. Therefore, most programs will measure everything in pixels.  
  1479. .LP
  1480. The sample server assumes square pixels.  
  1481. Serious WYSIWYG (what you see is what you get) applications for
  1482. publishing and drawing programs will adjust for
  1483. different screen resolutions automatically.
  1484. Considerable work
  1485. is involved in compensating for non-square pixels (a bit in the DDX
  1486. code for the sample server but quite a bit in the client applications).
  1487.  
  1488. .NH 3
  1489. Data Structures
  1490. .XS
  1491. Data Structures
  1492. .XE
  1493. .LP
  1494. X supports multiple screens that are connected to the same
  1495. server.  Therefore, all the per-screen information is bundled into one data
  1496. structure of attributes and procedures, which is the ScreenRec (see 
  1497. server/include/scrnintstr.h).  
  1498. The procedure entry points in a ScreenRec operate on 
  1499. regions, colormaps, cursors, and fonts, because these resources
  1500. can differ in format from one screen to another.
  1501.  
  1502. "Windows" are rectangular graphic areas on the screen 
  1503. that can be drawn into by graphic routines.
  1504. "Pixmaps" are off-screen graphic areas that can be drawn into.
  1505. They are both considered drawables and are 
  1506. described in the section on Drawables.
  1507. All graphic operations work on drawables,
  1508. and operations are available to copy patches from
  1509. one drawable to another.
  1510.  
  1511. The pixel image data in all drawables is in a format that is private
  1512. to DDX.
  1513. In fact, each instance of a drawable is associated with a given screen.
  1514. Presumably, the pixel image data for
  1515. pixmaps is chosen to be conveniently understood by the
  1516. hardware.   All screens in a single server must be able to handle 
  1517. all pixmaps depths declared in the connection setup information.
  1518. .LP
  1519. Pixmap images are transferred to the server in one of two ways:
  1520. XYPixmap or ZPimap.
  1521. XYPixmaps are a series of bitmaps, one for each bit plane of the image,
  1522. using the bitmap padding rules from the connection setup.
  1523. ZPixmaps are a series of bits, nibbles, bytes or words, one for each pixel, 
  1524. using the format rules (padding and so on) for the appropriate depth.
  1525. .LP
  1526. All screens in a given server must agree on a set of
  1527. pixmap image formats (PixmapFormat) to support (depth, 
  1528. number of bits per pixel, etc.).
  1529. .LP
  1530. There is no color interpretation of bits in the pixmap.  Pixmaps 
  1531. do not contain pixel values.  The interpretation is made only when
  1532. the bits are transferred onto the screen.
  1533. .LP
  1534. The screenInfo structure (in scrnintstr.h) is a global data structure that
  1535. has a pointer to an array of ScreenRecs, one for each screen on the server.
  1536. (These constitute the one and only description of each screen in the server.)
  1537. Each screen has an identifying index (0, 1, 2, ...).
  1538. In addition, the screenInfo struct contains global server-wide
  1539. details, such as the bit- and byte-
  1540. order in all bit images, and the list of pixmap image formats that are supported.
  1541. Obviously, these must be the same for all screens on the server.
  1542.  
  1543. .NH 3
  1544. Output Initialization
  1545. .XS
  1546. Output Initialization
  1547. .XE
  1548. .LP
  1549. .nf
  1550.  
  1551.     InitOutput(pScreenInfo, argc, argv)
  1552.         ScreenInfo *pScreenInfo;
  1553.         int argc;
  1554.         char **argv;
  1555. .fi
  1556. Upon initialization, your DDX
  1557. routine InitOutput() is called by DIX.
  1558. It is passed a pointer to screenInfo to initialize.
  1559. It is also passed the argc and argv from main() for your server
  1560. for the command-line arguments.
  1561. These arguments may indicate what or how many screen device(s) to use
  1562. or in what way to use them.
  1563. For instance, your server command line may allow a "-D" flag 
  1564. followed by the name of the screen device to use.
  1565.  
  1566. Your InitOutput() routine should initialize each screen you wish to use
  1567. by calling AddScreen(), and then it should initialize the pixmap formats
  1568. that you support by storing values directly into the screenInfo data structure.
  1569. You should also set certain implementation-dependent numbers and 
  1570. procedures in your
  1571. screenInfo, which determines
  1572. the pixmap and scanline padding rules for all screens in the server.
  1573. .nf
  1574.  
  1575.     int AddScreen(scrInitProc, argc, argv)
  1576.         Bool (*scrInitProc)();
  1577.         int argc;
  1578.         char **argv;
  1579. .fi
  1580. You should call AddScreen(), a DIX procedure, in InitOutput()
  1581. once for each screen to add it to the 
  1582. screenInfo database.
  1583. The first argument is an initialization procedure for the screen that you supply.
  1584. The second and third are the argc and argv from main().
  1585. It returns the screen number of the screen installed,
  1586. or -1 if there is either insufficient memory to add the screen, or
  1587. (*scrInitProc) returned FALSE.
  1588.  
  1589. The scrInitProc should be of the following form:
  1590. .nf
  1591.  
  1592.     Bool scrInitProc(iScreen, pScreen, argc, argv)
  1593.         int iScreen;
  1594.         ScreenPtr pScreen;
  1595.         int argc;
  1596.         char **argv;
  1597. .fi
  1598. iScreen is the index for this screen; 0 for the first one initialized, 
  1599. 1 for the second, etc.
  1600. pScreen is the pointer to the screen's new ScreenRec.
  1601. argc and argv are as before.
  1602. Your screen initialize procedure should return TRUE upon success or
  1603. FALSE if the screen
  1604. cannot be initialized (for instance, if the screen hardware does not exist on
  1605. this machine).
  1606.  
  1607. This procedure must determine what actual device it is supposed to initialize.
  1608. If you have a different procedure for each screen, then it is no problem.
  1609. If you have the same procedure for multiple screens, it may have trouble
  1610. figuring out which screen to initialize each time around, especially if
  1611. InitOutput() does not initialize all of the screens.
  1612. It is probably easiest to have one procedure for each screen.
  1613.  
  1614. The initialization procedure should fill in all the screen procedures
  1615. for that screen (windowing functions, region functions, etc.) and certain
  1616. screen attributes for that screen.
  1617.  
  1618. .NH 3
  1619. Region Routines in the ScreenRec
  1620. .XS
  1621. Region Routines in the ScreenRec
  1622. .XE
  1623. .LP
  1624. A region is a dynamically allocated data structure that describes
  1625. an irregularly shaped piece of real estate in XY pixel space.
  1626. You can think of it as a set of pixels on the screen to be operated upon with
  1627. set operations such as AND and OR.
  1628. .LP
  1629. A region is frequently implemented as a list of rectangles or bitmaps that
  1630. enclose the
  1631. selected pixels.
  1632. Region operators control the "clipping policy," or the operations that 
  1633. work on regions.
  1634. (The sample server
  1635. uses YX-banded rectangles.
  1636. Unless you have something already implemented for your
  1637. graphics system, you should keep that implementation.)
  1638. The procedure pointers to the region operators are located in the
  1639. ScreenRec data structure.
  1640. The definition of a region can be found in the file 
  1641. server/include/regionstr.h.
  1642. The region code is found in server/ddx/mi/miregion.c.
  1643. DDX implementations using other region formats will
  1644. need to supply different versions of the region operators.
  1645.  
  1646. Since the list of rectangles is unbounded in size, part of the region data
  1647. structure is usually a large, dynamically allocated chunk of memory.
  1648. As your region operators calculate logical combinations of 
  1649. regions, these blocks may need to be reallocated by your region 
  1650. software.
  1651. For instance, in the sample server, a RegionRec has some header information
  1652. and a pointer to a dynamically allocated rectangle list.
  1653. Periodically, the rectangle list needs to be expanded with Xrealloc(),
  1654. whereupon the new pointer is remembered in the RegionRec.
  1655. .nf
  1656.  
  1657.     RegionPtr pScreen->RegionCreate( rect, size)
  1658.         BoxPtr rect;
  1659.         int size;
  1660. .fi
  1661. RegionCreate creates a region that describes ONE rectangle.
  1662. The caller can avoid unnecessary reallocation and copying by declaring
  1663. the probable maximum number of rectangles that this region will need to 
  1664. describe itself.
  1665. Your region routines, though, cannot fail just because the region grows 
  1666. beyond this size.
  1667. The caller of this routine can pass almost anything as the size;
  1668. the value is merely a good guess as to the maximum size until it is proven
  1669. wrong by subsequent use.
  1670. Your region procedures are then on their own in
  1671. estimating how big the region will get.
  1672. Your implementation might ignore size, if applicable.
  1673. .nf
  1674.     void pScreen->RegionInit (pRegion, rect, size)
  1675.         RegionPtr    pRegion;
  1676.         BoxPtr        rect;
  1677.         int        size;
  1678. .fi
  1679. Given an existing raw region structure (such as an local variable), this
  1680. routine fills in the appropriate fields to make this region as usable as
  1681. one returned from RegionCreate.  This avoids the additional dynamic memory
  1682. allocation overhead for the region structure itself.
  1683. .nf
  1684.  
  1685.     Bool pScreen->RegionCopy(dstrgn, srcrgn)
  1686.         RegionPtr dstrgn, srcrgn;
  1687. .fi
  1688. RegionCopy copies the description of one region, srcrgn, to another 
  1689. already-created region,
  1690. dstrgn; returning TRUE if the copy succeeded, and FALSE otherwise.
  1691. .nf
  1692.  
  1693.     void pScreen->RegionDestroy( pRegion)
  1694.         RegionPtr pRegion;
  1695. .fi
  1696. RegionDestroy destroys a region and frees all allocated memory.
  1697. .nf
  1698.     void pScreen->RegionUninit (pRegion)
  1699.         RegionPtr pRegion;
  1700. .fi
  1701. Frees everything except the region structure itself, useful when the
  1702. region was originally passed to RegionInit instead of received from
  1703. RegionCreate.  When this call returns, pRegion must not be reused until
  1704. it has been RegionInit'ed again.
  1705. .nf
  1706.  
  1707.     Bool pScreen->Intersect(newReg, reg1, reg2)
  1708.         RegionPtr newReg, reg1, reg2;
  1709.  
  1710.     Bool  pScreen->Union(newReg, reg1, reg2)
  1711.         RegionPtr newReg, reg1, reg2;
  1712.  
  1713.     Bool  pScreen->Subtract(newReg, regMinuend, regSubtrahend)
  1714.         RegionPtr newReg, regMinuend, regSubtrahend;
  1715.  
  1716.     Bool pScreen->Inverse(newReg, pReg,  pBox)
  1717.         RegionPtr newReg, pReg;
  1718.         BoxPtr pBox;
  1719. .fi
  1720. The above four calls all do basic logical operations on regions.
  1721. They set the new region (which already exists)
  1722. to describe the logical intersection, union, set difference,
  1723. or inverse of the region(s) that were passed in.
  1724. Your routines must be able to handle a situation where the newReg is 
  1725. the same region as one of the other region arguments.
  1726.  
  1727. The subtract function removes the Subtrahend from the Minuend and
  1728. puts the result in newReg.
  1729.  
  1730. The inverse function returns a region that is the pBox minus the region passed in.
  1731. (A true "inverse" would make a region that extends to infinity in all directions
  1732. but has holes in the middle.)
  1733. It is undefined for situations where the region extends beyond the box.
  1734.  
  1735. Each routine must return the value TRUE for success.
  1736. .nf
  1737.  
  1738.     void pScreen->RegionReset(pRegion, pBox)
  1739.         RegionPtr pRegion;
  1740.         BoxPtr pBox;
  1741. .fi
  1742. RegionReset sets the region to describe
  1743. one rectangle and reallocates it to a size of one rectangle, if applicable.
  1744. .nf
  1745.  
  1746.     void  pScreen->TranslateRegion(pRegion, x, y)
  1747.         RegionPtr pRegion;
  1748.         int x, y;
  1749. .fi
  1750. TranslateRegion simply moves a region +x in the x direction and +y in the y 
  1751. direction.
  1752. .nf
  1753.  
  1754.     int  pScreen->RectIn(pRegion, pBox)
  1755.         RegionPtr pRegion;
  1756.         BoxPtr pBox;
  1757. .fi
  1758. RectIn returns one of the defined constants
  1759. rgnIN, rgnOUT, or rgnPART, depending upon whether the box is entirely
  1760. inside the region, entirely outside of the region, or partly in and partly out of 
  1761. the region.
  1762. These constants are defined in server/include/region.h.
  1763. .nf
  1764.  
  1765.     Bool pScreen->PointInRegion(pRegion, x, y, pBox)
  1766.         RegionPtr pRegion;
  1767.         int x, y;
  1768.         BoxPtr pBox;
  1769. .fi
  1770. PointInRegion returns true if the point x, y is in the region.
  1771. In addition, it fills the rectangle pBox with coordinates of a rectangle
  1772. that is entirely inside of pRegion and encloses the point.
  1773. In the mi implementation, it is the largest such rectangle.
  1774. (Due to the sample server implementation,
  1775. this comes cheaply.)
  1776.  
  1777. This routine used by DIX when tracking the pointing device and deciding whether
  1778. to report mouse events or change the cursor.
  1779. For instance, DIX needs to change the cursor when it moves from one window to
  1780. another.  Due to overlapping windows, the shape to check may be irregular.
  1781. A PointInRegion() call for every pointing device movement may be too expensive.
  1782. The pBox is a kind of wake-up box;
  1783. DIX need not call PointInRegion() again until the cursor wanders outside of 
  1784. the returned box.
  1785. .nf
  1786.  
  1787.     Bool pScreen->RegionNotEmpty(pRegion)
  1788.         RegionPtr pRegion;
  1789. .fi
  1790. RegionNotEmpty is a boolean function that returns
  1791. true or false depending upon whether the region encloses any pixels.
  1792. .nf
  1793.  
  1794.     void pScreen->RegionEmpty(pRegion)
  1795.         RegionPtr pRegion;
  1796. .fi
  1797. RegionEmpty sets the region to be empty.
  1798. .nf
  1799.  
  1800.     BoxPtr pScreen->RegionExtents(pRegion)
  1801.         RegionPtr pRegion;
  1802. .fi
  1803. RegionExtents returns a rectangle that is the smallest
  1804. possible superset of the entire region.
  1805. The caller will not modify this rectangle, so it can be the one
  1806. in your region struct.
  1807. .nf
  1808.     Bool pScreen->RegionAppend (pDstRgn, pRegion)
  1809.         RegionPtr pDstRgn;
  1810.         RegionPtr pRegion;
  1811.  
  1812.     Bool pScreen->RegionValidate (pRegion, pOverlap)
  1813.         RegionPtr pRegion;
  1814.         Bool *pOverlap;
  1815. .fi
  1816. These functions provide an optimization for clip list generation and
  1817. must be used in conjunction.  The combined effect is to produce the
  1818. union of a collection of regions, by using RegionAppend several times,
  1819. and finally calling RegionValidate which takes the intermediate
  1820. representation (which needn't be a valid region) and produces the
  1821. desired union.  pOverlap is set to TRUE if any of the original
  1822. regions overlap; FALSE otherwise.
  1823. .nf
  1824.     RegionPtr pScreen->BitmapToRegion (pPixmap)
  1825.         PixmapPtr pPixmap;
  1826. .fi
  1827. Given a depth-1 pixmap, this routine must create a valid region which
  1828. includes all the areas of the pixmap filled with 1's and excludes the
  1829. areas filled with 0's.  This
  1830. routine returns NULL if out of memory.
  1831. .nf
  1832.     RegionPtr pScreen->RectsToRegion (nrects, pRects, ordering)
  1833.         int nrects;
  1834.         xRectangle *pRects;
  1835.         int ordering;
  1836. .fi
  1837. Given a client-supplied list of rectangles, produces a region which includes
  1838. the union of all the rectangles.  Ordering may be used as a hint which
  1839. describes how the rectangles are sorted.  As the hint is provided by a
  1840. client, it must not be required to be correct, but the results when it is
  1841. not correct are not defined (core dump is not an option here).
  1842. .nf
  1843.     void pScreen->SendGraphicsExpose(client,pRegion,drawable,major,minor)
  1844.         ClientPtr client;
  1845.         RegionPtr pRegion;
  1846.         XID drawable;
  1847.         unsigned char major;
  1848.         unsigned short minor;
  1849. .fi
  1850. SendGraphicsExpose dispatches a list of GraphicsExposure events which
  1851. span the region to the specified client.  If the region is empty, or
  1852. a NULL pointer, a NoExpose event is sent instead.
  1853. .NH 3
  1854. Cursor Routines for a Screen
  1855. .XS
  1856. Cursor Routines for a Screen
  1857. .XE
  1858. .LP
  1859. A cursor is the visual form tied to the pointing device.
  1860. The default cursor is an "X" shape, but the cursor can have any shape.
  1861. When a client creates a window, it declares what shape the cursor will be when it
  1862. strays into that window on the screen.
  1863.  
  1864. For each possible shape the cursor assumes, there is a CursorRec data
  1865. structure.  This data structure contains a pointer to a CursorBits data
  1866. structure which contains a bitmap for the image of the cursor and a bitmap
  1867. for a mask behind the cursor, in addition, the CursorRec data structure
  1868. contains foreground and background colors for the cursor.  The CursorBits
  1869. data structure is shared among multiple CursorRec structures which use the
  1870. same font and glyph to describe both source and mask.  The cursor image
  1871. is applied to the screen by applying the mask first, clearing 1 bits in its
  1872. form to the background color, and then overwriting on the source image, in
  1873. the foreground color.  (One bits of the source image that fall on top of
  1874. zero bits of the mask image are undefined.)  This way, a cursor can have
  1875. transparent parts, and opaque parts in two colors.  X allows any cursor
  1876. size, but some hardware cursor schemes allow a maximum of N pixels by M
  1877. pixels.  Therefore, you are allowed to transform the cursor to a smaller
  1878. size, but be sure to include the hot-spot.
  1879.  
  1880. CursorBits in server/include/cursorstr.h
  1881. is a device-independent structure containing a device-independent
  1882. representation of the bits for the source and mask.  
  1883. (This is possible because the bitmap representation is the same
  1884. for all screens.)
  1885.  
  1886. When a cursor is created, it is "realized" for each screen.  At realization
  1887. time, each screen has the chance to convert the bits into some other
  1888. representation that may be more convenient (for instance, putting the cursor
  1889. into off-screen memory) and set up its device-private area in either the
  1890. CursorRec data structure or CursorBits data structure as appropriate to
  1891. possibly point to whatever data structures are needed.  It is more
  1892. memory-conservative to share realizations by using the CursorBits private
  1893. field, but this makes the assumption that the realization is independent of
  1894. the colors used (which is typically true).  For instance, the
  1895. following are the device private entries for a particular screen and cursor:
  1896. .nf
  1897.  
  1898.     pCursor->devPriv[pScreen->myNum]
  1899.     pCursor->bits->devPriv[pScreen->myNum]
  1900.  
  1901. .fi
  1902. This is done because the change from one cursor shape to another must
  1903. be fast and responsive;
  1904. the cursor image should be able to flutter as fast as the user moves it 
  1905. across the screen.
  1906.  
  1907. You must implement the following routines for your hardware:
  1908. .nf
  1909.  
  1910.     Bool pScreen->RealizeCursor( pScr, pCurs)
  1911.         ScreenPtr pScr;
  1912.         CursorPtr pCurs;
  1913.  
  1914.     Bool pScreen->UnrealizeCursor( pScr, pCurs)
  1915.         ScreenPtr pScr;
  1916.         CursorPtr pCurs;
  1917. .fi
  1918. RealizeCursor and UnrealizeCursor
  1919. should realize (allocate and calculate all data needed) 
  1920. and unrealize (free the dynamically allocated data)
  1921. a given cursor when DIX needs them.
  1922. They are called whenever a device-independent
  1923. cursor is created or destroyed.
  1924. The source and mask bits pointed to by fields in pCurs are
  1925. undefined for bits beyond the right edge
  1926. of the cursor.  This is so because the bits are in Bitmap format, 
  1927. which may have pad bits on the right edge.
  1928. You should inhibit UnrealizeCursor() if the cursor is currently in use;
  1929. this happens when the system is reset.
  1930. .nf
  1931.  
  1932.     Bool pScreen->DisplayCursor( pScr, pCurs)
  1933.         ScreenPtr pScr;
  1934.         CursorPtr pCurs;
  1935. .fi
  1936. DisplayCursor should change the cursor on the given screen to the one passed in.
  1937. It is called by DIX when the user moves the pointing device into a 
  1938. different window with
  1939. a different cursor.  The hotspot in the cursor should be aligned
  1940. with the current cursor position.
  1941. .nf
  1942.  
  1943.     void pScreen->RecolorCursor( pScr, pCurs, displayed)
  1944.         ScreenPtr pScr;
  1945.         CursorPtr pCurs;
  1946.         int displayed;
  1947. .fi
  1948. .LP
  1949. RecolorCursor notifies DDX that the colors in pCurs have changed and
  1950. indicates whether this is the cursor currently being displayed.  If it
  1951. is, the cursor hardware state may have to be updated.  Whether
  1952. displayed or not, state created at RealizeCursor time may have to be
  1953. updated.  A generic version, miRecolorCursor, may be used that 
  1954. does an unrealize, a realize, and possibly a display (in micursor.c);
  1955. however this constrains UnrealizeCursor and RealizeCursor to always return
  1956. TRUE as no error indication is returned here.
  1957. .nf
  1958.  
  1959.     void pScreen->ConstrainCursor( pScr, pBox)
  1960.         ScreenPtr pScr;
  1961.         BoxPtr pBox;
  1962. .fi
  1963. ConstrainCursor should cause the cursor to restrict its motion to the 
  1964. rectangle pBox.
  1965. DIX code is capable of enforcing
  1966. this constraint by forcefully moving the cursor if it strays out of the rectangle,
  1967. but ConstrainCursor offers a way to send a
  1968. hint to the driver or hardware if such support is available.  This can prevent the
  1969. cursor from wandering out of the box, then jumping back, as DIX forces it back.
  1970. .nf
  1971.  
  1972.     void pScreen->PointerNonInterestBox( pScr, pBox)
  1973.         ScreenPtr pScr;
  1974.         BoxPtr pBox;
  1975. .fi
  1976. PointerNonInterestBox is DIX's way of telling the pointing device code
  1977. not to report motion events while the cursor is inside a 
  1978. given rectangle on the given screen.
  1979. It is optional and, if not implemented, it should do nothing.
  1980. This routine is called only when the client has declared that it is 
  1981. not interested in motion events
  1982. in a given window.
  1983. The rectangle you get may be a subset of that window.
  1984. It saves DIX code the time required to discard uninteresting
  1985. mouse motion events.  This is only a hint, which may speed
  1986. performance.
  1987. .nf
  1988.  
  1989.     void pScreen->CursorLimits( pScr, pCurs, pHotBox, pTopLeftBox)
  1990.         ScreenPtr pScr;
  1991.         CursorPtr pCurs;
  1992.         BoxPtr pHotBox;
  1993.         BoxPtr pTopLeftBox;    /* return value */
  1994. .fi
  1995. .LP
  1996. CursorLimits should calculate the box that the cursor 
  1997. hot spot is
  1998. physically capable of moving within, as a function of the screen pScr,
  1999. the device-independent cursor pCurs, and a box that 
  2000. DIX hypothetically would want 
  2001. the hot spot
  2002. confined within, pHotBox.  
  2003. This routine is for informing DIX only; it alters no state within
  2004. DDX.
  2005. .nf
  2006.  
  2007.     Bool pScreen->SetCursorPosition( pScr, newx, newy, generateEvent)
  2008.         ScreenPtr pScr;
  2009.         unsigned int newx;
  2010.         unsigned int newy;
  2011.         Bool generateEvent;
  2012. .fi
  2013. .LP
  2014. SetCursorPosition should artificially move the cursor as though the user
  2015. had jerked the pointing device very quickly.
  2016. This is called in response to the WarpPointer request from the client,
  2017. and at other times.
  2018. If generateEvent is True, the device should decide whether or
  2019. not to call ProcessInputEvents() nd then it must call
  2020. DevicePtr->processInputProc.
  2021. Its effects are, of course, limited in value for absolute pointing devices
  2022. such as a tablet.
  2023. .nf
  2024.  
  2025.     void NewCurrentScreen(newScreen, x, y)
  2026.         ScreenPtr newScreen;
  2027.         int x,y;
  2028. .fi
  2029. .LP
  2030. If your ddx provides some mechanism for the user to magically move the
  2031. pointer between multiple screens, you need to inform DIX when this
  2032. occurs.  You should call NewCurrentScreen to accomplish this, specifying
  2033. the new screen and the new x and y coordinates of the pointer on that screen.
  2034.  
  2035. .NH 3
  2036. Visuals, Depths and Pixmap Formats for Screens
  2037. .XS
  2038. Visuals, Depths and Pixmap Formats for Screens
  2039. .XE
  2040. .LP
  2041. The "depth" of a image is the number of bits that are used per pixel to display it.
  2042.  
  2043. The "bits per pixel" of a pixmap image that is sent over the client byte stream
  2044. is a number that is either 4, 8, 16, 24 or 32.
  2045. It is the number of bits used per pixel in Z format.
  2046. For instance, a pixmap image that has a depth of six is best sent
  2047. in Z format as 8 bits per pixel.
  2048.  
  2049. A "pixmap image format" or a "pixmap format"
  2050. is a description of the format of a pixmap image as it 
  2051. is sent over
  2052. the byte stream.
  2053. For each depth available on a server, there is one and only one 
  2054. pixmap format.
  2055. This pixmap image format gives the bits per pixel and the scanline padding
  2056. unit. (For instance, are pixel rows padded to 
  2057. bytes, 16-bit words, or 32-bit words?)
  2058.  
  2059. For each screen, you must decide upon what depth(s) it supports.
  2060. You should only count the number of bits used for the actual image.
  2061. Some displays store additional bits to indicate what window
  2062. this pixel is in, how close this object is to a viewer, transparency, 
  2063. and other data; do not count these bits.
  2064.  
  2065. A "display class" tells whether
  2066. the display is monochrome or color, whether 
  2067. there is a lookup table, and how the lookup table
  2068. works.
  2069.  
  2070. A "visual" is a combination of depth, display class,
  2071. and a description of how the pixel values result in a color on the screen.
  2072. Each visual has a set of masks and offsets that are used to separate a 
  2073. pixel value into its
  2074. red, green, and blue components and a count of the number of colormap entries.
  2075. Some of these fields are only meaningful when the class dictates so.
  2076. Each visual also has a screen ID telling which screen it is usable on.
  2077. Note that the depth does not imply the number of map_entries;
  2078. for instance, a display can have 8 bits per pixel but only 254 colormap entries
  2079. for use by applications (the other two being reserved by hardware for the cursor).
  2080.  
  2081. Each visual is identified by a 32-bit visual ID which the client uses to
  2082. choose what visual is desired on a given window.
  2083. Clients can be using more than one visual on the same screen at the same time;
  2084. .LP
  2085. The class of a display describes how this translation takes place.
  2086. There are three ways to do the translation.
  2087. .IP \(bu 5
  2088. Pseudo - The pixel value, as a whole, is looked up 
  2089. in a table of length map_entries to
  2090. determine the color to display.
  2091. .IP \(bu 5
  2092. True - The 
  2093. pixel value is broken up into red, green, and blue fields, each of which 
  2094. are looked up in separate red, green, and blue lookup tables, 
  2095. each of length map_entries.
  2096. .IP \(bu 5
  2097. Gray - The pixel value is looked up in a table of length map_entries to 
  2098. determine a gray level to display.
  2099. .LP
  2100. In addition, the lookup table can be static (resulting colors are fixed for each 
  2101. pixel value)
  2102. or dynamic (lookup entries are under control of the client program).
  2103. This leads to a total of six classes:
  2104.  
  2105. .IP \(bu 5
  2106. Static Gray - The pixel value (of however many bits) determines directly the 
  2107. level of gray
  2108. that the pixel assumes.  
  2109. .IP \(bu 5
  2110. Gray Scale - The pixel value is fed through a lookup table to arrive at the level 
  2111. of gray to display
  2112. for the given pixel.  
  2113. .IP \(bu 5
  2114. Static Color - The pixel value is fed through a fixed lookup table that yields the 
  2115. color to display
  2116. for that pixel.
  2117. .IP \(bu 5
  2118. PseudoColor - The whole pixel value is fed through a programmable lookup 
  2119. table that has one
  2120. color (including red, green, and blue intensities) for each possible pixel value,
  2121. and that color is displayed.
  2122. .IP \(bu 5
  2123. True Color - Each pixel value consists of one or more bits
  2124. that directly determine each primary color intensity after being fed through 
  2125. a fixed table.
  2126. .IP \(bu 5
  2127. Direct Color - Each pixel value consists of one or more bits for each primary color.
  2128. Each primary color value is individually looked up in a table for that primary 
  2129. color, yielding
  2130. an intensity for that primary color.
  2131. For each pixel, the red value is looked up in the
  2132. red table, the green value in the green table, and
  2133. the blue value in the blue table.
  2134. .LP
  2135. Here are some examples:
  2136. .IP
  2137. A simple monochrome 1 bit per pixel display is Static Gray.
  2138.  
  2139. A display that has 2 bits per pixel for a choice
  2140. between the colors of black, white, green and violet is Static Color.
  2141.  
  2142. A display that has three bits per pixel, where 
  2143. each bit turns on or off one of the red, green or
  2144. blue guns, is in the True Color class.
  2145.  
  2146. If you take the last example and scramble the
  2147. correspondence between pixel values and colors
  2148. it becomes a Static Color display.
  2149.  
  2150. A display has 8 bits per pixel.  The 8 bits select one entry out of 256 entries
  2151. in a lookup table, each entry consisting of 24 bits (8bits each for red, green,
  2152. and blue).
  2153. The display can show any 256 of 16 million colors on the screen at once.
  2154. This is a pseudocolor display.
  2155. The client application gets to fill the lookup table in this class of display.
  2156.  
  2157. Imagine the same hardware from the last example.
  2158. Your server software allows the user, on the 
  2159. command line that starts up the server
  2160. program, 
  2161. to fill the lookup table to his liking once and for all.
  2162. From then on, the server software would not change the lookup table
  2163. until it exits.
  2164. For instance, the default might be a lookup table with a reasonable sample of 
  2165. colors from throughout the color space.
  2166. But the user could specify that the table be filled with 256 steps of gray scale
  2167. because he knew ahead of time he would be manipulating a lot of black-and-white 
  2168. scanned photographs
  2169. and not very many color things.
  2170. Clients would be presented with this unchangeable lookup table.
  2171. Although the hardware qualifies as a PseudoColor display,
  2172. the facade presented to the X client is that this is a Static Color display.
  2173.  
  2174. You have to decide what kind of display you have or want
  2175. to pretend you have.  
  2176. When you initialize the screen(s), this class value must be set in the
  2177. VisualRec data structure along with other display characteristics like the 
  2178. depth and other numbers.
  2179.  
  2180. The allowable DepthRec's and VisualRec's are pointed to by fields in the ScreenRec.
  2181. These are set up when InitOutput() is called; you should Xalloc() appropriate blocks
  2182. or use static variables initialized to the correct values.
  2183.  
  2184. .NH 3
  2185. Colormaps for Screens
  2186. .XS
  2187. Colormaps for Screens
  2188. .XE
  2189. .LP
  2190. A colormap is a device-independent
  2191. mapping between pixel values and colors displayed on the screen.
  2192.  
  2193. Different windows on the same screen can have different
  2194. colormaps at the same time.
  2195. At any given time, the most recently installed
  2196. colormap(s) will be in use in the server
  2197. so that its (their) windows' colors will be guaranteed to be correct.
  2198. Other windows may be off-color.
  2199. Although this may seem to be chaotic, in practice most clients 
  2200. use the default colormap for the screen.
  2201.  
  2202. The default colormap for a screen is initialized when the screen is initialized.
  2203. It always remains in existence and is not owned by any regular client.  It 
  2204. is owned by client 0 (the server itself).
  2205. Many clients will simply use this default colormap for their drawing.
  2206. Depending upon the class of the screen, the entries in this colormap may
  2207. be modifiable by client applications.
  2208.  
  2209. .NH 4
  2210. Colormap Routines
  2211. .XS
  2212. Colormap Routines
  2213. .XE
  2214. .LP
  2215. You need to implement the following routines to handle the device-dependent
  2216. aspects of color maps.  You will end up placing pointers to these procedures
  2217. in your ScreenRec data structure(s).  The sample server implementations of
  2218. many of these routines are in both cfbcmap.c and mfbcmap.c; since mfb does
  2219. not do very much with color, the cfb versions are typically more useful
  2220. prototypes.
  2221. .nf
  2222.  
  2223.     Bool pScreen->CreateColormap(pColormap)
  2224.         ColormapPtr pColormap;
  2225. .fi
  2226. .LP
  2227. This routine is called by the DIX CreateColormap routine after it has allocated
  2228. all the data for the new colormap and just before it returns to the dispatcher.
  2229. It is the DDX layer's chance to initialize the colormap, particularly if it is
  2230. a static map.  See the following
  2231. section for more details on initializing colormaps.
  2232. The routine returns FALSE if creation failed, such as due to memory
  2233. limitations.
  2234. Notice that the colormap has a devPriv field from which you can hang any
  2235. colormap specific storage you need.  Since each colormap might need special
  2236. information, we attached the field to the colormap and not the visual.
  2237. .nf
  2238.  
  2239.     pScreen->DestroyColormap(pColormap)
  2240.         ColormapPtr pColormap;
  2241. .fi
  2242. .LP
  2243. This routine is called by the DIX FreeColormap routine after it has uninstalled
  2244. the colormap and notified all interested parties, and before it has freed
  2245. any of the colormap storage.
  2246. It is the DDX layer's chance to free any data it added to the colormap.
  2247. .nf
  2248.  
  2249.     pScreen->InstallColormap(pColormap)
  2250.         ColormapPtr pColormap;
  2251. .fi
  2252. .LP
  2253. InstallColormap should 
  2254. fill a lookup table on the screen with which the colormap is associated with
  2255. the colors in pColormap.
  2256. If there is only one hardware lookup table for the screen, then all colors on
  2257. the screen may change simultaneously.
  2258.  
  2259. In the more general case of multiple hardware lookup tables,
  2260. this may cause some other colormap to be
  2261. uninstalled, meaning that windows that subscribed to the colormap
  2262. that was uninstalled may end up being off-color.
  2263. See the note, below, about uninstalling maps.
  2264. .nf
  2265.  
  2266.     pScreen->UninstallColormap(pColormap)
  2267.         ColormapPtr pColormap;
  2268. .fi
  2269. .LP
  2270. UninstallColormap should 
  2271. remove pColormap from screen pColormap->pScreen.  
  2272. Some other map, such as the default map if possible,
  2273. should be installed in place of pColormap if applicable.
  2274. If
  2275. pColormap is the default map, do nothing.
  2276. If any client has requested ColormapNotify events, the DDX layer must notify the client.  
  2277. (The routine WalkTree() is 
  2278. be used to find such windows.  The DIX routines TellNoMap(), 
  2279. TellNewMap()  and TellGainedMap() are provided to be used as 
  2280. the procedure parameter to WalkTree.  These procedures are in
  2281. server/dix/colormap.c.)
  2282. .nf
  2283.  
  2284.     int pScreen->ListInstalledColormaps(pScreen, pCmapList)
  2285.         ScreenPtr pScreen;
  2286.         Colormap *pCmapList;
  2287. .fi
  2288. .LP
  2289. ListInstalledColormaps fills the pCMapList in with the resource ids
  2290. of the installed maps and returns a count of installed maps.
  2291. pCmapList will point to an array of size MaxInstalledMaps that was allocated
  2292. by the caller.
  2293. .nf
  2294.  
  2295.     void pScreen->StoreColors (pmap, ndef, pdefs)
  2296.         ColormapPtr pmap;
  2297.         int ndef;
  2298.         xColorItem *pdefs;
  2299. .fi
  2300. .LP
  2301. StoreColors changes some of the entries in the colormap pmap.
  2302. The number of entries to change are ndef, and pdefs points to the information
  2303. describing what to change.
  2304. Note that partial changes of entries in the colormap are allowed.
  2305. Only the colors
  2306. indicated in the flags field of each xColorItem need to be changed.  
  2307. However, all three color fields will be sent with the proper value for the
  2308. benefit of screens that may not be able to set part of a colormap value.
  2309. If the screen is a static class, this routine does nothing.
  2310. The structure of colormap entries is nontrivial; see colormapst.h 
  2311. and the definition of xColorItem in Xproto.h for 
  2312. more details.
  2313. .nf
  2314.  
  2315.     void pScreen->ResolveColor(pRed, pGreen, pBlue, pVisual)
  2316.         unsigned short *pRed, *pGreen, *pBlue;
  2317.         VisualPtr pVisual;
  2318.  
  2319. .fi
  2320. .LP
  2321. Given a requested color, ResolveColor returns the nearest color that this hardware is
  2322. capable of displaying on this visual.
  2323. In other words, this rounds off each value, in place, to the number of bits
  2324. per primary color that your screen can use.
  2325. Remember that each screen has one of these routines.
  2326. The level of roundoff should be what you would expect from the value
  2327. you put in the bits_per_rgb field of the pVisual.
  2328.  
  2329. Each value is an unsigned value ranging from 0 to 65535.
  2330. The bits least likely to be used are the lowest ones.
  2331. .LP
  2332. For example, if you had a pseudocolor display
  2333. with any number of bits per pixel
  2334. that had a lookup table supplying 6 bits for each color gun
  2335. (a total of 256K different colors), you would
  2336. round off each value to 6 bits.  Please don't simply truncate these values
  2337. to the upper 6 bits, scale the result so that the maximum value seen
  2338. by the client will be 65535 for each primary.  This makes color values
  2339. more portable between different depth displays (a 6-bit truncated white
  2340. will not look white on an 8-bit display).
  2341. .NH 4
  2342. Initializing a Colormap
  2343. .XS
  2344. Initializing a Colormap
  2345. .XE
  2346. .LP
  2347. When a client requests a new colormap and when the server creates the default
  2348. colormap, the procedure CreateColormap in the DIX layer is invoked.
  2349. That procedure allocates memory for the colormap and related storage such as
  2350. the lists of which client owns which pixels.  
  2351. It then sets a bit, BeingCreated, in the flags field of the ColormapRec
  2352. and calls the DDX layer's CreateColormap routine.
  2353. This is your chance to initialize the colormap.
  2354. If the colormap is static, which you can tell by looking at the class field,
  2355. you will want to fill in each color cell to match the hardwares notion of the
  2356. color for that pixel.
  2357. If the colormap is the default for the screen, which you can tell by looking
  2358. at the IsDefault bit in the flags field, you should allocate BlackPixel
  2359. and WhitePixel to match the values you set in the pScreen structure.
  2360. (Of course, you picked those values to begin with.)
  2361. .LP
  2362. You can also wait and use AllocColor() to allocate blackPixel 
  2363. and whitePixel after the default colormap has been created.
  2364. If the default colormap is static and you initialized it in
  2365. pScreen->CreateColormap, then use can use AllocColor afterwards
  2366. to choose pixel values with the closest rgb values to those
  2367. desired for blackPixel and whitePixel.
  2368. If the default colormap is dynamic and uninitialized, then
  2369. the rgb values you request will be obeyed, and AllocColor will
  2370. again choose pixel values for you.
  2371. These pixel values can then be stored into the screen.
  2372. .LP
  2373. There are two ways to fill in the colormap.
  2374. The simplest way is to use AllocColor.  
  2375. .nf
  2376.  
  2377. AllocColor (pmap, pred, pgreen, pblue, pPix, client)
  2378.     ColormapPtr         pmap;
  2379.     unsigned short      *pred, *pgreen, *pblue;
  2380.     Pixel               *pPix;
  2381.     int                 client;
  2382.  
  2383. .fi
  2384. This takes three pointers to 16 bit color values and a pointer to a suggested
  2385. pixel value.  The pixel value is either an index into one colormap or a
  2386. combination of three indices depending on the type of pmap.
  2387. If your colormap starts out empty, and you don't deliberately pick the same
  2388. value twice, you will always get your suggested pixel.
  2389. The truly nervous could check that the value returned in *pPix is the one
  2390. AllocColor was called with.
  2391. If you don't care which pixel is used, or would like them sequentially
  2392. allocated from entry 0, set *pPix to 0.  This will find the first free
  2393. pixel and use that.
  2394. .LP
  2395. AllocColor will take care of all the  bookkeeping  and  will
  2396. call StoreColors to get the colormap rgb values initialized.
  2397. The hardware colormap will be changed whenever this colormap
  2398. is installed.
  2399. .LP
  2400. If for some reason AllocColor doesn't do what you want, you can do your
  2401. own bookkeeping and call StoreColors yourself.  This is much more difficult
  2402. and shouldn't be necessary for most devices.
  2403.  
  2404. .NH 3
  2405. Fonts for Screens
  2406. .XS
  2407. Fonts for Screens
  2408. .XE
  2409. .LP
  2410. A font is a set of bitmaps that depict the symbols in a character set.
  2411. Each font is for only one typeface in a given size, in other words, just one
  2412. bitmap for each character.
  2413. Parallel fonts may be available in a variety of sizes and variations, including
  2414. "bold" and "italic."
  2415. X supports fonts for 8-bit and 16-bit character codes (for oriental languages
  2416. that have more than 256 characters in the font).
  2417. Glyphs are bitmaps for individual characters.
  2418.  
  2419. The source comes with some useful font files in an
  2420. ASCII, plain-text format that should be comprehensible on a wide variety of operating systems.
  2421. The text format, referred to as BDF, is a slight extension of the
  2422. current Adobe 2.1 Bitmap Distribution Format (Adobe Systems, Inc.).
  2423.  
  2424. A short paper in PostScript format is included with the sample server
  2425. that defines BDF.  It includes helpful pictures, which is why it is
  2426. done in PostScript and is not included in this document.
  2427.  
  2428. Your implementation should include some sort of font compiler to read these
  2429. files and generate binary files that are directly usable by your server implementation.
  2430. The sample server comes with the source for a font compiler.
  2431.  
  2432. It is important the font properties contained in the BDF files are
  2433. preserved across any font compilation. In particular, copyright
  2434. information cannot be casually tossed aside without legal
  2435. ramifications. Other properties will be important to
  2436. some sophisticated applications.
  2437.  
  2438. All clients get font information from the server.
  2439. Therefore, your server can support any fonts it wants to.
  2440. It should probably support at least the fonts supplied with the X11 tape.
  2441. In principle, you can convert fonts from other
  2442. sources or dream up your own fonts for use on your server.
  2443.  
  2444. .NH 4
  2445. Portable Compiled Format
  2446. .XS
  2447. Portable Compiled Format
  2448. .XE
  2449. .LP
  2450. A font compiler is supplied with the sample server.
  2451. It has compile-time switches to convert the BDF files
  2452. into a portable binary form, called Portable Compiled Format or PCF.
  2453. This allows for an arbitrary data format inside the file, and by
  2454. describing the details of the format in the header of the file, any PCF
  2455. file can be read by any PCF reading client.  By selecting the format which
  2456. matches the required internal format for your renderer, the PCF reader can
  2457. avoid reformatting the data each time it is read in.
  2458. The font compiler should be directly portable to most UNIX-based systems 
  2459. and is probably portable
  2460. to many non-UNIX systems.
  2461.  
  2462. The fonts included with the tape are stored in fonts/bdf.  The
  2463. font compiler is found in fonts/tools/bdftopcf.
  2464. .NH 4
  2465. Font Realization
  2466. .XS
  2467. Font Realization
  2468. .XE
  2469. .LP
  2470. Each screen configured into the server
  2471. has an opportunity at font-load time
  2472. to "realize" a font into some internal format if necessary. 
  2473. This happens every time the font is loaded into memory.
  2474.  
  2475. A font (FontRec in server/include/dixfontstr.h) is
  2476. a device-independent structure containing a device-independent
  2477. representation of the font.  When a font is created, it is "realized"
  2478. for each screen.  At this point, the screen has the chance to convert
  2479. the font into some other format.  The DDX layer can also put information
  2480. in the devPrivate storage.
  2481. .nf
  2482.  
  2483.     Bool pScreen->RealizeFont(pScr, pFont)
  2484.         ScreenPtr pScr;
  2485.         FontPtr pFont;
  2486.  
  2487.     Bool pScreen->UnrealizeFont(pScr, pFont)
  2488.         ScreenPtr pScr;
  2489.         FontPtr pFont;
  2490. .fi
  2491. RealizeFont and UnrealizeFont should calculate and allocate these extra data structures and 
  2492. dispose of them when no longer needed.
  2493. These are called in response to OpenFont and CloseFont requests from 
  2494. the client.
  2495. The sample server implementation is in mfbfont.c (which does very little).
  2496.  
  2497. .NH 3
  2498. Other Screen Routines
  2499. .XS
  2500. Other Screen Routines
  2501. .XE
  2502. .LP
  2503. You must supply several other screen-specific routines for 
  2504. your X server implementation.
  2505. Some of these are described in other sections:
  2506. .IP \(bu 5
  2507. GetImage() is described in the Drawing Primitives section.
  2508. .IP \(bu 5
  2509. GetSpans() is described in the Pixblit routine section.
  2510. .IP \(bu 5
  2511. Several window and pixmap manipulation procedures are 
  2512. described in the Window section under Drawables.
  2513. .IP \(bu 5
  2514. The CreateGC() routine is described under Graphics Contexts.
  2515. .LP
  2516. .nf
  2517.  
  2518.     void pScreen->QueryBestSize(kind, pWidth, pHeight)
  2519.         int kind;
  2520.         CARD16 *pWidth, *pHeight;
  2521. .fi
  2522. QueryBestSize() returns the best sizes for cursors, tiles, and stipples
  2523. in response to client requests.
  2524. kind is one of the defined constants CursorShape, TileShape, or StippleShape
  2525. (defined in X.h).
  2526. For CursorShape, return the maximum width and 
  2527. height for cursors that you can handle.
  2528. For TileShape and StippleShape, start with the suggested values in pWidth
  2529. and pHeight and modify them in place to be optimal values that are
  2530. greater than or equal to the suggested values.
  2531. The sample server implementation is in server/ddx/mfb/mfbmisc.c.
  2532. .nf
  2533.  
  2534.     pScreen->SourceValidate(pDrawable, x, y, width, height)
  2535.         DrawablePtr pDrawable;
  2536.         int x, y, width, height;
  2537. .fi
  2538. SourceValidate should be called by CopyArea/CopyPlane primitives when
  2539. the source drawable is not the same as the destination, and the
  2540. SourceValidate function pointer in the screen is non-null.  If you know that
  2541. you will never need SourceValidate, you can avoid this check.  Currently,
  2542. SourceValidate is used by the mi software cursor code to remove the cursor
  2543. from the screen when the source rectangle overlaps the cursor position.
  2544. x,y,width,height describe the source rectangle (source relative, that is)
  2545. for the copy operation.
  2546. .nf
  2547.  
  2548.     Bool pScreen->SaveScreen(pScreen, on)
  2549.         ScreenPtr pScreen;
  2550.         int on;
  2551. .fi
  2552. SaveScreen() is used for Screen Saver support (see WaitForSomething()).
  2553. pScreen is the screen to save.
  2554. .nf
  2555.  
  2556.     Bool pScreen->CloseScreen(pScreen)
  2557.         ScreenPtr pScreen;
  2558. .fi
  2559. When the server is reset, it calls this routine for each screen.
  2560. .NH 2
  2561. Drawables
  2562. .XS
  2563. Drawables
  2564. .XE
  2565. .LP
  2566. A drawable is a descriptor of a surface that graphics are drawn into, either
  2567. a window on the screen or a pixmap in memory.
  2568.  
  2569. Each drawable has a type, class,
  2570. ScreenPtr for the screen it is associated with, depth, position, size,
  2571. and serial number.
  2572. The type is one of the defined constants DRAWABLE_PIXMAP,
  2573. DRAWABLE_WINDOW and UNDRAWABLE_WINDOW.
  2574. (An undrawable window is used for window class InputOnly.)
  2575. The serial number is guaranteed to be unique across drawables, and
  2576. is used in determining
  2577. the validity of the clipping information in a GC.
  2578. The screen selects the set of procedures used to manipulate and draw into the
  2579. drawable.  Position is used (currently) only by windows; pixmaps must
  2580. set these fields to 0,0 as this reduces the amount of conditional code
  2581. executed throughout the mi code.  Size indicates the actual client-specified
  2582. size of the drawable.
  2583. There are, in fact, no other fields that a window drawable and pixmap
  2584. drawable have in common besides those mentioned here.
  2585.  
  2586. Both PixmapRecs and WindowRecs are structs that start with a drawable and
  2587. continue on with more fields.  Pixmaps have devPrivate pointers, which are
  2588. assumed to point to DDX specific data, while windows have an array of
  2589. devPrivates unions, one entry of which will probably be used for DDX
  2590. specific data.  Entries in this array are allocated using
  2591. AllocateWindowPrivateIndex() (see Wrappers and Privates below).  This is
  2592. done because different graphics hardware has different requirements for
  2593. management; if the graphics is always handled by a processor with an
  2594. independent address space, there is no point having a pointer to the bit
  2595. image itself.
  2596.  
  2597. The definition of a drawable and a pixmap can be found in the file
  2598. server/include/pixmapstr.h.
  2599. The definition of a window can be found in the file server/include/windowstr.h.
  2600.  
  2601. .NH 3
  2602. Pixmaps
  2603. .XS
  2604. Pixmaps
  2605. .XE
  2606. .LP
  2607. A pixmap is a three-dimensional array of bits stored somewhere offscreen,
  2608. rather than in the visible portion of the screen's display frame buffer.  It
  2609. can be used as a source or destination in graphics operations.  There is no
  2610. implied interpretation of the pixel values in a pixmap, because it has no
  2611. associated visual or colormap.  There is only a depth that indicates the
  2612. number of significant bits per pixel.  Also, there is no implied physical
  2613. size for each pixel; all graphic units are in numbers of pixels.  Therefore,
  2614. a pixmap alone does not constitute a complete image; it represents only a
  2615. rectangular array of pixel values.
  2616.  
  2617. Note that the pixmap data structure is reference-counted.
  2618.  
  2619. The server
  2620. implementation is free to put the pixmap image data anywhere it sees fit,
  2621. according to its graphics hardware setup.
  2622. Many implementations will simply have the data dynamically
  2623. allocated in the server's address space.
  2624.  
  2625. The pixmap data structure has two fields that are private to the device.
  2626. Although you can use them for anything you want, they have intended purposes.
  2627. devKind is intended to be a device specific indication of the pixmap location (host
  2628. memory, off-screen, etc.).    In the
  2629. sample server, since all pixmaps are in memory, devKind stores the
  2630. width of the pixmap in bitmap scanline units.
  2631. devPrivate is probably a pointer to
  2632. the bits in the pixmap plus other device specific information.
  2633.  
  2634. A bitmap is a pixmap that is one bit deep.
  2635. .nf
  2636.  
  2637.     PixmapPtr pScreen->CreatePixmap(pScreen, width, height, depth)
  2638.         ScreenPtr pScreen;
  2639.         int width, height, depth;
  2640. .fi
  2641. This ScreenRec procedure must create a pixmap of the size
  2642. requested.
  2643. It must allocate a PixmapRec and fill in all of the fields.
  2644. The reference count field must be set to 1.
  2645. If successful, it returns a pointer to it; if not, it returns NULL.
  2646. See server/ddx/mfb/mfbpixmap.c for the server implementation.
  2647. .nf
  2648.  
  2649.     Bool pScreen->DestroyPixmap(pPixmap)
  2650.         PixmapPtr pPixmap;
  2651. .fi
  2652. This ScreenRec procedure must "destroy" a pixmap.
  2653. It should decrement the reference count and, if zero, it 
  2654. must deallocate the PixmapRec and all attached devPrivate blocks.
  2655. If successful, it returns TRUE. 
  2656. See server/ddx/mfb/mfbpixmap.c for the server implementation.
  2657.  
  2658. .NH 3
  2659. Windows
  2660. .XS
  2661. Windows
  2662. .XE
  2663. .LP
  2664. A window is a visible, or potentially visible, rectangle on the screen.
  2665. DIX windowing functions maintain an internal n-ary tree data structure, which
  2666. represents the current relationships of the mapped windows.
  2667. Windows that are contained in another window are children of that window and
  2668. are clipped to the boundaries of the parent.
  2669. The root window in the tree is the window for the entire screen.
  2670. Sibling windows constitute a doubly-linked list; the parent window has a pointer
  2671. to the head and tail of this list.
  2672. Each child also has a pointer to its parent.
  2673.  
  2674. The border of a window is drawn by a DDX procedure when DIX requests that it
  2675. be drawn.  The contents of the window is drawn by the client through
  2676. requests to the server.
  2677.  
  2678. Window painting is orchestrated through an expose event system.
  2679. When a region is exposed, 
  2680. DIX generates an expose event, telling the client to repaint the window and
  2681. passing the region that is the minimal area needed to be repainted.
  2682.  
  2683. As a favor to clients, the server may retain
  2684. the output to the hidden parts of windows
  2685. in off-screen memory; this is called "backing store".
  2686. When a part of such a window becomes exposed, it
  2687. can quickly move pixels into place instead of
  2688. triggering an expose event and waiting for a client on the other
  2689. end of the network to respond.
  2690. Even if the network response is insignificant, the time to
  2691. intelligently paint a section of a window is usually more than
  2692. the time to just copy already-painted sections.
  2693. At best, the repainting involves blanking out the area to a background color,
  2694. which will take about the
  2695. same amount of time.
  2696. In this way, backing store can dramatically increase the
  2697. performance of window moves.
  2698.  
  2699. On the other hand, backing store can be quite complex, because
  2700. all graphics drawn to hidden areas must be intercepted and redirected
  2701. to the off-screen window sections.
  2702. Not only can this be complicated for the server programmer,
  2703. but it can also impact window painting performance.
  2704. The backing store implementation can choose, at any time, to 
  2705. forget pieces of backing that are written into, relying instead upon
  2706. expose events to repaint for simplicity.
  2707.  
  2708. In X, the decision to use the backing-store scheme is made
  2709. by you, the server implementor.
  2710. X provides hooks for implementing backing store, therefore 
  2711. the decision to use this strategy can be made on the fly.
  2712. For example, you may use backing store only for certain windows
  2713. that the user requests or you may use backing store 
  2714. until memory runs out, at which time you
  2715. start dropping pieces of backing as needed to make more room.
  2716.  
  2717. When a window operation is requested by the client,
  2718. such as a window being created or moved,
  2719. a new state is computed.
  2720. During this transition, DIX informs DDX what rectangles in what windows are about to
  2721. become obscured and what rectangles in what windows have become exposed.
  2722. This provides a hook for the implementation of backing store.
  2723. If DDX is unable to restore exposed regions, DIX generates expose
  2724. events to the client.
  2725. It is then the client's responsibility to paint the
  2726. window parts that were exposed but not restored.
  2727.  
  2728. If a window is resized, pixels sometimes need to be
  2729. moved, depending upon
  2730. the application.
  2731. The client can request "Gravity" so that
  2732. certain blocks of the window are
  2733. moved as a result of a resize.
  2734. For instance, if the window has controls or other items
  2735. that always hang on the edge of the
  2736. window, and that edge is moved as a result of the resize,
  2737. then those pixels should be moved
  2738. to avoid having the client repaint it.
  2739. If the client needs to repaint it anyway, such an operation takes
  2740. time, so it is desirable
  2741. for the server to approximate the appearance of the window as best
  2742. it can while waiting for the client
  2743. to do it perfectly.
  2744. Gravity is used for that, also.
  2745.  
  2746. The window has several fields used in drawing
  2747. operations:
  2748. .IP \(bu 5
  2749. clipList - This region, in conjunction with
  2750. the client clip region in the gc, is used to clip output.
  2751. clipList has the window's children subtracted from it, in addition to pieces of sibling windows
  2752. that overlap this window.  To get the list with the
  2753. children included (subwindow-mode is IncludeInferiors),
  2754. the routine NotClippedByChildren(pWin) returns the unclipped region.
  2755. .IP \(bu 5
  2756. borderClip is the region used by CopyWindow and 
  2757. includes the area of the window, its children, and the border, but with the
  2758. overlapping areas of sibling children removed.
  2759. .LP
  2760. Most of the other fields are for DIX use only.
  2761.  
  2762. .NH 4
  2763. Window Procedures in the ScreenRec
  2764. .XS
  2765. Window Procedures in the ScreenRec
  2766. .XE
  2767. .LP
  2768. You should implement
  2769. all of the following procedures and store pointers to them in the screen record.
  2770.  
  2771. The device-independent portion of the server "owns" the window tree.
  2772. However, clever hardware might want to know the relationship of
  2773. mapped windows.  There are pointers to procedures
  2774. in the ScreenRec data structure that are called to give the hardware
  2775. a chance to update its internal state.  These are helpers and
  2776. hints to DDX only;
  2777. they do not change the window tree, which is only changed by DIX.
  2778. .nf
  2779.  
  2780.     void pScreen->CreateWindow(pWin)
  2781.         WindowPtr pWin;
  2782. .fi
  2783. This routine is a hook for when DIX creates a window.
  2784. It should fill in the "Window Procedures in the WindowRec" below
  2785. and also allocate the devPrivate block for it.
  2786.  
  2787. See server/ddx/mfb/mfbwindow.c for the sample server implementation.
  2788. .nf
  2789.  
  2790.     Bool pScreen->DestroyWindow(pWin);
  2791.         WindowPtr pWin;
  2792. .fi
  2793. This routine is a hook for when DIX destroys a window.
  2794. It should deallocate the devPrivate block for it and any other blocks that need
  2795. to be freed, besides doing other cleanup actions.
  2796.  
  2797. See server/ddx/mfb/mfbwindow.c for the sample server implementation.
  2798. .nf
  2799.  
  2800.     Bool pScreen->PositionWindow(pWin, x, y);
  2801.         WindowPtr pWin;
  2802.         int x, y;
  2803. .fi
  2804. This routine is a hook for when DIX moves or resizes a window.
  2805. It should do whatever private operations need to be done when a window is moved or resized.
  2806. For instance, if DDX keeps a pixmap tile used for drawing the background
  2807. or border, and it keeps the tile rotated such that it is longword
  2808. aligned to longword locations in the frame buffer, then you should rotate your tiles here.
  2809. The actual graphics involved in moving the pixels on the screen and drawing the
  2810. border are handled by CopyWindow(), below.
  2811. .LP
  2812. See server/ddx/mfb/mfbwindow.c for the sample server implementation.
  2813. .nf
  2814.  
  2815.     void pScreen->RealizeWindow(pWin);
  2816.         WindowPtr pWin;
  2817.  
  2818.     void  pScreen->UnrealizeWindow(pWin);
  2819.         WindowPtr pWin;
  2820. .fi
  2821. These routines are hooks for when DIX maps (makes visible) and unmaps (makes invisible)
  2822. a window.
  2823. It should do whatever private operations need to be done 
  2824. when these happen, such as allocating or deallocating structures that 
  2825. are only needed for visible windows.
  2826. RealizeWindow does NOT draw the window border, background or contents;
  2827. UnrealizeWindow does NOT erase the window or generate exposure events
  2828. for underlying windows; this is taken care of by DIX.
  2829. DIX does, however, call PaintWindowBackground() and PaintWindowBorder()
  2830. to perform some of these.
  2831.  
  2832. .nf
  2833.  
  2834.     Bool pScreen->ChangeWindowAttributes(pWin, vmask)
  2835.         WindowPtr pWin;
  2836.         long vmask;
  2837. .fi
  2838.  
  2839. ChangeWindowAttributes is called whenever DIX changes window attributes, such as the
  2840. size, front-to-back ordering, title, or anything of lesser severity that
  2841. affects the window itself.
  2842. The sample server implements this routine.  It computes accelerators
  2843. for quickly putting up background and border tiles.  (See description of the
  2844. set of routines stored in the WindowRec.)
  2845. .nf
  2846.  
  2847.     int pScreen->ValidateTree(pParent,  pChild, top, anyMarked)
  2848.         WindowPtr pParent, pChild;
  2849.         Bool top, anyMarked;
  2850. .fi
  2851.  
  2852. ValidateTree calculates the clipping region for the parent window and
  2853. all of its children.
  2854. This routine must be provided. The sample
  2855. server has a machine-independent version in server/ddx/mi/mivaltree.c.  This
  2856. is a very difficult routine to replace.
  2857. .nf
  2858.  
  2859.     void pScreen->WindowExposures(pWin, pRegion)
  2860.         WindowPtr pWin;
  2861.         RegionPtr pRegion;
  2862. .fi
  2863. The WindowExposures() routine
  2864. paints the border and generates exposure events for the window.
  2865. Since exposure events include a rectangle describing what was exposed, 
  2866. this routine may have to send back a series of exposure events, one for
  2867. each rectangle of the region.  
  2868. The count field in the expose event is a hint to the
  2869. client as to the number of
  2870. regions that are after this one.
  2871. This routine must be provided. The sample
  2872. server has a machine-independent version in server/ddx/mi/miexpose.c.
  2873. .nf
  2874.  
  2875.     void pScreen->ClipNotify (pWin, dx, dy)
  2876.         WindowPtr pWin;
  2877.         int dx, dy;
  2878. .fi
  2879. Whenever the cliplist for a window is changed, this function is called to
  2880. perform whatever hardware manipulations might be necessary.  When called,
  2881. the clip list and border clip regions in the window are set to the new
  2882. values.  dx,dy are the distance that the window has been moved (if at all).
  2883. .NH 4
  2884. Window Painting Procedures
  2885. .XS
  2886. Window Painting Procedures
  2887. .XE
  2888. .LP
  2889. In addition to the procedures listed above, there are four routines which
  2890. manipulate the actual window image directly.
  2891. In the sample server, mi implementations will work for 
  2892. most purposes and mfb/cfb routines speed up situations, such
  2893. as solid backgrounds/borders or tiles that are 8, 16 or 32 pixels square.
  2894.  
  2895. These three routines are used for systems that implement a backing-store scheme for it to
  2896. know when to stash away areas of pixels and to restore or reposition them.
  2897. .nf
  2898.  
  2899.     void pScreen->ClearToBackground(pWin, x, y, w, h, generateExposures);
  2900.         WindowPtr pWin;
  2901.         int x, y, w, h;
  2902.         Bool generateExposures;
  2903. .fi
  2904. This routine is called on a window in response to a ClearToBackground request
  2905. from the client.
  2906. This request has two different but related functions, depending upon generateExposures.
  2907.  
  2908. If generateExposures is true, the client is declaring that the given rectangle
  2909. on the window is incorrectly painted and needs to be repainted.
  2910. The sample server implementation calculates the exposure region
  2911. and hands it to the DIX procedure HandleExposures(), which
  2912. calls the WindowExposures() routine, below, for the window
  2913. and all of its child windows.
  2914.  
  2915. If generateExposures is false, the client is trying to simply erase part
  2916. of the window to the background fill style.
  2917. ClearToBackground should write the background color or tile to the 
  2918. rectangle in question (probably using PaintWindowBackground).
  2919. If w or h is zero, it clears all the way to the right or lower edge of the window.
  2920.  
  2921. The sample server implementation is in server/ddx/mi/miwindow.c.
  2922. .nf
  2923.  
  2924.     void pScreen->PaintWindowBackground(pWin, region, kind)
  2925.         WindowPtr pWin;
  2926.         RegionPtr region;
  2927.         int kind;    /* must be PW_BACKGROUND */
  2928.  
  2929.     void pScreen->PaintWindowBorder(pWin, region, kind)
  2930.         WindowPtr pWin;
  2931.         RegionPtr region;
  2932.         int kind;    /* must be PW_BORDER */
  2933. .fi
  2934. These two routines are for painting pieces of the window background or border.
  2935. They both actually paint the area designated by region.
  2936. The kind parameter is a defined constant that is always PW_BACKGROUND
  2937. or PW_BORDER, as shown.
  2938. Therefore, you can use the same routine for both.
  2939. The defined constant tells the routine whether to use the window's 
  2940. border fill style or its background fill style to paint the given region.
  2941. Both fill styles consist of a union which holds a tile pointer and a pixel
  2942. value, along with a separate variable which indicates which entry is valid.
  2943. For PW_BORDER, borderIsPixel != 0 indicates that the border PixUnion
  2944. contains a pixel value, else a tile.  For PW_BACKGROUND there are four
  2945. values, contained in backgroundState; None, ParentRelative, BackgroundPixmap
  2946. and BackgroundPixel.  None indicates that the region should be left
  2947. unfilled, while ParentRelative indicates that the background of the parent is
  2948. inherited (see the Protocol document for the exact semantics).
  2949. .nf
  2950.  
  2951.     void pScreen->CopyWindow(pWin, oldpt, oldRegion);
  2952.         WindowPtr pWin;
  2953.         POINT oldpt;
  2954.         RegionPtr oldRegion;
  2955. .fi
  2956.  
  2957. CopyWindow is called when a window is moved, and graphically
  2958. moves to pixels of a window on the screen.
  2959. It should not change any other state within DDX (see PositionWindow(), above).
  2960.  
  2961. oldpt is the old location of the upper-left corner.
  2962. oldRegion is the old region it is coming from.
  2963. The new location and new region is stored in the WindowRec.
  2964. oldRegion might modified in place by this routine (the sample
  2965. implementation does this).
  2966.  
  2967. CopyArea could be used, except that this operation has more complications.
  2968. First of all, you do not want to copy a rectangle onto a rectangle.
  2969. The original window may be obscured by other windows, and the new window location
  2970. may be similarly obscured.  
  2971. Second, some hardware supports multiple windows with multiple depths, and 
  2972. your routine needs to take care of that.
  2973.  
  2974. The pixels
  2975. in oldRegion (with reference point oldpt) are copied to the
  2976. window's new region (pWin->borderClip).   pWin->borderClip is gotten
  2977. directly from the window, rather than passing it as a parameter.
  2978.  
  2979. The sample server implementation is in server/ddx/mfb/mfbwindow.c.
  2980.  
  2981. .NH 4
  2982. Screen Operations for Backing Store
  2983. .XS
  2984. Screen Operations for Backing Store
  2985. .XE
  2986. .LP
  2987. Each ScreenRec has six functions which provide the backing store
  2988. interface.  For screens not supporting backing store, these pointers
  2989. may be nul.  Servers that implement some backing store scheme 
  2990. must fill in the procedure pointers for the procedures below,
  2991. and must maintain the backStorage field in each window struct.
  2992. The sample implementation is in ddx/mi/mibstore.c.
  2993. .nf
  2994.  
  2995.     void pScreen->SaveDoomedAreas(pWin, pRegion, dx, dy)
  2996.         WindowPtr pWin;
  2997.         RegionPtr pRegion;
  2998.         int dx, dy;
  2999. .fi
  3000. This routine saves the newly obscured region, pRegion, in backing store.
  3001. dx, dy indicate how far the window is being moved, useful as the obscured
  3002. region is relative to the window as it will appear in the new location,
  3003. rather then relative to the bits as the are on the screen when the function
  3004. is invoked.
  3005. .nf
  3006.  
  3007.     RegionPtr pBackingStore->RestoreAreas(pWin, pRegion)
  3008.         WindowPtr pWin;
  3009.         RegionPtr pRegion;
  3010. .fi
  3011. This looks at the exposed region of the window, pRegion, and tries to
  3012. restore to the screen the parts that have been saved.  It removes the
  3013. restored parts from the backing storage (because they are now on the screen)
  3014. and subtracts the areas from the exposed region.  The returned region is the
  3015. area of the window which should have expose events generated for and can be
  3016. either a new region, pWin->exposed, or NULL.  The region left in
  3017. pRegion is set to the area of the window which should be painted with
  3018. the window background.
  3019. .nf
  3020.  
  3021.     void pBackingStore->TranslateBackingStore(pWin, dx, dy, oldClip)
  3022.         WindowPtr pWin;
  3023.         int dx, dy;
  3024.         RegionPtr oldClip;
  3025. .fi
  3026. This is called when the window is moved or resized so that the backing
  3027. store can be translated if necessary.  oldClip is the old cliplist for
  3028. the window, which is used to save doomed areas if the window is moved
  3029. underneath its parent as a result of bitgravity.
  3030.  
  3031. .NH 2
  3032. Graphics Contexts and Validation
  3033. .XS
  3034. Graphics Contexts and Validation
  3035. .XE
  3036. .LP
  3037. This graphics context (GC) contains state variables such as foreground and
  3038. background pixel value (color), the current line style and width,
  3039. the current tile or stipple for pattern generation, the current font for text
  3040. generation, and other similar attributes.
  3041.  
  3042. In many graphics systems, the equivalent of the graphics context and the
  3043. drawable are combined as one entity.
  3044. The main distinction between the two kinds of status is that a drawable
  3045. describes a writing surface and the writings that may have already been done
  3046. on it, whereas a graphics context describes the drawing process.
  3047. A drawable is like a chalkboard.
  3048. A GC is like a piece of chalk.
  3049.  
  3050. Unlike many similar systems, there is no "current pen location."
  3051. Every graphic operation is accompanied by the coordinates where it is to happen.
  3052.  
  3053. The GC also includes two vectors of procedure pointers, the first
  3054. operate on the GC itself and are called GC funcs.  The second, called
  3055. GC ops,
  3056. contains the functions that carry out the fundamental graphic operations
  3057. such as drawing lines, polygons, arcs, text, and copying bitmaps.
  3058. The DDX graphic software can, if it
  3059. wants to be smart, change these two vectors of procedure pointers
  3060. to take advantage of hardware/firmware in the server machine, which can do
  3061. a better job under certain circumstances.  To reduce the amount of memory
  3062. consumed by each GC, it is wise to create a few "boilerplate" GC ops vectors
  3063. which can be shared by every GC which matches the constraints for that set.
  3064. Also, it is usually reasonable to have every GC created by a particular
  3065. module to share a common set of GC funcs.  Samples of this sort of
  3066. sharing can be seen in ddx/cfb/cfbgc.c and ddx/mfb/mfbgc.c.
  3067.  
  3068. The DDX software is notified any time the client (or DIX) uses a changed GC.
  3069. For instance, if the hardware has special support for drawing fixed-width
  3070. fonts, DDX can intercept changes to the current font in a GC just before
  3071. drawing is done.  It can plug into either a fixed-width procedure that makes
  3072. the hardware draw characters, or a variable-width procedure that carefully
  3073. lays out glyphs by hand in software, depending upon the new font that is
  3074. selected.
  3075.  
  3076. A definition of these structures can be found in the file 
  3077. server/include/gcstruct.h.
  3078.  
  3079. Also included in each GC is an array of devPrivates which portions of the
  3080. DDX can use for any reason.  Entries in this array are allocated with
  3081. AllocateGCPrivateIndex() (see Wrappers and Privates below).
  3082.  
  3083. The DIX routines available for manipulating GCs are
  3084. CreateGC, ChangeGC, CopyGC, SetClipRects, SetDashes, and FreeGC.
  3085. .nf
  3086.     
  3087.     GCPtr CreateGC(pDrawable, mask, pval, pStatus)
  3088.         DrawablePtr pDrawable;
  3089.         BITS32 mask;
  3090.         XID *pval;
  3091.         int *pStatus;
  3092.  
  3093.     int ChangeGC(pGC, mask, pval)
  3094.         GC *pGC;
  3095.         BITS32 mask;
  3096.         XID *pval;
  3097.  
  3098.     int CopyGC(pgcSrc, pgcDst, mask)
  3099.         GC *pgcSrc;
  3100.         GC *pgcDst;
  3101.         BITS32 mask;
  3102.  
  3103.     int SetClipRects(pGC, xOrigin, yOrigin, nrects, prects, ordering)
  3104.         GCPtr pGC;
  3105.         int xOrigin, yOrigin;
  3106.         int nrects;
  3107.         xRectangle *prects;
  3108.         int ordering;
  3109.  
  3110.     SetDashes(pGC, offset, ndash, pdash)
  3111.         GCPtr pGC;
  3112.         unsigned offset;
  3113.         unsigned ndash;
  3114.         unsigned char *pdash;
  3115.  
  3116.     int FreeGC(pGC, gid)
  3117.         GCPtr pGC;
  3118.         GContext gid;
  3119. .fi
  3120.  
  3121. As a convenience, each Screen structure contains an array of 
  3122. GCs that are preallocated, one at each depth the screen supports.
  3123. These are particularly useful in the mi code.  Two DIX routines
  3124. must be used to get these GCs:
  3125. .nf
  3126.  
  3127.     GCPtr GetScratchGC(pScreen, depth)
  3128.         ScreenPtr pScreen;
  3129.         int depth;
  3130.  
  3131.     FreeScratchGC(pGC)
  3132.         GCPtr pGC;
  3133.  
  3134. .fi
  3135. Always use these two routines, don't try to extract the scratch
  3136. GC yourself -- someone else might be using it, so a new one must
  3137. be created on the fly.
  3138.  
  3139. If you need a GC for a very long time, say until the server is restarted,
  3140. you should not take one from the pool used by GetScratchGC, but should
  3141. get your own using CreateGC or CreateScratchGC.
  3142. This leaves the ones in the pool free for routines that only need it for
  3143. a little while and don't want to pay a heavy cost to get it.
  3144. .nf
  3145.     GCPtr CreateScratchGC(pScreen, depth)
  3146.         ScreenPtr pScreen;
  3147.         int depth;
  3148.  
  3149. .fi
  3150. NULL is returned if the GC cannot be created.
  3151. The GC returned can be freed with FreeScratchGC.
  3152.  
  3153. .NH 3
  3154. Details of operation
  3155. .XS
  3156. Details of operation
  3157. .XE
  3158. .LP
  3159. At screen initialization, a screen must supply a GC creation procedure.
  3160. At GC creation, the screen must fill in GC funcs and GC ops vectors
  3161. (server/include/gcstruct.h).  For any particular GC, the func vector
  3162. must remain constant, while the op vector may vary.  This invariant is to
  3163. ensure that Wrappers work correctly.
  3164.  
  3165. When a client request is processed that results in a change
  3166. to the GC, the device-independent state of the GC is updated.
  3167. This includes a record of the state that changed.
  3168. Then the ChangeGC GC func is called.
  3169. This is useful for graphics subsystems that are able to process
  3170. state changes in parallel with the server CPU.
  3171. DDX may opt not to take any action at GC-modify time.
  3172. This is more efficient if multiple GC-modify requests occur
  3173. between draws using a given GC.
  3174.  
  3175. Validation occurs at the first draw operation that specifies the GC after
  3176. that GC was modified.  DIX calls then the ValidateGC GC func.  DDX should
  3177. then update its internal state.  DDX internal state may be stored as one or
  3178. more of the following:  1) device private block on the GC; 2) hardware
  3179. state; 3) changes to the GC ops.
  3180.  
  3181. The GC contains a serial number, which is loaded with a number fetched from
  3182. the window that was drawn into the last time the GC was used.  The serial
  3183. number in the drawable is changed when the drawable's
  3184. clipList or absCorner changes.  Thus, by
  3185. comparing the GC serial number with the drawable serial number, DIX can
  3186. force a validate if the drawable has been changed since the last time it
  3187. was used with this GC.
  3188.  
  3189. In addition, the drawable serial number is always guaranteed to have the
  3190. most significant bit set to 0.  Thus, the DDX layer can set the most
  3191. significant bit of the serial number to 1 in a GC to force a validate the next time
  3192. the GC is used.  DIX also uses this technique to indicate that a change has
  3193. been made to the GC by way of a SetGC, a SetDashes or a SetClip request.
  3194.  
  3195. .NH 3
  3196. GC Handling Routines
  3197. .XS
  3198. GC Handling Routines
  3199. .XE
  3200. .LP
  3201. The ScreenRec data structure has a pointer for
  3202. CreateGC().
  3203. .nf
  3204.  
  3205.     Bool pScreen->CreateGC(pGC)
  3206.         GCPtr pGC;
  3207. .fi
  3208. This routine must fill in the fields of
  3209. a dynamically allocated GC that is passed in.
  3210. It does NOT allocate the GC record itself or fill
  3211. in the defaults; DIX does that.
  3212.  
  3213. This must fill in both the GC funcs and ops; none of the drawing
  3214. functions will be called before the GC has been validated,
  3215. but the others (dealing with allocating of clip regions,
  3216. changing and destroying the GC, etc.) might be.
  3217.  
  3218. The GC funcs vector contains pointers to 7
  3219. routines and a devPrivate field:
  3220. .nf
  3221.  
  3222.     pGC->funcs->ChangeGC(pGC, changes)
  3223.         GCPtr pGC;
  3224.         Mask changes;
  3225. .fi
  3226.  
  3227. This GC func is called
  3228. immediately after a field in the GC is changed.
  3229. changes is a bit mask indicating the
  3230. changed fields of the GC in this request.
  3231.  
  3232. The ChangeGC routine is useful if you have a system where state-changes to the
  3233. GC can be swallowed immediately by your graphics system,
  3234. and a validate is not necessary.
  3235.  
  3236. .nf
  3237.  
  3238.     pGC->funcs->ValidateGC(pGC, changes, pDraw)
  3239.         GCPtr pGC;
  3240.         Mask changes;
  3241.         DrawablePtr pDraw;
  3242. .fi
  3243.  
  3244. ValidateGC is called by DIX
  3245. just before the GC will be used when one of many possible changes to the GC
  3246. or the graphics system
  3247. has happened. 
  3248. It can modify a devPrivates
  3249. field of the GC or its contents, change the op vector,
  3250. or change hardware according to the values in the GC.
  3251. It may not
  3252. change the device-independent portion of the GC itself.
  3253.  
  3254. In almost all cases, your ValidateGC() procedure should take the regions 
  3255. that drawing needs to be clipped to and combine them into a composite
  3256. clip region, which you keep a pointer to in the private part of the GC.
  3257. In this way, your drawing primitive routines (and whatever is below them)
  3258. can easily determine what to clip and where.
  3259. You should combine the regions clientClip (the region that the client desires to
  3260. clip output to) and the region returned by NotClippedByChildren(), in DIX.
  3261. An example is in server/ddx/mfb/mfbgc.c.
  3262.  
  3263. Some kinds of extension software may cause this routine to be called more than originally
  3264. intended; you should not rely on algorithms that will break under such circumstances.
  3265.  
  3266. See the Strategies document for more information on creatively using 
  3267. this routine.
  3268.  
  3269. .nf
  3270.  
  3271.     pGC->funcs->CopyGC(pGCSrc, mask, pGCDst)
  3272.         GCPtr pGCSrc;
  3273.         Mask mask;
  3274.         GCPtr pGCDst;
  3275.  
  3276. .fi
  3277.  
  3278. This routine is called by DIX 
  3279. when a GC is being copied to another GC.
  3280. This is for situations where dynamically allocated chunks of memory are hanging
  3281. off a GC devPrivates field which need to be transferred to the destination GC.
  3282. .nf
  3283.  
  3284.     pGC->funcs->DestroyGC(pGC)
  3285.         GCPtr pGC;
  3286. .fi
  3287. This routine is called before the GC is destroyed for the
  3288. entity interested in this GC to clean up after itself.
  3289. This routine is responsible for freeing any auxiliary storage allocated.
  3290.  
  3291. .NH 3
  3292. GC Clip Region Routines
  3293. .XS
  3294. GC Clip Region Routines
  3295. .XE
  3296. .LP
  3297. The GC clientClip field requires three procedures to manage it.  These
  3298. procedures are in the GC funcs vector.  The underlying principle is that dix
  3299. knows nothing about the internals of the clipping information, (except when
  3300. it has come from the client), and so calls ddX whenever it needs to copy,
  3301. set, or destroy such information.  It could have been possible for dix not
  3302. to allow ddX to touch the field in the GC, and require it to keep its own
  3303. copy in devPriv, but since clip masks can be very large, this seems like a
  3304. bad idea.  Thus, the server allows ddX to do whatever it wants to the
  3305. clientClip field of the GC, but requires it to do all manipulation itself.
  3306. .nf
  3307.  
  3308.     void pGC->funcs->ChangeClip(pGC, type, pValue, nrects)
  3309.         GCPtr pGC;
  3310.         int type;
  3311.         char *pValue;
  3312.         int nrects;
  3313. .fi
  3314. This routine is called whenever the client changes the client clip region.
  3315. The pGC points to the GC involved, the type tells what form the 
  3316. region has been sent in.
  3317. If type is CT_NONE, then there is no client clip.  If 
  3318. type is CT_UNSORTED, CT_YBANDED or CT_YXBANDED, then pValue pointer to a 
  3319. list of rectangles, nrects long.  If type is CT_REGION, then
  3320. pValue pointer to a RegionRec from the mi region code.  If type
  3321. is CT_PIXMAP pValue is a pointer to a pixmap.  (The defines
  3322. for CT_NONE, etc. are in server/include/gc.h.)
  3323. This routine is responsible for incrementing any necessary reference
  3324. counts (e.g. for a pixmap clip mask) for the new clipmask and 
  3325. freeing anything that used to be in the GC's clipMask field.  
  3326. The lists of rectangles passed in can be freed with Xfree(), the 
  3327. regions can be destroyed with the RegionDestroy field in the screen, 
  3328. and pixmaps can be destroyed by calling the screen's DestroyPixmap 
  3329. function.
  3330. DIX and MI code expect what they pass in to this to be freed
  3331. or otherwise inaccessible, and will never look inside what's
  3332. been put in the GC.  This is a good place to be wary of
  3333. storage leaks.
  3334. .LP
  3335. In the sample server, this routine transforms either the bitmap or 
  3336. the rectangle list into a region, so that future routines will 
  3337. have a more predictable 
  3338. starting point to work from.
  3339. (The validate routine must take this client clip region and merge it
  3340. with other regions to arrive at a composite clip region before any drawing
  3341. is done.)
  3342. .nf
  3343.  
  3344.     void pGC->funcs->DestroyClip(pGC)
  3345.         GCPtr pGC;
  3346. .fi
  3347. This routine is called whenever the client clip region must be destroyed.
  3348. The pGC points to the GC involved.  This call should set the clipType
  3349. field of the GC to CT_NONE.
  3350. In the sample server, the pointer to the client clip region is set to NULL
  3351. by this routine after destroying the region, so that other software
  3352. (including ChangeClip() above) will recognize that there is no client clip region.
  3353. .nf
  3354.     void pGC->funcs->CopyClip(pgcDst, pgcSrc)
  3355.         GCPtr pgcDst, pgcSrc;
  3356. .fi
  3357. This routine makes a copy of the clipMask and clipType from pgcSrc
  3358. into pgcDst.  It is responsible for destroying any previous clipMask
  3359. in pgcDst.  The clip mask in the source can be the same as the
  3360. clip mask in the dst (clients do the strangest things), so care must 
  3361. be taken when destroying things.  This call is required because dix
  3362. does not know how to copy the clip mask from pgcSrc.
  3363.  
  3364. .NH 2
  3365. Drawing Primitives
  3366. .XS
  3367. Drawing Primitives
  3368. .XE
  3369. .LP
  3370. The X protocol (rules for the byte stream that goes between client and server)
  3371. does all graphics using primitive
  3372. operations, which are called Drawing Primitives.
  3373. These include line drawing, area filling, arcs, and text drawing.
  3374. Your implementation must supply 16 routines 
  3375. to perform these on your hardware.
  3376. (The number 16 is arbitrary.)
  3377.  
  3378. More specifically, 16 procedure pointers are in each
  3379. GC op vector.
  3380. At any given time, ALL of them MUST point to a valid procedure that
  3381. attempts to do the operation assigned, although
  3382. the procedure pointers may change and may
  3383. point to different procedures to carry out the same operation.
  3384. A simple server will leave them all pointing to the same 16 routines, while
  3385. a more optimized implementation will switch each from one
  3386. procedure to another, depending upon what is most optimal
  3387. for the current GC and drawable.
  3388.  
  3389. The sample server contains a considerable chunk of code called the
  3390. mi (machine independent)
  3391. routines, which serve as drawing primitive routines.
  3392. Many server implementations will be able to use these as-is,
  3393. because they work for arbitrary depths.
  3394. They make no assumptions about the formats of pixmaps
  3395. and frame buffers, since they call a set of routines
  3396. known as the "Pixblit Routines" (see next section).
  3397. They do assume that the way to draw is
  3398. through these low-level routines that apply pixel values rows at a time.
  3399. If your hardware or firmware gives more performance when
  3400. things are done differently, you will want to take this fact into account
  3401. and rewrite some or all of the drawing primitives to fit your needs.
  3402.  
  3403. .NH 3
  3404. GC Components
  3405. .XS
  3406. GC Components
  3407. .XE
  3408. .LP
  3409. This section describes the fields in the GC that affect each drawing primitive.
  3410. The only primitive that is not affected is GetImage, which does not use a GC
  3411. because its destination is a protocol-style bit image.
  3412. Since each drawing primitive mirrors exactly the X protocol request of the
  3413. same name, you should refer to the X protocol specification document
  3414. for more details.
  3415.  
  3416. ALL of these routines MUST CLIP to the
  3417. appropriate regions in the drawable.
  3418. Since there are many regions to clip to simultaneously, 
  3419. your ValidateGC routine should combine these into a unified 
  3420. clip region to which your drawing routines can quickly refer.
  3421. This is exactly what the cfb and mfb routines supplied with the sample server
  3422. do.
  3423. The mi implementation passes responsibility for clipping while drawing
  3424. down to the Pixblit routines.
  3425.  
  3426. Also, all of them must adhere to the current plane mask.
  3427. The plane mask has one bit for every bit plane in the drawable;
  3428. only planes with 1 bits in the mask are affected by any drawing operation.  
  3429.  
  3430. All functions except for ImageText calls must obey the alu function.
  3431. This is usually Copy, but could be any of the allowable 16 raster-ops.
  3432.  
  3433. All of the functions, except for CopyArea, might use the current
  3434. foreground and background pixel values.
  3435. Each pixel value is 32 bits.
  3436. These correspond to foreground and background colors, but you have
  3437. to run them through the colormap to find out what color the pixel values
  3438. represent.  Do not worry about the color, just apply the pixel value.
  3439.  
  3440. The routines that draw lines (PolyLine, PolySegment, PolyRect, and PolyArc)
  3441. use the line width, line style, cap style, and join style.
  3442. Line width is in pixels.
  3443. The line style specifies whether it is solid or dashed, and what kind of dash.
  3444. The cap style specifies whether Rounded, Butt, etc.
  3445. The join style specifies whether joins between joined lines are Miter, Round or Beveled.
  3446. When lines cross as part of the same polyline, they are assumed to be drawn once.
  3447. (See the X protocol specification for more details.)
  3448.  
  3449. Zero-width lines are NOT meant to be really zero width; this is the client's way
  3450. of telling you that you can optimize line drawing with little regard to
  3451. the end caps and joins.
  3452. They are called "thin" lines and are meant to be one pixel wide.
  3453. These are frequently done in hardware or in a streamlined assembly language
  3454. routine.
  3455.  
  3456. Lines with widths greater than zero, though, must all be drawn with the same
  3457. algorithm, because client software assumes that every jag on every
  3458. line at an angle will come at the same place.
  3459. Two lines that should have
  3460. one pixel in the space between them
  3461. (because of their distance apart and their widths) should have such a one-pixel line 
  3462. of space between them if drawn, regardless of angle.
  3463.  
  3464. The solid area fill routines (FillPolygon, PolyFillRect, PolyFillArc)
  3465. all use the fill rule, which specifies subtle interpretations of
  3466. what points are inside and what are outside of a given polygon.
  3467. The PolyFillArc routine also uses the arc mode, which specifies
  3468. whether to fill pie segments or single-edge slices of an ellipse.
  3469.  
  3470. The line drawing, area fill, and PolyText routines must all
  3471. apply the correct "fill style."
  3472. This can be either a solid foreground color, a transparent stipple,
  3473. an opaque stipple, or a tile.
  3474. Stipples are bitmaps where the 1 bits represent that the foreground color is written,
  3475. and 0 bits represent that either the pixel is left alone (transparent) or that
  3476. the background color is written (opaque).
  3477. A tile is a pixmap of the full depth of the GC that is applied in its full glory to all areas.
  3478. The stipple and tile patterns can be any rectangular size, although some implementations
  3479. will be faster for certain sizes such as 8x8 or 32x32.
  3480. The mi implementation passes this responsibility down to the Pixblit routines.
  3481.  
  3482. See the X protocol document for full details.
  3483. The description of the CreateGC request has a very good, detailed description of these
  3484. attributes.
  3485.  
  3486. .NH 3
  3487. The Primitives
  3488. .XS
  3489. The Primitives
  3490. .XE
  3491. .LP
  3492. The Drawing Primitives are as follows:
  3493.  
  3494. .nf
  3495.  
  3496.     RegionPtr pGC->ops->CopyArea(src, dst, pGC, srcx, srcy, w, h, dstx, dsty)
  3497.         DrawablePtr dst, src;
  3498.         GCPtr pGC;
  3499.         int srcx, srcy, w, h, dstx, dsty;
  3500. .fi
  3501. CopyArea copies a rectangle of pixels from one drawable to another of
  3502. the same depth.  To effect scrolling, this must be able to copy from
  3503. any drawable to itself, overlapped.  No squeezing or stretching is done
  3504. because the source and destination are the same size.  However,
  3505. everything is still clipped to the clip regions of the destination
  3506. drawable.
  3507.  
  3508. If pGC->graphicsExposures is True, any portions of the destination which
  3509. were not valid in the source (either occluded by covering windows, or
  3510. outside the bounds of the drawable) should be collected together and
  3511. returned as a region (if this resultant region is empty, NULL can be
  3512. returned instead).  Furthermore, the invalid bits of the source are
  3513. not copied to the destination and (when the destination is a window)
  3514. are filled with the background tile.  The sample routine
  3515. miHandleExposures generates the appropriate return value and fills the
  3516. invalid area using pScreen->PaintWindowBackground.
  3517.  
  3518. For instance, imagine a window that is partially obscured by other
  3519. windows in front of it.  As text is scrolled on your window, the pixels
  3520. that are scrolled out from under obscuring windows will not be
  3521. available on the screen to copy to the right places, and so an exposure
  3522. event must be sent for the client to correctly repaint them.  Of
  3523. course, if you implement some sort of backing store, you could do this
  3524. without resorting to exposure events.
  3525.  
  3526. An example implementation is mfbCopyArea() in server/ddx/mfb/mfbbitblt.c.
  3527. .nf
  3528.  
  3529.     RegionPtr pGC->ops->CopyPlane(src, dst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
  3530.         DrawablePtr dst, src;
  3531.         GCPtr pGC;
  3532.         int srcx, srcy, w, h, dstx, dsty;
  3533.         long plane;
  3534. .fi
  3535. CopyPlane must copy one plane of a rectangle from the source
  3536. drawable onto the destination drawable.
  3537. Because this routine only copies one bit out of each pixel,
  3538. it can copy between drawables of different depths.
  3539. This is the only way of copying between drawables of different
  3540. depths, except for copying bitmaps to pixmaps and applying foreground
  3541. and background colors to it.
  3542. All other conditions of CopyArea apply to CopyPlane too.
  3543.  
  3544. An example implementation is mfbCopyPlane() in 
  3545. server/ddx/mfb/mfbbitblt.c.
  3546. .nf
  3547.  
  3548.     pGC->ops->PolyPoint(dst, pGC, mode, n, pPoint)
  3549.         DrawablePtr dst;
  3550.         GCPtr pGC;
  3551.         int mode;
  3552.         int n;
  3553.         POINT *pPoint;
  3554. .fi
  3555. PolyPoint draws a set of one-pixel dots (foreground color)
  3556. at the locations given in the array.
  3557. mode is one of the defined constants Origin (absolute coordinates) or Previous
  3558. (each coordinate is relative to the last).
  3559. Note that this does not use the background color or any tiles or stipples.
  3560.  
  3561. Example implementations are mfbPolyPoint() in server/ddx/mfb/mfbpolypnt.c and 
  3562. miPolyPoint in server/ddx/mi/mipolypnt.c.
  3563. .nf
  3564.  
  3565.     pGC->ops->Polylines(dst, pGC, mode, n, pPoint)
  3566.         DrawablePtr dst;
  3567.         GCPtr pGC;
  3568.         int mode;
  3569.         int n;
  3570.         POINT *pPoint;
  3571. .fi
  3572. Similar to PolyPoint, Polylines draws lines between the locations given in the array.
  3573. Zero-width lines are NOT meant to be really zero width; this is the client's way of 
  3574. telling you that you can maximally optimize line drawing with little regard to
  3575. the end caps and joins.
  3576. mode is one of the defined constants Previous or Origin, depending upon
  3577. whether the points are each relative to the last or are absolute.
  3578.  
  3579. Example implementations are miWideLine() and miWideDash() in
  3580. ddx/mi/miwideline.c and miZeroLine() in ddx/mi/mizerline.c.
  3581. .nf
  3582.  
  3583.     pGC->ops->PolySegment(dst, pGC, n, pPoint)
  3584.         DrawablePtr dst;
  3585.         GCPtr pGC;
  3586.         int n;
  3587.         POINT *pPoint;
  3588. .fi
  3589. PolySegments draws unconnected
  3590. lines between pairs of points in the array; the array must be of
  3591. even size; no interconnecting lines are drawn.
  3592.  
  3593. An example implementation is miPolySegment() in mipolyseg.c.
  3594. .nf
  3595.  
  3596.     pGC->ops->PolyRectangle(dst, pGC, n, pRect)
  3597.         DrawablePtr dst;
  3598.         GCPtr pGC;
  3599.         int n;
  3600.         RECT *pRect;
  3601. .fi
  3602. PolyRectangle draws outlines of rectangles for each rectangle in the array.
  3603.  
  3604. An example implementation is miPolyRectangle() in server/ddx/mi/mipolyrect.c.
  3605. .nf
  3606.  
  3607.     pGC->ops->PolyArc(dst, pGC, n, pArc)
  3608.         DrawablePtr dst;
  3609.         GCPtr pGC;
  3610.         int n;
  3611.         xArc*pArc;
  3612. .fi
  3613. PolyArc draws connected conic arcs according to the descriptions in the array.
  3614. See the protocol specification for more details.
  3615.  
  3616. Example implementations are miZeroPolyArc in server/ddx/mi/mizerarc. and
  3617. miPolyArc() in server/ddx/mi/miarc.c.
  3618. .nf
  3619.  
  3620.     pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pPoint)
  3621.         DrawablePtr dst;
  3622.         GCPtr pGC;
  3623.         int shape;
  3624.         int mode;
  3625.         int count;
  3626.         POINT *pPoint;
  3627. .fi
  3628. FillPolygon fills a polygon specified by the points in the array
  3629. with the appropriate fill style.
  3630. If necessary, an extra border line is assumed between the starting and ending lines.
  3631. The shape can be used as a hint
  3632. to optimize filling; it indicates whether it is convex (all interior angles
  3633. less than 180), nonconvex (some interior angles greater than 180 but
  3634. border does not cross itself), or complex (border crosses itself).
  3635. You can choose appropriate algorithms or hardware based upon mode.
  3636. mode is one of the defined constants Previous or Origin, depending upon
  3637. whether the points are each relative to the last or are absolute.
  3638.  
  3639. An example implementation is miFillPolygon() in server/ddx/mi/mipoly.c.
  3640. .nf
  3641.  
  3642.     pGC->ops->PolyFillRect(dst, pGC, n, pRect)
  3643.         DrawablePtr dst;
  3644.         GCPtr pGC;
  3645.         int n;
  3646.         RECT *pRect;
  3647. .fi
  3648. PolyFillRect fills multiple rectangles.
  3649.  
  3650. Example implementations are mfbPolyFillRect() in server/ddx/mfb/mfbfillrct.c and 
  3651. miPolyFillRect() in server/ddx/mi/mifillrct.c.
  3652. .nf
  3653.  
  3654.     pGC->ops->PolyFillArc(dst, pGC, n, pArc)
  3655.         DrawablePtr dst;
  3656.         GCPtr pGC;
  3657.         int n;
  3658.         ARC *pArc;
  3659. .fi
  3660. PolyFillArc fills a shape for each arc in the
  3661. list that is bounded by the arc and one or two
  3662. line segments with the current fill style.
  3663.  
  3664. An example implementation is miPolyFillArc() in server/ddx/mi/mifillarc.c.
  3665. .nf
  3666.  
  3667.     pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBinImage)
  3668.         DrawablePtr dst;
  3669.         GCPtr pGC;
  3670.         int x, y, w, h;
  3671.         int format;
  3672.         char *pBinImage;
  3673. .fi
  3674. PutImage copies a
  3675. pixmap image 
  3676. into the drawable.
  3677. The pixmap image must be in X protocol format (either Bitmap,
  3678. XYPixmap, or ZPixmap), and format tells the format.
  3679. (See the X protocol specification for details on these formats).
  3680. You must be able to accept all three formats, because the client
  3681. gets to decide which format to send.
  3682. Either the drawable and the pixmap image have the same depth, or the source 
  3683. pixmap image must be a Bitmap.
  3684. If a Bitmap, the foreground and background colors will be applied 
  3685. to the destination.
  3686.  
  3687. An example implementation is miPutImage() in server/ddx/mfb/mibitblt.c.
  3688. .nf
  3689.  
  3690.     pScreen->GetImage(src, x, y, w, h, format, planeMask, pBinImage)
  3691.          DrawablePtr src;
  3692.          int x, y, w, h;
  3693.          long format;
  3694.          pointer pBinImage;
  3695. .fi
  3696. GetImage copies the bits from the source drawable into
  3697. the destination pointer.  The bits are written into the buffer
  3698. according to the server-defined pixmap padding rules.
  3699. pBinImage is guaranteed to be big enough to hold all
  3700. the bits that must be written.
  3701.  
  3702. This routine does not correspond exactly to the X protocol
  3703. GetImage request, since DIX has to break the reply up into
  3704. buffers of a size requested by the transport layer.
  3705. If format is ZPixmap, the bits are written in the ZFormat
  3706. for the depth of the drawable; if there is a 0 bit in the
  3707. planeMask for a particular plane, all pixels must have the bit
  3708. in that plane equal to 0.
  3709. If format is XYPixmap, planemask is guaranteed to have a single
  3710. bit set; the bits should be written in Bitmap format, which
  3711. is the format for a single plane of an XYPixmap.
  3712.  
  3713. An example implementation is miGetImage() in server/ddx/mi/mibitblt.c.
  3714. .nf
  3715.  
  3716.     pGC->ops->ImageText8(pDraw, pGC, x, y, count, chars)
  3717.         DrawablePtr pDraw;
  3718.         GCPtr pGC;
  3719.         int x, y;
  3720.         int count;
  3721.         char *chars;
  3722. .fi
  3723. ImageText8 draws text.
  3724. The text is drawn in the foreground color;
  3725. the background color fills the remainder of the character rectangles.
  3726. The coordinates specify the baseline and start of the text.
  3727.  
  3728. An example implementation is miImageText8() in server/ddx/mi/mipolytext.c.
  3729. .nf
  3730.  
  3731.     pGC->ops->PolyText8(pDraw, pGC, x, y, count, chars)
  3732.         DrawablePtr pDraw;
  3733.         GCPtr pGC;
  3734.         int x, y;
  3735.         int count;
  3736.         char *chars;
  3737. .fi
  3738. PolyText8 works like ImageText8, except it draws with
  3739. the current fill style for special effects such as 
  3740. shaded text.
  3741. See the X protocol specification for more details.
  3742.  
  3743. An example implementation is miPolyText8() in server/ddx/mi/mipolytext.c.
  3744. .nf
  3745.  
  3746.     pGC->ops->PolyText16(pDraw, pGC, x, y, count, chars)
  3747.         DrawablePtr pDraw;
  3748.         GCPtr pGC;
  3749.         int x, y;
  3750.         int count;
  3751.         unsigned short *chars;
  3752.  
  3753.     pGC->ops->ImageText16(pDraw, pGC, x, y, count, chars)
  3754.         DrawablePtr pDraw;
  3755.         GCPtr pGC;
  3756.         int x, y;
  3757.         int count;
  3758.         unsigned short *chars;
  3759. .fi
  3760. These two routines are the same as the "8" versions,
  3761. except that they are for 16-bit character codes (useful 
  3762. for oriental writing systems).
  3763.  
  3764. The primary difference is in the way the character information is looked up.
  3765. The 8-bit and the 16-bit versions obviously have different kinds of character
  3766. values to look up; 
  3767. the main goal of the lookup is to provide a pointer to the CharInfo structs
  3768. for the characters to draw and to pass these pointers to the Glyph routines.
  3769. Given a CharInfo struct, lower-level software can draw the glyph desired
  3770. with little concern for other characteristics of the font.
  3771.  
  3772. 16-bit character fonts have 
  3773. a row-and-column scheme, where the 2bytes of the 
  3774. character code constitute the row and column in a square matrix of CharInfo
  3775. structs.
  3776. Each font has row and column minimum and maximum values; the CharInfo
  3777. structures form a two-dimensional matrix.
  3778.  
  3779. Example implementations are miPolyText16() and 
  3780. miImageText16() in server/ddx/mi/mipolytext.c.
  3781.  
  3782. See the X protocol specification for more details on these graphic operations.
  3783. .LP
  3784. There is a hook in the GC ops, called LineHelper, that used to be used in the
  3785. sample implementation by the code for wide lines.  It no longer servers any
  3786. purpose
  3787.  
  3788. .NH 2
  3789. Pixblit Procedures
  3790. .XS
  3791. Pixblit Procedures
  3792. .XE
  3793. .LP
  3794. The Drawing Primitive functions must be defined for your server.
  3795. One possible way to do this is to use the mi routines from the sample server.
  3796. If you choose to use the mi routines (even part of them!) you must implement
  3797. these Pixblit routines.
  3798. These routines read and write pixel values 
  3799. and deal directly with the image data.
  3800.  
  3801. The Pixblit routines for the sample server are part of the
  3802. "mfb" routines (for Monochrome Frame Buffer), and "cfb" routines
  3803. (for Color Frame Buffer).
  3804. As with the mi routines, the mfb and cfb routines
  3805. are portable but are not as portable
  3806. as the mi routines.
  3807.  
  3808. The mfb routines only work for monochrome frame
  3809. buffers, the simplest type of display.
  3810. Furthermore, they only work for screens that organize their
  3811. bits in rows of pixels on the screen.
  3812. (See the Strategies document for more details on porting mfb.)
  3813. The cfb routines work for packed-pixel displays from 2 to 32 bits
  3814. in depth, although they have a bit of code which has been tuned
  3815. to run on 8-bit (1 pixel per byte) displays.
  3816.  
  3817. In other words, if you have a "normal" frame buffer type display, you can probably
  3818. use either the mfb or cfb code, and the mi code.
  3819. If you have a stranger hardware, you will have to supply
  3820. your own Pixblit routines, but you can use the mi routines
  3821. on top of them.
  3822. If you have better ways of doing some of the Drawing Primitive functions,
  3823. then you may want to supply some of your own Drawing Primitive routines.
  3824. (Even people who write their own
  3825. Drawing Primitives save at least some of the mi code for certain 
  3826. special cases that their hardware or library or fancy algorithm does not handle.)
  3827.  
  3828. The client, DIX, and the
  3829. machine-independent routines do not carry the final responsibility of clipping.
  3830. They all depend
  3831. upon the Pixblit routines to do their clipping for them.
  3832. The rule is, if you touch the frame buffer, you clip.
  3833.  
  3834. (The higher level routines may decide to clip at a high level, 
  3835. but this is only for increased performance and cannot substitute for 
  3836. bottom-level clipping.
  3837. For instance, the mi routines, DIX, or the client may decide to 
  3838. check all character strings to be drawn
  3839. and chop off all characters that would
  3840. not be displayed.  
  3841. If so, it must retain the character on the edge that is partly displayed
  3842. so that the Pixblit routines can clip off precisely at the right place.)
  3843.  
  3844. To make this easier, all of the reasons to clip 
  3845. can be combined into one region in your ValidateGC procedure.
  3846. You 
  3847. take this composite clip region with you into the Pixblit routines.
  3848. (The sample server does this.)
  3849.  
  3850. Also, FillSpans() has to apply tile and stipple patterns.
  3851. The patterns are all aligned to the window origin so that 
  3852. when two people write patches that are contiguous, they will merge 
  3853. nicely.
  3854. (Really, they are aligned to the patOrg point in the GC.
  3855. This defaults to (0, 0) but can be set by the client to anything.)
  3856.  
  3857. However, the mi routines can
  3858. translate (relocate) the points  from window-relative to screen-relative
  3859. if desired.
  3860. If you set the miTranslate field in the GC (set it in the CreateGC or
  3861. ValidateGC routine),
  3862. then the mi output routines will translate all coordinates.
  3863. If it is false, then the coordinates will be passed window-relative.
  3864. Screens with no hardware translation will probably set miTranslate
  3865. to TRUE, so that geometry (e.g. polygons, rectangles) can be
  3866. translated, rather than having the resulting list of scanlines
  3867. translated; this is good because the list vertices in a drawing request
  3868. will generally be much smaller than the list of scanlines it produces.
  3869. Similarly, hardware that does translation can set miTranslate to
  3870. FALSE, and avoid the extra addition per vertex, which can be (but is
  3871. not always) important for getting the highest possible performance.
  3872. (Contrast the behavior of GetSpans, which is not expected to be 
  3873. called as often, and so has different constraints.)
  3874. The miTranslate field is settable in each GC, if , for example,
  3875. you are mixing several kinds of destinations (offscreen pixmaps,
  3876. main memory pixmaps, backing store, and windows), all of which have
  3877. different requirements, on one screen.
  3878.  
  3879. As with other drawing routines, there are fields in the GC to direct
  3880. higher code to the correct routine to execute for each function.
  3881. In this way, you can optimize for special cases, for example, drawing solids
  3882. versus drawing stipples.
  3883.  
  3884. The Pixblit routines are broken up into three sets.
  3885. The Span routines
  3886. simply fill in rows of pixels.
  3887. The Glyph routines fill in character glyphs.
  3888. The PushPixels routine is a three-input bitblt for
  3889. more sophisticated image creation.
  3890.  
  3891. It turns out that the Glyph and PushPixels routines actually have a
  3892. machine-independent implementation that depends upon the Span routines.
  3893. If you are really pressed for time, you can use these 
  3894. versions, although they are quite slow.
  3895.  
  3896. .NH 3
  3897. Span Routines
  3898. .XS
  3899. Span Routines
  3900. .XE
  3901. .LP
  3902. For these routines, all graphic operations have been reduced to "spans."
  3903. A span is a horizontal row of pixels.
  3904. If you can design these routines which write into and read from
  3905. rows of pixels at a time, you can use the mi routines.
  3906.  
  3907. Each routine takes
  3908. a destination drawable to draw into, a GC to use while drawing,
  3909. the number of spans to do, and two pointers to arrays that indicate the list
  3910. of starting points and the list of widths of spans.
  3911. .nf
  3912.  
  3913.     pGC->ops->FillSpans(dst, pGC, nSpans, pPoints, pWidths, sorted)
  3914.         DrawablePtr dst;
  3915.         GCPtr pGC;
  3916.         int nSpans;
  3917.         POINT *pPoints;
  3918.         int *pWidths;
  3919.         int sorted;
  3920. .fi
  3921. FillSpans should fill horizontal rows of pixels with
  3922. the appropriate patterns, stipples, etc.,
  3923. based on the values in the GC.
  3924. The starting points are in the array at pPoints; the widths are in pWidths.
  3925. If sorted is true, the scan lines are in increasing y order, in which case
  3926. you may be able to make assumptions and optimizations.
  3927. .LP
  3928. GC components: alu, clipOrg, clientClip, and fillStyle.
  3929. .LP
  3930. GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
  3931. (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
  3932. and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).
  3933.  
  3934. .nf
  3935.  
  3936.     void pGC->ops->SetSpans(pDrawable, pGC, pSrc, ppt, pWidths, nSpans, sorted)
  3937.         DrawablePtr pDrawable;
  3938.         GCPtr pGC;
  3939.         unsigned int *pSrc;
  3940.         POINT *pPoints;
  3941.         int *pWidths;
  3942.         int nSpans;
  3943.         int sorted;
  3944. .fi
  3945. For each span, this routine should copy pWidths bits from pSrc to
  3946. pDrawable at pPoints using the raster-op from the GC.
  3947. If sorted is true, the scan lines are in increasing y order.
  3948. The pixels in pSrc are
  3949. padded according to the screen's padding rules.
  3950. These
  3951. can be used to support
  3952. interesting extension libraries, for example, shaded primitives.   It does not
  3953. use the tile and stipple.
  3954. .LP
  3955. GC components: alu, clipOrg, and clientClip
  3956. .LP
  3957.  
  3958. The above functions are expected to handle all modifiers in the current
  3959. GC.  Therefore, it is expedient to have
  3960. different routines to quickly handle common special cases
  3961. and reload the procedure pointers
  3962. at validate time, as with the other output functions.
  3963. .nf
  3964.  
  3965.     unsigned int *pScreen->GetSpans(pDrawable, wMax, pPoints, pWidths, nSpans)
  3966.         DrawablePtr pDrawable;
  3967.         int wMax;
  3968.         POINT *pPoints;
  3969.         int *pWidths;
  3970.         int nSpans;
  3971. .fi
  3972. For each span, GetSpans gets bits from the drawable starting at pPoints
  3973. and continuing for pWidths bits.
  3974. Each scanline returned will be server-scanline padded.
  3975. The routine can return NULL if memory cannot be allocated to hold the
  3976. result.
  3977.  
  3978. GetSpans never translates -- for a window, the coordinates are
  3979. already screen-relative.
  3980. Consider the case of hardware that doesn't do translation:
  3981. the mi code that calls ddX will translate each shape (rectangle,
  3982. polygon,. etc.) before scan-converting it, which requires many
  3983. fewer additions that having GetSpans translate each span does.
  3984. Conversely, consider hardware that does translate: it can set its
  3985. translation point to (0, 0) and get each span, and the only
  3986. penalty is the small number of additions required to translate each
  3987. shape being scan-converted by the calling code.
  3988. Contrast the behavior of FillSpans and SetSpans (discussed
  3989. above under miTranslate), which are expected to be used more
  3990. often.
  3991.  
  3992. Thus, the penalty to hardware that does hardware translation is
  3993. negligible, and code that wants to call GetSpans() is greatly
  3994. simplified, both for extensions and the machine-independent
  3995. core implementation.
  3996.  
  3997. .NH 4
  3998. Glyph Routines
  3999. .XS
  4000. Glyph Routines
  4001. .XE
  4002. .LP
  4003. The Glyph routines draw individual character glyphs for text drawing requests.
  4004.  
  4005. You have a choice in implementing these routines.
  4006. You can use the mi versions;
  4007. they depend ultimately upon the span routines.
  4008. Although text drawing will work, it will be very slow.
  4009.  
  4010. .nf
  4011.  
  4012.     void pGC->ops->PolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  4013.         DrawablePtr pDrawable;
  4014.         GCPtr pGC;
  4015.         int x , y;
  4016.         unsigned int nglyph;
  4017.         CharInfoRec **ppci;        /* array of character info */
  4018.         char *pglyphBase;        /* unused in R5 */
  4019.  
  4020. .fi
  4021. .LP
  4022. GC components: alu, clipOrg, clientClip, font, and fillStyle.
  4023. .LP
  4024. GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
  4025. (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
  4026. and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).
  4027. .nf
  4028.  
  4029.     void pGC->ops->ImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  4030.         DrawablePtr pDrawable;
  4031.         GCPtr pGC;
  4032.         int x , y;
  4033.         unsigned int nglyph;
  4034.         CharInfoRec **ppci;    /* array of character info */
  4035.         char *pglyphBase;    /* unused in R5 */
  4036.  
  4037. .fi
  4038. .LP
  4039. GC components: clipOrg, clientClip, font, fgPixel, bgPixel
  4040. .LP
  4041. These routines must copy
  4042. the glyphs defined by the bitmaps in pglyphBase and the font metrics in
  4043. ppci to the DrawablePtr, pDrawable.
  4044. The poly routine follows all fill, stipple, and tile rules.
  4045. The image routine simply blasts the glyph
  4046. onto the glyph's rectangle, in foreground
  4047. and background colors.
  4048.  
  4049. More precisely, the Image routine fills the character rectangle
  4050. with the background color, and then the glyph is applied in the foreground color.
  4051. The glyph can extend outside of the character rectangle.
  4052. ImageGlyph() is used for terminal emulators and informal
  4053. text purposes such as button labels.
  4054.  
  4055. The exact specification for the Poly routine is that the glyph is
  4056. painted with the current fill style.
  4057. The character rectangle is irrelevant for this operation.
  4058. PolyText, at a higher level, includes facilities for font changes within strings
  4059. and such; it is to be used for WYSIWYG word processing and similar systems.
  4060.  
  4061. Both of these routines must clip themselves to the overall clipping region.
  4062.  
  4063. Example implementations in mi are miPolyGlyphBlt() and 
  4064. miImageGlyphBlt() in server/ddx/mi/miglblt.c.
  4065.  
  4066. .NH 4
  4067. PushPixels routine
  4068. .XS
  4069. PushPixels routine
  4070. .XE
  4071. .LP
  4072. The PushPixels routine writes the current fill style onto the drawable
  4073. in a certain shape defined by a bitmap.  PushPixels is equivalent to
  4074. using a second stipple.  You can thing of it as pushing the fillStyle
  4075. through a stencil.  PushPixels is not used by any of the mi rendering code,
  4076. but is used by the mi software cursor code.
  4077. .LP
  4078. .nf
  4079. .ta 1i 3i
  4080.     Suppose the stencil is:    00111100
  4081.     and the stipple is:    10101010
  4082.     PushPixels result:    00101000
  4083. .fi
  4084. .LP
  4085. You have a choice in implementing this routine.
  4086. You can use the mi version which depends ultimately upon FillSpans().
  4087. Although it will work, it will be slow.
  4088. .LP
  4089. .nf
  4090.  
  4091.     void pGC->ops->PushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  4092.         GC *pGC;
  4093.         PixmapPtr pBitMap;
  4094.         DrawablePtr pDrawable;
  4095.         int dx, dy, xOrg, yOrg;
  4096. .fi
  4097. .LP
  4098. GC components: alu, clipOrg, clientClip, and fillStyle.
  4099. .LP
  4100. GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
  4101. (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
  4102. and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).
  4103.  
  4104. PushPixels applys the foreground color, tile, or stipple from 
  4105. the pGC through a stencil
  4106. onto pDrawable.  
  4107. pBitMap points to a stencil (of which we use an area dx
  4108. wide by dy high), which is oriented over the drawable at xOrg, yOrg.  
  4109. Where there is a 1 bit
  4110. in the bitmap, the destination is set according to the current
  4111. fill style.  
  4112. Where there is a 0 bit
  4113. in the bitmap, the destination is left the way it is.
  4114.  
  4115. This routine must clip to the overall clipping region.
  4116.  
  4117. An Example implementation is miPushPixels() in server/ddx/mi/mipushpxl.c.
  4118.  
  4119. .NH 2
  4120. Shutdown Procedures
  4121. .XS
  4122. Shutdown Procedures
  4123. .XE
  4124. .LP
  4125. .nf
  4126.     void AbortDDX()
  4127.     void ddxGiveUp()
  4128. .fi
  4129. .LP
  4130. Some hardware may require special work to be done before the server
  4131. exits so that it is not left in an intermediate state.
  4132. As explained in the OS layer, FatalError() will call AbortDDX() just
  4133. before terminating the server.  In addition, ddxGiveUp() will be
  4134. called just before terminating the server on a "clean" death,
  4135. right after calling KillServerResources().
  4136. What AbortDDX() and ddxGiveUP do is left unspecified,
  4137. only that stubs must exist in the ddx layer.
  4138. It is up to local implementors as to what they should accomplish before
  4139. termination.
  4140.  
  4141. .NH 3
  4142. Command Line Procedures
  4143. .XS
  4144. Command Line Procedures
  4145. .XE
  4146. .LP
  4147. .nf
  4148.     int ddxProcessArgument(argc, argv, i)
  4149.         int argc;
  4150.         char *argv[];
  4151.         int i;
  4152.  
  4153.     void
  4154.     ddxUseMsg()
  4155. .fi
  4156. .LP
  4157. You should write these routines to deal with device-dependent command line
  4158. arguments.  The routine ddxProcessArgument() is called with the command line,
  4159. and the current index into argv; you should return zero if the argument
  4160. is not a device-dependent one, and otherwise return a count of the number
  4161. of elements of argv that are part of this one argument.  For a typical
  4162. option (e.g., "-realtime"), you should return the value one.  This
  4163. routine gets called before checks are made against device-independent
  4164. arguments, so it is possible to peek at all arguments or to override
  4165. device-independent argument processing.  You can document the
  4166. device-dependent arguments in ddxUseMsg(), which will be
  4167. called from UseMsg() after printing out the device-independent arguments.
  4168.  
  4169. .bp
  4170. .NH 2
  4171. Wrappers and devPrivates
  4172. .XS
  4173. Wrappers and devPrivates
  4174. .XE
  4175. .LP
  4176. Two new extensibility concepts have been developed for release 4, Wrappers
  4177. and devPrivates.  These replace the R3 GCInterest queues, which were not a
  4178. general enough mechanism for many extensions and only provided hooks into a
  4179. single data structure.
  4180. .NH 3
  4181. devPrivates
  4182. .XS
  4183. devPrivates
  4184. .XE
  4185. .LP
  4186. devPrivates are arrays of values attached to various data structures
  4187. (Screens, GCs and Windows currently).  These arrays are sized dynamically at
  4188. server startup (and reset) time as various modules allocate portions of
  4189. them.  They can be used for any purpose; each array entry is actually a
  4190. union, DevUnion, of common useful types (pointer, long and unsigned long).
  4191. devPrivates must be allocated on startup and whenever the server resets.  To
  4192. make this easier, the global variable "serverGeneration" is incremented each
  4193. time devPrivates should be allocated, but before the initialization process
  4194. begins, typical usage would be:
  4195. .nf
  4196. static int privateGeneration = 0;
  4197.  
  4198.     if (privateGeneration != serverGeneration)
  4199.     {
  4200.         allocate devPrivates here.
  4201.  
  4202.         privateGeneration = serverGeneration;
  4203.     }
  4204. .fi
  4205. .NH 4
  4206. Screen devPrivates
  4207. .XS
  4208. Screen devPrivates
  4209. .XE
  4210. .LP
  4211. An index into every screen devPrivates array is allocated with
  4212. .nf
  4213.     int AllocateScreenPrivateIndex()
  4214. .fi
  4215. This call can occur at any time, each existing devPrivates array is resized
  4216. to accommodate the new entry.  This routine returns -1 indicating an
  4217. allocation failure.  Otherwise, the return value can be used to index the
  4218. array of devPrivates on any screen:
  4219. .nf
  4220.     private = (PrivatePointer) pScreen->devPrivates[screenPrivateIndex].ptr;
  4221. .fi
  4222. The pointer in each screen is not initialized by
  4223. AllocateScreenPrivateIndex().
  4224. .NH 4
  4225. Window devPrivates
  4226. .XS
  4227. Window devPrivates
  4228. .XE
  4229. .LP
  4230. An index into every window devPrivates array is allocated with
  4231. .nf
  4232.     int AllocateWindowPrivateIndex ()
  4233. .fi
  4234. AllocateWindowPrivateIndex() never returns an error.  This call must be
  4235. associated with a call which causes a chunk of memory to be automatically
  4236. allocated and attached to the devPrivate entry on every screen which the
  4237. module will need to use the index:
  4238. .nf
  4239.     Bool AllocateWindowPrivate (pScreen, index, amount)
  4240.         ScreenPtr pScreen;
  4241.         int index;
  4242.         unsigned amount;
  4243. .fi
  4244. If this space is not always needed for every object, use 0 as the amount.
  4245. In this case, the pointer field of the entry in the devPrivates array is
  4246. initialized to NULL.  This call exists so that DIX may preallocate all of
  4247. the space required for an object with one call; this reduces memory
  4248. fragmentation considerably.  AllocateWindowPrivate returns FALSE on
  4249. allocation failure.  Both of these calls must occur before any window
  4250. structures are allocated; the server is careful to avoid window creation
  4251. until all modules are initialized, but do not call this after
  4252. initialization.  A typical allocation sequence for WindowPrivates would be:
  4253. .nf
  4254.     privateInitialize (pScreen)
  4255.         ScreenPtr pScreen;
  4256.     {
  4257.         if (privateGeneration != serverGeneration)
  4258.         {
  4259.         windowPrivateIndex = AllocateWindowPrivateIndex();
  4260.         privateGeneration = serverGeneration;
  4261.         }
  4262.         
  4263.         return (AllocateWindowPrivate(pScreen, windowPrivateIndex,
  4264.                       sizeof(windowPrivateStructure)));
  4265.     }
  4266. .fi
  4267. .NH
  4268. GC devPrivates
  4269. .XS
  4270. GC devPrivates
  4271. .XE
  4272. .LP
  4273. The calls for GC's mirror the Window calls exactly; they have the same
  4274. requirements and limitations:
  4275. .nf
  4276.     int AllocateGCPrivateIndex ()
  4277.  
  4278.     Bool AllocateGCPrivate (pScreen, index, amount)
  4279.         ScreenPtr pScreen;
  4280.         int index;
  4281.         unsigned amount;
  4282. .fi
  4283. .NH 3
  4284. Wrappers
  4285. .XS
  4286. Wrappers
  4287. .XE
  4288. .LP
  4289. Wrappers are not a body of code, nor an interface spec.  They are, instead,
  4290. a technique for hooking a new module into an existing calling sequence.
  4291. There are limitations on other portions of the server implementation which
  4292. make using wrappers possible; limits on when specific fields of data
  4293. structures may be modified.  They are intended as a replacement for
  4294. GCInterest queues, which were not general enough to support existing
  4295. modules; in particular software cursors and backing store both needed more
  4296. control over the activity.  The general mechanism for using wrappers is:
  4297. .nf
  4298. privateWrapperFunction (object, ...)
  4299.     ObjectPtr    object;
  4300. {
  4301.     pre-wrapped-function-stuff ...
  4302.  
  4303.     object->functionVector = (void *) object->devPrivates[privateIndex].ptr;
  4304.     (*object->functionVector) (object, ...);
  4305.     /*
  4306.      * this next line is occasionally required by the rules governing
  4307.      * wrapper functions.  Always using it will not cause problems.
  4308.      * Not using it when necessary can cause severe troubles.
  4309.      */
  4310.     object->devPrivates[privateIndex].ptr = (pointer) object->functionVector;
  4311.     object->functionVector = privateWrapperFunction;
  4312.  
  4313.     post-wrapped-function-stuff ...
  4314. }
  4315.  
  4316. privateInitialize (object)
  4317.     ObjectPtr    object;
  4318. {
  4319.     object->devPrivates[privateIndex].ptr = (pointer) object->functionVector;
  4320.     object->functionVector = privateWrapperFunction;
  4321. }
  4322. .fi
  4323. Thus the privateWrapperFunction provides hooks for performing work both
  4324. before and after the wrapped function has been called; the process of
  4325. resetting the functionVector is called "unwrapping" while the process of
  4326. fetching the wrapped function and replacing it with the wrapping function
  4327. is called "wrapping".  It should be clear that GCInterest queues could
  4328. be emulated using wrappers.  In general, any function vectors contained in
  4329. objects can be wrapped, but only vectors in GCs and Screens have been tested.
  4330. .LP
  4331. Wrapping screen functions is quite easy; each vector is individually
  4332. wrapped.  Screen functions are not supposed to change after initialization,
  4333. so rewrapping is technically not necessary, but causes no problems.
  4334. .LP
  4335. Wrapping GC functions is a bit more complicated.  GC's have two sets of
  4336. function vectors, one hanging from gc->ops and the other from gc->funcs.
  4337. Wrappers should modify only those values, not the internal values as they
  4338. may be shared by more than one GC (and, in the case of funcs, are probably
  4339. shared by all gcs).  To wrap the ops, wrap the funcs and, in each func
  4340. wrapper, unwrap the ops and funcs, call down, and re-wrap.  In each op
  4341. wrapper, unwrap both the funcs and ops, call down and rewrap afterwards.  The
  4342. rule is:  if you wrap funcs+ops, you must always unwrap both before down
  4343. calling.  If you wrap ops, you must always pull the ops value out of the GC
  4344. in the func wrapper and save it.  If you wrap funcs, you needn't pull the
  4345. funcs value out of the GC to rewrap as the func values are required to be
  4346. constant.  In this way, the wrapped validation routine can change the op
  4347. vector and not have it lost when your wrapper routine rewraps the GC.  This
  4348. occurs when the wrapped op revalidates the GC with new entries (many mi
  4349. routines do this for opaque stipples or double dashes).  The corollary to
  4350. this rule is:  Never change the func vector after CreateGC.
  4351. .NH 2
  4352. Scheduling Client Activity
  4353. .XS
  4354. Scheduling Client Activity
  4355. .XE
  4356. .LP
  4357. With the addition of support for the X Font Server Protocol, the X server
  4358. now has the ability to schedule clients much like an operating system would,
  4359. suspending and restarting them without regard for the state of their input
  4360. buffers.  This functionality allows the X server to suspend one client and
  4361. continue processing requests from other clients while waiting for a
  4362. long-term network activity (like loading a font) before continuing with the
  4363. first client.
  4364. .NH 3
  4365. Work Queue
  4366. .XS
  4367. Work Queue
  4368. .XE
  4369. .LP
  4370. To queue work for execution when all clients are in a stable state (i.e.
  4371. just before calling select() in WaitForSomething), call:
  4372. .nf
  4373.     Bool QueueWorkProc(function,client,closure)
  4374.         Bool        (*function)();
  4375.         ClientPtr    client;
  4376.         pointer        closure;
  4377. .fi
  4378. .LP
  4379. When the server is about to suspend itself, the given function will be
  4380. executed:
  4381. .nf
  4382.     (*function) (client, closure)
  4383. .fi
  4384. .LP
  4385. Neither client nor closure are actually used inside the work queue routines.
  4386. .NH 3
  4387. Client Suspension
  4388. .XS
  4389. Client Suspension
  4390. .XE
  4391. .LP
  4392. Three functions support "process control" for X clients:
  4393. .nf
  4394.     Bool ClientSleep (client, function, closure)
  4395.         ClientPtr    client;
  4396.         Bool        (*function)();
  4397.         pointer        closure;
  4398. .fi
  4399. .LP
  4400. This suspends the current client (the calling routine is responsible for
  4401. making its way back to Dispatch()).  No more X requests will be processed
  4402. for this client until ClientWakeup is called.
  4403. .nf
  4404.     Bool ClientSignal (client)
  4405.         ClientPtr    client;
  4406. .fi
  4407. .LP
  4408. This function causes a call to the (*function) parameter passed to
  4409. ClientSleep to be queued on the work queue.  This does not automatically
  4410. "wakeup" the client, but the function called is free to do so by calling:
  4411. .nf
  4412.     ClientWakeup (client)
  4413.         ClientPtr    client;
  4414. .fi
  4415. .LP
  4416. This re-enables X request processing for the specified client.
  4417. .NH 1
  4418. Extension Interfaces
  4419. .XS
  4420. Extension Interfaces
  4421. .XE
  4422. .LP
  4423. This section describes the functions which exist in DDX for extension
  4424. writers to use.
  4425. .NH 2
  4426. Extension initialization
  4427. .LP
  4428. This function should be called from your extensionInitProc which
  4429. should be called by InitExtensions.
  4430. .nf
  4431.     ExtensionEntry *AddExtension(name, NumEvents,NumErrors,
  4432.         MainProc, SwappedMainProc, CloseDownProc, MinorOpcodeProc)
  4433.  
  4434.         char *name;  /*Null terminate string; case matters*/
  4435.         int NumEvents;                
  4436.         int NumErrors;                
  4437.         int (* MainProc)();/*Called if client matches server order*/
  4438.         int (* SwappedMainProc)();/*Called if client differs from server*/
  4439.         void (* CloseDownProc)();  
  4440.         unsigned short (*MinorOpcodeProc)();
  4441.  
  4442. .fi
  4443. name is the name used by clients to refer to the extension.  NumEvents is the
  4444. number of event types used by the extension, NumErrors is the number of
  4445. error codes needed by the extension.  MainProc is called whenever a client
  4446. accesses the major opcode assigned to the extension.  SwappedMainProc is
  4447. identical, except the client using the extension has reversed byte-sex.
  4448. CloseDownProc is called at server reset time to deallocate any private
  4449. storage used by the extension.  MinorOpcodeProc is used by DIX to place the
  4450. appropriate value into errors.  The DIX routine StandardMinorOpcode can be
  4451. used here which takes the minor opcode from the normal place in the request
  4452. (i.e. just after the major opcode).
  4453. .NH 2
  4454. Resource type allocation.
  4455. .LP
  4456. These functions should also be called from your extensionInitProc to
  4457. allocate all of the various resource classes and types required for
  4458. the extension.  Each time the server resets, these types must be reallocated
  4459. as the old allocations will have been discarded.
  4460. Resource types are integer values starting at 1.  Get
  4461. a resource type by calling
  4462. .nf
  4463.  
  4464.     RESTYPE CreateNewResourceType(deleteFunc)
  4465.  
  4466. .fi
  4467. deleteFunc will be called to destroy all resources with this
  4468. type.
  4469.  
  4470. Resource classes are masks starting at 1 << 31 which can
  4471. be or'ed with any resource type to provide attributes for the
  4472. type.  To allocate a new class bit, call
  4473. .nf
  4474.  
  4475.     RESTYPE CreateNewResourceClass()
  4476.  
  4477. .fi
  4478. There are two ways of looking up resources, by type or 
  4479. by class.  Classes are non-exclusive subsets of the space of
  4480. all resources, so you can lookup the union of multiple classes.
  4481. (RC_ANY is the union of all classes).
  4482. .LP
  4483. Note that the appropriate class bits must be or'ed into the value returned
  4484. by CreateNewResourceType when calling resource lookup functions.
  4485. .LP
  4486. If you need to create a ``private'' resource ID for internal use, you
  4487. can call FakeClientID.
  4488. .nf
  4489.     XID FakeClientID(client)
  4490.         int client;
  4491. .fi
  4492. This allocates from ID space reserved for the server.
  4493. .LP
  4494. To associate a resource value with an ID, use AddResource.
  4495. .nf
  4496.     Bool AddResource(id, type, value)
  4497.         XID id;
  4498.         RESTYPE type;
  4499.         pointer value;
  4500. .fi
  4501. The type should be the full type of the resource, including any class
  4502. bits.  If AddResource fails to allocate memory to store the resource,
  4503. it will call the deleteFunc for the type, and then return False.
  4504. .LP
  4505. To free a resource, use one of the following.
  4506. .nf
  4507.     void FreeResource(id, skipDeleteFuncType)
  4508.         XID id;
  4509.         RESTYPE skipDeleteFuncType;
  4510.  
  4511.     void FreeResourceByType(id, type, skipFree)
  4512.         XID id;
  4513.         RESTYPE type;
  4514.         Bool    skipFree;
  4515. .nf
  4516. FreeResource frees all resources matching the given id, regardless of
  4517. type; the type's deleteFunc will be called on each matching resource,
  4518. except that skipDeleteFuncType can be set to a single type for which
  4519. the deleteFunc should not be called (otherwise pass RT_NONE).
  4520. FreeResourceByType frees a specific resource matching a given id
  4521. and type; if skipFree is true, then the deleteFunc is not called.
  4522. .LP
  4523. To look up a resource, use one of the following.
  4524. .nf
  4525.     pointer LookupIDByType(id, rtype)
  4526.         XID id;
  4527.         RESTYPE rtype;
  4528.  
  4529.     pointer LookupIDByClass(id, classes)
  4530.         XID id;
  4531.         RESTYPE classes;
  4532. .fi
  4533. LookupIDByType finds a resource with the given id and exact type.
  4534. LookupIDByClass finds a resource with the given id whose type is
  4535. included in any one of the specified classes.
  4536. .NH 2
  4537. Macros and Other Helpers
  4538. .LP
  4539. There are a number of macros in server/include/dix.h which
  4540. are useful to the extension writer.  Ones of particular interest
  4541. are: REQUEST, REQUEST_SIZE_MATCH, REQUEST_AT_LEAST_SIZE,
  4542. REQUEST_FIXED_SIZE, LEGAL_NEW_RESOURCE, LOOKUP_DRAWABLE, VERIFY_GC, and
  4543. VALIDATE_DRAWABLE_AND_GC. Useful byte swapping macros can be found
  4544. in server/include/misc.h: lswapl, lswaps, LengthRestB, LengthRestS,
  4545. LengthRestL, SwapRestS, SwapRestL, swapl, swaps, cpswapl, and cpswaps.
  4546. .bp
  4547. .NH 1
  4548. Summary of Routines
  4549. .XS
  4550. Summary of Routines
  4551. .XE
  4552. .LP
  4553. This is a summary of the routines discussed in this document.
  4554. The procedure names are in alphabetical order.
  4555. The Struct is the structure it is attached to; if blank, this 
  4556. procedure is not attached to a struct and must be named as shown.
  4557. The sample server provides implementations in the following
  4558. categories.  Notice that many of the graphics routines have both
  4559. mi and mfb implementations.
  4560. .TS
  4561. l l.
  4562. dix    portable to all systems; do not attempt to rewrite (server/dix)
  4563. 4.2    written for 4.2/4.3bsd Unix or equivalent (server/os/4.2bsd)
  4564. ddx    frame buffer dependent (examples in server/ddx/mfb,server/ddx/cfb)
  4565. mi    routine provided in server/ddx/mi
  4566. hd    hardware dependent (examples in many server/ddx directories)
  4567. none    not implemented in sample implementation
  4568. .TE
  4569. .TS
  4570. expand;
  4571. c c c 
  4572. l c l.
  4573. Procedure    Port    Struct
  4574. _
  4575. ALLOCATE_LOCAL    4.2
  4576. AbortDDX    hd
  4577. AddEnabledDevice    4.2
  4578. AddInputDevice    dix
  4579. AddScreen    dix
  4580. Bell    hd    Device
  4581. ChangeClip    mi    GC func
  4582. ChangeGC        GC func
  4583. ChangeWindowAttributes    ddx    Screen
  4584. ClearToBackground    ddx    Window
  4585. ClientAuthorized    4.2
  4586. ClientSignal    dix
  4587. ClientSleep    dix
  4588. ClientWakeup    dix
  4589. ClipNotify    ddx    Screen
  4590. CloseScreen    hd
  4591. ConstrainCursor    hd    Screen
  4592. CopyArea    mi    GC op
  4593. CopyGCDest    ddx    GC func
  4594. CopyGCSource    none    GC func
  4595. CopyPlane    mi    GC op
  4596. CopyWindow    ddx    Window
  4597. CreateGC    ddx    Screen
  4598. CreatePixmap    ddx    Screen
  4599. CreateWellKnowSockets    4.2
  4600. CreateWindow    ddx    Screen
  4601. CursorLimits    hd    Screen
  4602. DEALLOCATE_LOCAL    4.2
  4603. DestroyClip    ddx    GC func
  4604. DestroyGC    ddx    GC func
  4605. DestroyPixmap    ddx    Screen
  4606. DestroyWindow    ddx    Screen
  4607. DisplayCursor    hd    Screen
  4608. Error    4.2
  4609. ErrorF    4.2
  4610. ExpandFontNamePattern    4.2
  4611. FatalError    4.2
  4612. FillPolygon    mi    GC op
  4613. FillSpans    ddx    GC op
  4614. .TE
  4615. .bp
  4616. .TS
  4617. expand;
  4618. c c c 
  4619. l c l.
  4620. Procedure    Port    Struct
  4621. _
  4622. FlushAllOutput    4.2
  4623. FlushIfCriticalOutputPending    4.2
  4624. GetImage    mi    Screen
  4625. GetMotionEvents    hd    Device
  4626. GetSpans    ddx    Screen
  4627. GetStaticColormap    ddx    Screen
  4628. ImageGlyphBlt    mi    GC op
  4629. ImageText16    mi    GC op
  4630. ImageText8    mi    GC op
  4631. InitInput    hd    
  4632. InitKeyboardDeviceStruct    dix    
  4633. InitOutput    hd    
  4634. InitPointerDeviceStruct    dix    
  4635. InsertFakeRequest    4.2
  4636. InstallColormap    ddx    Screen
  4637. Intersect    mi    Screen
  4638. Inverse    mi    Screen
  4639. LegalModifier    hd
  4640. LineHelper    mi    GC op
  4641. ListInstalledColormaps    ddx    Screen
  4642. LookupKeyboardDevice    dix    
  4643. LookupPointerDevice    dix    
  4644. NextAvailableClient    dix
  4645. OsInit    4.2    
  4646. PaintWindowBackground    mi    Window
  4647. PaintWindowBorder    mi    Window
  4648. PointerNonInterestBox    hd    Screen
  4649. PointInRegion    mi    Screen
  4650. PolyArc    mi    GC op
  4651. PolyFillArc    mi    GC op
  4652. PolyFillRect    mi    GC op
  4653. PolyGlyphBlt    mi    GC op
  4654. Polylines    mi    GC op
  4655. PolyPoint    mi    GC op
  4656. PolyRectangle    mi    GC op
  4657. PolySegment    mi    GC op
  4658. PolyText16    mi    GC op
  4659. PolyText8    mi    GC op
  4660. PositionWindow    ddx    Screen
  4661. ProcessInputEvents    hd    
  4662. PushPixels    mi    GC op
  4663. PutImage    mi    GC op
  4664. QueryBestSize    hd    Screen
  4665. ReadRequestFromClient    4.2    
  4666. RealizeCursor    hd    Screen
  4667. .TE
  4668. .bp
  4669. .TS
  4670. expand;
  4671. c c c 
  4672. l c l.
  4673. Procedure    Port    Struct
  4674. _
  4675. RealizeFont    ddx    Screen
  4676. RealizeWindow    ddx    Screen
  4677. RecolorCursor    hd    Screen
  4678. RectIn    mi    Screen
  4679. RegionCopy    mi    Screen
  4680. RegionCreate    mi    Screen
  4681. RegionDestroy    mi    Screen
  4682. RegionEmpty    mi    Screen
  4683. RegionExtents    mi    Screen
  4684. RegionNotEmpty    mi    Screen
  4685. RegionReset    mi    Screen
  4686. ResolveColor    ddx    Screen
  4687. RegisterKeyboardDevice    dix    
  4688. RegisterPointerDevice    dix    
  4689. RemoveEnabledDevice    4.2
  4690. ResetCurrentRequest    4.2
  4691. RestoreAreas    none    BackingStore
  4692. SaveDoomedAreas    none    BackingStore
  4693. SaveScreen    ddx    Screen
  4694. SetCriticalOutputPending    4.2
  4695. SetCursorPosition    hd    Screen
  4696. SetInputCheck    dix    
  4697. SetSpans    ddx    GC op
  4698. StoreColors    ddx    Screen
  4699. Subtract    mi    Screen
  4700. TimeSinceLastInputEvent    hd
  4701. TranslateBackingStore    none    BackingStore
  4702. TranslateRegion    mi    Screen
  4703. UninstallColormap    ddx    Screen
  4704. Union    mi    Screen
  4705. UnrealizeCursor    hd    Screen
  4706. UnrealizeFont    ddx    Screen
  4707. UnrealizeWindow    ddx    Screen
  4708. ValidateGC    ddx    GC func
  4709. ValidateTree    mi    Screen
  4710. WaitForSomething    4.2
  4711. WindowExposures    mi    Window
  4712. WriteToClient    4.2    
  4713. Xalloc    4.2
  4714. Xfree    4.2
  4715. Xrealloc    4.2
  4716. .TE
  4717.  
  4718. .TC
  4719.