Squashed commit of the following:
[mesa.git] / src / gallium / auxiliary / util / u_surface.c
index daaa275ef25bde83a0515d0b90387bb273563da4..42440d0d67389afdbdd4b355de469009b0b50d4a 100644 (file)
@@ -35,6 +35,7 @@
 #include "pipe/p_screen.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
+#include "util/u_inlines.h"
 
 #include "util/u_memory.h"
 #include "util/u_surface.h"
 boolean
 util_create_rgba_surface(struct pipe_screen *screen,
                          uint width, uint height,
-                         struct pipe_texture **textureOut,
+                        uint bind,
+                         struct pipe_resource **textureOut,
                          struct pipe_surface **surfaceOut)
 {
    static const enum pipe_format rgbaFormats[] = {
-      PIPE_FORMAT_A8R8G8B8_UNORM,
       PIPE_FORMAT_B8G8R8A8_UNORM,
-      PIPE_FORMAT_R8G8B8A8_UNORM,
+      PIPE_FORMAT_A8R8G8B8_UNORM,
+      PIPE_FORMAT_A8B8G8R8_UNORM,
       PIPE_FORMAT_NONE
    };
    const uint target = PIPE_TEXTURE_2D;
-   const uint usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
    enum pipe_format format = PIPE_FORMAT_NONE;
-   struct pipe_texture templ;
+   struct pipe_resource templ;
    uint i;
 
    /* Choose surface format */
    for (i = 0; rgbaFormats[i]; i++) {
       if (screen->is_format_supported(screen, rgbaFormats[i],
-                                      target, usage, 0)) {
+                                      target, bind, 0)) {
          format = rgbaFormats[i];
          break;
       }
@@ -80,20 +81,22 @@ util_create_rgba_surface(struct pipe_screen *screen,
    templ.target = target;
    templ.format = format;
    templ.last_level = 0;
-   templ.width[0] = width;
-   templ.height[0] = height;
-   templ.depth[0] = 1;
-   pf_get_block(format, &templ.block);
-   templ.tex_usage = usage;
+   templ.width0 = width;
+   templ.height0 = height;
+   templ.depth0 = 1;
+   templ.bind = bind;
 
-   *textureOut = screen->texture_create(screen, &templ);
+   *textureOut = screen->resource_create(screen, &templ);
    if (!*textureOut)
       return FALSE;
 
    /* create surface / view into texture */
-   *surfaceOut = screen->get_tex_surface(screen, *textureOut, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+   *surfaceOut = screen->get_tex_surface(screen, 
+                                        *textureOut,
+                                        0, 0, 0,
+                                        bind);
    if (!*surfaceOut) {
-      pipe_texture_reference(textureOut, NULL);
+      pipe_resource_reference(textureOut, NULL);
       return FALSE;
    }
 
@@ -105,11 +108,11 @@ util_create_rgba_surface(struct pipe_screen *screen,
  * Release the surface and texture from util_create_rgba_surface().
  */
 void
-util_destroy_rgba_surface(struct pipe_texture *texture,
+util_destroy_rgba_surface(struct pipe_resource *texture,
                           struct pipe_surface *surface)
 {
    pipe_surface_reference(&surface, NULL);
-   pipe_texture_reference(&texture, NULL);
+   pipe_resource_reference(&texture, NULL);
 }
 
 
@@ -166,3 +169,19 @@ util_copy_framebuffer_state(struct pipe_framebuffer_state *dst,
 
    pipe_surface_reference(&dst->zsbuf, src->zsbuf);
 }
+
+
+void
+util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb)
+{
+   unsigned i;
+
+   for (i = 0; i < fb->nr_cbufs; i++) {
+      pipe_surface_reference(&fb->cbufs[i], NULL);
+   }
+
+   pipe_surface_reference(&fb->zsbuf, NULL);
+
+   fb->width = fb->height = 0;
+   fb->nr_cbufs = 0;
+}