#include "glheader.h"
#include "macros.h"
#include "mtypes.h"
#include "simple_list.h"
#include "enums.h"
#include "texformat.h"
#include "i830_screen.h"
#include "i830_dri.h"
#include "i830_context.h"
#include "i830_tex.h"
#include "i830_state.h"
#include "i830_ioctl.h"
void i830DestroyTexObj(i830ContextPtr imesa, i830TextureObjectPtr t)
{
unsigned i;
if ( imesa != NULL ) {
for ( i = 0 ; i < imesa->glCtx->Const.MaxTextureUnits ; i++ ) {
if ( t == imesa->CurrentTexObj[ i ] ) {
imesa->CurrentTexObj[ i ] = NULL;
imesa->dirty &= ~(I830_UPLOAD_TEX0 << i);
}
}
}
}
#if defined(i386) || defined(__i386__)
static __inline__ void * __memcpy(void * to, const void * from, size_t n)
{
int d0, d1, d2;
__asm__ __volatile__(
"rep ; movsl\n\t"
"testb $2,%b4\n\t"
"je 1f\n\t"
"movsw\n"
"1:\ttestb $1,%b4\n\t"
"je 2f\n\t"
"movsb\n"
"2:"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
:"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
: "memory");
return (to);
}
#else
#define __memcpy memcpy
#endif
static void i830UploadTexLevel( i830ContextPtr imesa,
i830TextureObjectPtr t, int hwlevel )
{
const struct gl_texture_image *image = t->image[0][hwlevel].image;
int j;
if (!image || !image->Data)
return;
if (image->Width * image->TexFormat->TexelBytes == t->Pitch) {
GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[0][hwlevel].offset);
GLubyte *src = (GLubyte *)image->Data;
memcpy( dst, src, t->Pitch * image->Height );
}
else switch (image->TexFormat->TexelBytes) {
case 1:
{
GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[0][hwlevel].offset);
GLubyte *src = (GLubyte *)image->Data;
for (j = 0 ; j < image->Height ; j++, dst += t->Pitch) {
__memcpy(dst, src, image->Width );
src += image->Width;
}
}
break;
case 2:
{
GLushort *dst = (GLushort *)(t->BufAddr + t->image[0][hwlevel].offset);
GLushort *src = (GLushort *)image->Data;
for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/2)) {
__memcpy(dst, src, image->Width * 2 );
src += image->Width;
}
}
break;
case 4:
{
GLuint *dst = (GLuint *)(t->BufAddr + t->image[0][hwlevel].offset);
GLuint *src = (GLuint *)image->Data;
for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/4)) {
__memcpy(dst, src, image->Width * 4 );
src += image->Width;
}
}
break;
default:
fprintf(stderr, "%s: Not supported texel size %d\n",
__FUNCTION__, image->TexFormat->TexelBytes);
}
}
int i830UploadTexImagesLocked( i830ContextPtr imesa, i830TextureObjectPtr t )
{
int ofs;
if ( t->base.memBlock == NULL ) {
int heap;
heap = driAllocateTexture( imesa->texture_heaps, imesa->nr_heaps,
(driTextureObject *) t );
if ( heap == -1 ) {
return -1;
}
ofs = t->base.memBlock->ofs;
t->BufAddr = imesa->i830Screen->tex.map + ofs;
t->Setup[I830_TEXREG_TM0S0] = (TM0S0_USE_FENCE |
(imesa->i830Screen->textureOffset + ofs));
if (t == imesa->CurrentTexObj[0])
imesa->dirty |= I830_UPLOAD_TEX0;
if (t == imesa->CurrentTexObj[1])
imesa->dirty |= I830_UPLOAD_TEX1;
#if 0
if (t == imesa->CurrentTexObj[2])
I830_STATECHANGE(imesa, I830_UPLOAD_TEX2);
if (t == imesa->CurrentTexObj[3])
I830_STATECHANGE(imesa, I830_UPLOAD_TEX3);
#endif
}
driUpdateTextureLRU( (driTextureObject *) t );
if (imesa->texture_heaps[0]->timestamp >= GET_DISPATCH_AGE(imesa))
i830WaitAgeLocked( imesa, imesa->texture_heaps[0]->timestamp );
if (t->base.dirty_images[0]) {
int i;
const int numLevels = t->base.lastLevel - t->base.firstLevel + 1;
for (i = 0 ; i < numLevels ; i++) {
if ( (t->base.dirty_images[0] & (1 << (i+t->base.firstLevel))) != 0 ) {
i830UploadTexLevel( imesa, t, i );
}
}
t->base.dirty_images[0] = 0;
imesa->sarea->perf_boxes |= I830_BOX_TEXTURE_LOAD;
}
return 0;
}