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