1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4 <!ENTITY % xorg-defs SYSTEM "defs.ent"> %xorg-defs;
5 <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
10 <title>Definition of the Porting Layer for the X v11 Sample Server</title>
11 <titleabbrev>X Porting Layer</titleabbrev>
13 <firstname>Susan</firstname><surname>Angebranndt</surname>
14 <affiliation><orgname>Digital Equipment Corporation</orgname></affiliation>
17 <firstname>Raymond</firstname><surname>Drewry</surname>
18 <affiliation><orgname>Digital Equipment Corporation</orgname></affiliation>
21 <firstname>Philip</firstname><surname>Karlton</surname>
22 <affiliation><orgname>Digital Equipment Corporation</orgname></affiliation>
25 <firstname>Todd</firstname><surname>Newman</surname>
26 <affiliation><orgname>Digital Equipment Corporation</orgname></affiliation>
29 <firstname>Bob</firstname><surname>Scheifler</surname>
30 <affiliation><orgname>Massachusetts Institute of Technology</orgname></affiliation>
33 <firstname>Keith</firstname><surname>Packard</surname>
34 <affiliation><orgname>MIT X Consortium</orgname></affiliation>
37 <firstname>David</firstname><othername>P.</othername><surname>Wiggins</surname>
38 <affiliation><orgname>X Consortium</orgname></affiliation>
41 <firstname>Jim</firstname><surname>Gettys</surname>
42 <affiliation><orgname>X.org Foundation and Hewlett Packard</orgname></affiliation>
44 <publisher><publishername>The X.Org Foundation</publishername></publisher>
45 <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
46 <releaseinfo>X Server Version &xserver.version;</releaseinfo>
47 <copyright><year>1994</year><holder>X Consortium, Inc.</holder></copyright>
48 <copyright><year>2004</year><holder>X.org Foundation, Inc.</holder></copyright>
50 <para>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</para>
51 <para>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</para>
52 <para>THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</para>
53 <para>LK201 and DEC are trademarks of Digital Equipment Corporation. Macintosh and Apple are trademarks of Apple Computer, Inc. PostScript is a trademark of Adobe Systems, Inc. Ethernet is a trademark of Xerox Corporation. X Window System is a trademark of the X.org Foundation, Inc. Cray is a trademark of Cray Research, Inc.</para>
55 <pubdate>&xserver.reldate;</pubdate>
58 <revnumber>1.0</revnumber>
59 <date>27 Oct 2004</date>
60 <authorinitials>sa</authorinitials>
61 <revremark>Initial Version</revremark>
64 <revnumber>1.1</revnumber>
65 <date>27 Oct 2004</date>
66 <authorinitials>bs</authorinitials>
67 <revremark>Minor Revisions</revremark>
70 <revnumber>2.0</revnumber>
71 <date>27 Oct 2004</date>
72 <authorinitials>kp</authorinitials>
73 <revremark>Revised for Release 4 and 5</revremark>
76 <revnumber>3.0</revnumber>
77 <date>27 Oct 2004</date>
78 <authorinitials>dpw</authorinitials>
79 <revremark>Revised for Release 6</revremark>
82 <revnumber>3.1</revnumber>
83 <date>27 Oct 2004</date>
84 <authorinitials>jg</authorinitials>
85 <revremark>Revised for Release 6.8.2</revremark>
88 <revnumber>3.2</revnumber>
89 <date>17 Dec 2006</date>
90 <authorinitials>efw</authorinitials>
91 <revremark>DocBook conversion</revremark>
94 <revnumber>3.3</revnumber>
95 <date>17 Feb 2008</date>
96 <authorinitials>aj</authorinitials>
97 <revremark>Revised for backing store changes</revremark>
100 <revnumber>3.4</revnumber>
101 <date>31 Mar 2008</date>
102 <authorinitials>efw</authorinitials>
103 <revremark>Revised for devPrivates changes</revremark>
106 <revnumber>3.5</revnumber>
107 <date>July 2010</date>
108 <authorinitials>ac</authorinitials>
109 <revremark>Revised for Xorg 1.9 devPrivates changes
110 and 1.8 CreateNewResourceType changes</revremark>
113 <revnumber>3.6</revnumber>
114 <date>July 2012</date>
115 <authorinitials>kp</authorinitials>
116 <revremark>Revised for X server 1.13 screen-specific devPrivates changes</revremark>
120 <para>The following document explains the structure of the X Window System display server and the interfaces among the larger pieces. It is intended as a reference for programmers who are implementing an X Display Server on their workstation hardware. It is included with the X Window System source tape, along with the document "Strategies for Porting the X v11 Sample Server." The order in which you should read these documents is:
122 <listitem><para>Read the first section of the "Strategies for Porting" document (Overview of Porting Process).</para></listitem>
123 <listitem><para>Skim over this document (the Definition document).</para></listitem>
124 <listitem><para>Skim over the remainder of the Strategies document.</para></listitem>
125 <listitem><para>Start planning and working, referring to the Strategies and Definition documents.</para></listitem>
127 You may also want to look at the following documents:
129 <listitem><para>"The X Window System" for an overview of X.</para></listitem>
130 <listitem><para>"Xlib - C Language X Interface" for a view of what the client programmer sees.</para></listitem>
131 <listitem><para>"X Window System Protocol" for a terse description of the byte stream protocol between the client and server.</para></listitem>
134 <para>To understand this document and the accompanying source code, you should know the C language. You should be familiar with 2D graphics and windowing concepts such as clipping, bitmaps, fonts, etc. You should have a general knowledge of the X Window System. To implement the server code on your hardware, you need to know a lot about your hardware, its graphic display device(s), and (possibly) its networking and multitasking facilities. This document depends a lot on the source code, so you should have a listing of the code handy.</para>
135 <para>Some source in the distribution is directly compilable on your machine. Some of it will require modification. Other parts may have to be completely written from scratch. The distribution also includes source for a sample implementation of a display server which runs on a very wide variety of color and monochrome displays on Linux and *BSD which you will find useful for implementing any type of X server.</para>
136 <para>Note to the 2008 edition: at this time this document must be considered incomplete, though improved over the 2004 edition. In particular, the new Render extension is still lacking good documentation, and has become vital to high performance X implementations. Modern applications and desktop environments are now much more sensitive to good implementation of the Render extension than in most operations of the old X graphics model. The shadow frame buffer implementation is also very useful in many circumstances, and also needs documentation. We hope to rectify these shortcomings in our documentation in the future. Help would be greatly appreciated.</para>
140 <!-- Original authorship information:
142 .OF 'Porting Layer Definition'- % -'October 27, 2004'
143 Definition of the Porting Layer
144 for the X v11 Sample Server
149 Digital Equipment Corporation
153 Massachusetts Institute of Technology
155 Revised for Release 4 and Release 5 by
159 Revised for Release 6 by
163 Minor Revisions for Release 6.8.2 by
165 X.org Foundation and Hewlett Packard
169 <title>The X Window System</title>
171 The X Window System, or simply "X," is a
172 windowing system that provides high-performance, high-level,
173 device-independent graphics.
176 X is a windowing system designed for bitmapped graphic displays.
177 The display can have a
178 simple, monochrome display or it can have a color display with up to 32 bits
179 per pixel with a special graphics processor doing the work. (In this
180 document, monochrome means a black and white display with one bit per pixel.
181 Even though the usual meaning of monochrome is more general, this special
182 case is so common that we decided to reserve the word for this purpose.)
183 In practice, monochrome displays are now almost unheard of, with 4 bit
184 gray scale displays being the low end.
187 X is designed for a networking environment where
188 users can run applications on machines other than their own workstations.
189 Sometimes, the connection is over an Ethernet network with a protocol such as TCP/IP;
190 but, any "reliable" byte stream is allowable.
191 A high-bandwidth byte stream is preferable; RS-232 at
192 9600 baud would be slow without compression techniques.
195 X by itself allows great freedom of design.
196 For instance, it does not include any user interface standard.
197 Its intent is to "provide mechanism, not policy."
198 By making it general, it can be the foundation for a wide
199 variety of interactive software.
202 For a more detailed overview, see the document "The X Window System."
203 For details on the byte stream protocol, see "X Window System protocol."
207 <title>Overview of the Server</title>
210 manages windows and simple graphics requests
211 for the user on behalf of different client applications.
212 The client applications can be running on any machine on the network.
213 The server mainly does three things:
215 <listitem><para>Responds to protocol requests from existing clients (mostly graphic and text drawing commands)</para></listitem>
216 <listitem><para>Sends device input (keystrokes and mouse actions) and other events to existing clients</para></listitem>
217 <listitem><para>Maintains client connections</para></listitem>
221 The server code is organized into four major pieces:
223 <listitem><para>Device Independent (DIX) layer - code shared among all implementations</para></listitem>
224 <listitem><para>Operating System (OS) layer - code that is different for each operating system but is shared among all graphic devices for this operating system</para></listitem>
225 <listitem><para>Device Dependent (DDX) layer - code that is (potentially) different for each combination of operating system and graphic device</para></listitem>
226 <listitem><para>Extension Interface - a standard way to add features to the X server</para></listitem>
230 The "porting layer" consists of the OS and DDX layers; these are
231 actually parallel and neither one is on top of the other.
232 The DIX layer is intended to be portable
233 without change to target systems and is not
234 detailed here, although several routines
235 in DIX that are called by DDX are
237 Extensions incorporate new functionality into the server; and require
238 additional functionality over a simple DDX.
241 The following sections outline the functions of the layers.
242 Section 3 briefly tells what you need to know about the DIX layer.
243 The OS layer is explained in Section 4.
244 Section 5 gives the theory of operation and procedural interface for the
246 Section 6 describes the functions which exist for the extension writer.
251 <title>DIX Layer</title>
253 The DIX layer is the machine and device independent part of X.
254 The source should be common to all operating systems and devices.
255 The port process should not include changes to this part, therefore internal interfaces to DIX
256 modules are not discussed, except for public interfaces to the DDX and the OS layers.
257 The functions described in this section are available for extension writers to use.
260 In the process of getting your server to work, if
261 you think that DIX must be modified for purposes other than bug fixes,
262 you may be doing something wrong.
263 Keep looking for a more compatible solution.
264 When the next release of the X server code is available,
265 you should be able to just drop in the new DIX code and compile it.
267 you will have to remember what changes you made and will have
268 to change the new sources before you can update to the new version.
271 The heart of the DIX code is a loop called the dispatch loop.
272 Each time the processor goes around the loop, it sends off accumulated input events
273 from the input devices to the clients, and it processes requests from the clients.
274 This loop is the most organized way for the server to
275 process the asynchronous requests that
277 Most of these operations are performed by OS and DDX routines that you must supply.
280 <title>Server Resource System</title>
282 X resources are C structs inside the server.
283 Client applications create and manipulate these objects
284 according to the rules of the X byte stream protocol.
285 Client applications refer to resources with resource IDs,
286 which are 32-bit integers that are sent over the network.
287 Within the server, of course, they are just C structs, and we refer to them
291 <title>Pre-Defined Resource Types</title>
293 The DDX layer has several kinds of resources:
295 <listitem><para>Window</para></listitem>
296 <listitem><para>Pixmap</para></listitem>
297 <listitem><para>Screen</para></listitem>
298 <listitem><para>Device</para></listitem>
299 <listitem><para>Colormap</para></listitem>
300 <listitem><para>Font</para></listitem>
301 <listitem><para>Cursor</para></listitem>
302 <listitem><para>Graphics Contexts</para></listitem>
306 The type names of the more
308 structs usually end in "Rec," such as "DeviceRec;"
309 the pointer types usually end in "Ptr," such as "DevicePtr."
313 important defined constants are declared
314 in .h files that have names that suggest the name of the object.
315 For instance, there are two .h files for windows,
316 window.h and windowstr.h.
317 window.h defines only what needs to be defined in order to use windows
318 without peeking inside of them;
319 windowstr.h defines the structs with all of their components in great detail
320 for those who need it.
323 Three kinds of fields are in these structs:
325 <listitem><para>Attribute fields - struct fields that contain values like normal structs</para></listitem>
326 <listitem><para>Pointers to procedures, or structures of procedures, that operate on the object</para></listitem>
327 <listitem><para>A single private field or a devPrivates list (see <xref linkend="wrappers_and_privates"/>)
328 used by your DDX code to store private data.</para></listitem>
333 the struct's procedure pointers to do its tasks.
334 These procedures are set either directly or indirectly by DDX procedures.
336 the procedures described in the remainder of this
337 document are accessed through one of these structs.
338 For example, the procedure to create a pixmap
339 is attached to a ScreenRec and might be called by using the expression
343 <programlisting>(* pScreen->CreatePixmap)(pScreen, width, height, depth).</programlisting>
347 All procedure pointers must be set to some routine unless noted otherwise;
348 a null pointer will have unfortunate consequences.
351 Procedure routines will be indicated in the documentation by this convention:
353 <programlisting>void pScreen->MyScreenRoutine(arg, arg, ...)</programlisting>
355 as opposed to a free routine, not in a data structure:
357 <programlisting>void MyFreeRoutine(arg, arg, ...)</programlisting>
361 The attribute fields are mostly set by DIX; DDX should not modify them
362 unless noted otherwise.
366 <title>Creating Resources and Resource Types</title>
368 These functions should also be called from your extensionInitProc to
369 allocate all of the various resource classes and types required for
370 the extension. Each time the server resets, these types must be reallocated
371 as the old allocations will have been discarded.
372 Resource types are integer values starting at 1. Get
373 a resource type by calling
374 <blockquote><programlisting>
376 RESTYPE CreateNewResourceType(deleteFunc, char *name)
378 </programlisting></blockquote>
379 deleteFunc will be called to destroy all resources with this
380 type. name will be used to identify this type of resource
381 to clients using the X-Resource extension, to security
382 extensions such as SELinux, and to tracing frameworks such as DTrace.
383 [The name argument was added in xorg-server 1.8.]
386 Resource classes are masks starting at 1 << 31 which can
387 be or'ed with any resource type to provide attributes for the
388 type. To allocate a new class bit, call
389 <blockquote><programlisting>
391 RESTYPE CreateNewResourceClass()
393 </programlisting></blockquote>
396 There are two ways of looking up resources, by type or
397 by class. Classes are non-exclusive subsets of the space of
398 all resources, so you can lookup the union of multiple classes.
399 (RC_ANY is the union of all classes).</para>
401 Note that the appropriate class bits must be or'ed into the value returned
402 by CreateNewResourceType when calling resource lookup functions.</para>
404 If you need to create a ``private'' resource ID for internal use, you
405 can call FakeClientID.
406 <blockquote><programlisting>
408 XID FakeClientID(client)
411 </programlisting></blockquote>
412 This allocates from ID space reserved for the server.</para>
414 To associate a resource value with an ID, use AddResource.
415 <blockquote><programlisting>
417 Bool AddResource(id, type, value)
422 </programlisting></blockquote>
423 The type should be the full type of the resource, including any class
424 bits. If AddResource fails to allocate memory to store the resource,
425 it will call the deleteFunc for the type, and then return False.</para>
427 To free a resource, use one of the following.
428 <blockquote><programlisting>
430 void FreeResource(id, skipDeleteFuncType)
432 RESTYPE skipDeleteFuncType;
434 void FreeResourceByType(id, type, skipFree)
439 </programlisting></blockquote>
440 FreeResource frees all resources matching the given id, regardless of
441 type; the type's deleteFunc will be called on each matching resource,
442 except that skipDeleteFuncType can be set to a single type for which
443 the deleteFunc should not be called (otherwise pass RT_NONE / X11_RESTYPE_NONE).
444 FreeResourceByType frees a specific resource matching a given id
445 and type; if skipFree is true, then the deleteFunc is not called.
449 <title>Looking Up Resources</title>
451 To look up a resource, use one of the following.
452 <blockquote><programlisting>
454 int dixLookupResourceByType(
461 int dixLookupResourceByClass(
468 </programlisting></blockquote>
469 dixLookupResourceByType finds a resource with the given id and exact type.
470 dixLookupResourceByClass finds a resource with the given id whose type is
471 included in any one of the specified classes.
472 The client and access_mode must be provided to allow security extensions to
473 check if the client has the right privileges for the requested access.
474 The bitmask values defined in the dixaccess.h header are or'ed together
475 to define the requested access_mode.
480 <title>Callback Manager</title>
482 To satisfy a growing number of requests for the introduction of ad hoc
483 notification style hooks in the server, a generic callback manager was
484 introduced in R6. A callback list object can be introduced for each
485 new hook that is desired, and other modules in the server can register
486 interest in the new callback list. The following functions support
487 these operations.</para>
489 Before getting bogged down in the interface details, an typical usage
490 example should establish the framework. Let's look at the
491 ClientStateCallback in dix/dispatch.c. The purpose of this particular
492 callback is to notify interested parties when a client's state
493 (initial, running, gone) changes. The callback is "created" in this
494 case by simply declaring a variable:
495 <blockquote><programlisting>
496 CallbackListPtr ClientStateCallback;
497 </programlisting></blockquote>
500 Whenever the client's state changes, the following code appears, which notifies
501 all interested parties of the change:
502 <blockquote><programlisting>
503 if (ClientStateCallback) CallCallbacks(&ClientStateCallback, (pointer)client);
504 </programlisting></blockquote>
507 Interested parties subscribe to the ClientStateCallback list by saying:
508 <blockquote><programlisting>
509 AddCallback(&ClientStateCallback, func, data);
510 </programlisting></blockquote>
513 When CallCallbacks is invoked on the list, func will be called thusly:
514 <blockquote><programlisting>
515 (*func)(&ClientStateCallback, data, client)
516 </programlisting></blockquote>
520 <blockquote><programlisting>
522 Bool AddCallback(pcbl, callback, subscriber_data)
523 CallbackListPtr *pcbl;
524 CallbackProcPtr callback;
525 pointer subscriber_data;
527 </programlisting></blockquote>
528 Adds the (callback, subscriber_data) pair to the given callback list. Creates the callback
529 list if it doesn't exist. Returns TRUE if successful.</para>
531 <blockquote><programlisting>
533 Bool DeleteCallback(pcbl, callback, subscriber_data)
534 CallbackListPtr *pcbl;
535 CallbackProcPtr callback;
536 pointer subscriber_data;
538 </programlisting></blockquote>
539 Removes the (callback, data) pair to the given callback list if present.
540 Returns TRUE if (callback, data) was found.</para>
542 <blockquote><programlisting>
544 void CallCallbacks(pcbl, call_data)
545 CallbackListPtr *pcbl;
548 </programlisting></blockquote>
549 For each callback currently registered on the given callback list, call
551 <blockquote><programlisting>
553 (*callback)(pcbl, subscriber_data, call_data);
554 </programlisting></blockquote>
557 <blockquote><programlisting>
558 void DeleteCallbackList(pcbl)
559 CallbackListPtr *pcbl;
561 </programlisting></blockquote>
562 Destroys the given callback list.</para>
565 <title>Extension Interfaces</title>
567 This function should be called from your extensionInitProc which
568 should be called by InitExtensions.
569 <blockquote><programlisting>
571 ExtensionEntry *AddExtension(name, NumEvents,NumErrors,
572 MainProc, SwappedMainProc, CloseDownProc, MinorOpcodeProc)
574 const char *name; /*Null terminate string; case matters*/
577 int (* MainProc)(ClientPtr);/*Called if client matches server order*/
578 int (* SwappedMainProc)(ClientPtr);/*Called if client differs from server*/
579 void (* CloseDownProc)(ExtensionEntry *);
580 unsigned short (*MinorOpcodeProc)(ClientPtr);
582 </programlisting></blockquote>
583 name is the name used by clients to refer to the extension. NumEvents is the
584 number of event types used by the extension, NumErrors is the number of
585 error codes needed by the extension. MainProc is called whenever a client
586 accesses the major opcode assigned to the extension. SwappedMainProc is
587 identical, except the client using the extension has reversed byte-sex.
588 CloseDownProc is called at server reset time to deallocate any private
589 storage used by the extension. MinorOpcodeProc is used by DIX to place the
590 appropriate value into errors. The DIX routine StandardMinorOpcode can be
591 used here which takes the minor opcode from the normal place in the request
592 (i.e. just after the major opcode).</para>
595 <title>Macros and Other Helpers</title>
597 There are a number of macros in Xserver/include/dix.h which
598 are useful to the extension writer. Ones of particular interest
599 are: REQUEST, REQUEST_SIZE_MATCH, REQUEST_AT_LEAST_SIZE,
600 REQUEST_FIXED_SIZE, LEGAL_NEW_RESOURCE, and
601 VALIDATE_DRAWABLE_AND_GC. Useful byte swapping macros can be found
602 in Xserver/include/dix.h: WriteReplyToClient and WriteSwappedDataToClient; and
603 in Xserver/include/misc.h: bswap_64, bswap_32, bswap_16, LengthRestB, LengthRestS,
604 LengthRestL, SwapRestS, SwapRestL, swapl, swaps, cpswapl, and cpswaps.</para>
609 <title>OS Layer</title>
611 This part of the source consists of a few routines that you have to rewrite
612 for each operating system.
613 These OS functions maintain the client connections and schedule work
614 to be done for clients.
615 They also provide an interface to font files,
616 font name to file name translation, and
617 low level memory management.
619 <programlisting>void OsInit()</programlisting>
621 OsInit initializes your OS code, performing whatever tasks need to be done.
622 Frequently there is not much to be done.
623 The sample server implementation is in Xserver/os/osinit.c.
626 <title>Scheduling and Request Delivery</title>
628 The main dispatch loop in DIX creates the illusion of multitasking between
629 different windows, while the server is itself but a single process.
630 The dispatch loop breaks up the work for each client into small digestible parts.
631 Some parts are requests from a client, such as individual graphic commands.
632 Some parts are events delivered to the client, such as keystrokes from the user.
633 The processing of events and requests for different
634 clients can be interleaved with one another so true multitasking
635 is not needed in the server.
638 You must supply some of the pieces for proper scheduling between clients.
641 int WaitForSomething(pClientReady)
647 WaitForSomething is the scheduler procedure you must write that will
648 suspend your server process until something needs to be done.
650 make the server suspend until one or more of the following occurs:
652 <listitem><para>There is an input event from the user or hardware (see SetInputCheck())</para></listitem>
653 <listitem><para>There are requests waiting from known clients, in which case you should return a count of clients stored in pClientReady</para></listitem>
654 <listitem><para>A new client tries to connect, in which case you should create the client and then continue waiting</para></listitem>
658 Before WaitForSomething() computes the masks to pass to select, poll or
659 similar operating system interface, it needs to
660 see if there is anything to do on the work queue; it must call a DIX
661 routine called ProcessWorkQueue().
669 If WaitForSomething() decides it is about to do something that might block
670 (in the sample server, before it calls select() or poll) it must call a DIX
671 routine called BlockHandler().
674 void BlockHandler(void *pTimeout)
677 The types of the arguments are for agreement between the OS and DDX
678 implementations, but the pTimeout is a pointer to the information
679 determining how long the block is allowed to last.
682 In the sample server, pTimeout is a pointer.
685 The DIX BlockHandler() iterates through the Screens, for each one calling
686 its BlockHandler. A BlockHandler is declared thus:
689 void xxxBlockHandler(ScreenPtr pScreen, void *pTimeout)
692 The arguments are a pointer to the Screen, and the arguments to the
696 Immediately after WaitForSomething returns from the
697 block, even if it didn't actually block, it must call the DIX routine
701 void WakeupHandler(int result)
704 Once again, the types are not specified by DIX. The result is the
705 success indicator for the thing that (may have) blocked.
706 In the sample server, result is the result from select() (or equivalent
707 operating system function).
710 The DIX WakeupHandler() calls each Screen's
711 WakeupHandler. A WakeupHandler is declared thus:
714 void xxxWakeupHandler(ScreenPtr pScreen, int result)
717 The arguments are the Screen, of the Screen, and the arguments to
718 the DIX WakeupHandler().
721 In addition to the per-screen BlockHandlers, any module may register
722 block and wakeup handlers (only together) using:
725 Bool RegisterBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
726 ServerBlockHandlerProcPtr blockHandler;
727 ServerWakeupHandlerProcPtr wakeupHandler;
731 A FALSE return code indicates that the registration failed for lack of
732 memory. To remove a registered Block handler at other than server reset time
733 (when they are all removed automatically), use:
736 RemoveBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
737 ServerBlockHandlerProcPtr blockHandler;
738 ServerWakeupHandlerProcPtr wakeupHandler;
742 All three arguments must match the values passed to
743 RegisterBlockAndWakeupHandlers.
746 These registered block handlers are called before the per-screen handlers:
749 void (*ServerBlockHandler) (void *blockData, void *pTimeout)
754 Sometimes block handlers need to adjust the time referenced by pTimeout,
755 which on UNIX family systems is generally represented by a struct timeval
756 consisting of seconds and microseconds in 32 bit values.
757 As a convenience to reduce error prone struct timeval computations which
758 require modulus arithmetic and correct overflow behavior in the face of
759 millisecond wrapping through 32 bits,
760 <blockquote><programlisting>
762 void AdjustWaitForDelay(void *pTimeout, unsigned long newdelay)
764 </programlisting></blockquote>
768 Any wakeup handlers registered with RegisterBlockAndWakeupHandlers will
769 be called after the Screen handlers:
770 <blockquote><programlisting>
772 void (*ServerWakeupHandler) (void *blockData, int result)
773 </programlisting></blockquote>
776 The WaitForSomething on the sample server also has a built
777 in screen saver that darkens the screen if no input happens for a period of time.
778 The sample server implementation is in Xserver/os/WaitFor.c.
781 Note that WaitForSomething() may be called when you already have several
782 outstanding things (events, requests, or new clients) queued up.
783 For instance, your server may have just done a large graphics request,
784 and it may have been a long time since WaitForSomething() was last called.
785 If many clients have lots of requests queued up, DIX will only service
786 some of them for a given client
787 before going on to the next client (see isItTimeToYield, below).
788 Therefore, WaitForSomething() will have to report that these same clients
789 still have requests queued up the next time around.
792 An implementation should return information on as
793 many outstanding things as it can.
794 For instance, if your implementation always checks for client data first and does not
795 report any input events until there is no client data left,
796 your mouse and keyboard might get locked out by an application that constantly
797 barrages the server with graphics drawing requests.
798 Therefore, as a general rule, input devices should always have priority over graphics
802 A list of indexes (client->index) for clients with data ready to be read or
803 processed should be returned in pClientReady, and the count of indexes
804 returned as the result value of the call.
805 These are not clients that have full requests ready, but any clients who have
806 any data ready to be read or processed.
808 will process requests from each client in turn by calling
809 ReadRequestFromClient(), below.
812 WaitForSomething() must create new clients as they are requested (by
813 whatever mechanism at the transport level). A new client is created
814 by calling the DIX routine:
815 <blockquote><programlisting>
817 ClientPtr NextAvailableClient(ospriv)
819 </programlisting></blockquote>
820 This routine returns NULL if a new client cannot be allocated (e.g. maximum
821 number of clients reached). The ospriv argument will be stored into the OS
822 private field (pClient->osPrivate), to store OS private information about the
823 client. In the sample server, the osPrivate field contains the
824 number of the socket for this client. See also "New Client Connections."
825 NextAvailableClient() will call InsertFakeRequest(), so you must be
829 If there are outstanding input events,
830 you should make sure that the two SetInputCheck() locations are unequal.
831 The DIX dispatcher will call your implementation of ProcessInputEvents()
832 until the SetInputCheck() locations are equal.
835 The sample server contains an implementation of WaitForSomething().
837 following two routines indicate to WaitForSomething() what devices should
838 be waited for. fd is an OS dependent type; in the sample server
839 it is an open file descriptor.
840 <blockquote><programlisting>
842 int AddEnabledDevice(fd)
845 int RemoveEnabledDevice(fd)
847 </programlisting></blockquote>
848 These two routines are
849 usually called by DDX from the initialize cases of the
850 Input Procedures that are stored in the DeviceRec (the
851 routine passed to AddInputDevice()).
852 The sample server implementation of AddEnabledDevice
853 and RemoveEnabledDevice are in Xserver/os/connection.c.
856 <title>Timer Facilities</title>
858 Similarly, the X server or an extension may need to wait for some timeout.
859 Early X releases implemented this functionality using block and wakeup handlers,
860 but this has been rewritten to use a general timer facilty, and the
861 internal screen saver facilities reimplemented to use Timers.
862 These functions are TimerInit, TimerForce, TimerSet, TimerCheck, TimerCancel,
863 and TimerFree, as defined in Xserver/include/os.h. A callback function will be called
864 when the timer fires, along with the current time, and a user provided argument.
865 <blockquote><programlisting>
866 typedef struct _OsTimerRec *OsTimerPtr;
868 typedef CARD32 (*OsTimerCallback)(
869 OsTimerPtr /* timer */,
873 OsTimerPtr TimerSet( OsTimerPtr /* timer */,
876 OsTimerCallback /* func */,
879 </programlisting></blockquote>
882 TimerSet returns a pointer to a timer structure and sets a timer to the specified time
883 with the specified argument. The flags can be TimerAbsolute and TimerForceOld.
884 The TimerSetOld flag controls whether if the timer is reset and the timer is pending, the
885 whether the callback function will get called.
886 The TimerAbsolute flag sets the callback time to an absolute time in the future rather
887 than a time relative to when TimerSet is called.
888 TimerFree should be called to free the memory allocated
890 <blockquote><programlisting>
893 Bool TimerForce(OsTimerPtr /* pTimer */)
895 void TimerCheck(void);
897 void TimerCancel(OsTimerPtr /* pTimer */)
899 void TimerFree(OsTimerPtr /* pTimer */)
900 </programlisting></blockquote>
903 TimerInit frees any existing timer entries. TimerForce forces a call to the timer's
904 callback function and returns true if the timer entry existed, else it returns false and
905 does not call the callback function. TimerCancel will cancel the specified timer.
906 TimerFree calls TimerCancel and frees the specified timer.
907 Calling TimerCheck will force the server to see if any timer callbacks should be called.
912 <title>New Client Connections</title>
914 The process whereby a new client-server connection starts up is
915 very dependent upon what your byte stream mechanism.
916 This section describes byte stream initiation using examples from the TCP/IP
917 implementation on the sample server.
920 The first thing that happens is a client initiates a connection with the server.
921 How a client knows to do this depends upon your network facilities and the
923 In a typical scenario, a user named Fred
924 on his X workstation is logged onto a Cray
925 supercomputer running a command shell in an X window. Fred can type shell
926 commands and have the Cray respond as though the X server were a dumb terminal.
927 Fred types in a command to run an X client application that was linked with Xlib.
928 Xlib looks at the shell environment variable DISPLAY, which has the
929 value "fredsbittube:0.0."
930 The host name of Fred's workstation is "fredsbittube," and the 0s are
931 for multiple screens and multiple X server processes.
933 happens on your system depends upon how X and Xlib are implemented.)
936 The client application calls a TCP routine on the
937 Cray to open a TCP connection for X
938 to communicate with the network node "fredsbittube."
939 The TCP software on the Cray does this by looking up the TCP
940 address of "fredsbittube" and sending an open request to TCP port 6000
944 All X servers on TCP listen for new clients on port 6000 by default;
945 this is known as a "well-known port" in IP terminology.
948 The server receives this request from its port 6000
949 and checks where it came from to see if it is on the server's list
950 of "trustworthy" hosts to talk to.
951 Then, it opens another port for communications with the client.
952 This is the byte stream that all X communications will go over.
955 Actually, it is a bit more complicated than that.
956 Each X server process running on the host machine is called a "display."
957 Each display can have more than one screen that it manages.
958 "corporatehydra:3.2" represents screen 2 on display 3 on
959 the multi-screened network node corporatehydra.
960 The open request would be sent on well-known port number 6003.
963 Once the byte stream is set up, what goes on does not depend very much
964 upon whether or not it is TCP.
965 The client sends an xConnClientPrefix struct (see Xproto.h) that has the
966 version numbers for the version of Xlib it is running, some byte-ordering information,
967 and two character strings used for authorization.
968 If the server does not like the authorization strings
969 or the version numbers do not match within the rules,
970 or if anything else is wrong, it sends a failure
971 response with a reason string.
974 If the information never comes, or comes much too slowly, the connection
975 should be broken off. You must implement the connection timeout. The
976 sample server implements this by keeping a timestamp for each still-connecting
977 client and, each time just before it attempts to accept new connections, it
978 closes any connection that are too old.
979 The connection timeout can be set from the command line.
982 You must implement whatever authorization schemes you want to support.
983 The sample server on the distribution tape supports a simple authorization
984 scheme. The only interface seen by DIX is:
985 <blockquote><programlisting>
988 ClientAuthorized(client, proto_n, auth_proto, string_n, auth_string)
990 unsigned int proto_n;
992 unsigned int string_n;
994 </programlisting></blockquote>
995 DIX will only call this once per client, once it has read the full initial
996 connection data from the client. If the connection should be
997 accepted ClientAuthorized() should return NULL, and otherwise should
998 return an error message string.
1001 Accepting new connections happens internally to WaitForSomething().
1002 WaitForSomething() must call the DIX routine NextAvailableClient()
1003 to create a client object.
1004 Processing of the initial connection data will be handled by DIX.
1005 Your OS layer must be able to map from a client
1006 to whatever information your OS code needs to communicate
1007 on the given byte stream to the client.
1008 DIX uses this ClientPtr to refer to
1009 the client from now on. The sample server uses the osPrivate field in
1010 the ClientPtr to store the file descriptor for the socket, the
1011 input and output buffers, and authorization information.
1014 To initialize the methods you choose to allow clients to connect to
1015 your server, main() calls the routine
1016 <blockquote><programlisting>
1018 void CreateWellKnownSockets()
1019 </programlisting></blockquote>
1020 This routine is called only once, and not called when the server
1021 is reset. To recreate any sockets during server resets, the following
1022 routine is called from the main loop:
1023 <blockquote><programlisting>
1025 void ResetWellKnownSockets()
1026 </programlisting></blockquote>
1027 Sample implementations of both of these routines are found in
1028 Xserver/os/connection.c.
1031 For more details, see the section called "Connection Setup" in the X protocol specification.
1035 <title>Reading Data from Clients</title>
1037 Requests from the client are read in as a byte stream by the OS layer.
1038 They may be in the form of several blocks of bytes delivered in sequence; requests may
1039 be broken up over block boundaries or there may be many requests per block.
1040 Each request carries with it length information.
1041 It is the responsibility of the following routine to break it up into request blocks.
1042 <blockquote><programlisting>
1044 int ReadRequestFromClient(who)
1046 </programlisting></blockquote>
1050 the routine ReadRequestFromClient() to get one request from the byte stream
1051 belonging to client "who."
1052 You must swap the third and fourth bytes (the second 16-bit word) according to the
1054 the protocol to determine the length of the
1056 This length is measured in 32-bit words, not in bytes. Therefore, the
1057 theoretical maximum request is 256K.
1058 (However, the maximum length allowed is dependent upon the server's input
1059 buffer. This size is sent to the client upon connection. The maximum
1060 size is the constant MAX_REQUEST_SIZE in Xserver/include/os.h)
1061 The rest of the request you return is
1062 assumed NOT to be correctly swapped for internal
1063 use, because that is the responsibility of DIX.
1066 The 'who' argument is the ClientPtr returned from WaitForSomething.
1067 The return value indicating status should be set to the (positive) byte count if the read is successful,
1068 0 if the read was blocked, or a negative error code if an error happened.
1071 You must then store a pointer to
1072 the bytes of the request in the client request buffer field;
1073 who->requestBuffer. This can simply be a pointer into your buffer;
1074 DIX may modify it in place but will not otherwise cause damage.
1075 Of course, the request must be contiguous; you must
1076 shuffle it around in your buffers if not.
1079 The sample server implementation is in Xserver/os/io.c.
1081 <section><title>Inserting Data for Clients</title>
1083 DIX can insert data into the client stream, and can cause a "replay" of
1084 the current request.
1085 <blockquote><programlisting>
1087 Bool InsertFakeRequest(client, data, count)
1092 int ResetCurrentRequest(client)
1094 </programlisting></blockquote>
1097 InsertFakeRequest() must insert the specified number of bytes of data
1098 into the head of the input buffer for the client. This may be a
1099 complete request, or it might be a partial request. For example,
1100 NextAvailableCient() will insert a partial request in order to read
1101 the initial connection data sent by the client. The routine returns FALSE
1102 if memory could not be allocated. ResetCurrentRequest()
1103 should "back up" the input buffer so that the currently executing request
1104 will be reexecuted. DIX may have altered some values (e.g. the overall
1105 request length), so you must recheck to see if you still have a complete
1106 request. ResetCurrentRequest() should always cause a yield (isItTimeToYield).
1112 <title>Sending Events, Errors And Replies To Clients</title>
1114 <blockquote><programlisting>
1116 int WriteToClient(who, n, buf)
1120 </programlisting></blockquote>
1121 WriteToClient should write n bytes starting at buf to the
1123 It returns the number of bytes written, but for simplicity,
1124 the number returned must be either the same value as the number
1125 requested, or -1, signaling an error.
1126 The sample server implementation is in Xserver/os/io.c.
1129 <blockquote><programlisting>
1130 void SendErrorToClient(client, majorCode, minorCode, resId, errorCode)
1132 unsigned int majorCode;
1133 unsigned int minorCode;
1136 </programlisting></blockquote>
1137 SendErrorToClient can be used to send errors back to clients,
1138 although in most cases your request function should simply return
1139 the error code, having set client->errorValue to the appropriate
1140 error value to return to the client, and DIX will call this
1141 function with the correct opcodes for you.
1144 <blockquote><programlisting>
1146 void FlushAllOutput()
1148 void FlushIfCriticalOutputPending()
1150 void SetCriticalOutputPending()
1151 </programlisting></blockquote>
1152 These three routines may be implemented to support buffered or delayed
1153 writes to clients, but at the very least, the stubs must exist.
1154 FlushAllOutput() unconditionally flushes all output to clients;
1155 FlushIfCriticalOutputPending() flushes output only if
1156 SetCriticalOutputPending() has be called since the last time output
1158 The sample server implementation is in Xserver/os/io.c and
1159 actually ignores requests to flush output on a per-client basis
1160 if it knows that there
1161 are requests in that client's input queue.
1165 <title>Font Support</title>
1167 In the sample server, fonts are encoded in disk files or fetched from the
1168 font server. The two fonts required by the server, <quote>fixed</quote>
1169 and <quote>cursor</quote> are commonly compiled into the font library.
1170 For disk fonts, there is one file per font, with a file name like
1171 "fixed.pcf". Font server fonts are read over the network using the
1172 X Font Server Protocol. The disk directories containing disk fonts and
1173 the names of the font servers are listed together in the current "font path."
1176 In principle, you can put all your fonts in ROM or in RAM in your server.
1177 You can put them all in one library file on disk.
1178 You could generate them on the fly from stroke descriptions. By placing the
1179 appropriate code in the Font Library, you will automatically export fonts in
1180 that format both through the X server and the Font server.
1183 The code for processing fonts in different formats, as well as handling the
1184 metadata files for them on disk (such as <filename>fonts.dir</filename>) is
1185 located in the libXfont library, which is provided as a separately compiled
1186 module. These routines are
1187 shared between the X server and the Font server, so instead of this document
1188 specifying what you must implement, simply refer to the font
1189 library interface specification for the details. All of the interface code to the Font
1190 library is contained in dix/dixfonts.c
1194 <title>Memory Management</title>
1196 Memory management is based on functions in the C runtime library, malloc(),
1197 realloc(), and free(), and you should simply call the C library functions
1198 directly. Consult a C runtime library reference manual for more details.
1201 Treat memory allocation carefully in your implementation. Memory
1202 leaks can be very hard to find and are frustrating to a user. An X
1203 server could be running for days or weeks without being reset, just
1204 like a regular terminal. If you leak a few dozen k per day, that will
1205 add up and will cause problems for users that leave their workstations
1210 <title>Client Scheduling</title>
1213 has the ability to schedule clients much like an operating system would,
1214 suspending and restarting them without regard for the state of their input
1215 buffers. This functionality allows the X server to suspend one client and
1216 continue processing requests from other clients while waiting for a
1217 long-term network activity (like loading a font) before continuing with the
1219 <blockquote><programlisting>
1220 Bool isItTimeToYield;
1221 </programlisting></blockquote>
1222 isItTimeToYield is a global variable you can set
1224 DIX to end the client's "time slice" and start paying attention to the next client.
1225 After the current request is finished, DIX will move to the next client.
1229 server, ReadRequestFromClient() sets isItTimeToYield after
1230 10 requests packets in a row are read from the same client.
1233 This scheduling algorithm can have a serious effect upon performance when two
1234 clients are drawing into their windows simultaneously.
1235 If it allows one client to run until its request
1236 queue is empty by ignoring isItTimeToYield, the client's queue may
1237 in fact never empty and other clients will be blocked out.
1238 On the other hand, if it switches between different clients too quickly,
1239 performance may suffer due to too much switching between contexts.
1240 For example, if a graphics processor needs to be set up with drawing modes
1241 before drawing, and two different clients are drawing with
1242 different modes into two different windows, you may
1243 switch your graphics processor modes so often that performance is impacted.
1246 See the Strategies document for
1247 heuristics on setting isItTimeToYield.
1250 The following functions provide the ability to suspend request
1251 processing on a particular client, resuming it at some later time:
1252 <blockquote><programlisting>
1254 int IgnoreClient (who)
1257 int AttendClient (who)
1259 </programlisting></blockquote>
1260 Ignore client is responsible for pretending that the given client doesn't
1261 exist. WaitForSomething should not return this client as ready for reading
1262 and should not return if only this client is ready. AttendClient undoes
1263 whatever IgnoreClient did, setting it up for input again.
1266 Three functions support "process control" for X clients:
1267 <blockquote><programlisting>
1269 Bool ClientSleep (client, function, closure)
1274 </programlisting></blockquote>
1275 This suspends the current client (the calling routine is responsible for
1276 making its way back to Dispatch()). No more X requests will be processed
1277 for this client until ClientWakeup is called.
1278 <blockquote><programlisting>
1280 Bool ClientSignal (client)
1283 </programlisting></blockquote>
1284 This function causes a call to the (*function) parameter passed to
1285 ClientSleep to be queued on the work queue. This does not automatically
1286 "wakeup" the client, but the function called is free to do so by calling:
1287 <blockquote><programlisting>
1289 ClientWakeup (client)
1292 </programlisting></blockquote>
1293 This re-enables X request processing for the specified client.
1297 <title>Other OS Functions</title>
1299 <blockquote><programlisting>
1301 ErrorF(char *f, ...)
1304 FatalError(char *f, ...)
1305 </programlisting></blockquote>
1306 You should write these three routines to provide for diagnostic output
1307 from the dix and ddx layers, although implementing them to produce no
1308 output will not affect the correctness of your server. ErrorF() and
1309 FatalError() take a printf() type of format specification in the first
1310 argument and an implementation-dependent number of arguments following
1311 that. Normally, the formats passed to ErrorF() and FatalError()
1312 should be terminated with a newline.
1315 After printing the message arguments, FatalError() must be implemented
1316 such that the server will call ddxGiveUp(EXIT_ERR_ABORT) to give the ddx layer
1317 a chance to reset the hardware, and then
1318 terminate the server; it must not return.
1321 The sample server implementation for these routines
1322 is in Xserver/os/log.c along with other routines for logging messages.
1328 <title>DDX Layer</title>
1330 This section describes the
1331 interface between DIX and DDX.
1332 While there may be an OS-dependent driver interface between DDX
1333 and the physical device, that interface is left to the DDX
1334 implementor and is not specified here.
1337 The DDX layer does most of its work through procedures that are
1338 pointed to by different structs.
1339 As previously described, the behavior of these resources is largely determined by
1340 these procedure pointers.
1341 Most of these routines are for graphic display on the screen or support functions thereof.
1342 The rest are for user input from input devices.
1345 <title>Input</title>
1347 In this document "input" refers to input from the user,
1348 such as mouse, keyboard, and
1350 X input devices are of several types: keyboard, pointing device, and
1351 many others. The core server has support for extension devices as
1352 described by the X Input Extension document; the interfaces used by
1353 that extension are described elsewhere. The core devices are actually
1354 implemented as two collections of devices, the mouse is a ButtonDevice,
1355 a ValuatorDevice and a PtrFeedbackDevice while the keyboard is a KeyDevice,
1356 a FocusDevice and a KbdFeedbackDevice. Each part implements a portion of
1357 the functionality of the device. This abstraction is hidden from view for
1358 core devices by DIX.
1361 You, the DDX programmer, are
1362 responsible for some of the routines in this section.
1363 Others are DIX routines that you should call to do the things you need to do in these DDX routines.
1364 Pay attention to which is which.
1367 <title>Input Device Data Structures</title>
1369 DIX keeps a global directory of devices in a central data structure
1371 For each device there is a device structure called a DeviceRec.
1372 DIX can locate any DeviceRec through InputInfo.
1373 In addition, it has a special pointer to identify the main pointing device
1374 and a special pointer to identify the main keyboard.
1377 The DeviceRec (Xserver/include/input.h) is a device-independent
1378 structure that contains the state of an input device.
1379 A DevicePtr is simply a pointer to a DeviceRec.
1382 An xEvent describes an event the server reports to a client.
1383 Defined in Xproto.h, it is a huge struct of union of structs that have fields for
1384 all kinds of events.
1385 All of the variants overlap, so that the struct is actually very small in memory.
1389 <title>Processing Events</title>
1391 The main DDX input interface is the following routine:
1392 <blockquote><programlisting>
1394 void ProcessInputEvents()
1395 </programlisting></blockquote>
1396 You must write this routine to deliver input events from the user.
1397 DIX calls it when input is pending (see next section), and possibly
1398 even when it is not.
1399 You should write it to get events from each device and deliver
1401 To deliver the events to DIX, DDX should call the following
1403 <blockquote><programlisting>
1405 void DevicePtr->processInputProc(pEvent, device, count)
1407 DeviceIntPtr device;
1409 </programlisting></blockquote>
1410 This is the "input proc" for the device, a DIX procedure.
1411 DIX will fill in this procedure pointer to one of its own routines by
1412 the time ProcessInputEvents() is called the first time.
1413 Call this input proc routine as many times as needed to
1414 deliver as many events as should be delivered.
1415 DIX will buffer them up and send them out as needed. Count is set
1416 to the number of event records which make up one atomic device event and
1417 is always 1 for the core devices (see the X Input Extension for descriptions
1418 of devices which may use count > 1).
1421 For example, your ProcessInputEvents() routine might check the mouse and the
1423 If the keyboard had several keystrokes queued up, it could just call
1424 the keyboard's processInputProc as many times as needed to flush its internal queue.
1427 event is an xEvent struct you pass to the input proc.
1428 When the input proc returns, it is finished with the event rec, and you can fill
1429 in new values and call the input proc again with it.
1432 You should deliver the events in the same order that they were generated.
1435 For keyboard and pointing devices the xEvent variant should be keyButtonPointer.
1436 Fill in the following fields in the xEvent record:
1439 <listitem><para>type - is one of the following: KeyPress, KeyRelease, ButtonPress,
1440 ButtonRelease, or MotionNotify</para></listitem>
1441 <listitem><para>detail - for KeyPress or KeyRelease fields, this should be the
1442 key number (not the ASCII code); otherwise unused</para></listitem>
1443 <listitem><para>time - is the time that the event happened (32-bits, in milliseconds, arbitrary origin)</para></listitem>
1444 <listitem><para>rootX - is the x coordinate of cursor</para></listitem>
1445 <listitem><para>rootY - is the y coordinate of cursor</para></listitem>
1448 The rest of the fields are filled in by DIX.
1451 The time stamp is maintained by your code in the DDX layer, and it is your responsibility to
1452 stamp all events correctly.
1455 The x and y coordinates of the pointing device and the time must be filled in for all event types
1456 including keyboard events.
1459 The pointing device must report all button press and release events.
1460 In addition, it should report a MotionNotify event every time it gets called
1461 if the pointing device has moved since the last notify.
1462 Intermediate pointing device moves are stored in a special GetMotionEvents buffer,
1463 because most client programs are not interested in them.
1466 There are quite a collection of sample implementations of this routine,
1467 one for each supported device.
1471 <title>Telling DIX When Input is Pending</title>
1473 In the server's dispatch loop, DIX checks to see
1474 if there is any device input pending whenever WaitForSomething() returns.
1475 If the check says that input is pending, DIX calls the
1476 DDX routine ProcessInputEvents().
1479 This check for pending input must be very quick; a procedure call
1481 The code that does the check is a hardwired IF
1482 statement in DIX code that simply compares the values
1483 pointed to by two pointers.
1484 If the values are different, then it assumes that input is pending and
1485 ProcessInputEvents() is called by DIX.
1488 You must pass pointers to DIX to tell it what values to compare.
1489 The following procedure
1490 is used to set these pointers:
1491 <blockquote><programlisting>
1493 void SetInputCheck(p1, p2)
1495 </programlisting></blockquote>
1496 You should call it sometime during initialization to indicate to DIX the
1497 correct locations to check.
1499 pay special attention to the size of what they actually point to,
1500 because the locations are assumed to be longs.
1503 These two pointers are initialized by DIX
1504 to point to arbitrary values that
1506 In other words, if you forget to call this routine during initialization,
1507 the worst thing that will happen is that
1508 ProcessInputEvents will be called when
1509 there are no events to process.
1513 point at the head and tail of some shared
1515 Another use would be to have one point at a constant 0, with the
1516 other pointing at some mask containing 1s
1517 for each input device that has
1521 The DDX layer of the sample server calls SetInputCheck()
1523 server's private internal queue is initialized.
1524 It passes pointers to the queue's head and tail. See Xserver/mi/mieq.c.
1527 <blockquote><programlisting>
1528 int TimeSinceLastInputEvent()
1529 </programlisting></blockquote>
1530 DDX must time stamp all hardware input
1531 events. But DIX sometimes needs to know the
1532 time and the OS layer needs to know the time since the last hardware
1534 order for the screen saver to work. TimeSinceLastInputEvent() returns
1535 the this time in milliseconds.
1539 <title>Controlling Input Devices</title>
1541 You must write four routines to do various device-specific
1542 things with the keyboard and pointing device.
1543 They can have any name you wish because
1544 you pass the procedure pointers to DIX routines.
1547 <blockquote><programlisting>
1549 int pInternalDevice->valuator->GetMotionProc(pdevice, coords, start, stop, pScreen)
1550 DeviceIntPtr pdevice;
1551 xTimecoord * coords;
1552 unsigned long start;
1555 </programlisting></blockquote>
1556 You write this DDX routine to fill in coords with all the motion
1557 events that have times (32-bit count of milliseconds) between time
1558 start and time stop. It should return the number of motion events
1559 returned. If there is no motion events support, this routine should
1560 do nothing and return zero. The maximum number of coords to return is
1561 set in InitPointerDeviceStruct(), below.
1564 When the user drags the pointing device, the cursor position
1565 theoretically sweeps through an infinite number of points. Normally,
1566 a client that is concerned with points other than the starting and
1567 ending points will receive a pointer-move event only as often as the
1568 server generates them. (Move events do not queue up; each new one
1569 replaces the last in the queue.) A server, if desired, can implement
1570 a scheme to save these intermediate events in a motion buffer. A
1571 client application, like a paint program, may then request that these
1572 events be delivered to it through the GetMotionProc routine.
1575 <blockquote><programlisting>
1577 void pInternalDevice->bell->BellProc(percent, pDevice, ctrl, unknown)
1579 DeviceIntPtr pDevice;
1582 </programlisting></blockquote>
1583 You need to write this routine to ring the bell on the keyboard.
1584 loud is a number from 0 to 100, with 100 being the loudest.
1585 Class is either BellFeedbackClass or KbdFeedbackClass (from XI.h).
1588 <blockquote><programlisting>
1590 void pInternalDevice->somedevice->CtrlProc(device, ctrl)
1592 SomethingCtrl *ctrl;
1594 </programlisting></blockquote>
1595 You write two versions of this procedure, one for the keyboard and one for the pointing device.
1596 DIX calls it to inform DDX when a client has requested changes in the current
1597 settings for the particular device.
1598 For a keyboard, this might be the repeat threshold and rate.
1599 For a pointing device, this might be a scaling factor (coarse or fine) for position reporting.
1600 See input.h for the ctrl structures.
1604 <title>Input Initialization</title>
1606 Input initialization is a bit complicated.
1607 It all starts with InitInput(), a routine that you write to call
1608 AddInputDevice() twice
1609 (once for pointing device and once for keyboard.)
1612 When you Add the devices, a routine you supply for each device
1613 gets called to initialize them.
1614 Your individual initialize routines must call InitKeyboardDeviceStruct()
1615 or InitPointerDeviceStruct(), depending upon which it is.
1616 In other words, you indicate twice that the keyboard is the keyboard and
1617 the pointer is the pointer.
1620 <blockquote><programlisting>
1622 void InitInput(argc, argv)
1625 </programlisting></blockquote>
1626 InitInput is a DDX routine you must write to initialize the
1627 input subsystem in DDX.
1628 It must call AddInputDevice() for each device that might generate events.
1631 <blockquote><programlisting>
1633 DevicePtr AddInputDevice(deviceProc, autoStart)
1634 DeviceProc deviceProc;
1636 </programlisting></blockquote>
1637 AddInputDevice is a DIX routine you call to create a device object.
1638 deviceProc is a DDX routine that is called by DIX to do various operations.
1639 AutoStart should be TRUE for devices that need to be turned on at
1640 initialization time with a special call, as opposed to waiting for some
1641 client application to
1643 This routine returns NULL if sufficient memory cannot be allocated to
1647 Note also that except for the main keyboard and pointing device,
1648 an extension is needed to provide for a client interface to a device.
1652 procedures return the specified DevicePtr. They may or may not be useful
1653 to DDX implementors.
1656 <blockquote><programlisting>
1658 DevicePtr LookupKeyboardDevice()
1659 </programlisting></blockquote>
1660 LookupKeyboardDevice returns pointer for current main keyboard device.
1663 <blockquote><programlisting>
1665 DevicePtr LookupPointerDevice()
1666 </programlisting></blockquote>
1667 LookupPointerDevice returns pointer for current main pointing device.
1670 A DeviceProc (the kind passed to AddInputDevice()) in the following form:
1671 <blockquote><programlisting>
1673 Bool pInternalDevice->DeviceProc(device, action);
1674 DeviceIntPtr device;
1676 </programlisting></blockquote>
1677 You must write a DeviceProc for each device.
1678 device points to the device record.
1679 action tells what action to take;
1680 it will be one of these defined constants (defined in input.h):
1684 At DEVICE_INIT time, the device should initialize itself by calling
1685 InitPointerDeviceStruct(), InitKeyboardDeviceStruct(), or a similar
1687 and "opening" the device if necessary.
1688 If you return a non-zero (i.e., != Success) value from the DEVICE_INIT
1689 call, that device will be considered unavailable. If either the main keyboard
1690 or main pointing device cannot be initialized, the DIX code will refuse
1691 to continue booting up.</para></listitem>
1693 DEVICE_ON - If the DeviceProc is called with DEVICE_ON, then it is
1695 putting events into the client stream by calling through the ProcessInputProc
1696 in the device.</para></listitem>
1698 DEVICE_OFF - If the DeviceProc is called with DEVICE_OFF, no further
1700 device should be given to the DIX layer.
1701 The device will appear to be dead to the user.</para></listitem>
1703 DEVICE_CLOSE - At DEVICE_CLOSE (terminate or reset) time, the device should
1704 be totally closed down.</para></listitem>
1708 <blockquote><programlisting>
1710 void InitPointerDeviceStruct(device, map, mapLength,
1711 GetMotionEvents, ControlProc, numMotionEvents)
1715 ValuatorMotionProcPtr ControlProc;
1716 PtrCtrlProcPtr GetMotionEvents;
1717 int numMotionEvents;
1718 </programlisting></blockquote>
1719 InitPointerDeviceStruct is a DIX routine you call at DEVICE_INIT time to declare
1720 some operating routines and data structures for a pointing device.
1721 map and mapLength are as described in the X Window
1722 System protocol specification.
1723 ControlProc and GetMotionEvents are DDX routines, see above.
1726 numMotionEvents is for the motion-buffer-size for the GetMotionEvents
1728 A typical length for a motion buffer would be 100 events.
1729 A server that does not implement this capability should set
1730 numMotionEvents to zero.
1733 <blockquote><programlisting>
1735 void InitKeyboardDeviceStruct(device, pKeySyms, pModifiers, Bell, ControlProc)
1737 KeySymsPtr pKeySyms;
1740 KbdCtrlProcPtr ControlProc;
1742 </programlisting></blockquote>
1743 You call this DIX routine when a keyboard device is initialized and
1744 its device procedure is called with
1746 The formats of the keysyms and modifier maps are defined in
1747 Xserver/include/input.h.
1748 They describe the layout of keys on the keyboards, and the glyphs
1749 associated with them. ( See the next section for information on
1750 setting up the modifier map and the keysym map.)
1751 ControlProc and Bell are DDX routines, see above.
1755 <title>Keyboard Mapping and Keycodes</title>
1757 When you send a keyboard event, you send a report that a given key has
1758 either been pressed or has been released. There must be a keycode for
1759 each key that identifies the key; the keycode-to-key mapping can be
1760 any mapping you desire, because you specify the mapping in a table you
1761 set up for DIX. However, you are restricted by the protocol
1762 specification to keycode values in the range 8 to 255 inclusive.
1765 The keycode mapping information that you set up consists of the following:
1768 A minimum and maximum keycode number</para></listitem>
1770 An array of sets of keysyms for each key, that is of length
1771 maxkeycode - minkeycode + 1.
1772 Each element of this array is a list of codes for symbols that are on that key.
1773 There is no limit to the number of symbols that can be on a key.</para></listitem>
1775 Once the map is set up, DIX keeps and
1776 maintains the client's changes to it.
1779 The X protocol defines standard names to indicate the symbol(s)
1780 printed on each keycap. (See X11/keysym.h)
1785 <title>Screens</title>
1787 Different computer graphics
1788 displays have different capabilities.
1789 Some are simple monochrome
1790 frame buffers that are just lying
1791 there in memory, waiting to be written into.
1792 Others are color displays with many bits per pixel using some color lookup table.
1793 Still others have high-speed graphic processors that prefer to do all of the work
1795 including maintaining their own high-level, graphic data structures.
1798 <title>Screen Hardware Requirements</title>
1800 The only requirement on screens is that you be able to both read
1801 and write locations in the frame buffer.
1802 All screens must have a depth of 32 or less (unless you use
1803 an X extension to allow a greater depth).
1804 All screens must fit into one of the classes listed in the section
1805 in this document on Visuals and Depths.
1808 X uses the pixel as its fundamental unit of distance on the screen.
1809 Therefore, most programs will measure everything in pixels.</para>
1811 The sample server assumes square pixels.
1812 Serious WYSIWYG (what you see is what you get) applications for
1813 publishing and drawing programs will adjust for
1814 different screen resolutions automatically.
1816 is involved in compensating for non-square pixels (a bit in the DDX
1817 code for the sample server but quite a bit in the client applications).</para>
1820 <title>Data Structures</title>
1822 X supports multiple screens that are connected to the same
1823 server. Therefore, all the per-screen information is bundled into one data
1824 structure of attributes and procedures, which is the ScreenRec (see
1825 Xserver/include/scrnintstr.h).
1826 The procedure entry points in a ScreenRec operate on
1827 regions, colormaps, cursors, and fonts, because these resources
1828 can differ in format from one screen to another.</para>
1830 Windows are areas on the screen that can be drawn into by graphic
1831 routines. "Pixmaps" are off-screen graphic areas that can be drawn
1832 into. They are both considered drawables and are described in the
1833 section on Drawables. All graphic operations work on drawables, and
1834 operations are available to copy patches from one drawable to another.</para>
1836 The pixel image data in all drawables is in a format that is private
1837 to DDX. In fact, each instance of a drawable is associated with a
1838 given screen. Presumably, the pixel image data for pixmaps is chosen
1839 to be conveniently understood by the hardware. All screens in a
1840 single server must be able to handle all pixmaps depths declared in
1841 the connection setup information.</para>
1843 Pixmap images are transferred to the server in one of two ways:
1844 XYPixmap or ZPimap. XYPixmaps are a series of bitmaps, one for each
1845 bit plane of the image, using the bitmap padding rules from the
1846 connection setup. ZPixmaps are a series of bits, nibbles, bytes or
1847 words, one for each pixel, using the format rules (padding and so on)
1848 for the appropriate depth.</para>
1850 All screens in a given server must agree on a set of pixmap image
1851 formats (PixmapFormat) to support (depth, number of bits per pixel,
1854 There is no color interpretation of bits in the pixmap. Pixmaps
1855 do not contain pixel values. The interpretation is made only when
1856 the bits are transferred onto the screen.</para>
1858 The screenInfo structure (in scrnintstr.h) is a global data structure
1859 that has a pointer to an array of ScreenRecs, one for each screen on
1860 the server. (These constitute the one and only description of each
1861 screen in the server.) Each screen has an identifying index (0, 1, 2, ...).
1862 In addition, the screenInfo struct contains global server-wide
1863 details, such as the bit- and byte- order in all bit images, and the
1864 list of pixmap image formats that are supported. The X protocol
1865 insists that these must be the same for all screens on the server.</para>
1868 <title>Output Initialization</title>
1870 <blockquote><programlisting>
1872 InitOutput(pScreenInfo, argc, argv)
1873 ScreenInfo *pScreenInfo;
1876 </programlisting></blockquote>
1877 Upon initialization, your DDX routine InitOutput() is called by DIX.
1878 It is passed a pointer to screenInfo to initialize. It is also passed
1879 the argc and argv from main() for your server for the command-line
1880 arguments. These arguments may indicate what or how many screen
1881 device(s) to use or in what way to use them. For instance, your
1882 server command line may allow a "-D" flag followed by the name of the
1883 screen device to use.</para>
1885 Your InitOutput() routine should initialize each screen you wish to
1886 use by calling AddScreen(), and then it should initialize the pixmap
1887 formats that you support by storing values directly into the
1888 screenInfo data structure. You should also set certain
1889 implementation-dependent numbers and procedures in your screenInfo,
1890 which determines the pixmap and scanline padding rules for all screens
1891 in the server.</para>
1893 <blockquote><programlisting>
1895 int AddScreen(scrInitProc, argc, argv)
1896 Bool (*scrInitProc)();
1899 </programlisting></blockquote>
1900 You should call AddScreen(), a DIX procedure, in InitOutput() once for
1901 each screen to add it to the screenInfo database. The first argument
1902 is an initialization procedure for the screen that you supply. The
1903 second and third are the argc and argv from main(). It returns the
1904 screen number of the screen installed, or -1 if there is either
1905 insufficient memory to add the screen, or (*scrInitProc) returned
1908 The scrInitProc should be of the following form:
1909 <blockquote><programlisting>
1911 Bool scrInitProc(pScreen, argc, argv)
1915 </programlisting></blockquote>
1916 pScreen is the pointer to the screen's new ScreenRec. argc and argv
1917 are as before. Your screen initialize procedure should return TRUE
1918 upon success or FALSE if the screen cannot be initialized (for
1919 instance, if the screen hardware does not exist on this machine).</para>
1921 This procedure must determine what actual device it is supposed to initialize.
1922 If you have a different procedure for each screen, then it is no problem.
1923 If you have the same procedure for multiple screens, it may have trouble
1924 figuring out which screen to initialize each time around, especially if
1925 InitOutput() does not initialize all of the screens.
1926 It is probably easiest to have one procedure for each screen.</para>
1928 The initialization procedure should fill in all the screen procedures
1929 for that screen (windowing functions, region functions, etc.) and certain
1930 screen attributes for that screen.</para>
1933 <title>Region Routines in the ScreenRec</title>
1935 A region is a dynamically allocated data structure that describes an
1936 irregularly shaped piece of real estate in XY pixel space. You can
1937 think of it as a set of pixels on the screen to be operated upon with
1938 set operations such as AND and OR.</para>
1940 A region is frequently implemented as a list of rectangles or bitmaps
1941 that enclose the selected pixels. Region operators control the
1942 "clipping policy," or the operations that work on regions. (The
1943 sample server uses YX-banded rectangles. Unless you have something
1944 already implemented for your graphics system, you should keep that
1945 implementation.) The procedure pointers to the region operators are
1946 located in the ScreenRec data structure. The definition of a region
1947 can be found in the file Xserver/include/regionstr.h. The region code
1948 is found in Xserver/mi/miregion.c. DDX implementations using other
1949 region formats will need to supply different versions of the region
1952 Since the list of rectangles is unbounded in size, part of the region
1953 data structure is usually a large, dynamically allocated chunk of
1954 memory. As your region operators calculate logical combinations of
1955 regions, these blocks may need to be reallocated by your region
1956 software. For instance, in the sample server, a RegionRec has some
1957 header information and a pointer to a dynamically allocated rectangle
1958 list. Periodically, the rectangle list needs to be expanded with
1959 realloc(), whereupon the new pointer is remembered in the RegionRec.</para>
1961 Most of the region operations come in two forms: a function pointer in
1962 the Screen structure, and a macro. The server can be compiled so that
1963 the macros make direct calls to the appropriate functions (instead of
1964 indirecting through a screen function pointer), or it can be compiled
1965 so that the macros are identical to the function pointer forms.
1966 Making direct calls is faster on many architectures.</para>
1968 <blockquote><programlisting>
1970 RegionPtr pScreen->RegionCreate( rect, size)
1974 macro: RegionPtr RegionCreate(rect, size)
1976 </programlisting></blockquote>
1977 RegionCreate creates a region that describes ONE rectangle. The
1978 caller can avoid unnecessary reallocation and copying by declaring the
1979 probable maximum number of rectangles that this region will need to
1980 describe itself. Your region routines, though, cannot fail just
1981 because the region grows beyond this size. The caller of this routine
1982 can pass almost anything as the size; the value is merely a good guess
1983 as to the maximum size until it is proven wrong by subsequent use.
1984 Your region procedures are then on their own in estimating how big the
1985 region will get. Your implementation might ignore size, if
1988 <blockquote><programlisting>
1990 void pScreen->RegionInit (pRegion, rect, size)
1995 macro: RegionInit(pRegion, rect, size)
1997 </programlisting></blockquote>
1998 Given an existing raw region structure (such as an local variable), this
1999 routine fills in the appropriate fields to make this region as usable as
2000 one returned from RegionCreate. This avoids the additional dynamic memory
2001 allocation overhead for the region structure itself.
2004 <blockquote><programlisting>
2006 Bool pScreen->RegionCopy(dstrgn, srcrgn)
2007 RegionPtr dstrgn, srcrgn;
2009 macro: Bool RegionCopy(dstrgn, srcrgn)
2011 </programlisting></blockquote>
2012 RegionCopy copies the description of one region, srcrgn, to another
2013 already-created region,
2014 dstrgn; returning TRUE if the copy succeeded, and FALSE otherwise.</para>
2016 <blockquote><programlisting>
2018 void pScreen->RegionDestroy( pRegion)
2021 macro: RegionDestroy(pRegion)
2023 </programlisting></blockquote>
2024 RegionDestroy destroys a region and frees all allocated memory.</para>
2026 <blockquote><programlisting>
2028 void pScreen->RegionUninit (pRegion)
2031 macro: RegionUninit(pRegion)
2033 </programlisting></blockquote>
2034 Frees everything except the region structure itself, useful when the
2035 region was originally passed to RegionInit instead of received from
2036 RegionCreate. When this call returns, pRegion must not be reused until
2037 it has been RegionInit'ed again.</para>
2039 <blockquote><programlisting>
2041 Bool pScreen->Intersect(newReg, reg1, reg2)
2042 RegionPtr newReg, reg1, reg2;
2044 macro: Bool RegionIntersect(newReg, reg1, reg2)
2046 Bool pScreen->Union(newReg, reg1, reg2)
2047 RegionPtr newReg, reg1, reg2;
2049 macro: Bool RegionUnion(newReg, reg1, reg2)
2051 Bool pScreen->Subtract(newReg, regMinuend, regSubtrahend)
2052 RegionPtr newReg, regMinuend, regSubtrahend;
2054 macro: Bool RegionUnion(newReg, regMinuend, regSubtrahend)
2056 Bool pScreen->Inverse(newReg, pReg, pBox)
2057 RegionPtr newReg, pReg;
2060 macro: Bool RegionInverse(newReg, pReg, pBox)
2062 </programlisting></blockquote>
2063 The above four calls all do basic logical operations on regions. They
2064 set the new region (which already exists) to describe the logical
2065 intersection, union, set difference, or inverse of the region(s) that
2066 were passed in. Your routines must be able to handle a situation
2067 where the newReg is the same region as one of the other region
2070 The subtract function removes the Subtrahend from the Minuend and
2071 puts the result in newReg.</para>
2073 The inverse function returns a region that is the pBox minus the
2074 region passed in. (A true "inverse" would make a region that extends
2075 to infinity in all directions but has holes in the middle.) It is
2076 undefined for situations where the region extends beyond the box.</para>
2078 Each routine must return the value TRUE for success.</para>
2080 <blockquote><programlisting>
2082 void pScreen->RegionReset(pRegion, pBox)
2086 macro: RegionReset(pRegion, pBox)
2088 </programlisting></blockquote>
2089 RegionReset sets the region to describe
2090 one rectangle and reallocates it to a size of one rectangle, if applicable.</para>
2092 <blockquote><programlisting>
2094 void pScreen->TranslateRegion(pRegion, x, y)
2098 macro: RegionTranslate(pRegion, x, y)
2100 </programlisting></blockquote>
2101 TranslateRegion simply moves a region +x in the x direction and +y in the y
2104 <blockquote><programlisting>
2106 int pScreen->RectIn(pRegion, pBox)
2110 macro: int RegionContainsRect(pRegion, pBox)
2112 </programlisting></blockquote>
2113 RectIn returns one of the defined constants rgnIN, rgnOUT, or rgnPART,
2114 depending upon whether the box is entirely inside the region, entirely
2115 outside of the region, or partly in and partly out of the region.
2116 These constants are defined in Xserver/include/region.h.</para>
2118 <blockquote><programlisting>
2120 Bool pScreen->PointInRegion(pRegion, x, y, pBox)
2125 macro: Bool RegionContainsPoint(pRegion, x, y, pBox)
2127 </programlisting></blockquote>
2128 PointInRegion returns true if the point x, y is in the region. In
2129 addition, it fills the rectangle pBox with coordinates of a rectangle
2130 that is entirely inside of pRegion and encloses the point. In the mi
2131 implementation, it is the largest such rectangle. (Due to the sample
2132 server implementation, this comes cheaply.)</para>
2134 This routine used by DIX when tracking the pointing device and
2135 deciding whether to report mouse events or change the cursor. For
2136 instance, DIX needs to change the cursor when it moves from one window
2137 to another. Due to overlapping windows, the shape to check may be
2138 irregular. A PointInRegion() call for every pointing device movement
2139 may be too expensive. The pBox is a kind of wake-up box; DIX need not
2140 call PointInRegion() again until the cursor wanders outside of the
2141 returned box.</para>
2143 <blockquote><programlisting>
2145 Bool pScreen->RegionNotEmpty(pRegion)
2148 macro: Bool RegionNotEmpty(pRegion)
2150 </programlisting></blockquote>
2151 RegionNotEmpty is a boolean function that returns
2152 true or false depending upon whether the region encloses any pixels.</para>
2154 <blockquote><programlisting>
2156 void pScreen->RegionEmpty(pRegion)
2159 macro: RegionEmpty(pRegion)
2161 </programlisting></blockquote>
2162 RegionEmpty sets the region to be empty.</para>
2164 <blockquote><programlisting>
2166 BoxPtr pScreen->RegionExtents(pRegion)
2169 macro: RegionExtents(pRegion)
2171 </programlisting></blockquote>
2172 RegionExtents returns a rectangle that is the smallest
2173 possible superset of the entire region.
2174 The caller will not modify this rectangle, so it can be the one
2175 in your region struct.</para>
2177 <blockquote><programlisting>
2179 Bool pScreen->RegionAppend (pDstRgn, pRegion)
2183 macro: Bool RegionAppend(pDstRgn, pRegion)
2185 Bool pScreen->RegionValidate (pRegion, pOverlap)
2189 macro: Bool RegionValidate(pRegion, pOverlap)
2191 </programlisting></blockquote>
2192 These functions provide an optimization for clip list generation and
2193 must be used in conjunction. The combined effect is to produce the
2194 union of a collection of regions, by using RegionAppend several times,
2195 and finally calling RegionValidate which takes the intermediate
2196 representation (which needn't be a valid region) and produces the
2197 desired union. pOverlap is set to TRUE if any of the original
2198 regions overlap; FALSE otherwise.</para>
2200 <blockquote><programlisting>
2202 RegionPtr pScreen->BitmapToRegion (pPixmap)
2205 macro: RegionPtr BitmapToRegion(pScreen, pPixmap)
2207 </programlisting></blockquote>
2208 Given a depth-1 pixmap, this routine must create a valid region which
2209 includes all the areas of the pixmap filled with 1's and excludes the
2210 areas filled with 0's. This routine returns NULL if out of memory.</para>
2212 <blockquote><programlisting>
2214 RegionPtr pScreen->RectsToRegion (nrects, pRects, ordering)
2219 macro: RegionPtr RegionFromRects(nrects, pRects, ordering)
2221 </programlisting></blockquote>
2222 Given a client-supplied list of rectangles, produces a region which includes
2223 the union of all the rectangles. Ordering may be used as a hint which
2224 describes how the rectangles are sorted. As the hint is provided by a
2225 client, it must not be required to be correct, but the results when it is
2226 not correct are not defined (core dump is not an option here).</para>
2228 <blockquote><programlisting>
2230 void pScreen->SendGraphicsExpose(client,pRegion,drawable,major,minor)
2237 </programlisting></blockquote>
2238 SendGraphicsExpose dispatches a list of GraphicsExposure events which
2239 span the region to the specified client. If the region is empty, or
2240 a NULL pointer, a NoExpose event is sent instead.</para>
2243 <title>Cursor Routines for a Screen</title>
2245 A cursor is the visual form tied to the pointing device. The default
2246 cursor is an "X" shape, but the cursor can have any shape. When a
2247 client creates a window, it declares what shape the cursor will be
2248 when it strays into that window on the screen.</para>
2250 For each possible shape the cursor assumes, there is a CursorRec data
2251 structure. This data structure contains a pointer to a CursorBits
2252 data structure which contains a bitmap for the image of the cursor and
2253 a bitmap for a mask behind the cursor, in addition, the CursorRec data
2254 structure contains foreground and background colors for the cursor.
2255 The CursorBits data structure is shared among multiple CursorRec
2256 structures which use the same font and glyph to describe both source
2257 and mask. The cursor image is applied to the screen by applying the
2258 mask first, clearing 1 bits in its form to the background color, and
2259 then overwriting on the source image, in the foreground color. (One
2260 bits of the source image that fall on top of zero bits of the mask
2261 image are undefined.) This way, a cursor can have transparent parts,
2262 and opaque parts in two colors. X allows any cursor size, but some
2263 hardware cursor schemes allow a maximum of N pixels by M pixels.
2264 Therefore, you are allowed to transform the cursor to a smaller size,
2265 but be sure to include the hot-spot.</para>
2267 CursorBits in Xserver/include/cursorstr.h is a device-independent
2268 structure containing a device-independent representation of the bits
2269 for the source and mask. (This is possible because the bitmap
2270 representation is the same for all screens.)</para>
2272 When a cursor is created, it is "realized" for each screen. At
2273 realization time, each screen has the chance to convert the bits into
2274 some other representation that may be more convenient (for instance,
2275 putting the cursor into off-screen memory) and set up its
2276 device-private area in either the CursorRec data structure or
2277 CursorBits data structure as appropriate to possibly point to whatever
2278 data structures are needed. It is more memory-conservative to share
2279 realizations by using the CursorBits private field, but this makes the
2280 assumption that the realization is independent of the colors used
2281 (which is typically true). For instance, the following are the device
2282 private entries for a particular screen and cursor:
2283 <blockquote><programlisting>
2285 pCursor->devPriv[pScreen->myNum]
2286 pCursor->bits->devPriv[pScreen->myNum]
2288 </programlisting></blockquote>
2289 This is done because the change from one cursor shape to another must
2290 be fast and responsive; the cursor image should be able to flutter as
2291 fast as the user moves it across the screen.</para>
2293 You must implement the following routines for your hardware:
2294 <blockquote><programlisting>
2296 Bool pScreen->RealizeCursor( pScr, pCurs)
2300 Bool pScreen->UnrealizeCursor( pScr, pCurs)
2304 </programlisting></blockquote>
2307 RealizeCursor and UnrealizeCursor should realize (allocate and
2308 calculate all data needed) and unrealize (free the dynamically
2309 allocated data) a given cursor when DIX needs them. They are called
2310 whenever a device-independent cursor is created or destroyed. The
2311 source and mask bits pointed to by fields in pCurs are undefined for
2312 bits beyond the right edge of the cursor. This is so because the bits
2313 are in Bitmap format, which may have pad bits on the right edge. You
2314 should inhibit UnrealizeCursor() if the cursor is currently in use;
2315 this happens when the system is reset.</para>
2317 <blockquote><programlisting>
2319 Bool pScreen->DisplayCursor( pScr, pCurs)
2323 </programlisting></blockquote>
2324 DisplayCursor should change the cursor on the given screen to the one
2325 passed in. It is called by DIX when the user moves the pointing
2326 device into a different window with a different cursor. The hotspot
2327 in the cursor should be aligned with the current cursor position.</para>
2329 <blockquote><programlisting>
2331 void pScreen->RecolorCursor( pScr, pCurs, displayed)
2335 </programlisting></blockquote>
2336 RecolorCursor notifies DDX that the colors in pCurs have changed and
2337 indicates whether this is the cursor currently being displayed. If it
2338 is, the cursor hardware state may have to be updated. Whether
2339 displayed or not, state created at RealizeCursor time may have to be
2340 updated. A generic version, miRecolorCursor, may be used that
2341 does an unrealize, a realize, and possibly a display (in micursor.c);
2342 however this constrains UnrealizeCursor and RealizeCursor to always return
2343 TRUE as no error indication is returned here.</para>
2345 <blockquote><programlisting>
2347 void pScreen->ConstrainCursor( pScr, pBox)
2351 </programlisting></blockquote>
2352 ConstrainCursor should cause the cursor to restrict its motion to the
2353 rectangle pBox. DIX code is capable of enforcing this constraint by
2354 forcefully moving the cursor if it strays out of the rectangle, but
2355 ConstrainCursor offers a way to send a hint to the driver or hardware
2356 if such support is available. This can prevent the cursor from
2357 wandering out of the box, then jumping back, as DIX forces it back.</para>
2359 <blockquote><programlisting>
2361 void pScreen->PointerNonInterestBox( pScr, pBox)
2365 </programlisting></blockquote>
2366 PointerNonInterestBox is DIX's way of telling the pointing device code
2367 not to report motion events while the cursor is inside a given
2368 rectangle on the given screen. It is optional and, if not
2369 implemented, it should do nothing. This routine is called only when
2370 the client has declared that it is not interested in motion events in
2371 a given window. The rectangle you get may be a subset of that window.
2372 It saves DIX code the time required to discard uninteresting mouse
2373 motion events. This is only a hint, which may speed performance.
2374 Nothing in DIX currently calls PointerNonInterestBox.</para>
2376 <blockquote><programlisting>
2378 void pScreen->CursorLimits( pScr, pCurs, pHotBox, pTopLeftBox)
2382 BoxPtr pTopLeftBox; /* return value */
2384 </programlisting></blockquote>
2385 CursorLimits should calculate the box that the cursor hot spot is
2386 physically capable of moving within, as a function of the screen pScr,
2387 the device-independent cursor pCurs, and a box that DIX hypothetically
2388 would want the hot spot confined within, pHotBox. This routine is for
2389 informing DIX only; it alters no state within DDX.</para>
2391 <blockquote><programlisting>
2393 Bool pScreen->SetCursorPosition( pScr, newx, newy, generateEvent)
2399 </programlisting></blockquote>
2400 SetCursorPosition should artificially move the cursor as though the
2401 user had jerked the pointing device very quickly. This is called in
2402 response to the WarpPointer request from the client, and at other
2403 times. If generateEvent is True, the device should decide whether or
2404 not to call ProcessInputEvents() and then it must call
2405 DevicePtr->processInputProc. Its effects are, of course, limited in
2406 value for absolute pointing devices such as a tablet.</para>
2408 <blockquote><programlisting>
2410 void NewCurrentScreen(newScreen, x, y)
2411 ScreenPtr newScreen;
2414 </programlisting></blockquote>
2415 If your ddx provides some mechanism for the user to magically move the
2416 pointer between multiple screens, you need to inform DIX when this
2417 occurs. You should call NewCurrentScreen to accomplish this, specifying
2418 the new screen and the new x and y coordinates of the pointer on that screen.</para>
2421 <title>Visuals, Depths and Pixmap Formats for Screens</title>
2423 The "depth" of a image is the number of bits that are used per pixel to display it.</para>
2425 The "bits per pixel" of a pixmap image that is sent over the client
2426 byte stream is a number that is either 4, 8, 16, 24 or 32. It is the
2427 number of bits used per pixel in Z format. For instance, a pixmap
2428 image that has a depth of six is best sent in Z format as 8 bits per
2431 A "pixmap image format" or a "pixmap format" is a description of the
2432 format of a pixmap image as it is sent over the byte stream. For each
2433 depth available on a server, there is one and only one pixmap format.
2434 This pixmap image format gives the bits per pixel and the scanline
2435 padding unit. (For instance, are pixel rows padded to bytes, 16-bit
2436 words, or 32-bit words?)</para>
2438 For each screen, you must decide upon what depth(s) it supports. You
2439 should only count the number of bits used for the actual image. Some
2440 displays store additional bits to indicate what window this pixel is
2441 in, how close this object is to a viewer, transparency, and other
2442 data; do not count these bits.</para>
2444 A "display class" tells whether the display is monochrome or color,
2445 whether there is a lookup table, and how the lookup table works.</para>
2447 A "visual" is a combination of depth, display class, and a description
2448 of how the pixel values result in a color on the screen. Each visual
2449 has a set of masks and offsets that are used to separate a pixel value
2450 into its red, green, and blue components and a count of the number of
2451 colormap entries. Some of these fields are only meaningful when the
2452 class dictates so. Each visual also has a screen ID telling which
2453 screen it is usable on. Note that the depth does not imply the number
2454 of map_entries; for instance, a display can have 8 bits per pixel but
2455 only 254 colormap entries for use by applications (the other two being
2456 reserved by hardware for the cursor).</para>
2458 Each visual is identified by a 32-bit visual ID which the client uses
2459 to choose what visual is desired on a given window. Clients can be
2460 using more than one visual on the same screen at the same time.</para>
2462 The class of a display describes how this translation takes place.
2463 There are three ways to do the translation.
2466 Pseudo - The pixel value, as a whole, is looked up
2467 in a table of length map_entries to
2468 determine the color to display.</para></listitem>
2471 pixel value is broken up into red, green, and blue fields, each of which
2472 are looked up in separate red, green, and blue lookup tables,
2473 each of length map_entries.</para></listitem>
2475 Gray - The pixel value is looked up in a table of length map_entries to
2476 determine a gray level to display.</para></listitem>
2480 In addition, the lookup table can be static (resulting colors are fixed for each
2482 or dynamic (lookup entries are under control of the client program).
2483 This leads to a total of six classes:
2486 Static Gray - The pixel value (of however many bits) determines directly the
2488 that the pixel assumes.</para></listitem>
2490 Gray Scale - The pixel value is fed through a lookup table to arrive at the level
2492 for the given pixel.</para></listitem>
2494 Static Color - The pixel value is fed through a fixed lookup table that yields the
2496 for that pixel.</para></listitem>
2498 PseudoColor - The whole pixel value is fed through a programmable lookup
2500 color (including red, green, and blue intensities) for each possible pixel value,
2501 and that color is displayed.</para></listitem>
2503 True Color - Each pixel value consists of one or more bits
2504 that directly determine each primary color intensity after being fed through
2505 a fixed table.</para></listitem>
2507 Direct Color - Each pixel value consists of one or more bits for each primary color.
2508 Each primary color value is individually looked up in a table for that primary
2510 an intensity for that primary color.
2511 For each pixel, the red value is looked up in the
2512 red table, the green value in the green table, and
2513 the blue value in the blue table.</para></listitem>
2517 Here are some examples:
2520 A simple monochrome 1 bit per pixel display is Static Gray.</para></listitem>
2522 A display that has 2 bits per pixel for a choice
2523 between the colors of black, white, green and violet is Static Color.</para></listitem>
2525 A display that has three bits per pixel, where
2526 each bit turns on or off one of the red, green or
2527 blue guns, is in the True Color class.</para></listitem>
2529 If you take the last example and scramble the
2530 correspondence between pixel values and colors
2531 it becomes a Static Color display.</para></listitem>
2532 </itemizedlist></para>
2534 A display has 8 bits per pixel. The 8 bits select one entry out of 256 entries
2535 in a lookup table, each entry consisting of 24 bits (8bits each for red, green,
2537 The display can show any 256 of 16 million colors on the screen at once.
2538 This is a pseudocolor display.
2539 The client application gets to fill the lookup table in this class of display.</para>
2541 Imagine the same hardware from the last example.
2542 Your server software allows the user, on the
2543 command line that starts up the server
2545 to fill the lookup table to his liking once and for all.
2546 From then on, the server software would not change the lookup table
2548 For instance, the default might be a lookup table with a reasonable sample of
2549 colors from throughout the color space.
2550 But the user could specify that the table be filled with 256 steps of gray scale
2551 because he knew ahead of time he would be manipulating a lot of black-and-white
2553 and not very many color things.
2554 Clients would be presented with this unchangeable lookup table.
2555 Although the hardware qualifies as a PseudoColor display,
2556 the facade presented to the X client is that this is a Static Color display.</para>
2558 You have to decide what kind of display you have or want
2559 to pretend you have.
2560 When you initialize the screen(s), this class value must be set in the
2561 VisualRec data structure along with other display characteristics like the
2562 depth and other numbers.</para>
2564 The allowable DepthRec's and VisualRec's are pointed to by fields in the ScreenRec.
2565 These are set up when InitOutput() is called; you should malloc() appropriate blocks
2566 or use static variables initialized to the correct values.</para>
2569 <title>Colormaps for Screens</title>
2571 A colormap is a device-independent
2572 mapping between pixel values and colors displayed on the screen.</para>
2574 Different windows on the same screen can have different
2575 colormaps at the same time.
2576 At any given time, the most recently installed
2577 colormap(s) will be in use in the server
2578 so that its (their) windows' colors will be guaranteed to be correct.
2579 Other windows may be off-color.
2580 Although this may seem to be chaotic, in practice most clients
2581 use the default colormap for the screen.</para>
2583 The default colormap for a screen is initialized when the screen is initialized.
2584 It always remains in existence and is not owned by any regular client. It
2585 is owned by client 0 (the server itself).
2586 Many clients will simply use this default colormap for their drawing.
2587 Depending upon the class of the screen, the entries in this colormap may
2588 be modifiable by client applications.</para>
2591 <title>Colormap Routines</title>
2593 You need to implement the following routines to handle the device-dependent
2594 aspects of color maps. You will end up placing pointers to these procedures
2595 in your ScreenRec data structure(s). The sample server implementations of
2596 many of these routines are in fbcmap.c.</para>
2598 <blockquote><programlisting>
2600 Bool pScreen->CreateColormap(pColormap)
2601 ColormapPtr pColormap;
2603 </programlisting></blockquote>
2604 This routine is called by the DIX CreateColormap routine after it has allocated
2605 all the data for the new colormap and just before it returns to the dispatcher.
2606 It is the DDX layer's chance to initialize the colormap, particularly if it is
2607 a static map. See the following
2608 section for more details on initializing colormaps.
2609 The routine returns FALSE if creation failed, such as due to memory
2611 Notice that the colormap has a devPriv field from which you can hang any
2612 colormap specific storage you need. Since each colormap might need special
2613 information, we attached the field to the colormap and not the visual.</para>
2615 <blockquote><programlisting>
2617 void pScreen->DestroyColormap(pColormap)
2618 ColormapPtr pColormap;
2620 </programlisting></blockquote>
2621 This routine is called by the DIX FreeColormap routine after it has uninstalled
2622 the colormap and notified all interested parties, and before it has freed
2623 any of the colormap storage.
2624 It is the DDX layer's chance to free any data it added to the colormap.</para>
2626 <blockquote><programlisting>
2628 void pScreen->InstallColormap(pColormap)
2629 ColormapPtr pColormap;
2631 </programlisting></blockquote>
2632 InstallColormap should
2633 fill a lookup table on the screen with which the colormap is associated with
2634 the colors in pColormap.
2635 If there is only one hardware lookup table for the screen, then all colors on
2636 the screen may change simultaneously.</para>
2638 In the more general case of multiple hardware lookup tables,
2639 this may cause some other colormap to be
2640 uninstalled, meaning that windows that subscribed to the colormap
2641 that was uninstalled may end up being off-color.
2642 See the note, below, about uninstalling maps.</para>
2644 <blockquote><programlisting>
2646 void pScreen->UninstallColormap(pColormap)
2647 ColormapPtr pColormap;
2649 </programlisting></blockquote>
2650 UninstallColormap should
2651 remove pColormap from screen pColormap->pScreen.
2652 Some other map, such as the default map if possible,
2653 should be installed in place of pColormap if applicable.
2655 pColormap is the default map, do nothing.
2656 If any client has requested ColormapNotify events, the DDX layer must notify the client.
2657 (The routine WalkTree() is
2658 be used to find such windows. The DIX routines TellNoMap(),
2659 TellNewMap() and TellGainedMap() are provided to be used as
2660 the procedure parameter to WalkTree. These procedures are in
2661 Xserver/dix/colormap.c.)</para>
2663 <blockquote><programlisting>
2665 int pScreen->ListInstalledColormaps(pScreen, pCmapList)
2670 </programlisting></blockquote>
2671 ListInstalledColormaps fills the pCmapList in with the resource ids
2672 of the installed maps and returns a count of installed maps.
2673 pCmapList will point to an array of size MaxInstalledMaps that was allocated
2674 by the caller.</para>
2676 <blockquote><programlisting>
2678 void pScreen->StoreColors (pmap, ndef, pdefs)
2683 </programlisting></blockquote>
2684 StoreColors changes some of the entries in the colormap pmap.
2685 The number of entries to change are ndef, and pdefs points to the information
2686 describing what to change.
2687 Note that partial changes of entries in the colormap are allowed.
2689 indicated in the flags field of each xColorItem need to be changed.
2690 However, all three color fields will be sent with the proper value for the
2691 benefit of screens that may not be able to set part of a colormap value.
2692 If the screen is a static class, this routine does nothing.
2693 The structure of colormap entries is nontrivial; see colormapst.h
2694 and the definition of xColorItem in Xproto.h for
2695 more details.</para>
2697 <blockquote><programlisting>
2699 void pScreen->ResolveColor(pRed, pGreen, pBlue, pVisual)
2700 unsigned short *pRed, *pGreen, *pBlue;
2704 </programlisting></blockquote>
2705 Given a requested color, ResolveColor returns the nearest color that this hardware is
2706 capable of displaying on this visual.
2707 In other words, this rounds off each value, in place, to the number of bits
2708 per primary color that your screen can use.
2709 Remember that each screen has one of these routines.
2710 The level of roundoff should be what you would expect from the value
2711 you put in the bits_per_rgb field of the pVisual.</para>
2713 Each value is an unsigned value ranging from 0 to 65535.
2714 The bits least likely to be used are the lowest ones.</para>
2716 For example, if you had a pseudocolor display
2717 with any number of bits per pixel
2718 that had a lookup table supplying 6 bits for each color gun
2719 (a total of 256K different colors), you would
2720 round off each value to 6 bits. Please don't simply truncate these values
2721 to the upper 6 bits, scale the result so that the maximum value seen
2722 by the client will be 65535 for each primary. This makes color values
2723 more portable between different depth displays (a 6-bit truncated white
2724 will not look white on an 8-bit display).</para>
2726 <title>Initializing a Colormap</title>
2728 When a client requests a new colormap and when the server creates the default
2729 colormap, the procedure CreateColormap in the DIX layer is invoked.
2730 That procedure allocates memory for the colormap and related storage such as
2731 the lists of which client owns which pixels.
2732 It then sets a bit, BeingCreated, in the flags field of the ColormapRec
2733 and calls the DDX layer's CreateColormap routine.
2734 This is your chance to initialize the colormap.
2735 If the colormap is static, which you can tell by looking at the class field,
2736 you will want to fill in each color cell to match the hardwares notion of the
2737 color for that pixel.
2738 If the colormap is the default for the screen, which you can tell by looking
2739 at the CM_IsDefault bit in the flags field, you should allocate BlackPixel
2740 and WhitePixel to match the values you set in the pScreen structure.
2741 (Of course, you picked those values to begin with.)</para>
2743 You can also wait and use AllocColor() to allocate blackPixel
2744 and whitePixel after the default colormap has been created.
2745 If the default colormap is static and you initialized it in
2746 pScreen->CreateColormap, then use can use AllocColor afterwards
2747 to choose pixel values with the closest rgb values to those
2748 desired for blackPixel and whitePixel.
2749 If the default colormap is dynamic and uninitialized, then
2750 the rgb values you request will be obeyed, and AllocColor will
2751 again choose pixel values for you.
2752 These pixel values can then be stored into the screen.</para>
2754 There are two ways to fill in the colormap.
2755 The simplest way is to use the DIX function AllocColor.
2756 <blockquote><programlisting>
2758 int AllocColor (pmap, pred, pgreen, pblue, pPix, client)
2760 unsigned short *pred, *pgreen, *pblue;
2764 </programlisting></blockquote>
2765 This takes three pointers to 16 bit color values and a pointer to a suggested
2766 pixel value. The pixel value is either an index into one colormap or a
2767 combination of three indices depending on the type of pmap.
2768 If your colormap starts out empty, and you don't deliberately pick the same
2769 value twice, you will always get your suggested pixel.
2770 The truly nervous could check that the value returned in *pPix is the one
2771 AllocColor was called with.
2772 If you don't care which pixel is used, or would like them sequentially
2773 allocated from entry 0, set *pPix to 0. This will find the first free
2774 pixel and use that.</para>
2776 AllocColor will take care of all the bookkeeping and will
2777 call StoreColors to get the colormap rgb values initialized.
2778 The hardware colormap will be changed whenever this colormap
2779 is installed.</para>
2781 If for some reason AllocColor doesn't do what you want, you can do your
2782 own bookkeeping and call StoreColors yourself. This is much more difficult
2783 and shouldn't be necessary for most devices.</para>
2787 <title>Fonts for Screens</title>
2789 A font is a set of bitmaps that depict the symbols in a character set.
2790 Each font is for only one typeface in a given size, in other words,
2791 just one bitmap for each character. Parallel fonts may be available
2792 in a variety of sizes and variations, including "bold" and "italic."
2793 X supports fonts for 8-bit and 16-bit character codes (for oriental
2794 languages that have more than 256 characters in the font). Glyphs are
2795 bitmaps for individual characters.</para>
2797 The source comes with some useful font files in an ASCII, plain-text
2798 format that should be comprehensible on a wide variety of operating
2799 systems. The text format, referred to as BDF, is a slight extension
2800 of the current Adobe 2.1 Bitmap Distribution Format (Adobe Systems,
2803 A short paper in PostScript format is included with the sample server
2804 that defines BDF. It includes helpful pictures, which is why it is
2805 done in PostScript and is not included in this document.</para>
2807 Your implementation should include some sort of font compiler to read
2808 these files and generate binary files that are directly usable by your
2809 server implementation. The sample server comes with the source for a
2810 font compiler.</para>
2812 It is important the font properties contained in the BDF files are
2813 preserved across any font compilation. In particular, copyright
2814 information cannot be casually tossed aside without legal
2815 ramifications. Other properties will be important to some
2816 sophisticated applications.</para>
2818 All clients get font information from the server. Therefore, your
2819 server can support any fonts it wants to. It should probably support
2820 at least the fonts supplied with the X11 tape. In principle, you can
2821 convert fonts from other sources or dream up your own fonts for use on
2824 <title>Portable Compiled Format</title>
2826 A font compiler is supplied with the sample server. It has
2827 compile-time switches to convert the BDF files into a portable binary
2828 form, called Portable Compiled Format or PCF. This allows for an
2829 arbitrary data format inside the file, and by describing the details
2830 of the format in the header of the file, any PCF file can be read by
2831 any PCF reading client. By selecting the format which matches the
2832 required internal format for your renderer, the PCF reader can avoid
2833 reformatting the data each time it is read in. The font compiler
2834 should be quite portable.</para>
2836 The fonts included with the tape are stored in fonts/bdf. The
2837 font compiler is found in fonts/tools/bdftopcf.</para>
2840 <title>Font Realization</title>
2842 Each screen configured into the server
2843 has an opportunity at font-load time
2844 to "realize" a font into some internal format if necessary.
2845 This happens every time the font is loaded into memory.</para>
2847 A font (FontRec in Xserver/include/dixfontstr.h) is
2848 a device-independent structure containing a device-independent
2849 representation of the font. When a font is created, it is "realized"
2850 for each screen. At this point, the screen has the chance to convert
2851 the font into some other format. The DDX layer can also put information
2852 in the devPrivate storage.</para>
2854 <blockquote><programlisting>
2856 Bool pScreen->RealizeFont(pScr, pFont)
2860 Bool pScreen->UnrealizeFont(pScr, pFont)
2864 </programlisting></blockquote>
2865 RealizeFont and UnrealizeFont should calculate and allocate these extra data structures and
2866 dispose of them when no longer needed.
2867 These are called in response to OpenFont and CloseFont requests from
2869 The sample server implementation is in fbscreen.c (which does very little).</para>
2873 <title>Other Screen Routines</title>
2875 You must supply several other screen-specific routines for
2876 your X server implementation.
2877 Some of these are described in other sections:
2880 GetImage() is described in the Drawing Primitives section.</para></listitem>
2882 GetSpans() is described in the Pixblit routine section.</para></listitem>
2884 Several window and pixmap manipulation procedures are
2885 described in the Window section under Drawables.</para></listitem>
2887 The CreateGC() routine is described under Graphics Contexts.</para></listitem>
2891 <blockquote><programlisting>
2893 void pScreen->QueryBestSize(kind, pWidth, pHeight)
2895 unsigned short *pWidth, *pHeight;
2898 </programlisting></blockquote>
2899 QueryBestSize() returns the best sizes for cursors, tiles, and stipples
2900 in response to client requests.
2901 kind is one of the defined constants CursorShape, TileShape, or StippleShape
2903 For CursorShape, return the maximum width and
2904 height for cursors that you can handle.
2905 For TileShape and StippleShape, start with the suggested values in pWidth
2906 and pHeight and modify them in place to be optimal values that are
2907 greater than or equal to the suggested values.
2908 The sample server implementation is in Xserver/fb/fbscreen.c.</para>
2910 <blockquote><programlisting>
2912 pScreen->SourceValidate(pDrawable, x, y, width, height)
2913 DrawablePtr pDrawable;
2914 int x, y, width, height;
2915 unsigned int subWindowMode;
2917 </programlisting></blockquote>
2918 SourceValidate should be called by any primitive that reads from pDrawable.
2920 you will never need SourceValidate, you can avoid this check. Currently,
2921 SourceValidate is used by the mi software cursor code to remove the cursor
2922 from the screen when the source rectangle overlaps the cursor position.
2923 x,y,width,height describe the source rectangle (source relative, that is)
2924 for the copy operation. subWindowMode comes from the GC or source Picture.
2927 <blockquote><programlisting>
2929 Bool pScreen->SaveScreen(pScreen, on)
2933 </programlisting></blockquote>
2934 SaveScreen() is used for Screen Saver support (see WaitForSomething()).
2935 pScreen is the screen to save.</para>
2937 <blockquote><programlisting>
2939 Bool pScreen->CloseScreen(pScreen)
2942 </programlisting></blockquote>
2943 When the server is reset, it calls this routine for each screen.</para>
2945 <blockquote><programlisting>
2947 Bool pScreen->CreateScreenResources(pScreen)
2950 </programlisting></blockquote>
2951 If this routine is not NULL, it will be called once per screen per
2952 server initialization/reset after all modules have had a chance to
2953 request private space on all structures that support them (see
2954 <xref linkend="wrappers_and_privates"/> below). You may create resources
2955 in this function instead of in the
2956 screen init function passed to AddScreen in order to guarantee that
2957 all pre-allocated space requests have been registered first. With the
2958 new devPrivates mechanism, this is not strictly necessary, however.
2959 This routine returns TRUE if successful.</para>
2963 <title>Drawables</title>
2965 A drawable is a descriptor of a surface that graphics are drawn into, either
2966 a window on the screen or a pixmap in memory.</para>
2968 Each drawable has a type, class,
2969 ScreenPtr for the screen it is associated with, depth, position, size,
2971 The type is one of the defined constants DRAWABLE_PIXMAP,
2972 DRAWABLE_WINDOW and UNDRAWABLE_WINDOW.
2973 (An undrawable window is used for window class InputOnly.)
2974 The serial number is guaranteed to be unique across drawables, and
2975 is used in determining
2976 the validity of the clipping information in a GC.
2977 The screen selects the set of procedures used to manipulate and draw into the
2978 drawable. Position is used (currently) only by windows; pixmaps must
2979 set these fields to 0,0 as this reduces the amount of conditional code
2980 executed throughout the mi code. Size indicates the actual client-specified
2981 size of the drawable.
2982 There are, in fact, no other fields that a window drawable and pixmap
2983 drawable have in common besides those mentioned here.</para>
2985 Both PixmapRecs and WindowRecs are structs that start with a drawable
2986 and continue on with more fields. Pixmaps have a single pointer field
2987 named devPrivate which usually points to the pixmap data but could conceivably be
2988 used for anything that DDX wants. Both windows and pixmaps also have a
2989 devPrivates field which can be used for DDX specific data (see <xref linkend="wrappers_and_privates"/>
2990 below). This is done because different graphics hardware has
2991 different requirements for management; if the graphics is always
2992 handled by a processor with an independent address space, there is no
2993 point having a pointer to the bit image itself.</para>
2995 The definition of a drawable and a pixmap can be found in the file
2996 Xserver/include/pixmapstr.h.
2997 The definition of a window can be found in the file Xserver/include/windowstr.h.</para>
2999 <title>Pixmaps</title>
3001 A pixmap is a three-dimensional array of bits stored somewhere offscreen,
3002 rather than in the visible portion of the screen's display frame buffer. It
3003 can be used as a source or destination in graphics operations. There is no
3004 implied interpretation of the pixel values in a pixmap, because it has no
3005 associated visual or colormap. There is only a depth that indicates the
3006 number of significant bits per pixel. Also, there is no implied physical
3007 size for each pixel; all graphic units are in numbers of pixels. Therefore,
3008 a pixmap alone does not constitute a complete image; it represents only a
3009 rectangular array of pixel values.</para>
3011 Note that the pixmap data structure is reference-counted.</para>
3013 The server implementation is free to put the pixmap data
3014 anywhere it sees fit, according to its graphics hardware setup. Many
3015 implementations will simply have the data dynamically allocated in the
3016 server's address space. More sophisticated implementations may put the
3017 data in undisplayed framebuffer storage.</para>
3019 In addition to dynamic devPrivates (see <xref linkend="wrappers_and_privates"/>
3020 below), the pixmap data structure has two fields that are private to
3021 the device. Although you can use them for anything you want, they
3022 have intended purposes. devKind is intended to be a device specific
3023 indication of the pixmap location (host memory, off-screen, etc.). In
3024 the sample server, since all pixmaps are in memory, devKind stores the
3025 width of the pixmap in bitmap scanline units. devPrivate is usually
3026 a pointer to the bits in the pixmap.</para>
3028 A bitmap is a pixmap that is one bit deep.</para>
3030 <blockquote><programlisting>
3032 PixmapPtr pScreen->CreatePixmap(pScreen, width, height, depth)
3034 int width, height, depth;
3036 </programlisting></blockquote>
3037 This ScreenRec procedure must create a pixmap of the size
3039 It must allocate a PixmapRec and fill in all of the fields.
3040 The reference count field must be set to 1.
3041 If width or height are zero, no space should be allocated
3042 for the pixmap data, and if the implementation is using the
3043 devPrivate field as a pointer to the pixmap data, it should be
3045 If successful, it returns a pointer to the new pixmap; if not, it returns NULL.
3046 See Xserver/fb/fbpixmap.c for the sample server implementation.</para>
3048 <blockquote><programlisting>
3050 Bool pScreen->DestroyPixmap(pPixmap)
3053 </programlisting></blockquote>
3054 This ScreenRec procedure must "destroy" a pixmap.
3055 It should decrement the reference count and, if zero, it
3056 must deallocate the PixmapRec and all attached devPrivate blocks.
3057 If successful, it returns TRUE.
3058 See Xserver/fb/fbpixmap.c for the sample server implementation.</para>
3060 <blockquote><programlisting>
3063 pScreen->ModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind, pPixData)
3072 </programlisting></blockquote>
3073 This routine takes a pixmap header and initializes the fields of the PixmapRec to the
3074 parameters of the same name. pPixmap must have been created via
3075 pScreen->CreatePixmap with a zero width or height to avoid
3076 allocating space for the pixmap data. pPixData is assumed to be the
3077 pixmap data; it will be stored in an implementation-dependent place
3078 (usually pPixmap->devPrivate.ptr). This routine returns
3079 TRUE if successful. See Xserver/mi/miscrinit.c for the sample
3080 server implementation.</para>
3082 <blockquote><programlisting>
3085 GetScratchPixmapHeader(pScreen, width, height, depth, bitsPerPixel, devKind, pPixData)
3094 void FreeScratchPixmapHeader(pPixmap)
3097 </programlisting></blockquote>
3098 DDX should use these two DIX routines when it has a buffer of raw
3099 image data that it wants to manipulate as a pixmap temporarily,
3100 usually so that some other part of the server can be leveraged to
3101 perform some operation on the data. The data should be passed in
3102 pPixData, and will be stored in an implementation-dependent place
3103 (usually pPixmap->devPrivate.ptr). The other
3104 fields go into the corresponding PixmapRec fields.
3105 If successful, GetScratchPixmapHeader returns a valid PixmapPtr which can
3106 be used anywhere the server expects a pixmap, else
3107 it returns NULL. The pixmap should be released when no longer needed
3108 (usually within the same function that allocated it)
3109 with FreeScratchPixmapHeader.</para>
3112 <title>Windows</title>
3114 A window is a visible, or potentially visible, rectangle on the screen.
3115 DIX windowing functions maintain an internal n-ary tree data structure, which
3116 represents the current relationships of the mapped windows.
3117 Windows that are contained in another window are children of that window and
3118 are clipped to the boundaries of the parent.
3119 The root window in the tree is the window for the entire screen.
3120 Sibling windows constitute a doubly-linked list; the parent window has a pointer
3121 to the head and tail of this list.
3122 Each child also has a pointer to its parent.</para>
3124 The border of a window is drawn by a DDX procedure when DIX requests that it
3125 be drawn. The contents of the window is drawn by the client through
3126 requests to the server.</para>
3128 Window painting is orchestrated through an expose event system.
3129 When a region is exposed,
3130 DIX generates an expose event, telling the client to repaint the window and
3131 passing the region that is the minimal area needed to be repainted.</para>
3133 As a favor to clients, the server may retain
3134 the output to the hidden parts of windows
3135 in off-screen memory; this is called "backing store".
3136 When a part of such a window becomes exposed, it
3137 can quickly move pixels into place instead of
3138 triggering an expose event and waiting for a client on the other
3139 end of the network to respond.
3140 Even if the network response is insignificant, the time to
3141 intelligently paint a section of a window is usually more than
3142 the time to just copy already-painted sections.
3143 At best, the repainting involves blanking out the area to a background color,
3144 which will take about the
3145 same amount of time.
3146 In this way, backing store can dramatically increase the
3147 performance of window moves.</para>
3149 On the other hand, backing store can be quite complex, because
3150 all graphics drawn to hidden areas must be intercepted and redirected
3151 to the off-screen window sections.
3152 Not only can this be complicated for the server programmer,
3153 but it can also impact window painting performance.
3154 The backing store implementation can choose, at any time, to
3155 forget pieces of backing that are written into, relying instead upon
3156 expose events to repaint for simplicity.</para>
3158 In X, the decision to use the backing-store scheme is made
3159 by you, the server implementor. The sample server implements
3160 backing store "for free" by reusing the infrastructure for the Composite
3161 extension. As a side effect, it treats the WhenMapped and Always hints
3162 as equivalent. However, it will never forget pixel contents when the
3163 window is mapped.</para>
3165 When a window operation is requested by the client,
3166 such as a window being created or moved,
3167 a new state is computed.
3168 During this transition, DIX informs DDX what rectangles in what windows are about to
3169 become obscured and what rectangles in what windows have become exposed.
3170 This provides a hook for the implementation of backing store.
3171 If DDX is unable to restore exposed regions, DIX generates expose
3172 events to the client.
3173 It is then the client's responsibility to paint the
3174 window parts that were exposed but not restored.</para>
3176 If a window is resized, pixels sometimes need to be
3177 moved, depending upon
3179 The client can request "Gravity" so that
3180 certain blocks of the window are
3181 moved as a result of a resize.
3182 For instance, if the window has controls or other items
3183 that always hang on the edge of the
3184 window, and that edge is moved as a result of the resize,
3185 then those pixels should be moved
3186 to avoid having the client repaint it.
3187 If the client needs to repaint it anyway, such an operation takes
3188 time, so it is desirable
3189 for the server to approximate the appearance of the window as best
3190 it can while waiting for the client
3192 Gravity is used for that, also.</para>
3194 The window has several fields used in drawing
3198 clipList - This region, in conjunction with
3199 the client clip region in the gc, is used to clip output.
3200 clipList has the window's children subtracted from it, in addition to pieces of sibling windows
3201 that overlap this window. To get the list with the
3202 children included (subwindow-mode is IncludeInferiors),
3203 the routine NotClippedByChildren(pWin) returns the unclipped region.</para></listitem>
3205 borderClip is the region used by CopyWindow and
3206 includes the area of the window, its children, and the border, but with the
3207 overlapping areas of sibling children removed.</para></listitem>
3209 Most of the other fields are for DIX use only.</para>
3211 <title>Window Procedures in the ScreenRec</title>
3213 You should implement
3214 all of the following procedures and store pointers to them in the screen record.</para>
3216 The device-independent portion of the server "owns" the window tree.
3217 However, clever hardware might want to know the relationship of
3218 mapped windows. There are pointers to procedures
3219 in the ScreenRec data structure that are called to give the hardware
3220 a chance to update its internal state. These are helpers and
3222 they do not change the window tree, which is only changed by DIX.</para>
3224 <blockquote><programlisting>
3226 Bool pScreen->CreateWindow(pWin)
3229 </programlisting></blockquote>
3230 This routine is a hook for when DIX creates a window.
3231 It should fill in the "Window Procedures in the WindowRec" below
3232 and also allocate the devPrivate block for it.</para>
3234 See Xserver/fb/fbwindow.c for the sample server implementation.</para>
3236 <blockquote><programlisting>
3238 Bool pScreen->DestroyWindow(pWin);
3241 </programlisting></blockquote>
3242 This routine is a hook for when DIX destroys a window.
3243 It should deallocate the devPrivate block for it and any other blocks that need
3244 to be freed, besides doing other cleanup actions.</para>
3246 See Xserver/fb/fbwindow.c for the sample server implementation.</para>
3248 <blockquote><programlisting>
3250 Bool pScreen->PositionWindow(pWin, x, y);
3254 </programlisting></blockquote>
3255 This routine is a hook for when DIX moves or resizes a window.
3256 It should do whatever private operations need to be done when a window is moved or resized.
3257 For instance, if DDX keeps a pixmap tile used for drawing the background
3258 or border, and it keeps the tile rotated such that it is longword
3259 aligned to longword locations in the frame buffer, then you should rotate your tiles here.
3260 The actual graphics involved in moving the pixels on the screen and drawing the
3261 border are handled by CopyWindow(), below.</para>
3263 See Xserver/fb/fbwindow.c for the sample server implementation.</para>
3265 <blockquote><programlisting>
3267 Bool pScreen->RealizeWindow(pWin);
3270 Bool pScreen->UnrealizeWindow(pWin);
3273 </programlisting></blockquote>
3274 These routines are hooks for when DIX maps (makes visible) and unmaps
3275 (makes invisible) a window. It should do whatever private operations
3276 need to be done when these happen, such as allocating or deallocating
3277 structures that are only needed for visible windows. RealizeWindow
3278 does NOT draw the window border, background or contents;
3279 UnrealizeWindow does NOT erase the window or generate exposure events
3280 for underlying windows; this is taken care of by DIX. DIX does,
3281 however, call PaintWindowBackground() and PaintWindowBorder() to
3282 perform some of these.</para>
3284 <blockquote><programlisting>
3286 Bool pScreen->ChangeWindowAttributes(pWin, vmask)
3288 unsigned long vmask;
3290 </programlisting></blockquote>
3291 ChangeWindowAttributes is called whenever DIX changes window
3292 attributes, such as the size, front-to-back ordering, title, or
3293 anything of lesser severity that affects the window itself. The
3294 sample server implements this routine. It computes accelerators for
3295 quickly putting up background and border tiles. (See description of
3296 the set of routines stored in the WindowRec.)</para>
3298 <blockquote><programlisting>
3300 int pScreen->ValidateTree(pParent, pChild, kind)
3301 WindowPtr pParent, pChild;
3304 </programlisting></blockquote>
3305 ValidateTree calculates the clipping region for the parent window and
3306 all of its children. This routine must be provided. The sample server
3307 has a machine-independent version in Xserver/mi/mivaltree.c. This is
3308 a very difficult routine to replace.</para>
3310 <blockquote><programlisting>
3312 void pScreen->PostValidateTree(pParent, pChild, kind)
3313 WindowPtr pParent, pChild;
3316 </programlisting></blockquote>
3317 If this routine is not NULL, DIX calls it shortly after calling
3318 ValidateTree, passing it the same arguments. This is useful for
3319 managing multi-layered framebuffers.
3320 The sample server sets this to NULL.</para>
3322 <blockquote><programlisting>
3324 void pScreen->WindowExposures(pWin, pRegion, pBSRegion)
3327 RegionPtr pBSRegion;
3329 </programlisting></blockquote>
3330 The WindowExposures() routine
3331 paints the border and generates exposure events for the window.
3332 pRegion is an unoccluded region of the window, and pBSRegion is an
3333 occluded region that has backing store.
3334 Since exposure events include a rectangle describing what was exposed,
3335 this routine may have to send back a series of exposure events, one for
3336 each rectangle of the region.
3337 The count field in the expose event is a hint to the
3338 client as to the number of
3339 regions that are after this one.
3340 This routine must be provided. The sample
3341 server has a machine-independent version in Xserver/mi/miexpose.c.</para>
3343 <blockquote><programlisting>
3345 void pScreen->ClipNotify (pWin, dx, dy)
3349 </programlisting></blockquote>
3350 Whenever the cliplist for a window is changed, this function is called to
3351 perform whatever hardware manipulations might be necessary. When called,
3352 the clip list and border clip regions in the window are set to the new
3353 values. dx,dy are the distance that the window has been moved (if at all).</para>
3356 <title>Window Painting Procedures</title>
3358 In addition to the procedures listed above, there are two routines which
3359 manipulate the actual window image directly.
3360 In the sample server, mi implementations will work for
3361 most purposes and fb routines speed up situations, such
3362 as solid backgrounds/borders or tiles that are 8, 16 or 32 pixels square.</para>
3364 <blockquote><programlisting>
3366 void pScreen->ClearToBackground(pWin, x, y, w, h, generateExposures);
3369 Bool generateExposures;
3371 </programlisting></blockquote>
3372 This routine is called on a window in response to a ClearToBackground request
3374 This request has two different but related functions, depending upon generateExposures.</para>
3376 If generateExposures is true, the client is declaring that the given rectangle
3377 on the window is incorrectly painted and needs to be repainted.
3378 The sample server implementation calculates the exposure region
3379 and hands it to the DIX procedure HandleExposures(), which
3380 calls the WindowExposures() routine, below, for the window
3381 and all of its child windows.</para>
3383 If generateExposures is false, the client is trying to simply erase part
3384 of the window to the background fill style.
3385 ClearToBackground should write the background color or tile to the
3386 rectangle in question (probably using PaintWindowBackground).
3387 If w or h is zero, it clears all the way to the right or lower edge of the window.</para>
3389 The sample server implementation is in Xserver/mi/miwindow.c.</para>
3391 <blockquote><programlisting>
3393 void pScreen->CopyWindow(pWin, oldpt, oldRegion);
3396 RegionPtr oldRegion;
3398 </programlisting></blockquote>
3399 CopyWindow is called when a window is moved, and graphically moves to
3400 pixels of a window on the screen. It should not change any other
3401 state within DDX (see PositionWindow(), above).</para>
3403 oldpt is the old location of the upper-left corner. oldRegion is the
3404 old region it is coming from. The new location and new region is
3405 stored in the WindowRec. oldRegion might modified in place by this
3406 routine (the sample implementation does this).</para>
3408 CopyArea could be used, except that this operation has more
3409 complications. First of all, you do not want to copy a rectangle onto
3410 a rectangle. The original window may be obscured by other windows,
3411 and the new window location may be similarly obscured. Second, some
3412 hardware supports multiple windows with multiple depths, and your
3413 routine needs to take care of that.</para>
3415 The pixels in oldRegion (with reference point oldpt) are copied to the
3416 window's new region (pWin->borderClip). pWin->borderClip is gotten
3417 directly from the window, rather than passing it as a parameter.</para>
3419 The sample server implementation is in Xserver/fb/fbwindow.c.</para>
3422 <title>Screen Operations for Multi-Layered Framebuffers</title>
3424 The following screen functions are useful if you have a framebuffer with
3425 multiple sets of independent bit planes, e.g. overlays or underlays in
3426 addition to the "main" planes. If you have a simple single-layer
3427 framebuffer, you should probably use the mi versions of these routines
3428 in mi/miwindow.c. This can be easily accomplished by calling miScreenInit.</para>
3430 <blockquote><programlisting>
3432 void pScreen->MarkWindow(pWin)
3435 </programlisting></blockquote>
3436 This formerly dix function MarkWindow has moved to ddx and is accessed
3437 via this screen function. This function should store something,
3438 usually a pointer to a device-dependent structure, in pWin->valdata so
3439 that ValidateTree has the information it needs to validate the window.</para>
3441 <blockquote><programlisting>
3443 Bool pScreen->MarkOverlappedWindows(parent, firstChild, ppLayerWin)
3445 WindowPtr firstChild;
3446 WindowPtr * ppLayerWin;
3448 </programlisting></blockquote>
3449 This formerly dix function MarkWindow has moved to ddx and is accessed
3450 via this screen function. In the process, it has grown another
3451 parameter: ppLayerWin, which is filled in with a pointer to the window
3452 at which save under marking and ValidateTree should begin. In the
3453 single-layered framebuffer case, pLayerWin == pWin.</para>
3455 <blockquote><programlisting>
3457 Bool pScreen->ChangeSaveUnder(pLayerWin, firstChild)
3458 WindowPtr pLayerWin;
3459 WindowPtr firstChild;
3461 </programlisting></blockquote>
3462 The dix functions ChangeSaveUnder and CheckSaveUnder have moved to ddx and
3463 are accessed via this screen function. pLayerWin should be the window
3464 returned in the ppLayerWin parameter of MarkOverlappedWindows. The function
3465 may turn on backing store for windows that might be covered, and may partially
3466 turn off backing store for windows. It returns TRUE if PostChangeSaveUnder
3467 needs to be called to finish turning off backing store.</para>
3469 <blockquote><programlisting>
3471 void pScreen->PostChangeSaveUnder(pLayerWin, firstChild)
3472 WindowPtr pLayerWin;
3473 WindowPtr firstChild;
3475 </programlisting></blockquote>
3476 The dix function DoChangeSaveUnder has moved to ddx and is accessed via
3477 this screen function. This function completes the job of turning off
3478 backing store that was started by ChangeSaveUnder.</para>
3480 <blockquote><programlisting>
3482 void pScreen->MoveWindow(pWin, x, y, pSib, kind)
3489 </programlisting></blockquote>
3490 The formerly dix function MoveWindow has moved to ddx and is accessed via
3491 this screen function. The new position of the window is given by
3492 x,y. kind is VTMove if the window is only moving, or VTOther if
3493 the border is also changing.</para>
3495 <blockquote><programlisting>
3497 void pScreen->ResizeWindow(pWin, x, y, w, h, pSib)
3505 </programlisting></blockquote>
3506 The formerly dix function SlideAndSizeWindow has moved to ddx and is accessed via
3507 this screen function. The new position is given by x,y. The new size
3508 is given by w,h.</para>
3510 <blockquote><programlisting>
3512 WindowPtr pScreen->GetLayerWindow(pWin)
3515 </programlisting></blockquote>
3516 This is a new function which returns a child of the layer parent of pWin.</para>
3518 <blockquote><programlisting>
3520 void pScreen->HandleExposures(pWin)
3523 </programlisting></blockquote>
3524 The formerly dix function HandleExposures has moved to ddx and is accessed via
3525 this screen function. This function is called after ValidateTree and
3526 uses the information contained in valdata to send exposures to windows.</para>
3528 <blockquote><programlisting>
3530 void pScreen->ReparentWindow(pWin, pPriorParent)
3532 WindowPtr pPriorParent;
3534 </programlisting></blockquote>
3535 This function will be called when a window is reparented. At the time of
3536 the call, pWin will already be spliced into its new position in the
3537 window tree, and pPriorParent is its previous parent. This function
3540 <blockquote><programlisting>
3542 void pScreen->SetShape(pWin)
3545 </programlisting></blockquote>
3546 The formerly dix function SetShape has moved to ddx and is accessed via
3547 this screen function. The window's new shape will have already been
3548 stored in the window when this function is called.</para>
3550 <blockquote><programlisting>
3552 void pScreen->ChangeBorderWidth(pWin, width)
3556 </programlisting></blockquote>
3557 The formerly dix function ChangeBorderWidth has moved to ddx and is accessed via
3558 this screen function. The new border width is given by width.</para>
3560 <blockquote><programlisting>
3562 void pScreen->MarkUnrealizedWindow(pChild, pWin, fromConfigure)
3567 </programlisting></blockquote>
3568 This function is called for windows that are being unrealized as part of
3569 an UnrealizeTree. pChild is the window being unrealized, pWin is an
3570 ancestor, and the fromConfigure value is simply propagated from UnrealizeTree.</para>
3575 <title>Graphics Contexts and Validation</title>
3577 This graphics context (GC) contains state variables such as foreground and
3578 background pixel value (color), the current line style and width,
3579 the current tile or stipple for pattern generation, the current font for text
3580 generation, and other similar attributes.</para>
3582 In many graphics systems, the equivalent of the graphics context and the
3583 drawable are combined as one entity.
3584 The main distinction between the two kinds of status is that a drawable
3585 describes a writing surface and the writings that may have already been done
3586 on it, whereas a graphics context describes the drawing process.
3587 A drawable is like a chalkboard.
3588 A GC is like a piece of chalk.</para>
3590 Unlike many similar systems, there is no "current pen location."
3591 Every graphic operation is accompanied by the coordinates where it is to happen.</para>
3593 The GC also includes two vectors of procedure pointers, the first
3594 operate on the GC itself and are called GC funcs. The second, called
3596 contains the functions that carry out the fundamental graphic operations
3597 such as drawing lines, polygons, arcs, text, and copying bitmaps.
3598 The DDX graphic software can, if it
3599 wants to be smart, change these two vectors of procedure pointers
3600 to take advantage of hardware/firmware in the server machine, which can do
3601 a better job under certain circumstances. To reduce the amount of memory
3602 consumed by each GC, it is wise to create a few "boilerplate" GC ops vectors
3603 which can be shared by every GC which matches the constraints for that set.
3604 Also, it is usually reasonable to have every GC created by a particular
3605 module to share a common set of GC funcs. Samples of this sort of
3606 sharing can be seen in fb/fbgc.c.</para>
3608 The DDX software is notified any time the client (or DIX) uses a changed GC.
3609 For instance, if the hardware has special support for drawing fixed-width
3610 fonts, DDX can intercept changes to the current font in a GC just before
3611 drawing is done. It can plug into either a fixed-width procedure that makes
3612 the hardware draw characters, or a variable-width procedure that carefully
3613 lays out glyphs by hand in software, depending upon the new font that is
3616 A definition of these structures can be found in the file
3617 Xserver/include/gcstruct.h.</para>
3619 Also included in each GC is support for dynamic devPrivates, which the
3620 DDX can use for any purpose (see <xref linkend="wrappers_and_privates"/> below).</para>
3622 The DIX routines available for manipulating GCs are
3623 CreateGC, ChangeGC, ChangeGCXIDs, CopyGC, SetClipRects, SetDashes, and FreeGC.
3624 <blockquote><programlisting>
3626 GCPtr CreateGC(pDrawable, mask, pval, pStatus)
3627 DrawablePtr pDrawable;
3632 int ChangeGC(client, pGC, mask, pUnion)
3636 ChangeGCValPtr pUnion;
3638 int ChangeGCXIDs(client, pGC, mask, pC32)
3644 int CopyGC(pgcSrc, pgcDst, mask)
3649 int SetClipRects(pGC, xOrigin, yOrigin, nrects, prects, ordering)
3651 int xOrigin, yOrigin;
3656 SetDashes(pGC, offset, ndash, pdash)
3660 unsigned char *pdash;
3662 int FreeGC(pGC, gid)
3666 </programlisting></blockquote>
3669 As a convenience, each Screen structure contains an array of
3670 GCs that are preallocated, one at each depth the screen supports.
3671 These are particularly useful in the mi code. Two DIX routines
3672 must be used to get these GCs:
3673 <blockquote><programlisting>
3675 GCPtr GetScratchGC(depth, pScreen)
3682 </programlisting></blockquote>
3683 Always use these two routines, don't try to extract the scratch
3684 GC yourself -- someone else might be using it, so a new one must
3685 be created on the fly.</para>
3687 If you need a GC for a very long time, say until the server is restarted,
3688 you should not take one from the pool used by GetScratchGC, but should
3689 get your own using CreateGC or CreateScratchGC.
3690 This leaves the ones in the pool free for routines that only need it for
3691 a little while and don't want to pay a heavy cost to get it.
3692 <blockquote><programlisting>
3694 GCPtr CreateScratchGC(pScreen, depth)
3698 </programlisting></blockquote>
3699 NULL is returned if the GC cannot be created.
3700 The GC returned can be freed with FreeScratchGC.</para>
3702 <title>Details of Operation</title>
3704 At screen initialization, a screen must supply a GC creation procedure.
3705 At GC creation, the screen must fill in GC funcs and GC ops vectors
3706 (Xserver/include/gcstruct.h). For any particular GC, the func vector
3707 must remain constant, while the op vector may vary. This invariant is to
3708 ensure that Wrappers work correctly.</para>
3710 When a client request is processed that results in a change
3711 to the GC, the device-independent state of the GC is updated.
3712 This includes a record of the state that changed.
3713 Then the ChangeGC GC func is called.
3714 This is useful for graphics subsystems that are able to process
3715 state changes in parallel with the server CPU.
3716 DDX may opt not to take any action at GC-modify time.
3717 This is more efficient if multiple GC-modify requests occur
3718 between draws using a given GC.</para>
3720 Validation occurs at the first draw operation that specifies the GC after
3721 that GC was modified. DIX calls then the ValidateGC GC func. DDX should
3722 then update its internal state. DDX internal state may be stored as one or
3723 more of the following: 1) device private block on the GC; 2) hardware
3724 state; 3) changes to the GC ops.</para>
3726 The GC contains a serial number, which is loaded with a number fetched from
3727 the window that was drawn into the last time the GC was used. The serial
3728 number in the drawable is changed when the drawable's
3729 clipList or absCorner changes. Thus, by
3730 comparing the GC serial number with the drawable serial number, DIX can
3731 force a validate if the drawable has been changed since the last time it
3732 was used with this GC.</para>
3734 In addition, the drawable serial number is always guaranteed to have the
3735 most significant bit set to 0. Thus, the DDX layer can set the most
3736 significant bit of the serial number to 1 in a GC to force a validate the next time
3737 the GC is used. DIX also uses this technique to indicate that a change has
3738 been made to the GC by way of a SetGC, a SetDashes or a SetClip request.</para>
3741 <title>GC Handling Routines</title>
3743 The ScreenRec data structure has a pointer for
3745 <blockquote><programlisting>
3747 Bool pScreen->CreateGC(pGC)
3749 </programlisting></blockquote>
3750 This routine must fill in the fields of
3751 a dynamically allocated GC that is passed in.
3752 It does NOT allocate the GC record itself or fill
3753 in the defaults; DIX does that.</para>
3755 This must fill in both the GC funcs and ops; none of the drawing
3756 functions will be called before the GC has been validated,
3757 but the others (dealing with allocating of clip regions,
3758 changing and destroying the GC, etc.) might be.</para>
3760 The GC funcs vector contains pointers to 7
3761 routines and a devPrivate field:
3762 <blockquote><programlisting>
3764 pGC->funcs->ChangeGC(pGC, changes)
3766 unsigned long changes;
3768 </programlisting></blockquote>
3769 This GC func is called immediately after a field in the GC is changed.
3770 changes is a bit mask indicating the changed fields of the GC in this
3773 The ChangeGC routine is useful if you have a system where
3774 state-changes to the GC can be swallowed immediately by your graphics
3775 system, and a validate is not necessary.</para>
3777 <blockquote><programlisting>
3779 pGC->funcs->ValidateGC(pGC, changes, pDraw)
3781 unsigned long changes;
3784 </programlisting></blockquote>
3785 ValidateGC is called by DIX just before the GC will be used when one
3786 of many possible changes to the GC or the graphics system has
3787 happened. It can modify devPrivates data attached to the GC,
3788 change the op vector, or change hardware according to the
3789 values in the GC. It may not change the device-independent portion of
3790 the GC itself.</para>
3792 In almost all cases, your ValidateGC() procedure should take the
3793 regions that drawing needs to be clipped to and combine them into a
3794 composite clip region, which you keep a pointer to in the private part
3795 of the GC. In this way, your drawing primitive routines (and whatever
3796 is below them) can easily determine what to clip and where. You
3797 should combine the regions clientClip (the region that the client
3798 desires to clip output to) and the region returned by
3799 NotClippedByChildren(), in DIX. An example is in Xserver/fb/fbgc.c.</para>
3801 Some kinds of extension software may cause this routine to be called
3802 more than originally intended; you should not rely on algorithms that
3803 will break under such circumstances.</para>
3805 See the Strategies document for more information on creatively using
3806 this routine.</para>
3808 <blockquote><programlisting>
3810 pGC->funcs->CopyGC(pGCSrc, mask, pGCDst)
3815 </programlisting></blockquote>
3816 This routine is called by DIX when a GC is being copied to another GC.
3817 This is for situations where dynamically allocated chunks of memory
3818 are stored in the GC's dynamic devPrivates and need to be transferred to
3819 the destination GC.</para>
3821 <blockquote><programlisting>
3823 pGC->funcs->DestroyGC(pGC)
3826 </programlisting></blockquote>
3827 This routine is called before the GC is destroyed for the
3828 entity interested in this GC to clean up after itself.
3829 This routine is responsible for freeing any auxiliary storage allocated.</para>
3832 <title>GC Clip Region Routines</title>
3834 The GC clientClip field requires three procedures to manage it. These
3835 procedures are in the GC funcs vector. The underlying principle is that dix
3836 knows nothing about the internals of the clipping information, (except when
3837 it has come from the client), and so calls ddX whenever it needs to copy,
3838 set, or destroy such information. It could have been possible for dix not
3839 to allow ddX to touch the field in the GC, and require it to keep its own
3840 copy in devPriv, but since clip masks can be very large, this seems like a
3841 bad idea. Thus, the server allows ddX to do whatever it wants to the
3842 clientClip field of the GC, but requires it to do all manipulation itself.</para>
3844 <blockquote><programlisting>
3846 void pGC->funcs->ChangeClip(pGC, type, pValue, nrects)
3852 </programlisting></blockquote>
3853 This routine is called whenever the client changes the client clip
3854 region. The pGC points to the GC involved, the type tells what form
3855 the region has been sent in. If type is CT_NONE, then there is no
3856 client clip. If type is CT_UNSORTED, CT_YBANDED or CT_YXBANDED, then
3857 pValue pointer to a list of rectangles, nrects long. If type is
3858 CT_REGION, then pValue pointer to a RegionRec from the mi region code.
3859 If type is CT_PIXMAP pValue is a pointer to a pixmap. (The defines
3860 for CT_NONE, etc. are in Xserver/include/gc.h.) This routine is
3861 responsible for incrementing any necessary reference counts (e.g. for
3862 a pixmap clip mask) for the new clipmask and freeing anything that
3863 used to be in the GC's clipMask field. The lists of rectangles passed
3864 in can be freed with free(), the regions can be destroyed with the
3865 RegionDestroy field in the screen, and pixmaps can be destroyed by
3866 calling the screen's DestroyPixmap function. DIX and MI code expect
3867 what they pass in to this to be freed or otherwise inaccessible, and
3868 will never look inside what's been put in the GC. This is a good
3869 place to be wary of storage leaks.</para>
3871 In the sample server, this routine transforms either the bitmap or the
3872 rectangle list into a region, so that future routines will have a more
3873 predictable starting point to work from. (The validate routine must
3874 take this client clip region and merge it with other regions to arrive
3875 at a composite clip region before any drawing is done.)</para>
3877 <blockquote><programlisting>
3879 void pGC->funcs->DestroyClip(pGC)
3882 </programlisting></blockquote>
3883 This routine is called whenever the client clip region must be destroyed.
3884 The pGC points to the GC involved. This call should set the clipType
3885 field of the GC to CT_NONE.
3886 In the sample server, the pointer to the client clip region is set to NULL
3887 by this routine after destroying the region, so that other software
3888 (including ChangeClip() above) will recognize that there is no client clip region.</para>
3890 <blockquote><programlisting>
3892 void pGC->funcs->CopyClip(pgcDst, pgcSrc)
3893 GCPtr pgcDst, pgcSrc;
3895 </programlisting></blockquote>
3896 This routine makes a copy of the clipMask and clipType from pgcSrc
3897 into pgcDst. It is responsible for destroying any previous clipMask
3898 in pgcDst. The clip mask in the source can be the same as the
3899 clip mask in the dst (clients do the strangest things), so care must
3900 be taken when destroying things. This call is required because dix
3901 does not know how to copy the clip mask from pgcSrc.</para>
3905 <title>Drawing Primitives</title>
3907 The X protocol (rules for the byte stream that goes between client and server)
3908 does all graphics using primitive
3909 operations, which are called Drawing Primitives.
3910 These include line drawing, area filling, arcs, and text drawing.
3911 Your implementation must supply 16 routines
3912 to perform these on your hardware.
3913 (The number 16 is arbitrary.)</para>
3915 More specifically, 16 procedure pointers are in each
3917 At any given time, ALL of them MUST point to a valid procedure that
3918 attempts to do the operation assigned, although
3919 the procedure pointers may change and may
3920 point to different procedures to carry out the same operation.
3921 A simple server will leave them all pointing to the same 16 routines, while
3922 a more optimized implementation will switch each from one
3923 procedure to another, depending upon what is most optimal
3924 for the current GC and drawable.</para>
3926 The sample server contains a considerable chunk of code called the
3927 mi (machine independent)
3928 routines, which serve as drawing primitive routines.
3929 Many server implementations will be able to use these as-is,
3930 because they work for arbitrary depths.
3931 They make no assumptions about the formats of pixmaps
3932 and frame buffers, since they call a set of routines
3933 known as the "Pixblit Routines" (see next section).
3934 They do assume that the way to draw is
3935 through these low-level routines that apply pixel values rows at a time.
3936 If your hardware or firmware gives more performance when
3937 things are done differently, you will want to take this fact into account
3938 and rewrite some or all of the drawing primitives to fit your needs.</para>
3940 <title>GC Components</title>
3942 This section describes the fields in the GC that affect each drawing primitive.
3943 The only primitive that is not affected is GetImage, which does not use a GC
3944 because its destination is a protocol-style bit image.
3945 Since each drawing primitive mirrors exactly the X protocol request of the
3946 same name, you should refer to the X protocol specification document
3947 for more details.</para>
3949 ALL of these routines MUST CLIP to the
3950 appropriate regions in the drawable.
3951 Since there are many regions to clip to simultaneously,
3952 your ValidateGC routine should combine these into a unified
3953 clip region to which your drawing routines can quickly refer.
3954 This is exactly what the fb routines supplied with the sample server
3956 The mi implementation passes responsibility for clipping while drawing
3957 down to the Pixblit routines.</para>
3959 Also, all of them must adhere to the current plane mask.
3960 The plane mask has one bit for every bit plane in the drawable;
3961 only planes with 1 bits in the mask are affected by any drawing operation.</para>
3963 All functions except for ImageText calls must obey the alu function.
3964 This is usually Copy, but could be any of the allowable 16 raster-ops.</para>
3966 All of the functions, except for CopyArea, might use the current
3967 foreground and background pixel values.
3968 Each pixel value is 32 bits.
3969 These correspond to foreground and background colors, but you have
3970 to run them through the colormap to find out what color the pixel values
3971 represent. Do not worry about the color, just apply the pixel value.</para>
3973 The routines that draw lines (PolyLine, PolySegment, PolyRect, and PolyArc)
3974 use the line width, line style, cap style, and join style.
3975 Line width is in pixels.
3976 The line style specifies whether it is solid or dashed, and what kind of dash.
3977 The cap style specifies whether Rounded, Butt, etc.
3978 The join style specifies whether joins between joined lines are Miter, Round or Beveled.
3979 When lines cross as part of the same polyline, they are assumed to be drawn once.
3980 (See the X protocol specification for more details.)</para>
3982 Zero-width lines are NOT meant to be really zero width; this is the client's way
3983 of telling you that you can optimize line drawing with little regard to
3984 the end caps and joins.
3985 They are called "thin" lines and are meant to be one pixel wide.
3986 These are frequently done in hardware or in a streamlined assembly language
3989 Lines with widths greater than zero, though, must all be drawn with the same
3990 algorithm, because client software assumes that every jag on every
3991 line at an angle will come at the same place.
3992 Two lines that should have
3993 one pixel in the space between them
3994 (because of their distance apart and their widths) should have such a one-pixel line
3995 of space between them if drawn, regardless of angle.</para>
3997 The solid area fill routines (FillPolygon, PolyFillRect, PolyFillArc)
3998 all use the fill rule, which specifies subtle interpretations of
3999 what points are inside and what are outside of a given polygon.
4000 The PolyFillArc routine also uses the arc mode, which specifies
4001 whether to fill pie segments or single-edge slices of an ellipse.</para>
4003 The line drawing, area fill, and PolyText routines must all
4004 apply the correct "fill style."
4005 This can be either a solid foreground color, a transparent stipple,
4006 an opaque stipple, or a tile.
4007 Stipples are bitmaps where the 1 bits represent that the foreground color is written,
4008 and 0 bits represent that either the pixel is left alone (transparent) or that
4009 the background color is written (opaque).
4010 A tile is a pixmap of the full depth of the GC that is applied in its full glory to all areas.
4011 The stipple and tile patterns can be any rectangular size, although some implementations
4012 will be faster for certain sizes such as 8x8 or 32x32.
4013 The mi implementation passes this responsibility down to the Pixblit routines.</para>
4015 See the X protocol document for full details.
4016 The description of the CreateGC request has a very good, detailed description of these
4020 <title>The Primitives</title>
4022 The Drawing Primitives are as follows:
4024 <blockquote><programlisting>
4026 RegionPtr pGC->ops->CopyArea(src, dst, pGC, srcx, srcy, w, h, dstx, dsty)
4027 DrawablePtr dst, src;
4029 int srcx, srcy, w, h, dstx, dsty;
4031 </programlisting></blockquote>
4032 CopyArea copies a rectangle of pixels from one drawable to another of
4033 the same depth. To effect scrolling, this must be able to copy from
4034 any drawable to itself, overlapped. No squeezing or stretching is done
4035 because the source and destination are the same size. However,
4036 everything is still clipped to the clip regions of the destination
4039 If pGC->graphicsExposures is True, any portions of the destination which
4040 were not valid in the source (either occluded by covering windows, or
4041 outside the bounds of the drawable) should be collected together and
4042 returned as a region (if this resultant region is empty, NULL can be
4043 returned instead). Furthermore, the invalid bits of the source are
4044 not copied to the destination and (when the destination is a window)
4045 are filled with the background tile. The sample routine
4046 miHandleExposures generates the appropriate return value and fills the
4047 invalid area using pScreen->PaintWindowBackground.</para>
4049 For instance, imagine a window that is partially obscured by other
4050 windows in front of it. As text is scrolled on your window, the pixels
4051 that are scrolled out from under obscuring windows will not be
4052 available on the screen to copy to the right places, and so an exposure
4053 event must be sent for the client to correctly repaint them. Of
4054 course, if you implement backing store, you could do this without resorting
4055 to exposure events.</para>
4057 An example implementation is fbCopyArea() in Xserver/fb/fbcopy.c.</para>
4059 <blockquote><programlisting>
4061 RegionPtr pGC->ops->CopyPlane(src, dst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
4062 DrawablePtr dst, src;
4064 int srcx, srcy, w, h, dstx, dsty;
4065 unsigned long plane;
4067 </programlisting></blockquote>
4068 CopyPlane must copy one plane of a rectangle from the source drawable
4069 onto the destination drawable. Because this routine only copies one
4070 bit out of each pixel, it can copy between drawables of different
4071 depths. This is the only way of copying between drawables of
4072 different depths, except for copying bitmaps to pixmaps and applying
4073 foreground and background colors to it. All other conditions of
4074 CopyArea apply to CopyPlane too.</para>
4076 An example implementation is fbCopyPlane() in
4077 Xserver/fb/fbcopy.c.</para>
4079 <blockquote><programlisting>
4081 void pGC->ops->PolyPoint(dst, pGC, mode, n, pPoint)
4088 </programlisting></blockquote>
4089 PolyPoint draws a set of one-pixel dots (foreground color)
4090 at the locations given in the array.
4091 mode is one of the defined constants Origin (absolute coordinates) or Previous
4092 (each coordinate is relative to the last).
4093 Note that this does not use the background color or any tiles or stipples.</para>
4095 Example implementations are fbPolyPoint() in Xserver/fb/fbpoint.c and
4096 miPolyPoint in Xserver/mi/mipolypnt.c.</para>
4098 <blockquote><programlisting>
4100 void pGC->ops->Polylines(dst, pGC, mode, n, pPoint)
4107 </programlisting></blockquote>
4108 Similar to PolyPoint, Polylines draws lines between the locations given in the array.
4109 Zero-width lines are NOT meant to be really zero width; this is the client's way of
4110 telling you that you can maximally optimize line drawing with little regard to
4111 the end caps and joins.
4112 mode is one of the defined constants Previous or Origin, depending upon
4113 whether the points are each relative to the last or are absolute.</para>
4115 Example implementations are miWideLine() and miWideDash() in
4116 mi/miwideline.c and miZeroLine() in mi/mizerline.c.</para>
4118 <blockquote><programlisting>
4120 void pGC->ops->PolySegment(dst, pGC, n, pPoint)
4124 xSegment *pSegments;
4126 </programlisting></blockquote>
4127 PolySegments draws unconnected
4128 lines between pairs of points in the array; the array must be of
4129 even size; no interconnecting lines are drawn.</para>
4131 An example implementation is miPolySegment() in mipolyseg.c.</para>
4133 <blockquote><programlisting>
4135 void pGC->ops->PolyRectangle(dst, pGC, n, pRect)
4141 </programlisting></blockquote>
4142 PolyRectangle draws outlines of rectangles for each rectangle in the array.</para>
4144 An example implementation is miPolyRectangle() in Xserver/mi/mipolyrect.c.</para>
4146 <blockquote><programlisting>
4148 void pGC->ops->PolyArc(dst, pGC, n, pArc)
4154 </programlisting></blockquote>
4155 PolyArc draws connected conic arcs according to the descriptions in the array.
4156 See the protocol specification for more details.</para>
4158 Example implementations are miZeroPolyArc in Xserver/mi/mizerarc. and
4159 miPolyArc() in Xserver/mi/miarc.c.</para>
4161 <blockquote><programlisting>
4163 void pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pPoint)
4171 </programlisting></blockquote>
4172 FillPolygon fills a polygon specified by the points in the array
4173 with the appropriate fill style.
4174 If necessary, an extra border line is assumed between the starting and ending lines.
4175 The shape can be used as a hint
4176 to optimize filling; it indicates whether it is convex (all interior angles
4177 less than 180), nonconvex (some interior angles greater than 180 but
4178 border does not cross itself), or complex (border crosses itself).
4179 You can choose appropriate algorithms or hardware based upon mode.
4180 mode is one of the defined constants Previous or Origin, depending upon
4181 whether the points are each relative to the last or are absolute.</para>
4183 An example implementation is miFillPolygon() in Xserver/mi/mipoly.c.</para>
4185 <blockquote><programlisting>
4187 void pGC->ops->PolyFillRect(dst, pGC, n, pRect)
4193 </programlisting></blockquote>
4194 PolyFillRect fills multiple rectangles.</para>
4196 Example implementations are fbPolyFillRect() in Xserver/fb/fbfillrect.c and
4197 miPolyFillRect() in Xserver/mi/mifillrct.c.</para>
4199 <blockquote><programlisting>
4201 void pGC->ops->PolyFillArc(dst, pGC, n, pArc)
4207 </programlisting></blockquote>
4208 PolyFillArc fills a shape for each arc in the
4209 list that is bounded by the arc and one or two
4210 line segments with the current fill style.</para>
4212 An example implementation is miPolyFillArc() in Xserver/mi/mifillarc.c.</para>
4214 <blockquote><programlisting>
4216 void pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBinImage)
4223 </programlisting></blockquote>
4224 PutImage copies a pixmap image into the drawable. The pixmap image
4225 must be in X protocol format (either Bitmap, XYPixmap, or ZPixmap),
4226 and format tells the format. (See the X protocol specification for
4227 details on these formats). You must be able to accept all three
4228 formats, because the client gets to decide which format to send.
4229 Either the drawable and the pixmap image have the same depth, or the
4230 source pixmap image must be a Bitmap. If a Bitmap, the foreground and
4231 background colors will be applied to the destination.</para>
4233 An example implementation is fbPutImage() in Xserver/fb/fbimage.c.</para>
4235 <blockquote><programlisting>
4237 void pScreen->GetImage(src, x, y, w, h, format, planeMask, pBinImage)
4240 unsigned int format;
4241 unsigned long planeMask;
4244 </programlisting></blockquote>
4245 GetImage copies the bits from the source drawable into
4246 the destination pointer. The bits are written into the buffer
4247 according to the server-defined pixmap padding rules.
4248 pBinImage is guaranteed to be big enough to hold all
4249 the bits that must be written.</para>
4251 This routine does not correspond exactly to the X protocol GetImage
4252 request, since DIX has to break the reply up into buffers of a size
4253 requested by the transport layer. If format is ZPixmap, the bits are
4254 written in the ZFormat for the depth of the drawable; if there is a 0
4255 bit in the planeMask for a particular plane, all pixels must have the
4256 bit in that plane equal to 0. If format is XYPixmap, planemask is
4257 guaranteed to have a single bit set; the bits should be written in
4258 Bitmap format, which is the format for a single plane of an XYPixmap.</para>
4260 <blockquote><programlisting>
4262 void pGC->ops->ImageText8(pDraw, pGC, x, y, count, chars)
4269 </programlisting></blockquote>
4270 ImageText8 draws text. The text is drawn in the foreground color; the
4271 background color fills the remainder of the character rectangles. The
4272 coordinates specify the baseline and start of the text.</para>
4274 An example implementation is miImageText8() in Xserver/mi/mipolytext.c.</para>
4276 <blockquote><programlisting>
4278 int pGC->ops->PolyText8(pDraw, pGC, x, y, count, chars)
4285 </programlisting></blockquote>
4286 PolyText8 works like ImageText8, except it draws with
4287 the current fill style for special effects such as
4289 See the X protocol specification for more details.</para>
4291 An example implementation is miPolyText8() in Xserver/mi/mipolytext.c.</para>
4293 <blockquote><programlisting>
4295 int pGC->ops->PolyText16(pDraw, pGC, x, y, count, chars)
4300 unsigned short *chars;
4302 void pGC->ops->ImageText16(pDraw, pGC, x, y, count, chars)
4307 unsigned short *chars;
4309 </programlisting></blockquote>
4310 These two routines are the same as the "8" versions,
4311 except that they are for 16-bit character codes (useful
4312 for oriental writing systems).</para>
4314 The primary difference is in the way the character information is
4315 looked up. The 8-bit and the 16-bit versions obviously have different
4316 kinds of character values to look up; the main goal of the lookup is
4317 to provide a pointer to the CharInfo structs for the characters to
4318 draw and to pass these pointers to the Glyph routines. Given a
4319 CharInfo struct, lower-level software can draw the glyph desired with
4320 little concern for other characteristics of the font.</para>
4322 16-bit character fonts have a row-and-column scheme, where the 2bytes
4323 of the character code constitute the row and column in a square matrix
4324 of CharInfo structs. Each font has row and column minimum and maximum
4325 values; the CharInfo structures form a two-dimensional matrix.</para>
4327 Example implementations are miPolyText16() and
4328 miImageText16() in Xserver/mi/mipolytext.c.</para>
4330 See the X protocol specification for more details on these graphic operations.</para>
4332 There is a hook in the GC ops, called LineHelper, that used to be used in the
4333 sample implementation by the code for wide lines. It no longer servers any
4334 purpose in the sample servers, but still exists, #ifdef'ed by NEED_LINEHELPER,
4335 in case someone needs it.</para>
4339 <title>Pixblit Procedures</title>
4341 The Drawing Primitive functions must be defined for your server.
4342 One possible way to do this is to use the mi routines from the sample server.
4343 If you choose to use the mi routines (even part of them!) you must implement
4344 these Pixblit routines.
4345 These routines read and write pixel values
4346 and deal directly with the image data.</para>
4348 The Pixblit routines for the sample server are part of the "fb"
4349 routines. As with the mi routines, the fb routines are
4350 portable but are not as portable as the mi routines.</para>
4352 The fb subsystem is a depth-independent framebuffer core, capable of
4353 operating at any depth from 1 to 32, based on the depth of the window
4354 or pixmap it is currently operating on. In particular, this means it
4355 can support pixmaps of multiple depths on the same screen. It supplies
4356 both Pixblit routines and higher-level optimized implementations of the
4357 Drawing Primitive routines. It does make the assumption that the pixel
4358 data it touches is available in the server's address space.</para>
4360 In other words, if you have a "normal" frame buffer type display, you
4361 can probably use the fb code, and the mi code. If you
4362 have a stranger hardware, you will have to supply your own Pixblit
4363 routines, but you can use the mi routines on top of them. If you have
4364 better ways of doing some of the Drawing Primitive functions, then you
4365 may want to supply some of your own Drawing Primitive routines. (Even
4366 people who write their own Drawing Primitives save at least some of
4367 the mi code for certain special cases that their hardware or library
4368 or fancy algorithm does not handle.)</para>
4370 The client, DIX, and the machine-independent routines do not carry the
4371 final responsibility of clipping. They all depend upon the Pixblit
4372 routines to do their clipping for them. The rule is, if you touch the
4373 frame buffer, you clip.</para>
4375 (The higher level routines may decide to clip at a high level, but
4376 this is only for increased performance and cannot substitute for
4377 bottom-level clipping. For instance, the mi routines, DIX, or the
4378 client may decide to check all character strings to be drawn and chop
4379 off all characters that would not be displayed. If so, it must retain
4380 the character on the edge that is partly displayed so that the Pixblit
4381 routines can clip off precisely at the right place.)</para>
4383 To make this easier, all of the reasons to clip can be combined into
4384 one region in your ValidateGC procedure. You take this composite clip
4385 region with you into the Pixblit routines. (The sample server does
4388 Also, FillSpans() has to apply tile and stipple patterns. The
4389 patterns are all aligned to the window origin so that when two people
4390 write patches that are contiguous, they will merge nicely. (Really,
4391 they are aligned to the patOrg point in the GC. This defaults to (0,
4392 0) but can be set by the client to anything.)</para>
4394 However, the mi routines can translate (relocate) the points from
4395 window-relative to screen-relative if desired. If you set the
4396 miTranslate field in the GC (set it in the CreateGC or ValidateGC
4397 routine), then the mi output routines will translate all coordinates.
4398 If it is false, then the coordinates will be passed window-relative.
4399 Screens with no hardware translation will probably set miTranslate to
4400 TRUE, so that geometry (e.g. polygons, rectangles) can be translated,
4401 rather than having the resulting list of scanlines translated; this is
4402 good because the list vertices in a drawing request will generally be
4403 much smaller than the list of scanlines it produces. Similarly,
4404 hardware that does translation can set miTranslate to FALSE, and avoid
4405 the extra addition per vertex, which can be (but is not always)
4406 important for getting the highest possible performance. (Contrast the
4407 behavior of GetSpans, which is not expected to be called as often, and
4408 so has different constraints.) The miTranslate field is settable in
4409 each GC, if , for example, you are mixing several kinds of
4410 destinations (offscreen pixmaps, main memory pixmaps, backing store,
4411 and windows), all of which have different requirements, on one screen.</para>
4413 As with other drawing routines, there are fields in the GC to direct
4414 higher code to the correct routine to execute for each function. In
4415 this way, you can optimize for special cases, for example, drawing
4416 solids versus drawing stipples.</para>
4418 The Pixblit routines are broken up into three sets. The Span routines
4419 simply fill in rows of pixels. The Glyph routines fill in character
4420 glyphs. The PushPixels routine is a three-input bitblt for more
4421 sophisticated image creation.</para>
4423 It turns out that the Glyph and PushPixels routines actually have a
4424 machine-independent implementation that depends upon the Span
4425 routines. If you are really pressed for time, you can use these
4426 versions, although they are quite slow.</para>
4428 <title>Span Routines</title>
4430 For these routines, all graphic operations have been reduced to "spans."
4431 A span is a horizontal row of pixels.
4432 If you can design these routines which write into and read from
4433 rows of pixels at a time, you can use the mi routines.</para>
4436 a destination drawable to draw into, a GC to use while drawing,
4437 the number of spans to do, and two pointers to arrays that indicate the list
4438 of starting points and the list of widths of spans.</para>
4440 <blockquote><programlisting>
4442 void pGC->ops->FillSpans(dst, pGC, nSpans, pPoints, pWidths, sorted)
4446 DDXPointPtr pPoints;
4450 </programlisting></blockquote>
4451 FillSpans should fill horizontal rows of pixels with
4452 the appropriate patterns, stipples, etc.,
4453 based on the values in the GC.
4454 The starting points are in the array at pPoints; the widths are in pWidths.
4455 If sorted is true, the scan lines are in increasing y order, in which case
4456 you may be able to make assumptions and optimizations.</para>
4458 GC components: alu, clipOrg, clientClip, and fillStyle.</para>
4460 GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
4461 (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
4462 and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).</para>
4464 <blockquote><programlisting>
4466 void pGC->ops->SetSpans(pDrawable, pGC, pSrc, ppt, pWidths, nSpans, sorted)
4467 DrawablePtr pDrawable;
4470 DDXPointPtr pPoints;
4475 </programlisting></blockquote>
4476 For each span, this routine should copy pWidths bits from pSrc to
4477 pDrawable at pPoints using the raster-op from the GC.
4478 If sorted is true, the scan lines are in increasing y order.
4479 The pixels in pSrc are
4480 padded according to the screen's padding rules.
4482 can be used to support
4483 interesting extension libraries, for example, shaded primitives. It does not
4484 use the tile and stipple.</para>
4486 GC components: alu, clipOrg, and clientClip</para>
4488 The above functions are expected to handle all modifiers in the current
4489 GC. Therefore, it is expedient to have
4490 different routines to quickly handle common special cases
4491 and reload the procedure pointers
4492 at validate time, as with the other output functions.</para>
4494 <blockquote><programlisting>
4496 void pScreen->GetSpans(pDrawable, wMax, pPoints, pWidths, nSpans)
4497 DrawablePtr pDrawable;
4499 DDXPointPtr pPoints;
4504 </programlisting></blockquote>
4505 For each span, GetSpans gets bits from the drawable starting at pPoints
4506 and continuing for pWidths bits.
4507 Each scanline returned will be server-scanline padded.
4508 The routine can return NULL if memory cannot be allocated to hold the
4511 GetSpans never translates -- for a window, the coordinates are already
4512 screen-relative. Consider the case of hardware that doesn't do
4513 translation: the mi code that calls ddX will translate each shape
4514 (rectangle, polygon,. etc.) before scan-converting it, which requires
4515 many fewer additions that having GetSpans translate each span does.
4516 Conversely, consider hardware that does translate: it can set its
4517 translation point to (0, 0) and get each span, and the only penalty is
4518 the small number of additions required to translate each shape being
4519 scan-converted by the calling code. Contrast the behavior of
4520 FillSpans and SetSpans (discussed above under miTranslate), which are
4521 expected to be used more often.</para>
4523 Thus, the penalty to hardware that does hardware translation is
4524 negligible, and code that wants to call GetSpans() is greatly
4525 simplified, both for extensions and the machine-independent core
4526 implementation.</para>
4528 <title>Glyph Routines</title>
4530 The Glyph routines draw individual character glyphs for text drawing requests.</para>
4532 You have a choice in implementing these routines. You can use the mi
4533 versions; they depend ultimately upon the span routines. Although
4534 text drawing will work, it will be very slow.</para>
4536 <blockquote><programlisting>
4538 void pGC->ops->PolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
4539 DrawablePtr pDrawable;
4542 unsigned int nglyph;
4543 CharInfoRec **ppci; /* array of character info */
4544 pointer unused; /* unused since R5 */
4546 </programlisting></blockquote>
4547 GC components: alu, clipOrg, clientClip, font, and fillStyle.</para>
4549 GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
4550 (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
4551 and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).</para>
4553 <blockquote><programlisting>
4555 void pGC->ops->ImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
4556 DrawablePtr pDrawable;
4559 unsigned int nglyph;
4560 CharInfoRec **ppci; /* array of character info */
4561 pointer unused; /* unused since R5 */
4563 </programlisting></blockquote>
4564 GC components: clipOrg, clientClip, font, fgPixel, bgPixel</para>
4566 These routines must copy the glyphs defined by the bitmaps in
4567 pglyphBase and the font metrics in ppci to the DrawablePtr, pDrawable.
4568 The poly routine follows all fill, stipple, and tile rules. The image
4569 routine simply blasts the glyph onto the glyph's rectangle, in
4570 foreground and background colors.</para>
4572 More precisely, the Image routine fills the character rectangle with
4573 the background color, and then the glyph is applied in the foreground
4574 color. The glyph can extend outside of the character rectangle.
4575 ImageGlyph() is used for terminal emulators and informal text purposes
4576 such as button labels.</para>
4578 The exact specification for the Poly routine is that the glyph is
4579 painted with the current fill style. The character rectangle is
4580 irrelevant for this operation. PolyText, at a higher level, includes
4581 facilities for font changes within strings and such; it is to be used
4582 for WYSIWYG word processing and similar systems.</para>
4584 Both of these routines must clip themselves to the overall clipping region.</para>
4586 Example implementations in mi are miPolyGlyphBlt() and
4587 miImageGlyphBlt() in Xserver/mi/miglblt.c.</para>
4590 <title>PushPixels routine</title>
4592 The PushPixels routine writes the current fill style onto the drawable
4593 in a certain shape defined by a bitmap. PushPixels is equivalent to
4594 using a second stipple. You can thing of it as pushing the fillStyle
4595 through a stencil. PushPixels is not used by any of the mi rendering code,
4596 but is used by the mi software cursor code.
4598 Suppose the stencil is: 00111100
4599 and the stipple is: 10101010
4600 PushPixels result: 00101000
4601 </para></blockquote>
4604 You have a choice in implementing this routine.
4605 You can use the mi version which depends ultimately upon FillSpans().
4606 Although it will work, it will be slow.</para>
4608 <blockquote><programlisting>
4610 void pGC->ops->PushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
4613 DrawablePtr pDrawable;
4614 int dx, dy, xOrg, yOrg;
4616 </programlisting></blockquote>
4617 GC components: alu, clipOrg, clientClip, and fillStyle.</para>
4619 GC mode-dependent components: fgPixel (for fillStyle Solid); tile, patOrg
4620 (for fillStyle Tile); stipple, patOrg, fgPixel (for fillStyle Stipple);
4621 and stipple, patOrg, fgPixel and bgPixel (for fillStyle OpaqueStipple).</para>
4623 PushPixels applies the foreground color, tile, or stipple from the pGC
4624 through a stencil onto pDrawable. pBitMap points to a stencil (of
4625 which we use an area dx wide by dy high), which is oriented over the
4626 drawable at xOrg, yOrg. Where there is a 1 bit in the bitmap, the
4627 destination is set according to the current fill style. Where there
4628 is a 0 bit in the bitmap, the destination is left the way it is.</para>
4630 This routine must clip to the overall clipping region.</para>
4632 An Example implementation is miPushPixels() in Xserver/mi/mipushpxl.c.</para>
4637 <title>Shutdown Procedures</title>
4639 <blockquote><programlisting>
4640 void ddxGiveUp(enum ExitCode error)
4641 </programlisting></blockquote>
4642 Some hardware may require special work to be done before the server
4643 exits so that it is not left in an intermediate state. As explained
4644 in the OS layer, FatalError() will call ddxGiveUp() just before
4645 terminating the server. In addition, ddxGiveUp() will be called just
4646 before terminating the server on a "clean" death. What
4647 ddxGiveUp does is left unspecified, only that it must exist in the
4648 ddx layer. It is up to local implementors as to what they should
4649 accomplish before termination.</para>
4651 <title>Command Line Procedures</title>
4653 <blockquote><programlisting>
4654 int ddxProcessArgument(argc, argv, i)
4662 </programlisting></blockquote>
4663 You should write these routines to deal with device-dependent command line
4664 arguments. The routine ddxProcessArgument() is called with the command line,
4665 and the current index into argv; you should return zero if the argument
4666 is not a device-dependent one, and otherwise return a count of the number
4667 of elements of argv that are part of this one argument. For a typical
4668 option (e.g., "-realtime"), you should return the value one. This
4669 routine gets called before checks are made against device-independent
4670 arguments, so it is possible to peek at all arguments or to override
4671 device-independent argument processing. You can document the
4672 device-dependent arguments in ddxUseMsg(), which will be
4673 called from UseMsg() after printing out the device-independent arguments.</para>
4676 <section id="wrappers_and_privates">
4677 <title>Wrappers and Privates</title>
4679 Two new extensibility concepts have been developed for release 4, Wrappers
4680 and devPrivates. These replace the R3 GCInterest queues, which were not a
4681 general enough mechanism for many extensions and only provided hooks into a
4682 single data structure. devPrivates have been revised substantially for
4683 X.Org X server release 1.5, updated again for the 1.9 release and extended
4684 again for the 1.13 relealse.</para>
4686 <title>devPrivates</title>
4688 devPrivates provides a way to attach arbitrary private data to various server structures.
4689 Any structure which contains a <structfield>devPrivates</structfield> field of
4690 type <type>PrivateRec</type> supports this mechanism. Some structures allow
4691 allocating space for private data after some objects have been created, others
4692 require all space allocations be registered before any objects of that type
4693 are created. <filename class="headerfile">Xserver/include/privates.h</filename>
4694 lists which of these cases applies to each structure containing
4695 <structfield>devPrivates</structfield>.</para>
4698 To request private space, use
4699 <blockquote><programlisting>
4700 Bool dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
4701 </programlisting></blockquote>
4702 The first argument is a pointer to a <type>DevPrivateKeyRec</type> which
4703 will serve as the unique identifier for the private data. Typically this is
4704 the address of a static <type>DevPrivateKeyRec</type> in your code.
4705 The second argument is the class of objects for which this key will apply.
4706 The third argument is the size of the space being requested, or
4707 <constant>0</constant> to only allocate a pointer that the caller will manage.
4708 If space is requested, this space will be automatically freed when the object
4709 is destroyed. Note that a call to <function>dixSetPrivate</function>
4710 that changes the pointer value may cause the space to be unreachable by the caller, however it will still be automatically freed.
4711 The function returns <literal>TRUE</literal> unless memory allocation fails.
4712 If the function is called more than once on the same key, all calls must use
4713 the same value for <type>size</type> or the server will abort.</para>
4716 To request per-screen private space in an object, use
4717 <blockquote><programlisting>
4718 Bool dixRegisterScreenPrivateKey(DevScreenPrivateKey key, ScreenPtr pScreen, DevPrivateType type, unsigned size);
4719 </programlisting></blockquote>
4720 The <parameter>type</parameter> and <parameter>size</parameter> arguments are
4721 the same as those to <function>dixRegisterPrivateKey</function> but this
4722 function ensures the given <parameter>key</parameter> exists on objects of
4723 the specified type with distinct storage for the given
4724 <parameter>pScreen</parameter>. The key is usable on ScreenPrivate variants
4725 that are otherwise equivalent to the following Private functions.</para>
4728 To request private space in objects created for a specific screen, use
4729 <blockquote><programlisting>
4730 Bool dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key, DevPrivateType type, unsigned size);
4731 </programlisting></blockquote>
4732 The <parameter>type</parameter> and <parameter>size</parameter> arguments are
4733 the same as those to <function>dixRegisterPrivateKey</function> but this
4734 function ensures only that the given <parameter>key</parameter> exists on objects of
4735 the specified type that are allocated with reference to the specified
4736 <parameter>pScreen</parameter>. Using the key on objects allocated for
4737 other screens will result in incorrect results; there is no check made to
4738 ensure that the caller's screen matches the private's screen. The key is
4739 usable in any of the following functions. Screen-specific private storage is available
4740 only for Windows, GCs, Pixmaps and Pictures. Attempts to allocate screen-specific
4741 privates on other objects will result in a call to FatalError.
4745 To attach a piece of private data to an object, use:
4746 <blockquote><programlisting>
4747 void dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
4748 </programlisting></blockquote>
4749 The first argument is the address of the <structfield>devPrivates</structfield>
4750 field in the target structure. This field is managed privately by the DIX
4751 layer and should not be directly modified. The second argument is a pointer
4752 to the <type>DevPrivateKeyRec</type> which you registered with
4753 <function>dixRegisterPrivateKey</function> or allocated with
4754 <function>dixCreatePrivateKey</function>. Only one
4755 piece of data with a given key can be attached to an object, and in most cases
4756 each key is specific to the type of object it was registered for. (An
4757 exception is the PRIVATE_XSELINUX class which applies to multiple object types.)
4758 The third argument is the value to store.</para>
4760 If private data with the given key is already associated with the object,
4761 <function>dixSetPrivate</function> will overwrite the old value with the
4765 To look up a piece of private data, use one of:
4766 <blockquote><programlisting>
4767 pointer dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
4768 pointer *dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
4769 </programlisting></blockquote>
4770 The first argument is the address of the <structfield>devPrivates</structfield> field
4771 in the target structure. The second argument is the key to look up.
4772 If a non-zero size was given when the key was registered, or if private data
4773 with the given key is already associated with the object, then
4774 <function>dixLookupPrivate</function> will return the pointer value
4775 while <function>dixLookupPrivateAddr</function>
4776 will return the address of the pointer.</para>
4779 When implementing new server resource objects that support devPrivates, there
4780 are four steps to perform:
4781 Add a type value to the <type>DevPrivateType</type> enum in
4782 <filename class="headerfile">Xserver/include/privates.h</filename>,
4783 declare a field of type <type>PrivateRec *</type> in your structure;
4784 initialize this field to <literal>NULL</literal> when creating any objects; and
4785 when freeing any objects call the <function>dixFreePrivates</function> or
4786 <function>dixFreeObjectWithPrivates</function> function.</para>
4789 <title>Wrappers</title>
4791 Wrappers are not a body of code, nor an interface spec. They are, instead,
4792 a technique for hooking a new module into an existing calling sequence.
4793 There are limitations on other portions of the server implementation which
4794 make using wrappers possible; limits on when specific fields of data
4795 structures may be modified. They are intended as a replacement for
4796 GCInterest queues, which were not general enough to support existing
4797 modules; in particular software cursors needed more
4798 control over the activity. The general mechanism for using wrappers is:
4799 <blockquote><programlisting>
4800 privateWrapperFunction (object, ...)
4803 pre-wrapped-function-stuff ...
4805 object->functionVector = dixLookupPrivate(&object->devPrivates, privateKey);
4806 (*object->functionVector) (object, ...);
4808 * this next line is occasionally required by the rules governing
4809 * wrapper functions. Always using it will not cause problems.
4810 * Not using it when necessary can cause severe troubles.
4812 dixSetPrivate(&object->devPrivates, privateKey, object->functionVector);
4813 object->functionVector = privateWrapperFunction;
4815 post-wrapped-function-stuff ...
4818 privateInitialize (object)
4821 dixSetPrivate(&object->devPrivates, privateKey, object->functionVector);
4822 object->functionVector = privateWrapperFunction;
4824 </programlisting></blockquote>
4827 Thus the privateWrapperFunction provides hooks for performing work both
4828 before and after the wrapped function has been called; the process of
4829 resetting the functionVector is called "unwrapping" while the process of
4830 fetching the wrapped function and replacing it with the wrapping function
4831 is called "wrapping". It should be clear that GCInterest queues could
4832 be emulated using wrappers. In general, any function vectors contained in
4833 objects can be wrapped, but only vectors in GCs and Screens have been tested.</para>
4835 Wrapping screen functions is quite easy; each vector is individually
4836 wrapped. Screen functions are not supposed to change after initialization,
4837 so rewrapping is technically not necessary, but causes no problems.</para>
4839 Wrapping GC functions is a bit more complicated. GC's have two tables of
4840 function vectors, one hanging from gc->ops and the other from gc->funcs, which
4841 should be initially wrapped from a CreateGC wrapper. Wrappers should modify
4842 only table pointers, not the contents of the tables, as they
4843 may be shared by more than one GC (and, in the case of funcs, are probably
4844 shared by all gcs). Your func wrappers may change the GC funcs or ops
4845 pointers, and op wrappers may change the GC op pointers but not the funcs.</para>
4847 Thus, the rule for GC wrappings is: wrap the funcs from CreateGC and, in each
4848 func wrapper, unwrap the ops and funcs, call down, and re-wrap. In each op
4849 wrapper, unwrap the ops, call down, and rewrap afterwards. Note that in
4850 re-wrapping you must save out the pointer you're replacing again. This way the
4851 chain will be maintained when wrappers adjust the funcs/ops tables they use.</para>
4855 <title>Work Queue</title>
4857 To queue work for execution when all clients are in a stable state (i.e.
4858 just before calling select() in WaitForSomething), call:
4859 <blockquote><programlisting>
4860 Bool QueueWorkProc(function,client,closure)
4864 </programlisting></blockquote>
4867 When the server is about to suspend itself, the given function will be
4869 <blockquote><programlisting>
4870 (*function) (client, closure)
4871 </programlisting></blockquote>
4874 Neither client nor closure are actually used inside the work queue routines.</para>
4878 <title>Summary of Routines</title>
4880 This is a summary of the routines discussed in this document.
4881 The procedure names are in alphabetical order.
4882 The Struct is the structure it is attached to; if blank, this
4883 procedure is not attached to a struct and must be named as shown.
4884 The sample server provides implementations in the following
4885 categories. Notice that many of the graphics routines have both
4886 mi and fb implementations.</para>
4889 <listitem><para>dix portable to all systems; do not attempt to rewrite (Xserver/dix)</para></listitem>
4890 <listitem><para>os routine provided in Xserver/os or Xserver/include/os.h</para></listitem>
4891 <listitem><para>ddx frame buffer dependent (examples in Xserver/fb)</para></listitem>
4892 <listitem><para>mi routine provided in Xserver/mi</para></listitem>
4893 <listitem><para>hd hardware dependent (examples in many Xserver/hw directories)</para></listitem>
4894 <listitem><para>none not implemented in sample implementation</para></listitem>
4897 <table frame="all" id="routines-1">
4898 <title>Server Routines (Page 1)</title>
4899 <tgroup cols='3' align='left' colsep='1' rowsep='1'>
4902 <entry>Procedure</entry>
4904 <entry>Struct</entry>
4908 <row><entry><function>ALLOCATE_LOCAL</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4909 <row><entry><function>AddCallback</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4910 <row><entry><function>AddEnabledDevice</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4911 <row><entry><function>AddInputDevice</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4912 <row><entry><function>AddScreen</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4913 <row><entry><function>AdjustWaitForDelay</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4914 <row><entry><function>Bell</function></entry><entry><literal>hd</literal></entry><entry><para>Device</para></entry></row>
4915 <row><entry><function>ChangeClip</function></entry><entry><literal>mi</literal></entry><entry><para>GC func</para></entry></row>
4916 <row><entry><function>ChangeGC</function></entry><entry><literal></literal></entry><entry><para>GC func</para></entry></row>
4917 <row><entry><function>ChangeWindowAttributes</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4918 <row><entry><function>ClearToBackground</function></entry><entry><literal>ddx</literal></entry><entry><para>Window</para></entry></row>
4919 <row><entry><function>ClientAuthorized</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4920 <row><entry><function>ClientSignal</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4921 <row><entry><function>ClientSleep</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4922 <row><entry><function>ClientWakeup</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4923 <row><entry><function>ClipNotify</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4924 <row><entry><function>CloseScreen</function></entry><entry><literal>hd</literal></entry><entry><para></para></entry></row>
4925 <row><entry><function>ConstrainCursor</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
4926 <row><entry><function>CopyGCDest</function></entry><entry><literal>ddx</literal></entry><entry><para>GC func</para></entry></row>
4927 <row><entry><function>CopyGCSource</function></entry><entry><literal>none</literal></entry><entry><para>GC func</para></entry></row>
4928 <row><entry><function>CopyWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Window</para></entry></row>
4929 <row><entry><function>CreateGC</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4930 <row><entry><function>CreateCallbackList</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4931 <row><entry><function>CreatePixmap</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4932 <row><entry><function>CreateScreenResources</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4933 <row><entry><function>CreateWellKnowSockets</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4934 <row><entry><function>CreateWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4935 <row><entry><function>CursorLimits</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
4936 <row><entry><function>DEALLOCATE_LOCAL</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4937 <row><entry><function>DeleteCallback</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4938 <row><entry><function>DeleteCallbackList</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4939 <row><entry><function>DestroyClip</function></entry><entry><literal>ddx</literal></entry><entry><para>GC func</para></entry></row>
4940 <row><entry><function>DestroyGC</function></entry><entry><literal>ddx</literal></entry><entry><para>GC func</para></entry></row>
4941 <row><entry><function>DestroyPixmap</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4942 <row><entry><function>DestroyWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4943 <row><entry><function>DisplayCursor</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
4944 <row><entry><function>Error</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4945 <row><entry><function>ErrorF</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4946 <row><entry><function>FatalError</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4947 <row><entry><function>FillPolygon</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4948 <row><entry><function>FillSpans</function></entry><entry><literal>ddx</literal></entry><entry><para>GC op</para></entry></row>
4949 <row><entry><function>FlushAllOutput</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4950 <row><entry><function>FlushIfCriticalOutputPending</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4951 <row><entry><function>FreeScratchPixmapHeader</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4952 <row><entry><function>GetMotionEvents</function></entry><entry><literal>hd</literal></entry><entry><para>Device</para></entry></row>
4953 <row><entry><function>GetScratchPixmapHeader</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4954 <row><entry><function>GetSpans</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4955 <row><entry><function>GetStaticColormap</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4960 <table frame="all" id="routines-2">
4961 <title>Server Routines (Page 2)</title>
4962 <tgroup cols='3' align='left' colsep='1' rowsep='1'>
4965 <entry>Procedure</entry>
4967 <entry>Struct</entry>
4971 <row><entry><function>ImageGlyphBlt</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4972 <row><entry><function>ImageText16</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4973 <row><entry><function>ImageText8</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4974 <row><entry><function>InitInput</function></entry><entry><literal>hd</literal></entry><entry><para></para></entry></row>
4975 <row><entry><function>InitKeyboardDeviceStruct</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4976 <row><entry><function>InitOutput</function></entry><entry><literal>hd</literal></entry><entry><para></para></entry></row>
4977 <row><entry><function>InitPointerDeviceStruct</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4978 <row><entry><function>InsertFakeRequest</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4979 <row><entry><function>InstallColormap</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4980 <row><entry><function>Intersect</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
4981 <row><entry><function>Inverse</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
4982 <row><entry><function>LineHelper</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4983 <row><entry><function>ListInstalledColormaps</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
4984 <row><entry><function>LookupKeyboardDevice</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4985 <row><entry><function>LookupPointerDevice</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4986 <row><entry><function>ModifyPixmapHeader</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
4987 <row><entry><function>NextAvailableClient</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
4988 <row><entry><function>OsInit</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
4989 <row><entry><function>PaintWindowBackground</function></entry><entry><literal>mi</literal></entry><entry><para>Window</para></entry></row>
4990 <row><entry><function>PaintWindowBorder</function></entry><entry><literal>mi</literal></entry><entry><para>Window</para></entry></row>
4991 <row><entry><function>PointerNonInterestBox</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
4992 <row><entry><function>PointInRegion</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
4993 <row><entry><function>PolyArc</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4994 <row><entry><function>PolyFillArc</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4995 <row><entry><function>PolyFillRect</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4996 <row><entry><function>PolyGlyphBlt</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4997 <row><entry><function>Polylines</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4998 <row><entry><function>PolyPoint</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
4999 <row><entry><function>PolyRectangle</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
5000 <row><entry><function>PolySegment</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
5001 <row><entry><function>PolyText16</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
5002 <row><entry><function>PolyText8</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
5003 <row><entry><function>PositionWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5004 <row><entry><function>ProcessInputEvents</function></entry><entry><literal>hd</literal></entry><entry><para></para></entry></row>
5005 <row><entry><function>PushPixels</function></entry><entry><literal>mi</literal></entry><entry><para>GC op</para></entry></row>
5006 <row><entry><function>QueryBestSize</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
5007 <row><entry><function>ReadRequestFromClient</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5008 <row><entry><function>RealizeCursor</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
5009 <row><entry><function>RealizeFont</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5010 <row><entry><function>RealizeWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5011 <row><entry><function>RecolorCursor</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
5012 <row><entry><function>RectIn</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5013 <row><entry><function>RegionCopy</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5014 <row><entry><function>RegionCreate</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5015 <row><entry><function>RegionDestroy</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5016 <row><entry><function>RegionEmpty</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5017 <row><entry><function>RegionExtents</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5018 <row><entry><function>RegionNotEmpty</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5019 <row><entry><function>RegionReset</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5020 <row><entry><function>ResolveColor</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5025 <table frame="all" id="routines-3">
5026 <title>Server Routines (Page 3)</title>
5027 <tgroup cols='3' align='left' colsep='1' rowsep='1'>
5030 <entry>Procedure</entry>
5032 <entry>Struct</entry>
5036 <row><entry><function>RemoveEnabledDevice</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5037 <row><entry><function>ResetCurrentRequest</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5038 <row><entry><function>SaveScreen</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5039 <row><entry><function>SetCriticalOutputPending</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5040 <row><entry><function>SetCursorPosition</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
5041 <row><entry><function>SetInputCheck</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
5042 <row><entry><function>SetSpans</function></entry><entry><literal>ddx</literal></entry><entry><para>GC op</para></entry></row>
5043 <row><entry><function>StoreColors</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5044 <row><entry><function>Subtract</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5045 <row><entry><function>TimerCancel</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5046 <row><entry><function>TimerCheck</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5047 <row><entry><function>TimerForce</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5048 <row><entry><function>TimerFree</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5049 <row><entry><function>TimerInit</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5050 <row><entry><function>TimerSet</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5051 <row><entry><function>TimeSinceLastInputEvent</function></entry><entry><literal>hd</literal></entry><entry><para></para></entry></row>
5052 <row><entry><function>TranslateRegion</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5053 <row><entry><function>UninstallColormap</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5054 <row><entry><function>Union</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5055 <row><entry><function>UnrealizeCursor</function></entry><entry><literal>hd</literal></entry><entry><para>Screen</para></entry></row>
5056 <row><entry><function>UnrealizeFont</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5057 <row><entry><function>UnrealizeWindow</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
5058 <row><entry><function>ValidateGC</function></entry><entry><literal>ddx</literal></entry><entry><para>GC func</para></entry></row>
5059 <row><entry><function>ValidateTree</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
5060 <row><entry><function>WaitForSomething</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
5061 <row><entry><function>WindowExposures</function></entry><entry><literal>mi</literal></entry><entry><para>Window</para></entry></row>
5062 <row><entry><function>WriteToClient</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>