don't use driDrawable information directly, don't resize at makecurrent
authorRoland Scheidegger <sroland@tungstengraphics.com>
Thu, 12 Jul 2007 19:52:02 +0000 (21:52 +0200)
committerRoland Scheidegger <sroland@tungstengraphics.com>
Thu, 12 Jul 2007 19:52:02 +0000 (21:52 +0200)
driDrawable information now isn't used in most parts of the driver.
makecurrent only updates fb information when the context is new
(driDrawable is still updated by the dri common code).

12 files changed:
src/mesa/drivers/dri/i915tex/intel_blit.c
src/mesa/drivers/dri/i915tex/intel_buffers.c
src/mesa/drivers/dri/i915tex/intel_context.c
src/mesa/drivers/dri/i915tex/intel_context.h
src/mesa/drivers/dri/i915tex/intel_fbo.c
src/mesa/drivers/dri/i915tex/intel_ioctl.c
src/mesa/drivers/dri/i915tex/intel_pixel_bitmap.c
src/mesa/drivers/dri/i915tex/intel_pixel_copy.c
src/mesa/drivers/dri/i915tex/intel_pixel_draw.c
src/mesa/drivers/dri/i915tex/intel_pixel_read.c
src/mesa/drivers/dri/i915tex/intel_span.c
src/mesa/drivers/dri/i915tex/intel_tex_copy.c

index 3e42d799808c05e7cf8edaabf90a442a2c231a50..2a0a63931522d1699ff5a4b76442f8ec84742958 100644 (file)
@@ -91,7 +91,7 @@ intelCopyBuffer(__DRIdrawablePrivate * dPriv,
       const struct intel_region *frontRegion
         = intelScreen->front_region;
       const struct intel_region *backRegion
-        = intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT ?
+        = intel_fb->Base._ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT ?
           intel_get_rb_region(&intel_fb->Base, BUFFER_FRONT_LEFT) :
           intel_get_rb_region(&intel_fb->Base, BUFFER_BACK_LEFT);
       const int backWidth = intel_fb->Base.Width;
@@ -108,7 +108,6 @@ intelCopyBuffer(__DRIdrawablePrivate * dPriv,
       ASSERT(intel_fb->Base.Name == 0);    /* Not a user-created FBO */
       ASSERT(frontRegion);
       ASSERT(backRegion);
-//      ASSERT(frontRegion->pitch == backRegion->pitch);
       ASSERT(frontRegion->cpp == backRegion->cpp);
 
       DBG("front pitch %d back pitch %d\n",
@@ -405,6 +404,7 @@ intelClearWithBlit(GLcontext * ctx, GLbitfield mask)
    LOCK_HARDWARE(intel);
 
    if (intel->numClipRects) {
+      assert(intel->numClipRects == 1);
       GLint cx, cy, cw, ch;
       drm_clip_rect_t clear;
       int i;
@@ -417,10 +417,9 @@ intelClearWithBlit(GLcontext * ctx, GLbitfield mask)
 
       if (fb->Name == 0) {
          /* clearing a window */
-
          /* flip top to bottom */
-         clear.x1 = cx + intel->drawX;
-         clear.y1 = intel->driDrawable->y + intel->driDrawable->h - cy - ch;
+         clear.x1 = cx;
+         clear.y1 = intel->pClipRects->y2 - cy - ch;
          clear.x2 = clear.x1 + cw;
          clear.y2 = clear.y1 + ch;
       }
index 20e9521105da1e64c3c7771083b0e8444819b9e5..59b291a709d531ae49821023f9bd17560276395f 100644 (file)
@@ -128,8 +128,6 @@ intel_readbuf_region(struct intel_context *intel)
  * Update the following fields for rendering to a user-created FBO:
  *   intel->numClipRects
  *   intel->pClipRects
- *   intel->drawX
- *   intel->drawY
  */
 static void
 intelSetRenderbufferClipRects(struct intel_context *intel)
@@ -142,8 +140,6 @@ intelSetRenderbufferClipRects(struct intel_context *intel)
    intel->fboRect.y2 = intel->ctx.DrawBuffer->Height;
    intel->numClipRects = 1;
    intel->pClipRects = &intel->fboRect;
-   intel->drawX = 0;
-   intel->drawY = 0;
 }
 
 /**
@@ -154,18 +150,17 @@ intelSetRenderbufferClipRects(struct intel_context *intel)
 static void
 intelSetPrivbufClipRects(struct intel_context *intel)
 {
-   __DRIdrawablePrivate *dPriv = intel->driDrawable;
-   if (!dPriv)
+   if (!intel->ctx.DrawBuffer) {
+      fprintf(stderr, "%s: DrawBuffer not set!\n", __FUNCTION__);
       return;
+   }
 
    intel->fakeClipRect.x1 = 0;
    intel->fakeClipRect.y1 = 0;
-   intel->fakeClipRect.x2 = dPriv->w;
-   intel->fakeClipRect.y2 = dPriv->h;
+   intel->fakeClipRect.x2 = intel->ctx.DrawBuffer->Width;
+   intel->fakeClipRect.y2 = intel->ctx.DrawBuffer->Height;
    intel->numClipRects = 1;
    intel->pClipRects = &intel->fakeClipRect;
-   intel->drawX = 0;
-   intel->drawY = 0;
 }
 
 
@@ -445,7 +440,6 @@ intelRotateWindow(struct intel_context *intel,
    int i;
    GLenum format, type;
 
-   int xOrig, yOrig;
    int origNumClipRects;
    drm_clip_rect_t *origRects;
 
@@ -469,8 +463,6 @@ intelRotateWindow(struct intel_context *intel,
 
 
    /* save current drawing origin and cliprects (restored at end) */
-   xOrig = intel->drawX;
-   yOrig = intel->drawY;
    origNumClipRects = intel->numClipRects;
    origRects = intel->pClipRects;
 
@@ -481,8 +473,6 @@ intelRotateWindow(struct intel_context *intel,
    fullRect.y1 = 0;
    fullRect.x2 = screen->rotatedWidth;
    fullRect.y2 = screen->rotatedHeight;
-   intel->drawX = 0;
-   intel->drawY = 0;
    intel->numClipRects = 1;
    intel->pClipRects = &fullRect;
 
@@ -565,8 +555,6 @@ intelRotateWindow(struct intel_context *intel,
    intel_batchbuffer_flush(intel->batch);
 
    /* restore original drawing origin and cliprects */
-   intel->drawX = xOrig;
-   intel->drawY = yOrig;
    intel->numClipRects = origNumClipRects;
    intel->pClipRects = origRects;
 
index 531b4adde808325ae0ffab86503633ee7c1b9582..451c7fd1ba5d88a7b4c286fe19c719fca11b0af6 100644 (file)
@@ -370,7 +370,7 @@ intelInitContext(struct intel_context *intel,
 
    if (!havePools)
       return GL_FALSE;
-     
+
    if (!_mesa_initialize_context(&intel->ctx,
                                  mesaVis, shareCtx,
                                  functions, (void *) intel))
@@ -572,6 +572,7 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
                  __DRIdrawablePrivate * driDrawPriv,
                  __DRIdrawablePrivate * driReadPriv)
 {
+   GLuint updatebufsize = GL_FALSE;
 
 #if 0
    if (driDrawPriv) {
@@ -619,19 +620,22 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
          }
       }
 
-      /* set GLframebuffer size to match window, if needed */
-      driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
+      /* only update GLframebuffer size to match window
+         if here for the first time */
+      if (intel->ctx.FirstTimeCurrent) {
+        updatebufsize = GL_TRUE;
+        driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
 
-      if (driReadPriv != driDrawPriv) {
-        driUpdateFramebufferSize(&intel->ctx, driReadPriv);
+        if (driReadPriv != driDrawPriv) {
+           driUpdateFramebufferSize(&intel->ctx, driReadPriv);
+        }
       }
 
       _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
-      intel->intelScreen->dummyctxptr = &intel->ctx;
 
       /* The drawbuffer won't always be updated by _mesa_make_current: 
        */
-      if (intel->ctx.DrawBuffer == &intel_fb->Base) {
+      if (updatebufsize && intel->ctx.DrawBuffer == &intel_fb->Base) {
 
         if (intel->driDrawable != driDrawPriv) {
            intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
index 7b97c564a3eddf12a8f4c67126cbe41036e01c33..f85b3a6362715bde79e6403a9eac37b5fac80628 100644 (file)
@@ -250,7 +250,6 @@ struct intel_context
 
    /* These refer to the current drawing buffer:
     */
-   int drawX, drawY;            /**< origin of drawing area within region */
    GLuint numClipRects;         /**< cliprects for drawing */
    drm_clip_rect_t *pClipRects;
    drm_clip_rect_t fboRect;     /**< cliprect for FBO rendering */
index 2dd3617f93a5f9586066ad603c28f5642c0ccea6..aeb909cce17f5ac364685fe97e88677d4aa9d7ac 100644 (file)
@@ -146,6 +146,8 @@ intel_delete_renderbuffer(struct gl_renderbuffer *rb)
 
    ASSERT(irb);
 
+   DBG("freeing renderbuffer\n");
+
    if (irb->PairedStencil || irb->PairedDepth) {
       intel_unpair_depth_stencil(ctx, irb);
    }
index 3250c6b3a9c931fa9695b3531869cf380a51f8bb..54721c78ab1f1f717c3b1bdd6b833625bf8fb6ec 100644 (file)
@@ -116,8 +116,7 @@ intel_batch_ioctl(struct intel_context *intel,
    batch.cliprects = intel->pClipRects;
    batch.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects;
    batch.DR1 = 0;
-   batch.DR4 = ((((GLuint) intel->drawX) & 0xffff) |
-                (((GLuint) intel->drawY) << 16));
+   batch.DR4 = 0; /* still need this ? */
 
    DBG("%s: 0x%x..0x%x DR4: %x cliprects: %d\n",
        __FUNCTION__,
index 65bf338589e9c7d7e55a10a49cb275d9081a30e2..96d3cbef5f2f317dd58c72ca505ab69a4aa0a62e 100644 (file)
@@ -195,18 +195,18 @@ do_blit_bitmap( GLcontext *ctx,
 
    LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
-      drm_clip_rect_t *box = dPriv->pClipRects;
+   if (intel->numClipRects) {
+      assert(intel->numClipRects == 1);
+      drm_clip_rect_t *box = intel->pClipRects;
       drm_clip_rect_t dest_rect;
-      GLint nbox = dPriv->numClipRects;
+      GLint nbox = intel->numClipRects;
       GLint srcx = 0, srcy = 0;
       GLint orig_screen_x1, orig_screen_y2;
       GLuint i;
 
 
-      orig_screen_x1 = dPriv->x + dstx;
-      orig_screen_y2 = dPriv->y + (dPriv->h - dsty);
+      orig_screen_x1 = dstx;
+      orig_screen_y2 = box->y2 - dsty;
 
       /* Do scissoring in GL coordinates:
        */
@@ -223,8 +223,8 @@ x      if (ctx->Scissor.Enabled)
 
       /* Convert from GL to hardware coordinates:
        */
-      dsty = dPriv->y + (dPriv->h - dsty - height);  
-      dstx = dPriv->x + dstx;
+      dsty = box->y2 - dsty - height;
+      dstx = dstx;
 
       dest_rect.x1 = dstx;
       dest_rect.y1 = dsty;
@@ -235,7 +235,7 @@ x      if (ctx->Scissor.Enabled)
          drm_clip_rect_t rect;
         int box_w, box_h;
         GLint px, py;
-        GLuint stipple[32];  
+        GLuint stipple[32];
 
          if (!intel_intersect_cliprects(&rect, &dest_rect, &box[i]))
             continue;
index 9d478283e47bd4c60771ce3fd399cb2e8aa9e0fc..03c7353ee15d9e5fe402180687cd0b020cadcc41 100644 (file)
@@ -191,14 +191,10 @@ do_texture_copypixels(GLcontext * ctx,
 
    LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
-
-
-      srcy = dPriv->h - srcy - height;  /* convert from gl to hardware coords */
-
-      srcx += dPriv->x;
-      srcy += dPriv->y;
+   if (intel->numClipRects) {
+      int bufHeight = intel->pClipRects->y2;
+      assert (intel->numClipRects == 1);
+      srcy = bufHeight - srcy - height;  /* convert from gl to hardware coords */
 
       /* Clip against the source region.  This is the only source
        * clipping we do.  XXX: Just set the texcord wrap mode to clamp
@@ -223,8 +219,8 @@ do_texture_copypixels(GLcontext * ctx,
       intel_meta_draw_quad(intel, 
                           dstx, 
                           dstx + width * ctx->Pixel.ZoomX, 
-                          dPriv->h - (dsty + height * ctx->Pixel.ZoomY), 
-                          dPriv->h - (dsty), 0,   /* XXX: what z value? */
+                          bufHeight - (dsty + height * ctx->Pixel.ZoomY), 
+                          bufHeight - (dsty), 0,   /* XXX: what z value? */
                            0x00ff00ff,
                            srcx, srcx + width, srcy, srcy + height);
 
@@ -271,11 +267,11 @@ do_blit_copypixels(GLcontext * ctx,
 
    LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
-      drm_clip_rect_t *box = dPriv->pClipRects;
+   if (intel->numClipRects) {
+      assert(intel->numClipRects == 1);
+      drm_clip_rect_t *box = intel->pClipRects;
       drm_clip_rect_t dest_rect;
-      GLint nbox = dPriv->numClipRects;
+      GLint nbox = intel->numClipRects;
       GLint delta_x = 0;
       GLint delta_y = 0;
       GLuint i;
@@ -299,13 +295,10 @@ do_blit_copypixels(GLcontext * ctx,
       }
 
       /* Convert from GL to hardware coordinates:
+       * cliprect should be size of buffer
        */
-      dsty = dPriv->h - dsty - height;  
-      srcy = dPriv->h - srcy - height;  
-      dstx += dPriv->x;
-      dsty += dPriv->y;
-      srcx += dPriv->x;
-      srcy += dPriv->y;
+      dsty = box->y2 - dsty - height;
+      srcy = box->y2 - srcy - height;
 
       /* Clip against the source region.  This is the only source
        * clipping we do.  Dst is clipped with cliprects below.
index 77c67c821eb07118df3fac7e85ba6bdf0af669c1..2d46c4b8c0e48b1bd5d055c9187646187f650ef3 100644 (file)
@@ -138,13 +138,15 @@ do_texture_drawpixels(GLcontext * ctx,
 
    LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
+   if (intel->numClipRects) {
+      assert(intel->numClipRects == 1);
+      int bufHeight = intel->pClipRects->y2;
+
       GLint srcx, srcy;
       GLint dstx, dsty;
 
       dstx = x;
-      dsty = dPriv->h - (y + height);
+      dsty = bufHeight - (y + height);
 
       srcx = 0;                 /* skiprows/pixels already done */
       srcy = 0;
@@ -172,8 +174,8 @@ do_texture_drawpixels(GLcontext * ctx,
        */
       intel_meta_draw_quad(intel,
                            dstx, dstx + width * ctx->Pixel.ZoomX,
-                           dPriv->h - (y + height * ctx->Pixel.ZoomY),
-                           dPriv->h - (y),
+                           bufHeight - (y + height * ctx->Pixel.ZoomY),
+                           bufHeight - (y),
                            -ctx->Current.RasterPos[2] * .5,
                            0x00ff00ff,
                            srcx, srcx + width, srcy + height, srcy);
@@ -289,21 +291,21 @@ do_blit_drawpixels(GLcontext * ctx,
    src_offset = (GLuint) _mesa_image_address(2, unpack, pixels, width, height,
                                              format, type, 0, 0, 0);
 
+   /* don't need a lock as cliprects shouldn't change */
    intelFlush(&intel->ctx);
-   LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
-      int nbox = dPriv->numClipRects;
-      drm_clip_rect_t *box = dPriv->pClipRects;
+   if (intel->numClipRects) {
+      assert(intel->numClipRects == 1);
+      int nbox = intel->numClipRects;
+      drm_clip_rect_t *box = intel->pClipRects;
       drm_clip_rect_t rect;
       drm_clip_rect_t dest_rect;
       struct _DriBufferObject *src_buffer =
          intel_bufferobj_buffer(intel, src, INTEL_READ);
       int i;
 
-      dest_rect.x1 = dPriv->x + x;
-      dest_rect.y1 = dPriv->y + dPriv->h - (y + height);
+      dest_rect.x1 = x;
+      dest_rect.y1 = box->y2 - (y + height);
       dest_rect.x2 = dest_rect.x1 + width;
       dest_rect.y2 = dest_rect.y1 + height;
 
@@ -327,7 +329,6 @@ do_blit_drawpixels(GLcontext * ctx,
       fence = intel_batchbuffer_flush(intel->batch);
       driFenceReference(fence);
    }
-   UNLOCK_HARDWARE(intel);
 
    if (fence) {
       driFenceFinish(fence, DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW, GL_FALSE);
index 24e49ae0663677d65759816e1352540d0d2ba1b7..9481cb4800f532acd4691c8820d06e2f65c6fec9 100644 (file)
@@ -77,7 +77,6 @@ do_texture_readpixels(GLcontext * ctx,
    struct intel_context *intel = intel_context(ctx);
    intelScreenPrivate *screen = intel->intelScreen;
    GLint pitch = pack->RowLength ? pack->RowLength : width;
-   __DRIdrawablePrivate *dPriv = intel->driDrawable;
    int textureFormat;
    GLenum glTextureFormat;
    int destFormat, depthFormat, destPitch;
@@ -107,7 +106,7 @@ do_texture_readpixels(GLcontext * ctx,
 
    LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
+   if (intel->numClipRects) {
       intel->vtbl.install_meta_state(intel);
       intel->vtbl.meta_no_depth_write(intel);
       intel->vtbl.meta_no_stencil_write(intel);
@@ -120,9 +119,7 @@ do_texture_readpixels(GLcontext * ctx,
          return GL_TRUE;
       }
 
-      y = dPriv->h - y - height;
-      x += dPriv->x;
-      y += dPriv->y;
+      y = intel->pClipRects->y2 - y - height;
 
 
       /* Set the frontbuffer up as a large rectangular texture.
@@ -230,29 +227,25 @@ do_blit_readpixels(GLcontext * ctx,
    dst_offset = (GLuint) _mesa_image_address(2, pack, pixels, width, height,
                                              format, type, 0, 0, 0);
 
-
-   /* Although the blits go on the command buffer, need to do this and
-    * fire with lock held to guarentee cliprects are correct.
-    */
+   /* reading from priv buffer, cliprects should not change */
    intelFlush(&intel->ctx);
-   LOCK_HARDWARE(intel);
 
-   if (intel->driDrawable->numClipRects) {
+   if (intel->numClipRects) {
+      assert (intel->numClipRects == 1);
       GLboolean all = (width * height * src->cpp == dst->Base.Size &&
                        x == 0 && dst_offset == 0);
 
       struct _DriBufferObject *dst_buffer =
          intel_bufferobj_buffer(intel, dst, all ? INTEL_WRITE_FULL :
                                 INTEL_WRITE_PART);
-      __DRIdrawablePrivate *dPriv = intel->driDrawable;
-      int nbox = dPriv->numClipRects;
-      drm_clip_rect_t *box = dPriv->pClipRects;
+      int nbox = intel->numClipRects;
+      drm_clip_rect_t *box = intel->pClipRects;
       drm_clip_rect_t rect;
       drm_clip_rect_t src_rect;
       int i;
 
-      src_rect.x1 = dPriv->x + x;
-      src_rect.y1 = dPriv->y + dPriv->h - (y + height);
+      src_rect.x1 = x;
+      src_rect.y1 = box->y2 - (y + height);
       src_rect.x2 = src_rect.x1 + width;
       src_rect.y2 = src_rect.y1 + height;
 
@@ -279,7 +272,6 @@ do_blit_readpixels(GLcontext * ctx,
       driFenceReference(fence);
 
    }
-   UNLOCK_HARDWARE(intel);
 
    if (fence) {
       driFenceFinish(fence, DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW, 
index ab0874e4fd6569f271e0ff43fca7e3b9595ed08f..368e0ec3c09fa1d1b922a9e9a2f64debccb14610 100644 (file)
@@ -51,8 +51,7 @@
    struct intel_renderbuffer *irb = intel_renderbuffer(rb);            \
    const GLint yScale = irb->RenderToTexture ? 1 : -1;                 \
    const GLint yBias = irb->RenderToTexture ? 0 : irb->Base.Height - 1;        \
-   GLubyte *buf = (GLubyte *) irb->pfMap                               \
-      + (intel->drawY * irb->pfPitch + intel->drawX) * irb->region->cpp;\
+   GLubyte *buf = (GLubyte *) irb->pfMap;                              \
    GLuint p;                                                           \
    assert(irb->pfMap);\
    (void) p;
    do {                                                                        \
       int _nc = intel->numClipRects;                                   \
       while ( _nc-- ) {                                                        \
-        int minx = intel->pClipRects[_nc].x1 - intel->drawX;           \
-        int miny = intel->pClipRects[_nc].y1 - intel->drawY;           \
-        int maxx = intel->pClipRects[_nc].x2 - intel->drawX;           \
-        int maxy = intel->pClipRects[_nc].y2 - intel->drawY;
+        int minx = intel->pClipRects[_nc].x1;          \
+        int miny = intel->pClipRects[_nc].y1;          \
+        int maxx = intel->pClipRects[_nc].x2;          \
+        int maxy = intel->pClipRects[_nc].y2;
 
 
 
    const GLuint pitch = irb->pfPitch/***XXX region->pitch*/; /* in pixels */ \
    const GLint yScale = irb->RenderToTexture ? 1 : -1;                 \
    const GLint yBias = irb->RenderToTexture ? 0 : irb->Base.Height - 1;        \
-   char *buf = (char *) irb->pfMap/*XXX use region->map*/ +             \
-      (intel->drawY * pitch + intel->drawX) * irb->region->cpp;
-
+   char *buf = (char *) irb->pfMap/*XXX use region->map*/ ;
 
 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
 
index b85a25642a29fea269f4569c6e48ce581ac1ec75..90c2b9ebb511c78061e3558dcce117b53184952b 100644 (file)
@@ -101,6 +101,7 @@ do_copy_texsubimage(struct intel_context *intel,
    }
 
    intelFlush(ctx);
+   /* XXX still need the lock ? */
    LOCK_HARDWARE(intel);
    {
       GLuint image_offset = intel_miptree_image_offset(intelImage->mt,
@@ -117,20 +118,8 @@ do_copy_texsubimage(struct intel_context *intel,
          dstx += x - orig_x;
          dsty += y - orig_y;
 
-         if (ctx->ReadBuffer->Name == 0) {
-            /* reading from a window, adjust x, y */
-            __DRIdrawablePrivate *dPriv = intel->driDrawable;
-            GLuint window_y;
-            /* window_y = position of window on screen if y=0=bottom */
-            window_y = intel->intelScreen->height - (dPriv->y + dPriv->h);
-            y = window_y + y;
-            x += dPriv->x;
-         }
-         else {
-            /* reading from a FBO */
-            /* invert Y */
-            y = ctx->ReadBuffer->Height - y - 1;
-         }
+         /* invert Y */
+         y = ctx->ReadBuffer->Height - y - 1;
 
 
          /* A bit of fiddling to get the blitter to work with -ve