replace _mesa_logbase2 with util_logbase2
[mesa.git] / src / mesa / state_tracker / st_cb_blit.c
index a236a08e95e1be35a3cd5c5745767f965d23f94b..73068b795f6879060ddba65394992fde5c8f7243 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * 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
+ * IN NO EVENT SHALL VMWARE 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.
   *   Brian Paul
   */
 
-#include "main/imports.h"
+#include "util/imports.h"
 #include "main/image.h"
 #include "main/macros.h"
 
 #include "st_context.h"
 #include "st_texture.h"
+#include "st_cb_bitmap.h"
 #include "st_cb_blit.h"
 #include "st_cb_fbo.h"
-#include "st_atom.h"
-
-#include "util/u_format.h"
+#include "st_manager.h"
+#include "st_scissor.h"
+#include "st_util.h"
 
+#include "util/format/u_format.h"
 
 static void
 st_BlitFramebuffer(struct gl_context *ctx,
+                   struct gl_framebuffer *readFB,
+                   struct gl_framebuffer *drawFB,
                    GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                    GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
                    GLbitfield mask, GLenum filter)
@@ -55,15 +59,17 @@ st_BlitFramebuffer(struct gl_context *ctx,
    const uint pFilter = ((filter == GL_NEAREST)
                          ? PIPE_TEX_FILTER_NEAREST
                          : PIPE_TEX_FILTER_LINEAR);
-   struct gl_framebuffer *readFB = ctx->ReadBuffer;
-   struct gl_framebuffer *drawFB = ctx->DrawBuffer;
    struct {
       GLint srcX0, srcY0, srcX1, srcY1;
       GLint dstX0, dstY0, dstX1, dstY1;
    } clip;
    struct pipe_blit_info blit;
 
-   st_validate_state(st);
+   st_manager_validate_framebuffers(st);
+
+   /* Make sure bitmap rendering has landed in the framebuffers */
+   st_flush_bitmap_cache(st);
+   st_invalidate_readpix_cache(st);
 
    clip.srcX0 = srcX0;
    clip.srcY0 = srcY0;
@@ -80,11 +86,12 @@ st_BlitFramebuffer(struct gl_context *ctx,
     *
     * XXX: This should depend on mask !
     */
-   if (!_mesa_clip_blit(ctx,
+   if (!_mesa_clip_blit(ctx, readFB, drawFB,
                         &clip.srcX0, &clip.srcY0, &clip.srcX1, &clip.srcY1,
                         &clip.dstX0, &clip.dstY0, &clip.dstX1, &clip.dstY1)) {
       return; /* nothing to draw/blit */
    }
+   memset(&blit, 0, sizeof(struct pipe_blit_info));
    blit.scissor_enable =
       (dstX0 != clip.dstX0) ||
       (dstY0 != clip.dstY0) ||
@@ -158,77 +165,75 @@ st_BlitFramebuffer(struct gl_context *ctx,
       blit.src.box.height = srcY0 - srcY1;
    }
 
+   if (drawFB != ctx->WinSysDrawBuffer)
+      st_window_rectangles_to_blit(ctx, &blit);
+
    blit.filter = pFilter;
+   blit.render_condition_enable = TRUE;
+   blit.alpha_blend = FALSE;
 
    if (mask & GL_COLOR_BUFFER_BIT) {
       struct gl_renderbuffer_attachment *srcAtt =
          &readFB->Attachment[readFB->_ColorReadBufferIndex];
+      GLuint i;
 
       blit.mask = PIPE_MASK_RGBA;
 
       if (srcAtt->Type == GL_TEXTURE) {
          struct st_texture_object *srcObj = st_texture_object(srcAtt->Texture);
-         GLuint i;
 
          if (!srcObj || !srcObj->pt) {
             return;
          }
 
-         for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) {
-            struct st_renderbuffer *dstRb =
-               st_renderbuffer(drawFB->_ColorDrawBuffers[i]);
-
-            if (dstRb) {
-               struct pipe_surface *dstSurf = dstRb->surface;
+         blit.src.resource = srcObj->pt;
+         blit.src.level = srcAtt->TextureLevel;
+         blit.src.box.z = srcAtt->Zoffset + srcAtt->CubeMapFace;
+         blit.src.format = srcObj->pt->format;
 
-               if (dstSurf) {
-                  blit.dst.resource = dstSurf->texture;
-                  blit.dst.level = dstSurf->u.tex.level;
-                  blit.dst.box.z = dstSurf->u.tex.first_layer;
-                  blit.dst.format = util_format_linear(dstSurf->format);
-
-                  blit.src.resource = srcObj->pt;
-                  blit.src.level = srcAtt->TextureLevel;
-                  blit.src.box.z = srcAtt->Zoffset + srcAtt->CubeMapFace;
-                  blit.src.format = util_format_linear(srcObj->pt->format);
-
-                  st->pipe->blit(st->pipe, &blit);
-               }
-            }
-         }
+         if (!ctx->Color.sRGBEnabled)
+            blit.src.format = util_format_linear(blit.src.format);
       }
       else {
          struct st_renderbuffer *srcRb =
             st_renderbuffer(readFB->_ColorReadBuffer);
          struct pipe_surface *srcSurf;
-         GLuint i;
 
-         if (!srcRb || !srcRb->surface) {
+         if (!srcRb)
+            return;
+
+         st_update_renderbuffer_surface(st, srcRb);
+
+         if (!srcRb->surface)
             return;
-         }
 
          srcSurf = srcRb->surface;
 
-         for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) {
-            struct st_renderbuffer *dstRb =
-               st_renderbuffer(drawFB->_ColorDrawBuffers[i]);
+         blit.src.resource = srcSurf->texture;
+         blit.src.level = srcSurf->u.tex.level;
+         blit.src.box.z = srcSurf->u.tex.first_layer;
+         blit.src.format = srcSurf->format;
+      }
+
+      for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) {
+         struct st_renderbuffer *dstRb =
+            st_renderbuffer(drawFB->_ColorDrawBuffers[i]);
+
+         if (dstRb) {
+            struct pipe_surface *dstSurf;
 
-            if (dstRb) {
-               struct pipe_surface *dstSurf = dstRb->surface;
+            st_update_renderbuffer_surface(st, dstRb);
 
-               if (dstSurf) {
-                  blit.dst.resource = dstSurf->texture;
-                  blit.dst.level = dstSurf->u.tex.level;
-                  blit.dst.box.z = dstSurf->u.tex.first_layer;
-                  blit.dst.format = util_format_linear(dstSurf->format);
+            dstSurf = dstRb->surface;
 
-                  blit.src.resource = srcSurf->texture;
-                  blit.src.level = srcSurf->u.tex.level;
-                  blit.src.box.z = srcSurf->u.tex.first_layer;
-                  blit.src.format = util_format_linear(srcSurf->format);
+            if (dstSurf) {
+               blit.dst.resource = dstSurf->texture;
+               blit.dst.level = dstSurf->u.tex.level;
+               blit.dst.box.z = dstSurf->u.tex.first_layer;
+               blit.dst.format = dstSurf->format;
 
-                  st->pipe->blit(st->pipe, &blit);
-               }
+               st->pipe->blit(st->pipe, &blit);
+               dstRb->defined = true; /* front buffer tracking */
             }
          }
       }