replace malloc macros in imports.h with u_memory.h versions
[mesa.git] / src / mesa / drivers / dri / i965 / intel_fbo.c
index 2bbbc34114c3935e3eccc1394441c2a19f4e3ea1..cc450baf51e3d9aec0a461db836f4bf0a8077365 100644 (file)
@@ -24,7 +24,7 @@
  */
 
 #include "main/enums.h"
-#include "main/imports.h"
+#include "util/imports.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/fbobject.h"
@@ -36,6 +36,7 @@
 #include "main/condrender.h"
 #include "util/hash_table.h"
 #include "util/set.h"
+#include "util/u_memory.h"
 
 #include "swrast/swrast.h"
 #include "drivers/common/meta.h"
@@ -250,7 +251,7 @@ static mesa_format
 intel_renderbuffer_format(struct gl_context * ctx, GLenum internalFormat)
 {
    struct brw_context *brw = brw_context(ctx);
-   MAYBE_UNUSED const struct gen_device_info *devinfo = &brw->screen->devinfo;
+   ASSERTED const struct gen_device_info *devinfo = &brw->screen->devinfo;
 
    switch (internalFormat) {
    default:
@@ -629,17 +630,17 @@ intel_render_texture(struct gl_context * ctx,
 }
 
 
-#define fbo_incomplete(fb, ...) do {                                          \
+#define fbo_incomplete(fb, error_id, ...) do {                                          \
       static GLuint msg_id = 0;                                               \
       if (unlikely(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT)) {    \
-         _mesa_gl_debug(ctx, &msg_id,                                         \
-                        MESA_DEBUG_SOURCE_API,                                \
-                        MESA_DEBUG_TYPE_OTHER,                                \
-                        MESA_DEBUG_SEVERITY_MEDIUM,                           \
-                        __VA_ARGS__);                                         \
+         _mesa_gl_debugf(ctx, &msg_id,                                        \
+                         MESA_DEBUG_SOURCE_API,                               \
+                         MESA_DEBUG_TYPE_OTHER,                               \
+                         MESA_DEBUG_SEVERITY_MEDIUM,                          \
+                         __VA_ARGS__);                                        \
       }                                                                       \
       DBG(__VA_ARGS__);                                                       \
-      fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;                               \
+      fb->_Status = error_id;                                                 \
    } while (0)
 
 /**
@@ -693,7 +694,7 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
              d_depth != s_depth ||
              depthRb->mt_level != stencilRb->mt_level ||
             depthRb->mt_layer != stencilRb->mt_layer) {
-           fbo_incomplete(fb,
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
                            "FBO incomplete: depth and stencil must match in"
                            "width, height, depth, LOD and layer\n");
         }
@@ -705,7 +706,7 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
          */
         if (depthRb->mt_level != stencilRb->mt_level ||
             depthRb->mt_layer != stencilRb->mt_layer) {
-           fbo_incomplete(fb,
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
                            "FBO incomplete: depth image level/layer %d/%d != "
                            "stencil image %d/%d\n",
                            depthRb->mt_level,
@@ -715,13 +716,14 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
         }
       } else {
         if (!brw->has_separate_stencil) {
-           fbo_incomplete(fb, "FBO incomplete: separate stencil "
-                           "unsupported\n");
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                      "FBO incomplete: separate stencil unsupported\n");
         }
         if (stencil_mt->format != MESA_FORMAT_S_UINT8) {
-           fbo_incomplete(fb, "FBO incomplete: separate stencil is %s "
-                           "instead of S8\n",
-                           _mesa_get_format_name(stencil_mt->format));
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                      "FBO incomplete: separate stencil is %s "
+                      "instead of S8\n",
+                      _mesa_get_format_name(stencil_mt->format));
         }
         if (devinfo->gen < 7 && !intel_renderbuffer_has_hiz(depthRb)) {
            /* Before Gen7, separate depth and stencil buffers can be used
@@ -730,8 +732,8 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
             *     [DevSNB]: This field must be set to the same value (enabled
             *     or disabled) as Hierarchical Depth Buffer Enable.
             */
-           fbo_incomplete(fb, "FBO incomplete: separate stencil "
-                           "without HiZ\n");
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                          "FBO incomplete: separate stencil without HiZ\n");
         }
       }
    }
@@ -749,29 +751,39 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
        */
       rb = fb->Attachment[i].Renderbuffer;
       if (rb == NULL) {
-        fbo_incomplete(fb, "FBO incomplete: attachment without "
-                        "renderbuffer\n");
+        fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                       "FBO incomplete: attachment without "
+                       "renderbuffer\n");
         continue;
       }
 
       if (fb->Attachment[i].Type == GL_TEXTURE) {
         if (rb->TexImage->Border) {
-           fbo_incomplete(fb, "FBO incomplete: texture with border\n");
+           fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                      "FBO incomplete: texture with border\n");
            continue;
         }
       }
 
       irb = intel_renderbuffer(rb);
       if (irb == NULL) {
-        fbo_incomplete(fb, "FBO incomplete: software rendering "
-                        "renderbuffer\n");
+        fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                   "FBO incomplete: software rendering renderbuffer\n");
         continue;
       }
 
+     if (rb->Format == MESA_FORMAT_R_SRGB8) {
+        fbo_incomplete(fb, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
+                       "FBO incomplete: Format not color renderable: %s\n",
+                       _mesa_get_format_name(rb->Format));
+        continue;
+     }
+
       if (!brw_render_target_supported(brw, rb)) {
-        fbo_incomplete(fb, "FBO incomplete: Unsupported HW "
-                        "texture/renderbuffer format attached: %s\n",
-                        _mesa_get_format_name(intel_rb_format(irb)));
+        fbo_incomplete(fb, GL_FRAMEBUFFER_UNSUPPORTED,
+                   "FBO incomplete: Unsupported HW "
+                   "texture/renderbuffer format attached: %s\n",
+                   _mesa_get_format_name(intel_rb_format(irb)));
       }
    }
 }
@@ -849,8 +861,8 @@ intel_blit_framebuffer_with_blitter(struct gl_context *ctx,
          }
 
          if (ctx->Color.sRGBEnabled &&
-             _mesa_get_format_color_encoding(src_irb->mt->format) !=
-             _mesa_get_format_color_encoding(dst_irb->mt->format)) {
+             _mesa_is_format_srgb(src_irb->mt->format) !=
+             _mesa_is_format_srgb(dst_irb->mt->format)) {
             perf_debug("glBlitFramebuffer() with sRGB conversion cannot be "
                        "handled by BLT path.\n");
             return mask;