OSDN Git Service

drm: Add tests for GEM_FLINK ioctl.
[android-x86/external-libdrm.git] / libdrm / dri_bufmgr.c
1 /*
2  * Copyright © 2007 Intel Corporation
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  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27
28 #include <string.h>
29 #include <stdlib.h>
30 #include <assert.h>
31 #include "dri_bufmgr.h"
32
33 /** @file dri_bufmgr.c
34  *
35  * Convenience functions for buffer management methods.
36  */
37
38 dri_bo *
39 dri_bo_alloc(dri_bufmgr *bufmgr, const char *name, unsigned long size,
40              unsigned int alignment)
41 {
42    return bufmgr->bo_alloc(bufmgr, name, size, alignment);
43 }
44
45 void
46 dri_bo_reference(dri_bo *bo)
47 {
48    bo->bufmgr->bo_reference(bo);
49 }
50
51 void
52 dri_bo_unreference(dri_bo *bo)
53 {
54    if (bo == NULL)
55       return;
56
57    bo->bufmgr->bo_unreference(bo);
58 }
59
60 int
61 dri_bo_map(dri_bo *buf, int write_enable)
62 {
63    return buf->bufmgr->bo_map(buf, write_enable);
64 }
65
66 int
67 dri_bo_unmap(dri_bo *buf)
68 {
69    return buf->bufmgr->bo_unmap(buf);
70 }
71
72 int
73 dri_bo_subdata(dri_bo *bo, unsigned long offset,
74                unsigned long size, const void *data)
75 {
76    int ret;
77    if (bo->bufmgr->bo_subdata)
78       return bo->bufmgr->bo_subdata(bo, offset, size, data);
79    if (size == 0 || data == NULL)
80       return 0;
81
82    ret = dri_bo_map(bo, 1);
83    if (ret)
84        return ret;
85    memcpy((unsigned char *)bo->virtual + offset, data, size);
86    dri_bo_unmap(bo);
87    return 0;
88 }
89
90 int
91 dri_bo_get_subdata(dri_bo *bo, unsigned long offset,
92                    unsigned long size, void *data)
93 {
94    int ret;
95    if (bo->bufmgr->bo_subdata)
96       return bo->bufmgr->bo_get_subdata(bo, offset, size, data);
97
98    if (size == 0 || data == NULL)
99       return 0;
100
101    ret = dri_bo_map(bo, 0);
102    if (ret)
103        return ret;
104    memcpy(data, (unsigned char *)bo->virtual + offset, size);
105    dri_bo_unmap(bo);
106    return 0;
107 }
108
109 void
110 dri_bo_wait_rendering(dri_bo *bo)
111 {
112    bo->bufmgr->bo_wait_rendering(bo);
113 }
114
115 void
116 dri_bufmgr_destroy(dri_bufmgr *bufmgr)
117 {
118    bufmgr->destroy(bufmgr);
119 }
120
121 void *dri_process_relocs(dri_bo *batch_buf)
122 {
123    return batch_buf->bufmgr->process_relocs(batch_buf);
124 }
125
126 void dri_post_submit(dri_bo *batch_buf)
127 {
128    batch_buf->bufmgr->post_submit(batch_buf);
129 }
130
131 void
132 dri_bufmgr_set_debug(dri_bufmgr *bufmgr, int enable_debug)
133 {
134    bufmgr->debug = enable_debug;
135 }
136
137 int
138 dri_bufmgr_check_aperture_space(dri_bo **bo_array, int count)
139 {
140         return bo_array[0]->bufmgr->check_aperture_space(bo_array, count);
141 }