• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_inlines.h"
32 #include "util/u_memory.h"
33 
34 struct pipe_surface *
fd_create_surface(struct pipe_context * pctx,struct pipe_resource * ptex,const struct pipe_surface * surf_tmpl)35 fd_create_surface(struct pipe_context *pctx, struct pipe_resource *ptex,
36                   const struct pipe_surface *surf_tmpl)
37 {
38    struct fd_surface *surface = CALLOC_STRUCT(fd_surface);
39 
40    if (!surface)
41       return NULL;
42 
43    struct pipe_surface *psurf = &surface->base;
44    unsigned level = surf_tmpl->u.tex.level;
45 
46    pipe_reference_init(&psurf->reference, 1);
47    pipe_resource_reference(&psurf->texture, ptex);
48 
49    psurf->context = pctx;
50    psurf->format = surf_tmpl->format;
51    psurf->width = u_minify(ptex->width0, level);
52    psurf->height = u_minify(ptex->height0, level);
53    psurf->nr_samples = surf_tmpl->nr_samples;
54 
55    if (ptex->target == PIPE_BUFFER) {
56       psurf->u.buf.first_element = surf_tmpl->u.buf.first_element;
57       psurf->u.buf.last_element = surf_tmpl->u.buf.last_element;
58    } else {
59       psurf->u.tex.level = level;
60       psurf->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
61       psurf->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
62    }
63 
64    return &surface->base;
65 }
66 
67 void
fd_surface_destroy(struct pipe_context * pctx,struct pipe_surface * psurf)68 fd_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)
69 {
70    pipe_resource_reference(&psurf->texture, NULL);
71    FREE(psurf);
72 }
73