1 /*
2 * Copyright © 2012 Rob Clark <[email protected]>
3 * SPDX-License-Identifier: MIT
4 *
5 * Authors:
6 * Rob Clark <[email protected]>
7 */
8
9 #include "freedreno_surface.h"
10 #include "freedreno_resource.h"
11 #include "freedreno_util.h"
12
13 #include "util/u_inlines.h"
14 #include "util/u_memory.h"
15
16 struct pipe_surface *
fd_create_surface(struct pipe_context * pctx,struct pipe_resource * ptex,const struct pipe_surface * surf_tmpl)17 fd_create_surface(struct pipe_context *pctx, struct pipe_resource *ptex,
18 const struct pipe_surface *surf_tmpl)
19 {
20 struct fd_surface *surface = CALLOC_STRUCT(fd_surface);
21
22 if (!surface)
23 return NULL;
24
25 struct pipe_surface *psurf = &surface->base;
26 unsigned level = surf_tmpl->u.tex.level;
27
28 pipe_reference_init(&psurf->reference, 1);
29 pipe_resource_reference(&psurf->texture, ptex);
30
31 psurf->context = pctx;
32 psurf->format = surf_tmpl->format;
33 psurf->width = u_minify(ptex->width0, level);
34 psurf->height = u_minify(ptex->height0, level);
35 psurf->nr_samples = surf_tmpl->nr_samples;
36
37 if (ptex->target == PIPE_BUFFER) {
38 psurf->u.buf.first_element = surf_tmpl->u.buf.first_element;
39 psurf->u.buf.last_element = surf_tmpl->u.buf.last_element;
40 } else {
41 psurf->u.tex.level = level;
42 psurf->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
43 psurf->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
44 }
45
46 return &surface->base;
47 }
48
49 void
fd_surface_destroy(struct pipe_context * pctx,struct pipe_surface * psurf)50 fd_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)
51 {
52 pipe_resource_reference(&psurf->texture, NULL);
53 FREE(psurf);
54 }
55