1/* 2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robclark@freedesktop.org> 25 */ 26 27#include "freedreno_surface.h" 28#include "freedreno_resource.h" 29#include "freedreno_util.h" 30 31#include "util/u_memory.h" 32#include "util/u_inlines.h" 33 34struct pipe_surface * 35fd_create_surface(struct pipe_context *pctx, 36 struct pipe_resource *ptex, 37 const struct pipe_surface *surf_tmpl) 38{ 39// struct fd_resource* tex = fd_resource(ptex); 40 struct fd_surface* surface = CALLOC_STRUCT(fd_surface); 41 42 if (!surface) 43 return NULL; 44 45 46 struct pipe_surface *psurf = &surface->base; 47 unsigned level = surf_tmpl->u.tex.level; 48 49 pipe_reference_init(&psurf->reference, 1); 50 pipe_resource_reference(&psurf->texture, ptex); 51 52 psurf->context = pctx; 53 psurf->format = surf_tmpl->format; 54 psurf->width = u_minify(ptex->width0, level); 55 psurf->height = u_minify(ptex->height0, level); 56 psurf->nr_samples = surf_tmpl->nr_samples; 57 58 if (ptex->target == PIPE_BUFFER) { 59 psurf->u.buf.first_element = surf_tmpl->u.buf.first_element; 60 psurf->u.buf.last_element = surf_tmpl->u.buf.last_element; 61 } else { 62 debug_assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); 63 psurf->u.tex.level = level; 64 psurf->u.tex.first_layer = surf_tmpl->u.tex.first_layer; 65 psurf->u.tex.last_layer = surf_tmpl->u.tex.last_layer; 66 } 67 68 // TODO 69 DBG("TODO: %ux%u", psurf->width, psurf->height); 70 71 return &surface->base; 72} 73 74void 75fd_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf) 76{ 77 pipe_resource_reference(&psurf->texture, NULL); 78 FREE(psurf); 79} 80