/* * Direct Rendering Support for SMedia Glamo 336x/337x * * (c) 2009-2010 Thomas White * Roughly based on sis_state.c (c) 2003 Eric Anholt * * 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 * THE AUTHORS 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. * * * Also partially based on intel_fbo.c, to which the following notice applies: * * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * 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, sub license, 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 (including the * next paragraph) 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 NON-INFRINGEMENT. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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. */ #include "main/context.h" #include "main/framebuffer.h" #include "main/api_arrayelt.h" #include "swrast/swrast.h" #include "swrast_setup/swrast_setup.h" #include "tnl/tnl.h" #include "glamo_fbo.h" #include "glamo_state.h" #include "glamo_context.h" #include "glamo_cmdq.h" #include "glamo_regs.h" static void glamoResizeBuffers(GLcontext *ctx, struct gl_framebuffer *fb, GLuint width, GLuint height) { struct glamo_framebuffer *glamo_fb = (struct glamo_framebuffer *)fb; int i; _mesa_resize_framebuffer(ctx, fb, width, height); fb->Initialized = GL_TRUE; /* XXX remove someday */ if (fb->Name != 0) { return; } /* Make sure all window system renderbuffers are up to date */ for (i = 0; i < 2; i++) { struct gl_renderbuffer *rb = &glamo_fb->color_rb[i]->base; /* only resize if size is changing */ if (rb && (rb->Width != width || rb->Height != height)) { rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height); } } } static void glamoClear(GLcontext *ctx, GLbitfield mask) { glamoContext *gCtx; struct gl_framebuffer *fb; int i; gCtx = GLAMO_CONTEXT(ctx); fb = ctx->DrawBuffer; printf("glamoClear (%f %f %f %f)\n", ctx->Color.ClearColor[0], ctx->Color.ClearColor[1], ctx->Color.ClearColor[2], ctx->Color.ClearColor[3]); fflush(stdout); for (i = 0; i < fb->_NumColorDrawBuffers; i++) { struct glamo_renderbuffer *grb; grb = glamo_renderbuffer(fb->_ColorDrawBuffers[i]); glamoDRMStartBurst(gCtx, GLAMO_REG_2D_DST_X); glamoDRMAddData(gCtx, fb->_Xmin, 2); /* dest X */ glamoDRMAddData(gCtx, fb->_Ymin, 2); /* dest Y */ glamoDRMAddBO(gCtx, grb->bo); /* dest L/H */ glamoDRMAddData(gCtx, grb->pitch & 0x7ff, 2); /* dest pitch */ glamoDRMAddData(gCtx, grb->height, 2); /* dest height */ glamoDRMAddData(gCtx, fb->_Xmax-fb->_Xmin, 2); /* width */ glamoDRMAddData(gCtx, fb->_Ymax-fb->_Ymin, 2); /* height */ glamoDRMAddData(gCtx, 0x0000, 2); /* patt L */ glamoDRMAddData(gCtx, 0x0000, 2); /* patt H */ glamoDRMAddData(gCtx, gCtx->col_clear, 2); /* FG colour */ glamoDRMDispatch(gCtx); glamoDRMStartBurst(gCtx, GLAMO_REG_2D_COMMAND1); glamoDRMAddData(gCtx, 0x0000, 2); /* Cmd param 1 */ glamoDRMAddData(gCtx, 0xf0 << 8, 2); /* Cmd param 2 */ glamoDRMAddData(gCtx, 0x0000, 2); /* Cmd param 3 */ glamoDRMDispatch(gCtx); } } static void glamoClearColor(GLcontext *ctx, const GLfloat color[4]) { struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); GLubyte col_byte[4]; printf("glamoClearColor (%f %f %f %f)\n", color[0], color[1], color[2], color[3]); fflush(stdout); CLAMPED_FLOAT_TO_UBYTE(col_byte[0], color[0]); CLAMPED_FLOAT_TO_UBYTE(col_byte[1], color[1]); CLAMPED_FLOAT_TO_UBYTE(col_byte[2], color[2]); CLAMPED_FLOAT_TO_UBYTE(col_byte[3], color[3]); gCtx->col_clear = GLAMO_PACKCOLOR565(col_byte[0], col_byte[1], col_byte[2]); } static void glamoShadeModel(GLcontext *ctx, GLenum mode) { printf("glamoShadeModel\n"); fflush(stdout); } static void glamoViewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height ) { struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); __DRIcontext *driContext = gCtx->driContext; void (*old_viewport)(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h); if ( !driContext->driScreenPriv->dri2.enabled ) return; /* TODO: Flush before fiddling with fake front buffer */ if ( ctx->DrawBuffer->Name == 0 ) { glamo_update_renderbuffers(driContext, driContext->driDrawablePriv); if ( driContext->driDrawablePriv != driContext->driReadablePriv ) { glamo_update_renderbuffers(driContext, driContext->driReadablePriv); } } old_viewport = ctx->Driver.Viewport; ctx->Driver.Viewport = NULL; gCtx->driDrawable = driContext->driDrawablePriv; ctx->Driver.Viewport = old_viewport; } static void glamoUploadMatrix(struct glamo_context *gCtx, uint16_t mreg, GLfloat *matrix) { int i; char *type; switch ( mreg ) { case G3D_MATRIX_MVP : type = "MVP"; break; case G3D_MATRIX_MV : type = "MV"; break; case G3D_MATRIX_IMVP : type = "inverse MVP"; break; default : type = "unknown"; break; } printf("Uploading %s matrix...\n", type); glamoDRMStartBurst(gCtx, mreg); if ( mreg != G3D_MATRIX_IMVP ) { for ( i=0; i<16; i++ ) { glamoDRMAddData(gCtx, float7s16(matrix[i]), 4); } } else { /* Normal matrix needs special treatment */ for ( i=0; i<3; i++ ) { glamoDRMAddData(gCtx, float7s16(matrix[4*i]), 4); glamoDRMAddData(gCtx, float7s16(matrix[4*i+1]), 4); glamoDRMAddData(gCtx, float7s16(matrix[4*i+2]), 4); } } glamoDRMDispatch(gCtx); } GLboolean glamoValidateState(GLcontext *ctx, GLuint new_state) { struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); if ( new_state & (_NEW_MODELVIEW|_NEW_PROJECTION) ) { glamoUploadMatrix(gCtx, G3D_MATRIX_MVP, ctx->_ModelProjectMatrix.m); /* FIXME: The following two aren't needed unless lighting * is in use... */ glamoUploadMatrix(gCtx, G3D_MATRIX_MV, ctx->ModelviewMatrixStack.Top->m); _math_matrix_alloc_inv(&(ctx->_ModelProjectMatrix)); _math_matrix_analyse(&(ctx->_ModelProjectMatrix)); glamoUploadMatrix(gCtx, G3D_MATRIX_IMVP, ctx->_ModelProjectMatrix.inv); } gCtx->new_state = 0; return GL_TRUE; } static void glamoUpdateState(GLcontext *ctx, GLbitfield new_state) { struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); printf("glamoUpdateState\n"); _swrast_InvalidateState(ctx, new_state); _swsetup_InvalidateState(ctx, new_state); _vbo_InvalidateState(ctx, new_state); _tnl_InvalidateState(ctx, new_state); _ae_invalidate_state(ctx, new_state); /* Make a note that some state has changed, * so that it can be sent to the GPU later. */ gCtx->new_state |= new_state; } static void glamoFlush(GLcontext *ctx) { printf("glamoFlush\n"); } void glamoInitStateFuncs(GLcontext *ctx) { ctx->Driver.UpdateState = glamoUpdateState; ctx->Driver.Clear = glamoClear; ctx->Driver.ClearColor = glamoClearColor; ctx->Driver.ClearDepth = NULL; ctx->Driver.ClearStencil = NULL; ctx->Driver.AlphaFunc = NULL; ctx->Driver.BlendFuncSeparate = NULL; ctx->Driver.ColorMask = NULL; ctx->Driver.CullFace = NULL; ctx->Driver.DepthMask = NULL; ctx->Driver.DepthFunc = NULL; ctx->Driver.DepthRange = NULL; ctx->Driver.DrawBuffer = NULL; ctx->Driver.Enable = NULL; ctx->Driver.FrontFace = NULL; ctx->Driver.Fogfv = NULL; ctx->Driver.Hint = NULL; ctx->Driver.Lightfv = NULL; ctx->Driver.LogicOpcode = NULL; ctx->Driver.PolygonMode = NULL; ctx->Driver.PolygonStipple = NULL; ctx->Driver.ReadBuffer = NULL; ctx->Driver.RenderMode = NULL; ctx->Driver.Scissor = NULL; ctx->Driver.ShadeModel = glamoShadeModel; ctx->Driver.LightModelfv = NULL; ctx->Driver.Viewport = glamoViewport; ctx->Driver.ResizeBuffers = glamoResizeBuffers; ctx->Driver.Flush = glamoFlush; }