943N/A/* Copyright (c) 1993, 1998, Oracle and/or its affiliates. All rights reserved.
830N/A *
830N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
830N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
830N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
830N/A */
830N/A
830N/A
830N/A/*
830N/A *
830N/A *
830N/A * @@@@ @@@@@ @ @ @@@@ @@@@ @@@ @@@@
830N/A * @ @ @ @@ @ @ @ @ @ @ @ @
830N/A * @@@@ @ @ @ @ @ @@@ @@@@ @@@@@ @@@@
830N/A * @ @ @ @ @@ @ @ @ @ @ @ @ @
830N/A * @ @ @ @ @ @@@@@ @@@@ @ @ @ @ @@@@
830N/A *
830N/A * DGA shared retained window access routines
830N/A *
830N/A * int
830N/A * dga_rtn_active(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * u_char
830N/A * dga_rtn_cached(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * void *
830N/A * dga_rtn_devinfo(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * void
830N/A * dga_rtn_devtype(clientp, type, name)
830N/A * Dga_window clientp;
830N/A * u_char *type;
830N/A * char **name;
830N/A *
830N/A * void
830N/A * dga_rtn_dimensions(clientp, width, height, linebytes)
830N/A * Dga_window clientp;
830N/A * short *width;
830N/A * short *height;
830N/A * u_int *linebytes;
830N/A *
830N/A * int
830N/A * dga_rtn_grab(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * void *
830N/A * dga_rtn_pixels(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * int
830N/A * dga_rtn_ungrab(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * int
830N/A * _dga_rtn_map(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A * int
830N/A * _dga_rtn_unmap(clientp)
830N/A * Dga_window clientp;
830N/A *
830N/A */
830N/A
830N/A#include <stdio.h>
830N/A#include <string.h>
830N/A#include <sys/types.h>
830N/A#include <unistd.h>
830N/A#ifdef SERVER_DGA
830N/A#include <X11/X.h>
830N/A#include <X11/Xmd.h>
830N/A#include "windowstr.h"
830N/A#include "dga_externaldefs.h"
830N/A#include "dga/dgawinstr.h"
830N/A#else
830N/A#include <fcntl.h>
830N/A#include <sys/mman.h>
830N/A
830N/A#ifdef SVR4
830N/A#include <netdb.h>
830N/A#include <sys/stat.h>
830N/A#else
830N/A#include <sys/param.h>
830N/A#endif
830N/A
830N/A#include <X11/Xlib.h>
830N/A#endif /* SERVER_DGA */
830N/A
830N/A#include "dga_incls.h"
830N/A#include "rtn_grab.h"
830N/A
830N/Aint dgai_rtn_ungrab_common();
830N/Aextern int dgai_win_check_multiple_grab(_Dga_window clientp, int drawableGrabber);
830N/Aextern void *_dga_is_X_window(Dga_token token, Display **dpyp, Window *winp);
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_active()
830N/A *
830N/A * DGA Retained Windows Active. This function is called to determine
830N/A * if DGA to the retained portion of the specified dga_window is currently
830N/A * active. Since the server can drop support for this functionality at
830N/A * any time, the client should always call this function when a change has
830N/A * been has been recorded in the retained window information. This function
830N/A * should be called prior to accessing any other retained window information.
830N/A * The function returns a non-zero result if DGA to the retained portion
830N/A * of the window is active. A zero result is returned if support has
830N/A * been dropped.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A *
830N/A * Outputs: 0 - DGA Retained window support has been dropped.
830N/A * -1 - DGA Retained window support continues.
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: None.
830N/A *
830N/A */
830N/Aint
830N/Adga_rtn_active(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A if ((clientp->rtn_flags & RTN_MAPPED))
830N/A return (RTN_PASSED);
830N/A else
830N/A return (RTN_FAILED);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_cached()
830N/A *
830N/A * DGA Retained HW Cache status. This function returns a non-zero
830N/A * value if the retained raster is cached in hardware. If set to
830N/A * DGA_RTN_NEW_DEV then the server has re-cached the retained
830N/A * raster from one device to another. If set to DGA_RTN_SAME_DEV
830N/A * the raster remains cached in the same device as previously
830N/A * recorded. If the retained raster is not cached in hw then the
830N/A * function returns DGA_RTN_NOT_CACHED (0).
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A *
830N/A * Outputs: DGA_RTN_NOT_CACHED - not cached in hw
830N/A * DGA_RTN_SAME_DEV - cached in the same hw device
830N/A * DGA_RTN_NEW_DEV - cached in the new hw device
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: RTN_INFOP() Internal MACRO
830N/A *
830N/A *
830N/A */
830N/Aint
830N/Adga_rtn_cached(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A if (RTN_INFOP(clientp)->cached)
830N/A if (clientp->c_rtncachseq != *(clientp->s_rtncachseq_p)) {
830N/A clientp->c_rtncachseq = *(clientp->s_rtncachseq_p);
830N/A return (DGA_RTN_NEW_DEV);
830N/A }
830N/A else
830N/A return (DGA_RTN_SAME_DEV);
830N/A else
830N/A return (DGA_RTN_NOT_CACHED);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_devinfop() <---external interface just to be consistent
830N/A * dga_rtn_devinfo()
830N/A *
830N/A * DGA Retained Device Info. This function returns a pointer to
830N/A * the shared device specific retained raster information when
830N/A * the retained raster is cached in hw. The pointer is invalid
830N/A * if the retained raster isn't cached in hw.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A *
830N/A * Outputs: void * - Pointer to the device specific information
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: RTN_INFOP() Internal MACRO
830N/A *
830N/A */
830N/Avoid *
830N/Adga_rtn_devinfo(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A /* This is the internal interface */
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A return (((char *)clientp->rtn_info) + RTN_INFOP(clientp)->device_offset);
830N/A}
830N/A
830N/Avoid *
830N/Adga_rtn_devinfop(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A return (((char *)clientp->rtn_info) + RTN_INFOP(clientp)->device_offset);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_devtype()
830N/A *
830N/A * DGA Retained Device Type. This function is used to obtain
830N/A * the retained raster hardware cache device type and name.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A * Unsign8 * - Pointer to location to store device type.
830N/A * char ** - Pointer to location to store name string pointer.
830N/A *
830N/A * Outputs: None.
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: RTN_INFOP() Internal MACRO
830N/A *
830N/A */
830N/Avoid
830N/Adga_rtn_devtype(clientpi, type, name)
830N/A Dga_window clientpi;
830N/A u_char *type;
830N/A char **name;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A *type = RTN_INFOP(clientp)->device;
830N/A *name = (char *) RTN_INFOP(clientp)->scr_name;
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_dimensions()
830N/A *
830N/A * DGA Retained Raster Dimensions. This function is used to obtain
830N/A * the retained raster's dimensions.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A * short * - Pointer to location to store the width.
830N/A * short * - Pointer to location to store the height.
830N/A * u_int * - Pointer to the location to store the linebytes.
830N/A *
830N/A * Outputs: None.
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: RTN_INFOP() Internal MACRO
830N/A *
830N/A */
830N/Avoid
830N/Adga_rtn_dimensions(clientpi, width, height, linebytes)
830N/A Dga_window clientpi;
830N/A short *width;
830N/A short *height;
830N/A u_int *linebytes;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A *width = RTN_INFOP(clientp)->width;
830N/A *height = RTN_INFOP(clientp)->height;
830N/A *linebytes = RTN_INFOP(clientp)->linebytes;
830N/A}
830N/A
830N/Aint
830N/Adga_rtn_bitsperpixel(Dga_window clientpi)
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A return(RTN_INFOP(clientp)->bitsperpixel);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_grab()
830N/A *
830N/A * DGA Retained Window Grab. This function creates the shared memory
830N/A * interface to allow the calling process Direct Graphics Access (DGA)
830N/A * to the retained raster associated with the specified DGA window.
830N/A * A request to allow DGA access to the retained raster is sent to the
830N/A * X/NeWS server. Should the server honor this request, shared memory
830N/A * mappings within the calling process's address space are then created.
830N/A * Should any of these steps fail, 0 is returned and the calling process
830N/A * is not allowed DGA to the retained raster. A non-zero result is
830N/A * returned upon success.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the Dga_window for which DGA
830N/A * to the retained raster is desired.
830N/A *
830N/A * Outputs: 0 - failed
830N/A * -1 - passed
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: XDgaGrabRetainedWindow()
830N/A * XDgaUnGrabRetainedWindow()
830N/A * _dga_is_X_window()
830N/A * _dga_rtn_map()
830N/A * fprintf() DEBUG ONLY
830N/A *
830N/A */
830N/Aint
830N/Adga_rtn_grab(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A Display *dpy;
830N/A Window win;
830N/A#ifdef SERVER_DGA
830N/A WXINFO *infop;
830N/A WindowPtr pWin;
830N/A#endif /* SERVER_DGA */
830N/A
830N/A /*
830N/A * Check for an invalid Dga_window
830N/A */
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A if ((clientp == (_Dga_window) NULL)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_grab: passed null pointer\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A#ifdef SERVER_DGA
830N/A /* Determine the window associated with this clientp */
830N/A infop = (WXINFO *) clientp->w_info;
830N/A pWin = (((WDEV *)(infop->wdev))->pWin);
830N/A
830N/A /* Check to see if backing store has been turned on for thw window */
830N/A if (pWin->backingStore == NotUseful)
830N/A return (RTN_FAILED);
830N/A
830N/A
830N/A if (!DgaSharedRetained(pWin, 1, pWin->drawable.id)) {
830N/A return (RTN_FAILED);
830N/A }
830N/A /* Map the shared memory into the calling process's address space.*/
830N/A if (!_dga_rtn_map(clientp)) {
830N/A
830N/A /* Ungrab the retained raster */
830N/A (void) DgaSharedRetained(pWin, 0, pWin->drawable.id);
830N/A return (RTN_FAILED);
830N/A }
830N/A#else
830N/A /*
830N/A * If the retained raster has already been grabbed. Don't
830N/A * do anything.
830N/A */
830N/A if (clientp->rtn_flags & RTN_GRABBED)
830N/A return (RTN_PASSED);
830N/A
830N/A /*
830N/A * Find out if this is an X window. If so get the Display and window
830N/A * id. These are used to determine the name of the shared retained
830N/A * info file. NOTE: DGA to retained rasters are currently supported
830N/A * only for X windows.
830N/A */
830N/A if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_grab: Unsupported window type\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A /* Check to see if backing store is turned on for this window; if not
830N/A * report failure
830N/A */
830N/A {
830N/A XWindowAttributes attr;
830N/A XGetWindowAttributes(dpy,win,&attr);
830N/A if (attr.backing_store == NotUseful) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr,"dga_rtn_grab: Window has no backing store\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A }
830N/A
830N/A
830N/A /*
830N/A * Request the server to allow DGA to the retained raster associated
830N/A * with this Dga_window.
830N/A */
830N/A if (!XDgaGrabRetainedWindow(dpy, win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_grab: XDgaGrabRetainedWindow failed\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A /*
830N/A * Now map the shared memory into the calling process's address
830N/A * space.
830N/A */
830N/A if (!_dga_rtn_map(clientp)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_grab: unable to map shared info\n");
830N/A#endif
830N/A /*
830N/A * Ungrab the retained raster
830N/A */
830N/A (void) XDgaUnGrabRetainedWindow(dpy, win);
830N/A return (RTN_FAILED);
830N/A }
830N/A#endif /* SERVER_DGA */
830N/A clientp->rtn_flags |= RTN_GRABBED;
830N/A return (RTN_PASSED);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_pixels()
830N/A *
830N/A * DGA Retained Pixel Memory . This function returns a pointer
830N/A * to the shared retained pixel memory.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the client structure.
830N/A *
830N/A * Outputs: u_char * - Pointer to retained pixel memory.
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: None.
830N/A *
830N/A *
830N/A */
830N/Avoid *
830N/Adga_rtn_pixels(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A return ((void *)clientp->rtn_pixels);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * dga_rtn_ungrab()
830N/A *
830N/A * DGA Retained Window Ungrab. This function frees the resources
830N/A * associated with a DGA retained retained raster. The shared
830N/A * memory mappings in the calling process's address space are
830N/A * unmapped, the shared info file is closed, and the server is
830N/A * notified through a protocol extension to free all its resources
830N/A * associated with the DGA retained raster. Should any of these
830N/A * steps fail, 0 is returned. A non-zero result is returned upon
830N/A * success.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the Dga_window for which DGA
830N/A * to the retained raster is desired.
830N/A *
830N/A * Outputs: 0 - failed
830N/A * -1 - passed
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: DisplayString() X11 MACRO
830N/A * XDgaUnGrabRetainedWindow()
830N/A * _dga_is_X_window()
830N/A * _dga_rtn_unmap()
830N/A * fprintf() DEBUG ONLY
830N/A *
830N/A */
830N/Aint
830N/Adga_rtn_ungrab(clientpi)
830N/A Dga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A
830N/A return (dgai_rtn_ungrab_common(clientp, 0));
830N/A}
830N/A
830N/Aint
830N/Adgai_rtn_ungrab_common(clientp, drawableGrabber)
830N/A _Dga_window clientp;
830N/A int drawableGrabber;
830N/A{
830N/A int status = -1;
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin;
830N/A WXINFO *infop;
830N/A#else
830N/A Display *dpy;
830N/A Window win;
830N/A#endif /* SERVER_DGA */
830N/A
830N/A /*
830N/A * Check for an invalid Dga_window
830N/A */
830N/A if ((clientp == (Dga_window) NULL)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_ungrab: passed null pointer\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * If the retained window has not been grabbed then don't
830N/A * do anything.
830N/A */
830N/A if ((clientp->rtn_flags & RTN_GRABBED) == 0)
830N/A return (RTN_FAILED);
830N/A
830N/A /*
830N/A * Unmap the calling process's resources if present.
830N/A */
830N/A status &= _dga_rtn_unmap(clientp);
830N/A
830N/A /*
830N/A * Set the dga_window retained window server sequence counter pointer
830N/A * to reflect that the retained raster has NOT been grabbed.
830N/A */
830N/A clientp->s_rtnseq_p = &(clientp->c_rtnseq);
830N/A
830N/A#ifdef SERVER_DGA
830N/A /* Determine the window associated with this clientp */
830N/A infop = (WXINFO *) clientp->w_info;
830N/A pWin = (((WDEV *)(infop->wdev))->pWin);
830N/A
830N/A status &= DgaSharedRetained(pWin, 0, pWin->drawable.id);
830N/A#else
830N/A /*
830N/A * Find out if this is an X window. If so get the Display and window
830N/A * id. These are used to determine the name of the shared retained
830N/A * info file. NOTE: DGA to retained rasters is currently supported
830N/A * only for X windows.
830N/A */
830N/A if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_rtn_grab: Unsupported window type\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Tell the server to deallocate its retained window
830N/A * resources.if there are no other clients grabbing this window
830N/A */
830N/A if (!dgai_win_check_multiple_grab(clientp,drawableGrabber))
830N/A status &= XDgaUnGrabRetainedWindow(dpy, win);
830N/A
830N/A#endif /* SERVER_DGA */
830N/A
830N/A clientp->rtn_flags = 0;
830N/A
830N/A if (status)
830N/A return (RTN_PASSED);
830N/A else
830N/A return (RTN_FAILED);
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * _dga_rtn_map()
830N/A *
830N/A * DGA Retained Window Map. This function maps the retained window
830N/A * shared memory into the clients address space after determining
830N/A * the path to the retained window information file. The shared
830N/A * retained info structure is mapped followed by the actual pixel
830N/A * array used when the pixels are not cached in hardware. The
830N/A * address of the shared retained info structure is then place in
830N/A * the dga_window structure along with the client dependent information.
830N/A * Should any operation fail, a NULL pointer is placed in the dga_window
830N/A * structure and 0 is returned.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the dga_window structure
830N/A *
830N/A * Outputs: 0 - failed
830N/A * -1 - passed
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: DisplayString() X11 MACRO
830N/A * XDgaGetRetainedPath()
830N/A * _dga_is_X_window()
830N/A * close()
830N/A * fprintf() DEBUG ONLY
830N/A * fstat()
830N/A * getpagesize() SUNOS ONLY
830N/A * mmap()
830N/A * munmap()
830N/A * open()
830N/A * sprintf()
830N/A * sscanf()
830N/A * strcat()
830N/A * strcpy()
830N/A * strlen()
830N/A * sysconf() SVR4 ONLY
830N/A * unlink()
830N/A *
830N/A */
830N/Aint
830N/A_dga_rtn_map(clientp)
830N/A_Dga_window clientp;
830N/A{
830N/A SHARED_RETAINED_INFO *infop;
830N/A#ifdef SERVER_DGA
830N/A WXINFO *winfop;
830N/A#else
830N/A u_char *pixels;
830N/A int filefd;
830N/A size_t size;
830N/A size_t pagesize;
830N/A u_int port;
830N/A Display *dpy;
830N/A Window win;
830N/A char *dpystr;
830N/A struct stat rstat;
830N/A char path[256];
830N/A char host[MAXHOSTNAMELEN];
830N/A#endif /* SERVER_DGA */
830N/A
830N/A /*
830N/A * Check for a non-zero pointer.
830N/A */
830N/A if (clientp == (_Dga_window) NULL) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: dga_window pointer (NULL)\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * If the shared retained information has already been mapped don't
830N/A * do anything.
830N/A */
830N/A if ((clientp->rtn_flags & RTN_MAPPED))
830N/A return (RTN_PASSED);
830N/A
830N/A#ifdef SERVER_DGA
830N/A /* Determine the window associated with this clientp */
830N/A winfop = (WXINFO *) clientp->w_info;
830N/A infop = (SHARED_RETAINED_INFO *)winfop->w_srtndlink;
830N/A
830N/A /* Initialise clientp's retained info structure - refer dga.h */
830N/A clientp->rtn_fd = 0; /* I don't think that it is needed any more */
830N/A clientp->rtn_size = infop->s_size;
830N/A clientp->c_rtnseq = 0;
830N/A clientp->s_rtnseq_p = (u_int *)&(infop->s_modified);
830N/A clientp->c_rtncachseq = 0;
830N/A clientp->s_rtncachseq_p = (u_int *)&(infop->s_cacheseq);
830N/A clientp->rtn_info = (caddr_t)infop;
830N/A clientp->rtn_pixels = (caddr_t)(infop->s_pixels);
830N/A clientp->rtn_flags |= RTN_MAPPED;
830N/A
830N/A return (RTN_PASSED);
830N/A#else /* SERVER_DGA */
830N/A /*
830N/A * Find out if this is an X window. If so get the Display and window
830N/A * id. These are used to determine the name of the shared retained
830N/A * info file. NOTE: DGA to retained rasters are currently supported
830N/A * only for X windows.
830N/A */
830N/A if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: Unsupported window type\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Now locate the shared retained info file within the file system.
830N/A * This file is located in /tmp by default, but through a server
830N/A * command line option, can be located anywhere on the system in
830N/A * question. Get the path from the server using the protocol
830N/A * extension. Then create the filename using the display string
830N/A * and the port number.
830N/A */
830N/A if (!XDgaGetRetainedPath(dpy, win, path)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: XDgaGetRetainedPath failed\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * If the path is equal to "", then use the default directory
830N/A * path.
830N/A */
830N/A if (!(*path))
830N/A (void) strcpy(path, "/tmp");
830N/A else if (strlen(path) > RTN_MAXPATH) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: path longer than supported\n");
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A (void) strcat(path, RTN_FILE);
830N/A
830N/A /*
830N/A * Now get the port number for this display
830N/A */
830N/A dpystr = DisplayString(dpy);
830N/A if (dpystr[0] == ':')
830N/A (void) sscanf(dpystr, ":%u", &port);
830N/A else
830N/A (void) sscanf(dpystr, "%[^:]:%u", host, &port);
830N/A
830N/A /*
830N/A * Combine the port number and the window id with the path
830N/A * string.
830N/A */
830N/A size = strlen(path);
830N/A (void) sprintf(path+size, "%01x.%08x", port, win);
830N/A
830N/A if ((filefd = open(path,O_RDWR,0666))<0) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: unable to open file %s\n",
830N/A path);
830N/A#endif
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Now unlink the file to guarantee that it will disappear
830N/A * should the client or server crash.
830N/A */
830N/A (void) unlink(path);
830N/A
830N/A#ifdef SVR4
830N/A pagesize = sysconf(_SC_PAGESIZE);
830N/A#else
830N/A pagesize = getpagesize();
830N/A#endif
830N/A
830N/A /*
830N/A * Check the state of the file. If the size of the file
830N/A * is insufficient to contain the first page of the shared
830N/A * retained info structure (ie < pagesize) report a failure.
830N/A */
830N/A if (fstat(filefd, &rstat) < 0) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: unable get file status\n");
830N/A#endif
830N/A (void) close(filefd);
830N/A return (RTN_FAILED);
830N/A }
830N/A if (rstat.st_size < pagesize) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: file not correct size, %ld\n",
830N/A rstat.st_size);
830N/A#endif
830N/A (void) close(filefd);
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Map the SHARED_RETAINED_INFO structure
830N/A */
830N/A infop = (SHARED_RETAINED_INFO *) mmap(0,
830N/A pagesize,
830N/A PROT_READ|PROT_WRITE,
830N/A MAP_SHARED,
830N/A filefd,
830N/A (off_t)0);
830N/A
830N/A if (infop == (SHARED_RETAINED_INFO *) -1) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: unable to mmap file %s\n",
830N/A path);
830N/A#endif
830N/A (void) close(filefd);
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * If the file is not actually a shared retained information file
830N/A * or its the wrong version, unmap the shared memory, close the
830N/A * file and return the error status.
830N/A */
830N/A if ((infop->magic != RTN_MAGIC) || (infop->version > RTN_VERS)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: contents of file %s incorrect\n",
830N/A path);
830N/A#endif
830N/A (void) munmap((caddr_t) infop, pagesize);
830N/A (void) close(filefd);
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Map the pixel page
830N/A */
830N/A pixels = (u_char *) mmap(0,
830N/A infop->s_size,
830N/A PROT_READ|PROT_WRITE,
830N/A MAP_SHARED,
830N/A filefd,
830N/A (off_t)infop->first_mmap_offset);
830N/A
830N/A if (pixels == (u_char *) -1) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_map: unable to mmap pixel area\n");
830N/A#endif
830N/A (void) munmap((caddr_t) infop, pagesize);
830N/A (void) close(filefd);
830N/A return (RTN_FAILED);
830N/A }
830N/A
830N/A /*
830N/A * Set the fields of the client information.
830N/A */
830N/A clientp->rtn_fd = filefd;
830N/A clientp->rtn_size = infop->s_size;
830N/A clientp->c_rtnseq = 0;
830N/A clientp->s_rtnseq_p = &(infop->s_modified);
830N/A clientp->c_rtncachseq = 0;
830N/A clientp->s_rtncachseq_p = &(infop->s_cacheseq);
830N/A clientp->rtn_info = (void *) infop;
830N/A clientp->rtn_pixels = (void *) pixels;
830N/A clientp->rtn_flags |= RTN_MAPPED;
830N/A
830N/A#ifdef DEBUG
830N/A _dga_rtn_dump(infop);
830N/A#endif
830N/A
830N/A return (RTN_PASSED);
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A/*
830N/A *
830N/A * _dga_rtn_unmap()
830N/A *
830N/A * DGA Retained Window Unmap. This function unmaps the retained window
830N/A * shared memory from the clients address space given the pointer to the
830N/A * dga_window structure. The pixel array associated with the retained info
830N/A * structure is unmapped first followed by the shared retained info
830N/A * structure. The pointer to the shared memory info structure within the
830N/A * dga_window structure is set to NULL and the shared memory file is then
830N/A * closed. Should any operation fail zero is returned.
830N/A *
830N/A * Inputs: Dga_window - Pointer to the dga_window structure for which
830N/A * the the shared retained info structure is to
830N/A * be removed.
830N/A *
830N/A * Outputs: 0 - failed
830N/A * -1 - passed
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: close()
830N/A * fprintf() DEBUG ONLY
830N/A * getpagesize() SUNOS ONLY
830N/A * munmap()
830N/A * sysconf() SVR4 ONLY
830N/A * unlink()
830N/A *
830N/A */
830N/Aint
830N/A_dga_rtn_unmap(clientp)
830N/A _Dga_window clientp;
830N/A{
830N/A size_t pagesize;
830N/A int status = 0;
830N/A
830N/A if ((clientp->rtn_flags & RTN_MAPPED) == 0)
830N/A return (RTN_FAILED);
830N/A
830N/A#ifndef SERVER_DGA
830N/A#ifdef SVR4
830N/A pagesize = sysconf(_SC_PAGESIZE);
830N/A#else
830N/A pagesize = getpagesize();
830N/A#endif
830N/A
830N/A if (munmap(clientp->rtn_pixels, clientp->rtn_size)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_unmap: pixel unmap failed\n");
830N/A#endif
830N/A status++;
830N/A }
830N/A if (munmap(clientp->rtn_info, pagesize)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "_dga_rtn_unmap: info page unmap failed\n");
830N/A#endif
830N/A status++;
830N/A }
830N/A#endif /*SERVER_DGA */
830N/A clientp->rtn_info = (void *) NULL;
830N/A clientp->c_rtnseq = 0;
830N/A clientp->s_rtnseq_p = (u_int *) &(clientp->s_rtnseq_p);
830N/A clientp->c_rtncachseq = 0;
830N/A clientp->s_rtncachseq_p = &(clientp->c_rtncachseq);
830N/A clientp->rtn_pixels = (void*) NULL;
830N/A (void) close(clientp->rtn_fd);
830N/A clientp->rtn_fd = -1;
830N/A clientp->rtn_flags &= ~(RTN_MAPPED);
830N/A clientp->rtn_flags |= RTN_MAPCHG;
830N/A if (status)
830N/A return (RTN_FAILED);
830N/A else
830N/A return (RTN_PASSED);
830N/A}
830N/A
830N/A#ifdef DEBUG
830N/A/*
830N/A *
830N/A * _dga_rtn_dump()
830N/A *
830N/A * DGA Retained Info Structure Dump. This function prints out the contents
830N/A * of the shared retained info structure found at the specified address.
830N/A *
830N/A * Inputs: SHARED_RETAINED_INFO * - Pointer to the structure to dump.
830N/A *
830N/A * Outputs: None.
830N/A *
830N/A * Globals: None.
830N/A *
830N/A * Externals: printf()
830N/A *
830N/A */
830N/Avoid
830N/A_dga_rtn_dump(infop)
830N/A SHARED_RETAINED_INFO *infop;
830N/A{
830N/A
830N/A if (infop == (SHARED_RETAINED_INFO *) NULL)
830N/A (void) printf("NULL info pointer passed to _dga_rtn_dump\n");
830N/A else {
830N/A (void) printf("Retained window info page is %p\n", infop);
830N/A (void) printf("\tmagic =\t\t%u\n", infop->magic);
830N/A (void) printf("\tversion =\t%u\n", infop->version);
830N/A (void) printf("\tobsolete =\t%u\n", infop->obsolete);
830N/A (void) printf("\tdevice =\t%u\n", infop->device);
830N/A (void) printf("\tcached =\t%u\n", infop->cached);
830N/A (void) printf("\ts_cacheseq =\t%u\n", infop->s_cacheseq);
830N/A (void) printf("\ts_modified =\t%u\n", infop->s_modified);
830N/A (void) printf("\ts_wxlink =\t%p\n", infop->s_wxlink);
830N/A (void) printf("\tfirst_mmap_offset =\t%u\n", infop->first_mmap_offset);
830N/A (void) printf("\tdevice_offset =\t%u\n", infop->device_offset);
830N/A (void) printf("\twidth =\t\t%d\n", infop->width);
830N/A (void) printf("\theight =\t%d\n", infop->height);
830N/A (void) printf("\tlineybtes =\t%u\n", infop->linebytes);
830N/A (void) printf("\ts_fd =\t\t%d\n", infop->s_fd);
830N/A (void) printf("\ts_size =\t%u\n", infop->s_size);
830N/A (void) printf("\ts_pixels =\t%p\n", infop->s_pixels);
830N/A (void) printf("\tfn = \t\t%s\n", infop->fn);
830N/A (void) printf("\tscr_name = \t%s\n", infop->scr_name);
830N/A (void) printf("\tc_fd =\t\t%d\n", infop->c_fd);
830N/A (void) printf("\tc_size =\t%u\n", infop->c_size);
830N/A (void) printf("\tc_pixels =\t%p\n", infop->c_pixels);
830N/A (void) printf("\tc_modified =\t%u\n", infop->c_modified);
830N/A (void) printf("\tc_cacheseq =\t%u\n", infop->c_cacheseq);
830N/A }
830N/A}
830N/A#endif
830N/A
830N/A
830N/Avoid *
830N/Adga_win_bboxinfop(clientpi)
830N/ADga_window clientpi;
830N/A{
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A WXINFO *infop = (WXINFO *) clientp->w_info;
830N/A
830N/A if (infop->w_version < 2)
830N/A return 0;
830N/A return (void *) &(infop->w_window_boundary);
830N/A}