static void *vg_init(const video_info_t *video, const input_driver_t **input, void **input_data) { unsigned temp_width = 0, temp_height = 0; VGfloat clearColor[4] = {0, 0, 0, 1}; settings_t *settings = config_get_ptr(); driver_t *driver = driver_get_ptr(); const gfx_ctx_driver_t *ctx = NULL; vg_t *vg = (vg_t*)calloc(1, sizeof(vg_t)); if (!vg) goto error; ctx = gfx_ctx_init_first(vg, settings->video.context_driver, GFX_CTX_OPENVG_API, 0, 0, false); if (!ctx) goto error; driver->video_context = ctx; gfx_ctx_get_video_size(vg, &temp_width, &temp_height); RARCH_LOG("Detecting screen resolution %ux%u.\n", temp_width, temp_height); if (temp_width != 0 && temp_height != 0) { video_driver_set_size_width(temp_width); video_driver_set_size_width(temp_height); } gfx_ctx_swap_interval(vg, video->vsync ? 1 : 0); gfx_ctx_update_window_title(vg); vg->mTexType = video->rgb32 ? VG_sXRGB_8888 : VG_sRGB_565; vg->keep_aspect = video->force_aspect; unsigned win_width = video->width; unsigned win_height = video->height; if (video->fullscreen && (win_width == 0) && (win_height == 0)) { video_driver_get_size(&temp_width, &temp_height); win_width = temp_width; win_height = temp_height; } if (!gfx_ctx_set_video_mode(vg, win_width, win_height, video->fullscreen)) goto error; video_driver_get_size(&temp_width, &temp_height); temp_width = 0; temp_height = 0; gfx_ctx_get_video_size(vg, &temp_width, &temp_height); vg->should_resize = true; if (temp_width != 0 && temp_height != 0) { RARCH_LOG("Verified window resolution %ux%u.\n", temp_width, temp_height); video_driver_set_size_width(temp_width); video_driver_set_size_height(temp_height); } video_driver_get_size(&temp_width, &temp_height); vg->mScreenAspect = (float)temp_width / temp_height; gfx_ctx_translate_aspect(vg, &vg->mScreenAspect, temp_width, temp_height); vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vg->mTextureWidth = vg->mTextureHeight = video->input_scale * RARCH_SCALE_BASE; vg->mImage = vgCreateImage(vg->mTexType, vg->mTextureWidth, vg->mTextureHeight, video->smooth ? VG_IMAGE_QUALITY_BETTER : VG_IMAGE_QUALITY_NONANTIALIASED); vg_set_nonblock_state(vg, !video->vsync); gfx_ctx_input_driver(vg, input, input_data); if (settings->video.font_enable && font_renderer_create_default(&vg->font_driver, &vg->mFontRenderer, *settings->video.font_path ? settings->video.font_path : NULL, settings->video.font_size)) { vg->mFont = vgCreateFont(0); if (vg->mFont != VG_INVALID_HANDLE) { vg->mFontsOn = true; vg->mFontHeight = settings->video.font_size; vg->mPaintFg = vgCreatePaint(); vg->mPaintBg = vgCreatePaint(); VGfloat paintFg[] = { settings->video.msg_color_r, settings->video.msg_color_g, settings->video.msg_color_b, 1.0f }; VGfloat paintBg[] = { settings->video.msg_color_r / 2.0f, settings->video.msg_color_g / 2.0f, settings->video.msg_color_b / 2.0f, 0.5f }; vgSetParameteri(vg->mPaintFg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetParameterfv(vg->mPaintFg, VG_PAINT_COLOR, 4, paintFg); vgSetParameteri(vg->mPaintBg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetParameterfv(vg->mPaintBg, VG_PAINT_COLOR, 4, paintBg); } } if (vg_query_extension("KHR_EGL_image") && gfx_ctx_image_buffer_init(vg, video)) { pvgCreateEGLImageTargetKHR = (PFNVGCREATEEGLIMAGETARGETKHRPROC)gfx_ctx_get_proc_address("vgCreateEGLImageTargetKHR"); if (pvgCreateEGLImageTargetKHR) { RARCH_LOG("[VG] Using EGLImage buffer\n"); vg->mEglImageBuf = true; } } #if 0 const char *ext = (const char*)vgGetString(VG_EXTENSIONS); if (ext) RARCH_LOG("[VG] Supported extensions: %s\n", ext); #endif return vg; error: if (vg) free(vg); if (driver) driver->video_context = NULL; return NULL; }
static bool gfx_ctx_init_egl_image_buffer(const video_info_t *video) { if (g_api == GFX_CTX_OPENVG_API) // don't bother, we just use VGImages for our EGLImage anyway { return false; } peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)gfx_ctx_get_proc_address("eglCreateImageKHR"); peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)gfx_ctx_get_proc_address("eglDestroyImageKHR"); if (!peglCreateImageKHR || !peglDestroyImageKHR || !gfx_ctx_egl_query_extension("KHR_image")) { return false; } g_egl_res = video->input_scale * RARCH_SCALE_BASE; EGLint pbufsurface_list[] = { EGL_WIDTH, g_egl_res, EGL_HEIGHT, g_egl_res, EGL_NONE }; EGLBoolean result; eglBindAPI(EGL_OPENVG_API); g_pbuff_surf = eglCreatePbufferSurface(g_egl_dpy, g_config, pbufsurface_list); if (g_pbuff_surf == EGL_NO_SURFACE) { RARCH_ERR("[VideoCore:EGLImage] failed to create PbufferSurface\n"); goto fail; } g_eglimage_ctx = eglCreateContext(g_egl_dpy, g_config, NULL, NULL); if (g_eglimage_ctx == EGL_NO_CONTEXT) { RARCH_ERR("[VideoCore:EGLImage] failed to create context\n"); goto fail; } // test to make sure we can switch context result = eglMakeCurrent(g_egl_dpy, g_pbuff_surf, g_pbuff_surf, g_eglimage_ctx); if (result == EGL_FALSE) { RARCH_ERR("[VideoCore:EGLImage] failed to make context current\n"); goto fail; } gfx_ctx_bind_api(g_api); eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx); g_smooth = video->smooth; return true; fail: if (g_pbuff_surf != EGL_NO_SURFACE) { eglDestroySurface(g_egl_dpy, g_pbuff_surf); g_pbuff_surf = EGL_NO_SURFACE; } if (g_eglimage_ctx != EGL_NO_CONTEXT) { eglDestroyContext(g_egl_dpy, g_eglimage_ctx); g_pbuff_surf = EGL_NO_CONTEXT; } gfx_ctx_bind_api(g_api); eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx); return false; }