Path: blob/21.2-virgl/src/gallium/auxiliary/driver_trace/tr_texture.c
4565 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "util/u_inlines.h"28#include "util/u_hash_table.h"29#include "util/u_memory.h"30#include "util/simple_list.h"3132#include "tr_screen.h"33#include "tr_context.h"34#include "tr_texture.h"353637struct pipe_surface *38trace_surf_create(struct trace_context *tr_ctx,39struct pipe_resource *res,40struct pipe_surface *surface)41{42struct trace_surface *tr_surf;4344if (!surface)45goto error;4647assert(surface->texture == res);4849tr_surf = CALLOC_STRUCT(trace_surface);50if (!tr_surf)51goto error;5253memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));54tr_surf->base.context = &tr_ctx->base;5556pipe_reference_init(&tr_surf->base.reference, 1);57tr_surf->base.texture = NULL;58pipe_resource_reference(&tr_surf->base.texture, res);59tr_surf->surface = surface;6061return &tr_surf->base;6263error:64pipe_surface_reference(&surface, NULL);65return NULL;66}676869void70trace_surf_destroy(struct trace_surface *tr_surf)71{72pipe_resource_reference(&tr_surf->base.texture, NULL);73pipe_surface_reference(&tr_surf->surface, NULL);74FREE(tr_surf);75}767778struct pipe_transfer *79trace_transfer_create(struct trace_context *tr_ctx,80struct pipe_resource *res,81struct pipe_transfer *transfer)82{83struct trace_transfer *tr_trans;8485if (!transfer)86goto error;8788tr_trans = CALLOC_STRUCT(trace_transfer);89if (!tr_trans)90goto error;9192memcpy(&tr_trans->base, transfer, tr_ctx->threaded ? sizeof(struct threaded_transfer) : sizeof(struct pipe_transfer));9394tr_trans->base.b.resource = NULL;95tr_trans->transfer = transfer;9697pipe_resource_reference(&tr_trans->base.b.resource, res);98assert(tr_trans->base.b.resource == res);99100return &tr_trans->base.b;101102error:103if (res->target == PIPE_BUFFER)104tr_ctx->pipe->buffer_unmap(tr_ctx->pipe, transfer);105else106tr_ctx->pipe->texture_unmap(tr_ctx->pipe, transfer);107return NULL;108}109110111void112trace_transfer_destroy(struct trace_context *tr_context,113struct trace_transfer *tr_trans)114{115pipe_resource_reference(&tr_trans->base.b.resource, NULL);116FREE(tr_trans);117}118119120121