1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#include "i915_sw_winsys.h"
#include "util/u_memory.h"
static struct i915_winsys_buffer *
i915_sw_buffer_create(struct i915_winsys *iws,
unsigned size,
enum i915_winsys_buffer_type type)
{
struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer);
if (!buf)
return NULL;
buf->magic = 0xDEAD1337;
buf->type = type;
buf->ptr = CALLOC(size, 1);
if (!buf->ptr)
goto err;
return (struct i915_winsys_buffer *)buf;
err:
assert(0);
FREE(buf);
return NULL;
}
static struct i915_winsys_buffer *
i915_sw_buffer_create_tiled(struct i915_winsys *iws,
unsigned *stride, unsigned height,
enum i915_winsys_buffer_tile *tiling,
enum i915_winsys_buffer_type type)
{
struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer);
if (!buf)
return NULL;
buf->magic = 0xDEAD1337;
buf->type = type;
buf->ptr = CALLOC(*stride * height, 1);
buf->tiling = *tiling;
buf->stride = *stride;
if (!buf->ptr)
goto err;
return (struct i915_winsys_buffer *)buf;
err:
assert(0);
FREE(buf);
return NULL;
}
static void *
i915_sw_buffer_map(struct i915_winsys *iws,
struct i915_winsys_buffer *buffer,
boolean write)
{
struct i915_sw_buffer *buf = i915_sw_buffer(buffer);
buf->map_count += 1;
return buf->ptr;
}
static void
i915_sw_buffer_unmap(struct i915_winsys *iws,
struct i915_winsys_buffer *buffer)
{
struct i915_sw_buffer *buf = i915_sw_buffer(buffer);
buf->map_count -= 1;
}
static int
i915_sw_buffer_write(struct i915_winsys *iws,
struct i915_winsys_buffer *buffer,
size_t offset,
size_t size,
const void *data)
{
struct i915_sw_buffer *buf = i915_sw_buffer(buffer);
memcpy((char*)buf->ptr + offset, data, size);
return 0;
}
static void
i915_sw_buffer_destroy(struct i915_winsys *iws,
struct i915_winsys_buffer *buffer)
{
struct i915_sw_buffer *buf = i915_sw_buffer(buffer);
#ifdef DEBUG
buf->magic = 0;
#endif
FREE(buf->ptr);
FREE(buf);
}
void
i915_sw_winsys_init_buffer_functions(struct i915_sw_winsys *isws)
{
isws->base.buffer_create = i915_sw_buffer_create;
isws->base.buffer_create_tiled = i915_sw_buffer_create_tiled;
isws->base.buffer_map = i915_sw_buffer_map;
isws->base.buffer_unmap = i915_sw_buffer_unmap;
isws->base.buffer_write = i915_sw_buffer_write;
isws->base.buffer_destroy = i915_sw_buffer_destroy;
}
|