static uintptr_t vita_load_texture(void *video_data, void *data, bool threaded, enum texture_filter_type filter_type) { unsigned int stride, pitch, j; 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); stride = vita2d_texture_get_stride(texture); stride /= 4; 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)); return (uintptr_t)texture; }
static bool vita_get_current_sw_framebuffer(void *data, struct retro_framebuffer *framebuffer) { vita_video_t *vita = (vita_video_t*)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; } 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); } framebuffer->data = vita2d_texture_get_datap(vita->texture); framebuffer->pitch = vita2d_texture_get_stride(vita->texture); framebuffer->format = vita->rgb32 ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565; framebuffer->memory_flags = 0; return true; }
static void vita_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { int i, j; void *tex_p; unsigned int stride; vita_video_t *vita = (vita_video_t*)data; (void)alpha; if (width != vita->menu.width && height != vita->menu.height && vita->menu.texture) { vita2d_free_texture(vita->menu.texture); vita->menu.texture = NULL; } if (!vita->menu.texture) { if (rgb32) { vita->menu.texture = vita2d_create_empty_texture(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.width = width; vita->menu.height = height; } 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); if (rgb32) { uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; stride /= 4; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex32[j + i*stride] = frame32[j + i*width]; } else { uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; stride /= 2; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex16[j + i*stride] = frame16[j + i*width]; } }
static void vita_set_filtering(void *data, unsigned index, bool smooth) { vita_video_t *vita = (vita_video_t *)data; 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); } }
static void *vita2d_font_init_font(void *gl_data, const char *font_path, float font_size) { unsigned int stride, pitch, j, k; const struct font_atlas *atlas = NULL; vita_font_t *font = (vita_font_t*)calloc(1, sizeof(*font)); if (!font) return NULL; if (!font_renderer_create_default((const void**)&font->font_driver, &font->font_data, font_path, font_size)) { RARCH_WARN("Couldn't initialize font renderer.\n"); free(font); return NULL; } atlas = font->font_driver->get_atlas(font->font_data); font->texture = vita2d_create_empty_texture_format(atlas->width,atlas->height,SCE_GXM_TEXTURE_FORMAT_U8_R111); if (!font->texture) { free(font); return NULL; } vita2d_texture_set_filters(font->texture, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_LINEAR); stride = vita2d_texture_get_stride(font->texture); uint8_t *tex32 = vita2d_texture_get_datap(font->texture); const uint8_t *frame32 = atlas->buffer; pitch = atlas->width; for (j = 0; j < atlas->height; j++) for (k = 0; k < atlas->width; k++) tex32[k + j*stride] = frame32[k + j*pitch]; return font; }
static bool vita2d_overlay_load(void *data, const void *image_data, unsigned num_images) { unsigned i,j,k; unsigned int stride, pitch; vita_video_t *vita = (vita_video_t*)data; const struct texture_image *images = (const struct texture_image*)image_data; vita2d_free_overlay(vita); vita->overlay = (struct vita_overlay_data*)calloc(num_images, sizeof(*vita->overlay)); if (!vita->overlay) return false; vita->overlays = num_images; for (i = 0; i < num_images; i++) { struct vita_overlay_data *o = (struct vita_overlay_data*)&vita->overlay[i]; o->width = images[i].width; o->height = images[i].height; o->tex = vita2d_create_empty_texture_format(o->width , o->height, SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB); vita2d_texture_set_filters(o->tex,SCE_GXM_TEXTURE_FILTER_LINEAR,SCE_GXM_TEXTURE_FILTER_LINEAR); stride = vita2d_texture_get_stride(o->tex); stride /= 4; uint32_t *tex32 = vita2d_texture_get_datap(o->tex); const uint32_t *frame32 = images[i].pixels; pitch = o->width; for (j = 0; j < o->height; j++) for (k = 0; k < o->width; k++) tex32[k + j*stride] = frame32[k + j*pitch]; vita2d_overlay_tex_geom(vita, i, 0, 0, 1, 1); /* Default. Stretch to whole screen. */ vita2d_overlay_vertex_geom(vita, i, 0, 0, 1, 1); vita->overlay[i].alpha_mod = 1.0f; } return true; }
static bool vita2d_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { void *tex_p; vita_video_t *vita = (vita_video_t *)data; if (frame) { if(!(vita->texture&&vita2d_texture_get_datap(vita->texture)==frame)) { unsigned i; unsigned int stride; if ((width != vita->width || height != vita->height) && vita->texture) { vita2d_free_texture(vita->texture); vita->texture = NULL; } if (!vita->texture) { RARCH_LOG("Creating texture: %ix%i\n", width, height); vita->width = width; vita->height = height; vita->texture = vita2d_create_empty_texture_format(width, height, vita->format); vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); } tex_p = vita2d_texture_get_datap(vita->texture); stride = vita2d_texture_get_stride(vita->texture); if (vita->format == SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1RGB) { stride /= 4; pitch /= 4; uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; for (i = 0; i < height; i++) memcpy_neon(&tex32[i*stride],&frame32[i*pitch],pitch*sizeof(uint32_t)); } else { stride /= 2; pitch /= 2; uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; for (i = 0; i < height; i++) memcpy_neon(&tex16[i*stride],&frame16[i*pitch],width*sizeof(uint16_t)); } } } if (vita->should_resize) vita2d_gfx_update_viewport(vita); vita2d_start_drawing(); vita2d_draw_rectangle(0,0,PSP_FB_WIDTH,PSP_FB_HEIGHT,vita2d_get_clear_color()); if (vita->texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->texture, 0, 0, PSP_FB_WIDTH / (float)vita->width, PSP_FB_HEIGHT / (float)vita->height); else { const float radian = 90 * 0.0174532925f; const float rad = vita->rotation * radian; float scalex = vita->vp.width / (float)vita->width; float scaley = vita->vp.height / (float)vita->height; vita2d_draw_texture_scale_rotate(vita->texture,vita->vp.x, vita->vp.y, scalex, scaley, rad); } } #ifdef HAVE_OVERLAY if (vita->overlay_enable) vita2d_render_overlay(vita); #endif if (vita->menu.active) { #ifdef HAVE_MENU menu_driver_frame(video_info); #endif if(vita->menu.texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->menu.texture, 0, 0, PSP_FB_WIDTH / (float)vita->menu.width, PSP_FB_HEIGHT / (float)vita->menu.height); else { if (vita->menu.width > vita->menu.height) { float scale = PSP_FB_HEIGHT / (float)vita->menu.height; float w = vita->menu.width * scale; vita2d_draw_texture_scale(vita->menu.texture, PSP_FB_WIDTH / 2.0f - w/2.0f, 0.0f, scale, scale); } else { float scale = PSP_FB_WIDTH / (float)vita->menu.width; float h = vita->menu.height * scale; vita2d_draw_texture_scale(vita->menu.texture, 0.0f, PSP_FB_HEIGHT / 2.0f - h/2.0f, scale, scale); } } } } if(!string_is_empty(msg)) font_driver_render_msg(video_info, NULL, msg, NULL); vita2d_end_drawing(); vita2d_swap_buffers(); return true; }
static bool vita2d_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char *msg) { int i, j; void *tex_p; unsigned int stride; vita_video_t *vita = (vita_video_t *)data; (void)frame; (void)width; (void)height; (void)pitch; (void)msg; if (frame) { if ((width != vita->width || height != vita->height) && vita->texture) { vita2d_free_texture(vita->texture); vita->texture = NULL; } if (!vita->texture) { RARCH_LOG("Creating texture: %ix%i\n", width, height); vita->width = width; vita->height = height; vita->texture = vita2d_create_empty_texture_format(width, height, vita->format); vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); } tex_p = vita2d_texture_get_datap(vita->texture); stride = vita2d_texture_get_stride(vita->texture); if (vita->format == SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1RGB) { stride /= 4; pitch /= 4; uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex32[j + i*stride] = frame32[j + i*pitch]; } else { stride /= 2; pitch /= 2; uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex16[j + i*stride] = frame16[j + i*pitch]; } } if (vita->should_resize) vita2d_gfx_update_viewport(vita); vita2d_start_drawing(); vita2d_clear_screen(); if (vita->texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->texture, 0, 0, PSP_FB_WIDTH / (float)vita->width, PSP_FB_HEIGHT / (float)vita->height); else { const float radian = 90 * 0.0174532925f; const float rad = vita->rotation * radian; float scalex = vita->vp.width / (float)vita->width; float scaley = vita->vp.height / (float)vita->height; vita2d_draw_texture_scale_rotate(vita->texture, vita->vp.x, vita->vp.y, scalex, scaley, rad); } } if (vita->menu.active && vita->menu.texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->menu.texture, 0, 0, PSP_FB_WIDTH / (float)vita->menu.width, PSP_FB_HEIGHT / (float)vita->menu.height); else { if (vita->menu.width > vita->menu.height) { float scale = PSP_FB_HEIGHT / (float)vita->menu.height; float w = vita->menu.width * scale; vita2d_draw_texture_scale(vita->menu.texture, PSP_FB_WIDTH / 2.0f - w/2.0f, 0.0f, scale, scale); } else { float scale = PSP_FB_WIDTH / (float)vita->menu.width; float h = vita->menu.height * scale; vita2d_draw_texture_scale(vita->menu.texture, 0.0f, PSP_FB_HEIGHT / 2.0f - h/2.0f, scale, scale); } } } vita2d_end_drawing(); vita2d_swap_buffers(); return true; }