home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEXlib / pl_startup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  19.4 KB  |  819 lines

  1. /* $XConsortium: pl_startup.c,v 1.9 92/08/26 13:06:22 mor Exp $ */
  2.  
  3. /******************************************************************************
  4. Copyright 1987,1991 by Digital Equipment Corporation, Maynard, Massachusetts
  5. Copyright 1992 by the Massachusetts Institute of Technology
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, distribute, and sell this software and its
  10. documentation for any purpose is hereby granted without fee, provided that
  11. the above copyright notice appear in all copies and that both that copyright
  12. notice and this permission notice appear in supporting documentation, and that
  13. the name of Digital or M.I.T. not be used in advertising or publicity
  14. pertaining to distribution of the software without specific, written prior
  15. permission.  Digital and M.I.T. make no representations about the suitability
  16. of this software for any purpose.  It is provided "as is" without express or
  17. implied warranty.
  18.  
  19. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25. SOFTWARE.
  26. ******************************************************************************/
  27.  
  28. #include "PEXlib.h"
  29. #include "PEXlibint.h"
  30. #include "pl_global_def.h"
  31. #include <stdio.h>
  32.  
  33.  
  34. int
  35. PEXInitialize (display, info_return, length, error_string)
  36.  
  37. INPUT  Display        *display;
  38. OUTPUT PEXExtensionInfo    **info_return;
  39. INPUT  int        length;
  40. OUTPUT char        *error_string;
  41.  
  42. {
  43.     pexGetExtensionInfoReq    *req;
  44.     pexGetExtensionInfoReply    rep;
  45.     PEXExtensionInfo        *extInfo;
  46.     XExtCodes            *pExtCodes;
  47.     PEXDisplayInfo        *pexDisplayInfo;
  48.     int                enumType, match, i;
  49.     PEXEnumTypeDesc        *enumReturn;
  50.     unsigned long        *numReturn;
  51.     char            *string;
  52.  
  53.     extern XExtCodes        *XInitExtension();
  54.     extern Status        _PEXConvertMaxHitsEvent();
  55.     Bool            _PEXConvertOCError();
  56.     void            _PEXPrintOCError();
  57.     int                _PEXCloseDisplay();
  58.  
  59.  
  60.     /*
  61.      * Lock the display.
  62.      */
  63.  
  64.     LockDisplay (display);
  65.  
  66.  
  67.     /*
  68.      * Initialize the PEX extension on this display.
  69.      */
  70.  
  71.     *info_return = NULL;
  72.  
  73.     if ((pExtCodes = XInitExtension (display, "X3D-PEX")) == NULL)
  74.     {
  75.         UnlockDisplay (display);
  76.     PEXSyncHandle (display);
  77.  
  78.     XGetErrorDatabaseText (display, "PEXlibMessage", "BadExtension",
  79.         "Could not initialize the PEX extension on the specified display",
  80.             error_string, length);
  81.  
  82.     return (PEXBadExtension);
  83.     }
  84.  
  85.  
  86.     /*
  87.      * For each display initialized by PEXlib, some additional data must
  88.      * be maintained (such as extension codes and float format).  A linked
  89.      * list of records is maintained, one for each open display, with the
  90.      * most recently referenced display always at the beginning.
  91.      */
  92.  
  93.     pexDisplayInfo = (PEXDisplayInfo *)
  94.     PEXAllocBuf ((unsigned) (sizeof (PEXDisplayInfo)));
  95.  
  96.     if (!pexDisplayInfo)
  97.     {
  98.         UnlockDisplay (display);
  99.     PEXSyncHandle (display);
  100.  
  101.     XGetErrorDatabaseText (display, "PEXlibMessage", "BadLocalAlloc",
  102.         "Could not allocate memory for PEXlib internal usage",
  103.             error_string, length);
  104.  
  105.     return (PEXBadLocalAlloc);
  106.     }
  107.  
  108.     PEXAddDisplayInfo (display, pexDisplayInfo);
  109.  
  110.     pexDisplayInfo->extCodes = pExtCodes;
  111.     pexDisplayInfo->extOpcode = pExtCodes->major_opcode;
  112.     pexDisplayInfo->lastResID = 0;
  113.     pexDisplayInfo->lastReqType = -1;
  114.     pexDisplayInfo->lastReqNum = -1;
  115.  
  116.  
  117.     /*
  118.      * Check if the PEX server on this display supports the client's native
  119.      * floating point format.  If not, choose a server supported format
  120.      * (hopefully, the server's native floating point format is in the
  121.      * first entry returned by PEXGetEnumTypeInfo).  In places specified by
  122.      * the PEXlib spec, PEXlib will convert between the client's native
  123.      * floating point format and the server supported format.
  124.      */
  125.  
  126.     enumType = PEXETFloatFormat;
  127.  
  128.     if (PEXGetEnumTypeInfo (display, DefaultRootWindow (display), 1,
  129.     &enumType, PEXETIndex, &numReturn, &enumReturn) == 0)
  130.     {
  131.         UnlockDisplay (display);
  132.     PEXSyncHandle (display);
  133.  
  134.     XGetErrorDatabaseText (display, "PEXlibMessage", "GetEnumFailure",
  135.         "Implicit call to PEXGetEnumTypeInfo by PEXInitialize failed",
  136.             error_string, length);
  137.  
  138.     return (PEXBadFloatConversion);
  139.     }
  140.  
  141.     pexDisplayInfo->fpSupport = enumReturn;
  142.     pexDisplayInfo->fpCount = *numReturn;
  143.  
  144.     for (i = match = 0; i < *numReturn; i++)
  145.     if (enumReturn[i].index == NATIVE_FP_FORMAT)
  146.     {
  147.         match = 1;
  148.         break;
  149.     }
  150.  
  151.     if (enumReturn == NULL || *numReturn == 0)
  152.     {
  153.         UnlockDisplay (display);
  154.     PEXSyncHandle (display);
  155.  
  156.     XGetErrorDatabaseText (display, "PEXlibMessage", "NoFloats",
  157.         "No floating point formats supported by server",
  158.             error_string, length);
  159.  
  160.     return (PEXBadFloatConversion);
  161.     }
  162.     else if (match)
  163.     {
  164.     pexDisplayInfo->fpFormat = NATIVE_FP_FORMAT;
  165.     pexDisplayInfo->fpConvert = 0;
  166.     }
  167.     else
  168.     {
  169.     pexDisplayInfo->fpFormat = enumReturn[0].index;
  170.     pexDisplayInfo->fpConvert = 1;
  171.     }
  172.  
  173.     PEXFreeBuf (numReturn);
  174.  
  175.  
  176.     /*
  177.      * Tell Xlib how to convert an Output Command error from
  178.      * wire to client format.
  179.      */
  180.  
  181.     XESetWireToError (display, pExtCodes->first_error + BadPEXOutputCommand,
  182.     _PEXConvertOCError);
  183.  
  184.  
  185.     /*
  186.      * Tell Xlib how to print the OC error.
  187.      */
  188.  
  189.     XESetPrintErrorValues (display, pExtCodes->extension, _PEXPrintOCError);
  190.  
  191.  
  192.     /*
  193.      * Tell Xlib how to convert a MaxHitReachedEvent from
  194.      * wire to client format.
  195.      */
  196.  
  197.     XESetWireToEvent (display, pExtCodes->first_event + PEXMaxHitsReached,
  198.     _PEXConvertMaxHitsEvent);
  199.  
  200.  
  201.     /*
  202.      * Tell Xlib which PEXlib function to call when the display is closed.
  203.      */
  204.  
  205.     XESetCloseDisplay (display, pExtCodes->extension, _PEXCloseDisplay);
  206.  
  207.  
  208.     /*
  209.      * Get information about the PEX server extension.
  210.      */
  211.  
  212.     PEXGetReq (GetExtensionInfo, req);
  213.     req->clientProtocolMajor = PEX_PROTO_MAJOR;
  214.     req->clientProtocolMinor = PEX_PROTO_MINOR;
  215.  
  216.     if (_XReply (display,  &rep, 0, xFalse) == 0)
  217.     {
  218.         UnlockDisplay (display);
  219.     PEXSyncHandle (display);
  220.  
  221.     XGetErrorDatabaseText (display, "PEXlibMessage", "GetInfoFailure",
  222.         "Could not get PEX extension information",
  223.             error_string, length);
  224.  
  225.     return (PEXBadExtension);
  226.     }
  227.  
  228.  
  229.     /*
  230.      * Get the vendor name string and null terminate it.
  231.      */
  232.  
  233.     if (!(string = (char *) PEXAllocBuf ((unsigned) (rep.lengthName + 1))))
  234.     {
  235.         UnlockDisplay (display);
  236.     PEXSyncHandle (display);
  237.  
  238.     XGetErrorDatabaseText (display, "PEXlibMessage", "BadLocalAlloc",
  239.         "Could not allocate memory for PEXlib internal usage",
  240.             error_string, length);
  241.  
  242.     return (PEXBadLocalAlloc);
  243.     }
  244.  
  245.     _XReadPad (display, (char *) string, (long) (rep.lengthName));
  246.     string[rep.lengthName] = '\0';
  247.  
  248.  
  249.     /*
  250.      * We can unlock the display now.
  251.      */
  252.  
  253.     UnlockDisplay (display);
  254.     PEXSyncHandle (display);
  255.  
  256.  
  257.     /*
  258.      * Store the extension info.
  259.      */
  260.  
  261.     extInfo = *info_return = pexDisplayInfo->extInfo = (PEXExtensionInfo *)
  262.     PEXAllocBuf ((unsigned) (sizeof (PEXExtensionInfo)));
  263.  
  264.     if (!extInfo)
  265.     {
  266.     XGetErrorDatabaseText (display, "PEXlibMessage", "BadLocalAlloc",
  267.         "Could not allocate memory for PEXlib internal usage",
  268.             error_string, length);
  269.  
  270.     return (PEXBadLocalAlloc);
  271.     }
  272.  
  273.     extInfo->major_version = rep.majorVersion;
  274.     extInfo->minor_version = rep.minorVersion;
  275.     extInfo->release = rep.release;
  276.     extInfo->subset_info = rep.subsetInfo;
  277.     extInfo->vendor_name = string;
  278.     extInfo->major_opcode = pExtCodes->major_opcode;
  279.     extInfo->first_event = pExtCodes->first_event;
  280.     extInfo->first_error = pExtCodes->first_error;
  281.  
  282.     if (rep.majorVersion == PEX_PROTO_MAJOR)
  283.     return (0);
  284.     else
  285.     {
  286.     char str[PEXErrorStringLength];
  287.  
  288.     XGetErrorDatabaseText (display, "PEXlibMessage", "BadProtoVersion",
  289.         "Client speaks PEX %d.%d; Server speaks PEX %d.%d",
  290.             str, PEXErrorStringLength);
  291.  
  292.     sprintf (error_string, str,
  293.             PEX_PROTO_MAJOR, PEX_PROTO_MINOR,
  294.         rep.majorVersion, rep.minorVersion);
  295.   
  296.     return (PEXBadProtocolVersion);
  297.     }
  298. }
  299.  
  300.  
  301. PEXExtensionInfo *
  302. PEXGetExtensionInfo (display)
  303.  
  304. INPUT Display    *display;
  305.  
  306. {
  307.     PEXDisplayInfo     *pexDisplayInfo;
  308.  
  309.     
  310.     PEXGetDisplayInfo (display, pexDisplayInfo);
  311.     return (pexDisplayInfo ? pexDisplayInfo->extInfo : NULL);
  312. }
  313.  
  314.  
  315. int
  316. PEXGetProtocolFloatFormat (display)
  317.  
  318. INPUT Display    *display;
  319.  
  320. {
  321.     PEXDisplayInfo     *pexDisplayInfo;
  322.  
  323.     
  324.     PEXGetDisplayInfo (display, pexDisplayInfo);
  325.     return (pexDisplayInfo ? pexDisplayInfo->fpFormat : 0);
  326. }
  327.  
  328.  
  329. /*
  330.  * PEXGetEnumTypeInfo is broken in the PEX spec.  For 5.1, PEXlib will
  331.  * be compatible with the PEX SI.  In 6.0, the encoding should be fixed.
  332.  */
  333.  
  334. Status
  335. PEXGetEnumTypeInfo (display, drawable, numEnumTypes, enumTypes,
  336.     itemMask, numReturn, enumInfoReturn)
  337.  
  338. INPUT Display            *display;
  339. INPUT Drawable            drawable;
  340. INPUT unsigned long        numEnumTypes;
  341. INPUT int            *enumTypes;
  342. INPUT unsigned long        itemMask;
  343. OUTPUT unsigned long        **numReturn;
  344. OUTPUT PEXEnumTypeDesc        **enumInfoReturn;
  345.  
  346. {
  347.     pexGetEnumTypeInfoReq    *req;
  348.     pexGetEnumTypeInfoReply    rep;
  349.     char            *prepbuf, *pstartrep;
  350.     PEXEnumTypeDesc        *penum;
  351.     unsigned long        *pcounts;
  352.     char            *pstring;
  353.     CARD16            *dstEnumType;
  354.     int                *srcEnumType;
  355.     int                numDescs, totDescs, length, i, j;
  356.  
  357.  
  358.     /*
  359.      * Lock around the critical section, for multithreading.
  360.      */
  361.  
  362.     LockDisplay (display);
  363.  
  364.  
  365.     /*
  366.      * Put the request in the X request buffer and get a reply.
  367.      */
  368.  
  369.     PEXGetReqExtra (GetEnumTypeInfo, numEnumTypes * sizeof (CARD16), req);
  370.  
  371.     req->drawable = drawable;
  372.     req->itemMask = itemMask;
  373.     req->numEnums = numEnumTypes;
  374.  
  375.     for (i = 0, dstEnumType = (CARD16 *) &req[1], srcEnumType = enumTypes;
  376.      i < numEnumTypes;
  377.      i++, dstEnumType++, srcEnumType++)
  378.     {
  379.     *dstEnumType = (CARD16) *srcEnumType;
  380.     }
  381.  
  382.     if (_XReply (display, &rep, 0, xFalse) == 0)
  383.     {
  384.     UnlockDisplay (display);
  385.     PEXSyncHandle (display);
  386.     *numReturn = NULL;
  387.     *enumInfoReturn = NULL;
  388.     return (0);            /* return an error */
  389.     }
  390.  
  391.  
  392.     /*
  393.      * Error if fewer than numEnumTypes lists returned.
  394.      */
  395.  
  396.     if (rep.numLists < numEnumTypes) 
  397.     {
  398.     UnlockDisplay (display);
  399.     PEXSyncHandle (display);
  400.     *numReturn = NULL;
  401.     *enumInfoReturn = NULL;
  402.     return (0);            /* return an error */
  403.     }
  404.  
  405.  
  406.     /*
  407.      * Allocate a scratch buffer and copy the reply data to the buffer.
  408.      */
  409.  
  410.     pstartrep = (char *) _XAllocScratch (display,
  411.     (unsigned long) (rep.length << 2));
  412.  
  413.     _XRead (display, pstartrep, (long) (rep.length << 2));
  414.  
  415.  
  416.     /*
  417.      * Count total number of enums returned.
  418.      */
  419.  
  420.     for (i = 0, totDescs = 0, prepbuf = pstartrep; i < rep.numLists; i++)
  421.     { 
  422.          numDescs = *((CARD32 *) prepbuf);
  423.      totDescs += numDescs; 
  424.  
  425.          prepbuf += sizeof (CARD32);
  426.          if (i == rep.numLists - 1)
  427.          break;
  428.  
  429.      if (itemMask == PEXETIndex)
  430.      {
  431.          prepbuf += PADDED_BYTES (numDescs * sizeof (INT16));
  432.      }
  433.      else if (itemMask == PEXETMnemonic)
  434.      {
  435.          for (j = 0; j < numDescs; j++)
  436.          {
  437.             length = *((CARD16 *) prepbuf);
  438.             prepbuf += PADDED_BYTES (sizeof (CARD16) + length);
  439.          }
  440.      }
  441.      else if (itemMask == PEXETAll)
  442.      {
  443.          for (j = 0; j < numDescs; j++)
  444.          {
  445.             prepbuf += sizeof (INT16);
  446.             length = *((CARD16 *) prepbuf);
  447.             prepbuf += (sizeof (CARD16) + PADDED_BYTES (length));
  448.          }
  449.      }
  450.     }
  451.  
  452.  
  453.     /*
  454.      * Allocate storage for enum data to be returned to the client.
  455.      */
  456.  
  457.     *enumInfoReturn = penum = (PEXEnumTypeDesc *)
  458.     PEXAllocBuf ((unsigned) (totDescs * sizeof (PEXEnumTypeDesc)));
  459.  
  460.  
  461.     /*
  462.      * Allocate storage to return the counts to the client.
  463.      */
  464.  
  465.     *numReturn = pcounts = (unsigned long *)
  466.        PEXAllocBuf ((unsigned) (numEnumTypes * sizeof (unsigned long)));
  467.  
  468.  
  469.     /*
  470.      * Retrieve the lists of enum info.
  471.      */
  472.  
  473.     for (i = 0, prepbuf = pstartrep; i < rep.numLists; i++, pcounts++)
  474.     {
  475.         *pcounts = numDescs = *((CARD32 *) prepbuf);
  476.         prepbuf += sizeof (CARD32);
  477.  
  478.     if (itemMask == PEXETIndex)
  479.     {
  480.         for (j = 0; j < numDescs; j++, penum++)
  481.         {
  482.         penum->descriptor = NULL;
  483.             penum->index = *((INT16 *) prepbuf);
  484.             prepbuf += sizeof (INT16);
  485.         }
  486.  
  487.         if (numDescs & 1)
  488.             prepbuf += sizeof (INT16);
  489.     }
  490.     else if (itemMask == PEXETMnemonic)
  491.     {
  492.         for (j = 0; j < numDescs; j++, penum++)
  493.         {
  494.         penum->index = 0;
  495.  
  496.         length = *((CARD16 *) prepbuf);
  497.         prepbuf += sizeof (CARD16);
  498.         penum->descriptor = pstring =
  499.             (char *) PEXAllocBuf ((unsigned) (length + 1));
  500.         COPY_AREA ((char *) prepbuf, (char *) pstring, length);
  501.         pstring[length] = '\0';       /* null terminate */
  502.  
  503.         prepbuf += (PADDED_BYTES (sizeof (CARD16) + length) - 
  504.             sizeof (CARD16));
  505.         }
  506.     }
  507.     else if (itemMask == PEXETAll)
  508.     {
  509.         for (j = 0; j < numDescs; j++, penum++)
  510.         {
  511.         penum->index = *((INT16 *) prepbuf);
  512.         prepbuf += sizeof (INT16);
  513.         
  514.         length = *((CARD16 *) prepbuf);
  515.         prepbuf += sizeof (CARD16);
  516.         penum->descriptor = pstring =
  517.             (char *) PEXAllocBuf ((unsigned) (length + 1));
  518.         COPY_AREA ((char *) prepbuf, (char *) pstring, length);
  519.         pstring[length] = '\0';       /* null terminate */
  520.  
  521.         prepbuf += PADDED_BYTES (length);
  522.         }
  523.     }
  524.     }
  525.  
  526.  
  527.     /*
  528.      * Done, so unlock and check for synchronous-ness.
  529.      */
  530.  
  531.     UnlockDisplay (display);
  532.     PEXSyncHandle (display);
  533.  
  534.     return (1);
  535. }
  536.  
  537.  
  538. Status
  539. PEXGetImpDepConstants (display, drawable, numNames, names, constantsReturn)
  540.  
  541. INPUT Display            *display;
  542. INPUT Drawable            drawable;
  543. INPUT unsigned long        numNames;
  544. INPUT unsigned short        *names;
  545. OUTPUT PEXImpDepConstant    **constantsReturn;
  546.  
  547. {
  548.     pexGetImpDepConstantsReq    *req;
  549.     pexGetImpDepConstantsReply    rep;
  550.     int                convertFP;
  551.  
  552.  
  553.     /*
  554.      * Lock around the critical section, for multithreading.
  555.      */
  556.  
  557.     LockDisplay (display);
  558.  
  559.  
  560.     /*
  561.      * Put the request in the X request buffer and get a reply.
  562.      */
  563.  
  564.     PEXGetFPReqExtra (GetImpDepConstants,
  565.     numNames * sizeof (CARD16), req, convertFP);
  566.  
  567.     req->drawable = drawable;
  568.     req->numNames = numNames;
  569.  
  570.     COPY_AREA ((char *) names, (char *) &req[1], numNames * sizeof (CARD16));
  571.  
  572.     if (_XReply (display, &rep, 0, xFalse) == 0)
  573.     {
  574.         UnlockDisplay (display);
  575.         PEXSyncHandle (display);
  576.     *constantsReturn = NULL;
  577.         return (0);            /* return an error */
  578.     }
  579.  
  580.  
  581.     /*
  582.      * Allocate a buffer for the client.
  583.      */
  584.  
  585.     *constantsReturn = (PEXImpDepConstant *) PEXAllocBuf (
  586.     (unsigned) (numNames * sizeof (PEXImpDepConstant)));
  587.  
  588.  
  589.     /*
  590.      * Copy the values into the buffer.
  591.      */
  592.  
  593.     _XRead (display, (char *) *constantsReturn,
  594.     (long) (numNames * sizeof (CARD32)));
  595.  
  596.  
  597.     /*
  598.      * Done, so unlock and check for synchronous-ness.
  599.      */
  600.  
  601.     UnlockDisplay (display);
  602.     PEXSyncHandle (display);
  603.  
  604.     return (1);
  605. }
  606.  
  607.  
  608. Status
  609. PEXMatchRenderingTargets (display, drawable, depth, type, visual,
  610.     maxTargets, numTargets, targets)
  611.  
  612. INPUT Display            *display;
  613. INPUT Drawable            drawable;
  614. INPUT int            depth;
  615. INPUT int            type;
  616. INPUT Visual            *visual;
  617. INPUT unsigned long              maxTargets;
  618. OUTPUT unsigned long        *numTargets;
  619. OUTPUT PEXRenderingTarget    **targets;
  620.  
  621. {
  622.     pexMatchRenderingTargetsReq        *req;
  623.     pexMatchRenderingTargetsReply       rep;
  624.     PEXRenderingTarget            *info;
  625.     pexRendererTarget            *matchRec;
  626.     int                    i;
  627.  
  628.  
  629.     /*
  630.      * Lock around the critical section, for multithreading.
  631.      */
  632.  
  633.     LockDisplay (display);
  634.  
  635.  
  636.     /*
  637.      * Put the request in the X request buffer and get a reply.
  638.      */
  639.  
  640.     PEXGetReq (MatchRenderingTargets, req);
  641.  
  642.     req->drawable = drawable;
  643.     req->depth = depth;
  644.     req->type = type;
  645.     req->visualID = visual ? visual->visualid : 0;
  646.     req->maxTriplets = maxTargets;
  647.  
  648.     if (_XReply (display, &rep, 0, xFalse) == 0)
  649.     {
  650.         UnlockDisplay (display);
  651.         PEXSyncHandle (display);
  652.     *numTargets = 0;
  653.     *targets = NULL;
  654.         return (0);               /* return an error */
  655.     }
  656.  
  657.     *numTargets = rep.length / 2;
  658.  
  659.  
  660.     /*
  661.      * Allocate a scratch buffer and copy the reply data to the buffer.
  662.      */
  663.  
  664.     matchRec = (pexRendererTarget *) _XAllocScratch (display,
  665.     (unsigned long) (rep.length << 2));
  666.  
  667.     _XRead (display, (char *) matchRec, (long) (rep.length << 2));
  668.  
  669.  
  670.     /*
  671.      * Allocate a buffer for the target list to pass back to the client.
  672.      */
  673.  
  674.     *targets = info = (PEXRenderingTarget *) PEXAllocBuf (
  675.     (unsigned) (*numTargets * sizeof (PEXRenderingTarget)));
  676.  
  677.     for (i = 0; i < *numTargets; i++)
  678.     {
  679.     info->depth = matchRec->depth;
  680.     info->type = matchRec->type;
  681.     info->visual = _XVIDtoVisual (display, matchRec->visualID);
  682.     info++;
  683.     matchRec++;
  684.     }
  685.  
  686.  
  687.     /*
  688.      * Done, so unlock and check for synchronous-ness.
  689.      */
  690.  
  691.     UnlockDisplay (display);
  692.     PEXSyncHandle (display);
  693.  
  694.     return (1);
  695. }
  696.  
  697.  
  698. /*
  699.  * Routine called to convert an Output Command error from wire format
  700.  * to client format.  The callback is set up in PEXInitialize.
  701.  */
  702.  
  703. Bool
  704. _PEXConvertOCError (display, client_error, wire_error)
  705.  
  706. INPUT Display        *display;
  707. OUTPUT XErrorEvent    *client_error;
  708. INPUT xError        *wire_error;
  709.  
  710. {
  711.     PEXOCErrorEvent        *client = (PEXOCErrorEvent *) client_error;
  712.     pexOutputCommandError    *wire = (pexOutputCommandError *) wire_error;
  713.  
  714.  
  715.     /*
  716.      * PEXOCErrorEvent = XErrorEvent + oc_op_code + ocs_processed_count
  717.      * Xlib will convert all of the XErrorEvent fields.  We must
  718.      * convert the op code and count.
  719.      */
  720.  
  721.     client->op_code = wire->opcode;
  722.     client->count = wire->numCommands;
  723.  
  724.     return (True);
  725. }
  726.  
  727.  
  728. /*
  729.  * Routine called when an Output Command error is printed.
  730.  * The callback is set up in PEXInitialize.
  731.  */
  732.  
  733. void
  734. _PEXPrintOCError (display, error, fp)
  735.  
  736. INPUT Display        *display;
  737. INPUT XErrorEvent    *error;
  738. #ifdef __STDC__
  739. INPUT void        *fp;
  740. #else
  741. INPUT FILE        *fp;
  742. #endif
  743. {
  744.     /*
  745.      * Xlib bug - extension codes should be passed to this function,
  746.      * but they're not.  We must get them ourselves.
  747.      */
  748.  
  749.     PEXDisplayInfo     *pexDisplayInfo;
  750.     char        opcode_message[PEXErrorStringLength];
  751.     char        oc_count_message[PEXErrorStringLength];
  752.  
  753.  
  754.     PEXGetDisplayInfo (display, pexDisplayInfo);
  755.  
  756.     if (error->error_code ==
  757.     pexDisplayInfo->extCodes->first_error + BadPEXOutputCommand)
  758.     {
  759.     PEXOCErrorEvent    *oc_error = (PEXOCErrorEvent *) error;
  760.  
  761.     XGetErrorDatabaseText (display,
  762.         "PEXlibMessage", "OCErrorOpCode",
  763.         "Opcode of failed output command : %d\n",
  764.             opcode_message, PEXErrorStringLength);
  765.  
  766.     XGetErrorDatabaseText (display,
  767.         "PEXlibMessage", "OCErrorCount",
  768.         "Number of output commands processed before error : %d\n",
  769.             oc_count_message, PEXErrorStringLength);
  770.  
  771.     fprintf (fp, "  ");
  772.     fprintf (fp, opcode_message, oc_error->op_code);
  773.  
  774.     fprintf (fp, "  ");
  775.     fprintf (fp, oc_count_message, oc_error->count);
  776.     }
  777. }
  778.  
  779.  
  780. /*
  781.  * Routine called when a display is closed via XCloseDisplay.
  782.  * The callback is set up in PEXInitialize.
  783.  */
  784.  
  785. int
  786. _PEXCloseDisplay (display, codes)
  787.  
  788. INPUT Display    *display;
  789. INPUT XExtCodes    *codes;
  790.  
  791. {
  792.     PEXDisplayInfo    *pexDisplayInfo;
  793.  
  794.  
  795.     /*
  796.      * Free the extension codes and other info attached to this display.
  797.      */
  798.  
  799.     PEXRemoveDisplayInfo (display, pexDisplayInfo);
  800.  
  801.     if (pexDisplayInfo == NULL)
  802.     return (0);
  803.  
  804.     PEXFreeBuf ((char *) (pexDisplayInfo->extInfo->vendor_name));
  805.     PEXFreeBuf ((char *) (pexDisplayInfo->extInfo));
  806.     PEXFreeBuf ((char *) (pexDisplayInfo->fpSupport));
  807.     PEXFreeBuf ((char *) pexDisplayInfo);
  808.  
  809.  
  810.     /*
  811.      * Free the pick path cache (if it's not in use)
  812.      */
  813.  
  814.     if (PEXPickCache && !PEXPickCacheInUse)
  815.     PEXFreeBuf ((char *) PEXPickCache);
  816.  
  817.     return (1);
  818. }
  819.