vc4_bufmgr.h revision 848b8605
1/*
2 * Copyright © 2014 Broadcom
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifndef VC4_BUFMGR_H
25#define VC4_BUFMGR_H
26
27#include <stdint.h>
28#include "util/u_inlines.h"
29
30struct vc4_context;
31
32struct vc4_bo {
33        struct pipe_reference reference;
34        struct vc4_screen *screen;
35        void *map;
36        const char *name;
37        uint32_t handle;
38        uint32_t size;
39
40#ifdef USE_VC4_SIMULATOR
41        void *simulator_winsys_map;
42        uint32_t simulator_winsys_stride;
43#endif
44};
45
46struct vc4_bo *vc4_bo_alloc(struct vc4_screen *screen, uint32_t size,
47                            const char *name);
48struct vc4_bo *vc4_bo_alloc_mem(struct vc4_screen *screen, const void *data,
49                                uint32_t size, const char *name);
50void vc4_bo_free(struct vc4_bo *bo);
51struct vc4_bo *vc4_bo_open_name(struct vc4_screen *screen, uint32_t name,
52                                uint32_t winsys_stride);
53bool vc4_bo_flink(struct vc4_bo *bo, uint32_t *name);
54
55static inline void
56vc4_bo_set_reference(struct vc4_bo **old_bo, struct vc4_bo *new_bo)
57{
58        if (pipe_reference(&(*old_bo)->reference, &new_bo->reference))
59                vc4_bo_free(*old_bo);
60        *old_bo = new_bo;
61}
62
63static inline struct vc4_bo *
64vc4_bo_reference(struct vc4_bo *bo)
65{
66        pipe_reference(NULL, &bo->reference);
67        return bo;
68}
69
70static inline void
71vc4_bo_unreference(struct vc4_bo **bo)
72{
73        if (pipe_reference(&(*bo)->reference, NULL))
74                vc4_bo_free(*bo);
75        *bo = NULL;
76}
77
78
79void *
80vc4_bo_map(struct vc4_bo *bo);
81
82#endif /* VC4_BUFMGR_H */
83
84