server_getteximage.c revision 88c504b1c053e580e42d5fc90ef2ccedc50c65bd
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/* Copyright (c) 2001, Stanford University
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * All rights reserved
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the file LICENSE.txt for information on redistributing this software.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "chromium.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "cr_error.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "cr_mem.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "cr_pixeldata.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "server_dispatch.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "server.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid SERVER_DISPATCH_APIENTRY
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynccrServerDispatchGetTexImage(GLenum target, GLint level, GLenum format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync GLenum type, GLvoid * pixels)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync GLsizei width, height, depth, size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync GLvoid *buffer = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef CR_ARB_pixel_buffer_object
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync GLvoid *pbo_offset;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*pixels are actualy a pointer to location of 8byte network pointer in hgcm buffer
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync regarless of guest/host bitness we're using only 4lower bytes as there're no
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pbo>4gb (yet?)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pbo_offset = (GLvoid*) ((uintptr_t) *((GLint*)pixels));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cr_server.head_spu->dispatch_table.GetTexImage(target, level, format, type, pbo_offset);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size = crTextureSize(format, type, width, height, depth);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
#if 0
{
CRContext *ctx = crStateGetCurrent();
CRTextureObj *tobj;
CRTextureLevel *tl;
GLint id;
crDebug("GetTexImage: %d, %i, %d, %d", target, level, format, type);
crDebug("===StateTracker===");
crDebug("Current TU: %i", ctx->texture.curTextureUnit);
if (target==GL_TEXTURE_2D)
{
tobj = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D;
CRASSERT(tobj);
tl = &tobj->level[0][level];
crDebug("Texture %i(hw %i), w=%i, h=%i", tobj->id, tobj->hwid, tl->width, tl->height, tl->depth);
}
else
{
crDebug("Not 2D tex");
}
crDebug("===GPU===");
cr_server.head_spu->dispatch_table.GetIntegerv(GL_ACTIVE_TEXTURE, &id);
crDebug("Current TU: %i", id);
if (target==GL_TEXTURE_2D)
{
cr_server.head_spu->dispatch_table.GetIntegerv(GL_TEXTURE_BINDING_2D, &id);
crDebug("Texture: %i, w=%i, h=%i, d=%i", id, width, height, depth);
}
}
#endif
if (size && (buffer = crAlloc(size))) {
/* Note, the other pixel PACK parameters (default values) should
* be OK at this point.
*/
cr_server.head_spu->dispatch_table.PixelStorei(GL_PACK_ALIGNMENT, 1);
cr_server.head_spu->dispatch_table.GetTexImage(target, level, format, type, buffer);
crServerReturnValue( buffer, size );
crFree(buffer);
}
else {
/* need to return _something_ to avoid blowing up */
GLuint dummy = 0;
crServerReturnValue( (GLvoid *) &dummy, sizeof(dummy) );
}
}
#if CR_ARB_texture_compression
void SERVER_DISPATCH_APIENTRY
crServerDispatchGetCompressedTexImageARB(GLenum target, GLint level,
GLvoid *img)
{
GLint size;
GLvoid *buffer=NULL;
#ifdef CR_ARB_pixel_buffer_object
if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
{
GLvoid *pbo_offset;
pbo_offset = (GLvoid*) ((uintptr_t) *((GLint*)img));
cr_server.head_spu->dispatch_table.GetCompressedTexImageARB(target, level, pbo_offset);
return;
}
#endif
cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
if (size && (buffer = crAlloc(size))) {
/* XXX the pixel PACK parameter should be OK at this point */
cr_server.head_spu->dispatch_table.GetCompressedTexImageARB(target, level, buffer);
crServerReturnValue( buffer, size );
crFree(buffer);
}
else {
/* need to return _something_ to avoid blowing up */
GLuint dummy = 0;
crServerReturnValue( (GLvoid *) &dummy, sizeof(dummy) );
}
}
#endif /* CR_ARB_texture_compression */
void SERVER_DISPATCH_APIENTRY crServerDispatchGetPolygonStipple( GLubyte * mask )
{
#ifdef CR_ARB_pixel_buffer_object
if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
{
GLvoid *pbo_offset;
pbo_offset = (GLubyte*) ((uintptr_t) *((GLint*)mask));
cr_server.head_spu->dispatch_table.GetPolygonStipple(pbo_offset);
}
else
#endif
{
GLubyte local_mask[128];
cr_server.head_spu->dispatch_table.GetPolygonStipple( local_mask );
crServerReturnValue( &(local_mask[0]), 128*sizeof(GLubyte) );
}
}