get rid of more pageflip/rotation code.
[mesa.git] / src / mesa / drivers / dri / i915tex / intel_context.c
index 7eb209cf5f435447a436a442fb7832aeec64dcbf..527b33f4af71935f802e8c1a51ec3776d9a61948 100644 (file)
@@ -33,6 +33,7 @@
 #include "extensions.h"
 #include "framebuffer.h"
 #include "imports.h"
+#include "points.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -129,6 +130,18 @@ intelGetString(GLcontext * ctx, GLenum name)
       case PCI_CHIP_I945_GM:
          chipset = "Intel(R) 945GM";
          break;
+      case PCI_CHIP_I945_GME:
+         chipset = "Intel(R) 945GME";
+         break;
+      case PCI_CHIP_G33_G:
+        chipset = "Intel(R) G33";
+        break;
+      case PCI_CHIP_Q35_G:
+        chipset = "Intel(R) Q35";
+        break;
+      case PCI_CHIP_Q33_G:
+        chipset = "Intel(R) Q33";
+        break;
       default:
          chipset = "Unknown Intel Chipset";
          break;
@@ -179,6 +192,7 @@ const struct dri_extension card_extensions[] = {
 #if 1                           /* XXX FBO temporary? */
    {"GL_EXT_packed_depth_stencil", NULL},
 #endif
+   {"GL_EXT_pixel_buffer_object", NULL},
    {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
    {"GL_EXT_stencil_wrap", NULL},
    {"GL_EXT_texture_edge_clamp", NULL},
@@ -208,7 +222,6 @@ static const struct tnl_pipeline_stage *intel_pipeline[] = {
    &_tnl_texgen_stage,
    &_tnl_texture_transform_stage,
    &_tnl_point_attenuation_stage,
-   &_tnl_arb_vertex_program_stage,
    &_tnl_vertex_program_stage,
 #if 1
    &_intel_render_stage,        /* ADD: unclipped rastersetup-to-dma */
@@ -270,18 +283,30 @@ intelFlush(GLcontext * ctx)
  * Check if we need to rotate/warp the front color buffer to the
  * rotated screen.  We generally need to do this when we get a glFlush
  * or glFinish after drawing to the front color buffer.
+ * If no rotation, just copy the private fake front buffer to the real one.
  */
 static void
-intelCheckFrontRotate(GLcontext * ctx)
+intelCheckFrontUpdate(GLcontext * ctx)
 {
    struct intel_context *intel = intel_context(ctx);
+   /* rely on _ColorDrawBufferMask being kept up to date by mesa
+      even for window-fbos. */
+   /* not sure. Might need that for all masks including
+      BUFFER_BIT_FRONT_LEFT maybe? */
    if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] ==
        BUFFER_BIT_FRONT_LEFT) {
+      __DRIdrawablePrivate *dPriv = intel->driDrawable;
+#if 0
       intelScreenPrivate *screen = intel->intelScreen;
       if (screen->current_rotation != 0) {
-         __DRIdrawablePrivate *dPriv = intel->driDrawable;
          intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
       }
+      else {
+         intelCopyBuffer(dPriv, NULL);
+      }
+#else
+      intelCopyBuffer(dPriv, NULL);
+#endif
    }
 }
 
@@ -293,7 +318,7 @@ static void
 intelglFlush(GLcontext * ctx)
 {
    intelFlush(ctx);
-   intelCheckFrontRotate(ctx);
+   intelCheckFrontUpdate(ctx);
 }
 
 void
@@ -307,7 +332,7 @@ intelFinish(GLcontext * ctx)
       driFenceUnReference(intel->batch->last_fence);
       intel->batch->last_fence = NULL;
    }
-   intelCheckFrontRotate(ctx);
+   intelCheckFrontUpdate(ctx);
 }
 
 
@@ -346,6 +371,14 @@ intelInitContext(struct intel_context *intel,
    drmI830Sarea *saPriv = (drmI830Sarea *)
       (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
    int fthrottle_mode;
+   GLboolean havePools;
+
+   DRM_LIGHT_LOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
+   havePools = intelCreatePools(intelScreen);
+   DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
+
+   if (!havePools)
+      return GL_FALSE;
 
    if (!_mesa_initialize_context(&intel->ctx,
                                  mesaVis, shareCtx,
@@ -357,10 +390,6 @@ intelInitContext(struct intel_context *intel,
    intel->driScreen = sPriv;
    intel->sarea = saPriv;
 
-   intel->width = intelScreen->width;
-   intel->height = intelScreen->height;
-   intel->current_rotation = intelScreen->current_rotation;
-
    if (!lockMutexInit) {
       lockMutexInit = GL_TRUE;
       _glthread_INIT_MUTEX(lockMutex);
@@ -390,6 +419,11 @@ intelInitContext(struct intel_context *intel,
    ctx->Const.MaxPointSizeAA = 3.0;
    ctx->Const.PointSizeGranularity = 1.0;
 
+   /* reinitialize the context point state.
+    * It depend on constants in __GLcontextRec::Const
+    */
+   _mesa_init_point(ctx);
+
    ctx->Const.MaxColorAttachments = 4;  /* XXX FBO: review this */
 
    /* Initialize the software rasterizer and helper modules. */
@@ -443,10 +477,6 @@ intelInitContext(struct intel_context *intel,
 
    intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
 
-   intel->vblank_flags = (intel->intelScreen->irq_active != 0)
-      ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
-
-   (*dri_interface->getUST) (&intel->swap_ust);
    _math_matrix_ctr(&intel->ViewportMatrix);
 
    /* Disable imaging extension until convolution is working in
@@ -548,62 +578,51 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
                  __DRIdrawablePrivate * driReadPriv)
 {
 
+#if 0
+   if (driDrawPriv) {
+      fprintf(stderr, "x %d, y %d, width %d, height %d\n",
+             driDrawPriv->x, driDrawPriv->y, driDrawPriv->w, driDrawPriv->h);
+   }
+#endif
+
    if (driContextPriv) {
       struct intel_context *intel =
          (struct intel_context *) driContextPriv->driverPrivate;
-      GLframebuffer *drawFb = (GLframebuffer *) driDrawPriv->driverPrivate;
+      struct intel_framebuffer *intel_fb =
+        (struct intel_framebuffer *) driDrawPriv->driverPrivate;
       GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
 
+      /* this is a hack so we have a valid context when the region allocation
+         is done. Need a per-screen context? */
+      intel->intelScreen->dummyctxptr = intel;
 
-      /* XXX FBO temporary fix-ups! */
-      /* if the renderbuffers don't have regions, init them from the context */
-      {
-         struct intel_renderbuffer *irbFront
-            = intel_get_renderbuffer(drawFb, BUFFER_FRONT_LEFT);
-         struct intel_renderbuffer *irbBack
-            = intel_get_renderbuffer(drawFb, BUFFER_BACK_LEFT);
-         struct intel_renderbuffer *irbDepth
-            = intel_get_renderbuffer(drawFb, BUFFER_DEPTH);
-         struct intel_renderbuffer *irbStencil
-            = intel_get_renderbuffer(drawFb, BUFFER_STENCIL);
-
-         if (irbFront && !irbFront->region) {
-            intel_region_reference(&irbFront->region, intel->intelScreen->front_region);
-         }
-         if (irbBack && !irbBack->region) {
-            intel_region_reference(&irbBack->region, intel->intelScreen->back_region);
-         }
-         if (irbDepth && !irbDepth->region) {
-            intel_region_reference(&irbDepth->region, intel->intelScreen->depth_region);
-         }
-         if (irbStencil && !irbStencil->region) {
-            intel_region_reference(&irbStencil->region, intel->intelScreen->depth_region);
-         }
-      }
+      /* update GLframebuffer size to match window if needed */
+      driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
 
-      /* set initial GLframebuffer size to match window, if needed */
-      if (drawFb->Width == 0 && driDrawPriv->w) {
-         _mesa_resize_framebuffer(&intel->ctx, drawFb,
-                                  driDrawPriv->w, driDrawPriv->h);
-      }         
-      if (readFb->Width == 0 && driReadPriv->w) {
-         _mesa_resize_framebuffer(&intel->ctx, readFb,
-                                  driReadPriv->w, driReadPriv->h);
-      }         
+      if (driReadPriv != driDrawPriv) {
+         driUpdateFramebufferSize(&intel->ctx, driReadPriv);
+      }
 
-      _mesa_make_current(&intel->ctx, drawFb, readFb);
+      _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
 
       /* The drawbuffer won't always be updated by _mesa_make_current: 
        */
-      if (intel->ctx.DrawBuffer == drawFb) {
+      if (intel->ctx.DrawBuffer == &intel_fb->Base) {
 
         if (intel->driDrawable != driDrawPriv) {
-           driDrawableInitVBlank(driDrawPriv, intel->vblank_flags, &intel->vbl_seq);       
+           intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
+              ? driGetDefaultVBlankFlags(&intel->optionCache)
+              : VBLANK_FLAG_NO_IRQ;
+           (*dri_interface->getUST) (&intel_fb->swap_ust);
+           driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags,
+                                 &intel_fb->vbl_seq);
            intel->driDrawable = driDrawPriv;
            intelWindowMoved(intel);
+           intel->lastStamp = driDrawPriv->lastStamp;
+        }
+        else if (intel->lastStamp != driDrawPriv->lastStamp) {
+           intel_draw_buffer(&intel->ctx, &intel_fb->Base);
         }
-
-        intel_draw_buffer(&intel->ctx, drawFb);
       }
    }
    else {
@@ -635,12 +654,12 @@ intelContendedLock(struct intel_context *intel, GLuint flags)
       DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
 
    if (sarea->width != intelScreen->width ||
-       sarea->height != intelScreen->height ||
-       sarea->rotation != intelScreen->current_rotation) {
+       sarea->height != intelScreen->height) {
 
       intelUpdateScreenRotation(sPriv, sarea);
    }
 
+#if 0
    if (sarea->width != intel->width ||
        sarea->height != intel->height ||
        sarea->rotation != intel->current_rotation) {
@@ -683,46 +702,44 @@ intelContendedLock(struct intel_context *intel, GLuint flags)
       intel->height = sarea->height;
       intel->current_rotation = sarea->rotation;
    }
-
-   /* Drawable changed?
-    */
-   if (dPriv && intel->lastStamp != dPriv->lastStamp) {
-      intelWindowMoved(intel);
-      intel->lastStamp = dPriv->lastStamp;
-   }
-
-   /* Update page flipping info
-    */
-   if (INTEL_DEBUG & DEBUG_LOCK)
-      if (intel->doPageFlip != intel->sarea->pf_active)
-        _mesa_printf("%s - age flipping %sactive\n", __progname,
-                     intel->sarea->pf_active ? "" : "in");
-
-   intel->doPageFlip = intel->sarea->pf_active;
-   driFlipRenderbuffers(intel->ctx.WinSysDrawBuffer,
-                       intel->sarea->pf_current_page);
-   intel_draw_buffer(&intel->ctx, intel->ctx.DrawBuffer);
+#endif
 }
 
 
+
 /* Lock the hardware and validate our state.  
  */
 void LOCK_HARDWARE( struct intel_context *intel )
 {
     char __ret=0;
-
+    struct intel_framebuffer *intel_fb = NULL;
+    struct intel_renderbuffer *intel_rb = NULL;
     _glthread_LOCK_MUTEX(lockMutex);
     assert(!intel->locked);
 
-    if (intel->swap_scheduled) {
+    if (intel->driDrawable) {
+       intel_fb = intel->driDrawable->driverPrivate;
+
+       if (intel_fb)
+         intel_rb =
+            intel_get_renderbuffer(&intel_fb->Base,
+                                   intel_fb->Base._ColorDrawBufferMask[0] ==
+                                   BUFFER_BIT_FRONT_LEFT ? BUFFER_FRONT_LEFT :
+                                   BUFFER_BACK_LEFT);
+    }
+
+    if (intel_rb && (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
        drmVBlank vbl;
+
        vbl.request.type = DRM_VBLANK_ABSOLUTE;
-       if ( intel->vblank_flags & VBLANK_FLAG_SECONDARY ) {
+
+       if ( intel_fb->vblank_flags & VBLANK_FLAG_SECONDARY ) {
            vbl.request.type |= DRM_VBLANK_SECONDARY;
        }
-       vbl.request.sequence = intel->vbl_seq;
+
+       vbl.request.sequence = intel_rb->vbl_pending;
        drmWaitVBlank(intel->driFd, &vbl);
-       intel->swap_scheduled = 0;
+       intel_fb->vbl_waited = vbl.reply.sequence;
     }
 
     DRM_CAS(intel->driHwLock, intel->hHWContext,