xcompcap-main.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. #include <glad/glad.h>
  2. #include <glad/glad_glx.h>
  3. #include <X11/Xlib.h>
  4. #include <X11/extensions/Xcomposite.h>
  5. #include <pthread.h>
  6. #include <vector>
  7. #include <obs-module.h>
  8. #include <graphics/vec4.h>
  9. #include <util/platform.h>
  10. #include "xcompcap-main.hpp"
  11. #include "xcompcap-helper.hpp"
  12. #include "xcursor.h"
  13. #define xdisp (XCompcap::disp())
  14. #define WIN_STRING_DIV "\r\n"
  15. bool XCompcapMain::init()
  16. {
  17. if (!xdisp) {
  18. blog(LOG_ERROR, "failed opening display");
  19. return false;
  20. }
  21. int eventBase, errorBase;
  22. if (!XCompositeQueryExtension(xdisp, &eventBase, &errorBase)) {
  23. blog(LOG_ERROR, "Xcomposite extension not supported");
  24. return false;
  25. }
  26. int major = 0, minor = 2;
  27. XCompositeQueryVersion(xdisp, &major, &minor);
  28. if (major == 0 && minor < 2) {
  29. blog(LOG_ERROR, "Xcomposite extension is too old: %d.%d < 0.2",
  30. major, minor);
  31. return false;
  32. }
  33. return true;
  34. }
  35. void XCompcapMain::deinit()
  36. {
  37. XCompcap::cleanupDisplay();
  38. }
  39. obs_properties_t *XCompcapMain::properties()
  40. {
  41. obs_properties_t *props = obs_properties_create();
  42. obs_property_t *wins = obs_properties_add_list(
  43. props, "capture_window", obs_module_text("Window"),
  44. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  45. for (Window win : XCompcap::getTopLevelWindows()) {
  46. std::string wname = XCompcap::getWindowName(win);
  47. std::string cls = XCompcap::getWindowClass(win);
  48. std::string winid = std::to_string((long long)win);
  49. std::string desc =
  50. (winid + WIN_STRING_DIV + wname + WIN_STRING_DIV + cls);
  51. obs_property_list_add_string(wins, wname.c_str(), desc.c_str());
  52. }
  53. obs_properties_add_int(props, "cut_top", obs_module_text("CropTop"), 0,
  54. 4096, 1);
  55. obs_properties_add_int(props, "cut_left", obs_module_text("CropLeft"),
  56. 0, 4096, 1);
  57. obs_properties_add_int(props, "cut_right", obs_module_text("CropRight"),
  58. 0, 4096, 1);
  59. obs_properties_add_int(props, "cut_bot", obs_module_text("CropBottom"),
  60. 0, 4096, 1);
  61. obs_properties_add_bool(props, "swap_redblue",
  62. obs_module_text("SwapRedBlue"));
  63. obs_properties_add_bool(props, "lock_x", obs_module_text("LockX"));
  64. obs_properties_add_bool(props, "show_cursor",
  65. obs_module_text("CaptureCursor"));
  66. obs_properties_add_bool(props, "include_border",
  67. obs_module_text("IncludeXBorder"));
  68. obs_properties_add_bool(props, "exclude_alpha",
  69. obs_module_text("ExcludeAlpha"));
  70. return props;
  71. }
  72. void XCompcapMain::defaults(obs_data_t *settings)
  73. {
  74. obs_data_set_default_string(settings, "capture_window", "");
  75. obs_data_set_default_int(settings, "cut_top", 0);
  76. obs_data_set_default_int(settings, "cut_left", 0);
  77. obs_data_set_default_int(settings, "cut_right", 0);
  78. obs_data_set_default_int(settings, "cut_bot", 0);
  79. obs_data_set_default_bool(settings, "swap_redblue", false);
  80. obs_data_set_default_bool(settings, "lock_x", false);
  81. obs_data_set_default_bool(settings, "show_cursor", true);
  82. obs_data_set_default_bool(settings, "include_border", false);
  83. obs_data_set_default_bool(settings, "exclude_alpha", false);
  84. }
  85. #define FIND_WINDOW_INTERVAL 2.0
  86. struct XCompcapMain_private {
  87. XCompcapMain_private()
  88. : win(0),
  89. cut_top(0),
  90. cur_cut_top(0),
  91. cut_left(0),
  92. cur_cut_left(0),
  93. cut_right(0),
  94. cur_cut_right(0),
  95. cut_bot(0),
  96. cur_cut_bot(0),
  97. inverted(false),
  98. width(0),
  99. height(0),
  100. pixmap(0),
  101. glxpixmap(0),
  102. tex(0),
  103. gltex(0)
  104. {
  105. pthread_mutexattr_init(&lockattr);
  106. pthread_mutexattr_settype(&lockattr, PTHREAD_MUTEX_RECURSIVE);
  107. pthread_mutex_init(&lock, &lockattr);
  108. }
  109. ~XCompcapMain_private()
  110. {
  111. pthread_mutex_destroy(&lock);
  112. pthread_mutexattr_destroy(&lockattr);
  113. }
  114. obs_source_t *source;
  115. std::string windowName;
  116. Window win = 0;
  117. int cut_top, cur_cut_top;
  118. int cut_left, cur_cut_left;
  119. int cut_right, cur_cut_right;
  120. int cut_bot, cur_cut_bot;
  121. bool inverted;
  122. bool swapRedBlue;
  123. bool lockX;
  124. bool include_border;
  125. bool exclude_alpha;
  126. bool draw_opaque;
  127. double window_check_time = 0.0;
  128. uint32_t width;
  129. uint32_t height;
  130. uint32_t border;
  131. Pixmap pixmap;
  132. GLXPixmap glxpixmap;
  133. gs_texture_t *tex;
  134. gs_texture_t *gltex;
  135. pthread_mutex_t lock;
  136. pthread_mutexattr_t lockattr;
  137. bool show_cursor = true;
  138. bool cursor_outside = false;
  139. xcursor_t *cursor = nullptr;
  140. };
  141. XCompcapMain::XCompcapMain(obs_data_t *settings, obs_source_t *source)
  142. {
  143. p = new XCompcapMain_private;
  144. p->source = source;
  145. obs_enter_graphics();
  146. p->cursor = xcursor_init(xdisp);
  147. obs_leave_graphics();
  148. updateSettings(settings);
  149. }
  150. static void xcc_cleanup(XCompcapMain_private *p);
  151. XCompcapMain::~XCompcapMain()
  152. {
  153. ObsGsContextHolder obsctx;
  154. if (p->tex) {
  155. gs_texture_destroy(p->tex);
  156. p->tex = 0;
  157. }
  158. xcc_cleanup(p);
  159. if (p->cursor) {
  160. xcursor_destroy(p->cursor);
  161. p->cursor = nullptr;
  162. }
  163. delete p;
  164. }
  165. static Window getWindowFromString(std::string wstr)
  166. {
  167. XErrorLock xlock;
  168. if (wstr == "") {
  169. return XCompcap::getTopLevelWindows().front();
  170. }
  171. if (wstr.substr(0, 4) == "root") {
  172. int i = std::stoi("0" + wstr.substr(4));
  173. return RootWindow(xdisp, i);
  174. }
  175. size_t firstMark = wstr.find(WIN_STRING_DIV);
  176. size_t markSize = strlen(WIN_STRING_DIV);
  177. if (firstMark == std::string::npos)
  178. return (Window)std::stol(wstr);
  179. Window wid = 0;
  180. wstr = wstr.substr(firstMark + markSize);
  181. size_t lastMark = wstr.rfind(WIN_STRING_DIV);
  182. std::string wname = wstr.substr(0, lastMark);
  183. std::string wcls = wstr.substr(lastMark + markSize);
  184. Window matchedNameWin = wid;
  185. for (Window cwin : XCompcap::getTopLevelWindows()) {
  186. std::string cwinname = XCompcap::getWindowName(cwin);
  187. std::string ccls = XCompcap::getWindowClass(cwin);
  188. if (cwin == wid && wname == cwinname && wcls == ccls)
  189. return wid;
  190. if (wname == cwinname ||
  191. (!matchedNameWin && !wcls.empty() && wcls == ccls))
  192. matchedNameWin = cwin;
  193. }
  194. return matchedNameWin;
  195. }
  196. static void xcc_cleanup(XCompcapMain_private *p)
  197. {
  198. PLock lock(&p->lock);
  199. XErrorLock xlock;
  200. if (p->gltex) {
  201. GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
  202. glBindTexture(GL_TEXTURE_2D, gltex);
  203. if (p->glxpixmap) {
  204. glXReleaseTexImageEXT(xdisp, p->glxpixmap,
  205. GLX_FRONT_LEFT_EXT);
  206. if (xlock.gotError()) {
  207. blog(LOG_ERROR,
  208. "cleanup glXReleaseTexImageEXT failed: %s",
  209. xlock.getErrorText().c_str());
  210. xlock.resetError();
  211. }
  212. glXDestroyPixmap(xdisp, p->glxpixmap);
  213. if (xlock.gotError()) {
  214. blog(LOG_ERROR,
  215. "cleanup glXDestroyPixmap failed: %s",
  216. xlock.getErrorText().c_str());
  217. xlock.resetError();
  218. }
  219. p->glxpixmap = 0;
  220. }
  221. gs_texture_destroy(p->gltex);
  222. p->gltex = 0;
  223. }
  224. if (p->pixmap) {
  225. XFreePixmap(xdisp, p->pixmap);
  226. if (xlock.gotError()) {
  227. blog(LOG_ERROR, "cleanup glXDestroyPixmap failed: %s",
  228. xlock.getErrorText().c_str());
  229. xlock.resetError();
  230. }
  231. p->pixmap = 0;
  232. }
  233. if (p->win) {
  234. XCompositeUnredirectWindow(xdisp, p->win,
  235. CompositeRedirectAutomatic);
  236. XSelectInput(xdisp, p->win, 0);
  237. p->win = 0;
  238. }
  239. if (p->tex) {
  240. gs_texture_destroy(p->tex);
  241. p->tex = 0;
  242. }
  243. }
  244. static gs_color_format gs_format_from_tex()
  245. {
  246. GLint iformat = 0;
  247. // consider GL_ARB_internalformat_query
  248. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
  249. &iformat);
  250. // These formats are known to be wrong on Intel platforms. We intentionally
  251. // use swapped internal formats here to preserve historic behavior which
  252. // swapped colors accidentally and because D3D11 would not support a
  253. // GS_RGBX format
  254. switch (iformat) {
  255. case GL_RGB:
  256. return GS_BGRX;
  257. case GL_RGBA:
  258. return GS_RGBA;
  259. default:
  260. return GS_RGBA;
  261. }
  262. }
  263. // from libobs-opengl/gl-subsystem.h because we need to handle GLX modifying textures outside libobs.
  264. struct fb_info;
  265. struct gs_texture {
  266. gs_device_t *device;
  267. enum gs_texture_type type;
  268. enum gs_color_format format;
  269. GLenum gl_format;
  270. GLenum gl_target;
  271. GLenum gl_internal_format;
  272. GLenum gl_type;
  273. GLuint texture;
  274. uint32_t levels;
  275. bool is_dynamic;
  276. bool is_render_target;
  277. bool is_dummy;
  278. bool gen_mipmaps;
  279. gs_samplerstate_t *cur_sampler;
  280. struct fbo_info *fbo;
  281. };
  282. // End shitty hack.
  283. void XCompcapMain::updateSettings(obs_data_t *settings)
  284. {
  285. PLock lock(&p->lock);
  286. ObsGsContextHolder obsctx;
  287. blog(LOG_DEBUG, "Settings updating");
  288. Window prevWin = p->win;
  289. xcc_cleanup(p);
  290. if (settings) {
  291. const char *windowName =
  292. obs_data_get_string(settings, "capture_window");
  293. p->windowName = windowName;
  294. p->win = getWindowFromString(windowName);
  295. p->cut_top = obs_data_get_int(settings, "cut_top");
  296. p->cut_left = obs_data_get_int(settings, "cut_left");
  297. p->cut_right = obs_data_get_int(settings, "cut_right");
  298. p->cut_bot = obs_data_get_int(settings, "cut_bot");
  299. p->lockX = obs_data_get_bool(settings, "lock_x");
  300. p->swapRedBlue = obs_data_get_bool(settings, "swap_redblue");
  301. p->show_cursor = obs_data_get_bool(settings, "show_cursor");
  302. p->include_border =
  303. obs_data_get_bool(settings, "include_border");
  304. p->exclude_alpha = obs_data_get_bool(settings, "exclude_alpha");
  305. p->draw_opaque = false;
  306. } else {
  307. p->win = prevWin;
  308. }
  309. XErrorLock xlock;
  310. if (p->win)
  311. XCompositeRedirectWindow(xdisp, p->win,
  312. CompositeRedirectAutomatic);
  313. if (xlock.gotError()) {
  314. blog(LOG_ERROR, "XCompositeRedirectWindow failed: %s",
  315. xlock.getErrorText().c_str());
  316. return;
  317. }
  318. if (p->win)
  319. XSelectInput(xdisp, p->win,
  320. StructureNotifyMask | ExposureMask |
  321. VisibilityChangeMask);
  322. XSync(xdisp, 0);
  323. XWindowAttributes attr;
  324. if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
  325. p->win = 0;
  326. p->width = 0;
  327. p->height = 0;
  328. return;
  329. }
  330. if (p->win && p->cursor && p->show_cursor) {
  331. Window child;
  332. int x, y;
  333. XTranslateCoordinates(xdisp, p->win, attr.root, 0, 0, &x, &y,
  334. &child);
  335. xcursor_offset(p->cursor, x, y);
  336. }
  337. const int config_attrs[] = {GLX_BIND_TO_TEXTURE_RGBA_EXT,
  338. GL_TRUE,
  339. GLX_DRAWABLE_TYPE,
  340. GLX_PIXMAP_BIT,
  341. GLX_BIND_TO_TEXTURE_TARGETS_EXT,
  342. GLX_TEXTURE_2D_BIT_EXT,
  343. GLX_DOUBLEBUFFER,
  344. GL_FALSE,
  345. None};
  346. int nelem = 0;
  347. GLXFBConfig *configs = glXChooseFBConfig(
  348. xdisp, XCompcap::getRootWindowScreen(attr.root), config_attrs,
  349. &nelem);
  350. bool found = false;
  351. GLXFBConfig config;
  352. for (int i = 0; i < nelem; i++) {
  353. config = configs[i];
  354. XVisualInfo *visual = glXGetVisualFromFBConfig(xdisp, config);
  355. if (!visual)
  356. continue;
  357. if (attr.depth != visual->depth) {
  358. XFree(visual);
  359. continue;
  360. }
  361. XFree(visual);
  362. found = true;
  363. break;
  364. }
  365. if (!found) {
  366. blog(LOG_ERROR, "no matching fb config found");
  367. p->win = 0;
  368. p->height = 0;
  369. p->width = 0;
  370. XFree(configs);
  371. return;
  372. }
  373. if (p->exclude_alpha || attr.depth != 32) {
  374. p->draw_opaque = true;
  375. }
  376. int inverted;
  377. glXGetFBConfigAttrib(xdisp, config, GLX_Y_INVERTED_EXT, &inverted);
  378. p->inverted = inverted != 0;
  379. p->border = attr.border_width;
  380. if (p->include_border) {
  381. p->width = attr.width + p->border * 2;
  382. p->height = attr.height + p->border * 2;
  383. } else {
  384. p->width = attr.width;
  385. p->height = attr.height;
  386. }
  387. if (p->cut_top + p->cut_bot < (int)p->height) {
  388. p->cur_cut_top = p->cut_top;
  389. p->cur_cut_bot = p->cut_bot;
  390. } else {
  391. p->cur_cut_top = 0;
  392. p->cur_cut_bot = 0;
  393. }
  394. if (p->cut_left + p->cut_right < (int)p->width) {
  395. p->cur_cut_left = p->cut_left;
  396. p->cur_cut_right = p->cut_right;
  397. } else {
  398. p->cur_cut_left = 0;
  399. p->cur_cut_right = 0;
  400. }
  401. // Precautionary since we dont error check every GLX call above.
  402. xlock.resetError();
  403. p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);
  404. if (xlock.gotError()) {
  405. blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
  406. xlock.getErrorText().c_str());
  407. p->pixmap = 0;
  408. XFree(configs);
  409. return;
  410. }
  411. // Should be consistent format with config we are using. Since we searched on RGBA lets use RGBA here.
  412. const int pixmap_attrs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
  413. GLX_TEXTURE_FORMAT_EXT,
  414. GLX_TEXTURE_FORMAT_RGBA_EXT, None};
  415. p->glxpixmap = glXCreatePixmap(xdisp, config, p->pixmap, pixmap_attrs);
  416. if (xlock.gotError()) {
  417. blog(LOG_ERROR, "glXCreatePixmap failed: %s",
  418. xlock.getErrorText().c_str());
  419. XFreePixmap(xdisp, p->pixmap);
  420. XFree(configs);
  421. p->pixmap = 0;
  422. p->glxpixmap = 0;
  423. return;
  424. }
  425. XFree(configs);
  426. // Build an OBS texture to bind the pixmap to.
  427. p->gltex = gs_texture_create(p->width, p->height, GS_RGBA, 1, 0,
  428. GS_GL_DUMMYTEX);
  429. GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
  430. glBindTexture(GL_TEXTURE_2D, gltex);
  431. glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
  432. if (xlock.gotError()) {
  433. blog(LOG_ERROR, "glXBindTexImageEXT failed: %s",
  434. xlock.getErrorText().c_str());
  435. XFreePixmap(xdisp, p->pixmap);
  436. XFree(configs);
  437. p->pixmap = 0;
  438. p->glxpixmap = 0;
  439. return;
  440. }
  441. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  442. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  443. // glxBindTexImageEXT might modify the textures format.
  444. gs_color_format format = gs_format_from_tex();
  445. glBindTexture(GL_TEXTURE_2D, 0);
  446. // sync OBS texture format based on any glxBindTexImageEXT changes
  447. p->gltex->format = format;
  448. // Create a pure OBS texture to use for rendering. Using the same
  449. // format so we can copy instead of drawing from the source gltex.
  450. if (p->tex)
  451. gs_texture_destroy(p->tex);
  452. p->tex = gs_texture_create(width(), height(), format, 1, 0,
  453. GS_GL_DUMMYTEX);
  454. if (p->swapRedBlue) {
  455. GLuint tex = *(GLuint *)gs_texture_get_obj(p->tex);
  456. glBindTexture(GL_TEXTURE_2D, tex);
  457. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
  458. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
  459. glBindTexture(GL_TEXTURE_2D, 0);
  460. }
  461. if (!p->windowName.empty()) {
  462. blog(LOG_INFO,
  463. "[window-capture: '%s'] update settings:\n"
  464. "\ttitle: %s\n"
  465. "\tclass: %s\n"
  466. "\tBit depth: %i\n"
  467. "\tFound proper GLXFBConfig (in %i): %s\n",
  468. obs_source_get_name(p->source),
  469. XCompcap::getWindowName(p->win).c_str(),
  470. XCompcap::getWindowClass(p->win).c_str(), attr.depth,
  471. nelem, found ? "yes" : "no");
  472. }
  473. }
  474. void XCompcapMain::tick(float seconds)
  475. {
  476. if (!obs_source_showing(p->source))
  477. return;
  478. PLock lock(&p->lock, true);
  479. if (!lock.isLocked())
  480. return;
  481. XCompcap::processEvents();
  482. if (p->win && XCompcap::windowWasReconfigured(p->win)) {
  483. p->window_check_time = FIND_WINDOW_INTERVAL;
  484. p->win = 0;
  485. }
  486. XDisplayLock xlock;
  487. XWindowAttributes attr;
  488. if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
  489. p->window_check_time += (double)seconds;
  490. if (p->window_check_time < FIND_WINDOW_INTERVAL)
  491. return;
  492. Window newWin = getWindowFromString(p->windowName);
  493. p->window_check_time = 0.0;
  494. if (newWin && XGetWindowAttributes(xdisp, newWin, &attr)) {
  495. p->win = newWin;
  496. updateSettings(0);
  497. } else {
  498. return;
  499. }
  500. }
  501. if (!p->tex || !p->gltex)
  502. return;
  503. obs_enter_graphics();
  504. if (p->lockX) {
  505. // XDisplayLock is still live so we should already be locked.
  506. XLockDisplay(xdisp);
  507. XSync(xdisp, 0);
  508. }
  509. if (p->include_border) {
  510. gs_copy_texture_region(p->tex, 0, 0, p->gltex, p->cur_cut_left,
  511. p->cur_cut_top, width(), height());
  512. } else {
  513. gs_copy_texture_region(p->tex, 0, 0, p->gltex,
  514. p->cur_cut_left + p->border,
  515. p->cur_cut_top + p->border, width(),
  516. height());
  517. }
  518. if (p->cursor && p->show_cursor) {
  519. xcursor_tick(p->cursor);
  520. p->cursor_outside =
  521. p->cursor->x < p->cur_cut_left ||
  522. p->cursor->y < p->cur_cut_top ||
  523. p->cursor->x > int(p->width - p->cur_cut_right) ||
  524. p->cursor->y > int(p->height - p->cur_cut_bot);
  525. }
  526. if (p->lockX)
  527. XUnlockDisplay(xdisp);
  528. obs_leave_graphics();
  529. }
  530. void XCompcapMain::render(gs_effect_t *effect)
  531. {
  532. if (!p->win)
  533. return;
  534. PLock lock(&p->lock, true);
  535. if (p->draw_opaque)
  536. effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
  537. else
  538. effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
  539. if (!lock.isLocked() || !p->tex)
  540. return;
  541. gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
  542. gs_effect_set_texture(image, p->tex);
  543. while (gs_effect_loop(effect, "Draw")) {
  544. gs_draw_sprite(p->tex, 0, 0, 0);
  545. }
  546. if (p->cursor && p->gltex && p->show_cursor && !p->cursor_outside) {
  547. effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
  548. while (gs_effect_loop(effect, "Draw")) {
  549. xcursor_render(p->cursor, -p->cur_cut_left,
  550. -p->cur_cut_top);
  551. }
  552. }
  553. }
  554. uint32_t XCompcapMain::width()
  555. {
  556. if (!p->win)
  557. return 0;
  558. return p->width - p->cur_cut_left - p->cur_cut_right;
  559. }
  560. uint32_t XCompcapMain::height()
  561. {
  562. if (!p->win)
  563. return 0;
  564. return p->height - p->cur_cut_bot - p->cur_cut_top;
  565. }