xcompcap-main.cpp 16 KB

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