









                MMIITT--SSHHMM----MMIITT ͭͭĥĥ

                ͭͭĥĥưưλȤ

                      _J_o_n_a_t_h_a_n _C_o_r_b_e_t
              Atmospheric Technology Division
          National Center for Atmospheric Research
                    corbet@ncar.ucar.edu

           Formatted and edited for release 5 by

                       _K_e_i_t_h _P_a_c_k_a_r_d
                      MIT X Consortium










                          _A_B_S_T_R_A_C_T


          ʸǤϡMIT-SHM ͭĥλȤ
     ñ롣ɮԤΤƤΤΡ
     ꤬ĤäƤ뤳Ȥ⤢Τ褦ʾ
     ϡɮԤˤΤ餻нԤޤ
     ʸϡas isפǰäƤ--
     ϲƤ뤬ޤǤȤϸΤǤ
     ʤ



              Copyright (C) 1991 X Consortium




Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documenta-
tion files (the ``Software''), to deal in the Software with-
out 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 fol-
lowing conditions:













The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.

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 PUR-
POSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X CONSOR-
TIUM 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.

Except as contained in this notice, the name of the X Con-
sortium shall not be used in advertising or otherwise to
promote the sale, use or other dealings in this Software
without prior written authorization from the X Consortium.

















































11..  ɬɬפʤ

ͭĥϰΥФǤݡȤƤʤ
Фͭĥ򥵥ݡȤƤ뤫ɤĴ٤ˤ
xdpyinfo(1) Ѥ뤳ȡäˡγĥѤ뤿
ϡƥब SYSV ͭץߥƥ֤󶡤Ƥɬ
롣mmap ˴ŤСζͭĥ¸ߤ
Sun ΥƥǶͭĥѤˤϡSYSV ͭ
ͭˤƥͥۤʤФʤʤ(ǥե
ȤǤͭǤϤʤ) Sun  DEC ΥƥǤ
ͭκ祵䤷Ƥɬפ롣Υ
ƥΥǥեͤϾơͭĥŪ
ǤʤǤ롣

22..  

γĥ󶡤ܵǽϡͭ XImage εǽǤ
롣εǽܼŪˤϡ ºݤΥ᡼ǡͭ
Ȥ˳ǼƤ XImage ؤΥ󥿥եǤ롣
ȤСXlib ֽ̿ͥǤϥǡ
ưɬפʤ礭ʥ᡼򰷤ˤϡεǽ
Ѥмºݤǽ¿夹롣

äơˤäƤ϶ͭԥåޥåפѤǤ롣
 X ФꤷեޥåȤΡԥ2
ǤꡢΥ᡼ǡ϶ͭꥻȤ˳Ǽ
롣ͭԥåޥåפȤȡXlib δؿȤ
˥ԥåޥåפƤѹ뤳ȤǽǤ롣
ͭԥåޥåפݡȤΤϡX Фԥ
ޥåפȤ줿ۥѤǤ
롣ԥåޥåפ餫Υեåϡ
˳ǼˤϡץꥱϥФȥԥ
ޥåפͭ뤳ȤϤǤʤxdpyinfo(1)ϤΤ褦ü
ʾϽϤʤ

33..  ͭͭĥĥλȤ

ͭĥȤץǤϡإåե򤤤Ĥ
󥹥ȡ뤷ʤФʤʤ:

     # include <X11/Xlib.h>        /* ɬ */
     # include <sys/ipc.h>
     # include <sys/shm.h>
     # include <X11/extensions/XShm.h>

ץۤƤ륷ƥǶͭĥݡ
ƤʤСʤե XShm.h ¸ߤʤ
ʤäơ #ifdef ¿Ѥ뤳Ȥˤʤ뤫⤷


ͭĥѤץ񤯾ɬΥ
ФǳĥȤ뤫ɤǽĴ٤٤Ǥ롣
Сͥåȥۤξ䤳γĥưʤĶξ
⡢ץμ¤ư뤳ȤǤ



                              11





                     MIT ͭĥ


åԤˤϡ

     Status XShmQueryExtension (display)
             Display *display

ޤ

     Status XShmQueryVersion (display, major, minor, pixmaps)
             Display *display;
             int *major, *minor;
             Bool *pixmaps

¹Ԥ뤳ȡ ``display'' ()ץब¹
ǥץ쥤Ǥ롣ͭĥѤǤ
ϡɤδؿͤ True Ǥ롣ѤǤʤ
ϡץϽ Xlib θƤӽФѤԤʤ
ФʤʤĥѲǽʾˤϡXShmQueryVersion 
 ``major'', ``minor'',  ``pixmaps'' ֤ͤ
``major'', ``minor'' ϳĥμΥСֹǤꡢ
``pixmaps'' ϶ͭԥåޥåפݡȤƤ
 True Ȥʤ롣

44..  ͭͭ XXIImmaaggee 

ͭ XImage δŪʲ˼:

     1 - ͭ XImage ι¤Τ
     2 - ᡼ǡǼ붦ͭꥻȤ

     3 - ͭꥻȤ˴ؤ򥵡Ф
     4 - ͭ XImage Ѥ롣̾ XImage
ȤۤƱǤ롣

ͭ XImage ˤϼδؿѤ:

     XImage *XShmCreateImage (display, visual, depth, format, data,
                              shminfo, width, height)
             Display *display;
             Visual *visual;
             unsigned int depth, width, height;
             int format;
             char *data;
             XShmSegmentInfo *shminfo;

ΤۤȤɤ XCreateImage ƱǤ롣äơ
ǤϤʤ ``offset'',
``bitmap_pad'', ``bytes_per_line'' ¸ߤʤդ
ȡͤϥмȤꤹΤǡץ¦ǹ
θɬפϤʤͭꥻȤ˳Ƥ
()``data'' ݥ󥿤ˤ NULL Ϥȡ

ޤɲäΰ1Ĥ롣ΰ ``shminfo''  XShm-
SegmentInfo ι¤ΤؤΥݥ󥿤Ǥ롣ץǤϤ
ι¤Τ1ĤƤʤФʤ餺ι¤ΤˤϾ



                              22





                     MIT ͭĥ


Ȥⶦͭ XImage ¸³֤Ʊ¸³֤
ʤФʤʤXShmCreateImage ƤӽФˤι¤
ɬפϤʤ

˽Ԥ줿ᤷͤ XImage ¤ΤǤꡢʹ
ΥƥåפǤϤι¤ΤѤǤ롣

Υƥåפ϶ͭꥻȤǤ롣 XIm-
age ˹ԤΤɤʤʤ顢Ƥ
礭Τ뤿ˤϡ XImage ľɬפ
Ǥ롣ȤˤϼΤ褦ʸƤӽФԤɬ
:

     shminfo.shmid = shmget (IPC_PRIVATE,
               image->bytes_per_line * image->height, IPC_CREAT|0777);

(Ǥ϶ͭ XImage ``image'' ƤΤȤ
롣) ʤ顢ΥƥॳƤӽФݤˤϵ§
˽ĥ顼åԤ٤Ǥ롣ޤXImage 
ݤǤϤʤ bytes_per_line եɤѤ뤳
ȡξԤͤϰۤʤ뤳Ȥ롣

ƥब֤ ͭID  shminfo ¤Τ˳Ǽ
աФȤͭꥻȤ˳դ뤿
ˡ ID ɬפȤʤ롣

ˡζͭꥻȤ򥯥饤ȤΥץ˳
դ:

     shminfo.shmaddr = image->data = shmat (shminfo.shmid, 0, 0);

shmat ֤ɥ쥹 XImage ¤Τ shminfo ¤ΤΡξ
ˡ׳ǼʤФʤʤ

shminfo ¤Τͤꤹ뤿ˤϡͭꥻ
ȤɤΤ褦 X Ф˳դ뤫ʤƤϤʤʤ
˴Ť ``readOnly'' եɤʲΤ褦ꤹ
ȡ̾ϥץϼΤ褦ˤʤ:

     shminfo.readOnly = False;

ͤ True ꤷƤ X ФϤΥȤ˽񤭹
ߤϤǤʤäơXShmGetImage θƤӽФϼԤ
ޤ

ǸˡδؿƤӽФǥФͭꥻȤ˳
դ:

     Status XShmAttach (display, shminfo);

˹Ԥ줿ϥǤʤơ֤졢XIm-
age ѽϽǤ롣





                              33





                     MIT ͭĥ


ͭ XImage  X Υɥ֥˽񤭹ˤϡXShm-
PutImage Ѥ:

     Status XShmPutImage (display, d, gc, image, src_x, src_y,
                          dest_x, dest_y, width, height, send_event)
             Display *display;
             Drawable d;
             GC gc;
             XImage *image;
             int src_x, src_y, dest_x, dest_y;
             unsigned int width, height;
             bool send_event;

Υ󥿥ե XPutImage ƱʤΤǡǲƤ
ϹԤʤ``send_event'' Ȥɲäδؿ1
롣ΰ True Ϥȡ᡼ν񤭹߽λ
X Фֽλץ٥Ȥ롣ˤꡢͭ
ꥻȤƤӻϤƤȤʤäץ¦
Τ뤳ȤǤ롣

λ٥Ȥη XShmCompletionEvent Ǥꡢϰ
Ǥ:

     typedef struct {
         int   type;              /* ٥ȤΥ */
         unsigned long serial;   /* ǸνꥯȤֹ */
         Bool send_event;         /* SendEvent ꥯȤƤ˿ */
         Display *display;        /* ٥Ȥɤ߹ޤ줿ǥץ쥤 */
         Drawable drawable;       /* ꥯȤΥɥ֥ */
         int major_code;     /* ShmReqCode */
         int minor_code;     /* X_ShmPutImage */
         ShmSeg shmseg;      /* ꥯȤǻȤ ShmSeg  */
         unsigned long offset;   /* Ȥ ShmSeg ؤΥեå */
     } XShmCompletionEvent;

Ȥ٥ȤΥͤϡΤ褦ʷǼ¹Ի˷ꤵ:

     int CompletionType = XShmGetEventBase (display) + ShmCompletion;

λ٥Ȥ˶ͭꥻȤ񤭴硢
꡼˸ɽ̤Ƥޤ⤷ʤ

᡼ǡͭ XImage ɤ߹ˤϡδؿ
Ȥ:

     Status XShmGetImage (display, d, image, x, y, plane_mask)
          Display *display;
          Drawable d;
          XImage *image;
          int x, y;
          unsigned long plane_mask;

ǡ``display'' оݤȤʤǥץ쥤``d'' 
ݤΥɥ֥롢``image'' Ͻоݤ XImage, ``x'' 



                              44





                     MIT ͭĥ


``y''  ``d'' ǤΥեåȡ``plane_mask'' ɤ߹
Ԥץ졼λǤ롣

ͭ XImage ˴ˤϡޤ X Ф򤳤 XImage
ڤΥ˥ȼȤ˴ʤФʤʤ
ϰʲμǹԤ:

     XShmDetach (display, shminfo);
     XDestroyImage (image);
     shmdt (shminfo.shmaddr);
     shmctl (shminfo.shmid, IPC_RMID, 0);

55..  ͭͭԥåޥåפλ

ǤդΥ᡼եޥåȤФѲǽǤ X ᡼
Ȱۤʤꡢͭĥϡͭԥåޥåפ˳Ǽ
ǡФƤ1ĤΥեޥå(Ĥޤ XYPixmap 
ZPixmap)ݡȤƤʤΥեޥåȤϡ᡼
ο(1ӥåȤΥԥåޥåפξϡեޥåȤϤޤ
ˤϤʤʤ)ȥ꡼ˤϰ¸ʤ XShmPixmapFor-
mat ȤäƥФФեޥåȤ뤳ȡ

     int XShmPixmapFormat (display)
             Display *display;

ץꥱ󤬥Хԥåޥåץǡեޥå(bpp
ޤ) 򰷤ȤǤʤСҤζͭ XIm-
age ƱˡǶͭꥻȤ``shminfo'' ¤
뤳ȡǽ XImage ɬפФ
櫓ǤϤʤˤ⥪СإåɤϤۤȤ̵
Ŭڤ bytes_per_line ͤ뤳ȤǤ롣

shminfo ¤ΤͤƥåȤ顢ñ˼θƤӽФԤ
Ф褤:

     Pixmap XShmCreatePixmap (display, d, data, shminfo, width,
                              height, depth);
             Display *display;
             Drawable d;
             char *data;
             XShmSegmentInfo *shminfo;
             unsigned int width, height, depth;

ΰ XCreatePixmap ȤۤƱǤ뤬2Ĥɲäΰ
 (``data''  ``shminfo'')롣ԤϰȤƤ
Ť shminfo ¤ΤƱǤ롣Ԥ϶ͭꥻ
ؤΥݥ󥿤Ǥꡢ shminfo.shmaddr ƱͤǤʤФʤ
ʤˤ⤫餺줬ΩˤʤäƤ
ͳɮԤ褯Τʤ

˹Ԥ줿ʤСԥåޥåפ֤롣
ԥåޥåפ̤̾뤳ȤǤ뤷˶ͭ
ꥻȤȤäƤľܿ뤳ȤǤ롣ͭ
ԥåޥåפϡXFreePixmap Ȥä̤̾˴뤳



                              55





                     MIT ͭĥ


Ǥ롣˽Ҥ٤褦ˡͭꥻȤڤ
Υ˴ϼʬȤǹԤʤФʤʤ























































                              66


