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.6 by cebix, 2001-07-01T21:09:29Z

# 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/8-bit indexed to 16-bit mode color expansion                   --- */
266 + /* -------------------------------------------------------------------------- */
267 +
268 + static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length)
269 + {
270 +        uint16 *q = (uint16 *)dest;
271 +        for (int i=0; i<length; i++) {
272 +                uint8 c = *p++;
273 +                *q++ = ExpandMap[c >> 6];
274 +                *q++ = ExpandMap[c >> 4];
275 +                *q++ = ExpandMap[c >> 2];
276 +                *q++ = ExpandMap[c];
277 +        }
278 + }
279 +
280 + static void Blit_Expand_4_To_16(uint8 * dest, const uint8 * p, uint32 length)
281 + {
282 +        uint16 *q = (uint16 *)dest;
283 +        for (int i=0; i<length; i++) {
284 +                uint8 c = *p++;
285 +                *q++ = ExpandMap[c >> 4];
286 +                *q++ = ExpandMap[c];
287 +        }
288 + }
289 +
290 + static void Blit_Expand_8_To_16(uint8 * dest, const uint8 * p, uint32 length)
291 + {
292 +        uint16 *q = (uint16 *)dest;
293 +        for (int i=0; i<length; i++)
294 +                *q++ = ExpandMap[*p++];
295 + }
296 +
297 + /* -------------------------------------------------------------------------- */
298 + /* --- 2/4/8-bit indexed to 32-bit mode color expansion                   --- */
299 + /* -------------------------------------------------------------------------- */
300 +
301 + static void Blit_Expand_2_To_32(uint8 * dest, const uint8 * p, uint32 length)
302 + {
303 +        uint32 *q = (uint32 *)dest;
304 +        for (int i=0; i<length; i++) {
305 +                uint8 c = *p++;
306 +                *q++ = ExpandMap[c >> 6];
307 +                *q++ = ExpandMap[c >> 4];
308 +                *q++ = ExpandMap[c >> 2];
309 +                *q++ = ExpandMap[c];
310 +        }
311 + }
312 +
313 + static void Blit_Expand_4_To_32(uint8 * dest, const uint8 * p, uint32 length)
314 + {
315 +        uint32 *q = (uint32 *)dest;
316 +        for (int i=0; i<length; i++) {
317 +                uint8 c = *p++;
318 +                *q++ = ExpandMap[c >> 4];
319 +                *q++ = ExpandMap[c];
320 +        }
321 + }
322 +
323 + static void Blit_Expand_8_To_32(uint8 * dest, const uint8 * p, uint32 length)
324 + {
325 +        uint32 *q = (uint32 *)dest;
326 +        for (int i=0; i<length; i++)
327 +                *q++ = ExpandMap[*p++];
328 + }
329 +
330 + /* -------------------------------------------------------------------------- */
331   /* --- Blitters to the host frame buffer, or XImage buffer                --- */
332   /* -------------------------------------------------------------------------- */
333  
# Line 229 | Line 352 | static Screen_blit_func_info Screen_blit
352          {  1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // NT
353          {  8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // OK (NBO)
354          { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw       , Blit_RGB555_OBO       },      // OK (OBO)
355 +        { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO     , Blit_BGR555_OBO       },      // NT
356          { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO     , Blit_RGB565_OBO       },      // OK (OBO)
357          { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK (OBO)
358          { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       },      // NT
359 <        { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK (OBO)
360 <        { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       }       // NT
359 >        { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw       , Blit_RGB888_OBO       },      // OK
360 >        { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       }       // OK
361   #else
362          {  1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // NT
363          {  8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw       , Blit_Copy_Raw         },      // OK (NBO)
364          { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO     , Blit_Copy_Raw         },      // OK (NBO)
365 +        { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO     , Blit_BGR555_OBO       },      // NT
366          { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO     , Blit_RGB565_OBO       },      // OK (NBO)
367          { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO     , Blit_Copy_Raw         },      // OK (NBO)
368          { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO     , Blit_BGR888_OBO       },      // NT
# Line 249 | Line 374 | static Screen_blit_func_info Screen_blit
374   // Initialize the framebuffer update function
375   // Returns FALSE, if the function was to be reduced to a simple memcpy()
376   // --> In that case, VOSF is not necessary
377 < bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order)
377 > bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth)
378   {
379 <        visualFormat.depth = visual_info->depth;
380 <        visualFormat.Rmask = visual_info->red_mask;
381 <        visualFormat.Gmask = visual_info->green_mask;
382 <        visualFormat.Bmask = visual_info->blue_mask;
379 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
380 >        if (mac_depth == VDEPTH_1BIT) {
381 >
382 >                // 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines
383 >                Screen_blit = Blit_Copy_Raw;
384 >
385 >        } else {
386 >
387 >                visualFormat.depth = visual_info->depth;
388 >                visualFormat.Rmask = visual_info->red_mask;
389 >                visualFormat.Gmask = visual_info->green_mask;
390 >                visualFormat.Bmask = visual_info->blue_mask;
391 >
392 >                // Compute RGB shift values
393 >                visualFormat.Rshift = 0;
394 >                for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
395 >                        ++visualFormat.Rshift;
396 >                visualFormat.Gshift = 0;
397 >                for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
398 >                        ++visualFormat.Gshift;
399 >                visualFormat.Bshift = 0;
400 >                for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
401 >                        ++visualFormat.Bshift;
402 >
403 >                bool blitter_found = false;
404          
405 <        // Compute RGB shift values
406 <        visualFormat.Rshift = 0;
407 <        for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
408 <                ++visualFormat.Rshift;
409 <        visualFormat.Gshift = 0;
410 <        for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
411 <                ++visualFormat.Gshift;
412 <        visualFormat.Bshift = 0;
413 <        for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
414 <                ++visualFormat.Bshift;
405 >                // 2/4/8-bit mode on 16/32-bit screen?
406 >                if (visualFormat.depth > 8) {
407 >                        if (mac_depth == VDEPTH_2BIT) {
408 >                                if (visual_info->depth <= 16) {
409 >                                        Screen_blit = Blit_Expand_2_To_16;
410 >                                        blitter_found = true;
411 >                                } else {
412 >                                        Screen_blit = Blit_Expand_2_To_32;
413 >                                        blitter_found = true;
414 >                                }
415 >                        } else if (mac_depth == VDEPTH_4BIT) {
416 >                                if (visual_info->depth <= 16) {
417 >                                        Screen_blit = Blit_Expand_4_To_16;
418 >                                        blitter_found = true;
419 >                                } else {
420 >                                        Screen_blit = Blit_Expand_4_To_32;
421 >                                        blitter_found = true;
422 >                                }
423 >                        } else if (mac_depth == VDEPTH_8BIT) {
424 >                                if (visual_info->depth <= 16) {
425 >                                        Screen_blit = Blit_Expand_8_To_16;
426 >                                        blitter_found = true;
427 >                                } else {
428 >                                        Screen_blit = Blit_Expand_8_To_32;
429 >                                        blitter_found = true;
430 >                                }
431 >                        }
432 >                }
433          
434 <        // Search for an adequate blit function
435 <        bool blitter_found = false;
436 <        const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
437 <        for (int i = 0; !blitter_found && (i < blitters_count); i++) {
438 <                if      (       (visualFormat.depth == Screen_blitters[i].depth)
439 <                        &&      (visualFormat.Rmask == Screen_blitters[i].Rmask)
440 <                        &&      (visualFormat.Gmask == Screen_blitters[i].Gmask)
441 <                        &&      (visualFormat.Bmask == Screen_blitters[i].Bmask)
442 <                        )
443 <                {
444 <                        blitter_found = true;
445 <                        Screen_blit = native_byte_order
446 <                                                ? Screen_blitters[i].handler_nbo
447 <                                                : Screen_blitters[i].handler_obo
448 <                                                ;
434 >                // Search for an adequate blit function
435 >                const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
436 >                for (int i = 0; !blitter_found && (i < blitters_count); i++) {
437 >                        if      (       (visualFormat.depth == Screen_blitters[i].depth)
438 >                                &&      (visualFormat.Rmask == Screen_blitters[i].Rmask)
439 >                                &&      (visualFormat.Gmask == Screen_blitters[i].Gmask)
440 >                                &&      (visualFormat.Bmask == Screen_blitters[i].Bmask)
441 >                                )
442 >                        {
443 >                                blitter_found = true;
444 >                                Screen_blit = native_byte_order
445 >                                                        ? Screen_blitters[i].handler_nbo
446 >                                                        : Screen_blitters[i].handler_obo
447 >                                                        ;
448 >                        }
449                  }
286        }
450          
451 <        // No appropriate blitter found, dump RGB mask values and abort()
452 <        if (!blitter_found) {
453 <                fprintf(stderr, "### No appropriate blitter found\n");
454 <                fprintf(stderr, "\tR/G/B mask values  : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
455 <                        visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
456 <                fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
457 <                        visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
458 <                abort();
451 >                // No appropriate blitter found, dump RGB mask values and abort()
452 >                if (!blitter_found) {
453 >                        fprintf(stderr, "### No appropriate blitter found\n");
454 >                        fprintf(stderr, "\tR/G/B mask values  : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
455 >                                visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
456 >                        fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
457 >                                visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
458 >                        abort();
459 >                }
460          }
461 + #else
462 +        // The UAE memory handlers will blit correctly
463 +        // --> no need for specialised blitters here
464 +        Screen_blit = Blit_Copy_Raw;
465 + #endif
466          
467          // If the blitter simply reduces to a copy, we don't need VOSF in DGA mode
468          // --> In that case, we return FALSE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines