Rev 3773 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3770 | Serge | 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
17 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
||
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
19 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
20 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
21 | * |
||
22 | * The above copyright notice and this permission notice (including the |
||
23 | * next paragraph) shall be included in all copies or substantial portions |
||
24 | * of the Software. |
||
25 | * |
||
26 | * |
||
27 | **************************************************************************/ |
||
28 | |||
29 | /** |
||
30 | * @file |
||
31 | * GDI software rasterizer support. |
||
32 | * |
||
33 | * @author Jose Fonseca |
||
34 | */ |
||
35 | |||
36 | #include "pipe/p_format.h" |
||
37 | #include "pipe/p_context.h" |
||
38 | #include "util/u_inlines.h" |
||
39 | #include "util/u_format.h" |
||
40 | #include "util/u_math.h" |
||
41 | #include "util/u_memory.h" |
||
42 | #include "state_tracker/sw_winsys.h" |
||
43 | #include |
||
44 | #include "kos_sw_winsys.h" |
||
45 | |||
46 | |||
47 | struct kos_sw_displaytarget |
||
48 | { |
||
49 | enum pipe_format format; |
||
50 | unsigned width; |
||
51 | unsigned height; |
||
52 | unsigned stride; |
||
53 | |||
54 | unsigned size; |
||
55 | |||
56 | void *data; |
||
57 | |||
58 | // BITMAPINFO bmi; |
||
59 | }; |
||
60 | |||
61 | |||
62 | /** Cast wrapper */ |
||
63 | static INLINE struct kos_sw_displaytarget * |
||
64 | kos_sw_displaytarget( struct sw_displaytarget *buf ) |
||
65 | { |
||
66 | return (struct kos_sw_displaytarget *)buf; |
||
67 | } |
||
68 | |||
69 | |||
70 | static boolean |
||
71 | kos_sw_is_displaytarget_format_supported( struct sw_winsys *ws, |
||
72 | unsigned tex_usage, |
||
73 | enum pipe_format format ) |
||
74 | { |
||
75 | switch(format) { |
||
76 | case PIPE_FORMAT_B8G8R8X8_UNORM: |
||
77 | case PIPE_FORMAT_B8G8R8A8_UNORM: |
||
78 | return TRUE; |
||
79 | |||
80 | /* TODO: Support other formats possible with BMPs, as described in |
||
81 | * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */ |
||
82 | |||
83 | default: |
||
84 | return FALSE; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | |||
89 | static void * |
||
90 | kos_sw_displaytarget_map(struct sw_winsys *ws, |
||
91 | struct sw_displaytarget *dt, |
||
92 | unsigned flags ) |
||
93 | { |
||
94 | struct kos_sw_displaytarget *gdt = kos_sw_displaytarget(dt); |
||
95 | |||
96 | return gdt->data; |
||
97 | } |
||
98 | |||
99 | |||
100 | static void |
||
101 | kos_sw_displaytarget_unmap(struct sw_winsys *ws, |
||
102 | struct sw_displaytarget *dt ) |
||
103 | { |
||
104 | |||
105 | } |
||
106 | |||
107 | |||
108 | static void |
||
109 | kos_sw_displaytarget_destroy(struct sw_winsys *winsys, |
||
110 | struct sw_displaytarget *dt) |
||
111 | { |
||
112 | struct kos_sw_displaytarget *gdt = kos_sw_displaytarget(dt); |
||
113 | |||
114 | user_free(gdt->data); |
||
115 | FREE(gdt); |
||
116 | } |
||
117 | |||
118 | |||
119 | static struct sw_displaytarget * |
||
120 | kos_sw_displaytarget_create(struct sw_winsys *winsys, |
||
121 | unsigned tex_usage, |
||
122 | enum pipe_format format, |
||
123 | unsigned width, unsigned height, |
||
124 | unsigned alignment, |
||
125 | unsigned *stride) |
||
126 | { |
||
127 | struct kos_sw_displaytarget *gdt; |
||
128 | unsigned cpp; |
||
129 | unsigned bpp; |
||
130 | |||
131 | gdt = CALLOC_STRUCT(kos_sw_displaytarget); |
||
132 | if(!gdt) |
||
133 | goto no_gdt; |
||
134 | |||
135 | gdt->format = format; |
||
136 | gdt->width = width; |
||
137 | gdt->height = height; |
||
138 | |||
139 | bpp = util_format_get_blocksizebits(format); |
||
140 | cpp = util_format_get_blocksize(format); |
||
141 | |||
142 | gdt->stride = align(width * cpp, alignment); |
||
143 | gdt->size = gdt->stride * height; |
||
144 | |||
145 | gdt->data = user_alloc(gdt->size); |
||
146 | if(!gdt->data) |
||
147 | goto no_data; |
||
148 | |||
149 | *stride = gdt->stride; |
||
150 | return (struct sw_displaytarget *)gdt; |
||
151 | |||
152 | no_data: |
||
153 | FREE(gdt); |
||
154 | no_gdt: |
||
155 | return NULL; |
||
156 | } |
||
157 | |||
158 | |||
159 | static struct sw_displaytarget * |
||
160 | kos_sw_displaytarget_from_handle(struct sw_winsys *winsys, |
||
161 | const struct pipe_resource *templet, |
||
162 | struct winsys_handle *whandle, |
||
163 | unsigned *stride) |
||
164 | { |
||
165 | assert(0); |
||
166 | return NULL; |
||
167 | } |
||
168 | |||
169 | |||
170 | static boolean |
||
171 | kos_sw_displaytarget_get_handle(struct sw_winsys *winsys, |
||
172 | struct sw_displaytarget *dt, |
||
173 | struct winsys_handle *whandle) |
||
174 | { |
||
175 | assert(0); |
||
176 | return FALSE; |
||
177 | } |
||
178 | |||
179 | |||
180 | void |
||
181 | kos_sw_display( struct sw_winsys *winsys, |
||
182 | struct sw_displaytarget *dt) |
||
183 | { |
||
184 | struct kos_sw_displaytarget *gdt = kos_sw_displaytarget(dt); |
||
3773 | Serge | 185 | |
186 | struct blit_call bc; |
||
187 | int ret; |
||
188 | |||
189 | bc.dstx = 0; |
||
190 | bc.dsty = 24; |
||
191 | bc.w = gdt->width; |
||
192 | bc.h = gdt->height; |
||
193 | bc.srcx = 0; |
||
194 | bc.srcy = 0; |
||
195 | bc.srcw = gdt->width; |
||
196 | bc.srch = gdt->height; |
||
197 | bc.stride = gdt->stride; |
||
198 | bc.bitmap = gdt->data; |
||
199 | |||
200 | __asm__ __volatile__( |
||
201 | "int $0x40":"=a"(ret):"a"(73), "b"(0x00), |
||
202 | "c"(&bc):"memory"); |
||
203 | |||
204 | return ret; |
||
3770 | Serge | 205 | |
206 | } |
||
207 | |||
208 | static void |
||
209 | kos_sw_displaytarget_display(struct sw_winsys *winsys, |
||
210 | struct sw_displaytarget *dt, |
||
211 | void *context_private) |
||
212 | { |
||
213 | kos_sw_display(winsys, dt); |
||
214 | } |
||
215 | |||
216 | |||
217 | static void |
||
218 | kos_sw_destroy(struct sw_winsys *winsys) |
||
219 | { |
||
220 | FREE(winsys); |
||
221 | } |
||
222 | |||
223 | struct sw_winsys * |
||
224 | kos_create_sw_winsys(void) |
||
225 | { |
||
226 | static struct sw_winsys *winsys; |
||
227 | |||
228 | winsys = CALLOC_STRUCT(sw_winsys); |
||
229 | if(!winsys) |
||
230 | return NULL; |
||
231 | |||
232 | winsys->destroy = kos_sw_destroy; |
||
233 | winsys->is_displaytarget_format_supported = kos_sw_is_displaytarget_format_supported; |
||
234 | winsys->displaytarget_create = kos_sw_displaytarget_create; |
||
235 | winsys->displaytarget_from_handle = kos_sw_displaytarget_from_handle; |
||
236 | winsys->displaytarget_get_handle = kos_sw_displaytarget_get_handle; |
||
237 | winsys->displaytarget_map = kos_sw_displaytarget_map; |
||
238 | winsys->displaytarget_unmap = kos_sw_displaytarget_unmap; |
||
239 | winsys->displaytarget_display = kos_sw_displaytarget_display; |
||
240 | winsys->displaytarget_destroy = kos_sw_displaytarget_destroy; |
||
241 | |||
242 | return winsys; |
||
243 | } |
||
244 |