1 | /*
|
---|
2 | * Common internal rootless definitions and code
|
---|
3 | */
|
---|
4 | /*
|
---|
5 | * Copyright (c) 2001 Greg Parker. All Rights Reserved.
|
---|
6 | * Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
|
---|
7 | *
|
---|
8 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
9 | * copy of this software and associated documentation files (the "Software"),
|
---|
10 | * to deal in the Software without restriction, including without limitation
|
---|
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
12 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
13 | * Software is furnished to do so, subject to the following conditions:
|
---|
14 | *
|
---|
15 | * The above copyright notice and this permission notice shall be included in
|
---|
16 | * all copies or substantial portions of the Software.
|
---|
17 | *
|
---|
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
21 | * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
---|
24 | * DEALINGS IN THE SOFTWARE.
|
---|
25 | *
|
---|
26 | * Except as contained in this notice, the name(s) of the above copyright
|
---|
27 | * holders shall not be used in advertising or otherwise to promote the sale,
|
---|
28 | * use or other dealings in this Software without prior written authorization.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifdef HAVE_DIX_CONFIG_H
|
---|
32 | #include <dix-config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include <stdint.h>
|
---|
36 | #ifndef _ROOTLESSCOMMON_H
|
---|
37 | #define _ROOTLESSCOMMON_H
|
---|
38 |
|
---|
39 | #include "misc.h"
|
---|
40 | #include "rootless.h"
|
---|
41 | #include "fb.h"
|
---|
42 |
|
---|
43 | #include "scrnintstr.h"
|
---|
44 |
|
---|
45 | #ifdef RENDER
|
---|
46 | #include "picturestr.h"
|
---|
47 | #endif
|
---|
48 |
|
---|
49 |
|
---|
50 | // Debug output, or not.
|
---|
51 | #ifdef ROOTLESSDEBUG
|
---|
52 | #define RL_DEBUG_MSG ErrorF
|
---|
53 | #else
|
---|
54 | #define RL_DEBUG_MSG(a, ...)
|
---|
55 | #endif
|
---|
56 |
|
---|
57 |
|
---|
58 | // Global variables
|
---|
59 | extern DevPrivateKey rootlessGCPrivateKey;
|
---|
60 | extern DevPrivateKey rootlessScreenPrivateKey;
|
---|
61 | extern DevPrivateKey rootlessWindowPrivateKey;
|
---|
62 | extern DevPrivateKey rootlessWindowOldPixmapPrivateKey;
|
---|
63 |
|
---|
64 |
|
---|
65 | // RootlessGCRec: private per-gc data
|
---|
66 | typedef struct {
|
---|
67 | GCFuncs *originalFuncs;
|
---|
68 | GCOps *originalOps;
|
---|
69 | } RootlessGCRec;
|
---|
70 |
|
---|
71 |
|
---|
72 | // RootlessScreenRec: per-screen private data
|
---|
73 | typedef struct _RootlessScreenRec {
|
---|
74 | // Rootless implementation functions
|
---|
75 | RootlessFrameProcsPtr imp;
|
---|
76 |
|
---|
77 | // Wrapped screen functions
|
---|
78 | CreateScreenResourcesProcPtr CreateScreenResources;
|
---|
79 | CloseScreenProcPtr CloseScreen;
|
---|
80 |
|
---|
81 | CreateWindowProcPtr CreateWindow;
|
---|
82 | DestroyWindowProcPtr DestroyWindow;
|
---|
83 | RealizeWindowProcPtr RealizeWindow;
|
---|
84 | UnrealizeWindowProcPtr UnrealizeWindow;
|
---|
85 | MoveWindowProcPtr MoveWindow;
|
---|
86 | ResizeWindowProcPtr ResizeWindow;
|
---|
87 | RestackWindowProcPtr RestackWindow;
|
---|
88 | ReparentWindowProcPtr ReparentWindow;
|
---|
89 | ChangeBorderWidthProcPtr ChangeBorderWidth;
|
---|
90 | PositionWindowProcPtr PositionWindow;
|
---|
91 | ChangeWindowAttributesProcPtr ChangeWindowAttributes;
|
---|
92 |
|
---|
93 | CreateGCProcPtr CreateGC;
|
---|
94 | CopyWindowProcPtr CopyWindow;
|
---|
95 | GetImageProcPtr GetImage;
|
---|
96 | SourceValidateProcPtr SourceValidate;
|
---|
97 |
|
---|
98 | MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
|
---|
99 | ValidateTreeProcPtr ValidateTree;
|
---|
100 |
|
---|
101 | SetShapeProcPtr SetShape;
|
---|
102 |
|
---|
103 | #ifdef RENDER
|
---|
104 | CompositeProcPtr Composite;
|
---|
105 | GlyphsProcPtr Glyphs;
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | InstallColormapProcPtr InstallColormap;
|
---|
109 | UninstallColormapProcPtr UninstallColormap;
|
---|
110 | StoreColorsProcPtr StoreColors;
|
---|
111 |
|
---|
112 | void *pixmap_data;
|
---|
113 | unsigned int pixmap_data_size;
|
---|
114 |
|
---|
115 | ColormapPtr colormap;
|
---|
116 |
|
---|
117 | void *redisplay_timer;
|
---|
118 | unsigned int redisplay_timer_set :1;
|
---|
119 | unsigned int redisplay_queued :1;
|
---|
120 | unsigned int redisplay_expired :1;
|
---|
121 | unsigned int colormap_changed :1;
|
---|
122 | } RootlessScreenRec, *RootlessScreenPtr;
|
---|
123 |
|
---|
124 | // "Definition of the Porting Layer for the X11 Sample Server" says
|
---|
125 | // unwrap and rewrap of screen functions is unnecessary, but
|
---|
126 | // screen->CreateGC changes after a call to cfbCreateGC.
|
---|
127 |
|
---|
128 | #define SCREEN_UNWRAP(screen, fn) \
|
---|
129 | screen->fn = SCREENREC(screen)->fn;
|
---|
130 |
|
---|
131 | #define SCREEN_WRAP(screen, fn) \
|
---|
132 | SCREENREC(screen)->fn = screen->fn; \
|
---|
133 | screen->fn = Rootless##fn
|
---|
134 |
|
---|
135 |
|
---|
136 | // Accessors for screen and window privates
|
---|
137 |
|
---|
138 | #define SCREENREC(pScreen) ((RootlessScreenRec *) \
|
---|
139 | dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey))
|
---|
140 |
|
---|
141 | #define SETSCREENREC(pScreen, v) \
|
---|
142 | dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v)
|
---|
143 |
|
---|
144 | #define WINREC(pWin) ((RootlessWindowRec *) \
|
---|
145 | dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey))
|
---|
146 |
|
---|
147 | #define SETWINREC(pWin, v) \
|
---|
148 | dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v)
|
---|
149 |
|
---|
150 | // Call a rootless implementation function.
|
---|
151 | // Many rootless implementation functions are allowed to be NULL.
|
---|
152 | #define CallFrameProc(pScreen, proc, params) \
|
---|
153 | if (SCREENREC(pScreen)->frameProcs.proc) { \
|
---|
154 | RL_DEBUG_MSG("calling frame proc " #proc " "); \
|
---|
155 | SCREENREC(pScreen)->frameProcs.proc params; \
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | // BoxRec manipulators
|
---|
160 | // Copied from shadowfb
|
---|
161 |
|
---|
162 | #define TRIM_BOX(box, pGC) { \
|
---|
163 | BoxPtr extents = &pGC->pCompositeClip->extents;\
|
---|
164 | if(box.x1 < extents->x1) box.x1 = extents->x1; \
|
---|
165 | if(box.x2 > extents->x2) box.x2 = extents->x2; \
|
---|
166 | if(box.y1 < extents->y1) box.y1 = extents->y1; \
|
---|
167 | if(box.y2 > extents->y2) box.y2 = extents->y2; \
|
---|
168 | }
|
---|
169 |
|
---|
170 | #define TRANSLATE_BOX(box, pDraw) { \
|
---|
171 | box.x1 += pDraw->x; \
|
---|
172 | box.x2 += pDraw->x; \
|
---|
173 | box.y1 += pDraw->y; \
|
---|
174 | box.y2 += pDraw->y; \
|
---|
175 | }
|
---|
176 |
|
---|
177 | #define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
|
---|
178 | TRANSLATE_BOX(box, pDraw); \
|
---|
179 | TRIM_BOX(box, pGC); \
|
---|
180 | }
|
---|
181 |
|
---|
182 | #define BOX_NOT_EMPTY(box) \
|
---|
183 | (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
|
---|
184 |
|
---|
185 |
|
---|
186 | // HUGE_ROOT and NORMAL_ROOT
|
---|
187 | // We don't want to clip windows to the edge of the screen.
|
---|
188 | // HUGE_ROOT temporarily makes the root window really big.
|
---|
189 | // This is needed as a wrapper around any function that calls
|
---|
190 | // SetWinSize or SetBorderSize which clip a window against its
|
---|
191 | // parents, including the root.
|
---|
192 |
|
---|
193 | extern RegionRec rootlessHugeRoot;
|
---|
194 |
|
---|
195 | #define HUGE_ROOT(pWin) \
|
---|
196 | do { \
|
---|
197 | WindowPtr w = pWin; \
|
---|
198 | while (w->parent) \
|
---|
199 | w = w->parent; \
|
---|
200 | saveRoot = w->winSize; \
|
---|
201 | w->winSize = rootlessHugeRoot; \
|
---|
202 | } while (0)
|
---|
203 |
|
---|
204 | #define NORMAL_ROOT(pWin) \
|
---|
205 | do { \
|
---|
206 | WindowPtr w = pWin; \
|
---|
207 | while (w->parent) \
|
---|
208 | w = w->parent; \
|
---|
209 | w->winSize = saveRoot; \
|
---|
210 | } while (0)
|
---|
211 |
|
---|
212 |
|
---|
213 | // Returns TRUE if this window is a top-level window (i.e. child of the root)
|
---|
214 | // The root is not a top-level window.
|
---|
215 | #define IsTopLevel(pWin) \
|
---|
216 | ((pWin) && (pWin)->parent && !(pWin)->parent->parent)
|
---|
217 |
|
---|
218 | // Returns TRUE if this window is a root window
|
---|
219 | #define IsRoot(pWin) \
|
---|
220 | ((pWin) == WindowTable[(pWin)->drawable.pScreen->myNum])
|
---|
221 |
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * SetPixmapBaseToScreen
|
---|
225 | * Move the given pixmap's base address to where pixel (0, 0)
|
---|
226 | * would be if the pixmap's actual data started at (x, y).
|
---|
227 | * Can't access the bits before the first word of the drawable's data in
|
---|
228 | * rootless mode, so make sure our base address is always 32-bit aligned.
|
---|
229 | */
|
---|
230 | #define SetPixmapBaseToScreen(pix, _x, _y) { \
|
---|
231 | PixmapPtr _pPix = (PixmapPtr) (pix); \
|
---|
232 | _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
|
---|
233 | ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \
|
---|
234 | (int)(_y) * _pPix->devKind); \
|
---|
235 | if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \
|
---|
236 | size_t _diff = ((size_t) _pPix->devPrivate.ptr) & \
|
---|
237 | (FB_UNIT / CHAR_BIT - 1); \
|
---|
238 | _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
|
---|
239 | _diff; \
|
---|
240 | _pPix->drawable.x = _diff / \
|
---|
241 | (_pPix->drawable.bitsPerPixel / CHAR_BIT); \
|
---|
242 | } \
|
---|
243 | }
|
---|
244 |
|
---|
245 |
|
---|
246 | // Returns TRUE if this window is visible inside a frame
|
---|
247 | // (e.g. it is visible and has a top-level or root parent)
|
---|
248 | Bool IsFramedWindow(WindowPtr pWin);
|
---|
249 |
|
---|
250 | // Routines that cause regions to get redrawn.
|
---|
251 | // DamageRegion and DamageRect are in global coordinates.
|
---|
252 | // DamageBox is in window-local coordinates.
|
---|
253 | void RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion);
|
---|
254 | void RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h);
|
---|
255 | void RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox);
|
---|
256 | void RootlessRedisplay(WindowPtr pWindow);
|
---|
257 | void RootlessRedisplayScreen(ScreenPtr pScreen);
|
---|
258 |
|
---|
259 | void RootlessQueueRedisplay(ScreenPtr pScreen);
|
---|
260 |
|
---|
261 | /* Return the colormap currently installed on the given screen. */
|
---|
262 | ColormapPtr RootlessGetColormap (ScreenPtr pScreen);
|
---|
263 |
|
---|
264 | /* Convert colormap to ARGB. */
|
---|
265 | Bool RootlessResolveColormap (ScreenPtr pScreen, int first_color,
|
---|
266 | int n_colors, uint32_t *colors);
|
---|
267 |
|
---|
268 | void RootlessFlushWindowColormap (WindowPtr pWin);
|
---|
269 | void RootlessFlushScreenColormaps (ScreenPtr pScreen);
|
---|
270 |
|
---|
271 | // Move a window to its proper location on the screen.
|
---|
272 | void RootlessRepositionWindow(WindowPtr pWin);
|
---|
273 |
|
---|
274 | // Move the window to it's correct place in the physical stacking order.
|
---|
275 | void RootlessReorderWindow(WindowPtr pWin);
|
---|
276 |
|
---|
277 | void RootlessScreenExpose (ScreenPtr pScreen);
|
---|
278 | void RootlessHideAllWindows (void);
|
---|
279 | void RootlessShowAllWindows (void);
|
---|
280 | void RootlessUpdateRooted (Bool state);
|
---|
281 |
|
---|
282 | void RootlessEnableRoot (ScreenPtr pScreen);
|
---|
283 | void RootlessDisableRoot (ScreenPtr pScreen);
|
---|
284 |
|
---|
285 | void RootlessSetPixmapOfAncestors(WindowPtr pWin);
|
---|
286 |
|
---|
287 | #endif /* _ROOTLESSCOMMON_H */
|
---|