Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
index bac36eeb56950bab9fa3d774496c51c98542f7ea..50fe9bd9f331717c0d176446d60d3f6b22d3a63e 100644 (file)
@@ -4,14 +4,12 @@
 #include "main/mtypes.h"
 #include "main/enums.h"
 #include "main/bufferobj.h"
-#include "main/convolve.h"
 #include "main/context.h"
 #include "main/formats.h"
 #include "main/texcompress.h"
 #include "main/texstore.h"
 #include "main/texgetimage.h"
 #include "main/texobj.h"
-#include "main/texstore.h"
 #include "main/teximage.h"
 
 #include "intel_context.h"
@@ -68,16 +66,12 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
    GLuint width = intelImage->base.Width;
    GLuint height = intelImage->base.Height;
    GLuint depth = intelImage->base.Depth;
-   GLuint l2width, l2height, l2depth;
    GLuint i, comp_byte = 0;
    GLuint texelBytes;
 
    DBG("%s\n", __FUNCTION__);
 
-   if (intelImage->base.Border ||
-       ((intelImage->base._BaseFormat == GL_DEPTH_COMPONENT) && 
-        ((intelObj->base.WrapS == GL_CLAMP_TO_BORDER) ||
-         (intelObj->base.WrapT == GL_CLAMP_TO_BORDER))))
+   if (intelImage->base.Border)
       return;
 
    if (intelImage->level > intelObj->base.BaseLevel &&
@@ -119,10 +113,7 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
       lastLevel = firstLevel;
    }
    else {
-      l2width = logbase2(width);
-      l2height = logbase2(height);
-      l2depth = logbase2(depth);
-      lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
+      lastLevel = firstLevel + logbase2(MAX2(MAX2(width, height), depth));
    }
 
    assert(!intelObj->mt);
@@ -213,9 +204,9 @@ try_pbo_upload(struct intel_context *intel,
    struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
    GLuint src_offset, src_stride;
    GLuint dst_x, dst_y, dst_stride;
-   dri_bo *dst_buffer = intel_region_buffer(intel,
-                                           intelImage->mt->region,
-                                           INTEL_WRITE_FULL);
+   drm_intel_bo *dst_buffer = intel_region_buffer(intel,
+                                                 intelImage->mt->region,
+                                                 INTEL_WRITE_FULL);
 
    if (!_mesa_is_bufferobj(unpack->BufferObj) ||
        intel->ctx._ImageTransferState ||
@@ -236,13 +227,13 @@ try_pbo_upload(struct intel_context *intel,
                                  intelImage->face, 0,
                                  &dst_x, &dst_y);
 
-   dst_stride = intelImage->mt->pitch;
+   dst_stride = intelImage->mt->region->pitch;
 
    if (drm_intel_bo_references(intel->batch->buf, dst_buffer))
-      intelFlush(&intel->ctx);
-   intel_prepare_render(intel);
+      intel_flush(&intel->ctx);
+
    {
-      dri_bo *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ);
+      drm_intel_bo *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ);
 
       if (!intelEmitCopyBlit(intel,
                             intelImage->mt->cpp,
@@ -290,7 +281,7 @@ try_pbo_zcopy(struct intel_context *intel,
                                  intelImage->face, 0,
                                  &dst_x, &dst_y);
 
-   dst_stride = intelImage->mt->pitch;
+   dst_stride = intelImage->mt->region->pitch;
 
    if (src_stride != dst_stride || dst_x != 0 || dst_y != 0 ||
        src_offset != 0) {
@@ -305,7 +296,7 @@ try_pbo_zcopy(struct intel_context *intel,
 
 
 static void
-intelTexImage(GLcontext * ctx,
+intelTexImage(struct gl_context * ctx,
               GLint dims,
               GLenum target, GLint level,
               GLint internalFormat,
@@ -320,8 +311,6 @@ intelTexImage(GLcontext * ctx,
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_object *intelObj = intel_texture_object(texObj);
    struct intel_texture_image *intelImage = intel_texture_image(texImage);
-   GLint postConvWidth = width;
-   GLint postConvHeight = height;
    GLint texelBytes, sizeInBytes;
    GLuint dstRowStride = 0, srcRowStride = texImage->RowStride;
 
@@ -331,25 +320,14 @@ intelTexImage(GLcontext * ctx,
    intelImage->face = target_to_face(target);
    intelImage->level = level;
 
-   if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
-      _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth,
-                                         &postConvHeight);
-   }
-
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
       texelBytes = 0;
    }
    else {
       texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
-      
-      /* Minimum pitch of 32 bytes */
-      if (postConvWidth * texelBytes < 32) {
-        postConvWidth = 32 / texelBytes;
-        texImage->RowStride = postConvWidth;
-      }
 
       if (!intelImage->mt) {      
-         assert(texImage->RowStride == postConvWidth);
+         assert(texImage->RowStride == width);
       }
    }
 
@@ -365,21 +343,6 @@ intelTexImage(GLcontext * ctx,
       texImage->Data = NULL;
    }
 
-   /* If this is the only texture image in the tree, could call
-    * bmBufferData with NULL data to free the old block and avoid
-    * waiting on any outstanding fences.
-    */
-   if (intelObj->mt &&
-       intelObj->mt->first_level == level &&
-       intelObj->mt->last_level == level &&
-       intelObj->mt->target != GL_TEXTURE_CUBE_MAP_ARB &&
-       !intel_miptree_match_image(intelObj->mt, &intelImage->base)) {
-
-      DBG("release it\n");
-      intel_miptree_release(intel, &intelObj->mt);
-      assert(!intelObj->mt);
-   }
-
    if (!intelObj->mt) {
       guess_and_alloc_mipmap_tree(intel, intelObj, intelImage, pixels == NULL);
       if (!intelObj->mt) {
@@ -473,14 +436,12 @@ intelTexImage(GLcontext * ctx,
                                           pixels, unpack, "glTexImage");
    }
 
-   intel_prepare_render(intel);
-
    if (intelImage->mt) {
       if (pixels != NULL) {
         /* Flush any queued rendering with the texture before mapping. */
         if (drm_intel_bo_references(intel->batch->buf,
                                     intelImage->mt->region->buffer)) {
-           intelFlush(ctx);
+           intel_flush(ctx);
         }
          texImage->Data = intel_miptree_image_map(intel,
                                                   intelImage->mt,
@@ -504,8 +465,8 @@ intelTexImage(GLcontext * ctx,
          assert(dims != 3);
       }
       else {
-         dstRowStride = postConvWidth * texelBytes;
-         sizeInBytes = depth * dstRowStride * postConvHeight;
+         dstRowStride = width * texelBytes;
+         sizeInBytes = depth * dstRowStride * height;
       }
 
       texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
@@ -559,7 +520,7 @@ intelTexImage(GLcontext * ctx,
 
 
 static void
-intelTexImage3D(GLcontext * ctx,
+intelTexImage3D(struct gl_context * ctx,
                 GLenum target, GLint level,
                 GLint internalFormat,
                 GLint width, GLint height, GLint depth,
@@ -576,7 +537,7 @@ intelTexImage3D(GLcontext * ctx,
 
 
 static void
-intelTexImage2D(GLcontext * ctx,
+intelTexImage2D(struct gl_context * ctx,
                 GLenum target, GLint level,
                 GLint internalFormat,
                 GLint width, GLint height, GLint border,
@@ -592,7 +553,7 @@ intelTexImage2D(GLcontext * ctx,
 
 
 static void
-intelTexImage1D(GLcontext * ctx,
+intelTexImage1D(struct gl_context * ctx,
                 GLenum target, GLint level,
                 GLint internalFormat,
                 GLint width, GLint border,
@@ -608,7 +569,7 @@ intelTexImage1D(GLcontext * ctx,
 
 
 static void
-intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
+intelCompressedTexImage2D( struct gl_context *ctx, GLenum target, GLint level,
                            GLint internalFormat,
                            GLint width, GLint height, GLint border,
                            GLsizei imageSize, const GLvoid *data,
@@ -626,7 +587,7 @@ intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
  * then unmap it.
  */
 static void
-intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
+intel_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
                    GLenum format, GLenum type, GLvoid * pixels,
                    struct gl_texture_object *texObj,
                    struct gl_texture_image *texImage, GLboolean compressed)
@@ -638,7 +599,7 @@ intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
     * make sure rendering is complete.
     * We could probably predicate this on texObj->_RenderToTexture
     */
-   intelFlush(ctx);
+   intel_flush(ctx);
 
    /* Map */
    if (intelImage->mt) {
@@ -686,7 +647,7 @@ intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
 
 
 static void
-intelGetTexImage(GLcontext * ctx, GLenum target, GLint level,
+intelGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
                  GLenum format, GLenum type, GLvoid * pixels,
                  struct gl_texture_object *texObj,
                  struct gl_texture_image *texImage)
@@ -697,7 +658,7 @@ intelGetTexImage(GLcontext * ctx, GLenum target, GLint level,
 
 
 static void
-intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
+intelGetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
                           GLvoid *pixels,
                           struct gl_texture_object *texObj,
                           struct gl_texture_image *texImage)
@@ -713,7 +674,7 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
 {
    struct gl_framebuffer *fb = dPriv->driverPrivate;
    struct intel_context *intel = pDRICtx->driverPrivate;
-   GLcontext *ctx = &intel->ctx;
+   struct gl_context *ctx = &intel->ctx;
    struct intel_texture_object *intelObj;
    struct intel_texture_image *intelImage;
    struct intel_mipmap_tree *mt;
@@ -728,7 +689,8 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    if (!intelObj)
       return;
 
-   if (dPriv->lastStamp != dPriv->dri2.stamp)
+   if (dPriv->lastStamp != dPriv->dri2.stamp ||
+       !pDRICtx->driScreenPriv->dri2.useInvalidate)
       intel_update_renderbuffers(pDRICtx, dPriv);
 
    rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
@@ -793,7 +755,7 @@ intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
 
 #if FEATURE_OES_EGL_image
 static void
-intel_image_target_texture_2d(GLcontext *ctx, GLenum target,
+intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
                              struct gl_texture_object *texObj,
                              struct gl_texture_image *texImage,
                              GLeglImageOES image_handle)
@@ -806,8 +768,8 @@ intel_image_target_texture_2d(GLcontext *ctx, GLenum target,
    __DRIimage *image;
 
    screen = intel->intelScreen->driScrnPriv;
-   image = screen->dri2.image->lookupEGLImage(intel->driContext, image_handle,
-                                             intel->driContext->loaderPrivate);
+   image = screen->dri2.image->lookupEGLImage(screen, image_handle,
+                                             screen->loaderPrivate);
    if (image == NULL)
       return;