Beispiel #1
0
/* Update the hardware state.  This is called if another context has
 * grabbed the hardware lock, which includes the X server.  This
 * function also updates the driver's window state after the X server
 * moves, resizes or restacks a window -- the change will be reflected
 * in the drawable position and clip rects.  Since the X server grabs
 * the hardware lock when it changes the window state, this routine will
 * automatically be called after such a change.
 */
void
sisGetLock( sisContextPtr smesa, GLuint flags )
{
   __DRIdrawablePrivate *dPriv = smesa->driDrawable;
   __DRIscreenPrivate *sPriv = smesa->driScreen;
   SISSAREAPrivPtr sarea = smesa->sarea;

   drmGetLock( smesa->driFd, smesa->hHWContext, flags );

   /* The window might have moved, so we might need to get new clip
    * rects.
    *
    * NOTE: This releases and regrabs the hw lock to allow the X server
    * to respond to the DRI protocol request for new drawable info.
    * Since the hardware state depends on having the latest drawable
    * clip rects, all state checking must be done _after_ this call.
    */
   DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );

   if ( smesa->lastStamp != dPriv->lastStamp ) {
      sisUpdateBufferSize( smesa );
      sisUpdateClipping( smesa->glCtx );
      sisDDDrawBuffer( smesa->glCtx, smesa->glCtx->Color.DrawBuffer );
      smesa->lastStamp = dPriv->lastStamp;
   }

   if ( sarea->CtxOwner != smesa->hHWContext ) {
      sarea->CtxOwner = smesa->hHWContext;
      smesa->GlobalFlag = GFLAG_ALL;
   }
}
GLboolean
sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
                __DRIdrawablePrivate *driDrawPriv,
                __DRIdrawablePrivate *driReadPriv )
{
   if ( driContextPriv ) {
      GET_CURRENT_CONTEXT(ctx);
      sisContextPtr oldSisCtx = ctx ? SIS_CONTEXT(ctx) : NULL;
      sisContextPtr newSisCtx = (sisContextPtr) driContextPriv->driverPrivate;

      if ( newSisCtx != oldSisCtx) {
         newSisCtx->GlobalFlag = GFLAG_ALL;
      }

      newSisCtx->driDrawable = driDrawPriv;

      _mesa_make_current2( newSisCtx->glCtx,
                         (GLframebuffer *) driDrawPriv->driverPrivate,
                         (GLframebuffer *) driReadPriv->driverPrivate );

      sisUpdateBufferSize( newSisCtx );
      sisUpdateClipping( newSisCtx->glCtx );
   } else {
      _mesa_make_current( 0, 0 );
   }

   return GL_TRUE;
}
void
sisUpdateBufferSize(sisContextPtr smesa)
{
   __GLSiSHardware *current = &smesa->current;
   __GLSiSHardware *prev = &smesa->prev;
   struct gl_framebuffer *fb = smesa->glCtx->DrawBuffer;

   if (!smesa->front.Base.InternalFormat) {
      /* do one-time init for the renderbuffers */
      sisInitRenderbuffer(&smesa->front.Base, GL_RGBA);
      sisSetSpanFunctions(&smesa->front, &fb->Visual);
      _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &smesa->front.Base);

      if (fb->Visual.doubleBufferMode) {
         sisInitRenderbuffer(&smesa->back.Base, GL_RGBA);
         sisSetSpanFunctions(&smesa->back, &fb->Visual);
         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &smesa->back.Base);
      }

      if (smesa->glCtx->Visual.depthBits > 0) {
         sisInitRenderbuffer(&smesa->depth.Base, 
                             (smesa->glCtx->Visual.depthBits == 16
                              ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT24));
         sisSetSpanFunctions(&smesa->depth, &fb->Visual);
         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &smesa->depth.Base);
      }

      if (smesa->glCtx->Visual.stencilBits > 0) {
         sisInitRenderbuffer(&smesa->stencil.Base, GL_STENCIL_INDEX8_EXT);
         sisSetSpanFunctions(&smesa->stencil, &fb->Visual);
         _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &smesa->stencil.Base);
      }
   }

   /* Make sure initialization did what we think it should */
   assert(smesa->front.Base.InternalFormat);
   assert(smesa->front.Base.AllocStorage);
   if (fb->Visual.doubleBufferMode) {
      assert(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
      assert(smesa->front.Base.AllocStorage);
   }
   if (fb->Visual.depthBits) {
      assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
      assert(smesa->depth.Base.AllocStorage);
   }

   /* XXX Should get the base offset of the frontbuffer from the X Server */
   smesa->front.offset = smesa->driDrawable->x * smesa->bytesPerPixel +
			 smesa->driDrawable->y * smesa->front.pitch;
   smesa->front.map = (char *) smesa->driScreen->pFB + smesa->front.offset;

   if ( smesa->width == smesa->driDrawable->w &&
	smesa->height == smesa->driDrawable->h )
   {
      return;
   }

   smesa->front.bpp = smesa->bytesPerPixel * 8;
   /* Front pitch set on context create */
   smesa->front.size = smesa->front.pitch * smesa->driDrawable->h;

   smesa->width = smesa->driDrawable->w;
   smesa->height = smesa->driDrawable->h;
   smesa->bottom = smesa->height - 1;

   if (smesa->back.offset)
      sisFreeBackbuffer( smesa );
   if (smesa->depth.offset)
      sisFreeZStencilBuffer( smesa );

   if ( smesa->glCtx->Visual.depthBits > 0 )
      sisAllocZStencilBuffer( smesa );
   if ( smesa->glCtx->Visual.doubleBufferMode )
      sisAllocBackbuffer( smesa );

   current->hwZ &= ~MASK_ZBufferPitch;
   current->hwZ |= smesa->depth.pitch >> 2;
   current->hwOffsetZ = smesa->depth.offset >> 2;

   if ((current->hwOffsetZ != prev->hwOffsetZ) || (current->hwZ != prev->hwZ)) {
      prev->hwOffsetZ = current->hwOffsetZ;
      prev->hwZ = current->hwZ;
      smesa->GlobalFlag |= GFLAG_ZSETTING;
   }
  
   sisUpdateClipping( smesa->glCtx );
}