• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2008 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include "util/u_inlines.h"
29 #include "util/u_hash_table.h"
30 #include "util/u_memory.h"
31 
32 #include "tr_screen.h"
33 #include "tr_context.h"
34 #include "tr_texture.h"
35 
36 
37 struct pipe_surface *
trace_surf_create(struct trace_context * tr_ctx,struct pipe_resource * res,struct pipe_surface * surface)38 trace_surf_create(struct trace_context *tr_ctx,
39                   struct pipe_resource *res,
40                   struct pipe_surface *surface)
41 {
42    struct trace_surface *tr_surf;
43 
44    if (!surface)
45       goto error;
46 
47    assert(surface->texture == res);
48 
49    tr_surf = CALLOC_STRUCT(trace_surface);
50    if (!tr_surf)
51       goto error;
52 
53    memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
54    tr_surf->base.context = &tr_ctx->base;
55 
56    pipe_reference_init(&tr_surf->base.reference, 1);
57    tr_surf->base.texture = NULL;
58    pipe_resource_reference(&tr_surf->base.texture, res);
59    tr_surf->surface = surface;
60 
61    return &tr_surf->base;
62 
63 error:
64    pipe_surface_reference(&surface, NULL);
65    return NULL;
66 }
67 
68 
69 void
trace_surf_destroy(struct trace_surface * tr_surf)70 trace_surf_destroy(struct trace_surface *tr_surf)
71 {
72    pipe_resource_reference(&tr_surf->base.texture, NULL);
73    pipe_surface_reference(&tr_surf->surface, NULL);
74    FREE(tr_surf);
75 }
76 
77 
78 struct pipe_transfer *
trace_transfer_create(struct trace_context * tr_ctx,struct pipe_resource * res,struct pipe_transfer * transfer)79 trace_transfer_create(struct trace_context *tr_ctx,
80 		      struct pipe_resource *res,
81 		      struct pipe_transfer *transfer)
82 {
83    struct trace_transfer *tr_trans;
84 
85    if (!transfer)
86       goto error;
87 
88    tr_trans = CALLOC_STRUCT(trace_transfer);
89    if (!tr_trans)
90       goto error;
91 
92    memcpy(&tr_trans->base, transfer, tr_ctx->threaded ? sizeof(struct threaded_transfer) : sizeof(struct pipe_transfer));
93 
94    tr_trans->base.b.resource = NULL;
95    tr_trans->transfer = transfer;
96 
97    pipe_resource_reference(&tr_trans->base.b.resource, res);
98    assert(tr_trans->base.b.resource == res);
99 
100    return &tr_trans->base.b;
101 
102 error:
103    if (res->target == PIPE_BUFFER)
104       tr_ctx->pipe->buffer_unmap(tr_ctx->pipe, transfer);
105    else
106       tr_ctx->pipe->texture_unmap(tr_ctx->pipe, transfer);
107    return NULL;
108 }
109 
110 
111 void
trace_transfer_destroy(struct trace_context * tr_context,struct trace_transfer * tr_trans)112 trace_transfer_destroy(struct trace_context *tr_context,
113                        struct trace_transfer *tr_trans)
114 {
115    pipe_resource_reference(&tr_trans->base.b.resource, NULL);
116    FREE(tr_trans);
117 }
118 
119