gallium: don't use arrays for texture width,height,depth
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_aaline.c
index 3dd7ee19fd1b87c674f1e5f8162642f058423b46..31de84b272b42cda6903d62f32943071ebe11738 100644 (file)
  */
 
 
-#include "pipe/p_util.h"
-#include "pipe/p_inlines.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_shader_tokens.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
 
-#include "tgsi/util/tgsi_transform.h"
-#include "tgsi/util/tgsi_dump.h"
+#include "tgsi/tgsi_transform.h"
+#include "tgsi/tgsi_dump.h"
 
 #include "draw_context.h"
 #include "draw_private.h"
@@ -60,8 +60,6 @@ struct aaline_fragment_shader
    struct pipe_shader_state state;
    void *driver_fs;
    void *aaline_fs;
-   void *aapoint_fs; /* not yet */
-   void *sprite_fs; /* not yet */
    uint sampler_unit;
    int generic_attrib;  /**< texcoord/generic used for texture */
 };
@@ -373,10 +371,15 @@ generate_aaline_fs(struct aaline_stage *aaline)
    aaline->fs->aaline_fs
       = aaline->driver_create_fs_state(aaline->pipe, &aaline_fs);
    if (aaline->fs->aaline_fs == NULL)
-      return FALSE;
+      goto fail;
 
    aaline->fs->generic_attrib = transform.maxGeneric + 1;
+   FREE((void *)aaline_fs.tokens);
    return TRUE;
+
+fail:
+   FREE((void *)aaline_fs.tokens);
+   return FALSE;
 }
 
 
@@ -395,9 +398,9 @@ aaline_create_texture(struct aaline_stage *aaline)
    texTemp.target = PIPE_TEXTURE_2D;
    texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */
    texTemp.last_level = MAX_TEXTURE_LEVEL;
-   texTemp.width[0] = 1 << MAX_TEXTURE_LEVEL;
-   texTemp.height[0] = 1 << MAX_TEXTURE_LEVEL;
-   texTemp.depth[0] = 1;
+   texTemp.width0 = 1 << MAX_TEXTURE_LEVEL;
+   texTemp.height0 = 1 << MAX_TEXTURE_LEVEL;
+   texTemp.depth0 = 1;
    pf_get_block(texTemp.format, &texTemp.block);
 
    aaline->texture = screen->texture_create(screen, &texTemp);
@@ -409,18 +412,18 @@ aaline_create_texture(struct aaline_stage *aaline)
     * texels which are zero.  Special case the 1x1 and 2x2 levels.
     */
    for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) {
-      struct pipe_surface *surface;
-      const uint size = aaline->texture->width[level];
+      struct pipe_transfer *transfer;
+      const uint size = u_minify(aaline->texture->width0, level);
       ubyte *data;
       uint i, j;
 
-      assert(aaline->texture->width[level] == aaline->texture->height[level]);
+      assert(aaline->texture->width0 == aaline->texture->height0);
 
       /* This texture is new, no need to flush. 
        */
-      surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0,
-                                        PIPE_BUFFER_USAGE_CPU_WRITE);
-      data = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE);
+      transfer = screen->get_tex_transfer(screen, aaline->texture, 0, level, 0,
+                                         PIPE_TRANSFER_WRITE, 0, 0, size, size);
+      data = screen->transfer_map(screen, transfer);
       if (data == NULL)
          return FALSE;
 
@@ -439,13 +442,13 @@ aaline_create_texture(struct aaline_stage *aaline)
             else {
                d = 255;
             }
-            data[i * surface->stride + j] = d;
+            data[i * transfer->stride + j] = d;
          }
       }
 
       /* unmap */
-      screen->surface_unmap(screen, surface);
-      screen->tex_surface_release(screen, &surface);
+      screen->transfer_unmap(screen, transfer);
+      screen->tex_transfer_destroy(transfer);
    }
    return TRUE;
 }
@@ -727,7 +730,7 @@ aaline_destroy(struct draw_stage *stage)
       aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso);
 
    if (aaline->texture)
-      pipe_texture_release(&aaline->texture);
+      pipe_texture_reference(&aaline->texture, NULL);
 
    draw_free_temp_verts( stage );
 
@@ -746,6 +749,7 @@ draw_aaline_stage(struct draw_context *draw)
       goto fail;
 
    aaline->stage.draw = draw;
+   aaline->stage.name = "aaline";
    aaline->stage.next = NULL;
    aaline->stage.point = draw_pipe_passthrough_point;
    aaline->stage.line = aaline_first_line;
@@ -815,6 +819,10 @@ aaline_delete_fs_state(struct pipe_context *pipe, void *fs)
    struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs;
    /* pass-through */
    aaline->driver_delete_fs_state(aaline->pipe, aafs->driver_fs);
+
+   if (aafs->aaline_fs)
+      aaline->driver_delete_fs_state(aaline->pipe, aafs->aaline_fs);
+
    FREE(aafs);
 }