intel: Make a wrapper for intelEmitCopyBlit using miptrees.
[mesa.git] / src / mesa / drivers / dri / intel / intel_pixel_bitmap.c
index 63fb4b37b188c987554a9dcd153a23a9ad2ec9c0..c538a29571aa4b47b0dc5cf5bb7cfd9eacfad549 100644 (file)
 #include "main/enums.h"
 #include "main/image.h"
 #include "main/colormac.h"
+#include "main/condrender.h"
 #include "main/mtypes.h"
 #include "main/macros.h"
+#include "main/pbo.h"
 #include "main/bufferobj.h"
 #include "main/state.h"
 #include "main/texobj.h"
 #include "main/context.h"
+#include "main/fbobject.h"
 #include "swrast/swrast.h"
 #include "drivers/common/meta.h"
 
@@ -67,14 +70,14 @@ static const GLubyte *map_pbo( struct gl_context *ctx,
 
    if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
                                  GL_COLOR_INDEX, GL_BITMAP,
-                                 (GLvoid *) bitmap)) {
+                                 INT_MAX, (const GLvoid *) bitmap)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)");
       return NULL;
    }
 
-   buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                                          GL_READ_ONLY_ARB,
-                                          unpack->BufferObj);
+   buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size,
+                                               GL_MAP_READ_BIT,
+                                               unpack->BufferObj);
    if (!buf) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
       return NULL;
@@ -83,7 +86,7 @@ static const GLubyte *map_pbo( struct gl_context *ctx,
    return ADD_POINTERS(buf, bitmap);
 }
 
-static GLboolean test_bit( const GLubyte *src, GLuint bit )
+static bool test_bit( const GLubyte *src, GLuint bit )
 {
    return (src[bit/8] & (1<<(bit % 8))) ? 1 : 0;
 }
@@ -103,7 +106,7 @@ static GLuint get_bitmap_rect(GLsizei width, GLsizei height,
                              GLuint w, GLuint h,
                              GLubyte *dest,
                              GLuint row_align,
-                             GLboolean invert)
+                             bool invert)
 {
    GLuint src_offset = (x + unpack->SkipPixels) & 0x7;
    GLuint mask = unpack->LsbFirst ? 0 : 7;
@@ -113,9 +116,8 @@ static GLuint get_bitmap_rect(GLsizei width, GLsizei height,
    GLint incr;
    GLuint count = 0;
 
-   if (INTEL_DEBUG & DEBUG_PIXEL)
-      printf("%s %d,%d %dx%d bitmap %dx%d skip %d src_offset %d mask %d\n",
-                  __FUNCTION__, x,y,w,h,width,height,unpack->SkipPixels, src_offset, mask);
+   DBG("%s %d,%d %dx%d bitmap %dx%d skip %d src_offset %d mask %d\n",
+       __FUNCTION__, x,y,w,h,width,height,unpack->SkipPixels, src_offset, mask);
 
    if (invert) {
       first = h-1;
@@ -157,7 +159,7 @@ static GLuint get_bitmap_rect(GLsizei width, GLsizei height,
 static INLINE int
 y_flip(struct gl_framebuffer *fb, int y, int height)
 {
-   if (fb->Name != 0)
+   if (_mesa_is_user_fbo(fb))
       return y;
    else
       return fb->Height - y - height;
@@ -166,7 +168,7 @@ y_flip(struct gl_framebuffer *fb, int y, int height)
 /*
  * Render a bitmap.
  */
-static GLboolean
+static bool
 do_blit_bitmap( struct gl_context *ctx, 
                GLint dstx, GLint dsty,
                GLsizei width, GLsizei height,
@@ -174,7 +176,7 @@ do_blit_bitmap( struct gl_context *ctx,
                const GLubyte *bitmap )
 {
    struct intel_context *intel = intel_context(ctx);
-   struct intel_region *dst = intel_drawbuf_region(intel);
+   struct intel_region *dst;
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    GLfloat tmpColor[4];
    GLubyte ubcolor[4];
@@ -194,21 +196,24 @@ do_blit_bitmap( struct gl_context *ctx,
        * It seems the blit Z coord is always 1.0 (the far plane) so fragments
        * will likely be obscured by other, closer geometry.
        */
-      return GL_FALSE;
+      return false;
    }
 
+   intel_prepare_render(intel);
+   dst = intel_drawbuf_region(intel);
+
    if (!dst)
-       return GL_FALSE;
+       return false;
 
    if (_mesa_is_bufferobj(unpack->BufferObj)) {
       bitmap = map_pbo(ctx, width, height, unpack, bitmap);
       if (bitmap == NULL)
-        return GL_TRUE;        /* even though this is an error, we're done */
+        return true;   /* even though this is an error, we're done */
    }
 
    COPY_4V(tmpColor, ctx->Current.RasterColor);
 
-   if (NEED_SECONDARY_COLOR(ctx)) {
+   if (_mesa_need_secondary_color(ctx)) {
        ADD_3V(tmpColor, tmpColor, ctx->Current.RasterSecondaryColor);
    }
 
@@ -223,9 +228,7 @@ do_blit_bitmap( struct gl_context *ctx,
       color = PACK_COLOR_8888(ubcolor[3], ubcolor[0], ubcolor[1], ubcolor[2]);
 
    if (!intel_check_blit_fragment_ops(ctx, tmpColor[3] == 1.0F))
-      return GL_FALSE;
-
-   intel_prepare_render(intel);
+      return false;
 
    /* Clip to buffer bounds and scissor. */
    if (!_mesa_clip_to_region(fb->_Xmin, fb->_Ymin,
@@ -256,14 +259,15 @@ do_blit_bitmap( struct gl_context *ctx,
          * Have to translate destination coordinates back into source
          * coordinates.
          */
-        if (get_bitmap_rect(bitmap_width, bitmap_height, unpack,
-                            bitmap,
-                            -orig_dstx + (dstx + px),
-                            -orig_dsty + y_flip(fb, dsty + py, h),
-                            w, h,
-                            (GLubyte *)stipple,
-                            8,
-                            fb->Name == 0 ? GL_TRUE : GL_FALSE) == 0)
+         int count = get_bitmap_rect(bitmap_width, bitmap_height, unpack,
+                                     bitmap,
+                                     -orig_dstx + (dstx + px),
+                                     -orig_dsty + y_flip(fb, dsty + py, h),
+                                     w, h,
+                                     (GLubyte *)stipple,
+                                     8,
+                                     _mesa_is_winsys_fbo(fb));
+         if (count == 0)
            continue;
 
         if (!intelEmitImmediateColorExpandBlit(intel,
@@ -272,33 +276,36 @@ do_blit_bitmap( struct gl_context *ctx,
                                                sz,
                                                color,
                                                dst->pitch,
-                                               dst->buffer,
+                                               dst->bo,
                                                0,
                                                dst->tiling,
                                                dstx + px,
                                                dsty + py,
                                                w, h,
                                                logic_op)) {
-           return GL_FALSE;
+           return false;
         }
+
+         if (ctx->Query.CurrentOcclusionObject)
+            ctx->Query.CurrentOcclusionObject->Result += count;
       }
    }
 out:
 
-   if (INTEL_DEBUG & DEBUG_SYNC)
-      intel_batchbuffer_flush(intel->batch);
+   if (unlikely(INTEL_DEBUG & DEBUG_SYNC))
+      intel_batchbuffer_flush(intel);
 
    if (_mesa_is_bufferobj(unpack->BufferObj)) {
       /* done with PBO so unmap it now */
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
-                              unpack->BufferObj);
+      ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj);
    }
 
    intel_check_front_buffer_rendering(intel);
 
-   return GL_TRUE;
+   return true;
 }
 
+
 /* There are a large number of possible ways to implement bitmap on
  * this hardware, most of them have some sort of drawback.  Here are a
  * few that spring to mind:
@@ -326,15 +333,12 @@ intelBitmap(struct gl_context * ctx,
            const struct gl_pixelstore_attrib *unpack,
            const GLubyte * pixels)
 {
-   struct intel_context *intel = intel_context(ctx);
+   if (!_mesa_check_conditional_render(ctx))
+      return;
 
    if (do_blit_bitmap(ctx, x, y, width, height,
                           unpack, pixels))
       return;
 
-   /* FIXME */
-   if (intel->gen == 6)
-       return _swrast_Bitmap(ctx, x, y, width, height, unpack, pixels);
-
    _mesa_meta_Bitmap(ctx, x, y, width, height, unpack, pixels);
 }