Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / include / pipe / p_util.h
index 1bc00ac7a022410aac0076e111ac9fcc2ec0de69..7dcdd282875ac9cc503083003c04ca7d64b6b398 100644 (file)
 #ifndef P_UTIL_H
 #define P_UTIL_H
 
+#include "p_config.h"
 #include "p_compiler.h"
 #include "p_debug.h"
+#include "p_format.h"
 #include "p_pointer.h"
 #include <math.h>
 #include <stdarg.h>
@@ -40,7 +42,9 @@ extern "C" {
 #endif
 
 
-#if defined(WIN32) && defined(DEBUG) /* memory debugging */
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) && defined(DEBUG) 
+
+/* memory debugging */
 
 #include "p_debug.h"
 
@@ -53,9 +57,7 @@ extern "C" {
 #define REALLOC( _ptr, _old_size, _size ) \
    debug_realloc( __FILE__, __LINE__, __FUNCTION__,  _ptr, _old_size, _size )
 
-#else
-   
-#ifdef WIN32
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
 
 void * __stdcall
 EngAllocMem(
@@ -67,17 +69,33 @@ void __stdcall
 EngFreeMem(
     void *Mem );
 
-static INLINE void *
-MALLOC( unsigned size )
-{
-#ifdef WINCE
-   /* TODO: Need to abstract this */
-   return malloc( size );
+#define MALLOC( _size ) EngAllocMem( 0, _size, 'D3AG' )
+#define _FREE( _ptr ) EngFreeMem( _ptr )
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+
+void *
+ExAllocatePool(
+    unsigned long PoolType, 
+    size_t NumberOfBytes);
+
+void 
+ExFreePool(void *P);
+
+#define MALLOC(_size) ExAllocatePool(0, _size)
+#define _FREE(_ptr) ExFreePool(_ptr)
+
 #else
-   return EngAllocMem( 0, size, 'D3AG' );
+
+#define MALLOC( SIZE )  malloc( SIZE )
+#define CALLOC( COUNT, SIZE )   calloc( COUNT, SIZE )
+#define FREE( PTR )  free( PTR )
+#define REALLOC( OLDPTR, OLDSIZE, NEWSIZE )  realloc( OLDPTR, NEWSIZE )
+
 #endif
-}
 
+
+#ifndef CALLOC
 static INLINE void *
 CALLOC( unsigned count, unsigned size )
 {
@@ -87,20 +105,19 @@ CALLOC( unsigned count, unsigned size )
    }
    return ptr;
 }
+#endif /* !CALLOC */
 
+#ifndef FREE
 static INLINE void
 FREE( void *ptr )
 {
    if( ptr ) {
-#ifdef WINCE
-      /* TODO: Need to abstract this */
-      free( ptr );
-#else
-      EngFreeMem( ptr );
-#endif
+      _FREE( ptr );
    }
 }
+#endif /* !FREE */
 
+#ifndef REALLOC
 static INLINE void *
 REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
 {
@@ -117,34 +134,13 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
    FREE( old_ptr );
    return new_ptr;
 }
+#endif /* !REALLOC */
 
-#else /* !WIN32 */
-
-#define MALLOC( SIZE )  malloc( SIZE )
-
-#define CALLOC( COUNT, SIZE )   calloc( COUNT, SIZE )
-
-#define FREE( PTR )  free( PTR )
-
-#define REALLOC( OLDPTR, OLDSIZE, NEWSIZE )  realloc( OLDPTR, NEWSIZE )
-
-#endif /* !WIN32 */
-#endif /* !DEBUG */
 
 #define MALLOC_STRUCT(T)   (struct T *) MALLOC(sizeof(struct T))
 
 #define CALLOC_STRUCT(T)   (struct T *) CALLOC(1, sizeof(struct T))
 
-#define GETENV( X ) debug_get_option( X, NULL )
-
-
-#ifdef WIN32
-int rpl_vsnprintf(char *, size_t, const char *, va_list);
-int rpl_snprintf(char *str, size_t size, const char *format, ...);
-#define vsnprintf rpl_vsnprintf
-#define snprintf rpl_snprintf
-#endif
-
 
 /**
  * Return memory on given byte alignment
@@ -207,7 +203,6 @@ mem_dup(const void *src, uint size)
 #define MIN2( A, B )   ( (A)<(B) ? (A) : (B) )
 #define MAX2( A, B )   ( (A)>(B) ? (A) : (B) )
 
-/* JB stop warnings */
 #ifndef Elements
 #define Elements(x) (sizeof(x)/sizeof((x)[0]))
 #endif
@@ -230,7 +225,7 @@ static INLINE int align_int(int x, int align)
 
 
 
-#if defined(__MSC__) && defined(__WIN32__)
+#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
 static INLINE unsigned ffs( unsigned u )
 {
    unsigned i;
@@ -347,14 +342,14 @@ static INLINE int ifloor(float f)
 }
 
 
-#if defined(__GNUC__) && defined(__i386__
+#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86
 static INLINE int iround(float f)
 {
    int r;
    __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
    return r;
 }
-#elif defined(__MSC__) && defined(__WIN32__)
+#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
 static INLINE int iround(float f)
 {
    int r;
@@ -407,10 +402,68 @@ static INLINE int align(int value, int alignment)
 
 /* util/p_util.c
  */
-extern void pipe_copy_rect(ubyte * dst, unsigned cpp, unsigned dst_pitch,
-                           unsigned dst_x, unsigned dst_y, unsigned width,
-                           unsigned height, const ubyte * src,
-                           int src_pitch, unsigned src_x, int src_y);
+extern void pipe_copy_rect(ubyte * dst, const struct pipe_format_block *block,
+                           unsigned dst_stride, unsigned dst_x, unsigned dst_y,
+                           unsigned width, unsigned height, const ubyte * src,
+                           int src_stride, unsigned src_x, int src_y);
+
+extern void
+pipe_fill_rect(ubyte * dst, const struct pipe_format_block *block,
+               unsigned dst_stride, unsigned dst_x, unsigned dst_y,
+               unsigned width, unsigned height, uint32_t value);
+
+
+#if defined(_MSC_VER) 
+#if _MSC_VER < 1400 && !defined(__cplusplus) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+static INLINE float cosf( float f ) 
+{
+   return (float) cos( (double) f );
+}
+
+static INLINE float sinf( float f ) 
+{
+   return (float) sin( (double) f );
+}
+
+static INLINE float ceilf( float f ) 
+{
+   return (float) ceil( (double) f );
+}
+
+static INLINE float floorf( float f ) 
+{
+   return (float) floor( (double) f );
+}
+
+static INLINE float powf( float f, float g ) 
+{
+   return (float) pow( (double) f, (double) g );
+}
+
+static INLINE float sqrtf( float f ) 
+{
+   return (float) sqrt( (double) f );
+}
+
+static INLINE float fabsf( float f ) 
+{
+   return (float) fabs( (double) f );
+}
+
+static INLINE float logf( float f ) 
+{
+   return (float) log( (double) f );
+}
+
+#else
+/* Work-around an extra semi-colon in VS 2005 logf definition */
+#ifdef logf
+#undef logf
+#define logf(x) ((float)log((double)(x)))
+#endif /* logf */
+#endif
+#endif /* _MSC_VER */
 
 
 #ifdef __cplusplus