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 dri_sw_displaytarget
48 struct sw_winsys base
;
51 static INLINE
struct dri_sw_displaytarget
*
52 dri_sw_displaytarget( struct sw_displaytarget
*dt
)
54 return (struct dri_sw_displaytarget
*)dt
;
57 static INLINE
struct dri_sw_winsys
*
58 dri_sw_winsys( struct sw_winsys
*ws
)
60 return (struct dri_sw_winsys
*)ws
;
65 dri_sw_is_displaytarget_format_supported( struct sw_winsys
*ws
,
67 enum pipe_format format
)
69 /* TODO: check visuals or other sensible thing here */
73 static struct sw_displaytarget
*
74 dri_sw_displaytarget_create(struct sw_winsys
*winsys
,
76 enum pipe_format format
,
77 unsigned width
, unsigned height
,
81 struct dri_sw_displaytarget
*dri_sw_dt
;
82 unsigned nblocksy
, size
, dri_sw_stride
, format_stride
;
84 dri_sw_dt
= CALLOC_STRUCT(dri_sw_displaytarget
);
88 format_stride
= util_format_get_stride(format
, width
);
89 dri_sw_stride
= align(format_stride
, alignment
);
91 nblocksy
= util_format_get_nblocksy(format
, height
);
92 size
= dri_sw_stride
* nblocksy
;
94 dri_sw_dt
->data
= align_malloc(size
, alignment
);
98 *stride
= dri_sw_stride
;
99 return (struct sw_displaytarget
*)dri_sw_dt
;
108 dri_sw_displaytarget_destroy(struct sw_winsys
*ws
,
109 struct sw_displaytarget
*dt
)
111 struct dri_sw_displaytarget
*dri_sw_dt
= dri_sw_displaytarget(dt
);
113 if (dri_sw_dt
->data
) {
114 FREE(dri_sw_dt
->data
);
121 dri_sw_displaytarget_map(struct sw_winsys
*ws
,
122 struct sw_displaytarget
*dt
,
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
;
131 dri_sw_displaytarget_unmap(struct sw_winsys
*ws
,
132 struct sw_displaytarget
*dt
)
134 struct dri_sw_displaytarget
*dri_sw_dt
= dri_sw_displaytarget(dt
);
135 dri_sw_dt
->mapped
= NULL
;
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
,
149 dri_sw_displaytarget_get_handle(struct sw_winsys
*winsys
,
150 struct sw_displaytarget
*dt
,
151 struct winsys_handle
*whandle
)
158 dri_sw_displaytarget_display(struct sw_winsys
*ws
,
159 struct sw_displaytarget
*dt
,
160 void *context_private
)
167 dri_destroy_sw_winsys(struct sw_winsys
*winsys
)
173 dri_create_sw_winsys(void)
175 struct dri_sw_winsys
*ws
;
177 ws
= CALLOC_STRUCT(dri_sw_winsys
);
181 ws
->base
.destroy
= dri_destroy_sw_winsys
;
183 ws
->base
.is_displaytarget_format_supported
= dri_sw_is_displaytarget_format_supported
;
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
;
191 /* texture functions */
192 ws
->base
.displaytarget_map
= dri_sw_displaytarget_map
;
193 ws
->base
.displaytarget_unmap
= dri_sw_displaytarget_unmap
;
195 ws
->base
.displaytarget_display
= dri_sw_displaytarget_display
;
200 /* vim: set sw=3 ts=8 sts=3 expandtab: */