Path: blob/21.2-virgl/src/gallium/drivers/freedreno/freedreno_surface.c
4570 views
/*1* Copyright (C) 2012 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#include "freedreno_surface.h"27#include "freedreno_resource.h"28#include "freedreno_util.h"2930#include "util/u_inlines.h"31#include "util/u_memory.h"3233struct pipe_surface *34fd_create_surface(struct pipe_context *pctx, struct pipe_resource *ptex,35const struct pipe_surface *surf_tmpl)36{37struct fd_surface *surface = CALLOC_STRUCT(fd_surface);3839if (!surface)40return NULL;4142struct pipe_surface *psurf = &surface->base;43unsigned level = surf_tmpl->u.tex.level;4445pipe_reference_init(&psurf->reference, 1);46pipe_resource_reference(&psurf->texture, ptex);4748psurf->context = pctx;49psurf->format = surf_tmpl->format;50psurf->width = u_minify(ptex->width0, level);51psurf->height = u_minify(ptex->height0, level);52psurf->nr_samples = surf_tmpl->nr_samples;5354if (ptex->target == PIPE_BUFFER) {55psurf->u.buf.first_element = surf_tmpl->u.buf.first_element;56psurf->u.buf.last_element = surf_tmpl->u.buf.last_element;57} else {58psurf->u.tex.level = level;59psurf->u.tex.first_layer = surf_tmpl->u.tex.first_layer;60psurf->u.tex.last_layer = surf_tmpl->u.tex.last_layer;61}6263return &surface->base;64}6566void67fd_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)68{69pipe_resource_reference(&psurf->texture, NULL);70FREE(psurf);71}727374