Merge branch 'gallium-embedded'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_buffer.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "util/u_inlines.h"
30 #include "util/u_memory.h"
31 #include "util/u_math.h"
32
33 #include "lp_winsys.h"
34 #include "lp_screen.h"
35 #include "lp_texture.h"
36 #include "lp_buffer.h"
37
38
39 static void *
40 llvmpipe_buffer_map(struct pipe_screen *screen,
41 struct pipe_buffer *buf,
42 unsigned flags)
43 {
44 struct llvmpipe_buffer *llvmpipe_buf = llvmpipe_buffer(buf);
45 return llvmpipe_buf->data;
46 }
47
48
49 static void
50 llvmpipe_buffer_unmap(struct pipe_screen *screen,
51 struct pipe_buffer *buf)
52 {
53 }
54
55
56 static void
57 llvmpipe_buffer_destroy(struct pipe_buffer *buf)
58 {
59 struct llvmpipe_buffer *sbuf = llvmpipe_buffer(buf);
60
61 if (!sbuf->userBuffer)
62 align_free(sbuf->data);
63
64 FREE(sbuf);
65 }
66
67
68 static struct pipe_buffer *
69 llvmpipe_buffer_create(struct pipe_screen *screen,
70 unsigned alignment,
71 unsigned usage,
72 unsigned size)
73 {
74 struct llvmpipe_buffer *buffer = CALLOC_STRUCT(llvmpipe_buffer);
75
76 pipe_reference_init(&buffer->base.reference, 1);
77 buffer->base.screen = screen;
78 buffer->base.alignment = MAX2(alignment, 16);
79 buffer->base.usage = usage;
80 buffer->base.size = size;
81
82 buffer->data = align_malloc(size, alignment);
83
84 return &buffer->base;
85 }
86
87
88 /**
89 * Create buffer which wraps user-space data.
90 */
91 static struct pipe_buffer *
92 llvmpipe_user_buffer_create(struct pipe_screen *screen,
93 void *ptr,
94 unsigned bytes)
95 {
96 struct llvmpipe_buffer *buffer;
97
98 buffer = CALLOC_STRUCT(llvmpipe_buffer);
99 if(!buffer)
100 return NULL;
101
102 pipe_reference_init(&buffer->base.reference, 1);
103 buffer->base.screen = screen;
104 buffer->base.size = bytes;
105 buffer->userBuffer = TRUE;
106 buffer->data = ptr;
107
108 return &buffer->base;
109 }
110
111
112 static void
113 llvmpipe_fence_reference(struct pipe_screen *screen,
114 struct pipe_fence_handle **ptr,
115 struct pipe_fence_handle *fence)
116 {
117 }
118
119
120 static int
121 llvmpipe_fence_signalled(struct pipe_screen *screen,
122 struct pipe_fence_handle *fence,
123 unsigned flag)
124 {
125 return 0;
126 }
127
128
129 static int
130 llvmpipe_fence_finish(struct pipe_screen *screen,
131 struct pipe_fence_handle *fence,
132 unsigned flag)
133 {
134 return 0;
135 }
136
137
138 void
139 llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen)
140 {
141 screen->buffer_create = llvmpipe_buffer_create;
142 screen->user_buffer_create = llvmpipe_user_buffer_create;
143 screen->buffer_map = llvmpipe_buffer_map;
144 screen->buffer_unmap = llvmpipe_buffer_unmap;
145 screen->buffer_destroy = llvmpipe_buffer_destroy;
146
147 screen->fence_reference = llvmpipe_fence_reference;
148 screen->fence_signalled = llvmpipe_fence_signalled;
149 screen->fence_finish = llvmpipe_fence_finish;
150
151 }