2016-12-01 17:13:36 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2016-2017 - Brad Parker
|
2016-12-01 17:13:36 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <caca.h>
|
|
|
|
|
2017-01-18 21:20:47 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2016-12-01 17:13:36 +00:00
|
|
|
#include "../../menu/menu_driver.h"
|
2017-01-18 21:20:47 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-01 17:13:36 +00:00
|
|
|
#include "../common/caca_common.h"
|
|
|
|
|
2017-01-19 16:20:42 +00:00
|
|
|
#include "../font_driver.h"
|
|
|
|
|
2017-01-18 21:20:47 +00:00
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../../verbosity.h"
|
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
static caca_canvas_t *caca_cv = NULL;
|
|
|
|
static caca_dither_t *caca_dither = NULL;
|
|
|
|
static caca_display_t *caca_display = NULL;
|
2016-12-01 17:13:36 +00:00
|
|
|
static unsigned char *caca_menu_frame = NULL;
|
2017-01-10 17:16:22 +00:00
|
|
|
static unsigned caca_menu_width = 0;
|
|
|
|
static unsigned caca_menu_height = 0;
|
|
|
|
static unsigned caca_menu_pitch = 0;
|
|
|
|
static unsigned caca_video_width = 0;
|
|
|
|
static unsigned caca_video_height = 0;
|
|
|
|
static unsigned caca_video_pitch = 0;
|
2017-01-21 22:41:20 +00:00
|
|
|
static bool caca_rgb32 = false;
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
static void caca_gfx_free(void *data);
|
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
static void caca_gfx_create(void)
|
2016-12-01 17:13:36 +00:00
|
|
|
{
|
|
|
|
caca_display = caca_create_display(NULL);
|
2017-04-24 10:25:07 +00:00
|
|
|
caca_cv = caca_get_canvas(caca_display);
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
if(!caca_video_width || !caca_video_height)
|
|
|
|
{
|
2017-04-24 10:25:07 +00:00
|
|
|
caca_video_width = caca_get_canvas_width(caca_cv);
|
2016-12-01 17:13:36 +00:00
|
|
|
caca_video_height = caca_get_canvas_height(caca_cv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caca_rgb32)
|
|
|
|
caca_dither = caca_create_dither(32, caca_video_width, caca_video_height, caca_video_pitch,
|
|
|
|
0x00ff0000, 0xff00, 0xff, 0x0);
|
|
|
|
else
|
|
|
|
caca_dither = caca_create_dither(16, caca_video_width, caca_video_height, caca_video_pitch,
|
|
|
|
0xf800, 0x7e0, 0x1f, 0x0);
|
2017-04-24 10:25:07 +00:00
|
|
|
|
|
|
|
video_driver_set_size(&caca_video_width, &caca_video_height);
|
2016-12-01 17:13:36 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 10:25:14 +00:00
|
|
|
static void *caca_gfx_init(const video_info_t *video,
|
2016-12-01 17:13:36 +00:00
|
|
|
const input_driver_t **input, void **input_data)
|
|
|
|
{
|
2017-01-10 17:16:22 +00:00
|
|
|
caca_t *caca = (caca_t*)calloc(1, sizeof(*caca));
|
2016-12-01 17:13:36 +00:00
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
caca->caca_cv = &caca_cv;
|
|
|
|
caca->caca_dither = &caca_dither;
|
|
|
|
caca->caca_display = &caca_display;
|
2016-12-01 17:13:36 +00:00
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
*input = NULL;
|
|
|
|
*input_data = NULL;
|
2016-12-01 17:13:36 +00:00
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
caca_video_width = video->width;
|
|
|
|
caca_video_height = video->height;
|
|
|
|
caca_rgb32 = video->rgb32;
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
if (video->rgb32)
|
|
|
|
caca_video_pitch = video->width * 4;
|
|
|
|
else
|
|
|
|
caca_video_pitch = video->width * 2;
|
|
|
|
|
|
|
|
caca_gfx_create();
|
|
|
|
|
|
|
|
if (!caca_cv || !caca_dither || !caca_display)
|
|
|
|
{
|
|
|
|
/* TODO: handle errors */
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
if (video->font_enable)
|
2017-08-05 01:51:14 +00:00
|
|
|
font_driver_init_osd(caca, false, video->is_threaded,
|
2017-04-29 14:52:52 +00:00
|
|
|
FONT_DRIVER_RENDER_CACA);
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
return caca;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_frame(void *data, const void *frame,
|
|
|
|
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
|
2017-01-18 16:41:27 +00:00
|
|
|
unsigned pitch, const char *msg, video_frame_info_t *video_info)
|
2016-12-01 17:13:36 +00:00
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
void *buffer = NULL;
|
|
|
|
const void *frame_to_copy = frame;
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
|
|
|
bool draw = true;
|
|
|
|
|
|
|
|
(void)data;
|
|
|
|
(void)frame;
|
|
|
|
(void)frame_width;
|
|
|
|
(void)frame_height;
|
|
|
|
(void)pitch;
|
|
|
|
(void)msg;
|
|
|
|
|
|
|
|
if (!frame || !frame_width || !frame_height)
|
|
|
|
return true;
|
|
|
|
|
2017-01-21 22:41:20 +00:00
|
|
|
if ( caca_video_width != frame_width ||
|
2017-01-10 17:16:22 +00:00
|
|
|
caca_video_height != frame_height ||
|
|
|
|
caca_video_pitch != pitch)
|
2016-12-01 17:13:36 +00:00
|
|
|
{
|
|
|
|
if (frame_width > 4 && frame_height > 4)
|
|
|
|
{
|
|
|
|
caca_video_width = frame_width;
|
|
|
|
caca_video_height = frame_height;
|
|
|
|
caca_video_pitch = pitch;
|
|
|
|
caca_gfx_free(NULL);
|
|
|
|
caca_gfx_create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!caca_cv)
|
|
|
|
return true;
|
|
|
|
|
2017-01-22 16:30:32 +00:00
|
|
|
if (caca_menu_frame && video_info->menu_is_alive)
|
2016-12-01 17:13:36 +00:00
|
|
|
frame_to_copy = caca_menu_frame;
|
|
|
|
|
|
|
|
width = caca_get_canvas_width(caca_cv);
|
|
|
|
height = caca_get_canvas_height(caca_cv);
|
|
|
|
|
2017-01-21 22:41:20 +00:00
|
|
|
if ( frame_to_copy == frame &&
|
|
|
|
frame_width == 4 &&
|
|
|
|
frame_height == 4 &&
|
2017-01-10 17:16:22 +00:00
|
|
|
(frame_width < width && frame_height < height))
|
2016-12-01 17:13:36 +00:00
|
|
|
draw = false;
|
|
|
|
|
2017-01-22 16:30:32 +00:00
|
|
|
if (video_info->menu_is_alive)
|
2017-01-21 20:39:29 +00:00
|
|
|
draw = false;
|
|
|
|
|
2016-12-01 17:13:36 +00:00
|
|
|
caca_clear_canvas(caca_cv);
|
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2017-01-18 20:23:18 +00:00
|
|
|
menu_driver_frame(video_info);
|
2016-12-01 17:13:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (msg)
|
2017-01-19 15:30:40 +00:00
|
|
|
font_driver_render_msg(video_info, NULL, msg, NULL);
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
if (draw)
|
|
|
|
{
|
|
|
|
caca_dither_bitmap(caca_cv, 0, 0,
|
2017-01-10 17:16:22 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
caca_dither, frame_to_copy);
|
2016-12-01 17:13:36 +00:00
|
|
|
|
|
|
|
buffer = caca_export_canvas_to_memory(caca_cv, "caca", &len);
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
if (len)
|
|
|
|
caca_refresh_display(caca_display);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void caca_gfx_set_nonblock_state(void *data, bool toggle)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_alive(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
video_driver_set_size(&caca_video_width, &caca_video_height);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_focus(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_has_windowed(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void caca_gfx_free(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
if (caca_display)
|
|
|
|
{
|
|
|
|
caca_free_display(caca_display);
|
|
|
|
caca_display = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caca_dither)
|
|
|
|
{
|
|
|
|
caca_free_dither(caca_dither);
|
|
|
|
caca_dither = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caca_menu_frame)
|
|
|
|
{
|
|
|
|
free(caca_menu_frame);
|
|
|
|
caca_menu_frame = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool caca_gfx_set_shader(void *data,
|
|
|
|
enum rarch_shader_type type, const char *path)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)type;
|
|
|
|
(void)path;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void caca_gfx_set_rotation(void *data,
|
|
|
|
unsigned rotation)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void caca_gfx_viewport_info(void *data,
|
|
|
|
struct video_viewport *vp)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)vp;
|
|
|
|
}
|
|
|
|
|
2017-01-22 17:17:48 +00:00
|
|
|
static bool caca_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle)
|
2016-12-01 17:13:36 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)buffer;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void caca_set_texture_frame(void *data,
|
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
unsigned pitch = width * 2;
|
|
|
|
|
|
|
|
if (rgb32)
|
|
|
|
pitch = width * 4;
|
|
|
|
|
|
|
|
if (caca_menu_frame)
|
|
|
|
{
|
|
|
|
free(caca_menu_frame);
|
|
|
|
caca_menu_frame = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-31 17:02:14 +00:00
|
|
|
if ( !caca_menu_frame ||
|
2017-01-21 22:41:20 +00:00
|
|
|
caca_menu_width != width ||
|
|
|
|
caca_menu_height != height ||
|
2017-01-10 17:16:22 +00:00
|
|
|
caca_menu_pitch != pitch)
|
2016-12-01 17:13:36 +00:00
|
|
|
if (pitch && height)
|
|
|
|
caca_menu_frame = (unsigned char*)malloc(pitch * height);
|
|
|
|
|
|
|
|
if (caca_menu_frame && frame && pitch && height)
|
|
|
|
memcpy(caca_menu_frame, frame, pitch * height);
|
|
|
|
}
|
|
|
|
|
2017-04-23 20:20:11 +00:00
|
|
|
static void caca_set_osd_msg(void *data,
|
|
|
|
video_frame_info_t *video_info,
|
|
|
|
const char *msg,
|
2017-01-19 15:30:40 +00:00
|
|
|
const void *params, void *font)
|
2016-12-01 17:13:36 +00:00
|
|
|
{
|
2017-04-23 20:20:11 +00:00
|
|
|
font_driver_render_msg(video_info, font, msg, params);
|
2016-12-01 17:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const video_poke_interface_t caca_poke_interface = {
|
2018-04-23 11:34:30 +00:00
|
|
|
NULL, /* get_flags */
|
2017-11-14 20:34:03 +00:00
|
|
|
NULL, /* set_coords */
|
|
|
|
NULL, /* set_mvp */
|
2016-12-01 17:13:36 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2018-04-15 16:12:56 +00:00
|
|
|
NULL,
|
2016-12-01 17:13:36 +00:00
|
|
|
caca_set_texture_frame,
|
|
|
|
NULL,
|
|
|
|
caca_set_osd_msg,
|
2018-01-30 21:29:57 +00:00
|
|
|
NULL, /* show_mouse */
|
|
|
|
NULL, /* grab_mouse_toggle */
|
|
|
|
NULL, /* get_current_shader */
|
|
|
|
NULL, /* get_current_software_framebuffer */
|
|
|
|
NULL, /* get_hw_render_interface */
|
2016-12-01 17:13:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void caca_gfx_get_poke_interface(void *data,
|
|
|
|
const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &caca_poke_interface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void caca_gfx_set_viewport(void *data, unsigned viewport_width,
|
|
|
|
unsigned viewport_height, bool force_full, bool allow_rotate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
video_driver_t video_caca = {
|
|
|
|
caca_gfx_init,
|
|
|
|
caca_gfx_frame,
|
|
|
|
caca_gfx_set_nonblock_state,
|
|
|
|
caca_gfx_alive,
|
|
|
|
caca_gfx_focus,
|
|
|
|
caca_gfx_suppress_screensaver,
|
|
|
|
caca_gfx_has_windowed,
|
|
|
|
caca_gfx_set_shader,
|
|
|
|
caca_gfx_free,
|
|
|
|
"caca",
|
|
|
|
caca_gfx_set_viewport,
|
|
|
|
caca_gfx_set_rotation,
|
|
|
|
caca_gfx_viewport_info,
|
|
|
|
caca_gfx_read_viewport,
|
|
|
|
NULL, /* read_frame_raw */
|
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
NULL, /* overlay_interface */
|
|
|
|
#endif
|
|
|
|
caca_gfx_get_poke_interface,
|
2018-07-12 20:55:08 +00:00
|
|
|
NULL /* wrap_type_to_enum */
|
2016-12-01 17:13:36 +00:00
|
|
|
};
|