rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / x11 / libdga / src / win_update.c
blobc998ce912d22f8336085cb410e2f107e5f438bfb
1 /* Copyright (c) 1993, 1994, 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.
26 ** win_update.c
28 ** Routines of the update phase for windows.
31 #include <assert.h>
32 #ifdef SERVER_DGA
33 #include <X11/Xlib.h>
34 #endif /* SERVER_DGA */
35 #include "dga_incls.h"
36 #include "pix_grab.h"
37 #include "mbufsetstr.h"
38 #include "rtn_grab.h"
40 static void dgai_win_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
41 static int dgai_win_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
42 static void dgai_win_mb_update (_Dga_window dgawin);
43 static void dgai_mbwin_syncLockSubj (_Dga_window dgawin);
47 ** Note: for the sake of simplicity, we always report the following
48 ** types of changes whenever an alias or mbufset composition change
49 ** occurs. We could try to optimize the change reporting and only
50 ** report an attribute change if we know that the attribute has definitely
51 ** changed since the last lock. But this requires a lot of comparison
52 ** between the current and previous lock subjects and the decision
53 ** tree gets quite large. This method of "over reporting" may result
54 ** in some redundant change reports. If we want to do this type of optimization
55 ** in the future, we still can. But for now we keep it simple.
57 ** These are the window changes that are automatically reported whenever
58 ** an alias or mbufset composition change occurs.
60 ** site
61 ** clip
62 ** curs
63 ** bstore
68 ** ENTRY ROUTINE FOR WINDOW UPDATE PHASE
71 int
72 dgai_win_update (_Dga_window dgawin, short bufIndex)
74 DgaLastSeqs lastSeqs;
77 ** 1. The first thing we do in the update phase is to synchronize
78 ** the client structure. When all pertinent client change
79 ** counters match the server, we are synchronized. The
80 ** reason we must do this in a loop is that some of the
81 ** synchronizations require us to temporarily unlock and
82 ** relock. While the drawable is unlocked, it can undergo
83 ** more changes, so we may need to start the synchronization
84 ** process over.
87 /* Determine sequence counts for state reported to client */
88 dgai_win_getLastSeqs(dgawin, &lastSeqs);
90 /* start accumulating changes */
91 dgawin->changeMask = 0;
93 /* repeat synchronization functions as needed through possible unlock/relocks */
94 do {
96 /* first, see if the window shared info is still valid */
97 if (dgai_mbsmemb_syncZombie(dgawin)) {
98 break;
101 /* next, we must check the multibuffer state.
102 This may alter the effective lock subject, whose type the
103 other synchronization checks depend on */
104 if (lastSeqs.mbufseq != *dgawin->s_mbufseq_p) {
105 dgai_win_mb_update(dgawin);
106 lastSeqs.mbufseq = *dgawin->s_mbufseq_p;
107 dgawin->c_mbufseq = lastSeqs.mbufseq;
110 /* synchronize with current changes to attributes of
111 the effective lock subject -- depends on the type
112 of the current lock subject */
113 if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
114 dgai_win_syncChanges(dgawin, &lastSeqs);
115 } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
116 dgai_vmbuf_syncChanges(dgawin, &lastSeqs, bufIndex);
117 } else {
118 /* should never happen */
119 assert(0);
122 /* Note: whether we need to sync again depends on the type too */
123 } while (dgai_win_syncAgain(dgawin, &lastSeqs));
125 /* Check if the devinfo has changed */
126 dgai_mbsmemb_devinfo_update(dgawin);
129 ** 2. The foregoing synchronization step has determined whether
130 ** any attribute changes have occurred. We must now determine
131 ** if there are any derivative changes to report.
133 ** Currently, the only derivative changes for a window or viewable
134 ** multibuffer are those in common with all mbufset members.
136 dgai_mbsmemb_figureDerivChgs(dgawin);
139 ** 3. Next, we must report changes through notification functions,
140 ** if possible.
143 /* report any changes that we can through notification */
144 dgai_mbsmemb_notify(dgawin);
148 ** 4. Lastly, indicate that we are fully synchronized and get out.
151 /* the dgawin client structure is now fully synchronized with the
152 shared info */
153 dgawin->c_wm_chngcnt[bufIndex + 1] = *dgawin->s_chngcnt_p;
156 ** 5. If this is an overlay window, then we need to tell the
157 ** server that we may have modified the opaque shape.
159 if (dgawin->isOverlay && dgawin->c_ovlstate != DGA_OVLSTATE_CONFLICT)
160 *dgawin->s_ovlshapevalid_p = 0;
162 /* if there are still any changes that were not notified through notification
163 functions, DGA_DRAW_MODIF will return nonzero (the client is
164 supposed to call this routine immediately following the lock).
165 This will cause a well-behaved client to synchronize with
166 the remaining unreported changes */
167 return (dgawin->changeMask);
171 static void
172 dgai_win_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
174 pLastSeqs->mbufseq = dgawin->c_mbufseq;
175 pLastSeqs->clipseq = dgawin->c_clipseq;
176 pLastSeqs->curseq = dgawin->c_curseq;
177 pLastSeqs->rtnseq = dgawin->c_rtnseq;
182 ** Returns nonzero if we are still not synchronized
185 static int
186 dgai_win_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
188 /* if a multibuffer change happened, we're still not done */
189 if (pLastSeqs->mbufseq != *dgawin->s_mbufseq_p) {
190 return (1);
193 /* Note: there's no need to check cacheseq because the effective lock subject
194 of a window can only be a window or viewable multibuffer.
195 Neither of these are cached */
197 if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
198 if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p) &&
199 (pLastSeqs->curseq == *dgawin->s_curseq_p) &&
200 (pLastSeqs->rtnseq == *dgawin->s_rtnseq_p) &&
201 (!dgawin->isOverlay
202 || dgawin->c_ovlstate == *dgawin->s_ovlstate_p)) {
203 return (0);
205 } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
206 if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p) &&
207 (pLastSeqs->curseq == *dgawin->s_curseq_p)) {
208 /* Note: viewable mbuf never has bstore to sync up to */
209 return (0);
211 } else {
212 /* should never happen */
213 assert(0);
216 /* we're not synchronized; need to go around the loop again */
217 return (1);
222 ** Called at window lock time when we have detected an mbufset change.
223 ** At the return of this routine, dgawin->eLockSubj indicates the member
224 ** drawable for which subsequent changes are to be detected.
227 static void
228 dgai_win_mb_update (_Dga_window dgawin)
230 /* react to enable and composition changes */
231 dgai_mbsmemb_syncMbufset(dgawin);
233 /* if window is multibuffered we may need synchronization */
234 if (dgawin->pMbs) {
236 /* synchronize with any display buffer change */
237 dgai_mbwin_syncLockSubj(dgawin);
239 /* synchronize render buffer state (if necessary) */
240 dgai_mbsmemb_syncRendBuf(dgawin);
243 /* an mbufset change causes us to report changes to all attrs */
244 { u_int reportChanges;
245 if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
246 reportChanges = DGA_WIN_CHANGEABLE_ATTRS;
247 } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
248 reportChanges = DGA_VMBUF_CHANGEABLE_ATTRS;
249 } else {
250 /* should never happen */
251 assert(0);
253 dgawin->changeMask |= (DGA_CHANGE_MBUFSET | reportChanges);
258 ** Determine effective lock subject for a multibuffered window.
261 static void
262 dgai_mbwin_syncLockSubj (_Dga_window dgawin)
264 WXINFO *infop;
266 infop = (WXINFO *) dgawin->w_info;
268 /* see if there is window aliasing. Window aliasing
269 can only happen in video flip mode */
270 if (infop->w_mbsInfo.flipMode == DGA_MBFLIP_VIDEO) {
272 /* when the window is aliased, the effective lock subject is the
273 currently displayed buffer */
274 dgawin->eLockSubj = infop->wx_dbuf.display_buffer;
276 if (dgawin->eLockSubj != dgawin->eLockSubjPrev) {
278 /* an alias change causes us to report changes on all attributes */
279 dgawin->changeMask |= (DGA_CHANGE_ALIAS | DGA_WIN_CHANGEABLE_ATTRS);
287 ** Current lock subject is a window. Synchronize with changes.
290 void
291 dgai_win_syncChanges (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
293 /* clip state has changed? */
294 if (pLastSeqs->clipseq != *dgawin->s_clipseq_p) {
295 dgawin->changeMask |= DGA_CHANGE_CLIP;
296 dgai_win_clip_update(dgawin);
297 pLastSeqs->clipseq = *dgawin->s_clipseq_p;
300 /* cursor state has changed? */
301 if (pLastSeqs->curseq != *dgawin->s_curseq_p) {
302 dgawin->changeMask |= DGA_CHANGE_CURSOR;
303 dgai_win_curs_update(dgawin);
304 pLastSeqs->curseq = *dgawin->s_curseq_p;
307 /* backing store state has changed? */
308 if ((pLastSeqs->rtnseq != *dgawin->s_rtnseq_p) ||
309 ((dgawin->rtn_flags & RTN_GRABBED) &&
310 !(dgawin->rtn_flags & RTN_MAPPED))) {
311 dgawin->changeMask |= DGA_CHANGE_BSTORE;
312 dgai_win_rtn_update(dgawin);
313 pLastSeqs->rtnseq = *dgawin->s_rtnseq_p;
316 if (dgawin->isOverlay && dgawin->c_ovlstate != *dgawin->s_ovlstate_p) {
317 dgawin->changeMask |= DGA_CHANGE_OVLSTATE;
318 dgawin->c_ovlstate = *dgawin->s_ovlstate_p;