ws/sw/dri: s/xm/dri_sw/
[mesa.git] / src / gallium / winsys / sw / dri / dri_sw_winsys.c
1 /**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
4 * All Rights Reserved.
5 * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_format.h"
31 #include "util/u_inlines.h"
32 #include "util/u_format.h"
33 #include "util/u_math.h"
34 #include "util/u_memory.h"
35
36 #include "state_tracker/sw_winsys.h"
37 #include "dri_sw_winsys.h"
38
39
40 struct dri_sw_displaytarget
41 {
42 void *data;
43 void *mapped;
44 };
45
46 struct dri_sw_winsys
47 {
48 struct sw_winsys base;
49 };
50
51 static INLINE struct dri_sw_displaytarget *
52 dri_sw_displaytarget( struct sw_displaytarget *dt )
53 {
54 return (struct dri_sw_displaytarget *)dt;
55 }
56
57 static INLINE struct dri_sw_winsys *
58 dri_sw_winsys( struct sw_winsys *ws )
59 {
60 return (struct dri_sw_winsys *)ws;
61 }
62
63
64 static boolean
65 dri_sw_is_displaytarget_format_supported( struct sw_winsys *ws,
66 unsigned tex_usage,
67 enum pipe_format format )
68 {
69 /* TODO: check visuals or other sensible thing here */
70 return TRUE;
71 }
72
73 static struct sw_displaytarget *
74 dri_sw_displaytarget_create(struct sw_winsys *winsys,
75 unsigned tex_usage,
76 enum pipe_format format,
77 unsigned width, unsigned height,
78 unsigned alignment,
79 unsigned *stride)
80 {
81 struct dri_sw_displaytarget *dri_sw_dt;
82 unsigned nblocksy, size, dri_sw_stride, format_stride;
83
84 dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget);
85 if(!dri_sw_dt)
86 goto no_dt;
87
88 format_stride = util_format_get_stride(format, width);
89 dri_sw_stride = align(format_stride, alignment);
90
91 nblocksy = util_format_get_nblocksy(format, height);
92 size = dri_sw_stride * nblocksy;
93
94 dri_sw_dt->data = align_malloc(size, alignment);
95 if(!dri_sw_dt->data)
96 goto no_data;
97
98 *stride = dri_sw_stride;
99 return (struct sw_displaytarget *)dri_sw_dt;
100
101 no_data:
102 FREE(dri_sw_dt);
103 no_dt:
104 return NULL;
105 }
106
107 static void
108 dri_sw_displaytarget_destroy(struct sw_winsys *ws,
109 struct sw_displaytarget *dt)
110 {
111 struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
112
113 if (dri_sw_dt->data) {
114 FREE(dri_sw_dt->data);
115 }
116
117 FREE(dri_sw_dt);
118 }
119
120 static void *
121 dri_sw_displaytarget_map(struct sw_winsys *ws,
122 struct sw_displaytarget *dt,
123 unsigned flags)
124 {
125 struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
126 dri_sw_dt->mapped = dri_sw_dt->data;
127 return dri_sw_dt->mapped;
128 }
129
130 static void
131 dri_sw_displaytarget_unmap(struct sw_winsys *ws,
132 struct sw_displaytarget *dt)
133 {
134 struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
135 dri_sw_dt->mapped = NULL;
136 }
137
138 static struct sw_displaytarget *
139 dri_sw_displaytarget_from_handle(struct sw_winsys *winsys,
140 const struct pipe_texture *templ,
141 struct winsys_handle *whandle,
142 unsigned *stride)
143 {
144 assert(0);
145 return NULL;
146 }
147
148 static boolean
149 dri_sw_displaytarget_get_handle(struct sw_winsys *winsys,
150 struct sw_displaytarget *dt,
151 struct winsys_handle *whandle)
152 {
153 assert(0);
154 return FALSE;
155 }
156
157 static void
158 dri_sw_displaytarget_display(struct sw_winsys *ws,
159 struct sw_displaytarget *dt,
160 void *context_private)
161 {
162 assert(0);
163 }
164
165
166 static void
167 dri_destroy_sw_winsys(struct sw_winsys *winsys)
168 {
169 FREE(winsys);
170 }
171
172 struct sw_winsys *
173 dri_create_sw_winsys(void)
174 {
175 struct dri_sw_winsys *ws;
176
177 ws = CALLOC_STRUCT(dri_sw_winsys);
178 if (!ws)
179 return NULL;
180
181 ws->base.destroy = dri_destroy_sw_winsys;
182
183 ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported;
184
185 /* screen texture functions */
186 ws->base.displaytarget_create = dri_sw_displaytarget_create;
187 ws->base.displaytarget_destroy = dri_sw_displaytarget_destroy;
188 ws->base.displaytarget_from_handle = dri_sw_displaytarget_from_handle;
189 ws->base.displaytarget_get_handle = dri_sw_displaytarget_get_handle;
190
191 /* texture functions */
192 ws->base.displaytarget_map = dri_sw_displaytarget_map;
193 ws->base.displaytarget_unmap = dri_sw_displaytarget_unmap;
194
195 ws->base.displaytarget_display = dri_sw_displaytarget_display;
196
197 return &ws->base;
198 }
199
200 /* vim: set sw=3 ts=8 sts=3 expandtab: */