ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.cpp
Revision: 1.1
Committed: 2001-01-28T14:05:19Z (23 years, 5 months ago) by gbeauche
Branch: MAIN
Log Message:
Mainly changes to the VOSF code:
- improved blitters selection
- improved blitters performance if UNALIGNED_PROFITABLE is set
- cleaned up 8 bpp blitters

File Contents

# Content
1 /*
2 * video_blit.cpp - Video/graphics emulation, blitters
3 *
4 * Basilisk II (C) 1997-2001 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "sysdeps.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27
28 #ifdef ENABLE_VOSF
29 // Format of the target visual
30 struct VisualFormat {
31 int depth; // Screen depth
32 uint32 Rmask, Gmask, Bmask; // RGB mask values
33 uint32 Rshift, Gshift, Bshift; // RGB shift values
34 };
35 static VisualFormat visualFormat;
36
37 /* -------------------------------------------------------------------------- */
38 /* --- Raw Copy / No conversion required --- */
39 /* -------------------------------------------------------------------------- */
40
41 static void Blit_Copy_Raw(uint8 * dest, const uint8 * source, uint32 length)
42 {
43 // This function is likely to be inlined and/or highly optimized
44 memcpy(dest, source, length);
45 }
46
47 /* -------------------------------------------------------------------------- */
48 /* --- RGB 555 --- */
49 /* -------------------------------------------------------------------------- */
50
51 #ifdef WORDS_BIGENDIAN
52 # define FB_FUNC_NAME Blit_RGB555_OBO
53 #else
54 # define FB_FUNC_NAME Blit_RGB555_NBO
55 #endif
56
57 #define FB_BLIT_1(dst, src) \
58 (dst = (((src) >> 8) & 0xff) | (((src) & 0xff) << 8))
59
60 #define FB_BLIT_2(dst, src) \
61 (dst = (((src) >> 8) & 0x00ff00ff) | (((src) & 0x00ff00ff) << 8))
62
63 #define FB_DEPTH 15
64 #include "video_blit.h"
65
66 /* -------------------------------------------------------------------------- */
67 /* --- BGR 555 --- */
68 /* -------------------------------------------------------------------------- */
69
70 // TODO: BGR 555 (SGI/Irix)
71 // R/G/B mask values: 0x001f, 0x03e0, 0x7c00
72
73 /* -------------------------------------------------------------------------- */
74 /* --- RGB 565 --- */
75 /* -------------------------------------------------------------------------- */
76
77 #ifdef WORDS_BIGENDIAN
78
79 // Native byte order
80
81 #define FB_BLIT_1(dst, src) \
82 (dst = (((src) & 0x1f) | (((src) << 1) & 0xffc0)))
83
84 #define FB_BLIT_2(dst, src) \
85 (dst = (((src) & 0x001f001f) | (((src) << 1) & 0xffc0ffc0)))
86
87 #define FB_DEPTH 16
88 #define FB_FUNC_NAME Blit_RGB565_NBO
89 #include "video_blit.h"
90
91 // Opposite byte order
92
93 #define FB_BLIT_1(dst, src) \
94 (dst = ((((src) >> 7) & 0xff) | (((src) << 9) & 0xc000) | (((src) << 8) & 0x1f00)))
95
96 #define FB_BLIT_2(dst, src) \
97 (dst = ((((src) >> 7) & 0x00ff00ff) | (((src) << 9) & 0xc000c000) | (((src) << 8) & 0x1f001f00)))
98
99 #define FB_DEPTH 16
100 #define FB_FUNC_NAME Blit_RGB565_OBO
101 #include "video_blit.h"
102
103 #else
104
105 // Native byte order
106
107 #define FB_BLIT_1(dst, src) \
108 (dst = (((src) >> 8) & 0x001f) | (((src) << 9) & 0xfe00) | (((src) >> 7) & 0x01c0))
109
110 // gb-- Disabled because I don't see any improvement
111 #if 0 && defined(__i386__) && defined(X86_ASSEMBLY)
112
113 #define FB_BLIT_2(dst, src) \
114 __asm__ ( "movl %0,%%ebx\n\t" \
115 "movl %0,%%ebp\n\t" \
116 "andl $0x1f001f00,%%ebx\n\t" \
117 "andl $0x007f007f,%0\n\t" \
118 "andl $0xe000e000,%%ebp\n\t" \
119 "shrl $8,%%ebx\n\t" \
120 "shrl $7,%%ebp\n\t" \
121 "shll $9,%0\n\t" \
122 "orl %%ebx,%%ebp\n\t" \
123 "orl %%ebp,%0\n\t" \
124 : "=r" (dst) : "0" (src) : "ebx", "ebp", "cc" )
125
126 #else
127
128 #define FB_BLIT_2(dst, src) \
129 (dst = (((src) >> 8) & 0x001f001f) | (((src) << 9) & 0xfe00fe00) | (((src) >> 7) & 0x01c001c0))
130
131 #endif
132
133 #define FB_DEPTH 16
134 #define FB_FUNC_NAME Blit_RGB565_NBO
135 #include "video_blit.h"
136
137 // Opposite byte order (untested)
138
139 #define FB_BLIT_1(dst, src) \
140 (dst = (((src) & 0x1f00) | (((src) << 1) & 0xe0fe) | (((src) >> 15) & 1)))
141
142 #define FB_BLIT_2(dst, src) \
143 (dst = (((src) & 0x1f001f00) | (((src) << 1) & 0xe0fee0fe) | (((src) >> 15) & 0x10001)))
144
145 #define FB_DEPTH 16
146 #define FB_FUNC_NAME Blit_RGB565_OBO
147 #include "video_blit.h"
148
149 #endif
150
151 /* -------------------------------------------------------------------------- */
152 /* --- RGB 888 --- */
153 /* -------------------------------------------------------------------------- */
154
155 #ifdef WORDS_BIGENDIAN
156 # define FB_FUNC_NAME Blit_RGB888_OBO
157 #else
158 # define FB_FUNC_NAME Blit_RGB888_NBO
159 #endif
160
161 #define FB_BLIT_2(dst, src) \
162 (dst = (((src) >> 24) & 0xff) | (((src) >> 8) & 0xff00) | (((src) & 0xff00) << 8) | (((src) & 0xff) << 24))
163
164 #define FB_DEPTH 24
165 #include "video_blit.h"
166
167 /* -------------------------------------------------------------------------- */
168 /* --- BGR 888 --- */
169 /* -------------------------------------------------------------------------- */
170
171 // Native byte order (untested)
172
173 #ifdef WORDS_BIGENDIAN
174
175 #define FB_BLIT_2(dst, src) \
176 (dst = (((src) >> 16) & 0xff) | ((src) & 0xff00) | (((src) & 0xff) << 16))
177
178 #define FB_FUNC_NAME Blit_BGR888_NBO
179 #define FB_DEPTH 24
180 #include "video_blit.h"
181
182 #else
183
184 #define FB_BLIT_2(dst, src) \
185 (dst = (((src) >> 16) & 0xff) | ((src) & 0xff0000) | (((src) & 0xff) << 16))
186
187 #define FB_FUNC_NAME Blit_BGR888_OBO
188 #define FB_DEPTH 24
189 #include "video_blit.h"
190
191 #endif
192
193 // Opposite byte order (untested)
194
195 #ifdef WORDS_BIGENDIAN
196 # define FB_FUNC_NAME Blit_BGR888_OBO
197 #else
198 # define FB_FUNC_NAME Blit_BGR888_NBO
199 #endif
200
201 #define FB_BLIT_2(dst, src) \
202 (dst = ((src) & 0xff00ff) | (((src) & 0xff00) << 16))
203
204 #define FB_DEPTH 24
205 #include "video_blit.h"
206
207 /* -------------------------------------------------------------------------- */
208 /* --- Blitters to the host frame buffer, or XImage buffer --- */
209 /* -------------------------------------------------------------------------- */
210
211 // Function used to update the hosst frame buffer (DGA), or an XImage buffer (WIN)
212 // --> Shall be initialized only through the Screen_blitter_init() function
213 typedef void (*Screen_blit_func)(uint8 * dest, const uint8 * source, uint32 length);
214 Screen_blit_func Screen_blit = 0;
215
216 // Structure used to match the adequate framebuffer update function
217 struct Screen_blit_func_info {
218 int depth; // Screen depth
219 uint32 Rmask; // Red mask
220 uint32 Gmask; // Green mask
221 uint32 Bmask; // Blue mask
222 Screen_blit_func handler_nbo; // Update function (native byte order)
223 Screen_blit_func handler_obo; // Update function (opposite byte order)
224 };
225
226 // Table of visual formats supported and their respective handler
227 static Screen_blit_func_info Screen_blitters[] = {
228 #ifdef WORDS_BIGENDIAN
229 { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
230 { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
231 { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw , Blit_RGB555_OBO }, // OK (OBO)
232 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (OBO)
233 { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK (OBO)
234 { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
235 { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK (OBO)
236 { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // NT
237 #else
238 { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
239 { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
240 { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO)
241 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (NBO)
242 { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
243 { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
244 { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
245 { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // NT
246 #endif
247 };
248
249 // Initialize the framebuffer update function
250 // Returns FALSE, if the function was to be reduced to a simple memcpy()
251 // --> In that case, VOSF is not necessary
252 bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order)
253 {
254 visualFormat.depth = visual_info->depth;
255 visualFormat.Rmask = visual_info->red_mask;
256 visualFormat.Gmask = visual_info->green_mask;
257 visualFormat.Bmask = visual_info->blue_mask;
258
259 // Compute RGB shift values
260 visualFormat.Rshift = 0;
261 for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
262 ++visualFormat.Rshift;
263 visualFormat.Gshift = 0;
264 for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
265 ++visualFormat.Gshift;
266 visualFormat.Bshift = 0;
267 for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
268 ++visualFormat.Bshift;
269
270 // Search for an adequate blit function
271 bool blitter_found = false;
272 const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
273 for (int i = 0; !blitter_found && (i < blitters_count); i++) {
274 if ( (visualFormat.depth == Screen_blitters[i].depth)
275 && (visualFormat.Rmask == Screen_blitters[i].Rmask)
276 && (visualFormat.Gmask == Screen_blitters[i].Gmask)
277 && (visualFormat.Bmask == Screen_blitters[i].Bmask)
278 )
279 {
280 blitter_found = true;
281 Screen_blit = native_byte_order
282 ? Screen_blitters[i].handler_nbo
283 : Screen_blitters[i].handler_obo
284 ;
285 }
286 }
287
288 // No appropriate blitter found, dump RGB mask values and abort()
289 if (!blitter_found) {
290 fprintf(stderr, "### No appropriate blitter found\n");
291 fprintf(stderr, "\tR/G/B mask values : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
292 visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
293 fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
294 visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
295 abort();
296 }
297
298 // If the blitter simply reduces to a copy, we don't need VOSF in DGA mode
299 // --> In that case, we return FALSE
300 return (Screen_blit != Blit_Copy_Raw);
301 }
302 #endif /* ENABLE_VOSF */