Revision d3079cd2

b/hw/vga.c
808 808
    return (r << 16) | (g << 8) | b;
809 809
}
810 810

  
811
static inline unsigned int rgb_to_pixel32bgr(unsigned int r, unsigned int g, unsigned b)
812
{
813
    return (b << 16) | (g << 8) | r;
814
}
815

  
811 816
#define DEPTH 8
812 817
#include "vga_template.h"
813 818

  
......
820 825
#define DEPTH 32
821 826
#include "vga_template.h"
822 827

  
828
#define BGR_FORMAT
829
#define DEPTH 32
830
#include "vga_template.h"
831

  
823 832
static unsigned int rgb_to_pixel8_dup(unsigned int r, unsigned int g, unsigned b)
824 833
{
825 834
    unsigned int col;
......
852 861
    return col;
853 862
}
854 863

  
864
static unsigned int rgb_to_pixel32bgr_dup(unsigned int r, unsigned int g, unsigned b)
865
{
866
    unsigned int col;
867
    col = rgb_to_pixel32bgr(r, g, b);
868
    return col;
869
}
870

  
855 871
/* return true if the palette was modified */
856 872
static int update_palette16(VGAState *s)
857 873
{
......
948 964
    return full_update;
949 965
}
950 966

  
951
static inline int get_depth_index(int depth)
967
#define NB_DEPTHS 5
968

  
969
static inline int get_depth_index(DisplayState *s)
952 970
{
953
    switch(depth) {
971
    switch(s->depth) {
954 972
    default:
955 973
    case 8:
956 974
        return 0;
......
959 977
    case 16:
960 978
        return 2;
961 979
    case 32:
962
        return 3;
980
        if (s->bgr)
981
            return 4;
982
        else
983
            return 3;
963 984
    }
964 985
}
965 986

  
966
static vga_draw_glyph8_func *vga_draw_glyph8_table[4] = {
987
static vga_draw_glyph8_func *vga_draw_glyph8_table[NB_DEPTHS] = {
967 988
    vga_draw_glyph8_8,
968 989
    vga_draw_glyph8_16,
969 990
    vga_draw_glyph8_16,
970 991
    vga_draw_glyph8_32,
992
    vga_draw_glyph8_32,
971 993
};
972 994

  
973
static vga_draw_glyph8_func *vga_draw_glyph16_table[4] = {
995
static vga_draw_glyph8_func *vga_draw_glyph16_table[NB_DEPTHS] = {
974 996
    vga_draw_glyph16_8,
975 997
    vga_draw_glyph16_16,
976 998
    vga_draw_glyph16_16,
977 999
    vga_draw_glyph16_32,
1000
    vga_draw_glyph16_32,
978 1001
};
979 1002

  
980
static vga_draw_glyph9_func *vga_draw_glyph9_table[4] = {
1003
static vga_draw_glyph9_func *vga_draw_glyph9_table[NB_DEPTHS] = {
981 1004
    vga_draw_glyph9_8,
982 1005
    vga_draw_glyph9_16,
983 1006
    vga_draw_glyph9_16,
984 1007
    vga_draw_glyph9_32,
1008
    vga_draw_glyph9_32,
985 1009
};
986 1010
    
987 1011
static const uint8_t cursor_glyph[32 * 4] = {
......
1103 1127
    }
1104 1128
    cursor_ptr = s->vram_ptr + (s->start_addr + cursor_offset) * 4;
1105 1129
    
1106
    depth_index = get_depth_index(s->ds->depth);
1130
    depth_index = get_depth_index(s->ds);
1107 1131
    if (cw == 16)
1108 1132
        vga_draw_glyph8 = vga_draw_glyph16_table[depth_index];
1109 1133
    else
......
1196 1220
    VGA_DRAW_LINE_NB,
1197 1221
};
1198 1222

  
1199
static vga_draw_line_func *vga_draw_line_table[4 * VGA_DRAW_LINE_NB] = {
1223
static vga_draw_line_func *vga_draw_line_table[NB_DEPTHS * VGA_DRAW_LINE_NB] = {
1200 1224
    vga_draw_line2_8,
1201 1225
    vga_draw_line2_16,
1202 1226
    vga_draw_line2_16,
1203 1227
    vga_draw_line2_32,
1228
    vga_draw_line2_32,
1204 1229

  
1205 1230
    vga_draw_line2d2_8,
1206 1231
    vga_draw_line2d2_16,
1207 1232
    vga_draw_line2d2_16,
1208 1233
    vga_draw_line2d2_32,
1234
    vga_draw_line2d2_32,
1209 1235

  
1210 1236
    vga_draw_line4_8,
1211 1237
    vga_draw_line4_16,
1212 1238
    vga_draw_line4_16,
1213 1239
    vga_draw_line4_32,
1240
    vga_draw_line4_32,
1214 1241

  
1215 1242
    vga_draw_line4d2_8,
1216 1243
    vga_draw_line4d2_16,
1217 1244
    vga_draw_line4d2_16,
1218 1245
    vga_draw_line4d2_32,
1246
    vga_draw_line4d2_32,
1219 1247

  
1220 1248
    vga_draw_line8d2_8,
1221 1249
    vga_draw_line8d2_16,
1222 1250
    vga_draw_line8d2_16,
1223 1251
    vga_draw_line8d2_32,
1252
    vga_draw_line8d2_32,
1224 1253

  
1225 1254
    vga_draw_line8_8,
1226 1255
    vga_draw_line8_16,
1227 1256
    vga_draw_line8_16,
1228 1257
    vga_draw_line8_32,
1258
    vga_draw_line8_32,
1229 1259

  
1230 1260
    vga_draw_line15_8,
1231 1261
    vga_draw_line15_15,
1232 1262
    vga_draw_line15_16,
1233 1263
    vga_draw_line15_32,
1264
    vga_draw_line15_32bgr,
1234 1265

  
1235 1266
    vga_draw_line16_8,
1236 1267
    vga_draw_line16_15,
1237 1268
    vga_draw_line16_16,
1238 1269
    vga_draw_line16_32,
1270
    vga_draw_line16_32bgr,
1239 1271

  
1240 1272
    vga_draw_line24_8,
1241 1273
    vga_draw_line24_15,
1242 1274
    vga_draw_line24_16,
1243 1275
    vga_draw_line24_32,
1276
    vga_draw_line24_32bgr,
1244 1277

  
1245 1278
    vga_draw_line32_8,
1246 1279
    vga_draw_line32_15,
1247 1280
    vga_draw_line32_16,
1248 1281
    vga_draw_line32_32,
1282
    vga_draw_line32_32bgr,
1283
};
1284

  
1285
typedef unsigned int rgb_to_pixel_dup_func(unsigned int r, unsigned int g, unsigned b);
1286

  
1287
static rgb_to_pixel_dup_func *rgb_to_pixel_dup_table[NB_DEPTHS] = {
1288
    rgb_to_pixel8_dup,
1289
    rgb_to_pixel15_dup,
1290
    rgb_to_pixel16_dup,
1291
    rgb_to_pixel32_dup,
1292
    rgb_to_pixel32bgr_dup,
1249 1293
};
1250 1294

  
1251 1295
static int vga_get_bpp(VGAState *s)
......
1362 1406
            break;
1363 1407
        }
1364 1408
    }
1365
    vga_draw_line = vga_draw_line_table[v * 4 + get_depth_index(s->ds->depth)];
1409
    vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
1366 1410

  
1367 1411
    if (disp_width != s->last_width ||
1368 1412
        height != s->last_height) {
......
1492 1536
    if (s->ds->depth == 0) {
1493 1537
        /* nothing to do */
1494 1538
    } else {
1495
        switch(s->ds->depth) {
1496
        case 8:
1497
            s->rgb_to_pixel = rgb_to_pixel8_dup;
1498
            break;
1499
        case 15:
1500
            s->rgb_to_pixel = rgb_to_pixel15_dup;
1501
            break;
1502
        default:
1503
        case 16:
1504
            s->rgb_to_pixel = rgb_to_pixel16_dup;
1505
            break;
1506
        case 32:
1507
            s->rgb_to_pixel = rgb_to_pixel32_dup;
1508
            break;
1509
        }
1539
        s->rgb_to_pixel = 
1540
            rgb_to_pixel_dup_table[get_depth_index(s->ds)];
1510 1541
        
1511 1542
        full_update = 0;
1512 1543
        if (!(s->ar_index & 0x20)) {
b/hw/vga_template.h
35 35
#error unsupport depth
36 36
#endif
37 37

  
38
#if DEPTH != 15
38
#ifdef BGR_FORMAT
39
#define PIXEL_NAME glue(DEPTH, bgr)
40
#else
41
#define PIXEL_NAME DEPTH
42
#endif /* BGR_FORMAT */
43

  
44
#if DEPTH != 15 && !defined(BGR_FORMAT)
39 45

  
40 46
static inline void glue(vga_draw_glyph_line_, DEPTH)(uint8_t *d, 
41 47
                                                     uint32_t font_data,
......
334 340
    }
335 341
}
336 342

  
343
void glue(vga_draw_cursor_line_, DEPTH)(uint8_t *d1, 
344
                                        const uint8_t *src1, 
345
                                        int poffset, int w,
346
                                        unsigned int color0, 
347
                                        unsigned int color1,
348
                                        unsigned int color_xor)
349
{
350
    const uint8_t *plane0, *plane1;
351
    int x, b0, b1;
352
    uint8_t *d;
353

  
354
    d = d1;
355
    plane0 = src1;
356
    plane1 = src1 + poffset;
357
    for(x = 0; x < w; x++) {
358
        b0 = (plane0[x >> 3] >> (7 - (x & 7))) & 1;
359
        b1 = (plane1[x >> 3] >> (7 - (x & 7))) & 1;
360
#if DEPTH == 8
361
        switch(b0 | (b1 << 1)) {
362
        case 0:
363
            break;
364
        case 1:
365
            d[0] ^= color_xor;
366
            break;
367
        case 2:
368
            d[0] = color0;
369
            break;
370
        case 3:
371
            d[0] = color1;
372
            break;
373
        }
374
#elif DEPTH == 16
375
        switch(b0 | (b1 << 1)) {
376
        case 0:
377
            break;
378
        case 1:
379
            ((uint16_t *)d)[0] ^= color_xor;
380
            break;
381
        case 2:
382
            ((uint16_t *)d)[0] = color0;
383
            break;
384
        case 3:
385
            ((uint16_t *)d)[0] = color1;
386
            break;
387
        }
388
#elif DEPTH == 32
389
        switch(b0 | (b1 << 1)) {
390
        case 0:
391
            break;
392
        case 1:
393
            ((uint32_t *)d)[0] ^= color_xor;
394
            break;
395
        case 2:
396
            ((uint32_t *)d)[0] = color0;
397
            break;
398
        case 3:
399
            ((uint32_t *)d)[0] = color1;
400
            break;
401
        }
402
#else
403
#error unsupported depth
404
#endif
405
        d += BPP;
406
    }
407
}
408

  
337 409
#endif /* DEPTH != 15 */
338 410

  
339 411

  
......
342 414
/* 
343 415
 * 15 bit color
344 416
 */
345
static void glue(vga_draw_line15_, DEPTH)(VGAState *s1, uint8_t *d, 
417
static void glue(vga_draw_line15_, PIXEL_NAME)(VGAState *s1, uint8_t *d, 
346 418
                                          const uint8_t *s, int width)
347 419
{
348 420
#if DEPTH == 15 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
......
357 429
        r = (v >> 7) & 0xf8;
358 430
        g = (v >> 2) & 0xf8;
359 431
        b = (v << 3) & 0xf8;
360
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
432
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
361 433
        s += 2;
362 434
        d += BPP;
363 435
    } while (--w != 0);
......
367 439
/* 
368 440
 * 16 bit color
369 441
 */
370
static void glue(vga_draw_line16_, DEPTH)(VGAState *s1, uint8_t *d, 
442
static void glue(vga_draw_line16_, PIXEL_NAME)(VGAState *s1, uint8_t *d, 
371 443
                                          const uint8_t *s, int width)
372 444
{
373 445
#if DEPTH == 16 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
......
382 454
        r = (v >> 8) & 0xf8;
383 455
        g = (v >> 3) & 0xfc;
384 456
        b = (v << 3) & 0xf8;
385
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
457
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
386 458
        s += 2;
387 459
        d += BPP;
388 460
    } while (--w != 0);
......
392 464
/* 
393 465
 * 24 bit color
394 466
 */
395
static void glue(vga_draw_line24_, DEPTH)(VGAState *s1, uint8_t *d, 
467
static void glue(vga_draw_line24_, PIXEL_NAME)(VGAState *s1, uint8_t *d, 
396 468
                                          const uint8_t *s, int width)
397 469
{
398 470
    int w;
......
409 481
        g = s[1];
410 482
        r = s[2];
411 483
#endif
412
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
484
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
413 485
        s += 3;
414 486
        d += BPP;
415 487
    } while (--w != 0);
......
418 490
/* 
419 491
 * 32 bit color
420 492
 */
421
static void glue(vga_draw_line32_, DEPTH)(VGAState *s1, uint8_t *d, 
493
static void glue(vga_draw_line32_, PIXEL_NAME)(VGAState *s1, uint8_t *d, 
422 494
                                          const uint8_t *s, int width)
423 495
{
424 496
#if DEPTH == 32 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
......
438 510
        g = s[1];
439 511
        r = s[2];
440 512
#endif
441
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
513
        ((PIXEL_TYPE *)d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
442 514
        s += 4;
443 515
        d += BPP;
444 516
    } while (--w != 0);
445 517
#endif
446 518
}
447 519

  
448
#if DEPTH != 15
449
void glue(vga_draw_cursor_line_, DEPTH)(uint8_t *d1, 
450
                                        const uint8_t *src1, 
451
                                        int poffset, int w,
452
                                        unsigned int color0, 
453
                                        unsigned int color1,
454
                                        unsigned int color_xor)
455
{
456
    const uint8_t *plane0, *plane1;
457
    int x, b0, b1;
458
    uint8_t *d;
459

  
460
    d = d1;
461
    plane0 = src1;
462
    plane1 = src1 + poffset;
463
    for(x = 0; x < w; x++) {
464
        b0 = (plane0[x >> 3] >> (7 - (x & 7))) & 1;
465
        b1 = (plane1[x >> 3] >> (7 - (x & 7))) & 1;
466
#if DEPTH == 8
467
        switch(b0 | (b1 << 1)) {
468
        case 0:
469
            break;
470
        case 1:
471
            d[0] ^= color_xor;
472
            break;
473
        case 2:
474
            d[0] = color0;
475
            break;
476
        case 3:
477
            d[0] = color1;
478
            break;
479
        }
480
#elif DEPTH == 16
481
        switch(b0 | (b1 << 1)) {
482
        case 0:
483
            break;
484
        case 1:
485
            ((uint16_t *)d)[0] ^= color_xor;
486
            break;
487
        case 2:
488
            ((uint16_t *)d)[0] = color0;
489
            break;
490
        case 3:
491
            ((uint16_t *)d)[0] = color1;
492
            break;
493
        }
494
#elif DEPTH == 32
495
        switch(b0 | (b1 << 1)) {
496
        case 0:
497
            break;
498
        case 1:
499
            ((uint32_t *)d)[0] ^= color_xor;
500
            break;
501
        case 2:
502
            ((uint32_t *)d)[0] = color0;
503
            break;
504
        case 3:
505
            ((uint32_t *)d)[0] = color1;
506
            break;
507
        }
508
#else
509
#error unsupported depth
510
#endif
511
        d += BPP;
512
    }
513
}
514
#endif
515

  
516 520
#undef PUT_PIXEL2
517 521
#undef DEPTH
518 522
#undef BPP
519 523
#undef PIXEL_TYPE
524
#undef PIXEL_NAME
525
#undef BGR_FORMAT
b/sdl.c
81 81
    ds->data = screen->pixels;
82 82
    ds->linesize = screen->pitch;
83 83
    ds->depth = screen->format->BitsPerPixel;
84
    if (ds->depth == 32 && screen->format->Rshift == 0) {
85
        ds->bgr = 1;
86
    } else {
87
        ds->bgr = 0;
88
    }
84 89
    ds->width = w;
85 90
    ds->height = h;
86 91
}
b/vl.h
677 677
    uint8_t *data;
678 678
    int linesize;
679 679
    int depth;
680
    int bgr; /* BGR color order instead of RGB. Only valid for depth == 32 */
680 681
    int width;
681 682
    int height;
682 683
    void *opaque;

Also available in: Unified diff