shm.xml revision ea1d6981
1ea1d6981Smrg<?xml version="1.0" encoding="UTF-8" ?> 2ea1d6981Smrg<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 3ea1d6981Smrg "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" 4ea1d6981Smrg[ 5ea1d6981Smrg<!ENTITY % defs SYSTEM "defs.ent"> %defs; 6ea1d6981Smrg]> 7ea1d6981Smrg 8ea1d6981Smrg 9ea1d6981Smrg<!-- lifted from troff+ms+XMan by doclifter --> 10ea1d6981Smrg<book id="shm"> 11ea1d6981Smrg 12ea1d6981Smrg<bookinfo> 13ea1d6981Smrg <title>MIT-SHM(The MIT Shared Memory Extension)</title> 14ea1d6981Smrg <subtitle>How the shared memory extension works</subtitle> 15ea1d6981Smrg <authorgroup> 16ea1d6981Smrg <author> 17ea1d6981Smrg <firstname>Jonathan</firstname><surname>Corbet</surname> 18ea1d6981Smrg <affiliation> 19ea1d6981Smrg <orgname>National Center for Atmospheric Research</orgname> 20ea1d6981Smrg <orgdiv>Atmospheric Technology Division</orgdiv> 21ea1d6981Smrg </affiliation> 22ea1d6981Smrg <email>corbet@ncar.ucar.edu</email> 23ea1d6981Smrg </author> 24ea1d6981Smrg <editor> 25ea1d6981Smrg <firstname>Keith</firstname><surname>Packard</surname> 26ea1d6981Smrg <affiliation><orgname>MIT X Consortium</orgname></affiliation> 27ea1d6981Smrg </editor> 28ea1d6981Smrg </authorgroup> 29ea1d6981Smrg <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo> 30ea1d6981Smrg <releaseinfo>Version 1.0</releaseinfo> 31ea1d6981Smrg <copyright><year>1991</year><holder>X Consortium</holder></copyright> 32ea1d6981Smrg 33ea1d6981Smrg<legalnotice> 34ea1d6981Smrg<para> 35ea1d6981SmrgPermission is hereby granted, free of charge, to any person obtaining a copy 36ea1d6981Smrgof this software and associated documentation files (the "Software"), to deal 37ea1d6981Smrgin the Software without restriction, including without limitation the rights 38ea1d6981Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39ea1d6981Smrgcopies of the Software, and to permit persons to whom the Software is 40ea1d6981Smrgfurnished to do so, subject to the following conditions: 41ea1d6981Smrg</para> 42ea1d6981Smrg<para> 43ea1d6981SmrgThe above copyright notice and this permission notice shall be included in 44ea1d6981Smrgall copies or substantial portions of the Software. 45ea1d6981Smrg</para> 46ea1d6981Smrg<para> 47ea1d6981SmrgTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48ea1d6981SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49ea1d6981SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50ea1d6981SmrgX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 51ea1d6981SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 52ea1d6981SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 53ea1d6981Smrg</para> 54ea1d6981Smrg<para> 55ea1d6981SmrgExcept as contained in this notice, the name of the X Consortium shall not be 56ea1d6981Smrgused in advertising or otherwise to promote the sale, use or other dealings 57ea1d6981Smrgin this Software without prior written authorization from the X Consortium. 58ea1d6981Smrg</para> 59ea1d6981Smrg<para>X Window System is a trademark of The OpenGroup.</para> 60ea1d6981Smrg</legalnotice> 61ea1d6981Smrg 62ea1d6981Smrg<abstract> 63ea1d6981Smrg<para> 64ea1d6981SmrgThis document briefly describes how to use the MIT-SHM shared memory 65ea1d6981Smrgextension. I have tried to make it accurate, but it would not surprise me 66ea1d6981Smrgif some errors remained. If you find anything wrong, do let me know and I 67ea1d6981Smrgwill incorporate the corrections. Meanwhile, please take this document "as 68ea1d6981Smrgis" (eman improvement over what was there before, but certainly not the 69ea1d6981Smrgdefinitive word.) 70ea1d6981Smrg</para> 71ea1d6981Smrg</abstract> 72ea1d6981Smrg 73ea1d6981Smrg</bookinfo> 74ea1d6981Smrg 75ea1d6981Smrg<chapter id="REQUIREMENTS"> 76ea1d6981Smrg<title>REQUIREMENTS</title> 77ea1d6981Smrg<para> 78ea1d6981SmrgThe shared memory extension is provided only by some X servers. To find out 79ea1d6981Smrgif your server supports the extension, use xdpyinfo(1). In particular, to 80ea1d6981Smrgbe able to use this extension, your system must provide the SYSV shared 81ea1d6981Smrgmemory primitives. There is not an mmap-based version of this extension. 82ea1d6981SmrgTo use shared memory on Sun systems, you must have built your kernel with 83ea1d6981SmrgSYSV shared memory enabled -- which is not the default configuration. 84ea1d6981SmrgAdditionally, the shared memeory maximum size will need to be increased on 85ea1d6981Smrgboth Sun and Digital systems; the defaults are far too small for any useful 86ea1d6981Smrgwork. 87ea1d6981Smrg</para> 88ea1d6981Smrg</chapter> 89ea1d6981Smrg 90ea1d6981Smrg<chapter id="WHAT_IS_PROVIDED"> 91ea1d6981Smrg<title>WHAT IS PROVIDED</title> 92ea1d6981Smrg 93ea1d6981Smrg<para> 94ea1d6981SmrgThe basic capability provided is that of shared memory XImages. This is 95ea1d6981Smrgessentially a version of the ximage interface where the actual image data 96ea1d6981Smrgis stored in a shared memory segment, and thus need not be moved through 97ea1d6981Smrgthe Xlib interprocess communication channel. For large images, use of this 98ea1d6981Smrgfacility can result in some real performance increases. 99ea1d6981Smrg</para> 100ea1d6981Smrg 101ea1d6981Smrg<para> 102ea1d6981SmrgAdditionally, some implementations provided shared memory pixmaps. These 103ea1d6981Smrgare 2 dimensional arrays of pixels in a format specified by the X server, 104ea1d6981Smrgwhere the image data is stored in the shared memory segment. Through use of 105ea1d6981Smrgshared memory pixmaps, it is possible to change the contents of these 106ea1d6981Smrgpixmaps without using any Xlib routines at all. Shared memory pixmaps can 107ea1d6981Smrgonly be supported when the X server can use regular virtual memory for 108ea1d6981Smrgpixmap data; if the pixmaps are stored in some magic graphics hardware, your 109ea1d6981Smrgapplication will not be able to share them with the server. Xdpyinfo(1) 110ea1d6981Smrgdoesn't print this particular nugget of information. 111ea1d6981Smrg</para> 112ea1d6981Smrg</chapter> 113ea1d6981Smrg 114ea1d6981Smrg<chapter id="HOW_TO_USE_THE_SHARED_MEMORY_EXTENSION"> 115ea1d6981Smrg<title>HOW TO USE THE SHARED MEMORY EXTENSION</title> 116ea1d6981Smrg<para> 117ea1d6981SmrgCode which uses the shared memory extension must include a number of header 118ea1d6981Smrgfiles: 119ea1d6981Smrg</para> 120ea1d6981Smrg 121ea1d6981Smrg<literallayout class="monospaced"> 122ea1d6981Smrg#include <X11/Xlib.h> /* of course */ 123ea1d6981Smrg#include <sys/ipc.h> 124ea1d6981Smrg#include <sys/shm.h> 125ea1d6981Smrg#include <X11/extensions/XShm.h> 126ea1d6981Smrg</literallayout> 127ea1d6981Smrg 128ea1d6981Smrg<para> 129ea1d6981SmrgOf course, if the system you are building on does not support shared 130ea1d6981Smrgmemory, the file XShm.h may not be present. You may want to make 131ea1d6981Smrgliberal use of #ifdefs. 132ea1d6981Smrg</para> 133ea1d6981Smrg 134ea1d6981Smrg<para> 135ea1d6981SmrgAny code which uses the shared memory extension should first check to see 136ea1d6981Smrgthat the server provides the extension. You could always be running over 137ea1d6981Smrgthe net, or in some other environment where the extension will not work. 138ea1d6981SmrgTo perform this check, call either 139ea1d6981Smrg</para> 140ea1d6981Smrg 141ea1d6981Smrg<funcsynopsis id='XShmQueryExtension'> 142ea1d6981Smrg<funcprototype> 143ea1d6981Smrg <funcdef>Status <function>XShmQueryExtension</function></funcdef> 144ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 145ea1d6981Smrg</funcprototype> 146ea1d6981Smrg</funcsynopsis> 147ea1d6981Smrg 148ea1d6981Smrg<para> 149ea1d6981Smrgor 150ea1d6981Smrg</para> 151ea1d6981Smrg 152ea1d6981Smrg<funcsynopsis id='XShmQueryVersion'> 153ea1d6981Smrg<funcprototype> 154ea1d6981Smrg <funcdef>Status <function>XShmQueryVersion</function></funcdef> 155ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 156ea1d6981Smrg <paramdef>int <parameter>*major</parameter></paramdef> 157ea1d6981Smrg <paramdef>int <parameter>*minor</parameter></paramdef> 158ea1d6981Smrg <paramdef>Bool <parameter>*pixmaps</parameter></paramdef> 159ea1d6981Smrg</funcprototype> 160ea1d6981Smrg</funcsynopsis> 161ea1d6981Smrg 162ea1d6981Smrg<para> 163ea1d6981SmrgWhere "display" is, of course, the display on which you are running. If 164ea1d6981Smrgthe shared memory extension may be used, the return value from either 165ea1d6981Smrgfunction will be True; otherwise your program should operate using 166ea1d6981Smrgconventional Xlib calls. When the extension is available, 167ea1d6981Smrg\fCXShmQueryVersion\fP also returns "major" and "minor" which are the 168ea1d6981Smrgversion numbers of the extension implementation, and "pixmaps" which is 169ea1d6981SmrgTrue iff shared memory pixmaps are supported. 170ea1d6981Smrg</para> 171ea1d6981Smrg</chapter> 172ea1d6981Smrg 173ea1d6981Smrg<chapter id="USE_OF_SHARED_MEMORY_XIMAGES"> 174ea1d6981Smrg<title>USE OF SHARED MEMORY XIMAGES</title> 175ea1d6981Smrg<para> 176ea1d6981SmrgThe basic sequence of operations for shared memory XImages is as follows: 177ea1d6981Smrg</para> 178ea1d6981Smrg 179ea1d6981Smrg<orderedlist> 180ea1d6981Smrg <listitem> 181ea1d6981Smrg <para> 182ea1d6981SmrgCreate the shared memory XImage structure 183ea1d6981Smrg </para> 184ea1d6981Smrg </listitem> 185ea1d6981Smrg <listitem> 186ea1d6981Smrg <para> 187ea1d6981SmrgCreate a shared memory segment to store the image data 188ea1d6981Smrg </para> 189ea1d6981Smrg </listitem> 190ea1d6981Smrg <listitem> 191ea1d6981Smrg <para> 192ea1d6981SmrgInform the server about the shared memory segment 193ea1d6981Smrg </para> 194ea1d6981Smrg </listitem> 195ea1d6981Smrg <listitem> 196ea1d6981Smrg <para> 197ea1d6981SmrgUse the shared memory XImage, much like a normal one. 198ea1d6981Smrg </para> 199ea1d6981Smrg </listitem> 200ea1d6981Smrg</orderedlist> 201ea1d6981Smrg 202ea1d6981Smrg<para> 203ea1d6981SmrgTo create a shared memory XImage, use: 204ea1d6981Smrg</para> 205ea1d6981Smrg 206ea1d6981Smrg<funcsynopsis id='XShmCreateImage'> 207ea1d6981Smrg<funcprototype> 208ea1d6981Smrg <funcdef>XImage <function>*XShmCreateImage</function></funcdef> 209ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 210ea1d6981Smrg <paramdef>Visual <parameter>*visual</parameter></paramdef> 211ea1d6981Smrg <paramdef>unsigned int <parameter>depth</parameter></paramdef> 212ea1d6981Smrg <paramdef>int <parameter>format</parameter></paramdef> 213ea1d6981Smrg <paramdef>char <parameter>*data</parameter></paramdef> 214ea1d6981Smrg <paramdef>XShmSegmentInfo <parameter>*shminfo</parameter></paramdef> 215ea1d6981Smrg <paramdef>unsigned int <parameter>width</parameter></paramdef> 216ea1d6981Smrg <paramdef>unsigned int <parameter>height</parameter></paramdef> 217ea1d6981Smrg</funcprototype> 218ea1d6981Smrg</funcsynopsis> 219ea1d6981Smrg 220ea1d6981Smrg<para> 221ea1d6981SmrgMost of the arguments are the same as for XCreateImage; I will not go 222ea1d6981Smrgthrough them here. Note, however, that there are no "offset", "bitmap_pad", 223ea1d6981Smrgor "bytes_per_line" arguments. These quantities will be defined by the 224ea1d6981Smrgserver itself, and your code needs to abide by them. Unless you have already 225ea1d6981Smrgallocated the shared memory segment (see below), you should pass in NULL for 226ea1d6981Smrgthe "data" pointer. 227ea1d6981Smrg</para> 228ea1d6981Smrg 229ea1d6981Smrg<para> 230ea1d6981SmrgThere is one additional argument: "shminfo", which is a pointer to a 231ea1d6981Smrgstructure of type XShmSegmentInfo. You must allocate one of these 232ea1d6981Smrgstructures such that it will have a lifetime at least as long as that of 233ea1d6981Smrgthe shared memory XImage. There is no need to initialize this structure 234ea1d6981Smrgbefore the call to XShmCreateImage. 235ea1d6981Smrg</para> 236ea1d6981Smrg 237ea1d6981Smrg<para> 238ea1d6981SmrgThe return value, if all goes well, will be an XImage structure, which you 239ea1d6981Smrgcan use for the subsequent steps. 240ea1d6981Smrg</para> 241ea1d6981Smrg 242ea1d6981Smrg<para> 243ea1d6981SmrgThe next step is to create the shared memory segment. This is 244ea1d6981Smrgbest done after the creation of the XImage, since you need to make use of 245ea1d6981Smrgthe information in that XImage to know how much memory to allocate. To 246ea1d6981Smrgcreate the segment, you need a call like: 247ea1d6981Smrg</para> 248ea1d6981Smrg 249ea1d6981Smrg 250ea1d6981Smrg<literallayout class="monospaced"> 251ea1d6981Smrgshminfo.shmid = shmget (IPC_PRIVATE, 252ea1d6981Smrg image->bytes_per_line * image->height, IPC_CREAT|0777); 253ea1d6981Smrg</literallayout> 254ea1d6981Smrg 255ea1d6981Smrg<para> 256ea1d6981Smrg(assuming that you have called your shared memory XImage "image"). You 257ea1d6981Smrgshould, of course, follow the Rules and do error checking on all of these 258ea1d6981Smrgsystem calls. Also, be sure to use the bytes_per_line field, not the width 259ea1d6981Smrgyou used to create the XImage as they may well be different. 260ea1d6981Smrg</para> 261ea1d6981Smrg 262ea1d6981Smrg<para> 263ea1d6981SmrgNote that the shared memory ID returned by the system is stored in the 264ea1d6981Smrgshminfo structure. The server will need that ID to attach itself to the 265ea1d6981Smrgsegment. 266ea1d6981Smrg</para> 267ea1d6981Smrg 268ea1d6981Smrg<para> 269ea1d6981SmrgAlso note that, on many systems for security reasons, the X server 270ea1d6981Smrgwill only accept to attach to the shared memory segment if it's 271ea1d6981Smrgreadable and writeable by "other". On systems where the X server is 272ea1d6981Smrgable to determine the uid of the X client over a local transport, the 273ea1d6981Smrgshared memory segment can be readable and writeable only by the uid of 274ea1d6981Smrgthe client. 275ea1d6981Smrg</para> 276ea1d6981Smrg 277ea1d6981Smrg<para> 278ea1d6981SmrgNext, attach this shared memory segment to your process: 279ea1d6981Smrg</para> 280ea1d6981Smrg 281ea1d6981Smrg<para> 282ea1d6981Smrgshminfo.shmaddr = image->data = shmat (shminfo.shmid, 0, 0); 283ea1d6981Smrg</para> 284ea1d6981Smrg 285ea1d6981Smrg<para> 286ea1d6981SmrgThe address returned by shmat should be stored in *both* the XImage 287ea1d6981Smrgstructure and the shminfo structure. 288ea1d6981Smrg</para> 289ea1d6981Smrg 290ea1d6981Smrg<para> 291ea1d6981SmrgTo finish filling in the shminfo structure, you need to decide how you want 292ea1d6981Smrgthe server to attach to the shared memory segment, and set the "readOnly" 293ea1d6981Smrgfield as follows. Normally, you would code: 294ea1d6981Smrg</para> 295ea1d6981Smrg<para> 296ea1d6981Smrgshminfo.readOnly = False; 297ea1d6981Smrg</para> 298ea1d6981Smrg 299ea1d6981Smrg<para> 300ea1d6981SmrgIf you set it to True, the server will not be able to write to this 301ea1d6981Smrgsegment, and thus XShmGetImage calls will fail. 302ea1d6981Smrg</para> 303ea1d6981Smrg 304ea1d6981Smrg<para> 305ea1d6981SmrgFinally, tell the server to attach to your shared memory segment with: 306ea1d6981Smrg</para> 307ea1d6981Smrg 308ea1d6981Smrg<literallayout class="monospaced"> 309ea1d6981SmrgStatus XShmAttach (display, shminfo); 310ea1d6981Smrg</literallayout> 311ea1d6981Smrg 312ea1d6981Smrg<para> 313ea1d6981SmrgIf all goes well, you will get a non-zero status back, and your XImage is 314ea1d6981Smrgready for use. 315ea1d6981Smrg</para> 316ea1d6981Smrg 317ea1d6981Smrg<para> 318ea1d6981SmrgTo write a shared memory XImage into an X drawable, use XShmPutImage: 319ea1d6981Smrg</para> 320ea1d6981Smrg 321ea1d6981Smrg<funcsynopsis id='XShmPutImage'> 322ea1d6981Smrg<funcprototype> 323ea1d6981Smrg <funcdef>Status <function>XShmPutImage </function></funcdef> 324ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 325ea1d6981Smrg <paramdef>Drawable <parameter>d</parameter></paramdef> 326ea1d6981Smrg <paramdef>GC <parameter>gc</parameter></paramdef> 327ea1d6981Smrg <paramdef>XImage <parameter>*image</parameter></paramdef> 328ea1d6981Smrg <paramdef>int <parameter>src_x</parameter></paramdef> 329ea1d6981Smrg <paramdef>int <parameter>src_y</parameter></paramdef> 330ea1d6981Smrg <paramdef>int <parameter>dest_x</parameter></paramdef> 331ea1d6981Smrg <paramdef>int <parameter>dest_y</parameter></paramdef> 332ea1d6981Smrg <paramdef>unsigned int <parameter>width</parameter></paramdef> 333ea1d6981Smrg <paramdef>unsigned int <parameter>height</parameter></paramdef> 334ea1d6981Smrg <paramdef>bool <parameter>send_event</parameter></paramdef> 335ea1d6981Smrg</funcprototype> 336ea1d6981Smrg</funcsynopsis> 337ea1d6981Smrg 338ea1d6981Smrg<para> 339ea1d6981SmrgThe interface is identical to that of XPutImage, so I will spare my fingers 340ea1d6981Smrgand not repeat that documentation here. There is one additional parameter, 341ea1d6981Smrghowever, called "send_event". If this parameter is passed as True, the 342ea1d6981Smrgserver will generate a "completion" event when the image write is complete; 343ea1d6981Smrgthus your program can know when it is safe to begin manipulating the shared 344ea1d6981Smrgmemory segment again. 345ea1d6981Smrg</para> 346ea1d6981Smrg 347ea1d6981Smrg<para> 348ea1d6981SmrgThe completion event has type XShmCompletionEvent, which is defined as the 349ea1d6981Smrgfollowing: 350ea1d6981Smrg</para> 351ea1d6981Smrg 352ea1d6981Smrg<literallayout class="monospaced"> 353ea1d6981Smrgtypedef struct { 354ea1d6981Smrg int type; /* of event */ 355ea1d6981Smrg unsigned long serial; /* # of last request processed */ 356ea1d6981Smrg Bool send_event; /* true if came from a SendEvent request */ 357ea1d6981Smrg Display *display; /* Display the event was read from */ 358ea1d6981Smrg Drawable drawable; /* drawable of request */ 359ea1d6981Smrg int major_code; /* ShmReqCode */ 360ea1d6981Smrg int minor_code; /* X_ShmPutImage */ 361ea1d6981Smrg ShmSeg shmseg; /* the ShmSeg used in the request */ 362ea1d6981Smrg unsigned long offset; /* the offset into ShmSeg used */ 363ea1d6981Smrg} XShmCompletionEvent; 364ea1d6981Smrg</literallayout> 365ea1d6981Smrg 366ea1d6981Smrg<para> 367ea1d6981SmrgThe event type value that will be used can be determined at run time with a 368ea1d6981Smrgline of the form: 369ea1d6981Smrg</para> 370ea1d6981Smrg 371ea1d6981Smrg<para> 372ea1d6981Smrgint CompletionType = XShmGetEventBase (display) + ShmCompletion; 373ea1d6981Smrg</para> 374ea1d6981Smrg 375ea1d6981Smrg<para> 376ea1d6981SmrgIf you modify the shared memory segment before the arrival of the 377ea1d6981Smrgcompletion event, the results you see on the screen may be inconsistent. 378ea1d6981Smrg</para> 379ea1d6981Smrg 380ea1d6981Smrg<para> 381ea1d6981SmrgTo read image data into a shared memory XImage, use the following: 382ea1d6981Smrg</para> 383ea1d6981Smrg 384ea1d6981Smrg<funcsynopsis id='XShmGetImage'> 385ea1d6981Smrg<funcprototype> 386ea1d6981Smrg <funcdef>Status <function>XShmGetImage </function></funcdef> 387ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 388ea1d6981Smrg <paramdef>Drawable <parameter>d</parameter></paramdef> 389ea1d6981Smrg <paramdef>XImage <parameter>*image</parameter></paramdef> 390ea1d6981Smrg <paramdef>int <parameter>x</parameter></paramdef> 391ea1d6981Smrg <paramdef>int <parameter>y</parameter></paramdef> 392ea1d6981Smrg <paramdef>unsigned long <parameter>plane_mask</parameter></paramdef> 393ea1d6981Smrg</funcprototype> 394ea1d6981Smrg</funcsynopsis> 395ea1d6981Smrg 396ea1d6981Smrg<para> 397ea1d6981SmrgWhere "display" is the display of interest, "d" is the source drawable, 398ea1d6981Smrg"image" is the destination XImage, "x" and "y" are the offsets within 399ea1d6981Smrg"d", and "plane_mask" defines which planes are to be read. 400ea1d6981Smrg</para> 401ea1d6981Smrg 402ea1d6981Smrg<para> 403ea1d6981SmrgTo destroy a shared memory XImage, you should first instruct the server to 404ea1d6981Smrgdetach from it, then destroy the segment itself, as follows: 405ea1d6981Smrg</para> 406ea1d6981Smrg 407ea1d6981Smrg<literallayout class="monospaced"> 408ea1d6981SmrgXShmDetach (display, shminfo); 409ea1d6981SmrgXDestroyImage (image); 410ea1d6981Smrgshmdt (shminfo.shmaddr); 411ea1d6981Smrgshmctl (shminfo.shmid, IPC_RMID, 0); 412ea1d6981Smrg</literallayout> 413ea1d6981Smrg 414ea1d6981Smrg</chapter> 415ea1d6981Smrg 416ea1d6981Smrg<chapter id="USE_OF_SHARED_MEMORY_PIXMAPS"> 417ea1d6981Smrg<title>USE OF SHARED MEMORY PIXMAPS</title> 418ea1d6981Smrg<para> 419ea1d6981SmrgUnlike X images, for which any image format is usable, the shared memory 420ea1d6981Smrgextension supports only a single format (i.e. XYPixmap or ZPixmap) for the 421ea1d6981Smrgdata stored in a shared memory pixmap. This format is independent of the 422ea1d6981Smrgdepth of the image (for 1-bit pixmaps it doesn't really matter what this 423ea1d6981Smrgformat is) and independent of the screen. Use XShmPixmapFormat to get the 424ea1d6981Smrgformat for the server: 425ea1d6981Smrg</para> 426ea1d6981Smrg 427ea1d6981Smrg<funcsynopsis id='XShmPixmapFormat'> 428ea1d6981Smrg<funcprototype> 429ea1d6981Smrg <funcdef>int <function>XShmPixmapFormat</function></funcdef> 430ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 431ea1d6981Smrg</funcprototype> 432ea1d6981Smrg</funcsynopsis> 433ea1d6981Smrg 434ea1d6981Smrg<para> 435ea1d6981SmrgIf your application can deal with the server pixmap data format (including 436ea1d6981Smrgbits-per-pixel et al.), create a shared memory segment and "shminfo" 437ea1d6981Smrgstructure in exactly the same way as is listed above for shared memory 438ea1d6981SmrgXImages. While it is, not strictly necessary to create an XImage first, 439ea1d6981Smrgdoing so incurs little overhead and will give you an appropriate 440ea1d6981Smrgbytes_per_line value to use. 441ea1d6981Smrg</para> 442ea1d6981Smrg 443ea1d6981Smrg<para> 444ea1d6981SmrgOnce you have your shminfo structure filled in, simply call: 445ea1d6981Smrg</para> 446ea1d6981Smrg 447ea1d6981Smrg<funcsynopsis id='XShmCreatePixmap'> 448ea1d6981Smrg<funcprototype> 449ea1d6981Smrg <funcdef>Pixmap <function>XShmCreatePixmap</function></funcdef> 450ea1d6981Smrg <paramdef>Display <parameter>*display</parameter></paramdef> 451ea1d6981Smrg <paramdef>Drawable <parameter>d</parameter></paramdef> 452ea1d6981Smrg <paramdef>char <parameter>*data</parameter></paramdef> 453ea1d6981Smrg <paramdef>XShmSegmentInfo <parameter>*shminfo</parameter></paramdef> 454ea1d6981Smrg <paramdef>unsigned int <parameter>width</parameter></paramdef> 455ea1d6981Smrg <paramdef>unsigned int <parameter>height</parameter></paramdef> 456ea1d6981Smrg <paramdef>unsigned int <parameter>depth</parameter></paramdef> 457ea1d6981Smrg</funcprototype> 458ea1d6981Smrg</funcsynopsis> 459ea1d6981Smrg 460ea1d6981Smrg<para> 461ea1d6981SmrgThe arguments are all the same as for XCreatePixmap, with two additions: 462ea1d6981Smrg"data" and "shminfo". The second of the two is the same old shminfo 463ea1d6981Smrgstructure that has been used before. The first is the pointer to the shared 464ea1d6981Smrgmemory segment, and should be the same as the shminfo.shmaddr field. I am 465ea1d6981Smrgnot sure why this is a separate parameter. 466ea1d6981Smrg</para> 467ea1d6981Smrg 468ea1d6981Smrg<para> 469ea1d6981SmrgIf everything works, you will get back a pixmap, which you can manipulate in 470ea1d6981Smrgall of the usual ways, with the added bonus of being able to tweak its 471ea1d6981Smrgcontents directly through the shared memory segment. Shared memory pixmaps 472ea1d6981Smrgare destroyed in the usual manner with XFreePixmap, though you should detach 473ea1d6981Smrgand destroy the shared memory segment itself as shown above. 474ea1d6981Smrg</para> 475ea1d6981Smrg</chapter> 476ea1d6981Smrg</book> 477