yolobs-studio/plugins/linux-capture/xcompcap-main.cpp

687 lines
16 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#include <glad/glad.h>
#include <glad/glad_glx.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xcomposite.h>
#include <pthread.h>
#include <vector>
#include <obs-module.h>
#include <graphics/vec4.h>
#include <util/platform.h>
#include "xcompcap-main.hpp"
#include "xcompcap-helper.hpp"
#include "xcursor.h"
#define xdisp (XCompcap::disp())
#define WIN_STRING_DIV "\r\n"
bool XCompcapMain::init()
{
if (!xdisp) {
blog(LOG_ERROR, "failed opening display");
return false;
}
int eventBase, errorBase;
if (!XCompositeQueryExtension(xdisp, &eventBase, &errorBase)) {
blog(LOG_ERROR, "Xcomposite extension not supported");
return false;
}
int major = 0, minor = 2;
XCompositeQueryVersion(xdisp, &major, &minor);
if (major == 0 && minor < 2) {
blog(LOG_ERROR, "Xcomposite extension is too old: %d.%d < 0.2",
2019-09-22 21:19:10 +00:00
major, minor);
2016-02-23 23:16:51 +00:00
return false;
}
return true;
}
void XCompcapMain::deinit()
{
XCompcap::cleanupDisplay();
}
obs_properties_t *XCompcapMain::properties()
{
obs_properties_t *props = obs_properties_create();
2019-09-22 21:19:10 +00:00
obs_property_t *wins = obs_properties_add_list(
props, "capture_window", obs_module_text("Window"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
for (Window win : XCompcap::getTopLevelWindows()) {
2016-02-23 23:16:51 +00:00
std::string wname = XCompcap::getWindowName(win);
2016-08-28 12:07:43 +00:00
std::string cls = XCompcap::getWindowClass(win);
2016-02-23 23:16:51 +00:00
std::string winid = std::to_string((long long)win);
std::string desc =
2019-09-22 21:19:10 +00:00
(winid + WIN_STRING_DIV + wname + WIN_STRING_DIV + cls);
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
obs_property_list_add_string(wins, wname.c_str(), desc.c_str());
2016-02-23 23:16:51 +00:00
}
2019-09-22 21:19:10 +00:00
obs_properties_add_int(props, "cut_top", obs_module_text("CropTop"), 0,
4096, 1);
2016-02-23 23:16:51 +00:00
obs_properties_add_int(props, "cut_left", obs_module_text("CropLeft"),
2019-09-22 21:19:10 +00:00
0, 4096, 1);
2016-02-23 23:16:51 +00:00
obs_properties_add_int(props, "cut_right", obs_module_text("CropRight"),
2019-09-22 21:19:10 +00:00
0, 4096, 1);
2016-02-23 23:16:51 +00:00
obs_properties_add_int(props, "cut_bot", obs_module_text("CropBottom"),
2019-09-22 21:19:10 +00:00
0, 4096, 1);
2016-02-23 23:16:51 +00:00
obs_properties_add_bool(props, "swap_redblue",
2019-09-22 21:19:10 +00:00
obs_module_text("SwapRedBlue"));
2016-02-23 23:16:51 +00:00
obs_properties_add_bool(props, "lock_x", obs_module_text("LockX"));
obs_properties_add_bool(props, "show_cursor",
2019-09-22 21:19:10 +00:00
obs_module_text("CaptureCursor"));
2016-02-23 23:16:51 +00:00
obs_properties_add_bool(props, "include_border",
2019-09-22 21:19:10 +00:00
obs_module_text("IncludeXBorder"));
2016-02-23 23:16:51 +00:00
2016-05-24 19:53:01 +00:00
obs_properties_add_bool(props, "exclude_alpha",
2019-09-22 21:19:10 +00:00
obs_module_text("ExcludeAlpha"));
2016-05-24 19:53:01 +00:00
2016-02-23 23:16:51 +00:00
return props;
}
void XCompcapMain::defaults(obs_data_t *settings)
{
obs_data_set_default_string(settings, "capture_window", "");
obs_data_set_default_int(settings, "cut_top", 0);
obs_data_set_default_int(settings, "cut_left", 0);
obs_data_set_default_int(settings, "cut_right", 0);
obs_data_set_default_int(settings, "cut_bot", 0);
obs_data_set_default_bool(settings, "swap_redblue", false);
obs_data_set_default_bool(settings, "lock_x", false);
obs_data_set_default_bool(settings, "show_cursor", true);
obs_data_set_default_bool(settings, "include_border", false);
2016-05-24 19:53:01 +00:00
obs_data_set_default_bool(settings, "exclude_alpha", false);
2016-02-23 23:16:51 +00:00
}
2016-08-28 12:07:43 +00:00
#define FIND_WINDOW_INTERVAL 2.0
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
struct XCompcapMain_private {
2016-02-23 23:16:51 +00:00
XCompcapMain_private()
2019-09-22 21:19:10 +00:00
: win(0),
cut_top(0),
cur_cut_top(0),
cut_left(0),
cur_cut_left(0),
cut_right(0),
cur_cut_right(0),
cut_bot(0),
cur_cut_bot(0),
inverted(false),
width(0),
height(0),
pixmap(0),
glxpixmap(0),
tex(0),
gltex(0)
2016-02-23 23:16:51 +00:00
{
pthread_mutexattr_init(&lockattr);
pthread_mutexattr_settype(&lockattr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock, &lockattr);
}
~XCompcapMain_private()
{
pthread_mutex_destroy(&lock);
pthread_mutexattr_destroy(&lockattr);
}
obs_source_t *source;
std::string windowName;
2016-08-28 12:07:43 +00:00
Window win = 0;
2016-02-23 23:16:51 +00:00
int cut_top, cur_cut_top;
int cut_left, cur_cut_left;
int cut_right, cur_cut_right;
int cut_bot, cur_cut_bot;
bool inverted;
bool swapRedBlue;
bool lockX;
bool include_border;
2016-05-24 19:53:01 +00:00
bool exclude_alpha;
2019-07-27 12:47:10 +00:00
bool draw_opaque;
2016-02-23 23:16:51 +00:00
2016-08-28 12:07:43 +00:00
double window_check_time = 0.0;
2016-02-23 23:16:51 +00:00
uint32_t width;
uint32_t height;
uint32_t border;
Pixmap pixmap;
GLXPixmap glxpixmap;
gs_texture_t *tex;
gs_texture_t *gltex;
pthread_mutex_t lock;
pthread_mutexattr_t lockattr;
bool show_cursor = true;
bool cursor_outside = false;
xcursor_t *cursor = nullptr;
};
XCompcapMain::XCompcapMain(obs_data_t *settings, obs_source_t *source)
{
p = new XCompcapMain_private;
p->source = source;
obs_enter_graphics();
p->cursor = xcursor_init(xdisp);
obs_leave_graphics();
updateSettings(settings);
}
static void xcc_cleanup(XCompcapMain_private *p);
XCompcapMain::~XCompcapMain()
{
ObsGsContextHolder obsctx;
if (p->tex) {
gs_texture_destroy(p->tex);
p->tex = 0;
}
xcc_cleanup(p);
if (p->cursor) {
xcursor_destroy(p->cursor);
p->cursor = nullptr;
}
delete p;
}
static Window getWindowFromString(std::string wstr)
{
2016-08-28 12:07:43 +00:00
XErrorLock xlock;
2016-02-23 23:16:51 +00:00
if (wstr == "") {
return XCompcap::getTopLevelWindows().front();
}
if (wstr.substr(0, 4) == "root") {
int i = std::stoi("0" + wstr.substr(4));
return RootWindow(xdisp, i);
}
size_t firstMark = wstr.find(WIN_STRING_DIV);
2016-08-28 12:07:43 +00:00
size_t markSize = strlen(WIN_STRING_DIV);
2016-02-23 23:16:51 +00:00
if (firstMark == std::string::npos)
return (Window)std::stol(wstr);
2016-08-28 12:07:43 +00:00
Window wid = 0;
2016-02-23 23:16:51 +00:00
2016-08-28 12:07:43 +00:00
wstr = wstr.substr(firstMark + markSize);
2016-02-23 23:16:51 +00:00
size_t lastMark = wstr.rfind(WIN_STRING_DIV);
std::string wname = wstr.substr(0, lastMark);
2016-08-28 12:07:43 +00:00
std::string wcls = wstr.substr(lastMark + markSize);
2016-02-23 23:16:51 +00:00
Window matchedNameWin = wid;
2019-09-22 21:19:10 +00:00
for (Window cwin : XCompcap::getTopLevelWindows()) {
2016-02-23 23:16:51 +00:00
std::string cwinname = XCompcap::getWindowName(cwin);
2016-08-28 12:07:43 +00:00
std::string ccls = XCompcap::getWindowClass(cwin);
2016-02-23 23:16:51 +00:00
2016-08-28 12:07:43 +00:00
if (cwin == wid && wname == cwinname && wcls == ccls)
2016-02-23 23:16:51 +00:00
return wid;
2016-08-28 12:07:43 +00:00
if (wname == cwinname ||
(!matchedNameWin && !wcls.empty() && wcls == ccls))
2016-02-23 23:16:51 +00:00
matchedNameWin = cwin;
}
return matchedNameWin;
}
static void xcc_cleanup(XCompcapMain_private *p)
{
PLock lock(&p->lock);
2019-09-22 21:19:10 +00:00
XErrorLock xlock;
2016-02-23 23:16:51 +00:00
if (p->gltex) {
2019-09-22 21:19:10 +00:00
GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
2019-07-27 12:47:10 +00:00
glBindTexture(GL_TEXTURE_2D, gltex);
2019-09-22 21:19:10 +00:00
if (p->glxpixmap) {
glXReleaseTexImageEXT(xdisp, p->glxpixmap,
GLX_FRONT_LEFT_EXT);
if (xlock.gotError()) {
blog(LOG_ERROR,
"cleanup glXReleaseTexImageEXT failed: %s",
xlock.getErrorText().c_str());
xlock.resetError();
}
glXDestroyPixmap(xdisp, p->glxpixmap);
if (xlock.gotError()) {
blog(LOG_ERROR,
"cleanup glXDestroyPixmap failed: %s",
xlock.getErrorText().c_str());
xlock.resetError();
}
p->glxpixmap = 0;
}
2016-02-23 23:16:51 +00:00
gs_texture_destroy(p->gltex);
p->gltex = 0;
}
if (p->pixmap) {
XFreePixmap(xdisp, p->pixmap);
2019-09-22 21:19:10 +00:00
if (xlock.gotError()) {
blog(LOG_ERROR, "cleanup glXDestroyPixmap failed: %s",
xlock.getErrorText().c_str());
xlock.resetError();
}
2016-02-23 23:16:51 +00:00
p->pixmap = 0;
}
if (p->win) {
XCompositeUnredirectWindow(xdisp, p->win,
2019-09-22 21:19:10 +00:00
CompositeRedirectAutomatic);
2016-02-23 23:16:51 +00:00
XSelectInput(xdisp, p->win, 0);
p->win = 0;
}
2019-09-22 21:19:10 +00:00
if (p->tex) {
gs_texture_destroy(p->tex);
p->tex = 0;
}
}
static gs_color_format gs_format_from_tex()
{
GLint iformat = 0;
// consider GL_ARB_internalformat_query
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
&iformat);
// These formats are known to be wrong on Intel platforms. We intentionally
// use swapped internal formats here to preserve historic behavior which
// swapped colors accidentally and because D3D11 would not support a
// GS_RGBX format
switch (iformat) {
case GL_RGB:
return GS_BGRX;
case GL_RGBA:
return GS_RGBA;
default:
return GS_RGBA;
}
2016-02-23 23:16:51 +00:00
}
2019-09-22 21:19:10 +00:00
// from libobs-opengl/gl-subsystem.h because we need to handle GLX modifying textures outside libobs.
struct fb_info;
struct gs_texture {
gs_device_t *device;
enum gs_texture_type type;
enum gs_color_format format;
GLenum gl_format;
GLenum gl_target;
GLenum gl_internal_format;
GLenum gl_type;
GLuint texture;
uint32_t levels;
bool is_dynamic;
bool is_render_target;
bool is_dummy;
bool gen_mipmaps;
gs_samplerstate_t *cur_sampler;
struct fbo_info *fbo;
};
// End shitty hack.
2016-02-23 23:16:51 +00:00
void XCompcapMain::updateSettings(obs_data_t *settings)
{
PLock lock(&p->lock);
ObsGsContextHolder obsctx;
blog(LOG_DEBUG, "Settings updating");
Window prevWin = p->win;
xcc_cleanup(p);
if (settings) {
2019-09-22 21:19:10 +00:00
const char *windowName =
obs_data_get_string(settings, "capture_window");
2016-02-23 23:16:51 +00:00
p->windowName = windowName;
p->win = getWindowFromString(windowName);
p->cut_top = obs_data_get_int(settings, "cut_top");
p->cut_left = obs_data_get_int(settings, "cut_left");
p->cut_right = obs_data_get_int(settings, "cut_right");
p->cut_bot = obs_data_get_int(settings, "cut_bot");
p->lockX = obs_data_get_bool(settings, "lock_x");
p->swapRedBlue = obs_data_get_bool(settings, "swap_redblue");
p->show_cursor = obs_data_get_bool(settings, "show_cursor");
2019-09-22 21:19:10 +00:00
p->include_border =
obs_data_get_bool(settings, "include_border");
2016-05-24 19:53:01 +00:00
p->exclude_alpha = obs_data_get_bool(settings, "exclude_alpha");
2019-07-27 12:47:10 +00:00
p->draw_opaque = false;
2016-02-23 23:16:51 +00:00
} else {
p->win = prevWin;
}
2019-09-22 21:19:10 +00:00
XErrorLock xlock;
2016-08-28 12:07:43 +00:00
if (p->win)
XCompositeRedirectWindow(xdisp, p->win,
2019-09-22 21:19:10 +00:00
CompositeRedirectAutomatic);
2016-02-23 23:16:51 +00:00
if (xlock.gotError()) {
blog(LOG_ERROR, "XCompositeRedirectWindow failed: %s",
2019-09-22 21:19:10 +00:00
xlock.getErrorText().c_str());
2016-02-23 23:16:51 +00:00
return;
}
2016-08-28 12:07:43 +00:00
if (p->win)
2018-02-19 19:54:37 +00:00
XSelectInput(xdisp, p->win,
2019-09-22 21:19:10 +00:00
StructureNotifyMask | ExposureMask |
VisibilityChangeMask);
2016-02-23 23:16:51 +00:00
XSync(xdisp, 0);
XWindowAttributes attr;
2016-08-28 12:07:43 +00:00
if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
2016-02-23 23:16:51 +00:00
p->win = 0;
p->width = 0;
p->height = 0;
return;
}
2016-08-28 12:07:43 +00:00
if (p->win && p->cursor && p->show_cursor) {
2016-02-23 23:16:51 +00:00
Window child;
int x, y;
XTranslateCoordinates(xdisp, p->win, attr.root, 0, 0, &x, &y,
2019-09-22 21:19:10 +00:00
&child);
2016-02-23 23:16:51 +00:00
xcursor_offset(p->cursor, x, y);
}
2019-09-22 21:19:10 +00:00
const int config_attrs[] = {GLX_BIND_TO_TEXTURE_RGBA_EXT,
GL_TRUE,
GLX_DRAWABLE_TYPE,
GLX_PIXMAP_BIT,
GLX_BIND_TO_TEXTURE_TARGETS_EXT,
GLX_TEXTURE_2D_BIT_EXT,
GLX_DOUBLEBUFFER,
GL_FALSE,
None};
2019-07-27 12:47:10 +00:00
int nelem = 0;
2019-09-22 21:19:10 +00:00
GLXFBConfig *configs = glXChooseFBConfig(
xdisp, XCompcap::getRootWindowScreen(attr.root), config_attrs,
&nelem);
2019-07-27 12:47:10 +00:00
2019-09-22 21:19:10 +00:00
bool found = false;
2019-07-27 12:47:10 +00:00
GLXFBConfig config;
for (int i = 0; i < nelem; i++) {
config = configs[i];
XVisualInfo *visual = glXGetVisualFromFBConfig(xdisp, config);
if (!visual)
continue;
2019-09-22 21:19:10 +00:00
if (attr.depth != visual->depth) {
2019-07-27 12:47:10 +00:00
XFree(visual);
continue;
}
XFree(visual);
2019-09-22 21:19:10 +00:00
found = true;
2019-07-27 12:47:10 +00:00
break;
}
2019-09-22 21:19:10 +00:00
if (!found) {
2019-07-27 12:47:10 +00:00
blog(LOG_ERROR, "no matching fb config found");
p->win = 0;
p->height = 0;
p->width = 0;
2019-09-22 21:19:10 +00:00
XFree(configs);
2019-07-27 12:47:10 +00:00
return;
}
2019-09-22 21:19:10 +00:00
if (p->exclude_alpha || attr.depth != 32) {
2019-07-27 12:47:10 +00:00
p->draw_opaque = true;
}
int inverted;
glXGetFBConfigAttrib(xdisp, config, GLX_Y_INVERTED_EXT, &inverted);
p->inverted = inverted != 0;
2016-02-23 23:16:51 +00:00
p->border = attr.border_width;
if (p->include_border) {
p->width = attr.width + p->border * 2;
p->height = attr.height + p->border * 2;
} else {
p->width = attr.width;
p->height = attr.height;
}
if (p->cut_top + p->cut_bot < (int)p->height) {
p->cur_cut_top = p->cut_top;
p->cur_cut_bot = p->cut_bot;
} else {
p->cur_cut_top = 0;
p->cur_cut_bot = 0;
}
if (p->cut_left + p->cut_right < (int)p->width) {
p->cur_cut_left = p->cut_left;
p->cur_cut_right = p->cut_right;
} else {
p->cur_cut_left = 0;
p->cur_cut_right = 0;
}
2019-09-22 21:19:10 +00:00
// Precautionary since we dont error check every GLX call above.
2016-02-23 23:16:51 +00:00
xlock.resetError();
p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);
if (xlock.gotError()) {
blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
2019-09-22 21:19:10 +00:00
xlock.getErrorText().c_str());
2016-02-23 23:16:51 +00:00
p->pixmap = 0;
XFree(configs);
return;
}
2019-09-22 21:19:10 +00:00
// Should be consistent format with config we are using. Since we searched on RGBA lets use RGBA here.
const int pixmap_attrs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT,
GLX_TEXTURE_FORMAT_RGBA_EXT, None};
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
p->glxpixmap = glXCreatePixmap(xdisp, config, p->pixmap, pixmap_attrs);
2016-02-23 23:16:51 +00:00
if (xlock.gotError()) {
blog(LOG_ERROR, "glXCreatePixmap failed: %s",
2019-09-22 21:19:10 +00:00
xlock.getErrorText().c_str());
2016-02-23 23:16:51 +00:00
XFreePixmap(xdisp, p->pixmap);
XFree(configs);
p->pixmap = 0;
p->glxpixmap = 0;
return;
}
XFree(configs);
2019-09-22 21:19:10 +00:00
// Build an OBS texture to bind the pixmap to.
p->gltex = gs_texture_create(p->width, p->height, GS_RGBA, 1, 0,
GS_GL_DUMMYTEX);
GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
2016-02-23 23:16:51 +00:00
glBindTexture(GL_TEXTURE_2D, gltex);
glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
2019-09-22 21:19:10 +00:00
if (xlock.gotError()) {
blog(LOG_ERROR, "glXBindTexImageEXT failed: %s",
xlock.getErrorText().c_str());
XFreePixmap(xdisp, p->pixmap);
XFree(configs);
p->pixmap = 0;
p->glxpixmap = 0;
return;
}
2016-02-23 23:16:51 +00:00
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2019-09-22 21:19:10 +00:00
// glxBindTexImageEXT might modify the textures format.
gs_color_format format = gs_format_from_tex();
glBindTexture(GL_TEXTURE_2D, 0);
// sync OBS texture format based on any glxBindTexImageEXT changes
p->gltex->format = format;
// Create a pure OBS texture to use for rendering. Using the same
// format so we can copy instead of drawing from the source gltex.
if (p->tex)
gs_texture_destroy(p->tex);
p->tex = gs_texture_create(width(), height(), format, 1, 0,
GS_GL_DUMMYTEX);
if (p->swapRedBlue) {
GLuint tex = *(GLuint *)gs_texture_get_obj(p->tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
glBindTexture(GL_TEXTURE_2D, 0);
}
2018-02-19 19:54:37 +00:00
if (!p->windowName.empty()) {
2019-09-22 21:19:10 +00:00
blog(LOG_INFO,
"[window-capture: '%s'] update settings:\n"
"\ttitle: %s\n"
"\tclass: %s\n"
"\tBit depth: %i\n"
"\tFound proper GLXFBConfig (in %i): %s\n",
obs_source_get_name(p->source),
XCompcap::getWindowName(p->win).c_str(),
XCompcap::getWindowClass(p->win).c_str(), attr.depth,
nelem, found ? "yes" : "no");
2018-02-19 19:54:37 +00:00
}
2016-02-23 23:16:51 +00:00
}
void XCompcapMain::tick(float seconds)
{
if (!obs_source_showing(p->source))
return;
PLock lock(&p->lock, true);
if (!lock.isLocked())
return;
XCompcap::processEvents();
2016-08-28 12:07:43 +00:00
if (p->win && XCompcap::windowWasReconfigured(p->win)) {
p->window_check_time = FIND_WINDOW_INTERVAL;
p->win = 0;
}
2016-02-23 23:16:51 +00:00
2016-08-28 12:07:43 +00:00
XDisplayLock xlock;
2016-02-23 23:16:51 +00:00
XWindowAttributes attr;
2016-08-28 12:07:43 +00:00
if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
p->window_check_time += (double)seconds;
if (p->window_check_time < FIND_WINDOW_INTERVAL)
return;
2016-02-23 23:16:51 +00:00
Window newWin = getWindowFromString(p->windowName);
2016-08-28 12:07:43 +00:00
p->window_check_time = 0.0;
if (newWin && XGetWindowAttributes(xdisp, newWin, &attr)) {
2016-02-23 23:16:51 +00:00
p->win = newWin;
updateSettings(0);
2016-08-28 12:07:43 +00:00
} else {
return;
2016-02-23 23:16:51 +00:00
}
}
if (!p->tex || !p->gltex)
return;
obs_enter_graphics();
if (p->lockX) {
2019-09-22 21:19:10 +00:00
// XDisplayLock is still live so we should already be locked.
2016-02-23 23:16:51 +00:00
XLockDisplay(xdisp);
XSync(xdisp, 0);
}
if (p->include_border) {
2019-09-22 21:19:10 +00:00
gs_copy_texture_region(p->tex, 0, 0, p->gltex, p->cur_cut_left,
p->cur_cut_top, width(), height());
2016-02-23 23:16:51 +00:00
} else {
2019-09-22 21:19:10 +00:00
gs_copy_texture_region(p->tex, 0, 0, p->gltex,
p->cur_cut_left + p->border,
p->cur_cut_top + p->border, width(),
height());
2016-02-23 23:16:51 +00:00
}
if (p->cursor && p->show_cursor) {
xcursor_tick(p->cursor);
p->cursor_outside =
2019-09-22 21:19:10 +00:00
p->cursor->x < p->cur_cut_left ||
p->cursor->y < p->cur_cut_top ||
p->cursor->x > int(p->width - p->cur_cut_right) ||
2016-02-23 23:16:51 +00:00
p->cursor->y > int(p->height - p->cur_cut_bot);
}
if (p->lockX)
XUnlockDisplay(xdisp);
obs_leave_graphics();
}
void XCompcapMain::render(gs_effect_t *effect)
{
if (!p->win)
return;
2016-08-28 12:07:43 +00:00
PLock lock(&p->lock, true);
2019-07-27 12:47:10 +00:00
if (p->draw_opaque)
effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
else
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
2016-02-23 23:16:51 +00:00
if (!lock.isLocked() || !p->tex)
return;
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
gs_effect_set_texture(image, p->tex);
while (gs_effect_loop(effect, "Draw")) {
gs_draw_sprite(p->tex, 0, 0, 0);
}
if (p->cursor && p->gltex && p->show_cursor && !p->cursor_outside) {
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
while (gs_effect_loop(effect, "Draw")) {
xcursor_render(p->cursor);
}
}
}
uint32_t XCompcapMain::width()
{
2016-08-28 12:07:43 +00:00
if (!p->win)
return 0;
2016-02-23 23:16:51 +00:00
return p->width - p->cur_cut_left - p->cur_cut_right;
}
uint32_t XCompcapMain::height()
{
2016-08-28 12:07:43 +00:00
if (!p->win)
return 0;
2016-02-23 23:16:51 +00:00
return p->height - p->cur_cut_bot - p->cur_cut_top;
}