1 /*
2  * Copyright 2012 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Author: Dave Airlie <airlied@redhat.com>
24  */
25 
26 /* this file provides API compat between server post 1.13 and pre it,
27    it should be reused inside as many drivers as possible */
28 #ifndef COMPAT_API_H
29 #define COMPAT_API_H
30 
31 #include <xorg-server.h>
32 #include <xorgVersion.h>
33 #include <xf86Module.h>
34 
35 #include <picturestr.h>
36 #ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
37 #define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
38 #define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
39 #endif
40 
41 #ifndef XF86_HAS_SCRN_CONV
42 #define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
43 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,1,0,0,0)
44 #define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
45 #else
46 #define xf86ScrnToScreen(s) ((s)->pScreen)
47 #endif
48 #else
49 #define xf86ScrnToScreen(s) ((s)->pScreen)
50 #endif
51 
52 #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 22
53 #define HAVE_NOTIFY_FD 1
54 #endif
55 
56 #ifndef XF86_SCRN_INTERFACE
57 
58 #define SCRN_ARG_TYPE int
59 #define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = xf86Screens[(arg1)]
60 
61 #define SCREEN_ARG_TYPE int
62 #define SCREEN_PTR(arg1) ScreenPtr screen = screenInfo.screens[(arg1)]
63 
64 #define SCREEN_INIT_ARGS_DECL int scrnIndex, ScreenPtr screen, int argc, char **argv
65 
66 #define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer timeout, pointer read_mask
67 #define BLOCKHANDLER_ARGS arg, blockData, timeout, read_mask
68 
69 #define WAKEUPHANDLER_ARGS_DECL int arg, pointer wakeupData, unsigned long result, pointer read_mask
70 #define WAKEUPHANDLER_ARGS arg, wakeupData, result, read_mask
71 
72 #define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr screen
73 #define CLOSE_SCREEN_ARGS scrnIndex, screen
74 
75 #define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
76 #define ADJUST_FRAME_ARGS(arg, x, y) (arg)->scrnIndex, x, y, 0
77 
78 #define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
79 #define SWITCH_MODE_ARGS(arg, m) (arg)->scrnIndex, m, 0
80 
81 #define FREE_SCREEN_ARGS_DECL int arg, int flags
82 
83 #define VT_FUNC_ARGS_DECL int arg, int flags
84 #define VT_FUNC_ARGS(flags) scrn->scrnIndex, (flags)
85 
86 #define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
87 
88 #else
89 #define SCRN_ARG_TYPE ScrnInfoPtr
90 #define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = (arg1)
91 
92 #define SCREEN_ARG_TYPE ScreenPtr
93 #define SCREEN_PTR(arg1) ScreenPtr screen = (arg1)
94 
95 #define SCREEN_INIT_ARGS_DECL ScreenPtr screen, int argc, char **argv
96 
97 #define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer timeout, pointer read_mask
98 #define BLOCKHANDLER_ARGS arg, timeout, read_mask
99 
100 #define WAKEUPHANDLER_ARGS_DECL ScreenPtr arg, unsigned long result, pointer read_mask
101 #define WAKEUPHANDLER_ARGS arg, result, read_mask
102 
103 #define CLOSE_SCREEN_ARGS_DECL ScreenPtr screen
104 #define CLOSE_SCREEN_ARGS screen
105 
106 #define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
107 #define ADJUST_FRAME_ARGS(arg, x, y) arg, x, y
108 
109 #define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
110 #define SWITCH_MODE_ARGS(arg, m) arg, m
111 
112 #define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
113 
114 #define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
115 #define VT_FUNC_ARGS(flags) scrn
116 
117 #define XF86_ENABLEDISABLEFB_ARG(x) (x)
118 
119 #endif
120 
121 static inline int
region_num_rects(const RegionRec * r)122 region_num_rects(const RegionRec *r)
123 {
124 	return r->data ? r->data->numRects : 1;
125 }
126 
127 static inline int
region_nil(const RegionRec * r)128 region_nil(const RegionRec *r)
129 {
130 	return region_num_rects(r) == 0;
131 }
132 
133 static inline BoxPtr
region_boxptr(const RegionRec * r)134 region_boxptr(const RegionRec *r)
135 {
136 	return (BoxPtr)(r->data + 1);
137 }
138 
139 static inline const BoxRec *
region_rects(const RegionRec * r)140 region_rects(const RegionRec *r)
141 {
142 	return r->data ? (const BoxRec *)(r->data + 1) :  &r->extents;
143 }
144 
145 inline static void
region_get_boxes(const RegionRec * r,const BoxRec ** s,const BoxRec ** e)146 region_get_boxes(const RegionRec *r, const BoxRec **s, const BoxRec **e)
147 {
148 	int n;
149 	if (r->data)
150 		*s = region_boxptr(r), n = r->data->numRects;
151 	else
152 		*s = &r->extents, n = 1;
153 	*e = *s + n;
154 }
155 
156 #ifndef INCLUDE_LEGACY_REGION_DEFINES
157 #define RegionCreate(r, s) REGION_CREATE(NULL, r, s)
158 #define RegionBreak(r) REGION_BREAK(NULL, r)
159 #define RegionSizeof REGION_SZOF
160 #define RegionBoxptr REGION_BOXPTR
161 #define RegionEnd REGION_END
162 #define RegionExtents(r) REGION_EXTENTS(NULL, r)
163 #define RegionRects REGION_RECTS
164 #define RegionNumRects REGION_NUM_RECTS
165 #define RegionContainsRect(r, b) RECT_IN_REGION(NULL, r, b)
166 #define RegionContainsPoint(r, x, y, b) POINT_IN_REGION(NULL, r, x, y, b)
167 #define RegionCopy(res, r) REGION_COPY(NULL, res, r)
168 #define RegionIntersect(res, r1, r2) REGION_INTERSECT(NULL, res, r1, r2)
169 #define RegionUnion(res, r1, r2) REGION_UNION(NULL, res, r1, r2)
170 #define RegionSubtract(res, r1, r2) REGION_SUBTRACT(NULL, res, r1, r2)
171 #define RegionTranslate(r, x, y) REGION_TRANSLATE(NULL, r, x, y)
172 #define RegionUninit(r) REGION_UNINIT(NULL, r)
173 #define region_from_bitmap BITMAP_TO_REGION
174 #define RegionNil REGION_NIL
175 #define RegionNull(r) REGION_NULL(NULL, r)
176 #define RegionNotEmpty(r) REGION_NOTEMPTY(NULL, r)
177 #define RegionEmpty(r) REGION_EMPTY(NULL, r)
178 #define RegionEqual(a, b) REGION_EQUAL(NULL, a, b)
179 #define RegionDestroy(r) REGION_DESTROY(NULL, r)
180 #else
181 #define region_from_bitmap BitmapToRegion
182 #endif
183 
184 #ifndef _X_UNUSED
185 #define _X_UNUSED
186 #endif
187 
188 #if HAS_DEVPRIVATEKEYREC
189 #define __get_private(p, key) dixGetPrivateAddr(&(p)->devPrivates, &(key))
190 #else
191 #define __get_private(p, key) dixLookupPrivate(&(p)->devPrivates, &(key))
192 typedef int DevPrivateKeyRec;
FreePixmap(PixmapPtr pixmap)193 static inline void FreePixmap(PixmapPtr pixmap)
194 {
195 	dixFreePrivates(pixmap->devPrivates);
196 	free(pixmap);
197 }
198 #endif
199 
200 #if !HAS_DIXREGISTERPRIVATEKEY
201 #define dixPrivateKeyRegistered(key__) (*(key__) != 0)
202 #endif
203 
204 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,9,99,902,0)
205 #define SourceValidate(d, x, y, w, h, mode) \
206 	if ((d)->pScreen->SourceValidate) (d)->pScreen->SourceValidate(d, x, y, w, h, mode)
207 #else
208 #define SourceValidate(d, x, y, w, h, mode) \
209 	if ((d)->pScreen->SourceValidate) (d)->pScreen->SourceValidate(d, x, y, w, h)
210 #endif
211 
212 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
213 #define DamageUnregister(d, dd) DamageUnregister(dd)
214 #endif
215 
216 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,16,99,1,0)
217 
218 #define XORG_XV_VERSION 2
219 #define ddStopVideo_ARGS XvPortPtr port, DrawablePtr draw
220 #define ddSetPortAttribute_ARGS XvPortPtr port, Atom attribute, INT32 value
221 #define ddGetPortAttribute_ARGS XvPortPtr port, Atom attribute, INT32 *value
222 #define ddQueryBestSize_ARGS XvPortPtr port, CARD8 motion, CARD16 vid_w, CARD16 vid_h, CARD16 drw_w, CARD16 drw_h, unsigned int *p_w, unsigned int *p_h
223 #define ddPutImage_ARGS DrawablePtr draw, XvPortPtr port, GCPtr gc, INT16 src_x, INT16 src_y, CARD16 src_w, CARD16 src_h, INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h, XvImagePtr format, unsigned char *buf, Bool sync, CARD16 width, CARD16 height
224 #define ddQueryImageAttributes_ARGS XvPortPtr port, XvImagePtr format, unsigned short *w, unsigned short *h, int *pitches, int *offsets
225 
226 #else
227 
228 #define XORG_XV_VERSION 1
229 #define ddStopVideo_ARGS ClientPtr client, XvPortPtr port, DrawablePtr draw
230 #define ddSetPortAttribute_ARGS ClientPtr client, XvPortPtr port, Atom attribute, INT32 value
231 #define ddGetPortAttribute_ARGS ClientPtr client, XvPortPtr port, Atom attribute, INT32 *value
232 #define ddQueryBestSize_ARGS ClientPtr client, XvPortPtr port, CARD8 motion, CARD16 vid_w, CARD16 vid_h, CARD16 drw_w, CARD16 drw_h, unsigned int *p_w, unsigned int *p_h
233 #define ddPutImage_ARGS ClientPtr client, DrawablePtr draw, XvPortPtr port, GCPtr gc, INT16 src_x, INT16 src_y, CARD16 src_w, CARD16 src_h, INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h, XvImagePtr format, unsigned char *buf, Bool sync, CARD16 width, CARD16 height
234 #define ddQueryImageAttributes_ARGS ClientPtr client, XvPortPtr port, XvImagePtr format, unsigned short *w, unsigned short *h, int *pitches, int *offsets
235 
236 #endif
237 
238 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,16,99,1,0)
239 #include <mi.h>
240 #define miHandleExposures(pSrcDrawable, pDstDrawable, \
241 			  pGC, srcx, srcy, width, height, \
242 			  dstx, dsty, plane) \
243 	miHandleExposures(pSrcDrawable, pDstDrawable, \
244 			  pGC, srcx, srcy, width, height, \
245 			  dstx, dsty)
246 #endif
247 
248 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,12,99,901,0)
249 #define isGPU(S) (S)->is_gpu
250 #else
251 #define isGPU(S) 0
252 #endif
253 
254 #if HAS_DIRTYTRACKING_ROTATION
255 #define PixmapSyncDirtyHelper(d, dd) PixmapSyncDirtyHelper(d)
256 #endif
257 
258 #if !HAVE_NOTIFY_FD
259 #define SetNotifyFd(fd, cb, mode, data) AddGeneralSocket(fd);
260 #define RemoveNotifyFd(fd) RemoveGeneralSocket(fd)
261 #endif
262 
263 #if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(25, 2)
264 #define PixmapDirtyDst(d) ((d)->secondary_dst)
265 #define PixmapDirtyPrimary(d) (PixmapDirtyDst(d)->primary_pixmap)
266 #else
267 #define PixmapDirtyDst(d) ((d)->slave_dst)
268 #define PixmapDirtyPrimary(d) (PixmapDirtyDst(d)->master_pixmap)
269 #endif
270 
271 #endif
272