trunk/src/osd/sdl/draw13.c
| r31861 | r31862 | |
| 1 | 1 | //============================================================ |
| 2 | 2 | // |
| 3 | | // draw13.c - SDL 1.3 drawing implementation |
| 3 | // draw13.c - SDL 2.0 drawing implementation |
| 4 | 4 | // |
| 5 | | // Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team. |
| 5 | // Copyright (c) 1996-2014, Nicola Salmoria and the MAME Team. |
| 6 | 6 | // Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | // |
| 8 | 8 | // SDLMAME by Olivier Galibert and R. Belmont |
| r31861 | r31862 | |
| 145 | 145 | |
| 146 | 146 | // core functions |
| 147 | 147 | |
| 148 | | static void draw13_exit(void); |
| 149 | | static void draw13_attach(sdl_draw_info *info, sdl_window_info *window); |
| 150 | | static int draw13_window_create(sdl_window_info *window, int width, int height); |
| 151 | | static void draw13_window_resize(sdl_window_info *window, int width, int height); |
| 152 | | static void draw13_window_destroy(sdl_window_info *window); |
| 153 | | static int draw13_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 154 | | static render_primitive_list &draw13_window_get_primitives(sdl_window_info *window); |
| 155 | | static void draw13_destroy_all_textures(sdl_window_info *window); |
| 156 | | static void draw13_window_clear(sdl_window_info *window); |
| 157 | | static int draw13_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 158 | | static void draw13_destroy_texture(sdl_info *sdl, texture_info *texture); |
| 148 | static void drawsdl2_exit(void); |
| 149 | static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window); |
| 150 | static int drawsdl2_window_create(sdl_window_info *window, int width, int height); |
| 151 | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height); |
| 152 | static void drawsdl2_window_destroy(sdl_window_info *window); |
| 153 | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 154 | static render_primitive_list &drawsdl2_window_get_primitives(sdl_window_info *window); |
| 155 | static void drawsdl2_destroy_all_textures(sdl_window_info *window); |
| 156 | static void drawsdl2_window_clear(sdl_window_info *window); |
| 157 | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 158 | static void drawsdl2_destroy_texture(sdl_info *sdl, texture_info *texture); |
| 159 | 159 | |
| 160 | 160 | //============================================================ |
| 161 | 161 | // Textures |
| r31861 | r31862 | |
| 455 | 455 | #endif |
| 456 | 456 | |
| 457 | 457 | //============================================================ |
| 458 | | // draw13_init |
| 458 | // drawsdl2_init |
| 459 | 459 | //============================================================ |
| 460 | 460 | |
| 461 | 461 | static void add_list(copy_info **head, copy_info *element, Uint32 bm) |
| r31861 | r31862 | |
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | | int draw13_init(running_machine &machine, sdl_draw_info *callbacks) |
| 489 | int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks) |
| 490 | 490 | { |
| 491 | 491 | const char *stemp; |
| 492 | 492 | |
| 493 | 493 | // fill in the callbacks |
| 494 | | callbacks->exit = draw13_exit; |
| 495 | | callbacks->attach = draw13_attach; |
| 494 | callbacks->exit = drawsdl2_exit; |
| 495 | callbacks->attach = drawsdl2_attach; |
| 496 | 496 | |
| 497 | 497 | osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n"); |
| 498 | 498 | |
| r31861 | r31862 | |
| 518 | 518 | |
| 519 | 519 | |
| 520 | 520 | //============================================================ |
| 521 | | // draw13_exit |
| 521 | // drawsdl2_exit |
| 522 | 522 | //============================================================ |
| 523 | 523 | |
| 524 | | static void draw13_exit(void) |
| 524 | static void drawsdl2_exit(void) |
| 525 | 525 | { |
| 526 | 526 | int i; |
| 527 | 527 | copy_info *bi, *freeme; |
| r31861 | r31862 | |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | //============================================================ |
| 542 | | // draw13_attach |
| 542 | // drawsdl2_attach |
| 543 | 543 | //============================================================ |
| 544 | 544 | |
| 545 | | static void draw13_attach(sdl_draw_info *info, sdl_window_info *window) |
| 545 | static void drawsdl2_attach(sdl_draw_info *info, sdl_window_info *window) |
| 546 | 546 | { |
| 547 | 547 | // fill in the callbacks |
| 548 | | window->create = draw13_window_create; |
| 549 | | window->resize = draw13_window_resize; |
| 550 | | window->get_primitives = draw13_window_get_primitives; |
| 551 | | window->draw = draw13_window_draw; |
| 552 | | window->destroy = draw13_window_destroy; |
| 553 | | window->destroy_all_textures = draw13_destroy_all_textures; |
| 554 | | window->clear = draw13_window_clear; |
| 555 | | window->xy_to_render_target = draw13_xy_to_render_target; |
| 548 | window->create = drawsdl2_window_create; |
| 549 | window->resize = drawsdl2_window_resize; |
| 550 | window->get_primitives = drawsdl2_window_get_primitives; |
| 551 | window->draw = drawsdl2_window_draw; |
| 552 | window->destroy = drawsdl2_window_destroy; |
| 553 | window->destroy_all_textures = drawsdl2_destroy_all_textures; |
| 554 | window->clear = drawsdl2_window_clear; |
| 555 | window->xy_to_render_target = drawsdl2_xy_to_render_target; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | //============================================================ |
| 559 | | // draw13_window_create |
| 559 | // drawsdl2_window_create |
| 560 | 560 | //============================================================ |
| 561 | 561 | |
| 562 | | static int draw13_window_create(sdl_window_info *window, int width, int height) |
| 562 | static int drawsdl2_window_create(sdl_window_info *window, int width, int height) |
| 563 | 563 | { |
| 564 | 564 | // allocate memory for our structures |
| 565 | 565 | sdl_info *sdl = (sdl_info *) osd_malloc(sizeof(*sdl)); |
| 566 | 566 | |
| 567 | | osd_printf_verbose("Enter draw13_window_create\n"); |
| 567 | osd_printf_verbose("Enter drawsdl2_window_create\n"); |
| 568 | 568 | |
| 569 | 569 | memset(sdl, 0, sizeof(*sdl)); |
| 570 | 570 | |
| r31861 | r31862 | |
| 638 | 638 | sdl->texture_max_height = 64; |
| 639 | 639 | |
| 640 | 640 | SDL_RenderPresent(sdl->sdl_renderer); |
| 641 | | osd_printf_verbose("Leave draw13_window_create\n"); |
| 641 | osd_printf_verbose("Leave drawsdl2_window_create\n"); |
| 642 | 642 | return 0; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | //============================================================ |
| 646 | | // draw13_window_resize |
| 646 | // drawsdl2_window_resize |
| 647 | 647 | //============================================================ |
| 648 | 648 | |
| 649 | | static void draw13_window_resize(sdl_window_info *window, int width, int height) |
| 649 | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height) |
| 650 | 650 | { |
| 651 | 651 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 652 | 652 | |
| r31861 | r31862 | |
| 665 | 665 | // drawsdl_xy_to_render_target |
| 666 | 666 | //============================================================ |
| 667 | 667 | |
| 668 | | static int draw13_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 668 | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 669 | 669 | { |
| 670 | 670 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 671 | 671 | |
| r31861 | r31862 | |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | //============================================================ |
| 682 | | // draw13_window_get_primitives |
| 682 | // drawsdl2_window_get_primitives |
| 683 | 683 | //============================================================ |
| 684 | 684 | |
| 685 | | static render_primitive_list &draw13_window_get_primitives(sdl_window_info *window) |
| 685 | static render_primitive_list &drawsdl2_window_get_primitives(sdl_window_info *window) |
| 686 | 686 | { |
| 687 | 687 | if ((!window->fullscreen) || (video_config.switchres)) |
| 688 | 688 | { |
| r31861 | r31862 | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | //============================================================ |
| 700 | | // draw13_window_draw |
| 700 | // drawsdl2_window_draw |
| 701 | 701 | //============================================================ |
| 702 | 702 | |
| 703 | | static int draw13_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 703 | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 704 | 704 | { |
| 705 | 705 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 706 | 706 | render_primitive *prim; |
| r31861 | r31862 | |
| 809 | 809 | |
| 810 | 810 | |
| 811 | 811 | //============================================================ |
| 812 | | // draw13_window_clear |
| 812 | // drawsdl2_window_clear |
| 813 | 813 | //============================================================ |
| 814 | 814 | |
| 815 | | static void draw13_window_clear(sdl_window_info *window) |
| 815 | static void drawsdl2_window_clear(sdl_window_info *window) |
| 816 | 816 | { |
| 817 | 817 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 818 | 818 | |
| r31861 | r31862 | |
| 821 | 821 | |
| 822 | 822 | |
| 823 | 823 | //============================================================ |
| 824 | | // draw13_window_destroy |
| 824 | // drawsdl2_window_destroy |
| 825 | 825 | //============================================================ |
| 826 | 826 | |
| 827 | | static void draw13_window_destroy(sdl_window_info *window) |
| 827 | static void drawsdl2_window_destroy(sdl_window_info *window) |
| 828 | 828 | { |
| 829 | 829 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 830 | 830 | |
| r31861 | r31862 | |
| 834 | 834 | |
| 835 | 835 | // free the memory in the window |
| 836 | 836 | |
| 837 | | draw13_destroy_all_textures(window); |
| 837 | drawsdl2_destroy_all_textures(window); |
| 838 | 838 | |
| 839 | 839 | SDL_DestroyWindow(window->sdl_window); |
| 840 | 840 | |
| r31861 | r31862 | |
| 1107 | 1107 | texture_info *expire = texture; |
| 1108 | 1108 | texture = texture->next; |
| 1109 | 1109 | if (now - expire->last_access > osd_ticks_per_second()) |
| 1110 | | draw13_destroy_texture(sdl, expire); |
| 1110 | drawsdl2_destroy_texture(sdl, expire); |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | // nothing found |
| r31861 | r31862 | |
| 1147 | 1147 | return texture; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | | static void draw13_destroy_texture(sdl_info *sdl, texture_info *texture) |
| 1150 | static void drawsdl2_destroy_texture(sdl_info *sdl, texture_info *texture) |
| 1151 | 1151 | { |
| 1152 | 1152 | texture_info *p; |
| 1153 | 1153 | |
| r31861 | r31862 | |
| 1169 | 1169 | osd_free(texture); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | | static void draw13_destroy_all_textures(sdl_window_info *window) |
| 1172 | static void drawsdl2_destroy_all_textures(sdl_window_info *window) |
| 1173 | 1173 | { |
| 1174 | 1174 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 1175 | 1175 | texture_info *next_texture=NULL, *texture = NULL; |
| r31861 | r31862 | |
| 1189 | 1189 | while (texture) |
| 1190 | 1190 | { |
| 1191 | 1191 | next_texture = texture->next; |
| 1192 | | draw13_destroy_texture(sdl, texture); |
| 1192 | drawsdl2_destroy_texture(sdl, texture); |
| 1193 | 1193 | texture = next_texture; |
| 1194 | 1194 | } |
| 1195 | 1195 | |