1
/**************************************************************************
3
* Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
* The above copyright notice and this permission notice (including the
23
* next paragraph) shall be included in all copies or substantial portions
27
**************************************************************************/
29
* Authors: Thomas Hellstr�m <thomas-at-tungstengraphics-dot-com>
35
#include "dri_bufpool.h"
38
* Buffer pool implementation using DRM buffer objects as DRI buffer objects.
42
pool_create(struct _DriBufferPool *pool,
43
unsigned long size, unsigned flags, unsigned hint,
46
drmBO *buf = (drmBO *) malloc(sizeof(*buf));
48
unsigned pageSize = getpagesize();
53
if ((alignment > pageSize) && (alignment % pageSize)) {
57
ret = drmBOCreate(pool->fd, 0, size, alignment / pageSize,
69
pool_destroy(struct _DriBufferPool *pool, void *private)
72
drmBO *buf = (drmBO *) private;
73
ret = drmBODestroy(pool->fd, buf);
79
pool_map(struct _DriBufferPool *pool, void *private, unsigned flags,
80
int hint, void **virtual)
82
drmBO *buf = (drmBO *) private;
84
return drmBOMap(pool->fd, buf, flags, hint, virtual);
88
pool_unmap(struct _DriBufferPool *pool, void *private)
90
drmBO *buf = (drmBO *) private;
91
return drmBOUnmap(pool->fd, buf);
95
pool_offset(struct _DriBufferPool *pool, void *private)
97
drmBO *buf = (drmBO *) private;
102
pool_flags(struct _DriBufferPool *pool, void *private)
104
drmBO *buf = (drmBO *) private;
110
pool_size(struct _DriBufferPool *pool, void *private)
112
drmBO *buf = (drmBO *) private;
117
pool_fence(struct _DriBufferPool *pool, void *private,
118
struct _DriFenceObject *fence)
121
* Noop. The kernel handles all fencing.
128
pool_kernel(struct _DriBufferPool *pool, void *private)
130
return (drmBO *) private;
134
pool_waitIdle(struct _DriBufferPool *pool, void *private, int lazy)
136
drmBO *buf = (drmBO *) private;
137
return drmBOWaitIdle(pool->fd, buf, (lazy) ? DRM_BO_HINT_WAIT_LAZY:0);
142
pool_takedown(struct _DriBufferPool *pool)
148
struct _DriBufferPool *
149
driDRMPoolInit(int fd)
151
struct _DriBufferPool *pool;
153
pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
159
pool->map = &pool_map;
160
pool->unmap = &pool_unmap;
161
pool->destroy = &pool_destroy;
162
pool->offset = &pool_offset;
163
pool->flags = &pool_flags;
164
pool->size = &pool_size;
165
pool->create = &pool_create;
166
pool->fence = &pool_fence;
167
pool->kernel = &pool_kernel;
168
pool->validate = NULL;
169
pool->setstatic = NULL;
170
pool->waitIdle = &pool_waitIdle;
171
pool->takeDown = &pool_takedown;
178
pool_setstatic(struct _DriBufferPool *pool, unsigned long offset,
179
unsigned long size, void *virtual, unsigned flags)
181
drmBO *buf = (drmBO *) malloc(sizeof(*buf));
187
ret = drmBOCreate(pool->fd, offset, size, 0, NULL, drm_bo_type_fake,
195
buf->virtual = virtual;
201
struct _DriBufferPool *
202
driDRMStaticPoolInit(int fd)
204
struct _DriBufferPool *pool;
206
pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
212
pool->map = &pool_map;
213
pool->unmap = &pool_unmap;
214
pool->destroy = &pool_destroy;
215
pool->offset = &pool_offset;
216
pool->flags = &pool_flags;
217
pool->size = &pool_size;
219
pool->fence = &pool_fence;
220
pool->kernel = &pool_kernel;
221
pool->validate = NULL;
222
pool->setstatic = &pool_setstatic;
223
pool->waitIdle = &pool_waitIdle;
224
pool->takeDown = &pool_takedown;