gallium: change pipe->texture_create() to operate like the CSO functions
authorBrian <brian.paul@tungstengraphics.com>
Wed, 6 Feb 2008 16:24:30 +0000 (09:24 -0700)
committerBen Skeggs <skeggsb@gmail.com>
Fri, 15 Feb 2008 02:50:32 +0000 (13:50 +1100)
Now, pass in a template object and return a new object.

src/mesa/pipe/cell/ppu/cell_texture.c
src/mesa/pipe/cell/ppu/cell_texture.h
src/mesa/pipe/i915simple/i915_texture.c
src/mesa/pipe/i915simple/i915_texture.h
src/mesa/pipe/i965simple/brw_tex_layout.c
src/mesa/pipe/i965simple/brw_tex_layout.h
src/mesa/pipe/p_context.h
src/mesa/pipe/softpipe/sp_texture.c
src/mesa/pipe/softpipe/sp_texture.h
src/mesa/state_tracker/st_texture.c

index 2cf60229394c3aa0f686161761cbbe1be04e5d4c..df178d9ca2476bc4b593c2bd54b54997902b0507 100644 (file)
@@ -79,31 +79,30 @@ cell_texture_layout(struct cell_texture * spt)
 }
 
 
-void
-cell_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+struct pipe_texture *
+cell_texture_create(struct pipe_context *pipe, const struct pipe_texture *templat)
 {
-   struct cell_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture),
-                                         sizeof(struct cell_texture));
+   struct cell_texture *spt = CALLOC_STRUCT(cell_texture);
+   if (!spt)
+      return NULL;
 
-   if (spt) {
-      memset(&spt->base + 1, 0,
-            sizeof(struct cell_texture) - sizeof(struct pipe_texture));
+   spt->base = *templat;
 
-      cell_texture_layout(spt);
+   cell_texture_layout(spt);
 
-      spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
-                                                PIPE_BUFFER_USAGE_PIXEL,
-                                                spt->buffer_size);
+   spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
+                                             PIPE_BUFFER_USAGE_PIXEL,
+                                             spt->buffer_size);
 
-      if (!spt->buffer) {
-        FREE(spt);
-        spt = NULL;
-      }
+   if (!spt->buffer) {
+      FREE(spt);
+      return NULL;
    }
 
-   *pt = &spt->base;
+   return &spt->base;
 }
 
+
 void
 cell_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
 {
index bd434c87762df36b60b2b6ee8033b19ac001ed2a..0264fed88e68232785dd7665f0f9395fb27cb14a 100644 (file)
@@ -60,8 +60,9 @@ cell_texture(struct pipe_texture *pt)
 
 
 
-extern void
-cell_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+extern struct pipe_texture *
+cell_texture_create(struct pipe_context *pipe,
+                    const struct pipe_texture *templat);
 
 extern void
 cell_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
index 61944fe7d9a210c37f2d89445cffa7ed7e0af53a..6faeab134ab1d9b4fecd5a5e4492a975a28b4f2a 100644 (file)
@@ -477,17 +477,17 @@ i945_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex)
    return TRUE;
 }
 
-void
-i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+
+struct pipe_texture *
+i915_texture_create(struct pipe_context *pipe,
+                    const struct pipe_texture *templat)
 {
-   struct i915_texture *tex = REALLOC(*pt, sizeof(struct pipe_texture),
-                                     sizeof(struct i915_texture));
+   struct i915_texture *tex = CALLOC_STRUCT(i915_texture);
 
    if (tex) {
       struct i915_context *i915 = i915_context(pipe);
 
-      memset(&tex->base + 1, 0,
-            sizeof(struct i915_texture) - sizeof(struct pipe_texture));
+      tex->base = *templat;
 
       if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) :
          i915_miptree_layout(pipe, tex))
@@ -498,13 +498,14 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
 
       if (!tex->buffer) {
         FREE(tex);
-        tex = NULL;
+        return NULL;
       }
    }
 
-   *pt = &tex->base;
+   return &tex->base;
 }
 
+
 void
 i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
 {
index 84a0502e81ae66ae7c3b7e4ebb034967c2a957ff..330d111dc789aae8119965043c0c5ad820a5d196 100644 (file)
@@ -6,8 +6,9 @@ struct pipe_context;
 struct pipe_texture;
 
 
-extern void
-i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+struct pipe_texture *
+i915_texture_create(struct pipe_context *pipe,
+                    const struct pipe_texture *templat);
 
 extern void
 i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
index b8b6b579e229973d916ef27d958fbe35bc8669aa..405fd1f794918b086b64d5741d15481c036632e9 100644 (file)
@@ -299,15 +299,14 @@ static boolean brw_miptree_layout(struct pipe_context *pipe, struct brw_texture
    return TRUE;
 }
 
-void
-brw_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+
+struct pipe_texture *
+brw_texture_create(struct pipe_context *pipe, const struct pipe_texture *templat)
 {
-   struct brw_texture *tex = REALLOC(*pt, sizeof(struct pipe_texture),
-                                     sizeof(struct brw_texture));
+   struct brw_texture *tex = CALLOC_STRUCT(brw_texture);
 
    if (tex) {
-      memset(&tex->base + 1, 0,
-            sizeof(struct brw_texture) - sizeof(struct pipe_texture));
+      tex->base = *templat;
 
       if (brw_miptree_layout(pipe, tex))
         tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
@@ -317,11 +316,11 @@ brw_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
 
       if (!tex->buffer) {
         FREE(tex);
-        tex = NULL;
+         return NULL;
       }
    }
 
-   *pt = &tex->base;
+   return &tex->base;
 }
 
 void
index 15e275058af558b49a97fa9be3e966fce9ecac62..cfd6b1ef3ae66c5fa46310cc2fc58c370eec56e4 100644 (file)
@@ -6,8 +6,8 @@
 struct pipe_context;
 struct pipe_texture;
 
-extern void
-brw_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+extern struct pipe_texture *
+brw_texture_create(struct pipe_context *pipe, const struct pipe_texture *templat);
 
 extern void
 brw_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
index 0dda06c53babd472dba927ea066c0467e4370de9..92a1cd70c42588139bd832f23c00d2d2d5fc183c 100644 (file)
@@ -199,8 +199,8 @@ struct pipe_context {
    /*
     * Texture functions
     */
-   void (*texture_create)(struct pipe_context *pipe,
-                         struct pipe_texture **pt);
+   struct pipe_texture * (*texture_create)(struct pipe_context *pipe,
+                                           const struct pipe_texture *templat);
 
    void (*texture_release)(struct pipe_context *pipe,
                           struct pipe_texture **pt);
index 172234843d80f597dee16ef949a1c0349d50cf95..fd2cc3dbbb4c57f4e2f56de9ea260da74555ba88 100644 (file)
@@ -79,31 +79,30 @@ softpipe_texture_layout(struct softpipe_texture * spt)
 }
 
 
-void
-softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+struct pipe_texture *
+softpipe_texture_create(struct pipe_context *pipe,
+                        const struct pipe_texture *templat)
 {
-   struct softpipe_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture),
-                                         sizeof(struct softpipe_texture));
-
-   if (spt) {
-      memset(&spt->base + 1, 0,
-            sizeof(struct softpipe_texture) - sizeof(struct pipe_texture));
+   struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
+   if (!spt)
+      return NULL;
 
-      softpipe_texture_layout(spt);
+   spt->base = *templat;
 
-      spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
-                                                PIPE_BUFFER_USAGE_PIXEL,
-                                                spt->buffer_size);
+   softpipe_texture_layout(spt);
 
-      if (!spt->buffer) {
-        FREE(spt);
-        spt = NULL;
-      }
+   spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
+                                             PIPE_BUFFER_USAGE_PIXEL,
+                                             spt->buffer_size);
+   if (!spt->buffer) {
+      FREE(spt);
+      return NULL;
    }
 
-   *pt = &spt->base;
+   return &spt->base;
 }
 
+
 void
 softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
 {
index c6cf370351de13bbb269836f558d24e9c8ece58a..fa646c0de9f93d20bca02a591abfec2acf9f13fa 100644 (file)
@@ -55,8 +55,9 @@ softpipe_texture(struct pipe_texture *pt)
 
 
 
-extern void
-softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+extern struct pipe_texture *
+softpipe_texture_create(struct pipe_context *pipe,
+                        const struct pipe_texture *templat);
 
 extern void
 softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
index 741f36c2a7d6cc3c2e0265d83486f6c538582151..844a9f80d851d12848c6b3875533bec236e2c8a7 100644 (file)
@@ -74,7 +74,7 @@ st_texture_create(struct st_context *st,
                  GLuint depth0,
                  GLuint compress_byte)
 {
-   struct pipe_texture *pt = CALLOC_STRUCT(pipe_texture);
+   struct pipe_texture pt;
 
    assert(target <= PIPE_TEXTURE_CUBE);
 
@@ -82,25 +82,20 @@ st_texture_create(struct st_context *st,
        _mesa_lookup_enum_by_nr(target),
        _mesa_lookup_enum_by_nr(format), first_level, last_level);
 
-   if (!pt)
-      return NULL;
-
    assert(format);
 
-   pt->target = target;
-   pt->format = format;
-   pt->first_level = first_level;
-   pt->last_level = last_level;
-   pt->width[0] = width0;
-   pt->height[0] = height0;
-   pt->depth[0] = depth0;
-   pt->compressed = compress_byte ? 1 : 0;
-   pt->cpp = pt->compressed ? compress_byte : st_sizeof_format(format);
-   pt->refcount = 1; 
-
-   st->pipe->texture_create(st->pipe, &pt);
-
-   return pt;
+   pt.target = target;
+   pt.format = format;
+   pt.first_level = first_level;
+   pt.last_level = last_level;
+   pt.width[0] = width0;
+   pt.height[0] = height0;
+   pt.depth[0] = depth0;
+   pt.compressed = compress_byte ? 1 : 0;
+   pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format);
+   pt.refcount = 1; 
+
+   return st->pipe->texture_create(st->pipe, &pt);
 }