~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to console.c

  • Committer: Blue Swirl
  • Date: 2009-08-31 15:14:40 UTC
  • Revision ID: git-v1:528e93a9787ccfc59582a44035f5f342caf5b84f
Fix breakage due to __thread

Thread-local storage is not supported on all hosts.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
    TextCell *cells;
139
139
    int text_x[2], text_y[2], cursor_invalidate;
140
140
 
 
141
    int update_x0;
 
142
    int update_y0;
 
143
    int update_x1;
 
144
    int update_y1;
 
145
 
141
146
    enum TTYState state;
142
147
    int esc_params[MAX_ESC_PARAMS];
143
148
    int nb_esc_params;
167
172
 
168
173
void vga_hw_screen_dump(const char *filename)
169
174
{
170
 
    /* There is currently no was of specifying which screen we want to dump,
171
 
       so always dump the dirst one.  */
 
175
    TextConsole *previous_active_console;
 
176
 
 
177
    previous_active_console = active_console;
 
178
    active_console = consoles[0];
 
179
    /* There is currently no way of specifying which screen we want to dump,
 
180
       so always dump the first one.  */
172
181
    if (consoles[0]->hw_screen_dump)
173
182
        consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
 
183
    active_console = previous_active_console;
174
184
}
175
185
 
176
186
void vga_hw_text_update(console_ch_t *chardata)
184
194
{
185
195
    unsigned int r, g, b, color;
186
196
 
187
 
    switch(ds->depth) {
 
197
    switch(ds_get_bits_per_pixel(ds)) {
188
198
#if 0
189
199
    case 8:
190
200
        r = (rgba >> 16) & 0xff;
221
231
    uint8_t *d, *d1;
222
232
    int x, y, bpp;
223
233
 
224
 
    bpp = (ds->depth + 7) >> 3;
225
 
    d1 = ds->data +
226
 
        ds->linesize * posy + bpp * posx;
 
234
    bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
 
235
    d1 = ds_get_data(ds) +
 
236
        ds_get_linesize(ds) * posy + bpp * posx;
227
237
    for (y = 0; y < height; y++) {
228
238
        d = d1;
229
239
        switch(bpp) {
246
256
            }
247
257
            break;
248
258
        }
249
 
        d1 += ds->linesize;
 
259
        d1 += ds_get_linesize(ds);
250
260
    }
251
261
}
252
262
 
257
267
    uint8_t *d;
258
268
    int wb, y, bpp;
259
269
 
260
 
    bpp = (ds->depth + 7) >> 3;
 
270
    bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
261
271
    wb = w * bpp;
262
272
    if (yd <= ys) {
263
 
        s = ds->data +
264
 
            ds->linesize * ys + bpp * xs;
265
 
        d = ds->data +
266
 
            ds->linesize * yd + bpp * xd;
 
273
        s = ds_get_data(ds) +
 
274
            ds_get_linesize(ds) * ys + bpp * xs;
 
275
        d = ds_get_data(ds) +
 
276
            ds_get_linesize(ds) * yd + bpp * xd;
267
277
        for (y = 0; y < h; y++) {
268
278
            memmove(d, s, wb);
269
 
            d += ds->linesize;
270
 
            s += ds->linesize;
 
279
            d += ds_get_linesize(ds);
 
280
            s += ds_get_linesize(ds);
271
281
        }
272
282
    } else {
273
 
        s = ds->data +
274
 
            ds->linesize * (ys + h - 1) + bpp * xs;
275
 
        d = ds->data +
276
 
            ds->linesize * (yd + h - 1) + bpp * xd;
 
283
        s = ds_get_data(ds) +
 
284
            ds_get_linesize(ds) * (ys + h - 1) + bpp * xs;
 
285
        d = ds_get_data(ds) +
 
286
            ds_get_linesize(ds) * (yd + h - 1) + bpp * xd;
277
287
       for (y = 0; y < h; y++) {
278
288
            memmove(d, s, wb);
279
 
            d -= ds->linesize;
280
 
            s -= ds->linesize;
 
289
            d -= ds_get_linesize(ds);
 
290
            s -= ds_get_linesize(ds);
281
291
        }
282
292
    }
283
293
}
297
307
                (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >>  8) | \
298
308
                (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
299
309
 
300
 
#ifdef WORDS_BIGENDIAN
 
310
#ifdef HOST_WORDS_BIGENDIAN
301
311
#define PAT(x) x
302
312
#else
303
313
#define PAT(x) cbswap_32(x)
367
377
 
368
378
static inline unsigned int col_expand(DisplayState *ds, unsigned int col)
369
379
{
370
 
    switch(ds->depth) {
 
380
    switch(ds_get_bits_per_pixel(ds)) {
371
381
    case 8:
372
382
        col |= col << 8;
373
383
        col |= col << 16;
437
447
        bgcol = color_table[t_attrib->bold][t_attrib->bgcol];
438
448
    }
439
449
 
440
 
    bpp = (ds->depth + 7) >> 3;
441
 
    d = ds->data +
442
 
        ds->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
443
 
    linesize = ds->linesize;
 
450
    bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
 
451
    d = ds_get_data(ds) +
 
452
        ds_get_linesize(ds) * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
 
453
    linesize = ds_get_linesize(ds);
444
454
    font_ptr = vgafont16 + FONT_HEIGHT * ch;
445
455
    xorcol = bgcol ^ fgcol;
446
 
    switch(ds->depth) {
 
456
    switch(ds_get_bits_per_pixel(ds)) {
447
457
    case 8:
448
458
        for(i = 0; i < FONT_HEIGHT; i++) {
449
459
            font_data = *font_ptr++;
531
541
    s->text_y[1] = MAX(s->text_y[1], y);
532
542
}
533
543
 
 
544
static void invalidate_xy(TextConsole *s, int x, int y)
 
545
{
 
546
    if (s->update_x0 > x * FONT_WIDTH)
 
547
        s->update_x0 = x * FONT_WIDTH;
 
548
    if (s->update_y0 > y * FONT_HEIGHT)
 
549
        s->update_y0 = y * FONT_HEIGHT;
 
550
    if (s->update_x1 < (x + 1) * FONT_WIDTH)
 
551
        s->update_x1 = (x + 1) * FONT_WIDTH;
 
552
    if (s->update_y1 < (y + 1) * FONT_HEIGHT)
 
553
        s->update_y1 = (y + 1) * FONT_HEIGHT;
 
554
}
 
555
 
534
556
static void update_xy(TextConsole *s, int x, int y)
535
557
{
536
558
    TextCell *c;
537
559
    int y1, y2;
538
560
 
539
561
    if (s == active_console) {
540
 
        if (!s->ds->depth) {
 
562
        if (!ds_get_bits_per_pixel(s->ds)) {
541
563
            text_update_xy(s, x, y);
542
564
            return;
543
565
        }
550
572
            c = &s->cells[y1 * s->width + x];
551
573
            vga_putcharxy(s->ds, x, y2, c->ch,
552
574
                          &(c->t_attrib));
553
 
            dpy_update(s->ds, x * FONT_WIDTH, y2 * FONT_HEIGHT,
554
 
                       FONT_WIDTH, FONT_HEIGHT);
 
575
            invalidate_xy(s, x, y2);
555
576
        }
556
577
    }
557
578
}
564
585
    if (s == active_console) {
565
586
        int x = s->x;
566
587
 
567
 
        if (!s->ds->depth) {
 
588
        if (!ds_get_bits_per_pixel(s->ds)) {
568
589
            s->cursor_invalidate = 1;
569
590
            return;
570
591
        }
585
606
            } else {
586
607
                vga_putcharxy(s->ds, x, y, c->ch, &(c->t_attrib));
587
608
            }
588
 
            dpy_update(s->ds, x * FONT_WIDTH, y * FONT_HEIGHT,
589
 
                       FONT_WIDTH, FONT_HEIGHT);
 
609
            invalidate_xy(s, x, y);
590
610
        }
591
611
    }
592
612
}
598
618
 
599
619
    if (s != active_console)
600
620
        return;
601
 
    if (!s->ds->depth) {
 
621
    if (!ds_get_bits_per_pixel(s->ds)) {
602
622
        s->text_x[0] = 0;
603
623
        s->text_y[0] = 0;
604
624
        s->text_x[1] = s->width - 1;
607
627
        return;
608
628
    }
609
629
 
610
 
    vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
 
630
    vga_fill_rect(s->ds, 0, 0, ds_get_width(s->ds), ds_get_height(s->ds),
611
631
                  color_table[0][COLOR_BLACK]);
612
632
    y1 = s->y_displayed;
613
633
    for(y = 0; y < s->height; y++) {
620
640
        if (++y1 == s->total_height)
621
641
            y1 = 0;
622
642
    }
623
 
    dpy_update(s->ds, 0, 0, s->ds->width, s->ds->height);
624
643
    console_show_cursor(s, 1);
 
644
    dpy_update(s->ds, 0, 0, ds_get_width(s->ds), ds_get_height(s->ds));
625
645
}
626
646
 
627
647
static void console_scroll(int ydelta)
683
703
            c++;
684
704
        }
685
705
        if (s == active_console && s->y_displayed == s->y_base) {
686
 
            if (!s->ds->depth) {
 
706
            if (!ds_get_bits_per_pixel(s->ds)) {
687
707
                s->text_x[0] = 0;
688
708
                s->text_y[0] = 0;
689
709
                s->text_x[1] = s->width - 1;
697
717
            vga_fill_rect(s->ds, 0, (s->height - 1) * FONT_HEIGHT,
698
718
                          s->width * FONT_WIDTH, FONT_HEIGHT,
699
719
                          color_table[0][s->t_attrib_default.bgcol]);
700
 
            dpy_update(s->ds, 0, 0,
701
 
                       s->width * FONT_WIDTH, s->height * FONT_HEIGHT);
 
720
            s->update_x0 = 0;
 
721
            s->update_y0 = 0;
 
722
            s->update_x1 = s->width * FONT_WIDTH;
 
723
            s->update_y1 = s->height * FONT_HEIGHT;
702
724
        }
703
725
    }
704
726
}
1038
1060
 
1039
1061
    if (index >= MAX_CONSOLES)
1040
1062
        return;
 
1063
    active_console->g_width = ds_get_width(active_console->ds);
 
1064
    active_console->g_height = ds_get_height(active_console->ds);
1041
1065
    s = consoles[index];
1042
1066
    if (s) {
 
1067
        DisplayState *ds = s->ds;
1043
1068
        active_console = s;
 
1069
        if (ds_get_bits_per_pixel(s->ds)) {
 
1070
            ds->surface = qemu_resize_displaysurface(ds, s->g_width, s->g_height);
 
1071
        } else {
 
1072
            s->ds->surface->width = s->width;
 
1073
            s->ds->surface->height = s->height;
 
1074
        }
 
1075
        dpy_resize(s->ds);
1044
1076
        vga_hw_invalidate();
1045
1077
    }
1046
1078
}
1050
1082
    TextConsole *s = chr->opaque;
1051
1083
    int i;
1052
1084
 
 
1085
    s->update_x0 = s->width * FONT_WIDTH;
 
1086
    s->update_y0 = s->height * FONT_HEIGHT;
 
1087
    s->update_x1 = 0;
 
1088
    s->update_y1 = 0;
1053
1089
    console_show_cursor(s, 0);
1054
1090
    for(i = 0; i < len; i++) {
1055
1091
        console_putchar(s, buf[i]);
1056
1092
    }
1057
1093
    console_show_cursor(s, 1);
 
1094
    if (ds_get_bits_per_pixel(s->ds) && s->update_x0 < s->update_x1) {
 
1095
        dpy_update(s->ds, s->update_x0, s->update_y0,
 
1096
                   s->update_x1 - s->update_x0,
 
1097
                   s->update_y1 - s->update_y0);
 
1098
    }
1058
1099
    return len;
1059
1100
}
1060
1101
 
1148
1189
static void text_console_invalidate(void *opaque)
1149
1190
{
1150
1191
    TextConsole *s = (TextConsole *) opaque;
1151
 
 
1152
 
    if (s->console_type != GRAPHIC_CONSOLE) {
1153
 
        if (s->g_width != s->ds->width ||
1154
 
            s->g_height != s->ds->height) {
1155
 
            if (s->console_type == TEXT_CONSOLE_FIXED_SIZE)
1156
 
                dpy_resize(s->ds, s->g_width, s->g_height);
1157
 
            else {
1158
 
                s->g_width = s->ds->width;
1159
 
                s->g_height = s->ds->height;
1160
 
                text_console_resize(s);
1161
 
            }
1162
 
        }
 
1192
    if (!ds_get_bits_per_pixel(s->ds) && s->console_type == TEXT_CONSOLE) {
 
1193
        s->g_width = ds_get_width(s->ds);
 
1194
        s->g_height = ds_get_height(s->ds);
 
1195
        text_console_resize(s);
1163
1196
    }
1164
1197
    console_refresh(s);
1165
1198
}
1191
1224
    }
1192
1225
}
1193
1226
 
 
1227
static TextConsole *get_graphic_console(DisplayState *ds)
 
1228
{
 
1229
    int i;
 
1230
    TextConsole *s;
 
1231
    for (i = 0; i < nb_consoles; i++) {
 
1232
        s = consoles[i];
 
1233
        if (s->console_type == GRAPHIC_CONSOLE && s->ds == ds)
 
1234
            return s;
 
1235
    }
 
1236
    return NULL;
 
1237
}
 
1238
 
1194
1239
static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
1195
1240
{
1196
1241
    TextConsole *s;
1199
1244
    if (nb_consoles >= MAX_CONSOLES)
1200
1245
        return NULL;
1201
1246
    s = qemu_mallocz(sizeof(TextConsole));
1202
 
    if (!s) {
1203
 
        return NULL;
1204
 
    }
1205
1247
    if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
1206
1248
        (console_type == GRAPHIC_CONSOLE))) {
1207
1249
        active_console = s;
1218
1260
            consoles[i] = consoles[i - 1];
1219
1261
        }
1220
1262
        consoles[i] = s;
 
1263
        nb_consoles++;
1221
1264
    }
1222
1265
    return s;
1223
1266
}
1224
1267
 
1225
 
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
1226
 
                                  vga_hw_invalidate_ptr invalidate,
1227
 
                                  vga_hw_screen_dump_ptr screen_dump,
1228
 
                                  vga_hw_text_update_ptr text_update,
1229
 
                                  void *opaque)
 
1268
DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
1269
                                   vga_hw_invalidate_ptr invalidate,
 
1270
                                   vga_hw_screen_dump_ptr screen_dump,
 
1271
                                   vga_hw_text_update_ptr text_update,
 
1272
                                   void *opaque)
1230
1273
{
1231
1274
    TextConsole *s;
 
1275
    DisplayState *ds;
 
1276
 
 
1277
    ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
 
1278
    ds->allocator = &default_allocator; 
 
1279
    ds->surface = qemu_create_displaysurface(ds, 640, 480);
1232
1280
 
1233
1281
    s = new_console(ds, GRAPHIC_CONSOLE);
1234
 
    if (!s)
1235
 
      return NULL;
 
1282
    if (s == NULL) {
 
1283
        qemu_free_displaysurface(ds);
 
1284
        qemu_free(ds);
 
1285
        return NULL;
 
1286
    }
1236
1287
    s->hw_update = update;
1237
1288
    s->hw_invalidate = invalidate;
1238
1289
    s->hw_screen_dump = screen_dump;
1239
1290
    s->hw_text_update = text_update;
1240
1291
    s->hw = opaque;
1241
 
    return s;
 
1292
 
 
1293
    register_displaystate(ds);
 
1294
    return ds;
1242
1295
}
1243
1296
 
1244
1297
int is_graphic_console(void)
1246
1299
    return active_console && active_console->console_type == GRAPHIC_CONSOLE;
1247
1300
}
1248
1301
 
 
1302
int is_fixedsize_console(void)
 
1303
{
 
1304
    return active_console && active_console->console_type != TEXT_CONSOLE;
 
1305
}
 
1306
 
1249
1307
void console_color_init(DisplayState *ds)
1250
1308
{
1251
1309
    int i, j;
1252
1310
    for (j = 0; j < 2; j++) {
1253
1311
        for (i = 0; i < 8; i++) {
1254
 
            color_table[j][i] = col_expand(ds, 
 
1312
            color_table[j][i] = col_expand(ds,
1255
1313
                   vga_get_color(ds, color_table_rgb[j][i]));
1256
1314
        }
1257
1315
    }
1258
1316
}
1259
1317
 
1260
 
CharDriverState *text_console_init(DisplayState *ds, const char *p)
 
1318
static int n_text_consoles;
 
1319
static CharDriverState *text_consoles[128];
 
1320
static char *text_console_strs[128];
 
1321
 
 
1322
static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p)
1261
1323
{
1262
 
    CharDriverState *chr;
1263
1324
    TextConsole *s;
1264
1325
    unsigned width;
1265
1326
    unsigned height;
1266
1327
    static int color_inited;
1267
1328
 
1268
 
    chr = qemu_mallocz(sizeof(CharDriverState));
1269
 
    if (!chr)
1270
 
        return NULL;
1271
 
    s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
 
1329
    s = new_console(ds, (p == NULL) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
1272
1330
    if (!s) {
1273
1331
        free(chr);
1274
 
        return NULL;
 
1332
        return;
1275
1333
    }
1276
1334
    chr->opaque = s;
1277
1335
    chr->chr_write = console_puts;
1281
1339
    s->out_fifo.buf = s->out_fifo_buf;
1282
1340
    s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
1283
1341
    s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
 
1342
    s->ds = ds;
1284
1343
 
1285
1344
    if (!color_inited) {
1286
1345
        color_inited = 1;
1291
1350
    s->total_height = DEFAULT_BACKSCROLL;
1292
1351
    s->x = 0;
1293
1352
    s->y = 0;
1294
 
    width = s->ds->width;
1295
 
    height = s->ds->height;
1296
 
    if (p != 0) {
 
1353
    width = ds_get_width(s->ds);
 
1354
    height = ds_get_height(s->ds);
 
1355
    if (p != NULL) {
1297
1356
        width = strtoul(p, (char **)&p, 10);
1298
1357
        if (*p == 'C') {
1299
1358
            p++;
1323
1382
    s->t_attrib_default.unvisible = 0;
1324
1383
    s->t_attrib_default.fgcol = COLOR_WHITE;
1325
1384
    s->t_attrib_default.bgcol = COLOR_BLACK;
1326
 
 
1327
1385
    /* set current text attributes to default */
1328
1386
    s->t_attrib = s->t_attrib_default;
1329
1387
    text_console_resize(s);
1330
1388
 
1331
1389
    qemu_chr_reset(chr);
 
1390
    if (chr->init)
 
1391
        chr->init(chr);
 
1392
}
 
1393
 
 
1394
CharDriverState *text_console_init(const char *p)
 
1395
{
 
1396
    CharDriverState *chr;
 
1397
 
 
1398
    chr = qemu_mallocz(sizeof(CharDriverState));
 
1399
 
 
1400
    if (n_text_consoles == 128) {
 
1401
        fprintf(stderr, "Too many text consoles\n");
 
1402
        exit(1);
 
1403
    }
 
1404
    text_consoles[n_text_consoles] = chr;
 
1405
    text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL;
 
1406
    n_text_consoles++;
1332
1407
 
1333
1408
    return chr;
1334
1409
}
 
1410
 
 
1411
void text_consoles_set_display(DisplayState *ds)
 
1412
{
 
1413
    int i;
 
1414
 
 
1415
    for (i = 0; i < n_text_consoles; i++) {
 
1416
        text_console_do_init(text_consoles[i], ds, text_console_strs[i]);
 
1417
        qemu_free(text_console_strs[i]);
 
1418
    }
 
1419
 
 
1420
    n_text_consoles = 0;
 
1421
}
 
1422
 
 
1423
void qemu_console_resize(DisplayState *ds, int width, int height)
 
1424
{
 
1425
    TextConsole *s = get_graphic_console(ds);
 
1426
    if (!s) return;
 
1427
 
 
1428
    s->g_width = width;
 
1429
    s->g_height = height;
 
1430
    if (is_graphic_console()) {
 
1431
        ds->surface = qemu_resize_displaysurface(ds, width, height);
 
1432
        dpy_resize(ds);
 
1433
    }
 
1434
}
 
1435
 
 
1436
void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
 
1437
                       int dst_x, int dst_y, int w, int h)
 
1438
{
 
1439
    if (is_graphic_console()) {
 
1440
        dpy_copy(ds, src_x, src_y, dst_x, dst_y, w, h);
 
1441
    }
 
1442
}
 
1443
 
 
1444
PixelFormat qemu_different_endianness_pixelformat(int bpp)
 
1445
{
 
1446
    PixelFormat pf;
 
1447
 
 
1448
    memset(&pf, 0x00, sizeof(PixelFormat));
 
1449
 
 
1450
    pf.bits_per_pixel = bpp;
 
1451
    pf.bytes_per_pixel = bpp / 8;
 
1452
    pf.depth = bpp == 32 ? 24 : bpp;
 
1453
 
 
1454
    switch (bpp) {
 
1455
        case 24:
 
1456
            pf.rmask = 0x000000FF;
 
1457
            pf.gmask = 0x0000FF00;
 
1458
            pf.bmask = 0x00FF0000;
 
1459
            pf.rmax = 255;
 
1460
            pf.gmax = 255;
 
1461
            pf.bmax = 255;
 
1462
            pf.rshift = 0;
 
1463
            pf.gshift = 8;
 
1464
            pf.bshift = 16;
 
1465
            pf.rbits = 8;
 
1466
            pf.gbits = 8;
 
1467
            pf.bbits = 8;
 
1468
            break;
 
1469
        case 32:
 
1470
            pf.rmask = 0x0000FF00;
 
1471
            pf.gmask = 0x00FF0000;
 
1472
            pf.bmask = 0xFF000000;
 
1473
            pf.amask = 0x00000000;
 
1474
            pf.amax = 255;
 
1475
            pf.rmax = 255;
 
1476
            pf.gmax = 255;
 
1477
            pf.bmax = 255;
 
1478
            pf.ashift = 0;
 
1479
            pf.rshift = 8;
 
1480
            pf.gshift = 16;
 
1481
            pf.bshift = 24;
 
1482
            pf.rbits = 8;
 
1483
            pf.gbits = 8;
 
1484
            pf.bbits = 8;
 
1485
            pf.abits = 8;
 
1486
            break;
 
1487
        default:
 
1488
            break;
 
1489
    }
 
1490
    return pf;
 
1491
}
 
1492
 
 
1493
PixelFormat qemu_default_pixelformat(int bpp)
 
1494
{
 
1495
    PixelFormat pf;
 
1496
 
 
1497
    memset(&pf, 0x00, sizeof(PixelFormat));
 
1498
 
 
1499
    pf.bits_per_pixel = bpp;
 
1500
    pf.bytes_per_pixel = bpp / 8;
 
1501
    pf.depth = bpp == 32 ? 24 : bpp;
 
1502
 
 
1503
    switch (bpp) {
 
1504
        case 16:
 
1505
            pf.rmask = 0x0000F800;
 
1506
            pf.gmask = 0x000007E0;
 
1507
            pf.bmask = 0x0000001F;
 
1508
            pf.rmax = 31;
 
1509
            pf.gmax = 63;
 
1510
            pf.bmax = 31;
 
1511
            pf.rshift = 11;
 
1512
            pf.gshift = 5;
 
1513
            pf.bshift = 0;
 
1514
            pf.rbits = 5;
 
1515
            pf.gbits = 6;
 
1516
            pf.bbits = 5;
 
1517
            break;
 
1518
        case 24:
 
1519
            pf.rmask = 0x00FF0000;
 
1520
            pf.gmask = 0x0000FF00;
 
1521
            pf.bmask = 0x000000FF;
 
1522
            pf.rmax = 255;
 
1523
            pf.gmax = 255;
 
1524
            pf.bmax = 255;
 
1525
            pf.rshift = 16;
 
1526
            pf.gshift = 8;
 
1527
            pf.bshift = 0;
 
1528
            pf.rbits = 8;
 
1529
            pf.gbits = 8;
 
1530
            pf.bbits = 8;
 
1531
        case 32:
 
1532
            pf.rmask = 0x00FF0000;
 
1533
            pf.gmask = 0x0000FF00;
 
1534
            pf.bmask = 0x000000FF;
 
1535
            pf.amax = 255;
 
1536
            pf.rmax = 255;
 
1537
            pf.gmax = 255;
 
1538
            pf.bmax = 255;
 
1539
            pf.ashift = 24;
 
1540
            pf.rshift = 16;
 
1541
            pf.gshift = 8;
 
1542
            pf.bshift = 0;
 
1543
            pf.rbits = 8;
 
1544
            pf.gbits = 8;
 
1545
            pf.bbits = 8;
 
1546
            pf.abits = 8;
 
1547
            break;
 
1548
        default:
 
1549
            break;
 
1550
    }
 
1551
    return pf;
 
1552
}
 
1553
 
 
1554
DisplaySurface* defaultallocator_create_displaysurface(int width, int height)
 
1555
{
 
1556
    DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
 
1557
 
 
1558
    surface->width = width;
 
1559
    surface->height = height;
 
1560
    surface->linesize = width * 4;
 
1561
    surface->pf = qemu_default_pixelformat(32);
 
1562
#ifdef HOST_WORDS_BIGENDIAN
 
1563
    surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
 
1564
#else
 
1565
    surface->flags = QEMU_ALLOCATED_FLAG;
 
1566
#endif
 
1567
    surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
 
1568
 
 
1569
    return surface;
 
1570
}
 
1571
 
 
1572
DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface,
 
1573
                                          int width, int height)
 
1574
{
 
1575
    surface->width = width;
 
1576
    surface->height = height;
 
1577
    surface->linesize = width * 4;
 
1578
    surface->pf = qemu_default_pixelformat(32);
 
1579
    if (surface->flags & QEMU_ALLOCATED_FLAG)
 
1580
        surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
 
1581
    else
 
1582
        surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
 
1583
#ifdef HOST_WORDS_BIGENDIAN
 
1584
    surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
 
1585
#else
 
1586
    surface->flags = QEMU_ALLOCATED_FLAG;
 
1587
#endif
 
1588
 
 
1589
    return surface;
 
1590
}
 
1591
 
 
1592
DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
 
1593
                                              int linesize, uint8_t *data)
 
1594
{
 
1595
    DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
 
1596
 
 
1597
    surface->width = width;
 
1598
    surface->height = height;
 
1599
    surface->linesize = linesize;
 
1600
    surface->pf = qemu_default_pixelformat(bpp);
 
1601
#ifdef HOST_WORDS_BIGENDIAN
 
1602
    surface->flags = QEMU_BIG_ENDIAN_FLAG;
 
1603
#endif
 
1604
    surface->data = data;
 
1605
 
 
1606
    return surface;
 
1607
}
 
1608
 
 
1609
void defaultallocator_free_displaysurface(DisplaySurface *surface)
 
1610
{
 
1611
    if (surface == NULL)
 
1612
        return;
 
1613
    if (surface->flags & QEMU_ALLOCATED_FLAG)
 
1614
        qemu_free(surface->data);
 
1615
    qemu_free(surface);
 
1616
}