ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_blit.cpp (file contents):
Revision 1.1 by gbeauche, 2001-01-28T14:05:19Z vs.
Revision 1.7 by cebix, 2001-07-06T22:00:39Z

# Line 19 | Line 19
19   */
20  
21   #include "sysdeps.h"
22 + #include "video.h"
23  
24   #include <stdio.h>
25   #include <stdlib.h>
# Line 34 | Line 35 | struct VisualFormat {
35   };
36   static VisualFormat visualFormat;
37  
38 + // This holds the pixels values of the palette colors for 8->16/32-bit expansion
39 + uint32 ExpandMap[256];
40 +
41   /* -------------------------------------------------------------------------- */
42   /* --- Raw Copy / No conversion required                                  --- */
43   /* -------------------------------------------------------------------------- */
# Line 67 | Line 71 | static void Blit_Copy_Raw(uint8 * dest,
71   /* --- BGR 555                                                            --- */
72   /* -------------------------------------------------------------------------- */
73  
74 < // TODO: BGR 555 (SGI/Irix)
75 < // R/G/B mask values: 0x001f, 0x03e0, 0x7c00
74 > #ifdef WORDS_BIGENDIAN
75 >
76 > // Native byte order
77 >
78 > #define FB_BLIT_1(dst, src) \
79 >        (dst = (((src) >> 10) & 0x001f) | ((src) & 0x03e0) | (((src) << 10) & 0x7c00))
80 >
81 > #define FB_BLIT_2(dst, src) \
82 >        (dst = (((src) >> 10) & 0x001f001f) | ((src) & 0x03e003e0) | (((src) << 10) & 0x7c007c00))
83 >
84 > #define FB_DEPTH 15
85 > #define FB_FUNC_NAME Blit_BGR555_NBO
86 > #include "video_blit.h"
87 >
88 > // Opposite byte order (untested)
89 >
90 > #define FB_BLIT_1(dst, src) \
91 >        (dst = (((src) >> 2) & 0x1f00) | (((src) >> 8) & 3) | (((src) << 8) & 0xe000) | (((src) << 2) & 0x7c))
92 >
93 > #define FB_BLIT_2(dst, src) \
94 >        (dst = (((src) >> 2) & 0x1f001f00) | (((src) >> 8) & 0x30003) | (((src) << 8) & 0xe000e000) | (((src) << 2) & 0x7c007c))
95 >
96 > #define FB_DEPTH 15
97 > #define FB_FUNC_NAME Blit_BGR555_OBO
98 > #include "video_blit.h"
99 >
100 > #else
101 >
102 > // Native byte order (untested)
103 >
104 > #define FB_BLIT_1(dst, src) \
105 >        (dst = (((src) >> 2) & 0x1f) | (((src) >> 8) & 0xe0) | (((src) << 8) & 0x0300) | (((src) << 2) & 0x7c00))
106 >
107 > #define FB_BLIT_2(dst, src) \
108 >        (dst = (((src) >> 2) & 0x1f001f) | (((src) >> 8) & 0xe000e0) | (((src) << 8) & 0x03000300) | (((src) << 2) & 0x7c007c00))
109 >
110 > #define FB_DEPTH 15
111 > #define FB_FUNC_NAME Blit_BGR555_NBO
112 > #include "video_blit.h"
113 >
114 > // Opposite byte order (untested)
115 >
116 > #define FB_BLIT_1(dst, src) \
117 >        (dst = (((src) << 6) & 0x1f00) | ((src) & 0xe003) | (((src) >> 6) & 0x7c))
118 >
119 > #define FB_BLIT_2(dst, src) \
120 >        (dst = (((src) << 6) & 0x1f001f00) | ((src) & 0xe003e003) | (((src) >> 6) & 0x7c007c))
121 >
122 > #define FB_DEPTH 15
123 > #define FB_FUNC_NAME Blit_BGR555_OBO
124 > #include "video_blit.h"
125 >
126 > #endif
127  
128   /* -------------------------------------------------------------------------- */
129   /* --- RGB 565                                                            --- */
# Line 168 | Line 223 | static void Blit_Copy_Raw(uint8 * dest,
223   /* --- BGR 888                                                            --- */
224   /* -------------------------------------------------------------------------- */
225  
226 < // Native byte order (untested)
226 > // Native byte order [BE] (untested)
227  
228   #ifdef WORDS_BIGENDIAN
229  
# Line 181 | Line 236 | static void Blit_Copy_Raw(uint8 * dest,
236  
237   #else
238  
239 + // Opposite byte order [LE] (untested)
240 +
241   #define FB_BLIT_2(dst, src) \
242          (dst = (((src) >> 16) & 0xff) | ((src) & 0xff0000) | (((src) & 0xff) << 16))
243  
# Line 190 | Line 247 | static void Blit_Copy_Raw(uint8 * dest,
247  
248   #endif
249  
250 < // Opposite byte order (untested)
250 > // Opposite byte order [BE] (untested) / Native byte order [LE] (untested)
251  
252   #ifdef WORDS_BIGENDIAN
253   # define FB_FUNC_NAME Blit_BGR888_OBO
# Line 205 | Line 262 | static void Blit_Copy_Raw(uint8 * dest,
262   #include "video_blit.h"
263  
264   /* -------------------------------------------------------------------------- */
265 + /* --- 2/4-bit indexed to 8-bit mode conversion                           --- */
266 + /* -------------------------------------------------------------------------- */
267 +
268 + static void Blit_Expand_2_To_8(uint8 * dest, const uint8 * p, uint32 length)
269 + {
270 +        uint8 *q = (uint8 *)dest;
271 +        for (int i=0; i<length; i++) {
272 +                uint8 c = *p++;
273 +                *q++ = c >> 6;
274 +                *q++ = (c >> 4) & 3;
275 +                *q++ = (c >> 2) & 3;
276 +                *q++ = c & 3;
277 +        }
278 + }
279 +
280 + static void Blit_Expand_4_To_8(uint8 * dest, const uint8 * p, uint32 length)
281 + {
282 +        uint8 *q = (uint8 *)dest;
283 +        for (int i=0; i<length; i++) {
284 +                uint8 c = *p++;
285 +                *q++ = c >> 4;
286 +                *q++ = c & 0x0f;
287 +        }
288 + }
289 +
290 + /* -------------------------------------------------------------------------- */
291 + /* --- 2/4/8-bit indexed to 16-bit mode color expansion                   --- */
292 + /* -------------------------------------------------------------------------- */
293 +
294 + static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length)
295 + {
296 +        uint16 *q = (uint16 *)dest;
297 +        for (int i=0; i<length; i++) {
298 +                uint8 c = *p++;
299 +                *q++ = ExpandMap[c >> 6];
300 +                *q++ = ExpandMap[c >> 4];
301 +                *q++ = ExpandMap[c >> 2];
302 +                *q++ = ExpandMap[c];
303 +        }
304 + }
305 +
306 + static void Blit_Expand_4_To_16(uint8 * dest, const uint8 * p, uint32 length)
307 + {
308 +        uint16 *q = (uint16 *)dest;
309 +        for (int i=0; i<length; i++) {
310 +                uint8 c = *p++;
311 +                *q++ = ExpandMap[c >> 4];
312 +                *q++ = ExpandMap[c];
313 +        }
314 + }
315 +
316 + static void Blit_Expand_8_To_16(uint8 * dest, const uint8 * p, uint32 length)
317 + {
318 +        uint16 *q = (uint16 *)dest;
319 +        for (int i=0; i<length; i++)
320 +                *q++ = ExpandMap[*p++];
321 + }
322 +
323 + /* -------------------------------------------------------------------------- */
324 + /* --- 2/4/8-bit indexed to 32-bit mode color expansion                   --- */
325 + /* -------------------------------------------------------------------------- */
326 +
327 + static void Blit_Expand_2_To_32(uint8 * dest, const uint8 * p, uint32 length)
328 + {
329 +        uint32 *q = (uint32 *)dest;
330 +        for (int i=0; i<length; i++) {
331 +                uint8 c = *p++;
332 +                *q++ = ExpandMap[c >> 6];
333 +                *q++ = ExpandMap[c >> 4];
334 +                *q++ = ExpandMap[c >> 2];
335 +                *q++ = ExpandMap[c];
336 +        }
337 + }
338 +
339 + static void Blit_Expand_4_To_32(uint8 * dest, const uint8 * p, uint32 length)
340 + {
341 +        uint32 *q = (uint32 *)dest;
342 +        for (int i=0; i<length; i++) {
343 +                uint8 c = *p++;
344 +                *q++ = ExpandMap[c >> 4];
345 +                *q++ = ExpandMap[c];
346 +        }
347 + }
348 +
349 + static void Blit_Expand_8_To_32(uint8 * dest, const uint8 * p, uint32 length)
350 + {
351 +        uint32 *q = (uint32 *)dest;
352 +        for (int i=0; i<length; i++)
353 +                *q++ = ExpandMap[*p++];
354 + }
355 +
356 + /* -------------------------------------------------------------------------- */
357   /* --- Blitters to the host frame buffer, or XImage buffer                --- */
358   /* -------------------------------------------------------------------------- */
359  
# Line 229 | Line 378 | static Screen_blit_func_info Screen_blit
378          {  1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // NT
379          {  8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // OK (NBO)
380          { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw       , Blit_RGB555_OBO       },      // OK (OBO)
381 +        { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO     , Blit_BGR555_OBO       },      // NT
382          { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO     , Blit_RGB565_OBO       },      // OK (OBO)
383          { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK (OBO)
384          { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       },      // NT
385 <        { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK (OBO)
386 <        { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       }       // NT
385 >        { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK
386 >        { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       }       // OK
387   #else
388          {  1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // NT
389          {  8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // OK (NBO)
390          { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO     , Blit_Copy_Raw         },      // OK (NBO)
391 +        { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO     , Blit_BGR555_OBO       },      // NT
392          { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO     , Blit_RGB565_OBO       },      // OK (NBO)
393          { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO     , Blit_Copy_Raw         },      // OK (NBO)
394          { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       },      // NT
# Line 249 | Line 400 | static Screen_blit_func_info Screen_blit
400   // Initialize the framebuffer update function
401   // Returns FALSE, if the function was to be reduced to a simple memcpy()
402   // --> In that case, VOSF is not necessary
403 < bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order)
403 > bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth)
404   {
405 <        visualFormat.depth = visual_info->depth;
406 <        visualFormat.Rmask = visual_info->red_mask;
407 <        visualFormat.Gmask = visual_info->green_mask;
408 <        visualFormat.Bmask = visual_info->blue_mask;
405 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
406 >        if (mac_depth == VDEPTH_1BIT) {
407 >
408 >                // 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines
409 >                Screen_blit = Blit_Copy_Raw;
410 >
411 >        } else {
412 >
413 >                visualFormat.depth = visual_info->depth;
414 >                visualFormat.Rmask = visual_info->red_mask;
415 >                visualFormat.Gmask = visual_info->green_mask;
416 >                visualFormat.Bmask = visual_info->blue_mask;
417 >
418 >                // Compute RGB shift values
419 >                visualFormat.Rshift = 0;
420 >                for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
421 >                        ++visualFormat.Rshift;
422 >                visualFormat.Gshift = 0;
423 >                for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
424 >                        ++visualFormat.Gshift;
425 >                visualFormat.Bshift = 0;
426 >                for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
427 >                        ++visualFormat.Bshift;
428 >
429 >                bool blitter_found = false;
430          
431 <        // Compute RGB shift values
432 <        visualFormat.Rshift = 0;
433 <        for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
434 <                ++visualFormat.Rshift;
435 <        visualFormat.Gshift = 0;
436 <        for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
437 <                ++visualFormat.Gshift;
438 <        visualFormat.Bshift = 0;
439 <        for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
440 <                ++visualFormat.Bshift;
431 >                // 2/4/8-bit mode on 8/16/32-bit screen?
432 >                if (visualFormat.depth == 8) {
433 >                        if (mac_depth == VDEPTH_2BIT) {
434 >                                Screen_blit = Blit_Expand_2_To_8;
435 >                                blitter_found = true;
436 >                        } else if (mac_depth == VDEPTH_4BIT) {
437 >                                Screen_blit = Blit_Expand_4_To_8;
438 >                                blitter_found = true;
439 >                        }
440 >                } else if (visualFormat.depth == 15 || visualFormat.depth == 16) {
441 >                        if (mac_depth == VDEPTH_2BIT) {
442 >                                Screen_blit = Blit_Expand_2_To_16;
443 >                                blitter_found = true;
444 >                        } else if (mac_depth == VDEPTH_4BIT) {
445 >                                Screen_blit = Blit_Expand_4_To_16;
446 >                                blitter_found = true;
447 >                        } else if (mac_depth == VDEPTH_8BIT) {
448 >                                Screen_blit = Blit_Expand_8_To_16;
449 >                                blitter_found = true;
450 >                        }
451 >                } else if (visualFormat.depth == 24 || visualFormat.depth == 32) {
452 >                        if (mac_depth == VDEPTH_2BIT) {
453 >                                Screen_blit = Blit_Expand_2_To_32;
454 >                                blitter_found = true;
455 >                        } else if (mac_depth == VDEPTH_4BIT) {
456 >                                Screen_blit = Blit_Expand_4_To_32;
457 >                                blitter_found = true;
458 >                        } else if (mac_depth == VDEPTH_8BIT) {
459 >                                Screen_blit = Blit_Expand_8_To_32;
460 >                                blitter_found = true;
461 >                        }
462 >                }
463          
464 <        // Search for an adequate blit function
465 <        bool blitter_found = false;
466 <        const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
467 <        for (int i = 0; !blitter_found && (i < blitters_count); i++) {
468 <                if      (       (visualFormat.depth == Screen_blitters[i].depth)
469 <                        &&      (visualFormat.Rmask == Screen_blitters[i].Rmask)
470 <                        &&      (visualFormat.Gmask == Screen_blitters[i].Gmask)
471 <                        &&      (visualFormat.Bmask == Screen_blitters[i].Bmask)
472 <                        )
473 <                {
474 <                        blitter_found = true;
475 <                        Screen_blit = native_byte_order
476 <                                                ? Screen_blitters[i].handler_nbo
477 <                                                : Screen_blitters[i].handler_obo
478 <                                                ;
464 >                // Search for an adequate blit function
465 >                const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
466 >                for (int i = 0; !blitter_found && (i < blitters_count); i++) {
467 >                        if      (       (visualFormat.depth == Screen_blitters[i].depth)
468 >                                &&      (visualFormat.Rmask == Screen_blitters[i].Rmask)
469 >                                &&      (visualFormat.Gmask == Screen_blitters[i].Gmask)
470 >                                &&      (visualFormat.Bmask == Screen_blitters[i].Bmask)
471 >                                )
472 >                        {
473 >                                blitter_found = true;
474 >                                Screen_blit = native_byte_order
475 >                                                        ? Screen_blitters[i].handler_nbo
476 >                                                        : Screen_blitters[i].handler_obo
477 >                                                        ;
478 >                        }
479                  }
286        }
480          
481 <        // No appropriate blitter found, dump RGB mask values and abort()
482 <        if (!blitter_found) {
483 <                fprintf(stderr, "### No appropriate blitter found\n");
484 <                fprintf(stderr, "\tR/G/B mask values  : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
485 <                        visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
486 <                fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
487 <                        visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
488 <                abort();
481 >                // No appropriate blitter found, dump RGB mask values and abort()
482 >                if (!blitter_found) {
483 >                        fprintf(stderr, "### No appropriate blitter found\n");
484 >                        fprintf(stderr, "\tR/G/B mask values  : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
485 >                                visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
486 >                        fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
487 >                                visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
488 >                        abort();
489 >                }
490          }
491 + #else
492 +        // The UAE memory handlers will blit correctly
493 +        // --> no need for specialised blitters here
494 +        Screen_blit = Blit_Copy_Raw;
495 + #endif
496          
497          // If the blitter simply reduces to a copy, we don't need VOSF in DGA mode
498          // --> In that case, we return FALSE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines