obs-studio/plugins/linux-capture/xshm-input.c

491 lines
11 KiB
C
Raw Normal View History

/*
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
This program 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 Foundation, either version 2 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <xcb/shm.h>
#include <xcb/xfixes.h>
#include <xcb/xinerama.h>
2014-07-09 22:12:57 -07:00
#include <obs-module.h>
#include <util/dstr.h>
#include "xcursor-xcb.h"
#include "xhelpers.h"
#define XSHM_DATA(voidptr) struct xshm_data *data = voidptr;
#define blog(level, msg, ...) blog(level, "xshm-input: " msg, ##__VA_ARGS__)
struct xshm_data {
obs_source_t *source;
xcb_connection_t *xcb;
xcb_screen_t *xcb_screen;
xcb_shm_t *xshm;
xcb_xcursor_t *cursor;
char *server;
uint_fast32_t screen_id;
int_fast32_t x_org;
int_fast32_t y_org;
int_fast32_t width;
int_fast32_t height;
gs_texture_t *texture;
bool show_cursor;
bool use_xinerama;
bool advanced;
};
/**
* Resize the texture
*
* This will automatically create the texture if it does not exist
*
* @note requires to be called within the obs graphics context
*/
static inline void xshm_resize_texture(struct xshm_data *data)
{
if (data->texture)
(API Change) Improve graphics API consistency Summary: - Prefix all graphics subsystem names with gs_ or GS_ - Unsquish funciton names (for example _setfloat to _set_float) - Changed create functions to be more consistent with the rest of the API elsewhere. For exmaple, instead of gs_create_texture/gs_texture_destroy, it's now gs_texture_create/gs_texture_destroy - Renamed gs_stencil_op enum to gs_stencil_op_type From: To: ----------------------------------------------------------- tvertarray gs_tvertarray vb_data gs_vb_data vbdata_create gs_vbdata_create vbdata_destroy gs_vbdata_destroy shader_param gs_shader_param gs_effect gs_effect effect_technique gs_effect_technique effect_pass gs_effect_pass effect_param gs_effect_param texture_t gs_texture_t stagesurf_t gs_stagesurf_t zstencil_t gs_zstencil_t vertbuffer_t gs_vertbuffer_t indexbuffer_t gs_indexbuffer_t samplerstate_t gs_samplerstate_t swapchain_t gs_swapchain_t texrender_t gs_texrender_t shader_t gs_shader_t sparam_t gs_sparam_t effect_t gs_effect_t technique_t gs_technique_t eparam_t gs_eparam_t device_t gs_device_t graphics_t graphics_t shader_param_type gs_shader_param_type SHADER_PARAM_UNKNOWN GS_SHADER_PARAM_UNKNOWN SHADER_PARAM_BOOL GS_SHADER_PARAM_BOOL SHADER_PARAM_FLOAT GS_SHADER_PARAM_FLOAT SHADER_PARAM_INT GS_SHADER_PARAM_INT SHADER_PARAM_STRING GS_SHADER_PARAM_STRING SHADER_PARAM_VEC2 GS_SHADER_PARAM_VEC2 SHADER_PARAM_VEC3 GS_SHADER_PARAM_VEC3 SHADER_PARAM_VEC4 GS_SHADER_PARAM_VEC4 SHADER_PARAM_MATRIX4X4 GS_SHADER_PARAM_MATRIX4X4 SHADER_PARAM_TEXTURE GS_SHADER_PARAM_TEXTURE shader_param_info gs_shader_param_info shader_type gs_shader_type SHADER_VERTEX GS_SHADER_VERTEX SHADER_PIXEL GS_SHADER_PIXEL shader_destroy gs_shader_destroy shader_numparams gs_shader_get_num_params shader_getparambyidx gs_shader_get_param_by_idx shader_getparambyname gs_shader_get_param_by_name shader_getviewprojmatrix gs_shader_get_viewproj_matrix shader_getworldmatrix gs_shader_get_world_matrix shader_getparaminfo gs_shader_get_param_info shader_setbool gs_shader_set_bool shader_setfloat gs_shader_set_float shader_setint gs_shader_set_int shader_setmatrix3 gs_shader_setmatrix3 shader_setmatrix4 gs_shader_set_matrix4 shader_setvec2 gs_shader_set_vec2 shader_setvec3 gs_shader_set_vec3 shader_setvec4 gs_shader_set_vec4 shader_settexture gs_shader_set_texture shader_setval gs_shader_set_val shader_setdefault gs_shader_set_default effect_property_type gs_effect_property_type EFFECT_NONE GS_EFFECT_NONE EFFECT_BOOL GS_EFFECT_BOOL EFFECT_FLOAT GS_EFFECT_FLOAT EFFECT_COLOR GS_EFFECT_COLOR EFFECT_TEXTURE GS_EFFECT_TEXTURE effect_param_info gs_effect_param_info effect_destroy gs_effect_destroy effect_gettechnique gs_effect_get_technique technique_begin gs_technique_begin technique_end gs_technique_end technique_beginpass gs_technique_begin_pass technique_beginpassbyname gs_technique_begin_pass_by_name technique_endpass gs_technique_end_pass effect_numparams gs_effect_get_num_params effect_getparambyidx gs_effect_get_param_by_idx effect_getparambyname gs_effect_get_param_by_name effect_updateparams gs_effect_update_params effect_getviewprojmatrix gs_effect_get_viewproj_matrix effect_getworldmatrix gs_effect_get_world_matrix effect_getparaminfo gs_effect_get_param_info effect_setbool gs_effect_set_bool effect_setfloat gs_effect_set_float effect_setint gs_effect_set_int effect_setmatrix4 gs_effect_set_matrix4 effect_setvec2 gs_effect_set_vec2 effect_setvec3 gs_effect_set_vec3 effect_setvec4 gs_effect_set_vec4 effect_settexture gs_effect_set_texture effect_setval gs_effect_set_val effect_setdefault gs_effect_set_default texrender_create gs_texrender_create texrender_destroy gs_texrender_destroy texrender_begin gs_texrender_begin texrender_end gs_texrender_end texrender_reset gs_texrender_reset texrender_gettexture gs_texrender_get_texture GS_BUILDMIPMAPS GS_BUILD_MIPMAPS GS_RENDERTARGET GS_RENDER_TARGET gs_device_name gs_get_device_name gs_device_type gs_get_device_type gs_entercontext gs_enter_context gs_leavecontext gs_leave_context gs_getcontext gs_get_context gs_renderstart gs_render_start gs_renderstop gs_render_stop gs_rendersave gs_render_save gs_getinput gs_get_input gs_geteffect gs_get_effect gs_create_effect_from_file gs_effect_create_from_file gs_create_effect gs_effect_create gs_create_vertexshader_from_file gs_vertexshader_create_from_file gs_create_pixelshader_from_file gs_pixelshader_create_from_file gs_create_texture_from_file gs_texture_create_from_file gs_resetviewport gs_reset_viewport gs_set2dmode gs_set_2d_mode gs_set3dmode gs_set_3d_mode gs_create_swapchain gs_swapchain_create gs_getsize gs_get_size gs_getwidth gs_get_width gs_getheight gs_get_height gs_create_texture gs_texture_create gs_create_cubetexture gs_cubetexture_create gs_create_volumetexture gs_voltexture_create gs_create_zstencil gs_zstencil_create gs_create_stagesurface gs_stagesurface_create gs_create_samplerstate gs_samplerstate_create gs_create_vertexshader gs_vertexshader_create gs_create_pixelshader gs_pixelshader_create gs_create_vertexbuffer gs_vertexbuffer_create gs_create_indexbuffer gs_indexbuffer_create gs_gettexturetype gs_get_texture_type gs_load_defaultsamplerstate gs_load_default_samplerstate gs_getvertexshader gs_get_vertex_shader gs_getpixelshader gs_get_pixel_shader gs_getrendertarget gs_get_render_target gs_getzstenciltarget gs_get_zstencil_target gs_setrendertarget gs_set_render_target gs_setcuberendertarget gs_set_cube_render_target gs_beginscene gs_begin_scene gs_draw gs_draw gs_endscene gs_end_scene gs_setcullmode gs_set_cull_mode gs_getcullmode gs_get_cull_mode gs_enable_depthtest gs_enable_depth_test gs_enable_stenciltest gs_enable_stencil_test gs_enable_stencilwrite gs_enable_stencil_write gs_blendfunction gs_blend_function gs_depthfunction gs_depth_function gs_stencilfunction gs_stencil_function gs_stencilop gs_stencil_op gs_setviewport gs_set_viewport gs_getviewport gs_get_viewport gs_setscissorrect gs_set_scissor_rect gs_create_texture_from_iosurface gs_texture_create_from_iosurface gs_create_gdi_texture gs_texture_create_gdi gs_is_compressed_format gs_is_compressed_format gs_num_total_levels gs_get_total_levels texture_setimage gs_texture_set_image cubetexture_setimage gs_cubetexture_set_image swapchain_destroy gs_swapchain_destroy texture_destroy gs_texture_destroy texture_getwidth gs_texture_get_width texture_getheight gs_texture_get_height texture_getcolorformat gs_texture_get_color_format texture_map gs_texture_map texture_unmap gs_texture_unmap texture_isrect gs_texture_is_rect texture_getobj gs_texture_get_obj cubetexture_destroy gs_cubetexture_destroy cubetexture_getsize gs_cubetexture_get_size cubetexture_getcolorformat gs_cubetexture_get_color_format volumetexture_destroy gs_voltexture_destroy volumetexture_getwidth gs_voltexture_get_width volumetexture_getheight gs_voltexture_get_height volumetexture_getdepth gs_voltexture_getdepth volumetexture_getcolorformat gs_voltexture_get_color_format stagesurface_destroy gs_stagesurface_destroy stagesurface_getwidth gs_stagesurface_get_width stagesurface_getheight gs_stagesurface_get_height stagesurface_getcolorformat gs_stagesurface_get_color_format stagesurface_map gs_stagesurface_map stagesurface_unmap gs_stagesurface_unmap zstencil_destroy gs_zstencil_destroy samplerstate_destroy gs_samplerstate_destroy vertexbuffer_destroy gs_vertexbuffer_destroy vertexbuffer_flush gs_vertexbuffer_flush vertexbuffer_getdata gs_vertexbuffer_get_data indexbuffer_destroy gs_indexbuffer_destroy indexbuffer_flush gs_indexbuffer_flush indexbuffer_getdata gs_indexbuffer_get_data indexbuffer_numindices gs_indexbuffer_get_num_indices indexbuffer_gettype gs_indexbuffer_get_type texture_rebind_iosurface gs_texture_rebind_iosurface texture_get_dc gs_texture_get_dc texture_release_dc gs_texture_release_dc
2014-08-07 23:42:07 -07:00
gs_texture_destroy(data->texture);
data->texture = gs_texture_create(data->width, data->height,
GS_BGRA, 1, NULL, GS_DYNAMIC);
}
/**
* Check if the xserver supports all the extensions we need
*/
static bool xshm_check_extensions(xcb_connection_t *xcb)
{
bool ok = true;
if (!xcb_get_extension_data(xcb, &xcb_shm_id)->present) {
blog(LOG_ERROR, "Missing SHM extension !");
ok = false;
}
if (!xcb_get_extension_data(xcb, &xcb_xinerama_id)->present)
blog(LOG_INFO, "Missing Xinerama extension !");
return ok;
}
/**
* Update the capture
*
* @return < 0 on error, 0 when size is unchanged, > 1 on size change
*/
static int_fast32_t xshm_update_geometry(struct xshm_data *data)
{
int_fast32_t old_width = data->width;
int_fast32_t old_height = data->height;
if (data->use_xinerama) {
if (xinerama_screen_geo(data->xcb, data->screen_id,
&data->x_org, &data->y_org,
&data->width, &data->height) < 0) {
return -1;
}
data->xcb_screen = xcb_get_screen(data->xcb, 0);
}
else {
data->x_org = 0;
data->y_org = 0;
if (x11_screen_geo(data->xcb, data->screen_id,
&data->width, &data->height) < 0) {
return -1;
}
data->xcb_screen = xcb_get_screen(data->xcb, data->screen_id);
}
if (!data->width || !data->height) {
blog(LOG_ERROR, "Failed to get geometry");
return -1;
}
blog(LOG_INFO, "Geometry %"PRIdFAST32"x%"PRIdFAST32
" @ %"PRIdFAST32",%"PRIdFAST32,
data->width, data->height, data->x_org, data->y_org);
if (old_width == data->width && old_height == data->height)
return 0;
return 1;
}
/**
* Returns the name of the plugin
*/
static const char* xshm_getname(void *unused)
{
UNUSED_PARAMETER(unused);
2014-07-09 22:12:57 -07:00
return obs_module_text("X11SharedMemoryScreenInput");
}
/**
* Stop the capture
*/
static void xshm_capture_stop(struct xshm_data *data)
{
obs_enter_graphics();
if (data->texture) {
gs_texture_destroy(data->texture);
data->texture = NULL;
}
if (data->cursor) {
xcb_xcursor_destroy(data->cursor);
data->cursor = NULL;
}
obs_leave_graphics();
if (data->xshm) {
xshm_xcb_detach(data->xshm);
data->xshm = NULL;
}
if (data->xcb) {
xcb_disconnect(data->xcb);
data->xcb = NULL;
}
if (data->server) {
bfree(data->server);
data->server = NULL;
}
}
/**
* Start the capture
*/
static void xshm_capture_start(struct xshm_data *data)
{
const char *server = (data->advanced && *data->server)
? data->server : NULL;
data->xcb = xcb_connect(server, NULL);
if (!data->xcb || xcb_connection_has_error(data->xcb)) {
blog(LOG_ERROR, "Unable to open X display !");
goto fail;
}
if (!xshm_check_extensions(data->xcb))
goto fail;
data->use_xinerama = xinerama_is_active(data->xcb) ? true : false;
if (xshm_update_geometry(data) < 0) {
blog(LOG_ERROR, "failed to update geometry !");
goto fail;
}
data->xshm = xshm_xcb_attach(data->xcb, data->width, data->height);
if (!data->xshm) {
blog(LOG_ERROR, "failed to attach shm !");
goto fail;
}
data->cursor = xcb_xcursor_init(data->xcb);
xcb_xcursor_offset(data->cursor, data->x_org, data->y_org);
obs_enter_graphics();
xshm_resize_texture(data);
obs_leave_graphics();
return;
fail:
xshm_capture_stop(data);
}
/**
* Update the capture with changed settings
*/
static void xshm_update(void *vptr, obs_data_t *settings)
{
XSHM_DATA(vptr);
xshm_capture_stop(data);
data->screen_id = obs_data_get_int(settings, "screen");
data->show_cursor = obs_data_get_bool(settings, "show_cursor");
data->advanced = obs_data_get_bool(settings, "advanced");
data->server = bstrdup(obs_data_get_string(settings, "server"));
xshm_capture_start(data);
}
/**
* Get the default settings for the capture
*/
static void xshm_defaults(obs_data_t *defaults)
{
obs_data_set_default_int(defaults, "screen", 0);
obs_data_set_default_bool(defaults, "show_cursor", true);
obs_data_set_default_bool(defaults, "advanced", false);
}
/**
* Toggle visibility of advanced settings
*/
static bool xshm_toggle_advanced(obs_properties_t *props,
obs_property_t *p, obs_data_t *settings)
{
UNUSED_PARAMETER(p);
const bool visible = obs_data_get_bool(settings, "advanced");
obs_property_t *server = obs_properties_get(props, "server");
obs_property_set_visible(server, visible);
/* trigger server changed callback so the screen list is refreshed */
obs_property_modified(server, settings);
return true;
}
/**
* The x server was changed
*/
static bool xshm_server_changed(obs_properties_t *props,
obs_property_t *p, obs_data_t *settings)
{
UNUSED_PARAMETER(p);
bool advanced = obs_data_get_bool(settings, "advanced");
int_fast32_t old_screen = obs_data_get_int(settings, "screen");
const char *server = obs_data_get_string(settings, "server");
obs_property_t *screens = obs_properties_get(props, "screen");
/* we want a real NULL here in case there is no string here */
server = (advanced && *server) ? server : NULL;
obs_property_list_clear(screens);
xcb_connection_t *xcb = xcb_connect(server, NULL);
if (!xcb || xcb_connection_has_error(xcb)) {
obs_property_set_enabled(screens, false);
return true;
}
struct dstr screen_info;
dstr_init(&screen_info);
bool xinerama = xinerama_is_active(xcb);
int_fast32_t count = (xinerama) ?
xinerama_screen_count(xcb) :
xcb_setup_roots_length(xcb_get_setup(xcb));
for (int_fast32_t i = 0; i < count; ++i) {
int_fast32_t x, y, w, h;
x = y = w = h = 0;
if (xinerama)
xinerama_screen_geo(xcb, i, &x, &y, &w, &h);
else
x11_screen_geo(xcb, i, &w, &h);
dstr_printf(&screen_info, "Screen %"PRIuFAST32" (%"PRIuFAST32
"x%"PRIuFAST32" @ %"PRIuFAST32
",%"PRIuFAST32")", i, w, h, x, y);
obs_property_list_add_int(screens, screen_info.array, i);
}
/* handle missing screen */
if (old_screen + 1 > count) {
dstr_printf(&screen_info, "Screen %"PRIuFAST32" (not found)",
old_screen);
size_t index = obs_property_list_add_int(screens,
screen_info.array, old_screen);
obs_property_list_item_disable(screens, index, true);
}
dstr_free(&screen_info);
xcb_disconnect(xcb);
obs_property_set_enabled(screens, true);
return true;
}
/**
* Get the properties for the capture
*/
static obs_properties_t *xshm_properties(void *vptr)
{
XSHM_DATA(vptr);
obs_properties_t *props = obs_properties_create();
obs_properties_add_list(props, "screen", obs_module_text("Screen"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
2014-07-09 22:12:57 -07:00
obs_properties_add_bool(props, "show_cursor",
obs_module_text("CaptureCursor"));
obs_property_t *advanced = obs_properties_add_bool(props, "advanced",
obs_module_text("AdvancedSettings"));
obs_property_t *server = obs_properties_add_text(props, "server",
obs_module_text("XServer"), OBS_TEXT_DEFAULT);
obs_property_set_modified_callback(advanced, xshm_toggle_advanced);
obs_property_set_modified_callback(server, xshm_server_changed);
/* trigger server callback to get screen count ... */
obs_data_t *settings = obs_source_get_settings(data->source);
obs_property_modified(server, settings);
obs_data_release(settings);
return props;
}
/**
* Destroy the capture
*/
static void xshm_destroy(void *vptr)
{
XSHM_DATA(vptr);
if (!data)
return;
xshm_capture_stop(data);
bfree(data);
}
/**
* Create the capture
*/
static void *xshm_create(obs_data_t *settings, obs_source_t *source)
{
struct xshm_data *data = bzalloc(sizeof(struct xshm_data));
data->source = source;
xshm_update(data, settings);
return data;
}
/**
* Prepare the capture data
*/
static void xshm_video_tick(void *vptr, float seconds)
{
UNUSED_PARAMETER(seconds);
XSHM_DATA(vptr);
if (!data->texture)
return;
if (!obs_source_showing(data->source))
return;
xcb_shm_get_image_cookie_t img_c;
xcb_shm_get_image_reply_t *img_r;
xcb_xfixes_get_cursor_image_cookie_t cur_c;
xcb_xfixes_get_cursor_image_reply_t *cur_r;
img_c = xcb_shm_get_image_unchecked(data->xcb, data->xcb_screen->root,
data->x_org, data->y_org, data->width, data->height,
~0, XCB_IMAGE_FORMAT_Z_PIXMAP, data->xshm->seg, 0);
cur_c = xcb_xfixes_get_cursor_image_unchecked(data->xcb);
img_r = xcb_shm_get_image_reply(data->xcb, img_c, NULL);
cur_r = xcb_xfixes_get_cursor_image_reply(data->xcb, cur_c, NULL);
if (!img_r)
goto exit;
obs_enter_graphics();
gs_texture_set_image(data->texture, (void *) data->xshm->data,
data->width * 4, false);
xcb_xcursor_update(data->cursor, cur_r);
obs_leave_graphics();
exit:
free(img_r);
free(cur_r);
}
/**
* Render the capture data
*/
static void xshm_video_render(void *vptr, gs_effect_t *effect)
{
XSHM_DATA(vptr);
effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
if (!data->texture)
return;
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
(API Change) Improve graphics API consistency Summary: - Prefix all graphics subsystem names with gs_ or GS_ - Unsquish funciton names (for example _setfloat to _set_float) - Changed create functions to be more consistent with the rest of the API elsewhere. For exmaple, instead of gs_create_texture/gs_texture_destroy, it's now gs_texture_create/gs_texture_destroy - Renamed gs_stencil_op enum to gs_stencil_op_type From: To: ----------------------------------------------------------- tvertarray gs_tvertarray vb_data gs_vb_data vbdata_create gs_vbdata_create vbdata_destroy gs_vbdata_destroy shader_param gs_shader_param gs_effect gs_effect effect_technique gs_effect_technique effect_pass gs_effect_pass effect_param gs_effect_param texture_t gs_texture_t stagesurf_t gs_stagesurf_t zstencil_t gs_zstencil_t vertbuffer_t gs_vertbuffer_t indexbuffer_t gs_indexbuffer_t samplerstate_t gs_samplerstate_t swapchain_t gs_swapchain_t texrender_t gs_texrender_t shader_t gs_shader_t sparam_t gs_sparam_t effect_t gs_effect_t technique_t gs_technique_t eparam_t gs_eparam_t device_t gs_device_t graphics_t graphics_t shader_param_type gs_shader_param_type SHADER_PARAM_UNKNOWN GS_SHADER_PARAM_UNKNOWN SHADER_PARAM_BOOL GS_SHADER_PARAM_BOOL SHADER_PARAM_FLOAT GS_SHADER_PARAM_FLOAT SHADER_PARAM_INT GS_SHADER_PARAM_INT SHADER_PARAM_STRING GS_SHADER_PARAM_STRING SHADER_PARAM_VEC2 GS_SHADER_PARAM_VEC2 SHADER_PARAM_VEC3 GS_SHADER_PARAM_VEC3 SHADER_PARAM_VEC4 GS_SHADER_PARAM_VEC4 SHADER_PARAM_MATRIX4X4 GS_SHADER_PARAM_MATRIX4X4 SHADER_PARAM_TEXTURE GS_SHADER_PARAM_TEXTURE shader_param_info gs_shader_param_info shader_type gs_shader_type SHADER_VERTEX GS_SHADER_VERTEX SHADER_PIXEL GS_SHADER_PIXEL shader_destroy gs_shader_destroy shader_numparams gs_shader_get_num_params shader_getparambyidx gs_shader_get_param_by_idx shader_getparambyname gs_shader_get_param_by_name shader_getviewprojmatrix gs_shader_get_viewproj_matrix shader_getworldmatrix gs_shader_get_world_matrix shader_getparaminfo gs_shader_get_param_info shader_setbool gs_shader_set_bool shader_setfloat gs_shader_set_float shader_setint gs_shader_set_int shader_setmatrix3 gs_shader_setmatrix3 shader_setmatrix4 gs_shader_set_matrix4 shader_setvec2 gs_shader_set_vec2 shader_setvec3 gs_shader_set_vec3 shader_setvec4 gs_shader_set_vec4 shader_settexture gs_shader_set_texture shader_setval gs_shader_set_val shader_setdefault gs_shader_set_default effect_property_type gs_effect_property_type EFFECT_NONE GS_EFFECT_NONE EFFECT_BOOL GS_EFFECT_BOOL EFFECT_FLOAT GS_EFFECT_FLOAT EFFECT_COLOR GS_EFFECT_COLOR EFFECT_TEXTURE GS_EFFECT_TEXTURE effect_param_info gs_effect_param_info effect_destroy gs_effect_destroy effect_gettechnique gs_effect_get_technique technique_begin gs_technique_begin technique_end gs_technique_end technique_beginpass gs_technique_begin_pass technique_beginpassbyname gs_technique_begin_pass_by_name technique_endpass gs_technique_end_pass effect_numparams gs_effect_get_num_params effect_getparambyidx gs_effect_get_param_by_idx effect_getparambyname gs_effect_get_param_by_name effect_updateparams gs_effect_update_params effect_getviewprojmatrix gs_effect_get_viewproj_matrix effect_getworldmatrix gs_effect_get_world_matrix effect_getparaminfo gs_effect_get_param_info effect_setbool gs_effect_set_bool effect_setfloat gs_effect_set_float effect_setint gs_effect_set_int effect_setmatrix4 gs_effect_set_matrix4 effect_setvec2 gs_effect_set_vec2 effect_setvec3 gs_effect_set_vec3 effect_setvec4 gs_effect_set_vec4 effect_settexture gs_effect_set_texture effect_setval gs_effect_set_val effect_setdefault gs_effect_set_default texrender_create gs_texrender_create texrender_destroy gs_texrender_destroy texrender_begin gs_texrender_begin texrender_end gs_texrender_end texrender_reset gs_texrender_reset texrender_gettexture gs_texrender_get_texture GS_BUILDMIPMAPS GS_BUILD_MIPMAPS GS_RENDERTARGET GS_RENDER_TARGET gs_device_name gs_get_device_name gs_device_type gs_get_device_type gs_entercontext gs_enter_context gs_leavecontext gs_leave_context gs_getcontext gs_get_context gs_renderstart gs_render_start gs_renderstop gs_render_stop gs_rendersave gs_render_save gs_getinput gs_get_input gs_geteffect gs_get_effect gs_create_effect_from_file gs_effect_create_from_file gs_create_effect gs_effect_create gs_create_vertexshader_from_file gs_vertexshader_create_from_file gs_create_pixelshader_from_file gs_pixelshader_create_from_file gs_create_texture_from_file gs_texture_create_from_file gs_resetviewport gs_reset_viewport gs_set2dmode gs_set_2d_mode gs_set3dmode gs_set_3d_mode gs_create_swapchain gs_swapchain_create gs_getsize gs_get_size gs_getwidth gs_get_width gs_getheight gs_get_height gs_create_texture gs_texture_create gs_create_cubetexture gs_cubetexture_create gs_create_volumetexture gs_voltexture_create gs_create_zstencil gs_zstencil_create gs_create_stagesurface gs_stagesurface_create gs_create_samplerstate gs_samplerstate_create gs_create_vertexshader gs_vertexshader_create gs_create_pixelshader gs_pixelshader_create gs_create_vertexbuffer gs_vertexbuffer_create gs_create_indexbuffer gs_indexbuffer_create gs_gettexturetype gs_get_texture_type gs_load_defaultsamplerstate gs_load_default_samplerstate gs_getvertexshader gs_get_vertex_shader gs_getpixelshader gs_get_pixel_shader gs_getrendertarget gs_get_render_target gs_getzstenciltarget gs_get_zstencil_target gs_setrendertarget gs_set_render_target gs_setcuberendertarget gs_set_cube_render_target gs_beginscene gs_begin_scene gs_draw gs_draw gs_endscene gs_end_scene gs_setcullmode gs_set_cull_mode gs_getcullmode gs_get_cull_mode gs_enable_depthtest gs_enable_depth_test gs_enable_stenciltest gs_enable_stencil_test gs_enable_stencilwrite gs_enable_stencil_write gs_blendfunction gs_blend_function gs_depthfunction gs_depth_function gs_stencilfunction gs_stencil_function gs_stencilop gs_stencil_op gs_setviewport gs_set_viewport gs_getviewport gs_get_viewport gs_setscissorrect gs_set_scissor_rect gs_create_texture_from_iosurface gs_texture_create_from_iosurface gs_create_gdi_texture gs_texture_create_gdi gs_is_compressed_format gs_is_compressed_format gs_num_total_levels gs_get_total_levels texture_setimage gs_texture_set_image cubetexture_setimage gs_cubetexture_set_image swapchain_destroy gs_swapchain_destroy texture_destroy gs_texture_destroy texture_getwidth gs_texture_get_width texture_getheight gs_texture_get_height texture_getcolorformat gs_texture_get_color_format texture_map gs_texture_map texture_unmap gs_texture_unmap texture_isrect gs_texture_is_rect texture_getobj gs_texture_get_obj cubetexture_destroy gs_cubetexture_destroy cubetexture_getsize gs_cubetexture_get_size cubetexture_getcolorformat gs_cubetexture_get_color_format volumetexture_destroy gs_voltexture_destroy volumetexture_getwidth gs_voltexture_get_width volumetexture_getheight gs_voltexture_get_height volumetexture_getdepth gs_voltexture_getdepth volumetexture_getcolorformat gs_voltexture_get_color_format stagesurface_destroy gs_stagesurface_destroy stagesurface_getwidth gs_stagesurface_get_width stagesurface_getheight gs_stagesurface_get_height stagesurface_getcolorformat gs_stagesurface_get_color_format stagesurface_map gs_stagesurface_map stagesurface_unmap gs_stagesurface_unmap zstencil_destroy gs_zstencil_destroy samplerstate_destroy gs_samplerstate_destroy vertexbuffer_destroy gs_vertexbuffer_destroy vertexbuffer_flush gs_vertexbuffer_flush vertexbuffer_getdata gs_vertexbuffer_get_data indexbuffer_destroy gs_indexbuffer_destroy indexbuffer_flush gs_indexbuffer_flush indexbuffer_getdata gs_indexbuffer_get_data indexbuffer_numindices gs_indexbuffer_get_num_indices indexbuffer_gettype gs_indexbuffer_get_type texture_rebind_iosurface gs_texture_rebind_iosurface texture_get_dc gs_texture_get_dc texture_release_dc gs_texture_release_dc
2014-08-07 23:42:07 -07:00
gs_effect_set_texture(image, data->texture);
while (gs_effect_loop(effect, "Draw")) {
gs_draw_sprite(data->texture, 0, 0, 0);
}
if (data->show_cursor) {
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
while (gs_effect_loop(effect, "Draw")) {
xcb_xcursor_render(data->cursor);
}
}
}
/**
* Width of the captured data
*/
static uint32_t xshm_getwidth(void *vptr)
{
XSHM_DATA(vptr);
return data->width;
}
/**
* Height of the captured data
*/
static uint32_t xshm_getheight(void *vptr)
{
XSHM_DATA(vptr);
return data->height;
}
struct obs_source_info xshm_input = {
.id = "xshm_input",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO |
OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_DO_NOT_DUPLICATE,
.get_name = xshm_getname,
.create = xshm_create,
.destroy = xshm_destroy,
.update = xshm_update,
.get_defaults = xshm_defaults,
.get_properties = xshm_properties,
.video_tick = xshm_video_tick,
.video_render = xshm_video_render,
.get_width = xshm_getwidth,
.get_height = xshm_getheight
};