static void d3d_calculate_rect(void *data, unsigned *width, unsigned *height, int *x, int *y, bool force_full, bool allow_rotate) { gfx_ctx_aspect_t aspect_data; float device_aspect = (float)*width / *height; d3d_video_t *d3d = (d3d_video_t*)data; settings_t *settings = config_get_ptr(); video_driver_get_size(width, height); aspect_data.aspect = &device_aspect; aspect_data.width = *width; aspect_data.height = *height; video_context_driver_translate_aspect(&aspect_data); *x = 0; *y = 0; if (settings->video.scale_integer && !force_full) { struct video_viewport vp = {0}; video_viewport_get_scaled_integer(&vp, *width, *height, video_driver_get_aspect_ratio(), d3d->keep_aspect); *x = vp.x; *y = vp.y; *width = vp.width; *height = vp.height; } else if (d3d->keep_aspect && !force_full) { float desired_aspect = video_driver_get_aspect_ratio(); #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { video_viewport_t *custom = video_viewport_get_custom(); if (custom) { *x = custom->x; *y = custom->y; *width = custom->width; *height = custom->height; } } else #endif { float delta; if (fabsf(device_aspect - desired_aspect) < 0.0001f) { /* If the aspect ratios of screen and desired aspect * ratio are sufficiently equal (floating point stuff), * assume they are actually equal. */ } else if (device_aspect > desired_aspect) { delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f; *x = int(roundf(*width * (0.5f - delta))); *width = unsigned(roundf(2.0f * (*width) * delta)); } else { delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f; *y = int(roundf(*height * (0.5f - delta))); *height = unsigned(roundf(2.0f * (*height) * delta)); } } } }
static void vita2d_gfx_set_viewport(void *data, unsigned viewport_width, unsigned viewport_height, bool force_full, bool allow_rotate) { gfx_ctx_aspect_t aspect_data; unsigned width, height; int x = 0; int y = 0; float device_aspect = (float)viewport_width / viewport_height; struct video_ortho ortho = {0, 1, 1, 0, -1, 1}; settings_t *settings = config_get_ptr(); vita_video_t *vita = (vita_video_t*)data; video_driver_get_size(&width, &height); aspect_data.aspect = &device_aspect; aspect_data.width = viewport_width; aspect_data.height = viewport_height; video_context_driver_translate_aspect(&aspect_data); if (settings->video.scale_integer && !force_full) { video_viewport_get_scaled_integer(&vita->vp, viewport_width, viewport_height, video_driver_get_aspect_ratio(), vita->keep_aspect); viewport_width = vita->vp.width; viewport_height = vita->vp.height; } else if (vita->keep_aspect && !force_full) { float desired_aspect = video_driver_get_aspect_ratio(); #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { const struct video_viewport *custom = video_viewport_get_custom(); /* Vukan has top-left origin viewport. */ x = custom->x; y = custom->y; viewport_width = custom->width; viewport_height = custom->height; } else #endif { float delta; if (fabsf(device_aspect - desired_aspect) < 0.0001f) { /* If the aspect ratios of screen and desired aspect * ratio are sufficiently equal (floating point stuff), * assume they are actually equal. */ } else if (device_aspect > desired_aspect) { delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f; x = (int)roundf(viewport_width * (0.5f - delta)); viewport_width = (unsigned)roundf(2.0f * viewport_width * delta); } else { delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f; y = (int)roundf(viewport_height * (0.5f - delta)); viewport_height = (unsigned)roundf(2.0f * viewport_height * delta); } } vita->vp.x = x; vita->vp.y = y; vita->vp.width = viewport_width; vita->vp.height = viewport_height; } else { vita->vp.x = 0; vita->vp.y = 0; vita->vp.width = viewport_width; vita->vp.height = viewport_height; } vita2d_set_projection(vita, &ortho, allow_rotate); /* Set last backbuffer viewport. */ if (!force_full) { vita->vp.width = viewport_width; vita->vp.height = viewport_height; } #if 0 vita->vp.x = (float)vita->vp.x; vita->vp.y = (float)vita->vp.y; vita->vp.width = (float)vita->vp.width; vita->vp.height = (float)vita->vp.height; vita->vp.minDepth = 0.0f; vita->vp.maxDepth = 1.0f; RARCH_LOG("Setting viewport @ %ux%u\n", viewport_width, viewport_height); #endif }
void gl1_gfx_set_viewport(gl1_t *gl1, video_frame_info_t *video_info, unsigned viewport_width, unsigned viewport_height, bool force_full, bool allow_rotate) { gfx_ctx_aspect_t aspect_data; int x = 0; int y = 0; float device_aspect = (float)viewport_width / viewport_height; unsigned height = video_info->height; aspect_data.aspect = &device_aspect; aspect_data.width = viewport_width; aspect_data.height = viewport_height; video_context_driver_translate_aspect(&aspect_data); if (video_info->scale_integer && !force_full) { video_viewport_get_scaled_integer(&gl1->vp, viewport_width, viewport_height, video_driver_get_aspect_ratio(), gl1->keep_aspect); viewport_width = gl1->vp.width; viewport_height = gl1->vp.height; } else if (gl1->keep_aspect && !force_full) { float desired_aspect = video_driver_get_aspect_ratio(); #if defined(HAVE_MENU) if (video_info->aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { /* GL has bottom-left origin viewport. */ x = video_info->custom_vp_x; y = height - video_info->custom_vp_y - video_info->custom_vp_height; viewport_width = video_info->custom_vp_width; viewport_height = video_info->custom_vp_height; } else #endif { float delta; if (fabsf(device_aspect - desired_aspect) < 0.0001f) { /* If the aspect ratios of screen and desired aspect * ratio are sufficiently equal (floating point stuff), * assume they are actually equal. */ } else if (device_aspect > desired_aspect) { delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f; x = (int)roundf(viewport_width * (0.5f - delta)); viewport_width = (unsigned)roundf(2.0f * viewport_width * delta); } else { delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f; y = (int)roundf(viewport_height * (0.5f - delta)); viewport_height = (unsigned)roundf(2.0f * viewport_height * delta); } } gl1->vp.x = x; gl1->vp.y = y; gl1->vp.width = viewport_width; gl1->vp.height = viewport_height; } else { gl1->vp.x = gl1->vp.y = 0; gl1->vp.width = viewport_width; gl1->vp.height = viewport_height; } #if defined(RARCH_MOBILE) /* In portrait mode, we want viewport to gravitate to top of screen. */ if (device_aspect < 1.0f) gl1->vp.y *= 2; #endif glViewport(gl1->vp.x, gl1->vp.y, gl1->vp.width, gl1->vp.height); gl1_set_projection(gl1, &gl1_default_ortho, allow_rotate); /* Set last backbuffer viewport. */ if (!force_full) { gl1->vp_out_width = viewport_width; gl1->vp_out_height = viewport_height; } #if 0 RARCH_LOG("Setting viewport @ %ux%u\n", viewport_width, viewport_height); #endif }