comparison render_fbdev.c @ 1786:2b661c1e431f

Remove some commented out code in fbdev backend
author Michael Pavone <pavone@retrodev.com>
date Thu, 14 Mar 2019 23:27:10 -0700
parents 8f2e78db0872
children 2fd0a8cb1c80
comparison
equal deleted inserted replaced
1785:8f2e78db0872 1786:2b661c1e431f
586 #ifndef DISABLE_OPENGL 586 #ifndef DISABLE_OPENGL
587 } 587 }
588 #endif 588 #endif
589 } 589 }
590 } 590 }
591
592 /*
593 static ui_render_fun on_context_destroyed, on_context_created;
594 void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create)
595 {
596 on_context_destroyed = destroy;
597 on_context_created = create;
598 }*/
599 591
600 static uint8_t scancode_map[128] = { 592 static uint8_t scancode_map[128] = {
601 [KEY_A] = 0x1C, 593 [KEY_A] = 0x1C,
602 [KEY_B] = 0x32, 594 [KEY_B] = 0x32,
603 [KEY_C] = 0x21, 595 [KEY_C] = 0x21,
804 void render_set_drag_drop_handler(drop_handler handler) 796 void render_set_drag_drop_handler(drop_handler handler)
805 { 797 {
806 drag_drop_handler = handler; 798 drag_drop_handler = handler;
807 } 799 }
808 800
809 /*static event_handler custom_event_handler;
810 void render_set_event_handler(event_handler handler)
811 {
812 custom_event_handler = handler;
813 }*/
814
815 char* render_joystick_type_id(int index) 801 char* render_joystick_type_id(int index)
816 { 802 {
817 return ""; 803 return strdup("");
818 /*SDL_Joystick *stick = render_get_joystick(index);
819 if (!stick) {
820 return NULL;
821 }
822 char *guid_string = malloc(33);
823 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, 33);
824 return guid_string;*/
825 } 804 }
826 805
827 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; 806 static uint32_t overscan_top[NUM_VID_STD] = {2, 21};
828 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; 807 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17};
829 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; 808 static uint32_t overscan_left[NUM_VID_STD] = {13, 13};
1357 } 1336 }
1358 #ifndef DISABLE_OPENGL 1337 #ifndef DISABLE_OPENGL
1359 } 1338 }
1360 #endif 1339 #endif
1361 1340
1362 /*
1363 #ifndef DISABLE_OPENGL
1364 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval;
1365 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0;
1366 if (gl_enabled)
1367 {
1368 flags |= SDL_WINDOW_OPENGL;
1369 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
1370 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
1371 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
1372 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
1373 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1374 #ifdef USE_GLES
1375 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
1376 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1377 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1378 #endif
1379 }
1380 #endif
1381 main_window = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_width, main_height, flags);
1382 if (!main_window) {
1383 fatal_error("Unable to create SDL window: %s\n", SDL_GetError());
1384 }
1385 #ifndef DISABLE_OPENGL
1386 if (gl_enabled)
1387 {
1388 main_context = SDL_GL_CreateContext(main_window);
1389 #ifdef USE_GLES
1390 int major_version;
1391 if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major_version) == 0 && major_version >= 2) {
1392 #else
1393 GLenum res = glewInit();
1394 if (res != GLEW_OK) {
1395 warning("Initialization of GLEW failed with code %d\n", res);
1396 }
1397
1398 if (res == GLEW_OK && GLEW_VERSION_2_0) {
1399 #endif
1400 render_gl = 1;
1401 SDL_GL_MakeCurrent(main_window, main_context);
1402 if (!strcmp("tear", vsync)) {
1403 if (SDL_GL_SetSwapInterval(-1) < 0) {
1404 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError());
1405 vsync = "on";
1406 } else {
1407 vsync = NULL;
1408 }
1409 }
1410 if (vsync) {
1411 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) {
1412 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError());
1413 }
1414 }
1415 } else {
1416 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n");
1417 }
1418 }
1419 if (!render_gl) {
1420 #endif
1421 flags = SDL_RENDERER_ACCELERATED;
1422 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) {
1423 flags |= SDL_RENDERER_PRESENTVSYNC;
1424 }
1425 main_renderer = SDL_CreateRenderer(main_window, -1, flags);
1426
1427 if (!main_renderer) {
1428 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError());
1429 }
1430 SDL_RendererInfo rinfo;
1431 SDL_GetRendererInfo(main_renderer, &rinfo);
1432 printf("SDL2 Render Driver: %s\n", rinfo.name);
1433 main_clip.x = main_clip.y = 0;
1434 main_clip.w = main_width;
1435 main_clip.h = main_height;
1436 #ifndef DISABLE_OPENGL
1437 }
1438 #endif
1439
1440 SDL_GetWindowSize(main_window, &main_width, &main_height);
1441 printf("Window created with size: %d x %d\n", main_width, main_height);*/
1442 update_aspect(); 1341 update_aspect();
1443 render_alloc_surfaces(); 1342 render_alloc_surfaces();
1444 def.ptrval = "off"; 1343 def.ptrval = "off";
1445 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); 1344 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on");
1446 } 1345 }
1744 } 1643 }
1745 events_processed = 0; 1644 events_processed = 0;
1746 #ifndef DISABLE_OPENGL 1645 #ifndef DISABLE_OPENGL
1747 } 1646 }
1748 #endif 1647 #endif
1749 /* 1648 }
1750 FILE *screenshot_file = NULL; 1649
1751 uint32_t shot_height, shot_width;
1752 char *ext;
1753 if (screenshot_path && which == FRAMEBUFFER_ODD) {
1754 screenshot_file = fopen(screenshot_path, "wb");
1755 if (screenshot_file) {
1756 #ifndef DISABLE_ZLIB
1757 ext = path_extension(screenshot_path);
1758 #endif
1759 info_message("Saving screenshot to %s\n", screenshot_path);
1760 } else {
1761 warning("Failed to open screenshot file %s for writing\n", screenshot_path);
1762 }
1763 free(screenshot_path);
1764 screenshot_path = NULL;
1765 shot_height = video_standard == VID_NTSC ? 243 : 294;
1766 shot_width = width;
1767 }
1768 interlaced = last != which;
1769 width -= overscan_left[video_standard] + overscan_right[video_standard];
1770 #ifndef DISABLE_OPENGL
1771 if (render_gl && which <= FRAMEBUFFER_EVEN) {
1772 SDL_GL_MakeCurrent(main_window, main_context);
1773 glBindTexture(GL_TEXTURE_2D, textures[which]);
1774 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, SRC_FORMAT, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]);
1775
1776 if (screenshot_file) {
1777 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now
1778 #ifndef DISABLE_ZLIB
1779 if (!strcasecmp(ext, "png")) {
1780 free(ext);
1781 save_png(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t));
1782 } else {
1783 free(ext);
1784 #endif
1785 save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t));
1786 #ifndef DISABLE_ZLIB
1787 }
1788 #endif
1789 }
1790 } else {
1791 #endif
1792 if (which <= FRAMEBUFFER_EVEN && last != which) {
1793 uint8_t *cur_dst = (uint8_t *)locked_pixels;
1794 uint8_t *cur_saved = (uint8_t *)texture_buf;
1795 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch;
1796 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0;
1797 for (int i = 0; i < height; ++i)
1798 {
1799 //copy saved line from other field
1800 memcpy(cur_dst + dst_off, cur_saved, locked_pitch);
1801 //save line from this field to buffer for next frame
1802 memcpy(cur_saved, cur_dst + src_off, locked_pitch);
1803 cur_dst += locked_pitch * 2;
1804 cur_saved += locked_pitch;
1805 }
1806 height = 480;
1807 }
1808 if (screenshot_file) {
1809 uint32_t shot_pitch = locked_pitch;
1810 if (which == FRAMEBUFFER_EVEN) {
1811 shot_height *= 2;
1812 } else {
1813 shot_pitch *= 2;
1814 }
1815 #ifndef DISABLE_ZLIB
1816 if (!strcasecmp(ext, "png")) {
1817 free(ext);
1818 save_png(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch);
1819 } else {
1820 free(ext);
1821 #endif
1822 save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch);
1823 #ifndef DISABLE_ZLIB
1824 }
1825 #endif
1826 }
1827 SDL_UnlockTexture(sdl_textures[which]);
1828 #ifndef DISABLE_OPENGL
1829 }
1830 #endif
1831 last_height = height;
1832 if (which <= FRAMEBUFFER_EVEN) {
1833 render_update_display();
1834 } else {
1835 SDL_RenderCopy(extra_renderers[which - FRAMEBUFFER_USER_START], sdl_textures[which], NULL, NULL);
1836 SDL_RenderPresent(extra_renderers[which - FRAMEBUFFER_USER_START]);
1837 }
1838 if (screenshot_file) {
1839 fclose(screenshot_file);
1840 }
1841 if (which <= FRAMEBUFFER_EVEN) {
1842 last = which;
1843 static uint32_t frame_counter, start;
1844 frame_counter++;
1845 last_frame= SDL_GetTicks();
1846 if ((last_frame - start) > FPS_INTERVAL) {
1847 if (start && (last_frame-start)) {
1848 #ifdef __ANDROID__
1849 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
1850 #else
1851 if (!fps_caption) {
1852 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1);
1853 }
1854 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
1855 SDL_SetWindowTitle(main_window, fps_caption);
1856 #endif
1857 }
1858 start = last_frame;
1859 frame_counter = 0;
1860 }
1861 }
1862 if (!sync_to_audio) {
1863 int32_t local_cur_min, local_min_remaining;
1864 SDL_LockAudio();
1865 if (last_buffered > NO_LAST_BUFFERED) {
1866 average_change *= 0.9f;
1867 average_change += (cur_min_buffered - last_buffered) * 0.1f;
1868 }
1869 local_cur_min = cur_min_buffered;
1870 local_min_remaining = min_remaining_buffer;
1871 last_buffered = cur_min_buffered;
1872 SDL_UnlockAudio();
1873 float frames_to_problem;
1874 if (average_change < 0) {
1875 frames_to_problem = (float)local_cur_min / -average_change;
1876 } else {
1877 frames_to_problem = (float)local_min_remaining / average_change;
1878 }
1879 float adjust_ratio = 0.0f;
1880 if (
1881 frames_to_problem < BUFFER_FRAMES_THRESHOLD
1882 || (average_change < 0 && local_cur_min < 3*min_buffered / 4)
1883 || (average_change >0 && local_cur_min > 5 * min_buffered / 4)
1884 || cur_min_buffered < 0
1885 ) {
1886
1887 if (cur_min_buffered < 0) {
1888 adjust_ratio = max_adjust;
1889 SDL_PauseAudio(1);
1890 last_buffered = NO_LAST_BUFFERED;
1891 cur_min_buffered = 0;
1892 } else {
1893 adjust_ratio = -1.0 * average_change / ((float)sample_rate / (float)source_hz);
1894 adjust_ratio /= 2.5 * source_hz;
1895 if (fabsf(adjust_ratio) > max_adjust) {
1896 adjust_ratio = adjust_ratio > 0 ? max_adjust : -max_adjust;
1897 }
1898 }
1899 } else if (local_cur_min < min_buffered / 2) {
1900 adjust_ratio = max_adjust;
1901 }
1902 if (adjust_ratio != 0.0f) {
1903 average_change = 0;
1904 for (uint8_t i = 0; i < num_audio_sources; i++)
1905 {
1906 audio_sources[i]->buffer_inc = ((double)audio_sources[i]->buffer_inc) + ((double)audio_sources[i]->buffer_inc) * adjust_ratio + 0.5;
1907 }
1908 }
1909 while (source_frame_count > 0)
1910 {
1911 render_update_display();
1912 source_frame_count--;
1913 }
1914 source_frame++;
1915 if (source_frame >= source_hz) {
1916 source_frame = 0;
1917 }
1918 source_frame_count = frame_repeat[source_frame];
1919 }*/
1920 }
1921 /*
1922 static ui_render_fun render_ui;
1923 void render_set_ui_render_fun(ui_render_fun fun)
1924 {
1925 render_ui = fun;
1926 }
1927 */
1928 void render_update_display() 1650 void render_update_display()
1929 { 1651 {
1930 #ifndef DISABLE_OPENGL 1652 #ifndef DISABLE_OPENGL
1931 if (render_gl) { 1653 if (render_gl) {
1932 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 1654 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);