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 #include "util/simple_list.h"
32 
33 #include "tr_screen.h"
34 #include "tr_context.h"
35 #include "tr_texture.h"
36 
37 
38 struct pipe_surface *
trace_surf_create(struct trace_context * tr_ctx,struct pipe_resource * res,struct pipe_surface * surface)39 trace_surf_create(struct trace_context *tr_ctx,
40                   struct pipe_resource *res,
41                   struct pipe_surface *surface)
42 {
43    struct trace_surface *tr_surf;
44 
45    if (!surface)
46       goto error;
47 
48    assert(surface->texture == res);
49 
50    tr_surf = CALLOC_STRUCT(trace_surface);
51    if (!tr_surf)
52       goto error;
53 
54    memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
55    tr_surf->base.context = &tr_ctx->base;
56 
57    pipe_reference_init(&tr_surf->base.reference, 1);
58    tr_surf->base.texture = NULL;
59    pipe_resource_reference(&tr_surf->base.texture, res);
60    tr_surf->surface = surface;
61 
62    return &tr_surf->base;
63 
64 error:
65    pipe_surface_reference(&surface, NULL);
66    return NULL;
67 }
68 
69 
70 void
trace_surf_destroy(struct trace_surface * tr_surf)71 trace_surf_destroy(struct trace_surface *tr_surf)
72 {
73    pipe_resource_reference(&tr_surf->base.texture, NULL);
74    pipe_surface_reference(&tr_surf->surface, NULL);
75    FREE(tr_surf);
76 }
77 
78 
79 struct pipe_transfer *
trace_transfer_create(struct trace_context * tr_ctx,struct pipe_resource * res,struct pipe_transfer * transfer)80 trace_transfer_create(struct trace_context *tr_ctx,
81 		      struct pipe_resource *res,
82 		      struct pipe_transfer *transfer)
83 {
84    struct trace_transfer *tr_trans;
85 
86    if (!transfer)
87       goto error;
88 
89    tr_trans = CALLOC_STRUCT(trace_transfer);
90    if (!tr_trans)
91       goto error;
92 
93    memcpy(&tr_trans->base, transfer, tr_ctx->threaded ? sizeof(struct threaded_transfer) : sizeof(struct pipe_transfer));
94 
95    tr_trans->base.b.resource = NULL;
96    tr_trans->transfer = transfer;
97 
98    pipe_resource_reference(&tr_trans->base.b.resource, res);
99    assert(tr_trans->base.b.resource == res);
100 
101    return &tr_trans->base.b;
102 
103 error:
104    if (res->target == PIPE_BUFFER)
105       tr_ctx->pipe->buffer_unmap(tr_ctx->pipe, transfer);
106    else
107       tr_ctx->pipe->texture_unmap(tr_ctx->pipe, transfer);
108    return NULL;
109 }
110 
111 
112 void
trace_transfer_destroy(struct trace_context * tr_context,struct trace_transfer * tr_trans)113 trace_transfer_destroy(struct trace_context *tr_context,
114                        struct trace_transfer *tr_trans)
115 {
116    pipe_resource_reference(&tr_trans->base.b.resource, NULL);
117    FREE(tr_trans);
118 }
119 
120