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