#include "glheader.h"
#include "context.h"
#include "simple_list.h"
#include "imports.h"
#include "matrix.h"
#include "extensions.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "array_cache/acache.h"
#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
#include "r128_context.h"
#include "r128_ioctl.h"
#include "r128_dd.h"
#include "r128_state.h"
#include "r128_span.h"
#include "r128_tex.h"
#include "r128_tris.h"
#include "r128_vb.h"
#include "vblank.h"
#include "utils.h"
#include "texmem.h"
#ifndef R128_DEBUG
int R128_DEBUG = 0;
#endif
static const char * const card_extensions[] =
{
"GL_ARB_multitexture",
"GL_ARB_texture_env_add",
"GL_ARB_texture_mirrored_repeat",
"GL_EXT_texture_edge_clamp",
"GL_EXT_texture_env_add",
"GL_IBM_texture_mirrored_repeat",
"GL_SGIS_generate_mipmap",
"GL_SGIS_texture_edge_clamp",
NULL
};
static const struct dri_debug_control debug_control[] =
{
{ "ioctl", DEBUG_VERBOSE_IOCTL },
{ "verb", DEBUG_VERBOSE_MSG },
{ "dri", DEBUG_VERBOSE_DRI },
{ "2d", DEBUG_VERBOSE_2D },
{ "sync", DEBUG_ALWAYS_SYNC },
{ "api", DEBUG_VERBOSE_API },
{ NULL, 0 }
};
GLboolean r128CreateContext( const __GLcontextModes *glVisual,
__DRIcontextPrivate *driContextPriv,
void *sharedContextPrivate )
{
GLcontext *ctx, *shareCtx;
__DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
r128ContextPtr rmesa;
r128ScreenPtr r128scrn;
int i;
rmesa = (r128ContextPtr) CALLOC( sizeof(*rmesa) );
if ( !rmesa )
return GL_FALSE;
if (sharedContextPrivate)
shareCtx = ((r128ContextPtr) sharedContextPrivate)->glCtx;
else
shareCtx = NULL;
rmesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) rmesa, GL_TRUE);
if (!rmesa->glCtx) {
FREE(rmesa);
return GL_FALSE;
}
driContextPriv->driverPrivate = rmesa;
ctx = rmesa->glCtx;
rmesa->driContext = driContextPriv;
rmesa->driScreen = sPriv;
rmesa->driDrawable = NULL;
rmesa->hHWContext = driContextPriv->hHWContext;
rmesa->driHwLock = &sPriv->pSAREA->lock;
rmesa->driFd = sPriv->fd;
r128scrn = rmesa->r128Screen = (r128ScreenPtr)(sPriv->private);
rmesa->sarea = (R128SAREAPrivPtr)((char *)sPriv->pSAREA +
r128scrn->sarea_priv_offset);
rmesa->CurrentTexObj[0] = NULL;
rmesa->CurrentTexObj[1] = NULL;
(void) memset( rmesa->texture_heaps, 0, sizeof( rmesa->texture_heaps ) );
make_empty_list( & rmesa->swapped );
rmesa->nr_heaps = r128scrn->numTexHeaps;
for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
rmesa->texture_heaps[i] = driCreateTextureHeap( i, rmesa,
r128scrn->texSize[i],
12,
R128_NR_TEX_REGIONS,
rmesa->sarea->texList[i],
& rmesa->sarea->texAge[i],
& rmesa->swapped,
sizeof( r128TexObj ),
(destroy_texture_object_t *) r128DestroyTexObj );
driSetTextureSwapCounterLocation( rmesa->texture_heaps[i],
& rmesa->c_textureSwaps );
}
rmesa->RenderIndex = -1;
rmesa->vert_buf = NULL;
rmesa->num_verts = 0;
ctx->Const.MaxTextureUnits = 2;
driCalculateMaxTextureLevels( rmesa->texture_heaps,
rmesa->nr_heaps,
& ctx->Const,
4,
10,
0,
0,
0,
11,
GL_FALSE );
ctx->Const.MinPointSize = 1.0;
ctx->Const.MinPointSizeAA = 1.0;
ctx->Const.MaxPointSize = 1.0;
ctx->Const.MaxPointSizeAA = 1.0;
ctx->Const.MinLineWidth = 1.0;
ctx->Const.MinLineWidthAA = 1.0;
ctx->Const.MaxLineWidth = 1.0;
ctx->Const.MaxLineWidthAA = 1.0;
ctx->Const.LineWidthGranularity = 1.0;
#if ENABLE_PERF_BOXES
rmesa->boxes = (getenv( "LIBGL_PERFORMANCE_BOXES" ) != NULL);
#endif
_swrast_CreateContext( ctx );
_ac_CreateContext( ctx );
_tnl_CreateContext( ctx );
_swsetup_CreateContext( ctx );
_swrast_allow_pixel_fog( ctx, GL_FALSE );
_swrast_allow_vertex_fog( ctx, GL_TRUE );
driInitExtensions( ctx, card_extensions, GL_TRUE );
if (sPriv->drmMinor >= 4)
_mesa_enable_extension( ctx, "GL_MESA_ycbcr_texture" );
r128InitVB( ctx );
r128InitTriFuncs( ctx );
r128DDInitDriverFuncs( ctx );
r128DDInitIoctlFuncs( ctx );
r128DDInitStateFuncs( ctx );
r128DDInitSpanFuncs( ctx );
r128DDInitTextureFuncs( ctx );
r128DDInitState( rmesa );
rmesa->do_irqs = (rmesa->r128Screen->irq && !getenv("R128_NO_IRQS"));
rmesa->vblank_flags = (rmesa->r128Screen->irq != 0)
? driGetDefaultVBlankFlags() : VBLANK_FLAG_NO_IRQ;
driContextPriv->driverPrivate = (void *)rmesa;
#if DO_DEBUG
R128_DEBUG = driParseDebugString( getenv( "R128_DEBUG" ),
debug_control );
#endif
return GL_TRUE;
}
void r128DestroyContext( __DRIcontextPrivate *driContextPriv )
{
r128ContextPtr rmesa = (r128ContextPtr) driContextPriv->driverPrivate;
assert(rmesa);
if ( rmesa ) {
GLboolean release_texture_heaps;
release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);
_swsetup_DestroyContext( rmesa->glCtx );
_tnl_DestroyContext( rmesa->glCtx );
_ac_DestroyContext( rmesa->glCtx );
_swrast_DestroyContext( rmesa->glCtx );
r128FreeVB( rmesa->glCtx );
rmesa->glCtx->DriverCtx = NULL;
_mesa_destroy_context(rmesa->glCtx);
if ( release_texture_heaps ) {
int i;
for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
rmesa->texture_heaps[ i ] = NULL;
}
assert( is_empty_list( & rmesa->swapped ) );
}
FREE( rmesa );
}
#if 0
glx_fini_prof();
#endif
}
GLboolean
r128MakeCurrent( __DRIcontextPrivate *driContextPriv,
__DRIdrawablePrivate *driDrawPriv,
__DRIdrawablePrivate *driReadPriv )
{
if ( driContextPriv ) {
GET_CURRENT_CONTEXT(ctx);
r128ContextPtr oldR128Ctx = ctx ? R128_CONTEXT(ctx) : NULL;
r128ContextPtr newR128Ctx = (r128ContextPtr) driContextPriv->driverPrivate;
if ( newR128Ctx != oldR128Ctx ) {
newR128Ctx->new_state |= R128_NEW_CONTEXT;
newR128Ctx->dirty = R128_UPLOAD_ALL;
}
newR128Ctx->driDrawable = driDrawPriv;
_mesa_make_current2( newR128Ctx->glCtx,
(GLframebuffer *) driDrawPriv->driverPrivate,
(GLframebuffer *) driReadPriv->driverPrivate );
newR128Ctx->new_state |= R128_NEW_WINDOW | R128_NEW_CLIP;
if ( !newR128Ctx->glCtx->Viewport.Width ) {
_mesa_set_viewport(newR128Ctx->glCtx, 0, 0,
driDrawPriv->w, driDrawPriv->h);
}
} else {
_mesa_make_current( 0, 0 );
}
return GL_TRUE;
}
GLboolean
r128UnbindContext( __DRIcontextPrivate *driContextPriv )
{
return GL_TRUE;
}