diff options
Diffstat (limited to 'xorg-server/hw/xfree86/common')
40 files changed, 16060 insertions, 15943 deletions
diff --git a/xorg-server/hw/xfree86/common/compiler.h b/xorg-server/hw/xfree86/common/compiler.h index 34e60c52a..0abdfb6c3 100644 --- a/xorg-server/hw/xfree86/common/compiler.h +++ b/xorg-server/hw/xfree86/common/compiler.h @@ -49,61 +49,58 @@ #ifndef _COMPILER_H -# define _COMPILER_H +#define _COMPILER_H #if defined(__SUNPRO_C) -# define DO_PROTOTYPES +#define DO_PROTOTYPES #endif /* Map Sun compiler platform defines to gcc-style used in the code */ #if defined(__amd64) && !defined(__amd64__) -# define __amd64__ +#define __amd64__ #endif #if defined(__i386) && !defined(__i386__) -# define __i386__ +#define __i386__ #endif #if defined(__sparc) && !defined(__sparc__) -# define __sparc__ +#define __sparc__ #endif #if defined(__sparcv9) && !defined(__sparc64__) -# define __sparc64__ +#define __sparc64__ #endif #ifndef _X_EXPORT -# include <X11/Xfuncproto.h> +#include <X11/Xfuncproto.h> #endif -# include <pixman.h> /* for uint*_t types */ +#include <pixman.h> /* for uint*_t types */ /* Allow drivers to use the GCC-supported __inline__ and/or __inline. */ -# ifndef __inline__ -# if defined(__GNUC__) +#ifndef __inline__ +#if defined(__GNUC__) /* gcc has __inline__ */ -# elif defined(__HIGHC__) -# define __inline__ _Inline -# else -# define __inline__ /**/ -# endif -# endif /* __inline__ */ -# ifndef __inline -# if defined(__GNUC__) +#elif defined(__HIGHC__) +#define __inline__ _Inline +#else +#define __inline__ /**/ +#endif +#endif /* __inline__ */ +#ifndef __inline +#if defined(__GNUC__) /* gcc has __inline */ -# elif defined(__HIGHC__) -# define __inline _Inline -# else -# define __inline /**/ -# endif -# endif /* __inline */ - +#elif defined(__HIGHC__) +#define __inline _Inline +#else +#define __inline /**/ +#endif +#endif /* __inline */ /* Support gcc's __FUNCTION__ for people using other compilers */ #if !defined(__GNUC__) && !defined(__FUNCTION__) -# define __FUNCTION__ __func__ /* C99 */ +#define __FUNCTION__ __func__ /* C99 */ #endif - -# if defined(NO_INLINE) || defined(DO_PROTOTYPES) - -# if !defined(__arm__) -# if !defined(__sparc__) && !defined(__sparc) && !defined(__arm32__) && !defined(__nds32__) \ +#if defined(NO_INLINE) || defined(DO_PROTOTYPES) +#if !defined(__arm__) +#if !defined(__sparc__) && !defined(__sparc) && !defined(__arm32__) && !defined(__nds32__) \ && !(defined(__alpha__) && defined(linux)) \ && !(defined(__ia64__) && defined(linux)) \ @@ -114,8 +111,7 @@ extern _X_EXPORT unsigned int inb(unsigned short); extern _X_EXPORT unsigned int inw(unsigned short); extern _X_EXPORT unsigned int inl(unsigned short); -# else /* __sparc__, __arm32__, __alpha__, __nds32__ */ - +#else /* __sparc__, __arm32__, __alpha__, __nds32__ */ extern _X_EXPORT void outb(unsigned long, unsigned char); extern _X_EXPORT void outw(unsigned long, unsigned short); extern _X_EXPORT void outl(unsigned long, unsigned int); @@ -123,10 +119,10 @@ extern _X_EXPORT unsigned int inb(unsigned long); extern _X_EXPORT unsigned int inw(unsigned long); extern _X_EXPORT unsigned int inl(unsigned long); -# endif /* __sparc__, __arm32__, __alpha__, __nds32__ */ -# endif /* __arm__ */ +#endif /* __sparc__, __arm32__, __alpha__, __nds32__ */ +#endif /* __arm__ */ -# if defined(__powerpc__) && !defined(__OpenBSD__) +#if defined(__powerpc__) && !defined(__OpenBSD__) extern unsigned long ldq_u(unsigned long *); extern unsigned long ldl_u(unsigned int *); extern unsigned long ldw_u(unsigned short *); @@ -139,50 +135,50 @@ extern void stl_brx(unsigned long, volatile unsigned char *, int); extern void stw_brx(unsigned short, volatile unsigned char *, int); extern unsigned long ldl_brx(volatile unsigned char *, int); extern unsigned short ldw_brx(volatile unsigned char *, int); -# endif /* __powerpc__ && !__OpenBSD */ +#endif /* __powerpc__ && !__OpenBSD */ -# endif /* NO_INLINE || DO_PROTOTYPES */ +#endif /* NO_INLINE || DO_PROTOTYPES */ -# ifndef NO_INLINE -# ifdef __GNUC__ -# ifdef __i386__ +#ifndef NO_INLINE +#ifdef __GNUC__ +#ifdef __i386__ -# ifdef __SSE__ -# define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") -# else -# define write_mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") -# endif +#ifdef __SSE__ +#define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") +#else +#define write_mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") +#endif -# ifdef __SSE2__ -# define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") -# else -# define mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") -# endif +#ifdef __SSE2__ +#define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") +#else +#define mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") +#endif -# elif defined __alpha__ +#elif defined __alpha__ -# define mem_barrier() __asm__ __volatile__ ("mb" : : : "memory") -# define write_mem_barrier() __asm__ __volatile__ ("wmb" : : : "memory") +#define mem_barrier() __asm__ __volatile__ ("mb" : : : "memory") +#define write_mem_barrier() __asm__ __volatile__ ("wmb" : : : "memory") -# elif defined __amd64__ +#elif defined __amd64__ -# define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") -# define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") +#define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") +#define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") -# elif defined __ia64__ +#elif defined __ia64__ -# ifndef __INTEL_COMPILER -# define mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") -# define write_mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") -# else -# include "ia64intrin.h" -# define mem_barrier() __mf() -# define write_mem_barrier() __mf() -# endif +#ifndef __INTEL_COMPILER +#define mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") +#define write_mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") +#else +#include "ia64intrin.h" +#define mem_barrier() __mf() +#define write_mem_barrier() __mf() +#endif -# elif defined __mips__ +#elif defined __mips__ /* Note: sync instruction requires MIPS II instruction set */ -# define mem_barrier() \ +#define mem_barrier() \ __asm__ __volatile__( \ ".set push\n\t" \ ".set noreorder\n\t" \ @@ -192,140 +188,169 @@ extern unsigned short ldw_brx(volatile unsigned char *, int); : /* no output */ \ : /* no input */ \ : "memory") -# define write_mem_barrier() mem_barrier() - -# elif defined __powerpc__ +#define write_mem_barrier() mem_barrier() -# if defined(linux) && defined(__powerpc64__) -# include <linux/version.h> -# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# include <asm/memory.h> -# endif -# endif /* defined(linux) && defined(__powerpc64__) */ +#elif defined __powerpc__ -# ifndef eieio /* We deal with arch-specific eieio() routines above... */ -# define eieio() __asm__ __volatile__ ("eieio" ::: "memory") -# endif /* eieio */ -# define mem_barrier() eieio() -# define write_mem_barrier() eieio() +#if defined(linux) && defined(__powerpc64__) +#include <linux/version.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) +#include <asm/memory.h> +#endif +#endif /* defined(linux) && defined(__powerpc64__) */ -# elif defined __sparc__ +#ifndef eieio /* We deal with arch-specific eieio() routines above... */ +#define eieio() __asm__ __volatile__ ("eieio" ::: "memory") +#endif /* eieio */ +#define mem_barrier() eieio() +#define write_mem_barrier() eieio() -# define barrier() __asm__ __volatile__ (".word 0x8143e00a" : : : "memory") -# define mem_barrier() /* XXX: nop for now */ -# define write_mem_barrier() /* XXX: nop for now */ -# endif -# endif /* __GNUC__ */ -# endif /* NO_INLINE */ +#elif defined __sparc__ -# ifndef mem_barrier -# define mem_barrier() /* NOP */ -# endif +#define barrier() __asm__ __volatile__ (".word 0x8143e00a" : : : "memory") +#define mem_barrier() /* XXX: nop for now */ +#define write_mem_barrier() /* XXX: nop for now */ +#endif +#endif /* __GNUC__ */ +#endif /* NO_INLINE */ -# ifndef write_mem_barrier -# define write_mem_barrier() /* NOP */ -# endif +#ifndef mem_barrier +#define mem_barrier() /* NOP */ +#endif +#ifndef write_mem_barrier +#define write_mem_barrier() /* NOP */ +#endif -# ifndef NO_INLINE -# ifdef __GNUC__ +#ifndef NO_INLINE +#ifdef __GNUC__ /* Define some packed structures to use with unaligned accesses */ -struct __una_u64 { uint64_t x __attribute__((packed)); }; -struct __una_u32 { uint32_t x __attribute__((packed)); }; -struct __una_u16 { uint16_t x __attribute__((packed)); }; +struct __una_u64 { + uint64_t x __attribute__ ((packed)); +}; +struct __una_u32 { + uint32_t x __attribute__ ((packed)); +}; +struct __una_u16 { + uint16_t x __attribute__ ((packed)); +}; /* Elemental unaligned loads */ -static __inline__ uint64_t ldq_u(uint64_t *p) +static __inline__ uint64_t +ldq_u(uint64_t * p) { - const struct __una_u64 *ptr = (const struct __una_u64 *) p; - return ptr->x; + const struct __una_u64 *ptr = (const struct __una_u64 *) p; + + return ptr->x; } -static __inline__ uint32_t ldl_u(uint32_t *p) +static __inline__ uint32_t +ldl_u(uint32_t * p) { - const struct __una_u32 *ptr = (const struct __una_u32 *) p; - return ptr->x; + const struct __una_u32 *ptr = (const struct __una_u32 *) p; + + return ptr->x; } -static __inline__ uint16_t ldw_u(uint16_t *p) +static __inline__ uint16_t +ldw_u(uint16_t * p) { - const struct __una_u16 *ptr = (const struct __una_u16 *) p; - return ptr->x; + const struct __una_u16 *ptr = (const struct __una_u16 *) p; + + return ptr->x; } /* Elemental unaligned stores */ -static __inline__ void stq_u(uint64_t val, uint64_t *p) +static __inline__ void +stq_u(uint64_t val, uint64_t * p) { - struct __una_u64 *ptr = (struct __una_u64 *) p; - ptr->x = val; + struct __una_u64 *ptr = (struct __una_u64 *) p; + + ptr->x = val; } -static __inline__ void stl_u(uint32_t val, uint32_t *p) +static __inline__ void +stl_u(uint32_t val, uint32_t * p) { - struct __una_u32 *ptr = (struct __una_u32 *) p; - ptr->x = val; + struct __una_u32 *ptr = (struct __una_u32 *) p; + + ptr->x = val; } -static __inline__ void stw_u(uint16_t val, uint16_t *p) +static __inline__ void +stw_u(uint16_t val, uint16_t * p) { - struct __una_u16 *ptr = (struct __una_u16 *) p; - ptr->x = val; + struct __una_u16 *ptr = (struct __una_u16 *) p; + + ptr->x = val; } -# else /* !__GNUC__ */ +#else /* !__GNUC__ */ -#include <string.h> /* needed for memmove */ +#include <string.h> /* needed for memmove */ -static __inline__ uint64_t ldq_u(uint64_t *p) +static __inline__ uint64_t +ldq_u(uint64_t * p) { - uint64_t ret; - memmove(&ret, p, sizeof(*p)); - return ret; + uint64_t ret; + + memmove(&ret, p, sizeof(*p)); + return ret; } -static __inline__ uint32_t ldl_u(uint32_t *p) +static __inline__ uint32_t +ldl_u(uint32_t * p) { - uint32_t ret; - memmove(&ret, p, sizeof(*p)); - return ret; + uint32_t ret; + + memmove(&ret, p, sizeof(*p)); + return ret; } -static __inline__ uint16_t ldw_u(uint16_t *p) +static __inline__ uint16_t +ldw_u(uint16_t * p) { - uint16_t ret; - memmove(&ret, p, sizeof(*p)); - return ret; + uint16_t ret; + + memmove(&ret, p, sizeof(*p)); + return ret; } -static __inline__ void stq_u(uint64_t val, uint64_t *p) +static __inline__ void +stq_u(uint64_t val, uint64_t * p) { - uint64_t tmp = val; - memmove(p, &tmp, sizeof(*p)); + uint64_t tmp = val; + + memmove(p, &tmp, sizeof(*p)); } -static __inline__ void stl_u(uint32_t val, uint32_t *p) +static __inline__ void +stl_u(uint32_t val, uint32_t * p) { - uint32_t tmp = val; - memmove(p, &tmp, sizeof(*p)); + uint32_t tmp = val; + + memmove(p, &tmp, sizeof(*p)); } -static __inline__ void stw_u(uint16_t val, uint16_t *p) +static __inline__ void +stw_u(uint16_t val, uint16_t * p) { - uint16_t tmp = val; - memmove(p, &tmp, sizeof(*p)); + uint16_t tmp = val; + + memmove(p, &tmp, sizeof(*p)); } -# endif /* __GNUC__ */ -# endif /* NO_INLINE */ +#endif /* __GNUC__ */ +#endif /* NO_INLINE */ -# ifndef NO_INLINE -# ifdef __GNUC__ -# if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__)) +#ifndef NO_INLINE +#ifdef __GNUC__ +#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__)) -# ifdef linux +#ifdef linux /* for Linux on Alpha, we use the LIBC _inx/_outx routines */ /* note that the appropriate setup via "ioperm" needs to be done */ /* *before* any inx/outx is done. */ @@ -358,24 +383,24 @@ outl(unsigned long port, unsigned int val) static __inline__ unsigned int inb(unsigned long port) { - return _inb(port); + return _inb(port); } static __inline__ unsigned int inw(unsigned long port) { - return _inw(port); + return _inw(port); } static __inline__ unsigned int inl(unsigned long port) { - return _inl(port); + return _inl(port); } -# endif /* linux */ +#endif /* linux */ -# if (defined(__FreeBSD__) || defined(__OpenBSD__)) \ +#if (defined(__FreeBSD__) || defined(__OpenBSD__)) \ && !defined(DO_PROTOTYPES) /* for FreeBSD and OpenBSD on Alpha, we use the libio (resp. libalpha) */ @@ -390,583 +415,567 @@ extern _X_EXPORT unsigned char inb(unsigned int port); extern _X_EXPORT unsigned short inw(unsigned int port); extern _X_EXPORT unsigned int inl(unsigned int port); -# endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */ - +#endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */ #if defined(__NetBSD__) #include <machine/pio.h> -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ */ + +#elif (defined(linux) || defined(__FreeBSD__)) && defined(__amd64__) -# elif (defined(linux) || defined(__FreeBSD__)) && defined(__amd64__) - -# include <inttypes.h> +#include <inttypes.h> static __inline__ void outb(unsigned short port, unsigned char val) { - __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outb %0,%1"::"a"(val), "d"(port)); } - static __inline__ void outw(unsigned short port, unsigned short val) { - __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outw %0,%1"::"a"(val), "d"(port)); } static __inline__ void outl(unsigned short port, unsigned int val) { - __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outl %0,%1"::"a"(val), "d"(port)); } static __inline__ unsigned int inb(unsigned short port) { - unsigned char ret; - __asm__ __volatile__("inb %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned char ret; + __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inw(unsigned short port) { - unsigned short ret; - __asm__ __volatile__("inw %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned short ret; + __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inl(unsigned short port) { - unsigned int ret; - __asm__ __volatile__("inl %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned int ret; + __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port)); + + return ret; } -# elif (defined(linux) || defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc__) +#elif (defined(linux) || defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc__) -# ifndef ASI_PL -# define ASI_PL 0x88 -# endif +#ifndef ASI_PL +#define ASI_PL 0x88 +#endif static __inline__ void outb(unsigned long port, unsigned char val) { - __asm__ __volatile__("stba %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (port), "i" (ASI_PL)); - barrier(); + __asm__ __volatile__("stba %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(port), "i"(ASI_PL)); + + barrier(); } static __inline__ void outw(unsigned long port, unsigned short val) { - __asm__ __volatile__("stha %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (port), "i" (ASI_PL)); - barrier(); + __asm__ __volatile__("stha %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(port), "i"(ASI_PL)); + + barrier(); } static __inline__ void outl(unsigned long port, unsigned int val) { - __asm__ __volatile__("sta %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (port), "i" (ASI_PL)); - barrier(); + __asm__ __volatile__("sta %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(port), "i"(ASI_PL)); + + barrier(); } static __inline__ unsigned int inb(unsigned long port) { - unsigned int ret; - __asm__ __volatile__("lduba [%1] %2, %0" - : "=r" (ret) - : "r" (port), "i" (ASI_PL)); - return ret; + unsigned int ret; + __asm__ __volatile__("lduba [%1] %2, %0":"=r"(ret) + :"r"(port), "i"(ASI_PL)); + + return ret; } static __inline__ unsigned int inw(unsigned long port) { - unsigned int ret; - __asm__ __volatile__("lduha [%1] %2, %0" - : "=r" (ret) - : "r" (port), "i" (ASI_PL)); - return ret; + unsigned int ret; + __asm__ __volatile__("lduha [%1] %2, %0":"=r"(ret) + :"r"(port), "i"(ASI_PL)); + + return ret; } static __inline__ unsigned int inl(unsigned long port) { - unsigned int ret; - __asm__ __volatile__("lda [%1] %2, %0" - : "=r" (ret) - : "r" (port), "i" (ASI_PL)); - return ret; + unsigned int ret; + __asm__ __volatile__("lda [%1] %2, %0":"=r"(ret) + :"r"(port), "i"(ASI_PL)); + + return ret; } static __inline__ unsigned char xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned char ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned char ret; + + __asm__ __volatile__("lduba [%1] %2, %0":"=r"(ret) + :"r"(addr), "i"(ASI_PL)); - __asm__ __volatile__("lduba [%1] %2, %0" - : "=r" (ret) - : "r" (addr), "i" (ASI_PL)); - return ret; + return ret; } static __inline__ unsigned short xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned short ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned short ret; - __asm__ __volatile__("lduh [%1], %0" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("lduh [%1], %0":"=r"(ret) + :"r"(addr)); + + return ret; } static __inline__ unsigned short xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned short ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned short ret; + + __asm__ __volatile__("lduha [%1] %2, %0":"=r"(ret) + :"r"(addr), "i"(ASI_PL)); - __asm__ __volatile__("lduha [%1] %2, %0" - : "=r" (ret) - : "r" (addr), "i" (ASI_PL)); - return ret; + return ret; } static __inline__ unsigned int xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned int ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned int ret; - __asm__ __volatile__("ld [%1], %0" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("ld [%1], %0":"=r"(ret) + :"r"(addr)); + + return ret; } static __inline__ unsigned int xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned int ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned int ret; + + __asm__ __volatile__("lda [%1] %2, %0":"=r"(ret) + :"r"(addr), "i"(ASI_PL)); - __asm__ __volatile__("lda [%1] %2, %0" - : "=r" (ret) - : "r" (addr), "i" (ASI_PL)); - return ret; + return ret; } static __inline__ void xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("stba %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); - barrier(); + __asm__ __volatile__("stba %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); + + barrier(); } static __inline__ void xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; + + __asm__ __volatile__("sth %0, [%1]": /* No outputs */ + :"r"(val), "r"(addr)); - __asm__ __volatile__("sth %0, [%1]" - : /* No outputs */ - : "r" (val), "r" (addr)); - barrier(); + barrier(); } static __inline__ void xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; + + __asm__ __volatile__("stha %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); - __asm__ __volatile__("stha %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); - barrier(); + barrier(); } static __inline__ void xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; + + __asm__ __volatile__("st %0, [%1]": /* No outputs */ + :"r"(val), "r"(addr)); - __asm__ __volatile__("st %0, [%1]" - : /* No outputs */ - : "r" (val), "r" (addr)); - barrier(); + barrier(); } static __inline__ void xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; + + __asm__ __volatile__("sta %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); - __asm__ __volatile__("sta %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); - barrier(); + barrier(); } static __inline__ void xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("stba %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); + __asm__ __volatile__("stba %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); } static __inline__ void xf86WriteMmio16BeNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("sth %0, [%1]" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("sth %0, [%1]": /* No outputs */ + :"r"(val), "r"(addr)); } static __inline__ void xf86WriteMmio16LeNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("stha %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); + __asm__ __volatile__("stha %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); } static __inline__ void xf86WriteMmio32BeNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("st %0, [%1]" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("st %0, [%1]": /* No outputs */ + :"r"(val), "r"(addr)); } static __inline__ void xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("sta %0, [%1] %2" - : /* No outputs */ - : "r" (val), "r" (addr), "i" (ASI_PL)); + __asm__ __volatile__("sta %0, [%1] %2": /* No outputs */ + :"r"(val), "r"(addr), "i"(ASI_PL)); } -# elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__)) -# ifdef __arm32__ -# define PORT_SIZE long -# else -# define PORT_SIZE short -# endif +#elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__)) +#ifdef __arm32__ +#define PORT_SIZE long +#else +#define PORT_SIZE short +#endif -_X_EXPORT unsigned int IOPortBase; /* Memory mapped I/O port area */ +_X_EXPORT unsigned int IOPortBase; /* Memory mapped I/O port area */ static __inline__ void outb(unsigned PORT_SIZE port, unsigned char val) { - *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; + *(volatile unsigned char *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = + val; } static __inline__ void outw(unsigned PORT_SIZE port, unsigned short val) { - *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; + *(volatile unsigned short *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = + val; } static __inline__ void outl(unsigned PORT_SIZE port, unsigned int val) { - *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; + *(volatile unsigned int *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = + val; } static __inline__ unsigned int inb(unsigned PORT_SIZE port) { - return *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase); + return *(volatile unsigned char *) (((unsigned PORT_SIZE) (port)) + + IOPortBase); } static __inline__ unsigned int inw(unsigned PORT_SIZE port) { - return *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase); + return *(volatile unsigned short *) (((unsigned PORT_SIZE) (port)) + + IOPortBase); } static __inline__ unsigned int inl(unsigned PORT_SIZE port) { - return *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase); + return *(volatile unsigned int *) (((unsigned PORT_SIZE) (port)) + + IOPortBase); } - -# if defined(__mips__) -# ifdef linux /* don't mess with other OSs */ -# if X_BYTE_ORDER == X_BIG_ENDIAN +#if defined(__mips__) +#ifdef linux /* don't mess with other OSs */ +#if X_BYTE_ORDER == X_BIG_ENDIAN static __inline__ unsigned int xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned int ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned int ret; - __asm__ __volatile__("lw %0, 0(%1)" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("lw %0, 0(%1)":"=r"(ret) + :"r"(addr)); + + return ret; } static __inline__ void xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__("sw %0, 0(%1)" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("sw %0, 0(%1)": /* No outputs */ + :"r"(val), "r"(addr)); } -# endif -# endif /* !linux */ -# endif /* __mips__ */ +#endif +#endif /* !linux */ +#endif /* __mips__ */ -# elif (defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) && defined(__powerpc__) +#elif (defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) && defined(__powerpc__) -# ifndef MAP_FAILED -# define MAP_FAILED ((void *)-1) -# endif +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif extern _X_EXPORT volatile unsigned char *ioBase; static __inline__ unsigned char xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) { - register unsigned char val; - __asm__ __volatile__( - "lbzx %0,%1,%2\n\t" - "eieio" - : "=r" (val) - : "b" (base), "r" (offset), - "m" (*((volatile unsigned char *)base+offset))); - return val; + register unsigned char val; + __asm__ __volatile__("lbzx %0,%1,%2\n\t" "eieio":"=r"(val) + :"b"(base), "r"(offset), + "m"(*((volatile unsigned char *) base + offset))); + return val; } static __inline__ unsigned short xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) { - register unsigned short val; - __asm__ __volatile__( - "lhzx %0,%1,%2\n\t" - "eieio" - : "=r" (val) - : "b" (base), "r" (offset), - "m" (*((volatile unsigned char *)base+offset))); - return val; + register unsigned short val; + __asm__ __volatile__("lhzx %0,%1,%2\n\t" "eieio":"=r"(val) + :"b"(base), "r"(offset), + "m"(*((volatile unsigned char *) base + offset))); + return val; } static __inline__ unsigned short xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) { - register unsigned short val; - __asm__ __volatile__( - "lhbrx %0,%1,%2\n\t" - "eieio" - : "=r" (val) - : "b" (base), "r" (offset), - "m" (*((volatile unsigned char *)base+offset))); - return val; + register unsigned short val; + __asm__ __volatile__("lhbrx %0,%1,%2\n\t" "eieio":"=r"(val) + :"b"(base), "r"(offset), + "m"(*((volatile unsigned char *) base + offset))); + return val; } static __inline__ unsigned int xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) { - register unsigned int val; - __asm__ __volatile__( - "lwzx %0,%1,%2\n\t" - "eieio" - : "=r" (val) - : "b" (base), "r" (offset), - "m" (*((volatile unsigned char *)base+offset))); - return val; + register unsigned int val; + __asm__ __volatile__("lwzx %0,%1,%2\n\t" "eieio":"=r"(val) + :"b"(base), "r"(offset), + "m"(*((volatile unsigned char *) base + offset))); + return val; } static __inline__ unsigned int xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) { - register unsigned int val; - __asm__ __volatile__( - "lwbrx %0,%1,%2\n\t" - "eieio" - : "=r" (val) - : "b" (base), "r" (offset), - "m" (*((volatile unsigned char *)base+offset))); - return val; + register unsigned int val; + __asm__ __volatile__("lwbrx %0,%1,%2\n\t" "eieio":"=r"(val) + :"b"(base), "r"(offset), + "m"(*((volatile unsigned char *) base + offset))); + return val; } static __inline__ void xf86WriteMmioNB8(__volatile__ void *base, const unsigned long offset, - const unsigned char val) + const unsigned char val) { - __asm__ __volatile__( - "stbx %1,%2,%3\n\t" - : "=m" (*((volatile unsigned char *)base+offset)) - : "r" (val), "b" (base), "r" (offset)); + __asm__ + __volatile__("stbx %1,%2,%3\n\t":"=m" + (*((volatile unsigned char *) base + offset)) + :"r"(val), "b"(base), "r"(offset)); } static __inline__ void xf86WriteMmioNB16Le(__volatile__ void *base, const unsigned long offset, - const unsigned short val) + const unsigned short val) { - __asm__ __volatile__( - "sthbrx %1,%2,%3\n\t" - : "=m" (*((volatile unsigned char *)base+offset)) - : "r" (val), "b" (base), "r" (offset)); + __asm__ + __volatile__("sthbrx %1,%2,%3\n\t":"=m" + (*((volatile unsigned char *) base + offset)) + :"r"(val), "b"(base), "r"(offset)); } static __inline__ void xf86WriteMmioNB16Be(__volatile__ void *base, const unsigned long offset, - const unsigned short val) + const unsigned short val) { - __asm__ __volatile__( - "sthx %1,%2,%3\n\t" - : "=m" (*((volatile unsigned char *)base+offset)) - : "r" (val), "b" (base), "r" (offset)); + __asm__ + __volatile__("sthx %1,%2,%3\n\t":"=m" + (*((volatile unsigned char *) base + offset)) + :"r"(val), "b"(base), "r"(offset)); } static __inline__ void xf86WriteMmioNB32Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - __asm__ __volatile__( - "stwbrx %1,%2,%3\n\t" - : "=m" (*((volatile unsigned char *)base+offset)) - : "r" (val), "b" (base), "r" (offset)); + __asm__ + __volatile__("stwbrx %1,%2,%3\n\t":"=m" + (*((volatile unsigned char *) base + offset)) + :"r"(val), "b"(base), "r"(offset)); } static __inline__ void xf86WriteMmioNB32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - __asm__ __volatile__( - "stwx %1,%2,%3\n\t" - : "=m" (*((volatile unsigned char *)base+offset)) - : "r" (val), "b" (base), "r" (offset)); + __asm__ + __volatile__("stwx %1,%2,%3\n\t":"=m" + (*((volatile unsigned char *) base + offset)) + :"r"(val), "b"(base), "r"(offset)); } static __inline__ void xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, const unsigned char val) { - xf86WriteMmioNB8(base, offset, val); - eieio(); + xf86WriteMmioNB8(base, offset, val); + eieio(); } static __inline__ void xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, const unsigned short val) { - xf86WriteMmioNB16Le(base, offset, val); - eieio(); + xf86WriteMmioNB16Le(base, offset, val); + eieio(); } static __inline__ void xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, const unsigned short val) { - xf86WriteMmioNB16Be(base, offset, val); - eieio(); + xf86WriteMmioNB16Be(base, offset, val); + eieio(); } static __inline__ void xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, const unsigned int val) { - xf86WriteMmioNB32Le(base, offset, val); - eieio(); + xf86WriteMmioNB32Le(base, offset, val); + eieio(); } static __inline__ void xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, const unsigned int val) { - xf86WriteMmioNB32Be(base, offset, val); - eieio(); + xf86WriteMmioNB32Be(base, offset, val); + eieio(); } - static __inline__ void outb(unsigned short port, unsigned char value) { - if(ioBase == MAP_FAILED) return; - xf86WriteMmio8((void *)ioBase, port, value); + if (ioBase == MAP_FAILED) + return; + xf86WriteMmio8((void *) ioBase, port, value); } static __inline__ void outw(unsigned short port, unsigned short value) { - if(ioBase == MAP_FAILED) return; - xf86WriteMmio16Le((void *)ioBase, port, value); + if (ioBase == MAP_FAILED) + return; + xf86WriteMmio16Le((void *) ioBase, port, value); } static __inline__ void outl(unsigned short port, unsigned int value) { - if(ioBase == MAP_FAILED) return; - xf86WriteMmio32Le((void *)ioBase, port, value); + if (ioBase == MAP_FAILED) + return; + xf86WriteMmio32Le((void *) ioBase, port, value); } static __inline__ unsigned int inb(unsigned short port) { - if(ioBase == MAP_FAILED) return 0; - return xf86ReadMmio8((void *)ioBase, port); + if (ioBase == MAP_FAILED) + return 0; + return xf86ReadMmio8((void *) ioBase, port); } static __inline__ unsigned int inw(unsigned short port) { - if(ioBase == MAP_FAILED) return 0; - return xf86ReadMmio16Le((void *)ioBase, port); + if (ioBase == MAP_FAILED) + return 0; + return xf86ReadMmio16Le((void *) ioBase, port); } static __inline__ unsigned int inl(unsigned short port) { - if(ioBase == MAP_FAILED) return 0; - return xf86ReadMmio32Le((void *)ioBase, port); + if (ioBase == MAP_FAILED) + return 0; + return xf86ReadMmio32Le((void *) ioBase, port); } #elif defined(__arm__) && defined(__linux__) @@ -999,7 +1008,7 @@ xf_outl(unsigned short port, unsigned int val) #define outw xf_outw #define outl xf_outl -# elif defined(__nds32__) +#elif defined(__nds32__) /* * Assume all port access are aligned. We need to revise this implementation @@ -1007,352 +1016,326 @@ xf_outl(unsigned short port, unsigned int val) * stw_u, they are assumed unaligned. */ -#define barrier() /* no barrier */ +#define barrier() /* no barrier */ #define PORT_SIZE long static __inline__ unsigned char xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) { - return *(volatile unsigned char *)((unsigned char *)base + offset) ; + return *(volatile unsigned char *) ((unsigned char *) base + offset); } static __inline__ void xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned char *)((unsigned char *)base + offset) = val ; - barrier(); + *(volatile unsigned char *) ((unsigned char *) base + offset) = val; + barrier(); } static __inline__ void xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned char *)((unsigned char *)base + offset) = val ; + *(volatile unsigned char *) ((unsigned char *) base + offset) = val; } static __inline__ unsigned short xf86ReadMmio16Swap(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned short ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned short ret; - __asm__ __volatile__( - "lhi %0, [%1];\n\t" - "wsbh %0, %0;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("lhi %0, [%1];\n\t" "wsbh %0, %0;\n\t":"=r"(ret) + :"r"(addr)); + + return ret; } static __inline__ unsigned short xf86ReadMmio16(__volatile__ void *base, const unsigned long offset) { - return *(volatile unsigned short *)((char *)base + offset) ; + return *(volatile unsigned short *) ((char *) base + offset); } static __inline__ void xf86WriteMmio16Swap(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; + + __asm__ __volatile__("wsbh %0, %0;\n\t" "shi %0, [%1];\n\t": /* No outputs */ + :"r"(val), "r"(addr)); - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "shi %0, [%1];\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); - barrier(); + barrier(); } static __inline__ void xf86WriteMmio16(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned short *)((unsigned char *)base + offset) = val ; - barrier(); + *(volatile unsigned short *) ((unsigned char *) base + offset) = val; + barrier(); } static __inline__ void xf86WriteMmio16SwapNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "shi %0, [%1];\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("wsbh %0, %0;\n\t" "shi %0, [%1];\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } static __inline__ void xf86WriteMmio16NB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned short *)((unsigned char *)base + offset) = val ; + *(volatile unsigned short *) ((unsigned char *) base + offset) = val; } static __inline__ unsigned int xf86ReadMmio32Swap(__volatile__ void *base, const unsigned long offset) { - unsigned long addr = ((unsigned long)base) + offset; - unsigned int ret; + unsigned long addr = ((unsigned long) base) + offset; + unsigned int ret; + + __asm__ __volatile__("lwi %0, [%1];\n\t" + "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret) + :"r"(addr)); - __asm__ __volatile__( - "lwi %0, [%1];\n\t" - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; + return ret; } static __inline__ unsigned int xf86ReadMmio32(__volatile__ void *base, const unsigned long offset) { - return *(volatile unsigned int *)((unsigned char *)base + offset) ; + return *(volatile unsigned int *) ((unsigned char *) base + offset); } static __inline__ void xf86WriteMmio32Swap(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - "swi %0, [%1];\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); - barrier(); + __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "swi %0, [%1];\n\t": /* No outputs */ + :"r"(val), "r"(addr)); + + barrier(); } static __inline__ void xf86WriteMmio32(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned int *)((unsigned char *)base + offset) = val ; - barrier(); + *(volatile unsigned int *) ((unsigned char *) base + offset) = val; + barrier(); } static __inline__ void xf86WriteMmio32SwapNB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - unsigned long addr = ((unsigned long)base) + offset; + unsigned long addr = ((unsigned long) base) + offset; - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - "swi %0, [%1];\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "swi %0, [%1];\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } static __inline__ void xf86WriteMmio32NB(__volatile__ void *base, const unsigned long offset, - const unsigned int val) + const unsigned int val) { - *(volatile unsigned int *)((unsigned char *)base + offset) = val ; + *(volatile unsigned int *) ((unsigned char *) base + offset) = val; } -# if defined(NDS32_MMIO_SWAP) +#if defined(NDS32_MMIO_SWAP) static __inline__ void outb(unsigned PORT_SIZE port, unsigned char val) { - xf86WriteMmio8(IOPortBase, port, val); + xf86WriteMmio8(IOPortBase, port, val); } static __inline__ void outw(unsigned PORT_SIZE port, unsigned short val) { - xf86WriteMmio16Swap(IOPortBase, port, val); + xf86WriteMmio16Swap(IOPortBase, port, val); } static __inline__ void outl(unsigned PORT_SIZE port, unsigned int val) { - xf86WriteMmio32Swap(IOPortBase, port, val); + xf86WriteMmio32Swap(IOPortBase, port, val); } static __inline__ unsigned int inb(unsigned PORT_SIZE port) { - return xf86ReadMmio8(IOPortBase, port); + return xf86ReadMmio8(IOPortBase, port); } static __inline__ unsigned int inw(unsigned PORT_SIZE port) { - return xf86ReadMmio16Swap(IOPortBase, port); + return xf86ReadMmio16Swap(IOPortBase, port); } static __inline__ unsigned int inl(unsigned PORT_SIZE port) { - return xf86ReadMmio32Swap(IOPortBase, port); + return xf86ReadMmio32Swap(IOPortBase, port); } -static __inline__ unsigned long ldq_u(unsigned long *p) +static __inline__ unsigned long +ldq_u(unsigned long *p) { - unsigned long addr = (unsigned long)p; - unsigned int ret; + unsigned long addr = (unsigned long) p; + unsigned int ret; + + __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t" + "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret) + :"r"(addr)); - __asm__ __volatile__( - "lmw.bi %0, [%1], %0, 0;\n\t" - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; + return ret; } -static __inline__ unsigned long ldl_u(unsigned int *p) +static __inline__ unsigned long +ldl_u(unsigned int *p) { - unsigned long addr = (unsigned long)p; - unsigned int ret; + unsigned long addr = (unsigned long) p; + unsigned int ret; - __asm__ __volatile__( - "lmw.bi %0, [%1], %0, 0;\n\t" - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t" + "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret) + :"r"(addr)); + + return ret; } -static __inline__ void stq_u(unsigned long val, unsigned long *p) +static __inline__ void +stq_u(unsigned long val, unsigned long *p) { - unsigned long addr = (unsigned long)p; + unsigned long addr = (unsigned long) p; - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - "smw.bi %0, [%1], %0, 0;\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } -static __inline__ void stl_u(unsigned long val, unsigned int *p) +static __inline__ void +stl_u(unsigned long val, unsigned int *p) { - unsigned long addr = (unsigned long)p; + unsigned long addr = (unsigned long) p; - __asm__ __volatile__( - "wsbh %0, %0;\n\t" - "rotri %0, %0, 16;\n\t" - "smw.bi %0, [%1], %0, 0;\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } -# else /* !NDS32_MMIO_SWAP */ +#else /* !NDS32_MMIO_SWAP */ static __inline__ void outb(unsigned PORT_SIZE port, unsigned char val) { - *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))) = val; - barrier(); + *(volatile unsigned char *) (((unsigned PORT_SIZE) (port))) = val; + barrier(); } static __inline__ void outw(unsigned PORT_SIZE port, unsigned short val) { - *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))) = val; - barrier(); + *(volatile unsigned short *) (((unsigned PORT_SIZE) (port))) = val; + barrier(); } static __inline__ void outl(unsigned PORT_SIZE port, unsigned int val) { - *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))) = val; - barrier(); + *(volatile unsigned int *) (((unsigned PORT_SIZE) (port))) = val; + barrier(); } + static __inline__ unsigned int inb(unsigned PORT_SIZE port) { - return *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))); + return *(volatile unsigned char *) (((unsigned PORT_SIZE) (port))); } static __inline__ unsigned int inw(unsigned PORT_SIZE port) { - return *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))); + return *(volatile unsigned short *) (((unsigned PORT_SIZE) (port))); } static __inline__ unsigned int inl(unsigned PORT_SIZE port) { - return *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))); + return *(volatile unsigned int *) (((unsigned PORT_SIZE) (port))); } -static __inline__ unsigned long ldq_u(unsigned long *p) +static __inline__ unsigned long +ldq_u(unsigned long *p) { - unsigned long addr = (unsigned long)p; - unsigned int ret; + unsigned long addr = (unsigned long) p; + unsigned int ret; - __asm__ __volatile__( - "lmw.bi %0, [%1], %0, 0;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; + __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t":"=r"(ret) + :"r"(addr)); + + return ret; } -static __inline__ unsigned long ldl_u(unsigned int *p) +static __inline__ unsigned long +ldl_u(unsigned int *p) { - unsigned long addr = (unsigned long)p; - unsigned int ret; + unsigned long addr = (unsigned long) p; + unsigned int ret; - __asm__ __volatile__( - "lmw.bi %0, [%1], %0, 0;\n\t" - : "=r" (ret) - : "r" (addr)); - return ret; -} + __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t":"=r"(ret) + :"r"(addr)); + return ret; +} -static __inline__ void stq_u(unsigned long val, unsigned long *p) +static __inline__ void +stq_u(unsigned long val, unsigned long *p) { - unsigned long addr = (unsigned long)p; + unsigned long addr = (unsigned long) p; - __asm__ __volatile__( - "smw.bi %0, [%1], %0, 0;\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } -static __inline__ void stl_u(unsigned long val, unsigned int *p) +static __inline__ void +stl_u(unsigned long val, unsigned int *p) { - unsigned long addr = (unsigned long)p; + unsigned long addr = (unsigned long) p; - __asm__ __volatile__( - "smw.bi %0, [%1], %0, 0;\n\t" - : /* No outputs */ - : "r" (val), "r" (addr)); + __asm__ __volatile__("smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */ + :"r"(val), "r"(addr)); } -# endif /* NDS32_MMIO_SWAP */ +#endif /* NDS32_MMIO_SWAP */ -# if (((X_BYTE_ORDER == X_BIG_ENDIAN) && !defined(NDS32_MMIO_SWAP)) || ((X_BYTE_ORDER != X_BIG_ENDIAN) && defined(NDS32_MMIO_SWAP))) -# define ldw_u(p) ((*(unsigned char *)(p)) << 8 | \ +#if (((X_BYTE_ORDER == X_BIG_ENDIAN) && !defined(NDS32_MMIO_SWAP)) || ((X_BYTE_ORDER != X_BIG_ENDIAN) && defined(NDS32_MMIO_SWAP))) +#define ldw_u(p) ((*(unsigned char *)(p)) << 8 | \ (*((unsigned char *)(p)+1))) -# define stw_u(v,p) (*(unsigned char *)(p)) = ((v) >> 8); \ +#define stw_u(v,p) (*(unsigned char *)(p)) = ((v) >> 8); \ (*((unsigned char *)(p)+1)) = (v) -# else -# define ldw_u(p) ((*(unsigned char *)(p)) | \ +#else +#define ldw_u(p) ((*(unsigned char *)(p)) | \ (*((unsigned char *)(p)+1)<<8)) -# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \ +#define stw_u(v,p) (*(unsigned char *)(p)) = (v); \ (*((unsigned char *)(p)+1)) = ((v) >> 8) -# endif +#endif -# define mem_barrier() /* XXX: nop for now */ -# define write_mem_barrier() /* XXX: nop for now */ +#define mem_barrier() /* XXX: nop for now */ +#define write_mem_barrier() /* XXX: nop for now */ -# else /* ix86 */ +#else /* ix86 */ -# if !defined(__SUNPRO_C) -# if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__m32r__) -# ifdef GCCUSESGAS +#if !defined(__SUNPRO_C) +#if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__m32r__) +#ifdef GCCUSESGAS /* * If gcc uses gas rather than the native assembler, the syntax of these @@ -1362,105 +1345,98 @@ static __inline__ void stl_u(unsigned long val, unsigned int *p) static __inline__ void outb(unsigned short port, unsigned char val) { - __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outb %0,%1"::"a"(val), "d"(port)); } - static __inline__ void outw(unsigned short port, unsigned short val) { - __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outw %0,%1"::"a"(val), "d"(port)); } static __inline__ void outl(unsigned short port, unsigned int val) { - __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__("outl %0,%1"::"a"(val), "d"(port)); } static __inline__ unsigned int inb(unsigned short port) { - unsigned char ret; - __asm__ __volatile__("inb %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned char ret; + __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inw(unsigned short port) { - unsigned short ret; - __asm__ __volatile__("inw %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned short ret; + __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inl(unsigned short port) { - unsigned int ret; - __asm__ __volatile__("inl %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned int ret; + __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port)); + + return ret; } -# else /* GCCUSESGAS */ +#else /* GCCUSESGAS */ static __inline__ void outb(unsigned short port, unsigned char val) { - __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port)); + __asm__ __volatile__("out%B0 (%1)"::"a"(val), "d"(port)); } static __inline__ void outw(unsigned short port, unsigned short val) { - __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port)); + __asm__ __volatile__("out%W0 (%1)"::"a"(val), "d"(port)); } static __inline__ void outl(unsigned short port, unsigned int val) { - __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port)); + __asm__ __volatile__("out%L0 (%1)"::"a"(val), "d"(port)); } static __inline__ unsigned int inb(unsigned short port) { - unsigned char ret; - __asm__ __volatile__("in%B0 (%1)" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned char ret; + __asm__ __volatile__("in%B0 (%1)":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inw(unsigned short port) { - unsigned short ret; - __asm__ __volatile__("in%W0 (%1)" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned short ret; + __asm__ __volatile__("in%W0 (%1)":"=a"(ret):"d"(port)); + + return ret; } static __inline__ unsigned int inl(unsigned short port) { - unsigned int ret; - __asm__ __volatile__("in%L0 (%1)" : - "=a" (ret) : - "d" (port)); - return ret; + unsigned int ret; + __asm__ __volatile__("in%L0 (%1)":"=a"(ret):"d"(port)); + + return ret; } -# endif /* GCCUSESGAS */ +#endif /* GCCUSESGAS */ -# else /* !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__m32r__) */ +#else /* !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__m32r__) */ static __inline__ void outb(unsigned short port, unsigned char val) @@ -1480,141 +1456,143 @@ outl(unsigned short port, unsigned int val) static __inline__ unsigned int inb(unsigned short port) { - return 0; + return 0; } static __inline__ unsigned int inw(unsigned short port) { - return 0; + return 0; } static __inline__ unsigned int inl(unsigned short port) { - return 0; + return 0; } -# endif /* FAKEIT */ -# endif /* __SUNPRO_C */ +#endif /* FAKEIT */ +#endif /* __SUNPRO_C */ -# endif /* ix86 */ +#endif /* ix86 */ -# else /* !GNUC */ -# if defined(__STDC__) && (__STDC__ == 1) -# ifndef asm -# define asm __asm -# endif -# endif -# if !defined(__SUNPRO_C) -# include <sys/inline.h> -# endif -# if !defined(__HIGHC__) && !defined(__SUNPRO_C) || \ +#else /* !GNUC */ +#if defined(__STDC__) && (__STDC__ == 1) +#ifndef asm +#define asm __asm +#endif +#endif +#if !defined(__SUNPRO_C) +#include <sys/inline.h> +#endif +#if !defined(__HIGHC__) && !defined(__SUNPRO_C) || \ defined(__USLC__) -# pragma asm partial_optimization outl -# pragma asm partial_optimization outw -# pragma asm partial_optimization outb -# pragma asm partial_optimization inl -# pragma asm partial_optimization inw -# pragma asm partial_optimization inb -# endif -# endif /* __GNUC__ */ - -# endif /* NO_INLINE */ - -# ifdef __alpha__ +#pragma asm partial_optimization outl +#pragma asm partial_optimization outw +#pragma asm partial_optimization outb +#pragma asm partial_optimization inl +#pragma asm partial_optimization inw +#pragma asm partial_optimization inb +#endif +#endif /* __GNUC__ */ + +#endif /* NO_INLINE */ + +#ifdef __alpha__ /* entry points for Mmio memory access routines */ -extern _X_EXPORT int (*xf86ReadMmio8)(void *, unsigned long); -extern _X_EXPORT int (*xf86ReadMmio16)(void *, unsigned long); -# ifndef STANDALONE_MMIO -extern _X_EXPORT int (*xf86ReadMmio32)(void *, unsigned long); -# else +extern _X_EXPORT int (*xf86ReadMmio8) (void *, unsigned long); +extern _X_EXPORT int (*xf86ReadMmio16) (void *, unsigned long); + +#ifndef STANDALONE_MMIO +extern _X_EXPORT int (*xf86ReadMmio32) (void *, unsigned long); +#else /* Some DRI 3D drivers need MMIO_IN32. */ static __inline__ int xf86ReadMmio32(void *Base, unsigned long Offset) { - mem_barrier(); - return *(volatile unsigned int*)((unsigned long)Base+(Offset)); -} -# endif -extern _X_EXPORT void (*xf86WriteMmio8)(int, void *, unsigned long); -extern _X_EXPORT void (*xf86WriteMmio16)(int, void *, unsigned long); -extern _X_EXPORT void (*xf86WriteMmio32)(int, void *, unsigned long); -extern _X_EXPORT void (*xf86WriteMmioNB8)(int, void *, unsigned long); -extern _X_EXPORT void (*xf86WriteMmioNB16)(int, void *, unsigned long); -extern _X_EXPORT void (*xf86WriteMmioNB32)(int, void *, unsigned long); -extern _X_EXPORT void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, int); + mem_barrier(); + return *(volatile unsigned int *) ((unsigned long) Base + (Offset)); +} +#endif +extern _X_EXPORT void (*xf86WriteMmio8) (int, void *, unsigned long); +extern _X_EXPORT void (*xf86WriteMmio16) (int, void *, unsigned long); +extern _X_EXPORT void (*xf86WriteMmio32) (int, void *, unsigned long); +extern _X_EXPORT void (*xf86WriteMmioNB8) (int, void *, unsigned long); +extern _X_EXPORT void (*xf86WriteMmioNB16) (int, void *, unsigned long); +extern _X_EXPORT void (*xf86WriteMmioNB32) (int, void *, unsigned long); +extern _X_EXPORT void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, + int); extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int); /* Some macros to hide the system dependencies for MMIO accesses */ /* Changed to kill noise generated by gcc's -Wcast-align */ -# define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset) -# define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset) -# ifndef STANDALONE_MMIO -# define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset) -# else -# define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) -# endif - -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset) +#define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset) +#ifndef STANDALONE_MMIO +#define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset) +#else +#define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) +#endif + +#define MMIO_OUT32(base, offset, val) \ do { \ write_mem_barrier(); \ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \ } while (0) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val) -# define MMIO_OUT8(base, offset, val) \ +#define MMIO_OUT8(base, offset, val) \ (*xf86WriteMmio8)((CARD8)(val), base, offset) -# define MMIO_OUT16(base, offset, val) \ +#define MMIO_OUT16(base, offset, val) \ (*xf86WriteMmio16)((CARD16)(val), base, offset) -# define MMIO_ONB8(base, offset, val) \ +#define MMIO_ONB8(base, offset, val) \ (*xf86WriteMmioNB8)((CARD8)(val), base, offset) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ (*xf86WriteMmioNB16)((CARD16)(val), base, offset) -# define MMIO_MOVE32(base, offset, val) \ +#define MMIO_MOVE32(base, offset, val) \ MMIO_OUT32(base, offset, val) -# elif defined(__powerpc__) +#elif defined(__powerpc__) /* * we provide byteswapping and no byteswapping functions here * with byteswapping as default, * drivers that don't need byteswapping should define PPC_MMIO_IS_BE */ -# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -# define MMIO_OUT8(base, offset, val) \ +#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) +#define MMIO_OUT8(base, offset, val) \ xf86WriteMmio8(base, offset, (CARD8)(val)) -# define MMIO_ONB8(base, offset, val) \ +#define MMIO_ONB8(base, offset, val) \ xf86WriteMmioNB8(base, offset, (CARD8)(val)) -# if defined(PPC_MMIO_IS_BE) /* No byteswapping */ -# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#if defined(PPC_MMIO_IS_BE) /* No byteswapping */ +#define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16Be(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32Be(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmioNB16Be(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmioNB32Be(base, offset, (CARD32)(val)) -# else /* byteswapping is the default */ -# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#else /* byteswapping is the default */ +#define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16Le(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32Le(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmioNB16Le(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmioNB32Le(base, offset, (CARD32)(val)) -# endif +#endif -# define MMIO_MOVE32(base, offset, val) \ +#define MMIO_MOVE32(base, offset, val) \ xf86WriteMmio32Be(base, offset, (CARD32)(val)) -# elif defined(__sparc__) || defined(sparc) || defined(__sparc) +#elif defined(__sparc__) || defined(sparc) || defined(__sparc) /* * Like powerpc, we provide byteswapping and no byteswapping functions * here with byteswapping as default, drivers that don't need byteswapping @@ -1622,133 +1600,129 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int); * do not need to use PPC_MMIO_IS_BE and the sparc one in all the same places * of drivers?). */ -# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -# define MMIO_OUT8(base, offset, val) \ +#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) +#define MMIO_OUT8(base, offset, val) \ xf86WriteMmio8(base, offset, (CARD8)(val)) -# define MMIO_ONB8(base, offset, val) \ +#define MMIO_ONB8(base, offset, val) \ xf86WriteMmio8NB(base, offset, (CARD8)(val)) -# if defined(SPARC_MMIO_IS_BE) /* No byteswapping */ -# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#if defined(SPARC_MMIO_IS_BE) /* No byteswapping */ +#define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16Be(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32Be(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmio16BeNB(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmio32BeNB(base, offset, (CARD32)(val)) -# else /* byteswapping is the default */ -# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#else /* byteswapping is the default */ +#define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16Le(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32Le(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmio16LeNB(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmio32LeNB(base, offset, (CARD32)(val)) -# endif +#endif -# define MMIO_MOVE32(base, offset, val) \ +#define MMIO_MOVE32(base, offset, val) \ xf86WriteMmio32Be(base, offset, (CARD32)(val)) -# elif defined(__nds32__) +#elif defined(__nds32__) /* * we provide byteswapping and no byteswapping functions here * with no byteswapping as default; when endianness of CPU core * and I/O devices don't match, byte swapping is necessary * drivers that need byteswapping should define NDS32_MMIO_SWAP */ -# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -# define MMIO_OUT8(base, offset, val) \ +#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) +#define MMIO_OUT8(base, offset, val) \ xf86WriteMmio8(base, offset, (CARD8)(val)) -# define MMIO_ONB8(base, offset, val) \ +#define MMIO_ONB8(base, offset, val) \ xf86WriteMmioNB8(base, offset, (CARD8)(val)) -# if defined(NDS32_MMIO_SWAP) /* byteswapping */ -# define MMIO_IN16(base, offset) xf86ReadMmio16Swap(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32Swap(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#if defined(NDS32_MMIO_SWAP) /* byteswapping */ +#define MMIO_IN16(base, offset) xf86ReadMmio16Swap(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32Swap(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16Swap(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32Swap(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmioNB16Swap(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmioNB32Swap(base, offset, (CARD32)(val)) -# else /* no byteswapping is the default */ -# define MMIO_IN16(base, offset) xf86ReadMmio16(base, offset) -# define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) -# define MMIO_OUT16(base, offset, val) \ +#else /* no byteswapping is the default */ +#define MMIO_IN16(base, offset) xf86ReadMmio16(base, offset) +#define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) +#define MMIO_OUT16(base, offset, val) \ xf86WriteMmio16(base, offset, (CARD16)(val)) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ xf86WriteMmio32(base, offset, (CARD32)(val)) -# define MMIO_ONB16(base, offset, val) \ +#define MMIO_ONB16(base, offset, val) \ xf86WriteMmioNB16(base, offset, (CARD16)(val)) -# define MMIO_ONB32(base, offset, val) \ +#define MMIO_ONB32(base, offset, val) \ xf86WriteMmioNB32(base, offset, (CARD32)(val)) -# endif +#endif -# define MMIO_MOVE32(base, offset, val) \ +#define MMIO_MOVE32(base, offset, val) \ xf86WriteMmio32(base, offset, (CARD32)(val)) -#ifdef N1213_HC /* for NDS32 N1213 hardcore */ -static __inline__ void nds32_flush_icache(char *addr) +#ifdef N1213_HC /* for NDS32 N1213 hardcore */ +static __inline__ void +nds32_flush_icache(char *addr) { - __asm__ volatile ( - "isync %0;" - "msync;" - "isb;" - "cctl %0,L1I_VA_INVAL;" - "isb;" - : : "r"(addr) : "memory"); + __asm__ volatile ("isync %0;" + "msync;" + "isb;" + "cctl %0,L1I_VA_INVAL;" "isb;"::"r" (addr):"memory"); } #else -static __inline__ void nds32_flush_icache(char *addr) +static __inline__ void +nds32_flush_icache(char *addr) { - __asm__ volatile ( - "isync %0;" - "isb;" - : : "r"(addr) : "memory"); + __asm__ volatile ("isync %0;" "isb;"::"r" (addr):"memory"); } #endif -# else /* !__alpha__ && !__powerpc__ && !__sparc__ */ +#else /* !__alpha__ && !__powerpc__ && !__sparc__ */ -# define MMIO_IN8(base, offset) \ +#define MMIO_IN8(base, offset) \ *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) -# define MMIO_IN16(base, offset) \ +#define MMIO_IN16(base, offset) \ *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) -# define MMIO_IN32(base, offset) \ +#define MMIO_IN32(base, offset) \ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) -# define MMIO_OUT8(base, offset, val) \ +#define MMIO_OUT8(base, offset, val) \ *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) = (val) -# define MMIO_OUT16(base, offset, val) \ +#define MMIO_OUT16(base, offset, val) \ *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val) -# define MMIO_OUT32(base, offset, val) \ +#define MMIO_OUT32(base, offset, val) \ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val) -# define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val) -# define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val) -# define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val) +#define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val) +#define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val) +#define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val) -# define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val) +#define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val) -# endif /* __alpha__ */ +#endif /* __alpha__ */ /* * With Intel, the version in os-support/misc/SlowBcopy.s is used. * This avoids port I/O during the copy (which causes problems with * some hardware). */ -# ifdef __alpha__ -# define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count) -# define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count) -# else /* __alpha__ */ -# define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count) -# define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count) -# endif /* __alpha__ */ - -#endif /* _COMPILER_H */ +#ifdef __alpha__ +#define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count) +#define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count) +#else /* __alpha__ */ +#define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count) +#define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count) +#endif /* __alpha__ */ + +#endif /* _COMPILER_H */ diff --git a/xorg-server/hw/xfree86/common/vidmodeproc.h b/xorg-server/hw/xfree86/common/vidmodeproc.h index da4d05e1c..aa43237d4 100644 --- a/xorg-server/hw/xfree86/common/vidmodeproc.h +++ b/xorg-server/hw/xfree86/common/vidmodeproc.h @@ -8,7 +8,6 @@ #ifndef _VIDMODEPROC_H_ #define _VIDMODEPROC_H_ - typedef enum { VIDMODE_H_DISPLAY, VIDMODE_H_SYNCSTART, @@ -35,17 +34,20 @@ typedef enum { } VidModeSelectMonitor; typedef union { - pointer ptr; - int i; - float f; + pointer ptr; + int i; + float f; } vidMonitorValue; extern _X_EXPORT void XFree86VidModeExtensionInit(void); extern _X_EXPORT Bool VidModeAvailable(int scrnIndex); -extern _X_EXPORT Bool VidModeGetCurrentModeline(int scrnIndex, pointer *mode, int *dotClock); -extern _X_EXPORT Bool VidModeGetFirstModeline(int scrnIndex, pointer *mode, int *dotClock); -extern _X_EXPORT Bool VidModeGetNextModeline(int scrnIndex, pointer *mode, int *dotClock); +extern _X_EXPORT Bool VidModeGetCurrentModeline(int scrnIndex, pointer *mode, + int *dotClock); +extern _X_EXPORT Bool VidModeGetFirstModeline(int scrnIndex, pointer *mode, + int *dotClock); +extern _X_EXPORT Bool VidModeGetNextModeline(int scrnIndex, pointer *mode, + int *dotClock); extern _X_EXPORT Bool VidModeDeleteModeline(int scrnIndex, pointer mode); extern _X_EXPORT Bool VidModeZoomViewport(int scrnIndex, int zoom); extern _X_EXPORT Bool VidModeGetViewPort(int scrnIndex, int *x, int *y); @@ -55,23 +57,28 @@ extern _X_EXPORT Bool VidModeLockZoom(int scrnIndex, Bool lock); extern _X_EXPORT Bool VidModeGetMonitor(int scrnIndex, pointer *monitor); extern _X_EXPORT int VidModeGetNumOfClocks(int scrnIndex, Bool *progClock); extern _X_EXPORT Bool VidModeGetClocks(int scrnIndex, int *Clocks); -extern _X_EXPORT ModeStatus VidModeCheckModeForMonitor(int scrnIndex, pointer mode); -extern _X_EXPORT ModeStatus VidModeCheckModeForDriver(int scrnIndex, pointer mode); +extern _X_EXPORT ModeStatus VidModeCheckModeForMonitor(int scrnIndex, + pointer mode); +extern _X_EXPORT ModeStatus VidModeCheckModeForDriver(int scrnIndex, + pointer mode); extern _X_EXPORT void VidModeSetCrtcForMode(int scrnIndex, pointer mode); extern _X_EXPORT Bool VidModeAddModeline(int scrnIndex, pointer mode); extern _X_EXPORT int VidModeGetDotClock(int scrnIndex, int Clock); extern _X_EXPORT int VidModeGetNumOfModes(int scrnIndex); -extern _X_EXPORT Bool VidModeSetGamma(int scrnIndex, float red, float green, float blue); -extern _X_EXPORT Bool VidModeGetGamma(int scrnIndex, float *red, float *green, float *blue); +extern _X_EXPORT Bool VidModeSetGamma(int scrnIndex, float red, float green, + float blue); +extern _X_EXPORT Bool VidModeGetGamma(int scrnIndex, float *red, float *green, + float *blue); extern _X_EXPORT pointer VidModeCreateMode(void); extern _X_EXPORT void VidModeCopyMode(pointer modefrom, pointer modeto); extern _X_EXPORT int VidModeGetModeValue(pointer mode, int valtyp); extern _X_EXPORT void VidModeSetModeValue(pointer mode, int valtyp, int val); -extern _X_EXPORT vidMonitorValue VidModeGetMonitorValue(pointer monitor, int valtyp, int indx); -extern _X_EXPORT Bool VidModeSetGammaRamp(int, int, CARD16 *, CARD16 *, CARD16 *); -extern _X_EXPORT Bool VidModeGetGammaRamp(int, int, CARD16 *, CARD16 *, CARD16 *); +extern _X_EXPORT vidMonitorValue VidModeGetMonitorValue(pointer monitor, + int valtyp, int indx); +extern _X_EXPORT Bool VidModeSetGammaRamp(int, int, CARD16 *, CARD16 *, + CARD16 *); +extern _X_EXPORT Bool VidModeGetGammaRamp(int, int, CARD16 *, CARD16 *, + CARD16 *); extern _X_EXPORT int VidModeGetGammaRampSize(int scrnIndex); #endif - - diff --git a/xorg-server/hw/xfree86/common/xf86.h b/xorg-server/hw/xfree86/common/xf86.h index b711f0555..fc4c34e92 100644 --- a/xorg-server/hw/xfree86/common/xf86.h +++ b/xorg-server/hw/xfree86/common/xf86.h @@ -57,21 +57,24 @@ extern _X_EXPORT int xf86DoShowOptions; extern _X_EXPORT Bool xf86DoConfigurePass1; extern _X_EXPORT DevPrivateKeyRec xf86ScreenKeyRec; + #define xf86ScreenKey (&xf86ScreenKeyRec) extern _X_EXPORT DevPrivateKeyRec xf86CreateRootWindowKeyRec; + #define xf86CreateRootWindowKey (&xf86CreateRootWindowKeyRec) -extern _X_EXPORT ScrnInfoPtr *xf86Screens; /* List of pointers to ScrnInfoRecs */ +extern _X_EXPORT ScrnInfoPtr *xf86Screens; /* List of pointers to ScrnInfoRecs */ extern _X_EXPORT const unsigned char byte_reversed[256]; extern _X_EXPORT Bool fbSlotClaimed; + #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) extern _X_EXPORT Bool sbusSlotClaimed; #endif extern _X_EXPORT confDRIRec xf86ConfigDRI; extern _X_EXPORT Bool xf86DRI2Enabled(void); -extern _X_EXPORT Bool VTSwitchEnabled; /* kbd driver */ +extern _X_EXPORT Bool VTSwitchEnabled; /* kbd driver */ #define XF86SCRNINFO(p) ((ScrnInfoPtr)dixLookupPrivate(&(p)->devPrivates, \ xf86ScreenKey)) @@ -104,20 +107,30 @@ extern _X_EXPORT Bool xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func); extern _X_EXPORT Bool xf86ComparePciBusString(const char *busID, int bus, int device, int func); -extern _X_EXPORT Bool xf86IsPrimaryPci(struct pci_device * pPci); -extern _X_EXPORT Bool xf86CheckPciMemBase(struct pci_device * pPci, +extern _X_EXPORT Bool xf86IsPrimaryPci(struct pci_device *pPci); +extern _X_EXPORT Bool xf86CheckPciMemBase(struct pci_device *pPci, memType base); -extern _X_EXPORT struct pci_device * xf86GetPciInfoForEntity(int entityIndex); +extern _X_EXPORT struct pci_device *xf86GetPciInfoForEntity(int entityIndex); extern _X_EXPORT int xf86MatchPciInstances(const char *driverName, - int vendorID, SymTabPtr chipsets, PciChipsets *PCIchipsets, - GDevPtr *devList, int numDevs, DriverPtr drvp, int **foundEntities); + int vendorID, SymTabPtr chipsets, + PciChipsets * PCIchipsets, + GDevPtr * devList, int numDevs, + DriverPtr drvp, int **foundEntities); extern _X_EXPORT ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, - int scrnFlag, int entityIndex,PciChipsets *p_chip, void *dummy, - EntityProc init, EntityProc enter, EntityProc leave, pointer private); + int scrnFlag, int entityIndex, + PciChipsets * p_chip, + void *dummy, EntityProc init, + EntityProc enter, + EntityProc leave, + pointer private); /* Obsolete! don't use */ extern _X_EXPORT Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, - int entityIndex,PciChipsets *p_chip, void *dummy, EntityProc init, - EntityProc enter, EntityProc leave, pointer private); + int entityIndex, + PciChipsets * p_chip, + void *dummy, EntityProc init, + EntityProc enter, + EntityProc leave, + pointer private); #else #define xf86VGAarbiterInit() do {} while (0) #define xf86VGAarbiterFini() do {} while (0) @@ -130,19 +143,24 @@ extern _X_EXPORT Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, /* xf86Bus.c */ -extern _X_EXPORT int xf86GetFbInfoForScreen(int scrnIndex); -extern _X_EXPORT int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); -extern _X_EXPORT int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); +extern _X_EXPORT int xf86GetFbInfoForScreen(int scrnIndex); +extern _X_EXPORT int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, + Bool active); +extern _X_EXPORT int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, + Bool active); extern _X_EXPORT Bool xf86DriverHasEntities(DriverPtr drvp); extern _X_EXPORT void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex); -extern _X_EXPORT void xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, - int instance); +extern _X_EXPORT void xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, + int entityIndex, + int instance); extern _X_EXPORT int xf86GetNumEntityInstances(int entityIndex); extern _X_EXPORT GDevPtr xf86GetDevFromEntity(int entityIndex, int instance); -extern _X_EXPORT void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex); +extern _X_EXPORT void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, + int entityIndex); extern _X_EXPORT EntityInfoPtr xf86GetEntityInfo(int entityIndex); extern _X_EXPORT Bool xf86SetEntityFuncs(int entityIndex, EntityProc init, - EntityProc enter, EntityProc leave, pointer); + EntityProc enter, EntityProc leave, + pointer); extern _X_EXPORT Bool xf86IsEntityPrimary(int entityIndex); extern _X_EXPORT ScrnInfoPtr xf86FindScreenForEntity(int entityIndex); @@ -159,8 +177,9 @@ extern _X_EXPORT int xf86AllocateEntityPrivateIndex(void); extern _X_EXPORT DevUnion *xf86GetEntityPrivate(int entityIndex, int privIndex); /* xf86Configure.c */ -extern _X_EXPORT GDevPtr xf86AddBusDeviceToConfigure(const char *driver, BusType bus, - void *busData, int chipset); +extern _X_EXPORT GDevPtr xf86AddBusDeviceToConfigure(const char *driver, + BusType bus, void *busData, + int chipset); /* xf86Cursor.c */ @@ -174,56 +193,63 @@ extern _X_EXPORT void xf86InitOrigins(void); extern _X_EXPORT void xf86ReconfigureLayout(void); /* xf86cvt.c */ -extern _X_EXPORT DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, - Bool Reduced, Bool Interlaced); +extern _X_EXPORT DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, + float VRefresh, Bool Reduced, + Bool Interlaced); /* xf86DPMS.c */ -extern _X_EXPORT Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags); +extern _X_EXPORT Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, + int flags); #ifdef DPMSExtension extern _X_EXPORT int DPMSSet(ClientPtr client, int level); extern _X_EXPORT Bool DPMSSupported(void); #endif - /* xf86DGA.c */ #ifdef XFreeXDGA -extern _X_EXPORT Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes, - int num); -extern _X_EXPORT Bool DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, int num); +extern _X_EXPORT Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, + DGAModePtr modes, int num); +extern _X_EXPORT Bool DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, + int num); extern _X_EXPORT xf86SetDGAModeProc xf86SetDGAMode; #endif /* xf86Events.c */ extern _X_EXPORT void SetTimeSinceLastInputEvent(void); -extern _X_EXPORT pointer xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data); +extern _X_EXPORT pointer xf86AddInputHandler(int fd, InputHandlerProc proc, + pointer data); extern _X_EXPORT int xf86RemoveInputHandler(pointer handler); extern _X_EXPORT void xf86DisableInputHandler(pointer handler); extern _X_EXPORT void xf86EnableInputHandler(pointer handler); -extern _X_EXPORT pointer xf86AddGeneralHandler(int fd, InputHandlerProc proc, pointer data); +extern _X_EXPORT pointer xf86AddGeneralHandler(int fd, InputHandlerProc proc, + pointer data); extern _X_EXPORT int xf86RemoveGeneralHandler(pointer handler); extern _X_EXPORT void xf86DisableGeneralHandler(pointer handler); extern _X_EXPORT void xf86EnableGeneralHandler(pointer handler); -extern _X_EXPORT InputHandlerProc xf86SetConsoleHandler(InputHandlerProc handler, pointer data); +extern _X_EXPORT InputHandlerProc xf86SetConsoleHandler(InputHandlerProc + handler, pointer data); extern _X_EXPORT void xf86InterceptSignals(int *signo); -extern _X_EXPORT void xf86InterceptSigIll(void (*sigillhandler)(void)); +extern _X_EXPORT void xf86InterceptSigIll(void (*sigillhandler) (void)); extern _X_EXPORT Bool xf86EnableVTSwitch(Bool new); extern _X_EXPORT void xf86ProcessActionEvent(ActionEvent action, void *arg); extern _X_EXPORT void xf86PrintBacktrace(void); /* xf86Helper.c */ -extern _X_EXPORT void xf86AddDriver(DriverPtr driver, pointer module, int flags); +extern _X_EXPORT void xf86AddDriver(DriverPtr driver, pointer module, + int flags); extern _X_EXPORT void xf86DeleteDriver(int drvIndex); extern _X_EXPORT ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags); extern _X_EXPORT void xf86DeleteScreen(int scrnIndex, int flags); extern _X_EXPORT int xf86AllocateScrnInfoPrivateIndex(void); -extern _X_EXPORT Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad); -extern _X_EXPORT Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, int fbbpp, - int depth24flags); +extern _X_EXPORT Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, + int pad); +extern _X_EXPORT Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, + int fbbpp, int depth24flags); extern _X_EXPORT void xf86PrintDepthBpp(ScrnInfoPtr scrp); extern _X_EXPORT Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask); extern _X_EXPORT Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual); @@ -231,125 +257,198 @@ extern _X_EXPORT Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma newGamma); extern _X_EXPORT void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y); extern _X_EXPORT void xf86SetBlackWhitePixels(ScreenPtr pScreen); extern _X_EXPORT void xf86EnableDisableFBAccess(int scrnIndex, Bool enable); -extern _X_EXPORT void xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, va_list args) _X_ATTRIBUTE_PRINTF(4,0); -extern _X_EXPORT void xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, ...) _X_ATTRIBUTE_PRINTF(4,5); -extern _X_EXPORT void xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) - _X_ATTRIBUTE_PRINTF(3,4); -extern _X_EXPORT void xf86MsgVerb(MessageType type, int verb, const char *format, ...) - _X_ATTRIBUTE_PRINTF(3,4); -extern _X_EXPORT void xf86Msg(MessageType type, const char *format, ...) _X_ATTRIBUTE_PRINTF(2,3); -extern _X_EXPORT void xf86ErrorFVerb(int verb, const char *format, ...) _X_ATTRIBUTE_PRINTF(2,3); -extern _X_EXPORT void xf86ErrorF(const char *format, ...) _X_ATTRIBUTE_PRINTF(1,2); -extern _X_EXPORT const char *xf86TokenToString(SymTabPtr table, int token); -extern _X_EXPORT int xf86StringToToken(SymTabPtr table, const char *string); -extern _X_EXPORT void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from); -extern _X_EXPORT void xf86PrintChipsets(const char *drvname, const char *drvmsg, - SymTabPtr chips); -extern _X_EXPORT int xf86MatchDevice(const char *drivername, GDevPtr **driversectlist); -extern _X_EXPORT const char *xf86GetVisualName(int visual); -extern _X_EXPORT int xf86GetVerbosity(void); -extern _X_EXPORT Pix24Flags xf86GetPix24(void); -extern _X_EXPORT int xf86GetDepth(void); -extern _X_EXPORT rgb xf86GetWeight(void); -extern _X_EXPORT Gamma xf86GetGamma(void); -extern _X_EXPORT Bool xf86GetFlipPixels(void); -extern _X_EXPORT const char *xf86GetServerName(void); -extern _X_EXPORT Bool xf86ServerIsExiting(void); -extern _X_EXPORT Bool xf86ServerIsResetting(void); -extern _X_EXPORT Bool xf86ServerIsInitialising(void); -extern _X_EXPORT Bool xf86ServerIsOnlyDetecting(void); -extern _X_EXPORT Bool xf86CaughtSignal(void); -extern _X_EXPORT Bool xf86GetVidModeAllowNonLocal(void); -extern _X_EXPORT Bool xf86GetVidModeEnabled(void); -extern _X_EXPORT Bool xf86GetModInDevAllowNonLocal(void); -extern _X_EXPORT Bool xf86GetModInDevEnabled(void); -extern _X_EXPORT Bool xf86GetAllowMouseOpenFail(void); -extern _X_EXPORT void xf86DisableRandR(void); -extern _X_EXPORT CARD32 xorgGetVersion(void); -extern _X_EXPORT CARD32 xf86GetModuleVersion(pointer module); -extern _X_EXPORT pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name); -extern _X_EXPORT pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name); -extern _X_EXPORT pointer xf86LoadOneModule(char *name, pointer optlist); -extern _X_EXPORT void xf86UnloadSubModule(pointer mod); -extern _X_EXPORT Bool xf86LoaderCheckSymbol(const char *name); -extern _X_EXPORT void xf86SetBackingStore(ScreenPtr pScreen); -extern _X_EXPORT void xf86SetSilkenMouse(ScreenPtr pScreen); -extern _X_EXPORT pointer xf86FindXvOptions(int scrnIndex, int adapt_index, char *port_name, - char **adaptor_name, pointer *adaptor_options); -extern _X_EXPORT void xf86GetOS(const char **name, int *major, int *minor, int *teeny); -extern _X_EXPORT ScrnInfoPtr xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, - int entityIndex, EntityProc init, - EntityProc enter, EntityProc leave, - pointer private); - -extern _X_EXPORT Bool xf86IsScreenPrimary(int scrnIndex); -extern _X_EXPORT int xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, - int format, unsigned long len, - pointer value); -extern _X_EXPORT Bool xf86IsUnblank(int mode); +extern _X_EXPORT void +xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, + const char *format, va_list args) +_X_ATTRIBUTE_PRINTF(4, 0); +extern _X_EXPORT void +xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, + const char *format, ...) +_X_ATTRIBUTE_PRINTF(4, 5); +extern _X_EXPORT void +xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) +_X_ATTRIBUTE_PRINTF(3, 4); +extern _X_EXPORT void +xf86MsgVerb(MessageType type, int verb, const char *format, ...) +_X_ATTRIBUTE_PRINTF(3, 4); +extern _X_EXPORT void +xf86Msg(MessageType type, const char *format, ...) +_X_ATTRIBUTE_PRINTF(2, 3); +extern _X_EXPORT void +xf86ErrorFVerb(int verb, const char *format, ...) +_X_ATTRIBUTE_PRINTF(2, 3); +extern _X_EXPORT void +xf86ErrorF(const char *format, ...) +_X_ATTRIBUTE_PRINTF(1, 2); +extern _X_EXPORT const char * +xf86TokenToString(SymTabPtr table, int token); +extern _X_EXPORT int +xf86StringToToken(SymTabPtr table, const char *string); +extern _X_EXPORT void +xf86ShowClocks(ScrnInfoPtr scrp, MessageType from); +extern _X_EXPORT void +xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips); +extern _X_EXPORT int +xf86MatchDevice(const char *drivername, GDevPtr ** driversectlist); +extern _X_EXPORT const char * +xf86GetVisualName(int visual); +extern _X_EXPORT int +xf86GetVerbosity(void); +extern _X_EXPORT Pix24Flags +xf86GetPix24(void); +extern _X_EXPORT int +xf86GetDepth(void); +extern _X_EXPORT rgb +xf86GetWeight(void); +extern _X_EXPORT Gamma +xf86GetGamma(void); +extern _X_EXPORT Bool +xf86GetFlipPixels(void); +extern _X_EXPORT const char * +xf86GetServerName(void); +extern _X_EXPORT Bool +xf86ServerIsExiting(void); +extern _X_EXPORT Bool +xf86ServerIsResetting(void); +extern _X_EXPORT Bool +xf86ServerIsInitialising(void); +extern _X_EXPORT Bool +xf86ServerIsOnlyDetecting(void); +extern _X_EXPORT Bool +xf86CaughtSignal(void); +extern _X_EXPORT Bool +xf86GetVidModeAllowNonLocal(void); +extern _X_EXPORT Bool +xf86GetVidModeEnabled(void); +extern _X_EXPORT Bool +xf86GetModInDevAllowNonLocal(void); +extern _X_EXPORT Bool +xf86GetModInDevEnabled(void); +extern _X_EXPORT Bool +xf86GetAllowMouseOpenFail(void); +extern _X_EXPORT void +xf86DisableRandR(void); +extern _X_EXPORT CARD32 +xorgGetVersion(void); +extern _X_EXPORT CARD32 +xf86GetModuleVersion(pointer module); +extern _X_EXPORT pointer +xf86LoadDrvSubModule(DriverPtr drv, const char *name); +extern _X_EXPORT pointer +xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name); +extern _X_EXPORT pointer +xf86LoadOneModule(char *name, pointer optlist); +extern _X_EXPORT void +xf86UnloadSubModule(pointer mod); +extern _X_EXPORT Bool +xf86LoaderCheckSymbol(const char *name); +extern _X_EXPORT void +xf86SetBackingStore(ScreenPtr pScreen); +extern _X_EXPORT void +xf86SetSilkenMouse(ScreenPtr pScreen); +extern _X_EXPORT pointer +xf86FindXvOptions(int scrnIndex, int adapt_index, char *port_name, + char **adaptor_name, pointer *adaptor_options); +extern _X_EXPORT void +xf86GetOS(const char **name, int *major, int *minor, int *teeny); +extern _X_EXPORT ScrnInfoPtr +xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, + int entityIndex, EntityProc init, + EntityProc enter, EntityProc leave, pointer private); + +extern _X_EXPORT Bool +xf86IsScreenPrimary(int scrnIndex); +extern _X_EXPORT int +xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, + int format, unsigned long len, pointer value); +extern _X_EXPORT Bool +xf86IsUnblank(int mode); /* xf86Init.c */ -extern _X_EXPORT PixmapFormatPtr xf86GetPixFormat(ScrnInfoPtr pScrn, int depth); -extern _X_EXPORT int xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth); +extern _X_EXPORT PixmapFormatPtr +xf86GetPixFormat(ScrnInfoPtr pScrn, int depth); +extern _X_EXPORT int +xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth); /* xf86Mode.c */ -extern _X_EXPORT int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, - int DivFactor, int MulFactor, int *divider); -extern _X_EXPORT const char *xf86ModeStatusToString(ModeStatus status); -extern _X_EXPORT ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, - ClockRangePtr clockRanges, LookupModeFlags strategy); -extern _X_EXPORT ModeStatus xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor); -extern _X_EXPORT ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, - ClockRangePtr clockRanges, - LookupModeFlags strategy, - int maxPitch, int virtualX, - int virtualY); -extern _X_EXPORT ModeStatus xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, - int flags); -extern _X_EXPORT int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, - int minHeight, int maxHeight, int pitchInc, - int virtualX, int virtualY, int apertureSize, - LookupModeFlags strategy); -extern _X_EXPORT void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode); -extern _X_EXPORT void xf86PruneDriverModes(ScrnInfoPtr scrp); -extern _X_EXPORT void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags); -extern _X_EXPORT void xf86PrintModes(ScrnInfoPtr scrp); -extern _X_EXPORT void xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges); -extern _X_EXPORT double xf86ModeHSync(const DisplayModeRec *mode); -extern _X_EXPORT double xf86ModeVRefresh(const DisplayModeRec *mode); -extern _X_EXPORT void xf86SetModeDefaultName(DisplayModePtr mode); -extern _X_EXPORT void xf86SetModeCrtc(DisplayModePtr p, int adjustFlags); -extern _X_EXPORT DisplayModePtr xf86DuplicateMode(const DisplayModeRec *pMode); -extern _X_EXPORT DisplayModePtr xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList); -extern _X_EXPORT Bool xf86ModesEqual(const DisplayModeRec *pMode1, - const DisplayModeRec *pMode2); -extern _X_EXPORT void xf86PrintModeline(int scrnIndex,DisplayModePtr mode); -extern _X_EXPORT DisplayModePtr xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new); +extern _X_EXPORT int +xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, + int DivFactor, int MulFactor, int *divider); +extern _X_EXPORT const char * +xf86ModeStatusToString(ModeStatus status); +extern _X_EXPORT ModeStatus +xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, + ClockRangePtr clockRanges, LookupModeFlags strategy); +extern _X_EXPORT ModeStatus +xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor); +extern _X_EXPORT ModeStatus +xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, + ClockRangePtr clockRanges, + LookupModeFlags strategy, + int maxPitch, int virtualX, int virtualY); +extern _X_EXPORT ModeStatus +xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags); +extern _X_EXPORT int +xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, + char **modeNames, ClockRangePtr clockRanges, + int *linePitches, int minPitch, int maxPitch, + int minHeight, int maxHeight, int pitchInc, + int virtualX, int virtualY, int apertureSize, + LookupModeFlags strategy); +extern _X_EXPORT void +xf86DeleteMode(DisplayModePtr * modeList, DisplayModePtr mode); +extern _X_EXPORT void +xf86PruneDriverModes(ScrnInfoPtr scrp); +extern _X_EXPORT void +xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags); +extern _X_EXPORT void +xf86PrintModes(ScrnInfoPtr scrp); +extern _X_EXPORT void +xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges); +extern _X_EXPORT double +xf86ModeHSync(const DisplayModeRec * mode); +extern _X_EXPORT double +xf86ModeVRefresh(const DisplayModeRec * mode); +extern _X_EXPORT void +xf86SetModeDefaultName(DisplayModePtr mode); +extern _X_EXPORT void +xf86SetModeCrtc(DisplayModePtr p, int adjustFlags); +extern _X_EXPORT DisplayModePtr +xf86DuplicateMode(const DisplayModeRec * pMode); +extern _X_EXPORT DisplayModePtr +xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList); +extern _X_EXPORT Bool +xf86ModesEqual(const DisplayModeRec * pMode1, const DisplayModeRec * pMode2); +extern _X_EXPORT void +xf86PrintModeline(int scrnIndex, DisplayModePtr mode); +extern _X_EXPORT DisplayModePtr +xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new); /* xf86Option.c */ -extern _X_EXPORT void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts); - +extern _X_EXPORT void +xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts); /* xf86RandR.c */ #ifdef RANDR -extern _X_EXPORT Bool xf86RandRInit (ScreenPtr pScreen); -extern _X_EXPORT Rotation xf86GetRotation(ScreenPtr pScreen); -extern _X_EXPORT Bool xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen, - int newvirtX, int newvirtY, - int newmmWidth, int newmmHeight, Bool resetMode); +extern _X_EXPORT Bool +xf86RandRInit(ScreenPtr pScreen); +extern _X_EXPORT Rotation +xf86GetRotation(ScreenPtr pScreen); +extern _X_EXPORT Bool +xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen, + int newvirtX, int newvirtY, + int newmmWidth, int newmmHeight, + Bool resetMode); #endif /* xf86VidModeExtentionInit.c */ -extern _X_EXPORT Bool VidModeExtensionInit(ScreenPtr pScreen); +extern _X_EXPORT Bool +VidModeExtensionInit(ScreenPtr pScreen); -#endif /* _NO_XF86_PROTOTYPES */ +#endif /* _NO_XF86_PROTOTYPES */ -#endif /* _XF86_H */ +#endif /* _XF86_H */ diff --git a/xorg-server/hw/xfree86/common/xf86AutoConfig.c b/xorg-server/hw/xfree86/common/xf86AutoConfig.c index 0c465682a..43c746b7f 100644 --- a/xorg-server/hw/xfree86/common/xf86AutoConfig.c +++ b/xorg-server/hw/xfree86/common/xf86AutoConfig.c @@ -41,12 +41,12 @@ #include "xf86_OSlib.h" #include "xf86pciBus.h" #ifdef __sparc__ -# include "xf86sbusBus.h" +#include "xf86sbusBus.h" #endif #ifdef sun -# include <sys/visual_io.h> -# include <ctype.h> +#include <sys/visual_io.h> +#include <ctype.h> #endif /* Sections for the default built-in configuration. */ @@ -103,13 +103,13 @@ AppendToList(const char *s, const char ***list, int *lines) str = xnfstrdup(s); for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) { - (*lines)++; - *list = xnfrealloc(*list, (*lines + 1) * sizeof(**list)); - newstr = xnfalloc(strlen(p) + 2); - strcpy(newstr, p); - strcat(newstr, "\n"); - (*list)[*lines - 1] = newstr; - (*list)[*lines] = NULL; + (*lines)++; + *list = xnfrealloc(*list, (*lines + 1) * sizeof(**list)); + newstr = xnfalloc(strlen(p) + 2); + strcpy(newstr, p); + strcat(newstr, "\n"); + (*list)[*lines - 1] = newstr; + (*list)[*lines] = NULL; } free(str); } @@ -120,7 +120,7 @@ FreeList(const char ***list, int *lines) int i; for (i = 0; i < *lines; i++) { - free((char *)((*list)[i])); + free((char *) ((*list)[i])); } free(*list); *list = NULL; @@ -151,30 +151,30 @@ xf86AutoConfig(void) listPossibleVideoDrivers(deviceList, 20); for (p = deviceList; *p; p++) { - snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p); - AppendToConfig(buf); - snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0); - AppendToConfig(buf); + snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p); + AppendToConfig(buf); + snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0); + AppendToConfig(buf); } AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE); for (p = deviceList; *p; p++) { - snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, *p, 0); - AppendToConfig(buf); + snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, *p, 0); + AppendToConfig(buf); } AppendToConfig(BUILTIN_LAYOUT_SECTION_POST); for (p = deviceList; *p; p++) { - free(*p); + free(*p); } xf86MsgVerb(X_DEFAULT, 0, - "Using default built-in configuration (%d lines)\n", - builtinLines); + "Using default built-in configuration (%d lines)\n", + builtinLines); xf86MsgVerb(X_DEFAULT, 3, "--- Start of built-in configuration ---\n"); for (cp = builtinConfig; *cp; cp++) - xf86ErrorFVerb(3, "\t%s", *cp); + xf86ErrorFVerb(3, "\t%s", *cp); xf86MsgVerb(X_DEFAULT, 3, "--- End of built-in configuration ---\n"); xf86initConfigFiles(); @@ -183,7 +183,7 @@ xf86AutoConfig(void) FreeConfig(); if (ret != CONFIG_OK) - xf86Msg(X_ERROR, "Error parsing the built-in default configuration.\n"); + xf86Msg(X_ERROR, "Error parsing the built-in default configuration.\n"); return ret == CONFIG_OK; } @@ -192,8 +192,8 @@ static void listPossibleVideoDrivers(char *matches[], int nmatches) { int i; - - for (i = 0 ; i < nmatches ; i++) { + + for (i = 0; i < nmatches; i++) { matches[i] = NULL; } i = 0; @@ -202,57 +202,60 @@ listPossibleVideoDrivers(char *matches[], int nmatches) /* Check for driver type based on /dev/fb type and if valid, use it instead of PCI bus probe results */ if (xf86Info.consoleFd >= 0) { - struct vis_identifier visid; - const char *cp; - extern char xf86SolarisFbDev[PATH_MAX]; - int iret; - - SYSCALL(iret = ioctl(xf86Info.consoleFd, VIS_GETIDENTIFIER, &visid)); - if (iret < 0) { - int fbfd; - - fbfd = open(xf86SolarisFbDev, O_RDONLY); - if (fbfd >= 0) { - SYSCALL(iret = ioctl(fbfd, VIS_GETIDENTIFIER, &visid)); - close(fbfd); - } - } - - if (iret < 0) { - xf86Msg(X_WARNING, - "could not get frame buffer identifier from %s\n", - xf86SolarisFbDev); - } else { - xf86Msg(X_PROBED, "console driver: %s\n", visid.name); - - /* Special case from before the general case was set */ - if (strcmp(visid.name, "NVDAnvda") == 0) { - matches[i++] = xnfstrdup("nvidia"); - } - - /* General case - split into vendor name (initial all-caps - prefix) & driver name (rest of the string). */ - if (strcmp(visid.name, "SUNWtext") != 0) { - for (cp = visid.name; (*cp != '\0') && isupper(*cp); cp++) { - /* find end of all uppercase vendor section */ - } - if ((cp != visid.name) && (*cp != '\0')) { - char *driverName = xnfstrdup(cp); - char *vendorName = xnfstrdup(visid.name); - vendorName[cp - visid.name] = '\0'; - - matches[i++] = vendorName; - matches[i++] = driverName; - } - } - } + struct vis_identifier visid; + const char *cp; + extern char xf86SolarisFbDev[PATH_MAX]; + int iret; + + SYSCALL(iret = ioctl(xf86Info.consoleFd, VIS_GETIDENTIFIER, &visid)); + if (iret < 0) { + int fbfd; + + fbfd = open(xf86SolarisFbDev, O_RDONLY); + if (fbfd >= 0) { + SYSCALL(iret = ioctl(fbfd, VIS_GETIDENTIFIER, &visid)); + close(fbfd); + } + } + + if (iret < 0) { + xf86Msg(X_WARNING, + "could not get frame buffer identifier from %s\n", + xf86SolarisFbDev); + } + else { + xf86Msg(X_PROBED, "console driver: %s\n", visid.name); + + /* Special case from before the general case was set */ + if (strcmp(visid.name, "NVDAnvda") == 0) { + matches[i++] = xnfstrdup("nvidia"); + } + + /* General case - split into vendor name (initial all-caps + prefix) & driver name (rest of the string). */ + if (strcmp(visid.name, "SUNWtext") != 0) { + for (cp = visid.name; (*cp != '\0') && isupper(*cp); cp++) { + /* find end of all uppercase vendor section */ + } + if ((cp != visid.name) && (*cp != '\0')) { + char *driverName = xnfstrdup(cp); + char *vendorName = xnfstrdup(visid.name); + + vendorName[cp - visid.name] = '\0'; + + matches[i++] = vendorName; + matches[i++] = driverName; + } + } + } } #endif #ifdef __sparc__ { - char *sbusDriver = sparcDriverName(); - if (sbusDriver) - matches[i++] = xnfstrdup(sbusDriver); + char *sbusDriver = sparcDriverName(); + + if (sbusDriver) + matches[i++] = xnfstrdup(sbusDriver); } #endif #ifdef XSERVER_LIBPCIACCESS @@ -261,9 +264,9 @@ listPossibleVideoDrivers(char *matches[], int nmatches) /* Fallback to platform default hardware */ if (i < (nmatches - 1)) { #if defined(__i386__) || defined(__amd64__) || defined(__hurd__) - matches[i++] = xnfstrdup("vesa"); + matches[i++] = xnfstrdup("vesa"); #elif defined(__sparc__) && !defined(sun) - matches[i++] = xnfstrdup("sunffb"); + matches[i++] = xnfstrdup("sunffb"); #endif } @@ -271,12 +274,12 @@ listPossibleVideoDrivers(char *matches[], int nmatches) /* Fallback to platform default frame buffer driver */ if (i < (nmatches - 1)) { #if !defined(__linux__) && defined(__sparc__) - matches[i++] = xnfstrdup("wsfb"); + matches[i++] = xnfstrdup("wsfb"); #else - matches[i++] = xnfstrdup("fbdev"); + matches[i++] = xnfstrdup("fbdev"); #endif } -#endif /* !sun */ +#endif /* !sun */ } /* copy a screen section and enter the desired driver @@ -320,7 +323,7 @@ GDevPtr autoConfigDevice(GDevPtr preconf_device) { GDevPtr ptr = NULL; - char *matches[20]; /* If we have more than 20 drivers we're in trouble */ + char *matches[20]; /* If we have more than 20 drivers we're in trouble */ int num_matches = 0, num_screens = 0, i; screenLayoutPtr slp; @@ -331,7 +334,8 @@ autoConfigDevice(GDevPtr preconf_device) /* If there's a configured section with no driver chosen, use it */ if (preconf_device) { ptr = preconf_device; - } else { + } + else { ptr = calloc(1, sizeof(GDevRec)); if (!ptr) { return NULL; @@ -361,7 +365,7 @@ autoConfigDevice(GDevPtr preconf_device) * plus one for the terminating NULL */ for (; slp[num_screens].screen; num_screens++); xf86ConfigLayout.screens = xnfcalloc(num_screens + num_matches, - sizeof(screenLayoutRec)); + sizeof(screenLayoutRec)); xf86ConfigLayout.screens[0] = slp[0]; /* do the first match and set that for the original first screen */ @@ -384,14 +388,16 @@ autoConfigDevice(GDevPtr preconf_device) * * TODO Handle rest of multiple screen sections */ for (i = 1; i < num_screens; i++) { - xf86ConfigLayout.screens[i+num_matches] = slp[i]; + xf86ConfigLayout.screens[i + num_matches] = slp[i]; } - xf86ConfigLayout.screens[num_screens+num_matches-1].screen = NULL; + xf86ConfigLayout.screens[num_screens + num_matches - 1].screen = + NULL; free(slp); - } else { + } + else { /* layout does not have any screens, not much to do */ ptr->driver = matches[0]; - for (i = 1; matches[i] ; i++) { + for (i = 1; matches[i]; i++) { if (matches[i] != matches[0]) { free(matches[i]); } diff --git a/xorg-server/hw/xfree86/common/xf86Bus.c b/xorg-server/hw/xfree86/common/xf86Bus.c index c665a2019..b176e8cc4 100644 --- a/xorg-server/hw/xfree86/common/xf86Bus.c +++ b/xorg-server/hw/xfree86/common/xf86Bus.c @@ -51,11 +51,11 @@ #include "xf86VGAarbiter.h" #endif /* Entity data */ -EntityPtr *xf86Entities = NULL; /* Bus slots claimed by drivers */ +EntityPtr *xf86Entities = NULL; /* Bus slots claimed by drivers */ int xf86NumEntities = 0; static int xf86EntityPrivateCount = 0; -BusRec primaryBus = { BUS_NONE, { 0 } }; +BusRec primaryBus = { BUS_NONE, {0} }; /** * Call the driver's correct probe function. @@ -73,9 +73,10 @@ BusRec primaryBus = { BUS_NONE, { 0 } }; * returned. Otherwise, \c FALSE is returned. */ Bool -xf86CallDriverProbe( DriverPtr drv, Bool detect_only ) +xf86CallDriverProbe(DriverPtr drv, Bool detect_only) { - Bool foundScreen = FALSE; + Bool foundScreen = FALSE; + #ifdef XSERVER_LIBPCIACCESS if (drv->PciProbe != NULL) { if (xf86DoConfigure && xf86DoConfigurePass1) { @@ -83,16 +84,16 @@ xf86CallDriverProbe( DriverPtr drv, Bool detect_only ) foundScreen = xf86PciAddMatchingDev(drv); } else { - assert(! detect_only); + assert(!detect_only); foundScreen = xf86PciProbeDev(drv); } } #endif if (!foundScreen && (drv->Probe != NULL)) { - xf86Msg( X_WARNING, "Falling back to old probe method for %s\n", - drv->driverName); - foundScreen = (*drv->Probe)(drv, (detect_only) ? PROBE_DETECT - : PROBE_DEFAULT); + xf86Msg(X_WARNING, "Falling back to old probe method for %s\n", + drv->driverName); + foundScreen = (*drv->Probe) (drv, (detect_only) ? PROBE_DETECT + : PROBE_DEFAULT); } return foundScreen; @@ -119,13 +120,14 @@ xf86BusConfig(void) */ for (i = 0; i < xf86NumDrivers; i++) { xorgHWFlags flags; + if (!xorgHWAccess) { if (!xf86DriverList[i]->driverFunc - || !xf86DriverList[i]->driverFunc(NULL, - GET_REQUIRED_HW_INTERFACES, - &flags) - || NEED_IO_ENABLED(flags)) - continue; + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) + continue; } xf86CallDriverProbe(xf86DriverList[i], FALSE); @@ -155,11 +157,13 @@ xf86BusConfig(void) for (layout = xf86ConfigLayout.screens; layout->screen != NULL; layout++) { Bool found = FALSE; + for (j = 0; j < xf86Screens[i]->numEntities; j++) { - GDevPtr dev = xf86GetDevFromEntity( - xf86Screens[i]->entityList[j], - xf86Screens[i]->entityInstanceList[j]); + GDevPtr dev = + xf86GetDevFromEntity(xf86Screens[i]->entityList[j], + xf86Screens[i]->entityInstanceList[j]); + if (dev == layout->screen->device) { /* A match has been found */ xf86Screens[i]->confScreen = layout->screen; @@ -167,12 +171,14 @@ xf86BusConfig(void) break; } } - if (found) break; + if (found) + break; } if (layout->screen == NULL) { /* No match found */ xf86Msg(X_ERROR, - "Screen %d deleted because of no matching config section.\n", i); + "Screen %d deleted because of no matching config section.\n", + i); xf86DeleteScreen(i--, 0); } } @@ -180,7 +186,7 @@ xf86BusConfig(void) /* If no screens left, return now. */ if (xf86NumScreens == 0) { xf86Msg(X_ERROR, - "Device(s) detected, but none match those in the config file.\n"); + "Device(s) detected, but none match those in the config file.\n"); return FALSE; } @@ -210,31 +216,31 @@ xf86BusProbe(void) */ BusType -StringToBusType(const char* busID, const char **retID) +StringToBusType(const char *busID, const char **retID) { char *p, *s; BusType ret = BUS_NONE; /* If no type field, Default to PCI */ if (isdigit(busID[0])) { - if (retID) - *retID = busID; - return BUS_PCI; + if (retID) + *retID = busID; + return BUS_PCI; } s = xstrdup(busID); p = strtok(s, ":"); if (p == NULL || *p == 0) { - free(s); - return BUS_NONE; + free(s); + return BUS_NONE; } if (!xf86NameCmp(p, "pci") || !xf86NameCmp(p, "agp")) - ret = BUS_PCI; + ret = BUS_PCI; if (!xf86NameCmp(p, "sbus")) - ret = BUS_SBUS; + ret = BUS_SBUS; if (ret != BUS_NONE) - if (retID) - *retID = busID + strlen(p) + 1; + if (retID) + *retID = busID + strlen(p) + 1; free(s); return ret; } @@ -244,10 +250,10 @@ xf86AllocateEntity(void) { xf86NumEntities++; xf86Entities = xnfrealloc(xf86Entities, - sizeof(EntityPtr) * xf86NumEntities); - xf86Entities[xf86NumEntities - 1] = xnfcalloc(1,sizeof(EntityRec)); + sizeof(EntityPtr) * xf86NumEntities); + xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec)); xf86Entities[xf86NumEntities - 1]->entityPrivates = - xnfcalloc(sizeof(DevUnion) * xf86EntityPrivateCount, 1); + xnfcalloc(sizeof(DevUnion) * xf86EntityPrivateCount, 1); return xf86NumEntities - 1; } @@ -255,25 +261,26 @@ Bool xf86IsEntityPrimary(int entityIndex) { EntityPtr pEnt = xf86Entities[entityIndex]; - - if (primaryBus.type != pEnt->bus.type) return FALSE; + + if (primaryBus.type != pEnt->bus.type) + return FALSE; switch (pEnt->bus.type) { case BUS_PCI: - return pEnt->bus.id.pci == primaryBus.id.pci; + return pEnt->bus.id.pci == primaryBus.id.pci; case BUS_SBUS: - return pEnt->bus.id.sbus.fbNum == primaryBus.id.sbus.fbNum; + return pEnt->bus.id.sbus.fbNum == primaryBus.id.sbus.fbNum; default: - return FALSE; + return FALSE; } } - + Bool xf86SetEntityFuncs(int entityIndex, EntityProc init, EntityProc enter, - EntityProc leave, pointer private) + EntityProc leave, pointer private) { if (entityIndex >= xf86NumEntities) - return FALSE; + return FALSE; xf86Entities[entityIndex]->entityInit = init; xf86Entities[entityIndex]->entityEnter = enter; xf86Entities[entityIndex]->entityLeave = leave; @@ -285,9 +292,10 @@ Bool xf86DriverHasEntities(DriverPtr drvp) { int i; + for (i = 0; i < xf86NumEntities; i++) { - if (xf86Entities[i]->driver == drvp) - return TRUE; + if (xf86Entities[i]->driver == drvp) + return TRUE; } return FALSE; } @@ -296,20 +304,20 @@ void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex) { if (entityIndex == -1) - return; + return; if (xf86Entities[entityIndex]->inUse && - !(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL)) { - ErrorF("Requested Entity already in use!\n"); - return; + !(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL)) { + ErrorF("Requested Entity already in use!\n"); + return; } pScrn->numEntities++; pScrn->entityList = xnfrealloc(pScrn->entityList, - pScrn->numEntities * sizeof(int)); + pScrn->numEntities * sizeof(int)); pScrn->entityList[pScrn->numEntities - 1] = entityIndex; xf86Entities[entityIndex]->inUse = TRUE; pScrn->entityInstanceList = xnfrealloc(pScrn->entityInstanceList, - pScrn->numEntities * sizeof(int)); + pScrn->numEntities * sizeof(int)); pScrn->entityInstanceList[pScrn->numEntities - 1] = 0; } @@ -319,13 +327,13 @@ xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, int instance) int i; if (entityIndex == -1 || entityIndex >= xf86NumEntities) - return; + return; for (i = 0; i < pScrn->numEntities; i++) { - if (pScrn->entityList[i] == entityIndex) { - pScrn->entityInstanceList[i] = instance; - break; - } + if (pScrn->entityList[i] == entityIndex) { + pScrn->entityInstanceList[i] = instance; + break; + } } } @@ -336,17 +344,18 @@ xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, int instance) ScrnInfoPtr xf86FindScreenForEntity(int entityIndex) { - int i,j; + int i, j; + + if (entityIndex == -1) + return NULL; - if (entityIndex == -1) return NULL; - if (xf86Screens) { - for (i = 0; i < xf86NumScreens; i++) { - for (j = 0; j < xf86Screens[i]->numEntities; j++) { - if ( xf86Screens[i]->entityList[j] == entityIndex ) - return xf86Screens[i]; - } - } + for (i = 0; i < xf86NumScreens; i++) { + for (j = 0; j < xf86Screens[i]->numEntities; j++) { + if (xf86Screens[i]->entityList[j] == entityIndex) + return xf86Screens[i]; + } + } } return NULL; } @@ -355,15 +364,15 @@ void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex) { int i; - + for (i = 0; i < pScrn->numEntities; i++) { - if (pScrn->entityList[i] == entityIndex) { - for (i++; i < pScrn->numEntities; i++) - pScrn->entityList[i-1] = pScrn->entityList[i]; - pScrn->numEntities--; - xf86Entities[entityIndex]->inUse = FALSE; - break; - } + if (pScrn->entityList[i] == entityIndex) { + for (i++; i < pScrn->numEntities; i++) + pScrn->entityList[i - 1] = pScrn->entityList[i]; + pScrn->numEntities--; + xf86Entities[entityIndex]->inUse = FALSE; + break; + } } } @@ -376,13 +385,14 @@ xf86ClearEntityListForScreen(int scrnIndex) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; int i, entityIndex; - - if (pScrn->entityList == NULL || pScrn->numEntities == 0) return; - + + if (pScrn->entityList == NULL || pScrn->numEntities == 0) + return; + for (i = 0; i < pScrn->numEntities; i++) { - entityIndex = pScrn->entityList[i]; - xf86Entities[entityIndex]->inUse = FALSE; - /* disable resource: call the disable function */ + entityIndex = pScrn->entityList[i]; + xf86Entities[entityIndex]->inUse = FALSE; + /* disable resource: call the disable function */ } free(pScrn->entityList); free(pScrn->entityInstanceList); @@ -398,14 +408,14 @@ void xf86AddDevToEntity(int entityIndex, GDevPtr dev) { EntityPtr pEnt; - + if (entityIndex >= xf86NumEntities) - return; - + return; + pEnt = xf86Entities[entityIndex]; pEnt->numInstances++; pEnt->devices = xnfrealloc(pEnt->devices, - pEnt->numInstances * sizeof(GDevPtr)); + pEnt->numInstances * sizeof(GDevPtr)); pEnt->devices[pEnt->numInstances - 1] = dev; dev->claimed = TRUE; } @@ -420,28 +430,29 @@ xf86GetEntityInfo(int entityIndex) { EntityInfoPtr pEnt; int i; - + if (entityIndex == -1) - return NULL; + return NULL; if (entityIndex >= xf86NumEntities) - return NULL; - - pEnt = xnfcalloc(1,sizeof(EntityInfoRec)); + return NULL; + + pEnt = xnfcalloc(1, sizeof(EntityInfoRec)); pEnt->index = entityIndex; pEnt->location = xf86Entities[entityIndex]->bus; pEnt->active = xf86Entities[entityIndex]->active; pEnt->chipset = xf86Entities[entityIndex]->chipset; pEnt->driver = xf86Entities[entityIndex]->driver; - if ( (xf86Entities[entityIndex]->devices) && - (xf86Entities[entityIndex]->devices[0]) ) { - for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++) - if (xf86Entities[entityIndex]->devices[i]->screen == 0) - break; - pEnt->device = xf86Entities[entityIndex]->devices[i]; - } else - pEnt->device = NULL; - + if ((xf86Entities[entityIndex]->devices) && + (xf86Entities[entityIndex]->devices[0])) { + for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++) + if (xf86Entities[entityIndex]->devices[i]->screen == 0) + break; + pEnt->device = xf86Entities[entityIndex]->devices[i]; + } + else + pEnt->device = NULL; + return pEnt; } @@ -449,8 +460,8 @@ int xf86GetNumEntityInstances(int entityIndex) { if (entityIndex >= xf86NumEntities) - return -1; - + return -1; + return xf86Entities[entityIndex]->numInstances; } @@ -458,19 +469,19 @@ GDevPtr xf86GetDevFromEntity(int entityIndex, int instance) { int i; - + /* We might not use AddDevtoEntity */ - if ( (!xf86Entities[entityIndex]->devices) || - (!xf86Entities[entityIndex]->devices[0]) ) - return NULL; + if ((!xf86Entities[entityIndex]->devices) || + (!xf86Entities[entityIndex]->devices[0])) + return NULL; if (entityIndex >= xf86NumEntities || - instance >= xf86Entities[entityIndex]->numInstances) - return NULL; - + instance >= xf86Entities[entityIndex]->numInstances) + return NULL; + for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++) - if (xf86Entities[entityIndex]->devices[i]->screen == instance) - break; + if (xf86Entities[entityIndex]->devices[i]->screen == instance) + break; return xf86Entities[entityIndex]->devices[i]; } @@ -485,7 +496,7 @@ xf86AccessEnter(void) for (i = 0; i < xf86NumEntities; i++) if (xf86Entities[i]->entityEnter) - xf86Entities[i]->entityEnter(i,xf86Entities[i]->private); + xf86Entities[i]->entityEnter(i, xf86Entities[i]->private); } void @@ -495,7 +506,7 @@ xf86AccessLeave(void) for (i = 0; i < xf86NumEntities; i++) if (xf86Entities[i]->entityLeave) - xf86Entities[i]->entityLeave(i,xf86Entities[i]->private); + xf86Entities[i]->entityLeave(i, xf86Entities[i]->private); } /* @@ -509,28 +520,29 @@ xf86PostProbe(void) if (fbSlotClaimed && ( #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - sbusSlotClaimed || + sbusSlotClaimed || #endif #ifdef XSERVER_LIBPCIACCESS - pciSlotClaimed + pciSlotClaimed #else - TRUE + TRUE #endif - )) - FatalError("Cannot run in framebuffer mode. Please specify busIDs " - " for all framebuffer devices\n"); + )) + FatalError("Cannot run in framebuffer mode. Please specify busIDs " + " for all framebuffer devices\n"); for (i = 0; i < xf86NumEntities; i++) if (xf86Entities[i]->entityInit) - xf86Entities[i]->entityInit(i,xf86Entities[i]->private); + xf86Entities[i]->entityInit(i, xf86Entities[i]->private); } int xf86GetLastScrnFlag(int entityIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { return xf86Entities[entityIndex]->lastScrnFlag; - } else { + } + else { return -1; } } @@ -538,7 +550,7 @@ xf86GetLastScrnFlag(int entityIndex) void xf86SetLastScrnFlag(int entityIndex, int scrnIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { xf86Entities[entityIndex]->lastScrnFlag = scrnIndex; } } @@ -546,10 +558,10 @@ xf86SetLastScrnFlag(int entityIndex, int scrnIndex) Bool xf86IsEntityShared(int entityIndex) { - if(entityIndex < xf86NumEntities) { - if(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL) { - return TRUE; - } + if (entityIndex < xf86NumEntities) { + if (xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL) { + return TRUE; + } } return FALSE; } @@ -557,7 +569,7 @@ xf86IsEntityShared(int entityIndex) void xf86SetEntityShared(int entityIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { xf86Entities[entityIndex]->entityProp |= IS_SHARED_ACCEL; } } @@ -565,10 +577,10 @@ xf86SetEntityShared(int entityIndex) Bool xf86IsEntitySharable(int entityIndex) { - if(entityIndex < xf86NumEntities) { - if(xf86Entities[entityIndex]->entityProp & ACCEL_IS_SHARABLE) { - return TRUE; - } + if (entityIndex < xf86NumEntities) { + if (xf86Entities[entityIndex]->entityProp & ACCEL_IS_SHARABLE) { + return TRUE; + } } return FALSE; } @@ -576,7 +588,7 @@ xf86IsEntitySharable(int entityIndex) void xf86SetEntitySharable(int entityIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { xf86Entities[entityIndex]->entityProp |= ACCEL_IS_SHARABLE; } } @@ -584,10 +596,10 @@ xf86SetEntitySharable(int entityIndex) Bool xf86IsPrimInitDone(int entityIndex) { - if(entityIndex < xf86NumEntities) { - if(xf86Entities[entityIndex]->entityProp & SA_PRIM_INIT_DONE) { - return TRUE; - } + if (entityIndex < xf86NumEntities) { + if (xf86Entities[entityIndex]->entityProp & SA_PRIM_INIT_DONE) { + return TRUE; + } } return FALSE; } @@ -595,7 +607,7 @@ xf86IsPrimInitDone(int entityIndex) void xf86SetPrimInitDone(int entityIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { xf86Entities[entityIndex]->entityProp |= SA_PRIM_INIT_DONE; } } @@ -603,12 +615,11 @@ xf86SetPrimInitDone(int entityIndex) void xf86ClearPrimInitDone(int entityIndex) { - if(entityIndex < xf86NumEntities) { + if (entityIndex < xf86NumEntities) { xf86Entities[entityIndex]->entityProp &= ~SA_PRIM_INIT_DONE; } } - /* * Allocate a private in the entities. */ @@ -622,12 +633,12 @@ xf86AllocateEntityPrivateIndex(void) idx = xf86EntityPrivateCount++; for (i = 0; i < xf86NumEntities; i++) { - pEnt = xf86Entities[i]; - nprivs = xnfrealloc(pEnt->entityPrivates, - xf86EntityPrivateCount * sizeof(DevUnion)); - /* Zero the new private */ - memset(&nprivs[idx], 0, sizeof(DevUnion)); - pEnt->entityPrivates = nprivs; + pEnt = xf86Entities[i]; + nprivs = xnfrealloc(pEnt->entityPrivates, + xf86EntityPrivateCount * sizeof(DevUnion)); + /* Zero the new private */ + memset(&nprivs[idx], 0, sizeof(DevUnion)); + pEnt->entityPrivates = nprivs; } return idx; } @@ -636,8 +647,7 @@ DevUnion * xf86GetEntityPrivate(int entityIndex, int privIndex) { if (entityIndex >= xf86NumEntities || privIndex >= xf86EntityPrivateCount) - return NULL; + return NULL; return &(xf86Entities[entityIndex]->entityPrivates[privIndex]); } - diff --git a/xorg-server/hw/xfree86/common/xf86Config.c b/xorg-server/hw/xfree86/common/xf86Config.c index f51be7e9c..ec679df16 100644 --- a/xorg-server/hw/xfree86/common/xf86Config.c +++ b/xorg-server/hw/xfree86/common/xf86Config.c @@ -109,36 +109,36 @@ #endif static ModuleDefault ModuleDefaults[] = { - {.name = "extmod", .toLoad = TRUE, .load_opt=NULL}, + {.name = "extmod",.toLoad = TRUE,.load_opt = NULL}, #ifdef DBE - {.name = "dbe", .toLoad = TRUE, .load_opt=NULL}, + {.name = "dbe",.toLoad = TRUE,.load_opt = NULL}, #endif #ifdef GLXEXT - {.name = "glx", .toLoad = TRUE, .load_opt=NULL}, + {.name = "glx",.toLoad = TRUE,.load_opt = NULL}, #endif #ifdef XRECORD - {.name = "record", .toLoad = TRUE, .load_opt=NULL}, + {.name = "record",.toLoad = TRUE,.load_opt = NULL}, #endif #ifdef XF86DRI - {.name = "dri", .toLoad = TRUE, .load_opt=NULL}, + {.name = "dri",.toLoad = TRUE,.load_opt = NULL}, #endif #ifdef DRI2 - {.name = "dri2", .toLoad = TRUE, .load_opt=NULL}, + {.name = "dri2",.toLoad = TRUE,.load_opt = NULL}, #endif - {.name = NULL, .toLoad = FALSE, .load_opt=NULL} + {.name = NULL,.toLoad = FALSE,.load_opt = NULL} }; - /* Forward declarations */ static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, - int scrnum, MessageType from); + int scrnum, MessageType from); static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor); static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, - Bool active); + Bool active); static Bool configInput(InputInfoPtr pInfo, XF86ConfInputPtr conf_input, - MessageType from); + MessageType from); static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display); static Bool addDefaultModes(MonPtr monitorp); + #ifdef XF86DRI static void configDRI(XF86ConfDRIPtr drip); #endif @@ -154,15 +154,15 @@ static void configExtensions(XF86ConfExtensionsPtr conf_ext); static char * xf86GetPathElem(char **pnt) { - char *p1; - - p1 = *pnt; - *pnt = index(*pnt, ','); - if (*pnt != NULL) { - **pnt = '\0'; - *pnt += 1; - } - return p1; + char *p1; + + p1 = *pnt; + *pnt = index(*pnt, ','); + if (*pnt != NULL) { + **pnt = '\0'; + *pnt += 1; + } + return p1; } /* @@ -178,67 +178,67 @@ xf86GetPathElem(char **pnt) static char * xf86ValidateFontPath(char *path) { - char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem; - struct stat stat_buf; - int flag; - int dirlen; - - tmp_path = calloc(1,strlen(path)+1); - out_pnt = tmp_path; - path_elem = NULL; - next = path; - while (next != NULL) { - path_elem = xf86GetPathElem(&next); - if (*path_elem == '/') { - dir_elem = xnfcalloc(1, strlen(path_elem) + 1); - if ((p1 = strchr(path_elem, ':')) != 0) - dirlen = p1 - path_elem; - else - dirlen = strlen(path_elem); - strlcpy(dir_elem, path_elem, dirlen + 1); - flag = stat(dir_elem, &stat_buf); - if (flag == 0) - if (!S_ISDIR(stat_buf.st_mode)) - flag = -1; - if (flag != 0) { - xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", dir_elem); - xf86ErrorF("\tEntry deleted from font path.\n"); - free(dir_elem); - continue; - } - else { - XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE); - flag = stat(p1, &stat_buf); - if (flag == 0) - if (!S_ISREG(stat_buf.st_mode)) - flag = -1; - free(p1); - if (flag != 0) { - xf86Msg(X_WARNING, - "`fonts.dir' not found (or not valid) in \"%s\".\n", - dir_elem); - xf86ErrorF("\tEntry deleted from font path.\n"); - xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem); - free(dir_elem); - continue; - } - } - free(dir_elem); - } + char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem; + struct stat stat_buf; + int flag; + int dirlen; + + tmp_path = calloc(1, strlen(path) + 1); + out_pnt = tmp_path; + path_elem = NULL; + next = path; + while (next != NULL) { + path_elem = xf86GetPathElem(&next); + if (*path_elem == '/') { + dir_elem = xnfcalloc(1, strlen(path_elem) + 1); + if ((p1 = strchr(path_elem, ':')) != 0) + dirlen = p1 - path_elem; + else + dirlen = strlen(path_elem); + strlcpy(dir_elem, path_elem, dirlen + 1); + flag = stat(dir_elem, &stat_buf); + if (flag == 0) + if (!S_ISDIR(stat_buf.st_mode)) + flag = -1; + if (flag != 0) { + xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", + dir_elem); + xf86ErrorF("\tEntry deleted from font path.\n"); + free(dir_elem); + continue; + } + else { + XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE); + flag = stat(p1, &stat_buf); + if (flag == 0) + if (!S_ISREG(stat_buf.st_mode)) + flag = -1; + free(p1); + if (flag != 0) { + xf86Msg(X_WARNING, + "`fonts.dir' not found (or not valid) in \"%s\".\n", + dir_elem); + xf86ErrorF("\tEntry deleted from font path.\n"); + xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem); + free(dir_elem); + continue; + } + } + free(dir_elem); + } - /* - * Either an OK directory, or a font server name. So add it to - * the path. - */ - if (out_pnt != tmp_path) - *out_pnt++ = ','; - strcat(out_pnt, path_elem); - out_pnt += strlen(path_elem); - } - return tmp_path; + /* + * Either an OK directory, or a font server name. So add it to + * the path. + */ + if (out_pnt != tmp_path) + *out_pnt++ = ','; + strcat(out_pnt, path_elem); + out_pnt += strlen(path_elem); + } + return tmp_path; } - /* * use the datastructure that the parser provides and pick out the parts * that we need at this point @@ -248,13 +248,15 @@ xf86ModulelistFromConfig(pointer **optlist) { int count = 0, i = 0; char **modulearray; + const char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", - "freetype", "type1", - NULL }; + "freetype", "type1", + NULL + }; pointer *optarray; XF86LoadPtr modp; Bool found; - + /* * make sure the config file has been parsed and that we have a * ModulePath set; if no ModulePath was given, use the default @@ -264,15 +266,17 @@ xf86ModulelistFromConfig(pointer **optlist) xf86Msg(X_ERROR, "Cannot access global config data structure\n"); return NULL; } - + if (xf86configptr->conf_modules) { /* Walk the disable list and let people know what we've parsed to * not be loaded */ modp = xf86configptr->conf_modules->mod_disable_lst; while (modp) { - xf86Msg(X_WARNING, "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n", modp->load_name); - modp = (XF86LoadPtr) modp->list.next; + xf86Msg(X_WARNING, + "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n", + modp->load_name); + modp = (XF86LoadPtr) modp->list.next; } /* * Walk the default settings table. For each module listed to be @@ -280,90 +284,103 @@ xf86ModulelistFromConfig(pointer **optlist) * sure it's not in the mod_no_load_lst. If it's not disabled, * append it to mod_load_lst */ - for (i=0 ; ModuleDefaults[i].name != NULL ; i++) { + for (i = 0; ModuleDefaults[i].name != NULL; i++) { if (ModuleDefaults[i].toLoad == FALSE) { - xf86Msg(X_WARNING, "\"%s\" is not to be loaded by default. Skipping.\n", ModuleDefaults[i].name); + xf86Msg(X_WARNING, + "\"%s\" is not to be loaded by default. Skipping.\n", + ModuleDefaults[i].name); continue; } found = FALSE; modp = xf86configptr->conf_modules->mod_load_lst; while (modp) { if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) { - xf86Msg(X_INFO, "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n", ModuleDefaults[i].name); + xf86Msg(X_INFO, + "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n", + ModuleDefaults[i].name); found = TRUE; break; } - modp = (XF86LoadPtr) modp->list.next; + modp = (XF86LoadPtr) modp->list.next; } if (found == FALSE) { modp = xf86configptr->conf_modules->mod_disable_lst; while (modp) { if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) { - xf86Msg(X_INFO, "\"%s\" will be loaded even though the default is to disable it.\n", ModuleDefaults[i].name); + xf86Msg(X_INFO, + "\"%s\" will be loaded even though the default is to disable it.\n", + ModuleDefaults[i].name); found = TRUE; break; } - modp = (XF86LoadPtr) modp->list.next; + modp = (XF86LoadPtr) modp->list.next; } } if (found == FALSE) { - XF86LoadPtr ptr = (XF86LoadPtr)xf86configptr->conf_modules; - xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt); - xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n", ModuleDefaults[i].name); + XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules; + + xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, + XF86_LOAD_MODULE, + ModuleDefaults[i].load_opt); + xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n", + ModuleDefaults[i].name); } - } - } else { - xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec)); - for (i=0 ; ModuleDefaults[i].name != NULL ; i++) { - if (ModuleDefaults[i].toLoad == TRUE) { - XF86LoadPtr ptr = (XF86LoadPtr)xf86configptr->conf_modules; - xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt); - } - } - } - - /* - * Walk the list of modules in the "Module" section to determine how - * many we have. - */ - modp = xf86configptr->conf_modules->mod_load_lst; - while (modp) { - for (i = 0; ignore[i]; i++) { - if (strcmp(modp->load_name, ignore[i]) == 0) - modp->ignore = 1; - } - if (!modp->ignore) - count++; - modp = (XF86LoadPtr) modp->list.next; - } + } + } + else { + xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec)); + for (i = 0; ModuleDefaults[i].name != NULL; i++) { + if (ModuleDefaults[i].toLoad == TRUE) { + XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules; + + xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, + XF86_LOAD_MODULE, + ModuleDefaults[i].load_opt); + } + } + } + + /* + * Walk the list of modules in the "Module" section to determine how + * many we have. + */ + modp = xf86configptr->conf_modules->mod_load_lst; + while (modp) { + for (i = 0; ignore[i]; i++) { + if (strcmp(modp->load_name, ignore[i]) == 0) + modp->ignore = 1; + } + if (!modp->ignore) + count++; + modp = (XF86LoadPtr) modp->list.next; + } /* * allocate the memory and walk the list again to fill in the pointers */ - modulearray = xnfalloc((count + 1) * sizeof(char*)); + modulearray = xnfalloc((count + 1) * sizeof(char *)); optarray = xnfalloc((count + 1) * sizeof(pointer)); count = 0; if (xf86configptr->conf_modules) { - modp = xf86configptr->conf_modules->mod_load_lst; - while (modp) { + modp = xf86configptr->conf_modules->mod_load_lst; + while (modp) { if (!modp->ignore) { - modulearray[count] = modp->load_name; - optarray[count] = modp->load_opt; - count++; + modulearray[count] = modp->load_name; + optarray[count] = modp->load_opt; + count++; } - modp = (XF86LoadPtr) modp->list.next; - } + modp = (XF86LoadPtr) modp->list.next; + } } modulearray[count] = NULL; optarray[count] = NULL; if (optlist) - *optlist = optarray; + *optlist = optarray; else - free(optarray); + free(optarray); return modulearray; } - char ** xf86DriverlistFromConfig(void) { @@ -371,7 +388,7 @@ xf86DriverlistFromConfig(void) int j; char **modulearray; screenLayoutPtr slp; - + /* * make sure the config file has been parsed and that we have a * ModulePath set; if no ModulePath was given, use the default @@ -381,7 +398,7 @@ xf86DriverlistFromConfig(void) xf86Msg(X_ERROR, "Cannot access global config data structure\n"); return NULL; } - + /* * Walk the list of driver lines in active "Device" sections to * determine now many implicitly loaded modules there are. @@ -390,7 +407,7 @@ xf86DriverlistFromConfig(void) if (xf86ConfigLayout.screens) { slp = xf86ConfigLayout.screens; while ((slp++)->screen) { - count++; + count++; } } @@ -399,39 +416,39 @@ xf86DriverlistFromConfig(void) */ j = 0; while (xf86ConfigLayout.inactives[j++].identifier) - count++; + count++; if (count == 0) - return NULL; + return NULL; /* * allocate the memory and walk the list again to fill in the pointers */ - modulearray = xnfalloc((count + 1) * sizeof(char*)); + modulearray = xnfalloc((count + 1) * sizeof(char *)); count = 0; slp = xf86ConfigLayout.screens; while (slp->screen) { - modulearray[count] = slp->screen->device->driver; - count++; - slp++; + modulearray[count] = slp->screen->device->driver; + count++; + slp++; } j = 0; - while (xf86ConfigLayout.inactives[j].identifier) - modulearray[count++] = xf86ConfigLayout.inactives[j++].driver; + while (xf86ConfigLayout.inactives[j].identifier) + modulearray[count++] = xf86ConfigLayout.inactives[j++].driver; modulearray[count] = NULL; /* Remove duplicates */ for (count = 0; modulearray[count] != NULL; count++) { - int i; + int i; - for (i = 0; i < count; i++) - if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { - modulearray[count] = ""; - break; - } + for (i = 0; i < count; i++) + if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { + modulearray[count] = ""; + break; + } } return modulearray; } @@ -452,7 +469,7 @@ xf86InputDriverlistFromConfig(void) xf86Msg(X_ERROR, "Cannot access global config data structure\n"); return NULL; } - + /* * Walk the list of driver lines in active "InputDevice" sections to * determine now many implicitly loaded modules there are. @@ -460,36 +477,36 @@ xf86InputDriverlistFromConfig(void) if (xf86ConfigLayout.inputs) { idp = xf86ConfigLayout.inputs; while (*idp) { - count++; - idp++; + count++; + idp++; } } if (count == 0) - return NULL; + return NULL; /* * allocate the memory and walk the list again to fill in the pointers */ - modulearray = xnfalloc((count + 1) * sizeof(char*)); + modulearray = xnfalloc((count + 1) * sizeof(char *)); count = 0; idp = xf86ConfigLayout.inputs; while (idp && *idp) { modulearray[count] = (*idp)->driver; - count++; - idp++; + count++; + idp++; } modulearray[count] = NULL; /* Remove duplicates */ for (count = 0; modulearray[count] != NULL; count++) { - int i; + int i; - for (i = 0; i < count; i++) - if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { - modulearray[count] = ""; - break; - } + for (i = 0; i < count; i++) + if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { + modulearray[count] = ""; + break; + } } return modulearray; } @@ -503,7 +520,7 @@ fixup_video_driver_list(char **drivers) int i; /* walk to the end of the list */ - for (end = drivers; *end && **end; end++) ; + for (end = drivers; *end && **end; end++); end--; /* @@ -513,7 +530,9 @@ fixup_video_driver_list(char **drivers) for (i = 0; fallback[i]; i++) { for (drv = drivers; drv != end; drv++) { if (strstr(*drv, fallback[i])) { - x = *drv; *drv = *end; *end = x; + x = *drv; + *drv = *end; + *end = x; end--; break; } @@ -522,13 +541,13 @@ fixup_video_driver_list(char **drivers) } static char ** -GenerateDriverlist(const char * dirname) +GenerateDriverlist(const char *dirname) { char **ret; const char *subdirs[] = { dirname, NULL }; - static const char *patlist[] = {"(.*)_drv\\.so", NULL}; + static const char *patlist[] = { "(.*)_drv\\.so", NULL }; ret = LoaderListDirs(subdirs, patlist); - + /* fix up the probe order for video drivers */ if (strstr(dirname, "drivers") && ret != NULL) fixup_video_driver_list(ret); @@ -552,7 +571,8 @@ xf86DriverlistFromCompile(void) * Print a READABLE ErrorMessage!!! All information that is * available is printed. */ -static void _X_ATTRIBUTE_PRINTF(1,2) +static void +_X_ATTRIBUTE_PRINTF(1, 2) xf86ConfigError(const char *msg, ...) { va_list ap; @@ -568,31 +588,31 @@ xf86ConfigError(const char *msg, ...) static void configFiles(XF86ConfFilesPtr fileconf) { - MessageType pathFrom; - Bool must_copy; - int size, countDirs; - char *temp_path, *log_buf, *start, *end; + MessageType pathFrom; + Bool must_copy; + int size, countDirs; + char *temp_path, *log_buf, *start, *end; /* FontPath */ must_copy = TRUE; temp_path = defaultFontPath ? defaultFontPath : ""; if (xf86fpFlag) - pathFrom = X_CMDLINE; + pathFrom = X_CMDLINE; else if (fileconf && fileconf->file_fontpath) { - pathFrom = X_CONFIG; - if (xf86Info.useDefaultFontPath) { - if (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath, - *temp_path ? "," : "", temp_path) == -1) - defaultFontPath = NULL; - else - must_copy = FALSE; - } - else - defaultFontPath = fileconf->file_fontpath; + pathFrom = X_CONFIG; + if (xf86Info.useDefaultFontPath) { + if (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath, + *temp_path ? "," : "", temp_path) == -1) + defaultFontPath = NULL; + else + must_copy = FALSE; + } + else + defaultFontPath = fileconf->file_fontpath; } else - pathFrom = X_DEFAULT; + pathFrom = X_DEFAULT; temp_path = defaultFontPath ? defaultFontPath : ""; /* xf86ValidateFontPath modifies its argument, but returns a copy of it. */ @@ -604,61 +624,61 @@ configFiles(XF86ConfFilesPtr fileconf) countDirs = 1; temp_path = defaultFontPath; while ((temp_path = index(temp_path, ',')) != NULL) { - countDirs++; - temp_path++; + countDirs++; + temp_path++; } log_buf = xnfalloc(strlen(defaultFontPath) + (2 * countDirs) + 1); temp_path = log_buf; start = defaultFontPath; - while((end = index(start, ',')) != NULL) { - size = (end - start) + 1; - *(temp_path++) = '\t'; - strncpy(temp_path, start, size); - temp_path += size; - *(temp_path++) = '\n'; - start += size; + while ((end = index(start, ',')) != NULL) { + size = (end - start) + 1; + *(temp_path++) = '\t'; + strncpy(temp_path, start, size); + temp_path += size; + *(temp_path++) = '\n'; + start += size; } /* copy last entry */ *(temp_path++) = '\t'; strcpy(temp_path, start); xf86Msg(pathFrom, "FontPath set to:\n%s\n", log_buf); free(log_buf); - - /* ModulePath */ - if (fileconf) { - if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) { - xf86ModulePath = fileconf->file_modulepath; - xf86ModPathFrom = X_CONFIG; + /* ModulePath */ + + if (fileconf) { + if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) { + xf86ModulePath = fileconf->file_modulepath; + xf86ModPathFrom = X_CONFIG; + } } - } - xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath); + xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath); - if (!xf86xkbdirFlag && fileconf && fileconf->file_xkbdir) { - XkbBaseDirectory = fileconf->file_xkbdir; - xf86Msg(X_CONFIG, "XKB base directory set to \"%s\"\n", - XkbBaseDirectory); - } + if (!xf86xkbdirFlag && fileconf && fileconf->file_xkbdir) { + XkbBaseDirectory = fileconf->file_xkbdir; + xf86Msg(X_CONFIG, "XKB base directory set to \"%s\"\n", + XkbBaseDirectory); + } #if 0 - /* LogFile */ - /* - * XXX The problem with this is that the log file is already open. - * One option might be to copy the exiting contents to the new location. - * and re-open it. The down side is that the default location would - * already have been overwritten. Another option would be to start with - * unique temporary location, then copy it once the correct name is known. - * A problem with this is what happens if the server exits before that - * happens. - */ - if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) { - xf86LogFile = fileconf->file_logfile; - xf86LogFileFrom = X_CONFIG; - } + /* LogFile */ + /* + * XXX The problem with this is that the log file is already open. + * One option might be to copy the exiting contents to the new location. + * and re-open it. The down side is that the default location would + * already have been overwritten. Another option would be to start with + * unique temporary location, then copy it once the correct name is known. + * A problem with this is what happens if the server exits before that + * happens. + */ + if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) { + xf86LogFile = fileconf->file_logfile; + xf86LogFileFrom = X_CONFIG; + } #endif - return; + return; } typedef enum { @@ -695,58 +715,58 @@ typedef enum { * if the parser found the option in the config file. */ static OptionInfoRec FlagOptions[] = { - { FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_SAVER_BLANKTIME, "BlankTime" , OPTV_INTEGER, - {0}, FALSE }, - { FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER, - {0}, FALSE }, - { FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER, - {0}, FALSE }, - { FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER, - {0}, FALSE }, - { FLAG_PIXMAP, "Pixmap", OPTV_INTEGER, - {0}, FALSE }, - { FLAG_NOPM, "NoPM", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_LOG, "Log", OPTV_STRING, - {0}, FALSE }, - { FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING, - {0}, FALSE }, - { FLAG_RANDR, "RandR", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_AIGLX, "AIGLX", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_IGNORE_ABI, "IgnoreABI", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_USE_DEFAULT_FONT_PATH, "UseDefaultFontPath", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_AUTO_ADD_DEVICES, "AutoAddDevices", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_AUTO_ENABLE_DEVICES, "AutoEnableDevices", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_GLX_VISUALS, "GlxVisuals", OPTV_STRING, - {0}, FALSE }, - { FLAG_DRI2, "DRI2", OPTV_BOOLEAN, - {0}, FALSE }, - { FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN, - {0}, FALSE }, - { -1, NULL, OPTV_NONE, - {0}, FALSE }, + {FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_SAVER_BLANKTIME, "BlankTime", OPTV_INTEGER, + {0}, FALSE}, + {FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER, + {0}, FALSE}, + {FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER, + {0}, FALSE}, + {FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER, + {0}, FALSE}, + {FLAG_PIXMAP, "Pixmap", OPTV_INTEGER, + {0}, FALSE}, + {FLAG_NOPM, "NoPM", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_LOG, "Log", OPTV_STRING, + {0}, FALSE}, + {FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING, + {0}, FALSE}, + {FLAG_RANDR, "RandR", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_AIGLX, "AIGLX", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_IGNORE_ABI, "IgnoreABI", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_USE_DEFAULT_FONT_PATH, "UseDefaultFontPath", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_AUTO_ADD_DEVICES, "AutoAddDevices", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_AUTO_ENABLE_DEVICES, "AutoEnableDevices", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_GLX_VISUALS, "GlxVisuals", OPTV_STRING, + {0}, FALSE}, + {FLAG_DRI2, "DRI2", OPTV_BOOLEAN, + {0}, FALSE}, + {FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN, + {0}, FALSE}, + {-1, NULL, OPTV_NONE, + {0}, FALSE}, }; static Bool @@ -759,6 +779,7 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) MessageType from; const char *s; XkbRMLVOSet set; + /* Default options. */ set.rules = "base"; set.model = "pc105"; @@ -772,13 +793,13 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) */ optp = NULL; if (flagsconf && flagsconf->flg_option_lst) - optp = xf86optionListDup(flagsconf->flg_option_lst); + optp = xf86optionListDup(flagsconf->flg_option_lst); if (layoutopts) { - tmp = xf86optionListDup(layoutopts); - if (optp) - optp = xf86optionListMerge(optp, tmp); - else - optp = tmp; + tmp = xf86optionListDup(layoutopts); + if (optp) + optp = xf86optionListMerge(optp, tmp); + else + optp = tmp; } xf86ProcessOptions(-1, optp, FlagOptions); @@ -790,23 +811,28 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI); if (xf86Info.ignoreABI) { - xf86Msg(X_CONFIG, "Ignoring ABI Version\n"); + xf86Msg(X_CONFIG, "Ignoring ABI Version\n"); } if (xf86SIGIOSupported()) { - xf86Info.useSIGIO = xf86ReturnOptValBool(FlagOptions, FLAG_USE_SIGIO, USE_SIGIO_BY_DEFAULT); - if (xf86IsOptionSet(FlagOptions, FLAG_USE_SIGIO)) { - from = X_CONFIG; - } else { - from = X_DEFAULT; - } - if (!xf86Info.useSIGIO) { - xf86Msg(from, "Disabling SIGIO handlers for input devices\n"); - } else if (from == X_CONFIG) { - xf86Msg(from, "Enabling SIGIO handlers for input devices\n"); - } - } else { - xf86Info.useSIGIO = FALSE; + xf86Info.useSIGIO = + xf86ReturnOptValBool(FlagOptions, FLAG_USE_SIGIO, + USE_SIGIO_BY_DEFAULT); + if (xf86IsOptionSet(FlagOptions, FLAG_USE_SIGIO)) { + from = X_CONFIG; + } + else { + from = X_DEFAULT; + } + if (!xf86Info.useSIGIO) { + xf86Msg(from, "Disabling SIGIO handlers for input devices\n"); + } + else if (from == X_CONFIG) { + xf86Msg(from, "Enabling SIGIO handlers for input devices\n"); + } + } + else { + xf86Info.useSIGIO = FALSE; } if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_DEVICES)) { @@ -838,86 +864,92 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) */ #ifdef XF86VIDMODE if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value)) - xf86Info.vidModeEnabled = !value; + xf86Info.vidModeEnabled = !value; if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value)) - xf86Info.vidModeAllowNonLocal = value; + xf86Info.vidModeAllowNonLocal = value; #endif if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value)) - xf86Info.allowMouseOpenFail = value; + xf86Info.allowMouseOpenFail = value; xf86Info.pmFlag = TRUE; - if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value)) - xf86Info.pmFlag = !value; + if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value)) + xf86Info.pmFlag = !value; { - if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) { - if (!xf86NameCmp(s,"flush")) { - xf86Msg(X_CONFIG, "Flushing logfile enabled\n"); - xf86Info.log = LogFlush; - LogSetParameter(XLOG_FLUSH, TRUE); - } else if (!xf86NameCmp(s,"sync")) { - xf86Msg(X_CONFIG, "Syncing logfile enabled\n"); - xf86Info.log = LogSync; - LogSetParameter(XLOG_FLUSH, TRUE); - LogSetParameter(XLOG_SYNC, TRUE); - } else { - xf86Msg(X_WARNING,"Unknown Log option\n"); - } - } - } - + if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) { + if (!xf86NameCmp(s, "flush")) { + xf86Msg(X_CONFIG, "Flushing logfile enabled\n"); + xf86Info.log = LogFlush; + LogSetParameter(XLOG_FLUSH, TRUE); + } + else if (!xf86NameCmp(s, "sync")) { + xf86Msg(X_CONFIG, "Syncing logfile enabled\n"); + xf86Info.log = LogSync; + LogSetParameter(XLOG_FLUSH, TRUE); + LogSetParameter(XLOG_SYNC, TRUE); + } + else { + xf86Msg(X_WARNING, "Unknown Log option\n"); + } + } + } + { - if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))){ - int policy = PictureParseCmapPolicy (s); - if (policy == PictureCmapPolicyInvalid) - xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s); - else - { - xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s); - PictureCmapPolicy = policy; - } - } + if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))) { + int policy = PictureParseCmapPolicy(s); + + if (policy == PictureCmapPolicyInvalid) + xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s); + else { + xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s); + PictureCmapPolicy = policy; + } + } } #ifdef RANDR xf86Info.disableRandR = FALSE; xf86Info.randRFrom = X_DEFAULT; if (xf86GetOptValBool(FlagOptions, FLAG_RANDR, &value)) { - xf86Info.disableRandR = !value; - xf86Info.randRFrom = X_CONFIG; + xf86Info.disableRandR = !value; + xf86Info.randRFrom = X_CONFIG; } #endif xf86Info.aiglx = TRUE; xf86Info.aiglxFrom = X_DEFAULT; if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) { - xf86Info.aiglx = value; - xf86Info.aiglxFrom = X_CONFIG; + xf86Info.aiglx = value; + xf86Info.aiglxFrom = X_CONFIG; } #ifdef GLXEXT xf86Info.glxVisuals = XF86_GlxVisualsTypical; xf86Info.glxVisualsFrom = X_DEFAULT; if ((s = xf86GetOptValString(FlagOptions, FLAG_GLX_VISUALS))) { - if (!xf86NameCmp(s, "minimal")) { - xf86Info.glxVisuals = XF86_GlxVisualsMinimal; - } else if (!xf86NameCmp(s, "typical")) { - xf86Info.glxVisuals = XF86_GlxVisualsTypical; - } else if (!xf86NameCmp(s, "all")) { - xf86Info.glxVisuals = XF86_GlxVisualsAll; - } else { - xf86Msg(X_WARNING,"Unknown GlxVisuals option\n"); - } + if (!xf86NameCmp(s, "minimal")) { + xf86Info.glxVisuals = XF86_GlxVisualsMinimal; + } + else if (!xf86NameCmp(s, "typical")) { + xf86Info.glxVisuals = XF86_GlxVisualsTypical; + } + else if (!xf86NameCmp(s, "all")) { + xf86Info.glxVisuals = XF86_GlxVisualsAll; + } + else { + xf86Msg(X_WARNING, "Unknown GlxVisuals option\n"); + } } if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) { - xf86Info.aiglx = value; - xf86Info.aiglxFrom = X_CONFIG; + xf86Info.aiglx = value; + xf86Info.aiglxFrom = X_CONFIG; } #endif /* if we're not hotplugging, force some input devices to exist */ - xf86Info.forceInputDevices = !(xf86Info.autoAddDevices && xf86Info.autoEnableDevices); + xf86Info.forceInputDevices = !(xf86Info.autoAddDevices && + xf86Info.autoEnableDevices); /* when forcing input devices, we use kbd. otherwise evdev, so use the * evdev rules set. */ @@ -930,8 +962,8 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) xf86Info.useDefaultFontPath = TRUE; xf86Info.useDefaultFontPathFrom = X_DEFAULT; if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) { - xf86Info.useDefaultFontPath = value; - xf86Info.useDefaultFontPathFrom = X_CONFIG; + xf86Info.useDefaultFontPath = value; + xf86Info.useDefaultFontPathFrom = X_CONFIG; } /* Make sure that timers don't overflow CARD32's after multiplying */ @@ -940,86 +972,93 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) i = -1; xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i); if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN; + ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN; else if (i != -1) - xf86ConfigError("BlankTime value %d outside legal range of 0 - %d minutes", - i, MAX_TIME_IN_MIN); + xf86ConfigError + ("BlankTime value %d outside legal range of 0 - %d minutes", i, + MAX_TIME_IN_MIN); #ifdef DPMSExtension i = -1; xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i); if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSStandbyTime = i * MILLI_PER_MIN; + DPMSStandbyTime = i * MILLI_PER_MIN; else if (i != -1) - xf86ConfigError("StandbyTime value %d outside legal range of 0 - %d minutes", - i, MAX_TIME_IN_MIN); + xf86ConfigError + ("StandbyTime value %d outside legal range of 0 - %d minutes", i, + MAX_TIME_IN_MIN); i = -1; xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i); if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSSuspendTime = i * MILLI_PER_MIN; + DPMSSuspendTime = i * MILLI_PER_MIN; else if (i != -1) - xf86ConfigError("SuspendTime value %d outside legal range of 0 - %d minutes", - i, MAX_TIME_IN_MIN); + xf86ConfigError + ("SuspendTime value %d outside legal range of 0 - %d minutes", i, + MAX_TIME_IN_MIN); i = -1; xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i); if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSOffTime = i * MILLI_PER_MIN; + DPMSOffTime = i * MILLI_PER_MIN; else if (i != -1) - xf86ConfigError("OffTime value %d outside legal range of 0 - %d minutes", - i, MAX_TIME_IN_MIN); + xf86ConfigError + ("OffTime value %d outside legal range of 0 - %d minutes", i, + MAX_TIME_IN_MIN); #endif i = -1; xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i); switch (i) { case 24: - pix24 = Pix24Use24; - break; + pix24 = Pix24Use24; + break; case 32: - pix24 = Pix24Use32; - break; + pix24 = Pix24Use32; + break; case -1: - break; + break; default: - xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i); - return FALSE; + xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i); + return FALSE; } if (xf86Pix24 != Pix24DontCare) { - xf86Info.pixmap24 = xf86Pix24; - xf86Info.pix24From = X_CMDLINE; - } else if (pix24 != Pix24DontCare) { - xf86Info.pixmap24 = pix24; - xf86Info.pix24From = X_CONFIG; - } else { - xf86Info.pixmap24 = Pix24DontCare; - xf86Info.pix24From = X_DEFAULT; + xf86Info.pixmap24 = xf86Pix24; + xf86Info.pix24From = X_CMDLINE; + } + else if (pix24 != Pix24DontCare) { + xf86Info.pixmap24 = pix24; + xf86Info.pix24From = X_CONFIG; + } + else { + xf86Info.pixmap24 = Pix24DontCare; + xf86Info.pix24From = X_DEFAULT; } #ifdef PANORAMIX from = X_DEFAULT; if (!noPanoramiXExtension) - from = X_CMDLINE; + from = X_CMDLINE; else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) { - noPanoramiXExtension = !value; - from = X_CONFIG; + noPanoramiXExtension = !value; + from = X_CONFIG; } if (!noPanoramiXExtension) - xf86Msg(from, "Xinerama: enabled\n"); + xf86Msg(from, "Xinerama: enabled\n"); #endif #ifdef DRI2 xf86Info.dri2 = FALSE; xf86Info.dri2From = X_DEFAULT; if (xf86GetOptValBool(FlagOptions, FLAG_DRI2, &value)) { - xf86Info.dri2 = value; - xf86Info.dri2From = X_CONFIG; + xf86Info.dri2 = value; + xf86Info.dri2From = X_CONFIG; } #endif return TRUE; } -Bool xf86DRI2Enabled(void) +Bool +xf86DRI2Enabled(void) { return xf86Info.dri2; } @@ -1029,17 +1068,17 @@ Bool xf86DRI2Enabled(void) * free) it if present. All other devices are moved forward. */ static void -freeDevice(InputInfoPtr *list, InputInfoPtr pInfo) +freeDevice(InputInfoPtr * list, InputInfoPtr pInfo) { InputInfoPtr *devs; for (devs = list; devs && *devs; devs++) { - if (*devs == pInfo) { - free(*devs); - for (; devs && *devs; devs++) - devs[0] = devs[1]; - break; - } + if (*devs == pInfo) { + free(*devs); + for (; devs && *devs; devs++) + devs[0] = devs[1]; + break; + } } } @@ -1047,14 +1086,14 @@ freeDevice(InputInfoPtr *list, InputInfoPtr pInfo) * Append pInfo to the null-terminated list, allocating space as necessary. * pInfo is used as the last element. */ -static InputInfoPtr* -addDevice(InputInfoPtr *list, InputInfoPtr pInfo) +static InputInfoPtr * +addDevice(InputInfoPtr * list, InputInfoPtr pInfo) { InputInfoPtr *devs; int count = 1; for (devs = list; devs && *devs; devs++) - count++; + count++; list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr)); list[count] = NULL; @@ -1084,14 +1123,16 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) InputInfoPtr corePointer = NULL, coreKeyboard = NULL; Bool foundPointer = FALSE, foundKeyboard = FALSE; const char *pointerMsg = NULL, *keyboardMsg = NULL; - InputInfoPtr *devs, /* iterator */ - indp; + InputInfoPtr *devs, /* iterator */ + indp; InputInfoPtr Pointer, Keyboard; XF86ConfInputPtr confInput; XF86ConfInputRec defPtr, defKbd; MessageType from = X_DEFAULT; + const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse", - "void", NULL }; + "void", NULL + }; /* * First check if a core pointer or core keyboard have been specified @@ -1100,249 +1141,255 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) */ for (devs = servlayoutp->inputs; devs && *devs; devs++) { indp = *devs; - if (indp->options && - xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) { - if (!corePointer) { - corePointer = indp; - } - } - if (indp->options && - xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) { - if (!coreKeyboard) { - coreKeyboard = indp; - } - } + if (indp->options && + xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) { + if (!corePointer) { + corePointer = indp; + } + } + if (indp->options && + xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) { + if (!coreKeyboard) { + coreKeyboard = indp; + } + } } confInput = NULL; /* 1. Check for the -pointer command line option. */ if (xf86PointerName) { - confInput = xf86findInput(xf86PointerName, - xf86configptr->conf_input_lst); - if (!confInput) { - xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", - xf86PointerName); - return FALSE; - } - from = X_CMDLINE; - /* - * If one was already specified in the ServerLayout, it needs to be - * removed. - */ - if (corePointer) { - freeDevice(servlayoutp->inputs, corePointer); - corePointer = NULL; - } - foundPointer = TRUE; + confInput = xf86findInput(xf86PointerName, + xf86configptr->conf_input_lst); + if (!confInput) { + xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", + xf86PointerName); + return FALSE; + } + from = X_CMDLINE; + /* + * If one was already specified in the ServerLayout, it needs to be + * removed. + */ + if (corePointer) { + freeDevice(servlayoutp->inputs, corePointer); + corePointer = NULL; + } + foundPointer = TRUE; } /* 2. ServerLayout-specified core pointer. */ if (corePointer) { - foundPointer = TRUE; - from = X_CONFIG; + foundPointer = TRUE; + from = X_CONFIG; } /* 3. First core pointer device. */ if (!foundPointer && (xf86Info.forceInputDevices || implicitLayout)) { - XF86ConfInputPtr p; - - for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { - if (p->inp_option_lst && - xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) { - confInput = p; - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "first core pointer device"; - break; - } - } + XF86ConfInputPtr p; + + for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { + if (p->inp_option_lst && + xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) { + confInput = p; + foundPointer = TRUE; + from = X_DEFAULT; + pointerMsg = "first core pointer device"; + break; + } + } } /* 4. First pointer with an allowed mouse driver. */ if (!foundPointer && xf86Info.forceInputDevices) { - const char **driver = mousedrivers; - confInput = xf86findInput(CONF_IMPLICIT_POINTER, - xf86configptr->conf_input_lst); - while (*driver && !confInput) { - confInput = xf86findInputByDriver(*driver, - xf86configptr->conf_input_lst); - driver++; - } - if (confInput) { - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "first mouse device"; - } + const char **driver = mousedrivers; + + confInput = xf86findInput(CONF_IMPLICIT_POINTER, + xf86configptr->conf_input_lst); + while (*driver && !confInput) { + confInput = xf86findInputByDriver(*driver, + xf86configptr->conf_input_lst); + driver++; + } + if (confInput) { + foundPointer = TRUE; + from = X_DEFAULT; + pointerMsg = "first mouse device"; + } } /* 5. Built-in default. */ if (!foundPointer && xf86Info.forceInputDevices) { - memset(&defPtr, 0, sizeof(defPtr)); - defPtr.inp_identifier = strdup("<default pointer>"); - defPtr.inp_driver = strdup("mouse"); - confInput = &defPtr; - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "default mouse configuration"; + memset(&defPtr, 0, sizeof(defPtr)); + defPtr.inp_identifier = strdup("<default pointer>"); + defPtr.inp_driver = strdup("mouse"); + confInput = &defPtr; + foundPointer = TRUE; + from = X_DEFAULT; + pointerMsg = "default mouse configuration"; } /* Add the core pointer device to the layout, and set it to Core. */ if (foundPointer && confInput) { - Pointer = xf86AllocateInput(); - if (Pointer) - foundPointer = configInput(Pointer, confInput, from); - if (foundPointer) { - Pointer->options = xf86AddNewOption(Pointer->options, - "CorePointer", "on"); - Pointer->options = xf86AddNewOption(Pointer->options, - "driver", confInput->inp_driver); - Pointer->options = xf86AddNewOption(Pointer->options, - "identifier", confInput->inp_identifier); - servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer); - } + Pointer = xf86AllocateInput(); + if (Pointer) + foundPointer = configInput(Pointer, confInput, from); + if (foundPointer) { + Pointer->options = xf86AddNewOption(Pointer->options, + "CorePointer", "on"); + Pointer->options = xf86AddNewOption(Pointer->options, + "driver", + confInput->inp_driver); + Pointer->options = + xf86AddNewOption(Pointer->options, "identifier", + confInput->inp_identifier); + servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer); + } } if (!foundPointer && xf86Info.forceInputDevices) { - /* This shouldn't happen. */ - xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n"); - xf86DeleteInput(Pointer, 0); - return FALSE; + /* This shouldn't happen. */ + xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n"); + xf86DeleteInput(Pointer, 0); + return FALSE; } confInput = NULL; /* 1. Check for the -keyboard command line option. */ if (xf86KeyboardName) { - confInput = xf86findInput(xf86KeyboardName, - xf86configptr->conf_input_lst); - if (!confInput) { - xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", - xf86KeyboardName); - return FALSE; - } - from = X_CMDLINE; - /* - * If one was already specified in the ServerLayout, it needs to be - * removed. - */ - if (coreKeyboard) { - freeDevice(servlayoutp->inputs, coreKeyboard); - coreKeyboard = NULL; - } - foundKeyboard = TRUE; + confInput = xf86findInput(xf86KeyboardName, + xf86configptr->conf_input_lst); + if (!confInput) { + xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", + xf86KeyboardName); + return FALSE; + } + from = X_CMDLINE; + /* + * If one was already specified in the ServerLayout, it needs to be + * removed. + */ + if (coreKeyboard) { + freeDevice(servlayoutp->inputs, coreKeyboard); + coreKeyboard = NULL; + } + foundKeyboard = TRUE; } /* 2. ServerLayout-specified core keyboard. */ if (coreKeyboard) { - foundKeyboard = TRUE; - from = X_CONFIG; + foundKeyboard = TRUE; + from = X_CONFIG; } /* 3. First core keyboard device. */ if (!foundKeyboard && (xf86Info.forceInputDevices || implicitLayout)) { - XF86ConfInputPtr p; - - for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { - if (p->inp_option_lst && - xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) { - confInput = p; - foundKeyboard = TRUE; - from = X_DEFAULT; - keyboardMsg = "first core keyboard device"; - break; - } - } + XF86ConfInputPtr p; + + for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { + if (p->inp_option_lst && + xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) { + confInput = p; + foundKeyboard = TRUE; + from = X_DEFAULT; + keyboardMsg = "first core keyboard device"; + break; + } + } } /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */ if (!foundKeyboard && xf86Info.forceInputDevices) { - confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD, - xf86configptr->conf_input_lst); - if (!confInput) { - confInput = xf86findInputByDriver("kbd", - xf86configptr->conf_input_lst); - } - if (confInput) { - foundKeyboard = TRUE; - from = X_DEFAULT; - keyboardMsg = "first keyboard device"; - } + confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD, + xf86configptr->conf_input_lst); + if (!confInput) { + confInput = xf86findInputByDriver("kbd", + xf86configptr->conf_input_lst); + } + if (confInput) { + foundKeyboard = TRUE; + from = X_DEFAULT; + keyboardMsg = "first keyboard device"; + } } /* 5. Built-in default. */ if (!foundKeyboard && xf86Info.forceInputDevices) { - memset(&defKbd, 0, sizeof(defKbd)); - defKbd.inp_identifier = strdup("<default keyboard>"); - defKbd.inp_driver = strdup("kbd"); - confInput = &defKbd; - foundKeyboard = TRUE; - keyboardMsg = "default keyboard configuration"; - from = X_DEFAULT; + memset(&defKbd, 0, sizeof(defKbd)); + defKbd.inp_identifier = strdup("<default keyboard>"); + defKbd.inp_driver = strdup("kbd"); + confInput = &defKbd; + foundKeyboard = TRUE; + keyboardMsg = "default keyboard configuration"; + from = X_DEFAULT; } /* Add the core keyboard device to the layout, and set it to Core. */ if (foundKeyboard && confInput) { - Keyboard = xf86AllocateInput(); - if (Keyboard) - foundKeyboard = configInput(Keyboard, confInput, from); - if (foundKeyboard) { - Keyboard->options = xf86AddNewOption(Keyboard->options, - "CoreKeyboard", "on"); - Keyboard->options = xf86AddNewOption(Keyboard->options, - "driver", confInput->inp_driver); - Keyboard->options = xf86AddNewOption(Keyboard->options, - "identifier", confInput->inp_identifier); - servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard); - } + Keyboard = xf86AllocateInput(); + if (Keyboard) + foundKeyboard = configInput(Keyboard, confInput, from); + if (foundKeyboard) { + Keyboard->options = xf86AddNewOption(Keyboard->options, + "CoreKeyboard", "on"); + Keyboard->options = xf86AddNewOption(Keyboard->options, + "driver", + confInput->inp_driver); + Keyboard->options = + xf86AddNewOption(Keyboard->options, "identifier", + confInput->inp_identifier); + servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard); + } } if (!foundKeyboard && xf86Info.forceInputDevices) { - /* This shouldn't happen. */ - xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n"); - xf86DeleteInput(Keyboard, 0); - return FALSE; + /* This shouldn't happen. */ + xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n"); + xf86DeleteInput(Keyboard, 0); + return FALSE; } if (pointerMsg) { - if (implicitLayout) - xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", - pointerMsg); - else - xf86Msg(X_DEFAULT, "The core pointer device wasn't specified " - "explicitly in the layout.\n" - "\tUsing the %s.\n", pointerMsg); + if (implicitLayout) + xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", + pointerMsg); + else + xf86Msg(X_DEFAULT, "The core pointer device wasn't specified " + "explicitly in the layout.\n" + "\tUsing the %s.\n", pointerMsg); } if (keyboardMsg) { - if (implicitLayout) - xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", - keyboardMsg); - else - xf86Msg(X_DEFAULT, "The core keyboard device wasn't specified " - "explicitly in the layout.\n" - "\tUsing the %s.\n", keyboardMsg); + if (implicitLayout) + xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", + keyboardMsg); + else + xf86Msg(X_DEFAULT, "The core keyboard device wasn't specified " + "explicitly in the layout.\n" + "\tUsing the %s.\n", keyboardMsg); } if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) { #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) - const char *config_backend; + const char *config_backend; + #if defined(CONFIG_HAL) - config_backend = "HAL"; + config_backend = "HAL"; #elif defined(CONFIG_UDEV) - config_backend = "udev"; + config_backend = "udev"; #else - config_backend = "wscons"; + config_backend = "wscons"; #endif - xf86Msg(X_INFO, "The server relies on %s to provide the list of " - "input devices.\n\tIf no devices become available, " - "reconfigure %s or disable AutoAddDevices.\n", - config_backend, config_backend); + xf86Msg(X_INFO, "The server relies on %s to provide the list of " + "input devices.\n\tIf no devices become available, " + "reconfigure %s or disable AutoAddDevices.\n", + config_backend, config_backend); #else - xf86Msg(X_WARNING, "Hotplugging requested but the server was " - "compiled without a config backend. " - "No input devices were configured, the server " - "will start without any input devices.\n"); + xf86Msg(X_WARNING, "Hotplugging requested but the server was " + "compiled without a config backend. " + "No input devices were configured, the server " + "will start without any input devices.\n"); #endif } @@ -1355,12 +1402,12 @@ typedef enum { } LayoutValues; static OptionInfoRec LayoutOptions[] = { - { LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING, - {0}, FALSE }, - { LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN, - {0}, FALSE }, - { -1, NULL, OPTV_NONE, - {0}, FALSE }, + {LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING, + {0}, FALSE}, + {LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN, + {0}, FALSE}, + {-1, NULL, OPTV_NONE, + {0}, FALSE}, }; static Bool @@ -1375,42 +1422,41 @@ configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp) */ irp = layout->lay_input_lst; while (irp) { - count++; - irp = (XF86ConfInputrefPtr)irp->list.next; + count++; + irp = (XF86ConfInputrefPtr) irp->list.next; } DebugF("Found %d input devices in the layout section %s\n", - count, layout->lay_identifier); + count, layout->lay_identifier); indp = xnfcalloc((count + 1), sizeof(InputInfoPtr)); indp[count] = NULL; irp = layout->lay_input_lst; count = 0; while (irp) { - indp[count] = xf86AllocateInput(); - if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) { - do { - free(indp[count]); - } while(count--); - free(indp); - return FALSE; - } - indp[count]->options = xf86OptionListMerge(indp[count]->options, - irp->iref_option_lst); - count++; - irp = (XF86ConfInputrefPtr)irp->list.next; + indp[count] = xf86AllocateInput(); + if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) { + do { + free(indp[count]); + } while (count--); + free(indp); + return FALSE; + } + indp[count]->options = xf86OptionListMerge(indp[count]->options, + irp->iref_option_lst); + count++; + irp = (XF86ConfInputrefPtr) irp->list.next; } servlayoutp->inputs = indp; return TRUE; } - /* * figure out which layout is active, which screens are used in that layout, * which drivers and monitors are used in these screens */ static Bool configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, - char *default_layout) + char *default_layout) { XF86ConfAdjacencyPtr adjp; XF86ConfInactivePtr idp; @@ -1423,7 +1469,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, int i = 0, j; if (!servlayoutp) - return FALSE; + return FALSE; /* * which layout section is the active one? @@ -1433,18 +1479,18 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, */ from = X_DEFAULT; if (xf86LayoutName != NULL) - from = X_CMDLINE; + from = X_CMDLINE; else if (default_layout) { - xf86LayoutName = default_layout; - from = X_CONFIG; + xf86LayoutName = default_layout; + from = X_CONFIG; } if (xf86LayoutName != NULL) { - if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) { - xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n", - xf86LayoutName); - return FALSE; - } - conf_layout = l; + if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) { + xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n", + xf86LayoutName); + return FALSE; + } + conf_layout = l; } xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier); adjp = conf_layout->lay_adjacency_lst; @@ -1457,12 +1503,12 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, */ while (adjp) { count++; - adjp = (XF86ConfAdjacencyPtr)adjp->list.next; + adjp = (XF86ConfAdjacencyPtr) adjp->list.next; } DebugF("Found %d screens in the layout section %s", count, conf_layout->lay_identifier); - if (!count) /* alloc enough storage even if no screen is specified */ + if (!count) /* alloc enough storage even if no screen is specified */ count = 1; slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec)); @@ -1476,107 +1522,105 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, count = 0; while (adjp) { slp[count].screen = xnfcalloc(1, sizeof(confScreenRec)); - if (adjp->adj_scrnum < 0) - scrnum = count; - else - scrnum = adjp->adj_scrnum; - if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum, - X_CONFIG)) { - do { - free(slp[count].screen); - } while(count--); - free(slp); - return FALSE; - } - slp[count].x = adjp->adj_x; - slp[count].y = adjp->adj_y; - slp[count].refname = adjp->adj_refscreen; - switch (adjp->adj_where) { - case CONF_ADJ_OBSOLETE: - slp[count].where = PosObsolete; - slp[count].topname = adjp->adj_top_str; - slp[count].bottomname = adjp->adj_bottom_str; - slp[count].leftname = adjp->adj_left_str; - slp[count].rightname = adjp->adj_right_str; - break; - case CONF_ADJ_ABSOLUTE: - slp[count].where = PosAbsolute; - break; - case CONF_ADJ_RIGHTOF: - slp[count].where = PosRightOf; - break; - case CONF_ADJ_LEFTOF: - slp[count].where = PosLeftOf; - break; - case CONF_ADJ_ABOVE: - slp[count].where = PosAbove; - break; - case CONF_ADJ_BELOW: - slp[count].where = PosBelow; - break; - case CONF_ADJ_RELATIVE: - slp[count].where = PosRelative; - break; - } + if (adjp->adj_scrnum < 0) + scrnum = count; + else + scrnum = adjp->adj_scrnum; + if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum, + X_CONFIG)) { + do { + free(slp[count].screen); + } while (count--); + free(slp); + return FALSE; + } + slp[count].x = adjp->adj_x; + slp[count].y = adjp->adj_y; + slp[count].refname = adjp->adj_refscreen; + switch (adjp->adj_where) { + case CONF_ADJ_OBSOLETE: + slp[count].where = PosObsolete; + slp[count].topname = adjp->adj_top_str; + slp[count].bottomname = adjp->adj_bottom_str; + slp[count].leftname = adjp->adj_left_str; + slp[count].rightname = adjp->adj_right_str; + break; + case CONF_ADJ_ABSOLUTE: + slp[count].where = PosAbsolute; + break; + case CONF_ADJ_RIGHTOF: + slp[count].where = PosRightOf; + break; + case CONF_ADJ_LEFTOF: + slp[count].where = PosLeftOf; + break; + case CONF_ADJ_ABOVE: + slp[count].where = PosAbove; + break; + case CONF_ADJ_BELOW: + slp[count].where = PosBelow; + break; + case CONF_ADJ_RELATIVE: + slp[count].where = PosRelative; + break; + } count++; - adjp = (XF86ConfAdjacencyPtr)adjp->list.next; + adjp = (XF86ConfAdjacencyPtr) adjp->list.next; } /* No screen was specified in the layout. take the first one from the * config file, or - if it is NULL - configScreen autogenerates one for * us */ - if (!count) - { + if (!count) { slp[0].screen = xnfcalloc(1, sizeof(confScreenRec)); - if (!configScreen(slp[0].screen, xf86configptr->conf_screen_lst, + if (!configScreen(slp[0].screen, xf86configptr->conf_screen_lst, 0, X_CONFIG)) { - free(slp[0].screen); - free(slp); - return FALSE; - } + free(slp[0].screen); + free(slp); + return FALSE; + } } /* XXX Need to tie down the upper left screen. */ /* Fill in the refscreen and top/bottom/left/right values */ for (i = 0; i < count; i++) { - for (j = 0; j < count; j++) { - if (slp[i].refname && - strcmp(slp[i].refname, slp[j].screen->id) == 0) { - slp[i].refscreen = slp[j].screen; - } - if (slp[i].topname && - strcmp(slp[i].topname, slp[j].screen->id) == 0) { - slp[i].top = slp[j].screen; - } - if (slp[i].bottomname && - strcmp(slp[i].bottomname, slp[j].screen->id) == 0) { - slp[i].bottom = slp[j].screen; - } - if (slp[i].leftname && - strcmp(slp[i].leftname, slp[j].screen->id) == 0) { - slp[i].left = slp[j].screen; - } - if (slp[i].rightname && - strcmp(slp[i].rightname, slp[j].screen->id) == 0) { - slp[i].right = slp[j].screen; - } - } - if (slp[i].where != PosObsolete - && slp[i].where != PosAbsolute - && !slp[i].refscreen) { - xf86Msg(X_ERROR,"Screen %s doesn't exist: deleting placement\n", - slp[i].refname); - slp[i].where = PosAbsolute; - slp[i].x = 0; - slp[i].y = 0; - } + for (j = 0; j < count; j++) { + if (slp[i].refname && + strcmp(slp[i].refname, slp[j].screen->id) == 0) { + slp[i].refscreen = slp[j].screen; + } + if (slp[i].topname && + strcmp(slp[i].topname, slp[j].screen->id) == 0) { + slp[i].top = slp[j].screen; + } + if (slp[i].bottomname && + strcmp(slp[i].bottomname, slp[j].screen->id) == 0) { + slp[i].bottom = slp[j].screen; + } + if (slp[i].leftname && + strcmp(slp[i].leftname, slp[j].screen->id) == 0) { + slp[i].left = slp[j].screen; + } + if (slp[i].rightname && + strcmp(slp[i].rightname, slp[j].screen->id) == 0) { + slp[i].right = slp[j].screen; + } + } + if (slp[i].where != PosObsolete + && slp[i].where != PosAbsolute && !slp[i].refscreen) { + xf86Msg(X_ERROR, "Screen %s doesn't exist: deleting placement\n", + slp[i].refname); + slp[i].where = PosAbsolute; + slp[i].x = 0; + slp[i].y = 0; + } } if (!count) - saved_count = 1; + saved_count = 1; else - saved_count = count; + saved_count = count; /* * Count the number of inactive devices. */ @@ -1584,7 +1628,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, idp = conf_layout->lay_inactive_lst; while (idp) { count++; - idp = (XF86ConfInactivePtr)idp->list.next; + idp = (XF86ConfInactivePtr) idp->list.next; } DebugF("Found %d inactive devices in the layout section %s\n", count, conf_layout->lay_identifier); @@ -1593,14 +1637,14 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, idp = conf_layout->lay_inactive_lst; count = 0; while (idp) { - if (!configDevice(&gdp[count], idp->inactive_device, FALSE)) - goto bail; + if (!configDevice(&gdp[count], idp->inactive_device, FALSE)) + goto bail; count++; - idp = (XF86ConfInactivePtr)idp->list.next; + idp = (XF86ConfInactivePtr) idp->list.next; } if (!configInputDevices(conf_layout, servlayoutp)) - goto bail; + goto bail; servlayoutp->id = conf_layout->lay_identifier; servlayoutp->screens = slp; @@ -1610,10 +1654,10 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, return TRUE; -bail: + bail: do { - free(slp[saved_count].screen); - } while(saved_count--); + free(slp[saved_count].screen); + } while (saved_count--); free(slp); free(gdp); return FALSE; @@ -1634,7 +1678,7 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen, XF86ConfLayoutRec layout; if (!servlayoutp) - return FALSE; + return FALSE; /* * which screen section is the active one? @@ -1645,13 +1689,13 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen, from = X_CONFIG; if (xf86ScreenName != NULL) { - if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) { - xf86Msg(X_ERROR, "No Screen section called \"%s\"\n", - xf86ScreenName); - return FALSE; - } - conf_screen = s; - from = X_CMDLINE; + if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) { + xf86Msg(X_ERROR, "No Screen section called \"%s\"\n", + xf86ScreenName); + return FALSE; + } + conf_screen = s; + from = X_CMDLINE; } /* We have exactly one screen */ @@ -1660,8 +1704,8 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen, slp[0].screen = xnfcalloc(1, sizeof(confScreenRec)); slp[1].screen = NULL; if (!configScreen(slp[0].screen, conf_screen, 0, from)) { - free(slp); - return FALSE; + free(slp); + return FALSE; } servlayoutp->id = "(implicit)"; servlayoutp->screens = slp; @@ -1671,14 +1715,15 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen, memset(&layout, 0, sizeof(layout)); layout.lay_identifier = servlayoutp->id; if (xf86layoutAddInputDevices(xf86configptr, &layout) > 0) { - if (!configInputDevices(&layout, servlayoutp)) - return FALSE; - from = X_DEFAULT; - } else { - /* Set up an empty input device list, then look for some core devices. */ - indp = xnfalloc(sizeof(InputInfoPtr)); - *indp = NULL; - servlayoutp->inputs = indp; + if (!configInputDevices(&layout, servlayoutp)) + return FALSE; + from = X_DEFAULT; + } + else { + /* Set up an empty input device list, then look for some core devices. */ + indp = xnfalloc(sizeof(InputInfoPtr)); + *indp = NULL; + servlayoutp->inputs = indp; } return TRUE; @@ -1691,31 +1736,31 @@ configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor) XF86ConfVideoPortPtr conf_port; xf86Msg(X_CONFIG, "| |-->VideoAdaptor \"%s\"\n", - conf_adaptor->va_identifier); + conf_adaptor->va_identifier); adaptor->identifier = conf_adaptor->va_identifier; adaptor->options = conf_adaptor->va_option_lst; if (conf_adaptor->va_busid || conf_adaptor->va_driver) { - xf86Msg(X_CONFIG, "| | Unsupported device type, skipping entry\n"); - return FALSE; + xf86Msg(X_CONFIG, "| | Unsupported device type, skipping entry\n"); + return FALSE; } /* * figure out how many videoport subsections there are and fill them in */ conf_port = conf_adaptor->va_port_lst; - while(conf_port) { + while (conf_port) { count++; - conf_port = (XF86ConfVideoPortPtr)conf_port->list.next; + conf_port = (XF86ConfVideoPortPtr) conf_port->list.next; } adaptor->ports = xnfalloc((count) * sizeof(confXvPortRec)); adaptor->numports = count; count = 0; conf_port = conf_adaptor->va_port_lst; - while(conf_port) { - adaptor->ports[count].identifier = conf_port->vp_identifier; - adaptor->ports[count].options = conf_port->vp_option_lst; + while (conf_port) { + adaptor->ports[count].identifier = conf_port->vp_identifier; + adaptor->ports[count].options = conf_port->vp_option_lst; count++; - conf_port = (XF86ConfVideoPortPtr)conf_port->list.next; + conf_port = (XF86ConfVideoPortPtr) conf_port->list.next; } return TRUE; @@ -1723,7 +1768,7 @@ configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor) static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum, - MessageType from) + MessageType from) { int count = 0; XF86ConfDisplayPtr dispptr; @@ -1739,96 +1784,98 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum, } xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier, - scrnum); + scrnum); /* * now we fill in the elements of the screen */ - screenp->id = conf_screen->scrn_identifier; - screenp->screennum = scrnum; + screenp->id = conf_screen->scrn_identifier; + screenp->screennum = scrnum; screenp->defaultdepth = conf_screen->scrn_defaultdepth; screenp->defaultbpp = conf_screen->scrn_defaultbpp; screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp; - screenp->monitor = xnfcalloc(1, sizeof(MonRec)); + screenp->monitor = xnfcalloc(1, sizeof(MonRec)); /* If no monitor is specified, create a default one. */ if (!conf_screen->scrn_monitor) { - XF86ConfMonitorRec defMon; + XF86ConfMonitorRec defMon; - memset(&defMon, 0, sizeof(defMon)); - defMon.mon_identifier = "<default monitor>"; - if (!configMonitor(screenp->monitor, &defMon)) - return FALSE; - defaultMonitor = TRUE; - } else { - if (!configMonitor(screenp->monitor,conf_screen->scrn_monitor)) - return FALSE; + memset(&defMon, 0, sizeof(defMon)); + defMon.mon_identifier = "<default monitor>"; + if (!configMonitor(screenp->monitor, &defMon)) + return FALSE; + defaultMonitor = TRUE; + } + else { + if (!configMonitor(screenp->monitor, conf_screen->scrn_monitor)) + return FALSE; } /* Configure the device. If there isn't one configured, attach to the * first inactive one that we can configure. If there's none that work, * set it to NULL so that the section can be autoconfigured later */ - screenp->device = xnfcalloc(1, sizeof(GDevRec)); + screenp->device = xnfcalloc(1, sizeof(GDevRec)); if ((!conf_screen->scrn_device) && (xf86configptr->conf_device_lst)) { conf_screen->scrn_device = xf86configptr->conf_device_lst; - xf86Msg(X_DEFAULT, "No device specified for screen \"%s\".\n" - "\tUsing the first device section listed.\n", screenp->id); + xf86Msg(X_DEFAULT, "No device specified for screen \"%s\".\n" + "\tUsing the first device section listed.\n", screenp->id); } - if (configDevice(screenp->device,conf_screen->scrn_device, TRUE)) { + if (configDevice(screenp->device, conf_screen->scrn_device, TRUE)) { screenp->device->myScreenSection = screenp; - } else { + } + else { screenp->device = NULL; } screenp->options = conf_screen->scrn_option_lst; - + /* * figure out how many display subsections there are and fill them in */ dispptr = conf_screen->scrn_display_lst; - while(dispptr) { + while (dispptr) { count++; - dispptr = (XF86ConfDisplayPtr)dispptr->list.next; + dispptr = (XF86ConfDisplayPtr) dispptr->list.next; } - screenp->displays = xnfalloc((count) * sizeof(DispRec)); + screenp->displays = xnfalloc((count) * sizeof(DispRec)); screenp->numdisplays = count; - + /* Fill in the default Virtual size, if any */ if (conf_screen->scrn_virtualX && conf_screen->scrn_virtualY) { - for (count = 0, dispptr = conf_screen->scrn_display_lst; - dispptr; - dispptr = (XF86ConfDisplayPtr)dispptr->list.next, count++) { - screenp->displays[count].virtualX = conf_screen->scrn_virtualX; - screenp->displays[count].virtualY = conf_screen->scrn_virtualY; - } + for (count = 0, dispptr = conf_screen->scrn_display_lst; + dispptr; + dispptr = (XF86ConfDisplayPtr) dispptr->list.next, count++) { + screenp->displays[count].virtualX = conf_screen->scrn_virtualX; + screenp->displays[count].virtualY = conf_screen->scrn_virtualY; + } } /* Now do the per-Display Virtual sizes */ count = 0; dispptr = conf_screen->scrn_display_lst; - while(dispptr) { - configDisplay(&(screenp->displays[count]),dispptr); + while (dispptr) { + configDisplay(&(screenp->displays[count]), dispptr); count++; - dispptr = (XF86ConfDisplayPtr)dispptr->list.next; + dispptr = (XF86ConfDisplayPtr) dispptr->list.next; } /* * figure out how many videoadaptor references there are and fill them in */ conf_adaptor = conf_screen->scrn_adaptor_lst; - while(conf_adaptor) { + while (conf_adaptor) { count++; - conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next; + conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next; } screenp->xvadaptors = xnfalloc((count) * sizeof(confXvAdaptorRec)); screenp->numxvadaptors = 0; conf_adaptor = conf_screen->scrn_adaptor_lst; - while(conf_adaptor) { + while (conf_adaptor) { if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]), - conf_adaptor->al_adaptor)) - screenp->numxvadaptors++; - conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next; + conf_adaptor->al_adaptor)) + screenp->numxvadaptors++; + conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next; } if (defaultMonitor) { - xf86Msg(X_DEFAULT, "No monitor specified for screen \"%s\".\n" - "\tUsing a default monitor configuration.\n", screenp->id); + xf86Msg(X_DEFAULT, "No monitor specified for screen \"%s\".\n" + "\tUsing a default monitor configuration.\n", screenp->id); } return TRUE; } @@ -1839,28 +1886,27 @@ typedef enum { } MonitorValues; static OptionInfoRec MonitorOptions[] = { - { MON_REDUCEDBLANKING, "ReducedBlanking", OPTV_BOOLEAN, - {0}, FALSE }, - { MON_MAX_PIX_CLOCK, "MaxPixClock", OPTV_FREQ, - {0}, FALSE }, - { -1, NULL, OPTV_NONE, - {0}, FALSE }, + {MON_REDUCEDBLANKING, "ReducedBlanking", OPTV_BOOLEAN, + {0}, FALSE}, + {MON_MAX_PIX_CLOCK, "MaxPixClock", OPTV_FREQ, + {0}, FALSE}, + {-1, NULL, OPTV_NONE, + {0}, FALSE}, }; static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) { int count; - DisplayModePtr mode,last = NULL; + DisplayModePtr mode, last = NULL; XF86ConfModeLinePtr cmodep; XF86ConfModesPtr modes; XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst; - Gamma zeros = {0.0, 0.0, 0.0}; + Gamma zeros = { 0.0, 0.0, 0.0 }; float badgamma = 0.0; double maxPixClock; - - xf86Msg(X_CONFIG, "| |-->Monitor \"%s\"\n", - conf_monitor->mon_identifier); + + xf86Msg(X_CONFIG, "| |-->Monitor \"%s\"\n", conf_monitor->mon_identifier); monitorp->id = conf_monitor->mon_identifier; monitorp->vendor = conf_monitor->mon_vendor; monitorp->model = conf_monitor->mon_modelname; @@ -1875,17 +1921,16 @@ configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) /* * fill in the monitor structure - */ - for( count = 0 ; - count < conf_monitor->mon_n_hsync && count < MAX_HSYNC; - count++) { + */ + for (count = 0; + count < conf_monitor->mon_n_hsync && count < MAX_HSYNC; count++) { monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi; monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo; } monitorp->nHsync = count; - for( count = 0 ; - count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH; - count++) { + for (count = 0; + count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH; + count++) { monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi; monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo; } @@ -1894,27 +1939,23 @@ configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) /* * first we collect the mode lines from the UseModes directive */ - while(modeslnk) - { - modes = xf86findModes (modeslnk->ml_modes_str, - xf86configptr->conf_modes_lst); - modeslnk->ml_modes = modes; - - - /* now add the modes found in the modes - section to the list of modes for this - monitor unless it has been added before - because we are reusing the same section - for another screen */ - if (xf86itemNotSublist( - (GenericListPtr)conf_monitor->mon_modeline_lst, - (GenericListPtr)modes->mon_modeline_lst)) { - conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr) - xf86addListItem( - (GenericListPtr)conf_monitor->mon_modeline_lst, - (GenericListPtr)modes->mon_modeline_lst); - } - modeslnk = modeslnk->list.next; + while (modeslnk) { + modes = xf86findModes(modeslnk->ml_modes_str, + xf86configptr->conf_modes_lst); + modeslnk->ml_modes = modes; + + /* now add the modes found in the modes + section to the list of modes for this + monitor unless it has been added before + because we are reusing the same section + for another screen */ + if (xf86itemNotSublist((GenericListPtr) conf_monitor->mon_modeline_lst, + (GenericListPtr) modes->mon_modeline_lst)) { + conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr) + xf86addListItem((GenericListPtr) conf_monitor->mon_modeline_lst, + (GenericListPtr) modes->mon_modeline_lst); + } + modeslnk = modeslnk->list.next; } /* @@ -1923,23 +1964,23 @@ configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) * is double linked */ cmodep = conf_monitor->mon_modeline_lst; - while( cmodep ) { + while (cmodep) { mode = xnfcalloc(1, sizeof(DisplayModeRec)); - mode->type = 0; - mode->Clock = cmodep->ml_clock; - mode->HDisplay = cmodep->ml_hdisplay; + mode->type = 0; + mode->Clock = cmodep->ml_clock; + mode->HDisplay = cmodep->ml_hdisplay; mode->HSyncStart = cmodep->ml_hsyncstart; - mode->HSyncEnd = cmodep->ml_hsyncend; - mode->HTotal = cmodep->ml_htotal; - mode->VDisplay = cmodep->ml_vdisplay; + mode->HSyncEnd = cmodep->ml_hsyncend; + mode->HTotal = cmodep->ml_htotal; + mode->VDisplay = cmodep->ml_vdisplay; mode->VSyncStart = cmodep->ml_vsyncstart; - mode->VSyncEnd = cmodep->ml_vsyncend; - mode->VTotal = cmodep->ml_vtotal; - mode->Flags = cmodep->ml_flags; - mode->HSkew = cmodep->ml_hskew; - mode->VScan = cmodep->ml_vscan; - mode->name = xnfstrdup(cmodep->ml_identifier); - if( last ) { + mode->VSyncEnd = cmodep->ml_vsyncend; + mode->VTotal = cmodep->ml_vtotal; + mode->Flags = cmodep->ml_flags; + mode->HSkew = cmodep->ml_hskew; + mode->VScan = cmodep->ml_vscan; + mode->name = xnfstrdup(cmodep->ml_identifier); + if (last) { mode->prev = last; last->next = mode; } @@ -1951,52 +1992,53 @@ configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) mode->prev = NULL; } last = mode; - cmodep = (XF86ConfModeLinePtr)cmodep->list.next; + cmodep = (XF86ConfModeLinePtr) cmodep->list.next; } - if(last){ - last->next = NULL; + if (last) { + last->next = NULL; } monitorp->Last = last; /* add the (VESA) default modes */ - if (! addDefaultModes(monitorp) ) - return FALSE; + if (!addDefaultModes(monitorp)) + return FALSE; if (conf_monitor->mon_gamma_red > GAMMA_ZERO) - monitorp->gamma.red = conf_monitor->mon_gamma_red; + monitorp->gamma.red = conf_monitor->mon_gamma_red; if (conf_monitor->mon_gamma_green > GAMMA_ZERO) - monitorp->gamma.green = conf_monitor->mon_gamma_green; + monitorp->gamma.green = conf_monitor->mon_gamma_green; if (conf_monitor->mon_gamma_blue > GAMMA_ZERO) - monitorp->gamma.blue = conf_monitor->mon_gamma_blue; - + monitorp->gamma.blue = conf_monitor->mon_gamma_blue; + /* Check that the gamma values are within range */ if (monitorp->gamma.red > GAMMA_ZERO && - (monitorp->gamma.red < GAMMA_MIN || - monitorp->gamma.red > GAMMA_MAX)) { - badgamma = monitorp->gamma.red; - } else if (monitorp->gamma.green > GAMMA_ZERO && - (monitorp->gamma.green < GAMMA_MIN || - monitorp->gamma.green > GAMMA_MAX)) { - badgamma = monitorp->gamma.green; - } else if (monitorp->gamma.blue > GAMMA_ZERO && - (monitorp->gamma.blue < GAMMA_MIN || - monitorp->gamma.blue > GAMMA_MAX)) { - badgamma = monitorp->gamma.blue; + (monitorp->gamma.red < GAMMA_MIN || monitorp->gamma.red > GAMMA_MAX)) { + badgamma = monitorp->gamma.red; + } + else if (monitorp->gamma.green > GAMMA_ZERO && + (monitorp->gamma.green < GAMMA_MIN || + monitorp->gamma.green > GAMMA_MAX)) { + badgamma = monitorp->gamma.green; + } + else if (monitorp->gamma.blue > GAMMA_ZERO && + (monitorp->gamma.blue < GAMMA_MIN || + monitorp->gamma.blue > GAMMA_MAX)) { + badgamma = monitorp->gamma.blue; } if (badgamma > GAMMA_ZERO) { - xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n", - badgamma, GAMMA_MIN, GAMMA_MAX); - return FALSE; + xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n", + badgamma, GAMMA_MIN, GAMMA_MAX); + return FALSE; } xf86ProcessOptions(-1, monitorp->options, MonitorOptions); xf86GetOptValBool(MonitorOptions, MON_REDUCEDBLANKING, &monitorp->reducedblanking); if (xf86GetOptValFreq(MonitorOptions, MON_MAX_PIX_CLOCK, OPTUNITS_KHZ, - &maxPixClock) == TRUE) { - monitorp->maxPixClock = (int) maxPixClock; + &maxPixClock) == TRUE) { + monitorp->maxPixClock = (int) maxPixClock; } - + return TRUE; } @@ -2006,71 +2048,71 @@ lookupVisual(const char *visname) int i; if (!visname || !*visname) - return -1; + return -1; for (i = 0; i <= DirectColor; i++) { - if (!xf86nameCompare(visname, xf86VisualNames[i])) - break; + if (!xf86nameCompare(visname, xf86VisualNames[i])) + break; } if (i <= DirectColor) - return i; + return i; return -1; } - static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display) { int count = 0; XF86ModePtr modep; - - displayp->frameX0 = conf_display->disp_frameX0; - displayp->frameY0 = conf_display->disp_frameY0; - displayp->virtualX = conf_display->disp_virtualX; - displayp->virtualY = conf_display->disp_virtualY; - displayp->depth = conf_display->disp_depth; - displayp->fbbpp = conf_display->disp_bpp; - displayp->weight.red = conf_display->disp_weight.red; - displayp->weight.green = conf_display->disp_weight.green; - displayp->weight.blue = conf_display->disp_weight.blue; - displayp->blackColour.red = conf_display->disp_black.red; + + displayp->frameX0 = conf_display->disp_frameX0; + displayp->frameY0 = conf_display->disp_frameY0; + displayp->virtualX = conf_display->disp_virtualX; + displayp->virtualY = conf_display->disp_virtualY; + displayp->depth = conf_display->disp_depth; + displayp->fbbpp = conf_display->disp_bpp; + displayp->weight.red = conf_display->disp_weight.red; + displayp->weight.green = conf_display->disp_weight.green; + displayp->weight.blue = conf_display->disp_weight.blue; + displayp->blackColour.red = conf_display->disp_black.red; displayp->blackColour.green = conf_display->disp_black.green; - displayp->blackColour.blue = conf_display->disp_black.blue; - displayp->whiteColour.red = conf_display->disp_white.red; + displayp->blackColour.blue = conf_display->disp_black.blue; + displayp->whiteColour.red = conf_display->disp_white.red; displayp->whiteColour.green = conf_display->disp_white.green; - displayp->whiteColour.blue = conf_display->disp_white.blue; - displayp->options = conf_display->disp_option_lst; + displayp->whiteColour.blue = conf_display->disp_white.blue; + displayp->options = conf_display->disp_option_lst; if (conf_display->disp_visual) { - displayp->defaultVisual = lookupVisual(conf_display->disp_visual); - if (displayp->defaultVisual == -1) { - xf86ConfigError("Invalid visual name: \"%s\"", - conf_display->disp_visual); - return FALSE; - } - } else { - displayp->defaultVisual = -1; - } - + displayp->defaultVisual = lookupVisual(conf_display->disp_visual); + if (displayp->defaultVisual == -1) { + xf86ConfigError("Invalid visual name: \"%s\"", + conf_display->disp_visual); + return FALSE; + } + } + else { + displayp->defaultVisual = -1; + } + /* * now hook in the modes */ modep = conf_display->disp_mode_lst; - while(modep) { + while (modep) { count++; - modep = (XF86ModePtr)modep->list.next; + modep = (XF86ModePtr) modep->list.next; } - displayp->modes = xnfalloc((count+1) * sizeof(char*)); + displayp->modes = xnfalloc((count + 1) * sizeof(char *)); modep = conf_display->disp_mode_lst; count = 0; - while(modep) { + while (modep) { displayp->modes[count] = modep->mode_name; count++; - modep = (XF86ModePtr)modep->list.next; + modep = (XF86ModePtr) modep->list.next; } displayp->modes[count] = NULL; - + return TRUE; } @@ -2084,11 +2126,11 @@ configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active) } if (active) - xf86Msg(X_CONFIG, "| |-->Device \"%s\"\n", - conf_device->dev_identifier); + xf86Msg(X_CONFIG, "| |-->Device \"%s\"\n", + conf_device->dev_identifier); else - xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n", - conf_device->dev_identifier); + xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n", + conf_device->dev_identifier); devicep->identifier = conf_device->dev_identifier; devicep->vendor = conf_device->dev_vendor; @@ -2111,16 +2153,16 @@ configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active) devicep->screen = conf_device->dev_screen; for (i = 0; i < MAXDACSPEEDS; i++) { - if (i < CONF_MAXDACSPEEDS) + if (i < CONF_MAXDACSPEEDS) devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i]; - else - devicep->dacSpeeds[i] = 0; + else + devicep->dacSpeeds[i] = 0; } devicep->numclocks = conf_device->dev_clocks; if (devicep->numclocks > MAXCLOCKS) - devicep->numclocks = MAXCLOCKS; + devicep->numclocks = MAXCLOCKS; for (i = 0; i < devicep->numclocks; i++) { - devicep->clock[i] = conf_device->dev_clock[i]; + devicep->clock[i] = conf_device->dev_clock[i]; } devicep->claimed = FALSE; @@ -2131,20 +2173,21 @@ configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active) static void configDRI(XF86ConfDRIPtr drip) { - struct group *grp; + struct group *grp; - xf86ConfigDRI.group = -1; - xf86ConfigDRI.mode = 0; + xf86ConfigDRI.group = -1; + xf86ConfigDRI.mode = 0; if (drip) { - if (drip->dri_group_name) { - if ((grp = getgrnam(drip->dri_group_name))) - xf86ConfigDRI.group = grp->gr_gid; - } else { - if (drip->dri_group >= 0) - xf86ConfigDRI.group = drip->dri_group; - } - xf86ConfigDRI.mode = drip->dri_mode; + if (drip->dri_group_name) { + if ((grp = getgrnam(drip->dri_group_name))) + xf86ConfigDRI.group = grp->gr_gid; + } + else { + if (drip->dri_group >= 0) + xf86ConfigDRI.group = drip->dri_group; + } + xf86ConfigDRI.mode = drip->dri_mode; } } #endif @@ -2155,49 +2198,51 @@ configExtensions(XF86ConfExtensionsPtr conf_ext) XF86OptionPtr o; if (conf_ext && conf_ext->ext_option_lst) { - for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) { - char *name = xf86OptionName(o); - char *val = xf86OptionValue(o); - char *n; - Bool enable = TRUE; - - /* Handle "No<ExtensionName>" */ - n = xf86NormalizeName(name); - if (strncmp(n, "no", 2) == 0) { - name += 2; - enable = FALSE; - } - - if (!val || - xf86NameCmp(val, "enable") == 0 || - xf86NameCmp(val, "enabled") == 0 || - xf86NameCmp(val, "on") == 0 || - xf86NameCmp(val, "1") == 0 || - xf86NameCmp(val, "yes") == 0 || - xf86NameCmp(val, "true") == 0) { - /* NOTHING NEEDED -- enabling is handled below */ - } else if (xf86NameCmp(val, "disable") == 0 || - xf86NameCmp(val, "disabled") == 0 || - xf86NameCmp(val, "off") == 0 || - xf86NameCmp(val, "0") == 0 || - xf86NameCmp(val, "no") == 0 || - xf86NameCmp(val, "false") == 0) { - enable = !enable; - } else { - xf86Msg(X_WARNING, "Ignoring unrecognized value \"%s\"\n", val); - free(n); - continue; - } - - if (EnableDisableExtension(name, enable)) { - xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n", - name, enable ? "enabled" : "disabled"); - } else { - xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n", + for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) { + char *name = xf86OptionName(o); + char *val = xf86OptionValue(o); + char *n; + Bool enable = TRUE; + + /* Handle "No<ExtensionName>" */ + n = xf86NormalizeName(name); + if (strncmp(n, "no", 2) == 0) { + name += 2; + enable = FALSE; + } + + if (!val || + xf86NameCmp(val, "enable") == 0 || + xf86NameCmp(val, "enabled") == 0 || + xf86NameCmp(val, "on") == 0 || + xf86NameCmp(val, "1") == 0 || + xf86NameCmp(val, "yes") == 0 || xf86NameCmp(val, "true") == 0) { + /* NOTHING NEEDED -- enabling is handled below */ + } + else if (xf86NameCmp(val, "disable") == 0 || + xf86NameCmp(val, "disabled") == 0 || + xf86NameCmp(val, "off") == 0 || + xf86NameCmp(val, "0") == 0 || + xf86NameCmp(val, "no") == 0 || + xf86NameCmp(val, "false") == 0) { + enable = !enable; + } + else { + xf86Msg(X_WARNING, "Ignoring unrecognized value \"%s\"\n", val); + free(n); + continue; + } + + if (EnableDisableExtension(name, enable)) { + xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n", + name, enable ? "enabled" : "disabled"); + } + else { + xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n", name); - } - free(n); - } + } + free(n); + } } } @@ -2219,12 +2264,11 @@ modeIsPresent(DisplayModePtr mode, MonPtr monitorp) DisplayModePtr knownmodes = monitorp->Modes; /* all I can think of is a linear search... */ - while(knownmodes != NULL) - { - if(!strcmp(mode->name, knownmodes->name) && - !(knownmodes->type & M_T_DEFAULT)) - return TRUE; - knownmodes = knownmodes->next; + while (knownmodes != NULL) { + if (!strcmp(mode->name, knownmodes->name) && + !(knownmodes->type & M_T_DEFAULT)) + return TRUE; + knownmodes = knownmodes->next; } return FALSE; } @@ -2236,16 +2280,15 @@ addDefaultModes(MonPtr monitorp) DisplayModePtr last = monitorp->Last; int i = 0; - for (i = 0; i < xf86NumDefaultModes; i++) - { - mode = xf86DuplicateMode(&xf86DefaultModes[i]); - if (!modeIsPresent(mode, monitorp)) - { - monitorp->Modes = xf86ModesAdd(monitorp->Modes, mode); - last = mode; - } else { - free(mode); - } + for (i = 0; i < xf86NumDefaultModes; i++) { + mode = xf86DuplicateMode(&xf86DefaultModes[i]); + if (!modeIsPresent(mode, monitorp)) { + monitorp->Modes = xf86ModesAdd(monitorp->Modes, mode); + last = mode; + } + else { + free(mode); + } } monitorp->Last = last; @@ -2253,27 +2296,25 @@ addDefaultModes(MonPtr monitorp) } static void -checkInput(serverLayoutPtr layout, Bool implicit_layout) { +checkInput(serverLayoutPtr layout, Bool implicit_layout) +{ checkCoreInputDevices(layout, implicit_layout); /* Unless we're forcing input devices, disable mouse/kbd devices in the * config. Otherwise the same physical device is added multiple times, * leading to duplicate events. */ - if (!xf86Info.forceInputDevices && layout->inputs) - { + if (!xf86Info.forceInputDevices && layout->inputs) { InputInfoPtr *dev = layout->inputs; BOOL warned = FALSE; - while(*dev) - { + while (*dev) { if (strcmp((*dev)->driver, "kbd") == 0 || strcmp((*dev)->driver, "mouse") == 0 || - strcmp((*dev)->driver, "vmmouse") == 0) - { + strcmp((*dev)->driver, "vmmouse") == 0) { InputInfoPtr *current; - if (!warned) - { + + if (!warned) { xf86Msg(X_WARNING, "Hotplugging is on, devices using " "drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.\n"); warned = TRUE; @@ -2287,8 +2328,9 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) { do { *current = *(current + 1); current++; - } while(*current); - } else + } while (*current); + } + else dev++; } } @@ -2305,63 +2347,66 @@ xf86HandleConfigFile(Bool autoconfig) Bool implicit_layout = FALSE; if (!autoconfig) { - char *filename, *dirname, *sysdirname; - const char *filesearch, *dirsearch; - MessageType filefrom = X_DEFAULT; - MessageType dirfrom = X_DEFAULT; - - if (!xf86PrivsElevated()) { - filesearch = ALL_CONFIGPATH; - dirsearch = ALL_CONFIGDIRPATH; - } else { - filesearch = RESTRICTED_CONFIGPATH; - dirsearch = RESTRICTED_CONFIGDIRPATH; - } - - if (xf86ConfigFile) - filefrom = X_CMDLINE; - if (xf86ConfigDir) - dirfrom = X_CMDLINE; - - xf86initConfigFiles(); - sysdirname = xf86openConfigDirFiles(SYS_CONFIGDIRPATH, NULL, - PROJECTROOT); - dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT); - filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT); - if (filename) { - xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename); - xf86ConfigFile = xnfstrdup(filename); - } else { - if (xf86ConfigFile) - xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n", - xf86ConfigFile); - } - if (dirname) { - xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n", - dirname); - xf86ConfigDir = xnfstrdup(dirname); - } else { - if (xf86ConfigDir) - xf86Msg(X_ERROR, - "Unable to locate/open config directory: \"%s\"\n", - xf86ConfigDir); - } - if (sysdirname) - xf86MsgVerb(X_DEFAULT, 0, "Using system config directory \"%s\"\n", - sysdirname); - if (!filename && !dirname && !sysdirname) - return CONFIG_NOFILE; - - free(filename); - free(dirname); - free(sysdirname); - } - - if ((xf86configptr = xf86readConfigFile ()) == NULL) { - xf86Msg(X_ERROR, "Problem parsing the config file\n"); - return CONFIG_PARSE_ERROR; - } - xf86closeConfigFile (); + char *filename, *dirname, *sysdirname; + const char *filesearch, *dirsearch; + MessageType filefrom = X_DEFAULT; + MessageType dirfrom = X_DEFAULT; + + if (!xf86PrivsElevated()) { + filesearch = ALL_CONFIGPATH; + dirsearch = ALL_CONFIGDIRPATH; + } + else { + filesearch = RESTRICTED_CONFIGPATH; + dirsearch = RESTRICTED_CONFIGDIRPATH; + } + + if (xf86ConfigFile) + filefrom = X_CMDLINE; + if (xf86ConfigDir) + dirfrom = X_CMDLINE; + + xf86initConfigFiles(); + sysdirname = xf86openConfigDirFiles(SYS_CONFIGDIRPATH, NULL, + PROJECTROOT); + dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT); + filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT); + if (filename) { + xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename); + xf86ConfigFile = xnfstrdup(filename); + } + else { + if (xf86ConfigFile) + xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n", + xf86ConfigFile); + } + if (dirname) { + xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n", + dirname); + xf86ConfigDir = xnfstrdup(dirname); + } + else { + if (xf86ConfigDir) + xf86Msg(X_ERROR, + "Unable to locate/open config directory: \"%s\"\n", + xf86ConfigDir); + } + if (sysdirname) + xf86MsgVerb(X_DEFAULT, 0, "Using system config directory \"%s\"\n", + sysdirname); + if (!filename && !dirname && !sysdirname) + return CONFIG_NOFILE; + + free(filename); + free(dirname); + free(sysdirname); + } + + if ((xf86configptr = xf86readConfigFile()) == NULL) { + xf86Msg(X_ERROR, "Problem parsing the config file\n"); + return CONFIG_PARSE_ERROR; + } + xf86closeConfigFile(); /* Initialise a few things. */ @@ -2377,59 +2422,65 @@ xf86HandleConfigFile(Bool autoconfig) /* First check if a layout section is present, and if it is valid. */ if (xf86configptr->conf_layout_lst == NULL || xf86ScreenName != NULL) { - if (xf86ScreenName == NULL) { - xf86Msg(X_DEFAULT, - "No Layout section. Using the first Screen section.\n"); - } - if (!configImpliedLayout(&xf86ConfigLayout, - xf86configptr->conf_screen_lst, - xf86configptr)) { + if (xf86ScreenName == NULL) { + xf86Msg(X_DEFAULT, + "No Layout section. Using the first Screen section.\n"); + } + if (!configImpliedLayout(&xf86ConfigLayout, + xf86configptr->conf_screen_lst, + xf86configptr)) { xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - implicit_layout = TRUE; - } else { - if (xf86configptr->conf_flags != NULL) { - char *dfltlayout = NULL; - pointer optlist = xf86configptr->conf_flags->flg_option_lst; - - if (optlist && xf86FindOption(optlist, "defaultserverlayout")) - dfltlayout = xf86SetStrOption(optlist, "defaultserverlayout", NULL); - if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst, - dfltlayout)) { - xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - } else { - if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst, - NULL)) { - xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - } + return CONFIG_PARSE_ERROR; + } + implicit_layout = TRUE; + } + else { + if (xf86configptr->conf_flags != NULL) { + char *dfltlayout = NULL; + pointer optlist = xf86configptr->conf_flags->flg_option_lst; + + if (optlist && xf86FindOption(optlist, "defaultserverlayout")) + dfltlayout = + xf86SetStrOption(optlist, "defaultserverlayout", NULL); + if (!configLayout + (&xf86ConfigLayout, xf86configptr->conf_layout_lst, + dfltlayout)) { + xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); + return CONFIG_PARSE_ERROR; + } + } + else { + if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst, + NULL)) { + xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); + return CONFIG_PARSE_ERROR; + } + } } xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions); #ifdef XSERVER_LIBPCIACCESS if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) { - ; /* IsolateDevice specified; overrides SingleCard */ - } else { - xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard); - if (singlecard) - scanptr = xf86ConfigLayout.screens->screen->device->busID; + ; /* IsolateDevice specified; overrides SingleCard */ + } + else { + xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard); + if (singlecard) + scanptr = xf86ConfigLayout.screens->screen->device->busID; } if (scanptr) { - if (strncmp(scanptr, "PCI:", 4) != 0) { - xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n" - "\tIgnoring IsolateDevice option.\n"); - } else - xf86PciIsolateDevice(scanptr); + if (strncmp(scanptr, "PCI:", 4) != 0) { + xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n" + "\tIgnoring IsolateDevice option.\n"); + } + else + xf86PciIsolateDevice(scanptr); } #endif /* Now process everything else */ - if (!configServerFlags(xf86configptr->conf_flags,xf86ConfigLayout.options)){ - ErrorF ("Problem when converting the config data structures\n"); - return CONFIG_PARSE_ERROR; + if (!configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options)) { + ErrorF("Problem when converting the config data structures\n"); + return CONFIG_PARSE_ERROR; } configFiles(xf86configptr->conf_files); @@ -2446,13 +2497,13 @@ xf86HandleConfigFile(Bool autoconfig) */ #ifdef XF86VIDMODE if (xf86VidModeDisabled) - xf86Info.vidModeEnabled = FALSE; + xf86Info.vidModeEnabled = FALSE; if (xf86VidModeAllowNonLocal) - xf86Info.vidModeAllowNonLocal = TRUE; + xf86Info.vidModeAllowNonLocal = TRUE; #endif if (xf86AllowMouseOpenFail) - xf86Info.allowMouseOpenFail = TRUE; + xf86Info.allowMouseOpenFail = TRUE; return CONFIG_OK; } diff --git a/xorg-server/hw/xfree86/common/xf86Configure.c b/xorg-server/hw/xfree86/common/xf86Configure.c index 994d46fc2..6f69117d3 100644 --- a/xorg-server/hw/xfree86/common/xf86Configure.c +++ b/xorg-server/hw/xfree86/common/xf86Configure.c @@ -43,7 +43,7 @@ typedef struct _DevToConfig { GDevRec GDev; - struct pci_device * pVideo; + struct pci_device *pVideo; #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) sbusDevicePtr sVideo; #endif @@ -77,28 +77,29 @@ static const char *DFLT_MOUSE_PROTO = "auto"; * the caller fill in the rest and/or change it as it sees fit. */ GDevPtr -xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int chipset) +xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, + int chipset) { int ret, i, j; if (!xf86DoConfigure || !xf86DoConfigurePass1) - return NULL; + return NULL; /* Check for duplicates */ - for (i = 0; i < nDevToConfig; i++) { + for (i = 0; i < nDevToConfig; i++) { switch (bus) { #ifdef XSERVER_LIBPCIACCESS - case BUS_PCI: - ret = xf86PciConfigure(busData, DevToConfig[i].pVideo); - break; + case BUS_PCI: + ret = xf86PciConfigure(busData, DevToConfig[i].pVideo); + break; #endif #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - case BUS_SBUS: - ret = xf86SbusConfigure(busData, DevToConfig[i].sVideo); - break; + case BUS_SBUS: + ret = xf86SbusConfigure(busData, DevToConfig[i].sVideo); + break; #endif - default: - return NULL; + default: + return NULL; } if (ret == 0) goto out; @@ -107,112 +108,113 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int /* Allocate new structure occurrence */ i = nDevToConfig++; DevToConfig = - xnfrealloc(DevToConfig, nDevToConfig * sizeof(DevToConfigRec)); + xnfrealloc(DevToConfig, nDevToConfig * sizeof(DevToConfigRec)); memset(DevToConfig + i, 0, sizeof(DevToConfigRec)); DevToConfig[i].GDev.chipID = - DevToConfig[i].GDev.chipRev = DevToConfig[i].GDev.irq = -1; + DevToConfig[i].GDev.chipRev = DevToConfig[i].GDev.irq = -1; DevToConfig[i].iDriver = CurrentDriver; /* Fill in what we know, converting the driver name to lower case */ DevToConfig[i].GDev.driver = xnfalloc(strlen(driver) + 1); - for (j = 0; (DevToConfig[i].GDev.driver[j] = tolower(driver[j])); j++); + for (j = 0; (DevToConfig[i].GDev.driver[j] = tolower(driver[j])); j++); switch (bus) { #ifdef XSERVER_LIBPCIACCESS - case BUS_PCI: - xf86PciConfigureNewDev(busData, DevToConfig[i].pVideo, - &DevToConfig[i].GDev, &chipset); - break; + case BUS_PCI: + xf86PciConfigureNewDev(busData, DevToConfig[i].pVideo, + &DevToConfig[i].GDev, &chipset); + break; #endif #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - case BUS_SBUS: - xf86SbusConfigureNewDev(busData, DevToConfig[i].sVideo, - &DevToConfig[i].GDev); - break; + case BUS_SBUS: + xf86SbusConfigureNewDev(busData, DevToConfig[i].sVideo, + &DevToConfig[i].GDev); + break; #endif - default: - break; + default: + break; } /* Get driver's available options */ if (xf86DriverList[CurrentDriver]->AvailableOptions) - DevToConfig[i].GDev.options = (OptionInfoPtr) - (*xf86DriverList[CurrentDriver]->AvailableOptions)(chipset, - bus); + DevToConfig[i].GDev.options = (OptionInfoPtr) + (*xf86DriverList[CurrentDriver]->AvailableOptions) (chipset, bus); return &DevToConfig[i].GDev; -out: + out: return NULL; } static XF86ConfInputPtr -configureInputSection (void) +configureInputSection(void) { XF86ConfInputPtr mouse = NULL; - parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) - ptr->inp_identifier = "Keyboard0"; + parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) + + ptr->inp_identifier = "Keyboard0"; ptr->inp_driver = "kbd"; ptr->list.next = NULL; /* Crude mechanism to auto-detect mouse (os dependent) */ - { - int fd; + { + int fd; - fd = open(DFLT_MOUSE_DEV, 0); - if (fd != -1) { - foundMouse = TRUE; - close(fd); - } + fd = open(DFLT_MOUSE_DEV, 0); + if (fd != -1) { + foundMouse = TRUE; + close(fd); + } } mouse = calloc(1, sizeof(XF86ConfInputRec)); mouse->inp_identifier = "Mouse0"; mouse->inp_driver = "mouse"; - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("Protocol"), - strdup(DFLT_MOUSE_PROTO)); - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("Device"), - strdup(DFLT_MOUSE_DEV)); - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("ZAxisMapping"), - strdup("4 5 6 7")); - ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse); + mouse->inp_option_lst = + xf86addNewOption(mouse->inp_option_lst, strdup("Protocol"), + strdup(DFLT_MOUSE_PROTO)); + mouse->inp_option_lst = + xf86addNewOption(mouse->inp_option_lst, strdup("Device"), + strdup(DFLT_MOUSE_DEV)); + mouse->inp_option_lst = + xf86addNewOption(mouse->inp_option_lst, strdup("ZAxisMapping"), + strdup("4 5 6 7")); + ptr = (XF86ConfInputPtr) xf86addListItem((glp) ptr, (glp) mouse); return ptr; } static XF86ConfScreenPtr -configureScreenSection (int screennum) +configureScreenSection(int screennum) { int i; - int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ }; - parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec) + int depths[] = { 1, 4, 8, 15, 16, 24 /*, 32 */ }; + parsePrologue(XF86ConfScreenPtr, XF86ConfScreenRec) - XNFasprintf(&ptr->scrn_identifier, "Screen%d", screennum); + XNFasprintf(&ptr->scrn_identifier, "Screen%d", screennum); XNFasprintf(&ptr->scrn_monitor_str, "Monitor%d", screennum); XNFasprintf(&ptr->scrn_device_str, "Card%d", screennum); - for (i=0; i<sizeof(depths)/sizeof(depths[0]); i++) - { - XF86ConfDisplayPtr display; - - display = calloc(1, sizeof(XF86ConfDisplayRec)); - display->disp_depth = depths[i]; - display->disp_black.red = display->disp_white.red = -1; - display->disp_black.green = display->disp_white.green = -1; - display->disp_black.blue = display->disp_white.blue = -1; - ptr->scrn_display_lst = (XF86ConfDisplayPtr)xf86addListItem( - (glp)ptr->scrn_display_lst, (glp)display); + for (i = 0; i < sizeof(depths) / sizeof(depths[0]); i++) { + XF86ConfDisplayPtr display; + + display = calloc(1, sizeof(XF86ConfDisplayRec)); + display->disp_depth = depths[i]; + display->disp_black.red = display->disp_white.red = -1; + display->disp_black.green = display->disp_white.green = -1; + display->disp_black.blue = display->disp_white.blue = -1; + ptr->scrn_display_lst = (XF86ConfDisplayPtr) xf86addListItem((glp) ptr-> + scrn_display_lst, + (glp) + display); } return ptr; } -static const char* +static const char * optionTypeToString(OptionValueType type) { switch (type) { @@ -223,7 +225,7 @@ optionTypeToString(OptionValueType type) case OPTV_STRING: return "<str>"; case OPTV_ANYSTR: - return "[<str>]"; + return "[<str>]"; case OPTV_REAL: return "<f>"; case OPTV_BOOLEAN: @@ -238,20 +240,21 @@ optionTypeToString(OptionValueType type) } static XF86ConfDevicePtr -configureDeviceSection (int screennum) +configureDeviceSection(int screennum) { OptionInfoPtr p; int i = 0; - parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec) - /* Move device info to parser structure */ - if (asprintf(&ptr->dev_identifier, "Card%d", screennum) == -1) + parsePrologue(XF86ConfDevicePtr, XF86ConfDeviceRec) + + /* Move device info to parser structure */ + if (asprintf(&ptr->dev_identifier, "Card%d", screennum) == -1) ptr->dev_identifier = NULL; ptr->dev_chipset = DevToConfig[screennum].GDev.chipset; ptr->dev_busid = DevToConfig[screennum].GDev.busID; ptr->dev_driver = DevToConfig[screennum].GDev.driver; ptr->dev_ramdac = DevToConfig[screennum].GDev.ramdac; - for (i = 0; (i < MAXDACSPEEDS) && (i < CONF_MAXDACSPEEDS); i++) + for (i = 0; (i < MAXDACSPEEDS) && (i < CONF_MAXDACSPEEDS); i++) ptr->dev_dacSpeeds[i] = DevToConfig[screennum].GDev.dacSpeeds[i]; ptr->dev_videoram = DevToConfig[screennum].GDev.videoRam; ptr->dev_textclockfreq = DevToConfig[screennum].GDev.textClockFreq; @@ -259,7 +262,8 @@ configureDeviceSection (int screennum) ptr->dev_mem_base = DevToConfig[screennum].GDev.MemBase; ptr->dev_io_base = DevToConfig[screennum].GDev.IOBase; ptr->dev_clockchip = DevToConfig[screennum].GDev.clockchip; - for (i = 0; (i < MAXCLOCKS) && (i < DevToConfig[screennum].GDev.numclocks); i++) + for (i = 0; (i < MAXCLOCKS) && (i < DevToConfig[screennum].GDev.numclocks); + i++) ptr->dev_clock[i] = DevToConfig[screennum].GDev.clock[i]; ptr->dev_clocks = i; ptr->dev_chipid = DevToConfig[screennum].GDev.chipID; @@ -268,161 +272,165 @@ configureDeviceSection (int screennum) /* Make sure older drivers don't segv */ if (DevToConfig[screennum].GDev.options) { - /* Fill in the available driver options for people to use */ - const char *descrip = - " ### Available Driver options are:-\n" - " ### Values: <i>: integer, <f>: float, " - "<bool>: \"True\"/\"False\",\n" - " ### <string>: \"String\", <freq>: \"<f> Hz/kHz/MHz\",\n" - " ### <percent>: \"<f>%\"\n" - " ### [arg]: arg optional\n"; - ptr->dev_comment = strdup(descrip); - if (ptr->dev_comment) { - for (p = DevToConfig[screennum].GDev.options; - p->name != NULL; p++) { - char *p_e; - const char *prefix = " #Option "; - const char *middle = " \t# "; - const char *suffix = "\n"; - const char *opttype = optionTypeToString(p->type); - char *optname; - int len = strlen(ptr->dev_comment) + strlen(prefix) + - strlen(middle) + strlen(suffix) + 1; - - if (asprintf(&optname, "\"%s\"", p->name) == -1) - break; - - len += max(20, strlen(optname)); - len += strlen(opttype); - - ptr->dev_comment = realloc(ptr->dev_comment, len); - if (!ptr->dev_comment) - break; - p_e = ptr->dev_comment + strlen(ptr->dev_comment); - sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, - opttype, suffix); - free(optname); - } - } + /* Fill in the available driver options for people to use */ + const char *descrip = + " ### Available Driver options are:-\n" + " ### Values: <i>: integer, <f>: float, " + "<bool>: \"True\"/\"False\",\n" + " ### <string>: \"String\", <freq>: \"<f> Hz/kHz/MHz\",\n" + " ### <percent>: \"<f>%\"\n" + " ### [arg]: arg optional\n"; + ptr->dev_comment = strdup(descrip); + if (ptr->dev_comment) { + for (p = DevToConfig[screennum].GDev.options; p->name != NULL; p++) { + char *p_e; + const char *prefix = " #Option "; + const char *middle = " \t# "; + const char *suffix = "\n"; + const char *opttype = optionTypeToString(p->type); + char *optname; + int len = strlen(ptr->dev_comment) + strlen(prefix) + + strlen(middle) + strlen(suffix) + 1; + + if (asprintf(&optname, "\"%s\"", p->name) == -1) + break; + + len += max(20, strlen(optname)); + len += strlen(opttype); + + ptr->dev_comment = realloc(ptr->dev_comment, len); + if (!ptr->dev_comment) + break; + p_e = ptr->dev_comment + strlen(ptr->dev_comment); + sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, + opttype, suffix); + free(optname); + } + } } return ptr; } static XF86ConfLayoutPtr -configureLayoutSection (void) +configureLayoutSection(void) { int scrnum = 0; - parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec) - ptr->lay_identifier = "X.org Configured"; + parsePrologue(XF86ConfLayoutPtr, XF86ConfLayoutRec) - { - XF86ConfInputrefPtr iptr; + ptr->lay_identifier = "X.org Configured"; - iptr = malloc (sizeof (XF86ConfInputrefRec)); - iptr->list.next = NULL; - iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = "Mouse0"; - iptr->iref_option_lst = - xf86addNewOption (iptr->iref_option_lst, strdup("CorePointer"), NULL); - ptr->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); + { + XF86ConfInputrefPtr iptr; + + iptr = malloc(sizeof(XF86ConfInputrefRec)); + iptr->list.next = NULL; + iptr->iref_option_lst = NULL; + iptr->iref_inputdev_str = "Mouse0"; + iptr->iref_option_lst = + xf86addNewOption(iptr->iref_option_lst, strdup("CorePointer"), + NULL); + ptr->lay_input_lst = (XF86ConfInputrefPtr) + xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); } { - XF86ConfInputrefPtr iptr; - - iptr = malloc (sizeof (XF86ConfInputrefRec)); - iptr->list.next = NULL; - iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = "Keyboard0"; - iptr->iref_option_lst = - xf86addNewOption (iptr->iref_option_lst, strdup("CoreKeyboard"), NULL); - ptr->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); - } - - for (scrnum = 0; scrnum < nDevToConfig; scrnum++) { - XF86ConfAdjacencyPtr aptr; - - aptr = malloc (sizeof (XF86ConfAdjacencyRec)); - aptr->list.next = NULL; - aptr->adj_x = 0; - aptr->adj_y = 0; - aptr->adj_scrnum = scrnum; - XNFasprintf(&aptr->adj_screen_str, "Screen%d", scrnum); - if (scrnum == 0) { - aptr->adj_where = CONF_ADJ_ABSOLUTE; - aptr->adj_refscreen = NULL; - } - else { - aptr->adj_where = CONF_ADJ_RIGHTOF; - XNFasprintf(&aptr->adj_refscreen, "Screen%d", scrnum - 1); - } - ptr->lay_adjacency_lst = - (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst, - (glp)aptr); + XF86ConfInputrefPtr iptr; + + iptr = malloc(sizeof(XF86ConfInputrefRec)); + iptr->list.next = NULL; + iptr->iref_option_lst = NULL; + iptr->iref_inputdev_str = "Keyboard0"; + iptr->iref_option_lst = + xf86addNewOption(iptr->iref_option_lst, strdup("CoreKeyboard"), + NULL); + ptr->lay_input_lst = (XF86ConfInputrefPtr) + xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); + } + + for (scrnum = 0; scrnum < nDevToConfig; scrnum++) { + XF86ConfAdjacencyPtr aptr; + + aptr = malloc(sizeof(XF86ConfAdjacencyRec)); + aptr->list.next = NULL; + aptr->adj_x = 0; + aptr->adj_y = 0; + aptr->adj_scrnum = scrnum; + XNFasprintf(&aptr->adj_screen_str, "Screen%d", scrnum); + if (scrnum == 0) { + aptr->adj_where = CONF_ADJ_ABSOLUTE; + aptr->adj_refscreen = NULL; + } + else { + aptr->adj_where = CONF_ADJ_RIGHTOF; + XNFasprintf(&aptr->adj_refscreen, "Screen%d", scrnum - 1); + } + ptr->lay_adjacency_lst = + (XF86ConfAdjacencyPtr) xf86addListItem((glp) ptr->lay_adjacency_lst, + (glp) aptr); } return ptr; } static XF86ConfFlagsPtr -configureFlagsSection (void) +configureFlagsSection(void) { - parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec) + parsePrologue(XF86ConfFlagsPtr, XF86ConfFlagsRec) - return ptr; + return ptr; } static XF86ConfModulePtr -configureModuleSection (void) +configureModuleSection(void) { char **elist, **el; + /* Find the list of extension & font modules. */ const char *esubdirs[] = { - "extensions", - "fonts", - NULL + "extensions", + "fonts", + NULL }; - parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec) + parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec) - elist = LoaderListDirs(esubdirs, NULL); + elist = LoaderListDirs(esubdirs, NULL); if (elist) { - for (el = elist; *el; el++) { - XF86LoadPtr module; - - module = calloc(1, sizeof(XF86LoadRec)); - module->load_name = *el; - ptr->mod_load_lst = (XF86LoadPtr)xf86addListItem( - (glp)ptr->mod_load_lst, (glp)module); - } - free(elist); + for (el = elist; *el; el++) { + XF86LoadPtr module; + + module = calloc(1, sizeof(XF86LoadRec)); + module->load_name = *el; + ptr->mod_load_lst = (XF86LoadPtr) xf86addListItem((glp) ptr-> + mod_load_lst, + (glp) module); + } + free(elist); } return ptr; } static XF86ConfFilesPtr -configureFilesSection (void) +configureFilesSection(void) { - parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec) + parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec) + + if (xf86ModulePath) + ptr->file_modulepath = strdup(xf86ModulePath); + if (defaultFontPath) + ptr->file_fontpath = strdup(defaultFontPath); - if (xf86ModulePath) - ptr->file_modulepath = strdup(xf86ModulePath); - if (defaultFontPath) - ptr->file_fontpath = strdup(defaultFontPath); - return ptr; } static XF86ConfMonitorPtr -configureMonitorSection (int screennum) +configureMonitorSection(int screennum) { - parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) + parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec) - XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup("Monitor Vendor"); ptr->mon_modelname = strdup("Monitor Model"); @@ -430,29 +438,24 @@ configureMonitorSection (int screennum) } /* Initialize Configure Monitor from Detailed Timing Block */ -static void handle_detailed_input(struct detailed_monitor_section *det_mon, - void *data) +static void +handle_detailed_input(struct detailed_monitor_section *det_mon, void *data) { XF86ConfMonitorPtr ptr = (XF86ConfMonitorPtr) data; switch (det_mon->type) { case DS_NAME: ptr->mon_modelname = realloc(ptr->mon_modelname, - strlen((char*)(det_mon->section.name)) + + strlen((char *) (det_mon->section.name)) + 1); - strcpy(ptr->mon_modelname, - (char*)(det_mon->section.name)); + strcpy(ptr->mon_modelname, (char *) (det_mon->section.name)); break; case DS_RANGES: - ptr->mon_hsync[ptr->mon_n_hsync].lo = - det_mon->section.ranges.min_h; - ptr->mon_hsync[ptr->mon_n_hsync].hi = - det_mon->section.ranges.max_h; + ptr->mon_hsync[ptr->mon_n_hsync].lo = det_mon->section.ranges.min_h; + ptr->mon_hsync[ptr->mon_n_hsync].hi = det_mon->section.ranges.max_h; ptr->mon_n_vrefresh = 1; - ptr->mon_vrefresh[ptr->mon_n_hsync].lo = - det_mon->section.ranges.min_v; - ptr->mon_vrefresh[ptr->mon_n_hsync].hi = - det_mon->section.ranges.max_v; + ptr->mon_vrefresh[ptr->mon_n_hsync].lo = det_mon->section.ranges.min_v; + ptr->mon_vrefresh[ptr->mon_n_hsync].hi = det_mon->section.ranges.max_v; ptr->mon_n_hsync++; default: break; @@ -460,53 +463,56 @@ static void handle_detailed_input(struct detailed_monitor_section *det_mon, } static XF86ConfMonitorPtr -configureDDCMonitorSection (int screennum) +configureDDCMonitorSection(int screennum) { int len, mon_width, mon_height; + #define displaySizeMaxLen 80 char displaySize_string[displaySizeMaxLen]; int displaySizeLen; - parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) + parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec) - XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name); XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); /* features in centimetres, we want millimetres */ - mon_width = 10 * ConfiguredMonitor->features.hsize ; - mon_height = 10 * ConfiguredMonitor->features.vsize ; + mon_width = 10 * ConfiguredMonitor->features.hsize; + mon_height = 10 * ConfiguredMonitor->features.vsize; #ifdef CONFIGURE_DISPLAYSIZE - ptr->mon_width = mon_width; + ptr->mon_width = mon_width; ptr->mon_height = mon_height; #else if (mon_width && mon_height) { - /* when values available add DisplaySize option AS A COMMENT */ - - displaySizeLen = snprintf(displaySize_string, displaySizeMaxLen, - "\t#DisplaySize\t%5d %5d\t# mm\n", - mon_width, mon_height); - - if (displaySizeLen>0 && displaySizeLen<displaySizeMaxLen) { - if (ptr->mon_comment) { - len = strlen(ptr->mon_comment); - } else { - len = 0; - } - if ((ptr->mon_comment = - realloc(ptr->mon_comment, len + strlen(displaySize_string) + 1))) { - strcpy(ptr->mon_comment + len, displaySize_string); - } - } + /* when values available add DisplaySize option AS A COMMENT */ + + displaySizeLen = snprintf(displaySize_string, displaySizeMaxLen, + "\t#DisplaySize\t%5d %5d\t# mm\n", + mon_width, mon_height); + + if (displaySizeLen > 0 && displaySizeLen < displaySizeMaxLen) { + if (ptr->mon_comment) { + len = strlen(ptr->mon_comment); + } + else { + len = 0; + } + if ((ptr->mon_comment = + realloc(ptr->mon_comment, + len + strlen(displaySize_string) + 1))) { + strcpy(ptr->mon_comment + len, displaySize_string); + } + } } -#endif /* def CONFIGURE_DISPLAYSIZE */ +#endif /* def CONFIGURE_DISPLAYSIZE */ - xf86ForEachDetailedBlock(ConfiguredMonitor, handle_detailed_input, - ptr); + xf86ForEachDetailedBlock(ConfiguredMonitor, handle_detailed_input, ptr); if (ConfiguredMonitor->features.dpms) { - ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, strdup("DPMS"), NULL); + ptr->mon_option_lst = + xf86addNewOption(ptr->mon_option_lst, strdup("DPMS"), NULL); } return ptr; @@ -515,7 +521,7 @@ configureDDCMonitorSection (int screennum) void DoConfigure(void) { - int i,j, screennum = -1; + int i, j, screennum = -1; const char *home = NULL; char filename[PATH_MAX]; const char *addslash = ""; @@ -526,13 +532,13 @@ DoConfigure(void) vlist = xf86DriverlistFromCompile(); if (!vlist) { - ErrorF("Missing output drivers. Configuration failed.\n"); - goto bail; + ErrorF("Missing output drivers. Configuration failed.\n"); + goto bail; } ErrorF("List of video drivers:\n"); for (vl = vlist; *vl; vl++) - ErrorF("\t%s\n", *vl); + ErrorF("\t%s\n", *vl); /* Load all the drivers that were found. */ xf86LoadModules(vlist, NULL); @@ -540,65 +546,71 @@ DoConfigure(void) free(vlist); for (i = 0; i < xf86NumDrivers; i++) { - xorgHWFlags flags; - if (!xf86DriverList[i]->driverFunc - || !xf86DriverList[i]->driverFunc(NULL, - GET_REQUIRED_HW_INTERFACES, - &flags) - || NEED_IO_ENABLED(flags)) { - xorgHWAccess = TRUE; - break; - } + xorgHWFlags flags; + + if (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) { + xorgHWAccess = TRUE; + break; + } } /* Enable full I/O access */ if (xorgHWAccess) { - if(!xf86EnableIO()) - /* oops, we have failed */ - xorgHWAccess = FALSE; + if (!xf86EnableIO()) + /* oops, we have failed */ + xorgHWAccess = FALSE; } /* Create XF86Config file structure */ xf86config = calloc(1, sizeof(XF86ConfigRec)); /* Call all of the probe functions, reporting the results. */ - for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { - xorgHWFlags flags; - Bool found_screen; - DriverRec * const drv = xf86DriverList[CurrentDriver]; - - if (!xorgHWAccess) { - if (!drv->driverFunc - || !drv->driverFunc( NULL, GET_REQUIRED_HW_INTERFACES, &flags ) - || NEED_IO_ENABLED(flags)) - continue; - } - - found_screen = xf86CallDriverProbe( drv, TRUE ); - if ( found_screen && drv->Identify ) { - (*drv->Identify)(0); - } + for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { + xorgHWFlags flags; + Bool found_screen; + DriverRec *const drv = xf86DriverList[CurrentDriver]; + + if (!xorgHWAccess) { + if (!drv->driverFunc + || !drv->driverFunc(NULL, GET_REQUIRED_HW_INTERFACES, &flags) + || NEED_IO_ENABLED(flags)) + continue; + } + + found_screen = xf86CallDriverProbe(drv, TRUE); + if (found_screen && drv->Identify) { + (*drv->Identify) (0); + } } if (nDevToConfig <= 0) { - ErrorF("No devices to configure. Configuration failed.\n"); - goto bail; + ErrorF("No devices to configure. Configuration failed.\n"); + goto bail; } /* Add device, monitor and screen sections for detected devices */ - for (screennum = 0; screennum < nDevToConfig; screennum++) { - XF86ConfDevicePtr DevicePtr; - XF86ConfMonitorPtr MonitorPtr; - XF86ConfScreenPtr ScreenPtr; - - DevicePtr = configureDeviceSection(screennum); - xf86config->conf_device_lst = (XF86ConfDevicePtr)xf86addListItem( - (glp)xf86config->conf_device_lst, (glp)DevicePtr); - MonitorPtr = configureMonitorSection(screennum); - xf86config->conf_monitor_lst = (XF86ConfMonitorPtr)xf86addListItem( - (glp)xf86config->conf_monitor_lst, (glp)MonitorPtr); - ScreenPtr = configureScreenSection(screennum); - xf86config->conf_screen_lst = (XF86ConfScreenPtr)xf86addListItem( - (glp)xf86config->conf_screen_lst, (glp)ScreenPtr); + for (screennum = 0; screennum < nDevToConfig; screennum++) { + XF86ConfDevicePtr DevicePtr; + XF86ConfMonitorPtr MonitorPtr; + XF86ConfScreenPtr ScreenPtr; + + DevicePtr = configureDeviceSection(screennum); + xf86config->conf_device_lst = (XF86ConfDevicePtr) xf86addListItem((glp) + xf86config-> + conf_device_lst, + (glp) + DevicePtr); + MonitorPtr = configureMonitorSection(screennum); + xf86config->conf_monitor_lst = (XF86ConfMonitorPtr) xf86addListItem((glp) xf86config->conf_monitor_lst, (glp) MonitorPtr); + ScreenPtr = configureScreenSection(screennum); + xf86config->conf_screen_lst = (XF86ConfScreenPtr) xf86addListItem((glp) + xf86config-> + conf_screen_lst, + (glp) + ScreenPtr); } xf86config->conf_files = configureFilesSection(); @@ -613,91 +625,95 @@ DoConfigure(void) home = getenv("HOME"); if ((home == NULL) || (home[0] == '\0')) { - home = "/"; - } else { - /* Determine if trailing slash is present or needed */ - int l = strlen(home); + home = "/"; + } + else { + /* Determine if trailing slash is present or needed */ + int l = strlen(home); - if (home[l-1] != '/') { - addslash = "/"; - } + if (home[l - 1] != '/') { + addslash = "/"; + } } snprintf(filename, sizeof(filename), "%s%s" XF86CONFIGFILE ".new", - home, addslash); + home, addslash); if (xf86writeConfigFile(filename, xf86config) == 0) { - xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", - filename, strerror(errno)); - goto bail; + xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", + filename, strerror(errno)); + goto bail; } xf86DoConfigurePass1 = FALSE; /* Try to get DDC information filled in */ xf86ConfigFile = filename; if (xf86HandleConfigFile(FALSE) != CONFIG_OK) { - goto bail; + goto bail; } xf86DoConfigurePass1 = FALSE; - - dev2screen = xnfcalloc(1,xf86NumDrivers*sizeof(int)); + + dev2screen = xnfcalloc(1, xf86NumDrivers * sizeof(int)); { - Bool *driverProbed = xnfcalloc(1,xf86NumDrivers*sizeof(Bool)); - for (screennum = 0; screennum < nDevToConfig; screennum++) { - int k,l,n,oldNumScreens; - - i = DevToConfig[screennum].iDriver; - - if (driverProbed[i]) continue; - driverProbed[i] = TRUE; - - oldNumScreens = xf86NumScreens; - - xf86CallDriverProbe( xf86DriverList[i], FALSE ); - - /* reorder */ - k = screennum > 0 ? screennum : 1; - for (l = oldNumScreens; l < xf86NumScreens; l++) { - /* is screen primary? */ - Bool primary = FALSE; - for (n = 0; n<xf86Screens[l]->numEntities; n++) { - if (xf86IsEntityPrimary(xf86Screens[l]->entityList[n])) { - dev2screen[0] = l; - primary = TRUE; - break; - } - } - if (primary) continue; - /* not primary: assign it to next device of same driver */ - /* - * NOTE: we assume that devices in DevToConfig - * and xf86Screens[] have the same order except - * for the primary device which always comes first. - */ - for (; k < nDevToConfig; k++) { - if (DevToConfig[k].iDriver == i) { - dev2screen[k++] = l; - break; - } - } - } - } - free(driverProbed); - } - + Bool *driverProbed = xnfcalloc(1, xf86NumDrivers * sizeof(Bool)); + + for (screennum = 0; screennum < nDevToConfig; screennum++) { + int k, l, n, oldNumScreens; + + i = DevToConfig[screennum].iDriver; + + if (driverProbed[i]) + continue; + driverProbed[i] = TRUE; + + oldNumScreens = xf86NumScreens; + + xf86CallDriverProbe(xf86DriverList[i], FALSE); + + /* reorder */ + k = screennum > 0 ? screennum : 1; + for (l = oldNumScreens; l < xf86NumScreens; l++) { + /* is screen primary? */ + Bool primary = FALSE; + + for (n = 0; n < xf86Screens[l]->numEntities; n++) { + if (xf86IsEntityPrimary(xf86Screens[l]->entityList[n])) { + dev2screen[0] = l; + primary = TRUE; + break; + } + } + if (primary) + continue; + /* not primary: assign it to next device of same driver */ + /* + * NOTE: we assume that devices in DevToConfig + * and xf86Screens[] have the same order except + * for the primary device which always comes first. + */ + for (; k < nDevToConfig; k++) { + if (DevToConfig[k].iDriver == i) { + dev2screen[k++] = l; + break; + } + } + } + } + free(driverProbed); + } if (nDevToConfig != xf86NumScreens) { - ErrorF("Number of created screens does not match number of detected" - " devices.\n Configuration failed.\n"); - goto bail; + ErrorF("Number of created screens does not match number of detected" + " devices.\n Configuration failed.\n"); + goto bail; } xf86PostProbe(); for (j = 0; j < xf86NumScreens; j++) { - xf86Screens[j]->scrnIndex = j; + xf86Screens[j]->scrnIndex = j; } xf86freeMonitorList(xf86config->conf_monitor_lst); @@ -705,53 +721,57 @@ DoConfigure(void) xf86freeScreenList(xf86config->conf_screen_lst); xf86config->conf_screen_lst = NULL; for (j = 0; j < xf86NumScreens; j++) { - XF86ConfMonitorPtr MonitorPtr; - XF86ConfScreenPtr ScreenPtr; + XF86ConfMonitorPtr MonitorPtr; + XF86ConfScreenPtr ScreenPtr; - ConfiguredMonitor = NULL; + ConfiguredMonitor = NULL; - if ((*xf86Screens[dev2screen[j]]->PreInit)(xf86Screens[dev2screen[j]], - PROBE_DETECT) && - ConfiguredMonitor) { - MonitorPtr = configureDDCMonitorSection(j); - } else { - MonitorPtr = configureMonitorSection(j); - } - ScreenPtr = configureScreenSection(j); - xf86config->conf_monitor_lst = (XF86ConfMonitorPtr)xf86addListItem( - (glp)xf86config->conf_monitor_lst, (glp)MonitorPtr); - xf86config->conf_screen_lst = (XF86ConfScreenPtr)xf86addListItem( - (glp)xf86config->conf_screen_lst, (glp)ScreenPtr); + if ((*xf86Screens[dev2screen[j]]->PreInit) (xf86Screens[dev2screen[j]], + PROBE_DETECT) && + ConfiguredMonitor) { + MonitorPtr = configureDDCMonitorSection(j); + } + else { + MonitorPtr = configureMonitorSection(j); + } + ScreenPtr = configureScreenSection(j); + + xf86config->conf_monitor_lst = (XF86ConfMonitorPtr) xf86addListItem((glp) xf86config->conf_monitor_lst, (glp) MonitorPtr); + xf86config->conf_screen_lst = (XF86ConfScreenPtr) xf86addListItem((glp) + xf86config-> + conf_screen_lst, + (glp) + ScreenPtr); } if (xf86writeConfigFile(filename, xf86config) == 0) { - xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", - filename, strerror(errno)); - goto bail; + xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", + filename, strerror(errno)); + goto bail; } ErrorF("\n"); if (!foundMouse) { - ErrorF("\n"__XSERVERNAME__" is not able to detect your mouse.\n" - "Edit the file and correct the Device.\n"); - } else { - ErrorF("\n"__XSERVERNAME__" detected your mouse at device %s.\n" - "Please check your config if the mouse is still not\n" - "operational, as by default "__XSERVERNAME__ - " tries to autodetect\n" - "the protocol.\n",DFLT_MOUSE_DEV); + ErrorF("\n" __XSERVERNAME__ " is not able to detect your mouse.\n" + "Edit the file and correct the Device.\n"); + } + else { + ErrorF("\n" __XSERVERNAME__ " detected your mouse at device %s.\n" + "Please check your config if the mouse is still not\n" + "operational, as by default " __XSERVERNAME__ + " tries to autodetect\n" "the protocol.\n", DFLT_MOUSE_DEV); } if (xf86NumScreens > 1) { - ErrorF("\n"__XSERVERNAME__ - " has configured a multihead system, please check your config.\n"); + ErrorF("\n" __XSERVERNAME__ + " has configured a multihead system, please check your config.\n"); } - ErrorF("\nYour %s file is %s\n\n", XF86CONFIGFILE ,filename); + ErrorF("\nYour %s file is %s\n\n", XF86CONFIGFILE, filename); ErrorF("To test the server, run 'X -config %s'\n\n", filename); -bail: + bail: OsCleanup(TRUE); AbortDDX(EXIT_ERR_CONFIGURE); fflush(stderr); @@ -765,47 +785,48 @@ bail: * Author: Marcus Schaefer, ms@suse.de */ -void DoShowOptions (void) { - int i = 0; - char **vlist = 0; - char *pSymbol = 0; - XF86ModuleData *initData = 0; - if (! (vlist = xf86DriverlistFromCompile())) { - ErrorF("Missing output drivers\n"); - goto bail; - } - xf86LoadModules (vlist,0); - free(vlist); - for (i = 0; i < xf86NumDrivers; i++) { - if (xf86DriverList[i]->AvailableOptions) { - const OptionInfoRec *pOption = - (*xf86DriverList[i]->AvailableOptions)(0,0); - if (! pOption) { - ErrorF ("(EE) Couldn't read option table for %s driver\n", - xf86DriverList[i]->driverName - ); - continue; - } - XNFasprintf(&pSymbol, "%sModuleData", - xf86DriverList[i]->driverName); - initData = LoaderSymbol (pSymbol); - if (initData) { - XF86ModuleVersionInfo *vers = initData->vers; - const OptionInfoRec *p; - ErrorF ("Driver[%d]:%s[%s] {\n", - i,xf86DriverList[i]->driverName,vers->vendor - ); - for (p = pOption; p->name != NULL; p++) { - ErrorF ("\t%s:%s\n", p->name, - optionTypeToString(p->type)); - } - ErrorF ("}\n"); - } - } - } - bail: - OsCleanup (TRUE); - AbortDDX (EXIT_ERR_DRIVERS); - fflush (stderr); - exit (0); +void +DoShowOptions(void) +{ + int i = 0; + char **vlist = 0; + char *pSymbol = 0; + XF86ModuleData *initData = 0; + + if (!(vlist = xf86DriverlistFromCompile())) { + ErrorF("Missing output drivers\n"); + goto bail; + } + xf86LoadModules(vlist, 0); + free(vlist); + for (i = 0; i < xf86NumDrivers; i++) { + if (xf86DriverList[i]->AvailableOptions) { + const OptionInfoRec *pOption = + (*xf86DriverList[i]->AvailableOptions) (0, 0); + if (!pOption) { + ErrorF("(EE) Couldn't read option table for %s driver\n", + xf86DriverList[i]->driverName); + continue; + } + XNFasprintf(&pSymbol, "%sModuleData", + xf86DriverList[i]->driverName); + initData = LoaderSymbol(pSymbol); + if (initData) { + XF86ModuleVersionInfo *vers = initData->vers; + const OptionInfoRec *p; + + ErrorF("Driver[%d]:%s[%s] {\n", + i, xf86DriverList[i]->driverName, vers->vendor); + for (p = pOption; p->name != NULL; p++) { + ErrorF("\t%s:%s\n", p->name, optionTypeToString(p->type)); + } + ErrorF("}\n"); + } + } + } + bail: + OsCleanup(TRUE); + AbortDDX(EXIT_ERR_DRIVERS); + fflush(stderr); + exit(0); } diff --git a/xorg-server/hw/xfree86/common/xf86Cursor.c b/xorg-server/hw/xfree86/common/xf86Cursor.c index 6f5d726f0..3716434f0 100644 --- a/xorg-server/hw/xfree86/common/xf86Cursor.c +++ b/xorg-server/hw/xfree86/common/xf86Cursor.c @@ -51,15 +51,15 @@ #endif typedef struct _xf86EdgeRec { - short screen; - short start; - short end; - DDXPointRec offset; - struct _xf86EdgeRec *next; + short screen; + short start; + short end; + DDXPointRec offset; + struct _xf86EdgeRec *next; } xf86EdgeRec, *xf86EdgePtr; typedef struct { - xf86EdgePtr left, right, up, down; + xf86EdgePtr left, right, up, down; } xf86ScreenLayoutRec, *xf86ScreenLayoutPtr; static Bool xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y); @@ -69,12 +69,12 @@ static void xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y); static void xf86PointerMoved(int scrnIndex, int x, int y); static miPointerScreenFuncRec xf86PointerScreenFuncs = { - xf86CursorOffScreen, - xf86CrossScreen, - xf86WarpCursor, - /* let miPointerInitialize take care of these */ - NULL, - NULL + xf86CursorOffScreen, + xf86CrossScreen, + xf86WarpCursor, + /* let miPointerInitialize take care of these */ + NULL, + NULL }; static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS]; @@ -92,41 +92,39 @@ void xf86InitViewport(ScrnInfoPtr pScr) { - pScr->PointerMoved = xf86PointerMoved; - - /* - * Compute the initial Viewport if necessary - */ - if (pScr->display) { - if (pScr->display->frameX0 < 0) { - pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2; - pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2; - } else { - pScr->frameX0 = pScr->display->frameX0; - pScr->frameY0 = pScr->display->frameY0; + pScr->PointerMoved = xf86PointerMoved; + + /* + * Compute the initial Viewport if necessary + */ + if (pScr->display) { + if (pScr->display->frameX0 < 0) { + pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2; + pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2; + } + else { + pScr->frameX0 = pScr->display->frameX0; + pScr->frameY0 = pScr->display->frameY0; + } } - } - - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - - /* - * Now adjust the initial Viewport, so it lies within the virtual area - */ - if (pScr->frameX1 >= pScr->virtualX) - { - pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay; - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; + + pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; + pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; + + /* + * Now adjust the initial Viewport, so it lies within the virtual area + */ + if (pScr->frameX1 >= pScr->virtualX) { + pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay; + pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; } - if (pScr->frameY1 >= pScr->virtualY) - { - pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; + if (pScr->frameY1 >= pScr->virtualY) { + pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay; + pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; } } - /* * xf86SetViewport -- * Scroll the visual part of the screen so the pointer is visible. @@ -135,48 +133,47 @@ xf86InitViewport(ScrnInfoPtr pScr) void xf86SetViewport(ScreenPtr pScreen, int x, int y) { - ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); - (*pScr->PointerMoved)(pScreen->myNum, x, y); + (*pScr->PointerMoved) (pScreen->myNum, x, y); } - -static void +static void xf86PointerMoved(int scrnIndex, int x, int y) { - Bool frameChanged = FALSE; - ScrnInfoPtr pScr = xf86Screens[scrnIndex]; - - /* - * check wether (x,y) belongs to the visual part of the screen - * if not, change the base of the displayed frame accoring - */ - if ( pScr->frameX0 > x) { - pScr->frameX0 = x; - pScr->frameX1 = x + pScr->currentMode->HDisplay - 1; - frameChanged = TRUE ; - } - - if ( pScr->frameX1 < x) { - pScr->frameX1 = x + 1; - pScr->frameX0 = x - pScr->currentMode->HDisplay + 1; - frameChanged = TRUE ; - } - - if ( pScr->frameY0 > y) { - pScr->frameY0 = y; - pScr->frameY1 = y + pScr->currentMode->VDisplay - 1; - frameChanged = TRUE; - } - - if ( pScr->frameY1 < y) { - pScr->frameY1 = y; - pScr->frameY0 = y - pScr->currentMode->VDisplay + 1; - frameChanged = TRUE; - } - - if (frameChanged && pScr->AdjustFrame != NULL) - pScr->AdjustFrame(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); + Bool frameChanged = FALSE; + ScrnInfoPtr pScr = xf86Screens[scrnIndex]; + + /* + * check wether (x,y) belongs to the visual part of the screen + * if not, change the base of the displayed frame accoring + */ + if (pScr->frameX0 > x) { + pScr->frameX0 = x; + pScr->frameX1 = x + pScr->currentMode->HDisplay - 1; + frameChanged = TRUE; + } + + if (pScr->frameX1 < x) { + pScr->frameX1 = x + 1; + pScr->frameX0 = x - pScr->currentMode->HDisplay + 1; + frameChanged = TRUE; + } + + if (pScr->frameY0 > y) { + pScr->frameY0 = y; + pScr->frameY1 = y + pScr->currentMode->VDisplay - 1; + frameChanged = TRUE; + } + + if (pScr->frameY1 < y) { + pScr->frameY1 = y; + pScr->frameY0 = y - pScr->currentMode->VDisplay + 1; + frameChanged = TRUE; + } + + if (frameChanged && pScr->AdjustFrame != NULL) + pScr->AdjustFrame(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); } /* @@ -187,7 +184,7 @@ xf86PointerMoved(int scrnIndex, int x, int y) void xf86LockZoom(ScreenPtr pScreen, Bool lock) { - XF86SCRNINFO(pScreen)->zoomLocked = lock; + XF86SCRNINFO(pScreen)->zoomLocked = lock; } /* @@ -199,121 +196,118 @@ xf86LockZoom(ScreenPtr pScreen, Bool lock) Bool xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode) { - ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); - ScreenPtr pCursorScreen; - Bool Switched; - int px, py, was_blocked; - DeviceIntPtr dev, it; + ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + ScreenPtr pCursorScreen; + Bool Switched; + int px, py, was_blocked; + DeviceIntPtr dev, it; - if (!pScr->vtSema || !mode || !pScr->SwitchMode) - return FALSE; + if (!pScr->vtSema || !mode || !pScr->SwitchMode) + return FALSE; #ifdef XFreeXDGA - if (DGAActive(pScr->scrnIndex)) - return FALSE; + if (DGAActive(pScr->scrnIndex)) + return FALSE; #endif - if (mode == pScr->currentMode) - return TRUE; - - if (mode->HDisplay > pScr->virtualX || mode->VDisplay > pScr->virtualY) - return FALSE; - - /* Let's take an educated guess for which pointer to take here. And about as - educated as it gets is to take the first pointer we find. - */ - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner) - break; - } - - pCursorScreen = miPointerGetScreen(dev); - if (pScreen == pCursorScreen) - miPointerGetPosition(dev, &px, &py); + if (mode == pScr->currentMode) + return TRUE; - was_blocked = xf86BlockSIGIO(); - Switched = (*pScr->SwitchMode)(pScr->scrnIndex, mode, 0); - if (Switched) { - pScr->currentMode = mode; + if (mode->HDisplay > pScr->virtualX || mode->VDisplay > pScr->virtualY) + return FALSE; - /* - * Adjust frame for new display size. - * Frame is centered around cursor position if cursor is on same screen. + /* Let's take an educated guess for which pointer to take here. And about as + educated as it gets is to take the first pointer we find. */ - if (pScreen == pCursorScreen) - pScr->frameX0 = px - (mode->HDisplay / 2) + 1; - else - pScr->frameX0 = (pScr->frameX0 + pScr->frameX1 + 1 - mode->HDisplay) / 2; - - if (pScr->frameX0 < 0) - pScr->frameX0 = 0; - - pScr->frameX1 = pScr->frameX0 + mode->HDisplay - 1; - if (pScr->frameX1 >= pScr->virtualX) { - pScr->frameX0 = pScr->virtualX - mode->HDisplay; - pScr->frameX1 = pScr->virtualX - 1; + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner) + break; } + pCursorScreen = miPointerGetScreen(dev); if (pScreen == pCursorScreen) - pScr->frameY0 = py - (mode->VDisplay / 2) + 1; - else - pScr->frameY0 = (pScr->frameY0 + pScr->frameY1 + 1 - mode->VDisplay) / 2; + miPointerGetPosition(dev, &px, &py); + + was_blocked = xf86BlockSIGIO(); + Switched = (*pScr->SwitchMode) (pScr->scrnIndex, mode, 0); + if (Switched) { + pScr->currentMode = mode; + + /* + * Adjust frame for new display size. + * Frame is centered around cursor position if cursor is on same screen. + */ + if (pScreen == pCursorScreen) + pScr->frameX0 = px - (mode->HDisplay / 2) + 1; + else + pScr->frameX0 = + (pScr->frameX0 + pScr->frameX1 + 1 - mode->HDisplay) / 2; + + if (pScr->frameX0 < 0) + pScr->frameX0 = 0; + + pScr->frameX1 = pScr->frameX0 + mode->HDisplay - 1; + if (pScr->frameX1 >= pScr->virtualX) { + pScr->frameX0 = pScr->virtualX - mode->HDisplay; + pScr->frameX1 = pScr->virtualX - 1; + } + + if (pScreen == pCursorScreen) + pScr->frameY0 = py - (mode->VDisplay / 2) + 1; + else + pScr->frameY0 = + (pScr->frameY0 + pScr->frameY1 + 1 - mode->VDisplay) / 2; + + if (pScr->frameY0 < 0) + pScr->frameY0 = 0; + + pScr->frameY1 = pScr->frameY0 + mode->VDisplay - 1; + if (pScr->frameY1 >= pScr->virtualY) { + pScr->frameY0 = pScr->virtualY - mode->VDisplay; + pScr->frameY1 = pScr->virtualY - 1; + } + } + xf86UnblockSIGIO(was_blocked); - if (pScr->frameY0 < 0) - pScr->frameY0 = 0; + if (pScr->AdjustFrame) + (*pScr->AdjustFrame) (pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); - pScr->frameY1 = pScr->frameY0 + mode->VDisplay - 1; - if (pScr->frameY1 >= pScr->virtualY) { - pScr->frameY0 = pScr->virtualY - mode->VDisplay; - pScr->frameY1 = pScr->virtualY - 1; + /* The original code centered the frame around the cursor if possible. + * Since this is hard to achieve with multiple cursors, we do the following: + * - center around the first pointer + * - move all other pointers to the nearest edge on the screen (or leave + * them unmodified if they are within the boundaries). + */ + if (pScreen == pCursorScreen) { + xf86WarpCursor(dev, pScreen, px, py); + } + + for (it = inputInfo.devices; it; it = it->next) { + if (it == dev) + continue; + + if (IsPointerDevice(it) && it->spriteInfo->spriteOwner) { + pCursorScreen = miPointerGetScreen(it); + if (pScreen == pCursorScreen) { + miPointerGetPosition(it, &px, &py); + if (px < pScr->frameX0) + px = pScr->frameX0; + else if (px > pScr->frameX1) + px = pScr->frameX1; + + if (py < pScr->frameY0) + py = pScr->frameY0; + else if (py > pScr->frameY1) + py = pScr->frameY1; + + xf86WarpCursor(it, pScreen, px, py); + } + } } - } - xf86UnblockSIGIO(was_blocked); - - if (pScr->AdjustFrame) - (*pScr->AdjustFrame)(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); - - /* The original code centered the frame around the cursor if possible. - * Since this is hard to achieve with multiple cursors, we do the following: - * - center around the first pointer - * - move all other pointers to the nearest edge on the screen (or leave - * them unmodified if they are within the boundaries). - */ - if (pScreen == pCursorScreen) - { - xf86WarpCursor(dev, pScreen, px, py); - } - - for (it = inputInfo.devices; it; it = it->next) - { - if (it == dev) - continue; - - if (IsPointerDevice(it) && it->spriteInfo->spriteOwner) - { - pCursorScreen = miPointerGetScreen(it); - if (pScreen == pCursorScreen) - { - miPointerGetPosition(it, &px, &py); - if (px < pScr->frameX0) - px = pScr->frameX0; - else if (px > pScr->frameX1) - px = pScr->frameX1; - - if(py < pScr->frameY0) - py = pScr->frameY0; - else if(py > pScr->frameY1) - py = pScr->frameY1; - - xf86WarpCursor(it, pScreen, px, py); - } - } - } - - return Switched; + + return Switched; } - + /* * xf86ZoomViewport -- * Reinitialize the visual part of the screen for another mode. @@ -322,31 +316,30 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode) void xf86ZoomViewport(ScreenPtr pScreen, int zoom) { - ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); - DisplayModePtr mode; + ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + DisplayModePtr mode; - if (pScr->zoomLocked || !(mode = pScr->currentMode)) - return; + if (pScr->zoomLocked || !(mode = pScr->currentMode)) + return; - do { - if (zoom > 0) - mode = mode->next; - else - mode = mode->prev; - } while (mode != pScr->currentMode && !(mode->type & M_T_USERDEF)); + do { + if (zoom > 0) + mode = mode->next; + else + mode = mode->prev; + } while (mode != pScr->currentMode && !(mode->type & M_T_USERDEF)); - (void)xf86SwitchMode(pScreen, mode); + (void) xf86SwitchMode(pScreen, mode); } - static xf86EdgePtr FindEdge(xf86EdgePtr edge, int val) { - while(edge && (edge->end <= val)) - edge = edge->next; + while (edge && (edge->end <= val)) + edge = edge->next; - if(edge && (edge->start <= val)) - return edge; + if (edge && (edge->start <= val)) + return edge; return NULL; } @@ -362,89 +355,98 @@ xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y) xf86EdgePtr edge; int tmp; - if(screenInfo.numScreens == 1) - return FALSE; + if (screenInfo.numScreens == 1) + return FALSE; - if(*x < 0) { + if (*x < 0) { tmp = *y; - if(tmp < 0) tmp = 0; - if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1; - - if((edge = xf86ScreenLayout[(*pScreen)->myNum].left)) - edge = FindEdge(edge, tmp); - - if(!edge) *x = 0; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } + if (tmp < 0) + tmp = 0; + if (tmp >= (*pScreen)->height) + tmp = (*pScreen)->height - 1; + + if ((edge = xf86ScreenLayout[(*pScreen)->myNum].left)) + edge = FindEdge(edge, tmp); + + if (!edge) + *x = 0; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } } - if(*x >= (*pScreen)->width) { + if (*x >= (*pScreen)->width) { tmp = *y; - if(tmp < 0) tmp = 0; - if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1; - - if((edge = xf86ScreenLayout[(*pScreen)->myNum].right)) - edge = FindEdge(edge, tmp); - - if(!edge) *x = (*pScreen)->width - 1; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } + if (tmp < 0) + tmp = 0; + if (tmp >= (*pScreen)->height) + tmp = (*pScreen)->height - 1; + + if ((edge = xf86ScreenLayout[(*pScreen)->myNum].right)) + edge = FindEdge(edge, tmp); + + if (!edge) + *x = (*pScreen)->width - 1; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } } - if(*y < 0) { + if (*y < 0) { tmp = *x; - if(tmp < 0) tmp = 0; - if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1; - - if((edge = xf86ScreenLayout[(*pScreen)->myNum].up)) - edge = FindEdge(edge, tmp); - - if(!edge) *y = 0; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } + if (tmp < 0) + tmp = 0; + if (tmp >= (*pScreen)->width) + tmp = (*pScreen)->width - 1; + + if ((edge = xf86ScreenLayout[(*pScreen)->myNum].up)) + edge = FindEdge(edge, tmp); + + if (!edge) + *y = 0; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } } - if(*y >= (*pScreen)->height) { + if (*y >= (*pScreen)->height) { tmp = *x; - if(tmp < 0) tmp = 0; - if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1; - - if((edge = xf86ScreenLayout[(*pScreen)->myNum].down)) - edge = FindEdge(edge, tmp); - - if(!edge) *y = (*pScreen)->height - 1; - else { - *x += edge->offset.x; - *y += edge->offset.y; - (*pScreen) = xf86Screens[edge->screen]->pScreen; - } + if (tmp < 0) + tmp = 0; + if (tmp >= (*pScreen)->width) + tmp = (*pScreen)->width - 1; + + if ((edge = xf86ScreenLayout[(*pScreen)->myNum].down)) + edge = FindEdge(edge, tmp); + + if (!edge) + *y = (*pScreen)->height - 1; + else { + *x += edge->offset.x; + *y += edge->offset.y; + (*pScreen) = xf86Screens[edge->screen]->pScreen; + } } - #if 0 /* This presents problems for overlapping screens when - HardEdges is used. Have to think about the logic more */ - if((*x < 0) || (*x >= (*pScreen)->width) || - (*y < 0) || (*y >= (*pScreen)->height)) { - /* We may have crossed more than one screen */ - xf86CursorOffScreen(pScreen, x, y); + HardEdges is used. Have to think about the logic more */ + if ((*x < 0) || (*x >= (*pScreen)->width) || + (*y < 0) || (*y >= (*pScreen)->height)) { + /* We may have crossed more than one screen */ + xf86CursorOffScreen(pScreen, x, y); } #endif return TRUE; } - - /* * xf86CrossScreen -- * Switch to another screen @@ -454,11 +456,10 @@ xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y) */ static void -xf86CrossScreen (ScreenPtr pScreen, Bool entering) +xf86CrossScreen(ScreenPtr pScreen, Bool entering) { } - /* * xf86WarpCursor -- * Warp possible to another screen @@ -466,88 +467,88 @@ xf86CrossScreen (ScreenPtr pScreen, Bool entering) /* ARGSUSED */ static void -xf86WarpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) +xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) { - int sigstate; - sigstate = xf86BlockSIGIO (); + int sigstate; + + sigstate = xf86BlockSIGIO(); miPointerWarpCursor(pDev, pScreen, x, y); xf86Info.currentScreen = pScreen; - xf86UnblockSIGIO (sigstate); + xf86UnblockSIGIO(sigstate); } - void * xf86GetPointerScreenFuncs(void) { - return (void *)&xf86PointerScreenFuncs; + return (void *) &xf86PointerScreenFuncs; } - static xf86EdgePtr -AddEdge( - xf86EdgePtr edge, - short min, - short max, - short dx, - short dy, - short screen -){ - xf86EdgePtr pEdge = edge, pPrev = NULL, pNew; - - while(1) { - while(pEdge && (min >= pEdge->end)) { - pPrev = pEdge; - pEdge = pEdge->next; - } - - if(!pEdge) { - if(!(pNew = malloc(sizeof(xf86EdgeRec)))) - break; - - pNew->screen = screen; - pNew->start = min; - pNew->end = max; - pNew->offset.x = dx; - pNew->offset.y = dy; - pNew->next = NULL; - - if(pPrev) - pPrev->next = pNew; - else - edge = pNew; - - break; - } else if (min < pEdge->start) { - if(!(pNew = malloc(sizeof(xf86EdgeRec)))) - break; - - pNew->screen = screen; - pNew->start = min; - pNew->offset.x = dx; - pNew->offset.y = dy; - pNew->next = pEdge; - - if(pPrev) pPrev->next = pNew; - else edge = pNew; - - if(max <= pEdge->start) { - pNew->end = max; - break; - } else { - pNew->end = pEdge->start; - min = pEdge->end; - } - } else - min = pEdge->end; - - pPrev = pEdge; - pEdge = pEdge->next; - - if(max <= min) break; - } - - return edge; +AddEdge(xf86EdgePtr edge, + short min, short max, short dx, short dy, short screen) +{ + xf86EdgePtr pEdge = edge, pPrev = NULL, pNew; + + while (1) { + while (pEdge && (min >= pEdge->end)) { + pPrev = pEdge; + pEdge = pEdge->next; + } + + if (!pEdge) { + if (!(pNew = malloc(sizeof(xf86EdgeRec)))) + break; + + pNew->screen = screen; + pNew->start = min; + pNew->end = max; + pNew->offset.x = dx; + pNew->offset.y = dy; + pNew->next = NULL; + + if (pPrev) + pPrev->next = pNew; + else + edge = pNew; + + break; + } + else if (min < pEdge->start) { + if (!(pNew = malloc(sizeof(xf86EdgeRec)))) + break; + + pNew->screen = screen; + pNew->start = min; + pNew->offset.x = dx; + pNew->offset.y = dy; + pNew->next = pEdge; + + if (pPrev) + pPrev->next = pNew; + else + edge = pNew; + + if (max <= pEdge->start) { + pNew->end = max; + break; + } + else { + pNew->end = pEdge->start; + min = pEdge->end; + } + } + else + min = pEdge->end; + + pPrev = pEdge; + pEdge = pEdge->next; + + if (max <= min) + break; + } + + return edge; } static void @@ -556,19 +557,20 @@ FillOutEdge(xf86EdgePtr pEdge, int limit) xf86EdgePtr pNext; int diff; - if(pEdge->start > 0) pEdge->start = 0; + if (pEdge->start > 0) + pEdge->start = 0; - while((pNext = pEdge->next)) { - diff = pNext->start - pEdge->end; - if(diff > 0) { - pEdge->end += diff >> 1; - pNext->start -= diff - (diff >> 1); - } - pEdge = pNext; + while ((pNext = pEdge->next)) { + diff = pNext->start - pEdge->end; + if (diff > 0) { + pEdge->end += diff >> 1; + pNext->start -= diff - (diff >> 1); + } + pEdge = pNext; } - if(pEdge->end < limit) - pEdge->end = limit; + if (pEdge->end < limit) + pEdge->end = limit; } /* @@ -591,252 +593,269 @@ xf86InitOrigins(void) HardEdges = FALSE; memset(xf86ScreenLayout, 0, MAXSCREENS * sizeof(xf86ScreenLayoutRec)); - + screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1; - while(1) { - for(mask = screensLeft, i = 0; mask; mask >>= 1, i++) { - if(!(mask & 1L)) continue; - - screen = &xf86ConfigLayout.screens[i]; - - if (screen->refscreen != NULL && - screen->refscreen->screennum >= xf86NumScreens) { - screensLeft &= ~(1 << i); - xf86Msg(X_WARNING, "Not including screen \"%s\" in origins calculation.\n", - screen->screen->id); - continue; - } - - pScreen = xf86Screens[i]->pScreen; - switch(screen->where) { - case PosObsolete: - OldStyleConfig = TRUE; - pLayout = &xf86ScreenLayout[i]; - /* force edge lists */ - if(screen->left) { - ref = screen->left->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->left = AddEdge(pLayout->left, - 0, pScreen->height, - xf86Screens[ref]->pScreen->width, 0, ref); - } - if(screen->right) { - ref = screen->right->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->right = AddEdge(pLayout->right, - 0, pScreen->height, -pScreen->width, 0, ref); - } - if(screen->top) { - ref = screen->top->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->up = AddEdge(pLayout->up, - 0, pScreen->width, - 0, xf86Screens[ref]->pScreen->height, ref); - } - if(screen->bottom) { - ref = screen->bottom->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->down = AddEdge(pLayout->down, - 0, pScreen->width, 0, -pScreen->height, ref); - } - /* we could also try to place it based on those - relative locations if we wanted to */ - screen->x = screen->y = 0; - /* FALLTHROUGH */ - case PosAbsolute: - pScreen->x = screen->x; - pScreen->y = screen->y; - screensLeft &= ~(1 << i); - break; - case PosRelative: - ref = screen->refscreen->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if(screensLeft & (1 << ref)) break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x + screen->x; - pScreen->y = refScreen->y + screen->y; - screensLeft &= ~(1 << i); - break; - case PosRightOf: - ref = screen->refscreen->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if(screensLeft & (1 << ref)) break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x + refScreen->width; - pScreen->y = refScreen->y; - screensLeft &= ~(1 << i); - break; - case PosLeftOf: - ref = screen->refscreen->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if(screensLeft & (1 << ref)) break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x - pScreen->width; - pScreen->y = refScreen->y; - screensLeft &= ~(1 << i); - break; - case PosBelow: - ref = screen->refscreen->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if(screensLeft & (1 << ref)) break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x; - pScreen->y = refScreen->y + refScreen->height; - screensLeft &= ~(1 << i); - break; - case PosAbove: - ref = screen->refscreen->screennum; - if (! xf86Screens[ref] || ! xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if(screensLeft & (1 << ref)) break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x; - pScreen->y = refScreen->y - pScreen->height; - screensLeft &= ~(1 << i); - break; - default: - ErrorF("Illegal placement keyword in Layout!\n"); - break; - } - - } - - if(!screensLeft) break; - - if(screensLeft == prevScreensLeft) { - /* All the remaining screens are referencing each other. - Assign a value to one of them and go through again */ - i = 0; - while(!((1 << i) & screensLeft)){ i++; } - - ref = xf86ConfigLayout.screens[i].refscreen->screennum; - xf86Screens[ref]->pScreen->x = xf86Screens[ref]->pScreen->y = 0; - screensLeft &= ~(1 << ref); - } - - prevScreensLeft = screensLeft; + while (1) { + for (mask = screensLeft, i = 0; mask; mask >>= 1, i++) { + if (!(mask & 1L)) + continue; + + screen = &xf86ConfigLayout.screens[i]; + + if (screen->refscreen != NULL && + screen->refscreen->screennum >= xf86NumScreens) { + screensLeft &= ~(1 << i); + xf86Msg(X_WARNING, + "Not including screen \"%s\" in origins calculation.\n", + screen->screen->id); + continue; + } + + pScreen = xf86Screens[i]->pScreen; + switch (screen->where) { + case PosObsolete: + OldStyleConfig = TRUE; + pLayout = &xf86ScreenLayout[i]; + /* force edge lists */ + if (screen->left) { + ref = screen->left->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + pLayout->left = AddEdge(pLayout->left, + 0, pScreen->height, + xf86Screens[ref]->pScreen->width, 0, + ref); + } + if (screen->right) { + ref = screen->right->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + pLayout->right = AddEdge(pLayout->right, + 0, pScreen->height, + -pScreen->width, 0, ref); + } + if (screen->top) { + ref = screen->top->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + pLayout->up = AddEdge(pLayout->up, + 0, pScreen->width, + 0, xf86Screens[ref]->pScreen->height, + ref); + } + if (screen->bottom) { + ref = screen->bottom->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + pLayout->down = AddEdge(pLayout->down, + 0, pScreen->width, 0, + -pScreen->height, ref); + } + /* we could also try to place it based on those + relative locations if we wanted to */ + screen->x = screen->y = 0; + /* FALLTHROUGH */ + case PosAbsolute: + pScreen->x = screen->x; + pScreen->y = screen->y; + screensLeft &= ~(1 << i); + break; + case PosRelative: + ref = screen->refscreen->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + if (screensLeft & (1 << ref)) + break; + refScreen = xf86Screens[ref]->pScreen; + pScreen->x = refScreen->x + screen->x; + pScreen->y = refScreen->y + screen->y; + screensLeft &= ~(1 << i); + break; + case PosRightOf: + ref = screen->refscreen->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + if (screensLeft & (1 << ref)) + break; + refScreen = xf86Screens[ref]->pScreen; + pScreen->x = refScreen->x + refScreen->width; + pScreen->y = refScreen->y; + screensLeft &= ~(1 << i); + break; + case PosLeftOf: + ref = screen->refscreen->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + if (screensLeft & (1 << ref)) + break; + refScreen = xf86Screens[ref]->pScreen; + pScreen->x = refScreen->x - pScreen->width; + pScreen->y = refScreen->y; + screensLeft &= ~(1 << i); + break; + case PosBelow: + ref = screen->refscreen->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + if (screensLeft & (1 << ref)) + break; + refScreen = xf86Screens[ref]->pScreen; + pScreen->x = refScreen->x; + pScreen->y = refScreen->y + refScreen->height; + screensLeft &= ~(1 << i); + break; + case PosAbove: + ref = screen->refscreen->screennum; + if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { + ErrorF("Referenced uninitialized screen in Layout!\n"); + break; + } + if (screensLeft & (1 << ref)) + break; + refScreen = xf86Screens[ref]->pScreen; + pScreen->x = refScreen->x; + pScreen->y = refScreen->y - pScreen->height; + screensLeft &= ~(1 << i); + break; + default: + ErrorF("Illegal placement keyword in Layout!\n"); + break; + } + + } + + if (!screensLeft) + break; + + if (screensLeft == prevScreensLeft) { + /* All the remaining screens are referencing each other. + Assign a value to one of them and go through again */ + i = 0; + while (!((1 << i) & screensLeft)) { + i++; + } + + ref = xf86ConfigLayout.screens[i].refscreen->screennum; + xf86Screens[ref]->pScreen->x = xf86Screens[ref]->pScreen->y = 0; + screensLeft &= ~(1 << ref); + } + + prevScreensLeft = screensLeft; } /* justify the topmost and leftmost to (0,0) */ minX = xf86Screens[0]->pScreen->x; minY = xf86Screens[0]->pScreen->y; - for(i = 1; i < xf86NumScreens; i++) { - if(xf86Screens[i]->pScreen->x < minX) - minX = xf86Screens[i]->pScreen->x; - if(xf86Screens[i]->pScreen->y < minY) - minY = xf86Screens[i]->pScreen->y; + for (i = 1; i < xf86NumScreens; i++) { + if (xf86Screens[i]->pScreen->x < minX) + minX = xf86Screens[i]->pScreen->x; + if (xf86Screens[i]->pScreen->y < minY) + minY = xf86Screens[i]->pScreen->y; } if (minX || minY) { - for(i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->pScreen->x -= minX; - xf86Screens[i]->pScreen->y -= minY; - } + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->pScreen->x -= minX; + xf86Screens[i]->pScreen->y -= minY; + } } - /* Create the edge lists */ - if(!OldStyleConfig) { - for(i = 0; i < xf86NumScreens; i++) { - pLayout = &xf86ScreenLayout[i]; - - pScreen = xf86Screens[i]->pScreen; - - left = pScreen->x; - right = left + pScreen->width; - top = pScreen->y; - bottom = top + pScreen->height; - - for(j = 0; j < xf86NumScreens; j++) { - if(i == j) continue; - - refScreen = xf86Screens[j]->pScreen; - - x1 = refScreen->x; - x2 = x1 + refScreen->width; - y1 = refScreen->y; - y2 = y1 + refScreen->height; - - if((bottom > y1) && (top < y2)) { - min = y1 - top; - if(min < 0) min = 0; - max = pScreen->height - (bottom - y2); - if(max > pScreen->height) max = pScreen->height; - - if(((left - 1) >= x1) && ((left - 1) < x2)) - pLayout->left = AddEdge(pLayout->left, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - - if((right >= x1) && (right < x2)) - pLayout->right = AddEdge(pLayout->right, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - } - - - if((left < x2) && (right > x1)) { - min = x1 - left; - if(min < 0) min = 0; - max = pScreen->width - (right - x2); - if(max > pScreen->width) max = pScreen->width; - - if(((top - 1) >= y1) && ((top - 1) < y2)) - pLayout->up = AddEdge(pLayout->up, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - - if((bottom >= y1) && (bottom < y2)) - pLayout->down = AddEdge(pLayout->down, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - } - } - } + if (!OldStyleConfig) { + for (i = 0; i < xf86NumScreens; i++) { + pLayout = &xf86ScreenLayout[i]; + + pScreen = xf86Screens[i]->pScreen; + + left = pScreen->x; + right = left + pScreen->width; + top = pScreen->y; + bottom = top + pScreen->height; + + for (j = 0; j < xf86NumScreens; j++) { + if (i == j) + continue; + + refScreen = xf86Screens[j]->pScreen; + + x1 = refScreen->x; + x2 = x1 + refScreen->width; + y1 = refScreen->y; + y2 = y1 + refScreen->height; + + if ((bottom > y1) && (top < y2)) { + min = y1 - top; + if (min < 0) + min = 0; + max = pScreen->height - (bottom - y2); + if (max > pScreen->height) + max = pScreen->height; + + if (((left - 1) >= x1) && ((left - 1) < x2)) + pLayout->left = AddEdge(pLayout->left, min, max, + pScreen->x - refScreen->x, + pScreen->y - refScreen->y, j); + + if ((right >= x1) && (right < x2)) + pLayout->right = AddEdge(pLayout->right, min, max, + pScreen->x - refScreen->x, + pScreen->y - refScreen->y, j); + } + + if ((left < x2) && (right > x1)) { + min = x1 - left; + if (min < 0) + min = 0; + max = pScreen->width - (right - x2); + if (max > pScreen->width) + max = pScreen->width; + + if (((top - 1) >= y1) && ((top - 1) < y2)) + pLayout->up = AddEdge(pLayout->up, min, max, + pScreen->x - refScreen->x, + pScreen->y - refScreen->y, j); + + if ((bottom >= y1) && (bottom < y2)) + pLayout->down = AddEdge(pLayout->down, min, max, + pScreen->x - refScreen->x, + pScreen->y - refScreen->y, j); + } + } + } } - if(!HardEdges && !OldStyleConfig) { - for(i = 0; i < xf86NumScreens; i++) { - pLayout = &xf86ScreenLayout[i]; - pScreen = xf86Screens[i]->pScreen; - if(pLayout->left) - FillOutEdge(pLayout->left, pScreen->height); - if(pLayout->right) - FillOutEdge(pLayout->right, pScreen->height); - if(pLayout->up) - FillOutEdge(pLayout->up, pScreen->width); - if(pLayout->down) - FillOutEdge(pLayout->down, pScreen->width); - } + if (!HardEdges && !OldStyleConfig) { + for (i = 0; i < xf86NumScreens; i++) { + pLayout = &xf86ScreenLayout[i]; + pScreen = xf86Screens[i]->pScreen; + if (pLayout->left) + FillOutEdge(pLayout->left, pScreen->height); + if (pLayout->right) + FillOutEdge(pLayout->right, pScreen->height); + if (pLayout->up) + FillOutEdge(pLayout->up, pScreen->width); + if (pLayout->down) + FillOutEdge(pLayout->down, pScreen->width); + } } update_desktop_dimensions(); @@ -848,15 +867,14 @@ xf86ReconfigureLayout(void) int i; for (i = 0; i < MAXSCREENS; i++) { - xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i]; - /* we don't have to zero these, xf86InitOrigins() takes care of that */ - free(sl->left); - free(sl->right); - free(sl->up); - free(sl->down); + xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i]; + + /* we don't have to zero these, xf86InitOrigins() takes care of that */ + free(sl->left); + free(sl->right); + free(sl->up); + free(sl->down); } xf86InitOrigins(); } - - diff --git a/xorg-server/hw/xfree86/common/xf86DGA.c b/xorg-server/hw/xfree86/common/xf86DGA.c index 0c958cdf3..316978cfa 100644 --- a/xorg-server/hw/xfree86/common/xf86DGA.c +++ b/xorg-server/hw/xfree86/common/xf86DGA.c @@ -52,6 +52,7 @@ #include "mi.h" static DevPrivateKeyRec DGAScreenKeyRec; + #define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec) static Bool mieq_installed; @@ -63,86 +64,76 @@ static void DGAHandleEvent(int screen_num, InternalEvent *event, DeviceIntPtr device); static void -DGACopyModeInfo( - DGAModePtr mode, - XDGAModePtr xmode -); + DGACopyModeInfo(DGAModePtr mode, XDGAModePtr xmode); int *XDGAEventBase = NULL; #define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \ dixLookupPrivate(&(pScreen)->devPrivates, &DGAScreenKeyRec)) - -typedef struct _FakedVisualList{ - Bool free; - VisualPtr pVisual; - struct _FakedVisualList *next; +typedef struct _FakedVisualList { + Bool free; + VisualPtr pVisual; + struct _FakedVisualList *next; } FakedVisualList; - typedef struct { - ScrnInfoPtr pScrn; - int numModes; - DGAModePtr modes; - CloseScreenProcPtr CloseScreen; - DestroyColormapProcPtr DestroyColormap; - InstallColormapProcPtr InstallColormap; - UninstallColormapProcPtr UninstallColormap; - DGADevicePtr current; - DGAFunctionPtr funcs; - int input; - ClientPtr client; - int pixmapMode; - FakedVisualList *fakedVisuals; - ColormapPtr dgaColormap; - ColormapPtr savedColormap; - Bool grabMouse; - Bool grabKeyboard; + ScrnInfoPtr pScrn; + int numModes; + DGAModePtr modes; + CloseScreenProcPtr CloseScreen; + DestroyColormapProcPtr DestroyColormap; + InstallColormapProcPtr InstallColormap; + UninstallColormapProcPtr UninstallColormap; + DGADevicePtr current; + DGAFunctionPtr funcs; + int input; + ClientPtr client; + int pixmapMode; + FakedVisualList *fakedVisuals; + ColormapPtr dgaColormap; + ColormapPtr savedColormap; + Bool grabMouse; + Bool grabKeyboard; } DGAScreenRec, *DGAScreenPtr; Bool -DGAInit( - ScreenPtr pScreen, - DGAFunctionPtr funcs, - DGAModePtr modes, - int num -){ +DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes, int num) +{ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; DGAScreenPtr pScreenPriv; int i; - if(!funcs || !funcs->SetMode || !funcs->OpenFramebuffer) - return FALSE; + if (!funcs || !funcs->SetMode || !funcs->OpenFramebuffer) + return FALSE; - if(!modes || num <= 0) - return FALSE; + if (!modes || num <= 0) + return FALSE; if (!dixRegisterPrivateKey(&DGAScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if (!pScreenPriv) - { - if(!(pScreenPriv = (DGAScreenPtr)malloc(sizeof(DGAScreenRec)))) - return FALSE; - dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv); - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = DGACloseScreen; - pScreenPriv->DestroyColormap = pScreen->DestroyColormap; - pScreen->DestroyColormap = DGADestroyColormap; - pScreenPriv->InstallColormap = pScreen->InstallColormap; - pScreen->InstallColormap = DGAInstallColormap; - pScreenPriv->UninstallColormap = pScreen->UninstallColormap; - pScreen->UninstallColormap = DGAUninstallColormap; + if (!pScreenPriv) { + if (!(pScreenPriv = (DGAScreenPtr) malloc(sizeof(DGAScreenRec)))) + return FALSE; + dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv); + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = DGACloseScreen; + pScreenPriv->DestroyColormap = pScreen->DestroyColormap; + pScreen->DestroyColormap = DGADestroyColormap; + pScreenPriv->InstallColormap = pScreen->InstallColormap; + pScreen->InstallColormap = DGAInstallColormap; + pScreenPriv->UninstallColormap = pScreen->UninstallColormap; + pScreen->UninstallColormap = DGAUninstallColormap; } pScreenPriv->pScrn = pScrn; pScreenPriv->numModes = num; pScreenPriv->modes = modes; - pScreenPriv->current = NULL; - + pScreenPriv->current = NULL; + pScreenPriv->funcs = funcs; pScreenPriv->input = 0; pScreenPriv->client = NULL; @@ -151,14 +142,14 @@ DGAInit( pScreenPriv->savedColormap = NULL; pScreenPriv->grabMouse = FALSE; pScreenPriv->grabKeyboard = FALSE; - - for(i = 0; i < num; i++) - modes[i].num = i + 1; + + for (i = 0; i < num; i++) + modes[i].num = i + 1; #ifdef PANORAMIX - if(!noPanoramiXExtension) - for(i = 0; i < num; i++) - modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; + if (!noPanoramiXExtension) + for (i = 0; i < num; i++) + modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; #endif return TRUE; @@ -169,51 +160,48 @@ DGAInit( */ Bool -DGAReInitModes( - ScreenPtr pScreen, - DGAModePtr modes, - int num -){ +DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, int num) +{ DGAScreenPtr pScreenPriv; int i; /* No DGA? Ignore call (but don't make it look like it failed) */ - if(!DGAScreenKeyRegistered) - return TRUE; - + if (!DGAScreenKeyRegistered) + return TRUE; + pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); /* Same as above */ - if(!pScreenPriv) - return TRUE; + if (!pScreenPriv) + return TRUE; /* Can't do this while DGA is active */ - if(pScreenPriv->current) - return FALSE; + if (pScreenPriv->current) + return FALSE; /* Quick sanity check */ - if(!num) - modes = NULL; - else if(!modes) - num = 0; + if (!num) + modes = NULL; + else if (!modes) + num = 0; pScreenPriv->numModes = num; pScreenPriv->modes = modes; /* This practically disables DGA. So be it. */ - if(!num) - return TRUE; + if (!num) + return TRUE; - for(i = 0; i < num; i++) - modes[i].num = i + 1; + for (i = 0; i < num; i++) + modes[i].num = i + 1; #ifdef PANORAMIX - if(!noPanoramiXExtension) - for(i = 0; i < num; i++) - modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; + if (!noPanoramiXExtension) + for (i = 0; i < num; i++) + modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; #endif - return TRUE; + return TRUE; } static void @@ -222,346 +210,346 @@ FreeMarkedVisuals(ScreenPtr pScreen) DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); FakedVisualList *prev, *curr, *tmp; - if(!pScreenPriv->fakedVisuals) - return; + if (!pScreenPriv->fakedVisuals) + return; prev = NULL; curr = pScreenPriv->fakedVisuals; - while(curr) { - if(curr->free) { - tmp = curr; - curr = curr->next; - if(prev) - prev->next = curr; - else - pScreenPriv->fakedVisuals = curr; - free(tmp->pVisual); - free(tmp); - } else { - prev = curr; - curr = curr->next; - } + while (curr) { + if (curr->free) { + tmp = curr; + curr = curr->next; + if (prev) + prev->next = curr; + else + pScreenPriv->fakedVisuals = curr; + free(tmp->pVisual); + free(tmp); + } + else { + prev = curr; + curr = curr->next; + } } } -static Bool +static Bool DGACloseScreen(int i, ScreenPtr pScreen) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if (mieq_installed) { - mieqSetHandler(ET_DGAEvent, NULL); - mieq_installed = FALSE; - } + if (mieq_installed) { + mieqSetHandler(ET_DGAEvent, NULL); + mieq_installed = FALSE; + } - FreeMarkedVisuals(pScreen); + FreeMarkedVisuals(pScreen); - pScreen->CloseScreen = pScreenPriv->CloseScreen; - pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - pScreen->InstallColormap = pScreenPriv->InstallColormap; - pScreen->UninstallColormap = pScreenPriv->UninstallColormap; + pScreen->CloseScreen = pScreenPriv->CloseScreen; + pScreen->DestroyColormap = pScreenPriv->DestroyColormap; + pScreen->InstallColormap = pScreenPriv->InstallColormap; + pScreen->UninstallColormap = pScreenPriv->UninstallColormap; - /* DGAShutdown() should have ensured that no DGA - screen were active by here */ + /* DGAShutdown() should have ensured that no DGA + screen were active by here */ - free(pScreenPriv); + free(pScreenPriv); - return((*pScreen->CloseScreen)(i, pScreen)); + return ((*pScreen->CloseScreen) (i, pScreen)); } - -static void +static void DGADestroyColormap(ColormapPtr pmap) { - ScreenPtr pScreen = pmap->pScreen; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - VisualPtr pVisual = pmap->pVisual; - - if(pScreenPriv->fakedVisuals) { - FakedVisualList *curr = pScreenPriv->fakedVisuals; - - while(curr) { - if(curr->pVisual == pVisual) { - /* We can't get rid of them yet since FreeColormap - still needs the pVisual during the cleanup */ - curr->free = TRUE; - break; - } - curr = curr->next; - } - } - - if(pScreenPriv->DestroyColormap) { + ScreenPtr pScreen = pmap->pScreen; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + VisualPtr pVisual = pmap->pVisual; + + if (pScreenPriv->fakedVisuals) { + FakedVisualList *curr = pScreenPriv->fakedVisuals; + + while (curr) { + if (curr->pVisual == pVisual) { + /* We can't get rid of them yet since FreeColormap + still needs the pVisual during the cleanup */ + curr->free = TRUE; + break; + } + curr = curr->next; + } + } + + if (pScreenPriv->DestroyColormap) { pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - (*pScreen->DestroyColormap)(pmap); + (*pScreen->DestroyColormap) (pmap); pScreen->DestroyColormap = DGADestroyColormap; - } + } } - -static void +static void DGAInstallColormap(ColormapPtr pmap) { ScreenPtr pScreen = pmap->pScreen; DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if(pScreenPriv->current && pScreenPriv->dgaColormap) { - if (pmap != pScreenPriv->dgaColormap) { - pScreenPriv->savedColormap = pmap; - pmap = pScreenPriv->dgaColormap; - } + if (pScreenPriv->current && pScreenPriv->dgaColormap) { + if (pmap != pScreenPriv->dgaColormap) { + pScreenPriv->savedColormap = pmap; + pmap = pScreenPriv->dgaColormap; + } } pScreen->InstallColormap = pScreenPriv->InstallColormap; - (*pScreen->InstallColormap)(pmap); + (*pScreen->InstallColormap) (pmap); pScreen->InstallColormap = DGAInstallColormap; } -static void +static void DGAUninstallColormap(ColormapPtr pmap) { ScreenPtr pScreen = pmap->pScreen; DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if(pScreenPriv->current && pScreenPriv->dgaColormap) { - if (pmap == pScreenPriv->dgaColormap) { - pScreenPriv->dgaColormap = NULL; - } + if (pScreenPriv->current && pScreenPriv->dgaColormap) { + if (pmap == pScreenPriv->dgaColormap) { + pScreenPriv->dgaColormap = NULL; + } } pScreen->UninstallColormap = pScreenPriv->UninstallColormap; - (*pScreen->UninstallColormap)(pmap); + (*pScreen->UninstallColormap) (pmap); pScreen->UninstallColormap = DGAUninstallColormap; } int -xf86SetDGAMode( - int index, - int num, - DGADevicePtr devRet -){ - ScreenPtr pScreen = screenInfo.screens[index]; - DGAScreenPtr pScreenPriv; - ScrnInfoPtr pScrn; - DGADevicePtr device; - PixmapPtr pPix = NULL; - DGAModePtr pMode = NULL; - - /* First check if DGAInit was successful on this screen */ - if (!DGAScreenKeyRegistered) - return BadValue; - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if (!pScreenPriv) - return BadValue; - pScrn = pScreenPriv->pScrn; - - if(!num) { - if(pScreenPriv->current) { - PixmapPtr oldPix = pScreenPriv->current->pPix; - if(oldPix) { - if(oldPix->drawable.id) - FreeResource(oldPix->drawable.id, RT_NONE); - else - (*pScreen->DestroyPixmap)(oldPix); - } - free(pScreenPriv->current); - pScreenPriv->current = NULL; - pScrn->vtSema = TRUE; - (*pScreenPriv->funcs->SetMode)(pScrn, NULL); - if(pScreenPriv->savedColormap) { - (*pScreen->InstallColormap)(pScreenPriv->savedColormap); - pScreenPriv->savedColormap = NULL; - } - pScreenPriv->dgaColormap = NULL; - (*pScrn->EnableDisableFBAccess)(index, TRUE); - - FreeMarkedVisuals(pScreen); - } - +xf86SetDGAMode(int index, int num, DGADevicePtr devRet) +{ + ScreenPtr pScreen = screenInfo.screens[index]; + DGAScreenPtr pScreenPriv; + ScrnInfoPtr pScrn; + DGADevicePtr device; + PixmapPtr pPix = NULL; + DGAModePtr pMode = NULL; + + /* First check if DGAInit was successful on this screen */ + if (!DGAScreenKeyRegistered) + return BadValue; + pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + if (!pScreenPriv) + return BadValue; + pScrn = pScreenPriv->pScrn; + + if (!num) { + if (pScreenPriv->current) { + PixmapPtr oldPix = pScreenPriv->current->pPix; + + if (oldPix) { + if (oldPix->drawable.id) + FreeResource(oldPix->drawable.id, RT_NONE); + else + (*pScreen->DestroyPixmap) (oldPix); + } + free(pScreenPriv->current); + pScreenPriv->current = NULL; + pScrn->vtSema = TRUE; + (*pScreenPriv->funcs->SetMode) (pScrn, NULL); + if (pScreenPriv->savedColormap) { + (*pScreen->InstallColormap) (pScreenPriv->savedColormap); + pScreenPriv->savedColormap = NULL; + } + pScreenPriv->dgaColormap = NULL; + (*pScrn->EnableDisableFBAccess) (index, TRUE); + + FreeMarkedVisuals(pScreen); + } + pScreenPriv->grabMouse = FALSE; pScreenPriv->grabKeyboard = FALSE; - return Success; - } - - if(!pScrn->vtSema && !pScreenPriv->current) /* Really switched away */ - return BadAlloc; - - if((num > 0) && (num <= pScreenPriv->numModes)) - pMode = &(pScreenPriv->modes[num - 1]); - else - return BadValue; - - if(!(device = (DGADevicePtr)malloc(sizeof(DGADeviceRec)))) - return BadAlloc; - - if(!pScreenPriv->current) { - Bool oldVTSema = pScrn->vtSema; - - pScrn->vtSema = FALSE; /* kludge until we rewrite VT switching */ - (*pScrn->EnableDisableFBAccess)(index, FALSE); - pScrn->vtSema = oldVTSema; - } - - if(!(*pScreenPriv->funcs->SetMode)(pScrn, pMode)) { - free(device); - return BadAlloc; - } - - pScrn->currentMode = pMode->mode; - - if(!pScreenPriv->current && !pScreenPriv->input) { - /* if it's multihead we need to warp the cursor off of - our screen so it doesn't get trapped */ - } - - pScrn->vtSema = FALSE; - - if(pScreenPriv->current) { - PixmapPtr oldPix = pScreenPriv->current->pPix; - if(oldPix) { - if(oldPix->drawable.id) - FreeResource(oldPix->drawable.id, RT_NONE); - else - (*pScreen->DestroyPixmap)(oldPix); - } - free(pScreenPriv->current); - pScreenPriv->current = NULL; - } - - if(pMode->flags & DGA_PIXMAP_AVAILABLE) { - if((pPix = (*pScreen->CreatePixmap)(pScreen, 0, 0, pMode->depth, 0))) { - (*pScreen->ModifyPixmapHeader)(pPix, - pMode->pixmapWidth, pMode->pixmapHeight, - pMode->depth, pMode->bitsPerPixel, - pMode->bytesPerScanline, - (pointer)(pMode->address)); - } - } + return Success; + } - devRet->mode = device->mode = pMode; - devRet->pPix = device->pPix = pPix; - pScreenPriv->current = device; - pScreenPriv->pixmapMode = FALSE; - pScreenPriv->grabMouse = TRUE; - pScreenPriv->grabKeyboard = TRUE; + if (!pScrn->vtSema && !pScreenPriv->current) /* Really switched away */ + return BadAlloc; - if (!mieq_installed) { - mieqSetHandler(ET_DGAEvent, DGAHandleEvent); - mieq_installed = TRUE; - } + if ((num > 0) && (num <= pScreenPriv->numModes)) + pMode = &(pScreenPriv->modes[num - 1]); + else + return BadValue; - return Success; -} + if (!(device = (DGADevicePtr) malloc(sizeof(DGADeviceRec)))) + return BadAlloc; + + if (!pScreenPriv->current) { + Bool oldVTSema = pScrn->vtSema; + + pScrn->vtSema = FALSE; /* kludge until we rewrite VT switching */ + (*pScrn->EnableDisableFBAccess) (index, FALSE); + pScrn->vtSema = oldVTSema; + } + + if (!(*pScreenPriv->funcs->SetMode) (pScrn, pMode)) { + free(device); + return BadAlloc; + } + + pScrn->currentMode = pMode->mode; + if (!pScreenPriv->current && !pScreenPriv->input) { + /* if it's multihead we need to warp the cursor off of + our screen so it doesn't get trapped */ + } + + pScrn->vtSema = FALSE; + + if (pScreenPriv->current) { + PixmapPtr oldPix = pScreenPriv->current->pPix; + + if (oldPix) { + if (oldPix->drawable.id) + FreeResource(oldPix->drawable.id, RT_NONE); + else + (*pScreen->DestroyPixmap) (oldPix); + } + free(pScreenPriv->current); + pScreenPriv->current = NULL; + } + if (pMode->flags & DGA_PIXMAP_AVAILABLE) { + if ((pPix = (*pScreen->CreatePixmap) (pScreen, 0, 0, pMode->depth, 0))) { + (*pScreen->ModifyPixmapHeader) (pPix, + pMode->pixmapWidth, + pMode->pixmapHeight, pMode->depth, + pMode->bitsPerPixel, + pMode->bytesPerScanline, + (pointer) (pMode->address)); + } + } + + devRet->mode = device->mode = pMode; + devRet->pPix = device->pPix = pPix; + pScreenPriv->current = device; + pScreenPriv->pixmapMode = FALSE; + pScreenPriv->grabMouse = TRUE; + pScreenPriv->grabKeyboard = TRUE; + + if (!mieq_installed) { + mieqSetHandler(ET_DGAEvent, DGAHandleEvent); + mieq_installed = TRUE; + } + + return Success; +} /*********** exported ones ***************/ void DGASetInputMode(int index, Bool keyboard, Bool mouse) { - ScreenPtr pScreen = screenInfo.screens[index]; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (pScreenPriv) - { - pScreenPriv->grabMouse = mouse; - pScreenPriv->grabKeyboard = keyboard; - - if (!mieq_installed) { - mieqSetHandler(ET_DGAEvent, DGAHandleEvent); - mieq_installed = TRUE; - } - } + ScreenPtr pScreen = screenInfo.screens[index]; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + + if (pScreenPriv) { + pScreenPriv->grabMouse = mouse; + pScreenPriv->grabKeyboard = keyboard; + + if (!mieq_installed) { + mieqSetHandler(ET_DGAEvent, DGAHandleEvent); + mieq_installed = TRUE; + } + } } Bool DGAChangePixmapMode(int index, int *x, int *y, int mode) { - DGAScreenPtr pScreenPriv; - DGADevicePtr pDev; - DGAModePtr pMode; - PixmapPtr pPix; - - if(!DGAScreenKeyRegistered) - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if(!pScreenPriv || !pScreenPriv->current || !pScreenPriv->current->pPix) - return FALSE; - - pDev = pScreenPriv->current; - pPix = pDev->pPix; - pMode = pDev->mode; - - if(mode) { - int shift = 2; - - if(*x > (pMode->pixmapWidth - pMode->viewportWidth)) - *x = pMode->pixmapWidth - pMode->viewportWidth; - if(*y > (pMode->pixmapHeight - pMode->viewportHeight)) - *y = pMode->pixmapHeight - pMode->viewportHeight; - - switch(xf86Screens[index]->bitsPerPixel) { - case 16: shift = 1; break; - case 32: shift = 0; break; - default: break; - } - - if(BITMAP_SCANLINE_PAD == 64) - shift++; - - *x = (*x >> shift) << shift; - - pPix->drawable.x = *x; - pPix->drawable.y = *y; - pPix->drawable.width = pMode->viewportWidth; - pPix->drawable.height = pMode->viewportHeight; - } else { - pPix->drawable.x = 0; - pPix->drawable.y = 0; - pPix->drawable.width = pMode->pixmapWidth; - pPix->drawable.height = pMode->pixmapHeight; - } - pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pScreenPriv->pixmapMode = mode; - - return TRUE; + DGAScreenPtr pScreenPriv; + DGADevicePtr pDev; + DGAModePtr pMode; + PixmapPtr pPix; + + if (!DGAScreenKeyRegistered) + return FALSE; + + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + if (!pScreenPriv || !pScreenPriv->current || !pScreenPriv->current->pPix) + return FALSE; + + pDev = pScreenPriv->current; + pPix = pDev->pPix; + pMode = pDev->mode; + + if (mode) { + int shift = 2; + + if (*x > (pMode->pixmapWidth - pMode->viewportWidth)) + *x = pMode->pixmapWidth - pMode->viewportWidth; + if (*y > (pMode->pixmapHeight - pMode->viewportHeight)) + *y = pMode->pixmapHeight - pMode->viewportHeight; + + switch (xf86Screens[index]->bitsPerPixel) { + case 16: + shift = 1; + break; + case 32: + shift = 0; + break; + default: + break; + } + + if (BITMAP_SCANLINE_PAD == 64) + shift++; + + *x = (*x >> shift) << shift; + + pPix->drawable.x = *x; + pPix->drawable.y = *y; + pPix->drawable.width = pMode->viewportWidth; + pPix->drawable.height = pMode->viewportHeight; + } + else { + pPix->drawable.x = 0; + pPix->drawable.y = 0; + pPix->drawable.width = pMode->pixmapWidth; + pPix->drawable.height = pMode->pixmapHeight; + } + pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pScreenPriv->pixmapMode = mode; + + return TRUE; } Bool -DGAAvailable(int index) +DGAAvailable(int index) { - if(!DGAScreenKeyRegistered) - return FALSE; - - if(DGA_GET_SCREEN_PRIV(screenInfo.screens[index])) - return TRUE; + if (!DGAScreenKeyRegistered) + return FALSE; - return FALSE; + if (DGA_GET_SCREEN_PRIV(screenInfo.screens[index])) + return TRUE; + + return FALSE; } Bool -DGAActive(int index) +DGAActive(int index) { - DGAScreenPtr pScreenPriv; + DGAScreenPtr pScreenPriv; - if(!DGAScreenKeyRegistered) - return FALSE; + if (!DGAScreenKeyRegistered) + return FALSE; - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - if(pScreenPriv && pScreenPriv->current) - return TRUE; + if (pScreenPriv && pScreenPriv->current) + return TRUE; - return FALSE; + return FALSE; } - - /* Called by the event code in case the server is abruptly terminated */ void @@ -570,35 +558,31 @@ DGAShutdown(void) ScrnInfoPtr pScrn; int i; - if(!DGAScreenKeyRegistered) - return; + if (!DGAScreenKeyRegistered) + return; - for(i = 0; i < screenInfo.numScreens; i++) { - pScrn = xf86Screens[i]; + for (i = 0; i < screenInfo.numScreens; i++) { + pScrn = xf86Screens[i]; - (void)(*pScrn->SetDGAMode)(pScrn->scrnIndex, 0, NULL); + (void) (*pScrn->SetDGAMode) (pScrn->scrnIndex, 0, NULL); } } /* Called by the extension to initialize a mode */ int -DGASetMode( - int index, - int num, - XDGAModePtr mode, - PixmapPtr *pPix -){ +DGASetMode(int index, int num, XDGAModePtr mode, PixmapPtr *pPix) +{ ScrnInfoPtr pScrn = xf86Screens[index]; DGADeviceRec device; int ret; - /* We rely on the extension to check that DGA is available */ + /* We rely on the extension to check that DGA is available */ - ret = (*pScrn->SetDGAMode)(index, num, &device); - if((ret == Success) && num) { - DGACopyModeInfo(device.mode, mode); - *pPix = device.pPix; + ret = (*pScrn->SetDGAMode) (index, num, &device); + if ((ret == Success) && num) { + DGACopyModeInfo(device.mode, mode); + *pPix = device.pPix; } return ret; @@ -607,124 +591,119 @@ DGASetMode( /* Called from the extension to let the DDX know which events are requested */ void -DGASelectInput( - int index, - ClientPtr client, - long mask -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - pScreenPriv->client = client; - pScreenPriv->input = mask; +DGASelectInput(int index, ClientPtr client, long mask) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + /* We rely on the extension to check that DGA is available */ + pScreenPriv->client = client; + pScreenPriv->input = mask; } int -DGAGetViewportStatus(int index) +DGAGetViewportStatus(int index) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - /* We rely on the extension to check that DGA is active */ + /* We rely on the extension to check that DGA is active */ - if (!pScreenPriv->funcs->GetViewport) - return 0; + if (!pScreenPriv->funcs->GetViewport) + return 0; - return (*pScreenPriv->funcs->GetViewport)(pScreenPriv->pScrn); + return (*pScreenPriv->funcs->GetViewport) (pScreenPriv->pScrn); } int -DGASetViewport( - int index, - int x, int y, - int mode -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (pScreenPriv->funcs->SetViewport) - (*pScreenPriv->funcs->SetViewport)(pScreenPriv->pScrn, x, y, mode); - return Success; -} +DGASetViewport(int index, int x, int y, int mode) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + if (pScreenPriv->funcs->SetViewport) + (*pScreenPriv->funcs->SetViewport) (pScreenPriv->pScrn, x, y, mode); + return Success; +} static int BitsClear(CARD32 data) { - int bits = 0; - CARD32 mask; - - for(mask = 1; mask; mask <<= 1) { - if(!(data & mask)) bits++; - else break; - } + int bits = 0; + CARD32 mask; + + for (mask = 1; mask; mask <<= 1) { + if (!(data & mask)) + bits++; + else + break; + } - return bits; + return bits; } int DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc) { - ScreenPtr pScreen = screenInfo.screens[index]; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - FakedVisualList *fvlp; - VisualPtr pVisual; - DGAModePtr pMode; - ColormapPtr pmap; - - if(!mode || (mode > pScreenPriv->numModes)) - return BadValue; - - if((alloc != AllocNone) && (alloc != AllocAll)) - return BadValue; - - pMode = &(pScreenPriv->modes[mode - 1]); - - if(!(pVisual = malloc(sizeof(VisualRec)))) - return BadAlloc; - - pVisual->vid = FakeClientID(0); - pVisual->class = pMode->visualClass; - pVisual->nplanes = pMode->depth; - pVisual->ColormapEntries = 1 << pMode->depth; - pVisual->bitsPerRGBValue = (pMode->depth + 2) / 3; - - switch (pVisual->class) { - case PseudoColor: - case GrayScale: - case StaticGray: - pVisual->bitsPerRGBValue = 8; /* not quite */ - pVisual->redMask = 0; - pVisual->greenMask = 0; - pVisual->blueMask = 0; - pVisual->offsetRed = 0; - pVisual->offsetGreen = 0; - pVisual->offsetBlue = 0; - break; - case DirectColor: - case TrueColor: - pVisual->ColormapEntries = 1 << pVisual->bitsPerRGBValue; - /* fall through */ - case StaticColor: - pVisual->redMask = pMode->red_mask; - pVisual->greenMask = pMode->green_mask; - pVisual->blueMask = pMode->blue_mask; - pVisual->offsetRed = BitsClear(pVisual->redMask); - pVisual->offsetGreen = BitsClear(pVisual->greenMask); - pVisual->offsetBlue = BitsClear(pVisual->blueMask); - } - - if(!(fvlp = malloc(sizeof(FakedVisualList)))) { - free(pVisual); - return BadAlloc; - } - - fvlp->free = FALSE; - fvlp->pVisual = pVisual; - fvlp->next = pScreenPriv->fakedVisuals; - pScreenPriv->fakedVisuals = fvlp; - - LEGAL_NEW_RESOURCE(id, client); - - return CreateColormap(id, pScreen, pVisual, &pmap, alloc, client->index); + ScreenPtr pScreen = screenInfo.screens[index]; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + FakedVisualList *fvlp; + VisualPtr pVisual; + DGAModePtr pMode; + ColormapPtr pmap; + + if (!mode || (mode > pScreenPriv->numModes)) + return BadValue; + + if ((alloc != AllocNone) && (alloc != AllocAll)) + return BadValue; + + pMode = &(pScreenPriv->modes[mode - 1]); + + if (!(pVisual = malloc(sizeof(VisualRec)))) + return BadAlloc; + + pVisual->vid = FakeClientID(0); + pVisual->class = pMode->visualClass; + pVisual->nplanes = pMode->depth; + pVisual->ColormapEntries = 1 << pMode->depth; + pVisual->bitsPerRGBValue = (pMode->depth + 2) / 3; + + switch (pVisual->class) { + case PseudoColor: + case GrayScale: + case StaticGray: + pVisual->bitsPerRGBValue = 8; /* not quite */ + pVisual->redMask = 0; + pVisual->greenMask = 0; + pVisual->blueMask = 0; + pVisual->offsetRed = 0; + pVisual->offsetGreen = 0; + pVisual->offsetBlue = 0; + break; + case DirectColor: + case TrueColor: + pVisual->ColormapEntries = 1 << pVisual->bitsPerRGBValue; + /* fall through */ + case StaticColor: + pVisual->redMask = pMode->red_mask; + pVisual->greenMask = pMode->green_mask; + pVisual->blueMask = pMode->blue_mask; + pVisual->offsetRed = BitsClear(pVisual->redMask); + pVisual->offsetGreen = BitsClear(pVisual->greenMask); + pVisual->offsetBlue = BitsClear(pVisual->blueMask); + } + + if (!(fvlp = malloc(sizeof(FakedVisualList)))) { + free(pVisual); + return BadAlloc; + } + + fvlp->free = FALSE; + fvlp->pVisual = pVisual; + fvlp->next = pScreenPriv->fakedVisuals; + pScreenPriv->fakedVisuals = fvlp; + + LEGAL_NEW_RESOURCE(id, client); + + return CreateColormap(id, pScreen, pVisual, &pmap, alloc, client->index); } /* Called by the extension to install a colormap on DGA active screens */ @@ -735,198 +714,184 @@ DGAInstallCmap(ColormapPtr cmap) ScreenPtr pScreen = cmap->pScreen; DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - /* We rely on the extension to check that DGA is active */ + /* We rely on the extension to check that DGA is active */ - if(!pScreenPriv->dgaColormap) - pScreenPriv->savedColormap = GetInstalledmiColormap(pScreen); + if (!pScreenPriv->dgaColormap) + pScreenPriv->savedColormap = GetInstalledmiColormap(pScreen); - pScreenPriv->dgaColormap = cmap; + pScreenPriv->dgaColormap = cmap; - (*pScreen->InstallColormap)(cmap); + (*pScreen->InstallColormap) (cmap); } int DGASync(int index) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - if (pScreenPriv->funcs->Sync) - (*pScreenPriv->funcs->Sync)(pScreenPriv->pScrn); + /* We rely on the extension to check that DGA is active */ - return Success; + if (pScreenPriv->funcs->Sync) + (*pScreenPriv->funcs->Sync) (pScreenPriv->pScrn); + + return Success; } int -DGAFillRect( - int index, - int x, int y, int w, int h, - unsigned long color -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if(pScreenPriv->funcs->FillRect && - (pScreenPriv->current->mode->flags & DGA_FILL_RECT)) { - - (*pScreenPriv->funcs->FillRect)(pScreenPriv->pScrn, x, y, w, h, color); - return Success; - } - return BadMatch; +DGAFillRect(int index, int x, int y, int w, int h, unsigned long color) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + /* We rely on the extension to check that DGA is active */ + + if (pScreenPriv->funcs->FillRect && + (pScreenPriv->current->mode->flags & DGA_FILL_RECT)) { + + (*pScreenPriv->funcs->FillRect) (pScreenPriv->pScrn, x, y, w, h, color); + return Success; + } + return BadMatch; } int -DGABlitRect( - int index, - int srcx, int srcy, - int w, int h, - int dstx, int dsty -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if(pScreenPriv->funcs->BlitRect && - (pScreenPriv->current->mode->flags & DGA_BLIT_RECT)) { - - (*pScreenPriv->funcs->BlitRect)(pScreenPriv->pScrn, - srcx, srcy, w, h, dstx, dsty); - return Success; - } - return BadMatch; +DGABlitRect(int index, int srcx, int srcy, int w, int h, int dstx, int dsty) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + /* We rely on the extension to check that DGA is active */ + + if (pScreenPriv->funcs->BlitRect && + (pScreenPriv->current->mode->flags & DGA_BLIT_RECT)) { + + (*pScreenPriv->funcs->BlitRect) (pScreenPriv->pScrn, + srcx, srcy, w, h, dstx, dsty); + return Success; + } + return BadMatch; } int -DGABlitTransRect( - int index, - int srcx, int srcy, - int w, int h, - int dstx, int dsty, - unsigned long color -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if(pScreenPriv->funcs->BlitTransRect && - (pScreenPriv->current->mode->flags & DGA_BLIT_RECT_TRANS)) { - - (*pScreenPriv->funcs->BlitTransRect)(pScreenPriv->pScrn, - srcx, srcy, w, h, dstx, dsty, color); - return Success; - } - return BadMatch; -} +DGABlitTransRect(int index, + int srcx, int srcy, + int w, int h, int dstx, int dsty, unsigned long color) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + /* We rely on the extension to check that DGA is active */ + + if (pScreenPriv->funcs->BlitTransRect && + (pScreenPriv->current->mode->flags & DGA_BLIT_RECT_TRANS)) { + + (*pScreenPriv->funcs->BlitTransRect) (pScreenPriv->pScrn, + srcx, srcy, w, h, dstx, dsty, + color); + return Success; + } + return BadMatch; +} int DGAGetModes(int index) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - /* We rely on the extension to check that DGA is available */ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - return pScreenPriv->numModes; -} + /* We rely on the extension to check that DGA is available */ + return pScreenPriv->numModes; +} int -DGAGetModeInfo( - int index, - XDGAModePtr mode, - int num -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - /* We rely on the extension to check that DGA is available */ +DGAGetModeInfo(int index, XDGAModePtr mode, int num) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - if((num <= 0) || (num > pScreenPriv->numModes)) - return BadValue; + /* We rely on the extension to check that DGA is available */ - DGACopyModeInfo(&(pScreenPriv->modes[num - 1]), mode); + if ((num <= 0) || (num > pScreenPriv->numModes)) + return BadValue; - return Success; -} + DGACopyModeInfo(&(pScreenPriv->modes[num - 1]), mode); + return Success; +} static void -DGACopyModeInfo( - DGAModePtr mode, - XDGAModePtr xmode -){ - DisplayModePtr dmode = mode->mode; - - xmode->num = mode->num; - xmode->name = dmode->name; - xmode->VSync_num = (int)(dmode->VRefresh * 1000.0); - xmode->VSync_den = 1000; - xmode->flags = mode->flags; - xmode->imageWidth = mode->imageWidth; - xmode->imageHeight = mode->imageHeight; - xmode->pixmapWidth = mode->pixmapWidth; - xmode->pixmapHeight = mode->pixmapHeight; - xmode->bytesPerScanline = mode->bytesPerScanline; - xmode->byteOrder = mode->byteOrder; - xmode->depth = mode->depth; - xmode->bitsPerPixel = mode->bitsPerPixel; - xmode->red_mask = mode->red_mask; - xmode->green_mask = mode->green_mask; - xmode->blue_mask = mode->blue_mask; - xmode->visualClass = mode->visualClass; - xmode->viewportWidth = mode->viewportWidth; - xmode->viewportHeight = mode->viewportHeight; - xmode->xViewportStep = mode->xViewportStep; - xmode->yViewportStep = mode->yViewportStep; - xmode->maxViewportX = mode->maxViewportX; - xmode->maxViewportY = mode->maxViewportY; - xmode->viewportFlags = mode->viewportFlags; - xmode->reserved1 = mode->reserved1; - xmode->reserved2 = mode->reserved2; - xmode->offset = mode->offset; - - if(dmode->Flags & V_INTERLACE) xmode->flags |= DGA_INTERLACED; - if(dmode->Flags & V_DBLSCAN) xmode->flags |= DGA_DOUBLESCAN; +DGACopyModeInfo(DGAModePtr mode, XDGAModePtr xmode) +{ + DisplayModePtr dmode = mode->mode; + + xmode->num = mode->num; + xmode->name = dmode->name; + xmode->VSync_num = (int) (dmode->VRefresh * 1000.0); + xmode->VSync_den = 1000; + xmode->flags = mode->flags; + xmode->imageWidth = mode->imageWidth; + xmode->imageHeight = mode->imageHeight; + xmode->pixmapWidth = mode->pixmapWidth; + xmode->pixmapHeight = mode->pixmapHeight; + xmode->bytesPerScanline = mode->bytesPerScanline; + xmode->byteOrder = mode->byteOrder; + xmode->depth = mode->depth; + xmode->bitsPerPixel = mode->bitsPerPixel; + xmode->red_mask = mode->red_mask; + xmode->green_mask = mode->green_mask; + xmode->blue_mask = mode->blue_mask; + xmode->visualClass = mode->visualClass; + xmode->viewportWidth = mode->viewportWidth; + xmode->viewportHeight = mode->viewportHeight; + xmode->xViewportStep = mode->xViewportStep; + xmode->yViewportStep = mode->yViewportStep; + xmode->maxViewportX = mode->maxViewportX; + xmode->maxViewportY = mode->maxViewportY; + xmode->viewportFlags = mode->viewportFlags; + xmode->reserved1 = mode->reserved1; + xmode->reserved2 = mode->reserved2; + xmode->offset = mode->offset; + + if (dmode->Flags & V_INTERLACE) + xmode->flags |= DGA_INTERLACED; + if (dmode->Flags & V_DBLSCAN) + xmode->flags |= DGA_DOUBLESCAN; } - Bool DGAVTSwitch(void) { ScreenPtr pScreen; int i; - for(i = 0; i < screenInfo.numScreens; i++) { - pScreen = screenInfo.screens[i]; + for (i = 0; i < screenInfo.numScreens; i++) { + pScreen = screenInfo.screens[i]; - /* Alternatively, this could send events to DGA clients */ + /* Alternatively, this could send events to DGA clients */ - if(DGAScreenKeyRegistered) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + if (DGAScreenKeyRegistered) { + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if(pScreenPriv && pScreenPriv->current) - return FALSE; - } + if (pScreenPriv && pScreenPriv->current) + return FALSE; + } } - return TRUE; + return TRUE; } Bool DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down) { - DGAScreenPtr pScreenPriv; - DGAEvent event; + DGAScreenPtr pScreenPriv; + DGAEvent event; - if(!DGAScreenKeyRegistered) /* no DGA */ + if (!DGAScreenKeyRegistered) /* no DGA */ return FALSE; - if (key_code < 8 || key_code > 255) - return FALSE; + if (key_code < 8 || key_code > 255) + return FALSE; - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - if(!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */ - return FALSE; + if (!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */ + return FALSE; memset(&event, 0, sizeof(event)); event.header = ET_Internal; @@ -937,23 +902,23 @@ DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down) event.detail = key_code; event.dx = 0; event.dy = 0; - mieqEnqueue (dev, (InternalEvent*)&event); + mieqEnqueue(dev, (InternalEvent *) &event); - return TRUE; -} + return TRUE; +} Bool DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy) { - DGAScreenPtr pScreenPriv; - DGAEvent event; + DGAScreenPtr pScreenPriv; + DGAEvent event; - if(!DGAScreenKeyRegistered) /* no DGA */ + if (!DGAScreenKeyRegistered) /* no DGA */ return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - if(!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */ + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + if (!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */ return FALSE; memset(&event, 0, sizeof(event)); @@ -965,7 +930,7 @@ DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy) event.detail = 0; event.dx = dx; event.dy = dy; - mieqEnqueue (dev, (InternalEvent*)&event); + mieqEnqueue(dev, (InternalEvent *) &event); return TRUE; } @@ -975,9 +940,9 @@ DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down) DGAScreenPtr pScreenPriv; DGAEvent event; - if(!DGAScreenKeyRegistered) /* no DGA */ + if (!DGAScreenKeyRegistered) /* no DGA */ return FALSE; - + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); if (!pScreenPriv || !pScreenPriv->grabMouse) @@ -992,32 +957,31 @@ DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down) event.detail = button; event.dx = 0; event.dy = 0; - mieqEnqueue (dev, (InternalEvent*)&event); + mieqEnqueue(dev, (InternalEvent *) &event); return TRUE; } /* We have the power to steal or modify events that are about to get queued */ -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -static Mask filters[] = -{ - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ +#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ +static Mask filters[] = { + NoSuchEvent, /* 0 */ + NoSuchEvent, /* 1 */ + KeyPressMask, /* KeyPress */ + KeyReleaseMask, /* KeyRelease */ + ButtonPressMask, /* ButtonPress */ + ButtonReleaseMask, /* ButtonRelease */ + PointerMotionMask, /* MotionNotify (initial state) */ }; static void -DGAProcessKeyboardEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr keybd) +DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd) { - KeyClassPtr keyc = keybd->key; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - DeviceIntPtr pointer = GetMaster(keybd, POINTER_OR_FLOAT); - DeviceEvent ev; + KeyClassPtr keyc = keybd->key; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + DeviceIntPtr pointer = GetMaster(keybd, POINTER_OR_FLOAT); + DeviceEvent ev; memset(&ev, 0, sizeof(ev)); ev.header = ET_Internal; @@ -1034,9 +998,9 @@ DGAProcessKeyboardEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr keybd) /* * Deliver the DGA event */ - if (pScreenPriv->client) - { + if (pScreenPriv->client) { dgaEvent de; + de.u.u.type = *XDGAEventBase + GetCoreType(ev.type); de.u.u.detail = event->detail; de.u.event.time = event->time; @@ -1045,39 +1009,37 @@ DGAProcessKeyboardEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr keybd) de.u.event.screen = pScreen->myNum; de.u.event.state = ev.corestate; - /* If the DGA client has selected input, then deliver based on the usual filter */ - TryClientEvents (pScreenPriv->client, keybd, (xEvent *)&de, 1, - filters[ev.type], pScreenPriv->input, 0); + /* If the DGA client has selected input, then deliver based on the usual filter */ + TryClientEvents(pScreenPriv->client, keybd, (xEvent *) &de, 1, + filters[ev.type], pScreenPriv->input, 0); } - else - { - /* If the keyboard is actively grabbed, deliver a grabbed core event */ - if (keybd->deviceGrab.grab && !keybd->deviceGrab.fromPassiveGrab) - { + else { + /* If the keyboard is actively grabbed, deliver a grabbed core event */ + if (keybd->deviceGrab.grab && !keybd->deviceGrab.fromPassiveGrab) { ev.detail.key = event->detail; - ev.time = event->time; - ev.root_x = event->dx; - ev.root_y = event->dy; - ev.corestate = event->state; - ev.deviceid = keybd->id; - DeliverGrabbedEvent ((InternalEvent*)&ev, keybd, FALSE); - } + ev.time = event->time; + ev.root_x = event->dx; + ev.root_y = event->dy; + ev.corestate = event->state; + ev.deviceid = keybd->id; + DeliverGrabbedEvent((InternalEvent *) &ev, keybd, FALSE); + } } } static void -DGAProcessPointerEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr mouse) +DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse) { - ButtonClassPtr butc = mouse->button; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - DeviceEvent ev; - DeviceIntPtr master = GetMaster(mouse, MASTER_KEYBOARD); + ButtonClassPtr butc = mouse->button; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + DeviceEvent ev; + DeviceIntPtr master = GetMaster(mouse, MASTER_KEYBOARD); memset(&ev, 0, sizeof(ev)); ev.header = ET_Internal; ev.length = sizeof(ev); ev.type = event->subtype; - ev.corestate = butc ? butc->state : 0; + ev.corestate = butc ? butc->state : 0; if (master && master->key) ev.corestate |= XkbStateFieldFromRec(&master->key->xkbInfo->state); @@ -1086,10 +1048,9 @@ DGAProcessPointerEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr mouse) /* * Deliver the DGA event */ - if (pScreenPriv->client) - { - dgaEvent de; - int coreEquiv; + if (pScreenPriv->client) { + dgaEvent de; + int coreEquiv; coreEquiv = GetCoreType(ev.type); @@ -1101,54 +1062,49 @@ DGAProcessPointerEvent (ScreenPtr pScreen, DGAEvent *event, DeviceIntPtr mouse) de.u.event.screen = pScreen->myNum; de.u.event.state = ev.corestate; - /* If the DGA client has selected input, then deliver based on the usual filter */ - TryClientEvents (pScreenPriv->client, mouse, (xEvent *)&de, 1, - filters[coreEquiv], pScreenPriv->input, 0); + /* If the DGA client has selected input, then deliver based on the usual filter */ + TryClientEvents(pScreenPriv->client, mouse, (xEvent *) &de, 1, + filters[coreEquiv], pScreenPriv->input, 0); } - else - { - /* If the pointer is actively grabbed, deliver a grabbed core event */ - if (mouse->deviceGrab.grab && !mouse->deviceGrab.fromPassiveGrab) - { - ev.detail.button = event->detail; - ev.time = event->time; - ev.root_x = event->dx; - ev.root_y = event->dy; - ev.corestate = event->state; + else { + /* If the pointer is actively grabbed, deliver a grabbed core event */ + if (mouse->deviceGrab.grab && !mouse->deviceGrab.fromPassiveGrab) { + ev.detail.button = event->detail; + ev.time = event->time; + ev.root_x = event->dx; + ev.root_y = event->dy; + ev.corestate = event->state; /* DGA is core only, so valuators.data doesn't actually matter. * Mask must be set for EventToCore to create motion events. */ SetBit(ev.valuators.mask, 0); SetBit(ev.valuators.mask, 1); - DeliverGrabbedEvent ((InternalEvent*)&ev, mouse, FALSE); - } + DeliverGrabbedEvent((InternalEvent *) &ev, mouse, FALSE); + } } } Bool -DGAOpenFramebuffer( - int index, - char **name, - unsigned char **mem, - int *size, - int *offset, - int *flags -){ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - - return (*pScreenPriv->funcs->OpenFramebuffer)(pScreenPriv->pScrn, - name, mem, size, offset, flags); +DGAOpenFramebuffer(int index, + char **name, + unsigned char **mem, int *size, int *offset, int *flags) +{ + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + /* We rely on the extension to check that DGA is available */ + + return (*pScreenPriv->funcs->OpenFramebuffer) (pScreenPriv->pScrn, + name, mem, size, offset, + flags); } void DGACloseFramebuffer(int index) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - /* We rely on the extension to check that DGA is available */ - if(pScreenPriv->funcs->CloseFramebuffer) - (*pScreenPriv->funcs->CloseFramebuffer)(pScreenPriv->pScrn); + /* We rely on the extension to check that DGA is available */ + if (pScreenPriv->funcs->CloseFramebuffer) + (*pScreenPriv->funcs->CloseFramebuffer) (pScreenPriv->pScrn); } /* For DGA 1.0 backwards compatibility only */ @@ -1156,62 +1112,62 @@ DGACloseFramebuffer(int index) int DGAGetOldDGAMode(int index) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - ScrnInfoPtr pScrn = pScreenPriv->pScrn; - DGAModePtr mode; - int i, w, h, p; - - /* We rely on the extension to check that DGA is available */ - - w = pScrn->currentMode->HDisplay; - h = pScrn->currentMode->VDisplay; - p = pad_to_int32(pScrn->displayWidth * bits_to_bytes(pScrn->bitsPerPixel)); - - for(i = 0; i < pScreenPriv->numModes; i++) { - mode = &(pScreenPriv->modes[i]); - - if((mode->viewportWidth == w) && (mode->viewportHeight == h) && - (mode->bytesPerScanline == p) && - (mode->bitsPerPixel == pScrn->bitsPerPixel) && - (mode->depth == pScrn->depth)) { - - return mode->num; - } - } - - return 0; + DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + ScrnInfoPtr pScrn = pScreenPriv->pScrn; + DGAModePtr mode; + int i, w, h, p; + + /* We rely on the extension to check that DGA is available */ + + w = pScrn->currentMode->HDisplay; + h = pScrn->currentMode->VDisplay; + p = pad_to_int32(pScrn->displayWidth * bits_to_bytes(pScrn->bitsPerPixel)); + + for (i = 0; i < pScreenPriv->numModes; i++) { + mode = &(pScreenPriv->modes[i]); + + if ((mode->viewportWidth == w) && (mode->viewportHeight == h) && + (mode->bytesPerScanline == p) && + (mode->bitsPerPixel == pScrn->bitsPerPixel) && + (mode->depth == pScrn->depth)) { + + return mode->num; + } + } + + return 0; } static void DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device) { - DGAEvent *event= &ev->dga_event; - ScreenPtr pScreen = screenInfo.screens[screen_num]; - DGAScreenPtr pScreenPriv; + DGAEvent *event = &ev->dga_event; + ScreenPtr pScreen = screenInfo.screens[screen_num]; + DGAScreenPtr pScreenPriv; /* no DGA */ if (!DGAScreenKeyRegistered || XDGAEventBase == 0) - return; + return; pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); /* DGA not initialized on this screen */ if (!pScreenPriv) - return; + return; if (!IsMaster(device)) - return; + return; switch (event->subtype) { case KeyPress: case KeyRelease: - DGAProcessKeyboardEvent (pScreen, event, device); - break; + DGAProcessKeyboardEvent(pScreen, event, device); + break; case MotionNotify: case ButtonPress: case ButtonRelease: - DGAProcessPointerEvent (pScreen, event, device); + DGAProcessPointerEvent(pScreen, event, device); break; default: - break; + break; } } diff --git a/xorg-server/hw/xfree86/common/xf86Events.c b/xorg-server/hw/xfree86/common/xf86Events.c index 41ffabde3..058057e92 100644 --- a/xorg-server/hw/xfree86/common/xf86Events.c +++ b/xorg-server/hw/xfree86/common/xf86Events.c @@ -93,15 +93,15 @@ * This has been generalised to work with Linux and *BSD+syscons (DHD) */ -Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for - *BSD and for avoiding VT - switches when using the DRI - automatic full screen mode.*/ +Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for + *BSD and for avoiding VT + switches when using the DRI + automatic full screen mode.*/ extern fd_set EnabledDevices; #ifdef XF86PM -extern void (*xf86OSPMClose)(void); +extern void (*xf86OSPMClose) (void); #endif static void xf86VTSwitch(void); @@ -111,16 +111,15 @@ static void xf86VTSwitch(void); * Wakeup handler. */ typedef struct x_IHRec { - int fd; - InputHandlerProc ihproc; - pointer data; - Bool enabled; - struct x_IHRec * next; + int fd; + InputHandlerProc ihproc; + pointer data; + Bool enabled; + struct x_IHRec *next; } IHRec, *IHPtr; static IHPtr InputHandlers = NULL; - Bool LegalModifier(unsigned int key, DeviceIntPtr pDev) { @@ -135,10 +134,10 @@ LegalModifier(unsigned int key, DeviceIntPtr pDev) int TimeSinceLastInputEvent(void) { - if (xf86Info.lastEventTime == 0) { - xf86Info.lastEventTime = GetTimeInMillis(); - } - return GetTimeInMillis() - xf86Info.lastEventTime; + if (xf86Info.lastEventTime == 0) { + xf86Info.lastEventTime = GetTimeInMillis(); + } + return GetTimeInMillis() - xf86Info.lastEventTime; } /* @@ -148,7 +147,7 @@ TimeSinceLastInputEvent(void) void SetTimeSinceLastInputEvent(void) { - xf86Info.lastEventTime = GetTimeInMillis(); + xf86Info.lastEventTime = GetTimeInMillis(); } /* @@ -158,15 +157,16 @@ SetTimeSinceLastInputEvent(void) * and keyboard. */ void -ProcessInputEvents (void) +ProcessInputEvents(void) { - int x, y; + int x, y; + + mieqProcessInputEvents(); - mieqProcessInputEvents(); + /* FIXME: This is a problem if we have multiple pointers */ + miPointerGetPosition(inputInfo.pointer, &x, &y); - /* FIXME: This is a problem if we have multiple pointers */ - miPointerGetPosition(inputInfo.pointer, &x, &y); - xf86SetViewport(xf86Info.currentScreen, x, y); + xf86SetViewport(xf86Info.currentScreen, x, y); } /* @@ -179,57 +179,57 @@ xf86ProcessActionEvent(ActionEvent action, void *arg) DebugF("ProcessActionEvent(%d,%x)\n", (int) action, arg); switch (action) { case ACTION_TERMINATE: - if (!xf86Info.dontZap) { + if (!xf86Info.dontZap) { #ifdef XFreeXDGA - DGAShutdown(); + DGAShutdown(); #endif - GiveUp(0); - } - break; + GiveUp(0); + } + break; case ACTION_NEXT_MODE: - if (!xf86Info.dontZoom) - xf86ZoomViewport(xf86Info.currentScreen, 1); - break; + if (!xf86Info.dontZoom) + xf86ZoomViewport(xf86Info.currentScreen, 1); + break; case ACTION_PREV_MODE: - if (!xf86Info.dontZoom) - xf86ZoomViewport(xf86Info.currentScreen, -1); - break; + if (!xf86Info.dontZoom) + xf86ZoomViewport(xf86Info.currentScreen, -1); + break; case ACTION_SWITCHSCREEN: - if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) { - int vtno = *((int *) arg); - - if (vtno != xf86Info.vtno) { - if (!xf86VTActivate(vtno)) { - ErrorF("Failed to switch from vt%02d to vt%02d: %s\n", - xf86Info.vtno, vtno, strerror(errno)); - } - } - } - break; + if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) { + int vtno = *((int *) arg); + + if (vtno != xf86Info.vtno) { + if (!xf86VTActivate(vtno)) { + ErrorF("Failed to switch from vt%02d to vt%02d: %s\n", + xf86Info.vtno, vtno, strerror(errno)); + } + } + } + break; case ACTION_SWITCHSCREEN_NEXT: - if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { - if (!xf86VTActivate(xf86Info.vtno + 1)) { - /* If first try failed, assume this is the last VT and - * try wrapping around to the first vt. - */ - if (!xf86VTActivate(1)) { - ErrorF("Failed to switch from vt%02d to next vt: %s\n", - xf86Info.vtno, strerror(errno)); - } - } - } - break; + if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { + if (!xf86VTActivate(xf86Info.vtno + 1)) { + /* If first try failed, assume this is the last VT and + * try wrapping around to the first vt. + */ + if (!xf86VTActivate(1)) { + ErrorF("Failed to switch from vt%02d to next vt: %s\n", + xf86Info.vtno, strerror(errno)); + } + } + } + break; case ACTION_SWITCHSCREEN_PREV: - if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) { - if (!xf86VTActivate(xf86Info.vtno - 1)) { - /* Don't know what the maximum VT is, so can't wrap around */ - ErrorF("Failed to switch from vt%02d to previous vt: %s\n", - xf86Info.vtno, strerror(errno)); - } - } - break; + if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) { + if (!xf86VTActivate(xf86Info.vtno - 1)) { + /* Don't know what the maximum VT is, so can't wrap around */ + ErrorF("Failed to switch from vt%02d to previous vt: %s\n", + xf86Info.vtno, strerror(errno)); + } + } + break; default: - break; + break; } } @@ -242,49 +242,49 @@ xf86ProcessActionEvent(ActionEvent action, void *arg) void xf86Wakeup(pointer blockData, int err, pointer pReadmask) { - fd_set* LastSelectMask = (fd_set*)pReadmask; + fd_set *LastSelectMask = (fd_set *) pReadmask; fd_set devicesWithInput; InputInfoPtr pInfo; if (err >= 0) { - XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices); - if (XFD_ANYSET(&devicesWithInput)) { - pInfo = xf86InputDevs; - while (pInfo) { - if (pInfo->read_input && pInfo->fd >= 0 && - (FD_ISSET(pInfo->fd, &devicesWithInput) != 0)) { - int sigstate = xf86BlockSIGIO(); - - /* - * Remove the descriptior from the set because more than one - * device may share the same file descriptor. - */ - FD_CLR(pInfo->fd, &devicesWithInput); - - pInfo->read_input(pInfo); - xf86UnblockSIGIO(sigstate); - } - pInfo = pInfo->next; - } - } + XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices); + if (XFD_ANYSET(&devicesWithInput)) { + pInfo = xf86InputDevs; + while (pInfo) { + if (pInfo->read_input && pInfo->fd >= 0 && + (FD_ISSET(pInfo->fd, &devicesWithInput) != 0)) { + int sigstate = xf86BlockSIGIO(); + + /* + * Remove the descriptior from the set because more than one + * device may share the same file descriptor. + */ + FD_CLR(pInfo->fd, &devicesWithInput); + + pInfo->read_input(pInfo); + xf86UnblockSIGIO(sigstate); + } + pInfo = pInfo->next; + } + } } - if (err >= 0) { /* we don't want the handlers called if select() */ - IHPtr ih; /* returned with an error condition, do we? */ - - for (ih = InputHandlers; ih; ih = ih->next) { - if (ih->enabled && ih->fd >= 0 && ih->ihproc && - (FD_ISSET(ih->fd, ((fd_set *)pReadmask)) != 0)) { - ih->ihproc(ih->fd, ih->data); - } - } + if (err >= 0) { /* we don't want the handlers called if select() */ + IHPtr ih; /* returned with an error condition, do we? */ + + for (ih = InputHandlers; ih; ih = ih->next) { + if (ih->enabled && ih->fd >= 0 && ih->ihproc && + (FD_ISSET(ih->fd, ((fd_set *) pReadmask)) != 0)) { + ih->ihproc(ih->fd, ih->data); + } + } } - if (xf86VTSwitchPending()) xf86VTSwitch(); + if (xf86VTSwitchPending()) + xf86VTSwitch(); } - /* * xf86SigioReadInput -- * signal handler for the SIGIO signal. @@ -307,8 +307,8 @@ xf86SigioReadInput(int fd, void *closure) void xf86AddEnabledDevice(InputInfoPtr pInfo) { - if (!xf86InstallSIGIOHandler (pInfo->fd, xf86SigioReadInput, pInfo)) { - AddEnabledDevice(pInfo->fd); + if (!xf86InstallSIGIOHandler(pInfo->fd, xf86SigioReadInput, pInfo)) { + AddEnabledDevice(pInfo->fd); } } @@ -319,8 +319,8 @@ xf86AddEnabledDevice(InputInfoPtr pInfo) void xf86RemoveEnabledDevice(InputInfoPtr pInfo) { - if (!xf86RemoveSIGIOHandler (pInfo->fd)) { - RemoveEnabledDevice(pInfo->fd); + if (!xf86RemoveSIGIOHandler(pInfo->fd)) { + RemoveEnabledDevice(pInfo->fd); } } @@ -330,13 +330,13 @@ void xf86InterceptSignals(int *signo) { if ((xf86SignalIntercept = signo)) - *signo = -1; + *signo = -1; } -static void (*xf86SigIllHandler)(void) = NULL; +static void (*xf86SigIllHandler) (void) = NULL; void -xf86InterceptSigIll(void (*sigillhandler)(void)) +xf86InterceptSigIll(void (*sigillhandler) (void)) { xf86SigIllHandler = sigillhandler; } @@ -348,18 +348,18 @@ xf86InterceptSigIll(void (*sigillhandler)(void)) int xf86SigWrapper(int signo) { - if ((signo == SIGILL) && xf86SigIllHandler) { - (*xf86SigIllHandler)(); - return 0; /* continue */ - } - - if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) { - *xf86SignalIntercept = signo; - return 0; /* continue */ - } - - xf86Info.caughtSignal = TRUE; - return 1; /* abort */ + if ((signo == SIGILL) && xf86SigIllHandler) { + (*xf86SigIllHandler) (); + return 0; /* continue */ + } + + if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) { + *xf86SignalIntercept = signo; + return 0; /* continue */ + } + + xf86Info.caughtSignal = TRUE; + return 1; /* abort */ } /* @@ -395,10 +395,9 @@ xf86ReleaseKeys(DeviceIntPtr pDev) */ for (i = keyc->xkbInfo->desc->min_key_code; - i < keyc->xkbInfo->desc->max_key_code; - i++) { + i < keyc->xkbInfo->desc->max_key_code; i++) { if (key_is_down(pDev, i, KEY_POSTED)) { - sigstate = xf86BlockSIGIO (); + sigstate = xf86BlockSIGIO(); QueueKeyboardEvents(pDev, KeyRelease, i, NULL); xf86UnblockSIGIO(sigstate); } @@ -412,142 +411,144 @@ xf86ReleaseKeys(DeviceIntPtr pDev) static void xf86VTSwitch(void) { - int i; - static int prevSIGIO; - InputInfoPtr pInfo; - IHPtr ih; + int i; + static int prevSIGIO; + InputInfoPtr pInfo; + IHPtr ih; - DebugF("xf86VTSwitch()\n"); + DebugF("xf86VTSwitch()\n"); #ifdef XFreeXDGA - if(!DGAVTSwitch()) - return; + if (!DGAVTSwitch()) + return; #endif - /* - * Since all screens are currently all in the same state it is sufficient - * check the first. This might change in future. - */ - if (xf86Screens[0]->vtSema) { + /* + * Since all screens are currently all in the same state it is sufficient + * check the first. This might change in future. + */ + if (xf86Screens[0]->vtSema) { - DebugF("xf86VTSwitch: Leaving, xf86Exiting is %s\n", - BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE)); + DebugF("xf86VTSwitch: Leaving, xf86Exiting is %s\n", + BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE)); #ifdef DPMSExtension - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(serverClient, DPMSModeOn); + if (DPMSPowerLevel != DPMSModeOn) + DPMSSet(serverClient, DPMSModeOn); #endif - for (i = 0; i < xf86NumScreens; i++) { - if (!(dispatchException & DE_TERMINATE)) - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); - } + for (i = 0; i < xf86NumScreens; i++) { + if (!(dispatchException & DE_TERMINATE)) + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); + } - /* - * Keep the order: Disable Device > LeaveVT - * EnterVT > EnableDevice - */ - for (ih = InputHandlers; ih; ih = ih->next) - xf86DisableInputHandler(ih); - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) { - if (pInfo->dev) { - xf86ReleaseKeys(pInfo->dev); - ProcessInputEvents(); - DisableDevice(pInfo->dev, TRUE); - } - } + /* + * Keep the order: Disable Device > LeaveVT + * EnterVT > EnableDevice + */ + for (ih = InputHandlers; ih; ih = ih->next) + xf86DisableInputHandler(ih); + for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) { + if (pInfo->dev) { + xf86ReleaseKeys(pInfo->dev); + ProcessInputEvents(); + DisableDevice(pInfo->dev, TRUE); + } + } + + prevSIGIO = xf86BlockSIGIO(); + for (i = 0; i < xf86NumScreens; i++) + xf86Screens[i]->LeaveVT(i, 0); + + xf86AccessLeave(); /* We need this here, otherwise */ + + if (!xf86VTSwitchAway()) { + /* + * switch failed + */ + + DebugF("xf86VTSwitch: Leave failed\n"); + xf86AccessEnter(); + for (i = 0; i < xf86NumScreens; i++) { + if (!xf86Screens[i]->EnterVT(i, 0)) + FatalError("EnterVT failed for screen %d\n", i); + } + if (!(dispatchException & DE_TERMINATE)) { + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); + } + } + dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); + + pInfo = xf86InputDevs; + while (pInfo) { + if (pInfo->dev) + EnableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; + } + for (ih = InputHandlers; ih; ih = ih->next) + xf86EnableInputHandler(ih); + + xf86UnblockSIGIO(prevSIGIO); - prevSIGIO = xf86BlockSIGIO(); - for (i = 0; i < xf86NumScreens; i++) - xf86Screens[i]->LeaveVT(i, 0); - - xf86AccessLeave(); /* We need this here, otherwise */ - - if (!xf86VTSwitchAway()) { - /* - * switch failed - */ - - DebugF("xf86VTSwitch: Leave failed\n"); - xf86AccessEnter(); - for (i = 0; i < xf86NumScreens; i++) { - if (!xf86Screens[i]->EnterVT(i, 0)) - FatalError("EnterVT failed for screen %d\n", i); - } - if (!(dispatchException & DE_TERMINATE)) { - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); - } - } - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - - pInfo = xf86InputDevs; - while (pInfo) { - if (pInfo->dev) - EnableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; - } - for (ih = InputHandlers; ih; ih = ih->next) - xf86EnableInputHandler(ih); - - xf86UnblockSIGIO(prevSIGIO); - - } else { + } + else { #ifdef XF86PM - if (xf86OSPMClose) - xf86OSPMClose(); - xf86OSPMClose = NULL; + if (xf86OSPMClose) + xf86OSPMClose(); + xf86OSPMClose = NULL; #endif - for (i = 0; i < xf86NumScreens; i++) { - /* - * zero all access functions to - * trap calls when switched away. - */ - xf86Screens[i]->vtSema = FALSE; - } - if (xorgHWAccess) - xf86DisableIO(); + for (i = 0; i < xf86NumScreens; i++) { + /* + * zero all access functions to + * trap calls when switched away. + */ + xf86Screens[i]->vtSema = FALSE; + } + if (xorgHWAccess) + xf86DisableIO(); + } } - } else { - DebugF("xf86VTSwitch: Entering\n"); - if (!xf86VTSwitchTo()) return; + else { + DebugF("xf86VTSwitch: Entering\n"); + if (!xf86VTSwitchTo()) + return; #ifdef XF86PM - xf86OSPMClose = xf86OSPMOpen(); + xf86OSPMClose = xf86OSPMOpen(); #endif - if (xorgHWAccess) - xf86EnableIO(); - xf86AccessEnter(); - for (i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->vtSema = TRUE; - if (!xf86Screens[i]->EnterVT(i, 0)) - FatalError("EnterVT failed for screen %d\n", i); - } - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess)(i, TRUE); - } + if (xorgHWAccess) + xf86EnableIO(); + xf86AccessEnter(); + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->vtSema = TRUE; + if (!xf86Screens[i]->EnterVT(i, 0)) + FatalError("EnterVT failed for screen %d\n", i); + } + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); + } - /* Turn screen saver off when switching back */ - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); + /* Turn screen saver off when switching back */ + dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - pInfo = xf86InputDevs; - while (pInfo) { - if (pInfo->dev) - EnableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; - } + pInfo = xf86InputDevs; + while (pInfo) { + if (pInfo->dev) + EnableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; + } - for (ih = InputHandlers; ih; ih = ih->next) - xf86EnableInputHandler(ih); + for (ih = InputHandlers; ih; ih = ih->next) + xf86EnableInputHandler(ih); - xf86UnblockSIGIO(prevSIGIO); - } + xf86UnblockSIGIO(prevSIGIO); + } } - /* Input handler registration */ static pointer @@ -556,11 +557,11 @@ addInputHandler(int fd, InputHandlerProc proc, pointer data) IHPtr ih; if (fd < 0 || !proc) - return NULL; + return NULL; ih = calloc(sizeof(*ih), 1); if (!ih) - return NULL; + return NULL; ih->fd = fd; ih->ihproc = proc; @@ -618,13 +619,13 @@ removeInputHandler(IHPtr ih) IHPtr p; if (ih == InputHandlers) - InputHandlers = ih->next; + InputHandlers = ih->next; else { - p = InputHandlers; - while (p && p->next != ih) - p = p->next; - if (ih) - p->next = ih->next; + p = InputHandlers; + while (p && p->next != ih) + p = p->next; + if (ih) + p->next = ih->next; } free(ih); } @@ -636,13 +637,13 @@ xf86RemoveInputHandler(pointer handler) int fd; if (!handler) - return -1; + return -1; ih = handler; fd = ih->fd; if (ih->fd >= 0) - RemoveEnabledDevice(ih->fd); + RemoveEnabledDevice(ih->fd); removeInputHandler(ih); return fd; @@ -655,13 +656,13 @@ xf86RemoveGeneralHandler(pointer handler) int fd; if (!handler) - return -1; + return -1; ih = handler; fd = ih->fd; if (ih->fd >= 0) - RemoveGeneralSocket(ih->fd); + RemoveGeneralSocket(ih->fd); removeInputHandler(ih); return fd; @@ -673,12 +674,12 @@ xf86DisableInputHandler(pointer handler) IHPtr ih; if (!handler) - return; + return; ih = handler; ih->enabled = FALSE; if (ih->fd >= 0) - RemoveEnabledDevice(ih->fd); + RemoveEnabledDevice(ih->fd); } void @@ -687,12 +688,12 @@ xf86DisableGeneralHandler(pointer handler) IHPtr ih; if (!handler) - return; + return; ih = handler; ih->enabled = FALSE; if (ih->fd >= 0) - RemoveGeneralSocket(ih->fd); + RemoveGeneralSocket(ih->fd); } void @@ -701,12 +702,12 @@ xf86EnableInputHandler(pointer handler) IHPtr ih; if (!handler) - return; + return; ih = handler; ih->enabled = TRUE; if (ih->fd >= 0) - AddEnabledDevice(ih->fd); + AddEnabledDevice(ih->fd); } void @@ -715,12 +716,12 @@ xf86EnableGeneralHandler(pointer handler) IHPtr ih; if (!handler) - return; + return; ih = handler; ih->enabled = TRUE; if (ih->fd >= 0) - AddGeneralSocket(ih->fd); + AddGeneralSocket(ih->fd); } /* @@ -734,17 +735,19 @@ xf86EnableVTSwitch(Bool new) old = VTSwitchEnabled; if (!new) { - /* Disable VT switching */ - def = VTSwitchEnabled; - VTSwitchEnabled = FALSE; - } else { - /* Restore VT switching to default */ - VTSwitchEnabled = def; + /* Disable VT switching */ + def = VTSwitchEnabled; + VTSwitchEnabled = FALSE; + } + else { + /* Restore VT switching to default */ + VTSwitchEnabled = def; } return old; } void -DDXRingBell(int volume, int pitch, int duration) { +DDXRingBell(int volume, int pitch, int duration) +{ xf86OSRingBell(volume, pitch, duration); } diff --git a/xorg-server/hw/xfree86/common/xf86Globals.c b/xorg-server/hw/xfree86/common/xf86Globals.c index d576fb915..0071004eb 100644 --- a/xorg-server/hw/xfree86/common/xf86Globals.c +++ b/xorg-server/hw/xfree86/common/xf86Globals.c @@ -50,9 +50,9 @@ DevPrivateKeyRec xf86CreateRootWindowKeyRec; DevPrivateKeyRec xf86ScreenKeyRec; -ScrnInfoPtr *xf86Screens = NULL; /* List of ScrnInfos */ -const unsigned char byte_reversed[256] = -{ +ScrnInfoPtr *xf86Screens = NULL; /* List of ScrnInfos */ + +const unsigned char byte_reversed[256] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, @@ -90,49 +90,49 @@ const unsigned char byte_reversed[256] = /* Globals that input drivers may access */ InputInfoPtr xf86InputDevs = NULL; - /* Globals that video drivers may not access */ xf86InfoRec xf86Info = { - .consoleFd = -1, - .vtno = -1, - .lastEventTime = -1, - .vtRequestsPending = FALSE, + .consoleFd = -1, + .vtno = -1, + .lastEventTime = -1, + .vtRequestsPending = FALSE, #ifdef sun - .vtPendingNum = -1, + .vtPendingNum = -1, #endif - .dontVTSwitch = FALSE, - .autoVTSwitch = TRUE, - .ShareVTs = FALSE, - .dontZap = FALSE, - .dontZoom = FALSE, - .notrapSignals = FALSE, - .caughtSignal = FALSE, - .currentScreen = NULL, + .dontVTSwitch = FALSE, + .autoVTSwitch = TRUE, + .ShareVTs = FALSE, + .dontZap = FALSE, + .dontZoom = FALSE, + .notrapSignals = FALSE, + .caughtSignal = FALSE, + .currentScreen = NULL, #ifdef CSRG_BASED - .consType = -1, + .consType = -1, #endif - .allowMouseOpenFail = FALSE, - .vidModeEnabled = TRUE, - .vidModeAllowNonLocal = FALSE, - .miscModInDevEnabled = TRUE, - .miscModInDevAllowNonLocal = FALSE, - .pixmap24 = Pix24DontCare, - .pix24From = X_DEFAULT, - .pmFlag = TRUE, - .log = LogNone, - .disableRandR = FALSE, - .randRFrom = X_DEFAULT, + .allowMouseOpenFail = FALSE, + .vidModeEnabled = TRUE, + .vidModeAllowNonLocal = FALSE, + .miscModInDevEnabled = TRUE, + .miscModInDevAllowNonLocal = FALSE, + .pixmap24 = Pix24DontCare, + .pix24From = X_DEFAULT, + .pmFlag = TRUE, + .log = LogNone, + .disableRandR = FALSE, + .randRFrom = X_DEFAULT, #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) - .forceInputDevices = FALSE, - .autoAddDevices = TRUE, - .autoEnableDevices = TRUE + .forceInputDevices = FALSE, + .autoAddDevices = TRUE, + .autoEnableDevices = TRUE #else - .forceInputDevices = TRUE, - .autoAddDevices = FALSE, - .autoEnableDevices = FALSE + .forceInputDevices = TRUE, + .autoAddDevices = FALSE, + .autoEnableDevices = FALSE #endif }; + const char *xf86ConfigFile = NULL; const char *xf86ConfigDir = NULL; const char *xf86ModulePath = DEFAULT_MODULE_PATH; @@ -140,8 +140,9 @@ MessageType xf86ModPathFrom = X_DEFAULT; const char *xf86LogFile = DEFAULT_LOGPREFIX; MessageType xf86LogFileFrom = X_DEFAULT; Bool xf86LogFileWasOpened = FALSE; -serverLayoutRec xf86ConfigLayout = {NULL, }; -confDRIRec xf86ConfigDRI = {0, }; +serverLayoutRec xf86ConfigLayout = { NULL, }; +confDRIRec xf86ConfigDRI = { 0, }; + XF86ConfigPtr xf86configptr = NULL; Bool xf86Resetting = FALSE; Bool xf86Initialising = FALSE; @@ -154,12 +155,12 @@ int xf86NumInputDrivers = 0; int xf86NumScreens = 0; const char *xf86VisualNames[] = { - "StaticGray", - "GrayScale", - "StaticColor", - "PseudoColor", - "TrueColor", - "DirectColor" + "StaticGray", + "GrayScale", + "StaticColor", + "PseudoColor", + "TrueColor", + "DirectColor" }; /* Parameters set only from the command line */ @@ -170,6 +171,7 @@ Bool xf86bsEnableFlag = FALSE; Bool xf86bsDisableFlag = FALSE; Bool xf86silkenMouseDisableFlag = FALSE; Bool xf86xkbdirFlag = FALSE; + #ifdef HAVE_ACPI Bool xf86acpiDisableFlag = FALSE; #endif @@ -182,10 +184,13 @@ int xf86LogVerbose = DEFAULT_LOG_VERBOSE; int xf86FbBpp = -1; Pix24Flags xf86Pix24 = Pix24DontCare; int xf86Depth = -1; -rgb xf86Weight = {0, 0, 0}; +rgb xf86Weight = { 0, 0, 0 }; + Bool xf86FlipPixels = FALSE; -Gamma xf86Gamma = {0.0, 0.0, 0.0}; +Gamma xf86Gamma = { 0.0, 0.0, 0.0 }; + Bool xf86AllowMouseOpenFail = FALSE; + #ifdef XF86VIDMODE Bool xf86VidModeDisabled = FALSE; Bool xf86VidModeAllowNonLocal = FALSE; diff --git a/xorg-server/hw/xfree86/common/xf86Helper.c b/xorg-server/hw/xfree86/common/xf86Helper.c index 248ccf47e..8c948cf6f 100644 --- a/xorg-server/hw/xfree86/common/xf86Helper.c +++ b/xorg-server/hw/xfree86/common/xf86Helper.c @@ -64,7 +64,6 @@ static int xf86ScrnInfoPrivateCount = 0; - /* Add a pointer to a new DriverRec to xf86DriverList */ void @@ -72,22 +71,21 @@ xf86AddDriver(DriverPtr driver, pointer module, int flags) { /* Don't add null entries */ if (!driver) - return; + return; if (xf86DriverList == NULL) - xf86NumDrivers = 0; + xf86NumDrivers = 0; xf86NumDrivers++; xf86DriverList = xnfrealloc(xf86DriverList, - xf86NumDrivers * sizeof(DriverPtr)); + xf86NumDrivers * sizeof(DriverPtr)); xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec)); if (flags & HaveDriverFuncs) - *xf86DriverList[xf86NumDrivers - 1] = *driver; + *xf86DriverList[xf86NumDrivers - 1] = *driver; else { - (void) memset( xf86DriverList[xf86NumDrivers - 1], 0, - sizeof( DriverRec ) ); - (void) memcpy( xf86DriverList[xf86NumDrivers - 1], driver, - sizeof(DriverRec1)); + (void) memset(xf86DriverList[xf86NumDrivers - 1], 0, sizeof(DriverRec)); + (void) memcpy(xf86DriverList[xf86NumDrivers - 1], driver, + sizeof(DriverRec1)); } xf86DriverList[xf86NumDrivers - 1]->module = module; @@ -98,11 +96,11 @@ void xf86DeleteDriver(int drvIndex) { if (xf86DriverList[drvIndex] - && (!xf86DriverHasEntities(xf86DriverList[drvIndex]))) { - if (xf86DriverList[drvIndex]->module) - UnloadModule(xf86DriverList[drvIndex]->module); - free(xf86DriverList[drvIndex]); - xf86DriverList[drvIndex] = NULL; + && (!xf86DriverHasEntities(xf86DriverList[drvIndex]))) { + if (xf86DriverList[drvIndex]->module) + UnloadModule(xf86DriverList[drvIndex]->module); + free(xf86DriverList[drvIndex]); + xf86DriverList[drvIndex] = NULL; } } @@ -113,16 +111,17 @@ xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags) { /* Don't add null entries */ if (!driver) - return; + return; if (xf86InputDriverList == NULL) - xf86NumInputDrivers = 0; + xf86NumInputDrivers = 0; xf86NumInputDrivers++; xf86InputDriverList = xnfrealloc(xf86InputDriverList, - xf86NumInputDrivers * sizeof(InputDriverPtr)); + xf86NumInputDrivers * + sizeof(InputDriverPtr)); xf86InputDriverList[xf86NumInputDrivers - 1] = - xnfalloc(sizeof(InputDriverRec)); + xnfalloc(sizeof(InputDriverRec)); *xf86InputDriverList[xf86NumInputDrivers - 1] = *driver; xf86InputDriverList[xf86NumInputDrivers - 1]->module = module; } @@ -131,7 +130,7 @@ void xf86DeleteInputDriver(int drvIndex) { if (xf86InputDriverList[drvIndex] && xf86InputDriverList[drvIndex]->module) - UnloadModule(xf86InputDriverList[drvIndex]->module); + UnloadModule(xf86InputDriverList[drvIndex]->module); free(xf86InputDriverList[drvIndex]); xf86InputDriverList[drvIndex] = NULL; } @@ -142,9 +141,9 @@ xf86LookupInputDriver(const char *name) int i; for (i = 0; i < xf86NumInputDrivers; i++) { - if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && - xf86NameCmp(name, xf86InputDriverList[i]->driverName) == 0) - return xf86InputDriverList[i]; + if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && + xf86NameCmp(name, xf86InputDriverList[i]->driverName) == 0) + return xf86InputDriverList[i]; } return NULL; } @@ -170,15 +169,15 @@ xf86AllocateScreen(DriverPtr drv, int flags) int i; if (xf86Screens == NULL) - xf86NumScreens = 0; + xf86NumScreens = 0; i = xf86NumScreens++; xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr)); xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1); - xf86Screens[i]->scrnIndex = i; /* Changes when a screen is removed */ - xf86Screens[i]->origIndex = i; /* This never changes */ + xf86Screens[i]->scrnIndex = i; /* Changes when a screen is removed */ + xf86Screens[i]->origIndex = i; /* This never changes */ xf86Screens[i]->privates = xnfcalloc(sizeof(DevUnion), - xf86ScrnInfoPrivateCount); + xf86ScrnInfoPrivateCount); /* * EnableDisableFBAccess now gets initialized in InitOutput() * xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess; @@ -193,7 +192,6 @@ xf86AllocateScreen(DriverPtr drv, int flags) return xf86Screens[i]; } - /* * Remove an entry from xf86Screens. Ideally it should free all allocated * data. To do this properly may require a driver hook. @@ -207,31 +205,31 @@ xf86DeleteScreen(int scrnIndex, int flags) /* First check if the screen is valid */ if (xf86NumScreens == 0 || xf86Screens == NULL) - return; + return; if (scrnIndex > xf86NumScreens - 1) - return; + return; if (!(pScrn = xf86Screens[scrnIndex])) - return; + return; /* If a FreeScreen function is defined, call it here */ if (pScrn->FreeScreen != NULL) - pScrn->FreeScreen(scrnIndex, 0); + pScrn->FreeScreen(scrnIndex, 0); while (pScrn->modes) - xf86DeleteMode(&pScrn->modes, pScrn->modes); + xf86DeleteMode(&pScrn->modes, pScrn->modes); while (pScrn->modePool) - xf86DeleteMode(&pScrn->modePool, pScrn->modePool); + xf86DeleteMode(&pScrn->modePool, pScrn->modePool); xf86OptionListFree(pScrn->options); if (pScrn->module) - UnloadModule(pScrn->module); + UnloadModule(pScrn->module); if (pScrn->drv) - pScrn->drv->refCount--; + pScrn->drv->refCount--; free(pScrn->privates); @@ -244,9 +242,9 @@ xf86DeleteScreen(int scrnIndex, int flags) xf86NumScreens--; for (i = scrnIndex; i < xf86NumScreens; i++) { - xf86Screens[i] = xf86Screens[i + 1]; - xf86Screens[i]->scrnIndex = i; - /* Also need to take care of the screen layout settings */ + xf86Screens[i] = xf86Screens[i + 1]; + xf86Screens[i]->scrnIndex = i; + /* Also need to take care of the screen layout settings */ } } @@ -263,12 +261,12 @@ xf86AllocateScrnInfoPrivateIndex(void) idx = xf86ScrnInfoPrivateCount++; for (i = 0; i < xf86NumScreens; i++) { - pScr = xf86Screens[i]; - nprivs = xnfrealloc(pScr->privates, - xf86ScrnInfoPrivateCount * sizeof(DevUnion)); - /* Zero the new private */ - memset(&nprivs[idx], 0, sizeof(DevUnion)); - pScr->privates = nprivs; + pScr = xf86Screens[i]; + nprivs = xnfrealloc(pScr->privates, + xf86ScrnInfoPrivateCount * sizeof(DevUnion)); + /* Zero the new private */ + memset(&nprivs[idx], 0, sizeof(DevUnion)); + pScr->privates = nprivs; } return idx; } @@ -279,22 +277,22 @@ xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad) int i; if (pScrn->numFormats >= MAXFORMATS) - return FALSE; + return FALSE; if (bpp <= 0) { - if (depth == 1) - bpp = 1; - else if (depth <= 8) - bpp = 8; - else if (depth <= 16) - bpp = 16; - else if (depth <= 32) - bpp = 32; - else - return FALSE; + if (depth == 1) + bpp = 1; + else if (depth <= 8) + bpp = 8; + else if (depth <= 16) + bpp = 16; + else if (depth <= 32) + bpp = 32; + else + return FALSE; } if (pad <= 0) - pad = BITMAP_SCANLINE_PAD; + pad = BITMAP_SCANLINE_PAD; i = pScrn->numFormats++; pScrn->formats[i].depth = depth; @@ -346,7 +344,7 @@ xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad) Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, - int depth24flags) + int depth24flags) { int i; DispPtr disp; @@ -360,174 +358,182 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, scrp->depthFrom = X_DEFAULT; if (xf86FbBpp > 0) { - scrp->bitsPerPixel = xf86FbBpp; - scrp->bitsPerPixelFrom = X_CMDLINE; + scrp->bitsPerPixel = xf86FbBpp; + scrp->bitsPerPixelFrom = X_CMDLINE; } if (xf86Depth > 0) { - scrp->depth = xf86Depth; - scrp->depthFrom = X_CMDLINE; + scrp->depth = xf86Depth; + scrp->depthFrom = X_CMDLINE; } if (xf86FbBpp < 0 && xf86Depth < 0) { - if (scrp->confScreen->defaultfbbpp > 0) { - scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp; - scrp->bitsPerPixelFrom = X_CONFIG; - } - if (scrp->confScreen->defaultdepth > 0) { - scrp->depth = scrp->confScreen->defaultdepth; - scrp->depthFrom = X_CONFIG; - } - - if (scrp->confScreen->defaultfbbpp <= 0 && - scrp->confScreen->defaultdepth <= 0) { - /* - * Check for DefaultDepth and DefaultFbBpp options in the - * Device sections. - */ - int i; - GDevPtr device; - Bool found = FALSE; - - for (i = 0; i < scrp->numEntities; i++) { - device = xf86GetDevFromEntity(scrp->entityList[i], - scrp->entityInstanceList[i]); - if (device && device->options) { - if (xf86FindOption(device->options, "DefaultDepth")) { - scrp->depth = xf86SetIntOption(device->options, - "DefaultDepth", -1); - scrp->depthFrom = X_CONFIG; - found = TRUE; - } - if (xf86FindOption(device->options, "DefaultFbBpp")) { - scrp->bitsPerPixel = xf86SetIntOption(device->options, - "DefaultFbBpp", - -1); - scrp->bitsPerPixelFrom = X_CONFIG; - found = TRUE; - } - } - if (found) - break; - } - } + if (scrp->confScreen->defaultfbbpp > 0) { + scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp; + scrp->bitsPerPixelFrom = X_CONFIG; + } + if (scrp->confScreen->defaultdepth > 0) { + scrp->depth = scrp->confScreen->defaultdepth; + scrp->depthFrom = X_CONFIG; + } + + if (scrp->confScreen->defaultfbbpp <= 0 && + scrp->confScreen->defaultdepth <= 0) { + /* + * Check for DefaultDepth and DefaultFbBpp options in the + * Device sections. + */ + int i; + GDevPtr device; + Bool found = FALSE; + + for (i = 0; i < scrp->numEntities; i++) { + device = xf86GetDevFromEntity(scrp->entityList[i], + scrp->entityInstanceList[i]); + if (device && device->options) { + if (xf86FindOption(device->options, "DefaultDepth")) { + scrp->depth = xf86SetIntOption(device->options, + "DefaultDepth", -1); + scrp->depthFrom = X_CONFIG; + found = TRUE; + } + if (xf86FindOption(device->options, "DefaultFbBpp")) { + scrp->bitsPerPixel = xf86SetIntOption(device->options, + "DefaultFbBpp", + -1); + scrp->bitsPerPixelFrom = X_CONFIG; + found = TRUE; + } + } + if (found) + break; + } + } } /* If none of these is set, pick a default */ if (scrp->bitsPerPixel < 0 && scrp->depth < 0) { if (fbbpp > 0 || depth > 0) { - if (fbbpp > 0) - scrp->bitsPerPixel = fbbpp; - if (depth > 0) - scrp->depth = depth; - } else { - scrp->depth = GLOBAL_DEFAULT_DEPTH; - } + if (fbbpp > 0) + scrp->bitsPerPixel = fbbpp; + if (depth > 0) + scrp->depth = depth; + } + else { + scrp->depth = GLOBAL_DEFAULT_DEPTH; + } } /* If any are not given, determine a default for the others */ if (scrp->bitsPerPixel < 0) { - /* The depth must be set */ - if (scrp->depth > -1) { - if (scrp->depth == 1) - scrp->bitsPerPixel = 1; - else if (scrp->depth <= 4) - scrp->bitsPerPixel = 4; - else if (scrp->depth <= 8) - scrp->bitsPerPixel = 8; - else if (scrp->depth <= 16) - scrp->bitsPerPixel = 16; - else if (scrp->depth <= 24) { - /* - * Figure out if a choice is possible based on the depth24 - * and pix24 flags. - */ - /* Check pix24 first */ - if (pix24 != Pix24DontCare) { - if (pix24 == Pix24Use32) { - if (DO_PIX32(depth24flags)) { - if (CHOOSE24FOR32(depth24flags)) - scrp->bitsPerPixel = 24; - else - scrp->bitsPerPixel = 32; - } else { - nomatch = TRUE; - } - } else if (pix24 == Pix24Use24) { - if (DO_PIX24(depth24flags)) { - if (CHOOSE32FOR24(depth24flags)) - scrp->bitsPerPixel = 32; - else - scrp->bitsPerPixel = 24; - } else { - nomatch = TRUE; - } - } - } else { - if (DO_PIX32(depth24flags)) { - if (CHOOSE24FOR32(depth24flags)) - scrp->bitsPerPixel = 24; - else - scrp->bitsPerPixel = 32; - } else if (DO_PIX24(depth24flags)) { - if (CHOOSE32FOR24(depth24flags)) - scrp->bitsPerPixel = 32; - else - scrp->bitsPerPixel = 24; - } - } - } else if (scrp->depth <= 32) - scrp->bitsPerPixel = 32; - else { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified depth (%d) is greater than 32\n", - scrp->depth); - return FALSE; - } - } else { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "xf86SetDepthBpp: internal error: depth and fbbpp" - " are both not set\n"); - return FALSE; - } - if (scrp->bitsPerPixel < 0) { - if (nomatch) - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Driver can't support depth 24 pixmap format (%d)\n", - PIX24TOBPP(pix24)); - else if ((depth24flags & (Support24bppFb | Support32bppFb)) == - NoDepth24Support) - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Driver can't support depth 24\n"); - else - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Can't find fbbpp for depth 24\n"); - return FALSE; - } - scrp->bitsPerPixelFrom = X_PROBED; + /* The depth must be set */ + if (scrp->depth > -1) { + if (scrp->depth == 1) + scrp->bitsPerPixel = 1; + else if (scrp->depth <= 4) + scrp->bitsPerPixel = 4; + else if (scrp->depth <= 8) + scrp->bitsPerPixel = 8; + else if (scrp->depth <= 16) + scrp->bitsPerPixel = 16; + else if (scrp->depth <= 24) { + /* + * Figure out if a choice is possible based on the depth24 + * and pix24 flags. + */ + /* Check pix24 first */ + if (pix24 != Pix24DontCare) { + if (pix24 == Pix24Use32) { + if (DO_PIX32(depth24flags)) { + if (CHOOSE24FOR32(depth24flags)) + scrp->bitsPerPixel = 24; + else + scrp->bitsPerPixel = 32; + } + else { + nomatch = TRUE; + } + } + else if (pix24 == Pix24Use24) { + if (DO_PIX24(depth24flags)) { + if (CHOOSE32FOR24(depth24flags)) + scrp->bitsPerPixel = 32; + else + scrp->bitsPerPixel = 24; + } + else { + nomatch = TRUE; + } + } + } + else { + if (DO_PIX32(depth24flags)) { + if (CHOOSE24FOR32(depth24flags)) + scrp->bitsPerPixel = 24; + else + scrp->bitsPerPixel = 32; + } + else if (DO_PIX24(depth24flags)) { + if (CHOOSE32FOR24(depth24flags)) + scrp->bitsPerPixel = 32; + else + scrp->bitsPerPixel = 24; + } + } + } + else if (scrp->depth <= 32) + scrp->bitsPerPixel = 32; + else { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Specified depth (%d) is greater than 32\n", + scrp->depth); + return FALSE; + } + } + else { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "xf86SetDepthBpp: internal error: depth and fbbpp" + " are both not set\n"); + return FALSE; + } + if (scrp->bitsPerPixel < 0) { + if (nomatch) + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Driver can't support depth 24 pixmap format (%d)\n", + PIX24TOBPP(pix24)); + else if ((depth24flags & (Support24bppFb | Support32bppFb)) == + NoDepth24Support) + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Driver can't support depth 24\n"); + else + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Can't find fbbpp for depth 24\n"); + return FALSE; + } + scrp->bitsPerPixelFrom = X_PROBED; } if (scrp->depth <= 0) { - /* bitsPerPixel is already set */ - switch (scrp->bitsPerPixel) { - case 32: - scrp->depth = 24; - break; - default: - /* 1, 4, 8, 16 and 24 */ - scrp->depth = scrp->bitsPerPixel; - break; - } - scrp->depthFrom = X_PROBED; + /* bitsPerPixel is already set */ + switch (scrp->bitsPerPixel) { + case 32: + scrp->depth = 24; + break; + default: + /* 1, 4, 8, 16 and 24 */ + scrp->depth = scrp->bitsPerPixel; + break; + } + scrp->depthFrom = X_PROBED; } /* Sanity checks */ if (scrp->depth < 1 || scrp->depth > 32) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified depth (%d) is not in the range 1-32\n", - scrp->depth); - return FALSE; + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Specified depth (%d) is not in the range 1-32\n", + scrp->depth); + return FALSE; } switch (scrp->bitsPerPixel) { case 1: @@ -536,26 +542,26 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, case 16: case 24: case 32: - break; + break; default: - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified fbbpp (%d) is not a permitted value\n", - scrp->bitsPerPixel); - return FALSE; + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Specified fbbpp (%d) is not a permitted value\n", + scrp->bitsPerPixel); + return FALSE; } if (scrp->depth > scrp->bitsPerPixel) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified depth (%d) is greater than the fbbpp (%d)\n", - scrp->depth, scrp->bitsPerPixel); - return FALSE; + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Specified depth (%d) is greater than the fbbpp (%d)\n", + scrp->depth, scrp->bitsPerPixel); + return FALSE; } /* set scrp->pixmap24 if the driver isn't flexible */ if (scrp->bitsPerPixel == 24 && !DO_PIX32FOR24(depth24flags)) { - scrp->pixmap24 = Pix24Use24; + scrp->pixmap24 = Pix24Use24; } if (scrp->bitsPerPixel == 32 && !DO_PIX24FOR32(depth24flags)) { - scrp->pixmap24 = Pix24Use32; + scrp->pixmap24 = Pix24Use32; } /* @@ -563,13 +569,13 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, * scrp->display with it. */ for (i = 0, disp = scrp->confScreen->displays; - i < scrp->confScreen->numdisplays; i++, disp++) { - if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel) - || (disp->depth == scrp->depth && disp->fbbpp <= 0) - || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) { - scrp->display = disp; - break; - } + i < scrp->confScreen->numdisplays; i++, disp++) { + if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel) + || (disp->depth == scrp->depth && disp->fbbpp <= 0) + || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) { + scrp->display = disp; + break; + } } /* @@ -577,40 +583,40 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, * depth or fbbpp specified. */ if (i == scrp->confScreen->numdisplays) { - for (i = 0, disp = scrp->confScreen->displays; - i < scrp->confScreen->numdisplays; i++, disp++) { - if (disp->depth <= 0 && disp->fbbpp <= 0) { - scrp->display = disp; - break; - } - } + for (i = 0, disp = scrp->confScreen->displays; + i < scrp->confScreen->numdisplays; i++, disp++) { + if (disp->depth <= 0 && disp->fbbpp <= 0) { + scrp->display = disp; + break; + } + } } /* * If all else fails, create a default one. */ if (i == scrp->confScreen->numdisplays) { - scrp->confScreen->numdisplays++; - scrp->confScreen->displays = - xnfrealloc(scrp->confScreen->displays, - scrp->confScreen->numdisplays * sizeof(DispRec)); - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Creating default Display subsection in Screen section\n" - "\t\"%s\" for depth/fbbpp %d/%d\n", - scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel); - memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec)); - scrp->confScreen->displays[i].blackColour.red = -1; - scrp->confScreen->displays[i].blackColour.green = -1; - scrp->confScreen->displays[i].blackColour.blue = -1; - scrp->confScreen->displays[i].whiteColour.red = -1; - scrp->confScreen->displays[i].whiteColour.green = -1; - scrp->confScreen->displays[i].whiteColour.blue = -1; - scrp->confScreen->displays[i].defaultVisual = -1; - scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *)); - scrp->confScreen->displays[i].modes[0] = NULL; - scrp->confScreen->displays[i].depth = depth; - scrp->confScreen->displays[i].fbbpp = fbbpp; - scrp->display = &scrp->confScreen->displays[i]; + scrp->confScreen->numdisplays++; + scrp->confScreen->displays = + xnfrealloc(scrp->confScreen->displays, + scrp->confScreen->numdisplays * sizeof(DispRec)); + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Creating default Display subsection in Screen section\n" + "\t\"%s\" for depth/fbbpp %d/%d\n", + scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel); + memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec)); + scrp->confScreen->displays[i].blackColour.red = -1; + scrp->confScreen->displays[i].blackColour.green = -1; + scrp->confScreen->displays[i].blackColour.blue = -1; + scrp->confScreen->displays[i].whiteColour.red = -1; + scrp->confScreen->displays[i].whiteColour.green = -1; + scrp->confScreen->displays[i].whiteColour.blue = -1; + scrp->confScreen->displays[i].defaultVisual = -1; + scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *)); + scrp->confScreen->displays[i].modes[0] = NULL; + scrp->confScreen->displays[i].depth = depth; + scrp->confScreen->displays[i].fbbpp = fbbpp; + scrp->display = &scrp->confScreen->displays[i]; } /* @@ -621,12 +627,13 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, scrp->imageByteOrder = IMAGE_BYTE_ORDER; scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD; if (scrp->depth < 8) { - /* Planar modes need these settings */ - scrp->bitmapScanlineUnit = 8; - scrp->bitmapBitOrder = MSBFirst; - } else { - scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - scrp->bitmapBitOrder = BITMAP_BIT_ORDER; + /* Planar modes need these settings */ + scrp->bitmapScanlineUnit = 8; + scrp->bitmapBitOrder = MSBFirst; + } + else { + scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; + scrp->bitmapBitOrder = BITMAP_BIT_ORDER; } /* @@ -640,14 +647,14 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, case 15: case 16: case 24: - /* Common depths. Nothing to do for them */ - break; + /* Common depths. Nothing to do for them */ + break; default: - if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Can't add pixmap format for depth %d\n", scrp->depth); - return FALSE; - } + if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Can't add pixmap format for depth %d\n", scrp->depth); + return FALSE; + } } /* Initialise the framebuffer format for this screen */ @@ -682,87 +689,91 @@ xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask) scrp->weight.blue = 0; if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) { - scrp->weight = xf86Weight; - weightFrom = X_CMDLINE; - } else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0 - && scrp->display->weight.blue > 0) { - scrp->weight = scrp->display->weight; - weightFrom = X_CONFIG; - } else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) { - scrp->weight = weight; - } else { - switch (scrp->depth) { - case 1: - case 4: - case 8: - scrp->weight.red = scrp->weight.green = - scrp->weight.blue = scrp->rgbBits; - break; - case 15: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5; - break; - case 16: - scrp->weight.red = scrp->weight.blue = 5; - scrp->weight.green = 6; - break; - case 18: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6; - break; - case 24: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8; - break; - case 30: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10; - break; - } + scrp->weight = xf86Weight; + weightFrom = X_CMDLINE; + } + else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0 + && scrp->display->weight.blue > 0) { + scrp->weight = scrp->display->weight; + weightFrom = X_CONFIG; + } + else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) { + scrp->weight = weight; + } + else { + switch (scrp->depth) { + case 1: + case 4: + case 8: + scrp->weight.red = scrp->weight.green = + scrp->weight.blue = scrp->rgbBits; + break; + case 15: + scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5; + break; + case 16: + scrp->weight.red = scrp->weight.blue = 5; + scrp->weight.green = 6; + break; + case 18: + scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6; + break; + case 24: + scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8; + break; + case 30: + scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10; + break; + } } if (scrp->weight.red) - xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n", - (int)scrp->weight.red, (int)scrp->weight.green, - (int)scrp->weight.blue); + xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n", + (int) scrp->weight.red, (int) scrp->weight.green, + (int) scrp->weight.blue); if (scrp->depth > MAX_PSEUDO_DEPTH && - (scrp->depth != scrp->weight.red + scrp->weight.green + - scrp->weight.blue)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Weight given (%d%d%d) is inconsistent with the " - "depth (%d)\n", - (int)scrp->weight.red, (int)scrp->weight.green, - (int)scrp->weight.blue, scrp->depth); - return FALSE; + (scrp->depth != scrp->weight.red + scrp->weight.green + + scrp->weight.blue)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Weight given (%d%d%d) is inconsistent with the " + "depth (%d)\n", + (int) scrp->weight.red, (int) scrp->weight.green, + (int) scrp->weight.blue, scrp->depth); + return FALSE; } if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) { - /* - * XXX Does this even mean anything for TrueColor visuals? - * If not, we shouldn't even be setting it here. However, this - * matches the behaviour of 3.x versions of XFree86. - */ - scrp->rgbBits = scrp->weight.red; - if (scrp->weight.green > scrp->rgbBits) - scrp->rgbBits = scrp->weight.green; - if (scrp->weight.blue > scrp->rgbBits) - scrp->rgbBits = scrp->weight.blue; + /* + * XXX Does this even mean anything for TrueColor visuals? + * If not, we shouldn't even be setting it here. However, this + * matches the behaviour of 3.x versions of XFree86. + */ + scrp->rgbBits = scrp->weight.red; + if (scrp->weight.green > scrp->rgbBits) + scrp->rgbBits = scrp->weight.green; + if (scrp->weight.blue > scrp->rgbBits) + scrp->rgbBits = scrp->weight.blue; } /* Set the mask and offsets */ if (mask.red == 0 || mask.green == 0 || mask.blue == 0) { - /* Default to a setting common to PC hardware */ - scrp->offset.red = scrp->weight.green + scrp->weight.blue; - scrp->offset.green = scrp->weight.blue; - scrp->offset.blue = 0; - scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red; - scrp->mask.green = ((1 << scrp->weight.green) - 1) - << scrp->offset.green; - scrp->mask.blue = (1 << scrp->weight.blue) - 1; - } else { - /* Initialise to the values passed */ - scrp->mask.red = mask.red; - scrp->mask.green = mask.green; - scrp->mask.blue = mask.blue; - scrp->offset.red = ffs(mask.red); - scrp->offset.green = ffs(mask.green); - scrp->offset.blue = ffs(mask.blue); + /* Default to a setting common to PC hardware */ + scrp->offset.red = scrp->weight.green + scrp->weight.blue; + scrp->offset.green = scrp->weight.blue; + scrp->offset.blue = 0; + scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red; + scrp->mask.green = ((1 << scrp->weight.green) - 1) + << scrp->offset.green; + scrp->mask.blue = (1 << scrp->weight.blue) - 1; + } + else { + /* Initialise to the values passed */ + scrp->mask.red = mask.red; + scrp->mask.green = mask.green; + scrp->mask.blue = mask.blue; + scrp->offset.red = ffs(mask.red); + scrp->offset.green = ffs(mask.green); + scrp->offset.blue = ffs(mask.blue); } return TRUE; } @@ -773,22 +784,25 @@ xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual) MessageType visualFrom = X_DEFAULT; if (defaultColorVisualClass >= 0) { - scrp->defaultVisual = defaultColorVisualClass; - visualFrom = X_CMDLINE; - } else if (scrp->display->defaultVisual >= 0) { - scrp->defaultVisual = scrp->display->defaultVisual; - visualFrom = X_CONFIG; - } else if (visual >= 0) { - scrp->defaultVisual = visual; - } else { - if (scrp->depth == 1) - scrp->defaultVisual = StaticGray; - else if (scrp->depth == 4) - scrp->defaultVisual = StaticColor; - else if (scrp->depth <= MAX_PSEUDO_DEPTH) - scrp->defaultVisual = PseudoColor; - else - scrp->defaultVisual = TrueColor; + scrp->defaultVisual = defaultColorVisualClass; + visualFrom = X_CMDLINE; + } + else if (scrp->display->defaultVisual >= 0) { + scrp->defaultVisual = scrp->display->defaultVisual; + visualFrom = X_CONFIG; + } + else if (visual >= 0) { + scrp->defaultVisual = visual; + } + else { + if (scrp->depth == 1) + scrp->defaultVisual = StaticGray; + else if (scrp->depth == 4) + scrp->defaultVisual = StaticColor; + else if (scrp->depth <= MAX_PSEUDO_DEPTH) + scrp->defaultVisual = PseudoColor; + else + scrp->defaultVisual = TrueColor; } switch (scrp->defaultVisual) { case StaticGray: @@ -797,14 +811,14 @@ xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual) case PseudoColor: case TrueColor: case DirectColor: - xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n", - xf86VisualNames[scrp->defaultVisual]); - return TRUE; + xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n", + xf86VisualNames[scrp->defaultVisual]); + return TRUE; default: - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Invalid default visual class (%d)\n", scrp->defaultVisual); - return FALSE; + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Invalid default visual class (%d)\n", scrp->defaultVisual); + return FALSE; } } @@ -818,45 +832,50 @@ Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma) { MessageType from = X_DEFAULT; + #if 0 - xf86MonPtr DDC = (xf86MonPtr)(scrp->monitor->DDC); + xf86MonPtr DDC = (xf86MonPtr) (scrp->monitor->DDC); #endif if (TEST_GAMMA(xf86Gamma)) { - from = X_CMDLINE; - scrp->gamma.red = SET_GAMMA(xf86Gamma.red); - scrp->gamma.green = SET_GAMMA(xf86Gamma.green); - scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue); - } else if (TEST_GAMMA(scrp->monitor->gamma)) { - from = X_CONFIG; - scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red); - scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green); - scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue); + from = X_CMDLINE; + scrp->gamma.red = SET_GAMMA(xf86Gamma.red); + scrp->gamma.green = SET_GAMMA(xf86Gamma.green); + scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue); + } + else if (TEST_GAMMA(scrp->monitor->gamma)) { + from = X_CONFIG; + scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red); + scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green); + scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue); #if 0 - } else if ( DDC && DDC->features.gamma > GAMMA_ZERO ) { + } + else if (DDC && DDC->features.gamma > GAMMA_ZERO) { from = X_PROBED; - scrp->gamma.red = SET_GAMMA(DDC->features.gamma); - scrp->gamma.green = SET_GAMMA(DDC->features.gamma); - scrp->gamma.blue = SET_GAMMA(DDC->features.gamma); - /* EDID structure version 2 gives optional seperate red, green & blue gamma values - * in bytes 0x57-0x59 */ + scrp->gamma.red = SET_GAMMA(DDC->features.gamma); + scrp->gamma.green = SET_GAMMA(DDC->features.gamma); + scrp->gamma.blue = SET_GAMMA(DDC->features.gamma); + /* EDID structure version 2 gives optional seperate red, green & blue gamma values + * in bytes 0x57-0x59 */ #endif - } else if (TEST_GAMMA(gamma)) { - scrp->gamma.red = SET_GAMMA(gamma.red); - scrp->gamma.green = SET_GAMMA(gamma.green); - scrp->gamma.blue = SET_GAMMA(gamma.blue); - } else { - scrp->gamma.red = 1.0; - scrp->gamma.green = 1.0; - scrp->gamma.blue = 1.0; + } + else if (TEST_GAMMA(gamma)) { + scrp->gamma.red = SET_GAMMA(gamma.red); + scrp->gamma.green = SET_GAMMA(gamma.green); + scrp->gamma.blue = SET_GAMMA(gamma.blue); + } + else { + scrp->gamma.red = 1.0; + scrp->gamma.green = 1.0; + scrp->gamma.blue = 1.0; } /* Pretend we succeeded if we support better a gamma system. * This avoids a confusing message. */ if (xf86_crtc_supports_gamma(scrp)) - return TRUE; + return TRUE; xf86DrvMsg(scrp->scrnIndex, from, - "Using gamma correction (%.1f, %.1f, %.1f)\n", - scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue); + "Using gamma correction (%.1f, %.1f, %.1f)\n", + scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue); return TRUE; } @@ -864,7 +883,6 @@ xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma) #undef TEST_GAMMA #undef SET_GAMMA - /* * Set the DPI from the command line option. XXX should allow it to be * calculated from the widthmm/heightmm values. @@ -877,7 +895,7 @@ void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y) { MessageType from = X_DEFAULT; - xf86MonPtr DDC = (xf86MonPtr)(pScrn->monitor->DDC); + xf86MonPtr DDC = (xf86MonPtr) (pScrn->monitor->DDC); int ddcWidthmm, ddcHeightmm; int widthErr, heightErr; @@ -885,100 +903,107 @@ xf86SetDpi(ScrnInfoPtr pScrn, int x, int y) pScrn->widthmm = pScrn->monitor->widthmm; pScrn->heightmm = pScrn->monitor->heightmm; - if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0) ) { - /* DDC gives display size in mm for individual modes, - * but cm for monitor - */ - ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */ - ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */ - } else { - ddcWidthmm = ddcHeightmm = 0; + if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0)) { + /* DDC gives display size in mm for individual modes, + * but cm for monitor + */ + ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */ + ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */ + } + else { + ddcWidthmm = ddcHeightmm = 0; } if (monitorResolution > 0) { - pScrn->xDpi = monitorResolution; - pScrn->yDpi = monitorResolution; - from = X_CMDLINE; - } else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) { - from = X_CONFIG; - if (pScrn->widthmm > 0) { - pScrn->xDpi = - (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm); - } - if (pScrn->heightmm > 0) { - pScrn->yDpi = - (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm); - } - if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) - pScrn->yDpi = pScrn->xDpi; - if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) - pScrn->xDpi = pScrn->yDpi; - xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", - pScrn->widthmm, pScrn->heightmm); - - /* Warn if config and probe disagree about display size */ - if ( ddcWidthmm && ddcHeightmm ) { - if (pScrn->widthmm > 0) { - widthErr = abs(ddcWidthmm - pScrn->widthmm); - } else { - widthErr = 0; - } - if (pScrn->heightmm > 0) { - heightErr = abs(ddcHeightmm - pScrn->heightmm); - } else { - heightErr = 0; - } - if (widthErr>10 || heightErr>10) { - /* Should include config file name for monitor here */ - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n", - ddcWidthmm,ddcHeightmm, pScrn->widthmm,pScrn->heightmm); - } - } - } else if ( ddcWidthmm && ddcHeightmm ) { - from = X_PROBED; - xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", - ddcWidthmm, ddcHeightmm ); - pScrn->widthmm = ddcWidthmm; - pScrn->heightmm = ddcHeightmm; - if (pScrn->widthmm > 0) { - pScrn->xDpi = - (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm); - } - if (pScrn->heightmm > 0) { - pScrn->yDpi = - (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm); - } - if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) - pScrn->yDpi = pScrn->xDpi; - if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) - pScrn->xDpi = pScrn->yDpi; - } else { - if (x > 0) - pScrn->xDpi = x; - else - pScrn->xDpi = DEFAULT_DPI; - if (y > 0) - pScrn->yDpi = y; - else - pScrn->yDpi = DEFAULT_DPI; + pScrn->xDpi = monitorResolution; + pScrn->yDpi = monitorResolution; + from = X_CMDLINE; + } + else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) { + from = X_CONFIG; + if (pScrn->widthmm > 0) { + pScrn->xDpi = + (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm); + } + if (pScrn->heightmm > 0) { + pScrn->yDpi = + (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm); + } + if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) + pScrn->yDpi = pScrn->xDpi; + if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) + pScrn->xDpi = pScrn->yDpi; + xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", + pScrn->widthmm, pScrn->heightmm); + + /* Warn if config and probe disagree about display size */ + if (ddcWidthmm && ddcHeightmm) { + if (pScrn->widthmm > 0) { + widthErr = abs(ddcWidthmm - pScrn->widthmm); + } + else { + widthErr = 0; + } + if (pScrn->heightmm > 0) { + heightErr = abs(ddcHeightmm - pScrn->heightmm); + } + else { + heightErr = 0; + } + if (widthErr > 10 || heightErr > 10) { + /* Should include config file name for monitor here */ + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n", + ddcWidthmm, ddcHeightmm, pScrn->widthmm, + pScrn->heightmm); + } + } + } + else if (ddcWidthmm && ddcHeightmm) { + from = X_PROBED; + xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", + ddcWidthmm, ddcHeightmm); + pScrn->widthmm = ddcWidthmm; + pScrn->heightmm = ddcHeightmm; + if (pScrn->widthmm > 0) { + pScrn->xDpi = + (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm); + } + if (pScrn->heightmm > 0) { + pScrn->yDpi = + (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm); + } + if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) + pScrn->yDpi = pScrn->xDpi; + if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) + pScrn->xDpi = pScrn->yDpi; + } + else { + if (x > 0) + pScrn->xDpi = x; + else + pScrn->xDpi = DEFAULT_DPI; + if (y > 0) + pScrn->yDpi = y; + else + pScrn->yDpi = DEFAULT_DPI; } xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n", - pScrn->xDpi, pScrn->yDpi); + pScrn->xDpi, pScrn->yDpi); } #undef MMPERINCH - void xf86SetBlackWhitePixels(ScreenPtr pScreen) { if (xf86FlipPixels) { - pScreen->whitePixel = 0; - pScreen->blackPixel = 1; - } else { - pScreen->whitePixel = 1; - pScreen->blackPixel = 0; + pScreen->whitePixel = 0; + pScreen->blackPixel = 1; + } + else { + pScreen->whitePixel = 1; + pScreen->blackPixel = 0; } } @@ -1009,21 +1034,19 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable) PixmapPtr pspix; pspix = (*pScreen->GetScreenPixmap) (pScreen); - if (enable) - { - /* - * Restore all of the clip lists on the screen - */ - if (!xf86Resetting) - SetRootClip (pScreen, TRUE); + if (enable) { + /* + * Restore all of the clip lists on the screen + */ + if (!xf86Resetting) + SetRootClip(pScreen, TRUE); } - else - { - /* - * Empty all of the clip lists on the screen - */ - SetRootClip (pScreen, FALSE); + else { + /* + * Empty all of the clip lists on the screen + */ + SetRootClip(pScreen, FALSE); } } @@ -1031,21 +1054,21 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable) (<type>) <screen name>(<screen index>): <message> */ void xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, - va_list args) + va_list args) { /* Prefix the scrnIndex name to the format string. */ if (scrnIndex >= 0 && scrnIndex < xf86NumScreens && - xf86Screens[scrnIndex]->name) - LogHdrMessageVerb(type, verb, format, args, "%s(%d): ", - xf86Screens[scrnIndex]->name, scrnIndex); + xf86Screens[scrnIndex]->name) + LogHdrMessageVerb(type, verb, format, args, "%s(%d): ", + xf86Screens[scrnIndex]->name, scrnIndex); else - LogVMessageVerb(type, verb, format, args); + LogVMessageVerb(type, verb, format, args); } /* Print driver messages, with verbose level specified directly */ void xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, - ...) + ...) { va_list ap; @@ -1069,26 +1092,26 @@ xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) (<type>) <driver>: <device name>: <message> */ void xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, - const char *format, va_list args) + const char *format, va_list args) { const char *driverName = NULL; const char *deviceName = NULL; /* Prefix driver and device names to formatted message. */ if (dev) { - deviceName = dev->name; - if (dev->drv) - driverName = dev->drv->driverName; + deviceName = dev->name; + if (dev->drv) + driverName = dev->drv->driverName; } LogHdrMessageVerb(type, verb, format, args, "%s: %s: ", driverName, - deviceName); + deviceName); } /* Print input driver message, with verbose level specified directly */ void -xf86IDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *format, - ...) +xf86IDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, + const char *format, ...) { va_list ap; @@ -1108,7 +1131,6 @@ xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...) va_end(ap); } - /* Print non-driver messages with verbose level specified directly */ void xf86MsgVerb(MessageType type, int verb, const char *format, ...) @@ -1139,7 +1161,7 @@ xf86ErrorFVerb(int verb, const char *format, ...) va_start(ap, format); if (xf86Verbose >= verb || xf86LogVerbose >= verb) - LogVWrite(verb, format, ap); + LogVWrite(verb, format, ap); va_end(ap); } @@ -1151,11 +1173,10 @@ xf86ErrorF(const char *format, ...) va_start(ap, format); if (xf86Verbose >= 1 || xf86LogVerbose >= 1) - LogVWrite(1, format, ap); + LogVWrite(1, format, ap); va_end(ap); } - void xf86LogInit(void) { @@ -1166,10 +1187,10 @@ xf86LogInit(void) /* Get the log file name */ if (xf86LogFileFrom == X_DEFAULT) { - /* Append the display number and ".log" */ - if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) - FatalError("Cannot allocate space for the log file name\n"); - xf86LogFile = lf; + /* Append the display number and ".log" */ + if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) + FatalError("Cannot allocate space for the log file name\n"); + xf86LogFile = lf; } xf86LogFile = LogInit(xf86LogFile, LOGOLDSUFFIX); @@ -1190,7 +1211,6 @@ xf86CloseLog(enum ExitCode error) LogClose(error); } - /* * Drivers can use these for using their own SymTabRecs. */ @@ -1200,13 +1220,12 @@ xf86TokenToString(SymTabPtr table, int token) { int i; - for (i = 0; table[i].token >= 0 && table[i].token != token; i++) - ; + for (i = 0; table[i].token >= 0 && table[i].token != token; i++); if (table[i].token < 0) - return NULL; + return NULL; else - return table[i].name; + return table[i].name; } int @@ -1215,10 +1234,9 @@ xf86StringToToken(SymTabPtr table, const char *string) int i; if (string == NULL) - return -1; + return -1; - for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++) - ; + for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++); return table[i].token; } @@ -1232,17 +1250,16 @@ xf86ShowClocks(ScrnInfoPtr scrp, MessageType from) int j; xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:"); - for (j=0; j < scrp->numClocks; j++) { - if ((j % 4) == 0) { - xf86ErrorF("\n"); - xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:"); - } - xf86ErrorF(" %7.3f", (double)scrp->clock[j] / 1000.0); + for (j = 0; j < scrp->numClocks; j++) { + if ((j % 4) == 0) { + xf86ErrorF("\n"); + xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:"); + } + xf86ErrorF(" %7.3f", (double) scrp->clock[j] / 1000.0); } xf86ErrorF("\n"); } - /* * This prints out the driver identify message, including the names of * the supported chipsets. @@ -1258,40 +1275,40 @@ xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips) len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2; xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg); for (i = 0; chips[i].name != NULL; i++) { - if (i != 0) { - xf86ErrorF(","); - len++; - } - if (len + 2 + strlen(chips[i].name) < 78) { - xf86ErrorF(" "); - len++; - } else { - xf86ErrorF("\n\t"); - len = 8; - } - xf86ErrorF("%s", chips[i].name); - len += strlen(chips[i].name); + if (i != 0) { + xf86ErrorF(","); + len++; + } + if (len + 2 + strlen(chips[i].name) < 78) { + xf86ErrorF(" "); + len++; + } + else { + xf86ErrorF("\n\t"); + len = 8; + } + xf86ErrorF("%s", chips[i].name); + len += strlen(chips[i].name); } xf86ErrorF("\n"); } - int -xf86MatchDevice(const char *drivername, GDevPtr **sectlist) +xf86MatchDevice(const char *drivername, GDevPtr ** sectlist) { - GDevPtr gdp, *pgdp = NULL; + GDevPtr gdp, *pgdp = NULL; confScreenPtr screensecptr; - int i,j; + int i, j; if (sectlist) - *sectlist = NULL; + *sectlist = NULL; /* * This can happen when running Xorg -showopts and a module like ati * or vmware tries to load its submodules when xf86ConfigLayout is empty */ if (!xf86ConfigLayout.screens) - return 0; + return 0; /* * This is a very important function that matches the device sections @@ -1314,11 +1331,11 @@ xf86MatchDevice(const char *drivername, GDevPtr **sectlist) * first we need to loop over all the Screens sections to get to all * 'active' device sections */ - for (j=0; xf86ConfigLayout.screens[j].screen != NULL; j++) { + for (j = 0; xf86ConfigLayout.screens[j].screen != NULL; j++) { screensecptr = xf86ConfigLayout.screens[j].screen; if ((screensecptr->device->driver != NULL) - && (xf86NameCmp( screensecptr->device->driver,drivername) == 0) - && (! screensecptr->device->claimed)) { + && (xf86NameCmp(screensecptr->device->driver, drivername) == 0) + && (!screensecptr->device->claimed)) { /* * we have a matching driver that wasn't claimed, yet */ @@ -1330,14 +1347,14 @@ xf86MatchDevice(const char *drivername, GDevPtr **sectlist) /* Then handle the inactive devices */ j = 0; while (xf86ConfigLayout.inactives[j].identifier) { - gdp = &xf86ConfigLayout.inactives[j]; - if (gdp->driver && !gdp->claimed && - !xf86NameCmp(gdp->driver,drivername)) { - /* we have a matching driver that wasn't claimed yet */ - pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr)); - pgdp[i++] = gdp; - } - j++; + gdp = &xf86ConfigLayout.inactives[j]; + if (gdp->driver && !gdp->claimed && + !xf86NameCmp(gdp->driver, drivername)) { + /* we have a matching driver that wasn't claimed yet */ + pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr)); + pgdp[i++] = gdp; + } + j++; } /* @@ -1347,9 +1364,9 @@ xf86MatchDevice(const char *drivername, GDevPtr **sectlist) pgdp[i] = NULL; if (sectlist) - *sectlist = pgdp; + *sectlist = pgdp; else - free(pgdp); + free(pgdp); return i; } @@ -1357,12 +1374,11 @@ const char * xf86GetVisualName(int visual) { if (visual < 0 || visual > DirectColor) - return NULL; + return NULL; return xf86VisualNames[visual]; } - int xf86GetVerbosity(void) { @@ -1375,84 +1391,72 @@ xf86GetPix24(void) return xf86Info.pixmap24; } - int xf86GetDepth(void) { return xf86Depth; } - rgb xf86GetWeight(void) { return xf86Weight; } - Gamma xf86GetGamma(void) { return xf86Gamma; } - Bool xf86GetFlipPixels(void) { return xf86FlipPixels; } - const char * xf86GetServerName(void) { return xf86ServerName; } - Bool xf86ServerIsExiting(void) { return (dispatchException & DE_TERMINATE) == DE_TERMINATE; } - Bool xf86ServerIsResetting(void) { return xf86Resetting; } - Bool xf86ServerIsInitialising(void) { return xf86Initialising; } - Bool xf86ServerIsOnlyDetecting(void) { return xf86DoConfigure; } - Bool xf86CaughtSignal(void) { return xf86Info.caughtSignal; } - Bool xf86GetVidModeAllowNonLocal(void) { return xf86Info.vidModeAllowNonLocal; } - Bool xf86GetVidModeEnabled(void) { @@ -1465,21 +1469,18 @@ xf86GetModInDevAllowNonLocal(void) return xf86Info.miscModInDevAllowNonLocal; } - Bool xf86GetModInDevEnabled(void) { return xf86Info.miscModInDevEnabled; } - Bool xf86GetAllowMouseOpenFail(void) { return xf86Info.allowMouseOpenFail; } - void xf86DisableRandR(void) { @@ -1490,7 +1491,7 @@ xf86DisableRandR(void) CARD32 xf86GetModuleVersion(pointer module) { - return (CARD32)LoaderGetModuleVersion(module); + return (CARD32) LoaderGetModuleVersion(module); } pointer @@ -1500,9 +1501,9 @@ xf86LoadDrvSubModule(DriverPtr drv, const char *name) int errmaj = 0, errmin = 0; ret = LoadSubModule(drv->module, name, NULL, NULL, NULL, NULL, - &errmaj, &errmin); + &errmaj, &errmin); if (!ret) - LoaderErrorMsg(NULL, name, errmaj, errmin); + LoaderErrorMsg(NULL, name, errmaj, errmin); return ret; } @@ -1513,9 +1514,9 @@ xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name) int errmaj = 0, errmin = 0; ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL, - &errmaj, &errmin); + &errmaj, &errmin); if (!ret) - LoaderErrorMsg(pScrn->name, name, errmaj, errmin); + LoaderErrorMsg(pScrn->name, name, errmaj, errmin); return ret; } @@ -1530,22 +1531,22 @@ xf86LoadOneModule(char *name, pointer opt) pointer mod; if (!name) - return NULL; + return NULL; /* Normalise the module name */ Name = xf86NormalizeName(name); /* Skip empty names */ if (Name == NULL) - return NULL; + return NULL; if (*Name == '\0') { - free(Name); - return NULL; + free(Name); + return NULL; } mod = LoadModule(Name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin); if (!mod) - LoaderErrorMsg(NULL, Name, errmaj, errmin); + LoaderErrorMsg(NULL, Name, errmaj, errmin); free(Name); return mod; } @@ -1563,12 +1564,12 @@ xf86LoaderCheckSymbol(const char *name) } typedef enum { - OPTION_BACKING_STORE + OPTION_BACKING_STORE } BSOpts; static const OptionInfoRec BSOptions[] = { - { OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE }, - { -1, NULL, OPTV_NONE, {0}, FALSE } + {OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} }; void @@ -1580,39 +1581,40 @@ xf86SetBackingStore(ScreenPtr pScreen) OptionInfoPtr options; options = xnfalloc(sizeof(BSOptions)); - (void)memcpy(options, BSOptions, sizeof(BSOptions)); + (void) memcpy(options, BSOptions, sizeof(BSOptions)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); /* check for commandline option here */ if (xf86bsEnableFlag) { - from = X_CMDLINE; - useBS = TRUE; - } else if (xf86bsDisableFlag) { - from = X_CMDLINE; - useBS = FALSE; - } else { - if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS)) - from = X_CONFIG; + from = X_CMDLINE; + useBS = TRUE; + } + else if (xf86bsDisableFlag) { + from = X_CMDLINE; + useBS = FALSE; + } + else { + if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS)) + from = X_CONFIG; } free(options); pScreen->backingStoreSupport = useBS ? Always : NotUseful; if (serverGeneration == 1) - xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n", - useBS ? "enabled" : "disabled"); + xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n", + useBS ? "enabled" : "disabled"); } - typedef enum { - OPTION_SILKEN_MOUSE + OPTION_SILKEN_MOUSE } SMOpts; static const OptionInfoRec SMOptions[] = { - { OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE }, - { -1, NULL, OPTV_NONE, {0}, FALSE } + {OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} }; void -xf86SetSilkenMouse (ScreenPtr pScreen) +xf86SetSilkenMouse(ScreenPtr pScreen) { Bool useSM = TRUE; MessageType from = X_DEFAULT; @@ -1620,18 +1622,19 @@ xf86SetSilkenMouse (ScreenPtr pScreen) OptionInfoPtr options; options = xnfalloc(sizeof(SMOptions)); - (void)memcpy(options, SMOptions, sizeof(SMOptions)); + (void) memcpy(options, SMOptions, sizeof(SMOptions)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); /* check for commandline option here */ /* disable if screen shares resources */ - /* TODO VGA arb disable silken mouse */ + /* TODO VGA arb disable silken mouse */ if (xf86silkenMouseDisableFlag) { from = X_CMDLINE; - useSM = FALSE; - } else { - if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM)) - from = X_CONFIG; + useSM = FALSE; + } + else { + if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM)) + from = X_CONFIG; } free(options); /* @@ -1641,33 +1644,37 @@ xf86SetSilkenMouse (ScreenPtr pScreen) */ pScrn->silkenMouse = useSM && xf86Info.useSIGIO && xf86SIGIOSupported(); if (serverGeneration == 1) - xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n", - pScrn->silkenMouse ? "enabled" : "disabled"); + xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n", + pScrn->silkenMouse ? "enabled" : "disabled"); } /* Wrote this function for the PM2 Xv driver, preliminary. */ pointer xf86FindXvOptions(int scrnIndex, int adaptor_index, char *port_name, - char **adaptor_name, pointer *adaptor_options) + char **adaptor_name, pointer *adaptor_options) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; confXvAdaptorPtr adaptor; int i; if (adaptor_index >= pScrn->confScreen->numxvadaptors) { - if (adaptor_name) *adaptor_name = NULL; - if (adaptor_options) *adaptor_options = NULL; - return NULL; + if (adaptor_name) + *adaptor_name = NULL; + if (adaptor_options) + *adaptor_options = NULL; + return NULL; } adaptor = &pScrn->confScreen->xvadaptors[adaptor_index]; - if (adaptor_name) *adaptor_name = adaptor->identifier; - if (adaptor_options) *adaptor_options = adaptor->options; + if (adaptor_name) + *adaptor_name = adaptor->identifier; + if (adaptor_options) + *adaptor_options = adaptor->options; for (i = 0; i < adaptor->numports; i++) - if (!xf86NameCmp(adaptor->ports[i].identifier, port_name)) - return adaptor->ports[i].options; + if (!xf86NameCmp(adaptor->ports[i].identifier, port_name)) + return adaptor->ports[i].options; return NULL; } @@ -1678,39 +1685,41 @@ xf86FindXvOptions(int scrnIndex, int adaptor_index, char *port_name, static void xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init, - EntityProc enter, EntityProc leave, pointer private) + EntityProc enter, EntityProc leave, pointer private) { ScrnInfoPtr pScrn; if ((pScrn = xf86FindScreenForEntity(pEnt->index))) - xf86RemoveEntityFromScreen(pScrn,pEnt->index); - xf86SetEntityFuncs(pEnt->index,init,enter,leave,private); + xf86RemoveEntityFromScreen(pScrn, pEnt->index); + xf86SetEntityFuncs(pEnt->index, init, enter, leave, private); } ScrnInfoPtr xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, - EntityProc init, EntityProc enter, EntityProc leave, - pointer private) + EntityProc init, EntityProc enter, EntityProc leave, + pointer private) { EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - if (!pEnt) return pScrn; + + if (!pEnt) + return pScrn; if (!(pEnt->location.type == BUS_NONE)) { - free(pEnt); - return pScrn; + free(pEnt); + return pScrn; } if (!pEnt->active) { - xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private); - free(pEnt); - return pScrn; + xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private); + free(pEnt); + return pScrn; } if (!pScrn) - pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag); - xf86AddEntityToScreen(pScrn,entityIndex); + pScrn = xf86AllocateScreen(pEnt->driver, scrnFlag); + xf86AddEntityToScreen(pScrn, entityIndex); - xf86SetEntityFuncs(entityIndex,init,enter,leave,private); + xf86SetEntityFuncs(entityIndex, init, enter, leave, private); free(pEnt); return pScrn; @@ -1722,48 +1731,49 @@ xf86IsScreenPrimary(int scrnIndex) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; int i; - for (i=0 ; i < pScrn->numEntities; i++) { - if (xf86IsEntityPrimary(i)) - return TRUE; + for (i = 0; i < pScrn->numEntities; i++) { + if (xf86IsEntityPrimary(i)) + return TRUE; } return FALSE; } int xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, - int format, unsigned long len, pointer value ) + int format, unsigned long len, pointer value) { RootWinPropPtr pNewProp = NULL, pRegProp; Bool existing = FALSE; DebugF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n", - ScrnIndex, property, type, format, len, value); + ScrnIndex, property, type, format, len, value); - if (ScrnIndex<0 || ScrnIndex>=xf86NumScreens) { - return BadMatch; + if (ScrnIndex < 0 || ScrnIndex >= xf86NumScreens) { + return BadMatch; } if (xf86RegisteredPropertiesTable && - xf86RegisteredPropertiesTable[ScrnIndex]) { - for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex]; - pNewProp; pNewProp = pNewProp->next) { - if (strcmp(pNewProp->name, NameForAtom(property)) == 0) - break; - } + xf86RegisteredPropertiesTable[ScrnIndex]) { + for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex]; + pNewProp; pNewProp = pNewProp->next) { + if (strcmp(pNewProp->name, NameForAtom(property)) == 0) + break; + } } if (!pNewProp) { - if ((pNewProp = (RootWinPropPtr)malloc(sizeof(RootWinProp))) == NULL) { - return BadAlloc; - } - /* - * We will put this property at the end of the list so that - * the changes are made in the order they were requested. - */ - pNewProp->next = NULL; - } else { - free(pNewProp->name); - existing = TRUE; + if ((pNewProp = (RootWinPropPtr) malloc(sizeof(RootWinProp))) == NULL) { + return BadAlloc; + } + /* + * We will put this property at the end of the list so that + * the changes are made in the order they were requested. + */ + pNewProp->next = NULL; + } + else { + free(pNewProp->name); + existing = TRUE; } pNewProp->name = xnfstrdup(NameForAtom(property)); @@ -1775,28 +1785,29 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, DebugF("new property filled\n"); if (xf86RegisteredPropertiesTable == NULL) { - DebugF("creating xf86RegisteredPropertiesTable[] size %d\n", - xf86NumScreens); - xf86RegisteredPropertiesTable = - xnfcalloc(sizeof(RootWinProp), xf86NumScreens); + DebugF("creating xf86RegisteredPropertiesTable[] size %d\n", + xf86NumScreens); + xf86RegisteredPropertiesTable = + xnfcalloc(sizeof(RootWinProp), xf86NumScreens); } DebugF("xf86RegisteredPropertiesTable %p\n", - (void *)xf86RegisteredPropertiesTable); + (void *) xf86RegisteredPropertiesTable); DebugF("xf86RegisteredPropertiesTable[%d] %p\n", - ScrnIndex, (void *)xf86RegisteredPropertiesTable[ScrnIndex]); + ScrnIndex, (void *) xf86RegisteredPropertiesTable[ScrnIndex]); if (!existing) { - if ( xf86RegisteredPropertiesTable[ScrnIndex] == NULL) { - xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp; - } else { - pRegProp = xf86RegisteredPropertiesTable[ScrnIndex]; - while (pRegProp->next != NULL) { - DebugF("- next %p\n", (void *)pRegProp); - pRegProp = pRegProp->next; + if (xf86RegisteredPropertiesTable[ScrnIndex] == NULL) { + xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp; + } + else { + pRegProp = xf86RegisteredPropertiesTable[ScrnIndex]; + while (pRegProp->next != NULL) { + DebugF("- next %p\n", (void *) pRegProp); + pRegProp = pRegProp->next; + } + pRegProp->next = pNewProp; } - pRegProp->next = pNewProp; - } } DebugF("xf86RegisterRootWindowProperty succeeded\n"); return Success; @@ -1805,16 +1816,16 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, Bool xf86IsUnblank(int mode) { - switch(mode) { + switch (mode) { case SCREEN_SAVER_OFF: case SCREEN_SAVER_FORCER: - return TRUE; + return TRUE; case SCREEN_SAVER_ON: case SCREEN_SAVER_CYCLE: - return FALSE; + return FALSE; default: - xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode); - return TRUE; + xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode); + return TRUE; } } diff --git a/xorg-server/hw/xfree86/common/xf86Init.c b/xorg-server/hw/xfree86/common/xf86Init.c index 5263b5f73..0974893d3 100644 --- a/xorg-server/hw/xfree86/common/xf86Init.c +++ b/xorg-server/hw/xfree86/common/xf86Init.c @@ -91,21 +91,22 @@ #include <hotplug.h> #ifdef XF86PM -void (*xf86OSPMClose)(void) = NULL; +void (*xf86OSPMClose) (void) = NULL; #endif static Bool xorgHWOpenConsole = FALSE; /* Common pixmap formats */ static PixmapFormatRec formats[MAXFORMATS] = { - { 1, 1, BITMAP_SCANLINE_PAD }, - { 4, 8, BITMAP_SCANLINE_PAD }, - { 8, 8, BITMAP_SCANLINE_PAD }, - { 15, 16, BITMAP_SCANLINE_PAD }, - { 16, 16, BITMAP_SCANLINE_PAD }, - { 24, 32, BITMAP_SCANLINE_PAD }, - { 32, 32, BITMAP_SCANLINE_PAD }, + {1, 1, BITMAP_SCANLINE_PAD}, + {4, 8, BITMAP_SCANLINE_PAD}, + {8, 8, BITMAP_SCANLINE_PAD}, + {15, 16, BITMAP_SCANLINE_PAD}, + {16, 16, BITMAP_SCANLINE_PAD}, + {24, 32, BITMAP_SCANLINE_PAD}, + {32, 32, BITMAP_SCANLINE_PAD}, }; + static int numFormats = 7; static Bool formatsDone = FALSE; @@ -123,241 +124,242 @@ static void xf86PrintBanner(void) { #if PRE_RELEASE - xf86ErrorFVerb(0, "\n" - "This is a pre-release version of the X server from " XVENDORNAME ".\n" - "It is not supported in any way.\n" - "Bugs may be filed in the bugzilla at http://bugs.freedesktop.org/.\n" - "Select the \"xorg\" product for bugs you find in this release.\n" - "Before reporting bugs in pre-release versions please check the\n" - "latest version in the X.Org Foundation git repository.\n" - "See http://wiki.x.org/wiki/GitPage for git access instructions.\n"); + xf86ErrorFVerb(0, "\n" + "This is a pre-release version of the X server from " + XVENDORNAME ".\n" "It is not supported in any way.\n" + "Bugs may be filed in the bugzilla at http://bugs.freedesktop.org/.\n" + "Select the \"xorg\" product for bugs you find in this release.\n" + "Before reporting bugs in pre-release versions please check the\n" + "latest version in the X.Org Foundation git repository.\n" + "See http://wiki.x.org/wiki/GitPage for git access instructions.\n"); #endif - xf86ErrorFVerb(0, "\nX.Org X Server %d.%d.%d", - XORG_VERSION_MAJOR, - XORG_VERSION_MINOR, - XORG_VERSION_PATCH); + xf86ErrorFVerb(0, "\nX.Org X Server %d.%d.%d", + XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH); #if XORG_VERSION_SNAP > 0 - xf86ErrorFVerb(0, ".%d", XORG_VERSION_SNAP); + xf86ErrorFVerb(0, ".%d", XORG_VERSION_SNAP); #endif #if XORG_VERSION_SNAP >= 900 - /* When the minor number is 99, that signifies that the we are making - * a release candidate for a major version. (X.0.0) - * When the patch number is 99, that signifies that the we are making - * a release candidate for a minor version. (X.Y.0) - * When the patch number is < 99, then we are making a release - * candidate for the next point release. (X.Y.Z) - */ + /* When the minor number is 99, that signifies that the we are making + * a release candidate for a major version. (X.0.0) + * When the patch number is 99, that signifies that the we are making + * a release candidate for a minor version. (X.Y.0) + * When the patch number is < 99, then we are making a release + * candidate for the next point release. (X.Y.Z) + */ #if XORG_VERSION_MINOR >= 99 - xf86ErrorFVerb(0, " (%d.0.0 RC %d)", XORG_VERSION_MAJOR+1, - XORG_VERSION_SNAP - 900); + xf86ErrorFVerb(0, " (%d.0.0 RC %d)", XORG_VERSION_MAJOR + 1, + XORG_VERSION_SNAP - 900); #elif XORG_VERSION_PATCH == 99 - xf86ErrorFVerb(0, " (%d.%d.0 RC %d)", XORG_VERSION_MAJOR, - XORG_VERSION_MINOR + 1, XORG_VERSION_SNAP - 900); + xf86ErrorFVerb(0, " (%d.%d.0 RC %d)", XORG_VERSION_MAJOR, + XORG_VERSION_MINOR + 1, XORG_VERSION_SNAP - 900); #else - xf86ErrorFVerb(0, " (%d.%d.%d RC %d)", XORG_VERSION_MAJOR, - XORG_VERSION_MINOR, XORG_VERSION_PATCH + 1, - XORG_VERSION_SNAP - 900); + xf86ErrorFVerb(0, " (%d.%d.%d RC %d)", XORG_VERSION_MAJOR, + XORG_VERSION_MINOR, XORG_VERSION_PATCH + 1, + XORG_VERSION_SNAP - 900); #endif #endif #ifdef XORG_CUSTOM_VERSION - xf86ErrorFVerb(0, " (%s)", XORG_CUSTOM_VERSION); + xf86ErrorFVerb(0, " (%s)", XORG_CUSTOM_VERSION); #endif #ifndef XORG_DATE -# define XORG_DATE "Unknown" +#define XORG_DATE "Unknown" #endif - xf86ErrorFVerb(0, "\nRelease Date: %s\n", XORG_DATE); - xf86ErrorFVerb(0, "X Protocol Version %d, Revision %d\n", - X_PROTOCOL, X_PROTOCOL_REVISION); - xf86ErrorFVerb(0, "Build Operating System: %s %s\n", OSNAME, OSVENDOR); + xf86ErrorFVerb(0, "\nRelease Date: %s\n", XORG_DATE); + xf86ErrorFVerb(0, "X Protocol Version %d, Revision %d\n", + X_PROTOCOL, X_PROTOCOL_REVISION); + xf86ErrorFVerb(0, "Build Operating System: %s %s\n", OSNAME, OSVENDOR); #ifdef HAS_UTSNAME - { - struct utsname name; + { + struct utsname name; - /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX, - and Irix) and Single Unix Spec 3 just say that non-negative is success. - All agree that failure is represented by a negative number. - */ - if (uname(&name) >= 0) { - xf86ErrorFVerb(0, "Current Operating System: %s %s %s %s %s\n", - name.sysname, name.nodename, name.release, name.version, name.machine); + /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX, + and Irix) and Single Unix Spec 3 just say that non-negative is success. + All agree that failure is represented by a negative number. + */ + if (uname(&name) >= 0) { + xf86ErrorFVerb(0, "Current Operating System: %s %s %s %s %s\n", + name.sysname, name.nodename, name.release, + name.version, name.machine); #ifdef linux - do { - char buf[80]; - int fd = open("/proc/cmdline", O_RDONLY); - if (fd != -1) { - xf86ErrorFVerb(0, "Kernel command line: "); - memset(buf, 0, 80); - while (read(fd, buf, 80) > 0) { - xf86ErrorFVerb(0, "%.80s", buf); - memset(buf, 0, 80); - } - close(fd); - } - } while (0); + do { + char buf[80]; + int fd = open("/proc/cmdline", O_RDONLY); + + if (fd != -1) { + xf86ErrorFVerb(0, "Kernel command line: "); + memset(buf, 0, 80); + while (read(fd, buf, 80) > 0) { + xf86ErrorFVerb(0, "%.80s", buf); + memset(buf, 0, 80); + } + close(fd); + } + } while (0); #endif + } } - } #endif #if defined(BUILD_DATE) && (BUILD_DATE > 19000000) - { - struct tm t; - char buf[100]; - - memset(&t, 0, sizeof(t)); - memset(buf, 0, sizeof(buf)); - t.tm_mday = BUILD_DATE % 100; - t.tm_mon = (BUILD_DATE / 100) % 100 - 1; - t.tm_year = BUILD_DATE / 10000 - 1900; + { + struct tm t; + char buf[100]; + + memset(&t, 0, sizeof(t)); + memset(buf, 0, sizeof(buf)); + t.tm_mday = BUILD_DATE % 100; + t.tm_mon = (BUILD_DATE / 100) % 100 - 1; + t.tm_year = BUILD_DATE / 10000 - 1900; #if defined(BUILD_TIME) - t.tm_sec = BUILD_TIME % 100; - t.tm_min = (BUILD_TIME / 100) % 100; - t.tm_hour = (BUILD_TIME / 10000) % 100; - if (strftime(buf, sizeof(buf), "%d %B %Y %I:%M:%S%p", &t)) - xf86ErrorFVerb(0, "Build Date: %s\n", buf); + t.tm_sec = BUILD_TIME % 100; + t.tm_min = (BUILD_TIME / 100) % 100; + t.tm_hour = (BUILD_TIME / 10000) % 100; + if (strftime(buf, sizeof(buf), "%d %B %Y %I:%M:%S%p", &t)) + xf86ErrorFVerb(0, "Build Date: %s\n", buf); #else - if (strftime(buf, sizeof(buf), "%d %B %Y", &t)) - xf86ErrorFVerb(0, "Build Date: %s\n", buf); + if (strftime(buf, sizeof(buf), "%d %B %Y", &t)) + xf86ErrorFVerb(0, "Build Date: %s\n", buf); #endif - } + } #endif #if defined(BUILDERSTRING) - xf86ErrorFVerb(0, "%s \n", BUILDERSTRING); + xf86ErrorFVerb(0, "%s \n", BUILDERSTRING); #endif - xf86ErrorFVerb(0, "Current version of pixman: %s\n", - pixman_version_string()); - xf86ErrorFVerb(0, "\tBefore reporting problems, check " - ""__VENDORDWEBSUPPORT__"\n" - "\tto make sure that you have the latest version.\n"); + xf86ErrorFVerb(0, "Current version of pixman: %s\n", + pixman_version_string()); + xf86ErrorFVerb(0, "\tBefore reporting problems, check " + "" __VENDORDWEBSUPPORT__ "\n" + "\tto make sure that you have the latest version.\n"); } static void xf86PrintMarkers(void) { - LogPrintMarkers(); + LogPrintMarkers(); } -Bool xf86PrivsElevated(void) +Bool +xf86PrivsElevated(void) { - static Bool privsTested = FALSE; - static Bool privsElevated = TRUE; + static Bool privsTested = FALSE; + static Bool privsElevated = TRUE; - if (!privsTested) { + if (!privsTested) { #if defined(WIN32) - privsElevated = FALSE; + privsElevated = FALSE; #else - if ((getuid() != geteuid()) || (getgid() != getegid())) { - privsElevated = TRUE; - } else { + if ((getuid() != geteuid()) || (getgid() != getegid())) { + privsElevated = TRUE; + } + else { #if defined(HAVE_ISSETUGID) - privsElevated = issetugid(); + privsElevated = issetugid(); #elif defined(HAVE_GETRESUID) - uid_t ruid, euid, suid; - gid_t rgid, egid, sgid; - - if ((getresuid(&ruid, &euid, &suid) == 0) && - (getresgid(&rgid, &egid, &sgid) == 0)) { - privsElevated = (euid != suid) || (egid != sgid); - } - else { - printf("Failed getresuid or getresgid"); - /* Something went wrong, make defensive assumption */ - privsElevated = TRUE; - } + uid_t ruid, euid, suid; + gid_t rgid, egid, sgid; + + if ((getresuid(&ruid, &euid, &suid) == 0) && + (getresgid(&rgid, &egid, &sgid) == 0)) { + privsElevated = (euid != suid) || (egid != sgid); + } + else { + printf("Failed getresuid or getresgid"); + /* Something went wrong, make defensive assumption */ + privsElevated = TRUE; + } #else - if (getuid()==0) { - /* running as root: uid==euid==0 */ - privsElevated = FALSE; - } - else { - /* - * If there are saved ID's the process might still be privileged - * even though the above test succeeded. If issetugid() and - * getresgid() aren't available, test this by trying to set - * euid to 0. - */ - unsigned int oldeuid; - oldeuid = geteuid(); - - if (seteuid(0) != 0) { - privsElevated = FALSE; - } else { - if (seteuid(oldeuid) != 0) { - FatalError("Failed to drop privileges. Exiting\n"); - } - privsElevated = TRUE; + if (getuid() == 0) { + /* running as root: uid==euid==0 */ + privsElevated = FALSE; + } + else { + /* + * If there are saved ID's the process might still be privileged + * even though the above test succeeded. If issetugid() and + * getresgid() aren't available, test this by trying to set + * euid to 0. + */ + unsigned int oldeuid; + + oldeuid = geteuid(); + + if (seteuid(0) != 0) { + privsElevated = FALSE; + } + else { + if (seteuid(oldeuid) != 0) { + FatalError("Failed to drop privileges. Exiting\n"); + } + privsElevated = TRUE; + } + } +#endif } - } #endif + privsTested = TRUE; } -#endif - privsTested = TRUE; - } - return privsElevated; + return privsElevated; } static Bool xf86CreateRootWindow(WindowPtr pWin) { - int ret = TRUE; - int err = Success; - ScreenPtr pScreen = pWin->drawable.pScreen; - RootWinPropPtr pProp; - CreateWindowProcPtr CreateWindow = (CreateWindowProcPtr) - dixLookupPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey); - - DebugF("xf86CreateRootWindow(%p)\n", pWin); - - if ( pScreen->CreateWindow != xf86CreateRootWindow ) { - /* Can't find hook we are hung on */ - xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */, - "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n", - (void *)xf86CreateRootWindow, - (void *)pScreen->CreateWindow ); - } - - /* Unhook this function ... */ - pScreen->CreateWindow = CreateWindow; - dixSetPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey, NULL); - - /* ... and call the previous CreateWindow fuction, if any */ - if (NULL!=pScreen->CreateWindow) { - ret = (*pScreen->CreateWindow)(pWin); - } - - /* Now do our stuff */ - if (xf86RegisteredPropertiesTable != NULL) { - if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) { - for (pProp = xf86RegisteredPropertiesTable[pScreen->myNum]; - pProp != NULL && err==Success; - pProp = pProp->next ) - { - Atom prop; - - prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE); - err = dixChangeWindowProperty(serverClient, pWin, - prop, pProp->type, - pProp->format, PropModeReplace, - pProp->size, pProp->data, - FALSE); - } - - /* Look at err */ - ret &= (err==Success); - - } else { - xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with " - "non-root window %p (parent %p)\n", - (void *)pWin, (void *)pWin->parent); - ret = FALSE; + int ret = TRUE; + int err = Success; + ScreenPtr pScreen = pWin->drawable.pScreen; + RootWinPropPtr pProp; + CreateWindowProcPtr CreateWindow = (CreateWindowProcPtr) + dixLookupPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey); + + DebugF("xf86CreateRootWindow(%p)\n", pWin); + + if (pScreen->CreateWindow != xf86CreateRootWindow) { + /* Can't find hook we are hung on */ + xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */ , + "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n", + (void *) xf86CreateRootWindow, + (void *) pScreen->CreateWindow); } - } - DebugF("xf86CreateRootWindow() returns %d\n", ret); - return ret; -} + /* Unhook this function ... */ + pScreen->CreateWindow = CreateWindow; + dixSetPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey, NULL); + + /* ... and call the previous CreateWindow fuction, if any */ + if (NULL != pScreen->CreateWindow) { + ret = (*pScreen->CreateWindow) (pWin); + } + + /* Now do our stuff */ + if (xf86RegisteredPropertiesTable != NULL) { + if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) { + for (pProp = xf86RegisteredPropertiesTable[pScreen->myNum]; + pProp != NULL && err == Success; pProp = pProp->next) { + Atom prop; + + prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE); + err = dixChangeWindowProperty(serverClient, pWin, + prop, pProp->type, + pProp->format, PropModeReplace, + pProp->size, pProp->data, FALSE); + } + + /* Look at err */ + ret &= (err == Success); + + } + else { + xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with " + "non-root window %p (parent %p)\n", + (void *) pWin, (void *) pWin->parent); + ret = FALSE; + } + } + DebugF("xf86CreateRootWindow() returns %d\n", ret); + return ret; +} static void InstallSignalHandlers(void) @@ -365,20 +367,21 @@ InstallSignalHandlers(void) /* * Install signal handler for unexpected signals */ - xf86Info.caughtSignal=FALSE; + xf86Info.caughtSignal = FALSE; if (!xf86Info.notrapSignals) { - OsRegisterSigWrapper(xf86SigWrapper); - } else { - signal(SIGSEGV, SIG_DFL); - signal(SIGILL, SIG_DFL); + OsRegisterSigWrapper(xf86SigWrapper); + } + else { + signal(SIGSEGV, SIG_DFL); + signal(SIGILL, SIG_DFL); #ifdef SIGEMT - signal(SIGEMT, SIG_DFL); + signal(SIGEMT, SIG_DFL); #endif - signal(SIGFPE, SIG_DFL); - signal(SIGBUS, SIG_DFL); - signal(SIGSYS, SIG_DFL); - signal(SIGXCPU, SIG_DFL); - signal(SIGXFSZ, SIG_DFL); + signal(SIGFPE, SIG_DFL); + signal(SIGBUS, SIG_DFL); + signal(SIGSYS, SIG_DFL); + signal(SIGXCPU, SIG_DFL); + signal(SIGXFSZ, SIG_DFL); } } @@ -389,485 +392,500 @@ InstallSignalHandlers(void) * collecting the pixmap formats. */ void -InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) +InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) { - int i, j, k, scr_index, was_blocked = 0; - char **modulelist; - pointer *optionlist; - Pix24Flags screenpix24, pix24; - MessageType pix24From = X_DEFAULT; - Bool pix24Fail = FALSE; - Bool autoconfig = FALSE; - GDevPtr configured_device; - - xf86Initialising = TRUE; - - if (serverGeneration == 1) { - if ((xf86ServerName = strrchr(argv[0], '/')) != 0) - xf86ServerName++; - else - xf86ServerName = argv[0]; - - xf86PrintBanner(); - xf86PrintMarkers(); - if (xf86LogFile) { - time_t t; - const char *ct; - t = time(NULL); - ct = ctime(&t); - xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s", - xf86LogFile, ct); - } - - /* Read and parse the config file */ - if (!xf86DoConfigure && !xf86DoShowOptions) { - switch (xf86HandleConfigFile(FALSE)) { - case CONFIG_OK: - break; - case CONFIG_PARSE_ERROR: - xf86Msg(X_ERROR, "Error parsing the config file\n"); - return; - case CONFIG_NOFILE: - autoconfig = TRUE; - break; - } - } + int i, j, k, scr_index, was_blocked = 0; + char **modulelist; + pointer *optionlist; + Pix24Flags screenpix24, pix24; + MessageType pix24From = X_DEFAULT; + Bool pix24Fail = FALSE; + Bool autoconfig = FALSE; + GDevPtr configured_device; + + xf86Initialising = TRUE; + + if (serverGeneration == 1) { + if ((xf86ServerName = strrchr(argv[0], '/')) != 0) + xf86ServerName++; + else + xf86ServerName = argv[0]; + + xf86PrintBanner(); + xf86PrintMarkers(); + if (xf86LogFile) { + time_t t; + const char *ct; + + t = time(NULL); + ct = ctime(&t); + xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s", + xf86LogFile, ct); + } - InstallSignalHandlers(); + /* Read and parse the config file */ + if (!xf86DoConfigure && !xf86DoShowOptions) { + switch (xf86HandleConfigFile(FALSE)) { + case CONFIG_OK: + break; + case CONFIG_PARSE_ERROR: + xf86Msg(X_ERROR, "Error parsing the config file\n"); + return; + case CONFIG_NOFILE: + autoconfig = TRUE; + break; + } + } - /* Initialise the loader */ - LoaderInit(); + InstallSignalHandlers(); - /* Tell the loader the default module search path */ - LoaderSetPath(xf86ModulePath); + /* Initialise the loader */ + LoaderInit(); - if (xf86Info.ignoreABI) { - LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); - } + /* Tell the loader the default module search path */ + LoaderSetPath(xf86ModulePath); - if (xf86DoShowOptions) - DoShowOptions(); + if (xf86Info.ignoreABI) { + LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); + } - /* Do a general bus probe. This will be a PCI probe for x86 platforms */ - xf86BusProbe(); + if (xf86DoShowOptions) + DoShowOptions(); - if (xf86DoConfigure) - DoConfigure(); + /* Do a general bus probe. This will be a PCI probe for x86 platforms */ + xf86BusProbe(); - if (autoconfig) { - if (!xf86AutoConfig()) { - xf86Msg(X_ERROR, "Auto configuration failed\n"); - return; - } - } + if (xf86DoConfigure) + DoConfigure(); + + if (autoconfig) { + if (!xf86AutoConfig()) { + xf86Msg(X_ERROR, "Auto configuration failed\n"); + return; + } + } #ifdef XF86PM - xf86OSPMClose = xf86OSPMOpen(); + xf86OSPMClose = xf86OSPMOpen(); #endif - /* Load all modules specified explicitly in the config file */ - if ((modulelist = xf86ModulelistFromConfig(&optionlist))) { - xf86LoadModules(modulelist, optionlist); - free(modulelist); - free(optionlist); - } + /* Load all modules specified explicitly in the config file */ + if ((modulelist = xf86ModulelistFromConfig(&optionlist))) { + xf86LoadModules(modulelist, optionlist); + free(modulelist); + free(optionlist); + } - /* Load all driver modules specified in the config file */ - /* If there aren't any specified in the config file, autoconfig them */ - /* FIXME: Does not handle multiple active screen sections, but I'm not - * sure if we really want to handle that case*/ - configured_device = xf86ConfigLayout.screens->screen->device; - if ((!configured_device) || (!configured_device->driver)) { - if (!autoConfigDevice(configured_device)) { - xf86Msg(X_ERROR, "Automatic driver configuration failed\n"); - return ; + /* Load all driver modules specified in the config file */ + /* If there aren't any specified in the config file, autoconfig them */ + /* FIXME: Does not handle multiple active screen sections, but I'm not + * sure if we really want to handle that case*/ + configured_device = xf86ConfigLayout.screens->screen->device; + if ((!configured_device) || (!configured_device->driver)) { + if (!autoConfigDevice(configured_device)) { + xf86Msg(X_ERROR, "Automatic driver configuration failed\n"); + return; + } + } + if ((modulelist = xf86DriverlistFromConfig())) { + xf86LoadModules(modulelist, NULL); + free(modulelist); } - } - if ((modulelist = xf86DriverlistFromConfig())) { - xf86LoadModules(modulelist, NULL); - free(modulelist); - } - /* Load all input driver modules specified in the config file. */ - if ((modulelist = xf86InputDriverlistFromConfig())) { - xf86LoadModules(modulelist, NULL); - free(modulelist); - } + /* Load all input driver modules specified in the config file. */ + if ((modulelist = xf86InputDriverlistFromConfig())) { + xf86LoadModules(modulelist, NULL); + free(modulelist); + } - /* - * It is expected that xf86AddDriver()/xf86AddInputDriver will be - * called for each driver as it is loaded. Those functions save the - * module pointers for drivers. - * XXX Nothing keeps track of them for other modules. - */ - /* XXX What do we do if not all of these could be loaded? */ + /* + * It is expected that xf86AddDriver()/xf86AddInputDriver will be + * called for each driver as it is loaded. Those functions save the + * module pointers for drivers. + * XXX Nothing keeps track of them for other modules. + */ + /* XXX What do we do if not all of these could be loaded? */ - /* - * At this point, xf86DriverList[] is all filled in with entries for - * each of the drivers to try and xf86NumDrivers has the number of - * drivers. If there are none, return now. - */ + /* + * At this point, xf86DriverList[] is all filled in with entries for + * each of the drivers to try and xf86NumDrivers has the number of + * drivers. If there are none, return now. + */ - if (xf86NumDrivers == 0) { - xf86Msg(X_ERROR, "No drivers available.\n"); - return; - } + if (xf86NumDrivers == 0) { + xf86Msg(X_ERROR, "No drivers available.\n"); + return; + } - /* - * Call each of the Identify functions and call the driverFunc to check - * if HW access is required. The Identify functions print out some - * identifying information, and anything else that might be - * needed at this early stage. - */ + /* + * Call each of the Identify functions and call the driverFunc to check + * if HW access is required. The Identify functions print out some + * identifying information, and anything else that might be + * needed at this early stage. + */ - for (i = 0; i < xf86NumDrivers; i++) { - if (xf86DriverList[i]->Identify != NULL) - xf86DriverList[i]->Identify(0); - - if (!xorgHWAccess || !xorgHWOpenConsole) { - xorgHWFlags flags; - if(!xf86DriverList[i]->driverFunc - || !xf86DriverList[i]->driverFunc(NULL, - GET_REQUIRED_HW_INTERFACES, - &flags)) - flags = HW_IO; - - if(NEED_IO_ENABLED(flags)) - xorgHWAccess = TRUE; - if(!(flags & HW_SKIP_CONSOLE)) - xorgHWOpenConsole = TRUE; - } - } + for (i = 0; i < xf86NumDrivers; i++) { + if (xf86DriverList[i]->Identify != NULL) + xf86DriverList[i]->Identify(0); - if (xorgHWOpenConsole) - xf86OpenConsole(); - else - xf86Info.dontVTSwitch = TRUE; + if (!xorgHWAccess || !xorgHWOpenConsole) { + xorgHWFlags flags; - if (xf86BusConfig() == FALSE) - return; + if (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags)) + flags = HW_IO; - xf86PostProbe(); + if (NEED_IO_ENABLED(flags)) + xorgHWAccess = TRUE; + if (!(flags & HW_SKIP_CONSOLE)) + xorgHWOpenConsole = TRUE; + } + } - /* - * Sort the drivers to match the requested ording. Using a slow - * bubble sort. - */ - for (j = 0; j < xf86NumScreens - 1; j++) { - for (i = 0; i < xf86NumScreens - j - 1; i++) { - if (xf86Screens[i + 1]->confScreen->screennum < - xf86Screens[i]->confScreen->screennum) { - ScrnInfoPtr tmpScrn = xf86Screens[i + 1]; - xf86Screens[i + 1] = xf86Screens[i]; - xf86Screens[i] = tmpScrn; - } - } - } - /* Fix up the indexes */ - for (i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->scrnIndex = i; - } + if (xorgHWOpenConsole) + xf86OpenConsole(); + else + xf86Info.dontVTSwitch = TRUE; - /* - * Call the driver's PreInit()'s to complete initialisation for the first - * generation. - */ + if (xf86BusConfig() == FALSE) + return; - for (i = 0; i < xf86NumScreens; i++) { - xf86VGAarbiterScrnInit(xf86Screens[i]); - xf86VGAarbiterLock(xf86Screens[i]); - if (xf86Screens[i]->PreInit && - xf86Screens[i]->PreInit(xf86Screens[i], 0)) - xf86Screens[i]->configured = TRUE; - xf86VGAarbiterUnlock(xf86Screens[i]); - } - for (i = 0; i < xf86NumScreens; i++) - if (!xf86Screens[i]->configured) - xf86DeleteScreen(i--, 0); + xf86PostProbe(); - /* - * If no screens left, return now. - */ + /* + * Sort the drivers to match the requested ording. Using a slow + * bubble sort. + */ + for (j = 0; j < xf86NumScreens - 1; j++) { + for (i = 0; i < xf86NumScreens - j - 1; i++) { + if (xf86Screens[i + 1]->confScreen->screennum < + xf86Screens[i]->confScreen->screennum) { + ScrnInfoPtr tmpScrn = xf86Screens[i + 1]; + + xf86Screens[i + 1] = xf86Screens[i]; + xf86Screens[i] = tmpScrn; + } + } + } + /* Fix up the indexes */ + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->scrnIndex = i; + } - if (xf86NumScreens == 0) { - xf86Msg(X_ERROR, - "Screen(s) found, but none have a usable configuration.\n"); - return; - } + /* + * Call the driver's PreInit()'s to complete initialisation for the first + * generation. + */ - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->name == NULL) { - XNFasprintf(&xf86Screens[i]->name, "screen%d", i); - xf86MsgVerb(X_WARNING, 0, - "Screen driver %d has no name set, using `%s'.\n", - i, xf86Screens[i]->name); - } - } + for (i = 0; i < xf86NumScreens; i++) { + xf86VGAarbiterScrnInit(xf86Screens[i]); + xf86VGAarbiterLock(xf86Screens[i]); + if (xf86Screens[i]->PreInit && + xf86Screens[i]->PreInit(xf86Screens[i], 0)) + xf86Screens[i]->configured = TRUE; + xf86VGAarbiterUnlock(xf86Screens[i]); + } + for (i = 0; i < xf86NumScreens; i++) + if (!xf86Screens[i]->configured) + xf86DeleteScreen(i--, 0); - /* Remove (unload) drivers that are not required */ - for (i = 0; i < xf86NumDrivers; i++) - if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0) - xf86DeleteDriver(i); + /* + * If no screens left, return now. + */ - /* - * At this stage we know how many screens there are. - */ + if (xf86NumScreens == 0) { + xf86Msg(X_ERROR, + "Screen(s) found, but none have a usable configuration.\n"); + return; + } - for (i = 0; i < xf86NumScreens; i++) - xf86InitViewport(xf86Screens[i]); + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->name == NULL) { + XNFasprintf(&xf86Screens[i]->name, "screen%d", i); + xf86MsgVerb(X_WARNING, 0, + "Screen driver %d has no name set, using `%s'.\n", + i, xf86Screens[i]->name); + } + } - /* - * Collect all pixmap formats and check for conflicts at the display - * level. Should we die here? Or just delete the offending screens? - */ - screenpix24 = Pix24DontCare; - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->imageByteOrder != - xf86Screens[0]->imageByteOrder) - FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); - if (xf86Screens[i]->bitmapScanlinePad != - xf86Screens[0]->bitmapScanlinePad) - FatalError("Inconsistent display bitmapScanlinePad. Exiting\n"); - if (xf86Screens[i]->bitmapScanlineUnit != - xf86Screens[0]->bitmapScanlineUnit) - FatalError("Inconsistent display bitmapScanlineUnit. Exiting\n"); - if (xf86Screens[i]->bitmapBitOrder != - xf86Screens[0]->bitmapBitOrder) - FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); - - /* Determine the depth 24 pixmap format the screens would like */ - if (xf86Screens[i]->pixmap24 != Pix24DontCare) { - if (screenpix24 == Pix24DontCare) - screenpix24 = xf86Screens[i]->pixmap24; - else if (screenpix24 != xf86Screens[i]->pixmap24) - FatalError("Inconsistent depth 24 pixmap format. Exiting\n"); - } - } - /* check if screenpix24 is consistent with the config/cmdline */ - if (xf86Info.pixmap24 != Pix24DontCare) { - pix24 = xf86Info.pixmap24; - pix24From = xf86Info.pix24From; - if (screenpix24 != Pix24DontCare && screenpix24 != xf86Info.pixmap24) - pix24Fail = TRUE; - } else if (screenpix24 != Pix24DontCare) { - pix24 = screenpix24; - pix24From = X_PROBED; - } else - pix24 = Pix24Use32; - - if (pix24Fail) - FatalError("Screen(s) can't use the required depth 24 pixmap format" - " (%d). Exiting\n", PIX24TOBPP(pix24)); - - /* Initialise the depth 24 format */ - for (j = 0; j < numFormats && formats[j].depth != 24; j++) - ; - formats[j].bitsPerPixel = PIX24TOBPP(pix24); - - /* Collect additional formats */ - for (i = 0; i < xf86NumScreens; i++) { - for (j = 0; j < xf86Screens[i]->numFormats; j++) { - for (k = 0; ; k++) { - if (k >= numFormats) { - if (k >= MAXFORMATS) - FatalError("Too many pixmap formats! Exiting\n"); - formats[k] = xf86Screens[i]->formats[j]; - numFormats++; - break; - } - if (formats[k].depth == xf86Screens[i]->formats[j].depth) { - if ((formats[k].bitsPerPixel == - xf86Screens[i]->formats[j].bitsPerPixel) && - (formats[k].scanlinePad == - xf86Screens[i]->formats[j].scanlinePad)) - break; - FatalError("Inconsistent pixmap format for depth %d." - " Exiting\n", formats[k].depth); - } - } - } - } - formatsDone = TRUE; + /* Remove (unload) drivers that are not required */ + for (i = 0; i < xf86NumDrivers; i++) + if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0) + xf86DeleteDriver(i); - if (xf86Info.vtno >= 0 ) { -#define VT_ATOM_NAME "XFree86_VT" - Atom VTAtom=-1; - CARD32 *VT = NULL; - int ret; - - /* This memory needs to stay available until the screen has been - initialized, and we can create the property for real. - */ - if ( (VT = malloc(sizeof(CARD32)))==NULL ) { - FatalError("Unable to make VT property - out of memory. Exiting...\n"); - } - *VT = xf86Info.vtno; - - VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME) - 1, TRUE); - - for (i = 0, ret = Success; i < xf86NumScreens && ret == Success; i++) { - ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex, - VTAtom, XA_INTEGER, 32, - 1, VT ); - if (ret != Success) - xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING, - "Failed to register VT property\n"); - } - } + /* + * At this stage we know how many screens there are. + */ + + for (i = 0; i < xf86NumScreens; i++) + xf86InitViewport(xf86Screens[i]); + + /* + * Collect all pixmap formats and check for conflicts at the display + * level. Should we die here? Or just delete the offending screens? + */ + screenpix24 = Pix24DontCare; + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->imageByteOrder != + xf86Screens[0]->imageByteOrder) + FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); + if (xf86Screens[i]->bitmapScanlinePad != + xf86Screens[0]->bitmapScanlinePad) + FatalError + ("Inconsistent display bitmapScanlinePad. Exiting\n"); + if (xf86Screens[i]->bitmapScanlineUnit != + xf86Screens[0]->bitmapScanlineUnit) + FatalError + ("Inconsistent display bitmapScanlineUnit. Exiting\n"); + if (xf86Screens[i]->bitmapBitOrder != + xf86Screens[0]->bitmapBitOrder) + FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); + + /* Determine the depth 24 pixmap format the screens would like */ + if (xf86Screens[i]->pixmap24 != Pix24DontCare) { + if (screenpix24 == Pix24DontCare) + screenpix24 = xf86Screens[i]->pixmap24; + else if (screenpix24 != xf86Screens[i]->pixmap24) + FatalError + ("Inconsistent depth 24 pixmap format. Exiting\n"); + } + } + /* check if screenpix24 is consistent with the config/cmdline */ + if (xf86Info.pixmap24 != Pix24DontCare) { + pix24 = xf86Info.pixmap24; + pix24From = xf86Info.pix24From; + if (screenpix24 != Pix24DontCare && + screenpix24 != xf86Info.pixmap24) + pix24Fail = TRUE; + } + else if (screenpix24 != Pix24DontCare) { + pix24 = screenpix24; + pix24From = X_PROBED; + } + else + pix24 = Pix24Use32; - if (SeatId) { - Atom SeatAtom; + if (pix24Fail) + FatalError("Screen(s) can't use the required depth 24 pixmap format" + " (%d). Exiting\n", PIX24TOBPP(pix24)); - SeatAtom = MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE); + /* Initialise the depth 24 format */ + for (j = 0; j < numFormats && formats[j].depth != 24; j++); + formats[j].bitsPerPixel = PIX24TOBPP(pix24); + /* Collect additional formats */ for (i = 0; i < xf86NumScreens; i++) { + for (j = 0; j < xf86Screens[i]->numFormats; j++) { + for (k = 0;; k++) { + if (k >= numFormats) { + if (k >= MAXFORMATS) + FatalError("Too many pixmap formats! Exiting\n"); + formats[k] = xf86Screens[i]->formats[j]; + numFormats++; + break; + } + if (formats[k].depth == xf86Screens[i]->formats[j].depth) { + if ((formats[k].bitsPerPixel == + xf86Screens[i]->formats[j].bitsPerPixel) && + (formats[k].scanlinePad == + xf86Screens[i]->formats[j].scanlinePad)) + break; + FatalError("Inconsistent pixmap format for depth %d." + " Exiting\n", formats[k].depth); + } + } + } + } + formatsDone = TRUE; + + if (xf86Info.vtno >= 0) { +#define VT_ATOM_NAME "XFree86_VT" + Atom VTAtom = -1; + CARD32 *VT = NULL; int ret; - ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex, - SeatAtom, XA_STRING, 8, - strlen(SeatId)+1, SeatId ); - if (ret != Success) { - xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING, - "Failed to register seat property\n"); + /* This memory needs to stay available until the screen has been + initialized, and we can create the property for real. + */ + if ((VT = malloc(sizeof(CARD32))) == NULL) { + FatalError + ("Unable to make VT property - out of memory. Exiting...\n"); + } + *VT = xf86Info.vtno; + + VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME) - 1, TRUE); + + for (i = 0, ret = Success; i < xf86NumScreens && ret == Success; + i++) { + ret = + xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex, + VTAtom, XA_INTEGER, 32, 1, + VT); + if (ret != Success) + xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING, + "Failed to register VT property\n"); + } + } + + if (SeatId) { + Atom SeatAtom; + + SeatAtom = + MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE); + + for (i = 0; i < xf86NumScreens; i++) { + int ret; + + ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex, + SeatAtom, XA_STRING, 8, + strlen(SeatId) + 1, + SeatId); + if (ret != Success) { + xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING, + "Failed to register seat property\n"); + } + } + } + + /* If a screen uses depth 24, show what the pixmap format is */ + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->depth == 24) { + xf86Msg(pix24From, "Depth 24 pixmap format is %d bpp\n", + PIX24TOBPP(pix24)); + break; } } } + else { + /* + * serverGeneration != 1; some OSs have to do things here, too. + */ + if (xorgHWOpenConsole) + xf86OpenConsole(); - /* If a screen uses depth 24, show what the pixmap format is */ - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->depth == 24) { - xf86Msg(pix24From, "Depth 24 pixmap format is %d bpp\n", - PIX24TOBPP(pix24)); - break; - } +#ifdef XF86PM + /* + should we reopen it here? We need to deal with an already opened + device. We could leave this to the OS layer. For now we simply + close it here + */ + if (xf86OSPMClose) + xf86OSPMClose(); + if ((xf86OSPMClose = xf86OSPMOpen()) != NULL) + xf86MsgVerb(X_INFO, 3, "APM registered successfully\n"); +#endif + + /* Make sure full I/O access is enabled */ + if (xorgHWAccess) + xf86EnableIO(); } - } else { + /* - * serverGeneration != 1; some OSs have to do things here, too. + * Use the previously collected parts to setup pScreenInfo */ - if (xorgHWOpenConsole) - xf86OpenConsole(); -#ifdef XF86PM - /* - should we reopen it here? We need to deal with an already opened - device. We could leave this to the OS layer. For now we simply - close it here - */ - if (xf86OSPMClose) - xf86OSPMClose(); - if ((xf86OSPMClose = xf86OSPMOpen()) != NULL) - xf86MsgVerb(X_INFO, 3, "APM registered successfully\n"); -#endif + pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder; + pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad; + pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit; + pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder; + pScreenInfo->numPixmapFormats = numFormats; + for (i = 0; i < numFormats; i++) + pScreenInfo->formats[i] = formats[i]; - /* Make sure full I/O access is enabled */ - if (xorgHWAccess) - xf86EnableIO(); - } - - /* - * Use the previously collected parts to setup pScreenInfo - */ - - pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder; - pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad; - pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit; - pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder; - pScreenInfo->numPixmapFormats = numFormats; - for (i = 0; i < numFormats; i++) - pScreenInfo->formats[i] = formats[i]; - - /* Make sure the server's VT is active */ - - if (serverGeneration != 1) { - xf86Resetting = TRUE; - /* All screens are in the same state, so just check the first */ - if (!xf86Screens[0]->vtSema) { + /* Make sure the server's VT is active */ + + if (serverGeneration != 1) { + xf86Resetting = TRUE; + /* All screens are in the same state, so just check the first */ + if (!xf86Screens[0]->vtSema) { #ifdef HAS_USL_VTS - ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ); + ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ); #endif - xf86AccessEnter(); - was_blocked = xf86BlockSIGIO(); + xf86AccessEnter(); + was_blocked = xf86BlockSIGIO(); + } } - } - - for (i = 0; i < xf86NumScreens; i++) - if (!xf86ColormapAllocatePrivates(xf86Screens[i])) - FatalError("Cannot register DDX private keys"); - - if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0) || - !dixRegisterPrivateKey(&xf86CreateRootWindowKeyRec, PRIVATE_SCREEN, 0)) - FatalError("Cannot register DDX private keys"); - - for (i = 0; i < xf86NumScreens; i++) { - xf86VGAarbiterLock(xf86Screens[i]); - /* - * Almost everything uses these defaults, and many of those that - * don't, will wrap them. - */ - xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess; + + for (i = 0; i < xf86NumScreens; i++) + if (!xf86ColormapAllocatePrivates(xf86Screens[i])) + FatalError("Cannot register DDX private keys"); + + if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0) || + !dixRegisterPrivateKey(&xf86CreateRootWindowKeyRec, PRIVATE_SCREEN, 0)) + FatalError("Cannot register DDX private keys"); + + for (i = 0; i < xf86NumScreens; i++) { + xf86VGAarbiterLock(xf86Screens[i]); + /* + * Almost everything uses these defaults, and many of those that + * don't, will wrap them. + */ + xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess; #ifdef XFreeXDGA - xf86Screens[i]->SetDGAMode = xf86SetDGAMode; + xf86Screens[i]->SetDGAMode = xf86SetDGAMode; #endif - xf86Screens[i]->DPMSSet = NULL; - xf86Screens[i]->LoadPalette = NULL; - xf86Screens[i]->SetOverscan = NULL; - xf86Screens[i]->DriverFunc = NULL; - xf86Screens[i]->pScreen = NULL; - scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv); - xf86VGAarbiterUnlock(xf86Screens[i]); - if (scr_index == i) { - /* - * Hook in our ScrnInfoRec, and initialise some other pScreen - * fields. - */ - dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates, - xf86ScreenKey, xf86Screens[i]); - xf86Screens[i]->pScreen = screenInfo.screens[scr_index]; - /* The driver should set this, but make sure it is set anyway */ - xf86Screens[i]->vtSema = TRUE; - } else { - /* This shouldn't normally happen */ - FatalError("AddScreen/ScreenInit failed for driver %d\n", i); - } - - DebugF("InitOutput - xf86Screens[%d]->pScreen = %p\n", - i, xf86Screens[i]->pScreen ); - DebugF("xf86Screens[%d]->pScreen->CreateWindow = %p\n", - i, xf86Screens[i]->pScreen->CreateWindow ); - - dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates, - xf86CreateRootWindowKey, - xf86Screens[i]->pScreen->CreateWindow); - xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow; - - if (PictureGetSubpixelOrder (xf86Screens[i]->pScreen) == SubPixelUnknown) - { - xf86MonPtr DDC = (xf86MonPtr)(xf86Screens[i]->monitor->DDC); - PictureSetSubpixelOrder (xf86Screens[i]->pScreen, - DDC ? - (DDC->features.input_type ? - SubPixelHorizontalRGB : SubPixelNone) : - SubPixelUnknown); - } + xf86Screens[i]->DPMSSet = NULL; + xf86Screens[i]->LoadPalette = NULL; + xf86Screens[i]->SetOverscan = NULL; + xf86Screens[i]->DriverFunc = NULL; + xf86Screens[i]->pScreen = NULL; + scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv); + xf86VGAarbiterUnlock(xf86Screens[i]); + if (scr_index == i) { + /* + * Hook in our ScrnInfoRec, and initialise some other pScreen + * fields. + */ + dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates, + xf86ScreenKey, xf86Screens[i]); + xf86Screens[i]->pScreen = screenInfo.screens[scr_index]; + /* The driver should set this, but make sure it is set anyway */ + xf86Screens[i]->vtSema = TRUE; + } + else { + /* This shouldn't normally happen */ + FatalError("AddScreen/ScreenInit failed for driver %d\n", i); + } + + DebugF("InitOutput - xf86Screens[%d]->pScreen = %p\n", + i, xf86Screens[i]->pScreen); + DebugF("xf86Screens[%d]->pScreen->CreateWindow = %p\n", + i, xf86Screens[i]->pScreen->CreateWindow); + + dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates, + xf86CreateRootWindowKey, + xf86Screens[i]->pScreen->CreateWindow); + xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow; + + if (PictureGetSubpixelOrder(xf86Screens[i]->pScreen) == SubPixelUnknown) { + xf86MonPtr DDC = (xf86MonPtr) (xf86Screens[i]->monitor->DDC); + + PictureSetSubpixelOrder(xf86Screens[i]->pScreen, + DDC ? + (DDC->features.input_type ? + SubPixelHorizontalRGB : SubPixelNone) : + SubPixelUnknown); + } #ifdef RANDR - if (!xf86Info.disableRandR) - xf86RandRInit (screenInfo.screens[scr_index]); - xf86Msg(xf86Info.randRFrom, "RandR %s\n", - xf86Info.disableRandR ? "disabled" : "enabled"); + if (!xf86Info.disableRandR) + xf86RandRInit(screenInfo.screens[scr_index]); + xf86Msg(xf86Info.randRFrom, "RandR %s\n", + xf86Info.disableRandR ? "disabled" : "enabled"); #endif - } + } - xf86VGAarbiterWrapFunctions(); - xf86UnblockSIGIO(was_blocked); + xf86VGAarbiterWrapFunctions(); + xf86UnblockSIGIO(was_blocked); - xf86InitOrigins(); + xf86InitOrigins(); - xf86Resetting = FALSE; - xf86Initialising = FALSE; + xf86Resetting = FALSE; + xf86Initialising = FALSE; - RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, xf86Wakeup, - NULL); + RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr) NoopDDA, xf86Wakeup, + NULL); } /** @@ -877,7 +895,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput(int argc, char **argv) { - InputInfoPtr* pInfo; + InputInfoPtr *pInfo; DeviceIntPtr dev; xf86Info.vtRequestsPending = FALSE; @@ -886,8 +904,10 @@ InitInput(int argc, char **argv) /* Initialize all configured input devices */ for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) { - (*pInfo)->options = xf86AddNewOption((*pInfo)->options, "driver", (*pInfo)->driver); - (*pInfo)->options = xf86AddNewOption((*pInfo)->options, "identifier", (*pInfo)->name); + (*pInfo)->options = + xf86AddNewOption((*pInfo)->options, "driver", (*pInfo)->driver); + (*pInfo)->options = + xf86AddNewOption((*pInfo)->options, "identifier", (*pInfo)->name); /* If one fails, the others will too */ if (NewInputDeviceRequest((*pInfo)->options, NULL, &dev) == BadAlloc) break; @@ -897,7 +917,7 @@ InitInput(int argc, char **argv) } void -CloseInput (void) +CloseInput(void) { config_fini(); mieqFini(); @@ -912,16 +932,16 @@ CloseInput (void) void OsVendorInit(void) { - static Bool beenHere = FALSE; + static Bool beenHere = FALSE; - signal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */ + signal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */ - if (!beenHere) { - umask(022); - xf86LogInit(); - } + if (!beenHere) { + umask(022); + xf86LogInit(); + } - /* Set stderr to non-blocking. */ + /* Set stderr to non-blocking. */ #ifndef O_NONBLOCK #if defined(FNDELAY) #define O_NONBLOCK FNDELAY @@ -930,21 +950,20 @@ OsVendorInit(void) #endif #ifdef O_NONBLOCK - if (!beenHere) { - if (xf86PrivsElevated()) - { - int status; + if (!beenHere) { + if (xf86PrivsElevated()) { + int status; - status = fcntl(fileno(stderr), F_GETFL, 0); - if (status != -1) { - fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK); - } + status = fcntl(fileno(stderr), F_GETFL, 0); + if (status != -1) { + fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK); + } + } } - } #endif #endif - beenHere = TRUE; + beenHere = TRUE; } /* @@ -963,16 +982,16 @@ ddxGiveUp(enum ExitCode error) #ifdef XF86PM if (xf86OSPMClose) - xf86OSPMClose(); + xf86OSPMClose(); xf86OSPMClose = NULL; #endif for (i = 0; i < xf86NumScreens; i++) { - /* - * zero all access functions to - * trap calls when switched away. - */ - xf86Screens[i]->vtSema = FALSE; + /* + * zero all access functions to + * trap calls when switched away. + */ + xf86Screens[i]->vtSema = FALSE; } #ifdef XFreeXDGA @@ -980,17 +999,15 @@ ddxGiveUp(enum ExitCode error) #endif if (xorgHWOpenConsole) - xf86CloseConsole(); + xf86CloseConsole(); xf86CloseLog(error); /* If an unexpected signal was caught, dump a core for debugging */ if (xf86Info.caughtSignal) - OsAbort(); + OsAbort(); } - - /* * AbortDDX -- * DDX - specific abort routine. Called by AbortServer(). The attempt is @@ -1001,38 +1018,38 @@ ddxGiveUp(enum ExitCode error) void AbortDDX(enum ExitCode error) { - int i; + int i; - xf86BlockSIGIO(); + xf86BlockSIGIO(); - /* - * try to restore the original video state - */ -#ifdef DPMSExtension /* Turn screens back on */ - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(serverClient, DPMSModeOn); + /* + * try to restore the original video state + */ +#ifdef DPMSExtension /* Turn screens back on */ + if (DPMSPowerLevel != DPMSModeOn) + DPMSSet(serverClient, DPMSModeOn); #endif - if (xf86Screens) { - for (i = 0; i < xf86NumScreens; i++) - if (xf86Screens[i]->vtSema) { - /* - * if we are aborting before ScreenInit() has finished - * we might not have been wrapped yet. Therefore enable - * screen explicitely. - */ - xf86VGAarbiterLock(xf86Screens[i]); - (xf86Screens[i]->LeaveVT)(i, 0); - xf86VGAarbiterUnlock(xf86Screens[i]); - } - } - - xf86AccessLeave(); - - /* - * This is needed for an abnormal server exit, since the normal exit stuff - * MUST also be performed (i.e. the vt must be left in a defined state) - */ - ddxGiveUp(error); + if (xf86Screens) { + for (i = 0; i < xf86NumScreens; i++) + if (xf86Screens[i]->vtSema) { + /* + * if we are aborting before ScreenInit() has finished + * we might not have been wrapped yet. Therefore enable + * screen explicitely. + */ + xf86VGAarbiterLock(xf86Screens[i]); + (xf86Screens[i]->LeaveVT) (i, 0); + xf86VGAarbiterUnlock(xf86Screens[i]); + } + } + + xf86AccessLeave(); + + /* + * This is needed for an abnormal server exit, since the normal exit stuff + * MUST also be performed (i.e. the vt must be left in a defined state) + */ + ddxGiveUp(error); } void @@ -1040,14 +1057,14 @@ OsVendorFatalError(void) { #ifdef VENDORSUPPORT ErrorF("\nPlease refer to your Operating System Vendor support pages\n" - "at %s for support on this crash.\n",VENDORSUPPORT); + "at %s for support on this crash.\n", VENDORSUPPORT); #else - ErrorF("\nPlease consult the "XVENDORNAME" support \n" - "\t at "__VENDORDWEBSUPPORT__"\n for help. \n"); + ErrorF("\nPlease consult the " XVENDORNAME " support \n" + "\t at " __VENDORDWEBSUPPORT__ "\n for help. \n"); #endif if (xf86LogFile && xf86LogFileWasOpened) - ErrorF("Please also check the log file at \"%s\" for additional " - "information.\n", xf86LogFile); + ErrorF("Please also check the log file at \"%s\" for additional " + "information.\n", xf86LogFile); ErrorF("\n"); } @@ -1074,13 +1091,13 @@ xf86SetLogVerbosity(int verb) static void xf86PrintDefaultModulePath(void) { - ErrorF("%s\n", DEFAULT_MODULE_PATH); + ErrorF("%s\n", DEFAULT_MODULE_PATH); } static void xf86PrintDefaultLibraryPath(void) { - ErrorF("%s\n", DEFAULT_LIBRARY_PATH); + ErrorF("%s\n", DEFAULT_LIBRARY_PATH); } /* @@ -1102,325 +1119,289 @@ ddxProcessArgument(int argc, char **argv, int i) FatalError("Required argument to %s not specified\n", argv[i]); \ } - /* First the options that are not allowed with elevated privileges */ - if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) { - if (xf86PrivsElevated()) { - FatalError("The '%s' option cannot be used with " - "elevated privileges.\n", argv[i]); - } - else if (!strcmp(argv[i], "-modulepath")) - { - char *mp; - CHECK_FOR_REQUIRED_ARGUMENT(); - mp = strdup(argv[i + 1]); - if (!mp) - FatalError("Can't allocate memory for ModulePath\n"); - xf86ModulePath = mp; - xf86ModPathFrom = X_CMDLINE; - return 2; + /* First the options that are not allowed with elevated privileges */ + if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) { + if (xf86PrivsElevated()) { + FatalError("The '%s' option cannot be used with " + "elevated privileges.\n", argv[i]); + } + else if (!strcmp(argv[i], "-modulepath")) { + char *mp; + + CHECK_FOR_REQUIRED_ARGUMENT(); + mp = strdup(argv[i + 1]); + if (!mp) + FatalError("Can't allocate memory for ModulePath\n"); + xf86ModulePath = mp; + xf86ModPathFrom = X_CMDLINE; + return 2; + } + else if (!strcmp(argv[i], "-logfile")) { + char *lf; + + CHECK_FOR_REQUIRED_ARGUMENT(); + lf = strdup(argv[i + 1]); + if (!lf) + FatalError("Can't allocate memory for LogFile\n"); + xf86LogFile = lf; + xf86LogFileFrom = X_CMDLINE; + return 2; + } } - else if (!strcmp(argv[i], "-logfile")) - { - char *lf; - CHECK_FOR_REQUIRED_ARGUMENT(); - lf = strdup(argv[i + 1]); - if (!lf) - FatalError("Can't allocate memory for LogFile\n"); - xf86LogFile = lf; - xf86LogFileFrom = X_CMDLINE; - return 2; + if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { + FatalError("\nInvalid argument for %s\n" + "\tWith elevated privileges, the file specified with %s must be\n" + "\ta relative path and must not contain any \"..\" elements.\n" + "\tUsing default " __XCONFIGFILE__ " search path.\n\n", + argv[i], argv[i]); + } + xf86ConfigFile = argv[i + 1]; + return 2; } - } - if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { - FatalError("\nInvalid argument for %s\n" - "\tWith elevated privileges, the file specified with %s must be\n" - "\ta relative path and must not contain any \"..\" elements.\n" - "\tUsing default "__XCONFIGFILE__" search path.\n\n", - argv[i], argv[i]); + if (!strcmp(argv[i], "-configdir")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { + FatalError("\nInvalid argument for %s\n" + "\tWith elevated privileges, the file specified with %s must be\n" + "\ta relative path and must not contain any \"..\" elements.\n" + "\tUsing default " __XCONFIGDIR__ " search path.\n\n", + argv[i], argv[i]); + } + xf86ConfigDir = argv[i + 1]; + return 2; } - xf86ConfigFile = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-configdir")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { - FatalError("\nInvalid argument for %s\n" - "\tWith elevated privileges, the file specified with %s must be\n" - "\ta relative path and must not contain any \"..\" elements.\n" - "\tUsing default "__XCONFIGDIR__" search path.\n\n", - argv[i], argv[i]); + if (!strcmp(argv[i], "-flipPixels")) { + xf86FlipPixels = TRUE; + return 1; } - xf86ConfigDir = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i],"-flipPixels")) - { - xf86FlipPixels = TRUE; - return 1; - } #ifdef XF86VIDMODE - if (!strcmp(argv[i],"-disableVidMode")) - { - xf86VidModeDisabled = TRUE; - return 1; - } - if (!strcmp(argv[i],"-allowNonLocalXvidtune")) - { - xf86VidModeAllowNonLocal = TRUE; - return 1; - } + if (!strcmp(argv[i], "-disableVidMode")) { + xf86VidModeDisabled = TRUE; + return 1; + } + if (!strcmp(argv[i], "-allowNonLocalXvidtune")) { + xf86VidModeAllowNonLocal = TRUE; + return 1; + } #endif - if (!strcmp(argv[i],"-allowMouseOpenFail")) - { - xf86AllowMouseOpenFail = TRUE; - return 1; - } - if (!strcmp(argv[i],"-ignoreABI")) - { - LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); - return 1; - } - if (!strcmp(argv[i],"-verbose")) - { - if (++i < argc && argv[i]) - { - char *end; - long val; - val = strtol(argv[i], &end, 0); - if (*end == '\0') - { - xf86SetVerbosity(val); - return 2; - } + if (!strcmp(argv[i], "-allowMouseOpenFail")) { + xf86AllowMouseOpenFail = TRUE; + return 1; } - xf86SetVerbosity(++xf86Verbose); - return 1; - } - if (!strcmp(argv[i],"-logverbose")) - { - if (++i < argc && argv[i]) - { - char *end; - long val; - val = strtol(argv[i], &end, 0); - if (*end == '\0') - { - xf86SetLogVerbosity(val); - return 2; - } + if (!strcmp(argv[i], "-ignoreABI")) { + LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); + return 1; } - xf86SetLogVerbosity(++xf86LogVerbose); - return 1; - } - if (!strcmp(argv[i],"-quiet")) - { - xf86SetVerbosity(-1); - return 1; - } - if (!strcmp(argv[i],"-showconfig") || !strcmp(argv[i],"-version")) - { - xf86PrintBanner(); - exit(0); - } - if (!strcmp(argv[i],"-showDefaultModulePath")) - { - xf86PrintDefaultModulePath(); - exit(0); - } - if (!strcmp(argv[i],"-showDefaultLibPath")) - { - xf86PrintDefaultLibraryPath(); - exit(0); - } - /* Notice the -fp flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-fp")) - { - xf86fpFlag = TRUE; - return 0; - } - /* Notice the -bs flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-bs")) - { - xf86bsDisableFlag = TRUE; - return 0; - } - /* Notice the +bs flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "+bs")) - { - xf86bsEnableFlag = TRUE; - return 0; - } - /* Notice the -s flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-s")) - { - xf86sFlag = TRUE; - return 0; - } - if (!strcmp(argv[i], "-pixmap24")) - { - xf86Pix24 = Pix24Use24; - return 1; - } - if (!strcmp(argv[i], "-pixmap32")) - { - xf86Pix24 = Pix24Use32; - return 1; - } - if (!strcmp(argv[i], "-fbbpp")) - { - int bpp; - CHECK_FOR_REQUIRED_ARGUMENT(); - if (sscanf(argv[++i], "%d", &bpp) == 1) - { - xf86FbBpp = bpp; - return 2; + if (!strcmp(argv[i], "-verbose")) { + if (++i < argc && argv[i]) { + char *end; + long val; + + val = strtol(argv[i], &end, 0); + if (*end == '\0') { + xf86SetVerbosity(val); + return 2; + } + } + xf86SetVerbosity(++xf86Verbose); + return 1; } - else - { - ErrorF("Invalid fbbpp\n"); - return 0; + if (!strcmp(argv[i], "-logverbose")) { + if (++i < argc && argv[i]) { + char *end; + long val; + + val = strtol(argv[i], &end, 0); + if (*end == '\0') { + xf86SetLogVerbosity(val); + return 2; + } + } + xf86SetLogVerbosity(++xf86LogVerbose); + return 1; } - } - if (!strcmp(argv[i], "-depth")) - { - int depth; - CHECK_FOR_REQUIRED_ARGUMENT(); - if (sscanf(argv[++i], "%d", &depth) == 1) - { - xf86Depth = depth; - return 2; + if (!strcmp(argv[i], "-quiet")) { + xf86SetVerbosity(-1); + return 1; } - else - { - ErrorF("Invalid depth\n"); - return 0; + if (!strcmp(argv[i], "-showconfig") || !strcmp(argv[i], "-version")) { + xf86PrintBanner(); + exit(0); } - } - if (!strcmp(argv[i], "-weight")) - { - int red, green, blue; - CHECK_FOR_REQUIRED_ARGUMENT(); - if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3) - { - xf86Weight.red = red; - xf86Weight.green = green; - xf86Weight.blue = blue; - return 2; + if (!strcmp(argv[i], "-showDefaultModulePath")) { + xf86PrintDefaultModulePath(); + exit(0); } - else - { - ErrorF("Invalid weighting\n"); - return 0; + if (!strcmp(argv[i], "-showDefaultLibPath")) { + xf86PrintDefaultLibraryPath(); + exit(0); + } + /* Notice the -fp flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "-fp")) { + xf86fpFlag = TRUE; + return 0; + } + /* Notice the -bs flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "-bs")) { + xf86bsDisableFlag = TRUE; + return 0; + } + /* Notice the +bs flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "+bs")) { + xf86bsEnableFlag = TRUE; + return 0; } - } - if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") || - !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma")) - { - double gamma; - CHECK_FOR_REQUIRED_ARGUMENT(); - if (sscanf(argv[++i], "%lf", &gamma) == 1) { - if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) { - ErrorF("gamma out of range, only %.2f <= gamma_value <= %.1f" - " is valid\n", GAMMA_MIN, GAMMA_MAX); - return 0; - } - if (!strcmp(argv[i-1], "-gamma")) - xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma; - else if (!strcmp(argv[i-1], "-rgamma")) xf86Gamma.red = gamma; - else if (!strcmp(argv[i-1], "-ggamma")) xf86Gamma.green = gamma; - else if (!strcmp(argv[i-1], "-bgamma")) xf86Gamma.blue = gamma; - return 2; + /* Notice the -s flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "-s")) { + xf86sFlag = TRUE; + return 0; + } + if (!strcmp(argv[i], "-pixmap24")) { + xf86Pix24 = Pix24Use24; + return 1; + } + if (!strcmp(argv[i], "-pixmap32")) { + xf86Pix24 = Pix24Use32; + return 1; + } + if (!strcmp(argv[i], "-fbbpp")) { + int bpp; + + CHECK_FOR_REQUIRED_ARGUMENT(); + if (sscanf(argv[++i], "%d", &bpp) == 1) { + xf86FbBpp = bpp; + return 2; + } + else { + ErrorF("Invalid fbbpp\n"); + return 0; + } + } + if (!strcmp(argv[i], "-depth")) { + int depth; + + CHECK_FOR_REQUIRED_ARGUMENT(); + if (sscanf(argv[++i], "%d", &depth) == 1) { + xf86Depth = depth; + return 2; + } + else { + ErrorF("Invalid depth\n"); + return 0; + } + } + if (!strcmp(argv[i], "-weight")) { + int red, green, blue; + + CHECK_FOR_REQUIRED_ARGUMENT(); + if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3) { + xf86Weight.red = red; + xf86Weight.green = green; + xf86Weight.blue = blue; + return 2; + } + else { + ErrorF("Invalid weighting\n"); + return 0; + } + } + if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") || + !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma")) { + double gamma; + + CHECK_FOR_REQUIRED_ARGUMENT(); + if (sscanf(argv[++i], "%lf", &gamma) == 1) { + if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) { + ErrorF("gamma out of range, only %.2f <= gamma_value <= %.1f" + " is valid\n", GAMMA_MIN, GAMMA_MAX); + return 0; + } + if (!strcmp(argv[i - 1], "-gamma")) + xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma; + else if (!strcmp(argv[i - 1], "-rgamma")) + xf86Gamma.red = gamma; + else if (!strcmp(argv[i - 1], "-ggamma")) + xf86Gamma.green = gamma; + else if (!strcmp(argv[i - 1], "-bgamma")) + xf86Gamma.blue = gamma; + return 2; + } + } + if (!strcmp(argv[i], "-layout")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + xf86LayoutName = argv[++i]; + return 2; + } + if (!strcmp(argv[i], "-screen")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + xf86ScreenName = argv[++i]; + return 2; + } + if (!strcmp(argv[i], "-pointer")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + xf86PointerName = argv[++i]; + return 2; + } + if (!strcmp(argv[i], "-keyboard")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + xf86KeyboardName = argv[++i]; + return 2; + } + if (!strcmp(argv[i], "-nosilk")) { + xf86silkenMouseDisableFlag = TRUE; + return 1; } - } - if (!strcmp(argv[i], "-layout")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - xf86LayoutName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-screen")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - xf86ScreenName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-pointer")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - xf86PointerName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-keyboard")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - xf86KeyboardName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-nosilk")) - { - xf86silkenMouseDisableFlag = TRUE; - return 1; - } #ifdef HAVE_ACPI - if (!strcmp(argv[i], "-noacpi")) - { - xf86acpiDisableFlag = TRUE; - return 1; - } + if (!strcmp(argv[i], "-noacpi")) { + xf86acpiDisableFlag = TRUE; + return 1; + } #endif - if (!strcmp(argv[i], "-configure")) - { - if (getuid() != 0 && geteuid() == 0) { - ErrorF("The '-configure' option can only be used by root.\n"); - exit(1); + if (!strcmp(argv[i], "-configure")) { + if (getuid() != 0 && geteuid() == 0) { + ErrorF("The '-configure' option can only be used by root.\n"); + exit(1); + } + xf86DoConfigure = TRUE; + xf86AllowMouseOpenFail = TRUE; + return 1; } - xf86DoConfigure = TRUE; - xf86AllowMouseOpenFail = TRUE; - return 1; - } - if (!strcmp(argv[i], "-showopts")) - { - if (getuid() != 0 && geteuid() == 0) { - ErrorF("The '-showopts' option can only be used by root.\n"); - exit(1); + if (!strcmp(argv[i], "-showopts")) { + if (getuid() != 0 && geteuid() == 0) { + ErrorF("The '-showopts' option can only be used by root.\n"); + exit(1); + } + xf86DoShowOptions = TRUE; + return 1; } - xf86DoShowOptions = TRUE; - return 1; - } #ifdef XSERVER_LIBPCIACCESS - if (!strcmp(argv[i], "-isolateDevice")) - { - CHECK_FOR_REQUIRED_ARGUMENT(); - if (strncmp(argv[++i], "PCI:", 4)) { - FatalError("Bus types other than PCI not yet isolable\n"); + if (!strcmp(argv[i], "-isolateDevice")) { + CHECK_FOR_REQUIRED_ARGUMENT(); + if (strncmp(argv[++i], "PCI:", 4)) { + FatalError("Bus types other than PCI not yet isolable\n"); + } + xf86PciIsolateDevice(argv[i]); + return 2; } - xf86PciIsolateDevice(argv[i]); - return 2; - } #endif - /* Notice cmdline xkbdir, but pass to dix as well */ - if (!strcmp(argv[i], "-xkbdir")) - { - xf86xkbdirFlag = TRUE; - return 0; - } - if (!strcmp(argv[i], "-novtswitch")) - { - xf86Info.autoVTSwitch = FALSE; - return 1; - } - if (!strcmp(argv[i], "-sharevts")) - { - xf86Info.ShareVTs = TRUE; - return 1; - } - - /* OS-specific processing */ - return xf86ProcessArgument(argc, argv, i); + /* Notice cmdline xkbdir, but pass to dix as well */ + if (!strcmp(argv[i], "-xkbdir")) { + xf86xkbdirFlag = TRUE; + return 0; + } + if (!strcmp(argv[i], "-novtswitch")) { + xf86Info.autoVTSwitch = FALSE; + return 1; + } + if (!strcmp(argv[i], "-sharevts")) { + xf86Info.ShareVTs = TRUE; + return 1; + } + + /* OS-specific processing */ + return xf86ProcessArgument(argc, argv, i); } /* @@ -1432,58 +1413,70 @@ ddxProcessArgument(int argc, char **argv, int i) void ddxUseMsg(void) { - ErrorF("\n"); - ErrorF("\n"); - ErrorF("Device Dependent Usage\n"); - if (!xf86PrivsElevated()) - { - ErrorF("-modulepath paths specify the module search path\n"); - ErrorF("-logfile file specify a log file name\n"); - ErrorF("-configure probe for devices and write an "__XCONFIGFILE__"\n"); - ErrorF("-showopts print available options for all installed drivers\n"); - } - ErrorF("-config file specify a configuration file, relative to the\n"); - ErrorF(" "__XCONFIGFILE__" search path, only root can use absolute\n"); - ErrorF("-configdir dir specify a configuration directory, relative to the\n"); - ErrorF(" "__XCONFIGDIR__" search path, only root can use absolute\n"); - ErrorF("-verbose [n] verbose startup messages\n"); - ErrorF("-logverbose [n] verbose log messages\n"); - ErrorF("-quiet minimal startup messages\n"); - ErrorF("-pixmap24 use 24bpp pixmaps for depth 24\n"); - ErrorF("-pixmap32 use 32bpp pixmaps for depth 24\n"); - ErrorF("-fbbpp n set bpp for the framebuffer. Default: 8\n"); - ErrorF("-depth n set colour depth. Default: 8\n"); - ErrorF("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n"); - ErrorF("-rgamma f set gamma value for red phase\n"); - ErrorF("-ggamma f set gamma value for green phase\n"); - ErrorF("-bgamma f set gamma value for blue phase\n"); - ErrorF("-weight nnn set RGB weighting at 16 bpp. Default: 565\n"); - ErrorF("-layout name specify the ServerLayout section name\n"); - ErrorF("-screen name specify the Screen section name\n"); - ErrorF("-keyboard name specify the core keyboard InputDevice name\n"); - ErrorF("-pointer name specify the core pointer InputDevice name\n"); - ErrorF("-nosilk disable Silken Mouse\n"); - ErrorF("-flipPixels swap default black/white Pixel values\n"); + ErrorF("\n"); + ErrorF("\n"); + ErrorF("Device Dependent Usage\n"); + if (!xf86PrivsElevated()) { + ErrorF("-modulepath paths specify the module search path\n"); + ErrorF("-logfile file specify a log file name\n"); + ErrorF("-configure probe for devices and write an " + __XCONFIGFILE__ "\n"); + ErrorF + ("-showopts print available options for all installed drivers\n"); + } + ErrorF + ("-config file specify a configuration file, relative to the\n"); + ErrorF(" " __XCONFIGFILE__ + " search path, only root can use absolute\n"); + ErrorF + ("-configdir dir specify a configuration directory, relative to the\n"); + ErrorF(" " __XCONFIGDIR__ + " search path, only root can use absolute\n"); + ErrorF("-verbose [n] verbose startup messages\n"); + ErrorF("-logverbose [n] verbose log messages\n"); + ErrorF("-quiet minimal startup messages\n"); + ErrorF("-pixmap24 use 24bpp pixmaps for depth 24\n"); + ErrorF("-pixmap32 use 32bpp pixmaps for depth 24\n"); + ErrorF("-fbbpp n set bpp for the framebuffer. Default: 8\n"); + ErrorF("-depth n set colour depth. Default: 8\n"); + ErrorF + ("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n"); + ErrorF("-rgamma f set gamma value for red phase\n"); + ErrorF("-ggamma f set gamma value for green phase\n"); + ErrorF("-bgamma f set gamma value for blue phase\n"); + ErrorF + ("-weight nnn set RGB weighting at 16 bpp. Default: 565\n"); + ErrorF("-layout name specify the ServerLayout section name\n"); + ErrorF("-screen name specify the Screen section name\n"); + ErrorF + ("-keyboard name specify the core keyboard InputDevice name\n"); + ErrorF + ("-pointer name specify the core pointer InputDevice name\n"); + ErrorF("-nosilk disable Silken Mouse\n"); + ErrorF("-flipPixels swap default black/white Pixel values\n"); #ifdef XF86VIDMODE - ErrorF("-disableVidMode disable mode adjustments with xvidtune\n"); - ErrorF("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n"); + ErrorF("-disableVidMode disable mode adjustments with xvidtune\n"); + ErrorF + ("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n"); #endif - ErrorF("-allowMouseOpenFail start server even if the mouse can't be initialized\n"); - ErrorF("-ignoreABI make module ABI mismatches non-fatal\n"); + ErrorF + ("-allowMouseOpenFail start server even if the mouse can't be initialized\n"); + ErrorF("-ignoreABI make module ABI mismatches non-fatal\n"); #ifdef XSERVER_LIBPCIACCESS - ErrorF("-isolateDevice bus_id restrict device resets to bus_id (PCI only)\n"); + ErrorF + ("-isolateDevice bus_id restrict device resets to bus_id (PCI only)\n"); #endif - ErrorF("-version show the server version\n"); - ErrorF("-showDefaultModulePath show the server default module path\n"); - ErrorF("-showDefaultLibPath show the server default library path\n"); - ErrorF("-novtswitch don't automatically switch VT at reset & exit\n"); - ErrorF("-sharevts share VTs with another X server\n"); - /* OS-specific usage */ - xf86UseMsg(); - ErrorF("\n"); + ErrorF("-version show the server version\n"); + ErrorF("-showDefaultModulePath show the server default module path\n"); + ErrorF("-showDefaultLibPath show the server default library path\n"); + ErrorF + ("-novtswitch don't automatically switch VT at reset & exit\n"); + ErrorF("-sharevts share VTs with another X server\n"); + /* OS-specific usage */ + xf86UseMsg(); + ErrorF("\n"); } - /* * xf86LoadModules iterates over a list that is being passed in. */ @@ -1497,34 +1490,34 @@ xf86LoadModules(char **list, pointer *optlist) Bool failed = FALSE; if (!list) - return TRUE; + return TRUE; for (i = 0; list[i] != NULL; i++) { - /* Normalise the module name */ - name = xf86NormalizeName(list[i]); + /* Normalise the module name */ + name = xf86NormalizeName(list[i]); - /* Skip empty names */ - if (name == NULL || *name == '\0') { - free(name); - continue; - } + /* Skip empty names */ + if (name == NULL || *name == '\0') { + free(name); + continue; + } - /* Replace obsolete keyboard driver with kbd */ - if (!xf86NameCmp(name, "keyboard")) { - strcpy(name, "kbd"); - } + /* Replace obsolete keyboard driver with kbd */ + if (!xf86NameCmp(name, "keyboard")) { + strcpy(name, "kbd"); + } - if (optlist) - opt = optlist[i]; - else - opt = NULL; + if (optlist) + opt = optlist[i]; + else + opt = NULL; if (!LoadModule(name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin)) { - LoaderErrorMsg(NULL, name, errmaj, errmin); - failed = TRUE; - } - free(name); + LoaderErrorMsg(NULL, name, errmaj, errmin); + failed = TRUE; + } + free(name); } return !failed; } @@ -1535,7 +1528,7 @@ PixmapFormatPtr xf86GetPixFormat(ScrnInfoPtr pScrn, int depth) { int i; - static PixmapFormatRec format; /* XXX not reentrant */ + static PixmapFormatRec format; /* XXX not reentrant */ /* * When the formats[] list initialisation isn't complete, check the @@ -1543,35 +1536,35 @@ xf86GetPixFormat(ScrnInfoPtr pScrn, int depth) */ if (!formatsDone) { - if (depth == 24) { - Pix24Flags pix24 = Pix24DontCare; - - format.depth = 24; - format.scanlinePad = BITMAP_SCANLINE_PAD; - if (xf86Info.pixmap24 != Pix24DontCare) - pix24 = xf86Info.pixmap24; - else if (pScrn->pixmap24 != Pix24DontCare) - pix24 = pScrn->pixmap24; - if (pix24 == Pix24Use24) - format.bitsPerPixel = 24; - else - format.bitsPerPixel = 32; - return &format; - } + if (depth == 24) { + Pix24Flags pix24 = Pix24DontCare; + + format.depth = 24; + format.scanlinePad = BITMAP_SCANLINE_PAD; + if (xf86Info.pixmap24 != Pix24DontCare) + pix24 = xf86Info.pixmap24; + else if (pScrn->pixmap24 != Pix24DontCare) + pix24 = pScrn->pixmap24; + if (pix24 == Pix24Use24) + format.bitsPerPixel = 24; + else + format.bitsPerPixel = 32; + return &format; + } } for (i = 0; i < numFormats; i++) - if (formats[i].depth == depth) - break; + if (formats[i].depth == depth) + break; if (i != numFormats) - return &formats[i]; + return &formats[i]; else if (!formatsDone) { - /* Check for screen-specified formats */ - for (i = 0; i < pScrn->numFormats; i++) - if (pScrn->formats[i].depth == depth) - break; - if (i != pScrn->numFormats) - return &pScrn->formats[i]; + /* Check for screen-specified formats */ + for (i = 0; i < pScrn->numFormats; i++) + if (pScrn->formats[i].depth == depth) + break; + if (i != pScrn->numFormats) + return &pScrn->formats[i]; } return NULL; } @@ -1581,10 +1574,9 @@ xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth) { PixmapFormatPtr format; - format = xf86GetPixFormat(pScrn, depth); if (format) - return format->bitsPerPixel; + return format->bitsPerPixel; else - return 0; + return 0; } diff --git a/xorg-server/hw/xfree86/common/xf86Mode.c b/xorg-server/hw/xfree86/common/xf86Mode.c index d202d4079..ab4d595c7 100644 --- a/xorg-server/hw/xfree86/common/xf86Mode.c +++ b/xorg-server/hw/xfree86/common/xf86Mode.c @@ -99,16 +99,16 @@ printModeRejectMessage(int index, DisplayModePtr p, int status) const char *type; if (p->type & M_T_BUILTIN) - type = "built-in "; + type = "built-in "; else if (p->type & M_T_DEFAULT) - type = "default "; + type = "default "; else if (p->type & M_T_DRIVER) - type = "driver "; + type = "driver "; else - type = ""; + type = ""; xf86DrvMsg(index, X_INFO, "Not using %smode \"%s\" (%s)\n", type, p->name, - xf86ModeStatusToString(status)); + xf86ModeStatusToString(status)); } /* @@ -118,33 +118,32 @@ printModeRejectMessage(int index, DisplayModePtr p, int status) */ int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, - int DivFactor, int MulFactor, int *divider) + int DivFactor, int MulFactor, int *divider) { int nearestClock = 0, nearestDiv = 1; int minimumGap = abs(freq - scrp->clock[0]); int i, j, k, gap; if (allowDiv2) - k = 2; + k = 2; else - k = 1; + k = 1; /* Must set this here in case the best match is scrp->clock[0] */ if (divider != NULL) - *divider = 0; - - for (i = 0; i < scrp->numClocks; i++) { - for (j = 1; j <= k; j++) { - gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor)); - if ((gap < minimumGap) || - ((gap == minimumGap) && (j < nearestDiv))) { - minimumGap = gap; - nearestClock = i; - nearestDiv = j; - if (divider != NULL) - *divider = (j - 1) * V_CLKDIV2; - } - } + *divider = 0; + + for (i = 0; i < scrp->numClocks; i++) { + for (j = 1; j <= k; j++) { + gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor)); + if ((gap < minimumGap) || ((gap == minimumGap) && (j < nearestDiv))) { + minimumGap = gap; + nearestClock = i; + nearestDiv = j; + if (divider != NULL) + *divider = (j - 1) * V_CLKDIV2; + } + } } return nearestClock; } @@ -160,67 +159,67 @@ xf86ModeStatusToString(ModeStatus status) { switch (status) { case MODE_OK: - return "Mode OK"; + return "Mode OK"; case MODE_HSYNC: - return "hsync out of range"; + return "hsync out of range"; case MODE_VSYNC: - return "vrefresh out of range"; + return "vrefresh out of range"; case MODE_H_ILLEGAL: - return "illegal horizontal timings"; + return "illegal horizontal timings"; case MODE_V_ILLEGAL: - return "illegal vertical timings"; + return "illegal vertical timings"; case MODE_BAD_WIDTH: - return "width requires unsupported line pitch"; + return "width requires unsupported line pitch"; case MODE_NOMODE: - return "no mode of this name"; + return "no mode of this name"; case MODE_NO_INTERLACE: - return "interlace mode not supported"; + return "interlace mode not supported"; case MODE_NO_DBLESCAN: - return "doublescan mode not supported"; + return "doublescan mode not supported"; case MODE_NO_VSCAN: - return "multiscan mode not supported"; + return "multiscan mode not supported"; case MODE_MEM: - return "insufficient memory for mode"; + return "insufficient memory for mode"; case MODE_VIRTUAL_X: - return "width too large for virtual size"; + return "width too large for virtual size"; case MODE_VIRTUAL_Y: - return "height too large for virtual size"; + return "height too large for virtual size"; case MODE_MEM_VIRT: - return "insufficient memory given virtual size"; + return "insufficient memory given virtual size"; case MODE_NOCLOCK: - return "no clock available for mode"; + return "no clock available for mode"; case MODE_CLOCK_HIGH: - return "mode clock too high"; + return "mode clock too high"; case MODE_CLOCK_LOW: - return "mode clock too low"; + return "mode clock too low"; case MODE_CLOCK_RANGE: - return "bad mode clock/interlace/doublescan"; + return "bad mode clock/interlace/doublescan"; case MODE_BAD_HVALUE: - return "horizontal timing out of range"; + return "horizontal timing out of range"; case MODE_BAD_VVALUE: - return "vertical timing out of range"; + return "vertical timing out of range"; case MODE_BAD_VSCAN: - return "VScan value out of range"; + return "VScan value out of range"; case MODE_HSYNC_NARROW: - return "horizontal sync too narrow"; + return "horizontal sync too narrow"; case MODE_HSYNC_WIDE: - return "horizontal sync too wide"; + return "horizontal sync too wide"; case MODE_HBLANK_NARROW: - return "horizontal blanking too narrow"; + return "horizontal blanking too narrow"; case MODE_HBLANK_WIDE: - return "horizontal blanking too wide"; + return "horizontal blanking too wide"; case MODE_VSYNC_NARROW: - return "vertical sync too narrow"; + return "vertical sync too narrow"; case MODE_VSYNC_WIDE: - return "vertical sync too wide"; + return "vertical sync too wide"; case MODE_VBLANK_NARROW: - return "vertical blanking too narrow"; + return "vertical blanking too narrow"; case MODE_VBLANK_WIDE: - return "vertical blanking too wide"; + return "vertical blanking too wide"; case MODE_PANEL: - return "exceeds panel dimensions"; + return "exceeds panel dimensions"; case MODE_INTERLACE_WIDTH: - return "width too large for interlaced mode"; + return "width too large for interlaced mode"; case MODE_ONE_WIDTH: return "all modes must have the same width"; case MODE_ONE_HEIGHT: @@ -230,13 +229,13 @@ xf86ModeStatusToString(ModeStatus status) case MODE_NO_REDUCED: return "monitor doesn't support reduced blanking"; case MODE_BANDWIDTH: - return "mode requires too much memory bandwidth"; + return "mode requires too much memory bandwidth"; case MODE_BAD: - return "unknown reason"; + return "unknown reason"; case MODE_ERROR: - return "internal error"; + return "internal error"; default: - return "unknown"; + return "unknown"; } } @@ -254,43 +253,46 @@ xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges) int scaledClock; for (cp = clockRanges; cp != NULL; cp = cp->next) { - DivFactor = max(1, cp->ClockDivFactor); - MulFactor = max(1, cp->ClockMulFactor); - if (scrp->progClock) { - if (cp->minClock) { - if (cp->maxClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Clock range: %6.2f to %6.2f MHz\n", - (double)cp->minClock / 1000.0, - (double)cp->maxClock / 1000.0); - } else { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Minimum clock: %6.2f MHz\n", - (double)cp->minClock / 1000.0); - } - } else { - if (cp->maxClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Maximum clock: %6.2f MHz\n", - (double)cp->maxClock / 1000.0); - } - } - } else if (DivFactor > 1 || MulFactor > 1) { - j = 0; - for (i = 0; i < scrp->numClocks; i++) { - scaledClock = (scrp->clock[i] * DivFactor) / MulFactor; - if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) { - if ((j % 8) == 0) { - if (j > 0) - xf86ErrorF("\n"); - xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:"); - } - xf86ErrorF(" %6.2f", (double)scaledClock / 1000.0); - j++; - } - } - xf86ErrorF("\n"); - } + DivFactor = max(1, cp->ClockDivFactor); + MulFactor = max(1, cp->ClockMulFactor); + if (scrp->progClock) { + if (cp->minClock) { + if (cp->maxClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Clock range: %6.2f to %6.2f MHz\n", + (double) cp->minClock / 1000.0, + (double) cp->maxClock / 1000.0); + } + else { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Minimum clock: %6.2f MHz\n", + (double) cp->minClock / 1000.0); + } + } + else { + if (cp->maxClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Maximum clock: %6.2f MHz\n", + (double) cp->maxClock / 1000.0); + } + } + } + else if (DivFactor > 1 || MulFactor > 1) { + j = 0; + for (i = 0; i < scrp->numClocks; i++) { + scaledClock = (scrp->clock[i] * DivFactor) / MulFactor; + if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) { + if ((j % 8) == 0) { + if (j > 0) + xf86ErrorF("\n"); + xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:"); + } + xf86ErrorF(" %6.2f", (double) scaledClock / 1000.0); + j++; + } + } + xf86ErrorF("\n"); + } } } @@ -298,10 +300,10 @@ static Bool modeInClockRange(ClockRangePtr cp, DisplayModePtr p) { return ((p->Clock >= cp->minClock) && - (p->Clock <= cp->maxClock) && - (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) && - (cp->doubleScanAllowed || - ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN)))); + (p->Clock <= cp->maxClock) && + (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) && + (cp->doubleScanAllowed || + ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN)))); } /* @@ -312,111 +314,112 @@ xf86FindClockRangeForMode(ClockRangePtr clockRanges, DisplayModePtr p) { ClockRangePtr cp; - for (cp = clockRanges; ; cp = cp->next) - if (!cp || modeInClockRange(cp, p)) - return cp; + for (cp = clockRanges;; cp = cp->next) + if (!cp || modeInClockRange(cp, p)) + return cp; } - /* * xf86HandleBuiltinMode() - handles built-in modes */ static ModeStatus xf86HandleBuiltinMode(ScrnInfoPtr scrp, - DisplayModePtr p, - DisplayModePtr modep, - ClockRangePtr clockRanges, - Bool allowDiv2) + DisplayModePtr p, + DisplayModePtr modep, + ClockRangePtr clockRanges, Bool allowDiv2) { ClockRangePtr cp; int extraFlags = 0; int MulFactor = 1; int DivFactor = 1; int clockIndex; - + /* Reject previously rejected modes */ if (p->status != MODE_OK) - return p->status; + return p->status; /* Reject previously considered modes */ if (p->prev) return MODE_NOMODE; if ((p->type & M_T_CLOCK_C) == M_T_CLOCK_C) { - /* Check clock is in range */ - cp = xf86FindClockRangeForMode(clockRanges, p); - if (cp == NULL){ - modep->type = p->type; - p->status = MODE_CLOCK_RANGE; - return MODE_CLOCK_RANGE; - } - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - if (!scrp->progClock) { - clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2, - cp->ClockDivFactor, - cp->ClockMulFactor, &extraFlags); - modep->Clock = (scrp->clock[clockIndex] * DivFactor) - / MulFactor; - modep->ClockIndex = clockIndex; - modep->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - modep->Clock /= 2; - modep->SynthClock /= 2; - } - } else { - modep->Clock = p->Clock; - modep->ClockIndex = -1; - modep->SynthClock = (modep->Clock * MulFactor) - / DivFactor; - } - modep->PrivFlags = cp->PrivFlags; - } else { - if(!scrp->progClock) { + /* Check clock is in range */ + cp = xf86FindClockRangeForMode(clockRanges, p); + if (cp == NULL) { + modep->type = p->type; + p->status = MODE_CLOCK_RANGE; + return MODE_CLOCK_RANGE; + } + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + if (!scrp->progClock) { + clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2, + cp->ClockDivFactor, + cp->ClockMulFactor, &extraFlags); + modep->Clock = (scrp->clock[clockIndex] * DivFactor) + / MulFactor; + modep->ClockIndex = clockIndex; + modep->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + modep->Clock /= 2; + modep->SynthClock /= 2; + } + } + else { modep->Clock = p->Clock; - modep->ClockIndex = p->ClockIndex; - modep->SynthClock = p->SynthClock; - } else { - modep->Clock = p->Clock; - modep->ClockIndex = -1; - modep->SynthClock = p->SynthClock; - } - modep->PrivFlags = p->PrivFlags; + modep->ClockIndex = -1; + modep->SynthClock = (modep->Clock * MulFactor) + / DivFactor; + } + modep->PrivFlags = cp->PrivFlags; } - modep->type = p->type; - modep->HDisplay = p->HDisplay; - modep->HSyncStart = p->HSyncStart; - modep->HSyncEnd = p->HSyncEnd; - modep->HTotal = p->HTotal; - modep->HSkew = p->HSkew; - modep->VDisplay = p->VDisplay; - modep->VSyncStart = p->VSyncStart; - modep->VSyncEnd = p->VSyncEnd; - modep->VTotal = p->VTotal; - modep->VScan = p->VScan; - modep->Flags = p->Flags | extraFlags; - modep->CrtcHDisplay = p->CrtcHDisplay; + else { + if (!scrp->progClock) { + modep->Clock = p->Clock; + modep->ClockIndex = p->ClockIndex; + modep->SynthClock = p->SynthClock; + } + else { + modep->Clock = p->Clock; + modep->ClockIndex = -1; + modep->SynthClock = p->SynthClock; + } + modep->PrivFlags = p->PrivFlags; + } + modep->type = p->type; + modep->HDisplay = p->HDisplay; + modep->HSyncStart = p->HSyncStart; + modep->HSyncEnd = p->HSyncEnd; + modep->HTotal = p->HTotal; + modep->HSkew = p->HSkew; + modep->VDisplay = p->VDisplay; + modep->VSyncStart = p->VSyncStart; + modep->VSyncEnd = p->VSyncEnd; + modep->VTotal = p->VTotal; + modep->VScan = p->VScan; + modep->Flags = p->Flags | extraFlags; + modep->CrtcHDisplay = p->CrtcHDisplay; modep->CrtcHBlankStart = p->CrtcHBlankStart; - modep->CrtcHSyncStart = p->CrtcHSyncStart; - modep->CrtcHSyncEnd = p->CrtcHSyncEnd; - modep->CrtcHBlankEnd = p->CrtcHBlankEnd; - modep->CrtcHTotal = p->CrtcHTotal; - modep->CrtcHSkew = p->CrtcHSkew; - modep->CrtcVDisplay = p->CrtcVDisplay; + modep->CrtcHSyncStart = p->CrtcHSyncStart; + modep->CrtcHSyncEnd = p->CrtcHSyncEnd; + modep->CrtcHBlankEnd = p->CrtcHBlankEnd; + modep->CrtcHTotal = p->CrtcHTotal; + modep->CrtcHSkew = p->CrtcHSkew; + modep->CrtcVDisplay = p->CrtcVDisplay; modep->CrtcVBlankStart = p->CrtcVBlankStart; - modep->CrtcVSyncStart = p->CrtcVSyncStart; - modep->CrtcVSyncEnd = p->CrtcVSyncEnd; - modep->CrtcVBlankEnd = p->CrtcVBlankEnd; - modep->CrtcVTotal = p->CrtcVTotal; - modep->CrtcHAdjusted = p->CrtcHAdjusted; - modep->CrtcVAdjusted = p->CrtcVAdjusted; - modep->HSync = p->HSync; - modep->VRefresh = p->VRefresh; - modep->Private = p->Private; - modep->PrivSize = p->PrivSize; + modep->CrtcVSyncStart = p->CrtcVSyncStart; + modep->CrtcVSyncEnd = p->CrtcVSyncEnd; + modep->CrtcVBlankEnd = p->CrtcVBlankEnd; + modep->CrtcVTotal = p->CrtcVTotal; + modep->CrtcHAdjusted = p->CrtcHAdjusted; + modep->CrtcVAdjusted = p->CrtcVAdjusted; + modep->HSync = p->HSync; + modep->VRefresh = p->VRefresh; + modep->Private = p->Private; + modep->PrivSize = p->PrivSize; p->prev = modep; - + return MODE_OK; } @@ -450,7 +453,7 @@ xf86HandleBuiltinMode(ScrnInfoPtr scrp, ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, - ClockRangePtr clockRanges, LookupModeFlags strategy) + ClockRangePtr clockRanges, LookupModeFlags strategy) { DisplayModePtr p, bestMode = NULL; ClockRangePtr cp; @@ -465,14 +468,15 @@ xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, ModeStatus status = MODE_NOMODE; Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; int n; + const int types[] = { - M_T_BUILTIN | M_T_PREFERRED, - M_T_BUILTIN, - M_T_USERDEF | M_T_PREFERRED, - M_T_USERDEF, - M_T_DRIVER | M_T_PREFERRED, - M_T_DRIVER, - 0 + M_T_BUILTIN | M_T_PREFERRED, + M_T_BUILTIN, + M_T_USERDEF | M_T_PREFERRED, + M_T_USERDEF, + M_T_DRIVER | M_T_PREFERRED, + M_T_DRIVER, + 0 }; const int ntypes = sizeof(types) / sizeof(int); @@ -480,206 +484,209 @@ xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, /* Some sanity checking */ if (scrp == NULL || scrp->modePool == NULL || - (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n"); - return MODE_ERROR; + (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n"); + return MODE_ERROR; } if (modep == NULL || modep->name == NULL) { - ErrorF("xf86LookupMode: called with invalid modep\n"); - return MODE_ERROR; + ErrorF("xf86LookupMode: called with invalid modep\n"); + return MODE_ERROR; } for (cp = clockRanges; cp != NULL; cp = cp->next) { - /* DivFactor and MulFactor must be > 0 */ - cp->ClockDivFactor = max(1, cp->ClockDivFactor); - cp->ClockMulFactor = max(1, cp->ClockMulFactor); + /* DivFactor and MulFactor must be > 0 */ + cp->ClockDivFactor = max(1, cp->ClockDivFactor); + cp->ClockMulFactor = max(1, cp->ClockMulFactor); } /* Scan the mode pool for matching names */ for (n = 0; n < ntypes; n++) { - int type = types[n]; - for (p = scrp->modePool; p != NULL; p = p->next) { - - /* scan through the modes in the sort order above */ - if ((p->type & type) != type) - continue; - - if (strcmp(p->name, modep->name) == 0) { - - /* Skip over previously rejected modes */ - if (p->status != MODE_OK) { - if (!found) - status = p->status; - continue; - } - - /* Skip over previously considered modes */ - if (p->prev) - continue; - - if (p->type & M_T_BUILTIN) { - return xf86HandleBuiltinMode(scrp, p,modep, clockRanges, - allowDiv2); - } - - /* Check clock is in range */ - cp = xf86FindClockRangeForMode(clockRanges, p); - if (cp == NULL) { - /* - * XXX Could do more here to provide a more detailed - * reason for not finding a mode. - */ - p->status = MODE_CLOCK_RANGE; - if (!found) - status = MODE_CLOCK_RANGE; - continue; - } - - /* - * If programmable clock and strategy is not - * LOOKUP_BEST_REFRESH, the required mode has been found, - * otherwise record the refresh and continue looking. - */ - if (scrp->progClock) { - found = TRUE; - if (strategy != LOOKUP_BEST_REFRESH) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - break; - } - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) - refresh /= INTERLACE_REFRESH_WEIGHT; - if (refresh > bestRefresh) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - bestRefresh = refresh; - } - continue; - } - - /* - * Clock is in range, so if it is not a programmable clock, find - * a matching clock. - */ - - i = xf86GetNearestClock(scrp, p->Clock, allowDiv2, - cp->ClockDivFactor, cp->ClockMulFactor, &k); - /* - * If the clock is too far from the requested clock, this - * mode is no good. - */ - if (k & V_CLKDIV2) - gap = abs((p->Clock * 2) - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - else - gap = abs(p->Clock - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - if (gap > minimumGap) { - p->status = MODE_NOCLOCK; - if (!found) - status = MODE_NOCLOCK; - continue; - } - found = TRUE; - - if (strategy == LOOKUP_BEST_REFRESH) { - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) - refresh /= INTERLACE_REFRESH_WEIGHT; - if (refresh > bestRefresh) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - bestRefresh = refresh; - } - continue; - } - if (strategy == LOOKUP_CLOSEST_CLOCK) { - if (gap < minimumGap) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - minimumGap = gap; - } - continue; - } - /* - * If strategy is neither LOOKUP_BEST_REFRESH or - * LOOKUP_CLOSEST_CLOCK the required mode has been found. - */ - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - break; - } - } - if (found) break; + int type = types[n]; + + for (p = scrp->modePool; p != NULL; p = p->next) { + + /* scan through the modes in the sort order above */ + if ((p->type & type) != type) + continue; + + if (strcmp(p->name, modep->name) == 0) { + + /* Skip over previously rejected modes */ + if (p->status != MODE_OK) { + if (!found) + status = p->status; + continue; + } + + /* Skip over previously considered modes */ + if (p->prev) + continue; + + if (p->type & M_T_BUILTIN) { + return xf86HandleBuiltinMode(scrp, p, modep, clockRanges, + allowDiv2); + } + + /* Check clock is in range */ + cp = xf86FindClockRangeForMode(clockRanges, p); + if (cp == NULL) { + /* + * XXX Could do more here to provide a more detailed + * reason for not finding a mode. + */ + p->status = MODE_CLOCK_RANGE; + if (!found) + status = MODE_CLOCK_RANGE; + continue; + } + + /* + * If programmable clock and strategy is not + * LOOKUP_BEST_REFRESH, the required mode has been found, + * otherwise record the refresh and continue looking. + */ + if (scrp->progClock) { + found = TRUE; + if (strategy != LOOKUP_BEST_REFRESH) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + break; + } + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) + refresh /= INTERLACE_REFRESH_WEIGHT; + if (refresh > bestRefresh) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + bestRefresh = refresh; + } + continue; + } + + /* + * Clock is in range, so if it is not a programmable clock, find + * a matching clock. + */ + + i = xf86GetNearestClock(scrp, p->Clock, allowDiv2, + cp->ClockDivFactor, cp->ClockMulFactor, + &k); + /* + * If the clock is too far from the requested clock, this + * mode is no good. + */ + if (k & V_CLKDIV2) + gap = abs((p->Clock * 2) - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + else + gap = abs(p->Clock - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + if (gap > minimumGap) { + p->status = MODE_NOCLOCK; + if (!found) + status = MODE_NOCLOCK; + continue; + } + found = TRUE; + + if (strategy == LOOKUP_BEST_REFRESH) { + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) + refresh /= INTERLACE_REFRESH_WEIGHT; + if (refresh > bestRefresh) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + bestRefresh = refresh; + } + continue; + } + if (strategy == LOOKUP_CLOSEST_CLOCK) { + if (gap < minimumGap) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + minimumGap = gap; + } + continue; + } + /* + * If strategy is neither LOOKUP_BEST_REFRESH or + * LOOKUP_CLOSEST_CLOCK the required mode has been found. + */ + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + break; + } + } + if (found) + break; } if (!found || bestMode == NULL) - return status; + return status; /* Fill in the mode parameters */ if (scrp->progClock) { - modep->Clock = bestMode->Clock; - modep->ClockIndex = -1; - modep->SynthClock = (modep->Clock * MulFactor) / DivFactor; - } else { - modep->Clock = (scrp->clock[clockIndex] * DivFactor) / - MulFactor; - modep->ClockIndex = clockIndex; - modep->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - modep->Clock /= 2; - modep->SynthClock /= 2; - } + modep->Clock = bestMode->Clock; + modep->ClockIndex = -1; + modep->SynthClock = (modep->Clock * MulFactor) / DivFactor; + } + else { + modep->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; + modep->ClockIndex = clockIndex; + modep->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + modep->Clock /= 2; + modep->SynthClock /= 2; + } } - modep->type = bestMode->type; - modep->PrivFlags = ModePrivFlags; - modep->HDisplay = bestMode->HDisplay; - modep->HSyncStart = bestMode->HSyncStart; - modep->HSyncEnd = bestMode->HSyncEnd; - modep->HTotal = bestMode->HTotal; - modep->HSkew = bestMode->HSkew; - modep->VDisplay = bestMode->VDisplay; - modep->VSyncStart = bestMode->VSyncStart; - modep->VSyncEnd = bestMode->VSyncEnd; - modep->VTotal = bestMode->VTotal; - modep->VScan = bestMode->VScan; - modep->Flags = bestMode->Flags | extraFlags; - modep->CrtcHDisplay = bestMode->CrtcHDisplay; - modep->CrtcHBlankStart = bestMode->CrtcHBlankStart; - modep->CrtcHSyncStart = bestMode->CrtcHSyncStart; - modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd; - modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd; - modep->CrtcHTotal = bestMode->CrtcHTotal; - modep->CrtcHSkew = bestMode->CrtcHSkew; - modep->CrtcVDisplay = bestMode->CrtcVDisplay; - modep->CrtcVBlankStart = bestMode->CrtcVBlankStart; - modep->CrtcVSyncStart = bestMode->CrtcVSyncStart; - modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd; - modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd; - modep->CrtcVTotal = bestMode->CrtcVTotal; - modep->CrtcHAdjusted = bestMode->CrtcHAdjusted; - modep->CrtcVAdjusted = bestMode->CrtcVAdjusted; - modep->HSync = bestMode->HSync; - modep->VRefresh = bestMode->VRefresh; - modep->Private = bestMode->Private; - modep->PrivSize = bestMode->PrivSize; + modep->type = bestMode->type; + modep->PrivFlags = ModePrivFlags; + modep->HDisplay = bestMode->HDisplay; + modep->HSyncStart = bestMode->HSyncStart; + modep->HSyncEnd = bestMode->HSyncEnd; + modep->HTotal = bestMode->HTotal; + modep->HSkew = bestMode->HSkew; + modep->VDisplay = bestMode->VDisplay; + modep->VSyncStart = bestMode->VSyncStart; + modep->VSyncEnd = bestMode->VSyncEnd; + modep->VTotal = bestMode->VTotal; + modep->VScan = bestMode->VScan; + modep->Flags = bestMode->Flags | extraFlags; + modep->CrtcHDisplay = bestMode->CrtcHDisplay; + modep->CrtcHBlankStart = bestMode->CrtcHBlankStart; + modep->CrtcHSyncStart = bestMode->CrtcHSyncStart; + modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd; + modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd; + modep->CrtcHTotal = bestMode->CrtcHTotal; + modep->CrtcHSkew = bestMode->CrtcHSkew; + modep->CrtcVDisplay = bestMode->CrtcVDisplay; + modep->CrtcVBlankStart = bestMode->CrtcVBlankStart; + modep->CrtcVSyncStart = bestMode->CrtcVSyncStart; + modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd; + modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd; + modep->CrtcVTotal = bestMode->CrtcVTotal; + modep->CrtcHAdjusted = bestMode->CrtcHAdjusted; + modep->CrtcVAdjusted = bestMode->CrtcVAdjusted; + modep->HSync = bestMode->HSync; + modep->VRefresh = bestMode->VRefresh; + modep->Private = bestMode->Private; + modep->PrivSize = bestMode->PrivSize; bestMode->prev = modep; @@ -699,51 +706,53 @@ xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor) /* Sanity checks */ if (mode == NULL || monitor == NULL) { - ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n"); - return MODE_ERROR; + ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n"); + return MODE_ERROR; } DebugF("xf86CheckModeForMonitor(%p %s, %p %s)\n", - mode, mode->name, monitor, monitor->id); + mode, mode->name, monitor, monitor->id); /* Some basic mode validity checks */ if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || - mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) - return MODE_H_ILLEGAL; + mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) + return MODE_H_ILLEGAL; if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || - mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) - return MODE_V_ILLEGAL; + mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) + return MODE_V_ILLEGAL; if (monitor->nHsync > 0) { - /* Check hsync against the allowed ranges */ - float hsync = xf86ModeHSync(mode); - for (i = 0; i < monitor->nHsync; i++) - if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) && - (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE))) - break; - - /* Now see whether we ran out of sync ranges without finding a match */ - if (i == monitor->nHsync) - return MODE_HSYNC; + /* Check hsync against the allowed ranges */ + float hsync = xf86ModeHSync(mode); + + for (i = 0; i < monitor->nHsync; i++) + if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) && + (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE))) + break; + + /* Now see whether we ran out of sync ranges without finding a match */ + if (i == monitor->nHsync) + return MODE_HSYNC; } if (monitor->nVrefresh > 0) { - /* Check vrefresh against the allowed ranges */ - float vrefrsh = xf86ModeVRefresh(mode); - for (i = 0; i < monitor->nVrefresh; i++) - if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) && - (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE))) - break; - - /* Now see whether we ran out of refresh ranges without finding a match */ - if (i == monitor->nVrefresh) - return MODE_VSYNC; + /* Check vrefresh against the allowed ranges */ + float vrefrsh = xf86ModeVRefresh(mode); + + for (i = 0; i < monitor->nVrefresh; i++) + if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) && + (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE))) + break; + + /* Now see whether we ran out of refresh ranges without finding a match */ + if (i == monitor->nVrefresh) + return MODE_VSYNC; } /* Force interlaced modes to have an odd VTotal */ if (mode->Flags & V_INTERLACE) - mode->CrtcVTotal = mode->VTotal |= 1; + mode->CrtcVTotal = mode->VTotal |= 1; /* * This code stops cvt -r modes, and only cvt -r modes, from hitting 15y+ @@ -759,7 +768,7 @@ xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor) } if ((monitor->maxPixClock) && (mode->Clock > monitor->maxPixClock)) - return MODE_CLOCK_HIGH; + return MODE_CLOCK_HIGH; return MODE_OK; } @@ -774,16 +783,15 @@ xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor) static Bool xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) { - int bpp = scrp->fbFormat.bitsPerPixel, - pad = scrp->fbFormat.scanlinePad; + int bpp = scrp->fbFormat.bitsPerPixel, pad = scrp->fbFormat.scanlinePad; int lineWidth, lastWidth; if (scrp->depth == 4) - pad *= 4; /* 4 planes */ + pad *= 4; /* 4 planes */ /* Sanity check */ if ((w < 0) || (x < 0) || (y <= 0)) - return FALSE; + return FALSE; lineWidth = (((w * bpp) + pad - 1) / pad) * pad; lastWidth = x * bpp; @@ -791,11 +799,11 @@ xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) /* * At this point, we need to compare * - * (lineWidth * (y - 1)) + lastWidth + * (lineWidth * (y - 1)) + lastWidth * * against * - * scrp->videoRam * (1024 * 8) + * scrp->videoRam * (1024 * 8) * * These are bit quantities. To avoid overflows, do the comparison in * terms of BITMAP_SCANLINE_PAD units. This assumes BITMAP_SCANLINE_PAD @@ -807,8 +815,8 @@ xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) lastWidth = (lastWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD; if ((lineWidth * (y - 1) + lastWidth) > - (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD))) - return FALSE; + (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD))) + return FALSE; return TRUE; } @@ -839,52 +847,53 @@ xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, - ClockRangePtr clockRanges, - LookupModeFlags strategy, - int maxPitch, int virtualX, int virtualY) + ClockRangePtr clockRanges, + LookupModeFlags strategy, + int maxPitch, int virtualX, int virtualY) { ClockRangePtr cp; ModeStatus status; Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; int i, needDiv2; - + /* Sanity checks */ if (!scrp || !mode || !clockRanges) { - ErrorF("xf86InitialCheckModeForDriver: " - "called with invalid parameters\n"); - return MODE_ERROR; + ErrorF("xf86InitialCheckModeForDriver: " + "called with invalid parameters\n"); + return MODE_ERROR; } DebugF("xf86InitialCheckModeForDriver(%p, %p %s, %p, 0x%x, %d, %d, %d)\n", - scrp, mode, mode->name , clockRanges, strategy, maxPitch, virtualX, virtualY); + scrp, mode, mode->name, clockRanges, strategy, maxPitch, virtualX, + virtualY); /* Some basic mode validity checks */ if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || - mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) - return MODE_H_ILLEGAL; + mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) + return MODE_H_ILLEGAL; if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || - mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) - return MODE_V_ILLEGAL; + mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) + return MODE_V_ILLEGAL; if (!xf86CheckModeSize(scrp, mode->HDisplay, mode->HDisplay, - mode->VDisplay)) + mode->VDisplay)) return MODE_MEM; if (maxPitch > 0 && mode->HDisplay > maxPitch) - return MODE_BAD_WIDTH; + return MODE_BAD_WIDTH; if (virtualX > 0 && mode->HDisplay > virtualX) - return MODE_VIRTUAL_X; + return MODE_VIRTUAL_X; if (virtualY > 0 && mode->VDisplay > virtualY) - return MODE_VIRTUAL_Y; + return MODE_VIRTUAL_Y; if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue) - return MODE_BAD_HVALUE; + return MODE_BAD_HVALUE; if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue) - return MODE_BAD_VVALUE; + return MODE_BAD_VVALUE; /* * The use of the DisplayModeRec's Crtc* and SynthClock elements below is @@ -910,48 +919,49 @@ xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, * confusion and is bad software design. However since it's part of * the driver API it's hard to change. */ - + if (scrp->ValidMode) { - - xf86SetModeCrtc(mode, INTERLACE_HALVE_V); - - cp = xf86FindClockRangeForMode(clockRanges, mode); - if (!cp) - return MODE_CLOCK_RANGE; - - if (cp->ClockMulFactor < 1) - cp->ClockMulFactor = 1; - if (cp->ClockDivFactor < 1) - cp->ClockDivFactor = 1; - - /* - * XXX The effect of clock dividers and multipliers on the monitor's - * pixel clock needs to be verified. - */ - if (scrp->progClock) { - mode->SynthClock = mode->Clock; - } else { - i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2, - cp->ClockDivFactor, cp->ClockMulFactor, - &needDiv2); - mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor; - if (needDiv2 & V_CLKDIV2) - mode->SynthClock /= 2; - } - - status = (*scrp->ValidMode)(scrp->scrnIndex, mode, FALSE, - MODECHECK_INITIAL); - if (status != MODE_OK) - return status; - - if (mode->HSync <= 0.0) - mode->HSync = (float)mode->SynthClock / (float)mode->CrtcHTotal; - if (mode->VRefresh <= 0.0) - mode->VRefresh = (mode->SynthClock * 1000.0) - / (mode->CrtcHTotal * mode->CrtcVTotal); + + xf86SetModeCrtc(mode, INTERLACE_HALVE_V); + + cp = xf86FindClockRangeForMode(clockRanges, mode); + if (!cp) + return MODE_CLOCK_RANGE; + + if (cp->ClockMulFactor < 1) + cp->ClockMulFactor = 1; + if (cp->ClockDivFactor < 1) + cp->ClockDivFactor = 1; + + /* + * XXX The effect of clock dividers and multipliers on the monitor's + * pixel clock needs to be verified. + */ + if (scrp->progClock) { + mode->SynthClock = mode->Clock; + } + else { + i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2, + cp->ClockDivFactor, cp->ClockMulFactor, + &needDiv2); + mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor; + if (needDiv2 & V_CLKDIV2) + mode->SynthClock /= 2; + } + + status = (*scrp->ValidMode) (scrp->scrnIndex, mode, FALSE, + MODECHECK_INITIAL); + if (status != MODE_OK) + return status; + + if (mode->HSync <= 0.0) + mode->HSync = (float) mode->SynthClock / (float) mode->CrtcHTotal; + if (mode->VRefresh <= 0.0) + mode->VRefresh = (mode->SynthClock * 1000.0) + / (mode->CrtcHTotal * mode->CrtcVTotal); } - + mode->HSync = xf86ModeHSync(mode); mode->VRefresh = xf86ModeVRefresh(mode); @@ -996,109 +1006,112 @@ xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags) ModeStatus status = MODE_NOMODE; /* Some sanity checking */ - if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n"); - return MODE_ERROR; + if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n"); + return MODE_ERROR; } if (mode == NULL) { - ErrorF("xf86CheckModeForDriver: called with invalid modep\n"); - return MODE_ERROR; + ErrorF("xf86CheckModeForDriver: called with invalid modep\n"); + return MODE_ERROR; } /* Check the mode size */ if (mode->HDisplay > scrp->virtualX) - return MODE_VIRTUAL_X; + return MODE_VIRTUAL_X; if (mode->VDisplay > scrp->virtualY) - return MODE_VIRTUAL_Y; + return MODE_VIRTUAL_Y; if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue) - return MODE_BAD_HVALUE; + return MODE_BAD_HVALUE; if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue) - return MODE_BAD_VVALUE; + return MODE_BAD_VVALUE; for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - /* DivFactor and MulFactor must be > 0 */ - cp->ClockDivFactor = max(1, cp->ClockDivFactor); - cp->ClockMulFactor = max(1, cp->ClockMulFactor); + /* DivFactor and MulFactor must be > 0 */ + cp->ClockDivFactor = max(1, cp->ClockDivFactor); + cp->ClockMulFactor = max(1, cp->ClockMulFactor); } if (scrp->progClock) { - /* Check clock is in range */ - for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - if (modeInClockRange(cp, mode)) - break; - } - if (cp == NULL) { - return MODE_CLOCK_RANGE; - } - /* - * If programmable clock the required mode has been found - */ - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - } else { - status = MODE_CLOCK_RANGE; - /* Check clock is in range */ - for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - if (modeInClockRange(cp, mode)) { - /* - * Clock is in range, so if it is not a programmable clock, - * find a matching clock. - */ - - i = xf86GetNearestClock(scrp, mode->Clock, 0, - cp->ClockDivFactor, cp->ClockMulFactor, &k); - /* - * If the clock is too far from the requested clock, this - * mode is no good. - */ - if (k & V_CLKDIV2) - gap = abs((mode->Clock * 2) - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - else - gap = abs(mode->Clock - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - if (gap > minimumGap) { - status = MODE_NOCLOCK; - continue; - } - - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - break; - } - } - if (cp == NULL) - return status; + /* Check clock is in range */ + for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { + if (modeInClockRange(cp, mode)) + break; + } + if (cp == NULL) { + return MODE_CLOCK_RANGE; + } + /* + * If programmable clock the required mode has been found + */ + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + } + else { + status = MODE_CLOCK_RANGE; + /* Check clock is in range */ + for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { + if (modeInClockRange(cp, mode)) { + /* + * Clock is in range, so if it is not a programmable clock, + * find a matching clock. + */ + + i = xf86GetNearestClock(scrp, mode->Clock, 0, + cp->ClockDivFactor, cp->ClockMulFactor, + &k); + /* + * If the clock is too far from the requested clock, this + * mode is no good. + */ + if (k & V_CLKDIV2) + gap = abs((mode->Clock * 2) - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + else + gap = abs(mode->Clock - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + if (gap > minimumGap) { + status = MODE_NOCLOCK; + continue; + } + + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + break; + } + } + if (cp == NULL) + return status; } /* Fill in the mode parameters */ if (scrp->progClock) { - mode->ClockIndex = -1; - mode->SynthClock = (mode->Clock * MulFactor) / DivFactor; - } else { - mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; - mode->ClockIndex = clockIndex; - mode->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - mode->Clock /= 2; - mode->SynthClock /= 2; - } + mode->ClockIndex = -1; + mode->SynthClock = (mode->Clock * MulFactor) / DivFactor; } - mode->PrivFlags = ModePrivFlags; + else { + mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; + mode->ClockIndex = clockIndex; + mode->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + mode->Clock /= 2; + mode->SynthClock /= 2; + } + } + mode->PrivFlags = ModePrivFlags; return MODE_OK; } -static int +static int inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy) { float aspect = 0.0; @@ -1107,24 +1120,25 @@ inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy) int x = 0, y = 0; DisplayModePtr mode; - if (!mon) return 0; + if (!mon) + return 0; DDC = mon->DDC; if (DDC && DDC->ver.revision >= 4) { - /* For 1.4, we might actually get native pixel format. How novel. */ - if (PREFERRED_TIMING_MODE(DDC->features.msc)) { - for (mode = modes; mode; mode = mode->next) { - if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) { - x = mode->HDisplay; - y = mode->VDisplay; - goto found; - } - } - } - /* - * Even if we don't, we might get aspect ratio from extra CVT info - * or from the monitor size fields. TODO. - */ + /* For 1.4, we might actually get native pixel format. How novel. */ + if (PREFERRED_TIMING_MODE(DDC->features.msc)) { + for (mode = modes; mode; mode = mode->next) { + if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) { + x = mode->HDisplay; + y = mode->VDisplay; + goto found; + } + } + } + /* + * Even if we don't, we might get aspect ratio from extra CVT info + * or from the monitor size fields. TODO. + */ } /* @@ -1132,41 +1146,42 @@ inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy) * before EDID 1.4, but right now we'll get that wrong. TODO. */ if (!aspect) { - if (!mon->widthmm || !mon->heightmm) - aspect = 4.0/3.0; - else - aspect = (float)mon->widthmm / (float)mon->heightmm; + if (!mon->widthmm || !mon->heightmm) + aspect = 4.0 / 3.0; + else + aspect = (float) mon->widthmm / (float) mon->heightmm; } /* find the largest M_T_DRIVER mode with that aspect ratio */ for (mode = modes; mode; mode = mode->next) { - float mode_aspect, metaspect; - if (!(mode->type & (M_T_DRIVER|M_T_USERDEF))) - continue; - mode_aspect = (float)mode->HDisplay / (float)mode->VDisplay; - metaspect = aspect / mode_aspect; - /* 5% slop or so, since we only get size in centimeters */ - if (fabs(1.0 - metaspect) < 0.05) { - if ((mode->HDisplay > x) && (mode->VDisplay > y)) { - x = mode->HDisplay; - y = mode->VDisplay; - } - } + float mode_aspect, metaspect; + + if (!(mode->type & (M_T_DRIVER | M_T_USERDEF))) + continue; + mode_aspect = (float) mode->HDisplay / (float) mode->VDisplay; + metaspect = aspect / mode_aspect; + /* 5% slop or so, since we only get size in centimeters */ + if (fabs(1.0 - metaspect) < 0.05) { + if ((mode->HDisplay > x) && (mode->VDisplay > y)) { + x = mode->HDisplay; + y = mode->VDisplay; + } + } } if (!x || !y) { - xf86DrvMsg(scrp->scrnIndex, X_WARNING, - "Unable to estimate virtual size\n"); - return 0; + xf86DrvMsg(scrp->scrnIndex, X_WARNING, + "Unable to estimate virtual size\n"); + return 0; } -found: + found: *vx = x; *vy = y; xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Estimated virtual size for aspect ratio %.4f is %dx%d\n", - aspect, *vx, *vy); + "Estimated virtual size for aspect ratio %.4f is %dx%d\n", + aspect, *vx, *vy); return 1; } @@ -1177,8 +1192,7 @@ LCM(unsigned int x, unsigned int y) { unsigned int m = x, n = y, o; - while ((o = m % n)) - { + while ((o = m % n)) { m = n; n = o; } @@ -1193,14 +1207,12 @@ LCM(unsigned int x, unsigned int y) * cannot exist. */ static int -scanLineWidth( - unsigned int xsize, /* pixels */ - unsigned int ysize, /* pixels */ - unsigned int width, /* pixels */ - unsigned long BankSize, /* char's */ - PixmapFormatRec *pBankFormat, - unsigned int nWidthUnit /* bits */ -) +scanLineWidth(unsigned int xsize, /* pixels */ + unsigned int ysize, /* pixels */ + unsigned int width, /* pixels */ + unsigned long BankSize, /* char's */ + PixmapFormatRec * pBankFormat, unsigned int nWidthUnit /* bits */ + ) { unsigned long nBitsPerBank, nBitsPerScanline, nBitsPerScanlinePadUnit; unsigned long minBitsPerScanline, maxBitsPerScanline; @@ -1223,7 +1235,7 @@ scanLineWidth( width = nBitsPerScanline / pBankFormat->bitsPerPixel; if (!xsize || !(nBitsPerBank % pBankFormat->bitsPerPixel)) - return (int)width; + return (int) width; /* * Scanlines will be server-pad aligned at this point. They will also be @@ -1244,40 +1256,36 @@ scanLineWidth( return -1; if (ysize == 1) - return (int)width; + return (int) width; maxBitsPerScanline = - (((unsigned long)(-1) >> 1) - minBitsPerScanline) / (ysize - 1); - while (nBitsPerScanline <= maxBitsPerScanline) - { + (((unsigned long) (-1) >> 1) - minBitsPerScanline) / (ysize - 1); + while (nBitsPerScanline <= maxBitsPerScanline) { unsigned long BankBase, BankUnit; BankUnit = ((nBitsPerBank + nBitsPerScanline - 1) / nBitsPerBank) * nBitsPerBank; if (!(BankUnit % nBitsPerScanline)) - return (int)width; + return (int) width; - for (BankBase = BankUnit; ; BankBase += nBitsPerBank) - { + for (BankBase = BankUnit;; BankBase += nBitsPerBank) { unsigned long x, y; y = BankBase / nBitsPerScanline; if (y >= ysize) - return (int)width; + return (int) width; x = BankBase % nBitsPerScanline; if (!(x % pBankFormat->bitsPerPixel)) continue; - if (x < minBitsPerScanline) - { + if (x < minBitsPerScanline) { /* * Skip ahead certain widths by dividing the excess scanline * amongst the y's. */ y *= nBitsPerScanlinePadUnit; - nBitsPerScanline += - ((x + y - 1) / y) * nBitsPerScanlinePadUnit; + nBitsPerScanline += ((x + y - 1) / y) * nBitsPerScanlinePadUnit; width = nBitsPerScanline / pBankFormat->bitsPerPixel; break; } @@ -1286,10 +1294,10 @@ scanLineWidth( continue; if (!(nBitsPerScanline % x)) - return (int)width; + return (int) width; BankBase = ((nBitsPerScanline - minBitsPerScanline) / - (nBitsPerScanline - x)) * BankUnit; + (nBitsPerScanline - x)) * BankUnit; } } @@ -1346,17 +1354,17 @@ scanLineWidth( int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, int pitchInc, - int minHeight, int maxHeight, int virtualX, int virtualY, - int apertureSize, LookupModeFlags strategy) + char **modeNames, ClockRangePtr clockRanges, + int *linePitches, int minPitch, int maxPitch, int pitchInc, + int minHeight, int maxHeight, int virtualX, int virtualY, + int apertureSize, LookupModeFlags strategy) { DisplayModePtr p, q, r, new, last, *endp; int i, numModes = 0; ModeStatus status; int linePitch = -1, virtX = 0, virtY = 0; int newLinePitch, newVirtX, newVirtY; - int modeSize; /* in pixels */ + int modeSize; /* in pixels */ Bool validateAllDefaultModes = FALSE; Bool userModes = FALSE; int saveType; @@ -1368,30 +1376,29 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, range vrefresh[MAX_VREFRESH]; Bool inferred_virtual = FALSE; - DebugF("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n", - scrp, availModes, modeNames, clockRanges, - linePitches, minPitch, maxPitch, pitchInc, - minHeight, maxHeight, virtualX, virtualY, - apertureSize, strategy - ); + DebugF + ("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n", + scrp, availModes, modeNames, clockRanges, linePitches, minPitch, + maxPitch, pitchInc, minHeight, maxHeight, virtualX, virtualY, + apertureSize, strategy); /* Some sanity checking */ if (scrp == NULL || scrp->name == NULL || !scrp->monitor || - (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n"); - return -1; + (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n"); + return -1; } if (linePitches != NULL && linePitches[0] <= 0) { - ErrorF("xf86ValidateModes: called with invalid linePitches\n"); - return -1; + ErrorF("xf86ValidateModes: called with invalid linePitches\n"); + return -1; } if (pitchInc <= 0) { - ErrorF("xf86ValidateModes: called with invalid pitchInc\n"); - return -1; + ErrorF("xf86ValidateModes: called with invalid pitchInc\n"); + return -1; } if ((virtualX > 0) != (virtualY > 0)) { - ErrorF("xf86ValidateModes: called with invalid virtual resolution\n"); - return -1; + ErrorF("xf86ValidateModes: called with invalid virtual resolution\n"); + return -1; } /* @@ -1399,83 +1406,87 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * in the monitor section. */ if (strategy & LOOKUP_OPTIONAL_TOLERANCES) { - strategy &= ~LOOKUP_OPTIONAL_TOLERANCES; - } else { - const char *type = ""; + strategy &= ~LOOKUP_OPTIONAL_TOLERANCES; + } + else { + const char *type = ""; Bool specified = FALSE; - if (scrp->monitor->nHsync <= 0) { - if (numTimings > 0) { - scrp->monitor->nHsync = numTimings; - for (i = 0; i < numTimings; i++) { - scrp->monitor->hsync[i].lo = hsync[i].lo; - scrp->monitor->hsync[i].hi = hsync[i].hi; - } - } else { - scrp->monitor->hsync[0].lo = 31.5; - scrp->monitor->hsync[0].hi = 48.0; - scrp->monitor->nHsync = 1; - } - type = "default "; - } else { + if (scrp->monitor->nHsync <= 0) { + if (numTimings > 0) { + scrp->monitor->nHsync = numTimings; + for (i = 0; i < numTimings; i++) { + scrp->monitor->hsync[i].lo = hsync[i].lo; + scrp->monitor->hsync[i].hi = hsync[i].hi; + } + } + else { + scrp->monitor->hsync[0].lo = 31.5; + scrp->monitor->hsync[0].hi = 48.0; + scrp->monitor->nHsync = 1; + } + type = "default "; + } + else { specified = TRUE; } - for (i = 0; i < scrp->monitor->nHsync; i++) { - if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi) - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %shsync value of %.2f kHz\n", - scrp->monitor->id, type, - scrp->monitor->hsync[i].lo); - else - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %shsync range of %.2f-%.2f kHz\n", - scrp->monitor->id, type, - scrp->monitor->hsync[i].lo, - scrp->monitor->hsync[i].hi); - } - - type = ""; - if (scrp->monitor->nVrefresh <= 0) { - if (numTimings > 0) { - scrp->monitor->nVrefresh = numTimings; - for (i = 0; i < numTimings; i++) { - scrp->monitor->vrefresh[i].lo = vrefresh[i].lo; - scrp->monitor->vrefresh[i].hi = vrefresh[i].hi; - } - } else { - scrp->monitor->vrefresh[0].lo = 50; - scrp->monitor->vrefresh[0].hi = 70; - scrp->monitor->nVrefresh = 1; - } - type = "default "; - } else { + for (i = 0; i < scrp->monitor->nHsync; i++) { + if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi) + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %shsync value of %.2f kHz\n", + scrp->monitor->id, type, scrp->monitor->hsync[i].lo); + else + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %shsync range of %.2f-%.2f kHz\n", + scrp->monitor->id, type, + scrp->monitor->hsync[i].lo, + scrp->monitor->hsync[i].hi); + } + + type = ""; + if (scrp->monitor->nVrefresh <= 0) { + if (numTimings > 0) { + scrp->monitor->nVrefresh = numTimings; + for (i = 0; i < numTimings; i++) { + scrp->monitor->vrefresh[i].lo = vrefresh[i].lo; + scrp->monitor->vrefresh[i].hi = vrefresh[i].hi; + } + } + else { + scrp->monitor->vrefresh[0].lo = 50; + scrp->monitor->vrefresh[0].hi = 70; + scrp->monitor->nVrefresh = 1; + } + type = "default "; + } + else { specified = TRUE; } - for (i = 0; i < scrp->monitor->nVrefresh; i++) { - if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi) - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %svrefresh value of %.2f Hz\n", - scrp->monitor->id, type, - scrp->monitor->vrefresh[i].lo); - else - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %svrefresh range of %.2f-%.2f Hz\n", - scrp->monitor->id, type, - scrp->monitor->vrefresh[i].lo, - scrp->monitor->vrefresh[i].hi); - } + for (i = 0; i < scrp->monitor->nVrefresh; i++) { + if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi) + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %svrefresh value of %.2f Hz\n", + scrp->monitor->id, type, + scrp->monitor->vrefresh[i].lo); + else + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %svrefresh range of %.2f-%.2f Hz\n", + scrp->monitor->id, type, + scrp->monitor->vrefresh[i].lo, + scrp->monitor->vrefresh[i].hi); + } type = ""; - if (!scrp->monitor->maxPixClock && !specified) { + if (!scrp->monitor->maxPixClock && !specified) { type = "default "; scrp->monitor->maxPixClock = 65000.0; } - if (scrp->monitor->maxPixClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %smaximum pixel clock of %.2f MHz\n", - scrp->monitor->id, type, - (float)scrp->monitor->maxPixClock / 1000.0); - } + if (scrp->monitor->maxPixClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %smaximum pixel clock of %.2f MHz\n", + scrp->monitor->id, type, + (float) scrp->monitor->maxPixClock / 1000.0); + } } /* @@ -1483,24 +1494,24 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, */ storeClockRanges = scrp->clockRanges; while (storeClockRanges != NULL) { - storeClockRanges = storeClockRanges->next; + storeClockRanges = storeClockRanges->next; } for (cp = clockRanges; cp != NULL; cp = cp->next, - storeClockRanges = storeClockRanges->next) { - storeClockRanges = xnfalloc(sizeof(ClockRange)); - if (scrp->clockRanges == NULL) - scrp->clockRanges = storeClockRanges; - memcpy(storeClockRanges, cp, sizeof(ClockRange)); + storeClockRanges = storeClockRanges->next) { + storeClockRanges = xnfalloc(sizeof(ClockRange)); + if (scrp->clockRanges == NULL) + scrp->clockRanges = storeClockRanges; + memcpy(storeClockRanges, cp, sizeof(ClockRange)); } /* Determine which pixmap format to pass to scanLineWidth() */ if (scrp->depth > 4) - BankFormat = &scrp->fbFormat; + BankFormat = &scrp->fbFormat; else - BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */ + BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */ if (scrp->xInc <= 0) - scrp->xInc = 8; /* Suitable for VGA and others */ + scrp->xInc = 8; /* Suitable for VGA and others */ #define _VIRTUALX(x) ((((x) + scrp->xInc - 1) / scrp->xInc) * scrp->xInc) @@ -1510,13 +1521,13 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * maxPitch values passed are ignored. */ if (linePitches) { - minPitch = maxPitch = linePitches[0]; - for (i = 1; linePitches[i] > 0; i++) { - if (linePitches[i] > maxPitch) - maxPitch = linePitches[i]; - if (linePitches[i] < minPitch) - minPitch = linePitches[i]; - } + minPitch = maxPitch = linePitches[0]; + for (i = 1; linePitches[i] > 0; i++) { + if (linePitches[i] > maxPitch) + maxPitch = linePitches[i]; + if (linePitches[i] < minPitch) + minPitch = linePitches[i]; + } } /* Initial check of virtual size against other constraints */ @@ -1525,60 +1536,62 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * Initialise virtX and virtY if the values are fixed. */ if (virtualY > 0) { - if (maxHeight > 0 && virtualY > maxHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too large for the hardware " - "(max %d)\n", virtualY, maxHeight); - return -1; - } - - if (minHeight > 0 && virtualY < minHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too small for the hardware " - "(min %d)\n", virtualY, minHeight); - return -1; - } - - virtualX = _VIRTUALX(virtualX); - if (linePitches != NULL) { - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= virtualX) && - (linePitches[i] == - scanLineWidth(virtualX, virtualY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - linePitch = linePitches[i]; - break; - } - } - } else { - linePitch = scanLineWidth(virtualX, virtualY, minPitch, - apertureSize, BankFormat, pitchInc); - } - - if ((linePitch < minPitch) || (linePitch > maxPitch)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual width (%d) is too large for the hardware " - "(max %d)\n", virtualX, maxPitch); - return -1; - } - - if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual size (%dx%d) (pitch %d) exceeds video memory\n", - virtualX, virtualY, linePitch); - return -1; - } - - virtX = virtualX; - virtY = virtualY; - scrp->virtualFrom = X_CONFIG; - } else if (!modeNames || !*modeNames) { - /* No virtual size given in the config, try to infer */ - /* XXX this doesn't take m{in,ax}Pitch into account; oh well */ - inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY); - if (inferred_virtual) - linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize, - BankFormat, pitchInc); + if (maxHeight > 0 && virtualY > maxHeight) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too large for the hardware " + "(max %d)\n", virtualY, maxHeight); + return -1; + } + + if (minHeight > 0 && virtualY < minHeight) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too small for the hardware " + "(min %d)\n", virtualY, minHeight); + return -1; + } + + virtualX = _VIRTUALX(virtualX); + if (linePitches != NULL) { + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= virtualX) && + (linePitches[i] == + scanLineWidth(virtualX, virtualY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + linePitch = linePitches[i]; + break; + } + } + } + else { + linePitch = scanLineWidth(virtualX, virtualY, minPitch, + apertureSize, BankFormat, pitchInc); + } + + if ((linePitch < minPitch) || (linePitch > maxPitch)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual width (%d) is too large for the hardware " + "(max %d)\n", virtualX, maxPitch); + return -1; + } + + if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual size (%dx%d) (pitch %d) exceeds video memory\n", + virtualX, virtualY, linePitch); + return -1; + } + + virtX = virtualX; + virtY = virtualY; + scrp->virtualFrom = X_CONFIG; + } + else if (!modeNames || !*modeNames) { + /* No virtual size given in the config, try to infer */ + /* XXX this doesn't take m{in,ax}Pitch into account; oh well */ + inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY); + if (inferred_virtual) + linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize, + BankFormat, pitchInc); } /* Print clock ranges and scaled clocks */ @@ -1591,253 +1604,256 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * member of the scrp->modes list for which a match was considered. */ if (scrp->modePool == NULL) { - q = NULL; - for (p = availModes; p != NULL; p = p->next) { - status = xf86InitialCheckModeForDriver(scrp, p, clockRanges, - strategy, maxPitch, - virtX, virtY); - - if (status == MODE_OK) { - status = xf86CheckModeForMonitor(p, scrp->monitor); - } - - if (status == MODE_OK) { - new = xnfalloc(sizeof(DisplayModeRec)); - *new = *p; - new->next = NULL; - if (!q) { - scrp->modePool = new; - } else { - q->next = new; - } - new->prev = NULL; - q = new; - q->name = xnfstrdup(p->name); - q->status = MODE_OK; - } else { - printModeRejectMessage(scrp->scrnIndex, p, status); - } - } - - if (scrp->modePool == NULL) { - xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n"); - return 0; - } - } else { - for (p = scrp->modePool; p != NULL; p = p->next) { - p->prev = NULL; - p->status = MODE_OK; - } + q = NULL; + for (p = availModes; p != NULL; p = p->next) { + status = xf86InitialCheckModeForDriver(scrp, p, clockRanges, + strategy, maxPitch, + virtX, virtY); + + if (status == MODE_OK) { + status = xf86CheckModeForMonitor(p, scrp->monitor); + } + + if (status == MODE_OK) { + new = xnfalloc(sizeof(DisplayModeRec)); + *new = *p; + new->next = NULL; + if (!q) { + scrp->modePool = new; + } + else { + q->next = new; + } + new->prev = NULL; + q = new; + q->name = xnfstrdup(p->name); + q->status = MODE_OK; + } + else { + printModeRejectMessage(scrp->scrnIndex, p, status); + } + } + + if (scrp->modePool == NULL) { + xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n"); + return 0; + } + } + else { + for (p = scrp->modePool; p != NULL; p = p->next) { + p->prev = NULL; + p->status = MODE_OK; + } } /* * Allocate one entry in scrp->modes for each named mode. */ while (scrp->modes) - xf86DeleteMode(&scrp->modes, scrp->modes); + xf86DeleteMode(&scrp->modes, scrp->modes); endp = &scrp->modes; last = NULL; if (modeNames != NULL) { - for (i = 0; modeNames[i] != NULL; i++) { - userModes = TRUE; - new = xnfcalloc(1, sizeof(DisplayModeRec)); - new->prev = last; - new->type = M_T_USERDEF; - new->name = xnfstrdup(modeNames[i]); - if (new->prev) - new->prev->next = new; - *endp = last = new; - endp = &new->next; - } + for (i = 0; modeNames[i] != NULL; i++) { + userModes = TRUE; + new = xnfcalloc(1, sizeof(DisplayModeRec)); + new->prev = last; + new->type = M_T_USERDEF; + new->name = xnfstrdup(modeNames[i]); + if (new->prev) + new->prev->next = new; + *endp = last = new; + endp = &new->next; + } } /* Lookup each mode */ #ifdef RANDR - if (!xf86Info.disableRandR + if (!xf86Info.disableRandR #ifdef PANORAMIX - && noPanoramiXExtension + && noPanoramiXExtension #endif - ) - validateAllDefaultModes = TRUE; + ) + validateAllDefaultModes = TRUE; #endif - for (p = scrp->modes; ; p = p->next) { - Bool repeat; - - /* - * If the supplied mode names don't produce a valid mode, scan through - * unconsidered modePool members until one survives validation. This - * is done in decreasing order by mode pixel area. - */ - - if (p == NULL) { - if ((numModes > 0) && !validateAllDefaultModes) - break; - - validateAllDefaultModes = TRUE; - r = NULL; - modeSize = 0; - for (q = scrp->modePool; q != NULL; q = q->next) { - if ((q->prev == NULL) && (q->status == MODE_OK)) { - /* - * Deal with the case where this mode wasn't considered - * because of a builtin mode of the same name. - */ - for (p = scrp->modes; p != NULL; p = p->next) { - if ((p->status != MODE_OK) && - !strcmp(p->name, q->name)) - break; - } - - if (p != NULL) - q->prev = p; - else { - /* - * A quick check to not allow default modes with - * horizontal timing parameters that CRTs may have - * problems with. - */ - if (!scrp->monitor->reducedblanking && - (q->type & M_T_DEFAULT) && - ((double)q->HTotal / (double)q->HDisplay) < 1.15) - continue; - - if (modeSize < (q->HDisplay * q->VDisplay)) { - r = q; - modeSize = q->HDisplay * q->VDisplay; - } - } - } - } - - if (r == NULL) - break; - - p = xnfcalloc(1, sizeof(DisplayModeRec)); - p->prev = last; - p->name = xnfstrdup(r->name); - if (!userModes) - p->type = M_T_USERDEF; - if (p->prev) - p->prev->next = p; - *endp = last = p; - endp = &p->next; - } - - repeat = FALSE; - lookupNext: - if (repeat && ((status = p->status) != MODE_OK)) - printModeRejectMessage(scrp->scrnIndex, p, status); - saveType = p->type; - status = xf86LookupMode(scrp, p, clockRanges, strategy); - if (repeat && status == MODE_NOMODE) - continue; - if (status != MODE_OK) - printModeRejectMessage(scrp->scrnIndex, p, status); - if (status == MODE_ERROR) { - ErrorF("xf86ValidateModes: " - "unexpected result from xf86LookupMode()\n"); - return -1; - } - if (status != MODE_OK) { - if (p->status == MODE_OK) - p->status = status; - continue; - } - p->type |= saveType; - repeat = TRUE; - - newLinePitch = linePitch; - newVirtX = virtX; - newVirtY = virtY; - - /* - * Don't let non-user defined modes increase the virtual size - */ - if (!(p->type & M_T_USERDEF) && (numModes > 0)) { - if (p->HDisplay > virtX) { - p->status = MODE_VIRTUAL_X; - goto lookupNext; - } - if (p->VDisplay > virtY) { - p->status = MODE_VIRTUAL_Y; - goto lookupNext; - } - } - /* - * Adjust virtual width and height if the mode is too large for the - * current values and if they are not fixed. - */ - if (virtualX <= 0 && p->HDisplay > newVirtX) - newVirtX = _VIRTUALX(p->HDisplay); - if (virtualY <= 0 && p->VDisplay > newVirtY) { - if (maxHeight > 0 && p->VDisplay > maxHeight) { - p->status = MODE_VIRTUAL_Y; /* ? */ - goto lookupNext; - } - newVirtY = p->VDisplay; - } - - /* - * If virtual resolution is to be increased, revalidate it. - */ - if ((virtX != newVirtX) || (virtY != newVirtY)) { - if (linePitches != NULL) { - newLinePitch = -1; - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= newVirtX) && - (linePitches[i] >= linePitch) && - (linePitches[i] == - scanLineWidth(newVirtX, newVirtY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - newLinePitch = linePitches[i]; - break; - } - } - } else { - if (linePitch < minPitch) - linePitch = minPitch; - newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch, - apertureSize, BankFormat, - pitchInc); - } - if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) { - p->status = MODE_BAD_WIDTH; - goto lookupNext; - } - - /* - * Check that the pixel area required by the new virtual height - * and line pitch isn't too large. - */ - if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) { - p->status = MODE_MEM_VIRT; - goto lookupNext; - } - } - - if (scrp->ValidMode) { - /* - * Give the driver a final say, passing it the proposed virtual - * geometry. - */ - scrp->virtualX = newVirtX; - scrp->virtualY = newVirtY; - scrp->displayWidth = newLinePitch; - p->status = (scrp->ValidMode)(scrp->scrnIndex, p, FALSE, - MODECHECK_FINAL); - - if (p->status != MODE_OK) { - goto lookupNext; - } - } - - /* Mode has passed all the tests */ - virtX = newVirtX; - virtY = newVirtY; - linePitch = newLinePitch; - p->status = MODE_OK; - numModes++; + for (p = scrp->modes;; p = p->next) { + Bool repeat; + + /* + * If the supplied mode names don't produce a valid mode, scan through + * unconsidered modePool members until one survives validation. This + * is done in decreasing order by mode pixel area. + */ + + if (p == NULL) { + if ((numModes > 0) && !validateAllDefaultModes) + break; + + validateAllDefaultModes = TRUE; + r = NULL; + modeSize = 0; + for (q = scrp->modePool; q != NULL; q = q->next) { + if ((q->prev == NULL) && (q->status == MODE_OK)) { + /* + * Deal with the case where this mode wasn't considered + * because of a builtin mode of the same name. + */ + for (p = scrp->modes; p != NULL; p = p->next) { + if ((p->status != MODE_OK) && !strcmp(p->name, q->name)) + break; + } + + if (p != NULL) + q->prev = p; + else { + /* + * A quick check to not allow default modes with + * horizontal timing parameters that CRTs may have + * problems with. + */ + if (!scrp->monitor->reducedblanking && + (q->type & M_T_DEFAULT) && + ((double) q->HTotal / (double) q->HDisplay) < 1.15) + continue; + + if (modeSize < (q->HDisplay * q->VDisplay)) { + r = q; + modeSize = q->HDisplay * q->VDisplay; + } + } + } + } + + if (r == NULL) + break; + + p = xnfcalloc(1, sizeof(DisplayModeRec)); + p->prev = last; + p->name = xnfstrdup(r->name); + if (!userModes) + p->type = M_T_USERDEF; + if (p->prev) + p->prev->next = p; + *endp = last = p; + endp = &p->next; + } + + repeat = FALSE; + lookupNext: + if (repeat && ((status = p->status) != MODE_OK)) + printModeRejectMessage(scrp->scrnIndex, p, status); + saveType = p->type; + status = xf86LookupMode(scrp, p, clockRanges, strategy); + if (repeat && status == MODE_NOMODE) + continue; + if (status != MODE_OK) + printModeRejectMessage(scrp->scrnIndex, p, status); + if (status == MODE_ERROR) { + ErrorF("xf86ValidateModes: " + "unexpected result from xf86LookupMode()\n"); + return -1; + } + if (status != MODE_OK) { + if (p->status == MODE_OK) + p->status = status; + continue; + } + p->type |= saveType; + repeat = TRUE; + + newLinePitch = linePitch; + newVirtX = virtX; + newVirtY = virtY; + + /* + * Don't let non-user defined modes increase the virtual size + */ + if (!(p->type & M_T_USERDEF) && (numModes > 0)) { + if (p->HDisplay > virtX) { + p->status = MODE_VIRTUAL_X; + goto lookupNext; + } + if (p->VDisplay > virtY) { + p->status = MODE_VIRTUAL_Y; + goto lookupNext; + } + } + /* + * Adjust virtual width and height if the mode is too large for the + * current values and if they are not fixed. + */ + if (virtualX <= 0 && p->HDisplay > newVirtX) + newVirtX = _VIRTUALX(p->HDisplay); + if (virtualY <= 0 && p->VDisplay > newVirtY) { + if (maxHeight > 0 && p->VDisplay > maxHeight) { + p->status = MODE_VIRTUAL_Y; /* ? */ + goto lookupNext; + } + newVirtY = p->VDisplay; + } + + /* + * If virtual resolution is to be increased, revalidate it. + */ + if ((virtX != newVirtX) || (virtY != newVirtY)) { + if (linePitches != NULL) { + newLinePitch = -1; + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= newVirtX) && + (linePitches[i] >= linePitch) && + (linePitches[i] == + scanLineWidth(newVirtX, newVirtY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + newLinePitch = linePitches[i]; + break; + } + } + } + else { + if (linePitch < minPitch) + linePitch = minPitch; + newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch, + apertureSize, BankFormat, + pitchInc); + } + if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) { + p->status = MODE_BAD_WIDTH; + goto lookupNext; + } + + /* + * Check that the pixel area required by the new virtual height + * and line pitch isn't too large. + */ + if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) { + p->status = MODE_MEM_VIRT; + goto lookupNext; + } + } + + if (scrp->ValidMode) { + /* + * Give the driver a final say, passing it the proposed virtual + * geometry. + */ + scrp->virtualX = newVirtX; + scrp->virtualY = newVirtY; + scrp->displayWidth = newLinePitch; + p->status = (scrp->ValidMode) (scrp->scrnIndex, p, FALSE, + MODECHECK_FINAL); + + if (p->status != MODE_OK) { + goto lookupNext; + } + } + + /* Mode has passed all the tests */ + virtX = newVirtX; + virtY = newVirtY; + linePitch = newLinePitch; + p->status = MODE_OK; + numModes++; } /* @@ -1846,102 +1862,105 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * fix up if so. */ if (inferred_virtual) { - int vx = 0, vy = 0; - for (p = scrp->modes; p; p = p->next) { - if (p->HDisplay > vx && p->VDisplay > vy) { - vx = p->HDisplay; - vy = p->VDisplay; - } - } - if (vx < virtX || vy < virtY) { - const int types[] = { - M_T_BUILTIN | M_T_PREFERRED, - M_T_BUILTIN, - M_T_DRIVER | M_T_PREFERRED, - M_T_DRIVER, - 0 - }; - const int ntypes = sizeof(types) / sizeof(int); - int n; - - /* - * We did not find the estimated virtual size. So now we want to - * find the largest mode available, but we want to search in the - * modes in the order of "types" listed above. - */ - for (n = 0; n < ntypes; n++) { - int type = types[n]; - - vx = 0; vy = 0; - for (p = scrp->modes; p; p = p->next) { - /* scan through the modes in the sort order above */ - if ((p->type & type) != type) - continue; - if (p->HDisplay > vx && p->VDisplay > vy) { - vx = p->HDisplay; - vy = p->VDisplay; - } - } - if (vx && vy) - /* Found one */ - break; - } - xf86DrvMsg(scrp->scrnIndex, X_WARNING, - "Shrinking virtual size estimate from %dx%d to %dx%d\n", - virtX, virtY, vx, vy); - virtX = _VIRTUALX(vx); - virtY = vy; - for (p = scrp->modes; p; p = p->next) { - if (numModes > 0) { - if (p->HDisplay > virtX) - p->status = MODE_VIRTUAL_X; - if (p->VDisplay > virtY) - p->status = MODE_VIRTUAL_Y; - if (p->status != MODE_OK) { - numModes--; - printModeRejectMessage(scrp->scrnIndex, p, p->status); - } - } - } - if (linePitches != NULL) { - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= virtX) && - (linePitches[i] == - scanLineWidth(virtX, virtY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - linePitch = linePitches[i]; - break; - } - } - } else { - linePitch = scanLineWidth(virtX, virtY, minPitch, - apertureSize, BankFormat, pitchInc); - } - } + int vx = 0, vy = 0; + + for (p = scrp->modes; p; p = p->next) { + if (p->HDisplay > vx && p->VDisplay > vy) { + vx = p->HDisplay; + vy = p->VDisplay; + } + } + if (vx < virtX || vy < virtY) { + const int types[] = { + M_T_BUILTIN | M_T_PREFERRED, + M_T_BUILTIN, + M_T_DRIVER | M_T_PREFERRED, + M_T_DRIVER, + 0 + }; + const int ntypes = sizeof(types) / sizeof(int); + int n; + + /* + * We did not find the estimated virtual size. So now we want to + * find the largest mode available, but we want to search in the + * modes in the order of "types" listed above. + */ + for (n = 0; n < ntypes; n++) { + int type = types[n]; + + vx = 0; + vy = 0; + for (p = scrp->modes; p; p = p->next) { + /* scan through the modes in the sort order above */ + if ((p->type & type) != type) + continue; + if (p->HDisplay > vx && p->VDisplay > vy) { + vx = p->HDisplay; + vy = p->VDisplay; + } + } + if (vx && vy) + /* Found one */ + break; + } + xf86DrvMsg(scrp->scrnIndex, X_WARNING, + "Shrinking virtual size estimate from %dx%d to %dx%d\n", + virtX, virtY, vx, vy); + virtX = _VIRTUALX(vx); + virtY = vy; + for (p = scrp->modes; p; p = p->next) { + if (numModes > 0) { + if (p->HDisplay > virtX) + p->status = MODE_VIRTUAL_X; + if (p->VDisplay > virtY) + p->status = MODE_VIRTUAL_Y; + if (p->status != MODE_OK) { + numModes--; + printModeRejectMessage(scrp->scrnIndex, p, p->status); + } + } + } + if (linePitches != NULL) { + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= virtX) && + (linePitches[i] == + scanLineWidth(virtX, virtY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + linePitch = linePitches[i]; + break; + } + } + } + else { + linePitch = scanLineWidth(virtX, virtY, minPitch, + apertureSize, BankFormat, pitchInc); + } + } } /* Update the ScrnInfoRec parameters */ - + scrp->virtualX = virtX; scrp->virtualY = virtY; scrp->displayWidth = linePitch; if (numModes <= 0) - return 0; - + return 0; + /* Make the mode list into a circular list by joining up the ends */ p = scrp->modes; while (p->next != NULL) - p = p->next; + p = p->next; /* p is now the last mode on the list */ p->next = scrp->modes; scrp->modes->prev = p; if (minHeight > 0 && virtY < minHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too small for the hardware " - "(min %d)\n", virtY, minHeight); - return -1; + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too small for the hardware " + "(min %d)\n", virtY, minHeight); + return -1; } return numModes; @@ -1959,26 +1978,27 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, * - doubly linked circular lists * */ - + void -xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode) +xf86DeleteMode(DisplayModePtr * modeList, DisplayModePtr mode) { /* Catch the easy/insane cases */ if (modeList == NULL || *modeList == NULL || mode == NULL) - return; + return; /* If the mode is at the start of the list, move the start of the list */ if (*modeList == mode) - *modeList = mode->next; + *modeList = mode->next; /* If mode is the only one on the list, set the list to NULL */ if ((mode == mode->prev) && (mode == mode->next)) { - *modeList = NULL; - } else { - if ((mode->prev != NULL) && (mode->prev->next == mode)) - mode->prev->next = mode->next; - if ((mode->next != NULL) && (mode->next->prev == mode)) - mode->next->prev = mode->prev; + *modeList = NULL; + } + else { + if ((mode->prev != NULL) && (mode->prev->next == mode)) + mode->prev->next = mode->next; + if ((mode->next != NULL) && (mode->next->prev == mode)) + mode->next->prev = mode->prev; } free(mode->name); @@ -1999,32 +2019,31 @@ xf86PruneDriverModes(ScrnInfoPtr scrp) p = scrp->modes; if (p == NULL) - return; + return; do { - if (!(first = scrp->modes)) - return; - n = p->next; - if (p->status != MODE_OK) { - xf86DeleteMode(&(scrp->modes), p); - } - p = n; + if (!(first = scrp->modes)) + return; + n = p->next; + if (p->status != MODE_OK) { + xf86DeleteMode(&(scrp->modes), p); + } + p = n; } while (p != NULL && p != first); /* modePool is no longer needed, turf it */ while (scrp->modePool) { - /* - * A modePool mode's prev field is used to hold a pointer to the - * member of the scrp->modes list for which a match was considered. - * Clear that pointer first, otherwise xf86DeleteMode might get - * confused - */ - scrp->modePool->prev = NULL; - xf86DeleteMode(&scrp->modePool, scrp->modePool); + /* + * A modePool mode's prev field is used to hold a pointer to the + * member of the scrp->modes list for which a match was considered. + * Clear that pointer first, otherwise xf86DeleteMode might get + * confused + */ + scrp->modePool->prev = NULL; + xf86DeleteMode(&scrp->modePool, scrp->modePool); } } - /* * xf86SetCrtcForModes * @@ -2045,18 +2064,18 @@ xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags) p = scrp->modes; if (p == NULL) - return; + return; do { - xf86SetModeCrtc(p, adjustFlags); - DebugF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n", - (p->type & M_T_DEFAULT) ? "Default " : "", - p->name, p->CrtcHDisplay, p->CrtcHBlankStart, - p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd, - p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart, - p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd, - p->CrtcVTotal); - p = p->next; + xf86SetModeCrtc(p, adjustFlags); + DebugF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n", + (p->type & M_T_DEFAULT) ? "Default " : "", + p->name, p->CrtcHDisplay, p->CrtcHBlankStart, + p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd, + p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart, + p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd, + p->CrtcVTotal); + p = p->next; } while (p != NULL && p != scrp->modes); } @@ -2068,63 +2087,65 @@ xf86PrintModes(ScrnInfoPtr scrp) const char *desc, *desc2, *prefix, *uprefix; if (scrp == NULL) - return; + return; xf86DrvMsg(scrp->scrnIndex, scrp->virtualFrom, "Virtual size is %dx%d " - "(pitch %d)\n", scrp->virtualX, scrp->virtualY, - scrp->displayWidth); - + "(pitch %d)\n", scrp->virtualX, scrp->virtualY, + scrp->displayWidth); + p = scrp->modes; if (p == NULL) - return; + return; do { - desc = desc2 = ""; - hsync = xf86ModeHSync(p); - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) { - desc = " (I)"; - } - if (p->Flags & V_DBLSCAN) { - desc = " (D)"; - } - if (p->VScan > 1) { - desc2 = " (VScan)"; - } - if (p->type & M_T_BUILTIN) - prefix = "Built-in mode"; - else if (p->type & M_T_DEFAULT) - prefix = "Default mode"; - else if (p->type & M_T_DRIVER) - prefix = "Driver mode"; - else - prefix = "Mode"; - if (p->type & M_T_USERDEF) - uprefix = "*"; - else - uprefix = " "; - if (hsync == 0 || refresh == 0) { - if (p->name) - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\"\n", uprefix, prefix, p->name); - else - xf86DrvMsg(scrp->scrnIndex, X_PROBED, - "%s%s %dx%d (unnamed)\n", - uprefix, prefix, p->HDisplay, p->VDisplay); - } else if (p->Clock == p->SynthClock) { - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n", - uprefix, prefix, p->name, p->Clock / 1000.0, - hsync, refresh, desc, desc2); - } else { - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), " - "%.1f kHz, %.1f Hz%s%s\n", - uprefix, prefix, p->name, p->Clock / 1000.0, - p->SynthClock / 1000.0, hsync, refresh, desc, desc2); - } - if (hsync != 0 && refresh != 0) - xf86PrintModeline(scrp->scrnIndex,p); - p = p->next; + desc = desc2 = ""; + hsync = xf86ModeHSync(p); + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) { + desc = " (I)"; + } + if (p->Flags & V_DBLSCAN) { + desc = " (D)"; + } + if (p->VScan > 1) { + desc2 = " (VScan)"; + } + if (p->type & M_T_BUILTIN) + prefix = "Built-in mode"; + else if (p->type & M_T_DEFAULT) + prefix = "Default mode"; + else if (p->type & M_T_DRIVER) + prefix = "Driver mode"; + else + prefix = "Mode"; + if (p->type & M_T_USERDEF) + uprefix = "*"; + else + uprefix = " "; + if (hsync == 0 || refresh == 0) { + if (p->name) + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\"\n", uprefix, prefix, p->name); + else + xf86DrvMsg(scrp->scrnIndex, X_PROBED, + "%s%s %dx%d (unnamed)\n", + uprefix, prefix, p->HDisplay, p->VDisplay); + } + else if (p->Clock == p->SynthClock) { + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n", + uprefix, prefix, p->name, p->Clock / 1000.0, + hsync, refresh, desc, desc2); + } + else { + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), " + "%.1f kHz, %.1f Hz%s%s\n", + uprefix, prefix, p->name, p->Clock / 1000.0, + p->SynthClock / 1000.0, hsync, refresh, desc, desc2); + } + if (hsync != 0 && refresh != 0) + xf86PrintModeline(scrp->scrnIndex, p); + p = p->next; } while (p != NULL && p != scrp->modes); } diff --git a/xorg-server/hw/xfree86/common/xf86Module.h b/xorg-server/hw/xfree86/common/xf86Module.h index 1de87dbbe..894b93f59 100644 --- a/xorg-server/hw/xfree86/common/xf86Module.h +++ b/xorg-server/hw/xfree86/common/xf86Module.h @@ -47,10 +47,10 @@ #endif typedef enum { - LD_RESOLV_IFDONE = 0, /* only check if no more - delays pending */ - LD_RESOLV_NOW = 1, /* finish one delay step */ - LD_RESOLV_FORCE = 2 /* force checking... */ + LD_RESOLV_IFDONE = 0, /* only check if no more + delays pending */ + LD_RESOLV_NOW = 1, /* finish one delay step */ + LD_RESOLV_FORCE = 2 /* force checking... */ } LoaderResolveOptions; #define DEFAULT_LIST ((char *)-1) @@ -97,21 +97,21 @@ typedef enum { /* Error return codes for errmaj. New codes must only be added at the end. */ typedef enum { LDR_NOERROR = 0, - LDR_NOMEM, /* memory allocation failed */ - LDR_NOENT, /* Module file does not exist */ - LDR_NOSUBENT, /* pre-requsite file to be sub-loaded does not exist */ - LDR_NOSPACE, /* internal module array full */ - LDR_NOMODOPEN, /* module file could not be opened (check errmin) */ - LDR_UNKTYPE, /* file is not a recognized module type */ - LDR_NOLOAD, /* type specific loader failed */ - LDR_ONCEONLY, /* Module should only be loaded once (not an error) */ - LDR_NOPORTOPEN, /* could not open port (check errmin) */ - LDR_NOHARDWARE, /* could not query/initialize the hardware device */ - LDR_MISMATCH, /* the module didn't match the spec'd requirments */ - LDR_BADUSAGE, /* LoadModule is called with bad arguments */ - LDR_INVALID, /* The module doesn't have a valid ModuleData object */ - LDR_BADOS, /* The module doesn't support the OS */ - LDR_MODSPECIFIC /* A module-specific error in the SetupProc */ + LDR_NOMEM, /* memory allocation failed */ + LDR_NOENT, /* Module file does not exist */ + LDR_NOSUBENT, /* pre-requsite file to be sub-loaded does not exist */ + LDR_NOSPACE, /* internal module array full */ + LDR_NOMODOPEN, /* module file could not be opened (check errmin) */ + LDR_UNKTYPE, /* file is not a recognized module type */ + LDR_NOLOAD, /* type specific loader failed */ + LDR_ONCEONLY, /* Module should only be loaded once (not an error) */ + LDR_NOPORTOPEN, /* could not open port (check errmin) */ + LDR_NOHARDWARE, /* could not query/initialize the hardware device */ + LDR_MISMATCH, /* the module didn't match the spec'd requirments */ + LDR_BADUSAGE, /* LoadModule is called with bad arguments */ + LDR_INVALID, /* The module doesn't have a valid ModuleData object */ + LDR_BADOS, /* The module doesn't support the OS */ + LDR_MODSPECIFIC /* A module-specific error in the SetupProc */ } LoaderErrorCode; /* @@ -129,19 +129,19 @@ typedef enum { /* This structure is expected to be returned by the initfunc */ typedef struct { - const char * modname; /* name of module, e.g. "foo" */ - const char * vendor; /* vendor specific string */ - CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ - CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */ - CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ - CARD8 majorversion; /* module-specific major version */ - CARD8 minorversion; /* module-specific minor version */ - CARD16 patchlevel; /* module-specific patch level */ - const char * abiclass; /* ABI class that the module uses */ - CARD32 abiversion; /* ABI version */ - const char * moduleclass; /* module class description */ - CARD32 checksum[4]; /* contains a digital signature of the */ - /* version info structure */ + const char *modname; /* name of module, e.g. "foo" */ + const char *vendor; /* vendor specific string */ + CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ + CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */ + CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ + CARD8 majorversion; /* module-specific major version */ + CARD8 minorversion; /* module-specific minor version */ + CARD16 patchlevel; /* module-specific patch level */ + const char *abiclass; /* ABI class that the module uses */ + CARD32 abiversion; /* ABI version */ + const char *moduleclass; /* module class description */ + CARD32 checksum[4]; /* contains a digital signature of the */ + /* version info structure */ } XF86ModuleVersionInfo; /* @@ -149,12 +149,12 @@ typedef struct { * specify version and/or ABI requirements. */ typedef struct { - CARD8 majorversion; /* module-specific major version */ - CARD8 minorversion; /* moudle-specific minor version */ - CARD16 patchlevel; /* module-specific patch level */ - const char * abiclass; /* ABI class that the module uses */ - CARD32 abiversion; /* ABI version */ - const char * moduleclass; /* module class */ + CARD8 majorversion; /* module-specific major version */ + CARD8 minorversion; /* moudle-specific minor version */ + CARD16 patchlevel; /* module-specific patch level */ + const char *abiclass; /* ABI class that the module uses */ + CARD32 abiversion; /* ABI version */ + const char *moduleclass; /* module class */ } XF86ModReqInfo; /* values to indicate unspecified fields in XF86ModReqInfo. */ @@ -171,42 +171,44 @@ typedef struct { #define INITARGS void -typedef void (*InitExtension)(INITARGS); +typedef void (*InitExtension) (INITARGS); typedef struct { - InitExtension initFunc; - const char * name; - Bool *disablePtr; - InitExtension setupFunc; - const char ** initDependencies; + InitExtension initFunc; + const char *name; + Bool *disablePtr; + InitExtension setupFunc; + const char **initDependencies; } ExtensionModule; extern _X_EXPORT ExtensionModule *ExtensionModuleList; /* Prototypes for Loader functions that are exported to modules */ extern _X_EXPORT pointer LoadSubModule(pointer, const char *, const char **, - const char **, pointer, const XF86ModReqInfo *, - int *, int *); + const char **, pointer, + const XF86ModReqInfo *, int *, int *); extern _X_EXPORT void UnloadSubModule(pointer); -extern _X_EXPORT void UnloadModule (pointer); +extern _X_EXPORT void UnloadModule(pointer); extern _X_EXPORT pointer LoaderSymbol(const char *); extern _X_EXPORT char **LoaderListDirs(const char **, const char **); extern _X_EXPORT void LoaderFreeDirList(char **); extern _X_EXPORT void LoaderErrorMsg(const char *, const char *, int, int); extern _X_EXPORT void LoadExtension(ExtensionModule *, Bool); -extern _X_EXPORT void LoaderGetOS(const char **name, int *major, int *minor, int *teeny); +extern _X_EXPORT void LoaderGetOS(const char **name, int *major, int *minor, + int *teeny); extern _X_EXPORT Bool LoaderShouldIgnoreABI(void); extern _X_EXPORT int LoaderGetABIVersion(const char *abiclass); -typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *); -typedef void (*ModuleTearDownProc)(pointer); +typedef pointer (*ModuleSetupProc) (pointer, pointer, int *, int *); +typedef void (*ModuleTearDownProc) (pointer); + #define MODULESETUPPROTO(func) pointer func(pointer, pointer, int*, int*) #define MODULETEARDOWNPROTO(func) void func(pointer) typedef struct { - XF86ModuleVersionInfo * vers; - ModuleSetupProc setup; - ModuleTearDownProc teardown; + XF86ModuleVersionInfo *vers; + ModuleSetupProc setup; + ModuleTearDownProc teardown; } XF86ModuleData; -#endif /* _XF86STR_H */ +#endif /* _XF86STR_H */ diff --git a/xorg-server/hw/xfree86/common/xf86Opt.h b/xorg-server/hw/xfree86/common/xf86Opt.h index b0fdaa6b6..0d808de14 100644 --- a/xorg-server/hw/xfree86/common/xf86Opt.h +++ b/xorg-server/hw/xfree86/common/xf86Opt.h @@ -38,13 +38,13 @@ typedef struct { } OptFrequency; typedef union { - unsigned long num; - char * str; - double realnum; - Bool bool; - OptFrequency freq; + unsigned long num; + char *str; + double realnum; + Bool bool; + OptFrequency freq; } ValueUnion; - + typedef enum { OPTV_NONE = 0, OPTV_INTEGER, @@ -63,57 +63,96 @@ typedef enum { } OptFreqUnits; typedef struct { - int token; - const char* name; - OptionValueType type; - ValueUnion value; - Bool found; + int token; + const char *name; + OptionValueType type; + ValueUnion value; + Bool found; } OptionInfoRec, *OptionInfoPtr; -extern _X_EXPORT int xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt); -extern _X_EXPORT double xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt); -extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt); -extern _X_EXPORT int xf86SetBoolOption(XF86OptionPtr list, const char *name, int deflt ); -extern _X_EXPORT double xf86SetPercentOption(XF86OptionPtr list, const char *name, double deflt ); -extern _X_EXPORT int xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt); -extern _X_EXPORT double xf86CheckRealOption(XF86OptionPtr optlist, const char *name, double deflt); -extern _X_EXPORT char *xf86CheckStrOption(XF86OptionPtr optlist, const char *name, char *deflt); -extern _X_EXPORT int xf86CheckBoolOption(XF86OptionPtr list, const char *name, int deflt ); -extern _X_EXPORT double xf86CheckPercentOption(XF86OptionPtr list, const char *name, double deflt ); -extern _X_EXPORT XF86OptionPtr xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val ); -extern _X_EXPORT XF86OptionPtr xf86NewOption(char *name, char *value ); -extern _X_EXPORT XF86OptionPtr xf86NextOption(XF86OptionPtr list ); -extern _X_EXPORT XF86OptionPtr xf86OptionListCreate(const char **options, int count, int used); -extern _X_EXPORT XF86OptionPtr xf86OptionListMerge(XF86OptionPtr head, XF86OptionPtr tail); +extern _X_EXPORT int xf86SetIntOption(XF86OptionPtr optlist, const char *name, + int deflt); +extern _X_EXPORT double xf86SetRealOption(XF86OptionPtr optlist, + const char *name, double deflt); +extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, + const char *deflt); +extern _X_EXPORT int xf86SetBoolOption(XF86OptionPtr list, const char *name, + int deflt); +extern _X_EXPORT double xf86SetPercentOption(XF86OptionPtr list, + const char *name, double deflt); +extern _X_EXPORT int xf86CheckIntOption(XF86OptionPtr optlist, const char *name, + int deflt); +extern _X_EXPORT double xf86CheckRealOption(XF86OptionPtr optlist, + const char *name, double deflt); +extern _X_EXPORT char *xf86CheckStrOption(XF86OptionPtr optlist, + const char *name, char *deflt); +extern _X_EXPORT int xf86CheckBoolOption(XF86OptionPtr list, const char *name, + int deflt); +extern _X_EXPORT double xf86CheckPercentOption(XF86OptionPtr list, + const char *name, double deflt); +extern _X_EXPORT XF86OptionPtr xf86AddNewOption(XF86OptionPtr head, + const char *name, + const char *val); +extern _X_EXPORT XF86OptionPtr xf86NewOption(char *name, char *value); +extern _X_EXPORT XF86OptionPtr xf86NextOption(XF86OptionPtr list); +extern _X_EXPORT XF86OptionPtr xf86OptionListCreate(const char **options, + int count, int used); +extern _X_EXPORT XF86OptionPtr xf86OptionListMerge(XF86OptionPtr head, + XF86OptionPtr tail); extern _X_EXPORT XF86OptionPtr xf86OptionListDuplicate(XF86OptionPtr list); extern _X_EXPORT void xf86OptionListFree(XF86OptionPtr opt); extern _X_EXPORT char *xf86OptionName(XF86OptionPtr opt); extern _X_EXPORT char *xf86OptionValue(XF86OptionPtr opt); extern _X_EXPORT void xf86OptionListReport(XF86OptionPtr parm); -extern _X_EXPORT XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name); -extern _X_EXPORT const char *xf86FindOptionValue(XF86OptionPtr options, const char *name); +extern _X_EXPORT XF86OptionPtr xf86FindOption(XF86OptionPtr options, + const char *name); +extern _X_EXPORT const char *xf86FindOptionValue(XF86OptionPtr options, + const char *name); extern _X_EXPORT void xf86MarkOptionUsed(XF86OptionPtr option); -extern _X_EXPORT void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name); +extern _X_EXPORT void xf86MarkOptionUsedByName(XF86OptionPtr options, + const char *name); extern _X_EXPORT Bool xf86CheckIfOptionUsed(XF86OptionPtr option); -extern _X_EXPORT Bool xf86CheckIfOptionUsedByName(XF86OptionPtr options, const char *name); -extern _X_EXPORT void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options); -extern _X_EXPORT void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, OptionInfoPtr optinfo); -extern _X_EXPORT OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table, int token); -extern _X_EXPORT const char *xf86TokenToOptName(const OptionInfoRec *table, int token); -extern _X_EXPORT Bool xf86IsOptionSet(const OptionInfoRec *table, int token); -extern _X_EXPORT char *xf86GetOptValString(const OptionInfoRec *table, int token); -extern _X_EXPORT Bool xf86GetOptValInteger(const OptionInfoRec *table, int token, int *value); -extern _X_EXPORT Bool xf86GetOptValULong(const OptionInfoRec *table, int token, unsigned long *value); -extern _X_EXPORT Bool xf86GetOptValReal(const OptionInfoRec *table, int token, double *value); -extern _X_EXPORT Bool xf86GetOptValFreq(const OptionInfoRec *table, int token, - OptFreqUnits expectedUnits, double *value); -extern _X_EXPORT Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value); -extern _X_EXPORT Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def); +extern _X_EXPORT Bool xf86CheckIfOptionUsedByName(XF86OptionPtr options, + const char *name); +extern _X_EXPORT void xf86ShowUnusedOptions(int scrnIndex, + XF86OptionPtr options); +extern _X_EXPORT void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, + OptionInfoPtr optinfo); +extern _X_EXPORT OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec * table, + int token); +extern _X_EXPORT const char *xf86TokenToOptName(const OptionInfoRec * table, + int token); +extern _X_EXPORT Bool xf86IsOptionSet(const OptionInfoRec * table, int token); +extern _X_EXPORT char *xf86GetOptValString(const OptionInfoRec * table, + int token); +extern _X_EXPORT Bool xf86GetOptValInteger(const OptionInfoRec * table, + int token, int *value); +extern _X_EXPORT Bool xf86GetOptValULong(const OptionInfoRec * table, int token, + unsigned long *value); +extern _X_EXPORT Bool xf86GetOptValReal(const OptionInfoRec * table, int token, + double *value); +extern _X_EXPORT Bool xf86GetOptValFreq(const OptionInfoRec * table, int token, + OptFreqUnits expectedUnits, + double *value); +extern _X_EXPORT Bool xf86GetOptValBool(const OptionInfoRec * table, int token, + Bool *value); +extern _X_EXPORT Bool xf86ReturnOptValBool(const OptionInfoRec * table, + int token, Bool def); extern _X_EXPORT int xf86NameCmp(const char *s1, const char *s2); extern _X_EXPORT char *xf86NormalizeName(const char *s); -extern _X_EXPORT XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceBoolOption(XF86OptionPtr optlist, const char *name, const Bool val); -extern _X_EXPORT XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceStrOption(XF86OptionPtr optlist, const char *name, const char* val); +extern _X_EXPORT XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, + const char *name, + const int val); +extern _X_EXPORT XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, + const char *name, + const double val); +extern _X_EXPORT XF86OptionPtr xf86ReplaceBoolOption(XF86OptionPtr optlist, + const char *name, + const Bool val); +extern _X_EXPORT XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, + const char *name, + const double val); +extern _X_EXPORT XF86OptionPtr xf86ReplaceStrOption(XF86OptionPtr optlist, + const char *name, + const char *val); #endif diff --git a/xorg-server/hw/xfree86/common/xf86Option.c b/xorg-server/hw/xfree86/common/xf86Option.c index dc0a01899..7cc744029 100644 --- a/xorg-server/hw/xfree86/common/xf86Option.c +++ b/xorg-server/hw/xfree86/common/xf86Option.c @@ -46,8 +46,8 @@ #include "xf86Parser.h" #include "optionstr.h" -static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p, - Bool markUsed); +static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, + OptionInfoPtr p, Bool markUsed); /* * xf86CollectOptions collects the options from each of the config file @@ -71,51 +71,51 @@ void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts) { XF86OptionPtr tmp; - XF86OptionPtr extras = (XF86OptionPtr)extraOpts; + XF86OptionPtr extras = (XF86OptionPtr) extraOpts; GDevPtr device; - + int i; pScrn->options = NULL; - for (i=pScrn->numEntities - 1; i >= 0; i--) { - device = xf86GetDevFromEntity(pScrn->entityList[i], - pScrn->entityInstanceList[i]); - if (device && device->options) { - tmp = xf86optionListDup(device->options); - if (pScrn->options) - xf86optionListMerge(pScrn->options,tmp); - else - pScrn->options = tmp; - } + for (i = pScrn->numEntities - 1; i >= 0; i--) { + device = xf86GetDevFromEntity(pScrn->entityList[i], + pScrn->entityInstanceList[i]); + if (device && device->options) { + tmp = xf86optionListDup(device->options); + if (pScrn->options) + xf86optionListMerge(pScrn->options, tmp); + else + pScrn->options = tmp; + } } if (pScrn->monitor->options) { - tmp = xf86optionListDup(pScrn->monitor->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; + tmp = xf86optionListDup(pScrn->monitor->options); + if (pScrn->options) + pScrn->options = xf86optionListMerge(pScrn->options, tmp); + else + pScrn->options = tmp; } if (pScrn->confScreen->options) { - tmp = xf86optionListDup(pScrn->confScreen->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; + tmp = xf86optionListDup(pScrn->confScreen->options); + if (pScrn->options) + pScrn->options = xf86optionListMerge(pScrn->options, tmp); + else + pScrn->options = tmp; } if (pScrn->display->options) { - tmp = xf86optionListDup(pScrn->display->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; + tmp = xf86optionListDup(pScrn->display->options); + if (pScrn->options) + pScrn->options = xf86optionListMerge(pScrn->options, tmp); + else + pScrn->options = tmp; } if (extras) { - tmp = xf86optionListDup(extras); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; + tmp = xf86optionListDup(extras); + if (pScrn->options) + pScrn->options = xf86optionListMerge(pScrn->options, tmp); + else + pScrn->options = tmp; } } @@ -130,11 +130,12 @@ void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts) { if (defaultOpts) { - XF86OptionPtr tmp =xf86optionListCreate(defaultOpts, -1, 0); - if (pInfo->options) - pInfo->options = xf86optionListMerge(tmp, pInfo->options); - else - pInfo->options = tmp; + XF86OptionPtr tmp = xf86optionListCreate(defaultOpts, -1, 0); + + if (pInfo->options) + pInfo->options = xf86optionListMerge(tmp, pInfo->options); + else + pInfo->options = tmp; } } @@ -147,47 +148,46 @@ xf86OptionListDuplicate(XF86OptionPtr options) { XF86OptionPtr o = NULL; - while (options) - { - o = xf86AddNewOption(o, xf86OptionName(options), xf86OptionValue(options)); + while (options) { + o = xf86AddNewOption(o, xf86OptionName(options), + xf86OptionValue(options)); options = xf86nextOption(options); } return o; } - /* Created for new XInput stuff -- essentially extensions to the parser */ static int -LookupIntOption(XF86OptionPtr optlist, const char *name, int deflt, Bool markUsed) +LookupIntOption(XF86OptionPtr optlist, const char *name, int deflt, + Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_INTEGER; if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.num; + deflt = o.value.num; return deflt; } - static double LookupRealOption(XF86OptionPtr optlist, const char *name, double deflt, - Bool markUsed) + Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_REAL; if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.realnum; + deflt = o.value.realnum; return deflt; } - static char * -LookupStrOption(XF86OptionPtr optlist, const char *name, const char *deflt, Bool markUsed) +LookupStrOption(XF86OptionPtr optlist, const char *name, const char *deflt, + Bool markUsed) { OptionInfoRec o; @@ -196,33 +196,34 @@ LookupStrOption(XF86OptionPtr optlist, const char *name, const char *deflt, Bool if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.str; if (deflt) - return strdup(deflt); + return strdup(deflt); else - return NULL; + return NULL; } - static int -LookupBoolOption(XF86OptionPtr optlist, const char *name, int deflt, Bool markUsed) +LookupBoolOption(XF86OptionPtr optlist, const char *name, int deflt, + Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_BOOLEAN; if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.bool; + deflt = o.value.bool; return deflt; } static double -LookupPercentOption(XF86OptionPtr optlist, const char *name, double deflt, Bool markUsed) +LookupPercentOption(XF86OptionPtr optlist, const char *name, double deflt, + Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_PERCENT; if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.realnum; + deflt = o.value.realnum; return deflt; } @@ -234,21 +235,18 @@ xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt) return LookupIntOption(optlist, name, deflt, TRUE); } - double xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt) { return LookupRealOption(optlist, name, deflt, TRUE); } - char * xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt) { return LookupStrOption(optlist, name, deflt, TRUE); } - int xf86SetBoolOption(XF86OptionPtr optlist, const char *name, int deflt) { @@ -271,33 +269,30 @@ xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt) return LookupIntOption(optlist, name, deflt, FALSE); } - double xf86CheckRealOption(XF86OptionPtr optlist, const char *name, double deflt) { return LookupRealOption(optlist, name, deflt, FALSE); } - char * xf86CheckStrOption(XF86OptionPtr optlist, const char *name, char *deflt) { return LookupStrOption(optlist, name, deflt, FALSE); } - int xf86CheckBoolOption(XF86OptionPtr optlist, const char *name, int deflt) { return LookupBoolOption(optlist, name, deflt, FALSE); } - double xf86CheckPercentOption(XF86OptionPtr optlist, const char *name, double deflt) { return LookupPercentOption(optlist, name, deflt, FALSE); } + /* * xf86AddNewOption() has the required property of replacing the option value * if the option is already present. @@ -306,36 +301,40 @@ XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val) { char tmp[16]; - snprintf(tmp,sizeof(tmp),"%i",val); - return xf86AddNewOption(optlist,name,tmp); + + snprintf(tmp, sizeof(tmp), "%i", val); + return xf86AddNewOption(optlist, name, tmp); } XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val) { char tmp[32]; - snprintf(tmp,sizeof(tmp),"%f",val); - return xf86AddNewOption(optlist,name,tmp); + + snprintf(tmp, sizeof(tmp), "%f", val); + return xf86AddNewOption(optlist, name, tmp); } XF86OptionPtr xf86ReplaceBoolOption(XF86OptionPtr optlist, const char *name, const Bool val) { - return xf86AddNewOption(optlist,name,val?"True":"False"); + return xf86AddNewOption(optlist, name, val ? "True" : "False"); } XF86OptionPtr -xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val) +xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, + const double val) { char tmp[16]; + snprintf(tmp, sizeof(tmp), "%lf%%", val); - return xf86AddNewOption(optlist,name,tmp); + return xf86AddNewOption(optlist, name, tmp); } XF86OptionPtr -xf86ReplaceStrOption(XF86OptionPtr optlist, const char *name, const char* val) +xf86ReplaceStrOption(XF86OptionPtr optlist, const char *name, const char *val) { - return xf86AddNewOption(optlist,name,val); + return xf86AddNewOption(optlist, name, val); } XF86OptionPtr @@ -348,14 +347,12 @@ xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val) return xf86addNewOption(head, tmp_name, tmp); } - XF86OptionPtr xf86NewOption(char *name, char *value) { return xf86newOption(name, value); } - XF86OptionPtr xf86NextOption(XF86OptionPtr list) { @@ -365,31 +362,31 @@ xf86NextOption(XF86OptionPtr list) XF86OptionPtr xf86OptionListCreate(const char **options, int count, int used) { - return xf86optionListCreate(options, count, used); + return xf86optionListCreate(options, count, used); } XF86OptionPtr xf86OptionListMerge(XF86OptionPtr head, XF86OptionPtr tail) { - return xf86optionListMerge(head, tail); + return xf86optionListMerge(head, tail); } void xf86OptionListFree(XF86OptionPtr opt) { - xf86optionListFree(opt); + xf86optionListFree(opt); } char * xf86OptionName(XF86OptionPtr opt) { - return xf86optionName(opt); + return xf86optionName(opt); } char * xf86OptionValue(XF86OptionPtr opt) { - return xf86optionValue(opt); + return xf86optionValue(opt); } void @@ -397,13 +394,13 @@ xf86OptionListReport(XF86OptionPtr parm) { XF86OptionPtr opts = parm; - while(opts) { - if (xf86optionValue(opts)) - xf86ErrorFVerb(5, "\tOption \"%s\" \"%s\"\n", - xf86optionName(opts), xf86optionValue(opts)); - else - xf86ErrorFVerb( 5, "\tOption \"%s\"\n", xf86optionName(opts)); - opts = xf86nextOption(opts); + while (opts) { + if (xf86optionValue(opts)) + xf86ErrorFVerb(5, "\tOption \"%s\" \"%s\"\n", + xf86optionName(opts), xf86optionValue(opts)); + else + xf86ErrorFVerb(5, "\tOption \"%s\"\n", xf86optionName(opts)); + opts = xf86nextOption(opts); } } @@ -415,22 +412,19 @@ xf86FindOption(XF86OptionPtr options, const char *name) return xf86findOption(options, name); } - const char * xf86FindOptionValue(XF86OptionPtr options, const char *name) { return xf86findOptionValue(options, name); } - void xf86MarkOptionUsed(XF86OptionPtr option) { if (option != NULL) - option->opt_used = TRUE; + option->opt_used = TRUE; } - void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name) { @@ -438,16 +432,16 @@ xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name) opt = xf86findOption(options, name); if (opt != NULL) - opt->opt_used = TRUE; + opt->opt_used = TRUE; } Bool xf86CheckIfOptionUsed(XF86OptionPtr option) { if (option != NULL) - return option->opt_used; + return option->opt_used; else - return FALSE; + return FALSE; } Bool @@ -457,24 +451,23 @@ xf86CheckIfOptionUsedByName(XF86OptionPtr options, const char *name) opt = xf86findOption(options, name); if (opt != NULL) - return opt->opt_used; + return opt->opt_used; else - return FALSE; + return FALSE; } void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr opt) { while (opt) { - if (opt->opt_name && !opt->opt_used) { - xf86DrvMsg(scrnIndex, X_WARNING, "Option \"%s\" is not used\n", - opt->opt_name); - } - opt = opt->list.next; + if (opt->opt_name && !opt->opt_used) { + xf86DrvMsg(scrnIndex, X_WARNING, "Option \"%s\" is not used\n", + opt->opt_name); + } + opt = opt->list.next; } } - static Bool GetBoolValue(OptionInfoPtr p, const char *s) { @@ -483,257 +476,269 @@ GetBoolValue(OptionInfoPtr p, const char *s) static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p, - Bool markUsed) + Bool markUsed) { char *s, *end; Bool wasUsed = FALSE; if ((s = xf86findOptionValue(options, p->name)) != NULL) { - if (markUsed) { - wasUsed = xf86CheckIfOptionUsedByName(options, p->name); - xf86MarkOptionUsedByName(options, p->name); - } - switch (p->type) { - case OPTV_INTEGER: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires an integer value\n", - p->name); - } - p->found = FALSE; - } else { - p->value.num = strtoul(s, &end, 0); - if (*end == '\0') { - p->found = TRUE; - } else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires an integer value\n", - p->name); - } - p->found = FALSE; - } - } - break; - case OPTV_STRING: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires an string value\n", - p->name); - } - p->found = FALSE; - } else { - p->value.str = s; - p->found = TRUE; - } - break; - case OPTV_ANYSTR: - p->value.str = s; - p->found = TRUE; - break; - case OPTV_REAL: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a floating point " - "value\n", p->name); - } - p->found = FALSE; - } else { - p->value.realnum = strtod(s, &end); - if (*end == '\0') { - p->found = TRUE; - } else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a floating point " - "value\n", p->name); - } - p->found = FALSE; - } - } - break; - case OPTV_BOOLEAN: - if (GetBoolValue(p, s)) { - p->found = TRUE; - } else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a boolean value\n", - p->name); - } - p->found = FALSE; - } - break; - case OPTV_PERCENT: - { - char tmp = 0; - /* awkward match, but %% doesn't increase the match counter, - * hence 100 looks the same as 100% to the caller of sccanf - */ - if (sscanf(s, "%lf%c", &p->value.realnum, &tmp) != 2 || tmp != '%') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a percent value\n", p->name); - } - p->found = FALSE; - } else { - p->found = TRUE; - } - } - break; - case OPTV_FREQ: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } else { - double freq = strtod(s, &end); - int units = 0; - - if (end != s) { - p->found = TRUE; - if (!xf86NameCmp(end, "Hz")) - units = 1; - else if (!xf86NameCmp(end, "kHz") || - !xf86NameCmp(end, "k")) - units = 1000; - else if (!xf86NameCmp(end, "MHz") || - !xf86NameCmp(end, "M")) - units = 1000000; - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } - if (p->found) - freq *= (double)units; - } else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } - if (p->found) { - p->value.freq.freq = freq; - p->value.freq.units = units; - } - } - break; - case OPTV_NONE: - /* Should never get here */ - p->found = FALSE; - break; - } - if (p->found && markUsed) { - int verb = 2; - if (wasUsed) - verb = 4; - xf86DrvMsgVerb(scrnIndex, X_CONFIG, verb, "Option \"%s\"", p->name); - if (!(p->type == OPTV_BOOLEAN && *s == 0)) { - xf86ErrorFVerb(verb, " \"%s\"", s); - } - xf86ErrorFVerb(verb, "\n"); - } - } else if (p->type == OPTV_BOOLEAN) { - /* Look for matches with options with or without a "No" prefix. */ - char *n, *newn; - OptionInfoRec opt; - - n = xf86NormalizeName(p->name); - if (!n) { - p->found = FALSE; - return FALSE; - } - if (strncmp(n, "no", 2) == 0) { - newn = n + 2; - } else { - free(n); - if (asprintf(&n, "No%s", p->name) == -1) { - p->found = FALSE; - return FALSE; - } - newn = n; - } - if ((s = xf86findOptionValue(options, newn)) != NULL) { - if (markUsed) - xf86MarkOptionUsedByName(options, newn); - if (GetBoolValue(&opt, s)) { - p->value.bool = !opt.value.bool; - p->found = TRUE; - } else { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a boolean value\n", newn); - p->found = FALSE; - } - } else { - p->found = FALSE; - } - if (p->found && markUsed) { - xf86DrvMsgVerb(scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn); - if (*s != 0) { - xf86ErrorFVerb(2, " \"%s\"", s); - } - xf86ErrorFVerb(2, "\n"); - } - free(n); - } else { - p->found = FALSE; + if (markUsed) { + wasUsed = xf86CheckIfOptionUsedByName(options, p->name); + xf86MarkOptionUsedByName(options, p->name); + } + switch (p->type) { + case OPTV_INTEGER: + if (*s == '\0') { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires an integer value\n", + p->name); + } + p->found = FALSE; + } + else { + p->value.num = strtoul(s, &end, 0); + if (*end == '\0') { + p->found = TRUE; + } + else { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires an integer value\n", + p->name); + } + p->found = FALSE; + } + } + break; + case OPTV_STRING: + if (*s == '\0') { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires an string value\n", + p->name); + } + p->found = FALSE; + } + else { + p->value.str = s; + p->found = TRUE; + } + break; + case OPTV_ANYSTR: + p->value.str = s; + p->found = TRUE; + break; + case OPTV_REAL: + if (*s == '\0') { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a floating point " + "value\n", p->name); + } + p->found = FALSE; + } + else { + p->value.realnum = strtod(s, &end); + if (*end == '\0') { + p->found = TRUE; + } + else { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a floating point " + "value\n", p->name); + } + p->found = FALSE; + } + } + break; + case OPTV_BOOLEAN: + if (GetBoolValue(p, s)) { + p->found = TRUE; + } + else { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a boolean value\n", + p->name); + } + p->found = FALSE; + } + break; + case OPTV_PERCENT: + { + char tmp = 0; + + /* awkward match, but %% doesn't increase the match counter, + * hence 100 looks the same as 100% to the caller of sccanf + */ + if (sscanf(s, "%lf%c", &p->value.realnum, &tmp) != 2 || tmp != '%') { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a percent value\n", + p->name); + } + p->found = FALSE; + } + else { + p->found = TRUE; + } + } + break; + case OPTV_FREQ: + if (*s == '\0') { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + } + p->found = FALSE; + } + else { + double freq = strtod(s, &end); + int units = 0; + + if (end != s) { + p->found = TRUE; + if (!xf86NameCmp(end, "Hz")) + units = 1; + else if (!xf86NameCmp(end, "kHz") || !xf86NameCmp(end, "k")) + units = 1000; + else if (!xf86NameCmp(end, "MHz") || !xf86NameCmp(end, "M")) + units = 1000000; + else { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + } + p->found = FALSE; + } + if (p->found) + freq *= (double) units; + } + else { + if (markUsed) { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + } + p->found = FALSE; + } + if (p->found) { + p->value.freq.freq = freq; + p->value.freq.units = units; + } + } + break; + case OPTV_NONE: + /* Should never get here */ + p->found = FALSE; + break; + } + if (p->found && markUsed) { + int verb = 2; + + if (wasUsed) + verb = 4; + xf86DrvMsgVerb(scrnIndex, X_CONFIG, verb, "Option \"%s\"", p->name); + if (!(p->type == OPTV_BOOLEAN && *s == 0)) { + xf86ErrorFVerb(verb, " \"%s\"", s); + } + xf86ErrorFVerb(verb, "\n"); + } + } + else if (p->type == OPTV_BOOLEAN) { + /* Look for matches with options with or without a "No" prefix. */ + char *n, *newn; + OptionInfoRec opt; + + n = xf86NormalizeName(p->name); + if (!n) { + p->found = FALSE; + return FALSE; + } + if (strncmp(n, "no", 2) == 0) { + newn = n + 2; + } + else { + free(n); + if (asprintf(&n, "No%s", p->name) == -1) { + p->found = FALSE; + return FALSE; + } + newn = n; + } + if ((s = xf86findOptionValue(options, newn)) != NULL) { + if (markUsed) + xf86MarkOptionUsedByName(options, newn); + if (GetBoolValue(&opt, s)) { + p->value.bool = !opt.value.bool; + p->found = TRUE; + } + else { + xf86DrvMsg(scrnIndex, X_WARNING, + "Option \"%s\" requires a boolean value\n", newn); + p->found = FALSE; + } + } + else { + p->found = FALSE; + } + if (p->found && markUsed) { + xf86DrvMsgVerb(scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn); + if (*s != 0) { + xf86ErrorFVerb(2, " \"%s\"", s); + } + xf86ErrorFVerb(2, "\n"); + } + free(n); + } + else { + p->found = FALSE; } return p->found; } - void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, OptionInfoPtr optinfo) { OptionInfoPtr p; for (p = optinfo; p->name != NULL; p++) { - ParseOptionValue(scrnIndex, options, p, TRUE); + ParseOptionValue(scrnIndex, options, p, TRUE); } } - OptionInfoPtr -xf86TokenToOptinfo(const OptionInfoRec *table, int token) +xf86TokenToOptinfo(const OptionInfoRec * table, int token) { const OptionInfoRec *p, *match = NULL, *set = NULL; if (!table) { - ErrorF("xf86TokenToOptinfo: table is NULL\n"); - return NULL; + ErrorF("xf86TokenToOptinfo: table is NULL\n"); + return NULL; } for (p = table; p->token >= 0; p++) { - if (p->token == token) { - match = p; - if (p->found) - set = p; - } + if (p->token == token) { + match = p; + if (p->found) + set = p; + } } if (set) - return (OptionInfoPtr)set; + return (OptionInfoPtr) set; else if (match) - return (OptionInfoPtr)match; + return (OptionInfoPtr) match; else - return NULL; + return NULL; } - const char * -xf86TokenToOptName(const OptionInfoRec *table, int token) +xf86TokenToOptName(const OptionInfoRec * table, int token) { const OptionInfoRec *p; @@ -741,9 +746,8 @@ xf86TokenToOptName(const OptionInfoRec *table, int token) return p->name; } - Bool -xf86IsOptionSet(const OptionInfoRec *table, int token) +xf86IsOptionSet(const OptionInfoRec * table, int token) { OptionInfoPtr p; @@ -751,137 +755,136 @@ xf86IsOptionSet(const OptionInfoRec *table, int token) return p && p->found; } - char * -xf86GetOptValString(const OptionInfoRec *table, int token) +xf86GetOptValString(const OptionInfoRec * table, int token) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) - return p->value.str; + return p->value.str; else - return NULL; + return NULL; } - Bool -xf86GetOptValInteger(const OptionInfoRec *table, int token, int *value) +xf86GetOptValInteger(const OptionInfoRec * table, int token, int *value) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - *value = p->value.num; - return TRUE; - } else - return FALSE; + *value = p->value.num; + return TRUE; + } + else + return FALSE; } - Bool -xf86GetOptValULong(const OptionInfoRec *table, int token, unsigned long *value) +xf86GetOptValULong(const OptionInfoRec * table, int token, unsigned long *value) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - *value = p->value.num; - return TRUE; - } else - return FALSE; + *value = p->value.num; + return TRUE; + } + else + return FALSE; } - Bool -xf86GetOptValReal(const OptionInfoRec *table, int token, double *value) +xf86GetOptValReal(const OptionInfoRec * table, int token, double *value) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - *value = p->value.realnum; - return TRUE; - } else - return FALSE; + *value = p->value.realnum; + return TRUE; + } + else + return FALSE; } - Bool -xf86GetOptValFreq(const OptionInfoRec *table, int token, - OptFreqUnits expectedUnits, double *value) +xf86GetOptValFreq(const OptionInfoRec * table, int token, + OptFreqUnits expectedUnits, double *value) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - if (p->value.freq.units > 0) { - /* Units give, so the scaling is known. */ - switch (expectedUnits) { - case OPTUNITS_HZ: - *value = p->value.freq.freq; - break; - case OPTUNITS_KHZ: - *value = p->value.freq.freq / 1000.0; - break; - case OPTUNITS_MHZ: - *value = p->value.freq.freq / 1000000.0; - break; - } - } else { - /* No units given, so try to guess the scaling. */ - switch (expectedUnits) { - case OPTUNITS_HZ: - *value = p->value.freq.freq; - break; - case OPTUNITS_KHZ: - if (p->value.freq.freq > 1000.0) - *value = p->value.freq.freq / 1000.0; - else - *value = p->value.freq.freq; - break; - case OPTUNITS_MHZ: - if (p->value.freq.freq > 1000000.0) - *value = p->value.freq.freq / 1000000.0; - else if (p->value.freq.freq > 1000.0) - *value = p->value.freq.freq / 1000.0; - else - *value = p->value.freq.freq; - } - } - return TRUE; - } else - return FALSE; + if (p->value.freq.units > 0) { + /* Units give, so the scaling is known. */ + switch (expectedUnits) { + case OPTUNITS_HZ: + *value = p->value.freq.freq; + break; + case OPTUNITS_KHZ: + *value = p->value.freq.freq / 1000.0; + break; + case OPTUNITS_MHZ: + *value = p->value.freq.freq / 1000000.0; + break; + } + } + else { + /* No units given, so try to guess the scaling. */ + switch (expectedUnits) { + case OPTUNITS_HZ: + *value = p->value.freq.freq; + break; + case OPTUNITS_KHZ: + if (p->value.freq.freq > 1000.0) + *value = p->value.freq.freq / 1000.0; + else + *value = p->value.freq.freq; + break; + case OPTUNITS_MHZ: + if (p->value.freq.freq > 1000000.0) + *value = p->value.freq.freq / 1000000.0; + else if (p->value.freq.freq > 1000.0) + *value = p->value.freq.freq / 1000.0; + else + *value = p->value.freq.freq; + } + } + return TRUE; + } + else + return FALSE; } - Bool -xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value) +xf86GetOptValBool(const OptionInfoRec * table, int token, Bool *value) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - *value = p->value.bool; - return TRUE; - } else - return FALSE; + *value = p->value.bool; + return TRUE; + } + else + return FALSE; } - Bool -xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def) +xf86ReturnOptValBool(const OptionInfoRec * table, int token, Bool def) { OptionInfoPtr p; p = xf86TokenToOptinfo(table, token); if (p && p->found) { - return p->value.bool; - } else - return def; + return p->value.bool; + } + else + return def; } - int xf86NameCmp(const char *s1, const char *s2) { @@ -895,21 +898,21 @@ xf86NormalizeName(const char *s) const char *p; if (s == NULL) - return NULL; + return NULL; ret = malloc(strlen(s) + 1); for (p = s, q = ret; *p != 0; p++) { - switch (*p) { - case '_': - case ' ': - case '\t': - continue; - default: - if (isupper(*p)) - *q++ = tolower(*p); - else - *q++ = *p; - } + switch (*p) { + case '_': + case ' ': + case '\t': + continue; + default: + if (isupper(*p)) + *q++ = tolower(*p); + else + *q++ = *p; + } } *q = '\0'; return ret; diff --git a/xorg-server/hw/xfree86/common/xf86Optionstr.h b/xorg-server/hw/xfree86/common/xf86Optionstr.h index fc9385617..c38499cb5 100644 --- a/xorg-server/hw/xfree86/common/xf86Optionstr.h +++ b/xorg-server/hw/xfree86/common/xf86Optionstr.h @@ -29,15 +29,13 @@ /* * All options are stored using this data type. */ -typedef struct _XF86OptionRec -{ - GenericListRec list; - char *opt_name; - char *opt_val; - int opt_used; - char *opt_comment; -} -XF86OptionRec; +typedef struct _XF86OptionRec { + GenericListRec list; + char *opt_name; + char *opt_val; + int opt_used; + char *opt_comment; +} XF86OptionRec; typedef struct _InputOption *XF86OptionPtr; diff --git a/xorg-server/hw/xfree86/common/xf86PM.c b/xorg-server/hw/xfree86/common/xf86PM.c index 47e0297d6..f69fffa0e 100644 --- a/xorg-server/hw/xfree86/common/xf86PM.c +++ b/xorg-server/hw/xfree86/common/xf86PM.c @@ -35,60 +35,90 @@ #include "xf86Xinput.h" #include "xf86_OSproc.h" -int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num) = NULL; -pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event) = NULL; +int (*xf86PMGetEventFromOs) (int fd, pmEvent * events, int num) = NULL; +pmWait (*xf86PMConfirmEventToOs) (int fd, pmEvent event) = NULL; static Bool suspended = FALSE; static int eventName(pmEvent event, const char **str) { - switch(event) { - case XF86_APM_SYS_STANDBY: *str="System Standby Request"; return 0; - case XF86_APM_SYS_SUSPEND: *str="System Suspend Request"; return 0; - case XF86_APM_CRITICAL_SUSPEND: *str="Critical Suspend"; return 0; - case XF86_APM_USER_STANDBY: *str="User System Standby Request"; return 0; - case XF86_APM_USER_SUSPEND: *str="User System Suspend Request"; return 0; - case XF86_APM_STANDBY_RESUME: *str="System Standby Resume"; return 0; - case XF86_APM_NORMAL_RESUME: *str="Normal Resume System"; return 0; - case XF86_APM_CRITICAL_RESUME: *str="Critical Resume System"; return 0; - case XF86_APM_LOW_BATTERY: *str="Battery Low"; return 3; - case XF86_APM_POWER_STATUS_CHANGE: *str="Power Status Change";return 3; - case XF86_APM_UPDATE_TIME: *str="Update Time";return 3; - case XF86_APM_CAPABILITY_CHANGED: *str="Capability Changed"; return 3; - case XF86_APM_STANDBY_FAILED: *str="Standby Request Failed"; return 0; - case XF86_APM_SUSPEND_FAILED: *str="Suspend Request Failed"; return 0; - default: *str="Unknown Event"; return 0; + switch (event) { + case XF86_APM_SYS_STANDBY: + *str = "System Standby Request"; + return 0; + case XF86_APM_SYS_SUSPEND: + *str = "System Suspend Request"; + return 0; + case XF86_APM_CRITICAL_SUSPEND: + *str = "Critical Suspend"; + return 0; + case XF86_APM_USER_STANDBY: + *str = "User System Standby Request"; + return 0; + case XF86_APM_USER_SUSPEND: + *str = "User System Suspend Request"; + return 0; + case XF86_APM_STANDBY_RESUME: + *str = "System Standby Resume"; + return 0; + case XF86_APM_NORMAL_RESUME: + *str = "Normal Resume System"; + return 0; + case XF86_APM_CRITICAL_RESUME: + *str = "Critical Resume System"; + return 0; + case XF86_APM_LOW_BATTERY: + *str = "Battery Low"; + return 3; + case XF86_APM_POWER_STATUS_CHANGE: + *str = "Power Status Change"; + return 3; + case XF86_APM_UPDATE_TIME: + *str = "Update Time"; + return 3; + case XF86_APM_CAPABILITY_CHANGED: + *str = "Capability Changed"; + return 3; + case XF86_APM_STANDBY_FAILED: + *str = "Standby Request Failed"; + return 0; + case XF86_APM_SUSPEND_FAILED: + *str = "Suspend Request Failed"; + return 0; + default: + *str = "Unknown Event"; + return 0; } } static int sigio_blocked_for_suspend; static void -suspend (pmEvent event, Bool undo) +suspend(pmEvent event, Bool undo) { int i; InputInfoPtr pInfo; for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); } pInfo = xf86InputDevs; while (pInfo) { - DisableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; + DisableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; } sigio_blocked_for_suspend = xf86BlockSIGIO(); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(i,event,undo); - else { - xf86Screens[i]->LeaveVT(i, 0); - xf86Screens[i]->vtSema = FALSE; - } + if (xf86Screens[i]->PMEvent) + xf86Screens[i]->PMEvent(i, event, undo); + else { + xf86Screens[i]->LeaveVT(i, 0); + xf86Screens[i]->vtSema = FALSE; + } } - xf86AccessLeave(); + xf86AccessLeave(); } @@ -100,23 +130,23 @@ resume(pmEvent event, Bool undo) xf86AccessEnter(); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(i,event,undo); - else { - xf86Screens[i]->vtSema = TRUE; - xf86Screens[i]->EnterVT(i, 0); - } + if (xf86Screens[i]->PMEvent) + xf86Screens[i]->PMEvent(i, event, undo); + else { + xf86Screens[i]->vtSema = TRUE; + xf86Screens[i]->EnterVT(i, 0); + } } xf86UnblockSIGIO(sigio_blocked_for_suspend); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); } dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); pInfo = xf86InputDevs; while (pInfo) { - EnableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; + EnableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; } } @@ -124,43 +154,44 @@ static void DoApmEvent(pmEvent event, Bool undo) { int i, was_blocked; - - switch(event) { + + switch (event) { #if 0 case XF86_APM_SYS_STANDBY: case XF86_APM_USER_STANDBY: #endif case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend?*/ + case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend? */ case XF86_APM_USER_SUSPEND: - /* should we do this ? */ - if (!undo && !suspended) { - suspend(event,undo); - suspended = TRUE; - } else if (undo && suspended) { - resume(event,undo); - suspended = FALSE; - } - break; + /* should we do this ? */ + if (!undo && !suspended) { + suspend(event, undo); + suspended = TRUE; + } + else if (undo && suspended) { + resume(event, undo); + suspended = FALSE; + } + break; #if 0 case XF86_APM_STANDBY_RESUME: #endif case XF86_APM_NORMAL_RESUME: case XF86_APM_CRITICAL_RESUME: - if (suspended) { - resume(event,undo); - suspended = FALSE; - } - break; + if (suspended) { + resume(event, undo); + suspended = FALSE; + } + break; default: - was_blocked = xf86BlockSIGIO(); - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) { - xf86Screens[i]->PMEvent(i,event,undo); - } - } - xf86UnblockSIGIO(was_blocked); - break; + was_blocked = xf86BlockSIGIO(); + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->PMEvent) { + xf86Screens[i]->PMEvent(i, event, undo); + } + } + xf86UnblockSIGIO(was_blocked); + break; } } @@ -170,39 +201,39 @@ void xf86HandlePMEvents(int fd, pointer data) { pmEvent events[MAX_NO_EVENTS]; - int i,n; + int i, n; Bool wait = FALSE; if (!xf86PMGetEventFromOs) - return; - - if ((n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS))) { - do { - for (i = 0; i < n; i++) { - const char *str = NULL; - int verb = eventName(events[i],&str); - - xf86MsgVerb(X_INFO,verb,"PM Event received: %s\n",str); - DoApmEvent(events[i],FALSE); - switch (xf86PMConfirmEventToOs(fd,events[i])) { - case PM_WAIT: - wait = TRUE; - break; - case PM_CONTINUE: - wait = FALSE; - break; - case PM_FAILED: - DoApmEvent(events[i],TRUE); - wait = FALSE; - break; - default: - break; - } - } - if (wait) - n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS); - else - break; - } while (1); + return; + + if ((n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS))) { + do { + for (i = 0; i < n; i++) { + const char *str = NULL; + int verb = eventName(events[i], &str); + + xf86MsgVerb(X_INFO, verb, "PM Event received: %s\n", str); + DoApmEvent(events[i], FALSE); + switch (xf86PMConfirmEventToOs(fd, events[i])) { + case PM_WAIT: + wait = TRUE; + break; + case PM_CONTINUE: + wait = FALSE; + break; + case PM_FAILED: + DoApmEvent(events[i], TRUE); + wait = FALSE; + break; + default: + break; + } + } + if (wait) + n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS); + else + break; + } while (1); } } diff --git a/xorg-server/hw/xfree86/common/xf86Priv.h b/xorg-server/hw/xfree86/common/xf86Priv.h index 255407b48..8d9cb5539 100644 --- a/xorg-server/hw/xfree86/common/xf86Priv.h +++ b/xorg-server/hw/xfree86/common/xf86Priv.h @@ -45,53 +45,55 @@ */ extern _X_EXPORT const char *xf86ConfigFile; extern _X_EXPORT const char *xf86ConfigDir; -extern _X_EXPORT Bool xf86AllowMouseOpenFail; +extern _X_EXPORT Bool xf86AllowMouseOpenFail; + #ifdef XF86VIDMODE -extern _X_EXPORT Bool xf86VidModeDisabled; -extern _X_EXPORT Bool xf86VidModeAllowNonLocal; -#endif -extern _X_EXPORT Bool xf86fpFlag; -extern _X_EXPORT Bool xf86sFlag; -extern _X_EXPORT Bool xf86bsEnableFlag; -extern _X_EXPORT Bool xf86bsDisableFlag; -extern _X_EXPORT Bool xf86silkenMouseDisableFlag; -extern _X_EXPORT Bool xf86xkbdirFlag; +extern _X_EXPORT Bool xf86VidModeDisabled; +extern _X_EXPORT Bool xf86VidModeAllowNonLocal; +#endif +extern _X_EXPORT Bool xf86fpFlag; +extern _X_EXPORT Bool xf86sFlag; +extern _X_EXPORT Bool xf86bsEnableFlag; +extern _X_EXPORT Bool xf86bsDisableFlag; +extern _X_EXPORT Bool xf86silkenMouseDisableFlag; +extern _X_EXPORT Bool xf86xkbdirFlag; + #ifdef HAVE_ACPI -extern _X_EXPORT Bool xf86acpiDisableFlag; +extern _X_EXPORT Bool xf86acpiDisableFlag; #endif -extern _X_EXPORT char *xf86LayoutName; -extern _X_EXPORT char *xf86ScreenName; -extern _X_EXPORT char *xf86PointerName; -extern _X_EXPORT char *xf86KeyboardName; -extern _X_EXPORT int xf86FbBpp; -extern _X_EXPORT int xf86Depth; -extern _X_EXPORT Pix24Flags xf86Pix24; -extern _X_EXPORT rgb xf86Weight; -extern _X_EXPORT Bool xf86FlipPixels; -extern _X_EXPORT Gamma xf86Gamma; -extern _X_EXPORT const char *xf86ServerName; +extern _X_EXPORT char *xf86LayoutName; +extern _X_EXPORT char *xf86ScreenName; +extern _X_EXPORT char *xf86PointerName; +extern _X_EXPORT char *xf86KeyboardName; +extern _X_EXPORT int xf86FbBpp; +extern _X_EXPORT int xf86Depth; +extern _X_EXPORT Pix24Flags xf86Pix24; +extern _X_EXPORT rgb xf86Weight; +extern _X_EXPORT Bool xf86FlipPixels; +extern _X_EXPORT Gamma xf86Gamma; +extern _X_EXPORT const char *xf86ServerName; /* Other parameters */ -extern _X_EXPORT xf86InfoRec xf86Info; -extern _X_EXPORT const char *xf86ModulePath; -extern _X_EXPORT MessageType xf86ModPathFrom; -extern _X_EXPORT const char *xf86LogFile; -extern _X_EXPORT MessageType xf86LogFileFrom; -extern _X_EXPORT Bool xf86LogFileWasOpened; -extern _X_EXPORT serverLayoutRec xf86ConfigLayout; - -extern _X_EXPORT DriverPtr *xf86DriverList; -extern _X_EXPORT int xf86NumDrivers; -extern _X_EXPORT Bool xf86Resetting; -extern _X_EXPORT Bool xf86Initialising; -extern _X_EXPORT int xf86NumScreens; -extern _X_EXPORT const char *xf86VisualNames[]; -extern _X_EXPORT int xf86Verbose; /* verbosity level */ -extern _X_EXPORT int xf86LogVerbose; /* log file verbosity level */ -extern _X_EXPORT Bool xorgHWAccess; - -extern _X_EXPORT RootWinPropPtr *xf86RegisteredPropertiesTable; +extern _X_EXPORT xf86InfoRec xf86Info; +extern _X_EXPORT const char *xf86ModulePath; +extern _X_EXPORT MessageType xf86ModPathFrom; +extern _X_EXPORT const char *xf86LogFile; +extern _X_EXPORT MessageType xf86LogFileFrom; +extern _X_EXPORT Bool xf86LogFileWasOpened; +extern _X_EXPORT serverLayoutRec xf86ConfigLayout; + +extern _X_EXPORT DriverPtr *xf86DriverList; +extern _X_EXPORT int xf86NumDrivers; +extern _X_EXPORT Bool xf86Resetting; +extern _X_EXPORT Bool xf86Initialising; +extern _X_EXPORT int xf86NumScreens; +extern _X_EXPORT const char *xf86VisualNames[]; +extern _X_EXPORT int xf86Verbose; /* verbosity level */ +extern _X_EXPORT int xf86LogVerbose; /* log file verbosity level */ +extern _X_EXPORT Bool xorgHWAccess; + +extern _X_EXPORT RootWinPropPtr *xf86RegisteredPropertiesTable; #ifndef DEFAULT_VERBOSE #define DEFAULT_VERBOSE 0 @@ -125,29 +127,43 @@ extern _X_EXPORT const DisplayModeRec xf86DefaultModes[]; extern _X_EXPORT const int xf86NumDefaultModes; /* xf86Configure.c */ -extern _X_EXPORT void DoConfigure(void) _X_NORETURN; -extern _X_EXPORT void DoShowOptions(void) _X_NORETURN; +extern _X_EXPORT void +DoConfigure(void) + _X_NORETURN; +extern _X_EXPORT void +DoShowOptions(void) + _X_NORETURN; /* xf86Events.c */ -extern _X_EXPORT void xf86Wakeup(pointer blockData, int err, pointer pReadmask); -extern _X_HIDDEN int xf86SigWrapper(int signo); -extern _X_EXPORT void xf86HandlePMEvents(int fd, pointer data); -extern _X_EXPORT int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num); -extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event); +extern _X_EXPORT void +xf86Wakeup(pointer blockData, int err, pointer pReadmask); +extern _X_HIDDEN int +xf86SigWrapper(int signo); +extern _X_EXPORT void +xf86HandlePMEvents(int fd, pointer data); +extern _X_EXPORT int (*xf86PMGetEventFromOs) (int fd, pmEvent * events, + int num); +extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs) (int fd, pmEvent event); /* xf86Helper.c */ -extern _X_EXPORT void xf86LogInit(void); -extern _X_EXPORT void xf86CloseLog(enum ExitCode error); +extern _X_EXPORT void +xf86LogInit(void); +extern _X_EXPORT void +xf86CloseLog(enum ExitCode error); /* xf86Init.c */ -extern _X_EXPORT Bool xf86LoadModules(char **list, pointer *optlist); -extern _X_EXPORT int xf86SetVerbosity(int verb); -extern _X_EXPORT int xf86SetLogVerbosity(int verb); -extern _X_EXPORT Bool xf86CallDriverProbe( struct _DriverRec * drv, Bool detect_only ); -extern _X_EXPORT Bool xf86PrivsElevated(void); - -#endif /* _NO_XF86_PROTOTYPES */ - - -#endif /* _XF86PRIV_H */ +extern _X_EXPORT Bool +xf86LoadModules(char **list, pointer *optlist); +extern _X_EXPORT int +xf86SetVerbosity(int verb); +extern _X_EXPORT int +xf86SetLogVerbosity(int verb); +extern _X_EXPORT Bool +xf86CallDriverProbe(struct _DriverRec *drv, Bool detect_only); +extern _X_EXPORT Bool +xf86PrivsElevated(void); + +#endif /* _NO_XF86_PROTOTYPES */ + +#endif /* _XF86PRIV_H */ diff --git a/xorg-server/hw/xfree86/common/xf86RandR.c b/xorg-server/hw/xfree86/common/xf86RandR.c index d0e47841e..abd894dff 100644 --- a/xorg-server/hw/xfree86/common/xf86RandR.c +++ b/xorg-server/hw/xfree86/common/xf86RandR.c @@ -37,13 +37,13 @@ #include "inputstr.h" typedef struct _xf86RandRInfo { - CreateScreenResourcesProcPtr CreateScreenResources; - CloseScreenProcPtr CloseScreen; - int virtualX; - int virtualY; - int mmWidth; - int mmHeight; - Rotation rotation; + CreateScreenResourcesProcPtr CreateScreenResources; + CloseScreenProcPtr CloseScreen; + int virtualX; + int virtualY; + int mmWidth; + int mmHeight; + Rotation rotation; } XF86RandRInfoRec, *XF86RandRInfoPtr; static DevPrivateKeyRec xf86RandRKeyRec; @@ -52,171 +52,162 @@ static DevPrivateKey xf86RandRKey; #define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey)) static int -xf86RandRModeRefresh (DisplayModePtr mode) +xf86RandRModeRefresh(DisplayModePtr mode) { if (mode->VRefresh) - return (int) (mode->VRefresh + 0.5); + return (int) (mode->VRefresh + 0.5); else if (mode->Clock == 0) - return 0; + return 0; else - return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5); + return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5); } static Bool -xf86RandRGetInfo (ScreenPtr pScreen, Rotation *rotations) +xf86RandRGetInfo(ScreenPtr pScreen, Rotation * rotations) { - RRScreenSizePtr pSize; - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int refresh0 = 60; - xorgRRModeMM RRModeMM; + RRScreenSizePtr pSize; + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + DisplayModePtr mode; + int refresh0 = 60; + xorgRRModeMM RRModeMM; *rotations = RR_Rotate_0; - for (mode = scrp->modes; mode != NULL ; mode = mode->next) - { - int refresh = xf86RandRModeRefresh (mode); - - if (mode == scrp->modes) - refresh0 = refresh; - - RRModeMM.mode = mode; - RRModeMM.virtX = randrp->virtualX; - RRModeMM.virtY = randrp->virtualY; - RRModeMM.mmWidth = randrp->mmWidth; - RRModeMM.mmHeight = randrp->mmHeight; - - if(scrp->DriverFunc) { - (*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM); - } - - pSize = RRRegisterSize (pScreen, - mode->HDisplay, mode->VDisplay, - RRModeMM.mmWidth, RRModeMM.mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate (pScreen, pSize, refresh); - if (mode == scrp->currentMode && - mode->HDisplay == scrp->virtualX && mode->VDisplay == scrp->virtualY) - RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize); - if (mode->next == scrp->modes) - break; + for (mode = scrp->modes; mode != NULL; mode = mode->next) { + int refresh = xf86RandRModeRefresh(mode); + + if (mode == scrp->modes) + refresh0 = refresh; + + RRModeMM.mode = mode; + RRModeMM.virtX = randrp->virtualX; + RRModeMM.virtY = randrp->virtualY; + RRModeMM.mmWidth = randrp->mmWidth; + RRModeMM.mmHeight = randrp->mmHeight; + + if (scrp->DriverFunc) { + (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); + } + + pSize = RRRegisterSize(pScreen, + mode->HDisplay, mode->VDisplay, + RRModeMM.mmWidth, RRModeMM.mmHeight); + if (!pSize) + return FALSE; + RRRegisterRate(pScreen, pSize, refresh); + if (mode == scrp->currentMode && + mode->HDisplay == scrp->virtualX && + mode->VDisplay == scrp->virtualY) + RRSetCurrentConfig(pScreen, randrp->rotation, refresh, pSize); + if (mode->next == scrp->modes) + break; } if (scrp->currentMode->HDisplay != randrp->virtualX || - scrp->currentMode->VDisplay != randrp->virtualY) - { - mode = scrp->modes; - - RRModeMM.mode = NULL; - RRModeMM.virtX = randrp->virtualX; - RRModeMM.virtY = randrp->virtualY; - RRModeMM.mmWidth = randrp->mmWidth; - RRModeMM.mmHeight = randrp->mmHeight; - - if(scrp->DriverFunc) { - (*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM); - } - - pSize = RRRegisterSize (pScreen, - randrp->virtualX, randrp->virtualY, - RRModeMM.mmWidth, RRModeMM.mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate (pScreen, pSize, refresh0); - if (scrp->virtualX == randrp->virtualX && - scrp->virtualY == randrp->virtualY) - { - RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize); - } + scrp->currentMode->VDisplay != randrp->virtualY) { + mode = scrp->modes; + + RRModeMM.mode = NULL; + RRModeMM.virtX = randrp->virtualX; + RRModeMM.virtY = randrp->virtualY; + RRModeMM.mmWidth = randrp->mmWidth; + RRModeMM.mmHeight = randrp->mmHeight; + + if (scrp->DriverFunc) { + (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); + } + + pSize = RRRegisterSize(pScreen, + randrp->virtualX, randrp->virtualY, + RRModeMM.mmWidth, RRModeMM.mmHeight); + if (!pSize) + return FALSE; + RRRegisterRate(pScreen, pSize, refresh0); + if (scrp->virtualX == randrp->virtualX && + scrp->virtualY == randrp->virtualY) { + RRSetCurrentConfig(pScreen, randrp->rotation, refresh0, pSize); + } } /* If there is driver support for randr, let it set our supported rotations */ - if(scrp->DriverFunc) { - xorgRRRotation RRRotation; + if (scrp->DriverFunc) { + xorgRRRotation RRRotation; - RRRotation.RRRotations = *rotations; - if (!(*scrp->DriverFunc)(scrp, RR_GET_INFO, &RRRotation)) - return TRUE; - *rotations = RRRotation.RRRotations; + RRRotation.RRRotations = *rotations; + if (!(*scrp->DriverFunc) (scrp, RR_GET_INFO, &RRRotation)) + return TRUE; + *rotations = RRRotation.RRRotations; } return TRUE; } static Bool -xf86RandRSetMode (ScreenPtr pScreen, - DisplayModePtr mode, - Bool useVirtual, - int mmWidth, - int mmHeight) +xf86RandRSetMode(ScreenPtr pScreen, + DisplayModePtr mode, + Bool useVirtual, int mmWidth, int mmHeight) { - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - int oldWidth = pScreen->width; - int oldHeight = pScreen->height; - int oldmmWidth = pScreen->mmWidth; - int oldmmHeight = pScreen->mmHeight; - int oldVirtualX = scrp->virtualX; - int oldVirtualY = scrp->virtualY; - WindowPtr pRoot = pScreen->root; - Bool ret = TRUE; + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + int oldWidth = pScreen->width; + int oldHeight = pScreen->height; + int oldmmWidth = pScreen->mmWidth; + int oldmmHeight = pScreen->mmHeight; + int oldVirtualX = scrp->virtualX; + int oldVirtualY = scrp->virtualY; + WindowPtr pRoot = pScreen->root; + Bool ret = TRUE; if (pRoot && scrp->vtSema) - (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE); - if (useVirtual) - { - scrp->virtualX = randrp->virtualX; - scrp->virtualY = randrp->virtualY; + (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE); + if (useVirtual) { + scrp->virtualX = randrp->virtualX; + scrp->virtualY = randrp->virtualY; } - else - { - scrp->virtualX = mode->HDisplay; - scrp->virtualY = mode->VDisplay; + else { + scrp->virtualX = mode->HDisplay; + scrp->virtualY = mode->VDisplay; } /* * The DIX forgets the physical dimensions we passed into RRRegisterSize, so * reconstruct them if possible. */ - if(scrp->DriverFunc) { - xorgRRModeMM RRModeMM; + if (scrp->DriverFunc) { + xorgRRModeMM RRModeMM; - RRModeMM.mode = mode; - RRModeMM.virtX = scrp->virtualX; - RRModeMM.virtY = scrp->virtualY; - RRModeMM.mmWidth = mmWidth; - RRModeMM.mmHeight = mmHeight; + RRModeMM.mode = mode; + RRModeMM.virtX = scrp->virtualX; + RRModeMM.virtY = scrp->virtualY; + RRModeMM.mmWidth = mmWidth; + RRModeMM.mmHeight = mmHeight; - (*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM); + (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); - mmWidth = RRModeMM.mmWidth; - mmHeight = RRModeMM.mmHeight; + mmWidth = RRModeMM.mmWidth; + mmHeight = RRModeMM.mmHeight; } - if(randrp->rotation & (RR_Rotate_90 | RR_Rotate_270)) - { - /* If the screen is rotated 90 or 270 degrees, swap the sizes. */ - pScreen->width = scrp->virtualY; - pScreen->height = scrp->virtualX; - pScreen->mmWidth = mmHeight; - pScreen->mmHeight = mmWidth; + if (randrp->rotation & (RR_Rotate_90 | RR_Rotate_270)) { + /* If the screen is rotated 90 or 270 degrees, swap the sizes. */ + pScreen->width = scrp->virtualY; + pScreen->height = scrp->virtualX; + pScreen->mmWidth = mmHeight; + pScreen->mmHeight = mmWidth; } - else - { - pScreen->width = scrp->virtualX; - pScreen->height = scrp->virtualY; - pScreen->mmWidth = mmWidth; - pScreen->mmHeight = mmHeight; + else { + pScreen->width = scrp->virtualX; + pScreen->height = scrp->virtualY; + pScreen->mmWidth = mmWidth; + pScreen->mmHeight = mmHeight; } - if (!xf86SwitchMode (pScreen, mode)) - { - pScreen->width = oldWidth; - pScreen->height = oldHeight; - pScreen->mmWidth = oldmmWidth; - pScreen->mmHeight = oldmmHeight; - scrp->virtualX = oldVirtualX; - scrp->virtualY = oldVirtualY; - ret = FALSE; + if (!xf86SwitchMode(pScreen, mode)) { + pScreen->width = oldWidth; + pScreen->height = oldHeight; + pScreen->mmWidth = oldmmWidth; + pScreen->mmHeight = oldmmHeight; + scrp->virtualX = oldVirtualX; + scrp->virtualY = oldVirtualY; + ret = FALSE; } /* * Make sure the layout is correct @@ -226,120 +217,117 @@ xf86RandRSetMode (ScreenPtr pScreen, /* * Make sure the whole screen is visible */ - xf86SetViewport (pScreen, pScreen->width, pScreen->height); - xf86SetViewport (pScreen, 0, 0); + xf86SetViewport(pScreen, pScreen->width, pScreen->height); + xf86SetViewport(pScreen, 0, 0); if (pRoot && scrp->vtSema) - (*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE); + (*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE); return ret; } static Bool -xf86RandRSetConfig (ScreenPtr pScreen, - Rotation rotation, - int rate, - RRScreenSizePtr pSize) +xf86RandRSetConfig(ScreenPtr pScreen, + Rotation rotation, int rate, RRScreenSizePtr pSize) { - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int pos[MAXDEVICES][2]; - Bool useVirtual = FALSE; - Rotation oldRotation = randrp->rotation; - DeviceIntPtr dev; - Bool view_adjusted = FALSE; - - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - miPointerGetPosition(dev, &pos[dev->id][0], &pos[dev->id][1]); + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + DisplayModePtr mode; + int pos[MAXDEVICES][2]; + Bool useVirtual = FALSE; + Rotation oldRotation = randrp->rotation; + DeviceIntPtr dev; + Bool view_adjusted = FALSE; + + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (!IsMaster(dev) && !IsFloating(dev)) + continue; + + miPointerGetPosition(dev, &pos[dev->id][0], &pos[dev->id][1]); } - for (mode = scrp->modes; ; mode = mode->next) - { - if (mode->HDisplay == pSize->width && - mode->VDisplay == pSize->height && - (rate == 0 || xf86RandRModeRefresh (mode) == rate)) - break; - if (mode->next == scrp->modes) - { - if (pSize->width == randrp->virtualX && - pSize->height == randrp->virtualY) - { - mode = scrp->modes; - useVirtual = TRUE; - break; - } - return FALSE; - } + for (mode = scrp->modes;; mode = mode->next) { + if (mode->HDisplay == pSize->width && + mode->VDisplay == pSize->height && + (rate == 0 || xf86RandRModeRefresh(mode) == rate)) + break; + if (mode->next == scrp->modes) { + if (pSize->width == randrp->virtualX && + pSize->height == randrp->virtualY) { + mode = scrp->modes; + useVirtual = TRUE; + break; + } + return FALSE; + } } if (randrp->rotation != rotation) { /* Have the driver do its thing. */ - if (scrp->DriverFunc) { - xorgRRRotation RRRotation; - RRRotation.RRConfig.rotation = rotation; - RRRotation.RRConfig.rate = rate; - RRRotation.RRConfig.width = pSize->width; - RRRotation.RRConfig.height = pSize->height; - - /* - * Currently we need to rely on HW support for rotation. - */ - if (!(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation)) - return FALSE; - } else - return FALSE; - - randrp->rotation = rotation; + if (scrp->DriverFunc) { + xorgRRRotation RRRotation; + + RRRotation.RRConfig.rotation = rotation; + RRRotation.RRConfig.rate = rate; + RRRotation.RRConfig.width = pSize->width; + RRRotation.RRConfig.height = pSize->height; + + /* + * Currently we need to rely on HW support for rotation. + */ + if (!(*scrp->DriverFunc) (scrp, RR_SET_CONFIG, &RRRotation)) + return FALSE; + } + else + return FALSE; + + randrp->rotation = rotation; } - if (!xf86RandRSetMode (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) { - if(randrp->rotation != oldRotation) { - /* Have the driver undo its thing. */ - if (scrp->DriverFunc) { - xorgRRRotation RRRotation; - RRRotation.RRConfig.rotation = oldRotation; - RRRotation.RRConfig.rate = xf86RandRModeRefresh (scrp->currentMode); - RRRotation.RRConfig.width = scrp->virtualX; - RRRotation.RRConfig.height = scrp->virtualY; - (*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation); - } - - randrp->rotation = oldRotation; - } - return FALSE; + if (!xf86RandRSetMode + (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) { + if (randrp->rotation != oldRotation) { + /* Have the driver undo its thing. */ + if (scrp->DriverFunc) { + xorgRRRotation RRRotation; + + RRRotation.RRConfig.rotation = oldRotation; + RRRotation.RRConfig.rate = + xf86RandRModeRefresh(scrp->currentMode); + RRRotation.RRConfig.width = scrp->virtualX; + RRRotation.RRConfig.height = scrp->virtualY; + (*scrp->DriverFunc) (scrp, RR_SET_CONFIG, &RRRotation); + } + + randrp->rotation = oldRotation; + } + return FALSE; } - update_desktop_dimensions(); /* * Move the cursor back where it belongs; SwitchMode repositions it * FIXME: duplicated code, see modes/xf86RandR12.c */ - for (dev = inputInfo.devices; dev; dev = dev->next) - { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - if (pScreen == miPointerGetScreen(dev)) { - int px = pos[dev->id][0]; - int py = pos[dev->id][1]; - - px = (px >= pScreen->width ? (pScreen->width - 1) : px); - py = (py >= pScreen->height ? (pScreen->height - 1) : py); - - /* Setting the viewpoint makes only sense on one device */ - if (!view_adjusted && IsMaster(dev)) { - xf86SetViewport(pScreen, px, py); - view_adjusted = TRUE; - } - - (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); - } + for (dev = inputInfo.devices; dev; dev = dev->next) { + if (!IsMaster(dev) && !IsFloating(dev)) + continue; + + if (pScreen == miPointerGetScreen(dev)) { + int px = pos[dev->id][0]; + int py = pos[dev->id][1]; + + px = (px >= pScreen->width ? (pScreen->width - 1) : px); + py = (py >= pScreen->height ? (pScreen->height - 1) : py); + + /* Setting the viewpoint makes only sense on one device */ + if (!view_adjusted && IsMaster(dev)) { + xf86SetViewport(pScreen, px, py); + view_adjusted = TRUE; + } + + (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); + } } return TRUE; @@ -351,22 +339,23 @@ xf86RandRSetConfig (ScreenPtr pScreen, * at the current mode size rather than the maximum size */ static Bool -xf86RandRCreateScreenResources (ScreenPtr pScreen) +xf86RandRCreateScreenResources(ScreenPtr pScreen) { - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + #if 0 - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); - DisplayModePtr mode; + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + DisplayModePtr mode; #endif pScreen->CreateScreenResources = randrp->CreateScreenResources; if (!(*pScreen->CreateScreenResources) (pScreen)) - return FALSE; + return FALSE; #if 0 mode = scrp->currentMode; if (mode) - xf86RandRSetMode (pScreen, mode, TRUE); + xf86RandRSetMode(pScreen, mode, TRUE); #endif return TRUE; @@ -376,10 +365,10 @@ xf86RandRCreateScreenResources (ScreenPtr pScreen) * Reset size back to original */ static Bool -xf86RandRCloseScreen (int index, ScreenPtr pScreen) +xf86RandRCloseScreen(int index, ScreenPtr pScreen) { - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); scrp->virtualX = pScreen->width = randrp->virtualX; scrp->virtualY = pScreen->height = randrp->virtualY; @@ -394,7 +383,7 @@ Rotation xf86GetRotation(ScreenPtr pScreen) { if (xf86RandRKey == NULL) - return RR_Rotate_0; + return RR_Rotate_0; return XF86RANDRINFO(pScreen)->rotation; } @@ -402,67 +391,65 @@ xf86GetRotation(ScreenPtr pScreen) /* Function to change RandR's idea of the virtual screen size */ Bool xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen, - int newvirtX, int newvirtY, int newmmWidth, int newmmHeight, - Bool resetMode) + int newvirtX, int newvirtY, int newmmWidth, + int newmmHeight, Bool resetMode) { XF86RandRInfoPtr randrp; if (xf86RandRKey == NULL) - return FALSE; + return FALSE; randrp = XF86RANDRINFO(pScreen); if (randrp == NULL) - return FALSE; + return FALSE; if (newvirtX > 0) - randrp->virtualX = newvirtX; + randrp->virtualX = newvirtX; if (newvirtY > 0) - randrp->virtualY = newvirtY; + randrp->virtualY = newvirtY; if (newmmWidth > 0) - randrp->mmWidth = newmmWidth; + randrp->mmWidth = newmmWidth; if (newmmHeight > 0) - randrp->mmHeight = newmmHeight; + randrp->mmHeight = newmmHeight; /* This is only for during server start */ if (resetMode) { - return (xf86RandRSetMode(pScreen, - XF86SCRNINFO(pScreen)->currentMode, - TRUE, - pScreen->mmWidth, pScreen->mmHeight)); + return (xf86RandRSetMode(pScreen, + XF86SCRNINFO(pScreen)->currentMode, + TRUE, pScreen->mmWidth, pScreen->mmHeight)); } return TRUE; } Bool -xf86RandRInit (ScreenPtr pScreen) +xf86RandRInit(ScreenPtr pScreen) { - rrScrPrivPtr rp; - XF86RandRInfoPtr randrp; - ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + rrScrPrivPtr rp; + XF86RandRInfoPtr randrp; + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); #ifdef PANORAMIX /* XXX disable RandR when using Xinerama */ if (!noPanoramiXExtension) - return TRUE; + return TRUE; #endif xf86RandRKey = &xf86RandRKeyRec; if (!dixRegisterPrivateKey(&xf86RandRKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; - randrp = malloc(sizeof (XF86RandRInfoRec)); + randrp = malloc(sizeof(XF86RandRInfoRec)); if (!randrp) - return FALSE; + return FALSE; - if (!RRScreenInit (pScreen)) - { - free(randrp); - return FALSE; + if (!RRScreenInit(pScreen)) { + free(randrp); + return FALSE; } rp = rrGetScrPriv(pScreen); rp->rrGetInfo = xf86RandRGetInfo; @@ -484,5 +471,3 @@ xf86RandRInit (ScreenPtr pScreen) dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, randrp); return TRUE; } - - diff --git a/xorg-server/hw/xfree86/common/xf86VGAarbiter.c b/xorg-server/hw/xfree86/common/xf86VGAarbiter.c index 819ad6e7c..7c9e6ba02 100644 --- a/xorg-server/hw/xfree86/common/xf86VGAarbiter.c +++ b/xorg-server/hw/xfree86/common/xf86VGAarbiter.c @@ -36,7 +36,6 @@ #include "xf86Priv.h" #include "pciaccess.h" - static GCFuncs VGAarbiterGCFuncs = { VGAarbiterValidateGC, VGAarbiterChangeGC, VGAarbiterCopyGC, VGAarbiterDestroyGC, VGAarbiterChangeClip, VGAarbiterDestroyClip, @@ -60,8 +59,10 @@ static miPointerSpriteFuncRec VGAarbiterSpriteFuncs = { }; static DevPrivateKeyRec VGAarbiterScreenKeyRec; + #define VGAarbiterScreenKey (&VGAarbiterScreenKeyRec) static DevPrivateKeyRec VGAarbiterGCKeyRec; + #define VGAarbiterGCKey (&VGAarbiterGCKeyRec) static int vga_no_arb = 0; @@ -69,8 +70,9 @@ void xf86VGAarbiterInit(void) { if (pci_device_vgaarb_init() != 0) { - vga_no_arb = 1; - xf86Msg(X_WARNING, "VGA arbiter: cannot open kernel arbiter, no multi-card support\n"); + vga_no_arb = 1; + xf86Msg(X_WARNING, + "VGA arbiter: cannot open kernel arbiter, no multi-card support\n"); } } @@ -78,7 +80,7 @@ void xf86VGAarbiterFini(void) { if (vga_no_arb) - return; + return; pci_device_vgaarb_fini(); } @@ -86,7 +88,7 @@ void xf86VGAarbiterLock(ScrnInfoPtr pScrn) { if (vga_no_arb) - return; + return; pci_device_vgaarb_set_target(pScrn->vgaDev); pci_device_vgaarb_lock(); } @@ -95,18 +97,19 @@ void xf86VGAarbiterUnlock(ScrnInfoPtr pScrn) { if (vga_no_arb) - return; + return; pci_device_vgaarb_unlock(); } -Bool xf86VGAarbiterAllowDRI(ScreenPtr pScreen) +Bool +xf86VGAarbiterAllowDRI(ScreenPtr pScreen) { int vga_count; int rsrc_decodes; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; if (vga_no_arb) - return TRUE; + return TRUE; pci_device_vgaarb_get_info(pScrn->vgaDev, &vga_count, &rsrc_decodes); if (vga_count > 1) { @@ -124,11 +127,11 @@ xf86VGAarbiterScrnInit(ScrnInfoPtr pScrn) EntityPtr pEnt; if (vga_no_arb) - return; + return; pEnt = xf86Entities[pScrn->entityList[0]]; if (pEnt->bus.type != BUS_PCI) - return; + return; dev = pEnt->bus.id.pci; pScrn->vgaDev = dev; @@ -138,7 +141,7 @@ void xf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc) { if (vga_no_arb) - return; + return; pci_device_vgaarb_set_target(pScrn->vgaDev); pci_device_vgaarb_decodes(rsrc); } @@ -149,7 +152,7 @@ xf86VGAarbiterWrapFunctions(void) ScrnInfoPtr pScrn; VGAarbiterScreenPtr pScreenPriv; miPointerScreenPtr PointPriv; - PictureScreenPtr ps; + PictureScreenPtr ps; ScreenPtr pScreen; int vga_count, i; @@ -164,7 +167,7 @@ xf86VGAarbiterWrapFunctions(void) if (vga_count < 2 || !xf86Screens) return FALSE; - xf86Msg(X_INFO,"Found %d VGA devices: arbiter wrapping enabled\n", + xf86Msg(X_INFO, "Found %d VGA devices: arbiter wrapping enabled\n", vga_count); for (i = 0; i < xf86NumScreens; i++) { @@ -173,11 +176,12 @@ xf86VGAarbiterWrapFunctions(void) pScrn = xf86Screens[pScreen->myNum]; PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - if (!dixRegisterPrivateKey(&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec))) + if (!dixRegisterPrivateKey + (&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec))) return FALSE; - if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0)) + return FALSE; if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec)))) return FALSE; @@ -201,9 +205,9 @@ xf86VGAarbiterWrapFunctions(void) WRAP_SCREEN(UnrealizeCursor, VGAarbiterUnrealizeCursor); WRAP_SCREEN(RecolorCursor, VGAarbiterRecolorCursor); WRAP_SCREEN(SetCursorPosition, VGAarbiterSetCursorPosition); - WRAP_PICT(Composite,VGAarbiterComposite); - WRAP_PICT(Glyphs,VGAarbiterGlyphs); - WRAP_PICT(CompositeRects,VGAarbiterCompositeRects); + WRAP_PICT(Composite, VGAarbiterComposite); + WRAP_PICT(Glyphs, VGAarbiterGlyphs); + WRAP_PICT(CompositeRects, VGAarbiterCompositeRects); WRAP_SCREEN_INFO(AdjustFrame, VGAarbiterAdjustFrame); WRAP_SCREEN_INFO(SwitchMode, VGAarbiterSwitchMode); WRAP_SCREEN_INFO(EnterVT, VGAarbiterEnterVT); @@ -217,15 +221,17 @@ xf86VGAarbiterWrapFunctions(void) /* Screen funcs */ static Bool -VGAarbiterCloseScreen (int i, ScreenPtr pScreen) +VGAarbiterCloseScreen(int i, ScreenPtr pScreen) { Bool val; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); - miPointerScreenPtr PointPriv = (miPointerScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, miPointerScreenKey); - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); + miPointerScreenPtr PointPriv = + (miPointerScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + miPointerScreenKey); + PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); UNWRAP_SCREEN(CreateGC); UNWRAP_SCREEN(CloseScreen); @@ -263,6 +269,7 @@ VGAarbiterBlockHandler(int i, pointer blockData, pointer pTimeout, pointer pReadmask) { ScreenPtr pScreen = screenInfo.screens[i]; + SCREEN_PROLOG(BlockHandler); VGAGet(pScreen); pScreen->BlockHandler(i, blockData, pTimeout, pReadmask); @@ -271,9 +278,11 @@ VGAarbiterBlockHandler(int i, } static void -VGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result, pointer pReadmask) +VGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result, + pointer pReadmask) { ScreenPtr pScreen = screenInfo.screens[i]; + SCREEN_PROLOG(WakeupHandler); VGAGet(pScreen); pScreen->WakeupHandler(i, blockData, result, pReadmask); @@ -282,100 +291,87 @@ VGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result, pointer } static void -VGAarbiterGetImage ( - DrawablePtr pDrawable, - int sx, int sy, int w, int h, - unsigned int format, - unsigned long planemask, - char *pdstLine - ) +VGAarbiterGetImage(DrawablePtr pDrawable, + int sx, int sy, int w, int h, + unsigned int format, unsigned long planemask, char *pdstLine) { ScreenPtr pScreen = pDrawable->pScreen; + SCREEN_PROLOG(GetImage); // if (xf86Screens[pScreen->myNum]->vtSema) { VGAGet(pScreen); // } - (*pScreen->GetImage) (pDrawable, sx, sy, w, h, - format, planemask, pdstLine); + (*pScreen->GetImage) (pDrawable, sx, sy, w, h, format, planemask, pdstLine); VGAPut(); - SCREEN_EPILOG (GetImage, VGAarbiterGetImage); + SCREEN_EPILOG(GetImage, VGAarbiterGetImage); } static void -VGAarbiterGetSpans ( - DrawablePtr pDrawable, - int wMax, - DDXPointPtr ppt, - int *pwidth, - int nspans, - char *pdstStart - ) -{ - ScreenPtr pScreen = pDrawable->pScreen; - - SCREEN_PROLOG (GetSpans); +VGAarbiterGetSpans(DrawablePtr pDrawable, + int wMax, + DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart) +{ + ScreenPtr pScreen = pDrawable->pScreen; + + SCREEN_PROLOG(GetSpans); VGAGet(pScreen); (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart); VGAPut(); - SCREEN_EPILOG (GetSpans, VGAarbiterGetSpans); + SCREEN_EPILOG(GetSpans, VGAarbiterGetSpans); } static void -VGAarbiterSourceValidate ( - DrawablePtr pDrawable, - int x, int y, int width, int height, - unsigned int subWindowMode ) +VGAarbiterSourceValidate(DrawablePtr pDrawable, + int x, int y, int width, int height, + unsigned int subWindowMode) { - ScreenPtr pScreen = pDrawable->pScreen; - SCREEN_PROLOG (SourceValidate); + ScreenPtr pScreen = pDrawable->pScreen; + + SCREEN_PROLOG(SourceValidate); VGAGet(pScreen); if (pScreen->SourceValidate) - (*pScreen->SourceValidate) (pDrawable, x, y, width, height, subWindowMode); + (*pScreen->SourceValidate) (pDrawable, x, y, width, height, + subWindowMode); VGAPut(); - SCREEN_EPILOG (SourceValidate, VGAarbiterSourceValidate); + SCREEN_EPILOG(SourceValidate, VGAarbiterSourceValidate); } static void -VGAarbiterCopyWindow( - WindowPtr pWin, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc ) +VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) { ScreenPtr pScreen = pWin->drawable.pScreen; - SCREEN_PROLOG (CopyWindow); + SCREEN_PROLOG(CopyWindow); VGAGet(pScreen); (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); VGAPut(); - SCREEN_EPILOG (CopyWindow, VGAarbiterCopyWindow); + SCREEN_EPILOG(CopyWindow, VGAarbiterCopyWindow); } static void -VGAarbiterClearToBackground ( - WindowPtr pWin, - int x, int y, - int w, int h, - Bool generateExposures ) +VGAarbiterClearToBackground(WindowPtr pWin, + int x, int y, int w, int h, Bool generateExposures) { ScreenPtr pScreen = pWin->drawable.pScreen; - SCREEN_PROLOG ( ClearToBackground); + SCREEN_PROLOG(ClearToBackground); VGAGet(pScreen); (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures); VGAPut(); - SCREEN_EPILOG (ClearToBackground, VGAarbiterClearToBackground); + SCREEN_EPILOG(ClearToBackground, VGAarbiterClearToBackground); } static PixmapPtr -VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, int depth, unsigned usage_hint) +VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, int depth, + unsigned usage_hint) { PixmapPtr pPix; - SCREEN_PROLOG ( CreatePixmap); + SCREEN_PROLOG(CreatePixmap); VGAGet(pScreen); pPix = (*pScreen->CreatePixmap) (pScreen, w, h, depth, usage_hint); VGAPut(); - SCREEN_EPILOG (CreatePixmap, VGAarbiterCreatePixmap); + SCREEN_EPILOG(CreatePixmap, VGAarbiterCreatePixmap); return pPix; } @@ -385,110 +381,89 @@ VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank) { Bool val; - SCREEN_PROLOG (SaveScreen); + SCREEN_PROLOG(SaveScreen); VGAGet(pScreen); val = (*pScreen->SaveScreen) (pScreen, unblank); VGAPut(); - SCREEN_EPILOG (SaveScreen, VGAarbiterSaveScreen); + SCREEN_EPILOG(SaveScreen, VGAarbiterSaveScreen); return val; } static void -VGAarbiterStoreColors ( - ColormapPtr pmap, - int ndef, - xColorItem *pdefs) +VGAarbiterStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs) { ScreenPtr pScreen = pmap->pScreen; - SCREEN_PROLOG (StoreColors); + SCREEN_PROLOG(StoreColors); VGAGet(pScreen); - (*pScreen->StoreColors) (pmap,ndef,pdefs); + (*pScreen->StoreColors) (pmap, ndef, pdefs); VGAPut(); - SCREEN_EPILOG ( StoreColors, VGAarbiterStoreColors); + SCREEN_EPILOG(StoreColors, VGAarbiterStoreColors); } static void -VGAarbiterRecolorCursor ( - DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCurs, - Bool displayed - ) -{ - SCREEN_PROLOG (RecolorCursor); +VGAarbiterRecolorCursor(DeviceIntPtr pDev, + ScreenPtr pScreen, CursorPtr pCurs, Bool displayed) +{ + SCREEN_PROLOG(RecolorCursor); VGAGet(pScreen); (*pScreen->RecolorCursor) (pDev, pScreen, pCurs, displayed); VGAPut(); - SCREEN_EPILOG ( RecolorCursor, VGAarbiterRecolorCursor); + SCREEN_EPILOG(RecolorCursor, VGAarbiterRecolorCursor); } static Bool -VGAarbiterRealizeCursor ( - DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCursor - ) +VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) { Bool val; - SCREEN_PROLOG (RealizeCursor); + SCREEN_PROLOG(RealizeCursor); VGAGet(pScreen); - val = (*pScreen->RealizeCursor) (pDev, pScreen,pCursor); + val = (*pScreen->RealizeCursor) (pDev, pScreen, pCursor); VGAPut(); - SCREEN_EPILOG ( RealizeCursor, VGAarbiterRealizeCursor); + SCREEN_EPILOG(RealizeCursor, VGAarbiterRealizeCursor); return val; } static Bool -VGAarbiterUnrealizeCursor ( - DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCursor - ) +VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, + ScreenPtr pScreen, CursorPtr pCursor) { Bool val; - SCREEN_PROLOG (UnrealizeCursor); + SCREEN_PROLOG(UnrealizeCursor); VGAGet(pScreen); val = (*pScreen->UnrealizeCursor) (pDev, pScreen, pCursor); VGAPut(); - SCREEN_EPILOG ( UnrealizeCursor, VGAarbiterUnrealizeCursor); + SCREEN_EPILOG(UnrealizeCursor, VGAarbiterUnrealizeCursor); return val; } static Bool -VGAarbiterDisplayCursor ( - DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCursor - ) +VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) { Bool val; - SCREEN_PROLOG (DisplayCursor); + SCREEN_PROLOG(DisplayCursor); VGAGet(pScreen); val = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor); VGAPut(); - SCREEN_EPILOG ( DisplayCursor, VGAarbiterDisplayCursor); + SCREEN_EPILOG(DisplayCursor, VGAarbiterDisplayCursor); return val; } static Bool -VGAarbiterSetCursorPosition ( - DeviceIntPtr pDev, - ScreenPtr pScreen, - int x, int y, - Bool generateEvent) +VGAarbiterSetCursorPosition(DeviceIntPtr pDev, + ScreenPtr pScreen, int x, int y, Bool generateEvent) { Bool val; - SCREEN_PROLOG (SetCursorPosition); + SCREEN_PROLOG(SetCursorPosition); VGAGet(pScreen); val = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent); VGAPut(); - SCREEN_EPILOG ( SetCursorPosition, VGAarbiterSetCursorPosition); + SCREEN_EPILOG(SetCursorPosition, VGAarbiterSetCursorPosition); return val; } @@ -496,11 +471,12 @@ static void VGAarbiterAdjustFrame(int index, int x, int y, int flags) { ScreenPtr pScreen = screenInfo.screens[index]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); VGAGet(pScreen); - (*pScreenPriv->AdjustFrame)(index, x, y, flags); + (*pScreenPriv->AdjustFrame) (index, x, y, flags); VGAPut(); } @@ -509,11 +485,12 @@ VGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags) { Bool val; ScreenPtr pScreen = screenInfo.screens[index]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); VGAGet(pScreen); - val = (*pScreenPriv->SwitchMode)(index, mode, flags); + val = (*pScreenPriv->SwitchMode) (index, mode, flags); VGAPut(); return val; } @@ -524,12 +501,13 @@ VGAarbiterEnterVT(int index, int flags) Bool val; ScrnInfoPtr pScrn = xf86Screens[index]; ScreenPtr pScreen = screenInfo.screens[index]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); VGAGet(pScreen); pScrn->EnterVT = pScreenPriv->EnterVT; - val = (*pScrn->EnterVT)(index, flags); + val = (*pScrn->EnterVT) (index, flags); pScreenPriv->EnterVT = pScrn->EnterVT; pScrn->EnterVT = VGAarbiterEnterVT; VGAPut(); @@ -541,12 +519,13 @@ VGAarbiterLeaveVT(int index, int flags) { ScrnInfoPtr pScrn = xf86Screens[index]; ScreenPtr pScreen = screenInfo.screens[index]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); VGAGet(pScreen); pScrn->LeaveVT = pScreenPriv->LeaveVT; - (*pScreenPriv->LeaveVT)(index, flags); + (*pScreenPriv->LeaveVT) (index, flags); pScreenPriv->LeaveVT = pScrn->LeaveVT; pScrn->LeaveVT = VGAarbiterLeaveVT; VGAPut(); @@ -556,450 +535,389 @@ static void VGAarbiterFreeScreen(int index, int flags) { ScreenPtr pScreen = screenInfo.screens[index]; - VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate( - &pScreen->devPrivates, VGAarbiterScreenKey); + VGAarbiterScreenPtr pScreenPriv = + (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + VGAarbiterScreenKey); VGAGet(pScreen); - (*pScreenPriv->FreeScreen)(index, flags); + (*pScreenPriv->FreeScreen) (index, flags); VGAPut(); } static Bool VGAarbiterCreateGC(GCPtr pGC) { - ScreenPtr pScreen = pGC->pScreen; - VGAarbiterGCPtr pGCPriv = (VGAarbiterGCPtr)dixLookupPrivate(&pGC->devPrivates, VGAarbiterGCKey); - Bool ret; + ScreenPtr pScreen = pGC->pScreen; + VGAarbiterGCPtr pGCPriv = + (VGAarbiterGCPtr) dixLookupPrivate(&pGC->devPrivates, VGAarbiterGCKey); + Bool ret; SCREEN_PROLOG(CreateGC); - ret = (*pScreen->CreateGC)(pGC); + ret = (*pScreen->CreateGC) (pGC); GC_WRAP(pGC); - SCREEN_EPILOG(CreateGC,VGAarbiterCreateGC); + SCREEN_EPILOG(CreateGC, VGAarbiterCreateGC); return ret; } /* GC funcs */ static void -VGAarbiterValidateGC( - GCPtr pGC, - unsigned long changes, - DrawablePtr pDraw ) +VGAarbiterValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw) { GC_UNWRAP(pGC); - (*pGC->funcs->ValidateGC)(pGC, changes, pDraw); + (*pGC->funcs->ValidateGC) (pGC, changes, pDraw); GC_WRAP(pGC); } - static void VGAarbiterDestroyGC(GCPtr pGC) { - GC_UNWRAP (pGC); - (*pGC->funcs->DestroyGC)(pGC); - GC_WRAP (pGC); + GC_UNWRAP(pGC); + (*pGC->funcs->DestroyGC) (pGC); + GC_WRAP(pGC); } static void -VGAarbiterChangeGC ( - GCPtr pGC, - unsigned long mask) +VGAarbiterChangeGC(GCPtr pGC, unsigned long mask) { - GC_UNWRAP (pGC); + GC_UNWRAP(pGC); (*pGC->funcs->ChangeGC) (pGC, mask); - GC_WRAP (pGC); + GC_WRAP(pGC); } static void -VGAarbiterCopyGC ( - GCPtr pGCSrc, - unsigned long mask, - GCPtr pGCDst) +VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) { - GC_UNWRAP (pGCDst); + GC_UNWRAP(pGCDst); (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); - GC_WRAP (pGCDst); + GC_WRAP(pGCDst); } static void -VGAarbiterChangeClip ( - GCPtr pGC, - int type, - pointer pvalue, - int nrects ) +VGAarbiterChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects) { - GC_UNWRAP (pGC); + GC_UNWRAP(pGC); (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); - GC_WRAP (pGC); + GC_WRAP(pGC); } static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc) { - GC_UNWRAP (pgcDst); - (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc); - GC_WRAP (pgcDst); + GC_UNWRAP(pgcDst); + (*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc); + GC_WRAP(pgcDst); } static void VGAarbiterDestroyClip(GCPtr pGC) { - GC_UNWRAP (pGC); - (* pGC->funcs->DestroyClip)(pGC); - GC_WRAP (pGC); + GC_UNWRAP(pGC); + (*pGC->funcs->DestroyClip) (pGC); + GC_WRAP(pGC); } /* GC Ops */ static void -VGAarbiterFillSpans( - DrawablePtr pDraw, - GC *pGC, - int nInit, - DDXPointPtr pptInit, - int *pwidthInit, - int fSorted ) +VGAarbiterFillSpans(DrawablePtr pDraw, + GC * pGC, + int nInit, + DDXPointPtr pptInit, int *pwidthInit, int fSorted) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted); + (*pGC->ops->FillSpans) (pDraw, pGC, nInit, pptInit, pwidthInit, fSorted); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterSetSpans( - DrawablePtr pDraw, - GCPtr pGC, - char *pcharsrc, - register DDXPointPtr ppt, - int *pwidth, - int nspans, - int fSorted ) +VGAarbiterSetSpans(DrawablePtr pDraw, + GCPtr pGC, + char *pcharsrc, + register DDXPointPtr ppt, + int *pwidth, int nspans, int fSorted) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted); + (*pGC->ops->SetSpans) (pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPutImage( - DrawablePtr pDraw, - GCPtr pGC, - int depth, - int x, int y, int w, int h, - int leftPad, - int format, - char *pImage ) +VGAarbiterPutImage(DrawablePtr pDraw, + GCPtr pGC, + int depth, + int x, int y, int w, int h, + int leftPad, int format, char *pImage) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h, - leftPad, format, pImage); + (*pGC->ops->PutImage) (pDraw, pGC, depth, x, y, w, h, + leftPad, format, pImage); VGAPut(); GC_WRAP(pGC); } static RegionPtr -VGAarbiterCopyArea( - DrawablePtr pSrc, - DrawablePtr pDst, - GC *pGC, - int srcx, int srcy, - int width, int height, - int dstx, int dsty ) +VGAarbiterCopyArea(DrawablePtr pSrc, + DrawablePtr pDst, + GC * pGC, + int srcx, int srcy, + int width, int height, int dstx, int dsty) { RegionPtr ret; ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - ret = (*pGC->ops->CopyArea)(pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty); + ret = (*pGC->ops->CopyArea) (pSrc, pDst, + pGC, srcx, srcy, width, height, dstx, dsty); VGAPut(); GC_WRAP(pGC); return ret; } static RegionPtr -VGAarbiterCopyPlane( - DrawablePtr pSrc, - DrawablePtr pDst, - GCPtr pGC, - int srcx, int srcy, - int width, int height, - int dstx, int dsty, - unsigned long bitPlane ) +VGAarbiterCopyPlane(DrawablePtr pSrc, + DrawablePtr pDst, + GCPtr pGC, + int srcx, int srcy, + int width, int height, + int dstx, int dsty, unsigned long bitPlane) { RegionPtr ret; ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - ret = (*pGC->ops->CopyPlane)(pSrc, pDst, pGC, srcx, srcy, - width, height, dstx, dsty, bitPlane); + ret = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, + width, height, dstx, dsty, bitPlane); VGAPut(); GC_WRAP(pGC); return ret; } static void -VGAarbiterPolyPoint( - DrawablePtr pDraw, - GCPtr pGC, - int mode, - int npt, - xPoint *pptInit ) +VGAarbiterPolyPoint(DrawablePtr pDraw, + GCPtr pGC, int mode, int npt, xPoint * pptInit) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit); + (*pGC->ops->PolyPoint) (pDraw, pGC, mode, npt, pptInit); VGAPut(); GC_WRAP(pGC); } - static void -VGAarbiterPolylines( - DrawablePtr pDraw, - GCPtr pGC, - int mode, - int npt, - DDXPointPtr pptInit ) +VGAarbiterPolylines(DrawablePtr pDraw, + GCPtr pGC, int mode, int npt, DDXPointPtr pptInit) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit); + (*pGC->ops->Polylines) (pDraw, pGC, mode, npt, pptInit); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolySegment( - DrawablePtr pDraw, - GCPtr pGC, - int nseg, - xSegment *pSeg ) +VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg, xSegment * pSeg) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg); + (*pGC->ops->PolySegment) (pDraw, pGC, nseg, pSeg); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolyRectangle( - DrawablePtr pDraw, - GCPtr pGC, - int nRectsInit, - xRectangle *pRectsInit ) +VGAarbiterPolyRectangle(DrawablePtr pDraw, + GCPtr pGC, int nRectsInit, xRectangle *pRectsInit) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyRectangle)(pDraw, pGC, nRectsInit, pRectsInit); + (*pGC->ops->PolyRectangle) (pDraw, pGC, nRectsInit, pRectsInit); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolyArc( - DrawablePtr pDraw, - GCPtr pGC, - int narcs, - xArc *parcs ) +VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs); + (*pGC->ops->PolyArc) (pDraw, pGC, narcs, parcs); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterFillPolygon( - DrawablePtr pDraw, - GCPtr pGC, - int shape, - int mode, - int count, - DDXPointPtr ptsIn ) +VGAarbiterFillPolygon(DrawablePtr pDraw, + GCPtr pGC, + int shape, int mode, int count, DDXPointPtr ptsIn) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, ptsIn); + (*pGC->ops->FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolyFillRect( - DrawablePtr pDraw, - GCPtr pGC, - int nrectFill, - xRectangle *prectInit) +VGAarbiterPolyFillRect(DrawablePtr pDraw, + GCPtr pGC, int nrectFill, xRectangle *prectInit) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyFillRect)(pDraw, pGC, nrectFill, prectInit); + (*pGC->ops->PolyFillRect) (pDraw, pGC, nrectFill, prectInit); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolyFillArc( - DrawablePtr pDraw, - GCPtr pGC, - int narcs, - xArc *parcs ) +VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs); + (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, parcs); VGAPut(); GC_WRAP(pGC); } static int -VGAarbiterPolyText8( - DrawablePtr pDraw, - GCPtr pGC, - int x, - int y, - int count, - char *chars ) +VGAarbiterPolyText8(DrawablePtr pDraw, + GCPtr pGC, int x, int y, int count, char *chars) { int ret; ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - ret = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars); + ret = (*pGC->ops->PolyText8) (pDraw, pGC, x, y, count, chars); VGAPut(); GC_WRAP(pGC); return ret; } static int -VGAarbiterPolyText16( - DrawablePtr pDraw, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars ) +VGAarbiterPolyText16(DrawablePtr pDraw, + GCPtr pGC, int x, int y, int count, unsigned short *chars) { int ret; ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - ret = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars); + ret = (*pGC->ops->PolyText16) (pDraw, pGC, x, y, count, chars); VGAPut(); GC_WRAP(pGC); return ret; } static void -VGAarbiterImageText8( - DrawablePtr pDraw, - GCPtr pGC, - int x, - int y, - int count, - char *chars ) +VGAarbiterImageText8(DrawablePtr pDraw, + GCPtr pGC, int x, int y, int count, char *chars) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars); + (*pGC->ops->ImageText8) (pDraw, pGC, x, y, count, chars); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterImageText16( - DrawablePtr pDraw, - GCPtr pGC, - int x, - int y, - int count, - unsigned short *chars ) +VGAarbiterImageText16(DrawablePtr pDraw, + GCPtr pGC, int x, int y, int count, unsigned short *chars) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars); + (*pGC->ops->ImageText16) (pDraw, pGC, x, y, count, chars); VGAPut(); GC_WRAP(pGC); } - static void -VGAarbiterImageGlyphBlt( - DrawablePtr pDraw, - GCPtr pGC, - int xInit, int yInit, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase ) +VGAarbiterImageGlyphBlt(DrawablePtr pDraw, + GCPtr pGC, + int xInit, int yInit, + unsigned int nglyph, + CharInfoPtr * ppci, pointer pglyphBase) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, xInit, yInit, - nglyph, ppci, pglyphBase); + (*pGC->ops->ImageGlyphBlt) (pDraw, pGC, xInit, yInit, + nglyph, ppci, pglyphBase); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPolyGlyphBlt( - DrawablePtr pDraw, - GCPtr pGC, - int xInit, int yInit, - unsigned int nglyph, - CharInfoPtr *ppci, - pointer pglyphBase ) +VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, + GCPtr pGC, + int xInit, int yInit, + unsigned int nglyph, + CharInfoPtr * ppci, pointer pglyphBase) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, xInit, yInit, - nglyph, ppci, pglyphBase); + (*pGC->ops->PolyGlyphBlt) (pDraw, pGC, xInit, yInit, + nglyph, ppci, pglyphBase); VGAPut(); GC_WRAP(pGC); } static void -VGAarbiterPushPixels( - GCPtr pGC, - PixmapPtr pBitMap, - DrawablePtr pDraw, - int dx, int dy, int xOrg, int yOrg ) +VGAarbiterPushPixels(GCPtr pGC, + PixmapPtr pBitMap, + DrawablePtr pDraw, int dx, int dy, int xOrg, int yOrg) { ScreenPtr pScreen = pGC->pScreen; + GC_UNWRAP(pGC); VGAGet(pScreen); - (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg); + (*pGC->ops->PushPixels) (pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg); VGAPut(); GC_WRAP(pGC); } - /* miSpriteFuncs */ static Bool -VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur) +VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCur) { Bool val; + SPRITE_PROLOG; VGAGet(pScreen); val = PointPriv->spriteFuncs->RealizeCursor(pDev, pScreen, pCur); @@ -1009,9 +927,11 @@ VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pC } static Bool -VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur) +VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCur) { Bool val; + SPRITE_PROLOG; VGAGet(pScreen); val = PointPriv->spriteFuncs->UnrealizeCursor(pDev, pScreen, pCur); @@ -1021,7 +941,8 @@ VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr } static void -VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur, int x, int y) +VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur, + int x, int y) { SPRITE_PROLOG; VGAGet(pScreen); @@ -1044,6 +965,7 @@ static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) { Bool val; + SPRITE_PROLOG; VGAGet(pScreen); val = PointPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen); @@ -1064,49 +986,49 @@ VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) static void VGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, - PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask, - INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, - CARD16 height) + PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask, + INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, + CARD16 height) { - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); + ScreenPtr pScreen = pDst->pDrawable->pScreen; + PictureScreenPtr ps = GetPictureScreen(pScreen); PICTURE_PROLOGUE(Composite); VGAGet(pScreen); (*ps->Composite) (op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, xDst, - yDst, width, height); + yDst, width, height); VGAPut(); PICTURE_EPILOGUE(Composite, VGAarbiterComposite); } static void VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst, - PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist, - GlyphListPtr list, GlyphPtr *glyphs) + PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist, + GlyphListPtr list, GlyphPtr * glyphs) { - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); + ScreenPtr pScreen = pDst->pDrawable->pScreen; + PictureScreenPtr ps = GetPictureScreen(pScreen); PICTURE_PROLOGUE(Glyphs); VGAGet(pScreen); - (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); + (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); VGAPut(); - PICTURE_EPILOGUE (Glyphs, VGAarbiterGlyphs); + PICTURE_EPILOGUE(Glyphs, VGAarbiterGlyphs); } static void -VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor *color, int nRect, - xRectangle *rects) +VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor * color, + int nRect, xRectangle *rects) { - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); + ScreenPtr pScreen = pDst->pDrawable->pScreen; + PictureScreenPtr ps = GetPictureScreen(pScreen); PICTURE_PROLOGUE(CompositeRects); VGAGet(pScreen); - (*ps->CompositeRects)(op, pDst, color, nRect, rects); + (*ps->CompositeRects) (op, pDst, color, nRect, rects); VGAPut(); - PICTURE_EPILOGUE (CompositeRects, VGAarbiterCompositeRects); + PICTURE_EPILOGUE(CompositeRects, VGAarbiterCompositeRects); } diff --git a/xorg-server/hw/xfree86/common/xf86VGAarbiterPriv.h b/xorg-server/hw/xfree86/common/xf86VGAarbiterPriv.h index 13fde5e79..2513ce65d 100644 --- a/xorg-server/hw/xfree86/common/xf86VGAarbiterPriv.h +++ b/xorg-server/hw/xfree86/common/xf86VGAarbiterPriv.h @@ -1,253 +1,268 @@ -/*
- * Copyright (c) 2009 Tiago Vignatti
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include <X11/X.h>
-#include "colormapst.h"
-#include "scrnintstr.h"
-#include "screenint.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "pixmap.h"
-#include "windowstr.h"
-#include "window.h"
-#include "xf86str.h"
-#include "mipointer.h"
-#include "mipointrst.h"
-# include "picturestr.h"
-
-
-#define WRAP_SCREEN(x,y) {pScreenPriv->x = pScreen->x; pScreen->x = y;}
-
-#define UNWRAP_SCREEN(x) pScreen->x = pScreenPriv->x
-
-#define SCREEN_PROLOG(x) pScreen->x = ((VGAarbiterScreenPtr) \
- dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey))->x
-
-#define SCREEN_EPILOG(x,y) pScreen->x = y;
-
-#define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\
- ps->x = y;}
-
-#define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;}
-
-#define PICTURE_PROLOGUE(field) ps->field = \
- ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
- VGAarbiterScreenKey))->field
-
-#define PICTURE_EPILOGUE(field, wrap) ps->field = wrap
-
-#define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0)
-
-#define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x
-
-#define SPRITE_PROLOG miPointerScreenPtr PointPriv = \
- (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates, \
- miPointerScreenKey); VGAarbiterScreenPtr pScreenPriv = \
- ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
- VGAarbiterScreenKey)); PointPriv->spriteFuncs = pScreenPriv->miSprite;
-
-#define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\
- PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs;
-
-#define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\
- PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \
- } while (0)
-
-#define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite
-
-#define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\
- pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\
- (x)->funcs = &VGAarbiterGCFuncs;
-
-#define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \
- (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\
- (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs;
-
-static inline void
-VGAGet(ScreenPtr pScreen) {
- pci_device_vgaarb_set_target(xf86Screens[pScreen->myNum]->vgaDev);
- pci_device_vgaarb_lock();
-}
-
-static inline void
-VGAPut(void) {
- pci_device_vgaarb_unlock();
-}
-
-typedef struct _VGAarbiterScreen {
- CreateGCProcPtr CreateGC;
- CloseScreenProcPtr CloseScreen;
- ScreenBlockHandlerProcPtr BlockHandler;
- ScreenWakeupHandlerProcPtr WakeupHandler;
- GetImageProcPtr GetImage;
- GetSpansProcPtr GetSpans;
- SourceValidateProcPtr SourceValidate;
- CopyWindowProcPtr CopyWindow;
- ClearToBackgroundProcPtr ClearToBackground;
- CreatePixmapProcPtr CreatePixmap;
- SaveScreenProcPtr SaveScreen;
- /* Colormap */
- StoreColorsProcPtr StoreColors;
- /* Cursor */
- DisplayCursorProcPtr DisplayCursor;
- RealizeCursorProcPtr RealizeCursor;
- UnrealizeCursorProcPtr UnrealizeCursor;
- RecolorCursorProcPtr RecolorCursor;
- SetCursorPositionProcPtr SetCursorPosition;
- void (*AdjustFrame)(int,int,int,int);
- Bool (*SwitchMode)(int, DisplayModePtr,int);
- Bool (*EnterVT)(int, int);
- void (*LeaveVT)(int, int);
- void (*FreeScreen)(int, int);
- miPointerSpriteFuncPtr miSprite;
- CompositeProcPtr Composite;
- GlyphsProcPtr Glyphs;
- CompositeRectsProcPtr CompositeRects;
-} VGAarbiterScreenRec, *VGAarbiterScreenPtr;
-
-typedef struct _VGAarbiterGC {
- GCOps *wrapOps;
- GCFuncs *wrapFuncs;
-} VGAarbiterGCRec, *VGAarbiterGCPtr;
-
-/* Screen funcs */
-static void VGAarbiterBlockHandler(int i, pointer blockData, pointer pTimeout, pointer pReadmask);
-static void VGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result, pointer pReadmask);
-static Bool VGAarbiterCloseScreen (int i, ScreenPtr pScreen);
-static void VGAarbiterGetImage (DrawablePtr pDrawable, int sx, int sy, int w,
- int h, unsigned int format, unsigned long planemask, char *pdstLine);
-static void VGAarbiterGetSpans (DrawablePtr pDrawable, int wMax, DDXPointPtr
- ppt, int *pwidth, int nspans, char *pdstStart);
-static void VGAarbiterSourceValidate (DrawablePtr pDrawable, int x, int y,
- int width, int height, unsigned int subWindowMode);
-static void VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
- RegionPtr prgnSrc);
-static void VGAarbiterClearToBackground (WindowPtr pWin, int x, int y, int w,
- int h, Bool generateExposures);
-static PixmapPtr VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h,
- int depth, unsigned int usage_hint);
-static Bool VGAarbiterCreateGC(GCPtr pGC);
-static Bool VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank);
-static void VGAarbiterStoreColors (ColormapPtr pmap, int ndef, xColorItem
- *pdefs);
-static void VGAarbiterRecolorCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
- CursorPtr pCurs, Bool displayed);
-static Bool VGAarbiterRealizeCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
- CursorPtr pCursor);
-static Bool VGAarbiterUnrealizeCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
- CursorPtr pCursor);
-static Bool VGAarbiterDisplayCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
- CursorPtr pCursor);
-static Bool VGAarbiterSetCursorPosition (DeviceIntPtr pDev, ScreenPtr
- pScreen, int x, int y, Bool generateEvent);
-static void VGAarbiterAdjustFrame(int index, int x, int y, int flags);
-static Bool VGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags);
-static Bool VGAarbiterEnterVT(int index, int flags);
-static void VGAarbiterLeaveVT(int index, int flags);
-static void VGAarbiterFreeScreen(int index, int flags);
-
-/* GC funcs */
-static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes,
- DrawablePtr pDraw);
-static void VGAarbiterChangeGC(GCPtr pGC, unsigned long mask);
-static void VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
-static void VGAarbiterDestroyGC(GCPtr pGC);
-static void VGAarbiterChangeClip(GCPtr pGC, int type, pointer pvalue,
- int nrects);
-static void VGAarbiterDestroyClip(GCPtr pGC);
-static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
-
-/* GC ops */
-static void VGAarbiterFillSpans( DrawablePtr pDraw, GC *pGC, int nInit,
- DDXPointPtr pptInit, int *pwidthInit, int fSorted);
-static void VGAarbiterSetSpans(DrawablePtr pDraw, GCPtr pGC, char *pcharsrc,
- register DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
-static void VGAarbiterPutImage(DrawablePtr pDraw, GCPtr pGC, int depth,
- int x, int y, int w, int h, int leftPad, int format, char *pImage);
-static RegionPtr VGAarbiterCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
- GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty);
-static RegionPtr VGAarbiterCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
- GCPtr pGC, int srcx, int srcy, int width, int height, int dstx, int dsty,
- unsigned long bitPlane);
-static void VGAarbiterPolyPoint(DrawablePtr pDraw, GCPtr pGC, int mode,
- int npt, xPoint *pptInit);
-static void VGAarbiterPolylines(DrawablePtr pDraw, GCPtr pGC, int mode,
- int npt, DDXPointPtr pptInit);
-static void VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg,
- xSegment *pSeg);
-static void VGAarbiterPolyRectangle(DrawablePtr pDraw, GCPtr pGC,
- int nRectsInit, xRectangle *pRectsInit);
-static void VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs,
- xArc *parcs);
-static void VGAarbiterFillPolygon(DrawablePtr pDraw, GCPtr pGC, int shape,
- int mode, int count, DDXPointPtr ptsIn);
-static void VGAarbiterPolyFillRect( DrawablePtr pDraw, GCPtr pGC,
- int nrectFill, xRectangle *prectInit);
-static void VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs,
- xArc *parcs);
-static int VGAarbiterPolyText8(DrawablePtr pDraw, GCPtr pGC, int x, int y,
- int count, char *chars);
-static int VGAarbiterPolyText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
- int count, unsigned short *chars);
-static void VGAarbiterImageText8(DrawablePtr pDraw, GCPtr pGC, int x, int y,
- int count, char *chars);
-static void VGAarbiterImageText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
- int count, unsigned short *chars);
-static void VGAarbiterImageGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit,
- int yInit, unsigned int nglyph, CharInfoPtr *ppci, pointer pglyphBase);
-static void VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit,
- int yInit, unsigned int nglyph, CharInfoPtr *ppci, pointer pglyphBase);
-static void VGAarbiterPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr
- pDraw, int dx, int dy, int xOrg, int yOrg);
-
-/* miSpriteFuncs */
-static Bool VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr
- pScreen, CursorPtr pCur);
-static Bool VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr
- pScreen, CursorPtr pCur);
-static void VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
- CursorPtr pCur, int x, int y);
-static void VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
- int x, int y);
-static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen);
-static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen);
-
-
-static void VGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
- PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask,
- INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
-static void VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
- PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist, GlyphListPtr
- list, GlyphPtr *glyphs);
-static void VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor
- *color, int nRect, xRectangle *rects);
+/* + * Copyright (c) 2009 Tiago Vignatti + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include "misc.h" +#include "xf86.h" +#include "xf86_OSproc.h" +#include <X11/X.h> +#include "colormapst.h" +#include "scrnintstr.h" +#include "screenint.h" +#include "gcstruct.h" +#include "pixmapstr.h" +#include "pixmap.h" +#include "windowstr.h" +#include "window.h" +#include "xf86str.h" +#include "mipointer.h" +#include "mipointrst.h" +#include "picturestr.h" + +#define WRAP_SCREEN(x,y) {pScreenPriv->x = pScreen->x; pScreen->x = y;} + +#define UNWRAP_SCREEN(x) pScreen->x = pScreenPriv->x + +#define SCREEN_PROLOG(x) pScreen->x = ((VGAarbiterScreenPtr) \ + dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey))->x + +#define SCREEN_EPILOG(x,y) pScreen->x = y; + +#define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\ + ps->x = y;} + +#define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;} + +#define PICTURE_PROLOGUE(field) ps->field = \ + ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \ + VGAarbiterScreenKey))->field + +#define PICTURE_EPILOGUE(field, wrap) ps->field = wrap + +#define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0) + +#define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x + +#define SPRITE_PROLOG miPointerScreenPtr PointPriv = \ + (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates, \ + miPointerScreenKey); VGAarbiterScreenPtr pScreenPriv = \ + ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \ + VGAarbiterScreenKey)); PointPriv->spriteFuncs = pScreenPriv->miSprite; + +#define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\ + PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; + +#define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\ + PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \ + } while (0) + +#define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite + +#define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\ + pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\ + (x)->funcs = &VGAarbiterGCFuncs; + +#define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \ + (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\ + (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs; + +static inline void +VGAGet(ScreenPtr pScreen) +{ + pci_device_vgaarb_set_target(xf86Screens[pScreen->myNum]->vgaDev); + pci_device_vgaarb_lock(); +} + +static inline void +VGAPut(void) +{ + pci_device_vgaarb_unlock(); +} + +typedef struct _VGAarbiterScreen { + CreateGCProcPtr CreateGC; + CloseScreenProcPtr CloseScreen; + ScreenBlockHandlerProcPtr BlockHandler; + ScreenWakeupHandlerProcPtr WakeupHandler; + GetImageProcPtr GetImage; + GetSpansProcPtr GetSpans; + SourceValidateProcPtr SourceValidate; + CopyWindowProcPtr CopyWindow; + ClearToBackgroundProcPtr ClearToBackground; + CreatePixmapProcPtr CreatePixmap; + SaveScreenProcPtr SaveScreen; + /* Colormap */ + StoreColorsProcPtr StoreColors; + /* Cursor */ + DisplayCursorProcPtr DisplayCursor; + RealizeCursorProcPtr RealizeCursor; + UnrealizeCursorProcPtr UnrealizeCursor; + RecolorCursorProcPtr RecolorCursor; + SetCursorPositionProcPtr SetCursorPosition; + void (*AdjustFrame) (int, int, int, int); + Bool (*SwitchMode) (int, DisplayModePtr, int); + Bool (*EnterVT) (int, int); + void (*LeaveVT) (int, int); + void (*FreeScreen) (int, int); + miPointerSpriteFuncPtr miSprite; + CompositeProcPtr Composite; + GlyphsProcPtr Glyphs; + CompositeRectsProcPtr CompositeRects; +} VGAarbiterScreenRec, *VGAarbiterScreenPtr; + +typedef struct _VGAarbiterGC { + GCOps *wrapOps; + GCFuncs *wrapFuncs; +} VGAarbiterGCRec, *VGAarbiterGCPtr; + +/* Screen funcs */ +static void VGAarbiterBlockHandler(int i, pointer blockData, pointer pTimeout, + pointer pReadmask); +static void VGAarbiterWakeupHandler(int i, pointer blockData, + unsigned long result, pointer pReadmask); +static Bool VGAarbiterCloseScreen(int i, ScreenPtr pScreen); +static void VGAarbiterGetImage(DrawablePtr pDrawable, int sx, int sy, int w, + int h, unsigned int format, + unsigned long planemask, char *pdstLine); +static void VGAarbiterGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt, + int *pwidth, int nspans, char *pdstStart); +static void VGAarbiterSourceValidate(DrawablePtr pDrawable, int x, int y, + int width, int height, + unsigned int subWindowMode); +static void VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, + RegionPtr prgnSrc); +static void VGAarbiterClearToBackground(WindowPtr pWin, int x, int y, int w, + int h, Bool generateExposures); +static PixmapPtr VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, + int depth, unsigned int usage_hint); +static Bool VGAarbiterCreateGC(GCPtr pGC); +static Bool VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank); +static void VGAarbiterStoreColors(ColormapPtr pmap, int ndef, xColorItem + * pdefs); +static void VGAarbiterRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCurs, Bool displayed); +static Bool VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCursor); +static Bool VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCursor); +static Bool VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCursor); +static Bool VGAarbiterSetCursorPosition(DeviceIntPtr pDev, ScreenPtr + pScreen, int x, int y, + Bool generateEvent); +static void VGAarbiterAdjustFrame(int index, int x, int y, int flags); +static Bool VGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags); +static Bool VGAarbiterEnterVT(int index, int flags); +static void VGAarbiterLeaveVT(int index, int flags); +static void VGAarbiterFreeScreen(int index, int flags); + +/* GC funcs */ +static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes, + DrawablePtr pDraw); +static void VGAarbiterChangeGC(GCPtr pGC, unsigned long mask); +static void VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst); +static void VGAarbiterDestroyGC(GCPtr pGC); +static void VGAarbiterChangeClip(GCPtr pGC, int type, pointer pvalue, + int nrects); +static void VGAarbiterDestroyClip(GCPtr pGC); +static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc); + +/* GC ops */ +static void VGAarbiterFillSpans(DrawablePtr pDraw, GC * pGC, int nInit, + DDXPointPtr pptInit, int *pwidthInit, + int fSorted); +static void VGAarbiterSetSpans(DrawablePtr pDraw, GCPtr pGC, char *pcharsrc, + register DDXPointPtr ppt, int *pwidth, + int nspans, int fSorted); +static void VGAarbiterPutImage(DrawablePtr pDraw, GCPtr pGC, int depth, int x, + int y, int w, int h, int leftPad, int format, + char *pImage); +static RegionPtr VGAarbiterCopyArea(DrawablePtr pSrc, DrawablePtr pDst, + GC * pGC, int srcx, int srcy, int width, + int height, int dstx, int dsty); +static RegionPtr VGAarbiterCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, + GCPtr pGC, int srcx, int srcy, int width, + int height, int dstx, int dsty, + unsigned long bitPlane); +static void VGAarbiterPolyPoint(DrawablePtr pDraw, GCPtr pGC, int mode, int npt, + xPoint * pptInit); +static void VGAarbiterPolylines(DrawablePtr pDraw, GCPtr pGC, int mode, int npt, + DDXPointPtr pptInit); +static void VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg, + xSegment * pSeg); +static void VGAarbiterPolyRectangle(DrawablePtr pDraw, GCPtr pGC, + int nRectsInit, xRectangle *pRectsInit); +static void VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, + xArc * parcs); +static void VGAarbiterFillPolygon(DrawablePtr pDraw, GCPtr pGC, int shape, + int mode, int count, DDXPointPtr ptsIn); +static void VGAarbiterPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nrectFill, + xRectangle *prectInit); +static void VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs, + xArc * parcs); +static int VGAarbiterPolyText8(DrawablePtr pDraw, GCPtr pGC, int x, int y, + int count, char *chars); +static int VGAarbiterPolyText16(DrawablePtr pDraw, GCPtr pGC, int x, int y, + int count, unsigned short *chars); +static void VGAarbiterImageText8(DrawablePtr pDraw, GCPtr pGC, int x, int y, + int count, char *chars); +static void VGAarbiterImageText16(DrawablePtr pDraw, GCPtr pGC, int x, int y, + int count, unsigned short *chars); +static void VGAarbiterImageGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit, + int yInit, unsigned int nglyph, + CharInfoPtr * ppci, pointer pglyphBase); +static void VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit, + int yInit, unsigned int nglyph, + CharInfoPtr * ppci, pointer pglyphBase); +static void VGAarbiterPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr + pDraw, int dx, int dy, int xOrg, int yOrg); + +/* miSpriteFuncs */ +static Bool VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr + pScreen, CursorPtr pCur); +static Bool VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr + pScreen, CursorPtr pCur); +static void VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + CursorPtr pCur, int x, int y); +static void VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, + int x, int y); +static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, + ScreenPtr pScreen); +static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen); + +static void VGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, + PicturePtr pDst, INT16 xSrc, INT16 ySrc, + INT16 xMask, INT16 yMask, INT16 xDst, + INT16 yDst, CARD16 width, CARD16 height); +static void VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst, + PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, + int nlist, GlyphListPtr list, GlyphPtr * glyphs); +static void VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, + xRenderColor * color, int nRect, + xRectangle *rects); diff --git a/xorg-server/hw/xfree86/common/xf86VidMode.c b/xorg-server/hw/xfree86/common/xf86VidMode.c index 2ae5484e3..13ffe061c 100644 --- a/xorg-server/hw/xfree86/common/xf86VidMode.c +++ b/xorg-server/hw/xfree86/common/xf86VidMode.c @@ -61,20 +61,20 @@ VidModeExtensionInit(ScreenPtr pScreen) { #ifdef XF86VIDMODE VidModePtr pVidMode; - + if (!xf86GetVidModeEnabled()) { - DebugF("!xf86GetVidModeEnabled()\n"); - return FALSE; + DebugF("!xf86GetVidModeEnabled()\n"); + return FALSE; } VidModeKey = &VidModeKeyRec; if (!dixRegisterPrivateKey(&VidModeKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; pVidMode = calloc(sizeof(VidModeRec), 1); if (!pVidMode) - return FALSE; + return FALSE; dixSetPrivate(&pScreen->devPrivates, VidModeKey, pVidMode); @@ -90,7 +90,6 @@ VidModeExtensionInit(ScreenPtr pScreen) #endif } - #ifdef XF86VIDMODE static Bool @@ -100,14 +99,14 @@ VidModeClose(int i, ScreenPtr pScreen) /* This shouldn't happen */ if (!pVidMode) - return FALSE; + return FALSE; pScreen->CloseScreen = pVidMode->CloseScreen; if (--VidModeCount == 0) { - free(dixLookupPrivate(&pScreen->devPrivates, VidModeKey)); - dixSetPrivate(&pScreen->devPrivates, VidModeKey, NULL); - VidModeKey = NULL; + free(dixLookupPrivate(&pScreen->devPrivates, VidModeKey)); + dixSetPrivate(&pScreen->devPrivates, VidModeKey, NULL); + VidModeKey = NULL; } return pScreen->CloseScreen(i, pScreen); } @@ -119,22 +118,22 @@ VidModeAvailable(int scrnIndex) VidModePtr pVidMode; if (VidModeKey == NULL) { - DebugF("VidModeKey == NULL\n"); - return FALSE; + DebugF("VidModeKey == NULL\n"); + return FALSE; } - + pScrn = xf86Screens[scrnIndex]; if (pScrn == NULL) { - DebugF("pScrn == NULL\n"); - return FALSE; + DebugF("pScrn == NULL\n"); + return FALSE; } - + pVidMode = VMPTR(pScrn->pScreen); if (pVidMode) - return TRUE; + return TRUE; else { - DebugF("pVidMode == NULL\n"); - return FALSE; + DebugF("pVidMode == NULL\n"); + return FALSE; } } @@ -144,15 +143,15 @@ VidModeGetCurrentModeline(int scrnIndex, pointer *mode, int *dotClock) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; if (pScrn->currentMode) { - *mode = (pointer)(pScrn->currentMode); - *dotClock = pScrn->currentMode->Clock; + *mode = (pointer) (pScrn->currentMode); + *dotClock = pScrn->currentMode->Clock; - return TRUE; + return TRUE; } return FALSE; } @@ -163,13 +162,13 @@ VidModeGetDotClock(int scrnIndex, int Clock) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return 0; + return 0; pScrn = xf86Screens[scrnIndex]; if ((pScrn->progClock) || (Clock >= MAXCLOCKS)) - return Clock; - else - return pScrn->clock[Clock]; + return Clock; + else + return pScrn->clock[Clock]; } int @@ -178,15 +177,16 @@ VidModeGetNumOfClocks(int scrnIndex, Bool *progClock) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return 0; + return 0; pScrn = xf86Screens[scrnIndex]; - if (pScrn->progClock){ - *progClock = TRUE; - return 0; - } else { - *progClock = FALSE; - return pScrn->numClocks; + if (pScrn->progClock) { + *progClock = TRUE; + return 0; + } + else { + *progClock = FALSE; + return pScrn->numClocks; } } @@ -197,20 +197,19 @@ VidModeGetClocks(int scrnIndex, int *Clocks) int i; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; if (pScrn->progClock) - return FALSE; + return FALSE; - for (i = 0; i < pScrn->numClocks; i++) - *Clocks++ = pScrn->clock[i]; + for (i = 0; i < pScrn->numClocks; i++) + *Clocks++ = pScrn->clock[i]; return TRUE; } - Bool VidModeGetFirstModeline(int scrnIndex, pointer *mode, int *dotClock) { @@ -218,20 +217,20 @@ VidModeGetFirstModeline(int scrnIndex, pointer *mode, int *dotClock) VidModePtr pVidMode; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; if (pScrn->modes == NULL) - return FALSE; + return FALSE; pVidMode = VMPTR(pScrn->pScreen); pVidMode->First = pScrn->modes; - pVidMode->Next = pVidMode->First->next; + pVidMode->Next = pVidMode->First->next; if (pVidMode->First->status == MODE_OK) { - *mode = (pointer)(pVidMode->First); - *dotClock = VidModeGetDotClock(scrnIndex, pVidMode->First->Clock); - return TRUE; + *mode = (pointer) (pVidMode->First); + *dotClock = VidModeGetDotClock(scrnIndex, pVidMode->First->Clock); + return TRUE; } return VidModeGetNextModeline(scrnIndex, mode, dotClock); @@ -245,20 +244,20 @@ VidModeGetNextModeline(int scrnIndex, pointer *mode, int *dotClock) DisplayModePtr p; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; pVidMode = VMPTR(pScrn->pScreen); for (p = pVidMode->Next; p != NULL && p != pVidMode->First; p = p->next) { - if (p->status == MODE_OK) { - pVidMode->Next = p->next; - *mode = (pointer)p; - *dotClock = VidModeGetDotClock(scrnIndex, p->Clock); - return TRUE; - } + if (p->status == MODE_OK) { + pVidMode->Next = p->next; + *mode = (pointer) p; + *dotClock = VidModeGetDotClock(scrnIndex, p->Clock); + return TRUE; + } } - + return FALSE; } @@ -268,10 +267,10 @@ VidModeDeleteModeline(int scrnIndex, pointer mode) ScrnInfoPtr pScrn; if ((mode == NULL) || (!VidModeAvailable(scrnIndex))) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; - xf86DeleteMode(&(pScrn->modes), (DisplayModePtr)mode); + xf86DeleteMode(&(pScrn->modes), (DisplayModePtr) mode); return TRUE; } @@ -281,7 +280,7 @@ VidModeZoomViewport(int scrnIndex, int zoom) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; xf86ZoomViewport(pScrn->pScreen, zoom); @@ -294,17 +293,17 @@ VidModeSetViewPort(int scrnIndex, int x, int y) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; - pScrn->frameX0 = min( max(x, 0), - pScrn->virtualX - pScrn->currentMode->HDisplay ); + pScrn->frameX0 = min(max(x, 0), + pScrn->virtualX - pScrn->currentMode->HDisplay); pScrn->frameX1 = pScrn->frameX0 + pScrn->currentMode->HDisplay - 1; - pScrn->frameY0 = min( max(y, 0), - pScrn->virtualY - pScrn->currentMode->VDisplay ); + pScrn->frameY0 = min(max(y, 0), + pScrn->virtualY - pScrn->currentMode->VDisplay); pScrn->frameY1 = pScrn->frameY0 + pScrn->currentMode->VDisplay - 1; if (pScrn->AdjustFrame != NULL) - (pScrn->AdjustFrame)(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + (pScrn->AdjustFrame) (scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); return TRUE; } @@ -315,7 +314,7 @@ VidModeGetViewPort(int scrnIndex, int *x, int *y) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; *x = pScrn->frameX0; @@ -331,7 +330,7 @@ VidModeSwitchMode(int scrnIndex, pointer mode) Bool retval; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; /* save in case we fail */ @@ -341,7 +340,7 @@ VidModeSwitchMode(int scrnIndex, pointer mode) retval = xf86SwitchMode(pScrn->pScreen, mode); /* we failed: restore it */ if (retval == FALSE) - pScrn->currentMode = pTmpMode; + pScrn->currentMode = pTmpMode; return retval; } @@ -351,12 +350,12 @@ VidModeLockZoom(int scrnIndex, Bool lock) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; if (xf86Info.dontZoom) - return FALSE; + return FALSE; xf86LockZoom(pScrn->pScreen, lock); return TRUE; @@ -368,10 +367,10 @@ VidModeGetMonitor(int scrnIndex, pointer *monitor) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; - *monitor = (pointer)(pScrn->monitor); + *monitor = (pointer) (pScrn->monitor); return TRUE; } @@ -382,11 +381,11 @@ VidModeCheckModeForMonitor(int scrnIndex, pointer mode) ScrnInfoPtr pScrn; if ((mode == NULL) || (!VidModeAvailable(scrnIndex))) - return MODE_ERROR; + return MODE_ERROR; pScrn = xf86Screens[scrnIndex]; - return xf86CheckModeForMonitor((DisplayModePtr)mode, pScrn->monitor); + return xf86CheckModeForMonitor((DisplayModePtr) mode, pScrn->monitor); } ModeStatus @@ -395,11 +394,11 @@ VidModeCheckModeForDriver(int scrnIndex, pointer mode) ScrnInfoPtr pScrn; if ((mode == NULL) || (!VidModeAvailable(scrnIndex))) - return MODE_ERROR; + return MODE_ERROR; pScrn = xf86Screens[scrnIndex]; - return xf86CheckModeForDriver(pScrn, (DisplayModePtr)mode, 0); + return xf86CheckModeForDriver(pScrn, (DisplayModePtr) mode, 0); } void @@ -407,15 +406,15 @@ VidModeSetCrtcForMode(int scrnIndex, pointer mode) { ScrnInfoPtr pScrn; DisplayModePtr ScreenModes; - + if ((mode == NULL) || (!VidModeAvailable(scrnIndex))) - return; + return; /* Ugly hack so that the xf86Mode.c function can be used without change */ pScrn = xf86Screens[scrnIndex]; ScreenModes = pScrn->modes; - pScrn->modes = (DisplayModePtr)mode; - + pScrn->modes = (DisplayModePtr) mode; + xf86SetCrtcForModes(pScrn, pScrn->adjustFlags); pScrn->modes = ScreenModes; return; @@ -425,19 +424,19 @@ Bool VidModeAddModeline(int scrnIndex, pointer mode) { ScrnInfoPtr pScrn; - + if ((mode == NULL) || (!VidModeAvailable(scrnIndex))) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; - ((DisplayModePtr)mode)->name = strdup(""); /* freed by deletemode */ - ((DisplayModePtr)mode)->status = MODE_OK; - ((DisplayModePtr)mode)->next = pScrn->modes->next; - ((DisplayModePtr)mode)->prev = pScrn->modes; - pScrn->modes->next = (DisplayModePtr)mode; - if( ((DisplayModePtr)mode)->next != NULL ) - ((DisplayModePtr)mode)->next->prev = (DisplayModePtr)mode; + ((DisplayModePtr) mode)->name = strdup(""); /* freed by deletemode */ + ((DisplayModePtr) mode)->status = MODE_OK; + ((DisplayModePtr) mode)->next = pScrn->modes->next; + ((DisplayModePtr) mode)->prev = pScrn->modes; + pScrn->modes->next = (DisplayModePtr) mode; + if (((DisplayModePtr) mode)->next != NULL) + ((DisplayModePtr) mode)->next->prev = (DisplayModePtr) mode; return TRUE; } @@ -446,15 +445,15 @@ int VidModeGetNumOfModes(int scrnIndex) { pointer mode = NULL; - int dotClock= 0, nummodes = 0; - + int dotClock = 0, nummodes = 0; + if (!VidModeGetFirstModeline(scrnIndex, &mode, &dotClock)) - return nummodes; + return nummodes; do { - nummodes++; - if (!VidModeGetNextModeline(scrnIndex, &mode, &dotClock)) - return nummodes; + nummodes++; + if (!VidModeGetNextModeline(scrnIndex, &mode, &dotClock)) + return nummodes; } while (TRUE); } @@ -465,16 +464,16 @@ VidModeSetGamma(int scrnIndex, float red, float green, float blue) Gamma gamma; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; gamma.red = red; gamma.green = green; gamma.blue = blue; if (xf86ChangeGamma(pScrn->pScreen, gamma) != Success) - return FALSE; + return FALSE; else - return TRUE; + return TRUE; } Bool @@ -483,7 +482,7 @@ VidModeGetGamma(int scrnIndex, float *red, float *green, float *blue) ScrnInfoPtr pScrn; if (!VidModeAvailable(scrnIndex)) - return FALSE; + return FALSE; pScrn = xf86Screens[scrnIndex]; *red = pScrn->gamma.red; @@ -499,7 +498,7 @@ VidModeSetGammaRamp(int scrnIndex, int size, CARD16 *r, CARD16 *g, CARD16 *b) if (!VidModeAvailable(scrnIndex)) return FALSE; - + pScrn = xf86Screens[scrnIndex]; xf86ChangeGammaRamp(pScrn->pScreen, size, r, g, b); return TRUE; @@ -531,14 +530,14 @@ pointer VidModeCreateMode(void) { DisplayModePtr mode; - + mode = malloc(sizeof(DisplayModeRec)); if (mode != NULL) { - mode->name = ""; - mode->VScan = 1; /* divides refresh rate. default = 1 */ - mode->Private = NULL; - mode->next = mode; - mode->prev = mode; + mode->name = ""; + mode->VScan = 1; /* divides refresh rate. default = 1 */ + mode->Private = NULL; + mode->next = mode; + mode->prev = mode; } return mode; } @@ -546,127 +545,125 @@ VidModeCreateMode(void) void VidModeCopyMode(pointer modefrom, pointer modeto) { - memcpy(modeto, modefrom, sizeof(DisplayModeRec)); + memcpy(modeto, modefrom, sizeof(DisplayModeRec)); } - int VidModeGetModeValue(pointer mode, int valtyp) { - int ret = 0; - - switch (valtyp) { + int ret = 0; + + switch (valtyp) { case VIDMODE_H_DISPLAY: - ret = ((DisplayModePtr) mode)->HDisplay; - break; + ret = ((DisplayModePtr) mode)->HDisplay; + break; case VIDMODE_H_SYNCSTART: - ret = ((DisplayModePtr)mode)->HSyncStart; - break; + ret = ((DisplayModePtr) mode)->HSyncStart; + break; case VIDMODE_H_SYNCEND: - ret = ((DisplayModePtr)mode)->HSyncEnd; - break; + ret = ((DisplayModePtr) mode)->HSyncEnd; + break; case VIDMODE_H_TOTAL: - ret = ((DisplayModePtr)mode)->HTotal; - break; + ret = ((DisplayModePtr) mode)->HTotal; + break; case VIDMODE_H_SKEW: - ret = ((DisplayModePtr)mode)->HSkew; - break; + ret = ((DisplayModePtr) mode)->HSkew; + break; case VIDMODE_V_DISPLAY: - ret = ((DisplayModePtr)mode)->VDisplay; - break; + ret = ((DisplayModePtr) mode)->VDisplay; + break; case VIDMODE_V_SYNCSTART: - ret = ((DisplayModePtr)mode)->VSyncStart; - break; + ret = ((DisplayModePtr) mode)->VSyncStart; + break; case VIDMODE_V_SYNCEND: - ret = ((DisplayModePtr)mode)->VSyncEnd; - break; + ret = ((DisplayModePtr) mode)->VSyncEnd; + break; case VIDMODE_V_TOTAL: - ret = ((DisplayModePtr)mode)->VTotal; - break; + ret = ((DisplayModePtr) mode)->VTotal; + break; case VIDMODE_FLAGS: - ret = ((DisplayModePtr)mode)->Flags; - break; + ret = ((DisplayModePtr) mode)->Flags; + break; case VIDMODE_CLOCK: - ret = ((DisplayModePtr)mode)->Clock; - break; - } - return ret; + ret = ((DisplayModePtr) mode)->Clock; + break; + } + return ret; } void VidModeSetModeValue(pointer mode, int valtyp, int val) { - switch (valtyp) { + switch (valtyp) { case VIDMODE_H_DISPLAY: - ((DisplayModePtr)mode)->HDisplay = val; - break; + ((DisplayModePtr) mode)->HDisplay = val; + break; case VIDMODE_H_SYNCSTART: - ((DisplayModePtr)mode)->HSyncStart = val; - break; + ((DisplayModePtr) mode)->HSyncStart = val; + break; case VIDMODE_H_SYNCEND: - ((DisplayModePtr)mode)->HSyncEnd = val; - break; + ((DisplayModePtr) mode)->HSyncEnd = val; + break; case VIDMODE_H_TOTAL: - ((DisplayModePtr)mode)->HTotal = val; - break; + ((DisplayModePtr) mode)->HTotal = val; + break; case VIDMODE_H_SKEW: - ((DisplayModePtr)mode)->HSkew = val; - break; + ((DisplayModePtr) mode)->HSkew = val; + break; case VIDMODE_V_DISPLAY: - ((DisplayModePtr)mode)->VDisplay = val; - break; + ((DisplayModePtr) mode)->VDisplay = val; + break; case VIDMODE_V_SYNCSTART: - ((DisplayModePtr)mode)->VSyncStart = val; - break; + ((DisplayModePtr) mode)->VSyncStart = val; + break; case VIDMODE_V_SYNCEND: - ((DisplayModePtr)mode)->VSyncEnd = val; - break; + ((DisplayModePtr) mode)->VSyncEnd = val; + break; case VIDMODE_V_TOTAL: - ((DisplayModePtr)mode)->VTotal = val; - break; + ((DisplayModePtr) mode)->VTotal = val; + break; case VIDMODE_FLAGS: - ((DisplayModePtr)mode)->Flags = val; - break; + ((DisplayModePtr) mode)->Flags = val; + break; case VIDMODE_CLOCK: - ((DisplayModePtr)mode)->Clock = val; - break; - } - return; + ((DisplayModePtr) mode)->Clock = val; + break; + } + return; } vidMonitorValue VidModeGetMonitorValue(pointer monitor, int valtyp, int indx) { - vidMonitorValue ret = { NULL, }; - - switch (valtyp) { + vidMonitorValue ret = { NULL, }; + + switch (valtyp) { case VIDMODE_MON_VENDOR: - ret.ptr = (((MonPtr)monitor)->vendor); - break; + ret.ptr = (((MonPtr) monitor)->vendor); + break; case VIDMODE_MON_MODEL: - ret.ptr = (((MonPtr)monitor)->model); - break; + ret.ptr = (((MonPtr) monitor)->model); + break; case VIDMODE_MON_NHSYNC: - ret.i = ((MonPtr)monitor)->nHsync; - break; + ret.i = ((MonPtr) monitor)->nHsync; + break; case VIDMODE_MON_NVREFRESH: - ret.i = ((MonPtr)monitor)->nVrefresh; - break; + ret.i = ((MonPtr) monitor)->nVrefresh; + break; case VIDMODE_MON_HSYNC_LO: - ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].lo); - break; + ret.f = (100.0 * ((MonPtr) monitor)->hsync[indx].lo); + break; case VIDMODE_MON_HSYNC_HI: - ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].hi); - break; + ret.f = (100.0 * ((MonPtr) monitor)->hsync[indx].hi); + break; case VIDMODE_MON_VREFRESH_LO: - ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].lo); - break; + ret.f = (100.0 * ((MonPtr) monitor)->vrefresh[indx].lo); + break; case VIDMODE_MON_VREFRESH_HI: - ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].hi); - break; - } - return ret; + ret.f = (100.0 * ((MonPtr) monitor)->vrefresh[indx].hi); + break; + } + return ret; } - -#endif /* XF86VIDMODE */ +#endif /* XF86VIDMODE */ diff --git a/xorg-server/hw/xfree86/common/xf86Xinput.c b/xorg-server/hw/xfree86/common/xf86Xinput.c index f6be99910..77b800000 100644 --- a/xorg-server/hw/xfree86/common/xf86Xinput.c +++ b/xorg-server/hw/xfree86/common/xf86Xinput.c @@ -64,13 +64,13 @@ #include "extinit.h" #include "loaderProcs.h" -#include "exevents.h" /* AddInputDevice */ +#include "exevents.h" /* AddInputDevice */ #include "exglobals.h" #include "eventstr.h" #include "inpututils.h" #include "optionstr.h" -#include <string.h> /* InputClassMatches */ +#include <string.h> /* InputClassMatches */ #ifdef HAVE_FNMATCH_H #include <fnmatch.h> #endif @@ -79,11 +79,11 @@ #endif #include <stdarg.h> -#include <stdint.h> /* for int64_t */ +#include <stdint.h> /* for int64_t */ #include "mi.h" -#include <ptrveloc.h> /* dix pointer acceleration */ +#include <ptrveloc.h> /* dix pointer acceleration */ #include <xserver-properties.h> #ifdef XFreeXDGA @@ -101,13 +101,13 @@ } static int -xf86InputDevicePostInit(DeviceIntPtr dev); + xf86InputDevicePostInit(DeviceIntPtr dev); /** * Eval config and modify DeviceVelocityRec accordingly */ static void -ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, +ProcessVelocityConfiguration(DeviceIntPtr pDev, char *devname, pointer list, DeviceVelocityPtr s) { int tempi; @@ -115,7 +115,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, Atom float_prop = XIGetKnownProperty(XATOM_FLOAT); Atom prop; - if(!s) + if (!s) return; /* common settings (available via device properties) */ @@ -139,14 +139,15 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, /* select profile by number */ tempi = xf86SetIntOption(list, "AccelerationProfile", - s->statistics.profile_number); + s->statistics.profile_number); prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER); if (XIChangeDeviceProperty(pDev, prop, XA_INTEGER, 32, PropModeReplace, 1, &tempi, FALSE) == Success) { xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i\n", devname, tempi); - } else { + } + else { xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i is unknown\n", devname, tempi); } @@ -158,7 +159,8 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, tempf = 1000.0 / tempf; XIChangeDeviceProperty(pDev, prop, float_prop, 32, PropModeReplace, 1, &tempf, FALSE); - } else { + } + else { tempf = xf86SetRealOption(list, "VelocityScale", s->corr_mul); XIChangeDeviceProperty(pDev, prop, float_prop, 32, PropModeReplace, 1, &tempf, FALSE); @@ -166,7 +168,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, tempi = xf86SetIntOption(list, "VelocityTrackerCount", -1); if (tempi > 1) - InitTrackers(s, tempi); + InitTrackers(s, tempi); s->initial_range = xf86SetIntOption(list, "VelocityInitialRange", s->initial_range); @@ -175,9 +177,9 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, tempf = xf86SetRealOption(list, "VelocityRelDiff", -1); if (tempf >= 0) { - xf86Msg(X_CONFIG, "%s: (accel) max rel. velocity difference: %.1f%%\n", - devname, tempf*100.0); - s->max_rel_diff = tempf; + xf86Msg(X_CONFIG, "%s: (accel) max rel. velocity difference: %.1f%%\n", + devname, tempf * 100.0); + s->max_rel_diff = tempf; } /* Configure softening. If const deceleration is used, this is expected @@ -194,25 +196,26 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list, } static void -ApplyAccelerationSettings(DeviceIntPtr dev){ +ApplyAccelerationSettings(DeviceIntPtr dev) +{ int scheme, i; DeviceVelocityPtr pVel; - InputInfoPtr pInfo = (InputInfoPtr)dev->public.devicePrivate; - char* schemeStr; + InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; + char *schemeStr; if (dev->valuator && dev->ptrfeed) { - schemeStr = xf86SetStrOption(pInfo->options, "AccelerationScheme", ""); + schemeStr = xf86SetStrOption(pInfo->options, "AccelerationScheme", ""); - scheme = dev->valuator->accelScheme.number; + scheme = dev->valuator->accelScheme.number; - if (!xf86NameCmp(schemeStr, "predictable")) - scheme = PtrAccelPredictable; + if (!xf86NameCmp(schemeStr, "predictable")) + scheme = PtrAccelPredictable; - if (!xf86NameCmp(schemeStr, "lightweight")) - scheme = PtrAccelLightweight; + if (!xf86NameCmp(schemeStr, "lightweight")) + scheme = PtrAccelLightweight; - if (!xf86NameCmp(schemeStr, "none")) - scheme = PtrAccelNoOp; + if (!xf86NameCmp(schemeStr, "none")) + scheme = PtrAccelNoOp; /* reinit scheme if needed */ if (dev->valuator->accelScheme.number != scheme) { @@ -221,14 +224,16 @@ ApplyAccelerationSettings(DeviceIntPtr dev){ } if (InitPointerAccelerationScheme(dev, scheme)) { - xf86Msg(X_CONFIG, "%s: (accel) selected scheme %s/%i\n", - pInfo->name, schemeStr, scheme); - } else { - xf86Msg(X_CONFIG, "%s: (accel) could not init scheme %s\n", - pInfo->name, schemeStr); - scheme = dev->valuator->accelScheme.number; + xf86Msg(X_CONFIG, "%s: (accel) selected scheme %s/%i\n", + pInfo->name, schemeStr, scheme); } - } else { + else { + xf86Msg(X_CONFIG, "%s: (accel) could not init scheme %s\n", + pInfo->name, schemeStr); + scheme = dev->valuator->accelScheme.number; + } + } + else { xf86Msg(X_CONFIG, "%s: (accel) keeping acceleration scheme %i\n", pInfo->name, scheme); } @@ -237,11 +242,11 @@ ApplyAccelerationSettings(DeviceIntPtr dev){ /* process special configuration */ switch (scheme) { - case PtrAccelPredictable: - pVel = GetDevicePredictableAccelData(dev); - ProcessVelocityConfiguration (dev, pInfo->name, pInfo->options, - pVel); - break; + case PtrAccelPredictable: + pVel = GetDevicePredictableAccelData(dev); + ProcessVelocityConfiguration(dev, pInfo->name, pInfo->options, + pVel); + break; } i = xf86SetIntOption(pInfo->options, "AccelerationNumerator", @@ -260,8 +265,8 @@ ApplyAccelerationSettings(DeviceIntPtr dev){ dev->ptrfeed->ctrl.threshold = i; xf86Msg(X_CONFIG, "%s: (accel) acceleration factor: %.3f\n", - pInfo->name, ((float)dev->ptrfeed->ctrl.num)/ - ((float)dev->ptrfeed->ctrl.den)); + pInfo->name, ((float) dev->ptrfeed->ctrl.num) / + ((float) dev->ptrfeed->ctrl.den)); xf86Msg(X_CONFIG, "%s: (accel) acceleration threshold: %i\n", pInfo->name, dev->ptrfeed->ctrl.threshold); } @@ -270,10 +275,10 @@ ApplyAccelerationSettings(DeviceIntPtr dev){ static void ApplyTransformationMatrix(DeviceIntPtr dev) { - InputInfoPtr pInfo = (InputInfoPtr)dev->public.devicePrivate; + InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; char *str; int rc; - float matrix[9] = {0}; + float matrix[9] = { 0 }; if (!dev->valuator) return; @@ -282,10 +287,12 @@ ApplyTransformationMatrix(DeviceIntPtr dev) if (!str) return; - rc = sscanf(str, "%f %f %f %f %f %f %f %f %f", &matrix[0], &matrix[1], &matrix[2], - &matrix[3], &matrix[4], &matrix[5], &matrix[6], &matrix[7], &matrix[8]); + rc = sscanf(str, "%f %f %f %f %f %f %f %f %f", &matrix[0], &matrix[1], + &matrix[2], &matrix[3], &matrix[4], &matrix[5], &matrix[6], + &matrix[7], &matrix[8]); if (rc != 9) { - xf86Msg(X_ERROR, "%s: invalid format for transformation matrix. Ignoring configuration.\n", + xf86Msg(X_ERROR, + "%s: invalid format for transformation matrix. Ignoring configuration.\n", pInfo->name); return; } @@ -304,8 +311,7 @@ ApplyTransformationMatrix(DeviceIntPtr dev) *********************************************************************** */ void -xf86ProcessCommonOptions(InputInfoPtr pInfo, - XF86OptionPtr list) +xf86ProcessCommonOptions(InputInfoPtr pInfo, XF86OptionPtr list) { if (xf86SetBoolOption(list, "Floating", 0) || !xf86SetBoolOption(list, "AlwaysCore", 1) || @@ -313,7 +319,8 @@ xf86ProcessCommonOptions(InputInfoPtr pInfo, !xf86SetBoolOption(list, "CorePointer", 1) || !xf86SetBoolOption(list, "CoreKeyboard", 1)) { xf86Msg(X_CONFIG, "%s: doesn't report core events\n", pInfo->name); - } else { + } + else { pInfo->flags |= XI86_ALWAYS_CORE; xf86Msg(X_CONFIG, "%s: always reports core events\n", pInfo->name); } @@ -331,15 +338,13 @@ xf86ProcessCommonOptions(InputInfoPtr pInfo, static DeviceIntPtr xf86ActivateDevice(InputInfoPtr pInfo) { - DeviceIntPtr dev; - Atom atom; + DeviceIntPtr dev; + Atom atom; dev = AddInputDevice(serverClient, pInfo->device_control, TRUE); - if (dev == NULL) - { - xf86Msg(X_ERROR, "Too many input devices. Ignoring %s\n", - pInfo->name); + if (dev == NULL) { + xf86Msg(X_ERROR, "Too many input devices. Ignoring %s\n", pInfo->name); pInfo->dev = NULL; return NULL; } @@ -356,7 +361,8 @@ xf86ActivateDevice(InputInfoPtr pInfo) dev->config_info = xf86SetStrOption(pInfo->options, "config_info", NULL); if (serverGeneration == 1) - xf86Msg(X_INFO, "XINPUT: Adding extended input device \"%s\" (type: %s, id %d)\n", + xf86Msg(X_INFO, + "XINPUT: Adding extended input device \"%s\" (type: %s, id %d)\n", pInfo->name, pInfo->type_name, dev->id); return dev; @@ -376,18 +382,17 @@ xf86ActivateDevice(InputInfoPtr pInfo) */ int -SetDeviceMode (ClientPtr client, DeviceIntPtr dev, int mode) +SetDeviceMode(ClientPtr client, DeviceIntPtr dev, int mode) { - InputInfoPtr pInfo = (InputInfoPtr)dev->public.devicePrivate; + InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - if (pInfo->switch_mode) { - return (*pInfo->switch_mode)(client, dev, mode); - } - else - return BadMatch; + if (pInfo->switch_mode) { + return (*pInfo->switch_mode) (client, dev, mode); + } + else + return BadMatch; } - /*********************************************************************** * * Caller: ProcXSetDeviceValuators @@ -402,19 +407,18 @@ SetDeviceMode (ClientPtr client, DeviceIntPtr dev, int mode) */ int -SetDeviceValuators (ClientPtr client, DeviceIntPtr dev, int *valuators, - int first_valuator, int num_valuators) +SetDeviceValuators(ClientPtr client, DeviceIntPtr dev, int *valuators, + int first_valuator, int num_valuators) { InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; if (pInfo->set_device_valuators) - return (*pInfo->set_device_valuators)(pInfo, valuators, first_valuator, - num_valuators); + return (*pInfo->set_device_valuators) (pInfo, valuators, first_valuator, + num_valuators); return BadMatch; } - /*********************************************************************** * * Caller: ProcXChangeDeviceControl @@ -425,26 +429,26 @@ SetDeviceValuators (ClientPtr client, DeviceIntPtr dev, int *valuators, */ int -ChangeDeviceControl (ClientPtr client, DeviceIntPtr dev, xDeviceCtl *control) +ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, xDeviceCtl * control) { - InputInfoPtr pInfo = (InputInfoPtr)dev->public.devicePrivate; - - if (!pInfo->control_proc) { - switch (control->control) { - case DEVICE_CORE: - case DEVICE_ABS_CALIB: - case DEVICE_ABS_AREA: - return BadMatch; - case DEVICE_RESOLUTION: - case DEVICE_ENABLE: - return Success; - default: - return BadMatch; - } - } - else { - return (*pInfo->control_proc)(pInfo, control); - } + InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; + + if (!pInfo->control_proc) { + switch (control->control) { + case DEVICE_CORE: + case DEVICE_ABS_CALIB: + case DEVICE_ABS_AREA: + return BadMatch; + case DEVICE_RESOLUTION: + case DEVICE_ENABLE: + return Success; + default: + return BadMatch; + } + } + else { + return (*pInfo->control_proc) (pInfo, control); + } } /* @@ -506,8 +510,9 @@ match_string_implicit(const char *attr, const char *pattern) { if (strlen(pattern)) { return strcmp(attr, pattern); - } else { - return strcmp(attr,"(implicit)"); + } + else { + return strcmp(attr, "(implicit)"); } } @@ -517,7 +522,7 @@ match_string_implicit(const char *attr, const char *pattern) */ static Bool MatchAttrToken(const char *attr, struct xorg_list *patterns, - int (*compare)(const char *attr, const char *pattern)) + int (*compare) (const char *attr, const char *pattern)) { const xf86MatchGroup *group; @@ -534,11 +539,11 @@ MatchAttrToken(const char *attr, struct xorg_list *patterns, * match. Each list entry is a separate Match line of the same type. */ xorg_list_for_each_entry(group, patterns, entry) { - char * const *cur; + char *const *cur; Bool match = FALSE; for (cur = group->values; *cur; cur++) - if ((*compare)(attr, *cur) == 0) { + if ((*compare) (attr, *cur) == 0) { match = TRUE; break; } @@ -556,10 +561,11 @@ MatchAttrToken(const char *attr, struct xorg_list *patterns, */ static Bool InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, - const InputAttributes *attrs) + const InputAttributes * attrs) { /* MatchProduct substring */ - if (!MatchAttrToken(attrs->product, &iclass->match_product, match_substring)) + if (!MatchAttrToken + (attrs->product, &iclass->match_product, match_substring)) return FALSE; /* MatchVendor substring */ @@ -567,7 +573,8 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, return FALSE; /* MatchDevicePath pattern */ - if (!MatchAttrToken(attrs->device, &iclass->match_device, match_path_pattern)) + if (!MatchAttrToken + (attrs->device, &iclass->match_device, match_path_pattern)) return FALSE; /* MatchOS case-insensitive string */ @@ -591,7 +598,7 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, * See if any of the device's tags match any of the MatchTag tokens. */ if (!xorg_list_is_empty(&iclass->match_tag)) { - char * const *tag; + char *const *tag; Bool match; if (!attrs->tags) @@ -615,22 +622,22 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, /* MatchIs* booleans */ if (iclass->is_keyboard.set && - iclass->is_keyboard.val != !!(attrs->flags & ATTR_KEYBOARD)) + iclass->is_keyboard.val != ! !(attrs->flags & ATTR_KEYBOARD)) return FALSE; if (iclass->is_pointer.set && - iclass->is_pointer.val != !!(attrs->flags & ATTR_POINTER)) + iclass->is_pointer.val != ! !(attrs->flags & ATTR_POINTER)) return FALSE; if (iclass->is_joystick.set && - iclass->is_joystick.val != !!(attrs->flags & ATTR_JOYSTICK)) + iclass->is_joystick.val != ! !(attrs->flags & ATTR_JOYSTICK)) return FALSE; if (iclass->is_tablet.set && - iclass->is_tablet.val != !!(attrs->flags & ATTR_TABLET)) + iclass->is_tablet.val != ! !(attrs->flags & ATTR_TABLET)) return FALSE; if (iclass->is_touchpad.set && - iclass->is_touchpad.val != !!(attrs->flags & ATTR_TOUCHPAD)) + iclass->is_touchpad.val != ! !(attrs->flags & ATTR_TOUCHPAD)) return FALSE; if (iclass->is_touchscreen.set && - iclass->is_touchscreen.val != !!(attrs->flags & ATTR_TOUCHSCREEN)) + iclass->is_touchscreen.val != ! !(attrs->flags & ATTR_TOUCHSCREEN)) return FALSE; return TRUE; @@ -642,7 +649,7 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, * well as any previous InputClass sections. */ static int -MergeInputClasses(const InputInfoPtr idev, const InputAttributes *attrs) +MergeInputClasses(const InputInfoPtr idev, const InputAttributes * attrs) { XF86ConfInputClassPtr cl; XF86OptionPtr classopts; @@ -661,8 +668,7 @@ MergeInputClasses(const InputInfoPtr idev, const InputAttributes *attrs) "InputClass configuration"); return BadAlloc; } - classopts = xf86ReplaceStrOption(classopts, "driver", - idev->driver); + classopts = xf86ReplaceStrOption(classopts, "driver", idev->driver); } /* Apply options to device with InputClass settings preferred. */ @@ -679,7 +685,7 @@ MergeInputClasses(const InputInfoPtr idev, const InputAttributes *attrs) * value of the last matching class and holler when returning TRUE. */ static Bool -IgnoreInputClass(const InputInfoPtr idev, const InputAttributes *attrs) +IgnoreInputClass(const InputInfoPtr idev, const InputAttributes * attrs) { XF86ConfInputClassPtr cl; Bool ignore = FALSE; @@ -724,13 +730,12 @@ xf86AddInput(InputDriverPtr drv, InputInfoPtr pInfo) pInfo->drv = drv; pInfo->module = DuplicateModule(drv->module, NULL); - for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next) - ; + for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next); *prev = pInfo; pInfo->next = NULL; - xf86CollectInputOptions(pInfo, (const char**)drv->default_options); + xf86CollectInputOptions(pInfo, (const char **) drv->default_options); xf86OptionListReport(pInfo->options); xf86ProcessCommonOptions(pInfo, pInfo->options); } @@ -743,10 +748,10 @@ xf86DeleteInput(InputInfoPtr pInp, int flags) { /* First check if the inputdev is valid. */ if (pInp == NULL) - return; + return; if (pInp->module) - UnloadModule(pInp->module); + UnloadModule(pInp->module); /* This should *really* be handled in drv->UnInit(dev) call instead, but * if the driver forgets about it make sure we free it or at least crash @@ -757,14 +762,15 @@ xf86DeleteInput(InputInfoPtr pInp, int flags) /* Remove the entry from the list. */ if (pInp == xf86InputDevs) - xf86InputDevs = pInp->next; + xf86InputDevs = pInp->next; else { - InputInfoPtr p = xf86InputDevs; - while (p && p->next != pInp) - p = p->next; - if (p) - p->next = pInp->next; - /* Else the entry wasn't in the xf86InputDevs list (ignore this). */ + InputInfoPtr p = xf86InputDevs; + + while (p && p->next != pInp) + p = p->next; + if (p) + p->next = pInp->next; + /* Else the entry wasn't in the xf86InputDevs list (ignore this). */ } free(pInp->driver); @@ -781,7 +787,8 @@ xf86DeleteInput(InputInfoPtr pInp, int flags) * @return Success or an error code */ static int -xf86InputDevicePostInit(DeviceIntPtr dev) { +xf86InputDevicePostInit(DeviceIntPtr dev) +{ ApplyAccelerationSettings(dev); ApplyTransformationMatrix(dev); return Success; @@ -823,7 +830,8 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable) goto unwind; } - xf86Msg(X_INFO, "Using input driver '%s' for '%s'\n", drv->driverName, pInfo->name); + xf86Msg(X_INFO, "Using input driver '%s' for '%s'\n", drv->driverName, + pInfo->name); if (!drv->PreInit) { xf86Msg(X_ERROR, @@ -842,35 +850,30 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable) goto unwind; } - if (!(dev = xf86ActivateDevice(pInfo))) - { + if (!(dev = xf86ActivateDevice(pInfo))) { rval = BadAlloc; goto unwind; } rval = ActivateDevice(dev, TRUE); - if (rval != Success) - { + if (rval != Success) { xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name); RemoveDevice(dev, TRUE); goto unwind; } rval = xf86InputDevicePostInit(dev); - if (rval != Success) - { - xf86Msg(X_ERROR, "Couldn't post-init device \"%s\"\n", pInfo->name); - RemoveDevice(dev, TRUE); - goto unwind; + if (rval != Success) { + xf86Msg(X_ERROR, "Couldn't post-init device \"%s\"\n", pInfo->name); + RemoveDevice(dev, TRUE); + goto unwind; } /* Enable it if it's properly initialised and we're currently in the VT */ - if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema) - { + if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema) { OsBlockSignals(); EnableDevice(dev, TRUE); - if (!dev->enabled) - { + if (!dev->enabled) { OsReleaseSignals(); xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name); RemoveDevice(dev, TRUE); @@ -885,9 +888,9 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable) *pdev = dev; return Success; -unwind: - if(pInfo) { - if(drv && drv->UnInit) + unwind: + if (pInfo) { + if (drv && drv->UnInit) drv->UnInit(drv, pInfo, 0); else xf86DeleteInput(pInfo, 0); @@ -896,8 +899,8 @@ unwind: } int -NewInputDeviceRequest (InputOption *options, InputAttributes *attrs, - DeviceIntPtr *pdev) +NewInputDeviceRequest(InputOption *options, InputAttributes * attrs, + DeviceIntPtr *pdev) { InputInfoPtr pInfo = NULL; InputOption *option = NULL; @@ -924,8 +927,7 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs, } } - if (strcasecmp(key, "name") == 0 || - strcasecmp(key, "identifier") == 0) { + if (strcasecmp(key, "name") == 0 || strcasecmp(key, "identifier") == 0) { if (pInfo->name) { rval = BadRequest; goto unwind; @@ -978,17 +980,19 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs, if (!pInfo->driver) { xf86Msg(X_INFO, "No input driver specified, ignoring this device.\n"); - xf86Msg(X_INFO, "This device may have been added with another device file.\n"); + xf86Msg(X_INFO, + "This device may have been added with another device file.\n"); rval = BadRequest; goto unwind; } rval = xf86NewInputDevice(pInfo, pdev, - (!is_auto || (is_auto && xf86Info.autoEnableDevices))); + (!is_auto || + (is_auto && xf86Info.autoEnableDevices))); return rval; -unwind: + unwind: if (is_auto && !xf86Info.autoAddDevices) xf86Msg(X_INFO, "AutoAddDevices is off - not adding device.\n"); xf86DeleteInput(pInfo, 0); @@ -1002,15 +1006,14 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev) InputDriverPtr drv = NULL; Bool isMaster = IsMaster(pDev); - if (pInfo) /* need to get these before RemoveDevice */ + if (pInfo) /* need to get these before RemoveDevice */ drv = pInfo->drv; OsBlockSignals(); RemoveDevice(pDev, TRUE); - if (!isMaster && pInfo != NULL) - { - if(drv->UnInit) + if (!isMaster && pInfo != NULL) { + if (drv->UnInit) drv->UnInit(drv, pInfo, 0); else xf86DeleteInput(pInfo, 0); @@ -1023,11 +1026,8 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev) */ void -xf86PostMotionEvent(DeviceIntPtr device, - int is_absolute, - int first_valuator, - int num_valuators, - ...) +xf86PostMotionEvent(DeviceIntPtr device, + int is_absolute, int first_valuator, int num_valuators, ...) { va_list var; int i = 0; @@ -1039,17 +1039,17 @@ xf86PostMotionEvent(DeviceIntPtr device, va_start(var, num_valuators); for (i = 0; i < num_valuators; i++) valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); + va_end(var); xf86PostMotionEventM(device, is_absolute, &mask); } void -xf86PostMotionEventP(DeviceIntPtr device, - int is_absolute, - int first_valuator, - int num_valuators, - const int *valuators) +xf86PostMotionEventP(DeviceIntPtr device, + int is_absolute, + int first_valuator, + int num_valuators, const int *valuators) { ValuatorMask mask; @@ -1060,14 +1060,12 @@ xf86PostMotionEventP(DeviceIntPtr device, } void -xf86PostMotionEventM(DeviceIntPtr device, - int is_absolute, - const ValuatorMask *mask) +xf86PostMotionEventM(DeviceIntPtr device, + int is_absolute, const ValuatorMask *mask) { int flags = 0; - if (valuator_mask_num_valuators(mask) > 0) - { + if (valuator_mask_num_valuators(mask) > 0) { if (is_absolute) flags = POINTER_ABSOLUTE; else @@ -1076,21 +1074,18 @@ xf86PostMotionEventM(DeviceIntPtr device, #if XFreeXDGA /* The evdev driver may not always send all axes across. */ - if (valuator_mask_isset(mask, 0) || - valuator_mask_isset(mask, 1)) + if (valuator_mask_isset(mask, 0) || valuator_mask_isset(mask, 1)) if (miPointerGetScreen(device)) { int index = miPointerGetScreen(device)->myNum; int dx = 0, dy = 0; - if (valuator_mask_isset(mask, 0)) - { + if (valuator_mask_isset(mask, 0)) { dx = valuator_mask_get(mask, 0); if (is_absolute) dx -= device->last.valuators[0]; } - if (valuator_mask_isset(mask, 1)) - { + if (valuator_mask_isset(mask, 1)) { dy = valuator_mask_get(mask, 1); if (is_absolute) dy -= device->last.valuators[1]; @@ -1105,11 +1100,8 @@ xf86PostMotionEventM(DeviceIntPtr device, } void -xf86PostProximityEvent(DeviceIntPtr device, - int is_in, - int first_valuator, - int num_valuators, - ...) +xf86PostProximityEvent(DeviceIntPtr device, + int is_in, int first_valuator, int num_valuators, ...) { va_list var; int i; @@ -1121,17 +1113,17 @@ xf86PostProximityEvent(DeviceIntPtr device, va_start(var, num_valuators); for (i = 0; i < num_valuators; i++) valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); + va_end(var); xf86PostProximityEventM(device, is_in, &mask); } void -xf86PostProximityEventP(DeviceIntPtr device, - int is_in, - int first_valuator, - int num_valuators, - const int *valuators) +xf86PostProximityEventP(DeviceIntPtr device, + int is_in, + int first_valuator, + int num_valuators, const int *valuators) { ValuatorMask mask; @@ -1142,21 +1134,17 @@ xf86PostProximityEventP(DeviceIntPtr device, } void -xf86PostProximityEventM(DeviceIntPtr device, - int is_in, - const ValuatorMask *mask) +xf86PostProximityEventM(DeviceIntPtr device, + int is_in, const ValuatorMask *mask) { QueueProximityEvents(device, is_in ? ProximityIn : ProximityOut, mask); } void -xf86PostButtonEvent(DeviceIntPtr device, - int is_absolute, - int button, - int is_down, - int first_valuator, - int num_valuators, - ...) +xf86PostButtonEvent(DeviceIntPtr device, + int is_absolute, + int button, + int is_down, int first_valuator, int num_valuators, ...) { va_list var; ValuatorMask mask; @@ -1169,19 +1157,19 @@ xf86PostButtonEvent(DeviceIntPtr device, va_start(var, num_valuators); for (i = 0; i < num_valuators; i++) valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); + va_end(var); xf86PostButtonEventM(device, is_absolute, button, is_down, &mask); } void -xf86PostButtonEventP(DeviceIntPtr device, - int is_absolute, - int button, - int is_down, - int first_valuator, - int num_valuators, - const int *valuators) +xf86PostButtonEventP(DeviceIntPtr device, + int is_absolute, + int button, + int is_down, + int first_valuator, + int num_valuators, const int *valuators) { ValuatorMask mask; @@ -1192,16 +1180,13 @@ xf86PostButtonEventP(DeviceIntPtr device, } void -xf86PostButtonEventM(DeviceIntPtr device, - int is_absolute, - int button, - int is_down, - const ValuatorMask *mask) +xf86PostButtonEventM(DeviceIntPtr device, + int is_absolute, + int button, int is_down, const ValuatorMask *mask) { int flags = 0; - if (valuator_mask_num_valuators(mask) > 0) - { + if (valuator_mask_num_valuators(mask) > 0) { if (is_absolute) flags = POINTER_ABSOLUTE; else @@ -1223,13 +1208,10 @@ xf86PostButtonEventM(DeviceIntPtr device, } void -xf86PostKeyEvent(DeviceIntPtr device, - unsigned int key_code, - int is_down, - int is_absolute, - int first_valuator, - int num_valuators, - ...) +xf86PostKeyEvent(DeviceIntPtr device, + unsigned int key_code, + int is_down, + int is_absolute, int first_valuator, int num_valuators, ...) { va_list var; int i = 0; @@ -1242,19 +1224,18 @@ xf86PostKeyEvent(DeviceIntPtr device, va_start(var, num_valuators); for (i = 0; i < num_valuators; i++) valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); + va_end(var); xf86PostKeyEventM(device, key_code, is_down, is_absolute, &mask); } void -xf86PostKeyEventP(DeviceIntPtr device, - unsigned int key_code, - int is_down, - int is_absolute, - int first_valuator, - int num_valuators, - const int *valuators) +xf86PostKeyEventP(DeviceIntPtr device, + unsigned int key_code, + int is_down, + int is_absolute, + int first_valuator, int num_valuators, const int *valuators) { ValuatorMask mask; @@ -1265,17 +1246,16 @@ xf86PostKeyEventP(DeviceIntPtr device, } void -xf86PostKeyEventM(DeviceIntPtr device, - unsigned int key_code, - int is_down, - int is_absolute, - const ValuatorMask *mask) +xf86PostKeyEventM(DeviceIntPtr device, + unsigned int key_code, + int is_down, int is_absolute, const ValuatorMask *mask) { #if XFreeXDGA DeviceIntPtr pointer; /* Some pointers send key events, paired device is wrong then. */ pointer = GetMaster(device, POINTER_OR_FLOAT); + if (miPointerGetScreen(pointer)) { int index = miPointerGetScreen(pointer)->myNum; @@ -1285,14 +1265,11 @@ xf86PostKeyEventM(DeviceIntPtr device, #endif QueueKeyboardEvents(device, - is_down ? KeyPress : KeyRelease, - key_code, mask); + is_down ? KeyPress : KeyRelease, key_code, mask); } void -xf86PostKeyboardEvent(DeviceIntPtr device, - unsigned int key_code, - int is_down) +xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, int is_down) { ValuatorMask mask; @@ -1323,41 +1300,38 @@ xf86FirstLocalDevice(void) */ int -xf86ScaleAxis(int Cx, - int to_max, - int to_min, - int from_max, - int from_min ) +xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min) { int X; int64_t to_width = to_max - to_min; int64_t from_width = from_max - from_min; if (from_width) { - X = (int)(((to_width * (Cx - from_min)) / from_width) + to_min); + X = (int) (((to_width * (Cx - from_min)) / from_width) + to_min); } else { - X = 0; - ErrorF ("Divide by Zero in xf86ScaleAxis\n"); + X = 0; + ErrorF("Divide by Zero in xf86ScaleAxis\n"); } - + if (X > to_max) - X = to_max; + X = to_max; if (X < to_min) - X = to_min; - + X = to_min; + return X; } Bool -xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval, - int resolution, int min_res, int max_res, int mode) +xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, + int maxval, int resolution, int min_res, int max_res, + int mode) { if (!dev || !dev->valuator) return FALSE; - return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res, - max_res, mode); + return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, + min_res, max_res, mode); } /* @@ -1368,16 +1342,15 @@ void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum) { if (axnum == 0) { - dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2; + dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2; dev->last.valuators[0] = dev->valuator->axisVal[0]; } else if (axnum == 1) { - dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2; + dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2; dev->last.valuators[1] = dev->valuator->axisVal[1]; } } - /** * Deactivate a device. Call this function from the driver if you receive a * read error or something else that spoils your day. @@ -1390,11 +1363,10 @@ xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum) void xf86DisableDevice(DeviceIntPtr dev, Bool panic) { - if(!panic) - { + if (!panic) { DisableDevice(dev, TRUE); - } else - { + } + else { SendDevicePresenceEvent(dev->id, DeviceUnrecoverable); DeleteInputDeviceRequest(dev); } diff --git a/xorg-server/hw/xfree86/common/xf86Xinput.h b/xorg-server/hw/xfree86/common/xf86Xinput.h index ad092dd03..3731a34d5 100644 --- a/xorg-server/hw/xfree86/common/xf86Xinput.h +++ b/xorg-server/hw/xfree86/common/xf86Xinput.h @@ -48,7 +48,6 @@ * authorization from the copyright holder(s) and author(s). */ - #ifndef _xf86Xinput_h #define _xf86Xinput_h @@ -59,52 +58,48 @@ #include "XIstubs.h" /* Input device flags */ -#define XI86_ALWAYS_CORE 0x04 /* device always controls the pointer */ +#define XI86_ALWAYS_CORE 0x04 /* device always controls the pointer */ /* the device sends Xinput and core pointer events */ #define XI86_SEND_CORE_EVENTS XI86_ALWAYS_CORE /* This holds the input driver entry and module information. */ typedef struct _InputDriverRec { - int driverVersion; - char * driverName; - void (*Identify)(int flags); - int (*PreInit)(struct _InputDriverRec *drv, - struct _InputInfoRec* pInfo, int flags); - void (*UnInit)(struct _InputDriverRec *drv, - struct _InputInfoRec *pInfo, - int flags); - pointer module; - char ** default_options; + int driverVersion; + char *driverName; + void (*Identify) (int flags); + int (*PreInit) (struct _InputDriverRec * drv, + struct _InputInfoRec * pInfo, int flags); + void (*UnInit) (struct _InputDriverRec * drv, + struct _InputInfoRec * pInfo, int flags); + pointer module; + char **default_options; } InputDriverRec, *InputDriverPtr; /* This is to input devices what the ScrnInfoRec is to screens. */ typedef struct _InputInfoRec { struct _InputInfoRec *next; - char * name; - char * driver; - - int flags; - - Bool (*device_control)(DeviceIntPtr device, int what); - void (*read_input)(struct _InputInfoRec *local); - int (*control_proc)(struct _InputInfoRec *local, - xDeviceCtl *control); - int (*switch_mode)(ClientPtr client, DeviceIntPtr dev, - int mode); - int (*set_device_valuators) - (struct _InputInfoRec *local, - int *valuators, int first_valuator, - int num_valuators); - - int fd; - DeviceIntPtr dev; - pointer private; - char * type_name; - InputDriverPtr drv; - pointer module; - XF86OptionPtr options; - InputAttributes *attrs; + char *name; + char *driver; + + int flags; + + Bool (*device_control) (DeviceIntPtr device, int what); + void (*read_input) (struct _InputInfoRec * local); + int (*control_proc) (struct _InputInfoRec * local, xDeviceCtl * control); + int (*switch_mode) (ClientPtr client, DeviceIntPtr dev, int mode); + int (*set_device_valuators) + (struct _InputInfoRec * local, + int *valuators, int first_valuator, int num_valuators); + + int fd; + DeviceIntPtr dev; + pointer private; + char *type_name; + InputDriverPtr drv; + pointer module; + XF86OptionPtr options; + InputAttributes *attrs; } *InputInfoPtr; /* xf86Globals.c */ @@ -112,73 +107,95 @@ extern InputInfoPtr xf86InputDevs; /* xf86Xinput.c */ extern _X_EXPORT void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute, - int first_valuator, int num_valuators, ...); + int first_valuator, int num_valuators, + ...); extern _X_EXPORT void xf86PostMotionEventP(DeviceIntPtr device, int is_absolute, - int first_valuator, int num_valuators, const int *valuators); + int first_valuator, + int num_valuators, + const int *valuators); extern _X_EXPORT void xf86PostMotionEventM(DeviceIntPtr device, int is_absolute, - const ValuatorMask *mask); + const ValuatorMask *mask); extern _X_EXPORT void xf86PostProximityEvent(DeviceIntPtr device, int is_in, - int first_valuator, int num_valuators, ...); -extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in, int first_valuator, - int num_valuators, const int *valuators); + int first_valuator, + int num_valuators, ...); +extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in, + int first_valuator, + int num_valuators, + const int *valuators); extern _X_EXPORT void xf86PostProximityEventM(DeviceIntPtr device, int is_in, - const ValuatorMask *mask); -extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, int button, - int is_down, int first_valuator, int num_valuators, - ...); -extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute, int button, - int is_down, int first_valuator, int num_valuators, - const int *valuators); -extern _X_EXPORT void xf86PostButtonEventM(DeviceIntPtr device, int is_absolute, int button, - int is_down, const ValuatorMask *mask); -extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down, - int is_absolute, int first_valuator, int num_valuators, - ...); -extern _X_EXPORT void xf86PostKeyEventM(DeviceIntPtr device, unsigned int key_code, int is_down, - int is_absolute, const ValuatorMask *mask); -extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device, unsigned int key_code, int is_down, - int is_absolute, int first_valuator, int num_valuators, - const int *valuators); -extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, - int is_down); + const ValuatorMask *mask); +extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, + int button, int is_down, + int first_valuator, int num_valuators, + ...); +extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute, + int button, int is_down, + int first_valuator, + int num_valuators, + const int *valuators); +extern _X_EXPORT void xf86PostButtonEventM(DeviceIntPtr device, int is_absolute, + int button, int is_down, + const ValuatorMask *mask); +extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device, + unsigned int key_code, int is_down, + int is_absolute, int first_valuator, + int num_valuators, ...); +extern _X_EXPORT void xf86PostKeyEventM(DeviceIntPtr device, + unsigned int key_code, int is_down, + int is_absolute, + const ValuatorMask *mask); +extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device, + unsigned int key_code, int is_down, + int is_absolute, int first_valuator, + int num_valuators, + const int *valuators); +extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, + unsigned int key_code, int is_down); extern _X_EXPORT void xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid, uint16_t type, uint32_t flags, const ValuatorMask *mask); extern _X_EXPORT InputInfoPtr xf86FirstLocalDevice(void); -extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); -extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, XF86OptionPtr options); -extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, - int maxval, int resolution, int min_res, - int max_res, int mode); +extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, + int from_min); +extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, + XF86OptionPtr options); +extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, + Atom label, int minval, + int maxval, int resolution, + int min_res, int max_res, + int mode); extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum); extern _X_EXPORT void xf86AddEnabledDevice(InputInfoPtr pInfo); extern _X_EXPORT void xf86RemoveEnabledDevice(InputInfoPtr pInfo); extern _X_EXPORT void xf86DisableDevice(DeviceIntPtr dev, Bool panic); extern _X_EXPORT void xf86EnableDevice(DeviceIntPtr dev); + /* not exported */ int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL is_auto); InputInfoPtr xf86AllocateInput(void); /* xf86Helper.c */ -extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags); +extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, pointer module, + int flags); extern _X_EXPORT void xf86DeleteInputDriver(int drvIndex); extern _X_EXPORT InputDriverPtr xf86LookupInputDriver(const char *name); extern _X_EXPORT InputInfoPtr xf86LookupInput(const char *name); extern _X_EXPORT void xf86DeleteInput(InputInfoPtr pInp, int flags); extern _X_EXPORT void xf86MotionHistoryAllocate(InputInfoPtr pInfo); -extern _X_EXPORT void xf86IDrvMsgVerb(InputInfoPtr dev, - MessageType type, int verb, - const char *format, ...) _X_ATTRIBUTE_PRINTF(4,5); -extern _X_EXPORT void xf86IDrvMsg(InputInfoPtr dev, - MessageType type, - const char *format, ...) _X_ATTRIBUTE_PRINTF(3,4); -extern _X_EXPORT void xf86VIDrvMsgVerb(InputInfoPtr dev, - MessageType type, - int verb, - const char *format, - va_list args) _X_ATTRIBUTE_PRINTF(4,0); +extern _X_EXPORT void +xf86IDrvMsgVerb(InputInfoPtr dev, + MessageType type, int verb, const char *format, ...) +_X_ATTRIBUTE_PRINTF(4, 5); +extern _X_EXPORT void +xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...) +_X_ATTRIBUTE_PRINTF(3, 4); +extern _X_EXPORT void +xf86VIDrvMsgVerb(InputInfoPtr dev, + MessageType type, int verb, const char *format, va_list args) +_X_ATTRIBUTE_PRINTF(4, 0); /* xf86Option.c */ -extern _X_EXPORT void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts); +extern _X_EXPORT void +xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts); -#endif /* _xf86Xinput_h */ +#endif /* _xf86Xinput_h */ diff --git a/xorg-server/hw/xfree86/common/xf86cmap.c b/xorg-server/hw/xfree86/common/xf86cmap.c index 191ae6132..cdc8459af 100644 --- a/xorg-server/hw/xfree86/common/xf86cmap.c +++ b/xorg-server/hw/xfree86/common/xf86cmap.c @@ -1,1183 +1,1181 @@ -/*
- * Copyright (c) 1998-2001 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#if defined(_XOPEN_SOURCE) || defined(sun) && defined(__SVR4)
-#include <math.h>
-#else
-#define _XOPEN_SOURCE /* to get prototype for pow on some systems */
-#include <math.h>
-#undef _XOPEN_SOURCE
-#endif
-
-#include <X11/X.h>
-#include "misc.h"
-#include <X11/Xproto.h>
-#include "colormapst.h"
-#include "scrnintstr.h"
-
-#include "resource.h"
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "xf86str.h"
-#include "micmap.h"
-#include "xf86Crtc.h"
-
-#ifdef XFreeXDGA
-#include <X11/extensions/xf86dgaproto.h>
-#include "dgaproc.h"
-#endif
-
-#include "xf86cmap.h"
-
-#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
- ((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field)
-#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
- ((pScreen)->field = wrapper)
-
-#define LOAD_PALETTE(pmap) \
- ((pmap == GetInstalledmiColormap(pmap->pScreen)) && \
- ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || \
- xf86Screens[pmap->pScreen->myNum]->vtSema || pScreenPriv->isDGAmode))
-
-
-typedef struct _CMapLink {
- ColormapPtr cmap;
- struct _CMapLink *next;
-} CMapLink, *CMapLinkPtr;
-
-typedef struct {
- ScrnInfoPtr pScrn;
- CloseScreenProcPtr CloseScreen;
- CreateColormapProcPtr CreateColormap;
- DestroyColormapProcPtr DestroyColormap;
- InstallColormapProcPtr InstallColormap;
- StoreColorsProcPtr StoreColors;
- Bool (*EnterVT)(int, int);
- Bool (*SwitchMode)(int, DisplayModePtr, int);
- int (*SetDGAMode)(int, int, DGADevicePtr);
- xf86ChangeGammaProc *ChangeGamma;
- int maxColors;
- int sigRGBbits;
- int gammaElements;
- LOCO *gamma;
- int *PreAllocIndices;
- CMapLinkPtr maps;
- unsigned int flags;
- Bool isDGAmode;
-} CMapScreenRec, *CMapScreenPtr;
-
-typedef struct {
- int numColors;
- LOCO *colors;
- Bool recalculate;
- int overscan;
-} CMapColormapRec, *CMapColormapPtr;
-
-static DevPrivateKeyRec CMapScreenKeyRec;
-#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec)
-#define CMapScreenKey (&CMapScreenKeyRec)
-static DevPrivateKeyRec CMapColormapKeyRec;
-#define CMapColormapKey (&CMapColormapKeyRec)
-
-static void CMapInstallColormap(ColormapPtr);
-static void CMapStoreColors(ColormapPtr, int, xColorItem *);
-static Bool CMapCloseScreen (int, ScreenPtr);
-static Bool CMapCreateColormap (ColormapPtr);
-static void CMapDestroyColormap (ColormapPtr);
-
-static Bool CMapEnterVT(int, int);
-static Bool CMapSwitchMode(int, DisplayModePtr, int);
-#ifdef XFreeXDGA
-static int CMapSetDGAMode(int, int, DGADevicePtr);
-#endif
-static int CMapChangeGamma(int, Gamma);
-
-static void ComputeGamma(CMapScreenPtr);
-static Bool CMapAllocateColormapPrivate(ColormapPtr);
-static void CMapRefreshColors(ColormapPtr, int, int*);
-static void CMapSetOverscan(ColormapPtr, int, int *);
-static void CMapReinstallMap(ColormapPtr);
-static void CMapUnwrapScreen(ScreenPtr pScreen);
-
-
-Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn)
-{
- /* If we support a better colormap system, then pretend we succeeded. */
- if (xf86_crtc_supports_gamma(pScrn))
- return TRUE;
- if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0))
- return FALSE;
- return TRUE;
-}
-
-Bool xf86HandleColormaps(
- ScreenPtr pScreen,
- int maxColors,
- int sigRGBbits,
- xf86LoadPaletteProc *loadPalette,
- xf86SetOverscanProc *setOverscan,
- unsigned int flags
-){
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- ColormapPtr pDefMap = NULL;
- CMapScreenPtr pScreenPriv;
- LOCO *gamma;
- int *indices;
- int elements;
-
- /* If we support a better colormap system, then pretend we succeeded. */
- if (xf86_crtc_supports_gamma(pScrn))
- return TRUE;
-
- if(!maxColors || !sigRGBbits || !loadPalette)
- return FALSE;
-
- elements = 1 << sigRGBbits;
-
- if(!(gamma = malloc(elements * sizeof(LOCO))))
- return FALSE;
-
- if(!(indices = malloc(maxColors * sizeof(int)))) {
- free(gamma);
- return FALSE;
- }
-
- if(!(pScreenPriv = malloc(sizeof(CMapScreenRec)))) {
- free(gamma);
- free(indices);
- return FALSE;
- }
-
- dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv);
-
- pScreenPriv->CloseScreen = pScreen->CloseScreen;
- pScreenPriv->CreateColormap = pScreen->CreateColormap;
- pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
- pScreenPriv->InstallColormap = pScreen->InstallColormap;
- pScreenPriv->StoreColors = pScreen->StoreColors;
- pScreen->CloseScreen = CMapCloseScreen;
- pScreen->CreateColormap = CMapCreateColormap;
- pScreen->DestroyColormap = CMapDestroyColormap;
- pScreen->InstallColormap = CMapInstallColormap;
- pScreen->StoreColors = CMapStoreColors;
-
- pScreenPriv->pScrn = pScrn;
- pScrn->LoadPalette = loadPalette;
- pScrn->SetOverscan = setOverscan;
- pScreenPriv->maxColors = maxColors;
- pScreenPriv->sigRGBbits = sigRGBbits;
- pScreenPriv->gammaElements = elements;
- pScreenPriv->gamma = gamma;
- pScreenPriv->PreAllocIndices = indices;
- pScreenPriv->maps = NULL;
- pScreenPriv->flags = flags;
- pScreenPriv->isDGAmode = FALSE;
-
- pScreenPriv->EnterVT = pScrn->EnterVT;
- pScreenPriv->SwitchMode = pScrn->SwitchMode;
- pScreenPriv->SetDGAMode = pScrn->SetDGAMode;
- pScreenPriv->ChangeGamma = pScrn->ChangeGamma;
-
- if (!(flags & CMAP_LOAD_EVEN_IF_OFFSCREEN)) {
- pScrn->EnterVT = CMapEnterVT;
- if ((flags & CMAP_RELOAD_ON_MODE_SWITCH) && pScrn->SwitchMode)
- pScrn->SwitchMode = CMapSwitchMode;
- }
-#ifdef XFreeXDGA
- pScrn->SetDGAMode = CMapSetDGAMode;
-#endif
- pScrn->ChangeGamma = CMapChangeGamma;
-
- ComputeGamma(pScreenPriv);
-
- /* get the default map */
- dixLookupResourceByType((pointer *)&pDefMap, pScreen->defColormap,
- RT_COLORMAP, serverClient, DixInstallAccess);
-
- if(!CMapAllocateColormapPrivate(pDefMap)) {
- CMapUnwrapScreen(pScreen);
- return FALSE;
- }
-
- /* Force the initial map to be loaded */
- SetInstalledmiColormap(pScreen, NULL);
- CMapInstallColormap(pDefMap);
- return TRUE;
-}
-
-
-/**** Screen functions ****/
-
-
-static Bool
-CMapCloseScreen (int i, ScreenPtr pScreen)
-{
- CMapUnwrapScreen(pScreen);
-
- return (*pScreen->CloseScreen) (i, pScreen);
-}
-
-static Bool
-CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
-{
- if (pVisual->nplanes > 16)
- return TRUE;
- return ((1 << pVisual->nplanes) > pScreenPriv->maxColors);
-}
-
-static Bool
-CMapAllocateColormapPrivate(ColormapPtr pmap)
-{
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pmap->pScreen->devPrivates, CMapScreenKey);
- CMapColormapPtr pColPriv;
- CMapLinkPtr pLink;
- int numColors;
- LOCO *colors;
-
- if (CMapColormapUseMax(pmap->pVisual, pScreenPriv))
- numColors = pmap->pVisual->ColormapEntries;
- else
- numColors = 1 << pmap->pVisual->nplanes;
-
- if(!(colors = malloc(numColors * sizeof(LOCO))))
- return FALSE;
-
- if(!(pColPriv = malloc(sizeof(CMapColormapRec)))) {
- free(colors);
- return FALSE;
- }
-
- dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv);
-
- pColPriv->numColors = numColors;
- pColPriv->colors = colors;
- pColPriv->recalculate = TRUE;
- pColPriv->overscan = -1;
-
- /* add map to list */
- pLink = malloc(sizeof(CMapLink));
- if(pLink) {
- pLink->cmap = pmap;
- pLink->next = pScreenPriv->maps;
- pScreenPriv->maps = pLink;
- }
-
- return TRUE;
-}
-
-static Bool
-CMapCreateColormap (ColormapPtr pmap)
-{
- ScreenPtr pScreen = pmap->pScreen;
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
- Bool ret = FALSE;
-
- pScreen->CreateColormap = pScreenPriv->CreateColormap;
- if((*pScreen->CreateColormap)(pmap)) {
- if(CMapAllocateColormapPrivate(pmap))
- ret = TRUE;
- }
- pScreen->CreateColormap = CMapCreateColormap;
-
- return ret;
-}
-
-static void
-CMapDestroyColormap (ColormapPtr cmap)
-{
- ScreenPtr pScreen = cmap->pScreen;
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
- CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
- &cmap->devPrivates, CMapColormapKey);
- CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
-
- if(pColPriv) {
- free(pColPriv->colors);
- free(pColPriv);
- }
-
- /* remove map from list */
- while(pLink) {
- if(pLink->cmap == cmap) {
- if(prevLink)
- prevLink->next = pLink->next;
- else
- pScreenPriv->maps = pLink->next;
- free(pLink);
- break;
- }
- prevLink = pLink;
- pLink = pLink->next;
- }
-
- if(pScreenPriv->DestroyColormap) {
- pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
- (*pScreen->DestroyColormap)(cmap);
- pScreen->DestroyColormap = CMapDestroyColormap;
- }
-}
-
-
-
-static void
-CMapStoreColors(
- ColormapPtr pmap,
- int ndef,
- xColorItem *pdefs
-){
- ScreenPtr pScreen = pmap->pScreen;
- VisualPtr pVisual = pmap->pVisual;
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
- int *indices = pScreenPriv->PreAllocIndices;
- int num = ndef;
-
- /* At the moment this isn't necessary since there's nobody below us */
- pScreen->StoreColors = pScreenPriv->StoreColors;
- (*pScreen->StoreColors)(pmap, ndef, pdefs);
- pScreen->StoreColors = CMapStoreColors;
-
- /* should never get here for these */
- if( (pVisual->class == TrueColor) ||
- (pVisual->class == StaticColor) ||
- (pVisual->class == StaticGray))
- return;
-
- if(pVisual->class == DirectColor) {
- CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
- &pmap->devPrivates, CMapColormapKey);
- int i;
-
- if (CMapColormapUseMax(pVisual, pScreenPriv)) {
- int index;
-
- num = 0;
- while(ndef--) {
- if(pdefs[ndef].flags & DoRed) {
- index = (pdefs[ndef].pixel & pVisual->redMask) >>
- pVisual->offsetRed;
- i = num;
- while(i--)
- if(indices[i] == index) break;
- if(i == -1)
- indices[num++] = index;
- }
- if(pdefs[ndef].flags & DoGreen) {
- index = (pdefs[ndef].pixel & pVisual->greenMask) >>
- pVisual->offsetGreen;
- i = num;
- while(i--)
- if(indices[i] == index) break;
- if(i == -1)
- indices[num++] = index;
- }
- if(pdefs[ndef].flags & DoBlue) {
- index = (pdefs[ndef].pixel & pVisual->blueMask) >>
- pVisual->offsetBlue;
- i = num;
- while(i--)
- if(indices[i] == index) break;
- if(i == -1)
- indices[num++] = index;
- }
- }
-
- } else {
- /* not really as overkill as it seems */
- num = pColPriv->numColors;
- for(i = 0; i < pColPriv->numColors; i++)
- indices[i] = i;
- }
- } else {
- while(ndef--)
- indices[ndef] = pdefs[ndef].pixel;
- }
-
- CMapRefreshColors(pmap, num, indices);
-}
-
-
-static void
-CMapInstallColormap(ColormapPtr pmap)
-{
- ScreenPtr pScreen = pmap->pScreen;
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
-
- if (pmap == GetInstalledmiColormap(pmap->pScreen))
- return;
-
- pScreen->InstallColormap = pScreenPriv->InstallColormap;
- (*pScreen->InstallColormap)(pmap);
- pScreen->InstallColormap = CMapInstallColormap;
-
- /* Important. We let the lower layers, namely DGA,
- overwrite the choice of Colormap to install */
- if (GetInstalledmiColormap(pmap->pScreen))
- pmap = GetInstalledmiColormap(pmap->pScreen);
-
- if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
- (pmap->pVisual->class == TrueColor) &&
- CMapColormapUseMax(pmap->pVisual, pScreenPriv))
- return;
-
- if(LOAD_PALETTE(pmap))
- CMapReinstallMap(pmap);
-}
-
-
-/**** ScrnInfoRec functions ****/
-
-static Bool
-CMapEnterVT(int index, int flags)
-{
- ScrnInfoPtr pScrn = xf86Screens[index];
- ScreenPtr pScreen = screenInfo.screens[index];
- Bool ret;
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
-
- pScrn->EnterVT = pScreenPriv->EnterVT;
- ret = (*pScreenPriv->EnterVT)(index, flags);
- pScreenPriv->EnterVT = pScrn->EnterVT;
- pScrn->EnterVT = CMapEnterVT;
- if(ret) {
- if(GetInstalledmiColormap(pScreen))
- CMapReinstallMap(GetInstalledmiColormap(pScreen));
- return TRUE;
- }
- return FALSE;
-}
-
-
-static Bool
-CMapSwitchMode(int index, DisplayModePtr mode, int flags)
-{
- ScreenPtr pScreen = screenInfo.screens[index];
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
-
- if((*pScreenPriv->SwitchMode)(index, mode, flags)) {
- if(GetInstalledmiColormap(pScreen))
- CMapReinstallMap(GetInstalledmiColormap(pScreen));
- return TRUE;
- }
- return FALSE;
-}
-
-#ifdef XFreeXDGA
-static int
-CMapSetDGAMode(int index, int num, DGADevicePtr dev)
-{
- ScreenPtr pScreen = screenInfo.screens[index];
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
- int ret;
-
- ret = (*pScreenPriv->SetDGAMode)(index, num, dev);
-
- pScreenPriv->isDGAmode = DGAActive(index);
-
- if(!pScreenPriv->isDGAmode && GetInstalledmiColormap(pScreen)
- && xf86Screens[pScreen->myNum]->vtSema)
- CMapReinstallMap(GetInstalledmiColormap(pScreen));
-
- return ret;
-}
-#endif
-
-
-/**** Utilities ****/
-
-static void
-CMapReinstallMap(ColormapPtr pmap)
-{
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pmap->pScreen->devPrivates, CMapScreenKey);
- CMapColormapPtr cmapPriv = (CMapColormapPtr)dixLookupPrivate(
- &pmap->devPrivates, CMapColormapKey);
- ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
- int i = cmapPriv->numColors;
- int *indices = pScreenPriv->PreAllocIndices;
-
- while(i--)
- indices[i] = i;
-
- if(cmapPriv->recalculate)
- CMapRefreshColors(pmap, cmapPriv->numColors, indices);
- else {
- (*pScrn->LoadPalette)(pScrn, cmapPriv->numColors,
- indices, cmapPriv->colors, pmap->pVisual);
- if (pScrn->SetOverscan) {
-#ifdef DEBUGOVERSCAN
- ErrorF("SetOverscan() called from CMapReinstallMap\n");
-#endif
- pScrn->SetOverscan(pScrn, cmapPriv->overscan);
- }
- }
-
- cmapPriv->recalculate = FALSE;
-}
-
-
-static void
-CMapRefreshColors(ColormapPtr pmap, int defs, int* indices)
-{
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pmap->pScreen->devPrivates, CMapScreenKey);
- CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
- &pmap->devPrivates, CMapColormapKey);
- VisualPtr pVisual = pmap->pVisual;
- ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
- int numColors, i;
- LOCO *gamma, *colors;
- EntryPtr entry;
- int reds, greens, blues, maxValue, index, shift;
-
- numColors = pColPriv->numColors;
- shift = 16 - pScreenPriv->sigRGBbits;
- maxValue = (1 << pScreenPriv->sigRGBbits) - 1;
- gamma = pScreenPriv->gamma;
- colors = pColPriv->colors;
-
- reds = pVisual->redMask >> pVisual->offsetRed;
- greens = pVisual->greenMask >> pVisual->offsetGreen;
- blues = pVisual->blueMask >> pVisual->offsetBlue;
-
- switch(pVisual->class) {
- case StaticGray:
- for(i = 0; i < numColors; i++) {
- index = (i+1) * maxValue / numColors;
- colors[i].red = gamma[index].red;
- colors[i].green = gamma[index].green;
- colors[i].blue = gamma[index].blue;
- }
- break;
- case TrueColor:
- if (CMapColormapUseMax(pVisual, pScreenPriv)) {
- for(i = 0; i <= reds; i++)
- colors[i].red = gamma[i * maxValue / reds].red;
- for(i = 0; i <= greens; i++)
- colors[i].green = gamma[i * maxValue / greens].green;
- for(i = 0; i <= blues; i++)
- colors[i].blue = gamma[i * maxValue / blues].blue;
- break;
- }
- for(i = 0; i < numColors; i++) {
- colors[i].red = gamma[((i >> pVisual->offsetRed) & reds) *
- maxValue / reds].red;
- colors[i].green = gamma[((i >> pVisual->offsetGreen) & greens) *
- maxValue / greens].green;
- colors[i].blue = gamma[((i >> pVisual->offsetBlue) & blues) *
- maxValue / blues].blue;
- }
- break;
- case StaticColor:
- case PseudoColor:
- case GrayScale:
- for(i = 0; i < defs; i++) {
- index = indices[i];
- entry = (EntryPtr)&pmap->red[index];
-
- if(entry->fShared) {
- colors[index].red =
- gamma[entry->co.shco.red->color >> shift].red;
- colors[index].green =
- gamma[entry->co.shco.green->color >> shift].green;
- colors[index].blue =
- gamma[entry->co.shco.blue->color >> shift].blue;
- } else {
- colors[index].red =
- gamma[entry->co.local.red >> shift].red;
- colors[index].green =
- gamma[entry->co.local.green >> shift].green;
- colors[index].blue =
- gamma[entry->co.local.blue >> shift].blue;
- }
- }
- break;
- case DirectColor:
- if (CMapColormapUseMax(pVisual, pScreenPriv)) {
- for(i = 0; i < defs; i++) {
- index = indices[i];
- if(index <= reds)
- colors[index].red =
- gamma[pmap->red[index].co.local.red >> shift].red;
- if(index <= greens)
- colors[index].green =
- gamma[pmap->green[index].co.local.green >> shift].green;
- if(index <= blues)
- colors[index].blue =
- gamma[pmap->blue[index].co.local.blue >> shift].blue;
-
- }
- break;
- }
- for(i = 0; i < defs; i++) {
- index = indices[i];
-
- colors[index].red = gamma[pmap->red[
- (index >> pVisual->offsetRed) & reds
- ].co.local.red >> shift].red;
- colors[index].green = gamma[pmap->green[
- (index >> pVisual->offsetGreen) & greens
- ].co.local.green >> shift].green;
- colors[index].blue = gamma[pmap->blue[
- (index >> pVisual->offsetBlue) & blues
- ].co.local.blue >> shift].blue;
- }
- break;
- }
-
-
- if(LOAD_PALETTE(pmap))
- (*pScrn->LoadPalette)(pScreenPriv->pScrn, defs, indices,
- colors, pmap->pVisual);
-
- if (pScrn->SetOverscan)
- CMapSetOverscan(pmap, defs, indices);
-
-}
-
-static Bool
-CMapCompareColors(LOCO *color1, LOCO *color2)
-{
- /* return TRUE if the color1 is "closer" to black than color2 */
-#ifdef DEBUGOVERSCAN
- ErrorF("#%02x%02x%02x vs #%02x%02x%02x (%d vs %d)\n",
- color1->red, color1->green, color1->blue,
- color2->red, color2->green, color2->blue,
- color1->red + color1->green + color1->blue,
- color2->red + color2->green + color2->blue);
-#endif
- return (color1->red + color1->green + color1->blue <
- color2->red + color2->green + color2->blue);
-}
-
-static void
-CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
-{
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pmap->pScreen->devPrivates, CMapScreenKey);
- CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
- &pmap->devPrivates, CMapColormapKey);
- ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
- VisualPtr pVisual = pmap->pVisual;
- int i;
- LOCO *colors;
- int index;
- Bool newOverscan = FALSE;
- int overscan, tmpOverscan;
-
- colors = pColPriv->colors;
- overscan = pColPriv->overscan;
-
- /*
- * Search for a new overscan index in the following cases:
- *
- * - The index hasn't yet been initialised. In this case search
- * for an index that is black or a close match to black.
- *
- * - The colour of the old index is changed. In this case search
- * all indices for a black or close match to black.
- *
- * - The colour of the old index wasn't black. In this case only
- * search the indices that were changed for a better match to black.
- */
-
- switch (pVisual->class) {
- case StaticGray:
- case TrueColor:
- /* Should only come here once. Initialise the overscan index to 0 */
- overscan = 0;
- newOverscan = TRUE;
- break;
- case StaticColor:
- /*
- * Only come here once, but search for the overscan in the same way
- * as for the other cases.
- */
- case DirectColor:
- case PseudoColor:
- case GrayScale:
- if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) {
- /* Uninitialised */
- newOverscan = TRUE;
- } else {
- /* Check if the overscan was changed */
- for (i = 0; i < defs; i++) {
- index = indices[i];
- if (index == overscan) {
- newOverscan = TRUE;
- break;
- }
- }
- }
- if (newOverscan) {
- /* The overscan is either uninitialised or it has been changed */
-
- if (overscan < 0 || overscan > pScreenPriv->maxColors - 1)
- tmpOverscan = pScreenPriv->maxColors - 1;
- else
- tmpOverscan = overscan;
-
- /* search all entries for a close match to black */
- for (i = pScreenPriv->maxColors - 1; i >= 0; i--) {
- if (colors[i].red == 0 && colors[i].green == 0 &&
- colors[i].blue == 0) {
- overscan = i;
-#ifdef DEBUGOVERSCAN
- ErrorF("Black found at index 0x%02x\n", i);
-#endif
- break;
- } else {
-#ifdef DEBUGOVERSCAN
- ErrorF("0x%02x: ", i);
-#endif
- if (CMapCompareColors(&colors[i], &colors[tmpOverscan])) {
- tmpOverscan = i;
-#ifdef DEBUGOVERSCAN
- ErrorF("possible \"Black\" at index 0x%02x\n", i);
-#endif
- }
- }
- }
- if (i < 0)
- overscan = tmpOverscan;
- } else {
- /* Check of the old overscan wasn't black */
- if (colors[overscan].red != 0 || colors[overscan].green != 0 ||
- colors[overscan].blue != 0) {
- int oldOverscan = tmpOverscan = overscan;
- /* See of there is now a better match */
- for (i = 0; i < defs; i++) {
- index = indices[i];
- if (colors[index].red == 0 && colors[index].green == 0 &&
- colors[index].blue == 0) {
- overscan = index;
-#ifdef DEBUGOVERSCAN
- ErrorF("Black found at index 0x%02x\n", index);
-#endif
- break;
- } else {
-#ifdef DEBUGOVERSCAN
- ErrorF("0x%02x: ", index);
-#endif
- if (CMapCompareColors(&colors[index],
- &colors[tmpOverscan])) {
- tmpOverscan = index;
-#ifdef DEBUGOVERSCAN
- ErrorF("possible \"Black\" at index 0x%02x\n",
- index);
-#endif
- }
- }
- }
- if (i == defs)
- overscan = tmpOverscan;
- if (overscan != oldOverscan)
- newOverscan = TRUE;
- }
- }
- break;
- }
- if (newOverscan) {
- pColPriv->overscan = overscan;
- if (LOAD_PALETTE(pmap)) {
-#ifdef DEBUGOVERSCAN
- ErrorF("SetOverscan() called from CmapSetOverscan\n");
-#endif
- pScrn->SetOverscan(pScreenPriv->pScrn, overscan);
- }
- }
-}
-
-static void
-CMapUnwrapScreen(ScreenPtr pScreen)
-{
- CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
- &pScreen->devPrivates, CMapScreenKey);
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
- pScreen->CloseScreen = pScreenPriv->CloseScreen;
- pScreen->CreateColormap = pScreenPriv->CreateColormap;
- pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
- pScreen->InstallColormap = pScreenPriv->InstallColormap;
- pScreen->StoreColors = pScreenPriv->StoreColors;
-
- pScrn->EnterVT = pScreenPriv->EnterVT;
- pScrn->SwitchMode = pScreenPriv->SwitchMode;
- pScrn->SetDGAMode = pScreenPriv->SetDGAMode;
- pScrn->ChangeGamma = pScreenPriv->ChangeGamma;
-
- free(pScreenPriv->gamma);
- free(pScreenPriv->PreAllocIndices);
- free(pScreenPriv);
-}
-
-
-static void
-ComputeGamma(CMapScreenPtr priv)
-{
- int elements = priv->gammaElements - 1;
- double RedGamma, GreenGamma, BlueGamma;
- int i;
-
-#ifndef DONT_CHECK_GAMMA
- /* This check is to catch drivers that are not initialising pScrn->gamma */
- if (priv->pScrn->gamma.red < GAMMA_MIN ||
- priv->pScrn->gamma.red > GAMMA_MAX ||
- priv->pScrn->gamma.green < GAMMA_MIN ||
- priv->pScrn->gamma.green > GAMMA_MAX ||
- priv->pScrn->gamma.blue < GAMMA_MIN ||
- priv->pScrn->gamma.blue > GAMMA_MAX) {
-
- xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
- "The %s driver didn't call xf86SetGamma() to initialise\n"
- "\tthe gamma values.\n", priv->pScrn->driverName);
- xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
- "PLEASE FIX THE `%s' DRIVER!\n", priv->pScrn->driverName);
- priv->pScrn->gamma.red = 1.0;
- priv->pScrn->gamma.green = 1.0;
- priv->pScrn->gamma.blue = 1.0;
- }
-#endif
-
- RedGamma = 1.0 / (double)priv->pScrn->gamma.red;
- GreenGamma = 1.0 / (double)priv->pScrn->gamma.green;
- BlueGamma = 1.0 / (double)priv->pScrn->gamma.blue;
-
- for(i = 0; i <= elements; i++) {
- if(RedGamma == 1.0)
- priv->gamma[i].red = i;
- else
- priv->gamma[i].red = (CARD16)(pow((double)i/(double)elements,
- RedGamma) * (double)elements + 0.5);
-
- if(GreenGamma == 1.0)
- priv->gamma[i].green = i;
- else
- priv->gamma[i].green = (CARD16)(pow((double)i/(double)elements,
- GreenGamma) * (double)elements + 0.5);
-
- if(BlueGamma == 1.0)
- priv->gamma[i].blue = i;
- else
- priv->gamma[i].blue = (CARD16)(pow((double)i/(double)elements,
- BlueGamma) * (double)elements + 0.5);
- }
-}
-
-
-int
-CMapChangeGamma(
- int index,
- Gamma gamma
-){
- int ret = Success;
- ScrnInfoPtr pScrn = xf86Screens[index];
- ScreenPtr pScreen = pScrn->pScreen;
- CMapColormapPtr pColPriv;
- CMapScreenPtr pScreenPriv;
- CMapLinkPtr pLink;
-
- /* Is this sufficient checking ? */
- if(!CMapScreenKeyRegistered)
- return BadImplementation;
-
- pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- CMapScreenKey);
- if(!pScreenPriv)
- return BadImplementation;
-
- if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX ||
- gamma.green < GAMMA_MIN || gamma.green > GAMMA_MAX ||
- gamma.blue < GAMMA_MIN || gamma.blue > GAMMA_MAX)
- return BadValue;
-
- pScrn->gamma.red = gamma.red;
- pScrn->gamma.green = gamma.green;
- pScrn->gamma.blue = gamma.blue;
-
- ComputeGamma(pScreenPriv);
-
- /* mark all colormaps on this screen */
- pLink = pScreenPriv->maps;
- while(pLink) {
- pColPriv = (CMapColormapPtr)dixLookupPrivate(&pLink->cmap->devPrivates,
- CMapColormapKey);
- pColPriv->recalculate = TRUE;
- pLink = pLink->next;
- }
-
- if(GetInstalledmiColormap(pScreen) &&
- ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
- pScrn->vtSema || pScreenPriv->isDGAmode)) {
- ColormapPtr pMap = GetInstalledmiColormap(pScreen);
-
- if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
- (pMap->pVisual->class == TrueColor) &&
- CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
-
- /* if the current map doesn't have a palette look
- for another map to change the gamma on. */
-
- pLink = pScreenPriv->maps;
- while(pLink) {
- if(pLink->cmap->pVisual->class == PseudoColor)
- break;
- pLink = pLink->next;
- }
-
- if(pLink) {
- /* need to trick CMapRefreshColors() into thinking
- this is the currently installed map */
- SetInstalledmiColormap(pScreen, pLink->cmap);
- CMapReinstallMap(pLink->cmap);
- SetInstalledmiColormap(pScreen, pMap);
- }
- } else
- CMapReinstallMap(pMap);
- }
-
- pScrn->ChangeGamma = pScreenPriv->ChangeGamma;
- if (pScrn->ChangeGamma)
- ret = pScrn->ChangeGamma(index, gamma);
- pScrn->ChangeGamma = CMapChangeGamma;
-
- return ret;
-}
-
-
-static void
-ComputeGammaRamp (
- CMapScreenPtr priv,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue
-){
- int elements = priv->gammaElements;
- LOCO *entry = priv->gamma;
- int shift = 16 - priv->sigRGBbits;
-
- while(elements--) {
- entry->red = *(red++) >> shift;
- entry->green = *(green++) >> shift;
- entry->blue = *(blue++) >> shift;
- entry++;
- }
-}
-
-int
-xf86ChangeGammaRamp(
- ScreenPtr pScreen,
- int size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue
-){
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- CMapColormapPtr pColPriv;
- CMapScreenPtr pScreenPriv;
- CMapLinkPtr pLink;
-
- if (xf86_crtc_supports_gamma(pScrn)) {
- RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
-
- if (crtc) {
- if (crtc->gammaSize != size)
- return BadValue;
-
- RRCrtcGammaSet(crtc, red, green, blue);
-
- return Success;
- }
- }
-
- if(!CMapScreenKeyRegistered)
- return BadImplementation;
-
- pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- CMapScreenKey);
- if(!pScreenPriv)
- return BadImplementation;
-
- if(pScreenPriv->gammaElements != size)
- return BadValue;
-
- ComputeGammaRamp(pScreenPriv, red, green, blue);
-
- /* mark all colormaps on this screen */
- pLink = pScreenPriv->maps;
- while(pLink) {
- pColPriv = (CMapColormapPtr)dixLookupPrivate(&pLink->cmap->devPrivates,
- CMapColormapKey);
- pColPriv->recalculate = TRUE;
- pLink = pLink->next;
- }
-
- if(GetInstalledmiColormap(pScreen) &&
- ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
- pScrn->vtSema || pScreenPriv->isDGAmode)) {
- ColormapPtr pMap = GetInstalledmiColormap(pScreen);
-
- if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
- (pMap->pVisual->class == TrueColor) &&
- CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
-
- /* if the current map doesn't have a palette look
- for another map to change the gamma on. */
-
- pLink = pScreenPriv->maps;
- while(pLink) {
- if(pLink->cmap->pVisual->class == PseudoColor)
- break;
- pLink = pLink->next;
- }
-
- if(pLink) {
- /* need to trick CMapRefreshColors() into thinking
- this is the currently installed map */
- SetInstalledmiColormap(pScreen, pLink->cmap);
- CMapReinstallMap(pLink->cmap);
- SetInstalledmiColormap(pScreen, pMap);
- }
- } else
- CMapReinstallMap(pMap);
- }
-
- return Success;
-}
-
-int
-xf86GetGammaRampSize(ScreenPtr pScreen)
-{
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- CMapScreenPtr pScreenPriv;
-
- if (xf86_crtc_supports_gamma(pScrn)) {
- RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
-
- if (crtc)
- return crtc->gammaSize;
- }
-
- if(!CMapScreenKeyRegistered) return 0;
-
- pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- CMapScreenKey);
- if(!pScreenPriv) return 0;
-
- return pScreenPriv->gammaElements;
-}
-
-int
-xf86GetGammaRamp(
- ScreenPtr pScreen,
- int size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue
-){
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- CMapScreenPtr pScreenPriv;
- LOCO *entry;
- int shift, sigbits;
-
- if (xf86_crtc_supports_gamma(pScrn)) {
- RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
-
- if (crtc) {
- if (crtc->gammaSize < size)
- return BadValue;
-
- if (!RRCrtcGammaGet(crtc))
- return BadImplementation;
-
- memcpy(red, crtc->gammaRed, size * sizeof(*red));
- memcpy(green, crtc->gammaGreen, size * sizeof(*green));
- memcpy(blue, crtc->gammaBlue, size * sizeof(*blue));
-
- return Success;
- }
- }
-
- if(!CMapScreenKeyRegistered)
- return BadImplementation;
-
- pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- CMapScreenKey);
- if(!pScreenPriv)
- return BadImplementation;
-
- if(size > pScreenPriv->gammaElements)
- return BadValue;
-
- entry = pScreenPriv->gamma;
- sigbits = pScreenPriv->sigRGBbits;
-
- while(size--) {
- *red = entry->red << (16 - sigbits);
- *green = entry->green << (16 - sigbits);
- *blue = entry->blue << (16 - sigbits);
- shift = sigbits;
- while(shift < 16) {
- *red |= *red >> shift;
- *green |= *green >> shift;
- *blue |= *blue >> shift;
- shift += sigbits;
- }
- red++; green++; blue++;
- entry++;
- }
-
- return Success;
-}
-
-int
-xf86ChangeGamma(
- ScreenPtr pScreen,
- Gamma gamma
-){
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
- if(pScrn->ChangeGamma)
- return (*pScrn->ChangeGamma)(pScreen->myNum, gamma);
-
- return BadImplementation;
-}
+/* + * Copyright (c) 1998-2001 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#if defined(_XOPEN_SOURCE) || defined(sun) && defined(__SVR4) +#include <math.h> +#else +#define _XOPEN_SOURCE /* to get prototype for pow on some systems */ +#include <math.h> +#undef _XOPEN_SOURCE +#endif + +#include <X11/X.h> +#include "misc.h" +#include <X11/Xproto.h> +#include "colormapst.h" +#include "scrnintstr.h" + +#include "resource.h" + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86str.h" +#include "micmap.h" +#include "xf86Crtc.h" + +#ifdef XFreeXDGA +#include <X11/extensions/xf86dgaproto.h> +#include "dgaproc.h" +#endif + +#include "xf86cmap.h" + +#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \ + ((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field) +#define SCREEN_EPILOGUE(pScreen, field, wrapper)\ + ((pScreen)->field = wrapper) + +#define LOAD_PALETTE(pmap) \ + ((pmap == GetInstalledmiColormap(pmap->pScreen)) && \ + ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || \ + xf86Screens[pmap->pScreen->myNum]->vtSema || pScreenPriv->isDGAmode)) + +typedef struct _CMapLink { + ColormapPtr cmap; + struct _CMapLink *next; +} CMapLink, *CMapLinkPtr; + +typedef struct { + ScrnInfoPtr pScrn; + CloseScreenProcPtr CloseScreen; + CreateColormapProcPtr CreateColormap; + DestroyColormapProcPtr DestroyColormap; + InstallColormapProcPtr InstallColormap; + StoreColorsProcPtr StoreColors; + Bool (*EnterVT) (int, int); + Bool (*SwitchMode) (int, DisplayModePtr, int); + int (*SetDGAMode) (int, int, DGADevicePtr); + xf86ChangeGammaProc *ChangeGamma; + int maxColors; + int sigRGBbits; + int gammaElements; + LOCO *gamma; + int *PreAllocIndices; + CMapLinkPtr maps; + unsigned int flags; + Bool isDGAmode; +} CMapScreenRec, *CMapScreenPtr; + +typedef struct { + int numColors; + LOCO *colors; + Bool recalculate; + int overscan; +} CMapColormapRec, *CMapColormapPtr; + +static DevPrivateKeyRec CMapScreenKeyRec; + +#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec) +#define CMapScreenKey (&CMapScreenKeyRec) +static DevPrivateKeyRec CMapColormapKeyRec; + +#define CMapColormapKey (&CMapColormapKeyRec) + +static void CMapInstallColormap(ColormapPtr); +static void CMapStoreColors(ColormapPtr, int, xColorItem *); +static Bool CMapCloseScreen(int, ScreenPtr); +static Bool CMapCreateColormap(ColormapPtr); +static void CMapDestroyColormap(ColormapPtr); + +static Bool CMapEnterVT(int, int); +static Bool CMapSwitchMode(int, DisplayModePtr, int); + +#ifdef XFreeXDGA +static int CMapSetDGAMode(int, int, DGADevicePtr); +#endif +static int CMapChangeGamma(int, Gamma); + +static void ComputeGamma(CMapScreenPtr); +static Bool CMapAllocateColormapPrivate(ColormapPtr); +static void CMapRefreshColors(ColormapPtr, int, int *); +static void CMapSetOverscan(ColormapPtr, int, int *); +static void CMapReinstallMap(ColormapPtr); +static void CMapUnwrapScreen(ScreenPtr pScreen); + +Bool +xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn) +{ + /* If we support a better colormap system, then pretend we succeeded. */ + if (xf86_crtc_supports_gamma(pScrn)) + return TRUE; + if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0)) + return FALSE; + + if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0)) + return FALSE; + return TRUE; +} + +Bool +xf86HandleColormaps(ScreenPtr pScreen, + int maxColors, + int sigRGBbits, + xf86LoadPaletteProc * loadPalette, + xf86SetOverscanProc * setOverscan, unsigned int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ColormapPtr pDefMap = NULL; + CMapScreenPtr pScreenPriv; + LOCO *gamma; + int *indices; + int elements; + + /* If we support a better colormap system, then pretend we succeeded. */ + if (xf86_crtc_supports_gamma(pScrn)) + return TRUE; + + if (!maxColors || !sigRGBbits || !loadPalette) + return FALSE; + + elements = 1 << sigRGBbits; + + if (!(gamma = malloc(elements * sizeof(LOCO)))) + return FALSE; + + if (!(indices = malloc(maxColors * sizeof(int)))) { + free(gamma); + return FALSE; + } + + if (!(pScreenPriv = malloc(sizeof(CMapScreenRec)))) { + free(gamma); + free(indices); + return FALSE; + } + + dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv); + + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreenPriv->CreateColormap = pScreen->CreateColormap; + pScreenPriv->DestroyColormap = pScreen->DestroyColormap; + pScreenPriv->InstallColormap = pScreen->InstallColormap; + pScreenPriv->StoreColors = pScreen->StoreColors; + pScreen->CloseScreen = CMapCloseScreen; + pScreen->CreateColormap = CMapCreateColormap; + pScreen->DestroyColormap = CMapDestroyColormap; + pScreen->InstallColormap = CMapInstallColormap; + pScreen->StoreColors = CMapStoreColors; + + pScreenPriv->pScrn = pScrn; + pScrn->LoadPalette = loadPalette; + pScrn->SetOverscan = setOverscan; + pScreenPriv->maxColors = maxColors; + pScreenPriv->sigRGBbits = sigRGBbits; + pScreenPriv->gammaElements = elements; + pScreenPriv->gamma = gamma; + pScreenPriv->PreAllocIndices = indices; + pScreenPriv->maps = NULL; + pScreenPriv->flags = flags; + pScreenPriv->isDGAmode = FALSE; + + pScreenPriv->EnterVT = pScrn->EnterVT; + pScreenPriv->SwitchMode = pScrn->SwitchMode; + pScreenPriv->SetDGAMode = pScrn->SetDGAMode; + pScreenPriv->ChangeGamma = pScrn->ChangeGamma; + + if (!(flags & CMAP_LOAD_EVEN_IF_OFFSCREEN)) { + pScrn->EnterVT = CMapEnterVT; + if ((flags & CMAP_RELOAD_ON_MODE_SWITCH) && pScrn->SwitchMode) + pScrn->SwitchMode = CMapSwitchMode; + } +#ifdef XFreeXDGA + pScrn->SetDGAMode = CMapSetDGAMode; +#endif + pScrn->ChangeGamma = CMapChangeGamma; + + ComputeGamma(pScreenPriv); + + /* get the default map */ + dixLookupResourceByType((pointer *) &pDefMap, pScreen->defColormap, + RT_COLORMAP, serverClient, DixInstallAccess); + + if (!CMapAllocateColormapPrivate(pDefMap)) { + CMapUnwrapScreen(pScreen); + return FALSE; + } + + /* Force the initial map to be loaded */ + SetInstalledmiColormap(pScreen, NULL); + CMapInstallColormap(pDefMap); + return TRUE; +} + +/**** Screen functions ****/ + +static Bool +CMapCloseScreen(int i, ScreenPtr pScreen) +{ + CMapUnwrapScreen(pScreen); + + return (*pScreen->CloseScreen) (i, pScreen); +} + +static Bool +CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv) +{ + if (pVisual->nplanes > 16) + return TRUE; + return ((1 << pVisual->nplanes) > pScreenPriv->maxColors); +} + +static Bool +CMapAllocateColormapPrivate(ColormapPtr pmap) +{ + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, + CMapScreenKey); + CMapColormapPtr pColPriv; + CMapLinkPtr pLink; + int numColors; + LOCO *colors; + + if (CMapColormapUseMax(pmap->pVisual, pScreenPriv)) + numColors = pmap->pVisual->ColormapEntries; + else + numColors = 1 << pmap->pVisual->nplanes; + + if (!(colors = malloc(numColors * sizeof(LOCO)))) + return FALSE; + + if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) { + free(colors); + return FALSE; + } + + dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv); + + pColPriv->numColors = numColors; + pColPriv->colors = colors; + pColPriv->recalculate = TRUE; + pColPriv->overscan = -1; + + /* add map to list */ + pLink = malloc(sizeof(CMapLink)); + if (pLink) { + pLink->cmap = pmap; + pLink->next = pScreenPriv->maps; + pScreenPriv->maps = pLink; + } + + return TRUE; +} + +static Bool +CMapCreateColormap(ColormapPtr pmap) +{ + ScreenPtr pScreen = pmap->pScreen; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + Bool ret = FALSE; + + pScreen->CreateColormap = pScreenPriv->CreateColormap; + if ((*pScreen->CreateColormap) (pmap)) { + if (CMapAllocateColormapPrivate(pmap)) + ret = TRUE; + } + pScreen->CreateColormap = CMapCreateColormap; + + return ret; +} + +static void +CMapDestroyColormap(ColormapPtr cmap) +{ + ScreenPtr pScreen = cmap->pScreen; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + CMapColormapPtr pColPriv = + (CMapColormapPtr) dixLookupPrivate(&cmap->devPrivates, CMapColormapKey); + CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps; + + if (pColPriv) { + free(pColPriv->colors); + free(pColPriv); + } + + /* remove map from list */ + while (pLink) { + if (pLink->cmap == cmap) { + if (prevLink) + prevLink->next = pLink->next; + else + pScreenPriv->maps = pLink->next; + free(pLink); + break; + } + prevLink = pLink; + pLink = pLink->next; + } + + if (pScreenPriv->DestroyColormap) { + pScreen->DestroyColormap = pScreenPriv->DestroyColormap; + (*pScreen->DestroyColormap) (cmap); + pScreen->DestroyColormap = CMapDestroyColormap; + } +} + +static void +CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs) +{ + ScreenPtr pScreen = pmap->pScreen; + VisualPtr pVisual = pmap->pVisual; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + int *indices = pScreenPriv->PreAllocIndices; + int num = ndef; + + /* At the moment this isn't necessary since there's nobody below us */ + pScreen->StoreColors = pScreenPriv->StoreColors; + (*pScreen->StoreColors) (pmap, ndef, pdefs); + pScreen->StoreColors = CMapStoreColors; + + /* should never get here for these */ + if ((pVisual->class == TrueColor) || + (pVisual->class == StaticColor) || (pVisual->class == StaticGray)) + return; + + if (pVisual->class == DirectColor) { + CMapColormapPtr pColPriv = + (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, + CMapColormapKey); + int i; + + if (CMapColormapUseMax(pVisual, pScreenPriv)) { + int index; + + num = 0; + while (ndef--) { + if (pdefs[ndef].flags & DoRed) { + index = (pdefs[ndef].pixel & pVisual->redMask) >> + pVisual->offsetRed; + i = num; + while (i--) + if (indices[i] == index) + break; + if (i == -1) + indices[num++] = index; + } + if (pdefs[ndef].flags & DoGreen) { + index = (pdefs[ndef].pixel & pVisual->greenMask) >> + pVisual->offsetGreen; + i = num; + while (i--) + if (indices[i] == index) + break; + if (i == -1) + indices[num++] = index; + } + if (pdefs[ndef].flags & DoBlue) { + index = (pdefs[ndef].pixel & pVisual->blueMask) >> + pVisual->offsetBlue; + i = num; + while (i--) + if (indices[i] == index) + break; + if (i == -1) + indices[num++] = index; + } + } + + } + else { + /* not really as overkill as it seems */ + num = pColPriv->numColors; + for (i = 0; i < pColPriv->numColors; i++) + indices[i] = i; + } + } + else { + while (ndef--) + indices[ndef] = pdefs[ndef].pixel; + } + + CMapRefreshColors(pmap, num, indices); +} + +static void +CMapInstallColormap(ColormapPtr pmap) +{ + ScreenPtr pScreen = pmap->pScreen; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + + if (pmap == GetInstalledmiColormap(pmap->pScreen)) + return; + + pScreen->InstallColormap = pScreenPriv->InstallColormap; + (*pScreen->InstallColormap) (pmap); + pScreen->InstallColormap = CMapInstallColormap; + + /* Important. We let the lower layers, namely DGA, + overwrite the choice of Colormap to install */ + if (GetInstalledmiColormap(pmap->pScreen)) + pmap = GetInstalledmiColormap(pmap->pScreen); + + if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && + (pmap->pVisual->class == TrueColor) && + CMapColormapUseMax(pmap->pVisual, pScreenPriv)) + return; + + if (LOAD_PALETTE(pmap)) + CMapReinstallMap(pmap); +} + +/**** ScrnInfoRec functions ****/ + +static Bool +CMapEnterVT(int index, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[index]; + ScreenPtr pScreen = screenInfo.screens[index]; + Bool ret; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + + pScrn->EnterVT = pScreenPriv->EnterVT; + ret = (*pScreenPriv->EnterVT) (index, flags); + pScreenPriv->EnterVT = pScrn->EnterVT; + pScrn->EnterVT = CMapEnterVT; + if (ret) { + if (GetInstalledmiColormap(pScreen)) + CMapReinstallMap(GetInstalledmiColormap(pScreen)); + return TRUE; + } + return FALSE; +} + +static Bool +CMapSwitchMode(int index, DisplayModePtr mode, int flags) +{ + ScreenPtr pScreen = screenInfo.screens[index]; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + + if ((*pScreenPriv->SwitchMode) (index, mode, flags)) { + if (GetInstalledmiColormap(pScreen)) + CMapReinstallMap(GetInstalledmiColormap(pScreen)); + return TRUE; + } + return FALSE; +} + +#ifdef XFreeXDGA +static int +CMapSetDGAMode(int index, int num, DGADevicePtr dev) +{ + ScreenPtr pScreen = screenInfo.screens[index]; + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + int ret; + + ret = (*pScreenPriv->SetDGAMode) (index, num, dev); + + pScreenPriv->isDGAmode = DGAActive(index); + + if (!pScreenPriv->isDGAmode && GetInstalledmiColormap(pScreen) + && xf86Screens[pScreen->myNum]->vtSema) + CMapReinstallMap(GetInstalledmiColormap(pScreen)); + + return ret; +} +#endif + +/**** Utilities ****/ + +static void +CMapReinstallMap(ColormapPtr pmap) +{ + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, + CMapScreenKey); + CMapColormapPtr cmapPriv = + (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); + ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum]; + int i = cmapPriv->numColors; + int *indices = pScreenPriv->PreAllocIndices; + + while (i--) + indices[i] = i; + + if (cmapPriv->recalculate) + CMapRefreshColors(pmap, cmapPriv->numColors, indices); + else { + (*pScrn->LoadPalette) (pScrn, cmapPriv->numColors, + indices, cmapPriv->colors, pmap->pVisual); + if (pScrn->SetOverscan) { +#ifdef DEBUGOVERSCAN + ErrorF("SetOverscan() called from CMapReinstallMap\n"); +#endif + pScrn->SetOverscan(pScrn, cmapPriv->overscan); + } + } + + cmapPriv->recalculate = FALSE; +} + +static void +CMapRefreshColors(ColormapPtr pmap, int defs, int *indices) +{ + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, + CMapScreenKey); + CMapColormapPtr pColPriv = + (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); + VisualPtr pVisual = pmap->pVisual; + ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum]; + int numColors, i; + LOCO *gamma, *colors; + EntryPtr entry; + int reds, greens, blues, maxValue, index, shift; + + numColors = pColPriv->numColors; + shift = 16 - pScreenPriv->sigRGBbits; + maxValue = (1 << pScreenPriv->sigRGBbits) - 1; + gamma = pScreenPriv->gamma; + colors = pColPriv->colors; + + reds = pVisual->redMask >> pVisual->offsetRed; + greens = pVisual->greenMask >> pVisual->offsetGreen; + blues = pVisual->blueMask >> pVisual->offsetBlue; + + switch (pVisual->class) { + case StaticGray: + for (i = 0; i < numColors; i++) { + index = (i + 1) * maxValue / numColors; + colors[i].red = gamma[index].red; + colors[i].green = gamma[index].green; + colors[i].blue = gamma[index].blue; + } + break; + case TrueColor: + if (CMapColormapUseMax(pVisual, pScreenPriv)) { + for (i = 0; i <= reds; i++) + colors[i].red = gamma[i * maxValue / reds].red; + for (i = 0; i <= greens; i++) + colors[i].green = gamma[i * maxValue / greens].green; + for (i = 0; i <= blues; i++) + colors[i].blue = gamma[i * maxValue / blues].blue; + break; + } + for (i = 0; i < numColors; i++) { + colors[i].red = gamma[((i >> pVisual->offsetRed) & reds) * + maxValue / reds].red; + colors[i].green = gamma[((i >> pVisual->offsetGreen) & greens) * + maxValue / greens].green; + colors[i].blue = gamma[((i >> pVisual->offsetBlue) & blues) * + maxValue / blues].blue; + } + break; + case StaticColor: + case PseudoColor: + case GrayScale: + for (i = 0; i < defs; i++) { + index = indices[i]; + entry = (EntryPtr) & pmap->red[index]; + + if (entry->fShared) { + colors[index].red = + gamma[entry->co.shco.red->color >> shift].red; + colors[index].green = + gamma[entry->co.shco.green->color >> shift].green; + colors[index].blue = + gamma[entry->co.shco.blue->color >> shift].blue; + } + else { + colors[index].red = gamma[entry->co.local.red >> shift].red; + colors[index].green = + gamma[entry->co.local.green >> shift].green; + colors[index].blue = gamma[entry->co.local.blue >> shift].blue; + } + } + break; + case DirectColor: + if (CMapColormapUseMax(pVisual, pScreenPriv)) { + for (i = 0; i < defs; i++) { + index = indices[i]; + if (index <= reds) + colors[index].red = + gamma[pmap->red[index].co.local.red >> shift].red; + if (index <= greens) + colors[index].green = + gamma[pmap->green[index].co.local.green >> shift].green; + if (index <= blues) + colors[index].blue = + gamma[pmap->blue[index].co.local.blue >> shift].blue; + + } + break; + } + for (i = 0; i < defs; i++) { + index = indices[i]; + + colors[index].red = gamma[pmap->red[(index >> pVisual-> + offsetRed) & reds].co.local. + red >> shift].red; + colors[index].green = + gamma[pmap->green[(index >> pVisual->offsetGreen) & greens].co. + local.green >> shift].green; + colors[index].blue = + gamma[pmap->blue[(index >> pVisual->offsetBlue) & blues].co. + local.blue >> shift].blue; + } + break; + } + + if (LOAD_PALETTE(pmap)) + (*pScrn->LoadPalette) (pScreenPriv->pScrn, defs, indices, + colors, pmap->pVisual); + + if (pScrn->SetOverscan) + CMapSetOverscan(pmap, defs, indices); + +} + +static Bool +CMapCompareColors(LOCO * color1, LOCO * color2) +{ + /* return TRUE if the color1 is "closer" to black than color2 */ +#ifdef DEBUGOVERSCAN + ErrorF("#%02x%02x%02x vs #%02x%02x%02x (%d vs %d)\n", + color1->red, color1->green, color1->blue, + color2->red, color2->green, color2->blue, + color1->red + color1->green + color1->blue, + color2->red + color2->green + color2->blue); +#endif + return (color1->red + color1->green + color1->blue < + color2->red + color2->green + color2->blue); +} + +static void +CMapSetOverscan(ColormapPtr pmap, int defs, int *indices) +{ + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, + CMapScreenKey); + CMapColormapPtr pColPriv = + (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); + ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum]; + VisualPtr pVisual = pmap->pVisual; + int i; + LOCO *colors; + int index; + Bool newOverscan = FALSE; + int overscan, tmpOverscan; + + colors = pColPriv->colors; + overscan = pColPriv->overscan; + + /* + * Search for a new overscan index in the following cases: + * + * - The index hasn't yet been initialised. In this case search + * for an index that is black or a close match to black. + * + * - The colour of the old index is changed. In this case search + * all indices for a black or close match to black. + * + * - The colour of the old index wasn't black. In this case only + * search the indices that were changed for a better match to black. + */ + + switch (pVisual->class) { + case StaticGray: + case TrueColor: + /* Should only come here once. Initialise the overscan index to 0 */ + overscan = 0; + newOverscan = TRUE; + break; + case StaticColor: + /* + * Only come here once, but search for the overscan in the same way + * as for the other cases. + */ + case DirectColor: + case PseudoColor: + case GrayScale: + if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) { + /* Uninitialised */ + newOverscan = TRUE; + } + else { + /* Check if the overscan was changed */ + for (i = 0; i < defs; i++) { + index = indices[i]; + if (index == overscan) { + newOverscan = TRUE; + break; + } + } + } + if (newOverscan) { + /* The overscan is either uninitialised or it has been changed */ + + if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) + tmpOverscan = pScreenPriv->maxColors - 1; + else + tmpOverscan = overscan; + + /* search all entries for a close match to black */ + for (i = pScreenPriv->maxColors - 1; i >= 0; i--) { + if (colors[i].red == 0 && colors[i].green == 0 && + colors[i].blue == 0) { + overscan = i; +#ifdef DEBUGOVERSCAN + ErrorF("Black found at index 0x%02x\n", i); +#endif + break; + } + else { +#ifdef DEBUGOVERSCAN + ErrorF("0x%02x: ", i); +#endif + if (CMapCompareColors(&colors[i], &colors[tmpOverscan])) { + tmpOverscan = i; +#ifdef DEBUGOVERSCAN + ErrorF("possible \"Black\" at index 0x%02x\n", i); +#endif + } + } + } + if (i < 0) + overscan = tmpOverscan; + } + else { + /* Check of the old overscan wasn't black */ + if (colors[overscan].red != 0 || colors[overscan].green != 0 || + colors[overscan].blue != 0) { + int oldOverscan = tmpOverscan = overscan; + + /* See of there is now a better match */ + for (i = 0; i < defs; i++) { + index = indices[i]; + if (colors[index].red == 0 && colors[index].green == 0 && + colors[index].blue == 0) { + overscan = index; +#ifdef DEBUGOVERSCAN + ErrorF("Black found at index 0x%02x\n", index); +#endif + break; + } + else { +#ifdef DEBUGOVERSCAN + ErrorF("0x%02x: ", index); +#endif + if (CMapCompareColors(&colors[index], + &colors[tmpOverscan])) { + tmpOverscan = index; +#ifdef DEBUGOVERSCAN + ErrorF("possible \"Black\" at index 0x%02x\n", + index); +#endif + } + } + } + if (i == defs) + overscan = tmpOverscan; + if (overscan != oldOverscan) + newOverscan = TRUE; + } + } + break; + } + if (newOverscan) { + pColPriv->overscan = overscan; + if (LOAD_PALETTE(pmap)) { +#ifdef DEBUGOVERSCAN + ErrorF("SetOverscan() called from CmapSetOverscan\n"); +#endif + pScrn->SetOverscan(pScreenPriv->pScrn, overscan); + } + } +} + +static void +CMapUnwrapScreen(ScreenPtr pScreen) +{ + CMapScreenPtr pScreenPriv = + (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + pScreen->CloseScreen = pScreenPriv->CloseScreen; + pScreen->CreateColormap = pScreenPriv->CreateColormap; + pScreen->DestroyColormap = pScreenPriv->DestroyColormap; + pScreen->InstallColormap = pScreenPriv->InstallColormap; + pScreen->StoreColors = pScreenPriv->StoreColors; + + pScrn->EnterVT = pScreenPriv->EnterVT; + pScrn->SwitchMode = pScreenPriv->SwitchMode; + pScrn->SetDGAMode = pScreenPriv->SetDGAMode; + pScrn->ChangeGamma = pScreenPriv->ChangeGamma; + + free(pScreenPriv->gamma); + free(pScreenPriv->PreAllocIndices); + free(pScreenPriv); +} + +static void +ComputeGamma(CMapScreenPtr priv) +{ + int elements = priv->gammaElements - 1; + double RedGamma, GreenGamma, BlueGamma; + int i; + +#ifndef DONT_CHECK_GAMMA + /* This check is to catch drivers that are not initialising pScrn->gamma */ + if (priv->pScrn->gamma.red < GAMMA_MIN || + priv->pScrn->gamma.red > GAMMA_MAX || + priv->pScrn->gamma.green < GAMMA_MIN || + priv->pScrn->gamma.green > GAMMA_MAX || + priv->pScrn->gamma.blue < GAMMA_MIN || + priv->pScrn->gamma.blue > GAMMA_MAX) { + + xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0, + "The %s driver didn't call xf86SetGamma() to initialise\n" + "\tthe gamma values.\n", priv->pScrn->driverName); + xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0, + "PLEASE FIX THE `%s' DRIVER!\n", + priv->pScrn->driverName); + priv->pScrn->gamma.red = 1.0; + priv->pScrn->gamma.green = 1.0; + priv->pScrn->gamma.blue = 1.0; + } +#endif + + RedGamma = 1.0 / (double) priv->pScrn->gamma.red; + GreenGamma = 1.0 / (double) priv->pScrn->gamma.green; + BlueGamma = 1.0 / (double) priv->pScrn->gamma.blue; + + for (i = 0; i <= elements; i++) { + if (RedGamma == 1.0) + priv->gamma[i].red = i; + else + priv->gamma[i].red = (CARD16) (pow((double) i / (double) elements, + RedGamma) * (double) elements + + 0.5); + + if (GreenGamma == 1.0) + priv->gamma[i].green = i; + else + priv->gamma[i].green = (CARD16) (pow((double) i / (double) elements, + GreenGamma) * + (double) elements + 0.5); + + if (BlueGamma == 1.0) + priv->gamma[i].blue = i; + else + priv->gamma[i].blue = (CARD16) (pow((double) i / (double) elements, + BlueGamma) * (double) elements + + 0.5); + } +} + +int +CMapChangeGamma(int index, Gamma gamma) +{ + int ret = Success; + ScrnInfoPtr pScrn = xf86Screens[index]; + ScreenPtr pScreen = pScrn->pScreen; + CMapColormapPtr pColPriv; + CMapScreenPtr pScreenPriv; + CMapLinkPtr pLink; + + /* Is this sufficient checking ? */ + if (!CMapScreenKeyRegistered) + return BadImplementation; + + pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + CMapScreenKey); + if (!pScreenPriv) + return BadImplementation; + + if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX || + gamma.green < GAMMA_MIN || gamma.green > GAMMA_MAX || + gamma.blue < GAMMA_MIN || gamma.blue > GAMMA_MAX) + return BadValue; + + pScrn->gamma.red = gamma.red; + pScrn->gamma.green = gamma.green; + pScrn->gamma.blue = gamma.blue; + + ComputeGamma(pScreenPriv); + + /* mark all colormaps on this screen */ + pLink = pScreenPriv->maps; + while (pLink) { + pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates, + CMapColormapKey); + pColPriv->recalculate = TRUE; + pLink = pLink->next; + } + + if (GetInstalledmiColormap(pScreen) && + ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || + pScrn->vtSema || pScreenPriv->isDGAmode)) { + ColormapPtr pMap = GetInstalledmiColormap(pScreen); + + if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && + (pMap->pVisual->class == TrueColor) && + CMapColormapUseMax(pMap->pVisual, pScreenPriv)) { + + /* if the current map doesn't have a palette look + for another map to change the gamma on. */ + + pLink = pScreenPriv->maps; + while (pLink) { + if (pLink->cmap->pVisual->class == PseudoColor) + break; + pLink = pLink->next; + } + + if (pLink) { + /* need to trick CMapRefreshColors() into thinking + this is the currently installed map */ + SetInstalledmiColormap(pScreen, pLink->cmap); + CMapReinstallMap(pLink->cmap); + SetInstalledmiColormap(pScreen, pMap); + } + } + else + CMapReinstallMap(pMap); + } + + pScrn->ChangeGamma = pScreenPriv->ChangeGamma; + if (pScrn->ChangeGamma) + ret = pScrn->ChangeGamma(index, gamma); + pScrn->ChangeGamma = CMapChangeGamma; + + return ret; +} + +static void +ComputeGammaRamp(CMapScreenPtr priv, + unsigned short *red, + unsigned short *green, unsigned short *blue) +{ + int elements = priv->gammaElements; + LOCO *entry = priv->gamma; + int shift = 16 - priv->sigRGBbits; + + while (elements--) { + entry->red = *(red++) >> shift; + entry->green = *(green++) >> shift; + entry->blue = *(blue++) >> shift; + entry++; + } +} + +int +xf86ChangeGammaRamp(ScreenPtr pScreen, + int size, + unsigned short *red, + unsigned short *green, unsigned short *blue) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + CMapColormapPtr pColPriv; + CMapScreenPtr pScreenPriv; + CMapLinkPtr pLink; + + if (xf86_crtc_supports_gamma(pScrn)) { + RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); + + if (crtc) { + if (crtc->gammaSize != size) + return BadValue; + + RRCrtcGammaSet(crtc, red, green, blue); + + return Success; + } + } + + if (!CMapScreenKeyRegistered) + return BadImplementation; + + pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + CMapScreenKey); + if (!pScreenPriv) + return BadImplementation; + + if (pScreenPriv->gammaElements != size) + return BadValue; + + ComputeGammaRamp(pScreenPriv, red, green, blue); + + /* mark all colormaps on this screen */ + pLink = pScreenPriv->maps; + while (pLink) { + pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates, + CMapColormapKey); + pColPriv->recalculate = TRUE; + pLink = pLink->next; + } + + if (GetInstalledmiColormap(pScreen) && + ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || + pScrn->vtSema || pScreenPriv->isDGAmode)) { + ColormapPtr pMap = GetInstalledmiColormap(pScreen); + + if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && + (pMap->pVisual->class == TrueColor) && + CMapColormapUseMax(pMap->pVisual, pScreenPriv)) { + + /* if the current map doesn't have a palette look + for another map to change the gamma on. */ + + pLink = pScreenPriv->maps; + while (pLink) { + if (pLink->cmap->pVisual->class == PseudoColor) + break; + pLink = pLink->next; + } + + if (pLink) { + /* need to trick CMapRefreshColors() into thinking + this is the currently installed map */ + SetInstalledmiColormap(pScreen, pLink->cmap); + CMapReinstallMap(pLink->cmap); + SetInstalledmiColormap(pScreen, pMap); + } + } + else + CMapReinstallMap(pMap); + } + + return Success; +} + +int +xf86GetGammaRampSize(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + CMapScreenPtr pScreenPriv; + + if (xf86_crtc_supports_gamma(pScrn)) { + RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); + + if (crtc) + return crtc->gammaSize; + } + + if (!CMapScreenKeyRegistered) + return 0; + + pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + CMapScreenKey); + if (!pScreenPriv) + return 0; + + return pScreenPriv->gammaElements; +} + +int +xf86GetGammaRamp(ScreenPtr pScreen, + int size, + unsigned short *red, + unsigned short *green, unsigned short *blue) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + CMapScreenPtr pScreenPriv; + LOCO *entry; + int shift, sigbits; + + if (xf86_crtc_supports_gamma(pScrn)) { + RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); + + if (crtc) { + if (crtc->gammaSize < size) + return BadValue; + + if (!RRCrtcGammaGet(crtc)) + return BadImplementation; + + memcpy(red, crtc->gammaRed, size * sizeof(*red)); + memcpy(green, crtc->gammaGreen, size * sizeof(*green)); + memcpy(blue, crtc->gammaBlue, size * sizeof(*blue)); + + return Success; + } + } + + if (!CMapScreenKeyRegistered) + return BadImplementation; + + pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + CMapScreenKey); + if (!pScreenPriv) + return BadImplementation; + + if (size > pScreenPriv->gammaElements) + return BadValue; + + entry = pScreenPriv->gamma; + sigbits = pScreenPriv->sigRGBbits; + + while (size--) { + *red = entry->red << (16 - sigbits); + *green = entry->green << (16 - sigbits); + *blue = entry->blue << (16 - sigbits); + shift = sigbits; + while (shift < 16) { + *red |= *red >> shift; + *green |= *green >> shift; + *blue |= *blue >> shift; + shift += sigbits; + } + red++; + green++; + blue++; + entry++; + } + + return Success; +} + +int +xf86ChangeGamma(ScreenPtr pScreen, Gamma gamma) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + if (pScrn->ChangeGamma) + return (*pScrn->ChangeGamma) (pScreen->myNum, gamma); + + return BadImplementation; +} diff --git a/xorg-server/hw/xfree86/common/xf86cmap.h b/xorg-server/hw/xfree86/common/xf86cmap.h index caa01e8ed..2661cf429 100644 --- a/xorg-server/hw/xfree86/common/xf86cmap.h +++ b/xorg-server/hw/xfree86/common/xf86cmap.h @@ -1,79 +1,67 @@ -
-/*
- * Copyright (c) 1998-2001 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifndef _XF86CMAP_H
-#define _XF86CMAP_H
-
-#include "xf86str.h"
-#include "colormapst.h"
-
-#define CMAP_PALETTED_TRUECOLOR 0x0000001
-#define CMAP_RELOAD_ON_MODE_SWITCH 0x0000002
-#define CMAP_LOAD_EVEN_IF_OFFSCREEN 0x0000004
-
-extern _X_EXPORT Bool xf86HandleColormaps(
- ScreenPtr pScreen,
- int maxCol,
- int sigRGBbits,
- xf86LoadPaletteProc *loadPalette,
- xf86SetOverscanProc *setOverscan,
- unsigned int flags
-);
-
-extern _X_EXPORT Bool xf86ColormapAllocatePrivates(
- ScrnInfoPtr pScrn
-);
-
-extern _X_EXPORT int
-xf86ChangeGamma(
- ScreenPtr pScreen,
- Gamma newGamma
-);
-
-extern _X_EXPORT int
-xf86ChangeGammaRamp(
- ScreenPtr pScreen,
- int size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue
-);
-
-extern _X_EXPORT int xf86GetGammaRampSize(ScreenPtr pScreen);
-
-extern _X_EXPORT int
-xf86GetGammaRamp(
- ScreenPtr pScreen,
- int size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue
-);
-
-#endif /* _XF86CMAP_H */
-
+ +/* + * Copyright (c) 1998-2001 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifndef _XF86CMAP_H +#define _XF86CMAP_H + +#include "xf86str.h" +#include "colormapst.h" + +#define CMAP_PALETTED_TRUECOLOR 0x0000001 +#define CMAP_RELOAD_ON_MODE_SWITCH 0x0000002 +#define CMAP_LOAD_EVEN_IF_OFFSCREEN 0x0000004 + +extern _X_EXPORT Bool xf86HandleColormaps(ScreenPtr pScreen, + int maxCol, + int sigRGBbits, + xf86LoadPaletteProc * loadPalette, + xf86SetOverscanProc * setOverscan, + unsigned int flags); + +extern _X_EXPORT Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn); + +extern _X_EXPORT int + xf86ChangeGamma(ScreenPtr pScreen, Gamma newGamma); + +extern _X_EXPORT int + +xf86ChangeGammaRamp(ScreenPtr pScreen, + int size, + unsigned short *red, + unsigned short *green, unsigned short *blue); + +extern _X_EXPORT int xf86GetGammaRampSize(ScreenPtr pScreen); + +extern _X_EXPORT int + +xf86GetGammaRamp(ScreenPtr pScreen, + int size, + unsigned short *red, + unsigned short *green, unsigned short *blue); + +#endif /* _XF86CMAP_H */ diff --git a/xorg-server/hw/xfree86/common/xf86fbman.c b/xorg-server/hw/xfree86/common/xf86fbman.c index ccb761a2c..3c29bf531 100644 --- a/xorg-server/hw/xfree86/common/xf86fbman.c +++ b/xorg-server/hw/xfree86/common/xf86fbman.c @@ -1,1446 +1,1431 @@ -
-/*
- * Copyright (c) 1998-2001 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "regionstr.h"
-#include "xf86fbman.h"
-
-/*
-#define DEBUG
-*/
-
-static DevPrivateKeyRec xf86FBManagerKeyRec;
-static DevPrivateKey xf86FBManagerKey;
-
-Bool xf86RegisterOffscreenManager(
- ScreenPtr pScreen,
- FBManagerFuncsPtr funcs
-){
-
- xf86FBManagerKey = &xf86FBManagerKeyRec;
-
- if (!dixRegisterPrivateKey(&xf86FBManagerKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs);
-
- return TRUE;
-}
-
-
-Bool
-xf86FBManagerRunning(ScreenPtr pScreen)
-{
- if (xf86FBManagerKey == NULL)
- return FALSE;
-
- if(!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey))
- return FALSE;
-
- return TRUE;
-}
-
-Bool
-xf86RegisterFreeBoxCallback(
- ScreenPtr pScreen,
- FreeBoxCallbackProcPtr FreeBoxCallback,
- pointer devPriv
-){
- FBManagerFuncsPtr funcs;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->RegisterFreeBoxCallback)(pScreen, FreeBoxCallback, devPriv);
-}
-
-
-FBAreaPtr
-xf86AllocateOffscreenArea(
- ScreenPtr pScreen,
- int w, int h,
- int gran,
- MoveAreaCallbackProcPtr moveCB,
- RemoveAreaCallbackProcPtr removeCB,
- pointer privData
-){
- FBManagerFuncsPtr funcs;
-
- if(xf86FBManagerKey == NULL)
- return NULL;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return NULL;
-
- return (*funcs->AllocateOffscreenArea)(
- pScreen, w, h, gran, moveCB, removeCB, privData);
-}
-
-
-FBLinearPtr
-xf86AllocateOffscreenLinear(
- ScreenPtr pScreen,
- int length,
- int gran,
- MoveLinearCallbackProcPtr moveCB,
- RemoveLinearCallbackProcPtr removeCB,
- pointer privData
-){
- FBManagerFuncsPtr funcs;
-
- if(xf86FBManagerKey == NULL)
- return NULL;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return NULL;
-
- return (*funcs->AllocateOffscreenLinear)(
- pScreen, length, gran, moveCB, removeCB, privData);
-}
-
-
-void
-xf86FreeOffscreenArea(FBAreaPtr area)
-{
- FBManagerFuncsPtr funcs;
-
- if(!area) return;
-
- if(xf86FBManagerKey == NULL)
- return;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
- &area->pScreen->devPrivates, xf86FBManagerKey)))
- return;
-
- (*funcs->FreeOffscreenArea)(area);
-
- return;
-}
-
-
-void
-xf86FreeOffscreenLinear(FBLinearPtr linear)
-{
- FBManagerFuncsPtr funcs;
-
- if(!linear) return;
-
- if(xf86FBManagerKey == NULL)
- return;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
- &linear->pScreen->devPrivates, xf86FBManagerKey)))
- return;
-
- (*funcs->FreeOffscreenLinear)(linear);
-
- return;
-}
-
-
-Bool
-xf86ResizeOffscreenArea(
- FBAreaPtr resize,
- int w, int h
-){
- FBManagerFuncsPtr funcs;
-
- if(!resize) return FALSE;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
- &resize->pScreen->devPrivates, xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->ResizeOffscreenArea)(resize, w, h);
-}
-
-Bool
-xf86ResizeOffscreenLinear(
- FBLinearPtr resize,
- int size
-){
- FBManagerFuncsPtr funcs;
-
- if(!resize) return FALSE;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
- &resize->pScreen->devPrivates, xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->ResizeOffscreenLinear)(resize, size);
-}
-
-
-Bool
-xf86QueryLargestOffscreenArea(
- ScreenPtr pScreen,
- int *w, int *h,
- int gran,
- int preferences,
- int severity
-){
- FBManagerFuncsPtr funcs;
-
- *w = 0;
- *h = 0;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->QueryLargestOffscreenArea)(
- pScreen, w, h, gran, preferences, severity);
-}
-
-Bool
-xf86QueryLargestOffscreenLinear(
- ScreenPtr pScreen,
- int *size,
- int gran,
- int severity
-){
- FBManagerFuncsPtr funcs;
-
- *size = 0;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->QueryLargestOffscreenLinear)(
- pScreen, size, gran, severity);
-}
-
-
-Bool
-xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
-{
- FBManagerFuncsPtr funcs;
-
- if(xf86FBManagerKey == NULL)
- return FALSE;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return FALSE;
-
- return (*funcs->PurgeOffscreenAreas)(pScreen);
-}
-
-/************************************************************\
-
- Below is a specific implementation of an offscreen manager.
-
-\************************************************************/
-
-static DevPrivateKeyRec xf86FBScreenKeyRec;
-#define xf86FBScreenKey (&xf86FBScreenKeyRec)
-
-typedef struct _FBLink {
- FBArea area;
- struct _FBLink *next;
-} FBLink, *FBLinkPtr;
-
-typedef struct _FBLinearLink {
- FBLinear linear;
- int free; /* need to add free here as FBLinear is publicly accessible */
- FBAreaPtr area; /* only used if allocation came from XY area */
- struct _FBLinearLink *next;
-} FBLinearLink, *FBLinearLinkPtr;
-
-
-typedef struct {
- ScreenPtr pScreen;
- RegionPtr InitialBoxes;
- RegionPtr FreeBoxes;
- FBLinkPtr UsedAreas;
- int NumUsedAreas;
- FBLinearLinkPtr LinearAreas;
- CloseScreenProcPtr CloseScreen;
- int NumCallbacks;
- FreeBoxCallbackProcPtr *FreeBoxesUpdateCallback;
- DevUnion *devPrivates;
-} FBManager, *FBManagerPtr;
-
-
-static void
-SendCallFreeBoxCallbacks(FBManagerPtr offman)
-{
- int i = offman->NumCallbacks;
-
- while(i--) {
- (*offman->FreeBoxesUpdateCallback[i])(
- offman->pScreen, offman->FreeBoxes, offman->devPrivates[i].ptr);
- }
-}
-
-static Bool
-localRegisterFreeBoxCallback(
- ScreenPtr pScreen,
- FreeBoxCallbackProcPtr FreeBoxCallback,
- pointer devPriv
-){
- FBManagerPtr offman;
- FreeBoxCallbackProcPtr *newCallbacks;
- DevUnion *newPrivates;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- newCallbacks = realloc( offman->FreeBoxesUpdateCallback,
- sizeof(FreeBoxCallbackProcPtr) * (offman->NumCallbacks + 1));
-
- newPrivates = realloc(offman->devPrivates,
- sizeof(DevUnion) * (offman->NumCallbacks + 1));
-
- if(!newCallbacks || !newPrivates)
- return FALSE;
-
- offman->FreeBoxesUpdateCallback = newCallbacks;
- offman->devPrivates = newPrivates;
-
- offman->FreeBoxesUpdateCallback[offman->NumCallbacks] = FreeBoxCallback;
- offman->devPrivates[offman->NumCallbacks].ptr = devPriv;
- offman->NumCallbacks++;
-
- SendCallFreeBoxCallbacks(offman);
-
- return TRUE;
-}
-
-
-static FBAreaPtr
-AllocateArea(
- FBManagerPtr offman,
- int w, int h,
- int granularity,
- MoveAreaCallbackProcPtr moveCB,
- RemoveAreaCallbackProcPtr removeCB,
- pointer privData
-){
- ScreenPtr pScreen = offman->pScreen;
- FBLinkPtr link = NULL;
- FBAreaPtr area = NULL;
- RegionRec NewReg;
- int i, x = 0, num;
- BoxPtr boxp;
-
- if(granularity <= 1) granularity = 0;
-
- boxp = RegionRects(offman->FreeBoxes);
- num = RegionNumRects(offman->FreeBoxes);
-
- /* look through the free boxes */
- for(i = 0; i < num; i++, boxp++) {
- x = boxp->x1;
- if (granularity > 1)
- x = ((x + granularity - 1) / granularity) * granularity;
-
- if(((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w))
- continue;
-
- link = malloc(sizeof(FBLink));
- if(!link) return NULL;
-
- area = &(link->area);
- link->next = offman->UsedAreas;
- offman->UsedAreas = link;
- offman->NumUsedAreas++;
- break;
- }
-
- /* try to boot a removeable one out if we are not expendable ourselves */
- if(!area && !removeCB) {
- link = offman->UsedAreas;
-
- while(link) {
- if(!link->area.RemoveAreaCallback) {
- link = link->next;
- continue;
- }
-
- boxp = &(link->area.box);
- x = boxp->x1;
- if (granularity > 1)
- x = ((x + granularity - 1) / granularity) * granularity;
-
- if(((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) {
- link = link->next;
- continue;
- }
-
- /* bye, bye */
- (*link->area.RemoveAreaCallback)(&link->area);
- RegionInit(&NewReg, &(link->area.box), 1);
- RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &NewReg);
- RegionUninit(&NewReg);
-
- area = &(link->area);
- break;
- }
- }
-
- if(area) {
- area->pScreen = pScreen;
- area->granularity = granularity;
- area->box.x1 = x;
- area->box.x2 = x + w;
- area->box.y1 = boxp->y1;
- area->box.y2 = boxp->y1 + h;
- area->MoveAreaCallback = moveCB;
- area->RemoveAreaCallback = removeCB;
- area->devPrivate.ptr = privData;
-
- RegionInit(&NewReg, &(area->box), 1);
- RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &NewReg);
- RegionUninit(&NewReg);
- }
-
- return area;
-}
-
-static FBAreaPtr
-localAllocateOffscreenArea(
- ScreenPtr pScreen,
- int w, int h,
- int gran,
- MoveAreaCallbackProcPtr moveCB,
- RemoveAreaCallbackProcPtr removeCB,
- pointer privData
-){
- FBManagerPtr offman;
- FBAreaPtr area = NULL;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- if((area = AllocateArea(offman, w, h, gran, moveCB, removeCB, privData)))
- SendCallFreeBoxCallbacks(offman);
-
- return area;
-}
-
-
-static void
-localFreeOffscreenArea(FBAreaPtr area)
-{
- FBManagerPtr offman;
- FBLinkPtr pLink, pLinkPrev = NULL;
- RegionRec FreedRegion;
- ScreenPtr pScreen;
-
- pScreen = area->pScreen;
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- pLink = offman->UsedAreas;
- if(!pLink) return;
-
- while(&(pLink->area) != area) {
- pLinkPrev = pLink;
- pLink = pLink->next;
- if(!pLink) return;
- }
-
- /* put the area back into the pool */
- RegionInit(&FreedRegion, &(pLink->area.box), 1);
- RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedRegion);
- RegionUninit(&FreedRegion);
-
- if(pLinkPrev)
- pLinkPrev->next = pLink->next;
- else offman->UsedAreas = pLink->next;
-
- free(pLink);
- offman->NumUsedAreas--;
-
- SendCallFreeBoxCallbacks(offman);
-}
-
-
-
-static Bool
-localResizeOffscreenArea(
- FBAreaPtr resize,
- int w, int h
-){
- FBManagerPtr offman;
- ScreenPtr pScreen;
- BoxRec OrigArea;
- RegionRec FreedReg;
- FBAreaPtr area = NULL;
- FBLinkPtr pLink, newLink, pLinkPrev = NULL;
-
- pScreen = resize->pScreen;
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- /* find this link */
- if(!(pLink = offman->UsedAreas))
- return FALSE;
-
- while(&(pLink->area) != resize) {
- pLinkPrev = pLink;
- pLink = pLink->next;
- if(!pLink) return FALSE;
- }
-
- OrigArea.x1 = resize->box.x1;
- OrigArea.x2 = resize->box.x2;
- OrigArea.y1 = resize->box.y1;
- OrigArea.y2 = resize->box.y2;
-
- /* if it's smaller, this is easy */
-
- if((w <= (resize->box.x2 - resize->box.x1)) &&
- (h <= (resize->box.y2 - resize->box.y1))) {
- RegionRec NewReg;
-
- resize->box.x2 = resize->box.x1 + w;
- resize->box.y2 = resize->box.y1 + h;
-
- if((resize->box.y2 == OrigArea.y2) &&
- (resize->box.x2 == OrigArea.x2))
- return TRUE;
-
- RegionInit(&FreedReg, &OrigArea, 1);
- RegionInit(&NewReg, &(resize->box), 1);
- RegionSubtract(&FreedReg, &FreedReg, &NewReg);
- RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
- RegionUninit(&FreedReg);
- RegionUninit(&NewReg);
-
- SendCallFreeBoxCallbacks(offman);
-
- return TRUE;
- }
-
-
- /* otherwise we remove the old region */
-
- RegionInit(&FreedReg, &OrigArea, 1);
- RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
-
- /* remove the old link */
- if(pLinkPrev)
- pLinkPrev->next = pLink->next;
- else offman->UsedAreas = pLink->next;
-
- /* and try to add a new one */
-
- if((area = AllocateArea(offman, w, h, resize->granularity,
- resize->MoveAreaCallback, resize->RemoveAreaCallback,
- resize->devPrivate.ptr))) {
-
- /* copy data over to our link and replace the new with old */
- memcpy(resize, area, sizeof(FBArea));
-
- pLinkPrev = NULL;
- newLink = offman->UsedAreas;
-
- while(&(newLink->area) != area) {
- pLinkPrev = newLink;
- newLink = newLink->next;
- }
-
- if(pLinkPrev)
- pLinkPrev->next = newLink->next;
- else offman->UsedAreas = newLink->next;
-
- pLink->next = offman->UsedAreas;
- offman->UsedAreas = pLink;
-
- free(newLink);
-
- /* AllocateArea added one but we really only exchanged one */
- offman->NumUsedAreas--;
- } else {
- /* reinstate the old region */
- RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
- RegionUninit(&FreedReg);
-
- pLink->next = offman->UsedAreas;
- offman->UsedAreas = pLink;
- return FALSE;
- }
-
-
- RegionUninit(&FreedReg);
-
- SendCallFreeBoxCallbacks(offman);
-
- return TRUE;
-}
-
-static Bool
-localQueryLargestOffscreenArea(
- ScreenPtr pScreen,
- int *width, int *height,
- int granularity,
- int preferences,
- int severity
-){
- FBManagerPtr offman;
- RegionPtr newRegion = NULL;
- BoxPtr pbox;
- int nbox;
- int x, w, h, area, oldArea;
-
- *width = *height = oldArea = 0;
-
- if(granularity <= 1) granularity = 0;
-
- if((preferences < 0) || (preferences > 3))
- return FALSE;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- if(severity < 0) severity = 0;
- if(severity > 2) severity = 2;
-
- switch(severity) {
- case 2:
- if(offman->NumUsedAreas) {
- FBLinkPtr pLink;
- RegionRec tmpRegion;
- newRegion = RegionCreate(NULL, 1);
- RegionCopy(newRegion, offman->InitialBoxes);
- pLink = offman->UsedAreas;
-
- while(pLink) {
- if(!pLink->area.RemoveAreaCallback) {
- RegionInit(&tmpRegion, &(pLink->area.box), 1);
- RegionSubtract(newRegion, newRegion, &tmpRegion);
- RegionUninit(&tmpRegion);
- }
- pLink = pLink->next;
- }
-
- nbox = RegionNumRects(newRegion);
- pbox = RegionRects(newRegion);
- break;
- }
- case 1:
- if(offman->NumUsedAreas) {
- FBLinkPtr pLink;
- RegionRec tmpRegion;
- newRegion = RegionCreate(NULL, 1);
- RegionCopy(newRegion, offman->FreeBoxes);
- pLink = offman->UsedAreas;
-
- while(pLink) {
- if(pLink->area.RemoveAreaCallback) {
- RegionInit(&tmpRegion, &(pLink->area.box), 1);
- RegionAppend(newRegion, &tmpRegion);
- RegionUninit(&tmpRegion);
- }
- pLink = pLink->next;
- }
-
- nbox = RegionNumRects(newRegion);
- pbox = RegionRects(newRegion);
- break;
- }
- default:
- nbox = RegionNumRects(offman->FreeBoxes);
- pbox = RegionRects(offman->FreeBoxes);
- break;
- }
-
- while(nbox--) {
- x = pbox->x1;
- if (granularity > 1)
- x = ((x + granularity - 1) / granularity) * granularity;
-
- w = pbox->x2 - x;
- h = pbox->y2 - pbox->y1;
- area = w * h;
-
- if(w > 0) {
- Bool gotIt = FALSE;
- switch(preferences) {
- case FAVOR_AREA_THEN_WIDTH:
- if((area > oldArea) || ((area == oldArea) && (w > *width)))
- gotIt = TRUE;
- break;
- case FAVOR_AREA_THEN_HEIGHT:
- if((area > oldArea) || ((area == oldArea) && (h > *height)))
- gotIt = TRUE;
- break;
- case FAVOR_WIDTH_THEN_AREA:
- if((w > *width) || ((w == *width) && (area > oldArea)))
- gotIt = TRUE;
- break;
- case FAVOR_HEIGHT_THEN_AREA:
- if((h > *height) || ((h == *height) && (area > oldArea)))
- gotIt = TRUE;
- break;
- }
- if(gotIt) {
- *width = w;
- *height = h;
- oldArea = area;
- }
- }
- pbox++;
- }
-
- if(newRegion)
- RegionDestroy(newRegion);
-
- return TRUE;
-}
-
-static Bool
-localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
-{
- FBManagerPtr offman;
- FBLinkPtr pLink, tmp, pPrev = NULL;
- RegionRec FreedRegion;
- Bool anyUsed = FALSE;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- pLink = offman->UsedAreas;
- if(!pLink) return TRUE;
-
- while(pLink) {
- if(pLink->area.RemoveAreaCallback) {
- (*pLink->area.RemoveAreaCallback)(&pLink->area);
-
- RegionInit(&FreedRegion, &(pLink->area.box), 1);
- RegionAppend(offman->FreeBoxes, &FreedRegion);
- RegionUninit(&FreedRegion);
-
- if(pPrev)
- pPrev->next = pLink->next;
- else offman->UsedAreas = pLink->next;
-
- tmp = pLink;
- pLink = pLink->next;
- free(tmp);
- offman->NumUsedAreas--;
- anyUsed = TRUE;
- } else {
- pPrev = pLink;
- pLink = pLink->next;
- }
- }
-
- if(anyUsed) {
- RegionValidate(offman->FreeBoxes, &anyUsed);
- SendCallFreeBoxCallbacks(offman);
- }
-
- return TRUE;
-}
-
-static void
-LinearMoveCBWrapper(FBAreaPtr from, FBAreaPtr to)
-{
- /* this will never get called */
-}
-
-static void
-LinearRemoveCBWrapper(FBAreaPtr area)
-{
- FBManagerPtr offman;
- FBLinearLinkPtr pLink, pLinkPrev = NULL;
- ScreenPtr pScreen = area->pScreen;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- pLink = offman->LinearAreas;
- if(!pLink) return;
-
- while(pLink->area != area) {
- pLinkPrev = pLink;
- pLink = pLink->next;
- if(!pLink) return;
- }
-
- /* give the user the callback it is expecting */
- (*pLink->linear.RemoveLinearCallback)(&(pLink->linear));
-
- if(pLinkPrev)
- pLinkPrev->next = pLink->next;
- else offman->LinearAreas = pLink->next;
-
- free(pLink);
-}
-
-static void
-DumpDebug(FBLinearLinkPtr pLink)
-{
-#ifdef DEBUG
- if (!pLink) ErrorF("MMmm, PLINK IS NULL!\n");
-
- while (pLink) {
- ErrorF(" Offset:%08x, Size:%08x, %s,%s\n",
- pLink->linear.offset,
- pLink->linear.size,
- pLink->free ? "Free" : "Used",
- pLink->area ? "Area" : "Linear");
-
- pLink = pLink->next;
- }
-#endif
-}
-
-static FBLinearPtr
-AllocateLinear(
- FBManagerPtr offman,
- int size,
- int granularity,
- pointer privData
-){
- ScreenPtr pScreen = offman->pScreen;
- FBLinearLinkPtr linear = NULL;
- FBLinearLinkPtr newlink = NULL;
- int offset, end;
-
- if(size <= 0) return NULL;
-
- if (!offman->LinearAreas) return NULL;
-
- linear = offman->LinearAreas;
- while (linear) {
- /* Make sure we get a free area that's not an XY fallback case */
- if (!linear->area && linear->free) {
- offset = linear->linear.offset;
- if (granularity > 1)
- offset = ((offset + granularity - 1) / granularity) * granularity;
- end = offset+size;
- if (end <= (linear->linear.offset + linear->linear.size))
- break;
- }
- linear = linear->next;
- }
- if (!linear)
- return NULL;
-
- /* break left */
- if (offset > linear->linear.offset) {
- newlink = malloc(sizeof(FBLinearLink));
- if (!newlink)
- return NULL;
- newlink->area = NULL;
- newlink->linear.offset = offset;
- newlink->linear.size = linear->linear.size - (offset - linear->linear.offset);
- newlink->free = 1;
- newlink->next = linear->next;
- linear->linear.size -= newlink->linear.size;
- linear->next = newlink;
- linear = newlink;
- }
-
- /* break right */
- if (size < linear->linear.size) {
- newlink = malloc(sizeof(FBLinearLink));
- if (!newlink)
- return NULL;
- newlink->area = NULL;
- newlink->linear.offset = offset + size;
- newlink->linear.size = linear->linear.size - size;
- newlink->free = 1;
- newlink->next = linear->next;
- linear->linear.size = size;
- linear->next = newlink;
- }
-
- /* p = middle block */
- linear->linear.granularity = granularity;
- linear->free = 0;
- linear->linear.pScreen = pScreen;
- linear->linear.MoveLinearCallback = NULL;
- linear->linear.RemoveLinearCallback = NULL;
- linear->linear.devPrivate.ptr = NULL;
-
- DumpDebug(offman->LinearAreas);
-
- return &(linear->linear);
-}
-
-static FBLinearPtr
-localAllocateOffscreenLinear(
- ScreenPtr pScreen,
- int length,
- int gran,
- MoveLinearCallbackProcPtr moveCB,
- RemoveLinearCallbackProcPtr removeCB,
- pointer privData
-){
- FBManagerPtr offman;
- FBLinearLinkPtr link;
- FBAreaPtr area;
- FBLinearPtr linear = NULL;
- BoxPtr extents;
- int w, h, pitch;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
-
- /* Try to allocate from linear memory first...... */
- DebugF("ALLOCATING LINEAR\n");
- if ((linear = AllocateLinear(offman, length, gran, privData)))
- return linear;
-
- DebugF("NOPE, ALLOCATING AREA\n");
-
- if(!(link = malloc(sizeof(FBLinearLink))))
- return NULL;
-
- /* No linear available, so try and pinch some from the XY areas */
- extents = RegionExtents(offman->InitialBoxes);
- pitch = extents->x2 - extents->x1;
-
- if (gran > 1) {
- if (gran > pitch) {
- /* we can't match the specified alignment with XY allocations */
- free(link);
- return NULL;
- }
-
- if (pitch % gran) {
- /* pitch and granularity aren't a perfect match, let's allocate
- * a bit more so we can align later on
- */
- length += gran - 1;
- }
- }
-
- if(length < pitch) { /* special case */
- w = length;
- h = 1;
- } else {
- w = pitch;
- h = (length + pitch - 1) / pitch;
- }
-
- if((area = localAllocateOffscreenArea(pScreen, w, h, gran,
- moveCB ? LinearMoveCBWrapper : NULL,
- removeCB ? LinearRemoveCBWrapper : NULL,
- privData)))
- {
- link->area = area;
- link->free = 0;
- link->next = offman->LinearAreas;
- offman->LinearAreas = link;
- linear = &(link->linear);
- linear->pScreen = pScreen;
- linear->size = h * w;
- linear->offset = (pitch * area->box.y1) + area->box.x1;
- if (gran > 1)
- linear->offset = ((linear->offset + gran - 1) / gran) * gran;
- linear->granularity = gran;
- linear->MoveLinearCallback = moveCB;
- linear->RemoveLinearCallback = removeCB;
- linear->devPrivate.ptr = privData;
- } else
- free(link);
-
- DumpDebug(offman->LinearAreas);
-
- return linear;
-}
-
-
-static void
-localFreeOffscreenLinear(FBLinearPtr linear)
-{
- FBManagerPtr offman;
- FBLinearLinkPtr pLink, pLinkPrev = NULL;
- ScreenPtr pScreen = linear->pScreen;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- pLink = offman->LinearAreas;
- if(!pLink) return;
-
- while(&(pLink->linear) != linear) {
- pLinkPrev = pLink;
- pLink = pLink->next;
- if(!pLink) return;
- }
-
- if(pLink->area) { /* really an XY area */
- DebugF("FREEING AREA\n");
- localFreeOffscreenArea(pLink->area);
- if(pLinkPrev)
- pLinkPrev->next = pLink->next;
- else offman->LinearAreas = pLink->next;
- free(pLink);
- DumpDebug(offman->LinearAreas);
- return;
- }
-
- pLink->free = 1;
-
- if (pLink->next && pLink->next->free) {
- FBLinearLinkPtr p = pLink->next;
- pLink->linear.size += p->linear.size;
- pLink->next = p->next;
- free(p);
- }
-
- if(pLinkPrev) {
- if (pLinkPrev->next && pLinkPrev->next->free && !pLinkPrev->area) {
- FBLinearLinkPtr p = pLinkPrev->next;
- pLinkPrev->linear.size += p->linear.size;
- pLinkPrev->next = p->next;
- free(p);
- }
- }
-
- DebugF("FREEING LINEAR\n");
- DumpDebug(offman->LinearAreas);
-}
-
-
-static Bool
-localResizeOffscreenLinear(FBLinearPtr resize, int length)
-{
- FBManagerPtr offman;
- FBLinearLinkPtr pLink;
- ScreenPtr pScreen = resize->pScreen;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- pLink = offman->LinearAreas;
- if(!pLink) return FALSE;
-
- while(&(pLink->linear) != resize) {
- pLink = pLink->next;
- if(!pLink) return FALSE;
- }
-
- /* This could actually be alot smarter and try to move allocations
- from XY to linear when available. For now if it was XY, we keep
- it XY */
-
- if(pLink->area) { /* really an XY area */
- BoxPtr extents;
- int pitch, w, h;
-
- extents = RegionExtents(offman->InitialBoxes);
- pitch = extents->x2 - extents->x1;
-
- if(length < pitch) { /* special case */
- w = length;
- h = 1;
- } else {
- w = pitch;
- h = (length + pitch - 1) / pitch;
- }
-
- if(localResizeOffscreenArea(pLink->area, w, h)) {
- resize->size = h * w;
- resize->offset = (pitch * pLink->area->box.y1) + pLink->area->box.x1;
- return TRUE;
- }
- } else {
- /* TODO!!!! resize the linear area */
- }
-
- return FALSE;
-}
-
-
-static Bool
-localQueryLargestOffscreenLinear(
- ScreenPtr pScreen,
- int *size,
- int gran,
- int priority
-)
-{
- FBManagerPtr offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- FBLinearLinkPtr pLink;
- FBLinearLinkPtr pLinkRet;
-
- *size = 0;
-
- pLink = offman->LinearAreas;
-
- if (pLink && !pLink->area) {
- pLinkRet = pLink;
- while (pLink) {
- if (pLink->free) {
- if (pLink->linear.size > pLinkRet->linear.size)
- pLinkRet = pLink;
- }
- pLink = pLink->next;
- }
-
- if (pLinkRet->free) {
- *size = pLinkRet->linear.size;
- return TRUE;
- }
- } else {
- int w, h;
-
- if(localQueryLargestOffscreenArea(pScreen, &w, &h, gran,
- FAVOR_WIDTH_THEN_AREA, priority))
- {
- FBManagerPtr offman;
- BoxPtr extents;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- extents = RegionExtents(offman->InitialBoxes);
- if((extents->x2 - extents->x1) == w)
- *size = w * h;
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-
-static FBManagerFuncs xf86FBManFuncs = {
- localAllocateOffscreenArea,
- localFreeOffscreenArea,
- localResizeOffscreenArea,
- localQueryLargestOffscreenArea,
- localRegisterFreeBoxCallback,
- localAllocateOffscreenLinear,
- localFreeOffscreenLinear,
- localResizeOffscreenLinear,
- localQueryLargestOffscreenLinear,
- localPurgeUnlockedOffscreenAreas
- };
-
-
-static Bool
-xf86FBCloseScreen (int i, ScreenPtr pScreen)
-{
- FBLinkPtr pLink, tmp;
- FBLinearLinkPtr pLinearLink, tmp2;
- FBManagerPtr offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
-
- pScreen->CloseScreen = offman->CloseScreen;
-
- pLink = offman->UsedAreas;
- while(pLink) {
- tmp = pLink;
- pLink = pLink->next;
- free(tmp);
- }
-
- pLinearLink = offman->LinearAreas;
- while(pLinearLink) {
- tmp2 = pLinearLink;
- pLinearLink = pLinearLink->next;
- free(tmp2);
- }
-
- RegionDestroy(offman->InitialBoxes);
- RegionDestroy(offman->FreeBoxes);
-
- free(offman->FreeBoxesUpdateCallback);
- free(offman->devPrivates);
- free(offman);
- dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, NULL);
-
- return (*pScreen->CloseScreen) (i, pScreen);
-}
-
-Bool
-xf86InitFBManager(
- ScreenPtr pScreen,
- BoxPtr FullBox
-){
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- RegionRec ScreenRegion;
- RegionRec FullRegion;
- BoxRec ScreenBox;
- Bool ret;
-
- ScreenBox.x1 = 0;
- ScreenBox.y1 = 0;
- ScreenBox.x2 = pScrn->virtualX;
- ScreenBox.y2 = pScrn->virtualY;
-
- if((FullBox->x1 > ScreenBox.x1) || (FullBox->y1 > ScreenBox.y1) ||
- (FullBox->x2 < ScreenBox.x2) || (FullBox->y2 < ScreenBox.y2)) {
- return FALSE;
- }
-
- if (FullBox->y2 < FullBox->y1) return FALSE;
- if (FullBox->x2 < FullBox->x1) return FALSE;
-
- RegionInit(&ScreenRegion, &ScreenBox, 1);
- RegionInit(&FullRegion, FullBox, 1);
-
- RegionSubtract(&FullRegion, &FullRegion, &ScreenRegion);
-
- ret = xf86InitFBManagerRegion(pScreen, &FullRegion);
-
- RegionUninit(&ScreenRegion);
- RegionUninit(&FullRegion);
-
- return ret;
-}
-
-Bool
-xf86InitFBManagerArea(
- ScreenPtr pScreen,
- int PixelArea,
- int Verbosity
-)
-{
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- xRectangle Rect[3];
- RegionPtr pRegion, pScreenRegion;
- int nRect;
- Bool ret = FALSE;
-
- if (PixelArea < (pScrn->displayWidth * pScrn->virtualY))
- return FALSE;
-
- Rect[0].x = Rect[0].y = 0;
- Rect[0].width = pScrn->displayWidth;
- Rect[0].height = PixelArea / pScrn->displayWidth;
- nRect = 1;
-
- /* Add a possible partial scanline */
- if ((Rect[1].height = Rect[1].width = PixelArea % pScrn->displayWidth)) {
- Rect[1].x = 0;
- Rect[1].y = Rect[0].height;
- Rect[1].height = 1;
- nRect++;
- }
-
- /* Factor out virtual resolution */
- pRegion = RegionFromRects(nRect, Rect, 0);
- if (pRegion) {
- if (!RegionNar(pRegion)) {
- Rect[2].x = Rect[2].y = 0;
- Rect[2].width = pScrn->virtualX;
- Rect[2].height = pScrn->virtualY;
-
- pScreenRegion = RegionFromRects(1, &Rect[2], 0);
- if (pScreenRegion) {
- if (!RegionNar(pScreenRegion)) {
- RegionSubtract(pRegion, pRegion, pScreenRegion);
-
- ret = xf86InitFBManagerRegion(pScreen, pRegion);
-
- if (ret && xf86GetVerbosity() >= Verbosity) {
- int scrnIndex = pScrn->scrnIndex;
-
- xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
- "Largest offscreen areas (with overlaps):\n");
-
- if (Rect[2].width < Rect[0].width) {
- xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
- "\t%d x %d rectangle at %d,0\n",
- Rect[0].width - Rect[2].width,
- Rect[0].height,
- Rect[2].width);
- }
- if (Rect[2].width < Rect[1].width) {
- xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
- "\t%d x %d rectangle at %d,0\n",
- Rect[1].width - Rect[2].width,
- Rect[0].height + Rect[1].height,
- Rect[2].width);
- }
- if (Rect[2].height < Rect[0].height) {
- xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
- "\t%d x %d rectangle at 0,%d\n",
- Rect[0].width,
- Rect[0].height - Rect[2].height,
- Rect[2].height);
- }
- if (Rect[1].height) {
- xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
- "\t%d x %d rectangle at 0,%d\n",
- Rect[1].width,
- Rect[0].height - Rect[2].height +
- Rect[1].height,
- Rect[2].height);
- }
- }
- }
-
- RegionDestroy(pScreenRegion);
- }
- }
-
- RegionDestroy(pRegion);
- }
-
- return ret;
-}
-
-Bool
-xf86InitFBManagerRegion(
- ScreenPtr pScreen,
- RegionPtr FullRegion
-){
- FBManagerPtr offman;
-
- if(RegionNil(FullRegion))
- return FALSE;
-
- if (!dixRegisterPrivateKey(&xf86FBScreenKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
- return FALSE;
-
- offman = malloc(sizeof(FBManager));
- if(!offman) return FALSE;
-
- dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, offman);
-
- offman->CloseScreen = pScreen->CloseScreen;
- pScreen->CloseScreen = xf86FBCloseScreen;
-
- offman->InitialBoxes = RegionCreate(NULL, 1);
- offman->FreeBoxes = RegionCreate(NULL, 1);
-
- RegionCopy(offman->InitialBoxes, FullRegion);
- RegionCopy(offman->FreeBoxes, FullRegion);
-
- offman->pScreen = pScreen;
- offman->UsedAreas = NULL;
- offman->LinearAreas = NULL;
- offman->NumUsedAreas = 0;
- offman->NumCallbacks = 0;
- offman->FreeBoxesUpdateCallback = NULL;
- offman->devPrivates = NULL;
-
- return TRUE;
-}
-
-Bool
-xf86InitFBManagerLinear(
- ScreenPtr pScreen,
- int offset,
- int size
-){
- FBManagerPtr offman;
- FBLinearLinkPtr link;
- FBLinearPtr linear;
-
- if (size <= 0)
- return FALSE;
-
- /* we expect people to have called the Area setup first for pixmap cache */
- if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBScreenKey))
- return FALSE;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- offman->LinearAreas = malloc(sizeof(FBLinearLink));
- if (!offman->LinearAreas)
- return FALSE;
-
- link = offman->LinearAreas;
- link->area = NULL;
- link->next = NULL;
- link->free = 1;
- linear = &(link->linear);
- linear->pScreen = pScreen;
- linear->size = size;
- linear->offset = offset;
- linear->granularity = 0;
- linear->MoveLinearCallback = NULL;
- linear->RemoveLinearCallback = NULL;
- linear->devPrivate.ptr = NULL;
-
- return TRUE;
-}
-
-
-/* This is an implementation specific function and should
- disappear after the next release. People should use the
- real linear functions instead */
-
-FBAreaPtr
-xf86AllocateLinearOffscreenArea (
- ScreenPtr pScreen,
- int length,
- int gran,
- MoveAreaCallbackProcPtr moveCB,
- RemoveAreaCallbackProcPtr removeCB,
- pointer privData
-){
- FBManagerFuncsPtr funcs;
- FBManagerPtr offman;
- BoxPtr extents;
- int w, h;
-
- if(xf86FBManagerKey == NULL)
- return NULL;
- if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBManagerKey)))
- return NULL;
-
- offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
- xf86FBScreenKey);
- extents = RegionExtents(offman->InitialBoxes);
- w = extents->x2 - extents->x1;
-
- if (gran > 1) {
- if (gran > w)
- return NULL;
-
- if (w % gran)
- length += gran - 1;
- }
-
- if(length <= w) { /* special case */
- h = 1;
- w = length;
- } else {
- h = (length + w - 1) / w;
- }
-
- return (*funcs->AllocateOffscreenArea)(
- pScreen, w, h, gran, moveCB, removeCB, privData);
-}
+ +/* + * Copyright (c) 1998-2001 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include "misc.h" +#include "xf86.h" + +#include <X11/X.h> +#include "scrnintstr.h" +#include "regionstr.h" +#include "xf86fbman.h" + +/* +#define DEBUG +*/ + +static DevPrivateKeyRec xf86FBManagerKeyRec; +static DevPrivateKey xf86FBManagerKey; + +Bool +xf86RegisterOffscreenManager(ScreenPtr pScreen, FBManagerFuncsPtr funcs) +{ + + xf86FBManagerKey = &xf86FBManagerKeyRec; + + if (!dixRegisterPrivateKey(&xf86FBManagerKeyRec, PRIVATE_SCREEN, 0)) + return FALSE; + + dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs); + + return TRUE; +} + +Bool +xf86FBManagerRunning(ScreenPtr pScreen) +{ + if (xf86FBManagerKey == NULL) + return FALSE; + + if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey)) + return FALSE; + + return TRUE; +} + +Bool +xf86RegisterFreeBoxCallback(ScreenPtr pScreen, + FreeBoxCallbackProcPtr FreeBoxCallback, + pointer devPriv) +{ + FBManagerFuncsPtr funcs; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->RegisterFreeBoxCallback) (pScreen, FreeBoxCallback, + devPriv); +} + +FBAreaPtr +xf86AllocateOffscreenArea(ScreenPtr pScreen, + int w, int h, + int gran, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, pointer privData) +{ + FBManagerFuncsPtr funcs; + + if (xf86FBManagerKey == NULL) + return NULL; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return NULL; + + return (*funcs->AllocateOffscreenArea) (pScreen, w, h, gran, moveCB, + removeCB, privData); +} + +FBLinearPtr +xf86AllocateOffscreenLinear(ScreenPtr pScreen, + int length, + int gran, + MoveLinearCallbackProcPtr moveCB, + RemoveLinearCallbackProcPtr removeCB, + pointer privData) +{ + FBManagerFuncsPtr funcs; + + if (xf86FBManagerKey == NULL) + return NULL; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return NULL; + + return (*funcs->AllocateOffscreenLinear) (pScreen, length, gran, moveCB, + removeCB, privData); +} + +void +xf86FreeOffscreenArea(FBAreaPtr area) +{ + FBManagerFuncsPtr funcs; + + if (!area) + return; + + if (xf86FBManagerKey == NULL) + return; + if (! + (funcs = + (FBManagerFuncsPtr) dixLookupPrivate(&area->pScreen->devPrivates, + xf86FBManagerKey))) + return; + + (*funcs->FreeOffscreenArea) (area); + + return; +} + +void +xf86FreeOffscreenLinear(FBLinearPtr linear) +{ + FBManagerFuncsPtr funcs; + + if (!linear) + return; + + if (xf86FBManagerKey == NULL) + return; + if (! + (funcs = + (FBManagerFuncsPtr) dixLookupPrivate(&linear->pScreen->devPrivates, + xf86FBManagerKey))) + return; + + (*funcs->FreeOffscreenLinear) (linear); + + return; +} + +Bool +xf86ResizeOffscreenArea(FBAreaPtr resize, int w, int h) +{ + FBManagerFuncsPtr funcs; + + if (!resize) + return FALSE; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (! + (funcs = + (FBManagerFuncsPtr) dixLookupPrivate(&resize->pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->ResizeOffscreenArea) (resize, w, h); +} + +Bool +xf86ResizeOffscreenLinear(FBLinearPtr resize, int size) +{ + FBManagerFuncsPtr funcs; + + if (!resize) + return FALSE; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (! + (funcs = + (FBManagerFuncsPtr) dixLookupPrivate(&resize->pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->ResizeOffscreenLinear) (resize, size); +} + +Bool +xf86QueryLargestOffscreenArea(ScreenPtr pScreen, + int *w, int *h, + int gran, int preferences, int severity) +{ + FBManagerFuncsPtr funcs; + + *w = 0; + *h = 0; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->QueryLargestOffscreenArea) (pScreen, w, h, gran, + preferences, severity); +} + +Bool +xf86QueryLargestOffscreenLinear(ScreenPtr pScreen, + int *size, int gran, int severity) +{ + FBManagerFuncsPtr funcs; + + *size = 0; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->QueryLargestOffscreenLinear) (pScreen, size, gran, + severity); +} + +Bool +xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen) +{ + FBManagerFuncsPtr funcs; + + if (xf86FBManagerKey == NULL) + return FALSE; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return FALSE; + + return (*funcs->PurgeOffscreenAreas) (pScreen); +} + +/************************************************************\ + + Below is a specific implementation of an offscreen manager. + +\************************************************************/ + +static DevPrivateKeyRec xf86FBScreenKeyRec; + +#define xf86FBScreenKey (&xf86FBScreenKeyRec) + +typedef struct _FBLink { + FBArea area; + struct _FBLink *next; +} FBLink, *FBLinkPtr; + +typedef struct _FBLinearLink { + FBLinear linear; + int free; /* need to add free here as FBLinear is publicly accessible */ + FBAreaPtr area; /* only used if allocation came from XY area */ + struct _FBLinearLink *next; +} FBLinearLink, *FBLinearLinkPtr; + +typedef struct { + ScreenPtr pScreen; + RegionPtr InitialBoxes; + RegionPtr FreeBoxes; + FBLinkPtr UsedAreas; + int NumUsedAreas; + FBLinearLinkPtr LinearAreas; + CloseScreenProcPtr CloseScreen; + int NumCallbacks; + FreeBoxCallbackProcPtr *FreeBoxesUpdateCallback; + DevUnion *devPrivates; +} FBManager, *FBManagerPtr; + +static void +SendCallFreeBoxCallbacks(FBManagerPtr offman) +{ + int i = offman->NumCallbacks; + + while (i--) { + (*offman->FreeBoxesUpdateCallback[i]) (offman->pScreen, + offman->FreeBoxes, + offman->devPrivates[i].ptr); + } +} + +static Bool +localRegisterFreeBoxCallback(ScreenPtr pScreen, + FreeBoxCallbackProcPtr FreeBoxCallback, + pointer devPriv) +{ + FBManagerPtr offman; + FreeBoxCallbackProcPtr *newCallbacks; + DevUnion *newPrivates; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + newCallbacks = realloc(offman->FreeBoxesUpdateCallback, + sizeof(FreeBoxCallbackProcPtr) * + (offman->NumCallbacks + 1)); + + newPrivates = realloc(offman->devPrivates, + sizeof(DevUnion) * (offman->NumCallbacks + 1)); + + if (!newCallbacks || !newPrivates) + return FALSE; + + offman->FreeBoxesUpdateCallback = newCallbacks; + offman->devPrivates = newPrivates; + + offman->FreeBoxesUpdateCallback[offman->NumCallbacks] = FreeBoxCallback; + offman->devPrivates[offman->NumCallbacks].ptr = devPriv; + offman->NumCallbacks++; + + SendCallFreeBoxCallbacks(offman); + + return TRUE; +} + +static FBAreaPtr +AllocateArea(FBManagerPtr offman, + int w, int h, + int granularity, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, pointer privData) +{ + ScreenPtr pScreen = offman->pScreen; + FBLinkPtr link = NULL; + FBAreaPtr area = NULL; + RegionRec NewReg; + int i, x = 0, num; + BoxPtr boxp; + + if (granularity <= 1) + granularity = 0; + + boxp = RegionRects(offman->FreeBoxes); + num = RegionNumRects(offman->FreeBoxes); + + /* look through the free boxes */ + for (i = 0; i < num; i++, boxp++) { + x = boxp->x1; + if (granularity > 1) + x = ((x + granularity - 1) / granularity) * granularity; + + if (((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) + continue; + + link = malloc(sizeof(FBLink)); + if (!link) + return NULL; + + area = &(link->area); + link->next = offman->UsedAreas; + offman->UsedAreas = link; + offman->NumUsedAreas++; + break; + } + + /* try to boot a removeable one out if we are not expendable ourselves */ + if (!area && !removeCB) { + link = offman->UsedAreas; + + while (link) { + if (!link->area.RemoveAreaCallback) { + link = link->next; + continue; + } + + boxp = &(link->area.box); + x = boxp->x1; + if (granularity > 1) + x = ((x + granularity - 1) / granularity) * granularity; + + if (((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) { + link = link->next; + continue; + } + + /* bye, bye */ + (*link->area.RemoveAreaCallback) (&link->area); + RegionInit(&NewReg, &(link->area.box), 1); + RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &NewReg); + RegionUninit(&NewReg); + + area = &(link->area); + break; + } + } + + if (area) { + area->pScreen = pScreen; + area->granularity = granularity; + area->box.x1 = x; + area->box.x2 = x + w; + area->box.y1 = boxp->y1; + area->box.y2 = boxp->y1 + h; + area->MoveAreaCallback = moveCB; + area->RemoveAreaCallback = removeCB; + area->devPrivate.ptr = privData; + + RegionInit(&NewReg, &(area->box), 1); + RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &NewReg); + RegionUninit(&NewReg); + } + + return area; +} + +static FBAreaPtr +localAllocateOffscreenArea(ScreenPtr pScreen, + int w, int h, + int gran, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, pointer privData) +{ + FBManagerPtr offman; + FBAreaPtr area = NULL; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + if ((area = AllocateArea(offman, w, h, gran, moveCB, removeCB, privData))) + SendCallFreeBoxCallbacks(offman); + + return area; +} + +static void +localFreeOffscreenArea(FBAreaPtr area) +{ + FBManagerPtr offman; + FBLinkPtr pLink, pLinkPrev = NULL; + RegionRec FreedRegion; + ScreenPtr pScreen; + + pScreen = area->pScreen; + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + pLink = offman->UsedAreas; + if (!pLink) + return; + + while (&(pLink->area) != area) { + pLinkPrev = pLink; + pLink = pLink->next; + if (!pLink) + return; + } + + /* put the area back into the pool */ + RegionInit(&FreedRegion, &(pLink->area.box), 1); + RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedRegion); + RegionUninit(&FreedRegion); + + if (pLinkPrev) + pLinkPrev->next = pLink->next; + else + offman->UsedAreas = pLink->next; + + free(pLink); + offman->NumUsedAreas--; + + SendCallFreeBoxCallbacks(offman); +} + +static Bool +localResizeOffscreenArea(FBAreaPtr resize, int w, int h) +{ + FBManagerPtr offman; + ScreenPtr pScreen; + BoxRec OrigArea; + RegionRec FreedReg; + FBAreaPtr area = NULL; + FBLinkPtr pLink, newLink, pLinkPrev = NULL; + + pScreen = resize->pScreen; + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + /* find this link */ + if (!(pLink = offman->UsedAreas)) + return FALSE; + + while (&(pLink->area) != resize) { + pLinkPrev = pLink; + pLink = pLink->next; + if (!pLink) + return FALSE; + } + + OrigArea.x1 = resize->box.x1; + OrigArea.x2 = resize->box.x2; + OrigArea.y1 = resize->box.y1; + OrigArea.y2 = resize->box.y2; + + /* if it's smaller, this is easy */ + + if ((w <= (resize->box.x2 - resize->box.x1)) && + (h <= (resize->box.y2 - resize->box.y1))) { + RegionRec NewReg; + + resize->box.x2 = resize->box.x1 + w; + resize->box.y2 = resize->box.y1 + h; + + if ((resize->box.y2 == OrigArea.y2) && (resize->box.x2 == OrigArea.x2)) + return TRUE; + + RegionInit(&FreedReg, &OrigArea, 1); + RegionInit(&NewReg, &(resize->box), 1); + RegionSubtract(&FreedReg, &FreedReg, &NewReg); + RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); + RegionUninit(&FreedReg); + RegionUninit(&NewReg); + + SendCallFreeBoxCallbacks(offman); + + return TRUE; + } + + /* otherwise we remove the old region */ + + RegionInit(&FreedReg, &OrigArea, 1); + RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); + + /* remove the old link */ + if (pLinkPrev) + pLinkPrev->next = pLink->next; + else + offman->UsedAreas = pLink->next; + + /* and try to add a new one */ + + if ((area = AllocateArea(offman, w, h, resize->granularity, + resize->MoveAreaCallback, + resize->RemoveAreaCallback, + resize->devPrivate.ptr))) { + + /* copy data over to our link and replace the new with old */ + memcpy(resize, area, sizeof(FBArea)); + + pLinkPrev = NULL; + newLink = offman->UsedAreas; + + while (&(newLink->area) != area) { + pLinkPrev = newLink; + newLink = newLink->next; + } + + if (pLinkPrev) + pLinkPrev->next = newLink->next; + else + offman->UsedAreas = newLink->next; + + pLink->next = offman->UsedAreas; + offman->UsedAreas = pLink; + + free(newLink); + + /* AllocateArea added one but we really only exchanged one */ + offman->NumUsedAreas--; + } + else { + /* reinstate the old region */ + RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); + RegionUninit(&FreedReg); + + pLink->next = offman->UsedAreas; + offman->UsedAreas = pLink; + return FALSE; + } + + RegionUninit(&FreedReg); + + SendCallFreeBoxCallbacks(offman); + + return TRUE; +} + +static Bool +localQueryLargestOffscreenArea(ScreenPtr pScreen, + int *width, int *height, + int granularity, int preferences, int severity) +{ + FBManagerPtr offman; + RegionPtr newRegion = NULL; + BoxPtr pbox; + int nbox; + int x, w, h, area, oldArea; + + *width = *height = oldArea = 0; + + if (granularity <= 1) + granularity = 0; + + if ((preferences < 0) || (preferences > 3)) + return FALSE; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + if (severity < 0) + severity = 0; + if (severity > 2) + severity = 2; + + switch (severity) { + case 2: + if (offman->NumUsedAreas) { + FBLinkPtr pLink; + RegionRec tmpRegion; + + newRegion = RegionCreate(NULL, 1); + RegionCopy(newRegion, offman->InitialBoxes); + pLink = offman->UsedAreas; + + while (pLink) { + if (!pLink->area.RemoveAreaCallback) { + RegionInit(&tmpRegion, &(pLink->area.box), 1); + RegionSubtract(newRegion, newRegion, &tmpRegion); + RegionUninit(&tmpRegion); + } + pLink = pLink->next; + } + + nbox = RegionNumRects(newRegion); + pbox = RegionRects(newRegion); + break; + } + case 1: + if (offman->NumUsedAreas) { + FBLinkPtr pLink; + RegionRec tmpRegion; + + newRegion = RegionCreate(NULL, 1); + RegionCopy(newRegion, offman->FreeBoxes); + pLink = offman->UsedAreas; + + while (pLink) { + if (pLink->area.RemoveAreaCallback) { + RegionInit(&tmpRegion, &(pLink->area.box), 1); + RegionAppend(newRegion, &tmpRegion); + RegionUninit(&tmpRegion); + } + pLink = pLink->next; + } + + nbox = RegionNumRects(newRegion); + pbox = RegionRects(newRegion); + break; + } + default: + nbox = RegionNumRects(offman->FreeBoxes); + pbox = RegionRects(offman->FreeBoxes); + break; + } + + while (nbox--) { + x = pbox->x1; + if (granularity > 1) + x = ((x + granularity - 1) / granularity) * granularity; + + w = pbox->x2 - x; + h = pbox->y2 - pbox->y1; + area = w * h; + + if (w > 0) { + Bool gotIt = FALSE; + + switch (preferences) { + case FAVOR_AREA_THEN_WIDTH: + if ((area > oldArea) || ((area == oldArea) && (w > *width))) + gotIt = TRUE; + break; + case FAVOR_AREA_THEN_HEIGHT: + if ((area > oldArea) || ((area == oldArea) && (h > *height))) + gotIt = TRUE; + break; + case FAVOR_WIDTH_THEN_AREA: + if ((w > *width) || ((w == *width) && (area > oldArea))) + gotIt = TRUE; + break; + case FAVOR_HEIGHT_THEN_AREA: + if ((h > *height) || ((h == *height) && (area > oldArea))) + gotIt = TRUE; + break; + } + if (gotIt) { + *width = w; + *height = h; + oldArea = area; + } + } + pbox++; + } + + if (newRegion) + RegionDestroy(newRegion); + + return TRUE; +} + +static Bool +localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen) +{ + FBManagerPtr offman; + FBLinkPtr pLink, tmp, pPrev = NULL; + RegionRec FreedRegion; + Bool anyUsed = FALSE; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + pLink = offman->UsedAreas; + if (!pLink) + return TRUE; + + while (pLink) { + if (pLink->area.RemoveAreaCallback) { + (*pLink->area.RemoveAreaCallback) (&pLink->area); + + RegionInit(&FreedRegion, &(pLink->area.box), 1); + RegionAppend(offman->FreeBoxes, &FreedRegion); + RegionUninit(&FreedRegion); + + if (pPrev) + pPrev->next = pLink->next; + else + offman->UsedAreas = pLink->next; + + tmp = pLink; + pLink = pLink->next; + free(tmp); + offman->NumUsedAreas--; + anyUsed = TRUE; + } + else { + pPrev = pLink; + pLink = pLink->next; + } + } + + if (anyUsed) { + RegionValidate(offman->FreeBoxes, &anyUsed); + SendCallFreeBoxCallbacks(offman); + } + + return TRUE; +} + +static void +LinearMoveCBWrapper(FBAreaPtr from, FBAreaPtr to) +{ + /* this will never get called */ +} + +static void +LinearRemoveCBWrapper(FBAreaPtr area) +{ + FBManagerPtr offman; + FBLinearLinkPtr pLink, pLinkPrev = NULL; + ScreenPtr pScreen = area->pScreen; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + pLink = offman->LinearAreas; + if (!pLink) + return; + + while (pLink->area != area) { + pLinkPrev = pLink; + pLink = pLink->next; + if (!pLink) + return; + } + + /* give the user the callback it is expecting */ + (*pLink->linear.RemoveLinearCallback) (&(pLink->linear)); + + if (pLinkPrev) + pLinkPrev->next = pLink->next; + else + offman->LinearAreas = pLink->next; + + free(pLink); +} + +static void +DumpDebug(FBLinearLinkPtr pLink) +{ +#ifdef DEBUG + if (!pLink) + ErrorF("MMmm, PLINK IS NULL!\n"); + + while (pLink) { + ErrorF(" Offset:%08x, Size:%08x, %s,%s\n", + pLink->linear.offset, + pLink->linear.size, + pLink->free ? "Free" : "Used", pLink->area ? "Area" : "Linear"); + + pLink = pLink->next; + } +#endif +} + +static FBLinearPtr +AllocateLinear(FBManagerPtr offman, int size, int granularity, pointer privData) +{ + ScreenPtr pScreen = offman->pScreen; + FBLinearLinkPtr linear = NULL; + FBLinearLinkPtr newlink = NULL; + int offset, end; + + if (size <= 0) + return NULL; + + if (!offman->LinearAreas) + return NULL; + + linear = offman->LinearAreas; + while (linear) { + /* Make sure we get a free area that's not an XY fallback case */ + if (!linear->area && linear->free) { + offset = linear->linear.offset; + if (granularity > 1) + offset = + ((offset + granularity - 1) / granularity) * granularity; + end = offset + size; + if (end <= (linear->linear.offset + linear->linear.size)) + break; + } + linear = linear->next; + } + if (!linear) + return NULL; + + /* break left */ + if (offset > linear->linear.offset) { + newlink = malloc(sizeof(FBLinearLink)); + if (!newlink) + return NULL; + newlink->area = NULL; + newlink->linear.offset = offset; + newlink->linear.size = + linear->linear.size - (offset - linear->linear.offset); + newlink->free = 1; + newlink->next = linear->next; + linear->linear.size -= newlink->linear.size; + linear->next = newlink; + linear = newlink; + } + + /* break right */ + if (size < linear->linear.size) { + newlink = malloc(sizeof(FBLinearLink)); + if (!newlink) + return NULL; + newlink->area = NULL; + newlink->linear.offset = offset + size; + newlink->linear.size = linear->linear.size - size; + newlink->free = 1; + newlink->next = linear->next; + linear->linear.size = size; + linear->next = newlink; + } + + /* p = middle block */ + linear->linear.granularity = granularity; + linear->free = 0; + linear->linear.pScreen = pScreen; + linear->linear.MoveLinearCallback = NULL; + linear->linear.RemoveLinearCallback = NULL; + linear->linear.devPrivate.ptr = NULL; + + DumpDebug(offman->LinearAreas); + + return &(linear->linear); +} + +static FBLinearPtr +localAllocateOffscreenLinear(ScreenPtr pScreen, + int length, + int gran, + MoveLinearCallbackProcPtr moveCB, + RemoveLinearCallbackProcPtr removeCB, + pointer privData) +{ + FBManagerPtr offman; + FBLinearLinkPtr link; + FBAreaPtr area; + FBLinearPtr linear = NULL; + BoxPtr extents; + int w, h, pitch; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + + /* Try to allocate from linear memory first...... */ + DebugF("ALLOCATING LINEAR\n"); + if ((linear = AllocateLinear(offman, length, gran, privData))) + return linear; + + DebugF("NOPE, ALLOCATING AREA\n"); + + if (!(link = malloc(sizeof(FBLinearLink)))) + return NULL; + + /* No linear available, so try and pinch some from the XY areas */ + extents = RegionExtents(offman->InitialBoxes); + pitch = extents->x2 - extents->x1; + + if (gran > 1) { + if (gran > pitch) { + /* we can't match the specified alignment with XY allocations */ + free(link); + return NULL; + } + + if (pitch % gran) { + /* pitch and granularity aren't a perfect match, let's allocate + * a bit more so we can align later on + */ + length += gran - 1; + } + } + + if (length < pitch) { /* special case */ + w = length; + h = 1; + } + else { + w = pitch; + h = (length + pitch - 1) / pitch; + } + + if ((area = localAllocateOffscreenArea(pScreen, w, h, gran, + moveCB ? LinearMoveCBWrapper : NULL, + removeCB ? LinearRemoveCBWrapper : + NULL, privData))) { + link->area = area; + link->free = 0; + link->next = offman->LinearAreas; + offman->LinearAreas = link; + linear = &(link->linear); + linear->pScreen = pScreen; + linear->size = h * w; + linear->offset = (pitch * area->box.y1) + area->box.x1; + if (gran > 1) + linear->offset = ((linear->offset + gran - 1) / gran) * gran; + linear->granularity = gran; + linear->MoveLinearCallback = moveCB; + linear->RemoveLinearCallback = removeCB; + linear->devPrivate.ptr = privData; + } + else + free(link); + + DumpDebug(offman->LinearAreas); + + return linear; +} + +static void +localFreeOffscreenLinear(FBLinearPtr linear) +{ + FBManagerPtr offman; + FBLinearLinkPtr pLink, pLinkPrev = NULL; + ScreenPtr pScreen = linear->pScreen; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + pLink = offman->LinearAreas; + if (!pLink) + return; + + while (&(pLink->linear) != linear) { + pLinkPrev = pLink; + pLink = pLink->next; + if (!pLink) + return; + } + + if (pLink->area) { /* really an XY area */ + DebugF("FREEING AREA\n"); + localFreeOffscreenArea(pLink->area); + if (pLinkPrev) + pLinkPrev->next = pLink->next; + else + offman->LinearAreas = pLink->next; + free(pLink); + DumpDebug(offman->LinearAreas); + return; + } + + pLink->free = 1; + + if (pLink->next && pLink->next->free) { + FBLinearLinkPtr p = pLink->next; + + pLink->linear.size += p->linear.size; + pLink->next = p->next; + free(p); + } + + if (pLinkPrev) { + if (pLinkPrev->next && pLinkPrev->next->free && !pLinkPrev->area) { + FBLinearLinkPtr p = pLinkPrev->next; + + pLinkPrev->linear.size += p->linear.size; + pLinkPrev->next = p->next; + free(p); + } + } + + DebugF("FREEING LINEAR\n"); + DumpDebug(offman->LinearAreas); +} + +static Bool +localResizeOffscreenLinear(FBLinearPtr resize, int length) +{ + FBManagerPtr offman; + FBLinearLinkPtr pLink; + ScreenPtr pScreen = resize->pScreen; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + pLink = offman->LinearAreas; + if (!pLink) + return FALSE; + + while (&(pLink->linear) != resize) { + pLink = pLink->next; + if (!pLink) + return FALSE; + } + + /* This could actually be alot smarter and try to move allocations + from XY to linear when available. For now if it was XY, we keep + it XY */ + + if (pLink->area) { /* really an XY area */ + BoxPtr extents; + int pitch, w, h; + + extents = RegionExtents(offman->InitialBoxes); + pitch = extents->x2 - extents->x1; + + if (length < pitch) { /* special case */ + w = length; + h = 1; + } + else { + w = pitch; + h = (length + pitch - 1) / pitch; + } + + if (localResizeOffscreenArea(pLink->area, w, h)) { + resize->size = h * w; + resize->offset = + (pitch * pLink->area->box.y1) + pLink->area->box.x1; + return TRUE; + } + } + else { + /* TODO!!!! resize the linear area */ + } + + return FALSE; +} + +static Bool +localQueryLargestOffscreenLinear(ScreenPtr pScreen, + int *size, int gran, int priority) +{ + FBManagerPtr offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + FBLinearLinkPtr pLink; + FBLinearLinkPtr pLinkRet; + + *size = 0; + + pLink = offman->LinearAreas; + + if (pLink && !pLink->area) { + pLinkRet = pLink; + while (pLink) { + if (pLink->free) { + if (pLink->linear.size > pLinkRet->linear.size) + pLinkRet = pLink; + } + pLink = pLink->next; + } + + if (pLinkRet->free) { + *size = pLinkRet->linear.size; + return TRUE; + } + } + else { + int w, h; + + if (localQueryLargestOffscreenArea(pScreen, &w, &h, gran, + FAVOR_WIDTH_THEN_AREA, priority)) { + FBManagerPtr offman; + BoxPtr extents; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + extents = RegionExtents(offman->InitialBoxes); + if ((extents->x2 - extents->x1) == w) + *size = w * h; + return TRUE; + } + } + + return FALSE; +} + +static FBManagerFuncs xf86FBManFuncs = { + localAllocateOffscreenArea, + localFreeOffscreenArea, + localResizeOffscreenArea, + localQueryLargestOffscreenArea, + localRegisterFreeBoxCallback, + localAllocateOffscreenLinear, + localFreeOffscreenLinear, + localResizeOffscreenLinear, + localQueryLargestOffscreenLinear, + localPurgeUnlockedOffscreenAreas +}; + +static Bool +xf86FBCloseScreen(int i, ScreenPtr pScreen) +{ + FBLinkPtr pLink, tmp; + FBLinearLinkPtr pLinearLink, tmp2; + FBManagerPtr offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + + pScreen->CloseScreen = offman->CloseScreen; + + pLink = offman->UsedAreas; + while (pLink) { + tmp = pLink; + pLink = pLink->next; + free(tmp); + } + + pLinearLink = offman->LinearAreas; + while (pLinearLink) { + tmp2 = pLinearLink; + pLinearLink = pLinearLink->next; + free(tmp2); + } + + RegionDestroy(offman->InitialBoxes); + RegionDestroy(offman->FreeBoxes); + + free(offman->FreeBoxesUpdateCallback); + free(offman->devPrivates); + free(offman); + dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, NULL); + + return (*pScreen->CloseScreen) (i, pScreen); +} + +Bool +xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + RegionRec ScreenRegion; + RegionRec FullRegion; + BoxRec ScreenBox; + Bool ret; + + ScreenBox.x1 = 0; + ScreenBox.y1 = 0; + ScreenBox.x2 = pScrn->virtualX; + ScreenBox.y2 = pScrn->virtualY; + + if ((FullBox->x1 > ScreenBox.x1) || (FullBox->y1 > ScreenBox.y1) || + (FullBox->x2 < ScreenBox.x2) || (FullBox->y2 < ScreenBox.y2)) { + return FALSE; + } + + if (FullBox->y2 < FullBox->y1) + return FALSE; + if (FullBox->x2 < FullBox->x1) + return FALSE; + + RegionInit(&ScreenRegion, &ScreenBox, 1); + RegionInit(&FullRegion, FullBox, 1); + + RegionSubtract(&FullRegion, &FullRegion, &ScreenRegion); + + ret = xf86InitFBManagerRegion(pScreen, &FullRegion); + + RegionUninit(&ScreenRegion); + RegionUninit(&FullRegion); + + return ret; +} + +Bool +xf86InitFBManagerArea(ScreenPtr pScreen, int PixelArea, int Verbosity) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xRectangle Rect[3]; + RegionPtr pRegion, pScreenRegion; + int nRect; + Bool ret = FALSE; + + if (PixelArea < (pScrn->displayWidth * pScrn->virtualY)) + return FALSE; + + Rect[0].x = Rect[0].y = 0; + Rect[0].width = pScrn->displayWidth; + Rect[0].height = PixelArea / pScrn->displayWidth; + nRect = 1; + + /* Add a possible partial scanline */ + if ((Rect[1].height = Rect[1].width = PixelArea % pScrn->displayWidth)) { + Rect[1].x = 0; + Rect[1].y = Rect[0].height; + Rect[1].height = 1; + nRect++; + } + + /* Factor out virtual resolution */ + pRegion = RegionFromRects(nRect, Rect, 0); + if (pRegion) { + if (!RegionNar(pRegion)) { + Rect[2].x = Rect[2].y = 0; + Rect[2].width = pScrn->virtualX; + Rect[2].height = pScrn->virtualY; + + pScreenRegion = RegionFromRects(1, &Rect[2], 0); + if (pScreenRegion) { + if (!RegionNar(pScreenRegion)) { + RegionSubtract(pRegion, pRegion, pScreenRegion); + + ret = xf86InitFBManagerRegion(pScreen, pRegion); + + if (ret && xf86GetVerbosity() >= Verbosity) { + int scrnIndex = pScrn->scrnIndex; + + xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, + "Largest offscreen areas (with overlaps):\n"); + + if (Rect[2].width < Rect[0].width) { + xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, + "\t%d x %d rectangle at %d,0\n", + Rect[0].width - Rect[2].width, + Rect[0].height, Rect[2].width); + } + if (Rect[2].width < Rect[1].width) { + xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, + "\t%d x %d rectangle at %d,0\n", + Rect[1].width - Rect[2].width, + Rect[0].height + Rect[1].height, + Rect[2].width); + } + if (Rect[2].height < Rect[0].height) { + xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, + "\t%d x %d rectangle at 0,%d\n", + Rect[0].width, + Rect[0].height - Rect[2].height, + Rect[2].height); + } + if (Rect[1].height) { + xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, + "\t%d x %d rectangle at 0,%d\n", + Rect[1].width, + Rect[0].height - Rect[2].height + + Rect[1].height, Rect[2].height); + } + } + } + + RegionDestroy(pScreenRegion); + } + } + + RegionDestroy(pRegion); + } + + return ret; +} + +Bool +xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr FullRegion) +{ + FBManagerPtr offman; + + if (RegionNil(FullRegion)) + return FALSE; + + if (!dixRegisterPrivateKey(&xf86FBScreenKeyRec, PRIVATE_SCREEN, 0)) + return FALSE; + + if (!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs)) + return FALSE; + + offman = malloc(sizeof(FBManager)); + if (!offman) + return FALSE; + + dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, offman); + + offman->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = xf86FBCloseScreen; + + offman->InitialBoxes = RegionCreate(NULL, 1); + offman->FreeBoxes = RegionCreate(NULL, 1); + + RegionCopy(offman->InitialBoxes, FullRegion); + RegionCopy(offman->FreeBoxes, FullRegion); + + offman->pScreen = pScreen; + offman->UsedAreas = NULL; + offman->LinearAreas = NULL; + offman->NumUsedAreas = 0; + offman->NumCallbacks = 0; + offman->FreeBoxesUpdateCallback = NULL; + offman->devPrivates = NULL; + + return TRUE; +} + +Bool +xf86InitFBManagerLinear(ScreenPtr pScreen, int offset, int size) +{ + FBManagerPtr offman; + FBLinearLinkPtr link; + FBLinearPtr linear; + + if (size <= 0) + return FALSE; + + /* we expect people to have called the Area setup first for pixmap cache */ + if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBScreenKey)) + return FALSE; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + offman->LinearAreas = malloc(sizeof(FBLinearLink)); + if (!offman->LinearAreas) + return FALSE; + + link = offman->LinearAreas; + link->area = NULL; + link->next = NULL; + link->free = 1; + linear = &(link->linear); + linear->pScreen = pScreen; + linear->size = size; + linear->offset = offset; + linear->granularity = 0; + linear->MoveLinearCallback = NULL; + linear->RemoveLinearCallback = NULL; + linear->devPrivate.ptr = NULL; + + return TRUE; +} + +/* This is an implementation specific function and should + disappear after the next release. People should use the + real linear functions instead */ + +FBAreaPtr +xf86AllocateLinearOffscreenArea(ScreenPtr pScreen, + int length, + int gran, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, + pointer privData) +{ + FBManagerFuncsPtr funcs; + FBManagerPtr offman; + BoxPtr extents; + int w, h; + + if (xf86FBManagerKey == NULL) + return NULL; + if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBManagerKey))) + return NULL; + + offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, + xf86FBScreenKey); + extents = RegionExtents(offman->InitialBoxes); + w = extents->x2 - extents->x1; + + if (gran > 1) { + if (gran > w) + return NULL; + + if (w % gran) + length += gran - 1; + } + + if (length <= w) { /* special case */ + h = 1; + w = length; + } + else { + h = (length + w - 1) / w; + } + + return (*funcs->AllocateOffscreenArea) (pScreen, w, h, gran, moveCB, + removeCB, privData); +} diff --git a/xorg-server/hw/xfree86/common/xf86fbman.h b/xorg-server/hw/xfree86/common/xf86fbman.h index 1b3c31635..99bf9917b 100644 --- a/xorg-server/hw/xfree86/common/xf86fbman.h +++ b/xorg-server/hw/xfree86/common/xf86fbman.h @@ -29,11 +29,9 @@ #ifndef _XF86FBMAN_H #define _XF86FBMAN_H - #include "scrnintstr.h" #include "regionstr.h" - #define FAVOR_AREA_THEN_WIDTH 0 #define FAVOR_AREA_THEN_HEIGHT 1 #define FAVOR_WIDTH_THEN_AREA 2 @@ -43,184 +41,131 @@ #define PRIORITY_NORMAL 1 #define PRIORITY_EXTREME 2 - typedef struct _FBArea { - ScreenPtr pScreen; - BoxRec box; - int granularity; - void (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*); - void (*RemoveAreaCallback)(struct _FBArea*); - DevUnion devPrivate; + ScreenPtr pScreen; + BoxRec box; + int granularity; + void (*MoveAreaCallback) (struct _FBArea *, struct _FBArea *); + void (*RemoveAreaCallback) (struct _FBArea *); + DevUnion devPrivate; } FBArea, *FBAreaPtr; typedef struct _FBLinear { - ScreenPtr pScreen; - int size; - int offset; - int granularity; - void (*MoveLinearCallback)(struct _FBLinear*, struct _FBLinear*); - void (*RemoveLinearCallback)(struct _FBLinear*); - DevUnion devPrivate; + ScreenPtr pScreen; + int size; + int offset; + int granularity; + void (*MoveLinearCallback) (struct _FBLinear *, struct _FBLinear *); + void (*RemoveLinearCallback) (struct _FBLinear *); + DevUnion devPrivate; } FBLinear, *FBLinearPtr; -typedef void (*FreeBoxCallbackProcPtr)(ScreenPtr, RegionPtr, pointer); -typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr, FBAreaPtr); -typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr); - -typedef void (*MoveLinearCallbackProcPtr)(FBLinearPtr, FBLinearPtr); -typedef void (*RemoveLinearCallbackProcPtr)(FBLinearPtr); +typedef void (*FreeBoxCallbackProcPtr) (ScreenPtr, RegionPtr, pointer); +typedef void (*MoveAreaCallbackProcPtr) (FBAreaPtr, FBAreaPtr); +typedef void (*RemoveAreaCallbackProcPtr) (FBAreaPtr); +typedef void (*MoveLinearCallbackProcPtr) (FBLinearPtr, FBLinearPtr); +typedef void (*RemoveLinearCallbackProcPtr) (FBLinearPtr); typedef struct { - FBAreaPtr (*AllocateOffscreenArea)( - ScreenPtr pScreen, - int w, int h, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - pointer privData); - void (*FreeOffscreenArea)(FBAreaPtr area); - Bool (*ResizeOffscreenArea)(FBAreaPtr area, int w, int h); - Bool (*QueryLargestOffscreenArea)( - ScreenPtr pScreen, - int *width, int *height, - int granularity, - int preferences, - int priority); - Bool (*RegisterFreeBoxCallback)( - ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - pointer devPriv); + FBAreaPtr(*AllocateOffscreenArea) (ScreenPtr pScreen, + int w, int h, + int granularity, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, + pointer privData); + void (*FreeOffscreenArea) (FBAreaPtr area); + Bool (*ResizeOffscreenArea) (FBAreaPtr area, int w, int h); + Bool (*QueryLargestOffscreenArea) (ScreenPtr pScreen, + int *width, int *height, + int granularity, + int preferences, int priority); + Bool (*RegisterFreeBoxCallback) (ScreenPtr pScreen, + FreeBoxCallbackProcPtr FreeBoxCallback, + pointer devPriv); /* linear functions */ - FBLinearPtr (*AllocateOffscreenLinear)( - ScreenPtr pScreen, - int size, - int granularity, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr removeCB, - pointer privData); - void (*FreeOffscreenLinear)(FBLinearPtr area); - Bool (*ResizeOffscreenLinear)(FBLinearPtr area, int size); - Bool (*QueryLargestOffscreenLinear)( - ScreenPtr pScreen, - int *size, - int granularity, - int priority); - Bool (*PurgeOffscreenAreas) (ScreenPtr); + FBLinearPtr(*AllocateOffscreenLinear) (ScreenPtr pScreen, + int size, + int granularity, + MoveLinearCallbackProcPtr moveCB, + RemoveLinearCallbackProcPtr + removeCB, pointer privData); + void (*FreeOffscreenLinear) (FBLinearPtr area); + Bool (*ResizeOffscreenLinear) (FBLinearPtr area, int size); + Bool (*QueryLargestOffscreenLinear) (ScreenPtr pScreen, + int *size, + int granularity, int priority); + Bool (*PurgeOffscreenAreas) (ScreenPtr); } FBManagerFuncs, *FBManagerFuncsPtr; - -extern _X_EXPORT Bool xf86RegisterOffscreenManager( - ScreenPtr pScreen, - FBManagerFuncsPtr funcs -); +extern _X_EXPORT Bool xf86RegisterOffscreenManager(ScreenPtr pScreen, + FBManagerFuncsPtr funcs); extern _X_EXPORT Bool -xf86InitFBManagerRegion( - ScreenPtr pScreen, - RegionPtr ScreenRegion -); + xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr ScreenRegion); extern _X_EXPORT Bool -xf86InitFBManagerArea( - ScreenPtr pScreen, - int PixalArea, - int Verbosity -); + xf86InitFBManagerArea(ScreenPtr pScreen, int PixalArea, int Verbosity); extern _X_EXPORT Bool -xf86InitFBManager( - ScreenPtr pScreen, - BoxPtr FullBox -); + xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox); extern _X_EXPORT Bool -xf86InitFBManagerLinear( - ScreenPtr pScreen, - int offset, - int size -); + xf86InitFBManagerLinear(ScreenPtr pScreen, int offset, int size); extern _X_EXPORT Bool -xf86FBManagerRunning( - ScreenPtr pScreen -); + xf86FBManagerRunning(ScreenPtr pScreen); extern _X_EXPORT FBAreaPtr -xf86AllocateOffscreenArea ( - ScreenPtr pScreen, - int w, int h, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - pointer privData -); +xf86AllocateOffscreenArea(ScreenPtr pScreen, + int w, int h, + int granularity, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, pointer privData); extern _X_EXPORT FBAreaPtr -xf86AllocateLinearOffscreenArea ( - ScreenPtr pScreen, - int length, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - pointer privData -); +xf86AllocateLinearOffscreenArea(ScreenPtr pScreen, + int length, + int granularity, + MoveAreaCallbackProcPtr moveCB, + RemoveAreaCallbackProcPtr removeCB, + pointer privData); extern _X_EXPORT FBLinearPtr -xf86AllocateOffscreenLinear ( - ScreenPtr pScreen, - int length, - int granularity, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr removeCB, - pointer privData -); +xf86AllocateOffscreenLinear(ScreenPtr pScreen, + int length, + int granularity, + MoveLinearCallbackProcPtr moveCB, + RemoveLinearCallbackProcPtr removeCB, + pointer privData); extern _X_EXPORT void xf86FreeOffscreenArea(FBAreaPtr area); extern _X_EXPORT void xf86FreeOffscreenLinear(FBLinearPtr area); extern _X_EXPORT Bool -xf86ResizeOffscreenArea( - FBAreaPtr resize, - int w, int h -); + xf86ResizeOffscreenArea(FBAreaPtr resize, int w, int h); extern _X_EXPORT Bool -xf86ResizeOffscreenLinear( - FBLinearPtr resize, - int size -); - + xf86ResizeOffscreenLinear(FBLinearPtr resize, int size); extern _X_EXPORT Bool -xf86RegisterFreeBoxCallback( - ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - pointer devPriv -); -extern _X_EXPORT Bool -xf86PurgeUnlockedOffscreenAreas( - ScreenPtr pScreen -); +xf86RegisterFreeBoxCallback(ScreenPtr pScreen, + FreeBoxCallbackProcPtr FreeBoxCallback, + pointer devPriv); +extern _X_EXPORT Bool + xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen); extern _X_EXPORT Bool -xf86QueryLargestOffscreenArea( - ScreenPtr pScreen, - int *width, int *height, - int granularity, - int preferences, - int priority -); + +xf86QueryLargestOffscreenArea(ScreenPtr pScreen, + int *width, int *height, + int granularity, int preferences, int priority); extern _X_EXPORT Bool -xf86QueryLargestOffscreenLinear( - ScreenPtr pScreen, - int *size, - int granularity, - int priority -); +xf86QueryLargestOffscreenLinear(ScreenPtr pScreen, + int *size, int granularity, int priority); -#endif /* _XF86FBMAN_H */ +#endif /* _XF86FBMAN_H */ diff --git a/xorg-server/hw/xfree86/common/xf86pciBus.c b/xorg-server/hw/xfree86/common/xf86pciBus.c index b95b25359..e52f1da84 100644 --- a/xorg-server/hw/xfree86/common/xf86pciBus.c +++ b/xorg-server/hw/xfree86/common/xf86pciBus.c @@ -41,7 +41,7 @@ #include "Pci.h" #include "xf86.h" #include "xf86Priv.h" -#include "dirent.h" /* DIR, FILE type definitions */ +#include "dirent.h" /* DIR, FILE type definitions */ /* Bus-specific headers */ #include "xf86Bus.h" @@ -77,7 +77,6 @@ Bool pciSlotClaimed = FALSE; (((c) & 0x00ffff00) \ == ((PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8))) - static struct pci_slot_match xf86IsolateDevice = { PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0 }; @@ -93,108 +92,110 @@ xf86PciProbe(void) int num = 0; struct pci_device *info; struct pci_device_iterator *iter; - struct pci_device ** xf86PciVideoInfo = NULL; - + struct pci_device **xf86PciVideoInfo = NULL; if (!xf86scanpci()) { - xf86PciVideoInfo = NULL; - return; + xf86PciVideoInfo = NULL; + return; } - iter = pci_slot_match_iterator_create(& xf86IsolateDevice); + iter = pci_slot_match_iterator_create(&xf86IsolateDevice); while ((info = pci_device_next(iter)) != NULL) { - if (PCIINFOCLASSES(info->device_class)) { - num++; - xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo, - (sizeof(struct pci_device *) - * (num + 1))); - xf86PciVideoInfo[num] = NULL; - xf86PciVideoInfo[num - 1] = info; - - pci_device_probe(info); - if (pci_device_is_boot_vga(info)) { + if (PCIINFOCLASSES(info->device_class)) { + num++; + xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo, + (sizeof(struct pci_device *) + * (num + 1))); + xf86PciVideoInfo[num] = NULL; + xf86PciVideoInfo[num - 1] = info; + + pci_device_probe(info); + if (pci_device_is_boot_vga(info)) { primaryBus.type = BUS_PCI; primaryBus.id.pci = info; } - info->user_data = 0; - } + info->user_data = 0; + } } free(iter); /* If we haven't found a primary device try a different heuristic */ if (primaryBus.type == BUS_NONE && num) { - for (i = 0; i < num; i++) { - uint16_t command; - - info = xf86PciVideoInfo[i]; - pci_device_cfg_read_u16(info, & command, 4); - - if ((command & PCI_CMD_MEM_ENABLE) - && ((num == 1) || IS_VGA(info->device_class))) { - if (primaryBus.type == BUS_NONE) { - primaryBus.type = BUS_PCI; - primaryBus.id.pci = info; - } else { - xf86Msg(X_NOTICE, - "More than one possible primary device found\n"); - primaryBus.type ^= (BusType)(-1); - } - } - } + for (i = 0; i < num; i++) { + uint16_t command; + + info = xf86PciVideoInfo[i]; + pci_device_cfg_read_u16(info, &command, 4); + + if ((command & PCI_CMD_MEM_ENABLE) + && ((num == 1) || IS_VGA(info->device_class))) { + if (primaryBus.type == BUS_NONE) { + primaryBus.type = BUS_PCI; + primaryBus.id.pci = info; + } + else { + xf86Msg(X_NOTICE, + "More than one possible primary device found\n"); + primaryBus.type ^= (BusType) (-1); + } + } + } } - + /* Print a summary of the video devices found */ for (k = 0; k < num; k++) { - const char *prim = " "; - Bool memdone = FALSE, iodone = FALSE; - + const char *prim = " "; + Bool memdone = FALSE, iodone = FALSE; - info = xf86PciVideoInfo[k]; + info = xf86PciVideoInfo[k]; - if (!PCIALWAYSPRINTCLASSES(info->device_class)) - continue; + if (!PCIALWAYSPRINTCLASSES(info->device_class)) + continue; - if (xf86IsPrimaryPci(info)) - prim = "*"; + if (xf86IsPrimaryPci(info)) + prim = "*"; - xf86Msg(X_PROBED, "PCI:%s(%u:%u:%u:%u) %04x:%04x:%04x:%04x ", prim, - info->domain, info->bus, info->dev, info->func, - info->vendor_id, info->device_id, - info->subvendor_id, info->subdevice_id); + xf86Msg(X_PROBED, "PCI:%s(%u:%u:%u:%u) %04x:%04x:%04x:%04x ", prim, + info->domain, info->bus, info->dev, info->func, + info->vendor_id, info->device_id, + info->subvendor_id, info->subdevice_id); - xf86ErrorF("rev %d", info->revision); + xf86ErrorF("rev %d", info->revision); - for (i = 0; i < 6; i++) { - struct pci_mem_region * r = & info->regions[i]; + for (i = 0; i < 6; i++) { + struct pci_mem_region *r = &info->regions[i]; - if ( r->size && ! r->is_IO ) { - if (!memdone) { - xf86ErrorF(", Mem @ "); - memdone = TRUE; - } else - xf86ErrorF(", "); - xf86ErrorF("0x%08lx/%ld", (long)r->base_addr, (long)r->size); - } - } + if (r->size && !r->is_IO) { + if (!memdone) { + xf86ErrorF(", Mem @ "); + memdone = TRUE; + } + else + xf86ErrorF(", "); + xf86ErrorF("0x%08lx/%ld", (long) r->base_addr, (long) r->size); + } + } - for (i = 0; i < 6; i++) { - struct pci_mem_region * r = & info->regions[i]; + for (i = 0; i < 6; i++) { + struct pci_mem_region *r = &info->regions[i]; - if ( r->size && r->is_IO ) { - if (!iodone) { - xf86ErrorF(", I/O @ "); - iodone = TRUE; - } else - xf86ErrorF(", "); - xf86ErrorF("0x%08lx/%ld", (long)r->base_addr, (long)r->size); - } - } + if (r->size && r->is_IO) { + if (!iodone) { + xf86ErrorF(", I/O @ "); + iodone = TRUE; + } + else + xf86ErrorF(", "); + xf86ErrorF("0x%08lx/%ld", (long) r->base_addr, (long) r->size); + } + } - if ( info->rom_size ) { - xf86ErrorF(", BIOS @ 0x\?\?\?\?\?\?\?\?/%ld", (long)info->rom_size); - } + if (info->rom_size) { + xf86ErrorF(", BIOS @ 0x\?\?\?\?\?\?\?\?/%ld", + (long) info->rom_size); + } - xf86ErrorF("\n"); + xf86ErrorF("\n"); } free(xf86PciVideoInfo); } @@ -205,28 +206,29 @@ xf86PciProbe(void) */ int -xf86ClaimPciSlot(struct pci_device * d, DriverPtr drvp, - int chipset, GDevPtr dev, Bool active) +xf86ClaimPciSlot(struct pci_device *d, DriverPtr drvp, + int chipset, GDevPtr dev, Bool active) { EntityPtr p = NULL; int num; - + if (xf86CheckPciSlot(d)) { - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = chipset; - p->bus.type = BUS_PCI; - p->bus.id.pci = d; - p->active = active; - p->inUse = FALSE; - if (dev) + num = xf86AllocateEntity(); + p = xf86Entities[num]; + p->driver = drvp; + p->chipset = chipset; + p->bus.type = BUS_PCI; + p->bus.id.pci = d; + p->active = active; + p->inUse = FALSE; + if (dev) xf86AddDevToEntity(num, dev); - pciSlotClaimed = TRUE; + pciSlotClaimed = TRUE; - return num; - } else - return -1; + return num; + } + else + return -1; } /* @@ -238,13 +240,13 @@ xf86UnclaimPciSlot(struct pci_device *d) int i; for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr p = xf86Entities[i]; + const EntityPtr p = xf86Entities[i]; - if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { - /* Probably the slot should be deallocated? */ - p->bus.type = BUS_NONE; - return; - } + if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { + /* Probably the slot should be deallocated? */ + p->bus.type = BUS_NONE; + return; + } } } @@ -267,56 +269,56 @@ xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func) int i; if (StringToBusType(busID, &id) != BUS_PCI) - return FALSE; + return FALSE; s = xstrdup(id); p = strtok(s, ":"); if (p == NULL || *p == 0) { - free(s); - return FALSE; + free(s); + return FALSE; } d = strpbrk(p, "@"); if (d != NULL) { - *(d++) = 0; - for (i = 0; d[i] != 0; i++) { - if (!isdigit(d[i])) { - free(s); - return FALSE; - } - } + *(d++) = 0; + for (i = 0; d[i] != 0; i++) { + if (!isdigit(d[i])) { + free(s); + return FALSE; + } + } } for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } + if (!isdigit(p[i])) { + free(s); + return FALSE; + } } *bus = atoi(p); if (d != NULL && *d != 0) - *bus += atoi(d) << 8; + *bus += atoi(d) << 8; p = strtok(NULL, ":"); if (p == NULL || *p == 0) { - free(s); - return FALSE; + free(s); + return FALSE; } for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } + if (!isdigit(p[i])) { + free(s); + return FALSE; + } } *device = atoi(p); *func = 0; p = strtok(NULL, ":"); if (p == NULL || *p == 0) { - free(s); - return TRUE; + free(s); + return TRUE; } for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } + if (!isdigit(p[i])) { + free(s); + return FALSE; + } } *func = atoi(p); free(s); @@ -333,9 +335,10 @@ xf86ComparePciBusString(const char *busID, int bus, int device, int func) int ibus, idevice, ifunc; if (xf86ParsePciBusString(busID, &ibus, &idevice, &ifunc)) { - return bus == ibus && device == idevice && func == ifunc; - } else { - return FALSE; + return bus == ibus && device == idevice && func == ifunc; + } + else { + return FALSE; } } @@ -343,7 +346,7 @@ xf86ComparePciBusString(const char *busID, int bus, int device, int func) * xf86IsPrimaryPci() -- return TRUE if primary device * is PCI and bus, dev and func numbers match. */ - + Bool xf86IsPrimaryPci(struct pci_device *pPci) { @@ -357,9 +360,9 @@ struct pci_device * xf86GetPciInfoForEntity(int entityIndex) { EntityPtr p; - + if (entityIndex >= xf86NumEntities) - return NULL; + return NULL; p = xf86Entities[entityIndex]; return (p->bus.type == BUS_PCI) ? p->bus.id.pci : NULL; @@ -370,13 +373,13 @@ xf86GetPciInfoForEntity(int entityIndex) * PCI base address register values for the given PCI device. */ Bool -xf86CheckPciMemBase( struct pci_device * pPci, memType base ) +xf86CheckPciMemBase(struct pci_device *pPci, memType base) { int i; for (i = 0; i < 6; i++) - if (base == pPci->regions[i].base_addr) - return TRUE; + if (base == pPci->regions[i].base_addr) + return TRUE; return FALSE; } @@ -390,11 +393,11 @@ xf86CheckPciSlot(const struct pci_device *d) int i; for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr p = xf86Entities[i]; + const EntityPtr p = xf86Entities[i]; - if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { - return FALSE; - } + if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { + return FALSE; + } } return TRUE; } @@ -405,41 +408,41 @@ xf86CheckPciSlot(const struct pci_device *d) Bool xf86PciAddMatchingDev(DriverPtr drvp) { - const struct pci_id_match * const devices = drvp->supported_devices; + const struct pci_id_match *const devices = drvp->supported_devices; int j; struct pci_device *pPci; struct pci_device_iterator *iter; int numFound = 0; - iter = pci_id_match_iterator_create(NULL); while ((pPci = pci_device_next(iter)) != NULL) { - /* Determine if this device is supported by the driver. If it is, - * add it to the list of devices to configure. - */ - for (j = 0 ; ! END_OF_MATCHES(devices[j]) ; j++) { - if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id ) - && PCI_ID_COMPARE( devices[j].device_id, pPci->device_id ) - && ((devices[j].device_class_mask & pPci->device_class) - == devices[j].device_class) ) { - if (xf86CheckPciSlot(pPci)) { - GDevPtr pGDev = xf86AddBusDeviceToConfigure( - drvp->driverName, BUS_PCI, pPci, -1); - if (pGDev != NULL) { - /* After configure pass 1, chipID and chipRev are - * treated as over-rides, so clobber them here. - */ - pGDev->chipID = -1; - pGDev->chipRev = -1; - } + /* Determine if this device is supported by the driver. If it is, + * add it to the list of devices to configure. + */ + for (j = 0; !END_OF_MATCHES(devices[j]); j++) { + if (PCI_ID_COMPARE(devices[j].vendor_id, pPci->vendor_id) + && PCI_ID_COMPARE(devices[j].device_id, pPci->device_id) + && ((devices[j].device_class_mask & pPci->device_class) + == devices[j].device_class)) { + if (xf86CheckPciSlot(pPci)) { + GDevPtr pGDev = + xf86AddBusDeviceToConfigure(drvp->driverName, BUS_PCI, + pPci, -1); + if (pGDev != NULL) { + /* After configure pass 1, chipID and chipRev are + * treated as over-rides, so clobber them here. + */ + pGDev->chipID = -1; + pGDev->chipRev = -1; + } - numFound++; - } + numFound++; + } - break; + break; + } } } - } pci_iterator_destroy(iter); @@ -450,97 +453,96 @@ Bool xf86PciProbeDev(DriverPtr drvp) { int i, j; - struct pci_device * pPci; + struct pci_device *pPci; Bool foundScreen = FALSE; - const struct pci_id_match * const devices = drvp->supported_devices; + const struct pci_id_match *const devices = drvp->supported_devices; GDevPtr *devList; - const unsigned numDevs = xf86MatchDevice(drvp->driverName, & devList); - - for ( i = 0 ; i < numDevs ; i++ ) { - struct pci_device_iterator *iter; - unsigned device_id; - - - /* Find the pciVideoRec associated with this device section. - */ - iter = pci_id_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - if (devList[i]->busID && *devList[i]->busID) { - if (xf86ComparePciBusString(devList[i]->busID, - ((pPci->domain << 8) - | pPci->bus), - pPci->dev, - pPci->func)) { - break; - } - } - else if (xf86IsPrimaryPci(pPci)) { - break; - } - } - - pci_iterator_destroy(iter); - - if (pPci == NULL) { - continue; - } - device_id = (devList[i]->chipID > 0) - ? devList[i]->chipID : pPci->device_id; - - - /* Once the pciVideoRec is found, determine if the device is supported - * by the driver. If it is, probe it! - */ - for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) { - if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id ) - && PCI_ID_COMPARE( devices[j].device_id, device_id ) + const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList); + + for (i = 0; i < numDevs; i++) { + struct pci_device_iterator *iter; + unsigned device_id; + + /* Find the pciVideoRec associated with this device section. + */ + iter = pci_id_match_iterator_create(NULL); + while ((pPci = pci_device_next(iter)) != NULL) { + if (devList[i]->busID && *devList[i]->busID) { + if (xf86ComparePciBusString(devList[i]->busID, + ((pPci->domain << 8) + | pPci->bus), + pPci->dev, pPci->func)) { + break; + } + } + else if (xf86IsPrimaryPci(pPci)) { + break; + } + } + + pci_iterator_destroy(iter); + + if (pPci == NULL) { + continue; + } + device_id = (devList[i]->chipID > 0) + ? devList[i]->chipID : pPci->device_id; + + /* Once the pciVideoRec is found, determine if the device is supported + * by the driver. If it is, probe it! + */ + for (j = 0; !END_OF_MATCHES(devices[j]); j++) { + if (PCI_ID_COMPARE(devices[j].vendor_id, pPci->vendor_id) + && PCI_ID_COMPARE(devices[j].device_id, device_id) && ((devices[j].device_class_mask & pPci->device_class) - == devices[j].device_class) ) { - int entry; - - /* Allow the same entity to be used more than once for - * devices with multiple screens per entity. This assumes - * implicitly that there will be a screen == 0 instance. - * - * FIXME Need to make sure that two different drivers don't - * FIXME claim the same screen > 0 instance. - */ - if ((devList[i]->screen == 0) && !xf86CheckPciSlot(pPci)) - continue; - - DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", - drvp->driverName, pPci->bus, pPci->dev, pPci->func); - - /* Allocate an entry in the lists to be returned */ - entry = xf86ClaimPciSlot(pPci, drvp, device_id, + == devices[j].device_class)) { + int entry; + + /* Allow the same entity to be used more than once for + * devices with multiple screens per entity. This assumes + * implicitly that there will be a screen == 0 instance. + * + * FIXME Need to make sure that two different drivers don't + * FIXME claim the same screen > 0 instance. + */ + if ((devList[i]->screen == 0) && !xf86CheckPciSlot(pPci)) + continue; + + DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", + drvp->driverName, pPci->bus, pPci->dev, pPci->func); + + /* Allocate an entry in the lists to be returned */ + entry = xf86ClaimPciSlot(pPci, drvp, device_id, devList[i], devList[i]->active); - if ((entry == -1) && (devList[i]->screen > 0)) { - unsigned k; - - for (k = 0; k < xf86NumEntities; k++ ) { - EntityPtr pEnt = xf86Entities[k]; - if (pEnt->bus.type != BUS_PCI) - continue; - if (pEnt->bus.id.pci == pPci) { - entry = k; - xf86AddDevToEntity(k, devList[i]); - break; - } - } - } - - if (entry != -1) { - if ((*drvp->PciProbe)(drvp, entry, pPci, - devices[j].match_data)) { - foundScreen = TRUE; - } else - xf86UnclaimPciSlot(pPci); - } - - break; - } - } + if ((entry == -1) && (devList[i]->screen > 0)) { + unsigned k; + + for (k = 0; k < xf86NumEntities; k++) { + EntityPtr pEnt = xf86Entities[k]; + + if (pEnt->bus.type != BUS_PCI) + continue; + if (pEnt->bus.id.pci == pPci) { + entry = k; + xf86AddDevToEntity(k, devList[i]); + break; + } + } + } + + if (entry != -1) { + if ((*drvp->PciProbe) (drvp, entry, pPci, + devices[j].match_data)) { + foundScreen = TRUE; + } + else + xf86UnclaimPciSlot(pPci); + } + + break; + } + } } free(devList); @@ -557,7 +559,8 @@ xf86PciIsolateDevice(char *argument) xf86IsolateDevice.bus = PCI_BUS_NO_DOMAIN(bus); xf86IsolateDevice.dev = device; xf86IsolateDevice.func = func; - } else + } + else FatalError("Invalid isolated device specification\n"); } @@ -567,25 +570,24 @@ pciDeviceHasBars(struct pci_device *pci) int i; for (i = 0; i < 6; i++) - if (pci->regions[i].size) - return TRUE; + if (pci->regions[i].size) + return TRUE; if (pci->rom_size) - return TRUE; + return TRUE; return FALSE; } struct Inst { - struct pci_device * pci; - GDevPtr dev; - Bool foundHW; /* PCIid in list of supported chipsets */ - Bool claimed; /* BusID matches with a device section */ - int chip; - int screen; + struct pci_device *pci; + GDevPtr dev; + Bool foundHW; /* PCIid in list of supported chipsets */ + Bool claimed; /* BusID matches with a device section */ + int chip; + int screen; }; - /** * Find set of unclaimed devices matching a given vendor ID. * @@ -620,12 +622,12 @@ struct Inst { */ int xf86MatchPciInstances(const char *driverName, int vendorID, - SymTabPtr chipsets, PciChipsets *PCIchipsets, - GDevPtr *devList, int numDevs, DriverPtr drvp, - int **foundEntities) + SymTabPtr chipsets, PciChipsets * PCIchipsets, + GDevPtr * devList, int numDevs, DriverPtr drvp, + int **foundEntities) { - int i,j; - struct pci_device * pPci; + int i, j; + struct pci_device *pPci; struct pci_device_iterator *iter; struct Inst *instances = NULL; int numClaimedInstances = 0; @@ -637,7 +639,6 @@ xf86MatchPciInstances(const char *driverName, int vendorID, *foundEntities = NULL; - /* Each PCI device will contribute at least one entry. Each device * section can contribute at most one entry. The sum of the two is * guaranteed to be larger than the maximum possible number of entries. @@ -645,199 +646,199 @@ xf86MatchPciInstances(const char *driverName, int vendorID, * need for realloc calls inside the loop. */ if (!(xf86DoConfigure && xf86DoConfigurePass1)) { - unsigned max_entries = numDevs; + unsigned max_entries = numDevs; - iter = pci_slot_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - max_entries++; - } + iter = pci_slot_match_iterator_create(NULL); + while ((pPci = pci_device_next(iter)) != NULL) { + max_entries++; + } - pci_iterator_destroy(iter); - instances = xnfalloc(max_entries * sizeof(struct Inst)); + pci_iterator_destroy(iter); + instances = xnfalloc(max_entries * sizeof(struct Inst)); } iter = pci_slot_match_iterator_create(NULL); while ((pPci = pci_device_next(iter)) != NULL) { - unsigned device_class = pPci->device_class; - Bool foundVendor = FALSE; - - - /* Convert the pre-PCI 2.0 device class for a VGA adapter to the - * 2.0 version of the same class. - */ - if ( device_class == 0x00000101 ) { - device_class = 0x00030000; - } - - - /* Find PCI devices that match the given vendor ID. The vendor ID is - * either specified explicitly as a parameter to the function or - * implicitly encoded in the high bits of id->PCIid. - * - * The first device with a matching vendor is recorded, even if the - * device ID doesn't match. This is done because the Device section - * in the xorg.conf file can over-ride the device ID. A matching PCI - * ID might not be found now, but after the device ID over-ride is - * applied there /might/ be a match. - */ - for (id = PCIchipsets; id->PCIid != -1; id++) { - const unsigned vendor_id = ((id->PCIid & 0xFFFF0000) >> 16) - | vendorID; - const unsigned device_id = (id->PCIid & 0x0000FFFF); - const unsigned match_class = 0x00030000 | id->PCIid; - - if ((vendor_id == pPci->vendor_id) - || ((vendorID == PCI_VENDOR_GENERIC) && (match_class == device_class))) { - if (!foundVendor && (instances != NULL)) { - ++allocatedInstances; - instances[allocatedInstances - 1].pci = pPci; - instances[allocatedInstances - 1].dev = NULL; - instances[allocatedInstances - 1].claimed = FALSE; - instances[allocatedInstances - 1].foundHW = FALSE; - instances[allocatedInstances - 1].screen = 0; - } - - foundVendor = TRUE; - - if ( (device_id == pPci->device_id) - || ((vendorID == PCI_VENDOR_GENERIC) - && (match_class == device_class)) ) { - if ( instances != NULL ) { - instances[allocatedInstances - 1].foundHW = TRUE; - instances[allocatedInstances - 1].chip = id->numChipset; - } - - - if ( xf86DoConfigure && xf86DoConfigurePass1 ) { - if (xf86CheckPciSlot(pPci)) { - GDevPtr pGDev = - xf86AddBusDeviceToConfigure(drvp->driverName, - BUS_PCI, pPci, -1); - if (pGDev) { - /* After configure pass 1, chipID and chipRev - * are treated as over-rides, so clobber them - * here. - */ - pGDev->chipID = -1; - pGDev->chipRev = -1; - } - - numFound++; - } - } - else { - numFound++; - } - - break; - } - } - } + unsigned device_class = pPci->device_class; + Bool foundVendor = FALSE; + + /* Convert the pre-PCI 2.0 device class for a VGA adapter to the + * 2.0 version of the same class. + */ + if (device_class == 0x00000101) { + device_class = 0x00030000; + } + + /* Find PCI devices that match the given vendor ID. The vendor ID is + * either specified explicitly as a parameter to the function or + * implicitly encoded in the high bits of id->PCIid. + * + * The first device with a matching vendor is recorded, even if the + * device ID doesn't match. This is done because the Device section + * in the xorg.conf file can over-ride the device ID. A matching PCI + * ID might not be found now, but after the device ID over-ride is + * applied there /might/ be a match. + */ + for (id = PCIchipsets; id->PCIid != -1; id++) { + const unsigned vendor_id = ((id->PCIid & 0xFFFF0000) >> 16) + | vendorID; + const unsigned device_id = (id->PCIid & 0x0000FFFF); + const unsigned match_class = 0x00030000 | id->PCIid; + + if ((vendor_id == pPci->vendor_id) + || ((vendorID == PCI_VENDOR_GENERIC) && + (match_class == device_class))) { + if (!foundVendor && (instances != NULL)) { + ++allocatedInstances; + instances[allocatedInstances - 1].pci = pPci; + instances[allocatedInstances - 1].dev = NULL; + instances[allocatedInstances - 1].claimed = FALSE; + instances[allocatedInstances - 1].foundHW = FALSE; + instances[allocatedInstances - 1].screen = 0; + } + + foundVendor = TRUE; + + if ((device_id == pPci->device_id) + || ((vendorID == PCI_VENDOR_GENERIC) + && (match_class == device_class))) { + if (instances != NULL) { + instances[allocatedInstances - 1].foundHW = TRUE; + instances[allocatedInstances - 1].chip = id->numChipset; + } + + if (xf86DoConfigure && xf86DoConfigurePass1) { + if (xf86CheckPciSlot(pPci)) { + GDevPtr pGDev = + xf86AddBusDeviceToConfigure(drvp->driverName, + BUS_PCI, pPci, -1); + + if (pGDev) { + /* After configure pass 1, chipID and chipRev + * are treated as over-rides, so clobber them + * here. + */ + pGDev->chipID = -1; + pGDev->chipRev = -1; + } + + numFound++; + } + } + else { + numFound++; + } + + break; + } + } + } } pci_iterator_destroy(iter); - /* In "probe only" or "configure" mode (signaled by instances being NULL), * our work is done. Return the number of detected devices. */ - if ( instances == NULL ) { - return numFound; + if (instances == NULL) { + return numFound; } - /* * This may be debatable, but if no PCI devices with a matching vendor * type is found, return zero now. It is probably not desirable to * allow the config file to override this. */ if (allocatedInstances <= 0) { - free(instances); - return 0; + free(instances); + return 0; } - DebugF("%s instances found: %d\n", driverName, allocatedInstances); - /* - * Check for devices that need duplicated instances. This is required - * when there is more than one screen per entity. - * - * XXX This currently doesn't work for cases where the BusID isn't - * specified explicitly in the config file. - */ + /* + * Check for devices that need duplicated instances. This is required + * when there is more than one screen per entity. + * + * XXX This currently doesn't work for cases where the BusID isn't + * specified explicitly in the config file. + */ for (j = 0; j < numDevs; j++) { - if (devList[j]->screen > 0 && devList[j]->busID - && *devList[j]->busID) { - for (i = 0; i < allocatedInstances; i++) { - pPci = instances[i].pci; - if (xf86ComparePciBusString(devList[j]->busID, - PCI_MAKE_BUS( pPci->domain, pPci->bus ), - pPci->dev, - pPci->func)) { - allocatedInstances++; - instances[allocatedInstances - 1] = instances[i]; - instances[allocatedInstances - 1].screen = devList[j]->screen; - numFound++; - break; - } - } - } + if (devList[j]->screen > 0 && devList[j]->busID && *devList[j]->busID) { + for (i = 0; i < allocatedInstances; i++) { + pPci = instances[i].pci; + if (xf86ComparePciBusString(devList[j]->busID, + PCI_MAKE_BUS(pPci->domain, + pPci->bus), pPci->dev, + pPci->func)) { + allocatedInstances++; + instances[allocatedInstances - 1] = instances[i]; + instances[allocatedInstances - 1].screen = + devList[j]->screen; + numFound++; + break; + } + } + } } for (i = 0; i < allocatedInstances; i++) { - GDevPtr dev = NULL; - GDevPtr devBus = NULL; - - pPci = instances[i].pci; - for (j = 0; j < numDevs; j++) { - if (devList[j]->busID && *devList[j]->busID) { - if (xf86ComparePciBusString(devList[j]->busID, - PCI_MAKE_BUS( pPci->domain, pPci->bus ), - pPci->dev, - pPci->func) && - devList[j]->screen == instances[i].screen) { - - if (devBus) - xf86MsgVerb(X_WARNING,0, - "%s: More than one matching Device section for " - "instances\n\t(BusID: %s) found: %s\n", - driverName, devList[j]->busID, - devList[j]->identifier); - else - devBus = devList[j]; - } - } else { - /* - * if device section without BusID is found - * only assign to it to the primary device. - */ - if (xf86IsPrimaryPci(pPci)) { - xf86Msg(X_PROBED, "Assigning device section with no busID" - " to primary device\n"); - if (dev || devBus) - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section " - "found: %s\n", driverName, devList[j]->identifier); - else - dev = devList[j]; - } - } - } - if (devBus) dev = devBus; /* busID preferred */ - if (!dev) { - if (xf86CheckPciSlot(pPci) && pciDeviceHasBars(pPci)) { - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID PCI:%u@%u:%u:%u) found\n", - driverName, pPci->domain, pPci->bus, pPci->dev, - pPci->func); - } - } else { - numClaimedInstances++; - instances[i].claimed = TRUE; - instances[i].dev = dev; - } + GDevPtr dev = NULL; + GDevPtr devBus = NULL; + + pPci = instances[i].pci; + for (j = 0; j < numDevs; j++) { + if (devList[j]->busID && *devList[j]->busID) { + if (xf86ComparePciBusString(devList[j]->busID, + PCI_MAKE_BUS(pPci->domain, + pPci->bus), pPci->dev, + pPci->func) && + devList[j]->screen == instances[i].screen) { + + if (devBus) + xf86MsgVerb(X_WARNING, 0, + "%s: More than one matching Device section for " + "instances\n\t(BusID: %s) found: %s\n", + driverName, devList[j]->busID, + devList[j]->identifier); + else + devBus = devList[j]; + } + } + else { + /* + * if device section without BusID is found + * only assign to it to the primary device. + */ + if (xf86IsPrimaryPci(pPci)) { + xf86Msg(X_PROBED, "Assigning device section with no busID" + " to primary device\n"); + if (dev || devBus) + xf86MsgVerb(X_WARNING, 0, + "%s: More than one matching Device section " + "found: %s\n", driverName, + devList[j]->identifier); + else + dev = devList[j]; + } + } + } + if (devBus) + dev = devBus; /* busID preferred */ + if (!dev) { + if (xf86CheckPciSlot(pPci) && pciDeviceHasBars(pPci)) { + xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " + "for instance (BusID PCI:%u@%u:%u:%u) found\n", + driverName, pPci->domain, pPci->bus, pPci->dev, + pPci->func); + } + } + else { + numClaimedInstances++; + instances[i].claimed = TRUE; + instances[i].dev = dev; + } } DebugF("%s instances found: %d\n", driverName, numClaimedInstances); /* @@ -846,78 +847,82 @@ xf86MatchPciInstances(const char *driverName, int vendorID, * If chipset is not valid ignore BusSlot completely. */ for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - MessageType from = X_PROBED; - - if (!instances[i].claimed) { - continue; - } - if (instances[i].dev->chipset) { - for (c = chipsets; c->token >= 0; c++) { - if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0) - break; - } - if (c->token == -1) { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " - "section \"%s\" isn't valid for this driver\n", - driverName, instances[i].dev->chipset, - instances[i].dev->identifier); - } else { - instances[i].chip = c->token; - - for (id = PCIchipsets; id->numChipset >= 0; id++) { - if (id->numChipset == instances[i].chip) - break; - } - if(id->numChipset >=0){ - xf86Msg(X_CONFIG,"Chipset override: %s\n", - instances[i].dev->chipset); - from = X_CONFIG; - } else { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " - "section \"%s\" isn't a valid PCI chipset\n", - driverName, instances[i].dev->chipset, - instances[i].dev->identifier); - } - } - } else if (instances[i].dev->chipID > 0) { - for (id = PCIchipsets; id->numChipset >= 0; id++) { - if (id->PCIid == instances[i].dev->chipID) - break; - } - if (id->numChipset == -1) { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device " - "section \"%s\" isn't valid for this driver\n", - driverName, instances[i].dev->chipID, - instances[i].dev->identifier); - } else { - instances[i].chip = id->numChipset; - - xf86Msg( X_CONFIG,"ChipID override: 0x%04X\n", - instances[i].dev->chipID); - from = X_CONFIG; - } - } else if (!instances[i].foundHW) { - /* - * This means that there was no override and the PCI chipType - * doesn't match one that is supported - */ - instances[i].claimed = FALSE; - numClaimedInstances--; - } - if (instances[i].claimed == TRUE){ - for (c = chipsets; c->token >= 0; c++) { - if (c->token == instances[i].chip) - break; - } - xf86Msg(from,"Chipset %s found\n", - c->name); - } + MessageType from = X_PROBED; + + if (!instances[i].claimed) { + continue; + } + if (instances[i].dev->chipset) { + for (c = chipsets; c->token >= 0; c++) { + if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0) + break; + } + if (c->token == -1) { + instances[i].claimed = FALSE; + numClaimedInstances--; + xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " + "section \"%s\" isn't valid for this driver\n", + driverName, instances[i].dev->chipset, + instances[i].dev->identifier); + } + else { + instances[i].chip = c->token; + + for (id = PCIchipsets; id->numChipset >= 0; id++) { + if (id->numChipset == instances[i].chip) + break; + } + if (id->numChipset >= 0) { + xf86Msg(X_CONFIG, "Chipset override: %s\n", + instances[i].dev->chipset); + from = X_CONFIG; + } + else { + instances[i].claimed = FALSE; + numClaimedInstances--; + xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " + "section \"%s\" isn't a valid PCI chipset\n", + driverName, instances[i].dev->chipset, + instances[i].dev->identifier); + } + } + } + else if (instances[i].dev->chipID > 0) { + for (id = PCIchipsets; id->numChipset >= 0; id++) { + if (id->PCIid == instances[i].dev->chipID) + break; + } + if (id->numChipset == -1) { + instances[i].claimed = FALSE; + numClaimedInstances--; + xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device " + "section \"%s\" isn't valid for this driver\n", + driverName, instances[i].dev->chipID, + instances[i].dev->identifier); + } + else { + instances[i].chip = id->numChipset; + + xf86Msg(X_CONFIG, "ChipID override: 0x%04X\n", + instances[i].dev->chipID); + from = X_CONFIG; + } + } + else if (!instances[i].foundHW) { + /* + * This means that there was no override and the PCI chipType + * doesn't match one that is supported + */ + instances[i].claimed = FALSE; + numClaimedInstances--; + } + if (instances[i].claimed == TRUE) { + for (c = chipsets; c->token >= 0; c++) { + if (c->token == instances[i].chip) + break; + } + xf86Msg(from, "Chipset %s found\n", c->name); + } } /* @@ -926,48 +931,48 @@ xf86MatchPciInstances(const char *driverName, int vendorID, */ numFound = 0; for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - if (!instances[i].claimed) - continue; - pPci = instances[i].pci; - + if (!instances[i].claimed) + continue; + pPci = instances[i].pci; /* - * Allow the same entity to be used more than once for devices with - * multiple screens per entity. This assumes implicitly that there - * will be a screen == 0 instance. - * - * XXX Need to make sure that two different drivers don't claim - * the same screen > 0 instance. - */ - if (instances[i].screen == 0 && !xf86CheckPciSlot( pPci )) - continue; - - DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", - driverName, pPci->bus, pPci->dev, pPci->func); - - /* Allocate an entry in the lists to be returned */ - numFound++; - retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); - retEntities[numFound - 1] = xf86ClaimPciSlot( pPci, drvp, - instances[i].chip, - instances[i].dev, - instances[i].dev->active); + * Allow the same entity to be used more than once for devices with + * multiple screens per entity. This assumes implicitly that there + * will be a screen == 0 instance. + * + * XXX Need to make sure that two different drivers don't claim + * the same screen > 0 instance. + */ + if (instances[i].screen == 0 && !xf86CheckPciSlot(pPci)) + continue; + + DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", + driverName, pPci->bus, pPci->dev, pPci->func); + + /* Allocate an entry in the lists to be returned */ + numFound++; + retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); + retEntities[numFound - 1] = xf86ClaimPciSlot(pPci, drvp, + instances[i].chip, + instances[i].dev, + instances[i].dev->active); if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) { - for (j = 0; j < xf86NumEntities; j++) { - EntityPtr pEnt = xf86Entities[j]; - if (pEnt->bus.type != BUS_PCI) - continue; - if (pEnt->bus.id.pci == pPci) { - retEntities[numFound - 1] = j; - xf86AddDevToEntity(j, instances[i].dev); - break; - } - } - } + for (j = 0; j < xf86NumEntities; j++) { + EntityPtr pEnt = xf86Entities[j]; + + if (pEnt->bus.type != BUS_PCI) + continue; + if (pEnt->bus.id.pci == pPci) { + retEntities[numFound - 1] = j; + xf86AddDevToEntity(j, instances[i].dev); + break; + } + } + } } free(instances); if (numFound > 0) { - *foundEntities = retEntities; + *foundEntities = retEntities; } return numFound; @@ -981,51 +986,52 @@ xf86MatchPciInstances(const char *driverName, int vendorID, * non-NULL all static resources listed there will be registered. */ static void -xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets *p_chip, - EntityProc init, EntityProc enter, - EntityProc leave, pointer private) +xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets * p_chip, + EntityProc init, EntityProc enter, + EntityProc leave, pointer private) { ScrnInfoPtr pScrn; if ((pScrn = xf86FindScreenForEntity(pEnt->index))) - xf86RemoveEntityFromScreen(pScrn,pEnt->index); + xf86RemoveEntityFromScreen(pScrn, pEnt->index); /* shared resources are only needed when entity is active: remove */ - xf86SetEntityFuncs(pEnt->index,init,enter,leave,private); + xf86SetEntityFuncs(pEnt->index, init, enter, leave, private); } ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, - PciChipsets *p_chip, void *dummy, EntityProc init, - EntityProc enter, EntityProc leave, pointer private) + PciChipsets * p_chip, void *dummy, EntityProc init, + EntityProc enter, EntityProc leave, pointer private) { EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - if (!pEnt) return pScrn; + + if (!pEnt) + return pScrn; if (!(pEnt->location.type == BUS_PCI) - || !xf86GetPciInfoForEntity(entityIndex)) { - free(pEnt); - return pScrn; + || !xf86GetPciInfoForEntity(entityIndex)) { + free(pEnt); + return pScrn; } if (!pEnt->active) { - xf86ConfigPciEntityInactive(pEnt, p_chip, init, enter, - leave, private); - free(pEnt); - return pScrn; + xf86ConfigPciEntityInactive(pEnt, p_chip, init, enter, leave, private); + free(pEnt); + return pScrn; } if (!pScrn) - pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag); + pScrn = xf86AllocateScreen(pEnt->driver, scrnFlag); if (xf86IsEntitySharable(entityIndex)) { xf86SetEntityShared(entityIndex); } - xf86AddEntityToScreen(pScrn,entityIndex); + xf86AddEntityToScreen(pScrn, entityIndex); if (xf86IsEntityShared(entityIndex)) { return pScrn; } free(pEnt); - xf86SetEntityFuncs(entityIndex,init,enter,leave,private); + xf86SetEntityFuncs(entityIndex, init, enter, leave, private); return pScrn; } @@ -1036,20 +1042,22 @@ xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, */ Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex, - PciChipsets *p_chip, void *dummy, EntityProc init, + PciChipsets * p_chip, void *dummy, EntityProc init, EntityProc enter, EntityProc leave, pointer private) { EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - if (!pEnt) return FALSE; + + if (!pEnt) + return FALSE; if (!pEnt->active || !(pEnt->location.type == BUS_PCI)) { free(pEnt); return FALSE; } - xf86AddEntityToScreen(pScrn,entityIndex); + xf86AddEntityToScreen(pScrn, entityIndex); free(pEnt); - if (!xf86SetEntityFuncs(entityIndex,init,enter,leave,private)) + if (!xf86SetEntityFuncs(entityIndex, init, enter, leave, private)) return FALSE; return TRUE; @@ -1057,106 +1065,165 @@ xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex, static int videoPtrToDriverList(struct pci_device *dev, - char *returnList[], int returnListMax) + char *returnList[], int returnListMax) { int i; + /* Add more entries here if we ever return more than 4 drivers for any device */ const char *driverList[5] = { NULL, NULL, NULL, NULL, NULL }; - switch (dev->vendor_id) + switch (dev->vendor_id) { + /* AMD Geode LX */ + case 0x1022: + if (dev->device_id == 0x2081) + driverList[0] = "geode"; + break; + /* older Geode products acquired by AMD still carry an NSC vendor_id */ + case 0x100b: + if (dev->device_id == 0x0030) { + /* NSC Geode GX2 specifically */ + driverList[0] = "geode"; + /* GX2 support started its life in the NSC tree and was later + forked by AMD for GEODE so we keep it as a backup */ + driverList[1] = "nsc"; + } + else + /* other NSC variant e.g. 0x0104 (SC1400), 0x0504 (SCx200) */ + driverList[0] = "nsc"; + break; + /* Cyrix Geode GX1 */ + case 0x1078: + if (dev->device_id == 0x0104) + driverList[0] = "cyrix"; + break; + case 0x1142: + driverList[0] = "apm"; + break; + case 0xedd8: + driverList[0] = "ark"; + break; + case 0x1a03: + driverList[0] = "ast"; + break; + case 0x1002: + driverList[0] = "ati"; + break; + case 0x102c: + driverList[0] = "chips"; + break; + case 0x1013: + driverList[0] = "cirrus"; + break; + case 0x3d3d: + driverList[0] = "glint"; + break; + case 0x105d: + driverList[0] = "i128"; + break; + case 0x8086: + if ((dev->device_id == 0x00d1) || (dev->device_id == 0x7800)) { + driverList[0] = "i740"; + } + else if (dev->device_id == 0x8108) { + break; /* "hooray" for poulsbo */ + } + else { + driverList[0] = "intel"; + } + break; + case 0x102b: + driverList[0] = "mga"; + break; + case 0x10c8: + driverList[0] = "neomagic"; + break; + case 0x10de: + case 0x12d2: { - /* AMD Geode LX */ - case 0x1022: - if (dev->device_id == 0x2081) - driverList[0] = "geode"; - break; - /* older Geode products acquired by AMD still carry an NSC vendor_id */ - case 0x100b: - if (dev->device_id == 0x0030) { - /* NSC Geode GX2 specifically */ - driverList[0] = "geode"; - /* GX2 support started its life in the NSC tree and was later - forked by AMD for GEODE so we keep it as a backup */ - driverList[1] = "nsc"; - } else - /* other NSC variant e.g. 0x0104 (SC1400), 0x0504 (SCx200) */ - driverList[0] = "nsc"; - break; - /* Cyrix Geode GX1 */ - case 0x1078: - if (dev->device_id == 0x0104) - driverList[0] = "cyrix"; - break; - case 0x1142: driverList[0] = "apm"; break; - case 0xedd8: driverList[0] = "ark"; break; - case 0x1a03: driverList[0] = "ast"; break; - case 0x1002: driverList[0] = "ati"; break; - case 0x102c: driverList[0] = "chips"; break; - case 0x1013: driverList[0] = "cirrus"; break; - case 0x3d3d: driverList[0] = "glint"; break; - case 0x105d: driverList[0] = "i128"; break; - case 0x8086: - if ((dev->device_id == 0x00d1) || (dev->device_id == 0x7800)) { - driverList[0] = "i740"; - } else if (dev->device_id == 0x8108) { - break; /* "hooray" for poulsbo */ - } else { - driverList[0] = "intel"; - } - break; - case 0x102b: driverList[0] = "mga"; break; - case 0x10c8: driverList[0] = "neomagic"; break; - case 0x10de: case 0x12d2: - { - int idx = 0; + int idx = 0; + #ifdef __linux__ - driverList[idx++] = "nouveau"; + driverList[idx++] = "nouveau"; #endif - driverList[idx++] = "nv"; - break; - } - case 0x1106: driverList[0] = "openchrome"; break; - case 0x1b36: driverList[0] = "qxl"; break; - case 0x1163: driverList[0] = "rendition"; break; - case 0x5333: - switch (dev->device_id) - { - case 0x88d0: case 0x88d1: case 0x88f0: case 0x8811: - case 0x8812: case 0x8814: case 0x8901: - driverList[0] = "s3"; break; - case 0x5631: case 0x883d: case 0x8a01: case 0x8a10: - case 0x8c01: case 0x8c03: case 0x8904: case 0x8a13: - driverList[0] = "s3virge"; break; - default: - driverList[0] = "savage"; break; - } - break; - case 0x1039: driverList[0] = "sis"; break; - case 0x126f: driverList[0] = "siliconmotion"; break; - case 0x121a: - if (dev->device_id < 0x0003) - driverList[0] = "voodoo"; - else - driverList[0] = "tdfx"; - break; - case 0x1011: driverList[0] = "tga"; break; - case 0x1023: driverList[0] = "trident"; break; - case 0x100c: driverList[0] = "tseng"; break; - case 0x80ee: driverList[0] = "vboxvideo"; break; - case 0x15ad: driverList[0] = "vmware"; break; - case 0x18ca: - if (dev->device_id == 0x47) - driverList[0] = "xgixp"; - else - driverList[0] = "xgi"; - break; - default: break; + driverList[idx++] = "nv"; + break; + } + case 0x1106: + driverList[0] = "openchrome"; + break; + case 0x1b36: + driverList[0] = "qxl"; + break; + case 0x1163: + driverList[0] = "rendition"; + break; + case 0x5333: + switch (dev->device_id) { + case 0x88d0: + case 0x88d1: + case 0x88f0: + case 0x8811: + case 0x8812: + case 0x8814: + case 0x8901: + driverList[0] = "s3"; + break; + case 0x5631: + case 0x883d: + case 0x8a01: + case 0x8a10: + case 0x8c01: + case 0x8c03: + case 0x8904: + case 0x8a13: + driverList[0] = "s3virge"; + break; + default: + driverList[0] = "savage"; + break; + } + break; + case 0x1039: + driverList[0] = "sis"; + break; + case 0x126f: + driverList[0] = "siliconmotion"; + break; + case 0x121a: + if (dev->device_id < 0x0003) + driverList[0] = "voodoo"; + else + driverList[0] = "tdfx"; + break; + case 0x1011: + driverList[0] = "tga"; + break; + case 0x1023: + driverList[0] = "trident"; + break; + case 0x100c: + driverList[0] = "tseng"; + break; + case 0x80ee: + driverList[0] = "vboxvideo"; + break; + case 0x15ad: + driverList[0] = "vmware"; + break; + case 0x18ca: + if (dev->device_id == 0x47) + driverList[0] = "xgixp"; + else + driverList[0] = "xgi"; + break; + default: + break; } for (i = 0; (i < returnListMax) && (driverList[i] != NULL); i++) { - returnList[i] = xnfstrdup(driverList[i]); + returnList[i] = xnfstrdup(driverList[i]); } - return i; /* Number of entries added */ + return i; /* Number of entries added */ } #ifdef __linux__ @@ -1181,7 +1248,7 @@ xchomp(char *line) * feature it can and should be removed because the symbol-based resolution * scheme should be the primary one */ static void -matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip) +matchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip) { DIR *idsdir; FILE *fp; @@ -1197,7 +1264,9 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip if (!idsdir) return; - xf86Msg(X_INFO, "Scanning %s directory for additional PCI ID's supported by the drivers\n", PCI_TXT_IDS_PATH); + xf86Msg(X_INFO, + "Scanning %s directory for additional PCI ID's supported by the drivers\n", + PCI_TXT_IDS_PATH); direntry = readdir(idsdir); /* Read the directory */ while (direntry) { @@ -1207,63 +1276,72 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip } len = strlen(direntry->d_name); /* A tiny bit of sanity checking. We should probably do better */ - if (strncmp(&(direntry->d_name[len-4]), ".ids", 4) == 0) { + if (strncmp(&(direntry->d_name[len - 4]), ".ids", 4) == 0) { /* We need the full path name to open the file */ snprintf(path_name, sizeof(path_name), "%s/%s", PCI_TXT_IDS_PATH, direntry->d_name); fp = fopen(path_name, "r"); if (fp == NULL) { - xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", path_name); + xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", + path_name); goto end; } /* Read the file */ #ifdef __GLIBC__ while ((read = getline(&line, &len, fp)) != -1) { #else - while ((line = fgetln(fp, &len)) != (char *)NULL) { -#endif /* __GLIBC __ */ + while ((line = fgetln(fp, &len)) != (char *) NULL) { +#endif /* __GLIBC __ */ xchomp(line); if (isdigit(line[0])) { strlcpy(vendor_str, line, sizeof(vendor_str)); - vendor = (int)strtol(vendor_str, NULL, 16); + vendor = (int) strtol(vendor_str, NULL, 16); if ((strlen(&line[4])) == 0) { chip_str[0] = '\0'; chip = -1; - } else { + } + else { /* Handle trailing whitespace */ if (isspace(line[4])) { chip_str[0] = '\0'; chip = -1; - } else { + } + else { /* Ok, it's a real ID */ strlcpy(chip_str, &line[4], sizeof(chip_str)); - chip = (int)strtol(chip_str, NULL, 16); + chip = (int) strtol(chip_str, NULL, 16); } } - if (vendor == match_vendor && chip == match_chip ) { + if (vendor == match_vendor && chip == match_chip) { i = 0; while (matches[i]) { i++; } - matches[i] = (char*)malloc(sizeof(char) * strlen(direntry->d_name) - 3); + matches[i] = + (char *) malloc(sizeof(char) * + strlen(direntry->d_name) - 3); if (!matches[i]) { - xf86Msg(X_ERROR, "Could not allocate space for the module name. Exiting.\n"); + xf86Msg(X_ERROR, + "Could not allocate space for the module name. Exiting.\n"); goto end; } /* hack off the .ids suffix. This should guard * against other problems, but it will end up * taking off anything after the first '.' */ - for (j = 0; j < (strlen(direntry->d_name) - 3) ; j++) { + for (j = 0; j < (strlen(direntry->d_name) - 3); j++) { if (direntry->d_name[j] == '.') { matches[i][j] = '\0'; break; - } else { + } + else { matches[i][j] = direntry->d_name[j]; } } - xf86Msg(X_INFO, "Matched %s from file name %s\n", matches[i], direntry->d_name); + xf86Msg(X_INFO, "Matched %s from file name %s\n", + matches[i], direntry->d_name); } - } else { + } + else { /* TODO Handle driver overrides here */ } } @@ -1275,38 +1353,39 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip free(line); closedir(idsdir); } -#endif /* __linux__ */ +#endif /* __linux__ */ /** * @return The numbers of found devices that match with the current system * drivers. */ int -xf86PciMatchDriver(char* matches[], int nmatches) { +xf86PciMatchDriver(char *matches[], int nmatches) +{ int i; - struct pci_device * info = NULL; + struct pci_device *info = NULL; struct pci_device_iterator *iter; /* Find the primary device, and get some information about it. */ iter = pci_slot_match_iterator_create(NULL); while ((info = pci_device_next(iter)) != NULL) { - if (xf86IsPrimaryPci(info)) { - break; - } + if (xf86IsPrimaryPci(info)) { + break; + } } pci_iterator_destroy(iter); #ifdef __linux__ if (info) - matchDriverFromFiles(matches, info->vendor_id, info->device_id); + matchDriverFromFiles(matches, info->vendor_id, info->device_id); #endif for (i = 0; (i < nmatches) && (matches[i]); i++) { - /* find end of matches list */ + /* find end of matches list */ } if ((info != NULL) && (i < nmatches)) { - i += videoPtrToDriverList(info, &(matches[i]), nmatches - i); + i += videoPtrToDriverList(info, &(matches[i]), nmatches - i); } return i; @@ -1315,14 +1394,13 @@ xf86PciMatchDriver(char* matches[], int nmatches) { Bool xf86PciConfigure(void *busData, struct pci_device *pDev) { - struct pci_device * pVideo = NULL; + struct pci_device *pVideo = NULL; pVideo = (struct pci_device *) busData; if (pDev && (pDev->domain == pVideo->domain) && (pDev->bus == pVideo->bus) && - (pDev->dev == pVideo->dev) && - (pDev->func == pVideo->func)) + (pDev->dev == pVideo->dev) && (pDev->func == pVideo->func)) return 0; return 1; @@ -1330,20 +1408,20 @@ xf86PciConfigure(void *busData, struct pci_device *pDev) void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, - GDevRec *GDev, int *chipset) + GDevRec * GDev, int *chipset) { char busnum[8]; pVideo = (struct pci_device *) busData; if (pVideo->bus < 256) - snprintf(busnum, sizeof(busnum), "%d", pVideo->bus); + snprintf(busnum, sizeof(busnum), "%d", pVideo->bus); else - snprintf(busnum, sizeof(busnum), "%d@%d", - pVideo->bus & 0x00ff, pVideo->bus >> 8); + snprintf(busnum, sizeof(busnum), "%d@%d", + pVideo->bus & 0x00ff, pVideo->bus >> 8); XNFasprintf(&GDev->busID, "PCI:%s:%d:%d", - busnum, pVideo->dev, pVideo->func); + busnum, pVideo->dev, pVideo->func); GDev->chipID = pVideo->device_id; GDev->chipRev = pVideo->revision; diff --git a/xorg-server/hw/xfree86/common/xf86sbusBus.c b/xorg-server/hw/xfree86/common/xf86sbusBus.c index b7bb913fe..c993b603c 100644 --- a/xorg-server/hw/xfree86/common/xf86sbusBus.c +++ b/xorg-server/hw/xfree86/common/xf86sbusBus.c @@ -53,23 +53,24 @@ CheckSbusDevice(const char *device, int fbNum) fd = open(device, O_RDONLY, 0); if (fd < 0) - return; + return; memset(&fbattr, 0, sizeof(fbattr)); if (ioctl(fd, FBIOGATTR, &fbattr) < 0) { - if (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0) { - close(fd); - return; - } + if (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0) { + close(fd); + return; + } } close(fd); for (i = 0; sbusDeviceTable[i].devId; i++) - if (sbusDeviceTable[i].fbType == fbattr.fbtype.fb_type) - break; - if (! sbusDeviceTable[i].devId) - return; - xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (++xf86nSbusInfo + 1)); + if (sbusDeviceTable[i].fbType == fbattr.fbtype.fb_type) + break; + if (!sbusDeviceTable[i].devId) + return; + xf86SbusInfo = + xnfrealloc(xf86SbusInfo, sizeof(psdp) * (++xf86nSbusInfo + 1)); xf86SbusInfo[xf86nSbusInfo] = NULL; - xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof (sbusDevice), 1); + xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof(sbusDevice), 1); psdp->devId = sbusDeviceTable[i].devId; psdp->fbNum = fbNum; psdp->device = xnfstrdup(device); @@ -88,136 +89,154 @@ xf86SbusProbe(void) xf86SbusInfo = malloc(sizeof(psdp)); *xf86SbusInfo = NULL; for (i = 0; i < 32; i++) { - snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i); - CheckSbusDevice(fbDevName, i); + snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i); + CheckSbusDevice(fbDevName, i); } if (sparcPromInit() >= 0) { - useProm = 1; - sparcPromAssignNodes(); + useProm = 1; + sparcPromAssignNodes(); } for (psdpp = xf86SbusInfo; (psdp = *psdpp); psdpp++) { - for (i = 0; sbusDeviceTable[i].devId; i++) - if (sbusDeviceTable[i].devId == psdp->devId) - psdp->descr = sbusDeviceTable[i].descr; - /* - * If we can use PROM information and found the PROM node for this - * device, we can tell more about the card. - */ - if (useProm && psdp->node.node) { - char *prop, *promPath; - int len, chiprev, vmsize; - - switch (psdp->devId) { - case SBUS_DEVICE_MGX: - prop = sparcPromGetProperty(&psdp->node, "fb_size", &len); - if (prop && len == 4 && *(int *)prop == 0x400000) - psdp->descr = "Quantum 3D MGXplus with 4M VRAM"; - break; - case SBUS_DEVICE_CG6: - chiprev = 0; - vmsize = 0; - prop = sparcPromGetProperty(&psdp->node, "chiprev", &len); - if (prop && len == 4) - chiprev = *(int *)prop; - prop = sparcPromGetProperty(&psdp->node, "vmsize", &len); - if (prop && len == 4) - vmsize = *(int *)prop; - switch (chiprev) { - case 1: - case 2: - case 3: - case 4: - psdp->descr = "Sun Double width GX"; break; - case 5: - case 6: - case 7: - case 8: - case 9: - psdp->descr = "Sun Single width GX"; break; - case 11: - switch (vmsize) { - case 2: - psdp->descr = "Sun Turbo GX with 1M VSIMM"; break; - case 4: - psdp->descr = "Sun Turbo GX Plus"; break; - default: - psdp->descr = "Sun Turbo GX"; break; - } - } - break; - case SBUS_DEVICE_CG14: - prop = sparcPromGetProperty(&psdp->node, "reg", &len); - vmsize = 0; - if (prop && !(len % 12) && len > 0) - vmsize = *(int *)(prop + len - 4); - switch (vmsize) { - case 0x400000: - psdp->descr = "Sun SX with 4M VSIMM"; break; - case 0x800000: - psdp->descr = "Sun SX with 8M VSIMM"; break; - } - break; - case SBUS_DEVICE_LEO: - prop = sparcPromGetProperty(&psdp->node, "model", &len); - if (prop && len > 0 && !strstr(prop, "501-2503")) - psdp->descr = "Sun Turbo ZX"; - break; - case SBUS_DEVICE_TCX: - if (sparcPromGetBool(&psdp->node, "tcx-8-bit")) - psdp->descr = "Sun TCX (8bit)"; - else - psdp->descr = "Sun TCX (S24)"; - break; - case SBUS_DEVICE_FFB: - prop = sparcPromGetProperty(&psdp->node, "name", &len); - chiprev = 0; - prop = sparcPromGetProperty(&psdp->node, "board_type", &len); - if (prop && len == 4) - chiprev = *(int *)prop; - if (strstr (prop, "afb")) { - if (chiprev == 3) - psdp->descr = "Sun|Elite3D-M6 Horizontal"; - } else { - switch (chiprev) { - case 0x08: - psdp->descr = "Sun FFB 67MHz Creator"; break; - case 0x0b: - psdp->descr = "Sun FFB 67MHz Creator 3D"; break; - case 0x1b: - psdp->descr = "Sun FFB 75MHz Creator 3D"; break; - case 0x20: - case 0x28: - psdp->descr = "Sun FFB2 Vertical Creator"; break; - case 0x23: - case 0x2b: - psdp->descr = "Sun FFB2 Vertical Creator 3D"; break; - case 0x30: - psdp->descr = "Sun FFB2+ Vertical Creator"; break; - case 0x33: - psdp->descr = "Sun FFB2+ Vertical Creator 3D"; break; - case 0x40: - case 0x48: - psdp->descr = "Sun FFB2 Horizontal Creator"; break; - case 0x43: - case 0x4b: - psdp->descr = "Sun FFB2 Horizontal Creator 3D"; break; - } - } - break; - } - - xf86Msg(X_PROBED, "SBUS:(0x%08x) %s", psdp->node.node, psdp->descr); - promPath = sparcPromNode2Pathname (&psdp->node); - if (promPath) { - xf86ErrorF(" at %s", promPath); - free(promPath); - } - } else - xf86Msg(X_PROBED, "SBUS: %s", psdp->descr); - xf86ErrorF("\n"); + for (i = 0; sbusDeviceTable[i].devId; i++) + if (sbusDeviceTable[i].devId == psdp->devId) + psdp->descr = sbusDeviceTable[i].descr; + /* + * If we can use PROM information and found the PROM node for this + * device, we can tell more about the card. + */ + if (useProm && psdp->node.node) { + char *prop, *promPath; + int len, chiprev, vmsize; + + switch (psdp->devId) { + case SBUS_DEVICE_MGX: + prop = sparcPromGetProperty(&psdp->node, "fb_size", &len); + if (prop && len == 4 && *(int *) prop == 0x400000) + psdp->descr = "Quantum 3D MGXplus with 4M VRAM"; + break; + case SBUS_DEVICE_CG6: + chiprev = 0; + vmsize = 0; + prop = sparcPromGetProperty(&psdp->node, "chiprev", &len); + if (prop && len == 4) + chiprev = *(int *) prop; + prop = sparcPromGetProperty(&psdp->node, "vmsize", &len); + if (prop && len == 4) + vmsize = *(int *) prop; + switch (chiprev) { + case 1: + case 2: + case 3: + case 4: + psdp->descr = "Sun Double width GX"; + break; + case 5: + case 6: + case 7: + case 8: + case 9: + psdp->descr = "Sun Single width GX"; + break; + case 11: + switch (vmsize) { + case 2: + psdp->descr = "Sun Turbo GX with 1M VSIMM"; + break; + case 4: + psdp->descr = "Sun Turbo GX Plus"; + break; + default: + psdp->descr = "Sun Turbo GX"; + break; + } + } + break; + case SBUS_DEVICE_CG14: + prop = sparcPromGetProperty(&psdp->node, "reg", &len); + vmsize = 0; + if (prop && !(len % 12) && len > 0) + vmsize = *(int *) (prop + len - 4); + switch (vmsize) { + case 0x400000: + psdp->descr = "Sun SX with 4M VSIMM"; + break; + case 0x800000: + psdp->descr = "Sun SX with 8M VSIMM"; + break; + } + break; + case SBUS_DEVICE_LEO: + prop = sparcPromGetProperty(&psdp->node, "model", &len); + if (prop && len > 0 && !strstr(prop, "501-2503")) + psdp->descr = "Sun Turbo ZX"; + break; + case SBUS_DEVICE_TCX: + if (sparcPromGetBool(&psdp->node, "tcx-8-bit")) + psdp->descr = "Sun TCX (8bit)"; + else + psdp->descr = "Sun TCX (S24)"; + break; + case SBUS_DEVICE_FFB: + prop = sparcPromGetProperty(&psdp->node, "name", &len); + chiprev = 0; + prop = sparcPromGetProperty(&psdp->node, "board_type", &len); + if (prop && len == 4) + chiprev = *(int *) prop; + if (strstr(prop, "afb")) { + if (chiprev == 3) + psdp->descr = "Sun|Elite3D-M6 Horizontal"; + } + else { + switch (chiprev) { + case 0x08: + psdp->descr = "Sun FFB 67MHz Creator"; + break; + case 0x0b: + psdp->descr = "Sun FFB 67MHz Creator 3D"; + break; + case 0x1b: + psdp->descr = "Sun FFB 75MHz Creator 3D"; + break; + case 0x20: + case 0x28: + psdp->descr = "Sun FFB2 Vertical Creator"; + break; + case 0x23: + case 0x2b: + psdp->descr = "Sun FFB2 Vertical Creator 3D"; + break; + case 0x30: + psdp->descr = "Sun FFB2+ Vertical Creator"; + break; + case 0x33: + psdp->descr = "Sun FFB2+ Vertical Creator 3D"; + break; + case 0x40: + case 0x48: + psdp->descr = "Sun FFB2 Horizontal Creator"; + break; + case 0x43: + case 0x4b: + psdp->descr = "Sun FFB2 Horizontal Creator 3D"; + break; + } + } + break; + } + + xf86Msg(X_PROBED, "SBUS:(0x%08x) %s", psdp->node.node, psdp->descr); + promPath = sparcPromNode2Pathname(&psdp->node); + if (promPath) { + xf86ErrorF(" at %s", promPath); + free(promPath); + } + } + else + xf86Msg(X_PROBED, "SBUS: %s", psdp->descr); + xf86ErrorF("\n"); } if (useProm) - sparcPromClose(); + sparcPromClose(); } /* @@ -240,52 +259,55 @@ xf86ParseSbusBusString(const char *busID, int *fbNum) int i, len; if (StringToBusType(busID, &id) != BUS_SBUS) - return FALSE; + return FALSE; if (*id != '/') { - if (!strncmp (id, "fb", 2)) { - if (!isdigit(id[2])) - return FALSE; - *fbNum = atoi(id + 2); - return TRUE; - } else { - sbusDevicePtr *psdpp; - int devId; - - for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) { - len = strlen(sbusDeviceTable[i].promName); - if (!strncmp (sbusDeviceTable[i].promName, id, len) - && isdigit(id[len])) - break; - } - devId = sbusDeviceTable[i].devId; - if (!devId) return FALSE; - i = atoi(id + len); - for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { - if ((*psdpp)->devId != devId) - continue; - if (!i) { - *fbNum = (*psdpp)->fbNum; - return TRUE; - } - i--; - } - } - return FALSE; + if (!strncmp(id, "fb", 2)) { + if (!isdigit(id[2])) + return FALSE; + *fbNum = atoi(id + 2); + return TRUE; + } + else { + sbusDevicePtr *psdpp; + int devId; + + for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) { + len = strlen(sbusDeviceTable[i].promName); + if (!strncmp(sbusDeviceTable[i].promName, id, len) + && isdigit(id[len])) + break; + } + devId = sbusDeviceTable[i].devId; + if (!devId) + return FALSE; + i = atoi(id + len); + for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { + if ((*psdpp)->devId != devId) + continue; + if (!i) { + *fbNum = (*psdpp)->fbNum; + return TRUE; + } + i--; + } + } + return FALSE; } if (sparcPromInit() >= 0) { - i = sparcPromPathname2Node(id); - sparcPromClose(); - if (i) { - sbusDevicePtr *psdpp; - for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { - if ((*psdpp)->node.node == i) { - *fbNum = (*psdpp)->fbNum; - return TRUE; - } - } - } + i = sparcPromPathname2Node(id); + sparcPromClose(); + if (i) { + sbusDevicePtr *psdpp; + + for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { + if ((*psdpp)->node.node == i) { + *fbNum = (*psdpp)->fbNum; + return TRUE; + } + } + } } return FALSE; } @@ -300,9 +322,10 @@ xf86CompareSbusBusString(const char *busID, int fbNum) int iFbNum; if (xf86ParseSbusBusString(busID, &iFbNum)) { - return fbNum == iFbNum; - } else { - return FALSE; + return fbNum == iFbNum; + } + else { + return FALSE; } } @@ -317,10 +340,10 @@ xf86CheckSbusSlot(int fbNum) EntityPtr p; for (i = 0; i < xf86NumEntities; i++) { - p = xf86Entities[i]; - /* Check if this SBUS slot is taken */ - if (p->bus.type == BUS_SBUS && p->bus.id.sbus.fbNum == fbNum) - return FALSE; + p = xf86Entities[i]; + /* Check if this SBUS slot is taken */ + if (p->bus.type == BUS_SBUS && p->bus.id.sbus.fbNum == fbNum) + return FALSE; } return TRUE; @@ -332,8 +355,7 @@ xf86CheckSbusSlot(int fbNum) */ int -xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp, - GDevPtr dev, Bool active) +xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp, GDevPtr dev, Bool active) { EntityPtr p = NULL; @@ -349,18 +371,19 @@ xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp, p->bus.id.sbus.fbNum = psdp->fbNum; p->active = active; p->inUse = FALSE; - sbusSlotClaimed = TRUE; - return num; - } else - return -1; + sbusSlotClaimed = TRUE; + return num; + } + else + return -1; } int -xf86MatchSbusInstances(const char *driverName, int sbusDevId, - GDevPtr *devList, int numDevs, DriverPtr drvp, - int **foundEntities) +xf86MatchSbusInstances(const char *driverName, int sbusDevId, + GDevPtr * devList, int numDevs, DriverPtr drvp, + int **foundEntities) { - int i,j; + int i, j; sbusDevicePtr psdp, *psdpp; int numClaimedInstances = 0; int allocatedInstances = 0; @@ -371,24 +394,24 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId, int useProm = 0; struct Inst { - sbusDevicePtr sbus; - GDevPtr dev; - Bool claimed; /* BusID matches with a device section */ + sbusDevicePtr sbus; + GDevPtr dev; + Bool claimed; /* BusID matches with a device section */ } *instances = NULL; *foundEntities = NULL; for (psdpp = xf86SbusInfo, psdp = *psdpp; psdp; psdp = *++psdpp) { - if (psdp->devId != sbusDevId) - continue; - if (psdp->fd == -2) - continue; - ++allocatedInstances; - instances = xnfrealloc(instances, - allocatedInstances * sizeof(struct Inst)); - instances[allocatedInstances - 1].sbus = psdp; - instances[allocatedInstances - 1].dev = NULL; - instances[allocatedInstances - 1].claimed = FALSE; - numFound++; + if (psdp->devId != sbusDevId) + continue; + if (psdp->fd == -2) + continue; + ++allocatedInstances; + instances = xnfrealloc(instances, + allocatedInstances * sizeof(struct Inst)); + instances[allocatedInstances - 1].sbus = psdp; + instances[allocatedInstances - 1].dev = NULL; + instances[allocatedInstances - 1].claimed = FALSE; + numFound++; } /* @@ -397,88 +420,97 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId, * allow the config file to override this. */ if (allocatedInstances <= 0) { - free(instances); - return 0; + free(instances); + return 0; } if (sparcPromInit() >= 0) - useProm = 1; + useProm = 1; if (xf86DoConfigure && xf86DoConfigurePass1) { - GDevPtr pGDev; - int actualcards = 0; - for (i = 0; i < allocatedInstances; i++) { - actualcards++; - pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, BUS_SBUS, - instances[i].sbus, -1); - if (pGDev) { - /* - * XF86Match???Instances() treat chipID and chipRev as - * overrides, so clobber them here. - */ - pGDev->chipID = pGDev->chipRev = -1; - } - } - free(instances); - if (useProm) - sparcPromClose(); - return actualcards; + GDevPtr pGDev; + int actualcards = 0; + + for (i = 0; i < allocatedInstances; i++) { + actualcards++; + pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, BUS_SBUS, + instances[i].sbus, -1); + if (pGDev) { + /* + * XF86Match???Instances() treat chipID and chipRev as + * overrides, so clobber them here. + */ + pGDev->chipID = pGDev->chipRev = -1; + } + } + free(instances); + if (useProm) + sparcPromClose(); + return actualcards; } DebugF("%s instances found: %d\n", driverName, allocatedInstances); for (i = 0; i < allocatedInstances; i++) { - char *promPath = NULL; - - psdp = instances[i].sbus; - devBus = NULL; - dev = NULL; - if (useProm && psdp->node.node) - promPath = sparcPromNode2Pathname(&psdp->node); - - for (j = 0; j < numDevs; j++) { - if (devList[j]->busID && *devList[j]->busID) { - if (xf86CompareSbusBusString(devList[j]->busID, psdp->fbNum)) { - if (devBus) - xf86MsgVerb(X_WARNING,0, - "%s: More than one matching Device section for " - "instance (BusID: %s) found: %s\n", - driverName,devList[j]->identifier, - devList[j]->busID); - else - devBus = devList[j]; - } - } else { - if (!dev && !devBus) { - if (promPath) - xf86Msg(X_PROBED, "Assigning device section with no busID to SBUS:%s\n", - promPath); - else - xf86Msg(X_PROBED, "Assigning device section with no busID to SBUS:fb%d\n", - psdp->fbNum); - dev = devList[j]; - } else - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section " - "found: %s\n", driverName, devList[j]->identifier); - } - } - if (devBus) dev = devBus; /* busID preferred */ - if (!dev && psdp->fd != -2) { - if (promPath) { - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID SBUS:%s) found\n", - driverName, promPath); - } else - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID SBUS:fb%d) found\n", - driverName, psdp->fbNum); - } else if (dev) { - numClaimedInstances++; - instances[i].claimed = TRUE; - instances[i].dev = dev; - } - free(promPath); + char *promPath = NULL; + + psdp = instances[i].sbus; + devBus = NULL; + dev = NULL; + if (useProm && psdp->node.node) + promPath = sparcPromNode2Pathname(&psdp->node); + + for (j = 0; j < numDevs; j++) { + if (devList[j]->busID && *devList[j]->busID) { + if (xf86CompareSbusBusString(devList[j]->busID, psdp->fbNum)) { + if (devBus) + xf86MsgVerb(X_WARNING, 0, + "%s: More than one matching Device section for " + "instance (BusID: %s) found: %s\n", + driverName, devList[j]->identifier, + devList[j]->busID); + else + devBus = devList[j]; + } + } + else { + if (!dev && !devBus) { + if (promPath) + xf86Msg(X_PROBED, + "Assigning device section with no busID to SBUS:%s\n", + promPath); + else + xf86Msg(X_PROBED, + "Assigning device section with no busID to SBUS:fb%d\n", + psdp->fbNum); + dev = devList[j]; + } + else + xf86MsgVerb(X_WARNING, 0, + "%s: More than one matching Device section " + "found: %s\n", driverName, + devList[j]->identifier); + } + } + if (devBus) + dev = devBus; /* busID preferred */ + if (!dev && psdp->fd != -2) { + if (promPath) { + xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " + "for instance (BusID SBUS:%s) found\n", + driverName, promPath); + } + else + xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " + "for instance (BusID SBUS:fb%d) found\n", + driverName, psdp->fbNum); + } + else if (dev) { + numClaimedInstances++; + instances[i].claimed = TRUE; + instances[i].dev = dev; + } + free(promPath); } DebugF("%s instances found: %d\n", driverName, numClaimedInstances); @@ -489,29 +521,29 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId, */ numFound = 0; for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - if (!instances[i].claimed) - continue; - psdp = instances[i].sbus; - if (!xf86CheckSbusSlot(psdp->fbNum)) - continue; - - DebugF("%s: card at fb%d %08x is claimed by a Device section\n", - driverName, psdp->fbNum, psdp->node.node); - - /* Allocate an entry in the lists to be returned */ - numFound++; - retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); - retEntities[numFound - 1] - = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev,instances[i].dev->active ? - TRUE : FALSE); + if (!instances[i].claimed) + continue; + psdp = instances[i].sbus; + if (!xf86CheckSbusSlot(psdp->fbNum)) + continue; + + DebugF("%s: card at fb%d %08x is claimed by a Device section\n", + driverName, psdp->fbNum, psdp->node.node); + + /* Allocate an entry in the lists to be returned */ + numFound++; + retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); + retEntities[numFound - 1] + = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev, + instances[i].dev->active ? TRUE : FALSE); } free(instances); if (numFound > 0) { - *foundEntities = retEntities; + *foundEntities = retEntities; } if (useProm) - sparcPromClose(); + sparcPromClose(); return numFound; } @@ -525,12 +557,12 @@ xf86GetSbusInfoForEntity(int entityIndex) sbusDevicePtr *psdpp; EntityPtr p = xf86Entities[entityIndex]; - if (entityIndex >= xf86NumEntities - || p->bus.type != BUS_SBUS) return NULL; + if (entityIndex >= xf86NumEntities || p->bus.type != BUS_SBUS) + return NULL; for (psdpp = xf86SbusInfo; *psdpp != NULL; psdpp++) { - if (p->bus.id.sbus.fbNum == (*psdpp)->fbNum) - return *psdpp; + if (p->bus.id.sbus.fbNum == (*psdpp)->fbNum) + return *psdpp; } return NULL; } @@ -541,11 +573,13 @@ xf86GetEntityForSbusInfo(sbusDevicePtr psdp) int i; for (i = 0; i < xf86NumEntities; i++) { - EntityPtr p = xf86Entities[i]; - if (p->bus.type != BUS_SBUS) continue; + EntityPtr p = xf86Entities[i]; - if (p->bus.id.sbus.fbNum == psdp->fbNum) - return i; + if (p->bus.type != BUS_SBUS) + continue; + + if (p->bus.id.sbus.fbNum == psdp->fbNum) + return i; } return -1; } @@ -601,32 +635,33 @@ typedef struct _sbusCmap { static void xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO *colors, VisualPtr pVisual) + LOCO * colors, VisualPtr pVisual) { int i, index; sbusCmapPtr cmap; struct fbcmap fbcmap; - unsigned char *data = malloc(numColors*3); - + unsigned char *data = malloc(numColors * 3); + cmap = SBUSCMAPPTR(pScrn->pScreen); - if (!cmap) return; + if (!cmap) + return; fbcmap.count = 0; fbcmap.index = indices[0]; fbcmap.red = data; fbcmap.green = data + numColors; fbcmap.blue = fbcmap.green + numColors; for (i = 0; i < numColors; i++) { - index = indices[i]; - if (fbcmap.count && index != fbcmap.index + fbcmap.count) { - ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); - fbcmap.count = 0; - fbcmap.index = index; - } - fbcmap.red[fbcmap.count] = colors[index].red; - fbcmap.green[fbcmap.count] = colors[index].green; - fbcmap.blue[fbcmap.count++] = colors[index].blue; + index = indices[i]; + if (fbcmap.count && index != fbcmap.index + fbcmap.count) { + ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); + fbcmap.count = 0; + fbcmap.index = index; + } + fbcmap.red[fbcmap.count] = colors[index].red; + fbcmap.green[fbcmap.count] = colors[index].green; + fbcmap.blue[fbcmap.count++] = colors[index].blue; } - ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); + ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); free(data); } @@ -635,20 +670,20 @@ xf86SbusCmapCloseScreen(int i, ScreenPtr pScreen) { sbusCmapPtr cmap; struct fbcmap fbcmap; - + cmap = SBUSCMAPPTR(pScreen); if (cmap->origCmapValid) { - fbcmap.index = 0; - fbcmap.count = 16; - fbcmap.red = cmap->origRed; - fbcmap.green = cmap->origGreen; - fbcmap.blue = cmap->origBlue; - ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); + fbcmap.index = 0; + fbcmap.count = 16; + fbcmap.red = cmap->origRed; + fbcmap.green = cmap->origGreen; + fbcmap.blue = cmap->origBlue; + ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); } pScreen->CloseScreen = cmap->CloseScreen; free(cmap); return (*pScreen->CloseScreen) (i, pScreen); -} +} Bool xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp) @@ -665,25 +700,26 @@ xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp) fbcmap.red = cmap->origRed; fbcmap.green = cmap->origGreen; fbcmap.blue = cmap->origBlue; - if (ioctl (psdp->fd, FBIOGETCMAP, &fbcmap) >= 0) - cmap->origCmapValid = TRUE; + if (ioctl(psdp->fd, FBIOGETCMAP, &fbcmap) >= 0) + cmap->origCmapValid = TRUE; fbcmap.index = 0; fbcmap.count = 2; fbcmap.red = data; fbcmap.green = data; fbcmap.blue = data; if (pScreen->whitePixel == 0) { - data[0] = 255; - data[1] = 0; - } else { - data[0] = 0; - data[1] = 255; + data[0] = 255; + data[1] = 0; + } + else { + data[0] = 0; + data[1] = 255; } - ioctl (psdp->fd, FBIOPUTCMAP, &fbcmap); + ioctl(psdp->fd, FBIOPUTCMAP, &fbcmap); cmap->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = xf86SbusCmapCloseScreen; return xf86HandleColormaps(pScreen, 256, 8, - xf86SbusCmapLoadPalette, NULL, 0); + xf86SbusCmapLoadPalette, NULL, 0); } Bool @@ -695,7 +731,7 @@ xf86SbusConfigure(void *busData, sbusDevicePtr sBus) } void -xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev) +xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec * GDev) { char *promPath = NULL; @@ -708,7 +744,8 @@ xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev) if (promPath) { XNFasprintf(&GDev->busID, "SBUS:%s", promPath); free(promPath); - } else { + } + else { XNFasprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum); } } diff --git a/xorg-server/hw/xfree86/common/xf86sbusBus.h b/xorg-server/hw/xfree86/common/xf86sbusBus.h index e210770db..a4d9c6cde 100644 --- a/xorg-server/hw/xfree86/common/xf86sbusBus.h +++ b/xorg-server/hw/xfree86/common/xf86sbusBus.h @@ -1,104 +1,111 @@ -/*
- * SBUS bus-specific declarations
- *
- * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _XF86_SBUSBUS_H
-#define _XF86_SBUSBUS_H
-
-#include "xf86str.h"
-
-#define SBUS_DEVICE_BW2 0x0001
-#define SBUS_DEVICE_CG2 0x0002
-#define SBUS_DEVICE_CG3 0x0003
-#define SBUS_DEVICE_CG4 0x0004
-#define SBUS_DEVICE_CG6 0x0005
-#define SBUS_DEVICE_CG8 0x0006
-#define SBUS_DEVICE_CG12 0x0007
-#define SBUS_DEVICE_CG14 0x0008
-#define SBUS_DEVICE_LEO 0x0009
-#define SBUS_DEVICE_TCX 0x000a
-#define SBUS_DEVICE_FFB 0x000b
-#define SBUS_DEVICE_GT 0x000c
-#define SBUS_DEVICE_MGX 0x000d
-
-typedef struct sbus_prom_node {
- int node;
- /* Because of misdesigned openpromio */
- int cookie[2];
-} sbusPromNode, *sbusPromNodePtr;
-
-typedef struct sbus_device {
- int devId;
- int fbNum;
- int fd;
- int width, height;
- sbusPromNode node;
- char *descr;
- char *device;
-} sbusDevice, *sbusDevicePtr;
-
-struct sbus_devtable {
- int devId;
- int fbType;
- char *promName;
- char *driverName;
- char *descr;
-};
-
-extern _X_EXPORT void xf86SbusProbe(void);
-extern _X_EXPORT sbusDevicePtr *xf86SbusInfo;
-extern _X_EXPORT struct sbus_devtable sbusDeviceTable[];
-
-extern _X_EXPORT int xf86MatchSbusInstances(const char *driverName, int sbusDevId,
- GDevPtr *devList, int numDevs, DriverPtr drvp,
- int **foundEntities);
-extern _X_EXPORT sbusDevicePtr xf86GetSbusInfoForEntity(int entityIndex);
-extern _X_EXPORT int xf86GetEntityForSbusInfo(sbusDevicePtr psdp);
-extern _X_EXPORT void xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp);
-extern _X_EXPORT pointer xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset,
- unsigned long size);
-extern _X_EXPORT void xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size);
-extern _X_EXPORT void xf86SbusHideOsHwCursor(sbusDevicePtr psdp);
-extern _X_EXPORT void xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg);
-extern _X_EXPORT Bool xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp);
-
-extern _X_EXPORT int promRootNode;
-
-extern _X_EXPORT int promGetSibling(int node);
-extern _X_EXPORT int promGetChild(int node);
-extern _X_EXPORT char * promGetProperty(const char *prop, int *lenp);
-extern _X_EXPORT int promGetBool(const char *prop);
-
-extern _X_EXPORT int sparcPromInit(void);
-extern _X_EXPORT void sparcPromClose(void);
-extern _X_EXPORT char * sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp);
-extern _X_EXPORT int sparcPromGetBool(sbusPromNodePtr pnode, const char *prop);
-extern _X_EXPORT void sparcPromAssignNodes(void);
-extern _X_EXPORT char * sparcPromNode2Pathname(sbusPromNodePtr pnode);
-extern _X_EXPORT int sparcPromPathname2Node(const char *pathName);
-extern _X_EXPORT char *sparcDriverName(void);
-
-extern Bool xf86SbusConfigure(void *busData, sbusDevicePtr sBus);
-extern void xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus,
- GDevRec *GDev);
-
-#endif /* _XF86_SBUSBUS_H */
+/* + * SBUS bus-specific declarations + * + * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _XF86_SBUSBUS_H +#define _XF86_SBUSBUS_H + +#include "xf86str.h" + +#define SBUS_DEVICE_BW2 0x0001 +#define SBUS_DEVICE_CG2 0x0002 +#define SBUS_DEVICE_CG3 0x0003 +#define SBUS_DEVICE_CG4 0x0004 +#define SBUS_DEVICE_CG6 0x0005 +#define SBUS_DEVICE_CG8 0x0006 +#define SBUS_DEVICE_CG12 0x0007 +#define SBUS_DEVICE_CG14 0x0008 +#define SBUS_DEVICE_LEO 0x0009 +#define SBUS_DEVICE_TCX 0x000a +#define SBUS_DEVICE_FFB 0x000b +#define SBUS_DEVICE_GT 0x000c +#define SBUS_DEVICE_MGX 0x000d + +typedef struct sbus_prom_node { + int node; + /* Because of misdesigned openpromio */ + int cookie[2]; +} sbusPromNode, *sbusPromNodePtr; + +typedef struct sbus_device { + int devId; + int fbNum; + int fd; + int width, height; + sbusPromNode node; + char *descr; + char *device; +} sbusDevice, *sbusDevicePtr; + +struct sbus_devtable { + int devId; + int fbType; + char *promName; + char *driverName; + char *descr; +}; + +extern _X_EXPORT void xf86SbusProbe(void); +extern _X_EXPORT sbusDevicePtr *xf86SbusInfo; +extern _X_EXPORT struct sbus_devtable sbusDeviceTable[]; + +extern _X_EXPORT int xf86MatchSbusInstances(const char *driverName, + int sbusDevId, GDevPtr * devList, + int numDevs, DriverPtr drvp, + int **foundEntities); +extern _X_EXPORT sbusDevicePtr xf86GetSbusInfoForEntity(int entityIndex); +extern _X_EXPORT int xf86GetEntityForSbusInfo(sbusDevicePtr psdp); +extern _X_EXPORT void xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, + sbusDevicePtr psdp); +extern _X_EXPORT pointer xf86MapSbusMem(sbusDevicePtr psdp, + unsigned long offset, + unsigned long size); +extern _X_EXPORT void xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, + unsigned long size); +extern _X_EXPORT void xf86SbusHideOsHwCursor(sbusDevicePtr psdp); +extern _X_EXPORT void xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, + int fg); +extern _X_EXPORT Bool xf86SbusHandleColormaps(ScreenPtr pScreen, + sbusDevicePtr psdp); + +extern _X_EXPORT int promRootNode; + +extern _X_EXPORT int promGetSibling(int node); +extern _X_EXPORT int promGetChild(int node); +extern _X_EXPORT char *promGetProperty(const char *prop, int *lenp); +extern _X_EXPORT int promGetBool(const char *prop); + +extern _X_EXPORT int sparcPromInit(void); +extern _X_EXPORT void sparcPromClose(void); +extern _X_EXPORT char *sparcPromGetProperty(sbusPromNodePtr pnode, + const char *prop, int *lenp); +extern _X_EXPORT int sparcPromGetBool(sbusPromNodePtr pnode, const char *prop); +extern _X_EXPORT void sparcPromAssignNodes(void); +extern _X_EXPORT char *sparcPromNode2Pathname(sbusPromNodePtr pnode); +extern _X_EXPORT int sparcPromPathname2Node(const char *pathName); +extern _X_EXPORT char *sparcDriverName(void); + +extern Bool xf86SbusConfigure(void *busData, sbusDevicePtr sBus); +extern void xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, + GDevRec * GDev); + +#endif /* _XF86_SBUSBUS_H */ diff --git a/xorg-server/hw/xfree86/common/xf86str.h b/xorg-server/hw/xfree86/common/xf86str.h index e2ca55875..6294845bc 100644 --- a/xorg-server/hw/xfree86/common/xf86str.h +++ b/xorg-server/hw/xfree86/common/xf86str.h @@ -55,139 +55,138 @@ typedef uint64_t memType; typedef uintptr_t memType; #endif - /* Video mode flags */ typedef enum { - V_PHSYNC = 0x0001, - V_NHSYNC = 0x0002, - V_PVSYNC = 0x0004, - V_NVSYNC = 0x0008, - V_INTERLACE = 0x0010, - V_DBLSCAN = 0x0020, - V_CSYNC = 0x0040, - V_PCSYNC = 0x0080, - V_NCSYNC = 0x0100, - V_HSKEW = 0x0200, /* hskew provided */ - V_BCAST = 0x0400, - V_PIXMUX = 0x1000, - V_DBLCLK = 0x2000, - V_CLKDIV2 = 0x4000 + V_PHSYNC = 0x0001, + V_NHSYNC = 0x0002, + V_PVSYNC = 0x0004, + V_NVSYNC = 0x0008, + V_INTERLACE = 0x0010, + V_DBLSCAN = 0x0020, + V_CSYNC = 0x0040, + V_PCSYNC = 0x0080, + V_NCSYNC = 0x0100, + V_HSKEW = 0x0200, /* hskew provided */ + V_BCAST = 0x0400, + V_PIXMUX = 0x1000, + V_DBLCLK = 0x2000, + V_CLKDIV2 = 0x4000 } ModeFlags; typedef enum { - INTERLACE_HALVE_V = 0x0001 /* Halve V values for interlacing */ + INTERLACE_HALVE_V = 0x0001 /* Halve V values for interlacing */ } CrtcAdjustFlags; /* Flags passed to ChipValidMode() */ typedef enum { MODECHECK_INITIAL = 0, - MODECHECK_FINAL = 1 + MODECHECK_FINAL = 1 } ModeCheckFlags; /* These are possible return values for xf86CheckMode() and ValidMode() */ typedef enum { - MODE_OK = 0, /* Mode OK */ - MODE_HSYNC, /* hsync out of range */ - MODE_VSYNC, /* vsync out of range */ - MODE_H_ILLEGAL, /* mode has illegal horizontal timings */ - MODE_V_ILLEGAL, /* mode has illegal horizontal timings */ - MODE_BAD_WIDTH, /* requires an unsupported linepitch */ - MODE_NOMODE, /* no mode with a maching name */ - MODE_NO_INTERLACE, /* interlaced mode not supported */ - MODE_NO_DBLESCAN, /* doublescan mode not supported */ - MODE_NO_VSCAN, /* multiscan mode not supported */ - MODE_MEM, /* insufficient video memory */ - MODE_VIRTUAL_X, /* mode width too large for specified virtual size */ - MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */ - MODE_MEM_VIRT, /* insufficient video memory given virtual size */ - MODE_NOCLOCK, /* no fixed clock available */ - MODE_CLOCK_HIGH, /* clock required is too high */ - MODE_CLOCK_LOW, /* clock required is too low */ - MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */ - MODE_BAD_HVALUE, /* horizontal timing was out of range */ - MODE_BAD_VVALUE, /* vertical timing was out of range */ - MODE_BAD_VSCAN, /* VScan value out of range */ - MODE_HSYNC_NARROW, /* horizontal sync too narrow */ - MODE_HSYNC_WIDE, /* horizontal sync too wide */ - MODE_HBLANK_NARROW, /* horizontal blanking too narrow */ - MODE_HBLANK_WIDE, /* horizontal blanking too wide */ - MODE_VSYNC_NARROW, /* vertical sync too narrow */ - MODE_VSYNC_WIDE, /* vertical sync too wide */ - MODE_VBLANK_NARROW, /* vertical blanking too narrow */ - MODE_VBLANK_WIDE, /* vertical blanking too wide */ - MODE_PANEL, /* exceeds panel dimensions */ - MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */ - MODE_ONE_WIDTH, /* only one width is supported */ - MODE_ONE_HEIGHT, /* only one height is supported */ - MODE_ONE_SIZE, /* only one resolution is supported */ - MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */ - MODE_BANDWIDTH, /* mode requires too much memory bandwidth */ - MODE_BAD = -2, /* unspecified reason */ - MODE_ERROR = -1 /* error condition */ + MODE_OK = 0, /* Mode OK */ + MODE_HSYNC, /* hsync out of range */ + MODE_VSYNC, /* vsync out of range */ + MODE_H_ILLEGAL, /* mode has illegal horizontal timings */ + MODE_V_ILLEGAL, /* mode has illegal horizontal timings */ + MODE_BAD_WIDTH, /* requires an unsupported linepitch */ + MODE_NOMODE, /* no mode with a maching name */ + MODE_NO_INTERLACE, /* interlaced mode not supported */ + MODE_NO_DBLESCAN, /* doublescan mode not supported */ + MODE_NO_VSCAN, /* multiscan mode not supported */ + MODE_MEM, /* insufficient video memory */ + MODE_VIRTUAL_X, /* mode width too large for specified virtual size */ + MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */ + MODE_MEM_VIRT, /* insufficient video memory given virtual size */ + MODE_NOCLOCK, /* no fixed clock available */ + MODE_CLOCK_HIGH, /* clock required is too high */ + MODE_CLOCK_LOW, /* clock required is too low */ + MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */ + MODE_BAD_HVALUE, /* horizontal timing was out of range */ + MODE_BAD_VVALUE, /* vertical timing was out of range */ + MODE_BAD_VSCAN, /* VScan value out of range */ + MODE_HSYNC_NARROW, /* horizontal sync too narrow */ + MODE_HSYNC_WIDE, /* horizontal sync too wide */ + MODE_HBLANK_NARROW, /* horizontal blanking too narrow */ + MODE_HBLANK_WIDE, /* horizontal blanking too wide */ + MODE_VSYNC_NARROW, /* vertical sync too narrow */ + MODE_VSYNC_WIDE, /* vertical sync too wide */ + MODE_VBLANK_NARROW, /* vertical blanking too narrow */ + MODE_VBLANK_WIDE, /* vertical blanking too wide */ + MODE_PANEL, /* exceeds panel dimensions */ + MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */ + MODE_ONE_WIDTH, /* only one width is supported */ + MODE_ONE_HEIGHT, /* only one height is supported */ + MODE_ONE_SIZE, /* only one resolution is supported */ + MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */ + MODE_BANDWIDTH, /* mode requires too much memory bandwidth */ + MODE_BAD = -2, /* unspecified reason */ + MODE_ERROR = -1 /* error condition */ } ModeStatus; /* * The mode sets are, from best to worst: USERDEF, DRIVER, and DEFAULT/BUILTIN. * Preferred will bubble a mode to the top within a set. */ -# define M_T_BUILTIN 0x01 /* built-in mode */ -# define M_T_CLOCK_C (0x02 | M_T_BUILTIN) /* built-in mode - configure clock */ -# define M_T_CRTC_C (0x04 | M_T_BUILTIN) /* built-in mode - configure CRTC */ -# define M_T_CLOCK_CRTC_C (M_T_CLOCK_C | M_T_CRTC_C) +#define M_T_BUILTIN 0x01 /* built-in mode */ +#define M_T_CLOCK_C (0x02 | M_T_BUILTIN) /* built-in mode - configure clock */ +#define M_T_CRTC_C (0x04 | M_T_BUILTIN) /* built-in mode - configure CRTC */ +#define M_T_CLOCK_CRTC_C (M_T_CLOCK_C | M_T_CRTC_C) /* built-in mode - configure CRTC and clock */ -# define M_T_PREFERRED 0x08 /* preferred mode within a set */ -# define M_T_DEFAULT 0x10 /* (VESA) default modes */ -# define M_T_USERDEF 0x20 /* One of the modes from the config file */ -# define M_T_DRIVER 0x40 /* Supplied by the driver (EDID, etc) */ -# define M_T_USERPREF 0x80 /* mode preferred by the user config */ +#define M_T_PREFERRED 0x08 /* preferred mode within a set */ +#define M_T_DEFAULT 0x10 /* (VESA) default modes */ +#define M_T_USERDEF 0x20 /* One of the modes from the config file */ +#define M_T_DRIVER 0x40 /* Supplied by the driver (EDID, etc) */ +#define M_T_USERPREF 0x80 /* mode preferred by the user config */ /* Video mode */ typedef struct _DisplayModeRec { - struct _DisplayModeRec * prev; - struct _DisplayModeRec * next; - char * name; /* identifier for the mode */ - ModeStatus status; - int type; + struct _DisplayModeRec *prev; + struct _DisplayModeRec *next; + char *name; /* identifier for the mode */ + ModeStatus status; + int type; /* These are the values that the user sees/provides */ - int Clock; /* pixel clock freq (kHz) */ - int HDisplay; /* horizontal timing */ - int HSyncStart; - int HSyncEnd; - int HTotal; - int HSkew; - int VDisplay; /* vertical timing */ - int VSyncStart; - int VSyncEnd; - int VTotal; - int VScan; - int Flags; - - /* These are the values the hardware uses */ - int ClockIndex; - int SynthClock; /* Actual clock freq to - * be programmed (kHz) */ - int CrtcHDisplay; - int CrtcHBlankStart; - int CrtcHSyncStart; - int CrtcHSyncEnd; - int CrtcHBlankEnd; - int CrtcHTotal; - int CrtcHSkew; - int CrtcVDisplay; - int CrtcVBlankStart; - int CrtcVSyncStart; - int CrtcVSyncEnd; - int CrtcVBlankEnd; - int CrtcVTotal; - Bool CrtcHAdjusted; - Bool CrtcVAdjusted; - int PrivSize; - INT32 * Private; - int PrivFlags; - - float HSync, VRefresh; + int Clock; /* pixel clock freq (kHz) */ + int HDisplay; /* horizontal timing */ + int HSyncStart; + int HSyncEnd; + int HTotal; + int HSkew; + int VDisplay; /* vertical timing */ + int VSyncStart; + int VSyncEnd; + int VTotal; + int VScan; + int Flags; + + /* These are the values the hardware uses */ + int ClockIndex; + int SynthClock; /* Actual clock freq to + * be programmed (kHz) */ + int CrtcHDisplay; + int CrtcHBlankStart; + int CrtcHSyncStart; + int CrtcHSyncEnd; + int CrtcHBlankEnd; + int CrtcHTotal; + int CrtcHSkew; + int CrtcVDisplay; + int CrtcVBlankStart; + int CrtcVSyncStart; + int CrtcVSyncEnd; + int CrtcVBlankEnd; + int CrtcVTotal; + Bool CrtcHAdjusted; + Bool CrtcVAdjusted; + int PrivSize; + INT32 *Private; + int PrivFlags; + + float HSync, VRefresh; } DisplayModeRec, *DisplayModePtr; /* The monitor description */ @@ -195,11 +194,17 @@ typedef struct _DisplayModeRec { #define MAX_HSYNC 8 #define MAX_VREFRESH 8 -typedef struct { float hi, lo; } range; +typedef struct { + float hi, lo; +} range; -typedef struct { CARD32 red, green, blue; } rgb; +typedef struct { + CARD32 red, green, blue; +} rgb; -typedef struct { float red, green, blue; } Gamma; +typedef struct { + float red, green, blue; +} Gamma; /* The permitted gamma range is 1 / GAMMA_MAX <= g <= GAMMA_MAX */ #define GAMMA_MAX 10.0 @@ -207,35 +212,35 @@ typedef struct { float red, green, blue; } Gamma; #define GAMMA_ZERO (GAMMA_MIN / 100.0) typedef struct { - char * id; - char * vendor; - char * model; - int nHsync; - range hsync[MAX_HSYNC]; - int nVrefresh; - range vrefresh[MAX_VREFRESH]; - DisplayModePtr Modes; /* Start of the monitor's mode list */ - DisplayModePtr Last; /* End of the monitor's mode list */ - Gamma gamma; /* Gamma of the monitor */ - int widthmm; - int heightmm; - pointer options; - pointer DDC; - Bool reducedblanking; /* Allow CVT reduced blanking modes? */ - int maxPixClock; /* in kHz, like mode->Clock */ + char *id; + char *vendor; + char *model; + int nHsync; + range hsync[MAX_HSYNC]; + int nVrefresh; + range vrefresh[MAX_VREFRESH]; + DisplayModePtr Modes; /* Start of the monitor's mode list */ + DisplayModePtr Last; /* End of the monitor's mode list */ + Gamma gamma; /* Gamma of the monitor */ + int widthmm; + int heightmm; + pointer options; + pointer DDC; + Bool reducedblanking; /* Allow CVT reduced blanking modes? */ + int maxPixClock; /* in kHz, like mode->Clock */ } MonRec, *MonPtr; /* the list of clock ranges */ typedef struct x_ClockRange { struct x_ClockRange *next; - int minClock; /* (kHz) */ - int maxClock; /* (kHz) */ - int clockIndex; /* -1 for programmable clocks */ - Bool interlaceAllowed; - Bool doubleScanAllowed; - int ClockMulFactor; - int ClockDivFactor; - int PrivFlags; + int minClock; /* (kHz) */ + int maxClock; /* (kHz) */ + int clockIndex; /* -1 for programmable clocks */ + Bool interlaceAllowed; + Bool doubleScanAllowed; + int ClockMulFactor; + int ClockDivFactor; + int PrivFlags; } ClockRange, *ClockRangePtr; /* @@ -254,8 +259,7 @@ typedef enum { GET_REQUIRED_HW_INTERFACES = 10 } xorgDriverFuncOp; -typedef Bool xorgDriverFuncProc (ScrnInfoPtr, xorgDriverFuncOp, - pointer); +typedef Bool xorgDriverFuncProc(ScrnInfoPtr, xorgDriverFuncOp, pointer); /* RR_GET_INFO, RR_SET_CONFIG */ typedef struct { @@ -294,13 +298,13 @@ typedef CARD32 xorgHWFlags; struct _DriverRec; typedef struct { - int driverVersion; - char * driverName; - void (*Identify)(int flags); - Bool (*Probe)(struct _DriverRec *drv, int flags); - const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype); - pointer module; - int refCount; + int driverVersion; + char *driverName; + void (*Identify) (int flags); + Bool (*Probe) (struct _DriverRec * drv, int flags); + const OptionInfoRec *(*AvailableOptions) (int chipid, int bustype); + pointer module; + int refCount; } DriverRec1; struct _SymTabRec; @@ -309,18 +313,18 @@ struct _PciChipsets; struct pci_device; typedef struct _DriverRec { - int driverVersion; - char * driverName; - void (*Identify)(int flags); - Bool (*Probe)(struct _DriverRec *drv, int flags); - const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype); - pointer module; - int refCount; - xorgDriverFuncProc *driverFunc; - - const struct pci_id_match * supported_devices; - Bool (*PciProbe)( struct _DriverRec * drv, int entity_num, - struct pci_device * dev, intptr_t match_data ); + int driverVersion; + char *driverName; + void (*Identify) (int flags); + Bool (*Probe) (struct _DriverRec * drv, int flags); + const OptionInfoRec *(*AvailableOptions) (int chipid, int bustype); + pointer module; + int refCount; + xorgDriverFuncProc *driverFunc; + + const struct pci_id_match *supported_devices; + Bool (*PciProbe) (struct _DriverRec * drv, int entity_num, + struct pci_device * dev, intptr_t match_data); } DriverRec, *DriverPtr; /* @@ -346,18 +350,18 @@ typedef enum { BUS_NONE, BUS_PCI, BUS_SBUS, - BUS_last /* Keep last */ + BUS_last /* Keep last */ } BusType; typedef struct { - int fbNum; + int fbNum; } SbusBusId; typedef struct _bus { BusType type; union { - struct pci_device *pci; - SbusBusId sbus; + struct pci_device *pci; + SbusBusId sbus; } id; } BusRec, *BusPtr; @@ -371,73 +375,73 @@ typedef enum { } DacSpeedIndex; typedef struct { - char * identifier; - char * vendor; - char * board; - char * chipset; - char * ramdac; - char * driver; - struct _confscreenrec * myScreenSection; - Bool claimed; - int dacSpeeds[MAXDACSPEEDS]; - int numclocks; - int clock[MAXCLOCKS]; - char * clockchip; - char * busID; - Bool active; - Bool inUse; - int videoRam; - int textClockFreq; - unsigned long BiosBase; /* Base address of video BIOS */ - unsigned long MemBase; /* Frame buffer base address */ - unsigned long IOBase; - int chipID; - int chipRev; - pointer options; - int irq; - int screen; /* For multi-CRTC cards */ + char *identifier; + char *vendor; + char *board; + char *chipset; + char *ramdac; + char *driver; + struct _confscreenrec *myScreenSection; + Bool claimed; + int dacSpeeds[MAXDACSPEEDS]; + int numclocks; + int clock[MAXCLOCKS]; + char *clockchip; + char *busID; + Bool active; + Bool inUse; + int videoRam; + int textClockFreq; + unsigned long BiosBase; /* Base address of video BIOS */ + unsigned long MemBase; /* Frame buffer base address */ + unsigned long IOBase; + int chipID; + int chipRev; + pointer options; + int irq; + int screen; /* For multi-CRTC cards */ } GDevRec, *GDevPtr; typedef struct { - int frameX0; - int frameY0; - int virtualX; - int virtualY; - int depth; - int fbbpp; - rgb weight; - rgb blackColour; - rgb whiteColour; - int defaultVisual; - char ** modes; - pointer options; + int frameX0; + int frameY0; + int virtualX; + int virtualY; + int depth; + int fbbpp; + rgb weight; + rgb blackColour; + rgb whiteColour; + int defaultVisual; + char **modes; + pointer options; } DispRec, *DispPtr; typedef struct _confxvportrec { - char * identifier; - pointer options; + char *identifier; + pointer options; } confXvPortRec, *confXvPortPtr; typedef struct _confxvadaptrec { - char * identifier; - int numports; - confXvPortPtr ports; - pointer options; + char *identifier; + int numports; + confXvPortPtr ports; + pointer options; } confXvAdaptorRec, *confXvAdaptorPtr; typedef struct _confscreenrec { - char * id; - int screennum; - int defaultdepth; - int defaultbpp; - int defaultfbbpp; - MonPtr monitor; - GDevPtr device; - int numdisplays; - DispPtr displays; - int numxvadaptors; - confXvAdaptorPtr xvadaptors; - pointer options; + char *id; + int screennum; + int defaultdepth; + int defaultbpp; + int defaultfbbpp; + MonPtr monitor; + GDevPtr device; + int numdisplays; + DispPtr displays; + int numxvadaptors; + confXvAdaptorPtr xvadaptors; + pointer options; } confScreenRec, *confScreenPtr; typedef enum { @@ -451,45 +455,45 @@ typedef enum { } PositionType; typedef struct _screenlayoutrec { - confScreenPtr screen; - char * topname; - confScreenPtr top; - char * bottomname; - confScreenPtr bottom; - char * leftname; - confScreenPtr left; - char * rightname; - confScreenPtr right; - PositionType where; - int x; - int y; - char * refname; - confScreenPtr refscreen; + confScreenPtr screen; + char *topname; + confScreenPtr top; + char *bottomname; + confScreenPtr bottom; + char *leftname; + confScreenPtr left; + char *rightname; + confScreenPtr right; + PositionType where; + int x; + int y; + char *refname; + confScreenPtr refscreen; } screenLayoutRec, *screenLayoutPtr; typedef struct _InputInfoRec InputInfoRec; typedef struct _serverlayoutrec { - char * id; - screenLayoutPtr screens; - GDevPtr inactives; - InputInfoRec** inputs; /* NULL terminated */ - pointer options; + char *id; + screenLayoutPtr screens; + GDevPtr inactives; + InputInfoRec **inputs; /* NULL terminated */ + pointer options; } serverLayoutRec, *serverLayoutPtr; typedef struct _confdribufferrec { - int count; - int size; + int count; + int size; enum { - XF86DRI_WC_HINT = 0x0001 /* Placeholder: not implemented */ - } flags; + XF86DRI_WC_HINT = 0x0001 /* Placeholder: not implemented */ + } flags; } confDRIBufferRec, *confDRIBufferPtr; typedef struct _confdrirec { - int group; - int mode; - int bufs_count; - confDRIBufferRec *bufs; + int group; + int mode; + int bufs_count; + confDRIBufferRec *bufs; } confDRIRec, *confDRIPtr; /* These values should be adjusted when new fields are added to ScrnInfoRec */ @@ -497,7 +501,7 @@ typedef struct _confdrirec { #define NUM_RESERVED_POINTERS 14 #define NUM_RESERVED_FUNCS 10 -typedef pointer (*funcPointer)(void); +typedef pointer (*funcPointer) (void); /* flags for depth 24 pixmap options */ typedef enum { @@ -565,9 +569,8 @@ typedef struct _PciChipsets { void *dummy; } PciChipsets; - /* Entity properties */ -typedef void (*EntityProc)(int entityIndex,pointer private); +typedef void (*EntityProc) (int entityIndex, pointer private); typedef struct _entityInfo { int index; @@ -581,37 +584,37 @@ typedef struct _entityInfo { /* DGA */ typedef struct { - int num; /* A unique identifier for the mode (num > 0) */ - DisplayModePtr mode; - int flags; /* DGA_CONCURRENT_ACCESS, etc... */ - int imageWidth; /* linear accessible portion (pixels) */ - int imageHeight; - int pixmapWidth; /* Xlib accessible portion (pixels) */ - int pixmapHeight; /* both fields ignored if no concurrent access */ - int bytesPerScanline; - int byteOrder; /* MSBFirst, LSBFirst */ - int depth; - int bitsPerPixel; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; - short visualClass; - int viewportWidth; - int viewportHeight; - int xViewportStep; /* viewport position granularity */ - int yViewportStep; - int maxViewportX; /* max viewport origin */ - int maxViewportY; - int viewportFlags; /* types of page flipping possible */ - int offset; /* offset into physical memory */ - unsigned char *address; /* server's mapped framebuffer */ - int reserved1; - int reserved2; + int num; /* A unique identifier for the mode (num > 0) */ + DisplayModePtr mode; + int flags; /* DGA_CONCURRENT_ACCESS, etc... */ + int imageWidth; /* linear accessible portion (pixels) */ + int imageHeight; + int pixmapWidth; /* Xlib accessible portion (pixels) */ + int pixmapHeight; /* both fields ignored if no concurrent access */ + int bytesPerScanline; + int byteOrder; /* MSBFirst, LSBFirst */ + int depth; + int bitsPerPixel; + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; + short visualClass; + int viewportWidth; + int viewportHeight; + int xViewportStep; /* viewport position granularity */ + int yViewportStep; + int maxViewportX; /* max viewport origin */ + int maxViewportY; + int viewportFlags; /* types of page flipping possible */ + int offset; /* offset into physical memory */ + unsigned char *address; /* server's mapped framebuffer */ + int reserved1; + int reserved2; } DGAModeRec, *DGAModePtr; typedef struct { - DGAModePtr mode; - PixmapPtr pPix; + DGAModePtr mode; + PixmapPtr pPix; } DGADeviceRec, *DGADevicePtr; /* @@ -625,25 +628,24 @@ typedef struct { * Driver entry point types */ -typedef Bool xf86ProbeProc (DriverPtr, int); -typedef Bool xf86PreInitProc (ScrnInfoPtr, int); -typedef Bool xf86ScreenInitProc (int, ScreenPtr, int, char**); -typedef Bool xf86SwitchModeProc (int, DisplayModePtr, int); -typedef void xf86AdjustFrameProc (int, int, int, int); -typedef Bool xf86EnterVTProc (int, int); -typedef void xf86LeaveVTProc (int, int); -typedef void xf86FreeScreenProc (int, int); -typedef ModeStatus xf86ValidModeProc (int, DisplayModePtr, Bool, int); +typedef Bool xf86ProbeProc(DriverPtr, int); +typedef Bool xf86PreInitProc(ScrnInfoPtr, int); +typedef Bool xf86ScreenInitProc(int, ScreenPtr, int, char **); +typedef Bool xf86SwitchModeProc(int, DisplayModePtr, int); +typedef void xf86AdjustFrameProc(int, int, int, int); +typedef Bool xf86EnterVTProc(int, int); +typedef void xf86LeaveVTProc(int, int); +typedef void xf86FreeScreenProc(int, int); +typedef ModeStatus xf86ValidModeProc(int, DisplayModePtr, Bool, int); typedef void xf86EnableDisableFBAccessProc(int, Bool); -typedef int xf86SetDGAModeProc (int, int, DGADevicePtr); -typedef int xf86ChangeGammaProc (int, Gamma); -typedef void xf86PointerMovedProc (int, int, int); -typedef Bool xf86PMEventProc (int, pmEvent, Bool); -typedef void xf86DPMSSetProc (ScrnInfoPtr, int, int); -typedef void xf86LoadPaletteProc (ScrnInfoPtr, int, int *, LOCO *, VisualPtr); -typedef void xf86SetOverscanProc (ScrnInfoPtr, int); -typedef void xf86ModeSetProc (ScrnInfoPtr); - +typedef int xf86SetDGAModeProc(int, int, DGADevicePtr); +typedef int xf86ChangeGammaProc(int, Gamma); +typedef void xf86PointerMovedProc(int, int, int); +typedef Bool xf86PMEventProc(int, pmEvent, Bool); +typedef void xf86DPMSSetProc(ScrnInfoPtr, int, int); +typedef void xf86LoadPaletteProc(ScrnInfoPtr, int, int *, LOCO *, VisualPtr); +typedef void xf86SetOverscanProc(ScrnInfoPtr, int); +typedef void xf86ModeSetProc(ScrnInfoPtr); /* * ScrnInfoRec @@ -656,217 +658,200 @@ typedef void xf86ModeSetProc (ScrnInfoPtr); * are to be dependent on compile-time defines. */ - typedef struct _ScrnInfoRec { - int driverVersion; - char * driverName; /* canonical name used in */ - /* the config file */ - ScreenPtr pScreen; /* Pointer to the ScreenRec */ - int scrnIndex; /* Number of this screen */ - Bool configured; /* Is this screen valid */ - int origIndex; /* initial number assigned to - * this screen before - * finalising the number of - * available screens */ + int driverVersion; + char *driverName; /* canonical name used in */ + /* the config file */ + ScreenPtr pScreen; /* Pointer to the ScreenRec */ + int scrnIndex; /* Number of this screen */ + Bool configured; /* Is this screen valid */ + int origIndex; /* initial number assigned to + * this screen before + * finalising the number of + * available screens */ /* Display-wide screenInfo values needed by this screen */ - int imageByteOrder; - int bitmapScanlineUnit; - int bitmapScanlinePad; - int bitmapBitOrder; - int numFormats; - PixmapFormatRec formats[MAXFORMATS]; - PixmapFormatRec fbFormat; - - int bitsPerPixel; /* fb bpp */ - Pix24Flags pixmap24; /* pixmap pref for depth 24 */ - int depth; /* depth of default visual */ - MessageType depthFrom; /* set from config? */ - MessageType bitsPerPixelFrom; /* set from config? */ - rgb weight; /* r/g/b weights */ - rgb mask; /* rgb masks */ - rgb offset; /* rgb offsets */ - int rgbBits; /* Number of bits in r/g/b */ - Gamma gamma; /* Gamma of the monitor */ - int defaultVisual; /* default visual class */ - int maxHValue; /* max horizontal timing */ - int maxVValue; /* max vertical timing value */ - int virtualX; /* Virtual width */ - int virtualY; /* Virtual height */ - int xInc; /* Horizontal timing increment */ - MessageType virtualFrom; /* set from config? */ - int displayWidth; /* memory pitch */ - int frameX0; /* viewport position */ - int frameY0; - int frameX1; - int frameY1; - int zoomLocked; /* Disallow mode changes */ - DisplayModePtr modePool; /* list of compatible modes */ - DisplayModePtr modes; /* list of actual modes */ - DisplayModePtr currentMode; /* current mode - * This was previously - * overloaded with the modes - * field, which is a pointer - * into a circular list */ - confScreenPtr confScreen; /* Screen config info */ - MonPtr monitor; /* Monitor information */ - DispPtr display; /* Display information */ - int * entityList; /* List of device entities */ - int numEntities; - int widthmm; /* physical display dimensions - * in mm */ - int heightmm; - int xDpi; /* width DPI */ - int yDpi; /* height DPI */ - char * name; /* Name to prefix messages */ - pointer driverPrivate; /* Driver private area */ - DevUnion * privates; /* Other privates can hook in - * here */ - DriverPtr drv; /* xf86DriverList[] entry */ - pointer module; /* Pointer to module head */ - int colorKey; - int overlayFlags; + int imageByteOrder; + int bitmapScanlineUnit; + int bitmapScanlinePad; + int bitmapBitOrder; + int numFormats; + PixmapFormatRec formats[MAXFORMATS]; + PixmapFormatRec fbFormat; + + int bitsPerPixel; /* fb bpp */ + Pix24Flags pixmap24; /* pixmap pref for depth 24 */ + int depth; /* depth of default visual */ + MessageType depthFrom; /* set from config? */ + MessageType bitsPerPixelFrom; /* set from config? */ + rgb weight; /* r/g/b weights */ + rgb mask; /* rgb masks */ + rgb offset; /* rgb offsets */ + int rgbBits; /* Number of bits in r/g/b */ + Gamma gamma; /* Gamma of the monitor */ + int defaultVisual; /* default visual class */ + int maxHValue; /* max horizontal timing */ + int maxVValue; /* max vertical timing value */ + int virtualX; /* Virtual width */ + int virtualY; /* Virtual height */ + int xInc; /* Horizontal timing increment */ + MessageType virtualFrom; /* set from config? */ + int displayWidth; /* memory pitch */ + int frameX0; /* viewport position */ + int frameY0; + int frameX1; + int frameY1; + int zoomLocked; /* Disallow mode changes */ + DisplayModePtr modePool; /* list of compatible modes */ + DisplayModePtr modes; /* list of actual modes */ + DisplayModePtr currentMode; /* current mode + * This was previously + * overloaded with the modes + * field, which is a pointer + * into a circular list */ + confScreenPtr confScreen; /* Screen config info */ + MonPtr monitor; /* Monitor information */ + DispPtr display; /* Display information */ + int *entityList; /* List of device entities */ + int numEntities; + int widthmm; /* physical display dimensions + * in mm */ + int heightmm; + int xDpi; /* width DPI */ + int yDpi; /* height DPI */ + char *name; /* Name to prefix messages */ + pointer driverPrivate; /* Driver private area */ + DevUnion *privates; /* Other privates can hook in + * here */ + DriverPtr drv; /* xf86DriverList[] entry */ + pointer module; /* Pointer to module head */ + int colorKey; + int overlayFlags; /* Some of these may be moved out of here into the driver private area */ - char * chipset; /* chipset name */ - char * ramdac; /* ramdac name */ - char * clockchip; /* clock name */ - Bool progClock; /* clock is programmable */ - int numClocks; /* number of clocks */ - int clock[MAXCLOCKS]; /* list of clock frequencies */ - int videoRam; /* amount of video ram (kb) */ - unsigned long biosBase; /* Base address of video BIOS */ - unsigned long memPhysBase; /* Physical address of FB */ - unsigned long fbOffset; /* Offset of FB in the above */ - int memClk; /* memory clock */ - int textClockFreq; /* clock of text mode */ - Bool flipPixels; /* swap default black/white */ - pointer options; - - int chipID; - int chipRev; + char *chipset; /* chipset name */ + char *ramdac; /* ramdac name */ + char *clockchip; /* clock name */ + Bool progClock; /* clock is programmable */ + int numClocks; /* number of clocks */ + int clock[MAXCLOCKS]; /* list of clock frequencies */ + int videoRam; /* amount of video ram (kb) */ + unsigned long biosBase; /* Base address of video BIOS */ + unsigned long memPhysBase; /* Physical address of FB */ + unsigned long fbOffset; /* Offset of FB in the above */ + int memClk; /* memory clock */ + int textClockFreq; /* clock of text mode */ + Bool flipPixels; /* swap default black/white */ + pointer options; + + int chipID; + int chipRev; /* Allow screens to be enabled/disabled individually */ - Bool vtSema; + Bool vtSema; /* hw cursor moves at SIGIO time */ - Bool silkenMouse; + Bool silkenMouse; /* Storage for clockRanges and adjustFlags for use with the VidMode ext */ - ClockRangePtr clockRanges; - int adjustFlags; + ClockRangePtr clockRanges; + int adjustFlags; /* * These can be used when the minor ABI version is incremented. * The NUM_* parameters must be reduced appropriately to keep the * structure size and alignment unchanged. */ - int reservedInt[NUM_RESERVED_INTS]; + int reservedInt[NUM_RESERVED_INTS]; - int * entityInstanceList; - struct pci_device *vgaDev; + int *entityInstanceList; + struct pci_device *vgaDev; - pointer reservedPtr[NUM_RESERVED_POINTERS]; + pointer reservedPtr[NUM_RESERVED_POINTERS]; /* * Driver entry points. * */ - xf86ProbeProc *Probe; - xf86PreInitProc *PreInit; - xf86ScreenInitProc *ScreenInit; - xf86SwitchModeProc *SwitchMode; - xf86AdjustFrameProc *AdjustFrame; - xf86EnterVTProc *EnterVT; - xf86LeaveVTProc *LeaveVT; - xf86FreeScreenProc *FreeScreen; - xf86ValidModeProc *ValidMode; - xf86EnableDisableFBAccessProc *EnableDisableFBAccess; - xf86SetDGAModeProc *SetDGAMode; - xf86ChangeGammaProc *ChangeGamma; - xf86PointerMovedProc *PointerMoved; - xf86PMEventProc *PMEvent; - xf86DPMSSetProc *DPMSSet; - xf86LoadPaletteProc *LoadPalette; - xf86SetOverscanProc *SetOverscan; - xorgDriverFuncProc *DriverFunc; - xf86ModeSetProc *ModeSet; + xf86ProbeProc *Probe; + xf86PreInitProc *PreInit; + xf86ScreenInitProc *ScreenInit; + xf86SwitchModeProc *SwitchMode; + xf86AdjustFrameProc *AdjustFrame; + xf86EnterVTProc *EnterVT; + xf86LeaveVTProc *LeaveVT; + xf86FreeScreenProc *FreeScreen; + xf86ValidModeProc *ValidMode; + xf86EnableDisableFBAccessProc *EnableDisableFBAccess; + xf86SetDGAModeProc *SetDGAMode; + xf86ChangeGammaProc *ChangeGamma; + xf86PointerMovedProc *PointerMoved; + xf86PMEventProc *PMEvent; + xf86DPMSSetProc *DPMSSet; + xf86LoadPaletteProc *LoadPalette; + xf86SetOverscanProc *SetOverscan; + xorgDriverFuncProc *DriverFunc; + xf86ModeSetProc *ModeSet; /* * This can be used when the minor ABI version is incremented. * The NUM_* parameter must be reduced appropriately to keep the * structure size and alignment unchanged. */ - funcPointer reservedFuncs[NUM_RESERVED_FUNCS]; + funcPointer reservedFuncs[NUM_RESERVED_FUNCS]; } ScrnInfoRec; - typedef struct { - Bool (*OpenFramebuffer)( - ScrnInfoPtr pScrn, - char **name, - unsigned char **mem, - int *size, - int *offset, - int *extra - ); - void (*CloseFramebuffer)(ScrnInfoPtr pScrn); - Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode); - void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags); - int (*GetViewport)(ScrnInfoPtr pScrn); - void (*Sync)(ScrnInfoPtr); - void (*FillRect)( - ScrnInfoPtr pScrn, - int x, int y, int w, int h, - unsigned long color - ); - void (*BlitRect)( - ScrnInfoPtr pScrn, - int srcx, int srcy, - int w, int h, - int dstx, int dsty - ); - void (*BlitTransRect)( - ScrnInfoPtr pScrn, - int srcx, int srcy, - int w, int h, - int dstx, int dsty, - unsigned long color - ); + Bool (*OpenFramebuffer) (ScrnInfoPtr pScrn, + char **name, + unsigned char **mem, + int *size, int *offset, int *extra); + void (*CloseFramebuffer) (ScrnInfoPtr pScrn); + Bool (*SetMode) (ScrnInfoPtr pScrn, DGAModePtr pMode); + void (*SetViewport) (ScrnInfoPtr pScrn, int x, int y, int flags); + int (*GetViewport) (ScrnInfoPtr pScrn); + void (*Sync) (ScrnInfoPtr); + void (*FillRect) (ScrnInfoPtr pScrn, + int x, int y, int w, int h, unsigned long color); + void (*BlitRect) (ScrnInfoPtr pScrn, + int srcx, int srcy, int w, int h, int dstx, int dsty); + void (*BlitTransRect) (ScrnInfoPtr pScrn, + int srcx, int srcy, + int w, int h, + int dstx, int dsty, unsigned long color); } DGAFunctionRec, *DGAFunctionPtr; typedef struct _SymTabRec { - int token; /* id of the token */ - const char * name; /* token name */ + int token; /* id of the token */ + const char *name; /* token name */ } SymTabRec, *SymTabPtr; /* flags for xf86LookupMode */ typedef enum { - LOOKUP_DEFAULT = 0, /* Use default mode lookup method */ - LOOKUP_BEST_REFRESH, /* Pick modes with best refresh */ - LOOKUP_CLOSEST_CLOCK, /* Pick modes with the closest clock */ - LOOKUP_LIST_ORDER, /* Pick first useful mode in list */ - LOOKUP_CLKDIV2 = 0x0100, /* Allow half clocks */ - LOOKUP_OPTIONAL_TOLERANCES = 0x0200 /* Allow missing hsync/vrefresh */ + LOOKUP_DEFAULT = 0, /* Use default mode lookup method */ + LOOKUP_BEST_REFRESH, /* Pick modes with best refresh */ + LOOKUP_CLOSEST_CLOCK, /* Pick modes with the closest clock */ + LOOKUP_LIST_ORDER, /* Pick first useful mode in list */ + LOOKUP_CLKDIV2 = 0x0100, /* Allow half clocks */ + LOOKUP_OPTIONAL_TOLERANCES = 0x0200 /* Allow missing hsync/vrefresh */ } LookupModeFlags; #define NoDepth24Support 0x00 -#define Support24bppFb 0x01 /* 24bpp framebuffer supported */ -#define Support32bppFb 0x02 /* 32bpp framebuffer supported */ -#define SupportConvert24to32 0x04 /* Can convert 24bpp pixmap to 32bpp */ -#define SupportConvert32to24 0x08 /* Can convert 32bpp pixmap to 24bpp */ -#define PreferConvert24to32 0x10 /* prefer 24bpp pixmap to 32bpp conv */ -#define PreferConvert32to24 0x20 /* prefer 32bpp pixmap to 24bpp conv */ - +#define Support24bppFb 0x01 /* 24bpp framebuffer supported */ +#define Support32bppFb 0x02 /* 32bpp framebuffer supported */ +#define SupportConvert24to32 0x04 /* Can convert 24bpp pixmap to 32bpp */ +#define SupportConvert32to24 0x08 /* Can convert 32bpp pixmap to 24bpp */ +#define PreferConvert24to32 0x10 /* prefer 24bpp pixmap to 32bpp conv */ +#define PreferConvert32to24 0x20 /* prefer 32bpp pixmap to 24bpp conv */ /* For DPMS */ -typedef void (*DPMSSetProcPtr)(ScrnInfoPtr, int, int); +typedef void (*DPMSSetProcPtr) (ScrnInfoPtr, int, int); /* Input handler proc */ -typedef void (*InputHandlerProc)(int fd, pointer data); +typedef void (*InputHandlerProc) (int fd, pointer data); /* These are used by xf86GetClocks */ #define CLK_REG_SAVE -1 @@ -876,9 +861,8 @@ typedef void (*InputHandlerProc)(int fd, pointer data); * misc constants */ #define INTERLACE_REFRESH_WEIGHT 1.5 -#define SYNC_TOLERANCE 0.01 /* 1 percent */ -#define CLOCK_TOLERANCE 2000 /* Clock matching tolerance (2MHz) */ - +#define SYNC_TOLERANCE 0.01 /* 1 percent */ +#define CLOCK_TOLERANCE 2000 /* Clock matching tolerance (2MHz) */ #define OVERLAY_8_32_DUALFB 0x00000001 #define OVERLAY_8_24_DUALFB 0x00000002 @@ -891,12 +875,12 @@ typedef void (*InputHandlerProc)(int fd, pointer data); /* Action Events */ typedef enum { - ACTION_TERMINATE = 0, /* Terminate Server */ - ACTION_NEXT_MODE = 10, /* Switch to next video mode */ + ACTION_TERMINATE = 0, /* Terminate Server */ + ACTION_NEXT_MODE = 10, /* Switch to next video mode */ ACTION_PREV_MODE, - ACTION_SWITCHSCREEN = 100, /* VT switch */ + ACTION_SWITCHSCREEN = 100, /* VT switch */ ACTION_SWITCHSCREEN_NEXT, ACTION_SWITCHSCREEN_PREV, } ActionEvent; -#endif /* _XF86STR_H */ +#endif /* _XF86STR_H */ diff --git a/xorg-server/hw/xfree86/common/xf86xv.c b/xorg-server/hw/xfree86/common/xf86xv.c index b46dfefed..88e2f314b 100644 --- a/xorg-server/hw/xfree86/common/xf86xv.c +++ b/xorg-server/hw/xfree86/common/xf86xv.c @@ -28,7 +28,6 @@ * authorization from the copyright holder(s) and author(s). */ - #ifdef HAVE_XORG_CONFIG_H #include <xorg-config.h> #endif @@ -56,7 +55,6 @@ #include "xf86xvpriv.h" - /* XvScreenRec fields */ static Bool xf86XVCloseScreen(int, ScreenPtr); @@ -64,40 +62,39 @@ static int xf86XVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *); /* XvAdaptorRec fields */ -static int xf86XVAllocatePort(unsigned long, XvPortPtr, XvPortPtr*); +static int xf86XVAllocatePort(unsigned long, XvPortPtr, XvPortPtr *); static int xf86XVFreePort(XvPortPtr); -static int xf86XVPutVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVPutStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVGetVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVGetStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); +static int xf86XVPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); +static int xf86XVPutStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); +static int xf86XVGetVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); +static int xf86XVGetStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); static int xf86XVStopVideo(ClientPtr, XvPortPtr, DrawablePtr); static int xf86XVSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32); -static int xf86XVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32*); +static int xf86XVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *); static int xf86XVQueryBestSize(ClientPtr, XvPortPtr, CARD8, - CARD16, CARD16,CARD16, CARD16, - unsigned int*, unsigned int*); + CARD16, CARD16, CARD16, CARD16, + unsigned int *, unsigned int *); static int xf86XVPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16, - XvImagePtr, unsigned char*, Bool, - CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16, + XvImagePtr, unsigned char *, Bool, CARD16, CARD16); static int xf86XVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr, - CARD16*, CARD16*, int*, int*); - + CARD16 *, CARD16 *, int *, int *); /* ScreenRec fields */ static Bool xf86XVDestroyWindow(WindowPtr pWin); static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2); -static void xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind); +static void xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, + VTKind kind); static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy); #define PostValidateTreeUndefined ((PostValidateTreeProcPtr)-1) @@ -111,19 +108,19 @@ static void xf86XVModeSet(ScrnInfoPtr pScrn); /* misc */ -static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int); - +static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr *, int); static DevPrivateKeyRec XF86XVWindowKeyRec; + #define XF86XVWindowKey (&XF86XVWindowKeyRec) DevPrivateKey XF86XvScreenKey; static unsigned long PortResource = 0; -DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL; -unsigned long (*XvGetRTPortProc)(void) = NULL; -int (*XvScreenInitProc)(ScreenPtr) = NULL; +DevPrivateKey (*XvGetScreenKeyProc) (void) = NULL; +unsigned long (*XvGetRTPortProc) (void) = NULL; +int (*XvScreenInitProc) (ScreenPtr) = NULL; #define GET_XV_SCREEN(pScreen) \ ((XvScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XF86XvScreenKey)) @@ -138,29 +135,26 @@ static xf86XVInitGenericAdaptorPtr *GenDrivers = NULL; static int NumGenDrivers = 0; int -xf86XVRegisterGenericAdaptorDriver( - xf86XVInitGenericAdaptorPtr InitFunc -){ - xf86XVInitGenericAdaptorPtr *newdrivers; +xf86XVRegisterGenericAdaptorDriver(xf86XVInitGenericAdaptorPtr InitFunc) +{ + xf86XVInitGenericAdaptorPtr *newdrivers; - newdrivers = realloc(GenDrivers, sizeof(xf86XVInitGenericAdaptorPtr) * - (1 + NumGenDrivers)); - if (!newdrivers) - return 0; - GenDrivers = newdrivers; + newdrivers = realloc(GenDrivers, sizeof(xf86XVInitGenericAdaptorPtr) * + (1 + NumGenDrivers)); + if (!newdrivers) + return 0; + GenDrivers = newdrivers; - GenDrivers[NumGenDrivers++] = InitFunc; + GenDrivers[NumGenDrivers++] = InitFunc; - return 1; + return 1; } int -xf86XVListGenericAdaptors( - ScrnInfoPtr pScrn, - XF86VideoAdaptorPtr **adaptors -){ - int i,j,n,num; - XF86VideoAdaptorPtr *DrivAdap,*new; +xf86XVListGenericAdaptors(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr ** adaptors) +{ + int i, j, n, num; + XF86VideoAdaptorPtr *DrivAdap, *new; num = 0; *adaptors = NULL; @@ -168,48 +162,49 @@ xf86XVListGenericAdaptors( * The v4l driver registers itself first, but can use surfaces registered * by other drivers. So, call the v4l driver last. */ - for (i = NumGenDrivers; --i >= 0; ) { - DrivAdap = NULL; - n = (*GenDrivers[i])(pScrn, &DrivAdap); - if (0 == n) - continue; - new = realloc(*adaptors, sizeof(XF86VideoAdaptorPtr) * (num+n)); - if (NULL == new) - continue; - *adaptors = new; - for (j = 0; j < n; j++, num++) - (*adaptors)[num] = DrivAdap[j]; + for (i = NumGenDrivers; --i >= 0;) { + DrivAdap = NULL; + n = (*GenDrivers[i]) (pScrn, &DrivAdap); + if (0 == n) + continue; + new = realloc(*adaptors, sizeof(XF86VideoAdaptorPtr) * (num + n)); + if (NULL == new) + continue; + *adaptors = new; + for (j = 0; j < n; j++, num++) + (*adaptors)[num] = DrivAdap[j]; } return num; } - /**************** Offscreen surface stuff *******************/ typedef struct { - XF86OffscreenImagePtr images; - int num; + XF86OffscreenImagePtr images; + int num; } OffscreenImageRec; static DevPrivateKeyRec OffscreenPrivateKeyRec; + #define OffscreenPrivateKey (&OffscreenPrivateKeyRec) #define GetOffscreenImage(pScreen) ((OffscreenImageRec *) dixLookupPrivate(&(pScreen)->devPrivates, OffscreenPrivateKey)) Bool -xf86XVRegisterOffscreenImages( - ScreenPtr pScreen, - XF86OffscreenImagePtr images, - int num -){ +xf86XVRegisterOffscreenImages(ScreenPtr pScreen, + XF86OffscreenImagePtr images, int num) +{ OffscreenImageRec *OffscreenImage; + /* This function may be called before xf86XVScreenInit, so there's * no better place than this to call dixRegisterPrivateKey to ensure we * have space reserved. After the first call it is a no-op. */ - if(!dixRegisterPrivateKey(OffscreenPrivateKey, PRIVATE_SCREEN, sizeof(OffscreenImageRec)) || - !(OffscreenImage = GetOffscreenImage(pScreen))) + if (!dixRegisterPrivateKey + (OffscreenPrivateKey, PRIVATE_SCREEN, sizeof(OffscreenImageRec)) || + !(OffscreenImage = GetOffscreenImage(pScreen))) /* Every X.org driver assumes this function always succeeds, so * just die on allocation failure. */ - FatalError("Could not allocate private storage for XV offscreen images.\n"); + FatalError + ("Could not allocate private storage for XV offscreen images.\n"); OffscreenImage->num = num; OffscreenImage->images = images; @@ -217,16 +212,14 @@ xf86XVRegisterOffscreenImages( } XF86OffscreenImagePtr -xf86XVQueryOffscreenImages( - ScreenPtr pScreen, - int *num -){ +xf86XVQueryOffscreenImages(ScreenPtr pScreen, int *num) +{ OffscreenImageRec *OffscreenImage = GetOffscreenImage(pScreen); + *num = OffscreenImage->num; return OffscreenImage->images; } - XF86VideoAdaptorPtr xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr pScrn) { @@ -239,396 +232,388 @@ xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr) free(ptr); } - Bool -xf86XVScreenInit( - ScreenPtr pScreen, - XF86VideoAdaptorPtr *adaptors, - int num -){ - ScrnInfoPtr pScrn; - XF86XVScreenPtr ScreenPriv; - XvScreenPtr pxvs; +xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num) +{ + ScrnInfoPtr pScrn; + XF86XVScreenPtr ScreenPriv; + XvScreenPtr pxvs; - if(num <= 0 || - !XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc) - return FALSE; + if (num <= 0 || + !XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc) + return FALSE; - if(Success != (*XvScreenInitProc)(pScreen)) return FALSE; + if (Success != (*XvScreenInitProc) (pScreen)) + return FALSE; - if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; + if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0)) + return FALSE; - XF86XvScreenKey = (*XvGetScreenKeyProc)(); + XF86XvScreenKey = (*XvGetScreenKeyProc) (); - PortResource = (*XvGetRTPortProc)(); + PortResource = (*XvGetRTPortProc) (); - pxvs = GET_XV_SCREEN(pScreen); + pxvs = GET_XV_SCREEN(pScreen); - /* Anyone initializing the Xv layer must provide these two. - The Xv di layer calls them without even checking if they exist! */ + /* Anyone initializing the Xv layer must provide these two. + The Xv di layer calls them without even checking if they exist! */ - pxvs->ddCloseScreen = xf86XVCloseScreen; - pxvs->ddQueryAdaptors = xf86XVQueryAdaptors; + pxvs->ddCloseScreen = xf86XVCloseScreen; + pxvs->ddQueryAdaptors = xf86XVQueryAdaptors; - /* The Xv di layer provides us with a private hook so that we don't - have to allocate our own screen private. They also provide - a CloseScreen hook so that we don't have to wrap it. I'm not - sure that I appreciate that. */ + /* The Xv di layer provides us with a private hook so that we don't + have to allocate our own screen private. They also provide + a CloseScreen hook so that we don't have to wrap it. I'm not + sure that I appreciate that. */ - ScreenPriv = malloc(sizeof(XF86XVScreenRec)); - pxvs->devPriv.ptr = (pointer)ScreenPriv; + ScreenPriv = malloc(sizeof(XF86XVScreenRec)); + pxvs->devPriv.ptr = (pointer) ScreenPriv; - if(!ScreenPriv) return FALSE; + if (!ScreenPriv) + return FALSE; - pScrn = xf86Screens[pScreen->myNum]; + pScrn = xf86Screens[pScreen->myNum]; - ScreenPriv->DestroyWindow = pScreen->DestroyWindow; - ScreenPriv->WindowExposures = pScreen->WindowExposures; - ScreenPriv->PostValidateTree = PostValidateTreeUndefined; - ScreenPriv->ClipNotify = pScreen->ClipNotify; - ScreenPriv->EnterVT = pScrn->EnterVT; - ScreenPriv->LeaveVT = pScrn->LeaveVT; - ScreenPriv->AdjustFrame = pScrn->AdjustFrame; - ScreenPriv->ModeSet = pScrn->ModeSet; + ScreenPriv->DestroyWindow = pScreen->DestroyWindow; + ScreenPriv->WindowExposures = pScreen->WindowExposures; + ScreenPriv->PostValidateTree = PostValidateTreeUndefined; + ScreenPriv->ClipNotify = pScreen->ClipNotify; + ScreenPriv->EnterVT = pScrn->EnterVT; + ScreenPriv->LeaveVT = pScrn->LeaveVT; + ScreenPriv->AdjustFrame = pScrn->AdjustFrame; + ScreenPriv->ModeSet = pScrn->ModeSet; - pScreen->DestroyWindow = xf86XVDestroyWindow; - pScreen->WindowExposures = xf86XVWindowExposures; - pScreen->ClipNotify = xf86XVClipNotify; - pScrn->EnterVT = xf86XVEnterVT; - pScrn->LeaveVT = xf86XVLeaveVT; - if(pScrn->AdjustFrame) - pScrn->AdjustFrame = xf86XVAdjustFrame; - pScrn->ModeSet = xf86XVModeSet; + pScreen->DestroyWindow = xf86XVDestroyWindow; + pScreen->WindowExposures = xf86XVWindowExposures; + pScreen->ClipNotify = xf86XVClipNotify; + pScrn->EnterVT = xf86XVEnterVT; + pScrn->LeaveVT = xf86XVLeaveVT; + if (pScrn->AdjustFrame) + pScrn->AdjustFrame = xf86XVAdjustFrame; + pScrn->ModeSet = xf86XVModeSet; - if(!xf86XVInitAdaptors(pScreen, adaptors, num)) - return FALSE; + if (!xf86XVInitAdaptors(pScreen, adaptors, num)) + return FALSE; - return TRUE; + return TRUE; } static void xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor) { - int i; - - free(pAdaptor->name); - pAdaptor->name = NULL; - - if(pAdaptor->pEncodings) { - XvEncodingPtr pEncode = pAdaptor->pEncodings; - - for(i = 0; i < pAdaptor->nEncodings; i++, pEncode++) - free(pEncode->name); - free(pAdaptor->pEncodings); - pAdaptor->pEncodings = NULL; - } - - free(pAdaptor->pFormats); - pAdaptor->pFormats = NULL; - - if(pAdaptor->pPorts) { - XvPortPtr pPort = pAdaptor->pPorts; - XvPortRecPrivatePtr pPriv; - - for(i = 0; i < pAdaptor->nPorts; i++, pPort++) { - pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr; - if(pPriv) { - if(pPriv->clientClip) - RegionDestroy(pPriv->clientClip); - if(pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - if (pPriv->ckeyFilled) - RegionDestroy(pPriv->ckeyFilled); - free(pPriv); - } - } - free(pAdaptor->pPorts); - pAdaptor->pPorts = NULL; - } - - if(pAdaptor->pAttributes) { - XvAttributePtr pAttribute = pAdaptor->pAttributes; - - for(i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) - free(pAttribute->name); - free(pAdaptor->pAttributes); - pAdaptor->pAttributes = NULL; - } - - free(pAdaptor->pImages); - free(pAdaptor->devPriv.ptr); - pAdaptor->pImages = NULL; - pAdaptor->devPriv.ptr = NULL; + int i; + + free(pAdaptor->name); + pAdaptor->name = NULL; + + if (pAdaptor->pEncodings) { + XvEncodingPtr pEncode = pAdaptor->pEncodings; + + for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++) + free(pEncode->name); + free(pAdaptor->pEncodings); + pAdaptor->pEncodings = NULL; + } + + free(pAdaptor->pFormats); + pAdaptor->pFormats = NULL; + + if (pAdaptor->pPorts) { + XvPortPtr pPort = pAdaptor->pPorts; + XvPortRecPrivatePtr pPriv; + + for (i = 0; i < pAdaptor->nPorts; i++, pPort++) { + pPriv = (XvPortRecPrivatePtr) pPort->devPriv.ptr; + if (pPriv) { + if (pPriv->clientClip) + RegionDestroy(pPriv->clientClip); + if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) + RegionDestroy(pPriv->pCompositeClip); + if (pPriv->ckeyFilled) + RegionDestroy(pPriv->ckeyFilled); + free(pPriv); + } + } + free(pAdaptor->pPorts); + pAdaptor->pPorts = NULL; + } + + if (pAdaptor->pAttributes) { + XvAttributePtr pAttribute = pAdaptor->pAttributes; + + for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) + free(pAttribute->name); + free(pAdaptor->pAttributes); + pAdaptor->pAttributes = NULL; + } + + free(pAdaptor->pImages); + free(pAdaptor->devPriv.ptr); + pAdaptor->pImages = NULL; + pAdaptor->devPriv.ptr = NULL; } static Bool -xf86XVInitAdaptors( - ScreenPtr pScreen, - XF86VideoAdaptorPtr *infoPtr, - int number -) { - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - XF86VideoAdaptorPtr adaptorPtr; - XvAdaptorPtr pAdaptor, pa; - XvAdaptorRecPrivatePtr adaptorPriv; - int na, numAdaptor; - XvPortRecPrivatePtr portPriv; - XvPortPtr pPort, pp; - int numPort; - XF86AttributePtr attributePtr; - XvAttributePtr pAttribute, pat; - XF86VideoFormatPtr formatPtr; - XvFormatPtr pFormat, pf; - int numFormat, totFormat; - XF86VideoEncodingPtr encodingPtr; - XvEncodingPtr pEncode, pe; - XF86ImagePtr imagePtr; - XvImagePtr pImage, pi; - int numVisuals; - VisualPtr pVisual; - int i; - - pxvs->nAdaptors = 0; - pxvs->pAdaptors = NULL; - - if(!(pAdaptor = calloc(number, sizeof(XvAdaptorRec)))) - return FALSE; - - for(pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) { - adaptorPtr = infoPtr[na]; - - if(!adaptorPtr->StopVideo || !adaptorPtr->SetPortAttribute || - !adaptorPtr->GetPortAttribute || !adaptorPtr->QueryBestSize) - continue; - - /* client libs expect at least one encoding */ - if(!adaptorPtr->nEncodings || !adaptorPtr->pEncodings) - continue; - - pa->type = adaptorPtr->type; - - if(!adaptorPtr->PutVideo && !adaptorPtr->GetVideo) - pa->type &= ~XvVideoMask; - - if(!adaptorPtr->PutStill && !adaptorPtr->GetStill) - pa->type &= ~XvStillMask; - - if(!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes) - pa->type &= ~XvImageMask; - - if(!adaptorPtr->PutVideo && !adaptorPtr->PutImage && - !adaptorPtr->PutStill) - pa->type &= ~XvInputMask; - - if(!adaptorPtr->GetVideo && !adaptorPtr->GetStill) - pa->type &= ~XvOutputMask; - - if(!(adaptorPtr->type & (XvPixmapMask | XvWindowMask))) - continue; - if(!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask))) - continue; - - pa->pScreen = pScreen; - pa->ddAllocatePort = xf86XVAllocatePort; - pa->ddFreePort = xf86XVFreePort; - pa->ddPutVideo = xf86XVPutVideo; - pa->ddPutStill = xf86XVPutStill; - pa->ddGetVideo = xf86XVGetVideo; - pa->ddGetStill = xf86XVGetStill; - pa->ddStopVideo = xf86XVStopVideo; - pa->ddPutImage = xf86XVPutImage; - pa->ddSetPortAttribute = xf86XVSetPortAttribute; - pa->ddGetPortAttribute = xf86XVGetPortAttribute; - pa->ddQueryBestSize = xf86XVQueryBestSize; - pa->ddQueryImageAttributes = xf86XVQueryImageAttributes; - pa->name = strdup(adaptorPtr->name); - - if(adaptorPtr->nEncodings && - (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { - - for(pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0; - i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++) - { - pe->id = encodingPtr->id; - pe->pScreen = pScreen; - pe->name = strdup(encodingPtr->name); - pe->width = encodingPtr->width; - pe->height = encodingPtr->height; - pe->rate.numerator = encodingPtr->rate.numerator; - pe->rate.denominator = encodingPtr->rate.denominator; - } - pa->nEncodings = adaptorPtr->nEncodings; - pa->pEncodings = pEncode; - } - - if(adaptorPtr->nImages && - (pImage = calloc(adaptorPtr->nImages, sizeof(XvImageRec)))) { - - for(i = 0, pi = pImage, imagePtr = adaptorPtr->pImages; - i < adaptorPtr->nImages; i++, pi++, imagePtr++) - { - pi->id = imagePtr->id; - pi->type = imagePtr->type; - pi->byte_order = imagePtr->byte_order; - memcpy(pi->guid, imagePtr->guid, 16); - pi->bits_per_pixel = imagePtr->bits_per_pixel; - pi->format = imagePtr->format; - pi->num_planes = imagePtr->num_planes; - pi->depth = imagePtr->depth; - pi->red_mask = imagePtr->red_mask; - pi->green_mask = imagePtr->green_mask; - pi->blue_mask = imagePtr->blue_mask; - pi->y_sample_bits = imagePtr->y_sample_bits; - pi->u_sample_bits = imagePtr->u_sample_bits; - pi->v_sample_bits = imagePtr->v_sample_bits; - pi->horz_y_period = imagePtr->horz_y_period; - pi->horz_u_period = imagePtr->horz_u_period; - pi->horz_v_period = imagePtr->horz_v_period; - pi->vert_y_period = imagePtr->vert_y_period; - pi->vert_u_period = imagePtr->vert_u_period; - pi->vert_v_period = imagePtr->vert_v_period; - memcpy(pi->component_order, imagePtr->component_order, 32); - pi->scanline_order = imagePtr->scanline_order; - } - pa->nImages = adaptorPtr->nImages; - pa->pImages = pImage; - } - - if(adaptorPtr->nAttributes && - (pAttribute = calloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec)))) - { - for(pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = 0; - i < adaptorPtr->nAttributes; pat++, i++, attributePtr++) - { - pat->flags = attributePtr->flags; - pat->min_value = attributePtr->min_value; - pat->max_value = attributePtr->max_value; - pat->name = strdup(attributePtr->name); - } - pa->nAttributes = adaptorPtr->nAttributes; - pa->pAttributes = pAttribute; - } - - - totFormat = adaptorPtr->nFormats; - - if(!(pFormat = calloc(totFormat, sizeof(XvFormatRec)))) { - xf86XVFreeAdaptor(pa); - continue; - } - for(pf = pFormat, i = 0, numFormat = 0, formatPtr = adaptorPtr->pFormats; - i < adaptorPtr->nFormats; i++, formatPtr++) - { - numVisuals = pScreen->numVisuals; - pVisual = pScreen->visuals; - - while(numVisuals--) { - if((pVisual->class == formatPtr->class) && - (pVisual->nplanes == formatPtr->depth)) { - - if(numFormat >= totFormat) { - void *moreSpace; - totFormat *= 2; - moreSpace = realloc(pFormat, - totFormat * sizeof(XvFormatRec)); - if(!moreSpace) break; - pFormat = moreSpace; - pf = pFormat + numFormat; - } - - pf->visual = pVisual->vid; - pf->depth = formatPtr->depth; - - pf++; - numFormat++; - } - pVisual++; - } - } - pa->nFormats = numFormat; - pa->pFormats = pFormat; - if(!numFormat) { - xf86XVFreeAdaptor(pa); - continue; - } - - if(!(adaptorPriv = calloc(1, sizeof(XvAdaptorRecPrivate)))) { - xf86XVFreeAdaptor(pa); - continue; - } - - adaptorPriv->flags = adaptorPtr->flags; - adaptorPriv->PutVideo = adaptorPtr->PutVideo; - adaptorPriv->PutStill = adaptorPtr->PutStill; - adaptorPriv->GetVideo = adaptorPtr->GetVideo; - adaptorPriv->GetStill = adaptorPtr->GetStill; - adaptorPriv->StopVideo = adaptorPtr->StopVideo; - adaptorPriv->SetPortAttribute = adaptorPtr->SetPortAttribute; - adaptorPriv->GetPortAttribute = adaptorPtr->GetPortAttribute; - adaptorPriv->QueryBestSize = adaptorPtr->QueryBestSize; - adaptorPriv->QueryImageAttributes = adaptorPtr->QueryImageAttributes; - adaptorPriv->PutImage = adaptorPtr->PutImage; - adaptorPriv->ReputImage = adaptorPtr->ReputImage; /* image/still */ - - pa->devPriv.ptr = (pointer)adaptorPriv; - - if(!(pPort = calloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) { - xf86XVFreeAdaptor(pa); - continue; - } - for(pp = pPort, i = 0, numPort = 0; - i < adaptorPtr->nPorts; i++) { - - if(!(pp->id = FakeClientID(0))) - continue; - - if(!(portPriv = calloc(1, sizeof(XvPortRecPrivate)))) - continue; - - if(!AddResource(pp->id, PortResource, pp)) { - free(portPriv); - continue; - } - - pp->pAdaptor = pa; - pp->pNotify = (XvPortNotifyPtr)NULL; - pp->pDraw = (DrawablePtr)NULL; - pp->client = (ClientPtr)NULL; - pp->grab.client = (ClientPtr)NULL; - pp->time = currentTime; - pp->devPriv.ptr = portPriv; - - portPriv->pScrn = pScrn; - portPriv->AdaptorRec = adaptorPriv; - portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr; - - pp++; - numPort++; - } - pa->nPorts = numPort; - pa->pPorts = pPort; - if(!numPort) { - xf86XVFreeAdaptor(pa); - continue; - } - - pa->base_id = pPort->id; - - pa++; - numAdaptor++; - } - - if(numAdaptor) { - pxvs->nAdaptors = numAdaptor; - pxvs->pAdaptors = pAdaptor; - } else { - free(pAdaptor); - return FALSE; - } - - return TRUE; +xf86XVInitAdaptors(ScreenPtr pScreen, XF86VideoAdaptorPtr * infoPtr, int number) +{ + XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + XF86VideoAdaptorPtr adaptorPtr; + XvAdaptorPtr pAdaptor, pa; + XvAdaptorRecPrivatePtr adaptorPriv; + int na, numAdaptor; + XvPortRecPrivatePtr portPriv; + XvPortPtr pPort, pp; + int numPort; + XF86AttributePtr attributePtr; + XvAttributePtr pAttribute, pat; + XF86VideoFormatPtr formatPtr; + XvFormatPtr pFormat, pf; + int numFormat, totFormat; + XF86VideoEncodingPtr encodingPtr; + XvEncodingPtr pEncode, pe; + XF86ImagePtr imagePtr; + XvImagePtr pImage, pi; + int numVisuals; + VisualPtr pVisual; + int i; + + pxvs->nAdaptors = 0; + pxvs->pAdaptors = NULL; + + if (!(pAdaptor = calloc(number, sizeof(XvAdaptorRec)))) + return FALSE; + + for (pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) { + adaptorPtr = infoPtr[na]; + + if (!adaptorPtr->StopVideo || !adaptorPtr->SetPortAttribute || + !adaptorPtr->GetPortAttribute || !adaptorPtr->QueryBestSize) + continue; + + /* client libs expect at least one encoding */ + if (!adaptorPtr->nEncodings || !adaptorPtr->pEncodings) + continue; + + pa->type = adaptorPtr->type; + + if (!adaptorPtr->PutVideo && !adaptorPtr->GetVideo) + pa->type &= ~XvVideoMask; + + if (!adaptorPtr->PutStill && !adaptorPtr->GetStill) + pa->type &= ~XvStillMask; + + if (!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes) + pa->type &= ~XvImageMask; + + if (!adaptorPtr->PutVideo && !adaptorPtr->PutImage && + !adaptorPtr->PutStill) + pa->type &= ~XvInputMask; + + if (!adaptorPtr->GetVideo && !adaptorPtr->GetStill) + pa->type &= ~XvOutputMask; + + if (!(adaptorPtr->type & (XvPixmapMask | XvWindowMask))) + continue; + if (!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask))) + continue; + + pa->pScreen = pScreen; + pa->ddAllocatePort = xf86XVAllocatePort; + pa->ddFreePort = xf86XVFreePort; + pa->ddPutVideo = xf86XVPutVideo; + pa->ddPutStill = xf86XVPutStill; + pa->ddGetVideo = xf86XVGetVideo; + pa->ddGetStill = xf86XVGetStill; + pa->ddStopVideo = xf86XVStopVideo; + pa->ddPutImage = xf86XVPutImage; + pa->ddSetPortAttribute = xf86XVSetPortAttribute; + pa->ddGetPortAttribute = xf86XVGetPortAttribute; + pa->ddQueryBestSize = xf86XVQueryBestSize; + pa->ddQueryImageAttributes = xf86XVQueryImageAttributes; + pa->name = strdup(adaptorPtr->name); + + if (adaptorPtr->nEncodings && + (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { + + for (pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0; + i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++) { + pe->id = encodingPtr->id; + pe->pScreen = pScreen; + pe->name = strdup(encodingPtr->name); + pe->width = encodingPtr->width; + pe->height = encodingPtr->height; + pe->rate.numerator = encodingPtr->rate.numerator; + pe->rate.denominator = encodingPtr->rate.denominator; + } + pa->nEncodings = adaptorPtr->nEncodings; + pa->pEncodings = pEncode; + } + + if (adaptorPtr->nImages && + (pImage = calloc(adaptorPtr->nImages, sizeof(XvImageRec)))) { + + for (i = 0, pi = pImage, imagePtr = adaptorPtr->pImages; + i < adaptorPtr->nImages; i++, pi++, imagePtr++) { + pi->id = imagePtr->id; + pi->type = imagePtr->type; + pi->byte_order = imagePtr->byte_order; + memcpy(pi->guid, imagePtr->guid, 16); + pi->bits_per_pixel = imagePtr->bits_per_pixel; + pi->format = imagePtr->format; + pi->num_planes = imagePtr->num_planes; + pi->depth = imagePtr->depth; + pi->red_mask = imagePtr->red_mask; + pi->green_mask = imagePtr->green_mask; + pi->blue_mask = imagePtr->blue_mask; + pi->y_sample_bits = imagePtr->y_sample_bits; + pi->u_sample_bits = imagePtr->u_sample_bits; + pi->v_sample_bits = imagePtr->v_sample_bits; + pi->horz_y_period = imagePtr->horz_y_period; + pi->horz_u_period = imagePtr->horz_u_period; + pi->horz_v_period = imagePtr->horz_v_period; + pi->vert_y_period = imagePtr->vert_y_period; + pi->vert_u_period = imagePtr->vert_u_period; + pi->vert_v_period = imagePtr->vert_v_period; + memcpy(pi->component_order, imagePtr->component_order, 32); + pi->scanline_order = imagePtr->scanline_order; + } + pa->nImages = adaptorPtr->nImages; + pa->pImages = pImage; + } + + if (adaptorPtr->nAttributes && + (pAttribute = + calloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec)))) { + for (pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = + 0; i < adaptorPtr->nAttributes; pat++, i++, attributePtr++) { + pat->flags = attributePtr->flags; + pat->min_value = attributePtr->min_value; + pat->max_value = attributePtr->max_value; + pat->name = strdup(attributePtr->name); + } + pa->nAttributes = adaptorPtr->nAttributes; + pa->pAttributes = pAttribute; + } + + totFormat = adaptorPtr->nFormats; + + if (!(pFormat = calloc(totFormat, sizeof(XvFormatRec)))) { + xf86XVFreeAdaptor(pa); + continue; + } + for (pf = pFormat, i = 0, numFormat = 0, formatPtr = + adaptorPtr->pFormats; i < adaptorPtr->nFormats; i++, formatPtr++) { + numVisuals = pScreen->numVisuals; + pVisual = pScreen->visuals; + + while (numVisuals--) { + if ((pVisual->class == formatPtr->class) && + (pVisual->nplanes == formatPtr->depth)) { + + if (numFormat >= totFormat) { + void *moreSpace; + + totFormat *= 2; + moreSpace = realloc(pFormat, + totFormat * sizeof(XvFormatRec)); + if (!moreSpace) + break; + pFormat = moreSpace; + pf = pFormat + numFormat; + } + + pf->visual = pVisual->vid; + pf->depth = formatPtr->depth; + + pf++; + numFormat++; + } + pVisual++; + } + } + pa->nFormats = numFormat; + pa->pFormats = pFormat; + if (!numFormat) { + xf86XVFreeAdaptor(pa); + continue; + } + + if (!(adaptorPriv = calloc(1, sizeof(XvAdaptorRecPrivate)))) { + xf86XVFreeAdaptor(pa); + continue; + } + + adaptorPriv->flags = adaptorPtr->flags; + adaptorPriv->PutVideo = adaptorPtr->PutVideo; + adaptorPriv->PutStill = adaptorPtr->PutStill; + adaptorPriv->GetVideo = adaptorPtr->GetVideo; + adaptorPriv->GetStill = adaptorPtr->GetStill; + adaptorPriv->StopVideo = adaptorPtr->StopVideo; + adaptorPriv->SetPortAttribute = adaptorPtr->SetPortAttribute; + adaptorPriv->GetPortAttribute = adaptorPtr->GetPortAttribute; + adaptorPriv->QueryBestSize = adaptorPtr->QueryBestSize; + adaptorPriv->QueryImageAttributes = adaptorPtr->QueryImageAttributes; + adaptorPriv->PutImage = adaptorPtr->PutImage; + adaptorPriv->ReputImage = adaptorPtr->ReputImage; /* image/still */ + + pa->devPriv.ptr = (pointer) adaptorPriv; + + if (!(pPort = calloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) { + xf86XVFreeAdaptor(pa); + continue; + } + for (pp = pPort, i = 0, numPort = 0; i < adaptorPtr->nPorts; i++) { + + if (!(pp->id = FakeClientID(0))) + continue; + + if (!(portPriv = calloc(1, sizeof(XvPortRecPrivate)))) + continue; + + if (!AddResource(pp->id, PortResource, pp)) { + free(portPriv); + continue; + } + + pp->pAdaptor = pa; + pp->pNotify = (XvPortNotifyPtr) NULL; + pp->pDraw = (DrawablePtr) NULL; + pp->client = (ClientPtr) NULL; + pp->grab.client = (ClientPtr) NULL; + pp->time = currentTime; + pp->devPriv.ptr = portPriv; + + portPriv->pScrn = pScrn; + portPriv->AdaptorRec = adaptorPriv; + portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr; + + pp++; + numPort++; + } + pa->nPorts = numPort; + pa->pPorts = pPort; + if (!numPort) { + xf86XVFreeAdaptor(pa); + continue; + } + + pa->base_id = pPort->id; + + pa++; + numAdaptor++; + } + + if (numAdaptor) { + pxvs->nAdaptors = numAdaptor; + pxvs->pAdaptors = pAdaptor; + } + else { + free(pAdaptor); + return FALSE; + } + + return TRUE; } /* Video should be clipped to the intersection of the window cliplist @@ -650,66 +635,64 @@ xf86XVInitAdaptors( static void xf86XVUpdateCompositeClip(XvPortRecPrivatePtr portPriv) { - RegionPtr pregWin, pCompositeClip; - WindowPtr pWin; - Bool freeCompClip = FALSE; - - if(portPriv->pCompositeClip) - return; - - pWin = (WindowPtr)portPriv->pDraw; - - /* get window clip list */ - if(portPriv->subWindowMode == IncludeInferiors) { - pregWin = NotClippedByChildren(pWin); - freeCompClip = TRUE; - } else - pregWin = &pWin->clipList; - - if(!portPriv->clientClip) { - portPriv->pCompositeClip = pregWin; - portPriv->FreeCompositeClip = freeCompClip; - return; - } - - pCompositeClip = RegionCreate(NullBox, 1); - RegionCopy(pCompositeClip, portPriv->clientClip); - RegionTranslate(pCompositeClip, - portPriv->pDraw->x, portPriv->pDraw->y); - RegionIntersect(pCompositeClip, pregWin, pCompositeClip); - - portPriv->pCompositeClip = pCompositeClip; - portPriv->FreeCompositeClip = TRUE; - - if(freeCompClip) { - RegionDestroy(pregWin); - } + RegionPtr pregWin, pCompositeClip; + WindowPtr pWin; + Bool freeCompClip = FALSE; + + if (portPriv->pCompositeClip) + return; + + pWin = (WindowPtr) portPriv->pDraw; + + /* get window clip list */ + if (portPriv->subWindowMode == IncludeInferiors) { + pregWin = NotClippedByChildren(pWin); + freeCompClip = TRUE; + } + else + pregWin = &pWin->clipList; + + if (!portPriv->clientClip) { + portPriv->pCompositeClip = pregWin; + portPriv->FreeCompositeClip = freeCompClip; + return; + } + + pCompositeClip = RegionCreate(NullBox, 1); + RegionCopy(pCompositeClip, portPriv->clientClip); + RegionTranslate(pCompositeClip, portPriv->pDraw->x, portPriv->pDraw->y); + RegionIntersect(pCompositeClip, pregWin, pCompositeClip); + + portPriv->pCompositeClip = pCompositeClip; + portPriv->FreeCompositeClip = TRUE; + + if (freeCompClip) { + RegionDestroy(pregWin); + } } /* Save the current clientClip and update the CompositeClip whenever we have a fresh GC */ static void -xf86XVCopyClip( - XvPortRecPrivatePtr portPriv, - GCPtr pGC -){ +xf86XVCopyClip(XvPortRecPrivatePtr portPriv, GCPtr pGC) +{ /* copy the new clip if it exists */ - if((pGC->clientClipType == CT_REGION) && pGC->clientClip) { - if(!portPriv->clientClip) - portPriv->clientClip = RegionCreate(NullBox, 1); - /* Note: this is in window coordinates */ - RegionCopy(portPriv->clientClip, pGC->clientClip); - RegionTranslate(portPriv->clientClip, - pGC->clipOrg.x, pGC->clipOrg.y); - } else if(portPriv->clientClip) { /* free the old clientClip */ - RegionDestroy(portPriv->clientClip); - portPriv->clientClip = NULL; + if ((pGC->clientClipType == CT_REGION) && pGC->clientClip) { + if (!portPriv->clientClip) + portPriv->clientClip = RegionCreate(NullBox, 1); + /* Note: this is in window coordinates */ + RegionCopy(portPriv->clientClip, pGC->clientClip); + RegionTranslate(portPriv->clientClip, pGC->clipOrg.x, pGC->clipOrg.y); + } + else if (portPriv->clientClip) { /* free the old clientClip */ + RegionDestroy(portPriv->clientClip); + portPriv->clientClip = NULL; } /* get rid of the old clip list */ - if(portPriv->pCompositeClip && portPriv->FreeCompositeClip) { - RegionDestroy(portPriv->pCompositeClip); + if (portPriv->pCompositeClip && portPriv->FreeCompositeClip) { + RegionDestroy(portPriv->pCompositeClip); } portPriv->pCompositeClip = pGC->pCompositeClip; @@ -719,19 +702,17 @@ xf86XVCopyClip( static void xf86XVCopyCompositeClip(XvPortRecPrivatePtr portPriv, - GCPtr pGC, - DrawablePtr pDraw) + GCPtr pGC, DrawablePtr pDraw) { if (!portPriv->clientClip) - portPriv->clientClip = RegionCreate(NullBox, 1); + portPriv->clientClip = RegionCreate(NullBox, 1); /* Keep the original GC composite clip around for ReputImage */ RegionCopy(portPriv->clientClip, pGC->pCompositeClip); - RegionTranslate(portPriv->clientClip, - -pDraw->x, -pDraw->y); + RegionTranslate(portPriv->clientClip, -pDraw->x, -pDraw->y); /* get rid of the old clip list */ if (portPriv->pCompositeClip && portPriv->FreeCompositeClip) - RegionDestroy(portPriv->pCompositeClip); + RegionDestroy(portPriv->pCompositeClip); portPriv->pCompositeClip = pGC->pCompositeClip; portPriv->FreeCompositeClip = FALSE; @@ -741,257 +722,257 @@ xf86XVCopyCompositeClip(XvPortRecPrivatePtr portPriv, static int xf86XVRegetVideo(XvPortRecPrivatePtr portPriv) { - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* that's all if it's totally obscured */ - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->GetVideo)(portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - portPriv->pDraw); - - if(ret == Success) - portPriv->isOn = XV_ON; - -CLIP_VIDEO_BAILOUT: - - if((clippedAway || (ret != Success)) && portPriv->isOn == XV_ON) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if(!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + xf86XVUpdateCompositeClip(portPriv); + + /* translate the video region to the screen */ + WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; + WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; + WinBox.x2 = WinBox.x1 + portPriv->drw_w; + WinBox.y2 = WinBox.y1 + portPriv->drw_h; + + /* clip to the window composite clip */ + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); + + /* that's all if it's totally obscured */ + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto CLIP_VIDEO_BAILOUT; + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->GetVideo) (portPriv->pScrn, + portPriv->vid_x, portPriv->vid_y, + WinBox.x1, WinBox.y1, + portPriv->vid_w, portPriv->vid_h, + portPriv->drw_w, portPriv->drw_h, + &ClipRegion, portPriv->DevPriv.ptr, + portPriv->pDraw); + + if (ret == Success) + portPriv->isOn = XV_ON; + + CLIP_VIDEO_BAILOUT: + + if ((clippedAway || (ret != Success)) && portPriv->isOn == XV_ON) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + /* This clip was copied and only good for one shot */ + if (!portPriv->FreeCompositeClip) + portPriv->pCompositeClip = NULL; + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; +} static int xf86XVReputVideo(XvPortRecPrivatePtr portPriv) { - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - /* bailout if we have to clip but the hardware doesn't support it */ - if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { - BoxPtr clipBox = RegionRects(&ClipRegion); - if( (RegionNumRects(&ClipRegion) != 1) || - (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || - (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) - { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->PutVideo)(portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - portPriv->pDraw); - - if(ret == Success) portPriv->isOn = XV_ON; - -CLIP_VIDEO_BAILOUT: - - if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if(!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + xf86XVUpdateCompositeClip(portPriv); + + /* translate the video region to the screen */ + WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; + WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; + WinBox.x2 = WinBox.x1 + portPriv->drw_w; + WinBox.y2 = WinBox.y1 + portPriv->drw_h; + + /* clip to the window composite clip */ + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); + + /* clip and translate to the viewport */ + if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { + RegionRec VPReg; + BoxRec VPBox; + + VPBox.x1 = portPriv->pScrn->frameX0; + VPBox.y1 = portPriv->pScrn->frameY0; + VPBox.x2 = portPriv->pScrn->frameX1 + 1; + VPBox.y2 = portPriv->pScrn->frameY1 + 1; + + RegionInit(&VPReg, &VPBox, 1); + RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); + RegionUninit(&VPReg); + } + + /* that's all if it's totally obscured */ + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto CLIP_VIDEO_BAILOUT; + } + + /* bailout if we have to clip but the hardware doesn't support it */ + if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { + BoxPtr clipBox = RegionRects(&ClipRegion); + + if ((RegionNumRects(&ClipRegion) != 1) || + (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || + (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) { + clippedAway = TRUE; + goto CLIP_VIDEO_BAILOUT; + } + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->pScrn, + portPriv->vid_x, portPriv->vid_y, + WinBox.x1, WinBox.y1, + portPriv->vid_w, portPriv->vid_h, + portPriv->drw_w, portPriv->drw_h, + &ClipRegion, portPriv->DevPriv.ptr, + portPriv->pDraw); + + if (ret == Success) + portPriv->isOn = XV_ON; + + CLIP_VIDEO_BAILOUT: + + if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + + /* This clip was copied and only good for one shot */ + if (!portPriv->FreeCompositeClip) + portPriv->pCompositeClip = NULL; + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; } /* Reput image/still */ static int xf86XVReputImage(XvPortRecPrivatePtr portPriv) { - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* the clip can get smaller over time */ - RegionCopy(portPriv->clientClip, portPriv->pCompositeClip); - RegionTranslate(portPriv->clientClip, - -portPriv->pDraw->x, -portPriv->pDraw->y); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - /* bailout if we have to clip but the hardware doesn't support it */ - if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { - BoxPtr clipBox = RegionRects(&ClipRegion); - if( (RegionNumRects(&ClipRegion) != 1) || - (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || - (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) - { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->ReputImage)(portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - portPriv->pDraw); - - portPriv->isOn = (ret == Success) ? XV_ON : XV_OFF; - -CLIP_VIDEO_BAILOUT: - - if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if(!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + xf86XVUpdateCompositeClip(portPriv); + + /* the clip can get smaller over time */ + RegionCopy(portPriv->clientClip, portPriv->pCompositeClip); + RegionTranslate(portPriv->clientClip, + -portPriv->pDraw->x, -portPriv->pDraw->y); + + /* translate the video region to the screen */ + WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; + WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; + WinBox.x2 = WinBox.x1 + portPriv->drw_w; + WinBox.y2 = WinBox.y1 + portPriv->drw_h; + + /* clip to the window composite clip */ + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); + + /* clip and translate to the viewport */ + if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { + RegionRec VPReg; + BoxRec VPBox; + + VPBox.x1 = portPriv->pScrn->frameX0; + VPBox.y1 = portPriv->pScrn->frameY0; + VPBox.x2 = portPriv->pScrn->frameX1 + 1; + VPBox.y2 = portPriv->pScrn->frameY1 + 1; + + RegionInit(&VPReg, &VPBox, 1); + RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); + RegionUninit(&VPReg); + } + + /* that's all if it's totally obscured */ + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto CLIP_VIDEO_BAILOUT; + } + + /* bailout if we have to clip but the hardware doesn't support it */ + if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { + BoxPtr clipBox = RegionRects(&ClipRegion); + + if ((RegionNumRects(&ClipRegion) != 1) || + (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || + (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) { + clippedAway = TRUE; + goto CLIP_VIDEO_BAILOUT; + } + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->ReputImage) (portPriv->pScrn, + portPriv->vid_x, portPriv->vid_y, + WinBox.x1, WinBox.y1, + portPriv->vid_w, portPriv->vid_h, + portPriv->drw_w, portPriv->drw_h, + &ClipRegion, + portPriv->DevPriv.ptr, + portPriv->pDraw); + portPriv->isOn = (ret == Success) ? XV_ON : XV_OFF; + + CLIP_VIDEO_BAILOUT: + + if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + + /* This clip was copied and only good for one shot */ + if (!portPriv->FreeCompositeClip) + portPriv->pCompositeClip = NULL; + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; +} static int xf86XVReputAllVideo(WindowPtr pWin, pointer data) { XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - while(WinPriv) { - if(WinPriv->PortRec->type == XvInputMask) - xf86XVReputVideo(WinPriv->PortRec); - else - xf86XVRegetVideo(WinPriv->PortRec); - WinPriv = WinPriv->next; + while (WinPriv) { + if (WinPriv->PortRec->type == XvInputMask) + xf86XVReputVideo(WinPriv->PortRec); + else + xf86XVRegetVideo(WinPriv->PortRec); + WinPriv = WinPriv->next; } return WT_WALKCHILDREN; @@ -1000,86 +981,86 @@ xf86XVReputAllVideo(WindowPtr pWin, pointer data) static int xf86XVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) { - XF86XVWindowPtr winPriv, PrivRoot; + XF86XVWindowPtr winPriv, PrivRoot; - winPriv = PrivRoot = GET_XF86XV_WINDOW(pWin); + winPriv = PrivRoot = GET_XF86XV_WINDOW(pWin); - /* Enlist our port in the window private */ - while(winPriv) { - if(winPriv->PortRec == portPriv) /* we're already listed */ - break; - winPriv = winPriv->next; - } + /* Enlist our port in the window private */ + while (winPriv) { + if (winPriv->PortRec == portPriv) /* we're already listed */ + break; + winPriv = winPriv->next; + } - if(!winPriv) { - winPriv = calloc(1, sizeof(XF86XVWindowRec)); - if(!winPriv) return BadAlloc; - winPriv->PortRec = portPriv; - winPriv->next = PrivRoot; - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv); - } + if (!winPriv) { + winPriv = calloc(1, sizeof(XF86XVWindowRec)); + if (!winPriv) + return BadAlloc; + winPriv->PortRec = portPriv; + winPriv->next = PrivRoot; + dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv); + } - portPriv->pDraw = (DrawablePtr)pWin; + portPriv->pDraw = (DrawablePtr) pWin; - return Success; + return Success; } - static void xf86XVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) { - XF86XVWindowPtr winPriv, prevPriv = NULL; - winPriv = GET_XF86XV_WINDOW(pWin); - - while(winPriv) { - if(winPriv->PortRec == portPriv) { - if(prevPriv) - prevPriv->next = winPriv->next; - else - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, - winPriv->next); - free(winPriv); - break; - } - prevPriv = winPriv; - winPriv = winPriv->next; - } - portPriv->pDraw = NULL; - if (portPriv->ckeyFilled) { - RegionDestroy(portPriv->ckeyFilled); - portPriv->ckeyFilled = NULL; - } - portPriv->clipChanged = FALSE; + XF86XVWindowPtr winPriv, prevPriv = NULL; + + winPriv = GET_XF86XV_WINDOW(pWin); + + while (winPriv) { + if (winPriv->PortRec == portPriv) { + if (prevPriv) + prevPriv->next = winPriv->next; + else + dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, + winPriv->next); + free(winPriv); + break; + } + prevPriv = winPriv; + winPriv = winPriv->next; + } + portPriv->pDraw = NULL; + if (portPriv->ckeyFilled) { + RegionDestroy(portPriv->ckeyFilled); + portPriv->ckeyFilled = NULL; + } + portPriv->clipChanged = FALSE; } static void -xf86XVReputOrStopPort(XvPortRecPrivatePtr pPriv, - WindowPtr pWin, - Bool visible) +xf86XVReputOrStopPort(XvPortRecPrivatePtr pPriv, WindowPtr pWin, Bool visible) { if (!visible) { - if (pPriv->isOn == XV_ON) { - (*pPriv->AdaptorRec->StopVideo)(pPriv->pScrn, pPriv->DevPriv.ptr, FALSE); - pPriv->isOn = XV_PENDING; - } + if (pPriv->isOn == XV_ON) { + (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, pPriv->DevPriv.ptr, + FALSE); + pPriv->isOn = XV_PENDING; + } - if (!pPriv->type) /* overlaid still/image*/ - xf86XVRemovePortFromWindow(pWin, pPriv); + if (!pPriv->type) /* overlaid still/image */ + xf86XVRemovePortFromWindow(pWin, pPriv); - return; + return; } switch (pPriv->type) { case XvInputMask: - xf86XVReputVideo(pPriv); - break; + xf86XVReputVideo(pPriv); + break; case XvOutputMask: - xf86XVRegetVideo(pPriv); - break; - default: /* overlaid still/image*/ - if (pPriv->AdaptorRec->ReputImage) - xf86XVReputImage(pPriv); - break; + xf86XVRegetVideo(pPriv); + break; + default: /* overlaid still/image */ + if (pPriv->AdaptorRec->ReputImage) + xf86XVReputImage(pPriv); + break; } } @@ -1092,33 +1073,34 @@ xf86XVReputOrStopAllPorts(ScrnInfoPtr pScrn, Bool onlyChanged) int c, i; for (c = pxvs->nAdaptors, pa = pxvs->pAdaptors; c > 0; c--, pa++) { - XvPortPtr pPort = pa->pPorts; + XvPortPtr pPort = pa->pPorts; - for (i = pa->nPorts; i > 0; i--, pPort++) { - XvPortRecPrivatePtr pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr; - WindowPtr pWin = (WindowPtr)pPriv->pDraw; - Bool visible; + for (i = pa->nPorts; i > 0; i--, pPort++) { + XvPortRecPrivatePtr pPriv = + (XvPortRecPrivatePtr) pPort->devPriv.ptr; + WindowPtr pWin = (WindowPtr) pPriv->pDraw; + Bool visible; - if (pPriv->isOn == XV_OFF || !pWin) - continue; + if (pPriv->isOn == XV_OFF || !pWin) + continue; - if (onlyChanged && !pPriv->clipChanged) - continue; + if (onlyChanged && !pPriv->clipChanged) + continue; - visible = pWin->visibility == VisibilityUnobscured || - pWin->visibility == VisibilityPartiallyObscured; + visible = pWin->visibility == VisibilityUnobscured || + pWin->visibility == VisibilityPartiallyObscured; - /* - * Stop and remove still/images if - * ReputImage isn't supported. - */ - if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) - visible = FALSE; + /* + * Stop and remove still/images if + * ReputImage isn't supported. + */ + if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) + visible = FALSE; - xf86XVReputOrStopPort(pPriv, pWin, visible); + xf86XVReputOrStopPort(pPriv, pWin, visible); - pPriv->clipChanged = FALSE; - } + pPriv->clipChanged = FALSE; + } } } @@ -1127,33 +1109,33 @@ xf86XVReputOrStopAllPorts(ScrnInfoPtr pScrn, Bool onlyChanged) static Bool xf86XVDestroyWindow(WindowPtr pWin) { - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr tmp, WinPriv = GET_XF86XV_WINDOW(pWin); - int ret; - - while(WinPriv) { - XvPortRecPrivatePtr pPriv = WinPriv->PortRec; - - if(pPriv->isOn > XV_OFF) { - (*pPriv->AdaptorRec->StopVideo)( - pPriv->pScrn, pPriv->DevPriv.ptr, TRUE); - pPriv->isOn = XV_OFF; - } + ScreenPtr pScreen = pWin->drawable.pScreen; + XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); + XF86XVWindowPtr tmp, WinPriv = GET_XF86XV_WINDOW(pWin); + int ret; - pPriv->pDraw = NULL; - tmp = WinPriv; - WinPriv = WinPriv->next; - free(tmp); - } + while (WinPriv) { + XvPortRecPrivatePtr pPriv = WinPriv->PortRec; + + if (pPriv->isOn > XV_OFF) { + (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, pPriv->DevPriv.ptr, + TRUE); + pPriv->isOn = XV_OFF; + } + + pPriv->pDraw = NULL; + tmp = WinPriv; + WinPriv = WinPriv->next; + free(tmp); + } - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, NULL); + dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, NULL); - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - ret = (*pScreen->DestroyWindow)(pWin); - pScreen->DestroyWindow = xf86XVDestroyWindow; + pScreen->DestroyWindow = ScreenPriv->DestroyWindow; + ret = (*pScreen->DestroyWindow) (pWin); + pScreen->DestroyWindow = xf86XVDestroyWindow; - return ret; + return ret; } static void @@ -1164,9 +1146,9 @@ xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind) ScrnInfoPtr pScrn; if (pWin) - pScreen = pWin->drawable.pScreen; + pScreen = pWin->drawable.pScreen; else - pScreen = pLayerWin->drawable.pScreen; + pScreen = pLayerWin->drawable.pScreen; ScreenPriv = GET_XF86XV_SCREEN(pScreen); pScrn = xf86Screens[pScreen->myNum]; @@ -1175,7 +1157,7 @@ xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind) pScreen->PostValidateTree = ScreenPriv->PostValidateTree; if (pScreen->PostValidateTree) { - (*pScreen->PostValidateTree)(pWin, pLayerWin, kind); + (*pScreen->PostValidateTree) (pWin, pLayerWin, kind); } ScreenPriv->PostValidateTree = PostValidateTreeUndefined; } @@ -1183,140 +1165,137 @@ xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind) static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2) { - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - XvPortRecPrivatePtr pPriv; - Bool AreasExposed; - - AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1)); - - pScreen->WindowExposures = ScreenPriv->WindowExposures; - (*pScreen->WindowExposures)(pWin, reg1, reg2); - pScreen->WindowExposures = xf86XVWindowExposures; - - /* filter out XClearWindow/Area */ - if (!pWin->valdata) return; - - while(WinPriv) { - Bool visible = TRUE; - - pPriv = WinPriv->PortRec; - - /* - * Stop and remove still/images if areas were exposed and - * ReputImage isn't supported. - */ - if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) - visible = !AreasExposed; - - /* - * Subtract exposed areas from overlaid image to match textured video - * behavior. - */ - if (!pPriv->type && pPriv->clientClip) - RegionSubtract(pPriv->clientClip, pPriv->clientClip, reg1); - - if (visible && pPriv->ckeyFilled) { - RegionRec tmp; - RegionNull(&tmp); - RegionCopy(&tmp, reg1); - RegionTranslate(&tmp, pWin->drawable.x, pWin->drawable.y); - RegionSubtract(pPriv->ckeyFilled, pPriv->ckeyFilled, &tmp); - } - - WinPriv = WinPriv->next; - xf86XVReputOrStopPort(pPriv, pWin, visible); - - pPriv->clipChanged = FALSE; - } + ScreenPtr pScreen = pWin->drawable.pScreen; + XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); + XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); + XvPortRecPrivatePtr pPriv; + Bool AreasExposed; + + AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1)); + + pScreen->WindowExposures = ScreenPriv->WindowExposures; + (*pScreen->WindowExposures) (pWin, reg1, reg2); + pScreen->WindowExposures = xf86XVWindowExposures; + + /* filter out XClearWindow/Area */ + if (!pWin->valdata) + return; + + while (WinPriv) { + Bool visible = TRUE; + + pPriv = WinPriv->PortRec; + + /* + * Stop and remove still/images if areas were exposed and + * ReputImage isn't supported. + */ + if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) + visible = !AreasExposed; + + /* + * Subtract exposed areas from overlaid image to match textured video + * behavior. + */ + if (!pPriv->type && pPriv->clientClip) + RegionSubtract(pPriv->clientClip, pPriv->clientClip, reg1); + + if (visible && pPriv->ckeyFilled) { + RegionRec tmp; + + RegionNull(&tmp); + RegionCopy(&tmp, reg1); + RegionTranslate(&tmp, pWin->drawable.x, pWin->drawable.y); + RegionSubtract(pPriv->ckeyFilled, pPriv->ckeyFilled, &tmp); + } + + WinPriv = WinPriv->next; + xf86XVReputOrStopPort(pPriv, pWin, visible); + + pPriv->clipChanged = FALSE; + } } static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy) { - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - XvPortRecPrivatePtr pPriv; + ScreenPtr pScreen = pWin->drawable.pScreen; + XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); + XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); + XvPortRecPrivatePtr pPriv; - while(WinPriv) { - pPriv = WinPriv->PortRec; + while (WinPriv) { + pPriv = WinPriv->PortRec; - if(pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); + if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) + RegionDestroy(pPriv->pCompositeClip); - pPriv->pCompositeClip = NULL; + pPriv->pCompositeClip = NULL; - if (pPriv->AdaptorRec->ClipNotify) - (*pPriv->AdaptorRec->ClipNotify)(pPriv->pScrn, pPriv->DevPriv.ptr, - pWin, dx, dy); + if (pPriv->AdaptorRec->ClipNotify) + (*pPriv->AdaptorRec->ClipNotify) (pPriv->pScrn, pPriv->DevPriv.ptr, + pWin, dx, dy); - pPriv->clipChanged = TRUE; + pPriv->clipChanged = TRUE; - if (ScreenPriv->PostValidateTree == PostValidateTreeUndefined) { - ScreenPriv->PostValidateTree = pScreen->PostValidateTree; - pScreen->PostValidateTree = xf86XVPostValidateTree; - } + if (ScreenPriv->PostValidateTree == PostValidateTreeUndefined) { + ScreenPriv->PostValidateTree = pScreen->PostValidateTree; + pScreen->PostValidateTree = xf86XVPostValidateTree; + } - WinPriv = WinPriv->next; - } + WinPriv = WinPriv->next; + } - if(ScreenPriv->ClipNotify) { - pScreen->ClipNotify = ScreenPriv->ClipNotify; - (*pScreen->ClipNotify)(pWin, dx, dy); - pScreen->ClipNotify = xf86XVClipNotify; - } + if (ScreenPriv->ClipNotify) { + pScreen->ClipNotify = ScreenPriv->ClipNotify; + (*pScreen->ClipNotify) (pWin, dx, dy); + pScreen->ClipNotify = xf86XVClipNotify; + } } - - /**** Required XvScreenRec fields ****/ static Bool xf86XVCloseScreen(int i, ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XvAdaptorPtr pa; - int c; - - if(!ScreenPriv) return TRUE; - - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - pScreen->WindowExposures = ScreenPriv->WindowExposures; - pScreen->ClipNotify = ScreenPriv->ClipNotify; - - pScrn->EnterVT = ScreenPriv->EnterVT; - pScrn->LeaveVT = ScreenPriv->LeaveVT; - pScrn->AdjustFrame = ScreenPriv->AdjustFrame; - pScrn->ModeSet = ScreenPriv->ModeSet; - - for(c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) { - xf86XVFreeAdaptor(pa); - } - - free(pxvs->pAdaptors); - free(ScreenPriv); - return TRUE; -} + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); + XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); + XvAdaptorPtr pa; + int c; + if (!ScreenPriv) + return TRUE; -static int -xf86XVQueryAdaptors( - ScreenPtr pScreen, - XvAdaptorPtr *p_pAdaptors, - int *p_nAdaptors -){ - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); + pScreen->DestroyWindow = ScreenPriv->DestroyWindow; + pScreen->WindowExposures = ScreenPriv->WindowExposures; + pScreen->ClipNotify = ScreenPriv->ClipNotify; + + pScrn->EnterVT = ScreenPriv->EnterVT; + pScrn->LeaveVT = ScreenPriv->LeaveVT; + pScrn->AdjustFrame = ScreenPriv->AdjustFrame; + pScrn->ModeSet = ScreenPriv->ModeSet; - *p_nAdaptors = pxvs->nAdaptors; - *p_pAdaptors = pxvs->pAdaptors; + for (c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) { + xf86XVFreeAdaptor(pa); + } - return Success; + free(pxvs->pAdaptors); + free(ScreenPriv); + return TRUE; } +static int +xf86XVQueryAdaptors(ScreenPtr pScreen, + XvAdaptorPtr * p_pAdaptors, int *p_nAdaptors) +{ + XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); + + *p_nAdaptors = pxvs->nAdaptors; + *p_pAdaptors = pxvs->pAdaptors; + + return Success; +} /**** ScrnInfoRec fields ****/ @@ -1329,11 +1308,12 @@ xf86XVEnterVT(int index, int flags) Bool ret; pScrn->EnterVT = ScreenPriv->EnterVT; - ret = (*ScreenPriv->EnterVT)(index, flags); + ret = (*ScreenPriv->EnterVT) (index, flags); ScreenPriv->EnterVT = pScrn->EnterVT; pScrn->EnterVT = xf86XVEnterVT; - if(ret) WalkTree(pScreen, xf86XVReputAllVideo, 0); + if (ret) + WalkTree(pScreen, xf86XVReputAllVideo, 0); return ret; } @@ -1350,31 +1330,31 @@ xf86XVLeaveVT(int index, int flags) XvPortRecPrivatePtr pPriv; int i, j; - for(i = 0; i < pxvs->nAdaptors; i++) { - pAdaptor = &pxvs->pAdaptors[i]; - for(j = 0; j < pAdaptor->nPorts; j++) { - pPort = &pAdaptor->pPorts[j]; - pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr; - if(pPriv->isOn > XV_OFF) { + for (i = 0; i < pxvs->nAdaptors; i++) { + pAdaptor = &pxvs->pAdaptors[i]; + for (j = 0; j < pAdaptor->nPorts; j++) { + pPort = &pAdaptor->pPorts[j]; + pPriv = (XvPortRecPrivatePtr) pPort->devPriv.ptr; + if (pPriv->isOn > XV_OFF) { - (*pPriv->AdaptorRec->StopVideo)( - pPriv->pScrn, pPriv->DevPriv.ptr, TRUE); - pPriv->isOn = XV_OFF; + (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, + pPriv->DevPriv.ptr, TRUE); + pPriv->isOn = XV_OFF; - if(pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); + if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) + RegionDestroy(pPriv->pCompositeClip); - pPriv->pCompositeClip = NULL; + pPriv->pCompositeClip = NULL; - if(!pPriv->type && pPriv->pDraw) { /* still */ - xf86XVRemovePortFromWindow((WindowPtr)pPriv->pDraw, pPriv); - } - } - } + if (!pPriv->type && pPriv->pDraw) { /* still */ + xf86XVRemovePortFromWindow((WindowPtr) pPriv->pDraw, pPriv); + } + } + } } pScrn->LeaveVT = ScreenPriv->LeaveVT; - (*ScreenPriv->LeaveVT)(index, flags); + (*ScreenPriv->LeaveVT) (index, flags); ScreenPriv->LeaveVT = pScrn->LeaveVT; pScrn->LeaveVT = xf86XVLeaveVT; } @@ -1382,17 +1362,17 @@ xf86XVLeaveVT(int index, int flags) static void xf86XVAdjustFrame(int index, int x, int y, int flags) { - ScrnInfoPtr pScrn = xf86Screens[index]; - ScreenPtr pScreen = pScrn->pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); + ScrnInfoPtr pScrn = xf86Screens[index]; + ScreenPtr pScreen = pScrn->pScreen; + XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - if(ScreenPriv->AdjustFrame) { - pScrn->AdjustFrame = ScreenPriv->AdjustFrame; - (*pScrn->AdjustFrame)(index, x, y, flags); - pScrn->AdjustFrame = xf86XVAdjustFrame; - } + if (ScreenPriv->AdjustFrame) { + pScrn->AdjustFrame = ScreenPriv->AdjustFrame; + (*pScrn->AdjustFrame) (index, x, y, flags); + pScrn->AdjustFrame = xf86XVAdjustFrame; + } - xf86XVReputOrStopAllPorts(pScrn, FALSE); + xf86XVReputOrStopAllPorts(pScrn, FALSE); } static void @@ -1403,14 +1383,14 @@ xf86XVModeSet(ScrnInfoPtr pScrn) /* Can be called before pScrn->pScreen is set */ if (!pScreen) - return; + return; ScreenPriv = GET_XF86XV_SCREEN(pScreen); if (ScreenPriv->ModeSet) { - pScrn->ModeSet = ScreenPriv->ModeSet; - (*pScrn->ModeSet)(pScrn); - pScrn->ModeSet = xf86XVModeSet; + pScrn->ModeSet = ScreenPriv->ModeSet; + (*pScrn->ModeSet) (pScrn); + pScrn->ModeSet = xf86XVModeSet; } xf86XVReputOrStopAllPorts(pScrn, FALSE); @@ -1419,589 +1399,583 @@ xf86XVModeSet(ScrnInfoPtr pScrn) /**** XvAdaptorRec fields ****/ static int -xf86XVAllocatePort( - unsigned long port, - XvPortPtr pPort, - XvPortPtr *ppPort -){ - *ppPort = pPort; - return Success; +xf86XVAllocatePort(unsigned long port, XvPortPtr pPort, XvPortPtr * ppPort) +{ + *ppPort = pPort; + return Success; } - - static int xf86XVFreePort(XvPortPtr pPort) { - return Success; + return Success; } - static int -xf86XVPutVideo( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - int result; - - /* No dumping video to pixmaps... For now anyhow */ - if(pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr)NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if(portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv); - if(result != Success) return result; - - portPriv->type = XvInputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - xf86XVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ - - return(xf86XVReputVideo(portPriv)); +xf86XVPutVideo(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + int result; + + /* No dumping video to pixmaps... For now anyhow */ + if (pDraw->type != DRAWABLE_WINDOW) { + pPort->pDraw = (DrawablePtr) NULL; + return BadAlloc; + } + + /* If we are changing windows, unregister our port in the old window */ + if (portPriv->pDraw && (portPriv->pDraw != pDraw)) + xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); + + /* Register our port with the new window */ + result = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); + if (result != Success) + return result; + + portPriv->type = XvInputMask; + + /* save a copy of these parameters */ + portPriv->vid_x = vid_x; + portPriv->vid_y = vid_y; + portPriv->vid_w = vid_w; + portPriv->vid_h = vid_h; + portPriv->drw_x = drw_x; + portPriv->drw_y = drw_y; + portPriv->drw_w = drw_w; + portPriv->drw_h = drw_h; + + /* make sure we have the most recent copy of the clientClip */ + xf86XVCopyClip(portPriv, pGC); + + /* To indicate to the DI layer that we were successful */ + pPort->pDraw = pDraw; + + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ + + return (xf86XVReputVideo(portPriv)); } static int -xf86XVPutStill( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - xf86XVCopyCompositeClip(portPriv, pGC, pDraw); - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - if(portPriv->pDraw) { - xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv); - } - - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_STILL_BAILOUT; - } - - if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { - BoxPtr clipBox = RegionRects(&ClipRegion); - if( (RegionNumRects(&ClipRegion) != 1) || - (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || - (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) - { - clippedAway = TRUE; - goto PUT_STILL_BAILOUT; - } - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->PutStill)(portPriv->pScrn, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - pDraw); - - if((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_STILLS)) { - - xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv); - portPriv->isOn = XV_ON; - portPriv->vid_x = vid_x; portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - -PUT_STILL_BAILOUT: - - if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if(!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; +xf86XVPutStill(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + if (pDraw->type != DRAWABLE_WINDOW) + return BadAlloc; + + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ + + WinBox.x1 = pDraw->x + drw_x; + WinBox.y1 = pDraw->y + drw_y; + WinBox.x2 = WinBox.x1 + drw_w; + WinBox.y2 = WinBox.y1 + drw_h; + + xf86XVCopyCompositeClip(portPriv, pGC, pDraw); + + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); + + if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { + RegionRec VPReg; + BoxRec VPBox; + + VPBox.x1 = portPriv->pScrn->frameX0; + VPBox.y1 = portPriv->pScrn->frameY0; + VPBox.x2 = portPriv->pScrn->frameX1 + 1; + VPBox.y2 = portPriv->pScrn->frameY1 + 1; + + RegionInit(&VPReg, &VPBox, 1); + RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); + RegionUninit(&VPReg); + } + + if (portPriv->pDraw) { + xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); + } + + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto PUT_STILL_BAILOUT; + } + + if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { + BoxPtr clipBox = RegionRects(&ClipRegion); + + if ((RegionNumRects(&ClipRegion) != 1) || + (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || + (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) { + clippedAway = TRUE; + goto PUT_STILL_BAILOUT; + } + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->PutStill) (portPriv->pScrn, + vid_x, vid_y, WinBox.x1, WinBox.y1, + vid_w, vid_h, drw_w, drw_h, + &ClipRegion, portPriv->DevPriv.ptr, + pDraw); + + if ((ret == Success) && + (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_STILLS)) { + + xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); + portPriv->isOn = XV_ON; + portPriv->vid_x = vid_x; + portPriv->vid_y = vid_y; + portPriv->vid_w = vid_w; + portPriv->vid_h = vid_h; + portPriv->drw_x = drw_x; + portPriv->drw_y = drw_y; + portPriv->drw_w = drw_w; + portPriv->drw_h = drw_h; + portPriv->type = 0; /* no mask means it's transient and should + not be reput once it's removed */ + pPort->pDraw = pDraw; /* make sure we can get stop requests */ + } + + PUT_STILL_BAILOUT: + + if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + + /* This clip was copied and only good for one shot */ + if (!portPriv->FreeCompositeClip) + portPriv->pCompositeClip = NULL; + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; } static int -xf86XVGetVideo( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - int result; - - /* No pixmaps... For now anyhow */ - if(pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr)NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if(portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv); - if(result != Success) return result; - - portPriv->type = XvOutputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - xf86XVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ - - return(xf86XVRegetVideo(portPriv)); +xf86XVGetVideo(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + int result; + + /* No pixmaps... For now anyhow */ + if (pDraw->type != DRAWABLE_WINDOW) { + pPort->pDraw = (DrawablePtr) NULL; + return BadAlloc; + } + + /* If we are changing windows, unregister our port in the old window */ + if (portPriv->pDraw && (portPriv->pDraw != pDraw)) + xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); + + /* Register our port with the new window */ + result = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); + if (result != Success) + return result; + + portPriv->type = XvOutputMask; + + /* save a copy of these parameters */ + portPriv->vid_x = vid_x; + portPriv->vid_y = vid_y; + portPriv->vid_w = vid_w; + portPriv->vid_h = vid_h; + portPriv->drw_x = drw_x; + portPriv->drw_y = drw_y; + portPriv->drw_w = drw_w; + portPriv->drw_h = drw_h; + + /* make sure we have the most recent copy of the clientClip */ + xf86XVCopyClip(portPriv, pGC); + + /* To indicate to the DI layer that we were successful */ + pPort->pDraw = pDraw; + + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ + + return (xf86XVRegetVideo(portPriv)); } static int -xf86XVGetStill( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if(portPriv->pDraw) { - xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv); - } - - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto GET_STILL_BAILOUT; - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->GetStill)(portPriv->pScrn, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - pDraw); - -GET_STILL_BAILOUT: - - if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} +xf86XVGetStill(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + if (pDraw->type != DRAWABLE_WINDOW) + return BadAlloc; + + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ + + WinBox.x1 = pDraw->x + drw_x; + WinBox.y1 = pDraw->y + drw_y; + WinBox.x2 = WinBox.x1 + drw_w; + WinBox.y2 = WinBox.y1 + drw_h; + + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); + + if (portPriv->pDraw) { + xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); + } + + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto GET_STILL_BAILOUT; + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->GetStill) (portPriv->pScrn, + vid_x, vid_y, WinBox.x1, WinBox.y1, + vid_w, vid_h, drw_w, drw_h, + &ClipRegion, portPriv->DevPriv.ptr, + pDraw); + GET_STILL_BAILOUT: + if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; +} static int -xf86XVStopVideo( - ClientPtr client, - XvPortPtr pPort, - DrawablePtr pDraw -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); +xf86XVStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - if(pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; + if (pDraw->type != DRAWABLE_WINDOW) + return BadAlloc; - xf86XVRemovePortFromWindow((WindowPtr)pDraw, portPriv); + xf86XVRemovePortFromWindow((WindowPtr) pDraw, portPriv); - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ - /* Must free resources. */ + /* Must free resources. */ - if(portPriv->isOn > XV_OFF) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, TRUE); - portPriv->isOn = XV_OFF; - } + if (portPriv->isOn > XV_OFF) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, TRUE); + portPriv->isOn = XV_OFF; + } - return Success; + return Success; } static int -xf86XVSetPortAttribute( - ClientPtr client, - XvPortPtr pPort, - Atom attribute, - INT32 value -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - - return((*portPriv->AdaptorRec->SetPortAttribute)(portPriv->pScrn, - attribute, value, portPriv->DevPriv.ptr)); -} +xf86XVSetPortAttribute(ClientPtr client, + XvPortPtr pPort, Atom attribute, INT32 value) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + return ((*portPriv->AdaptorRec->SetPortAttribute) (portPriv->pScrn, + attribute, value, + portPriv->DevPriv.ptr)); +} static int -xf86XVGetPortAttribute( - ClientPtr client, - XvPortPtr pPort, - Atom attribute, - INT32 *p_value -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - - return((*portPriv->AdaptorRec->GetPortAttribute)(portPriv->pScrn, - attribute, p_value, portPriv->DevPriv.ptr)); +xf86XVGetPortAttribute(ClientPtr client, + XvPortPtr pPort, Atom attribute, INT32 *p_value) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + + return ((*portPriv->AdaptorRec->GetPortAttribute) (portPriv->pScrn, + attribute, p_value, + portPriv->DevPriv.ptr)); } +static int +xf86XVQueryBestSize(ClientPtr client, + XvPortPtr pPort, + CARD8 motion, + CARD16 vid_w, CARD16 vid_h, + CARD16 drw_w, CARD16 drw_h, + unsigned int *p_w, unsigned int *p_h) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + (*portPriv->AdaptorRec->QueryBestSize) (portPriv->pScrn, + (Bool) motion, vid_w, vid_h, drw_w, + drw_h, p_w, p_h, + portPriv->DevPriv.ptr); -static int -xf86XVQueryBestSize( - ClientPtr client, - XvPortPtr pPort, - CARD8 motion, - CARD16 vid_w, CARD16 vid_h, - CARD16 drw_w, CARD16 drw_h, - unsigned int *p_w, unsigned int *p_h -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - - (*portPriv->AdaptorRec->QueryBestSize)(portPriv->pScrn, - (Bool)motion, vid_w, vid_h, drw_w, drw_h, - p_w, p_h, portPriv->DevPriv.ptr); - - return Success; + return Success; } - static int -xf86XVPutImage( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - 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* data, - Bool sync, - CARD16 width, CARD16 height -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if(!portPriv->pScrn->vtSema) return Success; /* Success ? */ - - xf86XVCopyCompositeClip(portPriv, pGC, pDraw); - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* If we are changing windows, unregister our port in the old window */ - if(portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - ret = xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv); - if(ret != Success) goto PUT_IMAGE_BAILOUT; - - if(!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_IMAGE_BAILOUT; - } - - if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { - BoxPtr clipBox = RegionRects(&ClipRegion); - if( (RegionNumRects(&ClipRegion) != 1) || - (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || - (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) - { - clippedAway = TRUE; - goto PUT_IMAGE_BAILOUT; - } - } - - if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { - RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); - } - - ret = (*portPriv->AdaptorRec->PutImage)(portPriv->pScrn, - src_x, src_y, WinBox.x1, WinBox.y1, - src_w, src_h, drw_w, drw_h, format->id, data, width, height, - sync, &ClipRegion, portPriv->DevPriv.ptr, - pDraw); - - if((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_IMAGES)) { - - portPriv->isOn = XV_ON; - portPriv->vid_x = src_x; portPriv->vid_y = src_y; - portPriv->vid_w = src_w; portPriv->vid_h = src_h; - portPriv->drw_x = drw_x; portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - -PUT_IMAGE_BAILOUT: - - if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo)( - portPriv->pScrn, portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if(!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; +xf86XVPutImage(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + 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 *data, Bool sync, CARD16 width, CARD16 height) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + RegionRec WinRegion; + RegionRec ClipRegion; + BoxRec WinBox; + int ret = Success; + Bool clippedAway = FALSE; + + if (pDraw->type != DRAWABLE_WINDOW) + return BadAlloc; + + if (!portPriv->pScrn->vtSema) + return Success; /* Success ? */ + + xf86XVCopyCompositeClip(portPriv, pGC, pDraw); + + WinBox.x1 = pDraw->x + drw_x; + WinBox.y1 = pDraw->y + drw_y; + WinBox.x2 = WinBox.x1 + drw_w; + WinBox.y2 = WinBox.y1 + drw_h; + + RegionInit(&WinRegion, &WinBox, 1); + RegionNull(&ClipRegion); + RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); + + if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { + RegionRec VPReg; + BoxRec VPBox; + + VPBox.x1 = portPriv->pScrn->frameX0; + VPBox.y1 = portPriv->pScrn->frameY0; + VPBox.x2 = portPriv->pScrn->frameX1 + 1; + VPBox.y2 = portPriv->pScrn->frameY1 + 1; + + RegionInit(&VPReg, &VPBox, 1); + RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); + RegionUninit(&VPReg); + } + + /* If we are changing windows, unregister our port in the old window */ + if (portPriv->pDraw && (portPriv->pDraw != pDraw)) + xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); + + /* Register our port with the new window */ + ret = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); + if (ret != Success) + goto PUT_IMAGE_BAILOUT; + + if (!RegionNotEmpty(&ClipRegion)) { + clippedAway = TRUE; + goto PUT_IMAGE_BAILOUT; + } + + if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) { + BoxPtr clipBox = RegionRects(&ClipRegion); + + if ((RegionNumRects(&ClipRegion) != 1) || + (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || + (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) { + clippedAway = TRUE; + goto PUT_IMAGE_BAILOUT; + } + } + + if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) { + RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion); + } + + ret = (*portPriv->AdaptorRec->PutImage) (portPriv->pScrn, + src_x, src_y, WinBox.x1, WinBox.y1, + src_w, src_h, drw_w, drw_h, + format->id, data, width, height, + sync, &ClipRegion, + portPriv->DevPriv.ptr, pDraw); + + if ((ret == Success) && + (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_IMAGES)) { + + portPriv->isOn = XV_ON; + portPriv->vid_x = src_x; + portPriv->vid_y = src_y; + portPriv->vid_w = src_w; + portPriv->vid_h = src_h; + portPriv->drw_x = drw_x; + portPriv->drw_y = drw_y; + portPriv->drw_w = drw_w; + portPriv->drw_h = drw_h; + portPriv->type = 0; /* no mask means it's transient and should + not be reput once it's removed */ + pPort->pDraw = pDraw; /* make sure we can get stop requests */ + } + + PUT_IMAGE_BAILOUT: + + if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { + (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, + portPriv->DevPriv.ptr, FALSE); + portPriv->isOn = XV_PENDING; + } + + /* This clip was copied and only good for one shot */ + if (!portPriv->FreeCompositeClip) + portPriv->pCompositeClip = NULL; + + RegionUninit(&WinRegion); + RegionUninit(&ClipRegion); + + return ret; } +static int +xf86XVQueryImageAttributes(ClientPtr client, + XvPortPtr pPort, + XvImagePtr format, + CARD16 *width, + CARD16 *height, int *pitches, int *offsets) +{ + XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); -static int -xf86XVQueryImageAttributes( - ClientPtr client, - XvPortPtr pPort, - XvImagePtr format, - CARD16 *width, - CARD16 *height, - int *pitches, - int *offsets -){ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); - - return (*portPriv->AdaptorRec->QueryImageAttributes)(portPriv->pScrn, - format->id, width, height, pitches, offsets); + return (*portPriv->AdaptorRec->QueryImageAttributes) (portPriv->pScrn, + format->id, width, + height, pitches, + offsets); } void -xf86XVFillKeyHelperDrawable (DrawablePtr pDraw, CARD32 key, RegionPtr fillboxes) +xf86XVFillKeyHelperDrawable(DrawablePtr pDraw, CARD32 key, RegionPtr fillboxes) { - ScreenPtr pScreen = pDraw->pScreen; - ChangeGCVal pval[2]; - BoxPtr pbox = RegionRects(fillboxes); - int i, nbox = RegionNumRects(fillboxes); - xRectangle *rects; - GCPtr gc; - - if(!xf86Screens[pScreen->myNum]->vtSema) return; - - gc = GetScratchGC(pDraw->depth, pScreen); - pval[0].val = key; - pval[1].val = IncludeInferiors; - (void) ChangeGC(NullClient, gc, GCForeground|GCSubwindowMode, pval); - ValidateGC(pDraw, gc); - - rects = malloc(nbox * sizeof(xRectangle)); - - for(i = 0; i < nbox; i++, pbox++) - { - rects[i].x = pbox->x1 - pDraw->x; - rects[i].y = pbox->y1 - pDraw->y; - rects[i].width = pbox->x2 - pbox->x1; - rects[i].height = pbox->y2 - pbox->y1; - } - - (*gc->ops->PolyFillRect)(pDraw, gc, nbox, rects); - - free(rects); - FreeScratchGC (gc); + ScreenPtr pScreen = pDraw->pScreen; + ChangeGCVal pval[2]; + BoxPtr pbox = RegionRects(fillboxes); + int i, nbox = RegionNumRects(fillboxes); + xRectangle *rects; + GCPtr gc; + + if (!xf86Screens[pScreen->myNum]->vtSema) + return; + + gc = GetScratchGC(pDraw->depth, pScreen); + pval[0].val = key; + pval[1].val = IncludeInferiors; + (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval); + ValidateGC(pDraw, gc); + + rects = malloc(nbox * sizeof(xRectangle)); + + for (i = 0; i < nbox; i++, pbox++) { + rects[i].x = pbox->x1 - pDraw->x; + rects[i].y = pbox->y1 - pDraw->y; + rects[i].width = pbox->x2 - pbox->x1; + rects[i].height = pbox->y2 - pbox->y1; + } + + (*gc->ops->PolyFillRect) (pDraw, gc, nbox, rects); + + free(rects); + FreeScratchGC(gc); } void -xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr fillboxes) +xf86XVFillKeyHelper(ScreenPtr pScreen, CARD32 key, RegionPtr fillboxes) { - xf86XVFillKeyHelperDrawable (&pScreen->root->drawable, key, fillboxes); + xf86XVFillKeyHelperDrawable(&pScreen->root->drawable, key, fillboxes); } void -xf86XVFillKeyHelperPort (DrawablePtr pDraw, pointer data, CARD32 key, RegionPtr clipboxes, Bool fillEverything) +xf86XVFillKeyHelperPort(DrawablePtr pDraw, pointer data, CARD32 key, + RegionPtr clipboxes, Bool fillEverything) { - WindowPtr pWin = (WindowPtr)pDraw; + WindowPtr pWin = (WindowPtr) pDraw; XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); XvPortRecPrivatePtr portPriv = NULL; RegionRec reg; RegionPtr fillboxes; while (WinPriv) { - XvPortRecPrivatePtr pPriv = WinPriv->PortRec; + XvPortRecPrivatePtr pPriv = WinPriv->PortRec; - if (data == pPriv->DevPriv.ptr) { - portPriv = pPriv; - break; - } + if (data == pPriv->DevPriv.ptr) { + portPriv = pPriv; + break; + } - WinPriv = WinPriv->next; + WinPriv = WinPriv->next; } if (!portPriv) - return; + return; if (!portPriv->ckeyFilled) - portPriv->ckeyFilled = RegionCreate(NULL, 0); + portPriv->ckeyFilled = RegionCreate(NULL, 0); if (!fillEverything) { - RegionNull(®); - fillboxes = ® - RegionSubtract(fillboxes, clipboxes, portPriv->ckeyFilled); - - if (!RegionNotEmpty(fillboxes)) - goto out; - } else - fillboxes = clipboxes; + RegionNull(®); + fillboxes = ® + RegionSubtract(fillboxes, clipboxes, portPriv->ckeyFilled); + if (!RegionNotEmpty(fillboxes)) + goto out; + } + else + fillboxes = clipboxes; RegionCopy(portPriv->ckeyFilled, clipboxes); xf86XVFillKeyHelperDrawable(pDraw, key, fillboxes); -out: + out: if (!fillEverything) RegionUninit(®); } - /* xf86XVClipVideoHelper - Takes the dst box in standard X BoxRec form (top and left @@ -2012,16 +1986,12 @@ out: */ Bool -xf86XVClipVideoHelper( - BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, - RegionPtr reg, - INT32 width, - INT32 height -){ +xf86XVClipVideoHelper(BoxPtr dst, + INT32 *xa, + INT32 *xb, + INT32 *ya, + INT32 *yb, RegionPtr reg, INT32 width, INT32 height) +{ double xsw, xdw, ysw, ydw; INT32 delta; BoxPtr extents = RegionExtents(reg); @@ -2032,159 +2002,168 @@ xf86XVClipVideoHelper( ysw = (*yb - *ya) << 16; ydw = dst->y2 - dst->y1; - *xa <<= 16; *xb <<= 16; - *ya <<= 16; *yb <<= 16; + *xa <<= 16; + *xb <<= 16; + *ya <<= 16; + *yb <<= 16; diff = extents->x1 - dst->x1; if (diff > 0) { - dst->x1 = extents->x1; - *xa += (diff * xsw) / xdw; + dst->x1 = extents->x1; + *xa += (diff * xsw) / xdw; } diff = dst->x2 - extents->x2; if (diff > 0) { - dst->x2 = extents->x2; - *xb -= (diff * xsw) / xdw; + dst->x2 = extents->x2; + *xb -= (diff * xsw) / xdw; } diff = extents->y1 - dst->y1; if (diff > 0) { - dst->y1 = extents->y1; - *ya += (diff * ysw) / ydw; + dst->y1 = extents->y1; + *ya += (diff * ysw) / ydw; } diff = dst->y2 - extents->y2; if (diff > 0) { - dst->y2 = extents->y2; - *yb -= (diff * ysw) / ydw; + dst->y2 = extents->y2; + *yb -= (diff * ysw) / ydw; } if (*xa < 0) { - diff = (((-*xa) * xdw) + xsw - 1) / xsw; - dst->x1 += diff; - *xa += (diff * xsw) / xdw; + diff = (((-*xa) * xdw) + xsw - 1) / xsw; + dst->x1 += diff; + *xa += (diff * xsw) / xdw; } delta = *xb - (width << 16); if (delta > 0) { - diff = ((delta * xdw) + xsw - 1) / xsw; - dst->x2 -= diff; - *xb -= (diff * xsw) / xdw; + diff = ((delta * xdw) + xsw - 1) / xsw; + dst->x2 -= diff; + *xb -= (diff * xsw) / xdw; } - if (*xa >= *xb) return FALSE; + if (*xa >= *xb) + return FALSE; if (*ya < 0) { - diff = (((-*ya) * ydw) + ysw - 1) / ysw; - dst->y1 += diff; - *ya += (diff * ysw) / ydw; + diff = (((-*ya) * ydw) + ysw - 1) / ysw; + dst->y1 += diff; + *ya += (diff * ysw) / ydw; } delta = *yb - (height << 16); if (delta > 0) { - diff = ((delta * ydw) + ysw - 1) / ysw; - dst->y2 -= diff; - *yb -= (diff * ysw) / ydw; + diff = ((delta * ydw) + ysw - 1) / ysw; + dst->y2 -= diff; + *yb -= (diff * ysw) / ydw; } - if (*ya >= *yb) return FALSE; + if (*ya >= *yb) + return FALSE; if ((dst->x1 > extents->x1) || (dst->x2 < extents->x2) || - (dst->y1 > extents->y1) || (dst->y2 < extents->y2)) - { - RegionRec clipReg; - RegionInit(&clipReg, dst, 1); - RegionIntersect(reg, reg, &clipReg); - RegionUninit(&clipReg); + (dst->y1 > extents->y1) || (dst->y2 < extents->y2)) { + RegionRec clipReg; + + RegionInit(&clipReg, dst, 1); + RegionIntersect(reg, reg, &clipReg); + RegionUninit(&clipReg); } return TRUE; } void -xf86XVCopyYUV12ToPacked( - const void *srcy, - const void *srcv, - const void *srcu, - void *dst, - int srcPitchy, - int srcPitchuv, - int dstPitch, - int h, - int w -){ +xf86XVCopyYUV12ToPacked(const void *srcy, + const void *srcv, + const void *srcu, + void *dst, + int srcPitchy, + int srcPitchuv, int dstPitch, int h, int w) +{ CARD32 *Dst; const CARD8 *Y, *U, *V; int i, j; w >>= 1; - for (j = 0; j < h; j++) { - Dst = dst; - Y = srcy; V = srcv; U = srcu; - i = w; - while (i >= 4) { + for (j = 0; j < h; j++) { + Dst = dst; + Y = srcy; + V = srcv; + U = srcu; + i = w; + while (i >= 4) { #if X_BYTE_ORDER == X_LITTLE_ENDIAN - Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); - Dst[1] = Y[2] | (Y[3] << 16) | (U[1] << 8) | (V[1] << 24); - Dst[2] = Y[4] | (Y[5] << 16) | (U[2] << 8) | (V[2] << 24); - Dst[3] = Y[6] | (Y[7] << 16) | (U[3] << 8) | (V[3] << 24); + Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); + Dst[1] = Y[2] | (Y[3] << 16) | (U[1] << 8) | (V[1] << 24); + Dst[2] = Y[4] | (Y[5] << 16) | (U[2] << 8) | (V[2] << 24); + Dst[3] = Y[6] | (Y[7] << 16) | (U[3] << 8) | (V[3] << 24); #else - /* This assumes a little-endian framebuffer */ - Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; - Dst[1] = (Y[2] << 24) | (Y[3] << 8) | (U[1] << 16) | V[1]; - Dst[2] = (Y[4] << 24) | (Y[5] << 8) | (U[2] << 16) | V[2]; - Dst[3] = (Y[6] << 24) | (Y[7] << 8) | (U[3] << 16) | V[3]; + /* This assumes a little-endian framebuffer */ + Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; + Dst[1] = (Y[2] << 24) | (Y[3] << 8) | (U[1] << 16) | V[1]; + Dst[2] = (Y[4] << 24) | (Y[5] << 8) | (U[2] << 16) | V[2]; + Dst[3] = (Y[6] << 24) | (Y[7] << 8) | (U[3] << 16) | V[3]; #endif - Dst += 4; Y += 8; V += 4; U += 4; - i -= 4; - } - - while (i--) { + Dst += 4; + Y += 8; + V += 4; + U += 4; + i -= 4; + } + + while (i--) { #if X_BYTE_ORDER == X_LITTLE_ENDIAN - Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); + Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); #else - /* This assumes a little-endian framebuffer */ - Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; + /* This assumes a little-endian framebuffer */ + Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; #endif - Dst++; Y += 2; V++; U++; - } - - dst = (CARD8 *)dst + dstPitch; - srcy = (const CARD8 *)srcy + srcPitchy; - if (j & 1) { - srcu = (const CARD8 *)srcu + srcPitchuv; - srcv = (const CARD8 *)srcv + srcPitchuv; - } + Dst++; + Y += 2; + V++; + U++; + } + + dst = (CARD8 *) dst + dstPitch; + srcy = (const CARD8 *) srcy + srcPitchy; + if (j & 1) { + srcu = (const CARD8 *) srcu + srcPitchuv; + srcv = (const CARD8 *) srcv + srcPitchuv; + } } } void -xf86XVCopyPacked( - const void *src, - void *dst, - int srcPitch, - int dstPitch, - int h, - int w -){ +xf86XVCopyPacked(const void *src, + void *dst, int srcPitch, int dstPitch, int h, int w) +{ const CARD32 *Src; CARD32 *Dst; int i; w >>= 1; while (--h >= 0) { - do { - Dst = dst; Src = src; - i = w; - while (i >= 4) { - Dst[0] = Src[0]; - Dst[1] = Src[1]; - Dst[2] = Src[2]; - Dst[3] = Src[3]; - Dst += 4; Src += 4; i -= 4; - } - if (!i) break; - Dst[0] = Src[0]; - if (i == 1) break; - Dst[1] = Src[1]; - if (i == 2) break; - Dst[2] = Src[2]; - } while (0); - - src = (const CARD8 *)src + srcPitch; - dst = (CARD8 *)dst + dstPitch; + do { + Dst = dst; + Src = src; + i = w; + while (i >= 4) { + Dst[0] = Src[0]; + Dst[1] = Src[1]; + Dst[2] = Src[2]; + Dst[3] = Src[3]; + Dst += 4; + Src += 4; + i -= 4; + } + if (!i) + break; + Dst[0] = Src[0]; + if (i == 1) + break; + Dst[1] = Src[1]; + if (i == 2) + break; + Dst[2] = Src[2]; + } while (0); + + src = (const CARD8 *) src + srcPitch; + dst = (CARD8 *) dst + dstPitch; } } diff --git a/xorg-server/hw/xfree86/common/xf86xv.h b/xorg-server/hw/xfree86/common/xf86xv.h index 08e5c790d..2db00a83f 100644 --- a/xorg-server/hw/xfree86/common/xf86xv.h +++ b/xorg-server/hw/xfree86/common/xf86xv.h @@ -1,289 +1,270 @@ -
-/*
- * Copyright (c) 1998-2003 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifndef _XF86XV_H_
-#define _XF86XV_H_
-
-#include "xvdix.h"
-#include "xf86str.h"
-
-#define VIDEO_NO_CLIPPING 0x00000001
-#define VIDEO_INVERT_CLIPLIST 0x00000002
-#define VIDEO_OVERLAID_IMAGES 0x00000004
-#define VIDEO_OVERLAID_STILLS 0x00000008
-/*
- * Usage of VIDEO_CLIP_TO_VIEWPORT is not recommended.
- * It can make reput behaviour inconsistent.
- */
-#define VIDEO_CLIP_TO_VIEWPORT 0x00000010
-
-typedef struct {
- int id;
- int type;
- int byte_order;
- unsigned char guid[16];
- int bits_per_pixel;
- int format;
- int num_planes;
-
- /* for RGB formats only */
- int depth;
- unsigned int red_mask;
- unsigned int green_mask;
- unsigned int blue_mask;
-
- /* for YUV formats only */
- unsigned int y_sample_bits;
- unsigned int u_sample_bits;
- unsigned int v_sample_bits;
- unsigned int horz_y_period;
- unsigned int horz_u_period;
- unsigned int horz_v_period;
- unsigned int vert_y_period;
- unsigned int vert_u_period;
- unsigned int vert_v_period;
- char component_order[32];
- int scanline_order;
-} XF86ImageRec, *XF86ImagePtr;
-
-
-typedef struct {
- ScrnInfoPtr pScrn;
- int id;
- unsigned short width, height;
- int *pitches; /* bytes */
- int *offsets; /* in bytes from start of framebuffer */
- DevUnion devPrivate;
-} XF86SurfaceRec, *XF86SurfacePtr;
-
-
-typedef int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
- short vid_x, short vid_y, short drw_x, short drw_y,
- short vid_w, short vid_h, short drw_w, short drw_h,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
- short vid_x, short vid_y, short drw_x, short drw_y,
- short vid_w, short vid_h, short drw_w, short drw_h,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
- short vid_x, short vid_y, short drw_x, short drw_y,
- short vid_w, short vid_h, short drw_w, short drw_h,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
- short vid_x, short vid_y, short drw_x, short drw_y,
- short vid_w, short vid_h, short drw_w, short drw_h,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn, pointer data, Bool Exit);
-typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, Atom attribute,
- INT32 value, pointer data);
-typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, Atom attribute,
- INT32 *value, pointer data);
-typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn, Bool motion,
- short vid_w, short vid_h, short drw_w, short drw_h,
- unsigned int *p_w, unsigned int *p_h, pointer data);
-typedef int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
- short src_x, short src_y, short drw_x, short drw_y,
- short src_w, short src_h, short drw_w, short drw_h,
- int image, unsigned char* buf, short width, short height, Bool Sync,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef int (* ReputImageFuncPtr)( ScrnInfoPtr pScrn,
- short src_x, short src_y, short drw_x, short drw_y,
- short src_w, short src_h, short drw_w, short drw_h,
- RegionPtr clipBoxes, pointer data, DrawablePtr pDraw );
-typedef int (*QueryImageAttributesFuncPtr)(ScrnInfoPtr pScrn,
- int image, unsigned short *width, unsigned short *height,
- int *pitches, int *offsets);
-typedef void (*ClipNotifyFuncPtr)(ScrnInfoPtr pScrn, pointer data,
- WindowPtr window, int dx, int dy);
-
-typedef enum {
- XV_OFF,
- XV_PENDING,
- XV_ON
-} XvStatus;
-
-/*** this is what the driver needs to fill out ***/
-
-typedef struct {
- int id;
- char *name;
- unsigned short width, height;
- XvRationalRec rate;
-} XF86VideoEncodingRec, *XF86VideoEncodingPtr;
-
-typedef struct {
- char depth;
- short class;
-} XF86VideoFormatRec, *XF86VideoFormatPtr;
-
-typedef struct {
- int flags;
- int min_value;
- int max_value;
- char *name;
-} XF86AttributeRec, *XF86AttributePtr;
-
-typedef struct {
- unsigned int type;
- int flags;
- char *name;
- int nEncodings;
- XF86VideoEncodingPtr pEncodings;
- int nFormats;
- XF86VideoFormatPtr pFormats;
- int nPorts;
- DevUnion *pPortPrivates;
- int nAttributes;
- XF86AttributePtr pAttributes;
- int nImages;
- XF86ImagePtr pImages;
- PutVideoFuncPtr PutVideo;
- PutStillFuncPtr PutStill;
- GetVideoFuncPtr GetVideo;
- GetStillFuncPtr GetStill;
- StopVideoFuncPtr StopVideo;
- SetPortAttributeFuncPtr SetPortAttribute;
- GetPortAttributeFuncPtr GetPortAttribute;
- QueryBestSizeFuncPtr QueryBestSize;
- PutImageFuncPtr PutImage;
- ReputImageFuncPtr ReputImage; /* image/still */
- QueryImageAttributesFuncPtr QueryImageAttributes;
- ClipNotifyFuncPtr ClipNotify;
-} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
-
-typedef struct {
- XF86ImagePtr image;
- int flags;
- int (*alloc_surface)(ScrnInfoPtr pScrn,
- int id,
- unsigned short width,
- unsigned short height,
- XF86SurfacePtr surface);
- int (*free_surface)(XF86SurfacePtr surface);
- int (*display) (XF86SurfacePtr surface,
- short vid_x, short vid_y,
- short drw_x, short drw_y,
- short vid_w, short vid_h,
- short drw_w, short drw_h,
- RegionPtr clipBoxes);
- int (*stop) (XF86SurfacePtr surface);
- int (*getAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 *value);
- int (*setAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 value);
- int max_width;
- int max_height;
- int num_attributes;
- XF86AttributePtr attributes;
-} XF86OffscreenImageRec, *XF86OffscreenImagePtr;
-
-extern _X_EXPORT Bool
-xf86XVScreenInit(
- ScreenPtr pScreen,
- XF86VideoAdaptorPtr *Adaptors,
- int num
-);
-
-typedef int (* xf86XVInitGenericAdaptorPtr)(ScrnInfoPtr pScrn,
- XF86VideoAdaptorPtr **Adaptors);
-
-extern _X_EXPORT int
-xf86XVRegisterGenericAdaptorDriver(
- xf86XVInitGenericAdaptorPtr InitFunc
-);
-
-extern _X_EXPORT int
-xf86XVListGenericAdaptors(
- ScrnInfoPtr pScrn,
- XF86VideoAdaptorPtr **Adaptors
-);
-
-extern _X_EXPORT Bool
-xf86XVRegisterOffscreenImages(
- ScreenPtr pScreen,
- XF86OffscreenImagePtr images,
- int num
-);
-
-extern _X_EXPORT XF86OffscreenImagePtr
-xf86XVQueryOffscreenImages(
- ScreenPtr pScreen,
- int *num
-);
-
-extern _X_EXPORT XF86VideoAdaptorPtr xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr pScrn);
-
-extern _X_EXPORT void xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr);
-
-extern _X_EXPORT void
-xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes);
-
-extern _X_EXPORT void
-xf86XVFillKeyHelperDrawable (DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes);
-
-extern _X_EXPORT void
-xf86XVFillKeyHelperPort (DrawablePtr pDraw, pointer data, CARD32 key, RegionPtr clipboxes, Bool fillEverything);
-
-extern _X_EXPORT Bool
-xf86XVClipVideoHelper(
- BoxPtr dst,
- INT32 *xa,
- INT32 *xb,
- INT32 *ya,
- INT32 *yb,
- RegionPtr reg,
- INT32 width,
- INT32 height
-);
-
-extern _X_EXPORT void
-xf86XVCopyYUV12ToPacked(
- const void *srcy,
- const void *srcv,
- const void *srcu,
- void *dst,
- int srcPitchy,
- int srcPitchuv,
- int dstPitch,
- int h,
- int w
-);
-
-extern _X_EXPORT void
-xf86XVCopyPacked(
- const void *src,
- void *dst,
- int srcPitch,
- int dstPitch,
- int h,
- int w
-);
-
-extern _X_EXPORT DevPrivateKey (*XvGetScreenKeyProc)(void);
-extern _X_EXPORT unsigned long (*XvGetRTPortProc)(void);
-extern _X_EXPORT int (*XvScreenInitProc)(ScreenPtr);
-
-#endif /* _XF86XV_H_ */
+ +/* + * Copyright (c) 1998-2003 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifndef _XF86XV_H_ +#define _XF86XV_H_ + +#include "xvdix.h" +#include "xf86str.h" + +#define VIDEO_NO_CLIPPING 0x00000001 +#define VIDEO_INVERT_CLIPLIST 0x00000002 +#define VIDEO_OVERLAID_IMAGES 0x00000004 +#define VIDEO_OVERLAID_STILLS 0x00000008 +/* + * Usage of VIDEO_CLIP_TO_VIEWPORT is not recommended. + * It can make reput behaviour inconsistent. + */ +#define VIDEO_CLIP_TO_VIEWPORT 0x00000010 + +typedef struct { + int id; + int type; + int byte_order; + unsigned char guid[16]; + int bits_per_pixel; + int format; + int num_planes; + + /* for RGB formats only */ + int depth; + unsigned int red_mask; + unsigned int green_mask; + unsigned int blue_mask; + + /* for YUV formats only */ + unsigned int y_sample_bits; + unsigned int u_sample_bits; + unsigned int v_sample_bits; + unsigned int horz_y_period; + unsigned int horz_u_period; + unsigned int horz_v_period; + unsigned int vert_y_period; + unsigned int vert_u_period; + unsigned int vert_v_period; + char component_order[32]; + int scanline_order; +} XF86ImageRec, *XF86ImagePtr; + +typedef struct { + ScrnInfoPtr pScrn; + int id; + unsigned short width, height; + int *pitches; /* bytes */ + int *offsets; /* in bytes from start of framebuffer */ + DevUnion devPrivate; +} XF86SurfaceRec, *XF86SurfacePtr; + +typedef int (*PutVideoFuncPtr) (ScrnInfoPtr pScrn, + short vid_x, short vid_y, short drw_x, + short drw_y, short vid_w, short vid_h, + short drw_w, short drw_h, RegionPtr clipBoxes, + pointer data, DrawablePtr pDraw); +typedef int (*PutStillFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, + short drw_x, short drw_y, short vid_w, + short vid_h, short drw_w, short drw_h, + RegionPtr clipBoxes, pointer data, + DrawablePtr pDraw); +typedef int (*GetVideoFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, + short drw_x, short drw_y, short vid_w, + short vid_h, short drw_w, short drw_h, + RegionPtr clipBoxes, pointer data, + DrawablePtr pDraw); +typedef int (*GetStillFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, + short drw_x, short drw_y, short vid_w, + short vid_h, short drw_w, short drw_h, + RegionPtr clipBoxes, pointer data, + DrawablePtr pDraw); +typedef void (*StopVideoFuncPtr) (ScrnInfoPtr pScrn, pointer data, Bool Exit); +typedef int (*SetPortAttributeFuncPtr) (ScrnInfoPtr pScrn, Atom attribute, + INT32 value, pointer data); +typedef int (*GetPortAttributeFuncPtr) (ScrnInfoPtr pScrn, Atom attribute, + INT32 *value, pointer data); +typedef void (*QueryBestSizeFuncPtr) (ScrnInfoPtr pScrn, Bool motion, + short vid_w, short vid_h, short drw_w, + short drw_h, unsigned int *p_w, + unsigned int *p_h, pointer data); +typedef int (*PutImageFuncPtr) (ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, + short src_h, short drw_w, short drw_h, + int image, unsigned char *buf, short width, + short height, Bool Sync, RegionPtr clipBoxes, + pointer data, DrawablePtr pDraw); +typedef int (*ReputImageFuncPtr) (ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, + short src_h, short drw_w, short drw_h, + RegionPtr clipBoxes, pointer data, + DrawablePtr pDraw); +typedef int (*QueryImageAttributesFuncPtr) (ScrnInfoPtr pScrn, int image, + unsigned short *width, + unsigned short *height, + int *pitches, int *offsets); +typedef void (*ClipNotifyFuncPtr) (ScrnInfoPtr pScrn, pointer data, + WindowPtr window, int dx, int dy); + +typedef enum { + XV_OFF, + XV_PENDING, + XV_ON +} XvStatus; + +/*** this is what the driver needs to fill out ***/ + +typedef struct { + int id; + char *name; + unsigned short width, height; + XvRationalRec rate; +} XF86VideoEncodingRec, *XF86VideoEncodingPtr; + +typedef struct { + char depth; + short class; +} XF86VideoFormatRec, *XF86VideoFormatPtr; + +typedef struct { + int flags; + int min_value; + int max_value; + char *name; +} XF86AttributeRec, *XF86AttributePtr; + +typedef struct { + unsigned int type; + int flags; + char *name; + int nEncodings; + XF86VideoEncodingPtr pEncodings; + int nFormats; + XF86VideoFormatPtr pFormats; + int nPorts; + DevUnion *pPortPrivates; + int nAttributes; + XF86AttributePtr pAttributes; + int nImages; + XF86ImagePtr pImages; + PutVideoFuncPtr PutVideo; + PutStillFuncPtr PutStill; + GetVideoFuncPtr GetVideo; + GetStillFuncPtr GetStill; + StopVideoFuncPtr StopVideo; + SetPortAttributeFuncPtr SetPortAttribute; + GetPortAttributeFuncPtr GetPortAttribute; + QueryBestSizeFuncPtr QueryBestSize; + PutImageFuncPtr PutImage; + ReputImageFuncPtr ReputImage; /* image/still */ + QueryImageAttributesFuncPtr QueryImageAttributes; + ClipNotifyFuncPtr ClipNotify; +} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr; + +typedef struct { + XF86ImagePtr image; + int flags; + int (*alloc_surface) (ScrnInfoPtr pScrn, + int id, + unsigned short width, + unsigned short height, XF86SurfacePtr surface); + int (*free_surface) (XF86SurfacePtr surface); + int (*display) (XF86SurfacePtr surface, + short vid_x, short vid_y, + short drw_x, short drw_y, + short vid_w, short vid_h, + short drw_w, short drw_h, RegionPtr clipBoxes); + int (*stop) (XF86SurfacePtr surface); + int (*getAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 *value); + int (*setAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 value); + int max_width; + int max_height; + int num_attributes; + XF86AttributePtr attributes; +} XF86OffscreenImageRec, *XF86OffscreenImagePtr; + +extern _X_EXPORT Bool + xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * Adaptors, int num); + +typedef int (*xf86XVInitGenericAdaptorPtr) (ScrnInfoPtr pScrn, + XF86VideoAdaptorPtr ** Adaptors); + +extern _X_EXPORT int + xf86XVRegisterGenericAdaptorDriver(xf86XVInitGenericAdaptorPtr InitFunc); + +extern _X_EXPORT int + xf86XVListGenericAdaptors(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr ** Adaptors); + +extern _X_EXPORT Bool + +xf86XVRegisterOffscreenImages(ScreenPtr pScreen, + XF86OffscreenImagePtr images, int num); + +extern _X_EXPORT XF86OffscreenImagePtr +xf86XVQueryOffscreenImages(ScreenPtr pScreen, int *num); + +extern _X_EXPORT XF86VideoAdaptorPtr xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr + pScrn); + +extern _X_EXPORT void xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr); + +extern _X_EXPORT void + xf86XVFillKeyHelper(ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes); + +extern _X_EXPORT void + +xf86XVFillKeyHelperDrawable(DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes); + +extern _X_EXPORT void + +xf86XVFillKeyHelperPort(DrawablePtr pDraw, pointer data, CARD32 key, + RegionPtr clipboxes, Bool fillEverything); + +extern _X_EXPORT Bool + +xf86XVClipVideoHelper(BoxPtr dst, + INT32 *xa, + INT32 *xb, + INT32 *ya, + INT32 *yb, RegionPtr reg, INT32 width, INT32 height); + +extern _X_EXPORT void + +xf86XVCopyYUV12ToPacked(const void *srcy, + const void *srcv, + const void *srcu, + void *dst, + int srcPitchy, + int srcPitchuv, int dstPitch, int h, int w); + +extern _X_EXPORT void + +xf86XVCopyPacked(const void *src, + void *dst, int srcPitch, int dstPitch, int h, int w); + +extern _X_EXPORT DevPrivateKey (*XvGetScreenKeyProc) (void); +extern _X_EXPORT unsigned long (*XvGetRTPortProc) (void); +extern _X_EXPORT int (*XvScreenInitProc) (ScreenPtr); + +#endif /* _XF86XV_H_ */ diff --git a/xorg-server/hw/xfree86/common/xf86xvmc.c b/xorg-server/hw/xfree86/common/xf86xvmc.c index 5a7f69d8a..e58465289 100644 --- a/xorg-server/hw/xfree86/common/xf86xvmc.c +++ b/xorg-server/hw/xfree86/common/xf86xvmc.c @@ -1,232 +1,224 @@ -
-/*
- * Copyright (c) 2001-2003 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "scrnintstr.h"
-#include "resource.h"
-#include "dixstruct.h"
-
-#include "xvmodproc.h"
-
-#include "xf86xvpriv.h"
-#include "xf86xvmc.h"
-
-XvMCScreenInitProcPtr XvMCScreenInitProc = NULL;
-
-
-typedef struct {
- CloseScreenProcPtr CloseScreen;
- int num_adaptors;
- XF86MCAdaptorPtr *adaptors;
- XvMCAdaptorPtr dixinfo;
-} xf86XvMCScreenRec, *xf86XvMCScreenPtr;
-
-static DevPrivateKeyRec XF86XvMCScreenKeyRec;
-#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec)
-
-#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \
- dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey)
-
-
-static int
-xf86XvMCCreateContext (
- XvPortPtr pPort,
- XvMCContextPtr pContext,
- int *num_priv,
- CARD32 **priv
-)
-{
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- pContext->port_priv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-
- return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext)(
- pScrn, pContext, num_priv, priv);
-}
-
-static void
-xf86XvMCDestroyContext ( XvMCContextPtr pContext)
-{
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext)(
- pScrn, pContext);
-}
-
-static int
-xf86XvMCCreateSurface (
- XvMCSurfacePtr pSurface,
- int *num_priv,
- CARD32 **priv
-)
-{
- XvMCContextPtr pContext = pSurface->context;
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface)(
- pScrn, pSurface, num_priv, priv);
-}
-
-static void
-xf86XvMCDestroySurface (XvMCSurfacePtr pSurface)
-{
- XvMCContextPtr pContext = pSurface->context;
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface)(
- pScrn, pSurface);
-}
-
-static int
-xf86XvMCCreateSubpicture (
- XvMCSubpicturePtr pSubpicture,
- int *num_priv,
- CARD32 **priv
-)
-{
- XvMCContextPtr pContext = pSubpicture->context;
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSubpicture)(
- pScrn, pSubpicture, num_priv, priv);
-}
-
-static void
-xf86XvMCDestroySubpicture (XvMCSubpicturePtr pSubpicture)
-{
- XvMCContextPtr pContext = pSubpicture->context;
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
- ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
-
- (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture)(
- pScrn, pSubpicture);
-}
-
-
-static Bool
-xf86XvMCCloseScreen (int i, ScreenPtr pScreen)
-{
- xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen);
-
- pScreen->CloseScreen = pScreenPriv->CloseScreen;
-
- free(pScreenPriv->dixinfo);
- free(pScreenPriv);
-
- return (*pScreen->CloseScreen)(i, pScreen);
-}
-
-Bool xf86XvMCScreenInit(
- ScreenPtr pScreen,
- int num_adaptors,
- XF86MCAdaptorPtr *adaptors
-)
-{
- XvMCAdaptorPtr pAdapt;
- xf86XvMCScreenPtr pScreenPriv;
- XvScreenPtr pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- XF86XvScreenKey);
- int i, j;
-
- if(!XvMCScreenInitProc) return FALSE;
-
- if(!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
- return FALSE;
-
- if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- if(!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) {
- free(pAdapt);
- return FALSE;
- }
-
- dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv);
-
- pScreenPriv->CloseScreen = pScreen->CloseScreen;
- pScreen->CloseScreen = xf86XvMCCloseScreen;
-
- pScreenPriv->num_adaptors = num_adaptors;
- pScreenPriv->adaptors = adaptors;
- pScreenPriv->dixinfo = pAdapt;
-
- for(i = 0; i < num_adaptors; i++) {
- pAdapt[i].xv_adaptor = NULL;
- for(j = 0; j < pxvs->nAdaptors; j++) {
- if(!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) {
- pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]);
- break;
- }
- }
- if(!pAdapt[i].xv_adaptor) {
- /* no adaptor by that name */
- free(pAdapt);
- return FALSE;
- }
- pAdapt[i].num_surfaces = (*adaptors)->num_surfaces;
- pAdapt[i].surfaces = (XvMCSurfaceInfoPtr*)((*adaptors)->surfaces);
- pAdapt[i].num_subpictures = (*adaptors)->num_subpictures;
- pAdapt[i].subpictures = (XvImagePtr*)((*adaptors)->subpictures);
- pAdapt[i].CreateContext = xf86XvMCCreateContext;
- pAdapt[i].DestroyContext = xf86XvMCDestroyContext;
- pAdapt[i].CreateSurface = xf86XvMCCreateSurface;
- pAdapt[i].DestroySurface = xf86XvMCDestroySurface;
- pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture;
- pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture;
- adaptors++;
- }
-
- if(Success != (*XvMCScreenInitProc)(pScreen, num_adaptors, pAdapt))
- return FALSE;
-
- return TRUE;
-}
-
-XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void)
-{
- return calloc(1, sizeof(XF86MCAdaptorRec));
-}
-
-void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor)
-{
- free(adaptor);
-}
+ +/* + * Copyright (c) 2001-2003 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include "misc.h" +#include "xf86.h" +#include "xf86_OSproc.h" + +#include <X11/X.h> +#include <X11/Xproto.h> +#include "scrnintstr.h" +#include "resource.h" +#include "dixstruct.h" + +#include "xvmodproc.h" + +#include "xf86xvpriv.h" +#include "xf86xvmc.h" + +XvMCScreenInitProcPtr XvMCScreenInitProc = NULL; + +typedef struct { + CloseScreenProcPtr CloseScreen; + int num_adaptors; + XF86MCAdaptorPtr *adaptors; + XvMCAdaptorPtr dixinfo; +} xf86XvMCScreenRec, *xf86XvMCScreenPtr; + +static DevPrivateKeyRec XF86XvMCScreenKeyRec; + +#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec) + +#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \ + dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey) + +static int +xf86XvMCCreateContext(XvPortPtr pPort, + XvMCContextPtr pContext, int *num_priv, CARD32 **priv) +{ + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + pContext->port_priv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); + + return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext) (pScrn, + pContext, + num_priv, + priv); +} + +static void +xf86XvMCDestroyContext(XvMCContextPtr pContext) +{ + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext) (pScrn, + pContext); +} + +static int +xf86XvMCCreateSurface(XvMCSurfacePtr pSurface, int *num_priv, CARD32 **priv) +{ + XvMCContextPtr pContext = pSurface->context; + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface) (pScrn, + pSurface, + num_priv, + priv); +} + +static void +xf86XvMCDestroySurface(XvMCSurfacePtr pSurface) +{ + XvMCContextPtr pContext = pSurface->context; + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface) (pScrn, + pSurface); +} + +static int +xf86XvMCCreateSubpicture(XvMCSubpicturePtr pSubpicture, + int *num_priv, CARD32 **priv) +{ + XvMCContextPtr pContext = pSubpicture->context; + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + return (*pScreenPriv->adaptors[pContext->adapt_num]-> + CreateSubpicture) (pScrn, pSubpicture, num_priv, priv); +} + +static void +xf86XvMCDestroySubpicture(XvMCSubpicturePtr pSubpicture) +{ + XvMCContextPtr pContext = pSubpicture->context; + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); + ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; + + (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture) (pScrn, + pSubpicture); +} + +static Bool +xf86XvMCCloseScreen(int i, ScreenPtr pScreen) +{ + xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen); + + pScreen->CloseScreen = pScreenPriv->CloseScreen; + + free(pScreenPriv->dixinfo); + free(pScreenPriv); + + return (*pScreen->CloseScreen) (i, pScreen); +} + +Bool +xf86XvMCScreenInit(ScreenPtr pScreen, + int num_adaptors, XF86MCAdaptorPtr * adaptors) +{ + XvMCAdaptorPtr pAdapt; + xf86XvMCScreenPtr pScreenPriv; + XvScreenPtr pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + XF86XvScreenKey); + int i, j; + + if (!XvMCScreenInitProc) + return FALSE; + + if (!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors))) + return FALSE; + + if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) + return FALSE; + + if (!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) { + free(pAdapt); + return FALSE; + } + + dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv); + + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = xf86XvMCCloseScreen; + + pScreenPriv->num_adaptors = num_adaptors; + pScreenPriv->adaptors = adaptors; + pScreenPriv->dixinfo = pAdapt; + + for (i = 0; i < num_adaptors; i++) { + pAdapt[i].xv_adaptor = NULL; + for (j = 0; j < pxvs->nAdaptors; j++) { + if (!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) { + pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]); + break; + } + } + if (!pAdapt[i].xv_adaptor) { + /* no adaptor by that name */ + free(pAdapt); + return FALSE; + } + pAdapt[i].num_surfaces = (*adaptors)->num_surfaces; + pAdapt[i].surfaces = (XvMCSurfaceInfoPtr *) ((*adaptors)->surfaces); + pAdapt[i].num_subpictures = (*adaptors)->num_subpictures; + pAdapt[i].subpictures = (XvImagePtr *) ((*adaptors)->subpictures); + pAdapt[i].CreateContext = xf86XvMCCreateContext; + pAdapt[i].DestroyContext = xf86XvMCDestroyContext; + pAdapt[i].CreateSurface = xf86XvMCCreateSurface; + pAdapt[i].DestroySurface = xf86XvMCDestroySurface; + pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture; + pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture; + adaptors++; + } + + if (Success != (*XvMCScreenInitProc) (pScreen, num_adaptors, pAdapt)) + return FALSE; + + return TRUE; +} + +XF86MCAdaptorPtr +xf86XvMCCreateAdaptorRec(void) +{ + return calloc(1, sizeof(XF86MCAdaptorRec)); +} + +void +xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor) +{ + free(adaptor); +} diff --git a/xorg-server/hw/xfree86/common/xf86xvmc.h b/xorg-server/hw/xfree86/common/xf86xvmc.h index 902b4f8fc..ff32379fe 100644 --- a/xorg-server/hw/xfree86/common/xf86xvmc.h +++ b/xorg-server/hw/xfree86/common/xf86xvmc.h @@ -33,24 +33,23 @@ #include "xf86xv.h" typedef struct { - int num_xvimages; - int *xvimage_ids; /* reference the subpictures in the XF86MCAdaptorRec */ -} XF86MCImageIDList; + int num_xvimages; + int *xvimage_ids; /* reference the subpictures in the XF86MCAdaptorRec */ +} XF86MCImageIDList; typedef struct { - int surface_type_id; /* Driver generated. Must be unique on the port */ - int chroma_format; - int color_description; /* no longer used */ - unsigned short max_width; - unsigned short max_height; - unsigned short subpicture_max_width; - unsigned short subpicture_max_height; - int mc_type; - int flags; - XF86MCImageIDList *compatible_subpictures; /* can be null, if none */ + int surface_type_id; /* Driver generated. Must be unique on the port */ + int chroma_format; + int color_description; /* no longer used */ + unsigned short max_width; + unsigned short max_height; + unsigned short subpicture_max_width; + unsigned short subpicture_max_height; + int mc_type; + int flags; + XF86MCImageIDList *compatible_subpictures; /* can be null, if none */ } XF86MCSurfaceInfoRec, *XF86MCSurfaceInfoPtr; - /* xf86XvMCCreateContextProc @@ -63,19 +62,13 @@ typedef struct { of 32 bit words in num_priv. This must be dynamically allocated space because DIX will free it after it passes it to the client. */ - -typedef int (*xf86XvMCCreateContextProcPtr) ( - ScrnInfoPtr pScrn, - XvMCContextPtr context, - int *num_priv, - CARD32 **priv -); +typedef int (*xf86XvMCCreateContextProcPtr) (ScrnInfoPtr pScrn, + XvMCContextPtr context, + int *num_priv, CARD32 **priv); -typedef void (*xf86XvMCDestroyContextProcPtr) ( - ScrnInfoPtr pScrn, - XvMCContextPtr context -); +typedef void (*xf86XvMCDestroyContextProcPtr) (ScrnInfoPtr pScrn, + XvMCContextPtr context); /* xf86XvMCCreateSurfaceProc @@ -86,18 +79,12 @@ typedef void (*xf86XvMCDestroyContextProcPtr) ( xf86XvMCCreateContextProc. */ +typedef int (*xf86XvMCCreateSurfaceProcPtr) (ScrnInfoPtr pScrn, + XvMCSurfacePtr surface, + int *num_priv, CARD32 **priv); -typedef int (*xf86XvMCCreateSurfaceProcPtr) ( - ScrnInfoPtr pScrn, - XvMCSurfacePtr surface, - int *num_priv, - CARD32 **priv -); - -typedef void (*xf86XvMCDestroySurfaceProcPtr) ( - ScrnInfoPtr pScrn, - XvMCSurfacePtr surface -); +typedef void (*xf86XvMCDestroySurfaceProcPtr) (ScrnInfoPtr pScrn, + XvMCSurfacePtr surface); /* xf86XvMCCreateSubpictureProc @@ -114,32 +101,25 @@ typedef void (*xf86XvMCDestroySurfaceProcPtr) ( xf86XvMCCreateContextProc. */ +typedef int (*xf86XvMCCreateSubpictureProcPtr) (ScrnInfoPtr pScrn, + XvMCSubpicturePtr subpicture, + int *num_priv, CARD32 **priv); -typedef int (*xf86XvMCCreateSubpictureProcPtr) ( - ScrnInfoPtr pScrn, - XvMCSubpicturePtr subpicture, - int *num_priv, - CARD32 **priv -); - -typedef void (*xf86XvMCDestroySubpictureProcPtr) ( - ScrnInfoPtr pScrn, - XvMCSubpicturePtr subpicture -); - +typedef void (*xf86XvMCDestroySubpictureProcPtr) (ScrnInfoPtr pScrn, + XvMCSubpicturePtr subpicture); typedef struct { - char *name; - int num_surfaces; - XF86MCSurfaceInfoPtr *surfaces; - int num_subpictures; - XF86ImagePtr *subpictures; - xf86XvMCCreateContextProcPtr CreateContext; - xf86XvMCDestroyContextProcPtr DestroyContext; - xf86XvMCCreateSurfaceProcPtr CreateSurface; - xf86XvMCDestroySurfaceProcPtr DestroySurface; - xf86XvMCCreateSubpictureProcPtr CreateSubpicture; - xf86XvMCDestroySubpictureProcPtr DestroySubpicture; + char *name; + int num_surfaces; + XF86MCSurfaceInfoPtr *surfaces; + int num_subpictures; + XF86ImagePtr *subpictures; + xf86XvMCCreateContextProcPtr CreateContext; + xf86XvMCDestroyContextProcPtr DestroyContext; + xf86XvMCCreateSurfaceProcPtr CreateSurface; + xf86XvMCDestroySurfaceProcPtr DestroySurface; + xf86XvMCCreateSubpictureProcPtr CreateSubpicture; + xf86XvMCDestroySubpictureProcPtr DestroySubpicture; } XF86MCAdaptorRec, *XF86MCAdaptorPtr; /* @@ -151,16 +131,14 @@ typedef struct { an array of structures. */ -extern _X_EXPORT Bool xf86XvMCScreenInit( - ScreenPtr pScreen, - int num_adaptors, - XF86MCAdaptorPtr *adaptors -); +extern _X_EXPORT Bool xf86XvMCScreenInit(ScreenPtr pScreen, + int num_adaptors, + XF86MCAdaptorPtr * adaptors); -extern _X_EXPORT XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void); +extern _X_EXPORT XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec(void); extern _X_EXPORT void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor); -typedef int (*XvMCScreenInitProcPtr)(ScreenPtr, int, XvMCAdaptorPtr); +typedef int (*XvMCScreenInitProcPtr) (ScreenPtr, int, XvMCAdaptorPtr); extern _X_EXPORT XvMCScreenInitProcPtr XvMCScreenInitProc; -#endif /* _XF86XVMC_H */ +#endif /* _XF86XVMC_H */ diff --git a/xorg-server/hw/xfree86/common/xisb.c b/xorg-server/hw/xfree86/common/xisb.c index 287a98b53..3568a578c 100644 --- a/xorg-server/hw/xfree86/common/xisb.c +++ b/xorg-server/hw/xfree86/common/xisb.c @@ -1,174 +1,168 @@ -/*
- * Copyright (c) 1997 Metro Link Incorporated
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of the Metro Link shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from Metro Link.
- *
- */
-
-/*
- X Input Serial Buffer routines for use in any XInput driver that accesses
- a serial device.
-*/
-
-
-/*****************************************************************************
- * Standard Headers
- ****************************************************************************/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <misc.h>
-#include <xf86.h>
-#include <xf86_OSproc.h>
-#include <xf86_OSlib.h>
-#include <xf86Xinput.h>
-#include "xisb.h"
-
-/*****************************************************************************
- * Local Headers
- ****************************************************************************/
-
-/*****************************************************************************
- * Variables without includable headers
- ****************************************************************************/
-
-/*****************************************************************************
- * Local Variables
- ****************************************************************************/
-
-/*****************************************************************************
- * Function Definitions
- ****************************************************************************/
-
-XISBuffer *
-XisbNew (int fd, ssize_t size)
-{
- XISBuffer *b;
-
- b = malloc(sizeof (XISBuffer));
- if (!b)
- return NULL;
- b->buf = malloc((sizeof (unsigned char) * size));
- if (!b->buf)
- {
- free(b);
- return NULL;
- }
-
- b->fd = fd;
- b->trace = 0;
- b->block_duration = 0;
- b->current = 1; /* force it to be past the end to trigger initial read */
- b->end = 0;
- b->buffer_size = size;
- return b;
-}
-
-void
-XisbFree (XISBuffer *b)
-{
- free(b->buf);
- free(b);
-}
-
-int
-XisbRead (XISBuffer *b)
-{
- int ret;
-
- if (b->current >= b->end)
- {
- if (b->block_duration >= 0)
- {
- if (xf86WaitForInput (b->fd, b->block_duration) < 1)
- return -1;
- }
- else
- {
- /*
- * automatically clear it so if XisbRead is called in a loop
- * the next call will make sure there is data with select and
- * thus prevent a blocking read
- */
- b->block_duration = 0;
- }
-
- ret = xf86ReadSerial (b->fd, b->buf, b->buffer_size);
- switch (ret)
- {
- case 0:
- return -1; /* timeout */
- case -1:
- return -2; /* error */
- default:
- b->end = ret;
- b->current = 0;
- break;
- }
- }
- if (b->trace)
- ErrorF ("read 0x%02x (%c)\n", b->buf[b->current],
- isprint(b->buf[b->current])?b->buf[b->current]:'.');
-
- return b->buf[b->current++];
-}
-
-/* the only purpose of this function is to provide output tracing */
-ssize_t
-XisbWrite (XISBuffer *b, unsigned char *msg, ssize_t len)
-{
- if (b->trace)
- {
- int i = 0;
- for (i = 0; i < len; i++)
- ErrorF ("\t\twrote 0x%02x (%c)\n", msg[i], msg[i]);
- }
- return (xf86WriteSerial (b->fd, msg, len));
-}
-
-/* turn tracing of this buffer on (1) or off (0) */
-void
-XisbTrace (XISBuffer *b, int trace)
-{
- b->trace = trace;
-}
-
-/*
- * specify a block_duration of -1 when you know the buffer's fd is ready to
- * read. After a read, it is automatically set to 0 so that the next read
- * will use check to select for data and prevent a block.
- * It is the caller's responsibility to set the block_duration to -1 if it
- * knows that there is data to read (because the main select loop triggered
- * the read) and want's to avoid the unnecessary overhead of the select call
- *
- * a zero or positive block duration will cause the select to block for the
- * give duration in usecs.
- */
-
-void
-XisbBlockDuration (XISBuffer *b, int block_duration)
-{
- b->block_duration = block_duration;
-}
+/* + * Copyright (c) 1997 Metro Link Incorporated + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of the Metro Link shall not be + * used in advertising or otherwise to promote the sale, use or other dealings + * in this Software without prior written authorization from Metro Link. + * + */ + +/* + X Input Serial Buffer routines for use in any XInput driver that accesses + a serial device. +*/ + +/***************************************************************************** + * Standard Headers + ****************************************************************************/ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <misc.h> +#include <xf86.h> +#include <xf86_OSproc.h> +#include <xf86_OSlib.h> +#include <xf86Xinput.h> +#include "xisb.h" + +/***************************************************************************** + * Local Headers + ****************************************************************************/ + +/***************************************************************************** + * Variables without includable headers + ****************************************************************************/ + +/***************************************************************************** + * Local Variables + ****************************************************************************/ + +/***************************************************************************** + * Function Definitions + ****************************************************************************/ + +XISBuffer * +XisbNew(int fd, ssize_t size) +{ + XISBuffer *b; + + b = malloc(sizeof(XISBuffer)); + if (!b) + return NULL; + b->buf = malloc((sizeof(unsigned char) * size)); + if (!b->buf) { + free(b); + return NULL; + } + + b->fd = fd; + b->trace = 0; + b->block_duration = 0; + b->current = 1; /* force it to be past the end to trigger initial read */ + b->end = 0; + b->buffer_size = size; + return b; +} + +void +XisbFree(XISBuffer * b) +{ + free(b->buf); + free(b); +} + +int +XisbRead(XISBuffer * b) +{ + int ret; + + if (b->current >= b->end) { + if (b->block_duration >= 0) { + if (xf86WaitForInput(b->fd, b->block_duration) < 1) + return -1; + } + else { + /* + * automatically clear it so if XisbRead is called in a loop + * the next call will make sure there is data with select and + * thus prevent a blocking read + */ + b->block_duration = 0; + } + + ret = xf86ReadSerial(b->fd, b->buf, b->buffer_size); + switch (ret) { + case 0: + return -1; /* timeout */ + case -1: + return -2; /* error */ + default: + b->end = ret; + b->current = 0; + break; + } + } + if (b->trace) + ErrorF("read 0x%02x (%c)\n", b->buf[b->current], + isprint(b->buf[b->current]) ? b->buf[b->current] : '.'); + + return b->buf[b->current++]; +} + +/* the only purpose of this function is to provide output tracing */ +ssize_t +XisbWrite(XISBuffer * b, unsigned char *msg, ssize_t len) +{ + if (b->trace) { + int i = 0; + + for (i = 0; i < len; i++) + ErrorF("\t\twrote 0x%02x (%c)\n", msg[i], msg[i]); + } + return (xf86WriteSerial(b->fd, msg, len)); +} + +/* turn tracing of this buffer on (1) or off (0) */ +void +XisbTrace(XISBuffer * b, int trace) +{ + b->trace = trace; +} + +/* + * specify a block_duration of -1 when you know the buffer's fd is ready to + * read. After a read, it is automatically set to 0 so that the next read + * will use check to select for data and prevent a block. + * It is the caller's responsibility to set the block_duration to -1 if it + * knows that there is data to read (because the main select loop triggered + * the read) and want's to avoid the unnecessary overhead of the select call + * + * a zero or positive block duration will cause the select to block for the + * give duration in usecs. + */ + +void +XisbBlockDuration(XISBuffer * b, int block_duration) +{ + b->block_duration = block_duration; +} diff --git a/xorg-server/hw/xfree86/common/xisb.h b/xorg-server/hw/xfree86/common/xisb.h index bacfde166..6ac1a6e37 100644 --- a/xorg-server/hw/xfree86/common/xisb.h +++ b/xorg-server/hw/xfree86/common/xisb.h @@ -35,15 +35,14 @@ * structs, typedefs, #defines, enums *****************************************************************************/ -typedef struct _XISBuffer -{ - int fd; - int trace; - int block_duration; - ssize_t current; /* bytes read */ - ssize_t end; - ssize_t buffer_size; - unsigned char *buf; +typedef struct _XISBuffer { + int fd; + int trace; + int block_duration; + ssize_t current; /* bytes read */ + ssize_t end; + ssize_t buffer_size; + unsigned char *buf; } XISBuffer; /****************************************************************************** @@ -52,12 +51,13 @@ typedef struct _XISBuffer * of globals. * put locals in the .c file. *****************************************************************************/ -extern _X_EXPORT XISBuffer * XisbNew (int fd, ssize_t size); -extern _X_EXPORT void XisbFree (XISBuffer *b); -extern _X_EXPORT int XisbRead (XISBuffer *b); -extern _X_EXPORT ssize_t XisbWrite (XISBuffer *b, unsigned char *msg, ssize_t len); -extern _X_EXPORT void XisbTrace (XISBuffer *b, int trace); -extern _X_EXPORT void XisbBlockDuration (XISBuffer *b, int block_duration); +extern _X_EXPORT XISBuffer *XisbNew(int fd, ssize_t size); +extern _X_EXPORT void XisbFree(XISBuffer * b); +extern _X_EXPORT int XisbRead(XISBuffer * b); +extern _X_EXPORT ssize_t XisbWrite(XISBuffer * b, unsigned char *msg, + ssize_t len); +extern _X_EXPORT void XisbTrace(XISBuffer * b, int trace); +extern _X_EXPORT void XisbBlockDuration(XISBuffer * b, int block_duration); /* * DO NOT PUT ANYTHING AFTER THIS ENDIF |