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 | #ifndef _ROOTLESSCOMMON_H
|
---|
36 | #define _ROOTLESSCOMMON_H
|
---|
37 |
|
---|
38 | #include "rootless.h"
|
---|
39 | #include "fb.h"
|
---|
40 |
|
---|
41 | #ifdef RENDER
|
---|
42 | #include "picturestr.h"
|
---|
43 | #endif
|
---|
44 |
|
---|
45 |
|
---|
46 | // Debug output, or not.
|
---|
47 | #ifdef ROOTLESSDEBUG
|
---|
48 | #define RL_DEBUG_MSG ErrorF
|
---|
49 | #else
|
---|
50 | #define RL_DEBUG_MSG(a, ...)
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | // Global variables
|
---|
55 | extern int rootlessGCPrivateIndex;
|
---|
56 | extern int rootlessScreenPrivateIndex;
|
---|
57 | extern int rootlessWindowPrivateIndex;
|
---|
58 |
|
---|
59 |
|
---|
60 | // RootlessGCRec: private per-gc data
|
---|
61 | typedef struct {
|
---|
62 | GCFuncs *originalFuncs;
|
---|
63 | GCOps *originalOps;
|
---|
64 | } RootlessGCRec;
|
---|
65 |
|
---|
66 |
|
---|
67 | // RootlessScreenRec: per-screen private data
|
---|
68 | typedef struct _RootlessScreenRec {
|
---|
69 | // Rootless implementation functions
|
---|
70 | RootlessFrameProcsPtr imp;
|
---|
71 |
|
---|
72 | // Wrapped screen functions
|
---|
73 | CreateScreenResourcesProcPtr CreateScreenResources;
|
---|
74 | CloseScreenProcPtr CloseScreen;
|
---|
75 |
|
---|
76 | CreateWindowProcPtr CreateWindow;
|
---|
77 | DestroyWindowProcPtr DestroyWindow;
|
---|
78 | RealizeWindowProcPtr RealizeWindow;
|
---|
79 | UnrealizeWindowProcPtr UnrealizeWindow;
|
---|
80 | MoveWindowProcPtr MoveWindow;
|
---|
81 | ResizeWindowProcPtr ResizeWindow;
|
---|
82 | RestackWindowProcPtr RestackWindow;
|
---|
83 | ReparentWindowProcPtr ReparentWindow;
|
---|
84 | ChangeBorderWidthProcPtr ChangeBorderWidth;
|
---|
85 | PositionWindowProcPtr PositionWindow;
|
---|
86 | ChangeWindowAttributesProcPtr ChangeWindowAttributes;
|
---|
87 |
|
---|
88 | CreateGCProcPtr CreateGC;
|
---|
89 | PaintWindowBackgroundProcPtr PaintWindowBackground;
|
---|
90 | PaintWindowBorderProcPtr PaintWindowBorder;
|
---|
91 | CopyWindowProcPtr CopyWindow;
|
---|
92 | GetImageProcPtr GetImage;
|
---|
93 | SourceValidateProcPtr SourceValidate;
|
---|
94 |
|
---|
95 | MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
|
---|
96 | ValidateTreeProcPtr ValidateTree;
|
---|
97 |
|
---|
98 | #ifdef SHAPE
|
---|
99 | SetShapeProcPtr SetShape;
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | #ifdef RENDER
|
---|
103 | CompositeProcPtr Composite;
|
---|
104 | GlyphsProcPtr Glyphs;
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | void *pixmap_data;
|
---|
108 | unsigned int pixmap_data_size;
|
---|
109 |
|
---|
110 | void *redisplay_timer;
|
---|
111 | unsigned int redisplay_timer_set :1;
|
---|
112 | unsigned int redisplay_queued :1;
|
---|
113 | unsigned int redisplay_expired :1;
|
---|
114 | } RootlessScreenRec, *RootlessScreenPtr;
|
---|
115 |
|
---|
116 |
|
---|
117 | #undef MIN
|
---|
118 | #define MIN(x,y) ((x) < (y) ? (x) : (y))
|
---|
119 | #undef MAX
|
---|
120 | #define MAX(x,y) ((x) > (y) ? (x) : (y))
|
---|
121 |
|
---|
122 | // "Definition of the Porting Layer for the X11 Sample Server" says
|
---|
123 | // unwrap and rewrap of screen functions is unnecessary, but
|
---|
124 | // screen->CreateGC changes after a call to cfbCreateGC.
|
---|
125 |
|
---|
126 | #define SCREEN_UNWRAP(screen, fn) \
|
---|
127 | screen->fn = SCREENREC(screen)->fn;
|
---|
128 |
|
---|
129 | #define SCREEN_WRAP(screen, fn) \
|
---|
130 | SCREENREC(screen)->fn = screen->fn; \
|
---|
131 | screen->fn = Rootless##fn
|
---|
132 |
|
---|
133 |
|
---|
134 | // Accessors for screen and window privates
|
---|
135 |
|
---|
136 | #define SCREENREC(pScreen) \
|
---|
137 | ((RootlessScreenRec *)(pScreen)->devPrivates[rootlessScreenPrivateIndex].ptr)
|
---|
138 |
|
---|
139 | #define WINREC(pWin) \
|
---|
140 | ((RootlessWindowRec *)(pWin)->devPrivates[rootlessWindowPrivateIndex].ptr)
|
---|
141 |
|
---|
142 |
|
---|
143 | // Call a rootless implementation function.
|
---|
144 | // Many rootless implementation functions are allowed to be NULL.
|
---|
145 | #define CallFrameProc(pScreen, proc, params) \
|
---|
146 | if (SCREENREC(pScreen)->frameProcs.proc) { \
|
---|
147 | RL_DEBUG_MSG("calling frame proc " #proc " "); \
|
---|
148 | SCREENREC(pScreen)->frameProcs.proc params; \
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | // BoxRec manipulators
|
---|
153 | // Copied from shadowfb
|
---|
154 |
|
---|
155 | #define TRIM_BOX(box, pGC) { \
|
---|
156 | BoxPtr extents = &pGC->pCompositeClip->extents;\
|
---|
157 | if(box.x1 < extents->x1) box.x1 = extents->x1; \
|
---|
158 | if(box.x2 > extents->x2) box.x2 = extents->x2; \
|
---|
159 | if(box.y1 < extents->y1) box.y1 = extents->y1; \
|
---|
160 | if(box.y2 > extents->y2) box.y2 = extents->y2; \
|
---|
161 | }
|
---|
162 |
|
---|
163 | #define TRANSLATE_BOX(box, pDraw) { \
|
---|
164 | box.x1 += pDraw->x; \
|
---|
165 | box.x2 += pDraw->x; \
|
---|
166 | box.y1 += pDraw->y; \
|
---|
167 | box.y2 += pDraw->y; \
|
---|
168 | }
|
---|
169 |
|
---|
170 | #define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
|
---|
171 | TRANSLATE_BOX(box, pDraw); \
|
---|
172 | TRIM_BOX(box, pGC); \
|
---|
173 | }
|
---|
174 |
|
---|
175 | #define BOX_NOT_EMPTY(box) \
|
---|
176 | (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
|
---|
177 |
|
---|
178 |
|
---|
179 | // HUGE_ROOT and NORMAL_ROOT
|
---|
180 | // We don't want to clip windows to the edge of the screen.
|
---|
181 | // HUGE_ROOT temporarily makes the root window really big.
|
---|
182 | // This is needed as a wrapper around any function that calls
|
---|
183 | // SetWinSize or SetBorderSize which clip a window against its
|
---|
184 | // parents, including the root.
|
---|
185 |
|
---|
186 | extern RegionRec rootlessHugeRoot;
|
---|
187 |
|
---|
188 | #define HUGE_ROOT(pWin) \
|
---|
189 | do { \
|
---|
190 | WindowPtr w = pWin; \
|
---|
191 | while (w->parent) \
|
---|
192 | w = w->parent; \
|
---|
193 | saveRoot = w->winSize; \
|
---|
194 | w->winSize = rootlessHugeRoot; \
|
---|
195 | } while (0)
|
---|
196 |
|
---|
197 | #define NORMAL_ROOT(pWin) \
|
---|
198 | do { \
|
---|
199 | WindowPtr w = pWin; \
|
---|
200 | while (w->parent) \
|
---|
201 | w = w->parent; \
|
---|
202 | w->winSize = saveRoot; \
|
---|
203 | } while (0)
|
---|
204 |
|
---|
205 |
|
---|
206 | // Returns TRUE if this window is a top-level window (i.e. child of the root)
|
---|
207 | // The root is not a top-level window.
|
---|
208 | #define IsTopLevel(pWin) \
|
---|
209 | ((pWin) && (pWin)->parent && !(pWin)->parent->parent)
|
---|
210 |
|
---|
211 | // Returns TRUE if this window is a root window
|
---|
212 | #define IsRoot(pWin) \
|
---|
213 | ((pWin) == WindowTable[(pWin)->drawable.pScreen->myNum])
|
---|
214 |
|
---|
215 |
|
---|
216 | /*
|
---|
217 | * SetPixmapBaseToScreen
|
---|
218 | * Move the given pixmap's base address to where pixel (0, 0)
|
---|
219 | * would be if the pixmap's actual data started at (x, y).
|
---|
220 | * Can't access the bits before the first word of the drawable's data in
|
---|
221 | * rootless mode, so make sure our base address is always 32-bit aligned.
|
---|
222 | */
|
---|
223 | #define SetPixmapBaseToScreen(pix, _x, _y) { \
|
---|
224 | PixmapPtr _pPix = (PixmapPtr) (pix); \
|
---|
225 | _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
|
---|
226 | ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \
|
---|
227 | (int)(_y) * _pPix->devKind); \
|
---|
228 | if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \
|
---|
229 | unsigned _diff = ((unsigned) _pPix->devPrivate.ptr) & \
|
---|
230 | (FB_UNIT / CHAR_BIT - 1); \
|
---|
231 | _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
|
---|
232 | _diff; \
|
---|
233 | _pPix->drawable.x = _diff / \
|
---|
234 | (_pPix->drawable.bitsPerPixel / CHAR_BIT); \
|
---|
235 | } \
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | // Returns TRUE if this window is visible inside a frame
|
---|
240 | // (e.g. it is visible and has a top-level or root parent)
|
---|
241 | Bool IsFramedWindow(WindowPtr pWin);
|
---|
242 |
|
---|
243 | // Routines that cause regions to get redrawn.
|
---|
244 | // DamageRegion and DamageRect are in global coordinates.
|
---|
245 | // DamageBox is in window-local coordinates.
|
---|
246 | void RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion);
|
---|
247 | void RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h);
|
---|
248 | void RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox);
|
---|
249 | void RootlessRedisplay(WindowPtr pWindow);
|
---|
250 | void RootlessRedisplayScreen(ScreenPtr pScreen);
|
---|
251 |
|
---|
252 | void RootlessQueueRedisplay(ScreenPtr pScreen);
|
---|
253 |
|
---|
254 | // Move a window to its proper location on the screen.
|
---|
255 | void RootlessRepositionWindow(WindowPtr pWin);
|
---|
256 |
|
---|
257 | // Move the window to it's correct place in the physical stacking order.
|
---|
258 | void RootlessReorderWindow(WindowPtr pWin);
|
---|
259 |
|
---|
260 | #endif /* _ROOTLESSCOMMON_H */
|
---|