missing files

This commit is contained in:
Keith Whitwell 2002-12-23 12:18:14 +00:00
parent 83b936adb3
commit 9363bd862f
14 changed files with 2214 additions and 0 deletions

View file

@ -0,0 +1,176 @@
/* $XFree86: xc/lib/GL/mesa/src/drv/common/depthtmp.h,v 1.5 2001/03/21 16:14:20 dawes Exp $ */
#ifndef DBG
#define DBG 0
#endif
#ifndef HAVE_HW_DEPTH_SPANS
#define HAVE_HW_DEPTH_SPANS 0
#endif
#ifndef HAVE_HW_DEPTH_PIXELS
#define HAVE_HW_DEPTH_PIXELS 0
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
static void TAG(WriteDepthSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLdepth *depth,
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_DEPTH_VARS;
y = Y_FLIP( y );
#if HAVE_HW_DEPTH_SPANS
(void) x1; (void) n1;
if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n",
(int)n, (int)x );
WRITE_DEPTH_SPAN();
#else
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN( x, y, n, x1, n1, i );
if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1 );
if ( mask ) {
for ( ; i < n1 ; i++, x1++ ) {
if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] );
}
} else {
for ( ; i < n1 ; i++, x1++ ) {
WRITE_DEPTH( x1, y, depth[i] );
}
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteDepthPixels)( GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLdepth depth[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_DEPTH_VARS;
if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
#if HAVE_HW_DEPTH_PIXELS
(void) i;
WRITE_DEPTH_PIXELS();
#else
HW_CLIPLOOP()
{
for ( i = 0 ; i < n ; i++ ) {
if ( mask[i] ) {
const int fy = Y_FLIP( y[i] );
if ( CLIPPIXEL( x[i], fy ) )
WRITE_DEPTH( x[i], fy, depth[i] );
}
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_WRITE_UNLOCK();
}
/* Read depth spans and pixels
*/
static void TAG(ReadDepthSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLdepth depth[] )
{
HW_READ_LOCK()
{
GLint x1, n1;
LOCAL_DEPTH_VARS;
y = Y_FLIP( y );
if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
#if HAVE_HW_DEPTH_SPANS
(void) x1; (void) n1;
READ_DEPTH_SPAN();
#else
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN( x, y, n, x1, n1, i );
for ( ; i < n1 ; i++ )
READ_DEPTH( depth[i], (x1+i), y );
}
HW_ENDCLIPLOOP();
#endif
}
HW_READ_UNLOCK();
}
static void TAG(ReadDepthPixels)( GLcontext *ctx, GLuint n,
const GLint x[], const GLint y[],
GLdepth depth[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_DEPTH_VARS;
if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
#if HAVE_HW_DEPTH_PIXELS
(void) i;
READ_DEPTH_PIXELS();
#else
HW_CLIPLOOP()
{
for ( i = 0 ; i < n ;i++ ) {
int fy = Y_FLIP( y[i] );
if ( CLIPPIXEL( x[i], fy ) )
READ_DEPTH( depth[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_READ_UNLOCK();
}
#if HAVE_HW_DEPTH_SPANS
#undef WRITE_DEPTH_SPAN
#undef WRITE_DEPTH_PIXELS
#undef READ_DEPTH_SPAN
#undef READ_DEPTH_PIXELS
#else
#undef WRITE_DEPTH
#undef READ_DEPTH
#endif
#undef TAG

View file

@ -0,0 +1,142 @@
/*
* GLX Hardware Device Driver common code
*
* Based on the original MGA G200 driver (c) 1999 Wittawat Yamwong
*
* 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
* WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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.
*
*
* Wittawat Yamwong <Wittawat.Yamwong@stud.uni-hannover.de>
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/hwlog.c,v 1.3 2001/08/18 02:51:03 dawes Exp $ */
#include "hwlog.h"
hwlog_t hwlog = { 0,0,0, "[???] "};
/* Should be shared, but is this a good place for it?
*/
#include <sys/time.h>
#include <stdarg.h>
int usec( void )
{
struct timeval tv;
struct timezone tz;
gettimeofday( &tv, &tz );
return (tv.tv_sec & 2047) * 1000000 + tv.tv_usec;
}
#ifdef HW_LOG_ENABLED
int hwOpenLog(const char *filename, char *prefix)
{
hwCloseLog();
hwSetLogLevel(0);
hwlog.prefix=prefix;
if (!filename)
return -1;
if ((hwlog.file = fopen(filename,"w")) == NULL)
return -1;
return 0;
}
void hwCloseLog()
{
if (hwlog.file) {
fclose(hwlog.file);
hwlog.file = NULL;
}
}
int hwIsLogReady()
{
return (hwlog.file != NULL);
}
void hwSetLogLevel(int level)
{
hwlog.level = level;
}
int hwGetLogLevel()
{
return hwlog.level;
}
void hwLog(int level, const char *format, ...)
{
va_list ap;
va_start(ap,format);
hwLogv(level,format,ap);
va_end(ap);
}
void hwLogv(int l, const char *format, va_list ap)
{
if (hwlog.file && (l <= hwlog.level)) {
vfprintf(hwlog.file,format,ap);
fflush(hwlog.file);
}
}
void hwMsg(int l, const char *format, ...)
{
va_list ap;
va_start(ap, format);
if (l <= hwlog.level) {
if (hwIsLogReady()) {
int t = usec();
hwLog(l, "%6i:", t - hwlog.timeTemp);
hwlog.timeTemp = t;
hwLogv(l, format, ap);
} else {
fprintf(stderr, hwlog.prefix);
vfprintf(stderr, format, ap);
}
}
va_end(ap);
}
#else /* ifdef HW_LOG_ENABLED */
int hwlogdummy()
{
return 0;
}
#endif
void hwError(const char *format, ...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, hwlog.prefix);
vfprintf(stderr, format, ap);
hwLogv(0, format, ap);
va_end(ap);
}

View file

@ -0,0 +1,101 @@
/*
* GLX Hardware Device Driver common code
*
* Based on the original MGA G200 driver (c) 1999 Wittawat Yamwong
*
* 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
* WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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.
*
*
* Wittawat Yamwong <Wittawat.Yamwong@stud.uni-hannover.de>
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/hwlog.h,v 1.5 2001/10/31 23:22:57 tsi Exp $ */
/* Usage:
* - use mgaError for error messages. Always write to X error and log file.
* - use mgaMsg for debugging. Can be disabled by undefining MGA_LOG_ENABLED.
*/
#ifndef HWLOG_INC
#define HWLOG_INC
#include <stdarg.h>
#include <stdio.h>
#define DBG_LEVEL_BASE 1
#define DBG_LEVEL_VERBOSE 10
#define DBG_LEVEL_ENTEREXIT 20
typedef struct
{
FILE *file;
int level;
unsigned int timeTemp;
char *prefix;
} hwlog_t;
extern hwlog_t hwlog;
#ifdef HW_LOG_ENABLED
/* open and close log file. */
int hwOpenLog(const char *filename, char *prefix);
void hwCloseLog(void);
/* return 1 if log file is succesfully opened */
int hwIsLogReady(void);
/* set current log level to 'level'. Messages with level less than or equal
the current log level will be written to the log file. */
void hwSetLogLevel(int level);
int hwGetLogLevel(void);
/* hwLog and hwLogv write a message to the log file. */
/* do not call these directly, use hwMsg() instead */
void hwLog(int level, const char *format, ...);
void hwLogv(int level, const char *format, va_list ap);
int usec( void );
/* hwMsg writes a message to the log file or to the standard X error file. */
void hwMsg(int level, const char *format, ...);
#else
static __inline__ int hwOpenLog(const char *f, char *prefix) { hwlog.prefix=prefix; return -1; }
#define hwIsLogReady() (0)
#define hwGetLogLevel() (-1)
#define hwLogLevel(n) (0)
#define hwLog()
#define hwMsg()
#define hwCloseLog()
#define hwSetLogLevel(x)
#define hwLogv(l,f,a)
#endif
void hwError(const char *format, ...);
#endif

View file

@ -0,0 +1,200 @@
/*
* GLX Hardware Device Driver common code
* Copyright (C) 1999 Keith Whitwell
*
* 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
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
*
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/mm.c,v 1.3 2001/08/18 02:51:03 dawes Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include "mm.h"
#include "hwlog.h"
/* KW: I don't know who the author of this code is, but it wasn't me
* despite what the copyright says...
*/
void mmDumpMemInfo( memHeap_t *heap )
{
TMemBlock *p;
fprintf(stderr, "Memory heap %p:\n", heap);
if (heap == 0) {
fprintf(stderr, " heap == 0\n");
} else {
p = (TMemBlock *)heap;
while (p) {
fprintf(stderr, " Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
p->free ? '.':'U',
p->reserved ? 'R':'.');
p = p->next;
}
}
fprintf(stderr, "End of memory blocks\n");
}
memHeap_t *mmInit(int ofs,
int size)
{
PMemBlock blocks;
if (size <= 0) {
return 0;
}
blocks = (TMemBlock *) calloc(1,sizeof(TMemBlock));
if (blocks) {
blocks->ofs = ofs;
blocks->size = size;
blocks->free = 1;
return (memHeap_t *)blocks;
} else
return 0;
}
static TMemBlock* SliceBlock(TMemBlock *p,
int startofs, int size,
int reserved, int alignment)
{
TMemBlock *newblock;
/* break left */
if (startofs > p->ofs) {
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
if (!newblock)
return NULL;
newblock->ofs = startofs;
newblock->size = p->size - (startofs - p->ofs);
newblock->free = 1;
newblock->next = p->next;
p->size -= newblock->size;
p->next = newblock;
p = newblock;
}
/* break right */
if (size < p->size) {
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
if (!newblock)
return NULL;
newblock->ofs = startofs + size;
newblock->size = p->size - size;
newblock->free = 1;
newblock->next = p->next;
p->size = size;
p->next = newblock;
}
/* p = middle block */
p->align = alignment;
p->free = 0;
p->reserved = reserved;
return p;
}
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
{
int mask,startofs,endofs;
TMemBlock *p;
if (!heap || align2 < 0 || size <= 0)
return NULL;
mask = (1 << align2)-1;
startofs = 0;
p = (TMemBlock *)heap;
while (p) {
if ((p)->free) {
startofs = (p->ofs + mask) & ~mask;
if ( startofs < startSearch ) {
startofs = startSearch;
}
endofs = startofs+size;
if (endofs <= (p->ofs+p->size))
break;
}
p = p->next;
}
if (!p)
return NULL;
p = SliceBlock(p,startofs,size,0,mask+1);
p->heap = heap;
return p;
}
static __inline__ int Join2Blocks(TMemBlock *p)
{
if (p->free && p->next && p->next->free) {
TMemBlock *q = p->next;
p->size += q->size;
p->next = q->next;
free(q);
return 1;
}
return 0;
}
int mmFreeMem(PMemBlock b)
{
TMemBlock *p,*prev;
if (!b)
return 0;
if (!b->heap) {
fprintf(stderr, "no heap\n");
return -1;
}
p = b->heap;
prev = NULL;
while (p && p != b) {
prev = p;
p = p->next;
}
if (!p || p->free || p->reserved) {
if (!p)
fprintf(stderr, "block not found in heap\n");
else if (p->free)
fprintf(stderr, "block already free\n");
else
fprintf(stderr, "block is reserved\n");
return -1;
}
p->free = 1;
Join2Blocks(p);
if (prev)
Join2Blocks(prev);
return 0;
}
void mmDestroy(memHeap_t *heap)
{
TMemBlock *p,*q;
if (!heap)
return;
p = (TMemBlock *)heap;
while (p) {
q = p->next;
free(p);
p = q;
}
}

View file

@ -0,0 +1,82 @@
/*
* GLX Hardware Device Driver common code
* Copyright (C) 1999 Keith Whitwell
*
* 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
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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 MM_INC
#define MM_INC
struct mem_block_t {
struct mem_block_t *next;
struct mem_block_t *heap;
int ofs,size;
int align;
int free:1;
int reserved:1;
};
typedef struct mem_block_t TMemBlock;
typedef struct mem_block_t *PMemBlock;
/* a heap is just the first block in a chain */
typedef struct mem_block_t memHeap_t;
static __inline__ int mmBlockSize(PMemBlock b)
{ return b->size; }
static __inline__ int mmOffset(PMemBlock b)
{ return b->ofs; }
/*
* input: total size in bytes
* return: a heap pointer if OK, NULL if error
*/
memHeap_t *mmInit( int ofs, int size );
/*
* Allocate 'size' bytes with 2^align2 bytes alignment,
* restrict the search to free memory after 'startSearch'
* depth and back buffers should be in different 4mb banks
* to get better page hits if possible
* input: size = size of block
* align2 = 2^align2 bytes alignment
* startSearch = linear offset from start of heap to begin search
* return: pointer to the allocated block, 0 if error
*/
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2,
int startSearch );
/*
* Free block starts at offset
* input: pointer to a block
* return: 0 if OK, -1 if error
*/
int mmFreeMem( PMemBlock b );
/*
* destroy MM
*/
void mmDestroy( memHeap_t *mmInit );
/* For debuging purpose. */
void mmDumpMemInfo( memHeap_t *mmInit );
#endif

View file

@ -0,0 +1,259 @@
#ifndef DBG
#define DBG 0
#endif
#ifndef HW_WRITE_LOCK
#define HW_WRITE_LOCK() HW_LOCK()
#endif
#ifndef HW_WRITE_UNLOCK
#define HW_WRITE_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_CLIPLOOP
#define HW_READ_CLIPLOOP() HW_CLIPLOOP()
#endif
#ifndef HW_WRITE_CLIPLOOP
#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
#endif
static void TAG(WriteRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgba[][4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
y = Y_FLIP(y);
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_RGBA( x1, y,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
else
{
for (;n1>0;i++,x1++,n1--)
WRITE_RGBA( x1, y,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteRGBSpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgb[][3],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
y = Y_FLIP(y);
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
}
else
{
for (;n1>0;i++,x1++,n1--)
WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteRGBAPixels)( const GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLubyte rgba[][4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_VARS;
if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
HW_WRITE_CLIPLOOP()
{
for (i=0;i<n;i++)
{
if (mask[i]) {
const int fy = Y_FLIP(y[i]);
if (CLIPPIXEL(x[i],fy))
WRITE_RGBA( x[i], fy,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLchan color[4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
INIT_MONO_PIXEL(p, color);
y = Y_FLIP( y );
if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_PIXEL( x1, y, p );
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx,
GLuint n,
const GLint x[], const GLint y[],
const GLchan color[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_VARS;
INIT_MONO_PIXEL(p, color);
if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
HW_WRITE_CLIPLOOP()
{
for (i=0;i<n;i++)
if (mask[i]) {
int fy = Y_FLIP(y[i]);
if (CLIPPIXEL( x[i], fy ))
WRITE_PIXEL( x[i], fy, p );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(ReadRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLubyte rgba[][4])
{
HW_READ_LOCK()
{
GLint x1,n1;
LOCAL_VARS;
y = Y_FLIP(y);
if (DBG) fprintf(stderr, "ReadRGBASpan\n");
HW_READ_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;n1>0;i++,x1++,n1--)
READ_RGBA( rgba[i], x1, y );
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
static void TAG(ReadRGBAPixels)( const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4], const GLubyte mask[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_VARS;
if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
HW_READ_CLIPLOOP()
{
for (i=0;i<n;i++)
if (mask[i]) {
int fy = Y_FLIP( y[i] );
if (CLIPPIXEL( x[i], fy ))
READ_RGBA( rgba[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
#undef WRITE_PIXEL
#undef WRITE_RGBA
#undef READ_RGBA
#undef TAG

View file

@ -0,0 +1,147 @@
/* $XFree86: xc/lib/GL/mesa/src/drv/common/stenciltmp.h,v 1.3 2001/03/21 16:14:20 dawes Exp $ */
#ifndef DBG
#define DBG 0
#endif
#ifndef HW_WRITE_LOCK
#define HW_WRITE_LOCK() HW_LOCK()
#endif
#ifndef HW_WRITE_UNLOCK
#define HW_WRITE_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
static void TAG(WriteStencilSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLstencil *stencil,
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_STENCIL_VARS;
y = Y_FLIP(y);
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;i<n1;i++,x1++)
if (mask[i])
WRITE_STENCIL( x1, y, stencil[i] );
}
else
{
for (;i<n1;i++,x1++)
WRITE_STENCIL( x1, y, stencil[i] );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteStencilPixels)( GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLstencil stencil[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_STENCIL_VARS;
if (DBG) fprintf(stderr, "WriteStencilPixels\n");
HW_CLIPLOOP()
{
for (i=0;i<n;i++)
{
if (mask[i]) {
const int fy = Y_FLIP(y[i]);
if (CLIPPIXEL(x[i],fy))
WRITE_STENCIL( x[i], fy, stencil[i] );
}
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
/* Read stencil spans and pixels
*/
static void TAG(ReadStencilSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLstencil stencil[])
{
HW_READ_LOCK()
{
GLint x1,n1;
LOCAL_STENCIL_VARS;
y = Y_FLIP(y);
if (DBG) fprintf(stderr, "ReadStencilSpan\n");
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;i<n1;i++)
READ_STENCIL( stencil[i], (x1+i), y );
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
static void TAG(ReadStencilPixels)( GLcontext *ctx, GLuint n,
const GLint x[], const GLint y[],
GLstencil stencil[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_STENCIL_VARS;
if (DBG) fprintf(stderr, "ReadStencilPixels\n");
HW_CLIPLOOP()
{
for (i=0;i<n;i++) {
int fy = Y_FLIP( y[i] );
if (CLIPPIXEL( x[i], fy ))
READ_STENCIL( stencil[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
#undef WRITE_STENCIL
#undef READ_STENCIL
#undef TAG

View file

@ -0,0 +1,176 @@
/* $XFree86: xc/lib/GL/mesa/src/drv/common/depthtmp.h,v 1.5 2001/03/21 16:14:20 dawes Exp $ */
#ifndef DBG
#define DBG 0
#endif
#ifndef HAVE_HW_DEPTH_SPANS
#define HAVE_HW_DEPTH_SPANS 0
#endif
#ifndef HAVE_HW_DEPTH_PIXELS
#define HAVE_HW_DEPTH_PIXELS 0
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
static void TAG(WriteDepthSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLdepth *depth,
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_DEPTH_VARS;
y = Y_FLIP( y );
#if HAVE_HW_DEPTH_SPANS
(void) x1; (void) n1;
if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n",
(int)n, (int)x );
WRITE_DEPTH_SPAN();
#else
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN( x, y, n, x1, n1, i );
if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1 );
if ( mask ) {
for ( ; i < n1 ; i++, x1++ ) {
if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] );
}
} else {
for ( ; i < n1 ; i++, x1++ ) {
WRITE_DEPTH( x1, y, depth[i] );
}
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteDepthPixels)( GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLdepth depth[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_DEPTH_VARS;
if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
#if HAVE_HW_DEPTH_PIXELS
(void) i;
WRITE_DEPTH_PIXELS();
#else
HW_CLIPLOOP()
{
for ( i = 0 ; i < n ; i++ ) {
if ( mask[i] ) {
const int fy = Y_FLIP( y[i] );
if ( CLIPPIXEL( x[i], fy ) )
WRITE_DEPTH( x[i], fy, depth[i] );
}
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_WRITE_UNLOCK();
}
/* Read depth spans and pixels
*/
static void TAG(ReadDepthSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLdepth depth[] )
{
HW_READ_LOCK()
{
GLint x1, n1;
LOCAL_DEPTH_VARS;
y = Y_FLIP( y );
if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
#if HAVE_HW_DEPTH_SPANS
(void) x1; (void) n1;
READ_DEPTH_SPAN();
#else
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN( x, y, n, x1, n1, i );
for ( ; i < n1 ; i++ )
READ_DEPTH( depth[i], (x1+i), y );
}
HW_ENDCLIPLOOP();
#endif
}
HW_READ_UNLOCK();
}
static void TAG(ReadDepthPixels)( GLcontext *ctx, GLuint n,
const GLint x[], const GLint y[],
GLdepth depth[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_DEPTH_VARS;
if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
#if HAVE_HW_DEPTH_PIXELS
(void) i;
READ_DEPTH_PIXELS();
#else
HW_CLIPLOOP()
{
for ( i = 0 ; i < n ;i++ ) {
int fy = Y_FLIP( y[i] );
if ( CLIPPIXEL( x[i], fy ) )
READ_DEPTH( depth[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
#endif
}
HW_READ_UNLOCK();
}
#if HAVE_HW_DEPTH_SPANS
#undef WRITE_DEPTH_SPAN
#undef WRITE_DEPTH_PIXELS
#undef READ_DEPTH_SPAN
#undef READ_DEPTH_PIXELS
#else
#undef WRITE_DEPTH
#undef READ_DEPTH
#endif
#undef TAG

View file

@ -0,0 +1,142 @@
/*
* GLX Hardware Device Driver common code
*
* Based on the original MGA G200 driver (c) 1999 Wittawat Yamwong
*
* 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
* WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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.
*
*
* Wittawat Yamwong <Wittawat.Yamwong@stud.uni-hannover.de>
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/hwlog.c,v 1.3 2001/08/18 02:51:03 dawes Exp $ */
#include "hwlog.h"
hwlog_t hwlog = { 0,0,0, "[???] "};
/* Should be shared, but is this a good place for it?
*/
#include <sys/time.h>
#include <stdarg.h>
int usec( void )
{
struct timeval tv;
struct timezone tz;
gettimeofday( &tv, &tz );
return (tv.tv_sec & 2047) * 1000000 + tv.tv_usec;
}
#ifdef HW_LOG_ENABLED
int hwOpenLog(const char *filename, char *prefix)
{
hwCloseLog();
hwSetLogLevel(0);
hwlog.prefix=prefix;
if (!filename)
return -1;
if ((hwlog.file = fopen(filename,"w")) == NULL)
return -1;
return 0;
}
void hwCloseLog()
{
if (hwlog.file) {
fclose(hwlog.file);
hwlog.file = NULL;
}
}
int hwIsLogReady()
{
return (hwlog.file != NULL);
}
void hwSetLogLevel(int level)
{
hwlog.level = level;
}
int hwGetLogLevel()
{
return hwlog.level;
}
void hwLog(int level, const char *format, ...)
{
va_list ap;
va_start(ap,format);
hwLogv(level,format,ap);
va_end(ap);
}
void hwLogv(int l, const char *format, va_list ap)
{
if (hwlog.file && (l <= hwlog.level)) {
vfprintf(hwlog.file,format,ap);
fflush(hwlog.file);
}
}
void hwMsg(int l, const char *format, ...)
{
va_list ap;
va_start(ap, format);
if (l <= hwlog.level) {
if (hwIsLogReady()) {
int t = usec();
hwLog(l, "%6i:", t - hwlog.timeTemp);
hwlog.timeTemp = t;
hwLogv(l, format, ap);
} else {
fprintf(stderr, hwlog.prefix);
vfprintf(stderr, format, ap);
}
}
va_end(ap);
}
#else /* ifdef HW_LOG_ENABLED */
int hwlogdummy()
{
return 0;
}
#endif
void hwError(const char *format, ...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, hwlog.prefix);
vfprintf(stderr, format, ap);
hwLogv(0, format, ap);
va_end(ap);
}

View file

@ -0,0 +1,101 @@
/*
* GLX Hardware Device Driver common code
*
* Based on the original MGA G200 driver (c) 1999 Wittawat Yamwong
*
* 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
* WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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.
*
*
* Wittawat Yamwong <Wittawat.Yamwong@stud.uni-hannover.de>
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/hwlog.h,v 1.5 2001/10/31 23:22:57 tsi Exp $ */
/* Usage:
* - use mgaError for error messages. Always write to X error and log file.
* - use mgaMsg for debugging. Can be disabled by undefining MGA_LOG_ENABLED.
*/
#ifndef HWLOG_INC
#define HWLOG_INC
#include <stdarg.h>
#include <stdio.h>
#define DBG_LEVEL_BASE 1
#define DBG_LEVEL_VERBOSE 10
#define DBG_LEVEL_ENTEREXIT 20
typedef struct
{
FILE *file;
int level;
unsigned int timeTemp;
char *prefix;
} hwlog_t;
extern hwlog_t hwlog;
#ifdef HW_LOG_ENABLED
/* open and close log file. */
int hwOpenLog(const char *filename, char *prefix);
void hwCloseLog(void);
/* return 1 if log file is succesfully opened */
int hwIsLogReady(void);
/* set current log level to 'level'. Messages with level less than or equal
the current log level will be written to the log file. */
void hwSetLogLevel(int level);
int hwGetLogLevel(void);
/* hwLog and hwLogv write a message to the log file. */
/* do not call these directly, use hwMsg() instead */
void hwLog(int level, const char *format, ...);
void hwLogv(int level, const char *format, va_list ap);
int usec( void );
/* hwMsg writes a message to the log file or to the standard X error file. */
void hwMsg(int level, const char *format, ...);
#else
static __inline__ int hwOpenLog(const char *f, char *prefix) { hwlog.prefix=prefix; return -1; }
#define hwIsLogReady() (0)
#define hwGetLogLevel() (-1)
#define hwLogLevel(n) (0)
#define hwLog()
#define hwMsg()
#define hwCloseLog()
#define hwSetLogLevel(x)
#define hwLogv(l,f,a)
#endif
void hwError(const char *format, ...);
#endif

View file

@ -0,0 +1,200 @@
/*
* GLX Hardware Device Driver common code
* Copyright (C) 1999 Keith Whitwell
*
* 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
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
*
*/
/* $XFree86: xc/lib/GL/mesa/src/drv/common/mm.c,v 1.3 2001/08/18 02:51:03 dawes Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include "mm.h"
#include "hwlog.h"
/* KW: I don't know who the author of this code is, but it wasn't me
* despite what the copyright says...
*/
void mmDumpMemInfo( memHeap_t *heap )
{
TMemBlock *p;
fprintf(stderr, "Memory heap %p:\n", heap);
if (heap == 0) {
fprintf(stderr, " heap == 0\n");
} else {
p = (TMemBlock *)heap;
while (p) {
fprintf(stderr, " Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
p->free ? '.':'U',
p->reserved ? 'R':'.');
p = p->next;
}
}
fprintf(stderr, "End of memory blocks\n");
}
memHeap_t *mmInit(int ofs,
int size)
{
PMemBlock blocks;
if (size <= 0) {
return 0;
}
blocks = (TMemBlock *) calloc(1,sizeof(TMemBlock));
if (blocks) {
blocks->ofs = ofs;
blocks->size = size;
blocks->free = 1;
return (memHeap_t *)blocks;
} else
return 0;
}
static TMemBlock* SliceBlock(TMemBlock *p,
int startofs, int size,
int reserved, int alignment)
{
TMemBlock *newblock;
/* break left */
if (startofs > p->ofs) {
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
if (!newblock)
return NULL;
newblock->ofs = startofs;
newblock->size = p->size - (startofs - p->ofs);
newblock->free = 1;
newblock->next = p->next;
p->size -= newblock->size;
p->next = newblock;
p = newblock;
}
/* break right */
if (size < p->size) {
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
if (!newblock)
return NULL;
newblock->ofs = startofs + size;
newblock->size = p->size - size;
newblock->free = 1;
newblock->next = p->next;
p->size = size;
p->next = newblock;
}
/* p = middle block */
p->align = alignment;
p->free = 0;
p->reserved = reserved;
return p;
}
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
{
int mask,startofs,endofs;
TMemBlock *p;
if (!heap || align2 < 0 || size <= 0)
return NULL;
mask = (1 << align2)-1;
startofs = 0;
p = (TMemBlock *)heap;
while (p) {
if ((p)->free) {
startofs = (p->ofs + mask) & ~mask;
if ( startofs < startSearch ) {
startofs = startSearch;
}
endofs = startofs+size;
if (endofs <= (p->ofs+p->size))
break;
}
p = p->next;
}
if (!p)
return NULL;
p = SliceBlock(p,startofs,size,0,mask+1);
p->heap = heap;
return p;
}
static __inline__ int Join2Blocks(TMemBlock *p)
{
if (p->free && p->next && p->next->free) {
TMemBlock *q = p->next;
p->size += q->size;
p->next = q->next;
free(q);
return 1;
}
return 0;
}
int mmFreeMem(PMemBlock b)
{
TMemBlock *p,*prev;
if (!b)
return 0;
if (!b->heap) {
fprintf(stderr, "no heap\n");
return -1;
}
p = b->heap;
prev = NULL;
while (p && p != b) {
prev = p;
p = p->next;
}
if (!p || p->free || p->reserved) {
if (!p)
fprintf(stderr, "block not found in heap\n");
else if (p->free)
fprintf(stderr, "block already free\n");
else
fprintf(stderr, "block is reserved\n");
return -1;
}
p->free = 1;
Join2Blocks(p);
if (prev)
Join2Blocks(prev);
return 0;
}
void mmDestroy(memHeap_t *heap)
{
TMemBlock *p,*q;
if (!heap)
return;
p = (TMemBlock *)heap;
while (p) {
q = p->next;
free(p);
p = q;
}
}

View file

@ -0,0 +1,82 @@
/*
* GLX Hardware Device Driver common code
* Copyright (C) 1999 Keith Whitwell
*
* 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
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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 MM_INC
#define MM_INC
struct mem_block_t {
struct mem_block_t *next;
struct mem_block_t *heap;
int ofs,size;
int align;
int free:1;
int reserved:1;
};
typedef struct mem_block_t TMemBlock;
typedef struct mem_block_t *PMemBlock;
/* a heap is just the first block in a chain */
typedef struct mem_block_t memHeap_t;
static __inline__ int mmBlockSize(PMemBlock b)
{ return b->size; }
static __inline__ int mmOffset(PMemBlock b)
{ return b->ofs; }
/*
* input: total size in bytes
* return: a heap pointer if OK, NULL if error
*/
memHeap_t *mmInit( int ofs, int size );
/*
* Allocate 'size' bytes with 2^align2 bytes alignment,
* restrict the search to free memory after 'startSearch'
* depth and back buffers should be in different 4mb banks
* to get better page hits if possible
* input: size = size of block
* align2 = 2^align2 bytes alignment
* startSearch = linear offset from start of heap to begin search
* return: pointer to the allocated block, 0 if error
*/
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2,
int startSearch );
/*
* Free block starts at offset
* input: pointer to a block
* return: 0 if OK, -1 if error
*/
int mmFreeMem( PMemBlock b );
/*
* destroy MM
*/
void mmDestroy( memHeap_t *mmInit );
/* For debuging purpose. */
void mmDumpMemInfo( memHeap_t *mmInit );
#endif

View file

@ -0,0 +1,259 @@
#ifndef DBG
#define DBG 0
#endif
#ifndef HW_WRITE_LOCK
#define HW_WRITE_LOCK() HW_LOCK()
#endif
#ifndef HW_WRITE_UNLOCK
#define HW_WRITE_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_CLIPLOOP
#define HW_READ_CLIPLOOP() HW_CLIPLOOP()
#endif
#ifndef HW_WRITE_CLIPLOOP
#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
#endif
static void TAG(WriteRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgba[][4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
y = Y_FLIP(y);
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_RGBA( x1, y,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
else
{
for (;n1>0;i++,x1++,n1--)
WRITE_RGBA( x1, y,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteRGBSpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgb[][3],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
y = Y_FLIP(y);
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
}
else
{
for (;n1>0;i++,x1++,n1--)
WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteRGBAPixels)( const GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLubyte rgba[][4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_VARS;
if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
HW_WRITE_CLIPLOOP()
{
for (i=0;i<n;i++)
{
if (mask[i]) {
const int fy = Y_FLIP(y[i]);
if (CLIPPIXEL(x[i],fy))
WRITE_RGBA( x[i], fy,
rgba[i][0], rgba[i][1],
rgba[i][2], rgba[i][3] );
}
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLchan color[4],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_VARS;
INIT_MONO_PIXEL(p, color);
y = Y_FLIP( y );
if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
HW_WRITE_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;n1>0;i++,x1++,n1--)
if (mask[i])
WRITE_PIXEL( x1, y, p );
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx,
GLuint n,
const GLint x[], const GLint y[],
const GLchan color[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_VARS;
INIT_MONO_PIXEL(p, color);
if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
HW_WRITE_CLIPLOOP()
{
for (i=0;i<n;i++)
if (mask[i]) {
int fy = Y_FLIP(y[i]);
if (CLIPPIXEL( x[i], fy ))
WRITE_PIXEL( x[i], fy, p );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(ReadRGBASpan)( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLubyte rgba[][4])
{
HW_READ_LOCK()
{
GLint x1,n1;
LOCAL_VARS;
y = Y_FLIP(y);
if (DBG) fprintf(stderr, "ReadRGBASpan\n");
HW_READ_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;n1>0;i++,x1++,n1--)
READ_RGBA( rgba[i], x1, y );
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
static void TAG(ReadRGBAPixels)( const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4], const GLubyte mask[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_VARS;
if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
HW_READ_CLIPLOOP()
{
for (i=0;i<n;i++)
if (mask[i]) {
int fy = Y_FLIP( y[i] );
if (CLIPPIXEL( x[i], fy ))
READ_RGBA( rgba[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
#undef WRITE_PIXEL
#undef WRITE_RGBA
#undef READ_RGBA
#undef TAG

View file

@ -0,0 +1,147 @@
/* $XFree86: xc/lib/GL/mesa/src/drv/common/stenciltmp.h,v 1.3 2001/03/21 16:14:20 dawes Exp $ */
#ifndef DBG
#define DBG 0
#endif
#ifndef HW_WRITE_LOCK
#define HW_WRITE_LOCK() HW_LOCK()
#endif
#ifndef HW_WRITE_UNLOCK
#define HW_WRITE_UNLOCK() HW_UNLOCK()
#endif
#ifndef HW_READ_LOCK
#define HW_READ_LOCK() HW_LOCK()
#endif
#ifndef HW_READ_UNLOCK
#define HW_READ_UNLOCK() HW_UNLOCK()
#endif
static void TAG(WriteStencilSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLstencil *stencil,
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint x1;
GLint n1;
LOCAL_STENCIL_VARS;
y = Y_FLIP(y);
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
(int)i, (int)n1, (int)x1);
if (mask)
{
for (;i<n1;i++,x1++)
if (mask[i])
WRITE_STENCIL( x1, y, stencil[i] );
}
else
{
for (;i<n1;i++,x1++)
WRITE_STENCIL( x1, y, stencil[i] );
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
static void TAG(WriteStencilPixels)( GLcontext *ctx,
GLuint n,
const GLint x[],
const GLint y[],
const GLstencil stencil[],
const GLubyte mask[] )
{
HW_WRITE_LOCK()
{
GLint i;
LOCAL_STENCIL_VARS;
if (DBG) fprintf(stderr, "WriteStencilPixels\n");
HW_CLIPLOOP()
{
for (i=0;i<n;i++)
{
if (mask[i]) {
const int fy = Y_FLIP(y[i]);
if (CLIPPIXEL(x[i],fy))
WRITE_STENCIL( x[i], fy, stencil[i] );
}
}
}
HW_ENDCLIPLOOP();
}
HW_WRITE_UNLOCK();
}
/* Read stencil spans and pixels
*/
static void TAG(ReadStencilSpan)( GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLstencil stencil[])
{
HW_READ_LOCK()
{
GLint x1,n1;
LOCAL_STENCIL_VARS;
y = Y_FLIP(y);
if (DBG) fprintf(stderr, "ReadStencilSpan\n");
HW_CLIPLOOP()
{
GLint i = 0;
CLIPSPAN(x,y,n,x1,n1,i);
for (;i<n1;i++)
READ_STENCIL( stencil[i], (x1+i), y );
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
static void TAG(ReadStencilPixels)( GLcontext *ctx, GLuint n,
const GLint x[], const GLint y[],
GLstencil stencil[] )
{
HW_READ_LOCK()
{
GLint i;
LOCAL_STENCIL_VARS;
if (DBG) fprintf(stderr, "ReadStencilPixels\n");
HW_CLIPLOOP()
{
for (i=0;i<n;i++) {
int fy = Y_FLIP( y[i] );
if (CLIPPIXEL( x[i], fy ))
READ_STENCIL( stencil[i], x[i], fy );
}
}
HW_ENDCLIPLOOP();
}
HW_READ_UNLOCK();
}
#undef WRITE_STENCIL
#undef READ_STENCIL
#undef TAG