static void *sdl_ctx_init(video_frame_info_t *video_info, void *video_driver) { gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*) calloc(1, sizeof(gfx_ctx_sdl_data_t)); if (!sdl) return NULL; #ifdef HAVE_X11 XInitThreads(); #endif if (SDL_WasInit(0) == 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) goto error; } else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) goto error; RARCH_LOG("[SDL_GL] SDL %i.%i.%i gfx context driver initialized.\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL); return sdl; error: RARCH_WARN("[SDL_GL]: Failed to initialize SDL gfx context driver: %s\n", SDL_GetError()); sdl_ctx_destroy_resources(sdl); if (sdl) free(sdl); return NULL; }
static int frontend_ps3_exec_exitspawn(const char *path, char const *argv[], char const *envp[]) { int ret; unsigned i; char spawn_data[256]; SceNpDrmKey *license_data = NULL; for(i = 0; i < sizeof(spawn_data); ++i) spawn_data[i] = i & 0xff; ret = sceNpDrmProcessExitSpawn(license_data, path, (const char** const)argv, envp, (sys_addr_t)spawn_data, 256, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); if(ret < 0) { RARCH_WARN("SELF file is not of NPDRM type, trying another approach to boot it...\n"); sys_game_process_exitspawn(path, (const char** const)argv, envp, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); } return ret; }
static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer) { sdl2_video_t *vid = (sdl2_video_t*)data; RARCH_PERFORMANCE_INIT(sdl2_gfx_read_viewport); RARCH_PERFORMANCE_START(sdl2_gfx_read_viewport); rarch_render_cached_frame(); SDL_Surface *surf = SDL_GetWindowSurface(vid->window); SDL_Surface *bgr24 = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_BGR24, 0); if (!bgr24) { RARCH_WARN("Failed to convert viewport data to BGR24: %s", SDL_GetError()); return false; } memcpy(buffer, bgr24->pixels, bgr24->h * bgr24->pitch); RARCH_PERFORMANCE_STOP(sdl2_gfx_read_viewport); return true; }
static bool core_info_list_update_missing_firmware_internal( core_info_list_t *core_info_list, const char *core, const char *systemdir) { size_t i; char path[PATH_MAX_LENGTH]; core_info_t *info = NULL; if (!core_info_list || !core) return false; path[0] = '\0'; info = core_info_find_internal(core_info_list, core); if (!info) return false; runloop_ctl(RUNLOOP_CTL_UNSET_MISSING_BIOS, NULL); for (i = 0; i < info->firmware_count; i++) { if (string_is_empty(info->firmware[i].path)) continue; fill_pathname_join(path, systemdir, info->firmware[i].path, sizeof(path)); info->firmware[i].missing = !path_file_exists(path); if (info->firmware[i].missing && !info->firmware[i].optional) { runloop_ctl(RUNLOOP_CTL_SET_MISSING_BIOS, NULL); RARCH_WARN("Firmware missing: %s\n", info->firmware[i].path); } } return true; }
// Generic file loader. ssize_t read_file(const char *path, void **buf) { void *rom_buf = NULL; FILE *file = fopen(path, "rb"); ssize_t rc = 0; size_t len = 0; if (!file) goto error; fseek(file, 0, SEEK_END); len = ftell(file); rewind(file); rom_buf = malloc(len + 1); if (!rom_buf) { RARCH_ERR("Couldn't allocate memory.\n"); goto error; } if ((rc = fread(rom_buf, 1, len, file)) < (ssize_t)len) RARCH_WARN("Didn't read whole file.\n"); *buf = rom_buf; // Allow for easy reading of strings to be safe. // Will only work with sane character formatting (Unix). ((char*)rom_buf)[len] = '\0'; fclose(file); return rc; error: if (file) fclose(file); free(rom_buf); *buf = NULL; return -1; }
static void x11_set_window_pid(Display *dpy, Window win) { long scret = 0; char *hostname = NULL; pid_t pid = getpid(); XChangeProperty(dpy, win, XInternAtom(dpy, "_NET_WM_PID", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1); errno = 0; if((scret = sysconf(_SC_HOST_NAME_MAX)) == -1 && errno) return; if((hostname = (char*)malloc(scret + 1)) == NULL) return; if(gethostname(hostname, scret + 1) == -1) RARCH_WARN("Failed to get hostname.\n"); else { XChangeProperty(dpy, win, XA_WM_CLIENT_MACHINE, XA_STRING, 8, PropModeReplace, (unsigned char *)hostname, strlen(hostname)); } free(hostname); }
void find_input_driver(void) { driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); int i = find_driver_index("input_driver", settings->input.driver); if (i >= 0) driver->input = (const input_driver_t*)input_driver_find_handle(i); else { unsigned d; RARCH_ERR("Couldn't find any input driver named \"%s\"\n", settings->input.driver); RARCH_LOG_OUTPUT("Available input drivers are:\n"); for (d = 0; input_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", input_driver_find_ident(d)); RARCH_WARN("Going to default to first input driver...\n"); driver->input = (const input_driver_t*)input_driver_find_handle(0); if (!driver->input) retro_fail(1, "find_input_driver()"); } }
static bool gl_cg_load_imports(void *data) { unsigned i; retro_ctx_memory_info_t mem_info; struct state_tracker_info tracker_info = {0}; cg_shader_data_t *cg_data = (cg_shader_data_t*)data; if (!cg_data->shader->variables) return true; for (i = 0; i < cg_data->shader->variables; i++) { unsigned memtype; switch (cg_data->shader->variable[i].ram_type) { case RARCH_STATE_WRAM: memtype = RETRO_MEMORY_SYSTEM_RAM; break; default: memtype = -1u; } mem_info.id = memtype; core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); if ((memtype != -1u) && (cg_data->shader->variable[i].addr >= mem_info.size)) { RARCH_ERR("Address out of bounds.\n"); return false; } } mem_info.data = NULL; mem_info.size = 0; mem_info.id = RETRO_MEMORY_SYSTEM_RAM; core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info); tracker_info.wram = (uint8_t*)mem_info.data; tracker_info.info = cg_data->shader->variable; tracker_info.info_elem = cg_data->shader->variables; #ifdef HAVE_PYTHON if (*cg_data->shader->script_path) { tracker_info.script = cg_data->shader->script_path; tracker_info.script_is_file = true; } tracker_info.script_class = *cg_data->shader->script_class ? cg_data->shader->script_class : NULL; #endif cg_data->state_tracker = state_tracker_init(&tracker_info); if (!cg_data->state_tracker) RARCH_WARN("Failed to initialize state tracker.\n"); return true; }
void recording_dump_frame(const void *data, unsigned width, unsigned height, size_t pitch) { struct ffemu_video_data ffemu_data = {0}; global_t *global = global_get_ptr(); if (!recording_data) return; ffemu_data.pitch = pitch; ffemu_data.width = width; ffemu_data.height = height; ffemu_data.data = data; if (video_driver_ctl(RARCH_DISPLAY_CTL_HAS_GPU_RECORD, NULL)) { uint8_t *gpu_buf = NULL; struct video_viewport vp = {0}; video_driver_viewport_info(&vp); if (!vp.width || !vp.height) { RARCH_WARN("%s \n", msg_hash_to_str(MSG_VIEWPORT_SIZE_CALCULATION_FAILED)); event_command(EVENT_CMD_GPU_RECORD_DEINIT); recording_dump_frame(data, width, height, pitch); return; } /* User has resized. We kinda have a problem now. */ if (vp.width != global->record.gpu_width || vp.height != global->record.gpu_height) { RARCH_WARN("%s\n", msg_hash_to_str(MSG_RECORDING_TERMINATED_DUE_TO_RESIZE)); runloop_msg_queue_push_new(MSG_RECORDING_TERMINATED_DUE_TO_RESIZE, 1, 180, true); event_command(EVENT_CMD_RECORD_DEINIT); return; } if (!video_driver_ctl(RARCH_DISPLAY_CTL_GPU_RECORD_GET, &gpu_buf)) return; /* Big bottleneck. * Since we might need to do read-backs asynchronously, * it might take 3-4 times before this returns true. */ if (!video_driver_ctl(RARCH_DISPLAY_CTL_READ_VIEWPORT, gpu_buf)) return; ffemu_data.pitch = global->record.gpu_width * 3; ffemu_data.width = global->record.gpu_width; ffemu_data.height = global->record.gpu_height; ffemu_data.data = gpu_buf + (ffemu_data.height - 1) * ffemu_data.pitch; ffemu_data.pitch = -ffemu_data.pitch; } if (!video_driver_ctl(RARCH_DISPLAY_CTL_HAS_GPU_RECORD, NULL)) ffemu_data.is_dupe = !data; if (recording_driver && recording_driver->push_video) recording_driver->push_video(recording_data, &ffemu_data); }
/** * video_shader_resolve_parameters: * @conf : Preset file to read from. * @shader : Shader passes handle. * * Resolves all shader parameters belonging to shaders. * * Returns: true (1) if successful, otherwise false (0). **/ bool video_shader_resolve_parameters(config_file_t *conf, struct video_shader *shader) { unsigned i; struct video_shader_parameter *param = &shader->parameters[shader->num_parameters]; shader->num_parameters = 0; /* Find all parameters in our shaders. */ for (i = 0; i < shader->passes; i++) { char line[4096] = {0}; FILE *file = fopen(shader->pass[i].source.path, "r"); if (!file) continue; while (shader->num_parameters < ARRAY_SIZE(shader->parameters) && fgets(line, sizeof(line), file)) { int ret = sscanf(line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f", param->id, param->desc, ¶m->initial, ¶m->minimum, ¶m->maximum, ¶m->step); if (ret < 5) continue; param->id[63] = '\0'; param->desc[63] = '\0'; if (ret == 5) param->step = 0.1f * (param->maximum - param->minimum); RARCH_LOG("Found #pragma parameter %s (%s) %f %f %f %f\n", param->desc, param->id, param->initial, param->minimum, param->maximum, param->step); param->current = param->initial; shader->num_parameters++; param++; } fclose(file); } if (conf) { /* Read in parameters which override the defaults. */ char parameters[4096] = {0}; const char *id = NULL; char *save = NULL; if (!config_get_array(conf, "parameters", parameters, sizeof(parameters))) return true; for (id = strtok_r(parameters, ";", &save); id; id = strtok_r(NULL, ";", &save)) { struct video_shader_parameter *parameter = (struct video_shader_parameter*) video_shader_parse_find_parameter(shader->parameters, shader->num_parameters, id); if (!parameter) { RARCH_WARN("[CGP/GLSLP]: Parameter %s is set in the preset, but no shader uses this parameter, ignoring.\n", id); continue; } if (!config_get_float(conf, id, ¶meter->current)) RARCH_WARN("[CGP/GLSLP]: Parameter %s is not set in preset.\n", id); } } return true; }
static bool get_texture_image(const char *shader_path, xmlNodePtr ptr) { if (gl_teximage_cnt >= MAX_TEXTURES) { RARCH_WARN("Too many texture images. Ignoring ...\n"); return true; } bool linear = true; char filename[PATH_MAX]; char filter[64]; char id[64]; xml_get_prop(filename, sizeof(filename), ptr, "file"); xml_get_prop(filter, sizeof(filter), ptr, "filter"); xml_get_prop(id, sizeof(id), ptr, "id"); struct texture_image img; if (!*id) { RARCH_ERR("Could not find ID in texture.\n"); return false; } if (!*filename) { RARCH_ERR("Could not find filename in texture.\n"); return false; } if (strcmp(filter, "nearest") == 0) linear = false; char tex_path[PATH_MAX]; fill_pathname_resolve_relative(tex_path, shader_path, (const char*)filename, sizeof(tex_path)); RARCH_LOG("Loading texture image from: \"%s\" ...\n", tex_path); if (!texture_image_load(tex_path, &img)) { RARCH_ERR("Failed to load texture image from: \"%s\"\n", tex_path); return false; } strlcpy(gl_teximage_uniforms[gl_teximage_cnt], (const char*)id, sizeof(gl_teximage_uniforms[0])); glGenTextures(1, &gl_teximage[gl_teximage_cnt]); pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1); glBindTexture(GL_TEXTURE_2D, gl_teximage[gl_teximage_cnt]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, BORDER_FUNC); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, BORDER_FUNC); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, img.width, img.height, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img.pixels); pglActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); free(img.pixels); gl_teximage_cnt++; return true; }
bool gl_glsl_init(const char *path) { #if !defined(HAVE_OPENGLES2) && !defined(HAVE_OPENGL_MODERN) && !defined(__APPLE__) // Load shader functions. LOAD_GL_SYM(CreateProgram); LOAD_GL_SYM(UseProgram); LOAD_GL_SYM(CreateShader); LOAD_GL_SYM(DeleteShader); LOAD_GL_SYM(ShaderSource); LOAD_GL_SYM(CompileShader); LOAD_GL_SYM(AttachShader); LOAD_GL_SYM(DetachShader); LOAD_GL_SYM(LinkProgram); LOAD_GL_SYM(GetUniformLocation); LOAD_GL_SYM(Uniform1i); LOAD_GL_SYM(Uniform1f); LOAD_GL_SYM(Uniform2fv); LOAD_GL_SYM(Uniform4fv); LOAD_GL_SYM(UniformMatrix4fv); LOAD_GL_SYM(GetShaderiv); LOAD_GL_SYM(GetShaderInfoLog); LOAD_GL_SYM(GetProgramiv); LOAD_GL_SYM(GetProgramInfoLog); LOAD_GL_SYM(DeleteProgram); LOAD_GL_SYM(GetAttachedShaders); LOAD_GL_SYM(GetAttribLocation); LOAD_GL_SYM(EnableVertexAttribArray); LOAD_GL_SYM(DisableVertexAttribArray); LOAD_GL_SYM(VertexAttribPointer); RARCH_LOG("Checking GLSL shader support ...\n"); bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader && pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader && pglDetachShader && pglLinkProgram && pglGetUniformLocation && pglUniform1i && pglUniform1f && pglUniform2fv && pglUniform4fv && pglUniformMatrix4fv && pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog && pglDeleteProgram && pglGetAttachedShaders && pglGetAttribLocation && pglEnableVertexAttribArray && pglDisableVertexAttribArray && pglVertexAttribPointer; if (!shader_support) { RARCH_ERR("GLSL shaders aren't supported by your OpenGL driver.\n"); return false; } #endif unsigned num_progs = 0; struct shader_program progs[RARCH_GLSL_MAX_SHADERS] = {{0}}; if (path) { num_progs = get_xml_shaders(path, progs, RARCH_GLSL_MAX_SHADERS - 1); if (num_progs == 0) { RARCH_ERR("Couldn't find any valid shaders in XML file.\n"); return false; } } else { RARCH_WARN("[GL]: Stock GLSL shaders will be used.\n"); num_progs = 1; progs[0].vertex = strdup(stock_vertex_modern); progs[0].fragment = strdup(stock_fragment_modern); glsl_modern = true; } #ifdef HAVE_OPENGLES2 if (!glsl_modern) { RARCH_ERR("[GL]: GLES context is used, but shader is not modern. Cannot use it.\n"); return false; } #endif struct shader_program stock_prog = {0}; stock_prog.vertex = strdup(glsl_modern ? stock_vertex_modern : stock_vertex_legacy); stock_prog.fragment = strdup(glsl_modern ? stock_fragment_modern : stock_fragment_legacy); if (!compile_programs(&gl_program[0], &stock_prog, 1)) { RARCH_ERR("GLSL stock programs failed to compile.\n"); return false; } for (unsigned i = 0; i < num_progs; i++) { gl_filter_type[i + 1] = progs[i].filter; gl_scale[i + 1].type_x = progs[i].type_x; gl_scale[i + 1].type_y = progs[i].type_y; gl_scale[i + 1].scale_x = progs[i].scale_x; gl_scale[i + 1].scale_y = progs[i].scale_y; gl_scale[i + 1].abs_x = progs[i].abs_x; gl_scale[i + 1].abs_y = progs[i].abs_y; gl_scale[i + 1].valid = progs[i].valid_scale; } if (!compile_programs(&gl_program[1], progs, num_progs)) return false; // RetroArch custom two-pass with two different files. if (num_progs == 1 && *g_settings.video.second_pass_shader && g_settings.video.render_to_texture) { unsigned secondary_progs = get_xml_shaders(g_settings.video.second_pass_shader, progs, 1); if (secondary_progs == 1) { if (!compile_programs(&gl_program[2], progs, 1)) { RARCH_ERR("Failed to compile second pass shader.\n"); return false; } num_progs++; } else { RARCH_ERR("Did not find exactly one valid shader in secondary shader file.\n"); return false; } } for (unsigned i = 0; i <= num_progs; i++) find_uniforms(gl_program[i], &gl_uniforms[i]); #ifdef GLSL_DEBUG if (!gl_check_error()) RARCH_WARN("Detected GL error in GLSL.\n"); #endif if (gl_tracker_info_cnt > 0) { struct state_tracker_info info = {0}; info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM); info.info = gl_tracker_info; info.info_elem = gl_tracker_info_cnt; #ifdef HAVE_PYTHON info.script = gl_script_program; info.script_class = *gl_tracker_script_class ? gl_tracker_script_class : NULL; info.script_is_file = false; #endif gl_state_tracker = state_tracker_init(&info); if (!gl_state_tracker) RARCH_WARN("Failed to init state tracker.\n"); } glsl_enable = true; gl_num_programs = num_progs; gl_program[gl_num_programs + 1] = gl_program[0]; gl_uniforms[gl_num_programs + 1] = gl_uniforms[0]; gl_glsl_reset_attrib(); return true; }
static void frontend_ps3_get_environment_settings(int *argc, char *argv[], void *args, void *params_data) { #ifndef IS_SALAMANDER bool original_verbose = verbosity_is_enabled(); verbosity_enable(); #endif (void)args; #ifndef IS_SALAMANDER #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) retro_main_log_file_init("/retroarch-log.txt"); #endif #endif int ret; unsigned int get_type; unsigned int get_attributes; CellGameContentSize size; char dirName[CELL_GAME_DIRNAME_SIZE] = {0}; #ifdef HAVE_MULTIMAN /* not launched from external launcher, set default path */ // second param is multiMAN SELF file if(path_file_exists(argv[2]) && *argc > 1 && (string_is_equal(argv[2], EMULATOR_CONTENT_DIR))) { multiman_detected = true; RARCH_LOG("Started from multiMAN, auto-game start enabled.\n"); } else #endif #ifndef IS_SALAMANDER if (*argc > 1 && !string_is_empty(argv[1])) { static char path[PATH_MAX_LENGTH] = {0}; struct rarch_main_wrap *args = (struct rarch_main_wrap*)params_data; if (args) { strlcpy(path, argv[1], sizeof(path)); args->touched = true; args->no_content = false; args->verbose = false; args->config_path = NULL; args->sram_path = NULL; args->state_path = NULL; args->content_path = path; args->libretro_path = NULL; RARCH_LOG("argv[0]: %s\n", argv[0]); RARCH_LOG("argv[1]: %s\n", argv[1]); RARCH_LOG("argv[2]: %s\n", argv[2]); RARCH_LOG("Auto-start game %s.\n", argv[1]); } } else RARCH_WARN("Started from Salamander, auto-game start disabled.\n"); #endif memset(&size, 0x00, sizeof(CellGameContentSize)); ret = cellGameBootCheck(&get_type, &get_attributes, &size, dirName); if(ret < 0) { RARCH_ERR("cellGameBootCheck() Error: 0x%x.\n", ret); } else { char content_info_path[PATH_MAX_LENGTH] = {0}; RARCH_LOG("cellGameBootCheck() OK.\n"); RARCH_LOG("Directory name: [%s].\n", dirName); RARCH_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", size.hddFreeSizeKB, size.sizeKB, size.sysSizeKB); switch(get_type) { case CELL_GAME_GAMETYPE_DISC: RARCH_LOG("RetroArch was launched on Optical Disc Drive.\n"); break; case CELL_GAME_GAMETYPE_HDD: RARCH_LOG("RetroArch was launched on HDD.\n"); break; } if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) RARCH_LOG("RetroArch was launched from host machine (APP_HOME).\n"); ret = cellGameContentPermit(content_info_path, g_defaults.dir.port); #ifdef HAVE_MULTIMAN if (multiman_detected) { fill_pathname_join(content_info_path, "/dev_hdd0/game/", EMULATOR_CONTENT_DIR, sizeof(content_info_path)); fill_pathname_join(g_defaults.dir.port, content_info_path, "USRDIR", sizeof(g_defaults.dir.port)); } #endif if(ret < 0) RARCH_ERR("cellGameContentPermit() Error: 0x%x\n", ret); else { RARCH_LOG("cellGameContentPermit() OK.\n"); RARCH_LOG("content_info_path : [%s].\n", content_info_path); RARCH_LOG("usrDirPath : [%s].\n", g_defaults.dir.port); } strlcpy(g_defaults.dir.content_history, g_defaults.dir.port, sizeof(g_defaults.dir.content_history)); fill_pathname_join(g_defaults.dir.core, g_defaults.dir.port, "cores", sizeof(g_defaults.dir.core)); fill_pathname_join(g_defaults.dir.core_info, g_defaults.dir.core, "info", sizeof(g_defaults.dir.core_info)); fill_pathname_join(g_defaults.dir.savestate, g_defaults.dir.core, "savestates", sizeof(g_defaults.dir.savestate)); fill_pathname_join(g_defaults.dir.sram, g_defaults.dir.core, "savefiles", sizeof(g_defaults.dir.sram)); fill_pathname_join(g_defaults.dir.system, g_defaults.dir.core, "system", sizeof(g_defaults.dir.system)); fill_pathname_join(g_defaults.dir.shader, g_defaults.dir.core, "shaders_cg", sizeof(g_defaults.dir.shader)); fill_pathname_join(g_defaults.path.config, g_defaults.dir.port, file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(g_defaults.path.config)); fill_pathname_join(g_defaults.dir.overlay, g_defaults.dir.core, "overlays", sizeof(g_defaults.dir.overlay)); fill_pathname_join(g_defaults.dir.assets, g_defaults.dir.core, "assets", sizeof(g_defaults.dir.assets)); fill_pathname_join(g_defaults.dir.cursor, g_defaults.dir.core, "database/cursors", sizeof(g_defaults.dir.cursor)); fill_pathname_join(g_defaults.dir.database, g_defaults.dir.core, "database/rdb", sizeof(g_defaults.dir.database)); fill_pathname_join(g_defaults.dir.playlist, g_defaults.dir.core, "playlists", sizeof(g_defaults.dir.playlist)); } #ifndef IS_SALAMANDER if (original_verbose) verbosity_enable(); else verbosity_disable(); #endif }
static bool d3d_initialize(void *data, const video_info_t *info) { d3d_video_t *d3d = (d3d_video_t*)data; bool ret = true; if (!d3d->g_pD3D) ret = d3d_init_base(d3d, info); else if (d3d->needs_restore) { D3DPRESENT_PARAMETERS d3dpp; d3d_make_d3dpp(d3d, info, &d3dpp); if (d3d->dev->Reset(&d3dpp) != D3D_OK) { HRESULT res = d3d->dev->TestCooperativeLevel(); const char *err; switch (res) { case D3DERR_DEVICELOST: err = "DEVICELOST"; break; case D3DERR_DEVICENOTRESET: err = "DEVICENOTRESET"; break; case D3DERR_DRIVERINTERNALERROR: err = "DRIVERINTERNALERROR"; break; default: err = "Unknown"; } // Try to recreate the device completely ... RARCH_WARN("[D3D]: Attempting to recover from dead state (%s).\n", err); d3d_deinitialize(d3d); d3d->g_pD3D->Release(); d3d->g_pD3D = NULL; ret = d3d_init_base(d3d, info); if (ret) RARCH_LOG("[D3D]: Recovered from dead state.\n"); else return ret; } } if (!ret) return ret; d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height, info->force_aspect, g_extern.system.aspect_ratio); #ifdef HAVE_SHADERS if (!d3d_init_shader(d3d)) { RARCH_ERR("Failed to initialize shader subsystem.\n"); return false; } #endif if (!d3d_init_chain(d3d, info)) { RARCH_ERR("Failed to initialize render chain.\n"); return false; } #if defined(_XBOX360) strlcpy(g_settings.video.font_path, "game:\\media\\Arial_12.xpr", sizeof(g_settings.video.font_path)); #endif d3d->font_ctx = d3d_font_init_first(d3d, g_settings.video.font_path, g_settings.video.font_size); if (!d3d->font_ctx) { RARCH_ERR("Failed to initialize font.\n"); return false; } return true; }
static void get_environment_settings(int argc, char *argv[]) { g_extern.verbose = true; int ret; unsigned int get_type; unsigned int get_attributes; CellGameContentSize size; char dirName[CELL_GAME_DIRNAME_SIZE]; char contentInfoPath[PATH_MAX]; #ifdef HAVE_HDD_CACHE_PARTITION CellSysCacheParam param; memset(¶m, 0x00, sizeof(CellSysCacheParam)); strlcpy(param.cacheId,CACHE_ID, sizeof(CellSysCacheParam)); ret = cellSysCacheMount(¶m); if(ret != CELL_SYSCACHE_RET_OK_CLEARED) { RARCH_ERR("System cache partition could not be mounted, it might be already mounted.\n"); } #endif #ifdef HAVE_MULTIMAN if(argc > 1) { /* launched from external launcher */ strlcpy(default_paths.multiman_self_file, argv[2], sizeof(default_paths.multiman_self_file)); } else { /* not launched from external launcher, set default path */ strlcpy(default_paths.multiman_self_file, "/dev_hdd0/game/BLES80608/USRDIR/RELOAD.SELF", sizeof(default_paths.multiman_self_file)); } if(path_file_exists(default_paths.multiman_self_file) && argc > 1 && path_file_exists(argv[1])) { g_console.external_launcher_support = EXTERN_LAUNCHER_MULTIMAN; RARCH_LOG("Started from multiMAN, auto-game start enabled.\n"); } else #endif { g_console.external_launcher_support = EXTERN_LAUNCHER_SALAMANDER; RARCH_WARN("Not started from multiMAN, auto-game start disabled.\n"); } memset(&size, 0x00, sizeof(CellGameContentSize)); ret = cellGameBootCheck(&get_type, &get_attributes, &size, dirName); if(ret < 0) { RARCH_ERR("cellGameBootCheck() Error: 0x%x.\n", ret); } else { RARCH_LOG("cellGameBootCheck() OK.\n"); RARCH_LOG("Directory name: [%s].\n", dirName); RARCH_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", size.hddFreeSizeKB, size.sizeKB, size.sysSizeKB); switch(get_type) { case CELL_GAME_GAMETYPE_DISC: RARCH_LOG("RetroArch was launched on Optical Disc Drive.\n"); break; case CELL_GAME_GAMETYPE_HDD: RARCH_LOG("RetroArch was launched on HDD.\n"); break; } if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) RARCH_LOG("RetroArch was launched from host machine (APP_HOME).\n"); ret = cellGameContentPermit(contentInfoPath, default_paths.port_dir); #ifdef HAVE_MULTIMAN if(g_console.external_launcher_support == EXTERN_LAUNCHER_MULTIMAN) { snprintf(contentInfoPath, sizeof(contentInfoPath), "/dev_hdd0/game/%s", EMULATOR_CONTENT_DIR); snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "/dev_hdd0/game/%s/USRDIR", EMULATOR_CONTENT_DIR); } #endif if(ret < 0) { RARCH_ERR("cellGameContentPermit() Error: 0x%x\n", ret); } else { RARCH_LOG("cellGameContentPermit() OK.\n"); RARCH_LOG("contentInfoPath : [%s].\n", contentInfoPath); RARCH_LOG("usrDirPath : [%s].\n", default_paths.port_dir); } #ifdef HAVE_HDD_CACHE_PARTITION snprintf(default_paths.cache_dir, sizeof(default_paths.cache_dir), "/dev_hdd1/"); #endif snprintf(default_paths.core_dir, sizeof(default_paths.core_dir), "%s/cores", default_paths.port_dir); snprintf(default_paths.executable_extension, sizeof(default_paths.executable_extension), ".SELF"); snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.core_dir); snprintf(default_paths.filesystem_root_dir, sizeof(default_paths.filesystem_root_dir), "/"); snprintf(default_paths.sram_dir, sizeof(default_paths.sram_dir), "%s/sram", default_paths.core_dir); snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.core_dir); /* now we fill in all the variables */ snprintf(default_paths.border_file, sizeof(default_paths.border_file), "%s/borders/Centered-1080p/mega-man-2.png", default_paths.core_dir); snprintf(default_paths.menu_border_file, sizeof(default_paths.menu_border_file), "%s/borders/Menu/main-menu.png", default_paths.core_dir); snprintf(default_paths.cgp_dir, sizeof(default_paths.cgp_dir), "%s/presets", default_paths.core_dir); snprintf(default_paths.input_presets_dir, sizeof(default_paths.input_presets_dir), "%s/input", default_paths.cgp_dir); snprintf(default_paths.border_dir, sizeof(default_paths.border_dir), "%s/borders", default_paths.core_dir); snprintf(default_paths.shader_dir, sizeof(default_paths.shader_dir), "%s/shaders", default_paths.core_dir); snprintf(default_paths.shader_file, sizeof(default_paths.shader_file), "%s/shaders/stock.cg", default_paths.core_dir); snprintf(default_paths.menu_shader_file, sizeof(default_paths.menu_shader_file), "%s/shaders/Borders/Menu/border-only-rarch.cg", default_paths.core_dir); snprintf(default_paths.config_file, sizeof(default_paths.config_file), "%s/retroarch.cfg", default_paths.port_dir); } g_extern.verbose = false; }
/** * netplay_net_pre_frame: * @netplay : pointer to netplay object * * Pre-frame for Netplay (normal version). **/ static bool netplay_net_pre_frame(netplay_t *netplay) { retro_ctx_serialize_info_t serial_info; if (netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->self_ptr], netplay->self_frame_count)) { serial_info.data_const = NULL; serial_info.data = netplay->buffer[netplay->self_ptr].state; serial_info.size = netplay->state_size; memset(serial_info.data, 0, serial_info.size); if ((netplay->quirks & NETPLAY_QUIRK_INITIALIZATION) || netplay->self_frame_count == 0) { /* Don't serialize until it's safe */ } else if (!(netplay->quirks & NETPLAY_QUIRK_NO_SAVESTATES) && core_serialize(&serial_info)) { if (netplay->force_send_savestate && !netplay->stall) { /* Send this along to the other side */ serial_info.data_const = netplay->buffer[netplay->self_ptr].state; netplay_load_savestate(netplay, &serial_info, false); netplay->force_send_savestate = false; } } else { /* If the core can't serialize properly, we must stall for the * remote input on EVERY frame, because we can't recover */ netplay->quirks |= NETPLAY_QUIRK_NO_SAVESTATES; netplay->stall_frames = 0; } /* If we can't transmit savestates, we must stall until the client is ready */ if (!netplay->has_connection && netplay->self_frame_count > 0 && (netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION))) netplay->stall = RARCH_NETPLAY_STALL_NO_CONNECTION; } if (netplay->is_server && !netplay->has_connection) { fd_set fds; struct timeval tmp_tv = {0}; int new_fd; struct sockaddr_storage their_addr; socklen_t addr_size; /* Check for a connection */ FD_ZERO(&fds); FD_SET(netplay->fd, &fds); if (socket_select(netplay->fd + 1, &fds, NULL, NULL, &tmp_tv) > 0 && FD_ISSET(netplay->fd, &fds)) { addr_size = sizeof(their_addr); new_fd = accept(netplay->fd, (struct sockaddr*)&their_addr, &addr_size); if (new_fd < 0) { RARCH_ERR("%s\n", msg_hash_to_str(MSG_NETPLAY_FAILED)); return true; } socket_close(netplay->fd); netplay->fd = new_fd; #if defined(IPPROTO_TCP) && defined(TCP_NODELAY) { int flag = 1; if (setsockopt(netplay->fd, IPPROTO_TCP, TCP_NODELAY, (void*)&flag, sizeof(int)) < 0) RARCH_WARN("Could not set netplay TCP socket to nodelay. Expect jitter.\n"); } #endif #if defined(F_SETFD) && defined(FD_CLOEXEC) /* Don't let any inherited processes keep open our port */ if (fcntl(netplay->fd, F_SETFD, FD_CLOEXEC) < 0) RARCH_WARN("Cannot set Netplay port to close-on-exec. It may fail to reopen if the client disconnects.\n"); #endif /* Establish the connection */ if (netplay_handshake(netplay)) { netplay->has_connection = true; /* Send them the savestate */ if (!(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION))) { netplay->force_send_savestate = true; } else { /* Because the first frame isn't serialized, we're actually at * frame 1 */ netplay->self_ptr = NEXT_PTR(netplay->self_ptr); netplay->self_frame_count = 1; } /* And expect the current frame from the other side */ netplay->read_frame_count = netplay->other_frame_count = netplay->self_frame_count; netplay->read_ptr = netplay->other_ptr = netplay->self_ptr; /* Unstall if we were waiting for this */ if (netplay->stall == RARCH_NETPLAY_STALL_NO_CONNECTION) netplay->stall = 0; } else { socket_close(netplay->fd); /* FIXME: Get in a state to accept another client */ } } } netplay->can_poll = true; input_poll_net(); return (netplay->stall != RARCH_NETPLAY_STALL_NO_CONNECTION); }
void init_audio(void) { size_t outsamples_max, max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2; runloop_t *runloop = rarch_main_get_ptr(); driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); audio_convert_init_simd(); /* Resource leaks will follow if audio is initialized twice. */ if (driver->audio_data) return; /* Accomodate rewind since at some point we might have two full buffers. */ outsamples_max = max_bufsamples * AUDIO_MAX_RATIO * settings->slowmotion_ratio; /* Used for recording even if audio isn't enabled. */ rarch_assert(global->audio_data.conv_outsamples = (int16_t*)malloc(outsamples_max * sizeof(int16_t))); if (!global->audio_data.conv_outsamples) goto error; global->audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING; global->audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING; global->audio_data.chunk_size = global->audio_data.block_chunk_size; /* Needs to be able to hold full content of a full max_bufsamples * in addition to its own. */ rarch_assert(global->audio_data.rewind_buf = (int16_t*) malloc(max_bufsamples * sizeof(int16_t))); if (!global->audio_data.rewind_buf) goto error; global->audio_data.rewind_size = max_bufsamples; if (!settings->audio.enable) { driver->audio_active = false; return; } find_audio_driver(); #ifdef HAVE_THREADS if (global->system.audio_callback.callback) { RARCH_LOG("Starting threaded audio driver ...\n"); if (!rarch_threaded_audio_init(&driver->audio, &driver->audio_data, *settings->audio.device ? settings->audio.device : NULL, settings->audio.out_rate, settings->audio.latency, driver->audio)) { RARCH_ERR("Cannot open threaded audio driver ... Exiting ...\n"); rarch_fail(1, "init_audio()"); } } else #endif { driver->audio_data = driver->audio->init(*settings->audio.device ? settings->audio.device : NULL, settings->audio.out_rate, settings->audio.latency); } if (!driver->audio_data) { RARCH_ERR("Failed to initialize audio driver. Will continue without audio.\n"); driver->audio_active = false; } global->audio_data.use_float = false; if (driver->audio_active && driver->audio->use_float(driver->audio_data)) global->audio_data.use_float = true; if (!settings->audio.sync && driver->audio_active) { rarch_main_command(RARCH_CMD_AUDIO_SET_NONBLOCKING_STATE); global->audio_data.chunk_size = global->audio_data.nonblock_chunk_size; } if (global->audio_data.in_rate <= 0.0f) { /* Should never happen. */ RARCH_WARN("Input rate is invalid (%.3f Hz). Using output rate (%u Hz).\n", global->audio_data.in_rate, settings->audio.out_rate); global->audio_data.in_rate = settings->audio.out_rate; } global->audio_data.orig_src_ratio = global->audio_data.src_ratio = (double)settings->audio.out_rate / global->audio_data.in_rate; if (!rarch_resampler_realloc(&driver->resampler_data, &driver->resampler, settings->audio.resampler, global->audio_data.orig_src_ratio)) { RARCH_ERR("Failed to initialize resampler \"%s\".\n", settings->audio.resampler); driver->audio_active = false; } rarch_assert(global->audio_data.data = (float*) malloc(max_bufsamples * sizeof(float))); if (!global->audio_data.data) goto error; global->audio_data.data_ptr = 0; rarch_assert(settings->audio.out_rate < global->audio_data.in_rate * AUDIO_MAX_RATIO); rarch_assert(global->audio_data.outsamples = (float*) malloc(outsamples_max * sizeof(float))); if (!global->audio_data.outsamples) goto error; global->audio_data.rate_control = false; if (!global->system.audio_callback.callback && driver->audio_active && settings->audio.rate_control) { if (driver->audio->buffer_size && driver->audio->write_avail) { global->audio_data.driver_buffer_size = driver->audio->buffer_size(driver->audio_data); global->audio_data.rate_control = true; } else RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n"); } rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); runloop->measure_data.buffer_free_samples_count = 0; if (driver->audio_active && !settings->audio.mute_enable && global->system.audio_callback.callback) { /* Threaded driver is initially stopped. */ driver->audio->start(driver->audio_data); } return; error: if (global->audio_data.conv_outsamples) free(global->audio_data.conv_outsamples); global->audio_data.conv_outsamples = NULL; if (global->audio_data.data) free(global->audio_data.data); global->audio_data.data = NULL; if (global->audio_data.rewind_buf) free(global->audio_data.rewind_buf); global->audio_data.rewind_buf = NULL; if (global->audio_data.outsamples) free(global->audio_data.outsamples); global->audio_data.outsamples = NULL; }
bool gl_glsl_init(const char *path) { #ifndef __APPLE__ // Load shader functions. LOAD_GL_SYM(CreateProgram); LOAD_GL_SYM(UseProgram); LOAD_GL_SYM(CreateShader); LOAD_GL_SYM(DeleteShader); LOAD_GL_SYM(ShaderSource); LOAD_GL_SYM(CompileShader); LOAD_GL_SYM(AttachShader); LOAD_GL_SYM(DetachShader); LOAD_GL_SYM(LinkProgram); LOAD_GL_SYM(GetUniformLocation); LOAD_GL_SYM(Uniform1i); LOAD_GL_SYM(Uniform1f); LOAD_GL_SYM(Uniform2fv); LOAD_GL_SYM(Uniform4fv); LOAD_GL_SYM(GetShaderiv); LOAD_GL_SYM(GetShaderInfoLog); LOAD_GL_SYM(GetProgramiv); LOAD_GL_SYM(GetProgramInfoLog); LOAD_GL_SYM(DeleteProgram); LOAD_GL_SYM(GetAttachedShaders); LOAD_GL_SYM(GetAttribLocation); LOAD_GL_SYM(EnableVertexAttribArray); LOAD_GL_SYM(DisableVertexAttribArray); LOAD_GL_SYM(VertexAttribPointer); #endif RARCH_LOG("Checking GLSL shader support ...\n"); #ifdef __APPLE__ const bool shader_support = true; #else bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader && pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader && pglDetachShader && pglLinkProgram && pglGetUniformLocation && pglUniform1i && pglUniform1f && pglUniform2fv && pglUniform4fv && pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog && pglDeleteProgram && pglGetAttachedShaders && pglGetAttribLocation && pglEnableVertexAttribArray && pglDisableVertexAttribArray && pglVertexAttribPointer; #endif if (!shader_support) { RARCH_ERR("GLSL shaders aren't supported by your OpenGL driver.\n"); return false; } struct shader_program stock_prog = {0}; stock_prog.vertex = strdup(stock_vertex); stock_prog.fragment = strdup(stock_fragment); if (!compile_programs(&gl_program[0], &stock_prog, 1)) return false; struct shader_program progs[MAX_PROGRAMS]; unsigned num_progs = get_xml_shaders(path, progs, MAX_PROGRAMS - 1); if (num_progs == 0) { RARCH_ERR("Couldn't find any valid shaders in XML file.\n"); return false; } for (unsigned i = 0; i < num_progs; i++) { gl_filter_type[i + 1] = progs[i].filter; gl_scale[i + 1].type_x = progs[i].type_x; gl_scale[i + 1].type_y = progs[i].type_y; gl_scale[i + 1].scale_x = progs[i].scale_x; gl_scale[i + 1].scale_y = progs[i].scale_y; gl_scale[i + 1].abs_x = progs[i].abs_x; gl_scale[i + 1].abs_y = progs[i].abs_y; gl_scale[i + 1].valid = progs[i].valid_scale; } if (!compile_programs(&gl_program[1], progs, num_progs)) return false; // RetroArch custom two-pass with two different files. if (num_progs == 1 && *g_settings.video.second_pass_shader && g_settings.video.render_to_texture) { unsigned secondary_progs = get_xml_shaders(g_settings.video.second_pass_shader, progs, 1); if (secondary_progs == 1) { compile_programs(&gl_program[2], progs, 1); num_progs++; } else { RARCH_ERR("Did not find valid shader in secondary shader file.\n"); return false; } } //if (!gl_check_error()) // RARCH_WARN("Detected GL error.\n"); if (gl_tracker_info_cnt > 0) { struct state_tracker_info info = {0}; info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM); info.info = gl_tracker_info; info.info_elem = gl_tracker_info_cnt; #ifdef HAVE_PYTHON if (*gl_tracker_script) info.script = gl_tracker_script; else if (gl_script_program) info.script = (const char*)gl_script_program; else info.script = NULL; info.script_class = *gl_tracker_script_class ? gl_tracker_script_class : NULL; info.script_is_file = *gl_tracker_script; #endif gl_state_tracker = state_tracker_init(&info); if (!gl_state_tracker) RARCH_WARN("Failed to init state tracker.\n"); } glsl_enable = true; gl_num_programs = num_progs; gl_program[gl_num_programs + 1] = gl_program[0]; gl_glsl_reset_attrib(); return true; }
/** * main_entry: * * Main function of RetroArch. * * If HAVE_MAIN is not defined, will contain main loop and will not * be exited from until we exit the program. Otherwise, will * just do initialization. * * Returns: varies per platform. **/ int rarch_main(int argc, char *argv[], void *data) { void *args = (void*)data; int ret = 0; settings_t *settings = NULL; driver_t *driver = NULL; rarch_main_alloc(); driver = driver_get_ptr(); if (driver) driver->frontend_ctx = (frontend_ctx_driver_t*)frontend_ctx_init_first(); if (!driver || !driver->frontend_ctx) RARCH_WARN("Frontend context could not be initialized.\n"); if (driver->frontend_ctx && driver->frontend_ctx->init) driver->frontend_ctx->init(args); rarch_main_new(); if (driver->frontend_ctx) { if (!(ret = (main_load_content(argc, argv, args, driver->frontend_ctx->environment_get, driver->frontend_ctx->process_args)))) return ret; } event_command(EVENT_CMD_HISTORY_INIT); settings = config_get_ptr(); if (settings->history_list_enable) { global_t *global = global_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr(); if (global->content_is_init || system->no_content) history_playlist_push( g_defaults.history, global->fullpath, settings->libretro, system ? &system->info : NULL); } if (driver) driver->ui_companion = (ui_companion_driver_t*)ui_companion_init_first(); if (driver->ui_companion && driver->ui_companion->toggle) { if (settings->ui.companion_start_on_boot) driver->ui_companion->toggle(driver->ui_companion_data); } #ifndef HAVE_MAIN do{ ret = rarch_main_iterate(); rarch_main_data_iterate(); }while(ret != -1); main_exit(args); #endif return 0; }
static void get_environment_settings(int argc, char *argv[]) { int ret; unsigned int get_type; unsigned int get_attributes; CellGameContentSize size; char dirName[CELL_GAME_DIRNAME_SIZE]; char contentInfoPath[PATH_MAX]; #ifdef HAVE_MULTIMAN /* not launched from external launcher, set default path */ strlcpy(default_paths.multiman_self_file, "/dev_hdd0/game/BLES80608/USRDIR/RELOAD.SELF", sizeof(default_paths.multiman_self_file)); if(path_file_exists(default_paths.multiman_self_file) && argc > 1 && path_file_exists(argv[1])) { g_extern.lifecycle_mode_state |= (1ULL << MODE_EXTLAUNCH_MULTIMAN); RARCH_LOG("Started from multiMAN, auto-game start enabled.\n"); } else #endif #ifndef IS_SALAMANDER { g_extern.lifecycle_mode_state |= (1ULL << MODE_EXTLAUNCH_SALAMANDER); RARCH_WARN("Started from Salamander, auto-game start disabled.\n"); } #endif memset(&size, 0x00, sizeof(CellGameContentSize)); ret = cellGameBootCheck(&get_type, &get_attributes, &size, dirName); if(ret < 0) { RARCH_ERR("cellGameBootCheck() Error: 0x%x.\n", ret); } else { RARCH_LOG("cellGameBootCheck() OK.\n"); RARCH_LOG("Directory name: [%s].\n", dirName); RARCH_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", size.hddFreeSizeKB, size.sizeKB, size.sysSizeKB); switch(get_type) { case CELL_GAME_GAMETYPE_DISC: RARCH_LOG("RetroArch was launched on Optical Disc Drive.\n"); break; case CELL_GAME_GAMETYPE_HDD: RARCH_LOG("RetroArch was launched on HDD.\n"); break; } if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) RARCH_LOG("RetroArch was launched from host machine (APP_HOME).\n"); ret = cellGameContentPermit(contentInfoPath, default_paths.port_dir); #ifdef HAVE_MULTIMAN if (g_extern.lifecycle_mode_state & (1ULL << MODE_EXTLAUNCH_MULTIMAN)) { snprintf(contentInfoPath, sizeof(contentInfoPath), "/dev_hdd0/game/%s", EMULATOR_CONTENT_DIR); snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "/dev_hdd0/game/%s/USRDIR", EMULATOR_CONTENT_DIR); } #endif if(ret < 0) { RARCH_ERR("cellGameContentPermit() Error: 0x%x\n", ret); } else { RARCH_LOG("cellGameContentPermit() OK.\n"); RARCH_LOG("contentInfoPath : [%s].\n", contentInfoPath); RARCH_LOG("usrDirPath : [%s].\n", default_paths.port_dir); } snprintf(default_paths.core_dir, sizeof(default_paths.core_dir), "%s/cores", default_paths.port_dir); snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.core_dir); snprintf(default_paths.filesystem_root_dir, sizeof(default_paths.filesystem_root_dir), "/"); snprintf(default_paths.filebrowser_startup_dir, sizeof(default_paths.filebrowser_startup_dir), default_paths.filesystem_root_dir); snprintf(default_paths.sram_dir, sizeof(default_paths.sram_dir), "%s/sram", default_paths.core_dir); snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.core_dir); /* now we fill in all the variables */ snprintf(default_paths.border_file, sizeof(default_paths.border_file), "%s/borders/Centered-1080p/mega-man-2.png", default_paths.core_dir); snprintf(default_paths.menu_border_file, sizeof(default_paths.menu_border_file), "%s/borders/Menu/main-menu_1080p.png", default_paths.core_dir); snprintf(default_paths.cgp_dir, sizeof(default_paths.cgp_dir), "%s/presets", default_paths.core_dir); snprintf(default_paths.input_presets_dir, sizeof(default_paths.input_presets_dir), "%s/input", default_paths.cgp_dir); snprintf(default_paths.border_dir, sizeof(default_paths.border_dir), "%s/borders", default_paths.core_dir); #if defined(HAVE_CG) || defined(HAVE_GLSL) snprintf(default_paths.shader_dir, sizeof(default_paths.shader_dir), "%s/shaders", default_paths.core_dir); snprintf(default_paths.shader_file, sizeof(default_paths.shader_file), "%s/shaders/stock.cg", default_paths.core_dir); snprintf(default_paths.menu_shader_file, sizeof(default_paths.menu_shader_file), "%s/shaders/Borders/Menu/border-only-rarch.cg", default_paths.core_dir); #endif #ifdef IS_SALAMANDER snprintf(default_paths.config_path, sizeof(default_paths.config_path), "%s/retroarch.cfg", default_paths.port_dir); #else snprintf(g_extern.config_path, sizeof(g_extern.config_path), "%s/retroarch.cfg", default_paths.port_dir); #endif } }
static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr) { prog->scale_x = 1.0; prog->scale_y = 1.0; prog->type_x = prog->type_y = RARCH_SCALE_INPUT; prog->valid_scale = false; // Check if shader forces a certain texture filtering. char attr[64]; if (xml_get_prop(attr, sizeof(attr), ptr, "filter")) { if (strcmp(attr, "nearest") == 0) { prog->filter = RARCH_GL_NEAREST; RARCH_LOG("XML: Shader forces GL_NEAREST.\n"); } else if (strcmp(attr, "linear") == 0) { prog->filter = RARCH_GL_LINEAR; RARCH_LOG("XML: Shader forces GL_LINEAR.\n"); } else RARCH_WARN("XML: Invalid property for filter.\n"); } else prog->filter = RARCH_GL_NOFORCE; // Check for scaling attributes *lots of code <_<* char attr_scale[64], attr_scale_x[64], attr_scale_y[64]; char attr_size[64], attr_size_x[64], attr_size_y[64]; char attr_outscale[64], attr_outscale_x[64], attr_outscale_y[64]; xml_get_prop(attr_scale, sizeof(attr_scale), ptr, "scale"); xml_get_prop(attr_scale_x, sizeof(attr_scale_x), ptr, "scale_x"); xml_get_prop(attr_scale_y, sizeof(attr_scale_y), ptr, "scale_y"); xml_get_prop(attr_size, sizeof(attr_size), ptr, "size"); xml_get_prop(attr_size_x, sizeof(attr_size_x), ptr, "size_x"); xml_get_prop(attr_size_y, sizeof(attr_size_y), ptr, "size_y"); xml_get_prop(attr_outscale, sizeof(attr_outscale), ptr, "outscale"); xml_get_prop(attr_outscale_x, sizeof(attr_outscale_x), ptr, "outscale_x"); xml_get_prop(attr_outscale_y, sizeof(attr_outscale_y), ptr, "outscale_y"); unsigned x_attr_cnt = 0, y_attr_cnt = 0; if (*attr_scale) { float scale = strtod(attr_scale, NULL); prog->scale_x = scale; prog->scale_y = scale; prog->valid_scale = true; prog->type_x = prog->type_y = RARCH_SCALE_INPUT; RARCH_LOG("Got scale attr: %.1f\n", scale); x_attr_cnt++; y_attr_cnt++; } if (*attr_scale_x) { float scale = strtod(attr_scale_x, NULL); prog->scale_x = scale; prog->valid_scale = true; prog->type_x = RARCH_SCALE_INPUT; RARCH_LOG("Got scale_x attr: %.1f\n", scale); x_attr_cnt++; } if (*attr_scale_y) { float scale = strtod(attr_scale_y, NULL); prog->scale_y = scale; prog->valid_scale = true; prog->type_y = RARCH_SCALE_INPUT; RARCH_LOG("Got scale_y attr: %.1f\n", scale); y_attr_cnt++; } if (*attr_size) { prog->abs_x = prog->abs_y = strtoul(attr_size, NULL, 0); prog->valid_scale = true; prog->type_x = prog->type_y = RARCH_SCALE_ABSOLUTE; RARCH_LOG("Got size attr: %u\n", prog->abs_x); x_attr_cnt++; y_attr_cnt++; } if (*attr_size_x) { prog->abs_x = strtoul(attr_size_x, NULL, 0); prog->valid_scale = true; prog->type_x = RARCH_SCALE_ABSOLUTE; RARCH_LOG("Got size_x attr: %u\n", prog->abs_x); x_attr_cnt++; } if (*attr_size_y) { prog->abs_y = strtoul(attr_size_y, NULL, 0); prog->valid_scale = true; prog->type_y = RARCH_SCALE_ABSOLUTE; RARCH_LOG("Got size_y attr: %u\n", prog->abs_y); y_attr_cnt++; } if (*attr_outscale) { float scale = strtod(attr_outscale, NULL); prog->scale_x = scale; prog->scale_y = scale; prog->valid_scale = true; prog->type_x = prog->type_y = RARCH_SCALE_VIEWPORT; RARCH_LOG("Got outscale attr: %.1f\n", scale); x_attr_cnt++; y_attr_cnt++; } if (*attr_outscale_x) { float scale = strtod(attr_outscale_x, NULL); prog->scale_x = scale; prog->valid_scale = true; prog->type_x = RARCH_SCALE_VIEWPORT; RARCH_LOG("Got outscale_x attr: %.1f\n", scale); x_attr_cnt++; } if (*attr_outscale_y) { float scale = strtod(attr_outscale_y, NULL); prog->scale_y = scale; prog->valid_scale = true; prog->type_y = RARCH_SCALE_VIEWPORT; RARCH_LOG("Got outscale_y attr: %.1f\n", scale); y_attr_cnt++; } if (x_attr_cnt > 1) return false; if (y_attr_cnt > 1) return false; return true; }
static void sdl2_init_font(sdl2_video_t *vid, const char *font_path, unsigned font_size) { int i, r, g, b; SDL_Color colors[256]; SDL_Surface *tmp = NULL; SDL_Palette *pal = NULL; const struct font_atlas *atlas = NULL; settings_t *settings = config_get_ptr(); if (!settings->video.font_enable) return; if (!font_renderer_create_default(&vid->font_driver, &vid->font_data, *font_path ? font_path : NULL, font_size)) { RARCH_WARN("[SDL]: Could not initialize fonts.\n"); return; } r = settings->video.msg_color_r * 255; g = settings->video.msg_color_g * 255; b = settings->video.msg_color_b * 255; r = (r < 0) ? 0 : (r > 255 ? 255 : r); g = (g < 0) ? 0 : (g > 255 ? 255 : g); b = (b < 0) ? 0 : (b > 255 ? 255 : b); vid->font_r = r; vid->font_g = g; vid->font_b = b; atlas = vid->font_driver->get_atlas(vid->font_data); tmp = SDL_CreateRGBSurfaceFrom(atlas->buffer, atlas->width, atlas->height, 8, atlas->width, 0, 0, 0, 0); for (i = 0; i < 256; ++i) { colors[i].r = colors[i].g = colors[i].b = i; colors[i].a = 255; } pal = SDL_AllocPalette(256); SDL_SetPaletteColors(pal, colors, 0, 256); SDL_SetSurfacePalette(tmp, pal); SDL_SetColorKey(tmp, SDL_TRUE, 0); vid->font.tex = SDL_CreateTextureFromSurface(vid->renderer, tmp); if (vid->font.tex) { vid->font.w = atlas->width; vid->font.h = atlas->height; vid->font.active = true; SDL_SetTextureBlendMode(vid->font.tex, SDL_BLENDMODE_ADD); } else RARCH_WARN("[SDL]: Failed to initialize font texture: %s\n", SDL_GetError()); SDL_FreePalette(pal); SDL_FreeSurface(tmp); }
static void *gl_glsl_init(void *data, const char *path) { unsigned i; struct shader_program_info shader_prog_info; bool shader_support = false; #ifdef GLSL_DEBUG char *error_string = NULL; #endif config_file_t *conf = NULL; const char *stock_vertex = NULL; const char *stock_fragment = NULL; glsl_shader_data_t *glsl = (glsl_shader_data_t*) calloc(1, sizeof(glsl_shader_data_t)); if (!glsl) return NULL; (void)shader_support; #ifndef HAVE_OPENGLES RARCH_LOG("[GLSL]: Checking GLSL shader support ...\n"); shader_support = glCreateProgram && glUseProgram && glCreateShader && glDeleteShader && glShaderSource && glCompileShader && glAttachShader && glDetachShader && glLinkProgram && glGetUniformLocation && glUniform1i && glUniform1f && glUniform2fv && glUniform4fv && glUniformMatrix4fv && glGetShaderiv && glGetShaderInfoLog && glGetProgramiv && glGetProgramInfoLog && glDeleteProgram && glGetAttachedShaders && glGetAttribLocation && glEnableVertexAttribArray && glDisableVertexAttribArray && glVertexAttribPointer && glGenBuffers && glBufferData && glDeleteBuffers && glBindBuffer; if (!shader_support) { RARCH_ERR("GLSL shaders aren't supported by your OpenGL driver.\n"); goto error; } #endif glsl->shader = (struct video_shader*)calloc(1, sizeof(*glsl->shader)); if (!glsl->shader) goto error; if (!string_is_empty(path)) { bool ret = false; const char *path_ext = path_get_extension(path); if (string_is_equal_fast(path_ext, "glslp", 5)) { conf = config_file_new(path); if (conf) { ret = video_shader_read_conf_cgp(conf, glsl->shader); glsl->shader->modern = true; } } else if (string_is_equal_fast(path_ext, "glsl", 4)) { strlcpy(glsl->shader->pass[0].source.path, path, sizeof(glsl->shader->pass[0].source.path)); glsl->shader->passes = 1; glsl->shader->modern = true; ret = true; } if (!ret) { RARCH_ERR("[GL]: Failed to parse GLSL shader.\n"); goto error; } } else { RARCH_WARN("[GL]: Stock GLSL shaders will be used.\n"); glsl->shader->passes = 1; glsl->shader->pass[0].source.string.vertex = strdup(glsl_core ? stock_vertex_core : stock_vertex_modern); glsl->shader->pass[0].source.string.fragment = strdup(glsl_core ? stock_fragment_core : stock_fragment_modern); glsl->shader->modern = true; } if (!string_is_empty(path)) video_shader_resolve_relative(glsl->shader, path); video_shader_resolve_parameters(conf, glsl->shader); if (conf) { config_file_free(conf); conf = NULL; } stock_vertex = (glsl->shader->modern) ? stock_vertex_modern : stock_vertex_legacy; stock_fragment = (glsl->shader->modern) ? stock_fragment_modern : stock_fragment_legacy; if (glsl_core) { stock_vertex = stock_vertex_core; stock_fragment = stock_fragment_core; } #ifdef HAVE_OPENGLES if (!glsl->shader->modern) { RARCH_ERR("[GL]: GLES context is used, but shader is not modern. Cannot use it.\n"); goto error; } #else if (glsl_core && !glsl->shader->modern) { RARCH_ERR("[GL]: GL core context is used, but shader is not core compatible. Cannot use it.\n"); goto error; } #endif /* Find all aliases we use in our GLSLP and add #defines for them so * that a shader can choose a fallback if we are not using a preset. */ *glsl->alias_define = '\0'; for (i = 0; i < glsl->shader->passes; i++) { if (*glsl->shader->pass[i].alias) { char define[128]; define[0] = '\0'; snprintf(define, sizeof(define), "#define %s_ALIAS\n", glsl->shader->pass[i].alias); strlcat(glsl->alias_define, define, sizeof(glsl->alias_define)); } } shader_prog_info.vertex = stock_vertex; shader_prog_info.fragment = stock_fragment; shader_prog_info.is_file = false; if (!gl_glsl_compile_program(glsl, 0, &glsl->prg[0], &shader_prog_info)) { RARCH_ERR("GLSL stock programs failed to compile.\n"); goto error; } if (!gl_glsl_compile_programs(glsl, &glsl->prg[1])) goto error; if (!gl_load_luts(glsl->shader, glsl->lut_textures)) { RARCH_ERR("[GL]: Failed to load LUTs.\n"); goto error; } for (i = 0; i <= glsl->shader->passes; i++) gl_glsl_find_uniforms(glsl, i, glsl->prg[i].id, &glsl->uniforms[i]); #ifdef GLSL_DEBUG if (!gl_check_error(&error_string)) { RARCH_ERR("%s\n", error_string); free(error_string); RARCH_WARN("Detected GL error in GLSL.\n"); } #endif if (glsl->shader->variables) { retro_ctx_memory_info_t mem_info; struct state_tracker_info info; mem_info.id = RETRO_MEMORY_SYSTEM_RAM; core_get_memory(&mem_info); info.wram = (uint8_t*)mem_info.data; info.info = glsl->shader->variable; info.info_elem = glsl->shader->variables; info.script = NULL; info.script_class = NULL; #ifdef HAVE_PYTHON info.script = glsl->shader->script; if (*glsl->shader->script_class) info.script_class= glsl->shader->script_class; #endif info.script_is_file = NULL; glsl->state_tracker = state_tracker_init(&info); if (!glsl->state_tracker) RARCH_WARN("Failed to init state tracker.\n"); } glsl->prg[glsl->shader->passes + 1] = glsl->prg[0]; glsl->uniforms[glsl->shader->passes + 1] = glsl->uniforms[0]; if (glsl->shader->modern) { shader_prog_info.vertex = glsl_core ? stock_vertex_core_blend : stock_vertex_modern_blend; shader_prog_info.fragment = glsl_core ? stock_fragment_core_blend : stock_fragment_modern_blend; shader_prog_info.is_file = false; gl_glsl_compile_program( glsl, VIDEO_SHADER_STOCK_BLEND, &glsl->prg[VIDEO_SHADER_STOCK_BLEND], &shader_prog_info ); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_STOCK_BLEND].id, &glsl->uniforms[VIDEO_SHADER_STOCK_BLEND]); } else { glsl->prg[VIDEO_SHADER_STOCK_BLEND] = glsl->prg[0]; glsl->uniforms[VIDEO_SHADER_STOCK_BLEND] = glsl->uniforms[0]; } #ifdef HAVE_SHADERPIPELINE #ifdef HAVE_OPENGLES if (gl_query_extension("GL_OES_standard_derivatives")) { shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_ribbon_modern : stock_vertex_xmb_ribbon_legacy; shader_prog_info.fragment = stock_fragment_xmb; } else { shader_prog_info.vertex = stock_vertex_xmb_ribbon_simple_legacy; shader_prog_info.fragment = stock_fragment_xmb_ribbon_simple; } #else shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_ribbon_modern : stock_vertex_xmb_ribbon_legacy; shader_prog_info.fragment = stock_fragment_xmb; #endif shader_prog_info.is_file = false; gl_glsl_compile_program( glsl, VIDEO_SHADER_MENU, &glsl->prg[VIDEO_SHADER_MENU], &shader_prog_info); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU].id, &glsl->uniforms[VIDEO_SHADER_MENU]); shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_simple_modern : stock_vertex_xmb_ribbon_simple_legacy; shader_prog_info.fragment = stock_fragment_xmb_ribbon_simple; gl_glsl_compile_program( glsl, VIDEO_SHADER_MENU_2, &glsl->prg[VIDEO_SHADER_MENU_2], &shader_prog_info); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_2].id, &glsl->uniforms[VIDEO_SHADER_MENU_2]); #if defined(HAVE_OPENGLES) shader_prog_info.vertex = stock_vertex_xmb_snow_modern; #else shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; #endif shader_prog_info.fragment = stock_fragment_xmb_simple_snow; gl_glsl_compile_program( glsl, VIDEO_SHADER_MENU_3, &glsl->prg[VIDEO_SHADER_MENU_3], &shader_prog_info); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_3].id, &glsl->uniforms[VIDEO_SHADER_MENU_3]); #if defined(HAVE_OPENGLES) shader_prog_info.vertex = stock_vertex_xmb_snow_modern; #else shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; #endif shader_prog_info.fragment = stock_fragment_xmb_snow; gl_glsl_compile_program( glsl, VIDEO_SHADER_MENU_4, &glsl->prg[VIDEO_SHADER_MENU_4], &shader_prog_info); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_4].id, &glsl->uniforms[VIDEO_SHADER_MENU_4]); #if defined(HAVE_OPENGLES) shader_prog_info.vertex = stock_vertex_xmb_snow_modern; #else shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; #endif shader_prog_info.fragment = stock_fragment_xmb_bokeh; gl_glsl_compile_program( glsl, VIDEO_SHADER_MENU_5, &glsl->prg[VIDEO_SHADER_MENU_5], &shader_prog_info); gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_5].id, &glsl->uniforms[VIDEO_SHADER_MENU_5]); #endif gl_glsl_reset_attrib(glsl); for (i = 0; i < GFX_MAX_SHADERS; i++) { glGenBuffers(1, &glsl->vbo[i].vbo_primary); glGenBuffers(1, &glsl->vbo[i].vbo_secondary); } return glsl; error: gl_glsl_destroy_resources(glsl); if (conf) config_file_free(conf); if (glsl) free(glsl); return NULL; }
static bool get_texture_image(const char *shader_path, xmlNodePtr ptr) { if (gl_teximage_cnt >= MAX_TEXTURES) { RARCH_WARN("Too many texture images. Ignoring ...\n"); return true; } bool linear = true; xmlChar *filename = xmlGetProp(ptr, (const xmlChar*)"file"); xmlChar *filter = xmlGetProp(ptr, (const xmlChar*)"filter"); xmlChar *id = xmlGetProp(ptr, (const xmlChar*)"id"); char *last = NULL; struct texture_image img; if (!id) { RARCH_ERR("Could not find ID in texture.\n"); goto error; } if (!filename) { RARCH_ERR("Could not find filename in texture.\n"); goto error; } if (filter && strcmp((const char*)filter, "nearest") == 0) linear = false; char tex_path[PATH_MAX]; strlcpy(tex_path, shader_path, sizeof(tex_path)); last = strrchr(tex_path, '/'); if (!last) last = strrchr(tex_path, '\\'); if (last) last[1] = '\0'; strlcat(tex_path, (const char*)filename, sizeof(tex_path)); RARCH_LOG("Loading texture image from: \"%s\" ...\n", tex_path); if (!texture_image_load(tex_path, &img)) { RARCH_ERR("Failed to load texture image from: \"%s\"\n", tex_path); goto error; } strlcpy(gl_teximage_uniforms[gl_teximage_cnt], (const char*)id, sizeof(gl_teximage_uniforms[0])); glGenTextures(1, &gl_teximage[gl_teximage_cnt]); pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1); glBindTexture(GL_TEXTURE_2D, gl_teximage[gl_teximage_cnt]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, BORDER_FUNC); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, BORDER_FUNC); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexImage2D(GL_TEXTURE_2D, 0, RARCH_GL_INTERNAL_FORMAT32, img.width, img.height, 0, RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img.pixels); pglActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); free(img.pixels); xmlFree(filename); xmlFree(id); if (filter) xmlFree(filter); gl_teximage_cnt++; return true; error: if (filename) xmlFree(filename); if (filter) xmlFree(filter); if (filter) xmlFree(id); return false; }
bool input_driver_ctl(enum rarch_input_ctl_state state, void *data) { static bool input_driver_block_hotkey = false; static bool input_driver_block_libretro_input = false; static bool input_driver_osk_enabled = false; static bool input_driver_keyboard_linefeed_enable = false; static bool input_driver_nonblock_state = false; static bool input_driver_flushing_input = false; static bool input_driver_data_own = false; switch (state) { case RARCH_INPUT_CTL_KEY_PRESSED: { unsigned *key = (unsigned*)data; if (key && current_input->key_pressed) return current_input->key_pressed(current_input_data, *key); } return false; case RARCH_INPUT_CTL_HAS_CAPABILITIES: if (!current_input->get_capabilities || !current_input_data) return false; break; case RARCH_INPUT_CTL_POLL: current_input->poll(current_input_data); break; case RARCH_INPUT_CTL_INIT: if (current_input) current_input_data = current_input->init(); if (!current_input_data) return false; break; case RARCH_INPUT_CTL_DEINIT: if (current_input && current_input->free) current_input->free(current_input_data); current_input_data = NULL; break; case RARCH_INPUT_CTL_DESTROY_DATA: current_input_data = NULL; break; case RARCH_INPUT_CTL_DESTROY: input_driver_block_hotkey = false; input_driver_block_libretro_input = false; input_driver_keyboard_linefeed_enable = false; input_driver_nonblock_state = false; input_driver_flushing_input = false; input_driver_data_own = false; memset(&input_driver_turbo_btns, 0, sizeof(turbo_buttons_t)); current_input = NULL; break; case RARCH_INPUT_CTL_GRAB_STDIN: if (!current_input->grab_stdin) return false; return current_input->grab_stdin(current_input_data); case RARCH_INPUT_CTL_KB_MAPPING_IS_BLOCKED: if (!current_input->keyboard_mapping_is_blocked) return false; return current_input->keyboard_mapping_is_blocked( current_input_data); case RARCH_INPUT_CTL_FIND_DRIVER: { int i; driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); drv.label = "input_driver"; drv.s = settings->input.driver; driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); i = drv.len; if (i >= 0) current_input = (const input_driver_t*) input_driver_find_handle(i); else { unsigned d; RARCH_ERR("Couldn't find any input driver named \"%s\"\n", settings->input.driver); RARCH_LOG_OUTPUT("Available input drivers are:\n"); for (d = 0; input_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", input_driver_find_ident(d)); RARCH_WARN("Going to default to first input driver...\n"); current_input = (const input_driver_t*) input_driver_find_handle(0); if (current_input) return true; retro_fail(1, "find_input_driver()"); return false; } } break; case RARCH_INPUT_CTL_SET_FLUSHING_INPUT: input_driver_flushing_input = true; break; case RARCH_INPUT_CTL_UNSET_FLUSHING_INPUT: input_driver_flushing_input = false; break; case RARCH_INPUT_CTL_IS_FLUSHING_INPUT: return input_driver_flushing_input; case RARCH_INPUT_CTL_SET_HOTKEY_BLOCK: input_driver_block_hotkey = true; break; case RARCH_INPUT_CTL_UNSET_HOTKEY_BLOCK: input_driver_block_hotkey = false; break; case RARCH_INPUT_CTL_IS_HOTKEY_BLOCKED: return input_driver_block_hotkey; case RARCH_INPUT_CTL_SET_LIBRETRO_INPUT_BLOCKED: input_driver_block_libretro_input = true; break; case RARCH_INPUT_CTL_UNSET_LIBRETRO_INPUT_BLOCKED: input_driver_block_libretro_input = false; break; case RARCH_INPUT_CTL_IS_LIBRETRO_INPUT_BLOCKED: return input_driver_block_libretro_input; case RARCH_INPUT_CTL_SET_NONBLOCK_STATE: input_driver_nonblock_state = true; break; case RARCH_INPUT_CTL_UNSET_NONBLOCK_STATE: input_driver_nonblock_state = false; break; case RARCH_INPUT_CTL_IS_NONBLOCK_STATE: return input_driver_nonblock_state; case RARCH_INPUT_CTL_SET_OWN_DRIVER: input_driver_data_own = true; break; case RARCH_INPUT_CTL_UNSET_OWN_DRIVER: input_driver_data_own = false; break; case RARCH_INPUT_CTL_OWNS_DRIVER: return input_driver_data_own; case RARCH_INPUT_CTL_SET_OSK_ENABLED: input_driver_osk_enabled = true; break; case RARCH_INPUT_CTL_UNSET_OSK_ENABLED: input_driver_osk_enabled = false; break; case RARCH_INPUT_CTL_IS_OSK_ENABLED: return input_driver_osk_enabled; case RARCH_INPUT_CTL_SET_KEYBOARD_LINEFEED_ENABLED: input_driver_keyboard_linefeed_enable = true; break; case RARCH_INPUT_CTL_UNSET_KEYBOARD_LINEFEED_ENABLED: input_driver_keyboard_linefeed_enable = false; break; case RARCH_INPUT_CTL_IS_KEYBOARD_LINEFEED_ENABLED: return input_driver_keyboard_linefeed_enable; case RARCH_INPUT_CTL_COMMAND_INIT: #ifdef HAVE_COMMAND input_driver_command_init(); #endif break; case RARCH_INPUT_CTL_COMMAND_DEINIT: #ifdef HAVE_COMMAND if (input_driver_command) rarch_cmd_free(input_driver_command); input_driver_command = NULL; #endif break; case RARCH_INPUT_CTL_REMOTE_DEINIT: #ifdef HAVE_NETWORK_GAMEPAD if (input_driver_remote) rarch_remote_free(input_driver_remote); input_driver_remote = NULL; #endif break; case RARCH_INPUT_CTL_REMOTE_INIT: #ifdef HAVE_NETWORK_GAMEPAD input_driver_remote_init(); #endif break; case RARCH_INPUT_CTL_NONE: default: break; } return true; }
bool wifi_driver_ctl(enum rarch_wifi_ctl_state state, void *data) { settings_t *settings = config_get_ptr(); switch (state) { case RARCH_WIFI_CTL_DESTROY: wifi_driver_active = false; wifi_driver_data_own = false; wifi_driver = NULL; wifi_data = NULL; break; case RARCH_WIFI_CTL_SET_OWN_DRIVER: wifi_driver_data_own = true; break; case RARCH_WIFI_CTL_UNSET_OWN_DRIVER: wifi_driver_data_own = false; break; case RARCH_WIFI_CTL_OWNS_DRIVER: return wifi_driver_data_own; case RARCH_WIFI_CTL_SET_ACTIVE: wifi_driver_active = true; break; case RARCH_WIFI_CTL_FIND_DRIVER: { int i; driver_ctx_info_t drv; drv.label = "wifi_driver"; drv.s = settings->wifi.driver; driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); i = drv.len; if (i >= 0) wifi_driver = (const wifi_driver_t*)wifi_driver_find_handle(i); else { unsigned d; RARCH_ERR("Couldn't find any wifi driver named \"%s\"\n", settings->wifi.driver); RARCH_LOG_OUTPUT("Available wifi drivers are:\n"); for (d = 0; wifi_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", wifi_driver_find_ident(d)); RARCH_WARN("Going to default to first wifi driver...\n"); wifi_driver = (const wifi_driver_t*)wifi_driver_find_handle(0); if (!wifi_driver) retroarch_fail(1, "find_wifi_driver()"); } } break; case RARCH_WIFI_CTL_UNSET_ACTIVE: wifi_driver_active = false; break; case RARCH_WIFI_CTL_IS_ACTIVE: return wifi_driver_active; case RARCH_WIFI_CTL_DEINIT: if (wifi_data && wifi_driver) { if (wifi_driver->free) wifi_driver->free(wifi_data); } wifi_data = NULL; break; case RARCH_WIFI_CTL_STOP: if ( wifi_driver && wifi_driver->stop && wifi_data) wifi_driver->stop(wifi_data); break; case RARCH_WIFI_CTL_START: if (wifi_driver && wifi_data && wifi_driver->start) { if (settings->wifi.allow) return wifi_driver->start(wifi_data); } return false; case RARCH_WIFI_CTL_SET_CB: { /*struct retro_wifi_callback *cb = (struct retro_wifi_callback*)data; wifi_cb = *cb;*/ } break; case RARCH_WIFI_CTL_INIT: /* Resource leaks will follow if wifi is initialized twice. */ if (wifi_data) return false; wifi_driver_ctl(RARCH_WIFI_CTL_FIND_DRIVER, NULL); wifi_data = wifi_driver->init(); if (!wifi_data) { RARCH_ERR("Failed to initialize wifi driver. Will continue without wifi.\n"); wifi_driver_ctl(RARCH_WIFI_CTL_UNSET_ACTIVE, NULL); } /*if (wifi_cb.initialized) wifi_cb.initialized();*/ break; default: break; } return false; }
/** * recording_init: * * Initializes recording. * * Returns: true (1) if successful, otherwise false (0). **/ bool recording_init(void) { char recording_file[PATH_MAX_LENGTH] = {0}; struct ffemu_params params = {0}; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); const struct retro_hw_render_callback *hw_render = (const struct retro_hw_render_callback*)video_driver_callback(); bool *recording_enabled = recording_is_enabled(); if (!*recording_enabled) return false; if (global->inited.core.type == CORE_TYPE_DUMMY) { RARCH_WARN("%s\n", msg_hash_to_str(MSG_USING_LIBRETRO_DUMMY_CORE_RECORDING_SKIPPED)); return false; } if (!settings->video.gpu_record && hw_render->context_type) { RARCH_WARN("%s.\n", msg_hash_to_str(MSG_HW_RENDERED_MUST_USE_POSTSHADED_RECORDING)); return false; } RARCH_LOG("%s: FPS: %.4f, Sample rate: %.4f\n", msg_hash_to_str(MSG_CUSTOM_TIMING_GIVEN), (float)av_info->timing.fps, (float)av_info->timing.sample_rate); strlcpy(recording_file, global->record.path, sizeof(recording_file)); if (global->record.use_output_dir) fill_pathname_join(recording_file, global->record.output_dir, global->record.path, sizeof(recording_file)); params.out_width = av_info->geometry.base_width; params.out_height = av_info->geometry.base_height; params.fb_width = av_info->geometry.max_width; params.fb_height = av_info->geometry.max_height; params.channels = 2; params.filename = recording_file; params.fps = av_info->timing.fps; params.samplerate = av_info->timing.sample_rate; params.pix_fmt = (video_driver_get_pixel_format() == RETRO_PIXEL_FORMAT_XRGB8888) ? FFEMU_PIX_ARGB8888 : FFEMU_PIX_RGB565; params.config = NULL; if (*global->record.config) params.config = global->record.config; if (video_driver_ctl(RARCH_DISPLAY_CTL_SUPPORTS_RECORDING, NULL)) { unsigned gpu_size; struct video_viewport vp = {0}; video_driver_viewport_info(&vp); if (!vp.width || !vp.height) { RARCH_ERR("Failed to get viewport information from video driver. " "Cannot start recording ...\n"); return false; } params.out_width = vp.width; params.out_height = vp.height; params.fb_width = next_pow2(vp.width); params.fb_height = next_pow2(vp.height); if (settings->video.force_aspect && (video_driver_get_aspect_ratio() > 0.0f)) params.aspect_ratio = video_driver_get_aspect_ratio(); else params.aspect_ratio = (float)vp.width / vp.height; params.pix_fmt = FFEMU_PIX_BGR24; global->record.gpu_width = vp.width; global->record.gpu_height = vp.height; RARCH_LOG("%s %u x %u\n", msg_hash_to_str(MSG_DETECTED_VIEWPORT_OF), vp.width, vp.height); gpu_size = vp.width * vp.height * 3; if (!video_driver_ctl(RARCH_DISPLAY_CTL_GPU_RECORD_INIT, &gpu_size)) return false; } else { if (global->record.width || global->record.height) { params.out_width = global->record.width; params.out_height = global->record.height; } if (settings->video.force_aspect && (video_driver_get_aspect_ratio() > 0.0f)) params.aspect_ratio = video_driver_get_aspect_ratio(); else params.aspect_ratio = (float)params.out_width / params.out_height; if (settings->video.post_filter_record && video_driver_ctl(RARCH_DISPLAY_CTL_FRAME_FILTER_ALIVE, NULL)) { unsigned max_width = 0; unsigned max_height = 0; params.pix_fmt = FFEMU_PIX_RGB565; if (video_driver_ctl(RARCH_DISPLAY_CTL_FRAME_FILTER_IS_32BIT, NULL)) params.pix_fmt = FFEMU_PIX_ARGB8888; rarch_softfilter_get_max_output_size( video_driver_frame_filter_get_ptr(), &max_width, &max_height); params.fb_width = next_pow2(max_width); params.fb_height = next_pow2(max_height); } } RARCH_LOG("%s %s @ %ux%u. (FB size: %ux%u pix_fmt: %u)\n", msg_hash_to_str(MSG_RECORDING_TO), global->record.path, params.out_width, params.out_height, params.fb_width, params.fb_height, (unsigned)params.pix_fmt); if (!record_driver_init_first(&recording_driver, &recording_data, ¶ms)) { RARCH_ERR("%s\n", msg_hash_to_str(MSG_FAILED_TO_START_RECORDING)); event_command(EVENT_CMD_GPU_RECORD_DEINIT); return false; } return true; }
static bool load_content_from_compressed_archive( struct string_list *temporary_content, struct retro_game_info *info, unsigned i, struct string_list* additional_path_allocs, bool need_fullpath, const char *path) { union string_list_elem_attr attributes; ssize_t new_path_len; char new_path[PATH_MAX_LENGTH]; char new_basedir[PATH_MAX_LENGTH]; bool ret = false; settings_t *settings = config_get_ptr(); rarch_system_info_t *sys_info= NULL; runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sys_info); if (sys_info && sys_info->info.block_extract) return true; if (!need_fullpath || !path_contains_compressed_file(path)) return true; RARCH_LOG("Compressed file in case of need_fullpath." " Now extracting to temporary directory.\n"); strlcpy(new_basedir, settings->cache_directory, sizeof(new_basedir)); if (string_is_empty(new_basedir) || !path_is_directory(new_basedir)) { RARCH_WARN("Tried extracting to cache directory, but " "cache directory was not set or found. " "Setting cache directory to directory " "derived by basename...\n"); fill_pathname_basedir(new_basedir, path, sizeof(new_basedir)); } attributes.i = 0; fill_pathname_join(new_path, new_basedir, path_basename(path), sizeof(new_path)); ret = content_file_compressed_read(path, NULL, new_path, &new_path_len); if (!ret || new_path_len < 0) { RARCH_ERR("%s \"%s\".\n", msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE), path); return false; } RARCH_LOG("New path is: [%s]\n", new_path); string_list_append(additional_path_allocs, new_path, attributes); info[i].path = additional_path_allocs->elems[additional_path_allocs->size -1 ].data; if (!string_list_append(temporary_content, new_path, attributes)) return false; return true; }
static bool gl_cg_load_preset(void *data, const char *path) { unsigned i; config_file_t *conf = NULL; cg_shader_data_t *cg_data = (cg_shader_data_t*)data; if (!gl_cg_load_stock(cg_data)) return false; RARCH_LOG("Loading Cg meta-shader: %s\n", path); conf = config_file_new(path); if (!conf) { RARCH_ERR("Failed to load preset.\n"); return false; } cg_data->shader = (struct video_shader*)calloc(1, sizeof(*cg_data->shader)); if (!cg_data->shader) { config_file_free(conf); return false; } if (!video_shader_read_conf_cgp(conf, cg_data->shader)) { RARCH_ERR("Failed to parse CGP file.\n"); config_file_free(conf); return false; } video_shader_resolve_relative(cg_data->shader, path); video_shader_resolve_parameters(conf, cg_data->shader); config_file_free(conf); if (cg_data->shader->passes > GFX_MAX_SHADERS - 3) { RARCH_WARN("Too many shaders ... Capping shader amount to %d.\n", GFX_MAX_SHADERS - 3); cg_data->shader->passes = GFX_MAX_SHADERS - 3; } for (i = 0; i < cg_data->shader->passes; i++) if (*cg_data->shader->pass[i].alias) snprintf(cg_data->cg_alias_define[i], sizeof(cg_data->cg_alias_define[i]), "-D%s_ALIAS", cg_data->shader->pass[i].alias); for (i = 0; i < cg_data->shader->passes; i++) { if (!gl_cg_load_shader(cg_data, i)) { RARCH_ERR("Failed to load shaders ...\n"); return false; } } if (!gl_load_luts(cg_data->shader, cg_data->lut_textures)) { RARCH_ERR("Failed to load lookup textures ...\n"); return false; } if (!gl_cg_load_imports(cg_data)) { RARCH_ERR("Failed to load imports ...\n"); return false; } return true; }
static void init_video_filter(enum retro_pixel_format colfmt) { unsigned width, height, pow2_x, pow2_y, maxsize; struct retro_game_geometry *geom = NULL; settings_t *settings = config_get_ptr(); struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); deinit_video_filter(); if (!*settings->video.softfilter_plugin) return; /* Deprecated format. Gets pre-converted. */ if (colfmt == RETRO_PIXEL_FORMAT_0RGB1555) colfmt = RETRO_PIXEL_FORMAT_RGB565; if (video_state.hw_render_callback.context_type) { RARCH_WARN("Cannot use CPU filters when hardware rendering is used.\n"); return; } geom = av_info ? (struct retro_game_geometry*)&av_info->geometry : NULL; width = geom->max_width; height = geom->max_height; video_state.filter.filter = rarch_softfilter_new( settings->video.softfilter_plugin, RARCH_SOFTFILTER_THREADS_AUTO, colfmt, width, height); if (!video_state.filter.filter) { RARCH_ERR("Failed to load filter.\n"); return; } rarch_softfilter_get_max_output_size(video_state.filter.filter, &width, &height); pow2_x = next_pow2(width); pow2_y = next_pow2(height); maxsize = max(pow2_x, pow2_y); video_state.filter.scale = maxsize / RARCH_SCALE_BASE; video_state.filter.out_rgb32 = rarch_softfilter_get_output_format( video_state.filter.filter) == RETRO_PIXEL_FORMAT_XRGB8888; video_state.filter.out_bpp = video_state.filter.out_rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); /* TODO: Aligned output. */ video_state.filter.buffer = malloc(width * height * video_state.filter.out_bpp); if (!video_state.filter.buffer) goto error; return; error: RARCH_ERR("Softfilter initialization failed.\n"); deinit_video_filter(); }