pgbouncer: update to 1.24.0
[oi-userland.git] / components / x11 / libdga / src / mbufset.c
blobf74924f692d63dd28d699bd77a2d0f5c36b8a54c
1 /* Copyright (c) 1993, 1997, Oracle and/or its affiliates. All rights reserved.
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
24 /*
25 ** mbufset.c - Routines to manipulate multibuffer set objects.
28 #include <malloc.h>
29 #ifdef SERVER_DGA
30 #include <X11/Xlib.h>
31 #endif /* SERVER_DGA */
32 #include "dga_incls.h"
33 #include "pix_grab.h"
34 #include "mbufsetstr.h"
36 static void dgai_mbufset_destroy (DgaMbufSetPtr pMbs);
38 extern int dga_pixlist_add(Dga_token token, Display *dpy, Pixmap pix);
41 ** Create a client-side multibuffer set object based on information
42 ** in the shinfo of a window. The window must be locked prior to calling.
45 DgaMbufSetPtr
46 dgai_mbufset_create (_Dga_window dgawin)
48 DgaMbufSetPtr pMbs;
49 WXINFO *infop;
50 DgaMbufSetShinfoPtr pMbsInfo;
51 short numBufs, i;
52 unsigned long bufViewableFlags, bufMask;
53 Dga_token token;
54 _Dga_pixmap dgapix;
55 XID *pShinfoId;
57 infop = (WXINFO *) dgawin->w_info;
58 pMbsInfo = &infop->w_mbsInfo;
59 token = (Dga_token) pMbsInfo->nmbufShpxToken;
60 pShinfoId = &(pMbsInfo->nmbufIds[0]);
62 /* allocate mbufset client structure */
63 if (!(pMbs = (DgaMbufSetPtr) malloc(sizeof(DgaMbufSet)))) {
64 return (NULL);
67 numBufs = infop->wx_dbuf.number_buffers;
68 pMbs->numBufs = numBufs;
70 for (i = 0; i < numBufs; i++) {
71 pMbs->pNbPixmaps[i] = NULL;
74 bufViewableFlags = pMbsInfo->bufViewableFlags;
75 bufMask = 1L;
76 for (i = 0; i < numBufs; i++, pShinfoId++) {
77 if (!(bufViewableFlags & bufMask)) {
78 if (!dga_pixlist_add(token, dgawin->w_dpy, (Pixmap)*pShinfoId) ||
79 !(dgapix = dga_pix_grab(token, (Pixmap)*pShinfoId))) {
80 goto Bad;
82 pMbs->pNbPixmaps[i] = dgapix;
83 pMbs->pNbShinfo[i] = (SHARED_PIXMAP_INFO *)dgapix->p_infop;
84 } else {
85 pMbs->pNbShinfo[i] = NULL;
87 pMbs->mbufseq[i] = 0;
88 pMbs->clipseq[i] = 0;
89 pMbs->curseq[i] = 0;
90 pMbs->cacheSeqs[i] = 0;
91 pMbs->devInfoSeqs[i] = 0;
92 pMbs->prevLocked[i] = 0;
93 bufMask = bufMask << 1;
96 /* success */
97 pMbs->refcnt = 1;
98 return (pMbs);
100 Bad:
101 dgai_mbufset_destroy(pMbs);
102 return (NULL);
106 void
107 dgai_mbufset_incref (DgaMbufSetPtr pMbs)
109 pMbs->refcnt++;
113 static void
114 dgai_mbufset_destroy (DgaMbufSetPtr pMbs)
116 short i;
118 for (i = 0; i < pMbs->numBufs; i++) {
119 if (pMbs->pNbPixmaps[i]) {
120 dga_pix_ungrab(pMbs->pNbPixmaps[i]);
123 free(pMbs);
126 void
127 dgai_mbufset_decref (DgaMbufSetPtr pMbs)
129 if ((int)(--(pMbs->refcnt)) <= 0) {
130 dgai_mbufset_destroy(pMbs);