2 * Copyright © 2007 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
29 #include "dri_bufmgr.h"
31 /** @file dri_bufmgr.c
33 * Convenience functions for buffer management methods.
37 dri_bo_alloc(dri_bufmgr
*bufmgr
, const char *name
, unsigned long size
,
38 unsigned int alignment
, unsigned int location_mask
)
40 assert((location_mask
& ~(DRM_BO_FLAG_MEM_LOCAL
| DRM_BO_FLAG_MEM_TT
|
41 DRM_BO_FLAG_MEM_VRAM
| DRM_BO_FLAG_MEM_PRIV0
|
42 DRM_BO_FLAG_MEM_PRIV1
| DRM_BO_FLAG_MEM_PRIV2
|
43 DRM_BO_FLAG_MEM_PRIV3
|
44 DRM_BO_FLAG_MEM_PRIV4
)) == 0);
46 return bufmgr
->bo_alloc(bufmgr
, name
, size
, alignment
, location_mask
);
50 dri_bo_alloc_static(dri_bufmgr
*bufmgr
, const char *name
, unsigned long offset
,
51 unsigned long size
, void *virtual,
52 unsigned int location_mask
)
54 assert((location_mask
& ~(DRM_BO_FLAG_MEM_LOCAL
| DRM_BO_FLAG_MEM_TT
|
55 DRM_BO_FLAG_MEM_VRAM
| DRM_BO_FLAG_MEM_PRIV0
|
56 DRM_BO_FLAG_MEM_PRIV1
| DRM_BO_FLAG_MEM_PRIV2
|
57 DRM_BO_FLAG_MEM_PRIV3
|
58 DRM_BO_FLAG_MEM_PRIV4
)) == 0);
60 return bufmgr
->bo_alloc_static(bufmgr
, name
, offset
, size
, virtual,
65 dri_bo_reference(dri_bo
*bo
)
67 bo
->bufmgr
->bo_reference(bo
);
71 dri_bo_unreference(dri_bo
*bo
)
76 bo
->bufmgr
->bo_unreference(bo
);
80 dri_bo_map(dri_bo
*buf
, GLboolean write_enable
)
82 return buf
->bufmgr
->bo_map(buf
, write_enable
);
86 dri_bo_unmap(dri_bo
*buf
)
88 return buf
->bufmgr
->bo_unmap(buf
);
92 dri_bo_validate(dri_bo
*buf
, unsigned int flags
)
94 return buf
->bufmgr
->bo_validate(buf
, flags
);
98 dri_fence_validated(dri_bufmgr
*bufmgr
, const char *name
, GLboolean flushed
)
100 return bufmgr
->fence_validated(bufmgr
, name
, flushed
);
104 dri_fence_wait(dri_fence
*fence
)
106 fence
->bufmgr
->fence_wait(fence
);
110 dri_fence_reference(dri_fence
*fence
)
112 fence
->bufmgr
->fence_reference(fence
);
116 dri_fence_unreference(dri_fence
*fence
)
121 fence
->bufmgr
->fence_unreference(fence
);
125 dri_bo_subdata(dri_bo
*bo
, unsigned long offset
,
126 unsigned long size
, const void *data
)
128 if (size
== 0 || data
== NULL
)
131 dri_bo_map(bo
, GL_TRUE
);
132 memcpy((unsigned char *)bo
->virtual + offset
, data
, size
);
137 dri_bo_get_subdata(dri_bo
*bo
, unsigned long offset
,
138 unsigned long size
, void *data
)
140 if (size
== 0 || data
== NULL
)
143 dri_bo_map(bo
, GL_FALSE
);
144 memcpy(data
, (unsigned char *)bo
->virtual + offset
, size
);
149 dri_bufmgr_destroy(dri_bufmgr
*bufmgr
)
151 bufmgr
->destroy(bufmgr
);