identity: Move sampler view create and destroy to id_objects.c
authorJakob Bornecrantz <jakob@vmware.com>
Sat, 1 May 2010 11:38:25 +0000 (12:38 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Sun, 2 May 2010 23:27:38 +0000 (00:27 +0100)
src/gallium/drivers/identity/id_context.c
src/gallium/drivers/identity/id_objects.c
src/gallium/drivers/identity/id_objects.h

index 90a669d51898a4f5f5ed35d219e666ea0172d58f..7e62213597c5241f0d123b86aeeeedc566fbf75e 100644 (file)
@@ -700,43 +700,31 @@ identity_is_resource_referenced(struct pipe_context *_pipe,
 }
 
 static struct pipe_sampler_view *
-identity_create_sampler_view(struct pipe_context *pipe,
-                             struct pipe_resource *resource,
-                             const struct pipe_sampler_view *templ)
+identity_context_create_sampler_view(struct pipe_context *_pipe,
+                                     struct pipe_resource *_resource,
+                                     const struct pipe_sampler_view *templ)
 {
-   struct identity_context *id_pipe = identity_context(pipe);
-   struct identity_resource *id_resource = identity_resource(resource);
-   struct pipe_context *pipe_unwrapped = id_pipe->pipe;
-   struct pipe_resource *resource_unwrapped = id_resource->resource;
-   struct identity_sampler_view *view = MALLOC(sizeof(struct identity_sampler_view));
-
-   view->sampler_view = pipe_unwrapped->create_sampler_view(pipe_unwrapped,
-                                                            resource_unwrapped,
-                                                            templ);
+   struct identity_context *id_context = identity_context(_pipe);
+   struct identity_resource *id_resource = identity_resource(_resource);
+   struct pipe_context *pipe = id_context->pipe;
+   struct pipe_resource *resource = id_resource->resource;
+   struct pipe_sampler_view *result;
 
-   view->base = *templ;
-   view->base.reference.count = 1;
-   view->base.texture = NULL;
-   pipe_resource_reference(&view->base.texture, resource);
-   view->base.context = pipe;
+   result = pipe->create_sampler_view(pipe,
+                                      resource,
+                                      templ);
 
-   return &view->base;
+   if (result)
+      return identity_sampler_view_create(id_context, id_resource, result);
+   return NULL;
 }
 
 static void
-identity_sampler_view_destroy(struct pipe_context *pipe,
-                              struct pipe_sampler_view *view)
+identity_context_sampler_view_destroy(struct pipe_context *_pipe,
+                                      struct pipe_sampler_view *_view)
 {
-   struct identity_context *id_pipe = identity_context(pipe);
-   struct identity_sampler_view *id_view = identity_sampler_view(view);
-   struct pipe_context *pipe_unwrapped = id_pipe->pipe;
-   struct pipe_sampler_view *view_unwrapped = id_view->sampler_view;
-
-   pipe_unwrapped->sampler_view_destroy(pipe_unwrapped,
-                                        view_unwrapped);
-
-   pipe_resource_reference(&view->texture, NULL);
-   FREE(view);
+   identity_sampler_view_destroy(identity_context(_pipe),
+                                 identity_sampler_view(_view));
 }
 
 static struct pipe_transfer *
@@ -905,8 +893,8 @@ identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    id_pipe->base.clear = identity_clear;
    id_pipe->base.flush = identity_flush;
    id_pipe->base.is_resource_referenced = identity_is_resource_referenced;
-   id_pipe->base.create_sampler_view = identity_create_sampler_view;
-   id_pipe->base.sampler_view_destroy = identity_sampler_view_destroy;
+   id_pipe->base.create_sampler_view = identity_context_create_sampler_view;
+   id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy;
    id_pipe->base.get_transfer = identity_context_get_transfer;
    id_pipe->base.transfer_destroy = identity_context_transfer_destroy;
    id_pipe->base.transfer_map = identity_context_transfer_map;
index 5070c0475d39e5a1461ea1ffcd7841ed91e39217..ca4743f9ef725d2e33ce4ecaf60188d134b5f9fb 100644 (file)
@@ -108,6 +108,42 @@ identity_surface_destroy(struct identity_surface *id_surface)
 }
 
 
+struct pipe_sampler_view *
+identity_sampler_view_create(struct identity_context *id_context,
+                             struct identity_resource *id_resource,
+                             struct pipe_sampler_view *view)
+{
+   struct identity_sampler_view *id_view;
+
+   if (!view)
+      goto error;
+
+   assert(view->texture == id_resource->resource);
+
+   id_view = MALLOC(sizeof(struct identity_sampler_view));
+
+   id_view->base = *view;
+   id_view->base.reference.count = 1;
+   id_view->base.texture = NULL;
+   pipe_resource_reference(&id_view->base.texture, id_resource->resource);
+   id_view->base.context = id_context->pipe;
+
+   return &id_view->base;
+error:
+   return NULL;
+}
+
+void
+identity_sampler_view_destroy(struct identity_context *id_context,
+                              struct identity_sampler_view *id_view)
+{
+   pipe_resource_reference(&id_view->base.texture, NULL);
+   id_context->pipe->sampler_view_destroy(id_context->pipe,
+                                          id_view->sampler_view);
+   FREE(id_view);
+}
+
+
 struct pipe_transfer *
 identity_transfer_create(struct identity_context *id_context,
                          struct identity_resource *id_resource,
@@ -144,8 +180,8 @@ identity_transfer_destroy(struct identity_context *id_context,
                           struct identity_transfer *id_transfer)
 {
    pipe_resource_reference(&id_transfer->base.resource, NULL);
-   id_context->pipe->transfer_destroy(id_context->pipe,
-                                      id_transfer->transfer);
+   id_transfer->pipe->transfer_destroy(id_context->pipe,
+                                       id_transfer->transfer);
    FREE(id_transfer);
 }
 
index 611519b6e87aa91f8fc27135d98b43790ad35c8c..5eea10b0b5a7d6494662cb04f048aae2cacc239b 100644 (file)
@@ -154,6 +154,15 @@ identity_surface_create(struct identity_resource *id_resource,
 void
 identity_surface_destroy(struct identity_surface *id_surface);
 
+struct pipe_sampler_view *
+identity_sampler_view_create(struct identity_context *id_context,
+                             struct identity_resource *id_resource,
+                             struct pipe_sampler_view *view);
+
+void
+identity_sampler_view_destroy(struct identity_context *id_context,
+                              struct identity_sampler_view *id_sampler_view);
+
 struct pipe_transfer *
 identity_transfer_create(struct identity_context *id_context,
                          struct identity_resource *id_resource,