static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font_size) { #ifdef HAVE_FREETYPE if (!g_settings.video.font_enable) return; const char *path = font_path; if (!*path) path = font_renderer_get_default_font(); if (path) { vid->font = font_renderer_new(path, font_size); if (vid->font) { int r = g_settings.video.msg_color_r * 255; int g = g_settings.video.msg_color_g * 255; int b = g_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); // RGB888 -> RGB555 if (!vid->render32) { r >>= 3; g >>= 3; b >>= 3; } vid->font_r = r; vid->font_g = g; vid->font_b = b; }
//////////////// Message rendering static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { #ifdef HAVE_FREETYPE if (!g_settings.video.font_enable) return; const char *path = font_path; if (!*path) path = font_renderer_get_default_font(); if (path) { gl->font = font_renderer_new(path, font_size); if (gl->font) { glGenTextures(1, &gl->font_tex); glBindTexture(GL_TEXTURE_2D, gl->font_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } else RARCH_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); } else RARCH_LOG("Did not find default font.\n"); for (unsigned i = 0; i < 4; i++) { gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; gl->font_color[4 * i + 3] = 1.0; } for (unsigned i = 0; i < 4; i++) { for (unsigned j = 0; j < 3; j++) gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j]; gl->font_color_dark[4 * i + 3] = 1.0; } #else (void)gl; (void)font_path; (void)font_size; #endif }
static void *rpi_init(const video_info_t *video, const input_driver_t **input, void **input_data) { int32_t success; EGLBoolean result; EGLint num_config; rpi_t *rpi = (rpi_t*)calloc(1, sizeof(rpi_t)); *input = NULL; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; DISPMANX_MODEINFO_T dispman_modeinfo; VC_RECT_T dst_rect; VC_RECT_T src_rect; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; bcm_host_init(); // get an EGL display connection rpi->mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); rarch_assert(rpi->mDisplay != EGL_NO_DISPLAY); // initialize the EGL display connection result = eglInitialize(rpi->mDisplay, NULL, NULL); rarch_assert(result != EGL_FALSE); eglBindAPI(EGL_OPENVG_API); // get an appropriate EGL frame buffer configuration result = eglChooseConfig(rpi->mDisplay, attribute_list, &config, 1, &num_config); rarch_assert(result != EGL_FALSE); // create an EGL rendering context rpi->mContext = eglCreateContext(rpi->mDisplay, config, EGL_NO_CONTEXT, NULL); rarch_assert(rpi->mContext != EGL_NO_CONTEXT); // create an EGL window surface success = graphics_get_display_size(0 /* LCD */, &rpi->mScreenWidth, &rpi->mScreenHeight); rarch_assert(success >= 0); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = rpi->mScreenWidth; dst_rect.height = rpi->mScreenHeight; src_rect.x = 0; src_rect.y = 0; src_rect.width = rpi->mScreenWidth << 16; src_rect.height = rpi->mScreenHeight << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */); vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo); dispman_update = vc_dispmanx_update_start(0); dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0 /*layer*/, &dst_rect, 0 /*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0 /*clamp*/, DISPMANX_NO_ROTATE); nativewindow.element = dispman_element; nativewindow.width = rpi->mScreenWidth; nativewindow.height = rpi->mScreenHeight; vc_dispmanx_update_submit_sync(dispman_update); rpi->mSurface = eglCreateWindowSurface(rpi->mDisplay, config, &nativewindow, NULL); rarch_assert(rpi->mSurface != EGL_NO_SURFACE); // connect the context to the surface result = eglMakeCurrent(rpi->mDisplay, rpi->mSurface, rpi->mSurface, rpi->mContext); rarch_assert(result != EGL_FALSE); rpi->mTexType = video->rgb32 ? VG_sABGR_8888 : VG_sARGB_1555; rpi->mKeepAspect = video->force_aspect; // check for SD televisions: they should always be 4:3 if (dispman_modeinfo.width == 720 && (dispman_modeinfo.height == 480 || dispman_modeinfo.height == 576)) rpi->mScreenAspect = 4.0f / 3.0f; else rpi->mScreenAspect = (float)dispman_modeinfo.width / dispman_modeinfo.height; VGfloat clearColor[4] = {0, 0, 0, 1}; vgSetfv(VG_CLEAR_COLOR, 4, clearColor); rpi->mTextureWidth = rpi->mTextureHeight = video->input_scale * RARCH_SCALE_BASE; // We can't use the native format because there's no sXRGB_1555 type and // emulation cores can send 0 in the top bit. We lose some speed on // conversion but I doubt it has any real affect, since we are only drawing // one image at the end of the day. Still keep the alpha channel for ABGR. rpi->mImage = vgCreateImage(video->rgb32 ? VG_sABGR_8888 : VG_sXBGR_8888, rpi->mTextureWidth, rpi->mTextureHeight, video->smooth ? VG_IMAGE_QUALITY_BETTER : VG_IMAGE_QUALITY_NONANTIALIASED); rpi_set_nonblock_state(rpi, !video->vsync); linuxraw_input_t *linuxraw_input = (linuxraw_input_t*)input_linuxraw.init(); if (linuxraw_input) { *input = (const input_driver_t *)&input_linuxraw; *input_data = linuxraw_input; } #ifdef HAVE_FREETYPE if (g_settings.video.font_enable) { rpi->mFont = vgCreateFont(0); rpi->mFontHeight = g_settings.video.font_size * (g_settings.video.font_scale ? (float) rpi->mScreenWidth / 1280.0f : 1.0f); const char *path = g_settings.video.font_path; if (!*path || !path_file_exists(path)) path = font_renderer_get_default_font(); rpi->mFontRenderer = font_renderer_new(path, rpi->mFontHeight); if (rpi->mFont != VG_INVALID_HANDLE && rpi->mFontRenderer) { rpi->mFontsOn = true; rpi->mPaintFg = vgCreatePaint(); rpi->mPaintBg = vgCreatePaint(); VGfloat paintFg[] = { g_settings.video.msg_color_r, g_settings.video.msg_color_g, g_settings.video.msg_color_b, 1.0f }; VGfloat paintBg[] = { g_settings.video.msg_color_r / 2.0f, g_settings.video.msg_color_g / 2.0f, g_settings.video.msg_color_b / 2.0f, 0.5f }; vgSetParameteri(rpi->mPaintFg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetParameterfv(rpi->mPaintFg, VG_PAINT_COLOR, 4, paintFg); vgSetParameteri(rpi->mPaintBg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetParameterfv(rpi->mPaintBg, VG_PAINT_COLOR, 4, paintBg); } } #endif struct sigaction sa; sa.sa_handler = rpi_kill; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); return rpi; }