Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
index 6402141170d5d181d73e85989a4dfef37e37f12c..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,12 +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_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,
@@ -289,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) {
@@ -304,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,
@@ -319,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;
 
@@ -330,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);
       }
    }
 
@@ -364,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) {
@@ -477,7 +441,7 @@ intelTexImage(GLcontext * ctx,
         /* 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,
@@ -501,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);
@@ -556,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,
@@ -573,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,
@@ -589,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,
@@ -605,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,
@@ -623,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)
@@ -635,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) {
@@ -683,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)
@@ -694,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)
@@ -703,37 +667,14 @@ intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
                       texObj, texImage, GL_TRUE);
 }
 
-
-void
-intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname,
-                 unsigned long long offset, GLint depth, GLuint pitch)
-{
-   struct intel_context *intel = pDRICtx->driverPrivate;
-   struct gl_texture_object *tObj = _mesa_lookup_texture(&intel->ctx, texname);
-   struct intel_texture_object *intelObj = intel_texture_object(tObj);
-
-   if (!intelObj)
-      return;
-
-   if (intelObj->mt)
-      intel_miptree_release(intel, &intelObj->mt);
-
-   intelObj->imageOverride = GL_TRUE;
-   intelObj->depthOverride = depth;
-   intelObj->pitchOverride = pitch;
-
-   if (offset)
-      intelObj->textureOffset = offset;
-}
-
 void
 intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
-                  GLint glx_texture_format,
+                  GLint texture_format,
                   __DRIdrawable *dPriv)
 {
    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;
@@ -748,7 +689,8 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    if (!intelObj)
       return;
 
-   if (!dPriv->validBuffers)
+   if (dPriv->lastStamp != dPriv->dri2.stamp ||
+       !pDRICtx->driScreenPriv->dri2.useInvalidate)
       intel_update_renderbuffers(pDRICtx, dPriv);
 
    rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
@@ -758,7 +700,7 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    if (rb->region == NULL)
       return;
 
-   if (glx_texture_format == GLX_TEXTURE_FORMAT_RGB_EXT)
+   if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
       internalFormat = GL_RGB;
    else
       internalFormat = GL_RGBA;
@@ -788,7 +730,7 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
 
    intelImage->face = target_to_face(target);
    intelImage->level = level;
-   if (glx_texture_format == GLX_TEXTURE_FORMAT_RGB_EXT)
+   if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
       texImage->TexFormat = MESA_FORMAT_XRGB8888;
    else
       texImage->TexFormat = MESA_FORMAT_ARGB8888;
@@ -808,9 +750,57 @@ intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
    /* The old interface didn't have the format argument, so copy our
     * implementation's behavior at the time.
     */
-   intelSetTexBuffer2(pDRICtx, target, GLX_TEXTURE_FORMAT_RGBA_EXT, dPriv);
+   intelSetTexBuffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv);
 }
 
+#if FEATURE_OES_EGL_image
+static void
+intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
+                             struct gl_texture_object *texObj,
+                             struct gl_texture_image *texImage,
+                             GLeglImageOES image_handle)
+{
+   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);
+   struct intel_mipmap_tree *mt;
+   __DRIscreen *screen;
+   __DRIimage *image;
+
+   screen = intel->intelScreen->driScrnPriv;
+   image = screen->dri2.image->lookupEGLImage(screen, image_handle,
+                                             screen->loaderPrivate);
+   if (image == NULL)
+      return;
+
+   mt = intel_miptree_create_for_region(intel, target,
+                                       image->internal_format,
+                                       0, 0, image->region, 1, 0);
+   if (mt == NULL)
+       return;
+
+   if (intelImage->mt) {
+      intel_miptree_release(intel, &intelImage->mt);
+      assert(!texImage->Data);
+   }
+   if (intelObj->mt)
+      intel_miptree_release(intel, &intelObj->mt);
+
+   intelObj->mt = mt;
+   _mesa_init_teximage_fields(&intel->ctx, target, texImage,
+                             image->region->width, image->region->height, 1,
+                             0, image->internal_format);
+
+   intelImage->face = target_to_face(target);
+   intelImage->level = 0;
+   texImage->TexFormat = image->format;
+   texImage->RowStride = image->region->pitch;
+   intel_miptree_reference(&intelImage->mt, intelObj->mt);
+
+   if (!intel_miptree_match_image(intelObj->mt, &intelImage->base))
+      fprintf(stderr, "miptree doesn't match image\n");
+}
+#endif
 
 void
 intelInitTextureImageFuncs(struct dd_function_table *functions)
@@ -822,4 +812,8 @@ intelInitTextureImageFuncs(struct dd_function_table *functions)
 
    functions->CompressedTexImage2D = intelCompressedTexImage2D;
    functions->GetCompressedTexImage = intelGetCompressedTexImage;
+
+#if FEATURE_OES_EGL_image
+   functions->EGLImageTargetTexture2D = intel_image_target_texture_2d;
+#endif
 }