103b705cfSriastradh/* 203b705cfSriastradh * Copyright 2012 Red Hat, Inc. 303b705cfSriastradh * 403b705cfSriastradh * Permission is hereby granted, free of charge, to any person obtaining a 503b705cfSriastradh * copy of this software and associated documentation files (the "Software"), 603b705cfSriastradh * to deal in the Software without restriction, including without limitation 703b705cfSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 803b705cfSriastradh * and/or sell copies of the Software, and to permit persons to whom the 903b705cfSriastradh * Software is furnished to do so, subject to the following conditions: 1003b705cfSriastradh * 1103b705cfSriastradh * The above copyright notice and this permission notice (including the next 1203b705cfSriastradh * paragraph) shall be included in all copies or substantial portions of the 1303b705cfSriastradh * Software. 1403b705cfSriastradh * 1503b705cfSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1603b705cfSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1703b705cfSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1803b705cfSriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1903b705cfSriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2003b705cfSriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2103b705cfSriastradh * DEALINGS IN THE SOFTWARE. 2203b705cfSriastradh * 2303b705cfSriastradh * Author: Dave Airlie <airlied@redhat.com> 2403b705cfSriastradh */ 2503b705cfSriastradh 2603b705cfSriastradh/* this file provides API compat between server post 1.13 and pre it, 2703b705cfSriastradh it should be reused inside as many drivers as possible */ 2803b705cfSriastradh#ifndef COMPAT_API_H 2903b705cfSriastradh#define COMPAT_API_H 3003b705cfSriastradh 3103b705cfSriastradh#include <xorg-server.h> 3203b705cfSriastradh#include <xorgVersion.h> 3346edf8f1Smrg#include <xf86Module.h> 3446edf8f1Smrg 3503b705cfSriastradh#include <picturestr.h> 3603b705cfSriastradh#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR 3703b705cfSriastradh#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum] 3803b705cfSriastradh#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p 3903b705cfSriastradh#endif 4003b705cfSriastradh 4103b705cfSriastradh#ifndef XF86_HAS_SCRN_CONV 4203b705cfSriastradh#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum] 4363ef14f0Smrg#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,1,0,0,0) 4403b705cfSriastradh#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex] 4563ef14f0Smrg#else 4663ef14f0Smrg#define xf86ScrnToScreen(s) ((s)->pScreen) 4763ef14f0Smrg#endif 4863ef14f0Smrg#else 4963ef14f0Smrg#define xf86ScrnToScreen(s) ((s)->pScreen) 5063ef14f0Smrg#endif 5163ef14f0Smrg 5263ef14f0Smrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 22 5363ef14f0Smrg#define HAVE_NOTIFY_FD 1 5403b705cfSriastradh#endif 5503b705cfSriastradh 5603b705cfSriastradh#ifndef XF86_SCRN_INTERFACE 5703b705cfSriastradh 5803b705cfSriastradh#define SCRN_ARG_TYPE int 5903b705cfSriastradh#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = xf86Screens[(arg1)] 6003b705cfSriastradh 6103b705cfSriastradh#define SCREEN_ARG_TYPE int 6203b705cfSriastradh#define SCREEN_PTR(arg1) ScreenPtr screen = screenInfo.screens[(arg1)] 6303b705cfSriastradh 6403b705cfSriastradh#define SCREEN_INIT_ARGS_DECL int scrnIndex, ScreenPtr screen, int argc, char **argv 6503b705cfSriastradh 6603b705cfSriastradh#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer timeout, pointer read_mask 6703b705cfSriastradh#define BLOCKHANDLER_ARGS arg, blockData, timeout, read_mask 6803b705cfSriastradh 6903b705cfSriastradh#define WAKEUPHANDLER_ARGS_DECL int arg, pointer wakeupData, unsigned long result, pointer read_mask 7003b705cfSriastradh#define WAKEUPHANDLER_ARGS arg, wakeupData, result, read_mask 7103b705cfSriastradh 7203b705cfSriastradh#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr screen 7303b705cfSriastradh#define CLOSE_SCREEN_ARGS scrnIndex, screen 7403b705cfSriastradh 7503b705cfSriastradh#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags 7603b705cfSriastradh#define ADJUST_FRAME_ARGS(arg, x, y) (arg)->scrnIndex, x, y, 0 7703b705cfSriastradh 7803b705cfSriastradh#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags 7903b705cfSriastradh#define SWITCH_MODE_ARGS(arg, m) (arg)->scrnIndex, m, 0 8003b705cfSriastradh 8103b705cfSriastradh#define FREE_SCREEN_ARGS_DECL int arg, int flags 8203b705cfSriastradh 8303b705cfSriastradh#define VT_FUNC_ARGS_DECL int arg, int flags 8403b705cfSriastradh#define VT_FUNC_ARGS(flags) scrn->scrnIndex, (flags) 8503b705cfSriastradh 8603b705cfSriastradh#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex) 8703b705cfSriastradh 8803b705cfSriastradh#else 8903b705cfSriastradh#define SCRN_ARG_TYPE ScrnInfoPtr 9003b705cfSriastradh#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = (arg1) 9103b705cfSriastradh 9203b705cfSriastradh#define SCREEN_ARG_TYPE ScreenPtr 9303b705cfSriastradh#define SCREEN_PTR(arg1) ScreenPtr screen = (arg1) 9403b705cfSriastradh 9503b705cfSriastradh#define SCREEN_INIT_ARGS_DECL ScreenPtr screen, int argc, char **argv 9603b705cfSriastradh 97fe196524Smrg#if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(23, 0) 9846edf8f1Smrg#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer timeout 9946edf8f1Smrg#define BLOCKHANDLER_ARGS arg, timeout 100fe196524Smrg 101fe196524Smrg#define WAKEUPHANDLER_ARGS_DECL ScreenPtr arg, int result 102fe196524Smrg#define WAKEUPHANDLER_ARGS arg, result 10346edf8f1Smrg#else 10403b705cfSriastradh#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer timeout, pointer read_mask 10503b705cfSriastradh#define BLOCKHANDLER_ARGS arg, timeout, read_mask 10603b705cfSriastradh 10703b705cfSriastradh#define WAKEUPHANDLER_ARGS_DECL ScreenPtr arg, unsigned long result, pointer read_mask 10803b705cfSriastradh#define WAKEUPHANDLER_ARGS arg, result, read_mask 109fe196524Smrg#endif 11003b705cfSriastradh 11103b705cfSriastradh#define CLOSE_SCREEN_ARGS_DECL ScreenPtr screen 11203b705cfSriastradh#define CLOSE_SCREEN_ARGS screen 11303b705cfSriastradh 11403b705cfSriastradh#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y 11503b705cfSriastradh#define ADJUST_FRAME_ARGS(arg, x, y) arg, x, y 11603b705cfSriastradh 11703b705cfSriastradh#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode 11803b705cfSriastradh#define SWITCH_MODE_ARGS(arg, m) arg, m 11903b705cfSriastradh 12003b705cfSriastradh#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg 12103b705cfSriastradh 12203b705cfSriastradh#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg 12303b705cfSriastradh#define VT_FUNC_ARGS(flags) scrn 12403b705cfSriastradh 12503b705cfSriastradh#define XF86_ENABLEDISABLEFB_ARG(x) (x) 12603b705cfSriastradh 12703b705cfSriastradh#endif 12803b705cfSriastradh 12942542f5fSchristosstatic inline int 13042542f5fSchristosregion_num_rects(const RegionRec *r) 13142542f5fSchristos{ 13242542f5fSchristos return r->data ? r->data->numRects : 1; 13342542f5fSchristos} 13442542f5fSchristos 13542542f5fSchristosstatic inline int 13642542f5fSchristosregion_nil(const RegionRec *r) 13742542f5fSchristos{ 13842542f5fSchristos return region_num_rects(r) == 0; 13942542f5fSchristos} 14042542f5fSchristos 14142542f5fSchristosstatic inline BoxPtr 14242542f5fSchristosregion_boxptr(const RegionRec *r) 14342542f5fSchristos{ 14442542f5fSchristos return (BoxPtr)(r->data + 1); 14542542f5fSchristos} 14642542f5fSchristos 14742542f5fSchristosstatic inline const BoxRec * 14842542f5fSchristosregion_rects(const RegionRec *r) 14942542f5fSchristos{ 15042542f5fSchristos return r->data ? (const BoxRec *)(r->data + 1) : &r->extents; 15142542f5fSchristos} 15242542f5fSchristos 15363ef14f0Smrginline static void 15463ef14f0Smrgregion_get_boxes(const RegionRec *r, const BoxRec **s, const BoxRec **e) 15563ef14f0Smrg{ 15663ef14f0Smrg int n; 15763ef14f0Smrg if (r->data) 15863ef14f0Smrg *s = region_boxptr(r), n = r->data->numRects; 15963ef14f0Smrg else 16063ef14f0Smrg *s = &r->extents, n = 1; 16163ef14f0Smrg *e = *s + n; 16263ef14f0Smrg} 16363ef14f0Smrg 16403b705cfSriastradh#ifndef INCLUDE_LEGACY_REGION_DEFINES 16503b705cfSriastradh#define RegionCreate(r, s) REGION_CREATE(NULL, r, s) 16603b705cfSriastradh#define RegionBreak(r) REGION_BREAK(NULL, r) 16703b705cfSriastradh#define RegionSizeof REGION_SZOF 16803b705cfSriastradh#define RegionBoxptr REGION_BOXPTR 16903b705cfSriastradh#define RegionEnd REGION_END 17003b705cfSriastradh#define RegionExtents(r) REGION_EXTENTS(NULL, r) 17103b705cfSriastradh#define RegionRects REGION_RECTS 17203b705cfSriastradh#define RegionNumRects REGION_NUM_RECTS 17303b705cfSriastradh#define RegionContainsRect(r, b) RECT_IN_REGION(NULL, r, b) 17403b705cfSriastradh#define RegionContainsPoint(r, x, y, b) POINT_IN_REGION(NULL, r, x, y, b) 17503b705cfSriastradh#define RegionCopy(res, r) REGION_COPY(NULL, res, r) 17603b705cfSriastradh#define RegionIntersect(res, r1, r2) REGION_INTERSECT(NULL, res, r1, r2) 17703b705cfSriastradh#define RegionUnion(res, r1, r2) REGION_UNION(NULL, res, r1, r2) 17842542f5fSchristos#define RegionSubtract(res, r1, r2) REGION_SUBTRACT(NULL, res, r1, r2) 17903b705cfSriastradh#define RegionTranslate(r, x, y) REGION_TRANSLATE(NULL, r, x, y) 18003b705cfSriastradh#define RegionUninit(r) REGION_UNINIT(NULL, r) 18103b705cfSriastradh#define region_from_bitmap BITMAP_TO_REGION 18203b705cfSriastradh#define RegionNil REGION_NIL 18303b705cfSriastradh#define RegionNull(r) REGION_NULL(NULL, r) 18403b705cfSriastradh#define RegionNotEmpty(r) REGION_NOTEMPTY(NULL, r) 18503b705cfSriastradh#define RegionEmpty(r) REGION_EMPTY(NULL, r) 18603b705cfSriastradh#define RegionEqual(a, b) REGION_EQUAL(NULL, a, b) 18703b705cfSriastradh#define RegionDestroy(r) REGION_DESTROY(NULL, r) 18803b705cfSriastradh#else 18903b705cfSriastradh#define region_from_bitmap BitmapToRegion 19003b705cfSriastradh#endif 19103b705cfSriastradh 19203b705cfSriastradh#ifndef _X_UNUSED 19303b705cfSriastradh#define _X_UNUSED 19403b705cfSriastradh#endif 19503b705cfSriastradh 19603b705cfSriastradh#if HAS_DEVPRIVATEKEYREC 19703b705cfSriastradh#define __get_private(p, key) dixGetPrivateAddr(&(p)->devPrivates, &(key)) 19803b705cfSriastradh#else 19903b705cfSriastradh#define __get_private(p, key) dixLookupPrivate(&(p)->devPrivates, &(key)) 20003b705cfSriastradhtypedef int DevPrivateKeyRec; 20103b705cfSriastradhstatic inline void FreePixmap(PixmapPtr pixmap) 20203b705cfSriastradh{ 20303b705cfSriastradh dixFreePrivates(pixmap->devPrivates); 20403b705cfSriastradh free(pixmap); 20503b705cfSriastradh} 20603b705cfSriastradh#endif 20703b705cfSriastradh 20842542f5fSchristos#if !HAS_DIXREGISTERPRIVATEKEY 20942542f5fSchristos#define dixPrivateKeyRegistered(key__) (*(key__) != 0) 21042542f5fSchristos#endif 21142542f5fSchristos 21203b705cfSriastradh#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,9,99,902,0) 21303b705cfSriastradh#define SourceValidate(d, x, y, w, h, mode) \ 21403b705cfSriastradh if ((d)->pScreen->SourceValidate) (d)->pScreen->SourceValidate(d, x, y, w, h, mode) 21503b705cfSriastradh#else 21603b705cfSriastradh#define SourceValidate(d, x, y, w, h, mode) \ 21703b705cfSriastradh if ((d)->pScreen->SourceValidate) (d)->pScreen->SourceValidate(d, x, y, w, h) 21803b705cfSriastradh#endif 21903b705cfSriastradh 22042542f5fSchristos#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0) 22142542f5fSchristos#define DamageUnregister(d, dd) DamageUnregister(dd) 22242542f5fSchristos#endif 22342542f5fSchristos 22442542f5fSchristos#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,16,99,1,0) 22542542f5fSchristos 22642542f5fSchristos#define XORG_XV_VERSION 2 22742542f5fSchristos#define ddStopVideo_ARGS XvPortPtr port, DrawablePtr draw 22842542f5fSchristos#define ddSetPortAttribute_ARGS XvPortPtr port, Atom attribute, INT32 value 22942542f5fSchristos#define ddGetPortAttribute_ARGS XvPortPtr port, Atom attribute, INT32 *value 23042542f5fSchristos#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 23142542f5fSchristos#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 23242542f5fSchristos#define ddQueryImageAttributes_ARGS XvPortPtr port, XvImagePtr format, unsigned short *w, unsigned short *h, int *pitches, int *offsets 23342542f5fSchristos 23442542f5fSchristos#else 23542542f5fSchristos 23642542f5fSchristos#define XORG_XV_VERSION 1 23742542f5fSchristos#define ddStopVideo_ARGS ClientPtr client, XvPortPtr port, DrawablePtr draw 23842542f5fSchristos#define ddSetPortAttribute_ARGS ClientPtr client, XvPortPtr port, Atom attribute, INT32 value 23942542f5fSchristos#define ddGetPortAttribute_ARGS ClientPtr client, XvPortPtr port, Atom attribute, INT32 *value 24042542f5fSchristos#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 24142542f5fSchristos#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 24242542f5fSchristos#define ddQueryImageAttributes_ARGS ClientPtr client, XvPortPtr port, XvImagePtr format, unsigned short *w, unsigned short *h, int *pitches, int *offsets 24342542f5fSchristos 24442542f5fSchristos#endif 24542542f5fSchristos 24613496ba1Ssnj#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,16,99,1,0) 24713496ba1Ssnj#include <mi.h> 24813496ba1Ssnj#define miHandleExposures(pSrcDrawable, pDstDrawable, \ 24913496ba1Ssnj pGC, srcx, srcy, width, height, \ 25013496ba1Ssnj dstx, dsty, plane) \ 25113496ba1Ssnj miHandleExposures(pSrcDrawable, pDstDrawable, \ 25213496ba1Ssnj pGC, srcx, srcy, width, height, \ 25313496ba1Ssnj dstx, dsty) 25413496ba1Ssnj#endif 25513496ba1Ssnj 25663ef14f0Smrg#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,12,99,901,0) 25763ef14f0Smrg#define isGPU(S) (S)->is_gpu 25863ef14f0Smrg#else 25963ef14f0Smrg#define isGPU(S) 0 26063ef14f0Smrg#endif 26163ef14f0Smrg 26263ef14f0Smrg#if HAS_DIRTYTRACKING_ROTATION 26363ef14f0Smrg#define PixmapSyncDirtyHelper(d, dd) PixmapSyncDirtyHelper(d) 26463ef14f0Smrg#endif 26563ef14f0Smrg 26663ef14f0Smrg#if !HAVE_NOTIFY_FD 26763ef14f0Smrg#define SetNotifyFd(fd, cb, mode, data) AddGeneralSocket(fd); 26863ef14f0Smrg#define RemoveNotifyFd(fd) RemoveGeneralSocket(fd) 26963ef14f0Smrg#endif 27063ef14f0Smrg 27103b705cfSriastradh#endif 272