1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
5 * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
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"
36 #include "state_tracker/sw_winsys.h"
37 #include "dri_sw_winsys.h"
40 struct xm_displaytarget
48 static INLINE
struct xm_displaytarget
*
49 xm_displaytarget( struct sw_displaytarget
*dt
)
51 return (struct xm_displaytarget
*)dt
;
55 /* pipe_screen::is_format_supported */
57 xm_is_displaytarget_format_supported( struct sw_winsys
*ws
,
59 enum pipe_format format
)
61 /* TODO: check visuals or other sensible thing here */
66 bytes_per_line(unsigned stride
, unsigned mul
)
68 unsigned mask
= mul
- 1;
70 return ((stride
* 8 + mask
) & ~mask
) / 8;
73 /* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */
74 static struct sw_displaytarget
*
75 xm_displaytarget_create(struct sw_winsys
*winsys
,
77 enum pipe_format format
,
78 unsigned width
, unsigned height
,
82 struct xm_displaytarget
*xm_dt
;
83 unsigned nblocksy
, size
, xm_stride
, loader_stride
, format_stride
;
85 xm_dt
= CALLOC_STRUCT(xm_displaytarget
);
89 format_stride
= util_format_get_stride(format
, width
);
90 xm_stride
= align(format_stride
, alignment
);
91 loader_stride
= bytes_per_line(format_stride
, 32);
93 nblocksy
= util_format_get_nblocksy(format
, height
);
94 size
= xm_stride
* nblocksy
;
97 debug_printf("swrast format stride: %8d\n", format_stride
);
98 debug_printf("swrast pipe stride : %8d\n", xm_stride
);
99 debug_printf("swrast loader stride: %8d\n", loader_stride
);
103 * Allocate with the aligned stride required by the pipe but set the stride
104 * to the one hardcoded in the loaders XXX
107 xm_dt
->data
= align_malloc(size
, alignment
);
111 *stride
= loader_stride
;
112 return (struct sw_displaytarget
*)xm_dt
;
120 /* pipe_screen::texture_destroy */
122 xm_displaytarget_destroy(struct sw_winsys
*ws
,
123 struct sw_displaytarget
*dt
)
125 struct xm_displaytarget
*xm_dt
= xm_displaytarget(dt
);
134 /* pipe_context::transfer_map */
136 xm_displaytarget_map(struct sw_winsys
*ws
,
137 struct sw_displaytarget
*dt
,
140 struct xm_displaytarget
*xm_dt
= xm_displaytarget(dt
);
141 xm_dt
->mapped
= xm_dt
->data
;
142 return xm_dt
->mapped
;
145 /* pipe_context::transfer_unmap */
147 xm_displaytarget_unmap(struct sw_winsys
*ws
,
148 struct sw_displaytarget
*dt
)
150 struct xm_displaytarget
*xm_dt
= xm_displaytarget(dt
);
151 xm_dt
->mapped
= NULL
;
154 /* pipe_screen::texture_from_handle */
155 static struct sw_displaytarget
*
156 xm_displaytarget_from_handle(struct sw_winsys
*winsys
,
157 const struct pipe_texture
*templ
,
158 struct winsys_handle
*whandle
,
165 /* pipe_screen::texture_get_handle */
167 xm_displaytarget_get_handle(struct sw_winsys
*winsys
,
168 struct sw_displaytarget
*dt
,
169 struct winsys_handle
*whandle
)
175 /* pipe_screen::flush_frontbuffer */
177 xm_displaytarget_display(struct sw_winsys
*ws
,
178 struct sw_displaytarget
*dt
,
179 void *context_private
)
186 dri_destroy_sw_winsys(struct sw_winsys
*winsys
)
192 dri_create_sw_winsys(void)
194 struct sw_winsys
*ws
;
196 ws
= CALLOC_STRUCT(sw_winsys
);
200 ws
->destroy
= dri_destroy_sw_winsys
;
202 ws
->is_displaytarget_format_supported
= xm_is_displaytarget_format_supported
;
204 /* screen texture functions */
205 ws
->displaytarget_create
= xm_displaytarget_create
;
206 ws
->displaytarget_destroy
= xm_displaytarget_destroy
;
207 ws
->displaytarget_from_handle
= xm_displaytarget_from_handle
;
208 ws
->displaytarget_get_handle
= xm_displaytarget_get_handle
;
210 /* texture functions */
211 ws
->displaytarget_map
= xm_displaytarget_map
;
212 ws
->displaytarget_unmap
= xm_displaytarget_unmap
;
214 ws
->displaytarget_display
= xm_displaytarget_display
;
219 /* vim: set sw=3 ts=8 sts=3 expandtab: */