From 3a4963b4749d4988f55c6d3220b883b249e4395a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 24 Jan 2017 14:08:28 +0100 Subject: [PATCH] (vita2d_gfx.c) Cleanups --- gfx/drivers/vita2d_gfx.c | 118 ++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 46 deletions(-) diff --git a/gfx/drivers/vita2d_gfx.c b/gfx/drivers/vita2d_gfx.c index 07ba4550c5..00d648f8eb 100644 --- a/gfx/drivers/vita2d_gfx.c +++ b/gfx/drivers/vita2d_gfx.c @@ -221,7 +221,8 @@ static bool vita2d_gfx_frame(void *data, const void *frame, menu_driver_frame(video_info); #endif - if(vita->menu.texture){ + if(vita->menu.texture) + { if (vita->fullscreen) vita2d_draw_texture_scale(vita->menu.texture, 0, 0, @@ -363,12 +364,13 @@ static void vita2d_gfx_update_viewport(vita_video_t* vita) else if (vita->keep_aspect) { float desired_aspect = video_driver_get_aspect_ratio(); - if (vita->rotation == ORIENTATION_VERTICAL || - vita->rotation == ORIENTATION_FLIPPED_ROTATED){ - device_aspect = 1.0 / device_aspect; - width = PSP_FB_HEIGHT; - height = PSP_FB_WIDTH; - } + if ( (vita->rotation == ORIENTATION_VERTICAL ||) + (vita->rotation == ORIENTATION_FLIPPED_ROTATED)) + { + device_aspect = 1.0 / device_aspect; + width = PSP_FB_HEIGHT; + height = PSP_FB_WIDTH; + } #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { @@ -409,11 +411,13 @@ static void vita2d_gfx_update_viewport(vita_video_t* vita) height = (unsigned)roundf(2.0f * height * delta); } - if (vita->rotation == ORIENTATION_VERTICAL || - vita->rotation == ORIENTATION_FLIPPED_ROTATED){ - x = (PSP_FB_WIDTH - width) * 0.5f; - y = (PSP_FB_HEIGHT - height) * 0.5f; - } + if ( (vita->rotation == ORIENTATION_VERTICAL) || + (vita->rotation == ORIENTATION_FLIPPED_ROTATED) + ) + { + x = (PSP_FB_WIDTH - width) * 0.5f; + y = (PSP_FB_HEIGHT - height) * 0.5f; + } } vita->vp.x = x; @@ -440,12 +444,12 @@ static void vita2d_gfx_set_viewport(void *data, unsigned viewport_width, { gfx_ctx_aspect_t aspect_data; unsigned width, height; - int x = 0; - int y = 0; - float device_aspect = (float)viewport_width / viewport_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; + settings_t *settings = config_get_ptr(); + vita_video_t *vita = (vita_video_t*)data; video_driver_get_size(&width, &height); @@ -528,15 +532,16 @@ static void vita2d_gfx_set_viewport(void *data, unsigned viewport_width, vita->vp.height = viewport_height; } - /*vita->vp.x = (float)vita->vp.x; +#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;*/ + vita->vp.maxDepth = 1.0f; - - //RARCH_LOG("Setting viewport @ %ux%u\n", viewport_width, viewport_height); + RARCH_LOG("Setting viewport @ %ux%u\n", viewport_width, viewport_height); +#endif } static void vita2d_gfx_set_rotation(void *data, @@ -574,8 +579,10 @@ static void vita_set_filtering(void *data, unsigned index, bool smooth) if (vita) { - vita->tex_filter = smooth? SCE_GXM_TEXTURE_FILTER_LINEAR : SCE_GXM_TEXTURE_FILTER_POINT; - vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); + vita->tex_filter = smooth ? + SCE_GXM_TEXTURE_FILTER_LINEAR : SCE_GXM_TEXTURE_FILTER_POINT; + vita2d_texture_set_filters(vita->texture,vita->tex_filter, + vita->tex_filter); } } @@ -601,7 +608,9 @@ static void vita_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) break; } - video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); + video_driver_set_aspect_ratio_value( + aspectratio_lut[aspect_ratio_idx].value); + if (!vita) return; vita->keep_aspect = true; @@ -637,18 +646,23 @@ static void vita_set_texture_frame(void *data, const void *frame, bool rgb32, if (rgb32) { vita->menu.texture = vita2d_create_empty_texture(width, height); - RARCH_LOG("Creating Frame RGBA8 texture: w: %i h: %i\n", width, height); + RARCH_LOG("Creating Frame RGBA8 texture: w: %i h: %i\n", + width, height); } else { - vita->menu.texture = vita2d_create_empty_texture_format(width, height, SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_RGBA); - RARCH_LOG("Creating Frame R5G6B5 texture: w: %i h: %i\n", width, height); + vita->menu.texture = vita2d_create_empty_texture_format( + width, height, SCE_GXM_TEXTURE_FORMAT_U4U4U4U4_RGBA); + RARCH_LOG("Creating Frame R5G6B5 texture: w: %i h: %i\n", + width, height); } vita->menu.width = width; vita->menu.height = height; } - vita2d_texture_set_filters(vita->menu.texture,SCE_GXM_TEXTURE_FILTER_LINEAR,SCE_GXM_TEXTURE_FILTER_LINEAR); + vita2d_texture_set_filters(vita->menu.texture, + SCE_GXM_TEXTURE_FILTER_LINEAR, + SCE_GXM_TEXTURE_FILTER_LINEAR); tex_p = vita2d_texture_get_datap(vita->menu.texture); stride = vita2d_texture_get_stride(vita->menu.texture); @@ -689,30 +703,40 @@ static uintptr_t vita_load_texture(void *video_data, void *data, bool threaded, enum texture_filter_type filter_type) { unsigned int stride, pitch, j; - struct texture_image *image = (struct texture_image*)data; + uint32_t *tex32 = NULL; + const uint32_t *frame32 = NULL; + struct texture_image *image = (struct texture_image*)data; struct vita2d_texture *texture = vita2d_create_empty_texture_format(image->width, image->height,SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB); + if (!texture) return 0; - if(filter_type == TEXTURE_FILTER_MIPMAP_LINEAR || - filter_type == TEXTURE_FILTER_LINEAR) - vita2d_texture_set_filters(texture,SCE_GXM_TEXTURE_FILTER_LINEAR,SCE_GXM_TEXTURE_FILTER_LINEAR); + if ((filter_type == TEXTURE_FILTER_MIPMAP_LINEAR) || + (filter_type == TEXTURE_FILTER_LINEAR)) + vita2d_texture_set_filters(texture, + SCE_GXM_TEXTURE_FILTER_LINEAR, + SCE_GXM_TEXTURE_FILTER_LINEAR); - stride = vita2d_texture_get_stride(texture); + stride = vita2d_texture_get_stride(texture); stride /= 4; - uint32_t *tex32 = vita2d_texture_get_datap(texture); - const uint32_t *frame32 = image->pixels; - pitch = image->width; + + tex32 = vita2d_texture_get_datap(texture); + frame32 = image->pixels; + pitch = image->width; + for (j = 0; j < image->height; j++) - memcpy_neon(&tex32[j*stride],&frame32[j*pitch],pitch*sizeof(uint32_t)); + memcpy_neon( + &tex32[j*stride], + &frame32[j*pitch], + pitch * sizeof(uint32_t)); return (uintptr_t)texture; } static void vita_unload_texture(void *data, uintptr_t handle) { - struct vita2d_texture *texture = (struct vita2d_texture*)handle; + struct vita2d_texture *texture = (struct vita2d_texture*)handle; if (!texture) return; @@ -740,17 +764,19 @@ static bool vita_get_current_sw_framebuffer(void *data, if (!vita->texture || vita->width != framebuffer->width || vita->height != framebuffer->height) { - if(vita->texture){ - vita2d_wait_rendering_done(); - vita2d_free_texture(vita->texture); - vita->texture = NULL; + if(vita->texture) + { + vita2d_wait_rendering_done(); + vita2d_free_texture(vita->texture); + vita->texture = NULL; } - + vita->width = framebuffer->width; vita->height = framebuffer->height; - vita->texture = vita2d_create_empty_texture_format(vita->width, vita->height, vita->format); - vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); - + vita->texture = vita2d_create_empty_texture_format( + vita->width, vita->height, vita->format); + vita2d_texture_set_filters(vita->texture, + vita->tex_filter,vita->tex_filter); } framebuffer->data = vita2d_texture_get_datap(vita->texture);