src/osd/sdl/drawogl.c
| r3029 | r3030 | |
| 749 | 749 | sdl_info *sdl = window->dxdata; |
| 750 | 750 | |
| 751 | 751 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 752 | //SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id); |
| 752 | 753 | SDL_SetWindowSize(window->window_id, width, height); |
| 753 | 754 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 754 | | |
| 755 | | //FIXME: no idea why, but this is necessary to avoid crashes with numscreen>1 |
| 756 | | SDL_GL_DeleteContext(sdl->gl_context_id); |
| 757 | | sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); |
| 755 | sdl->blittimer = 3; |
| 758 | 756 | #else |
| 759 | 757 | SDL_FreeSurface(sdl->sdlsurf); |
| 760 | 758 | |
| r3029 | r3030 | |
| 762 | 760 | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 763 | 761 | window->width = sdl->sdlsurf->w; |
| 764 | 762 | window->height = sdl->sdlsurf->h; |
| 765 | | |
| 766 | 763 | #endif |
| 767 | 764 | sdl->init_context = 1; |
| 768 | 765 | |
| r3029 | r3030 | |
| 1587 | 1584 | if (sdl == NULL) |
| 1588 | 1585 | return; |
| 1589 | 1586 | |
| 1587 | // free the memory in the window |
| 1588 | |
| 1589 | drawogl_destroy_all_textures(window); |
| 1590 | |
| 1590 | 1591 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1591 | 1592 | SDL_GL_DeleteContext(sdl->gl_context_id); |
| 1592 | 1593 | SDL_DestroyWindow(window->window_id); |
| r3029 | r3030 | |
| 1598 | 1599 | } |
| 1599 | 1600 | #endif |
| 1600 | 1601 | |
| 1601 | | // free the memory in the window |
| 1602 | | |
| 1603 | | drawogl_destroy_all_textures(window); |
| 1604 | | |
| 1605 | 1602 | free(sdl); |
| 1606 | 1603 | window->dxdata = NULL; |
| 1607 | 1604 | } |
| r3029 | r3030 | |
| 1761 | 1758 | texture->borderpix = 0; // don't border the screen right now, there's a bug |
| 1762 | 1759 | } |
| 1763 | 1760 | |
| 1764 | | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1765 | | |
| 1766 | | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1767 | | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1761 | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1762 | |
| 1763 | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1764 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1768 | 1765 | |
| 1769 | 1766 | // if we added pixels for the border, and that just barely pushed us over, take it back |
| 1770 | 1767 | if (texture->borderpix && |
| r3029 | r3030 | |
| 1773 | 1770 | { |
| 1774 | 1771 | texture->borderpix = FALSE; |
| 1775 | 1772 | |
| 1776 | | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1777 | | |
| 1778 | | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1779 | | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1773 | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1774 | |
| 1775 | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1776 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1780 | 1777 | } |
| 1781 | 1778 | |
| 1782 | 1779 | // if we're above the max width/height, do what? |
| 1783 | | if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height) |
| 1784 | | { |
| 1785 | | static int printed = FALSE; |
| 1786 | | if (!printed) |
| 1787 | | mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height); |
| 1788 | | printed = TRUE; |
| 1789 | | } |
| 1780 | if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height) |
| 1781 | { |
| 1782 | static int printed = FALSE; |
| 1783 | if (!printed) |
| 1784 | mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height); |
| 1785 | printed = TRUE; |
| 1786 | } |
| 1790 | 1787 | |
| 1791 | | if(!texture->nocopy || texture->type==TEXTURE_TYPE_DYNAMIC || texture->type==TEXTURE_TYPE_SHADER || |
| 1792 | | // any of the mame core's device generated bitmap types: |
| 1793 | | texture->format==SDL_TEXFORMAT_RGB32 || |
| 1794 | | texture->format==SDL_TEXFORMAT_RGB32_PALETTED || |
| 1795 | | texture->format==SDL_TEXFORMAT_RGB15 || |
| 1796 | | texture->format==SDL_TEXFORMAT_RGB15_PALETTED || |
| 1797 | | texture->format==SDL_TEXFORMAT_PALETTE16 || |
| 1798 | | texture->format==SDL_TEXFORMAT_PALETTE16A |
| 1799 | | ) |
| 1800 | | { |
| 1801 | | mame_printf_verbose("GL texture: copy %d, shader %d, dynamic %d, %dx%d %dx%d [%s, Equal: %d, Palette: %d,\n" |
| 1802 | | " scale %dx%d (eff: %d), border %d, pitch %d,%d/%d], colors: %d, bytes/pix %d\n", |
| 1803 | | !texture->nocopy, texture->type==TEXTURE_TYPE_SHADER, texture->type==TEXTURE_TYPE_DYNAMIC, |
| 1804 | | finalwidth, finalheight, finalwidth_create, finalheight_create, |
| 1805 | | texfmt_to_string[texture->format], |
| 1806 | | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], |
| 1807 | | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], |
| 1808 | | texture->xprescale, texture->yprescale, texture->prescale_effect, |
| 1809 | | texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width, |
| 1810 | | sdl->totalColors, (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE] |
| 1811 | | ); |
| 1812 | | } |
| 1788 | if(!texture->nocopy || texture->type==TEXTURE_TYPE_DYNAMIC || texture->type==TEXTURE_TYPE_SHADER || |
| 1789 | // any of the mame core's device generated bitmap types: |
| 1790 | texture->format==SDL_TEXFORMAT_RGB32 || |
| 1791 | texture->format==SDL_TEXFORMAT_RGB32_PALETTED || |
| 1792 | texture->format==SDL_TEXFORMAT_RGB15 || |
| 1793 | texture->format==SDL_TEXFORMAT_RGB15_PALETTED || |
| 1794 | texture->format==SDL_TEXFORMAT_PALETTE16 || |
| 1795 | texture->format==SDL_TEXFORMAT_PALETTE16A |
| 1796 | ) |
| 1797 | { |
| 1798 | mame_printf_verbose("GL texture: copy %d, shader %d, dynamic %d, %dx%d %dx%d [%s, Equal: %d, Palette: %d,\n" |
| 1799 | " scale %dx%d (eff: %d), border %d, pitch %d,%d/%d], colors: %d, bytes/pix %d\n", |
| 1800 | !texture->nocopy, texture->type==TEXTURE_TYPE_SHADER, texture->type==TEXTURE_TYPE_DYNAMIC, |
| 1801 | finalwidth, finalheight, finalwidth_create, finalheight_create, |
| 1802 | texfmt_to_string[texture->format], |
| 1803 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], |
| 1804 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], |
| 1805 | texture->xprescale, texture->yprescale, texture->prescale_effect, |
| 1806 | texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width, |
| 1807 | sdl->totalColors, (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE] |
| 1808 | ); |
| 1809 | } |
| 1813 | 1810 | |
| 1814 | 1811 | // set the final values |
| 1815 | 1812 | texture->rawwidth = finalwidth; |
| r3029 | r3030 | |
| 2309 | 2306 | texture->format = SDL_TEXFORMAT_ARGB32; |
| 2310 | 2307 | break; |
| 2311 | 2308 | case TEXFORMAT_RGB32: |
| 2312 | | if (texsource->palette != NULL) |
| 2313 | | texture->format = SDL_TEXFORMAT_RGB32_PALETTED; |
| 2314 | | else |
| 2315 | | texture->format = SDL_TEXFORMAT_RGB32; |
| 2309 | if (texsource->palette != NULL) |
| 2310 | texture->format = SDL_TEXFORMAT_RGB32_PALETTED; |
| 2311 | else |
| 2312 | texture->format = SDL_TEXFORMAT_RGB32; |
| 2316 | 2313 | break; |
| 2317 | 2314 | case TEXFORMAT_PALETTE16: |
| 2318 | 2315 | texture->format = SDL_TEXFORMAT_PALETTE16; |
| 2319 | 2316 | break; |
| 2320 | 2317 | case TEXFORMAT_RGB15: |
| 2321 | | if (texsource->palette != NULL) |
| 2322 | | texture->format = SDL_TEXFORMAT_RGB15_PALETTED; |
| 2323 | | else |
| 2324 | | texture->format = SDL_TEXFORMAT_RGB15; |
| 2325 | | |
| 2318 | if (texsource->palette != NULL) |
| 2319 | texture->format = SDL_TEXFORMAT_RGB15_PALETTED; |
| 2320 | else |
| 2321 | texture->format = SDL_TEXFORMAT_RGB15; |
| 2326 | 2322 | break; |
| 2327 | 2323 | case TEXFORMAT_PALETTEA16: |
| 2328 | 2324 | texture->format = SDL_TEXFORMAT_PALETTE16A; |
| r3029 | r3030 | |
| 2351 | 2347 | if ( texture->type==TEXTURE_TYPE_SHADER ) |
| 2352 | 2348 | { |
| 2353 | 2349 | if ( texture_shader_create(sdl, window, texsource, texture, flags) ) |
| 2354 | | { |
| 2355 | | free(texture); |
| 2356 | | return NULL; |
| 2357 | | } |
| 2358 | | } |
| 2350 | { |
| 2351 | free(texture); |
| 2352 | return NULL; |
| 2353 | } |
| 2354 | } |
| 2359 | 2355 | else |
| 2360 | 2356 | { |
| 2361 | 2357 | // get a name for this texture |
| r3029 | r3030 | |
| 2363 | 2359 | |
| 2364 | 2360 | glEnable(texture->texTarget); |
| 2365 | 2361 | |
| 2366 | | // make sure we're operating on *this* texture |
| 2367 | | glBindTexture(texture->texTarget, texture->texture); |
| 2362 | // make sure we're operating on *this* texture |
| 2363 | glBindTexture(texture->texTarget, texture->texture); |
| 2364 | |
| 2365 | // this doesn't actually upload, it just sets up the PBO's parameters |
| 2366 | glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], |
| 2367 | texture->rawwidth_create, texture->rawheight_create, |
| 2368 | texture->borderpix ? 1 : 0, |
| 2369 | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2370 | texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); |
| 2368 | 2371 | |
| 2369 | | // this doesn't actually upload, it just sets up the PBO's parameters |
| 2370 | | glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], |
| 2371 | | texture->rawwidth_create, texture->rawheight_create, |
| 2372 | | texture->borderpix ? 1 : 0, |
| 2373 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2374 | | texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); |
| 2375 | | |
| 2376 | 2372 | if ((PRIMFLAG_GET_SCREENTEX(flags)) && video_config.filter) |
| 2377 | 2373 | { |
| 2378 | 2374 | // screen textures get the user's choice of filtering |
| r3029 | r3030 | |
| 2408 | 2404 | |
| 2409 | 2405 | if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2410 | 2406 | { |
| 2411 | | assert(sdl->usepbo); |
| 2407 | assert(sdl->usepbo); |
| 2412 | 2408 | |
| 2413 | | // create the PBO |
| 2414 | | pfn_glGenBuffers(1, (GLuint *)&texture->pbo); |
| 2409 | // create the PBO |
| 2410 | pfn_glGenBuffers(1, (GLuint *)&texture->pbo); |
| 2415 | 2411 | |
| 2416 | | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2412 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2417 | 2413 | |
| 2418 | | // set up the PBO dimension, .. |
| 2414 | // set up the PBO dimension, .. |
| 2419 | 2415 | pfn_glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, |
| 2420 | 2416 | texture->rawwidth * texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], |
| 2421 | 2417 | NULL, GL_STREAM_DRAW); |
| 2422 | | } |
| 2418 | } |
| 2423 | 2419 | |
| 2424 | | if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC ) |
| 2425 | | { |
| 2426 | | texture->data = malloc(texture->rawwidth* texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2427 | | texture->data_own=TRUE; |
| 2428 | | } |
| 2420 | if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC ) |
| 2421 | { |
| 2422 | texture->data = malloc(texture->rawwidth* texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2423 | texture->data_own=TRUE; |
| 2424 | } |
| 2429 | 2425 | |
| 2430 | 2426 | if (texture->prescale_effect && !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST]) |
| 2431 | 2427 | texture->effectbuf = malloc_or_die(texsource->width * 3 * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| r3029 | r3030 | |
| 2442 | 2438 | // Load The Data |
| 2443 | 2439 | pfn_glBufferData( GL_ARRAY_BUFFER_ARB, 4*2*sizeof(GLfloat), texture->texCoord, GL_STREAM_DRAW ); |
| 2444 | 2440 | glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers |
| 2445 | | } else { |
| 2441 | } |
| 2442 | else |
| 2443 | { |
| 2446 | 2444 | glTexCoordPointer(2, GL_FLOAT, 0, texture->texCoord); |
| 2447 | 2445 | } |
| 2448 | 2446 | |
| r3029 | r3030 | |
| 2516 | 2514 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2517 | 2515 | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2518 | 2516 | texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); |
| 2519 | | } else { |
| 2517 | } |
| 2518 | else |
| 2519 | { |
| 2520 | 2520 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2521 | 2521 | GL_ALPHA, GL_UNSIGNED_SHORT, texture->data); |
| 2522 | 2522 | } |
| 2523 | | } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2523 | } |
| 2524 | else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2524 | 2525 | { |
| 2525 | 2526 | glBindTexture(texture->texTarget, texture->texture); |
| 2526 | 2527 | |
| r3029 | r3030 | |
| 2533 | 2534 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2534 | 2535 | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2535 | 2536 | texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); |
| 2536 | | } else { |
| 2537 | } |
| 2538 | else |
| 2539 | { |
| 2537 | 2540 | glBindTexture(texture->texTarget, texture->texture); |
| 2538 | 2541 | |
| 2539 | 2542 | // give the card a hint |
| r3029 | r3030 | |
| 2542 | 2545 | else |
| 2543 | 2546 | glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->rawwidth); |
| 2544 | 2547 | |
| 2545 | | // and upload the image |
| 2546 | | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2547 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2548 | | texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); |
| 2548 | // and upload the image |
| 2549 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2550 | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2551 | texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); |
| 2549 | 2552 | } |
| 2550 | 2553 | } |
| 2551 | 2554 | |
| r3029 | r3030 | |
| 2585 | 2588 | |
| 2586 | 2589 | if ( texture->type != TEXTURE_TYPE_SHADER || |
| 2587 | 2590 | ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->glsl_program_mb2sc ) ) |
| 2588 | | { |
| 2591 | { |
| 2589 | 2592 | // compute the U/V scale factors |
| 2590 | 2593 | if (texture->borderpix) |
| 2591 | 2594 | { |
| r3029 | r3030 | |
| 2603 | 2606 | vstart = 0.0f; |
| 2604 | 2607 | vstop = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create; |
| 2605 | 2608 | } |
| 2606 | | } else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc ) |
| 2609 | } |
| 2610 | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc ) |
| 2607 | 2611 | { |
| 2608 | 2612 | int surf_w_pow2 = get_valid_pow2_value (window->width, texture->texpow2); |
| 2609 | 2613 | int surf_h_pow2 = get_valid_pow2_value (window->height, texture->texpow2); |
| r3029 | r3030 | |
| 2612 | 2616 | ustop = (float)(window->width) / (float)surf_w_pow2; |
| 2613 | 2617 | vstart = 0.0f; |
| 2614 | 2618 | vstop = (float)(window->height) / (float)surf_h_pow2; |
| 2615 | | } else { |
| 2619 | } |
| 2620 | else |
| 2621 | { |
| 2616 | 2622 | assert(0); // ?? |
| 2617 | 2623 | } |
| 2618 | 2624 | |
| r3029 | r3030 | |
| 2639 | 2645 | texture->texCoord[5]=vstart + dv * 0.0f; |
| 2640 | 2646 | texture->texCoord[6]=ustart + du * 0.0f; |
| 2641 | 2647 | texture->texCoord[7]=vstart + dv * 0.0f; |
| 2642 | | } else { |
| 2648 | } |
| 2649 | else |
| 2650 | { |
| 2643 | 2651 | // transformation: mamebm -> scrn |
| 2644 | 2652 | texture->texCoord[0]=ustart + du * prim->texcoords.tl.u; |
| 2645 | 2653 | texture->texCoord[1]=vstart + dv * prim->texcoords.tl.v; |
| r3029 | r3030 | |
| 2670 | 2678 | if ( shaderIdx<=sdl->glsl_program_mb2sc ) |
| 2671 | 2679 | { |
| 2672 | 2680 | glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]); |
| 2673 | | } else { |
| 2681 | } |
| 2682 | else |
| 2683 | { |
| 2674 | 2684 | glBindTexture(texture->texTarget, texture->mpass_texture_scrn[mpass_src_idx]); |
| 2675 | 2685 | } |
| 2676 | 2686 | pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]); |
| r3029 | r3030 | |
| 2684 | 2694 | { |
| 2685 | 2695 | glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]); |
| 2686 | 2696 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]); |
| 2687 | | } else { |
| 2697 | } |
| 2698 | else |
| 2699 | { |
| 2688 | 2700 | glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[texture->mpass_dest_idx]); |
| 2689 | 2701 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_mamebm[texture->mpass_dest_idx]); |
| 2690 | 2702 | } |
| r3029 | r3030 | |
| 2694 | 2706 | glPushAttrib(GL_VIEWPORT_BIT); |
| 2695 | 2707 | GL_CHECK_ERROR_NORMAL(); |
| 2696 | 2708 | glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight); |
| 2697 | | } else if ( shaderIdx==sdl->glsl_program_mb2sc ) |
| 2709 | } |
| 2710 | else if ( shaderIdx==sdl->glsl_program_mb2sc ) |
| 2698 | 2711 | { |
| 2699 | 2712 | assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 ); |
| 2700 | 2713 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2701 | 2714 | GL_CHECK_ERROR_NORMAL(); |
| 2702 | 2715 | } |
| 2703 | 2716 | glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn .. |
| 2704 | | } else { |
| 2717 | } |
| 2718 | else |
| 2719 | { |
| 2705 | 2720 | glBindTexture(texture->texTarget, 0); |
| 2706 | 2721 | pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
| 2707 | 2722 | |
| r3029 | r3030 | |
| 2759 | 2774 | if ( GL_CHECK_ERROR_QUIET() ) { |
| 2760 | 2775 | mame_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx); |
| 2761 | 2776 | } |
| 2762 | | } else { |
| 2777 | } |
| 2778 | else |
| 2779 | { |
| 2763 | 2780 | mame_printf_verbose("GLSL: could not get render container for screen %d\n", window->start_viewscreen); |
| 2764 | 2781 | } |
| 2765 | 2782 | } |
| r3029 | r3030 | |
| 2772 | 2789 | |
| 2773 | 2790 | // if we didn't find one, create a new texture |
| 2774 | 2791 | if (texture == NULL && prim->texture.base != NULL) |
| 2775 | | { |
| 2776 | | texture = texture_create(sdl, window, &prim->texture, prim->flags); |
| 2792 | { |
| 2793 | texture = texture_create(sdl, window, &prim->texture, prim->flags); |
| 2777 | 2794 | |
| 2778 | | } else if (texture != NULL) |
| 2779 | | { |
| 2795 | } |
| 2796 | else if (texture != NULL) |
| 2797 | { |
| 2780 | 2798 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2781 | 2799 | { |
| 2782 | 2800 | pfn_glUseProgramObjectARB(sdl->glsl_program[shaderIdx]); // back to our shader |
| 2783 | | } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2784 | | { |
| 2785 | | assert ( sdl->usepbo ) ; |
| 2786 | | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2787 | | glEnable(texture->texTarget); |
| 2788 | | } else { |
| 2789 | | glEnable(texture->texTarget); |
| 2790 | | } |
| 2791 | 2801 | } |
| 2802 | else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2803 | { |
| 2804 | assert ( sdl->usepbo ) ; |
| 2805 | pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); |
| 2806 | glEnable(texture->texTarget); |
| 2807 | } |
| 2808 | else |
| 2809 | { |
| 2810 | glEnable(texture->texTarget); |
| 2811 | } |
| 2812 | } |
| 2792 | 2813 | |
| 2793 | | if (texture != NULL) |
| 2814 | if (texture != NULL) |
| 2794 | 2815 | { |
| 2795 | 2816 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2796 | 2817 | { |
| r3029 | r3030 | |
| 2825 | 2846 | // Load The Data |
| 2826 | 2847 | pfn_glBufferSubData( GL_ARRAY_BUFFER_ARB, 0, 4*2*sizeof(GLfloat), texture->texCoord ); |
| 2827 | 2848 | glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers |
| 2828 | | } else { |
| 2849 | } |
| 2850 | else |
| 2851 | { |
| 2829 | 2852 | glTexCoordPointer(2, GL_FLOAT, 0, texture->texCoord); |
| 2830 | 2853 | } |
| 2831 | 2854 | } |
| r3029 | r3030 | |
| 2889 | 2912 | static void drawogl_destroy_all_textures(sdl_window_info *window) |
| 2890 | 2913 | { |
| 2891 | 2914 | sdl_info *sdl = window->dxdata; |
| 2892 | | int lock=FALSE; |
| 2915 | texture_info *next_texture=NULL, *texture = NULL; |
| 2916 | int lock=FALSE; |
| 2893 | 2917 | |
| 2894 | | if ( ! sdl->initialized ) |
| 2895 | | { |
| 2918 | if (sdl == NULL) |
| 2896 | 2919 | return; |
| 2897 | | } |
| 2898 | 2920 | |
| 2899 | | if(window->primlist && window->primlist->lock) { lock=TRUE; osd_lock_acquire(window->primlist->lock); } |
| 2900 | | { |
| 2901 | | texture_info *next_texture=NULL, *texture = NULL; |
| 2902 | | sdl_info *sdl = window->dxdata; |
| 2921 | if ( !sdl->initialized ) |
| 2922 | return; |
| 2903 | 2923 | |
| 2904 | | if (sdl == NULL) |
| 2905 | | goto exit; |
| 2924 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 2925 | SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id); |
| 2926 | #endif |
| 2927 | |
| 2928 | if(window->primlist && window->primlist->lock) |
| 2929 | { |
| 2930 | lock=TRUE; |
| 2931 | osd_lock_acquire(window->primlist->lock); |
| 2932 | } |
| 2906 | 2933 | |
| 2907 | | texture = sdl->texlist; |
| 2934 | texture = sdl->texlist; |
| 2935 | glFinish(); |
| 2908 | 2936 | |
| 2909 | | glFinish(); |
| 2937 | texture_all_disable(sdl); |
| 2938 | glFinish(); |
| 2939 | glDisableClientState(GL_VERTEX_ARRAY); |
| 2910 | 2940 | |
| 2911 | | texture_all_disable(sdl); |
| 2941 | while (texture) |
| 2942 | { |
| 2943 | next_texture = texture->next; |
| 2912 | 2944 | |
| 2913 | | glFinish(); |
| 2945 | if(sdl->usevbo) |
| 2946 | { |
| 2947 | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 2948 | texture->texCoordBufferName=0; |
| 2949 | } |
| 2950 | |
| 2951 | if(sdl->usepbo && texture->pbo) |
| 2952 | { |
| 2953 | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 2954 | texture->pbo=0; |
| 2955 | } |
| 2956 | |
| 2957 | if( sdl->glsl_program_num > 1 ) |
| 2958 | { |
| 2959 | assert(sdl->usefbo); |
| 2960 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 2961 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 2962 | } |
| 2963 | |
| 2964 | if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 2965 | { |
| 2966 | assert(sdl->usefbo); |
| 2967 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 2968 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 2969 | } |
| 2914 | 2970 | |
| 2915 | | glDisableClientState(GL_VERTEX_ARRAY); |
| 2971 | if(texture->lut_texture) |
| 2972 | glDeleteTextures(1, (GLuint *)&texture->lut_texture); |
| 2916 | 2973 | |
| 2917 | | while (texture) |
| 2918 | | { |
| 2919 | | next_texture = texture->next; |
| 2920 | | |
| 2921 | | if(sdl->usevbo) |
| 2922 | | { |
| 2923 | | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 2924 | | texture->texCoordBufferName=0; |
| 2925 | | } |
| 2926 | | |
| 2927 | | if(sdl->usepbo && texture->pbo) |
| 2928 | | { |
| 2929 | | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 2930 | | texture->pbo=0; |
| 2931 | | } |
| 2932 | | |
| 2933 | | if( sdl->glsl_program_num > 1 ) |
| 2934 | | { |
| 2935 | | assert(sdl->usefbo); |
| 2936 | | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 2937 | | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 2938 | | } |
| 2939 | | |
| 2940 | | if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 2941 | | { |
| 2942 | | assert(sdl->usefbo); |
| 2943 | | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 2944 | | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 2945 | | } |
| 2946 | | |
| 2947 | | if(texture->lut_texture) |
| 2948 | | glDeleteTextures(1, (GLuint *)&texture->lut_texture); |
| 2949 | | |
| 2950 | | glDeleteTextures(1, (GLuint *)&texture->texture); |
| 2951 | | if ( texture->data_own ) |
| 2952 | | { |
| 2953 | | free(texture->data); |
| 2954 | | texture->data=NULL; |
| 2955 | | texture->data_own=FALSE; |
| 2956 | | } |
| 2957 | | if (texture->effectbuf) |
| 2958 | | { |
| 2959 | | free(texture->effectbuf); |
| 2960 | | } |
| 2961 | | free(texture); |
| 2962 | | texture = next_texture; |
| 2963 | | } |
| 2964 | | sdl->texlist = NULL; |
| 2965 | | |
| 2966 | | if ( sdl->useglsl ) |
| 2974 | glDeleteTextures(1, (GLuint *)&texture->texture); |
| 2975 | if ( texture->data_own ) |
| 2967 | 2976 | { |
| 2968 | | glsl_shader_free(sdl->glsl); |
| 2969 | | sdl->glsl = NULL; |
| 2977 | free(texture->data); |
| 2978 | texture->data=NULL; |
| 2979 | texture->data_own=FALSE; |
| 2970 | 2980 | } |
| 2981 | if (texture->effectbuf) |
| 2982 | { |
| 2983 | free(texture->effectbuf); |
| 2984 | } |
| 2985 | free(texture); |
| 2986 | texture = next_texture; |
| 2987 | } |
| 2988 | sdl->texlist = NULL; |
| 2971 | 2989 | |
| 2972 | | sdl->initialized = 0; |
| 2973 | | } |
| 2974 | | exit: |
| 2975 | | if(lock) { osd_lock_release(window->primlist->lock); } |
| 2990 | if ( sdl->useglsl ) |
| 2991 | { |
| 2992 | glsl_shader_free(sdl->glsl); |
| 2993 | sdl->glsl = NULL; |
| 2994 | } |
| 2995 | |
| 2996 | sdl->initialized = 0; |
| 2997 | |
| 2998 | if (lock) |
| 2999 | osd_lock_release(window->primlist->lock); |
| 2976 | 3000 | } |
| 2977 | 3001 | |
| 2978 | 3002 | //============================================================ |
src/osd/sdl/input.c
| r3029 | r3030 | |
| 169 | 169 | |
| 170 | 170 | // deivce list management |
| 171 | 171 | static void device_list_reset_devices(device_info *devlist_head); |
| 172 | | static void device_list_free_devices(device_info *devlist_head); |
| 172 | static void device_list_free_devices(device_info **devlist_head); |
| 173 | 173 | |
| 174 | 174 | // generic device management |
| 175 | 175 | static device_info *generic_device_alloc(device_info **devlist_head_ptr, const char *name); |
| r3029 | r3030 | |
| 943 | 943 | // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then |
| 944 | 944 | devinfo = generic_device_alloc(&mouse_list, "System mouse"); |
| 945 | 945 | devinfo->device = input_device_add(DEVICE_CLASS_MOUSE, devinfo->name, devinfo); |
| 946 | mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); |
| 946 | 947 | |
| 947 | 948 | // add the axes |
| 948 | 949 | input_device_item_add(devinfo->device, "X", &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state); |
| r3029 | r3030 | |
| 987 | 988 | osd_lock_free(input_lock); |
| 988 | 989 | |
| 989 | 990 | // free all devices |
| 990 | | device_list_free_devices(keyboard_list); |
| 991 | | device_list_free_devices(mouse_list); |
| 992 | | device_list_free_devices(joystick_list); |
| 991 | device_list_free_devices(&keyboard_list); |
| 992 | device_list_free_devices(&mouse_list); |
| 993 | device_list_free_devices(&joystick_list); |
| 993 | 994 | } |
| 994 | 995 | |
| 995 | 996 | |
| r3029 | r3030 | |
| 1031 | 1032 | SDL_Event event; |
| 1032 | 1033 | |
| 1033 | 1034 | osd_lock_acquire(input_lock); |
| 1035 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1036 | /* Make sure we get all pending events */ |
| 1037 | SDL_PumpEvents(); |
| 1038 | #endif |
| 1034 | 1039 | while(SDL_PollEvent(&event)) |
| 1035 | 1040 | { |
| 1036 | 1041 | if (event_buf_count < MAX_BUF_EVENTS) |
| r3029 | r3030 | |
| 1114 | 1119 | devinfo = generic_device_find_index(joystick_list, joy_logical[event.jhat.which]); |
| 1115 | 1120 | if (devinfo) |
| 1116 | 1121 | { |
| 1122 | // FIXME: change == to x & y != 0 |
| 1117 | 1123 | if (event.jhat.value == SDL_HAT_UP) |
| 1118 | 1124 | { |
| 1119 | 1125 | devinfo->joystick.hatsU[event.jhat.hat] = 0x80; |
| r3029 | r3030 | |
| 1195 | 1201 | break; |
| 1196 | 1202 | case SDL_MOUSEMOTION: |
| 1197 | 1203 | devinfo = mouse_list; |
| 1204 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1205 | // FIXME: may apply to 1.2 as well ... |
| 1206 | devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; |
| 1207 | devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1208 | #else |
| 1198 | 1209 | devinfo->mouse.lX = event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; |
| 1199 | | devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1210 | devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1211 | #endif |
| 1200 | 1212 | { |
| 1201 | 1213 | int cx=-1, cy=-1; |
| 1202 | 1214 | sdl_window_info *window = GET_WINDOW(&event.motion); |
| r3029 | r3030 | |
| 1216 | 1228 | case SDL_TEXTINPUT: |
| 1217 | 1229 | if (*event.text.text) |
| 1218 | 1230 | { |
| 1219 | | sdl_window_info *w = GET_WINDOW(&event.text); |
| 1231 | sdl_window_info *window = GET_WINDOW(&event.text); |
| 1220 | 1232 | unicode_char result; |
| 1221 | | osd_uchar_from_osdchar(&result, event.text.text, 1); |
| 1222 | | ui_input_push_char_event(machine, w->target, result); |
| 1233 | if (window != NULL ) |
| 1234 | { |
| 1235 | osd_uchar_from_osdchar(&result, event.text.text, 1); |
| 1236 | ui_input_push_char_event(machine, window->target, result); |
| 1237 | } |
| 1223 | 1238 | } |
| 1224 | 1239 | break; |
| 1225 | 1240 | case SDL_WINDOWEVENT: |
| r3029 | r3030 | |
| 1241 | 1256 | |
| 1242 | 1257 | } |
| 1243 | 1258 | case SDL_WINDOWEVENT_RESIZED: |
| 1244 | | sdlwindow_resize(window, event.window.data1, event.window.data2); |
| 1259 | if (event.window.data1 != window->width || event.window.data2 != window->height) |
| 1260 | sdlwindow_resize(window, event.window.data1, event.window.data2); |
| 1245 | 1261 | /* fall through break; */ |
| 1246 | 1262 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 1247 | 1263 | case SDL_WINDOWEVENT_ENTER: |
| r3029 | r3030 | |
| 1258 | 1274 | } |
| 1259 | 1275 | } |
| 1260 | 1276 | |
| 1277 | //============================================================ |
| 1278 | // sdlinput_release_keys |
| 1279 | //============================================================ |
| 1261 | 1280 | |
| 1281 | void sdlinput_release_keys(running_machine *machine) |
| 1282 | { |
| 1283 | // FIXME: SDL >= 1.3 will nuke the window event buffer when |
| 1284 | // a window is closed. This will leave keys in a pressed |
| 1285 | // state when a window is destroyed and recreated. |
| 1286 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1287 | device_info *devinfo; |
| 1288 | |
| 1289 | devinfo = keyboard_list; |
| 1290 | if (devinfo != NULL) |
| 1291 | memset(&devinfo->keyboard.state, 0, sizeof(devinfo->keyboard.state)); |
| 1292 | #endif |
| 1293 | } |
| 1294 | |
| 1262 | 1295 | //============================================================ |
| 1263 | 1296 | // sdlinput_should_hide_mouse |
| 1264 | 1297 | //============================================================ |
| r3029 | r3030 | |
| 1384 | 1417 | |
| 1385 | 1418 | // LCTRL-F8 to decrease prescaling effect # |
| 1386 | 1419 | case IPT_OSD_8: |
| 1387 | | if (sdl_use_unsupported()) { |
| 1420 | if (osd_use_unsupported()) { |
| 1388 | 1421 | typedesc->token = "DECREASE_EFFECT"; |
| 1389 | 1422 | typedesc->name = "Decrease Effect"; |
| 1390 | 1423 | input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F8, KEYCODE_LCONTROL); |
| r3029 | r3030 | |
| 1392 | 1425 | break; |
| 1393 | 1426 | // add a Not lcrtl condition to frameskip decrease |
| 1394 | 1427 | case IPT_UI_FRAMESKIP_DEC: |
| 1395 | | if (sdl_use_unsupported()) |
| 1428 | if (osd_use_unsupported()) |
| 1396 | 1429 | input_seq_set_3(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F8, SEQCODE_NOT, KEYCODE_LCONTROL); |
| 1397 | 1430 | break; |
| 1398 | 1431 | |
| 1399 | 1432 | // LCTRL-F9 to increase prescaling effect # |
| 1400 | 1433 | case IPT_OSD_9: |
| 1401 | | if (sdl_use_unsupported()) { |
| 1434 | if (osd_use_unsupported()) { |
| 1402 | 1435 | typedesc->token = "INCREASE_EFFECT"; |
| 1403 | 1436 | typedesc->name = "Increase Effect"; |
| 1404 | 1437 | input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F9, KEYCODE_LCONTROL); |
| r3029 | r3030 | |
| 1406 | 1439 | break; |
| 1407 | 1440 | // add a Not lcrtl condition to frameskip increase |
| 1408 | 1441 | case IPT_UI_FRAMESKIP_INC: |
| 1409 | | if (sdl_use_unsupported()) |
| 1442 | if (osd_use_unsupported()) |
| 1410 | 1443 | input_seq_set_3(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F9, SEQCODE_NOT, KEYCODE_LCONTROL); |
| 1411 | 1444 | break; |
| 1412 | 1445 | |
| r3029 | r3030 | |
| 1446 | 1479 | // device_list_free_devices |
| 1447 | 1480 | //============================================================ |
| 1448 | 1481 | |
| 1449 | | static void device_list_free_devices(device_info *devlist_head) |
| 1482 | static void device_list_free_devices(device_info **devlist_head) |
| 1450 | 1483 | { |
| 1451 | 1484 | device_info *curdev, *next; |
| 1452 | 1485 | |
| 1453 | | for (curdev = devlist_head; curdev != NULL; ) |
| 1486 | for (curdev = *devlist_head; curdev != NULL; ) |
| 1454 | 1487 | { |
| 1455 | 1488 | next = curdev->next; |
| 1456 | 1489 | generic_device_free(curdev); |
| 1457 | 1490 | curdev = next; |
| 1458 | 1491 | } |
| 1492 | *devlist_head = NULL; |
| 1459 | 1493 | } |
| 1460 | 1494 | |
| 1461 | 1495 | //============================================================ |
src/osd/sdl/drawsdl.c
| r3029 | r3030 | |
| 18 | 18 | #include "render.h" |
| 19 | 19 | #include "options.h" |
| 20 | 20 | #include "driver.h" |
| 21 | #include "ui.h" |
| 21 | 22 | |
| 22 | 23 | // standard SDL headers |
| 23 | 24 | #include <SDL/SDL.h> |
| r3029 | r3030 | |
| 38 | 39 | // MACROS |
| 39 | 40 | //============================================================ |
| 40 | 41 | |
| 42 | //#define IS_YUV_MODE(_m) ((_m) >= VIDEO_SCALE_MODE_YV12 && (_m) <= VIDEO_SCALE_MODE_YUY2X2) |
| 41 | 43 | |
| 42 | 44 | //============================================================ |
| 43 | 45 | // TYPES |
| 44 | 46 | //============================================================ |
| 45 | 47 | |
| 48 | typedef struct _sdl_scale_mode sdl_scale_mode; |
| 49 | |
| 46 | 50 | /* sdl_info is the information about SDL for the current screen */ |
| 47 | 51 | typedef struct _sdl_info sdl_info; |
| 48 | 52 | struct _sdl_info |
| r3029 | r3030 | |
| 69 | 73 | int hw_scale_height; |
| 70 | 74 | int last_hofs; |
| 71 | 75 | int last_vofs; |
| 76 | int old_blitwidth; |
| 77 | int old_blitheight; |
| 78 | |
| 79 | // shortcut to scale mode info |
| 80 | |
| 81 | const sdl_scale_mode *scale_mode; |
| 72 | 82 | }; |
| 73 | 83 | |
| 84 | struct _sdl_scale_mode |
| 85 | { |
| 86 | const char *name; |
| 87 | int is_scale; /* Scale mode? */ |
| 88 | int is_yuv; /* Yuv mode? */ |
| 89 | int mult_w; /* Width multiplier */ |
| 90 | int mult_h; /* Height multiplier */ |
| 91 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 92 | int extra_flags; /* Texture/surface flags */ |
| 93 | #else |
| 94 | int sdl_scale_mode; /* sdl 1.3 scale mode */ |
| 95 | #endif |
| 96 | int pixel_format; /* Pixel/Overlay format */ |
| 97 | void (*yuv_blit)(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 98 | }; |
| 99 | |
| 74 | 100 | //============================================================ |
| 75 | 101 | // INLINES |
| 76 | 102 | //============================================================ |
| r3029 | r3030 | |
| 113 | 139 | |
| 114 | 140 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 115 | 141 | static int shown_video_info = 0; |
| 116 | | static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 142 | |
| 143 | static const sdl_scale_mode scale_modes[] = |
| 144 | { |
| 145 | { "none", 0, 0, 0, 0, SDL_DOUBLEBUF, 0, 0 }, |
| 146 | { "async", 0, 0, 0, 0, SDL_DOUBLEBUF | SDL_ASYNCBLIT, 0, 0 }, |
| 147 | { "yv12", 1, 1, 1, 1, 0, SDL_YV12_OVERLAY, yuv_RGB_to_YV12 }, |
| 148 | { "yv12x2", 1, 1, 2, 2, 0, SDL_YV12_OVERLAY, yuv_RGB_to_YV12X2 }, |
| 149 | { "yuy2", 1, 1, 1, 1, 0, SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2 }, |
| 150 | { "yuy2x2", 1, 1, 2, 1, 0, SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2X2 }, |
| 151 | { NULL } |
| 152 | }; |
| 153 | #else |
| 154 | static const sdl_scale_mode scale_modes[] = |
| 155 | { |
| 156 | { "none", 0, 0, 0, 0, SDL_TEXTURESCALEMODE_NONE, 0, 0 }, |
| 157 | { "hwblit", 1, 0, 1, 1, SDL_TEXTURESCALEMODE_FAST, 0, 0 }, |
| 158 | { "hwbest", 1, 0, 1, 1, SDL_TEXTURESCALEMODE_BEST, 0, 0 }, |
| 159 | { "yv12", 1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 }, |
| 160 | { "yv12x2", 1, 1, 2, 2, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 }, |
| 161 | { "yuy2", 1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 }, |
| 162 | { "yuy2x2", 1, 1, 2, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 }, |
| 163 | { NULL } |
| 164 | }; |
| 117 | 165 | #endif |
| 118 | 166 | |
| 119 | 167 | //============================================================ |
| 168 | // drawsdl_scale_mode |
| 169 | //============================================================ |
| 170 | |
| 171 | const char *drawsdl_scale_mode_str(int index) |
| 172 | { |
| 173 | const sdl_scale_mode *sm = scale_modes; |
| 174 | |
| 175 | while (index>0) |
| 176 | { |
| 177 | if (sm->name == NULL) |
| 178 | return NULL; |
| 179 | index--; |
| 180 | sm++; |
| 181 | } |
| 182 | return sm->name; |
| 183 | }; |
| 184 | |
| 185 | int drawsdl_scale_mode(const char *s) |
| 186 | { |
| 187 | const sdl_scale_mode *sm = scale_modes; |
| 188 | int index; |
| 189 | |
| 190 | index = 0; |
| 191 | while (sm->name != NULL) |
| 192 | { |
| 193 | if (strcmp(sm->name, s) == 0) |
| 194 | return index; |
| 195 | index++; |
| 196 | sm++; |
| 197 | } |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | //============================================================ |
| 120 | 202 | // drawsdl_init |
| 121 | 203 | //============================================================ |
| 122 | 204 | |
| r3029 | r3030 | |
| 176 | 258 | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight) |
| 177 | 259 | { |
| 178 | 260 | sdl_info * sdl = window->dxdata; |
| 261 | const sdl_scale_mode *sdl_sm = sdl->scale_mode; |
| 179 | 262 | SDL_DisplayMode mode; |
| 263 | UINT32 fmt; |
| 180 | 264 | |
| 181 | 265 | // Determine preferred pixelformat and set up yuv if necessary |
| 182 | 266 | SDL_GetCurrentDisplayMode(&mode); |
| r3029 | r3030 | |
| 186 | 270 | free(sdl->yuv_bitmap); |
| 187 | 271 | sdl->yuv_bitmap = NULL; |
| 188 | 272 | } |
| 189 | | |
| 190 | | switch (window->scale_mode) |
| 273 | |
| 274 | if (sdl_sm->is_scale) |
| 275 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 276 | |
| 277 | if (sdl_sm->is_yuv) |
| 278 | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 279 | |
| 280 | fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format); |
| 281 | |
| 282 | if (sdl_sm->is_scale) |
| 283 | sdl->texture_id = SDL_CreateTexture(fmt, SDL_TEXTUREACCESS_STREAMING, |
| 284 | sdl->hw_scale_width * sdl_sm->mult_w, sdl->hw_scale_height * sdl_sm->mult_h); |
| 285 | else |
| 191 | 286 | { |
| 192 | | case VIDEO_SCALE_MODE_NONE: |
| 193 | | sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING, |
| 194 | | tempwidth, tempheight); |
| 195 | | SDL_SetTextureScaleMode(sdl->texture_id, SDL_TEXTURESCALEMODE_NONE); |
| 196 | | break; |
| 197 | | case VIDEO_SCALE_MODE_HWBLIT: |
| 198 | | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 199 | | sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING, |
| 200 | | sdl->hw_scale_width, sdl->hw_scale_height); |
| 201 | | break; |
| 202 | | case VIDEO_SCALE_MODE_YV12: |
| 203 | | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 204 | | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 205 | | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, |
| 206 | | sdl->hw_scale_width, sdl->hw_scale_height); |
| 207 | | break; |
| 208 | | case VIDEO_SCALE_MODE_YV12X2: |
| 209 | | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 210 | | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 211 | | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, |
| 212 | | sdl->hw_scale_width * 2, sdl->hw_scale_height * 2); |
| 213 | | break; |
| 214 | | case VIDEO_SCALE_MODE_YUY2: |
| 215 | | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 216 | | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 217 | | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 218 | | sdl->hw_scale_width, sdl->hw_scale_height); |
| 219 | | break; |
| 220 | | case VIDEO_SCALE_MODE_YUY2X2: |
| 221 | | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 222 | | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 223 | | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 224 | | sdl->hw_scale_width * 2, sdl->hw_scale_height); |
| 225 | | break; |
| 287 | sdl->texture_id = SDL_CreateTexture(fmt, SDL_TEXTUREACCESS_STREAMING, |
| 288 | tempwidth, tempheight); |
| 226 | 289 | } |
| 290 | |
| 291 | SDL_SetTextureScaleMode(sdl->texture_id, sdl_sm->sdl_scale_mode); |
| 292 | |
| 227 | 293 | } |
| 228 | 294 | #endif |
| 229 | 295 | |
| r3029 | r3030 | |
| 235 | 301 | static void yuv_overlay_init(sdl_window_info *window) |
| 236 | 302 | { |
| 237 | 303 | sdl_info *sdl = window->dxdata; |
| 304 | const sdl_scale_mode *sdl_sm = sdl->scale_mode; |
| 238 | 305 | int minimum_width, minimum_height; |
| 239 | 306 | |
| 240 | 307 | render_target_get_minimum_size(window->target, &minimum_width, &minimum_height); |
| r3029 | r3030 | |
| 248 | 315 | { |
| 249 | 316 | free(sdl->yuv_bitmap); |
| 250 | 317 | } |
| 318 | |
| 319 | mame_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); |
| 320 | |
| 251 | 321 | sdl->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16)); |
| 252 | 322 | |
| 253 | | mame_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); |
| 254 | | switch (window->scale_mode) |
| 255 | | { |
| 256 | | case VIDEO_SCALE_MODE_YV12: |
| 257 | | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 258 | | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 259 | | break; |
| 260 | | case VIDEO_SCALE_MODE_YV12X2: |
| 261 | | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2, |
| 262 | | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 263 | | break; |
| 264 | | case VIDEO_SCALE_MODE_YUY2: |
| 265 | | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 266 | | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 267 | | break; |
| 268 | | case VIDEO_SCALE_MODE_YUY2X2: |
| 269 | | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height, |
| 270 | | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 271 | | break; |
| 272 | | } |
| 323 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 324 | sdl_sm->pixel_format, sdl->sdlsurf); |
| 325 | |
| 273 | 326 | if ( sdl->yuvsurf == NULL ) { |
| 274 | 327 | mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| 275 | 328 | //return 1; |
| 276 | 329 | } |
| 330 | |
| 277 | 331 | sdl->hw_scale_width = minimum_width; |
| 278 | 332 | sdl->hw_scale_height = minimum_height; |
| 279 | 333 | |
| 280 | 334 | if (!shown_video_info) |
| 281 | 335 | { |
| 282 | | mame_printf_verbose("YUV Mode : %s\n", scale_mode_names[window->scale_mode]); |
| 336 | mame_printf_verbose("YUV Mode : %s\n", sdl_sm->name); |
| 283 | 337 | mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); |
| 284 | 338 | mame_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 285 | 339 | shown_video_info = 1; |
| r3029 | r3030 | |
| 288 | 342 | #endif |
| 289 | 343 | |
| 290 | 344 | //============================================================ |
| 345 | // drawsdl_show_info |
| 346 | //============================================================ |
| 347 | |
| 348 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 349 | static void drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo *render_info) |
| 350 | { |
| 351 | #define RF_ENTRY(x) {x, #x } |
| 352 | static struct { |
| 353 | int flag; |
| 354 | const char *name; |
| 355 | } rflist[] = |
| 356 | { |
| 357 | RF_ENTRY(SDL_RENDERER_SINGLEBUFFER), |
| 358 | RF_ENTRY(SDL_RENDERER_PRESENTCOPY), |
| 359 | RF_ENTRY(SDL_RENDERER_PRESENTFLIP2), |
| 360 | RF_ENTRY(SDL_RENDERER_PRESENTFLIP3), |
| 361 | RF_ENTRY(SDL_RENDERER_PRESENTDISCARD), |
| 362 | RF_ENTRY(SDL_RENDERER_PRESENTVSYNC), |
| 363 | RF_ENTRY(SDL_RENDERER_ACCELERATED), |
| 364 | {-1, NULL} |
| 365 | }; |
| 366 | int i; |
| 367 | |
| 368 | mame_printf_verbose("window: using renderer %s\n", render_info->name ? render_info->name : "<unknown>"); |
| 369 | for (i = 0; rflist[i].name != NULL; i++) |
| 370 | if (render_info->flags & rflist[i].flag) |
| 371 | mame_printf_verbose("renderer: flag %s\n", rflist[i].name); |
| 372 | } |
| 373 | #endif |
| 374 | |
| 375 | //============================================================ |
| 291 | 376 | // drawsdl_window_create |
| 292 | 377 | //============================================================ |
| 293 | 378 | |
| r3029 | r3030 | |
| 301 | 386 | |
| 302 | 387 | window->dxdata = sdl; |
| 303 | 388 | |
| 389 | sdl->scale_mode = &scale_modes[window->scale_mode]; |
| 390 | |
| 304 | 391 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 305 | 392 | sdl->extra_flags = (window->fullscreen ? |
| 306 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE); |
| 393 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS |
| 394 | | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE); |
| 307 | 395 | |
| 308 | 396 | SDL_SelectVideoDisplay(window->monitor->handle); |
| 309 | 397 | |
| r3029 | r3030 | |
| 321 | 409 | window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 322 | 410 | width, height, sdl->extra_flags); |
| 323 | 411 | SDL_ShowWindow(window->window_id); |
| 324 | | SDL_RaiseWindow(window->window_id); |
| 325 | 412 | |
| 326 | 413 | // create a texture |
| 327 | 414 | SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD); |
| 328 | 415 | SDL_SelectRenderer(window->window_id); |
| 416 | |
| 417 | { |
| 418 | struct SDL_RendererInfo render_info; |
| 419 | SDL_GetRendererInfo(&render_info); |
| 420 | |
| 421 | drawsdl_show_info(window, &render_info); |
| 422 | |
| 423 | // Check scale mode |
| 424 | |
| 425 | if (sdl->scale_mode->pixel_format) |
| 426 | { |
| 427 | int i; |
| 428 | int found = 0; |
| 429 | |
| 430 | for (i=0; i < render_info.num_texture_formats; i++) |
| 431 | if (sdl->scale_mode->pixel_format == render_info.texture_formats[i]) |
| 432 | found = 1; |
| 433 | |
| 434 | if (!found) |
| 435 | { |
| 436 | mame_printf_verbose("window: Scale mode %s not supported! Using default.\n", sdl->scale_mode->name); |
| 437 | ui_popup_time(3, "Scale mode %s not supported! Using default.", sdl->scale_mode->name); |
| 438 | sdl->scale_mode = &scale_modes[0]; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 329 | 443 | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 330 | | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 444 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 445 | SDL_RaiseWindow(window->window_id); |
| 331 | 446 | setup_texture(window, width, height); |
| 332 | 447 | #else |
| 333 | 448 | sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 334 | | // create the SDL surface (which creates the window in windowed mode) |
| 335 | | if (!IS_YUV_MODE(window->scale_mode)) |
| 336 | | sdl->extra_flags |= SDL_DOUBLEBUF; |
| 337 | 449 | |
| 450 | sdl->extra_flags |= sdl->scale_mode->extra_flags; |
| 451 | |
| 338 | 452 | sdl->sdlsurf = SDL_SetVideoMode(width, height, |
| 339 | 453 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 340 | 454 | |
| r3029 | r3030 | |
| 344 | 458 | window->width = sdl->sdlsurf->w; |
| 345 | 459 | window->height = sdl->sdlsurf->h; |
| 346 | 460 | |
| 347 | | if (IS_YUV_MODE(window->scale_mode)) |
| 348 | | { |
| 461 | if (sdl->scale_mode->is_yuv) |
| 349 | 462 | yuv_overlay_init(window); |
| 350 | | } |
| 351 | 463 | |
| 352 | 464 | // set the window title |
| 353 | 465 | SDL_WM_SetCaption(window->title, "SDLMAME"); |
| r3029 | r3030 | |
| 365 | 477 | |
| 366 | 478 | static void drawsdl_window_resize(sdl_window_info *window, int width, int height) |
| 367 | 479 | { |
| 368 | | sdl_info *sdl = window->dxdata; |
| 369 | 480 | |
| 370 | 481 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 371 | 482 | SDL_SetWindowSize(window->window_id, width, height); |
| 372 | 483 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 373 | 484 | |
| 374 | | // create a texture |
| 375 | | SDL_SelectRenderer(window->window_id); |
| 376 | | SDL_DestroyTexture(sdl->texture_id); |
| 485 | #else |
| 486 | sdl_info *sdl = window->dxdata; |
| 377 | 487 | |
| 378 | | setup_texture(window, window->width, window->height); |
| 379 | | #else |
| 380 | 488 | if (sdl->yuvsurf != NULL) |
| 381 | 489 | { |
| 382 | 490 | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| r3029 | r3030 | |
| 390 | 498 | window->width = sdl->sdlsurf->w; |
| 391 | 499 | window->height = sdl->sdlsurf->h; |
| 392 | 500 | |
| 393 | | if (IS_YUV_MODE(window->scale_mode)) |
| 501 | if (sdl->scale_mode->is_yuv) |
| 394 | 502 | { |
| 395 | 503 | yuv_overlay_init(window); |
| 396 | 504 | } |
| r3029 | r3030 | |
| 470 | 578 | return 0; |
| 471 | 579 | if (*yt<0 || *xt >= window->blitheight) |
| 472 | 580 | return 0; |
| 473 | | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode))) |
| 581 | if (!sdl->scale_mode->is_scale) |
| 474 | 582 | { |
| 475 | 583 | return 1; |
| 476 | 584 | } |
| r3029 | r3030 | |
| 487 | 595 | static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window) |
| 488 | 596 | { |
| 489 | 597 | sdl_info *sdl = window->dxdata; |
| 598 | |
| 490 | 599 | if ((!window->fullscreen) || (video_config.switchres)) |
| 491 | 600 | { |
| 492 | 601 | sdlwindow_blit_surface_size(window, window->width, window->height); |
| r3029 | r3030 | |
| 495 | 604 | { |
| 496 | 605 | sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height); |
| 497 | 606 | } |
| 498 | | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode))) |
| 607 | if (!sdl->scale_mode->is_scale) |
| 499 | 608 | render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 500 | 609 | else |
| 501 | 610 | render_target_set_bounds(window->target, sdl->hw_scale_width, sdl->hw_scale_height, 0); |
| r3029 | r3030 | |
| 534 | 643 | bmask = sdl->sdlsurf->format->Bmask; |
| 535 | 644 | amask = sdl->sdlsurf->format->Amask; |
| 536 | 645 | |
| 646 | if (window->blitwidth != sdl->old_blitwidth || window->blitheight != sdl->old_blitheight) |
| 647 | { |
| 648 | if (sdl->scale_mode->is_yuv) |
| 649 | yuv_overlay_init(window); |
| 650 | sdl->old_blitwidth = window->blitwidth; |
| 651 | sdl->old_blitheight = window->blitheight; |
| 652 | sdl->blittimer = 3; |
| 653 | } |
| 654 | |
| 537 | 655 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf); |
| 538 | 656 | // Clear if necessary |
| 539 | 657 | |
| r3029 | r3030 | |
| 544 | 662 | } |
| 545 | 663 | |
| 546 | 664 | |
| 547 | | if (IS_YUV_MODE(window->scale_mode)) |
| 665 | if (sdl->scale_mode->is_yuv) |
| 548 | 666 | { |
| 549 | 667 | SDL_LockYUVOverlay(sdl->yuvsurf); |
| 550 | 668 | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap; |
| r3029 | r3030 | |
| 554 | 672 | surfptr = (UINT8 *)sdl->sdlsurf->pixels; |
| 555 | 673 | #else |
| 556 | 674 | SDL_SelectRenderer(window->window_id); |
| 675 | |
| 676 | if (window->blitwidth != sdl->old_blitwidth || window->blitheight != sdl->old_blitheight) |
| 557 | 677 | { |
| 678 | SDL_DestroyTexture(sdl->texture_id); |
| 679 | setup_texture(window, window->blitwidth, window->blitheight); |
| 680 | sdl->old_blitwidth = window->blitwidth; |
| 681 | sdl->old_blitheight = window->blitheight; |
| 682 | sdl->blittimer = 3; |
| 683 | } |
| 684 | |
| 685 | { |
| 558 | 686 | Uint32 format; |
| 559 | 687 | int access, w, h; |
| 560 | 688 | |
| r3029 | r3030 | |
| 563 | 691 | bpp = bpp / 8; /* convert to bytes per pixels */ |
| 564 | 692 | } |
| 565 | 693 | |
| 694 | // Clear if necessary |
| 695 | if (sdl->blittimer > 0) |
| 696 | { |
| 697 | /* SDL Underlays need alpha = 0 ! */ |
| 698 | SDL_RenderFill(0,0,0,0 /*255*/,NULL); |
| 699 | sdl->blittimer--; |
| 700 | } |
| 701 | |
| 566 | 702 | SDL_LockTexture(sdl->texture_id, NULL, 1, (void **) &surfptr, &pitch); |
| 567 | | // Clear if necessary |
| 568 | | if (window->scale_mode == VIDEO_SCALE_MODE_NONE) |
| 569 | | if (sdl->blittimer > 0) |
| 570 | | { |
| 571 | | memset(surfptr, 0, window->height * pitch); |
| 572 | | sdl->blittimer--; |
| 573 | | } |
| 574 | 703 | |
| 575 | 704 | #endif |
| 576 | 705 | // get ready to center the image |
| r3029 | r3030 | |
| 617 | 746 | osd_lock_acquire(window->primlist->lock); |
| 618 | 747 | |
| 619 | 748 | // render to it |
| 620 | | if (!IS_YUV_MODE(window->scale_mode)) |
| 749 | if (!sdl->scale_mode->is_yuv) |
| 621 | 750 | { |
| 622 | 751 | int mamewidth, mameheight; |
| 623 | 752 | |
| 624 | | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || !SDL_VERSION_ATLEAST(1,3,0)) |
| 753 | if (!sdl->scale_mode->is_scale) |
| 625 | 754 | { |
| 626 | 755 | mamewidth = blitwidth; |
| 627 | 756 | mameheight = blitheight; |
| 757 | #if !SDL_VERSION_ATLEAST(1,3,0) |
| 628 | 758 | surfptr += ((vofs * pitch) + (hofs * bpp)); |
| 759 | #endif |
| 629 | 760 | } |
| 630 | 761 | else |
| 631 | 762 | { |
| r3029 | r3030 | |
| 660 | 791 | assert (sdl->yuv_bitmap != NULL); |
| 661 | 792 | assert (surfptr != NULL); |
| 662 | 793 | drawsdl_rgb555_draw_primitives(window->primlist->head, sdl->yuv_bitmap, sdl->hw_scale_width, sdl->hw_scale_height, sdl->hw_scale_width); |
| 663 | | switch (window->scale_mode) |
| 664 | | { |
| 665 | | case VIDEO_SCALE_MODE_YV12: |
| 666 | | yuv_RGB_to_YV12((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 667 | | break; |
| 668 | | case VIDEO_SCALE_MODE_YV12X2: |
| 669 | | yuv_RGB_to_YV12X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 670 | | break; |
| 671 | | case VIDEO_SCALE_MODE_YUY2: |
| 672 | | yuv_RGB_to_YUY2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 673 | | break; |
| 674 | | case VIDEO_SCALE_MODE_YUY2X2: |
| 675 | | yuv_RGB_to_YUY2X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 676 | | break; |
| 677 | | } |
| 794 | sdl->scale_mode->yuv_blit((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 678 | 795 | } |
| 679 | 796 | |
| 680 | 797 | osd_lock_release(window->primlist->lock); |
| r3029 | r3030 | |
| 682 | 799 | // unlock and flip |
| 683 | 800 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 684 | 801 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf); |
| 685 | | if (!IS_YUV_MODE(window->scale_mode)) |
| 802 | if (!sdl->scale_mode->is_yuv) |
| 686 | 803 | { |
| 687 | 804 | SDL_Flip(sdl->sdlsurf); |
| 688 | 805 | } |
| r3029 | r3030 | |
| 699 | 816 | } |
| 700 | 817 | #else |
| 701 | 818 | SDL_UnlockTexture(sdl->texture_id); |
| 702 | | if (window->scale_mode == VIDEO_SCALE_MODE_NONE) |
| 703 | 819 | { |
| 704 | | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 705 | | SDL_RenderCopy(sdl->texture_id, NULL, NULL); |
| 706 | | SDL_RenderPresent(); |
| 707 | | } |
| 708 | | else |
| 709 | | { |
| 710 | 820 | SDL_Rect r; |
| 821 | |
| 711 | 822 | r.x=hofs; |
| 712 | 823 | r.y=vofs; |
| 713 | 824 | r.w=blitwidth; |
| 714 | 825 | r.h=blitheight; |
| 826 | //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height); |
| 715 | 827 | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 716 | 828 | SDL_RenderCopy(sdl->texture_id, NULL, &r); |
| 717 | 829 | SDL_RenderPresent(); |
src/osd/sdl/debugwin.c
| r3029 | r3030 | |
| 9 | 9 | // |
| 10 | 10 | //============================================================ |
| 11 | 11 | |
| 12 | | #if !defined(SDLMAME_WIN32) && !defined(SDLMAME_NO_X11) |
| 12 | #if !defined(SDLMAME_WIN32) && !defined(SDLMAME_NO_X11) && !defined(SDLMAME_SOLARIS) |
| 13 | 13 | |
| 14 | 14 | #include <gdk/gdkkeysyms.h> |
| 15 | 15 | #include <gtk/gtk.h> |
| r3029 | r3030 | |
| 119 | 119 | { |
| 120 | 120 | memorycombo_item **tail = &memorycombo; |
| 121 | 121 | UINT32 cpunum, spacenum; |
| 122 | const char *rgntag; |
| 122 | 123 | int itemnum; |
| 123 | | const char *rgnname; |
| 124 | 124 | |
| 125 | 125 | // first add all the CPUs' address spaces |
| 126 | 126 | for (cpunum = 0; cpunum < MAX_CPU; cpunum++) |
| r3029 | r3030 | |
| 134 | 134 | memset(ci, 0, sizeof(*ci)); |
| 135 | 135 | ci->cpunum = cpunum; |
| 136 | 136 | ci->spacenum = spacenum; |
| 137 | | ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 4); |
| 138 | | sprintf(ci->name, "CPU #%d (%s) %s memory", cpunum, cpunum_name(cpunum), address_space_names[spacenum]); |
| 137 | ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8); |
| 138 | |
| 139 | snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum), address_space_names[spacenum]); |
| 140 | |
| 139 | 141 | *tail = ci; |
| 140 | 142 | tail = &ci->next; |
| 141 | 143 | } |
| 142 | 144 | } |
| 143 | 145 | |
| 144 | 146 | // then add all the memory regions |
| 145 | | rgnname = memory_region_next(machine, NULL); |
| 146 | | while (rgnname != NULL) |
| 147 | for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag)) |
| 147 | 148 | { |
| 148 | | UINT8 *base = memory_region(machine, rgnname); |
| 149 | 149 | memorycombo_item *ci = malloc_or_die(sizeof(*ci)); |
| 150 | | UINT32 flags = memory_region_flags(machine, rgnname); |
| 151 | | UINT8 width = 0, little_endian; |
| 150 | UINT32 flags = memory_region_flags(machine, rgntag); |
| 151 | UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 152 | UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8); |
| 152 | 153 | |
| 153 | 154 | memset(ci, 0, sizeof(*ci)); |
| 154 | | ci->base = base; |
| 155 | | ci->length = memory_region_length(machine, rgnname); |
| 156 | | little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 157 | | switch (flags & ROMREGION_WIDTHMASK) |
| 158 | | { |
| 159 | | case ROMREGION_8BIT: |
| 160 | | width = 8; |
| 161 | | break; |
| 162 | | case ROMREGION_16BIT: |
| 163 | | width = 16; |
| 164 | | break; |
| 165 | | case ROMREGION_32BIT: |
| 166 | | width = 32; |
| 167 | | break; |
| 168 | | case ROMREGION_64BIT: |
| 169 | | width = 64; |
| 170 | | break; |
| 171 | | } |
| 172 | | ci->prefsize = MIN(width, 4); |
| 155 | ci->base = memory_region(machine, rgntag); |
| 156 | ci->length = memory_region_length(machine, rgntag); |
| 157 | ci->prefsize = MIN(width, 8); |
| 173 | 158 | ci->offset_xor = width - 1; |
| 174 | 159 | ci->little_endian = little_endian; |
| 175 | | strcpy(ci->name, rgnname); |
| 160 | |
| 161 | snprintf(ci->name, ARRAY_LENGTH(ci->name), "Region \"%s\"", rgntag); |
| 162 | |
| 176 | 163 | *tail = ci; |
| 177 | 164 | tail = &ci->next; |
| 178 | | |
| 179 | | // and get the next region |
| 180 | | rgnname = memory_region_next(machine, rgnname); |
| 181 | 165 | } |
| 182 | 166 | |
| 183 | 167 | // finally add all global array symbols |
| r3029 | r3030 | |
| 199 | 183 | memset(ci, 0, sizeof(*ci)); |
| 200 | 184 | ci->base = base; |
| 201 | 185 | ci->length = valcount * valsize; |
| 202 | | ci->prefsize = MIN(valsize, 4); |
| 186 | ci->prefsize = MIN(valsize, 8); |
| 203 | 187 | ci->little_endian = TRUE; |
| 204 | 188 | strcpy(ci->name, strrchr(name, '/') + 1); |
| 205 | 189 | *tail = ci; |
| r3029 | r3030 | |
| 386 | 370 | debug_view_set_property_UINT32(dmain->registers, DVP_REGS_CPUNUM, cpunum); |
| 387 | 371 | |
| 388 | 372 | // then update the caption |
| 389 | | sprintf(title, "Debug: %s - CPU %d (%s)", machine->gamedrv->name, cpunum, cpunum_name(cpunum)); |
| 373 | sprintf(title, "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum)); |
| 390 | 374 | gtk_window_set_title(GTK_WINDOW(dmain->win), title); |
| 391 | 375 | debugmain_update_checks(dmain); |
| 392 | 376 | } |
| r3029 | r3030 | |
| 411 | 395 | gtk_main_iteration(); |
| 412 | 396 | } |
| 413 | 397 | |
| 414 | | void debugwin_update_during_game(void) |
| 398 | void debugwin_update_during_game(running_machine *machine) |
| 415 | 399 | { |
| 416 | 400 | if(dmain) |
| 417 | 401 | gtk_main_iteration_do(FALSE); |
| r3029 | r3030 | |
| 594 | 578 | |
| 595 | 579 | disasmwin_update_checks(info); |
| 596 | 580 | |
| 597 | | sprintf(title, "Disassembly: %s (%d)", cpunum_name(cpunum), cpunum); |
| 581 | sprintf(title, "Disassembly: CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum)); |
| 598 | 582 | gtk_window_set_title(GTK_WINDOW(info->win), title); |
| 599 | 583 | } |
| 600 | 584 | |
| r3029 | r3030 | |
| 704 | 688 | if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes) |
| 705 | 689 | { |
| 706 | 690 | char name[100]; |
| 707 | | sprintf(name, "CPU #%d (%s)", cpunum, cpunum_name(cpunum)); |
| 691 | sprintf(name, "CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum)); |
| 708 | 692 | gtk_combo_box_append_text(dis->cpu_w, name); |
| 709 | 693 | if(cpunum == curcpu) |
| 710 | 694 | citem = item; |
| r3029 | r3030 | |
| 900 | 884 | { |
| 901 | 885 | } |
| 902 | 886 | |
| 903 | | void debugwin_update_during_game(void) |
| 887 | void debugwin_update_during_game(running_machine *machine) |
| 904 | 888 | { |
| 905 | 889 | } |
| 906 | 890 | |
src/osd/sdl/window.c
| r3029 | r3030 | |
| 99 | 99 | static int main_threadid; |
| 100 | 100 | static int window_threadid; |
| 101 | 101 | |
| 102 | | static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 103 | | |
| 104 | | |
| 105 | 102 | // debugger |
| 106 | 103 | //static int in_background; |
| 107 | 104 | |
| r3029 | r3030 | |
| 122 | 119 | //============================================================ |
| 123 | 120 | |
| 124 | 121 | static void sdlwindow_exit(running_machine *machine); |
| 125 | | static void sdlwindow_video_window_destroy(sdl_window_info *window); |
| 122 | static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window); |
| 126 | 123 | static OSDWORK_CALLBACK( draw_video_contents_wt ); |
| 127 | 124 | static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ); |
| 128 | 125 | static OSDWORK_CALLBACK( sdlwindow_resize_wt ); |
| r3029 | r3030 | |
| 262 | 259 | |
| 263 | 260 | |
| 264 | 261 | //============================================================ |
| 265 | | // sdlwindow_exit |
| 266 | | // (main thread) |
| 262 | // sdlwindow_sync |
| 267 | 263 | //============================================================ |
| 268 | 264 | |
| 269 | 265 | static void sdlwindow_sync(void) |
| 270 | 266 | { |
| 271 | 267 | if (multithreading_enabled) |
| 272 | 268 | { |
| 273 | | osd_work_queue_wait(work_queue, osd_ticks_per_second()*10); |
| 269 | // Fallback |
| 270 | while (!osd_work_queue_wait(work_queue, osd_ticks_per_second()*10)) |
| 271 | { |
| 272 | mame_printf_warning("sdlwindow_sync: Sleeping...\n"); |
| 273 | osd_sleep(100000); |
| 274 | } |
| 274 | 275 | } |
| 275 | 276 | } |
| 276 | 277 | |
| r3029 | r3030 | |
| 299 | 300 | { |
| 300 | 301 | sdl_window_info *temp = sdl_window_list; |
| 301 | 302 | sdl_window_list = temp->next; |
| 302 | | sdlwindow_video_window_destroy(temp); |
| 303 | sdlwindow_video_window_destroy(machine, temp); |
| 303 | 304 | } |
| 304 | 305 | |
| 305 | 306 | // if we're multithreaded, clean up the window thread |
| r3029 | r3030 | |
| 400 | 401 | newheight = target_height; |
| 401 | 402 | } |
| 402 | 403 | |
| 404 | //FIXME: really necessary to distinguish for yuv_modes ? |
| 403 | 405 | if ((render_target_get_layer_config(window->target) & LAYER_CONFIG_ZOOM_TO_SCREEN) |
| 404 | | && (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode)))) |
| 406 | && (window->scale_mode == VIDEO_SCALE_MODE_NONE )) |
| 405 | 407 | newwidth = window_width; |
| 406 | 408 | |
| 407 | 409 | if ((window->blitwidth != newwidth) || (window->blitheight != newheight)) |
| r3029 | r3030 | |
| 511 | 513 | } |
| 512 | 514 | |
| 513 | 515 | window->destroy(window); |
| 516 | sdlinput_release_keys(wp->machine); |
| 514 | 517 | |
| 515 | 518 | // toggle the window mode |
| 516 | 519 | window->fullscreen = !window->fullscreen; |
| r3029 | r3030 | |
| 528 | 531 | |
| 529 | 532 | clear_worker_param(&wp); |
| 530 | 533 | wp.window = window; |
| 534 | wp.machine = machine; |
| 531 | 535 | |
| 532 | | //FIMXE: Reset Key state .... |
| 533 | 536 | execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp); |
| 534 | 537 | } |
| 535 | 538 | |
| 536 | 539 | static void sdlwindow_modify_yuv(running_machine *machine, sdl_window_info *window, int dir) |
| 537 | 540 | { |
| 538 | 541 | int new_scale_mode = window->scale_mode; |
| 539 | | |
| 540 | | if (dir > 0 && window->scale_mode < VIDEO_SCALE_MODE_MAX) |
| 542 | worker_param wp; |
| 543 | const char *stemp; |
| 544 | |
| 545 | if (dir > 0) |
| 541 | 546 | new_scale_mode = window->scale_mode + 1; |
| 542 | | if (dir < 0 && window->scale_mode > VIDEO_SCALE_MODE_MIN) |
| 547 | if (dir < 0) |
| 543 | 548 | new_scale_mode = window->scale_mode - 1; |
| 544 | 549 | |
| 545 | | // FIXME: Changing to yv12 mode from video_mode none does not work |
| 546 | | if (new_scale_mode != window->scale_mode) |
| 547 | | { |
| 548 | | worker_param wp; |
| 550 | stemp = drawsdl_scale_mode_str(new_scale_mode); |
| 551 | |
| 552 | if (stemp==NULL) |
| 553 | return; |
| 554 | |
| 555 | clear_worker_param(&wp); |
| 556 | wp.window = window; |
| 557 | wp.machine = machine; |
| 558 | sdlwindow_sync(); |
| 559 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 560 | |
| 561 | window->scale_mode = new_scale_mode; |
| 562 | |
| 563 | ui_popup_time(1, "Scale mode %s", stemp); |
| 564 | mame_printf_verbose("Scale mode %s\n", stemp); |
| 549 | 565 | |
| 550 | | clear_worker_param(&wp); |
| 551 | | wp.window = window; |
| 552 | | sdlwindow_sync(); |
| 553 | | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 554 | | |
| 555 | | window->scale_mode = new_scale_mode; |
| 556 | | execute_async_wait(&complete_create_wt, &wp); |
| 557 | | sdlwindow_sync(); |
| 566 | sdlwindow_sync(); |
| 567 | execute_async_wait(&complete_create_wt, &wp); |
| 568 | sdlwindow_sync(); |
| 558 | 569 | |
| 559 | | ui_popup_time(1, "YUV mode %s", scale_mode_names[window->scale_mode]); |
| 560 | | mame_printf_verbose("YUV mode %s\n", scale_mode_names[window->scale_mode]); |
| 561 | | } |
| 562 | 570 | } |
| 563 | 571 | |
| 564 | 572 | static OSDWORK_CALLBACK( destroy_all_textures_wt ) |
| r3029 | r3030 | |
| 581 | 589 | clear_worker_param(&wp); |
| 582 | 590 | |
| 583 | 591 | wp.window = window; |
| 592 | wp.machine = machine; |
| 584 | 593 | |
| 585 | 594 | if (dir > 0 && window->prescale < 3) |
| 586 | 595 | new_prescale = window->prescale + 1; |
| r3029 | r3030 | |
| 642 | 651 | void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window) |
| 643 | 652 | { |
| 644 | 653 | #if USE_OPENGL |
| 654 | //FIXME: Not yet working in 1.3 |
| 655 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 645 | 656 | worker_param wp; |
| 646 | 657 | |
| 647 | 658 | // If we are not fullscreen (windowed) remember our windowed size |
| r3029 | r3030 | |
| 654 | 665 | clear_worker_param(&wp); |
| 655 | 666 | |
| 656 | 667 | wp.window = window; |
| 668 | wp.machine = machine; |
| 657 | 669 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 658 | 670 | |
| 659 | 671 | window->scale_mode = VIDEO_SCALE_MODE_NONE; |
| r3029 | r3030 | |
| 673 | 685 | |
| 674 | 686 | execute_async_wait(&complete_create_wt, &wp); |
| 675 | 687 | #endif |
| 688 | #endif |
| 676 | 689 | } |
| 677 | 690 | |
| 678 | 691 | |
| r3029 | r3030 | |
| 684 | 697 | static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window) |
| 685 | 698 | { |
| 686 | 699 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 687 | | // FIXME: belongs into callback |
| 688 | 700 | // do not do mouse capture if the debugger's enabled to avoid |
| 689 | 701 | // the possibility of losing control |
| 690 | 702 | if (!options_get_bool(mame_options(), OPTION_DEBUG)) |
| 691 | 703 | { |
| 704 | //FIXME: SDL1.3: really broken: the whole SDL code |
| 705 | // will only work correct with relative mouse movements ... |
| 692 | 706 | if (!window->fullscreen && !sdlinput_should_hide_mouse(machine)) |
| 693 | 707 | { |
| 694 | 708 | SDL_ShowCursor(SDL_ENABLE); |
| r3029 | r3030 | |
| 701 | 715 | if (!SDL_GetWindowGrab(window->window_id)) |
| 702 | 716 | SDL_SetWindowGrab(window->window_id, 1); |
| 703 | 717 | } |
| 718 | SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility |
| 704 | 719 | } |
| 720 | |
| 705 | 721 | #else |
| 706 | 722 | // do not do mouse capture if the debugger's enabled to avoid |
| 707 | 723 | // the possibility of losing control |
| r3029 | r3030 | |
| 727 | 743 | #endif |
| 728 | 744 | } |
| 729 | 745 | |
| 746 | |
| 730 | 747 | //============================================================ |
| 731 | 748 | // sdlwindow_video_window_create |
| 732 | 749 | // (main thread) |
| r3029 | r3030 | |
| 752 | 769 | window->refresh = config->refresh; |
| 753 | 770 | window->monitor = monitor; |
| 754 | 771 | |
| 755 | | //FIXME: these should be per_window in config-> |
| 772 | //FIXME: these should be per_window in config-> or even better a bit set |
| 756 | 773 | window->fullscreen = !video_config.windowed; |
| 757 | 774 | window->prescale = video_config.prescale; |
| 758 | 775 | window->prescale_effect = video_config.prescale_effect; |
| r3029 | r3030 | |
| 775 | 792 | |
| 776 | 793 | draw.attach(&draw, window); |
| 777 | 794 | |
| 778 | | // create a lock that we can use to skip blitting |
| 779 | | window->render_lock = osd_lock_alloc(); |
| 795 | // create an event that we can use to skip blitting |
| 796 | window->rendered_event = osd_event_alloc(FALSE, TRUE); |
| 780 | 797 | |
| 781 | 798 | // load the layout |
| 782 | 799 | window->target = render_target_alloc(NULL, FALSE); |
| r3029 | r3030 | |
| 794 | 811 | sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine->gamedrv->description, machine->gamedrv->name, index); |
| 795 | 812 | |
| 796 | 813 | wp->window = window; |
| 814 | |
| 797 | 815 | if (multithreading_enabled) |
| 798 | 816 | { |
| 799 | 817 | osd_work_item *wi; |
| r3029 | r3030 | |
| 813 | 831 | return 0; |
| 814 | 832 | |
| 815 | 833 | error: |
| 816 | | sdlwindow_video_window_destroy(window); |
| 834 | sdlwindow_video_window_destroy(machine, window); |
| 817 | 835 | return 1; |
| 818 | 836 | } |
| 819 | 837 | |
| 838 | |
| 820 | 839 | //============================================================ |
| 821 | 840 | // sdlwindow_video_window_destroy |
| 822 | 841 | // (main thread) |
| r3029 | r3030 | |
| 832 | 851 | // free the textures etc |
| 833 | 852 | window->destroy(window); |
| 834 | 853 | |
| 854 | // release all keys ... |
| 855 | sdlinput_release_keys(wp->machine); |
| 856 | |
| 857 | |
| 835 | 858 | free(wp); |
| 836 | 859 | return NULL; |
| 837 | 860 | } |
| 838 | 861 | |
| 839 | | static void sdlwindow_video_window_destroy(sdl_window_info *window) |
| 862 | static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window) |
| 840 | 863 | { |
| 841 | 864 | sdl_window_info **prevptr; |
| 842 | 865 | worker_param wp; |
| r3029 | r3030 | |
| 847 | 870 | sdlwindow_sync(); |
| 848 | 871 | } |
| 849 | 872 | |
| 850 | | osd_lock_acquire(window->render_lock); |
| 873 | //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10); |
| 851 | 874 | |
| 852 | 875 | // remove us from the list |
| 853 | 876 | for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->next) |
| r3029 | r3030 | |
| 860 | 883 | // free the textures etc |
| 861 | 884 | clear_worker_param(&wp); |
| 862 | 885 | wp.window = window; |
| 886 | wp.machine = machine; |
| 863 | 887 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 864 | 888 | |
| 865 | 889 | // free the render target, after the textures! |
| 866 | 890 | if (window->target != NULL) |
| 867 | 891 | render_target_free(window->target); |
| 868 | 892 | |
| 869 | | // free the lock |
| 870 | | osd_lock_free(window->render_lock); |
| 893 | // free the event |
| 894 | osd_event_free(window->rendered_event); |
| 871 | 895 | |
| 872 | 896 | // free the window itself |
| 873 | 897 | free(window); |
| r3029 | r3030 | |
| 953 | 977 | { |
| 954 | 978 | |
| 955 | 979 | ASSERT_MAIN_THREAD(); |
| 956 | | |
| 980 | |
| 957 | 981 | // adjust the cursor state |
| 958 | 982 | sdlwindow_update_cursor_state(machine, window); |
| 959 | 983 | |
| 960 | 984 | // if we're visible and running and not in the middle of a resize, draw |
| 961 | 985 | if (window->target != NULL) |
| 962 | 986 | { |
| 963 | | int got_lock = TRUE; |
| 964 | 987 | int tempwidth, tempheight; |
| 965 | 988 | |
| 966 | 989 | // see if the games video mode has changed |
| r3029 | r3030 | |
| 980 | 1003 | sdlwindow_resize(window, tempwidth, tempheight); |
| 981 | 1004 | } |
| 982 | 1005 | } |
| 983 | | |
| 984 | | got_lock = osd_lock_try(window->render_lock); |
| 985 | 1006 | |
| 986 | | // only render if we were able to get the lock |
| 987 | | if (got_lock) |
| 1007 | // only render if we have been signalled |
| 1008 | if (osd_event_wait(window->rendered_event, 0)) |
| 988 | 1009 | { |
| 989 | 1010 | worker_param wp; |
| 990 | 1011 | const render_primitive_list *primlist; |
| 991 | 1012 | |
| 992 | 1013 | clear_worker_param(&wp); |
| 993 | 1014 | |
| 994 | | // don't hold the lock; we just used it to see if rendering was still happening |
| 995 | | osd_lock_release(window->render_lock); |
| 996 | | |
| 997 | 1015 | // ensure the target bounds are up-to-date, and then get the primitives |
| 998 | 1016 | primlist = window->get_primitives(window); |
| 999 | 1017 | |
| r3029 | r3030 | |
| 1090 | 1108 | if (window->create(window, tempwidth, tempheight)) |
| 1091 | 1109 | return (void *) &result[1]; |
| 1092 | 1110 | |
| 1111 | // Make sure we have a consistent state |
| 1112 | SDL_ShowCursor(0); |
| 1113 | SDL_ShowCursor(1); |
| 1114 | |
| 1093 | 1115 | return (void *) &result[0]; |
| 1094 | 1116 | } |
| 1095 | 1117 | |
| r3029 | r3030 | |
| 1171 | 1193 | sdlinput_process_events_buf(wp->machine); |
| 1172 | 1194 | |
| 1173 | 1195 | window->primlist = wp->list; |
| 1174 | | osd_lock_acquire(window->render_lock); |
| 1175 | 1196 | |
| 1176 | 1197 | // if no bitmap, just fill |
| 1177 | 1198 | if (window->primlist == NULL) |
| r3029 | r3030 | |
| 1185 | 1206 | else |
| 1186 | 1207 | window->draw(window, dc, update); |
| 1187 | 1208 | } |
| 1188 | | osd_lock_release(window->render_lock); |
| 1209 | |
| 1210 | /* all done, ready for next */ |
| 1211 | osd_event_set(window->rendered_event); |
| 1189 | 1212 | free(wp); |
| 1190 | 1213 | |
| 1191 | 1214 | return NULL; |
src/osd/sdl/debugosx.c
| r3029 | r3030 | |
| 481 | 481 | // debugwin_update_during_game |
| 482 | 482 | //============================================================ |
| 483 | 483 | |
| 484 | | void debugwin_update_during_game(void) |
| 484 | void debugwin_update_during_game(running_machine *machine) |
| 485 | 485 | { |
| 486 | 486 | osx_init_debugger(); |
| 487 | 487 | |
| 488 | 488 | // if we're running live, do some checks |
| 489 | | if ( ! debug_cpu_is_stopped(Machine) ) |
| 489 | if ( ! debug_cpu_is_stopped(machine) ) |
| 490 | 490 | { |
| 491 | 491 | // see if the interrupt key is pressed and break if it is |
| 492 | 492 | temporarily_fake_that_we_are_not_visible = TRUE; |
| 493 | | if (ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK)) |
| 493 | if (ui_input_pressed(machine, IPT_UI_DEBUG_BREAK)) |
| 494 | 494 | { |
| 495 | 495 | debugwin_info *info; |
| 496 | 496 | HIViewRef focuswnd; |
| r3029 | r3030 | |
| 500 | 500 | focuswnd = NULL; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | | debugger_break(Machine); |
| 503 | debugger_break(machine); |
| 504 | 504 | debug_console_printf("User-initiated break\n"); |
| 505 | 505 | |
| 506 | 506 | // if we were focused on some window's edit box, reset it to default |
| r3029 | r3030 | |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | |
| 524 | | #if 0 |
| 525 | 524 | //============================================================ |
| 526 | | // debugwin_is_debugger_visible |
| 527 | | //============================================================ |
| 528 | | |
| 529 | | int debugwin_is_debugger_visible(void) |
| 530 | | { |
| 531 | | debugwin_info *info; |
| 532 | | |
| 533 | | // a bit of hackiness to allow us to check key sequences even if we are visible |
| 534 | | if (temporarily_fake_that_we_are_not_visible) |
| 535 | | return 0; |
| 536 | | |
| 537 | | // if any one of our windows is visible, return true |
| 538 | | for (info = window_list; info; info = info->next) |
| 539 | | if (IsWindowVisible(info->wnd)) |
| 540 | | return 1; |
| 541 | | return 0; |
| 542 | | } |
| 543 | | #endif |
| 544 | | |
| 545 | | |
| 546 | | //============================================================ |
| 547 | 525 | // debug_window_create |
| 548 | 526 | //============================================================ |
| 549 | 527 | |
| r3029 | r3030 | |
| 1935 | 1913 | // log_create_window |
| 1936 | 1914 | //============================================================ |
| 1937 | 1915 | |
| 1938 | | static void log_create_window(void) |
| 1916 | static void log_create_window(running_machine *machine) |
| 1939 | 1917 | { |
| 1940 | 1918 | debugwin_info *info; |
| 1941 | 1919 | char title[256]; |
| r3029 | r3030 | |
| 1943 | 1921 | Rect bounds; |
| 1944 | 1922 | |
| 1945 | 1923 | // create the window |
| 1946 | | snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", Machine->gamedrv->description, Machine->gamedrv->name); |
| 1924 | snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", machine->gamedrv->description, machine->gamedrv->name); |
| 1947 | 1925 | info = debug_window_create(title, NULL); |
| 1948 | 1926 | if (!info || !debug_view_create(info, 0, DVT_LOG)) |
| 1949 | 1927 | return; |
| r3029 | r3030 | |
| 1990 | 1968 | { |
| 1991 | 1969 | memorycombo_item **tail = &memorycombo; |
| 1992 | 1970 | UINT32 cpunum, spacenum; |
| 1971 | const char *rgntag; |
| 1993 | 1972 | int itemnum; |
| 1994 | | const char *rgnname; |
| 1995 | 1973 | |
| 1996 | 1974 | // first add all the CPUs' address spaces |
| 1997 | 1975 | for (cpunum = 0; cpunum < MAX_CPU; cpunum++) |
| r3029 | r3030 | |
| 2005 | 1983 | memset(ci, 0, sizeof(*ci)); |
| 2006 | 1984 | ci->cpunum = cpunum; |
| 2007 | 1985 | ci->spacenum = spacenum; |
| 2008 | | ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 4); |
| 2009 | | sprintf(ci->name, "CPU #%d (%s) %s memory", cpunum, cpunum_name(cpunum), address_space_names[spacenum]); |
| 1986 | ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8); |
| 1987 | snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum), address_space_names[spacenum]); |
| 2010 | 1988 | *tail = ci; |
| 2011 | 1989 | tail = &ci->next; |
| 2012 | 1990 | } |
| 2013 | 1991 | } |
| 2014 | 1992 | |
| 2015 | 1993 | // then add all the memory regions |
| 2016 | | rgnname = memory_region_next(machine, NULL); |
| 2017 | | while (rgnname != NULL) |
| 1994 | for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag)) |
| 2018 | 1995 | { |
| 2019 | | UINT8 *base = memory_region(machine, rgnname); |
| 2020 | 1996 | memorycombo_item *ci = malloc_or_die(sizeof(*ci)); |
| 2021 | | UINT32 flags = memory_region_flags(machine, rgnname); |
| 2022 | | UINT8 width = 0, little_endian; |
| 1997 | UINT32 flags = memory_region_flags(machine, rgntag); |
| 1998 | UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 1999 | UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8); |
| 2023 | 2000 | |
| 2024 | 2001 | memset(ci, 0, sizeof(*ci)); |
| 2025 | | ci->base = base; |
| 2026 | | ci->length = memory_region_length(machine, rgnname); |
| 2027 | | little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE); |
| 2028 | | switch (flags & ROMREGION_WIDTHMASK) |
| 2029 | | { |
| 2030 | | case ROMREGION_8BIT: |
| 2031 | | width = 8; |
| 2032 | | break; |
| 2033 | | case ROMREGION_16BIT: |
| 2034 | | width = 16; |
| 2035 | | break; |
| 2036 | | case ROMREGION_32BIT: |
| 2037 | | width = 32; |
| 2038 | | break; |
| 2039 | | case ROMREGION_64BIT: |
| 2040 | | width = 64; |
| 2041 | | break; |
| 2042 | | } |
| 2043 | | ci->prefsize = MIN(width, 4); |
| 2002 | ci->base = memory_region(machine, rgntag); |
| 2003 | ci->length = memory_region_length(machine, rgntag); |
| 2004 | ci->prefsize = MIN(width, 8); |
| 2044 | 2005 | ci->offset_xor = width - 1; |
| 2045 | 2006 | ci->little_endian = little_endian; |
| 2046 | | strcpy(ci->name, rgnname); |
| 2007 | |
| 2008 | snprintf(ci->name, ARRAY_LENGTH(ci->name), "Regio \"%s\"", rgntag); |
| 2009 | |
| 2047 | 2010 | *tail = ci; |
| 2048 | 2011 | tail = &ci->next; |
| 2049 | | |
| 2050 | | // and get the next region |
| 2051 | | rgnname = memory_region_next(machine, rgnname); |
| 2052 | 2012 | } |
| 2053 | 2013 | |
| 2054 | 2014 | // finally add all global array symbols |
| r3029 | r3030 | |
| 2070 | 2030 | memset(ci, 0, sizeof(*ci)); |
| 2071 | 2031 | ci->base = base; |
| 2072 | 2032 | ci->length = valcount * valsize; |
| 2073 | | ci->prefsize = MIN(valsize, 4); |
| 2033 | ci->prefsize = MIN(valsize, 8); |
| 2074 | 2034 | ci->little_endian = TRUE; |
| 2075 | 2035 | strcpy(ci->name, strrchr(name, '/') + 1); |
| 2076 | 2036 | *tail = ci; |
| r3029 | r3030 | |
| 2725 | 2685 | char name[100]; |
| 2726 | 2686 | UInt16 item; |
| 2727 | 2687 | |
| 2728 | | snprintf(name, ARRAY_LENGTH(name), "CPU #%d (%s)", cpunum, cpunum_name(cpunum)); |
| 2688 | snprintf(name, ARRAY_LENGTH(name), "CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum)); |
| 2729 | 2689 | |
| 2730 | 2690 | cfName = CFStringCreateWithCString( NULL, name, CFStringGetSystemEncoding() ); |
| 2731 | 2691 | AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item ); |
| r3029 | r3030 | |
| 3134 | 3094 | cpunum = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM); |
| 3135 | 3095 | |
| 3136 | 3096 | // then update the caption |
| 3137 | | snprintf(title, ARRAY_LENGTH(title), "Disassembly: %s (%d)", cpunum_name(cpunum), cpunum); |
| 3097 | snprintf(title, ARRAY_LENGTH(title), "Disassembly: CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum)); |
| 3138 | 3098 | |
| 3139 | 3099 | cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() ); |
| 3140 | 3100 | |
| r3029 | r3030 | |
| 3444 | 3404 | debug_view_set_property_UINT32(main_console->view[1].view, DVP_REGS_CPUNUM, cpunum); |
| 3445 | 3405 | |
| 3446 | 3406 | // then update the caption |
| 3447 | | snprintf(title, ARRAY_LENGTH(title), "Debug: %s - CPU %d (%s)", machine->gamedrv->name, cpu_getactivecpu(), activecpu_name()); |
| 3407 | snprintf(title, ARRAY_LENGTH(title), "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpu_getactivecpu(), machine->config->cpu[cpu_getactivecpu()].tag, activecpu_name()); |
| 3448 | 3408 | |
| 3449 | 3409 | cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() ); |
| 3450 | 3410 | |
| r3029 | r3030 | |
| 3530 | 3490 | return 1; |
| 3531 | 3491 | |
| 3532 | 3492 | case ID_NEW_LOG_WND: |
| 3533 | | log_create_window(); |
| 3493 | log_create_window(Machine); |
| 3534 | 3494 | return 1; |
| 3535 | 3495 | |
| 3536 | 3496 | case ID_RUN_AND_HIDE: |
| r3029 | r3030 | |
| 3664 | 3624 | |
| 3665 | 3625 | case 'l': |
| 3666 | 3626 | case 'L': |
| 3667 | | log_create_window(); |
| 3627 | log_create_window(Machine); |
| 3668 | 3628 | return 1; |
| 3669 | 3629 | } |
| 3670 | 3630 | } |