xcompcap-main.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 0.5
  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. XCompcap::unregisterSource(this);
  156. if (p->tex) {
  157. gs_texture_destroy(p->tex);
  158. p->tex = 0;
  159. }
  160. xcc_cleanup(p);
  161. if (p->cursor) {
  162. xcursor_destroy(p->cursor);
  163. p->cursor = nullptr;
  164. }
  165. delete p;
  166. }
  167. static Window getWindowFromString(std::string wstr)
  168. {
  169. XErrorLock xlock;
  170. if (wstr == "") {
  171. return XCompcap::getTopLevelWindows().front();
  172. }
  173. if (wstr.substr(0, 4) == "root") {
  174. int i = std::stoi("0" + wstr.substr(4));
  175. return RootWindow(xdisp, i);
  176. }
  177. size_t firstMark = wstr.find(WIN_STRING_DIV);
  178. size_t lastMark = wstr.rfind(WIN_STRING_DIV);
  179. size_t markSize = strlen(WIN_STRING_DIV);
  180. // wstr only consists of the window-id
  181. if (firstMark == std::string::npos)
  182. return (Window)std::stol(wstr);
  183. // wstr also contains window-name and window-class
  184. std::string wid = wstr.substr(0, firstMark);
  185. std::string wname = wstr.substr(firstMark + markSize,
  186. lastMark - firstMark - markSize);
  187. std::string wcls = wstr.substr(lastMark + markSize);
  188. Window winById = (Window)std::stol(wid);
  189. // first try to find a match by the window-id
  190. for (Window cwin : XCompcap::getTopLevelWindows()) {
  191. // match by window-id
  192. if (cwin == winById) {
  193. return cwin;
  194. }
  195. }
  196. // then try to find a match by name & class
  197. for (Window cwin : XCompcap::getTopLevelWindows()) {
  198. std::string cwinname = XCompcap::getWindowName(cwin);
  199. std::string ccls = XCompcap::getWindowClass(cwin);
  200. // match by name and class
  201. if (wname == cwinname && wcls == ccls) {
  202. return cwin;
  203. }
  204. }
  205. // no match
  206. blog(LOG_DEBUG, "Did not find Window By ID %s, Name '%s' or Class '%s'",
  207. wid.c_str(), wname.c_str(), wcls.c_str());
  208. return 0;
  209. }
  210. static void xcc_cleanup(XCompcapMain_private *p)
  211. {
  212. PLock lock(&p->lock);
  213. XErrorLock xlock;
  214. if (p->gltex) {
  215. GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
  216. glBindTexture(GL_TEXTURE_2D, gltex);
  217. if (p->glxpixmap) {
  218. glXReleaseTexImageEXT(xdisp, p->glxpixmap,
  219. GLX_FRONT_LEFT_EXT);
  220. if (xlock.gotError()) {
  221. blog(LOG_ERROR,
  222. "cleanup glXReleaseTexImageEXT failed: %s",
  223. xlock.getErrorText().c_str());
  224. xlock.resetError();
  225. }
  226. glXDestroyPixmap(xdisp, p->glxpixmap);
  227. if (xlock.gotError()) {
  228. blog(LOG_ERROR,
  229. "cleanup glXDestroyPixmap failed: %s",
  230. xlock.getErrorText().c_str());
  231. xlock.resetError();
  232. }
  233. p->glxpixmap = 0;
  234. }
  235. gs_texture_destroy(p->gltex);
  236. p->gltex = 0;
  237. }
  238. if (p->pixmap) {
  239. XFreePixmap(xdisp, p->pixmap);
  240. if (xlock.gotError()) {
  241. blog(LOG_ERROR, "cleanup glXDestroyPixmap failed: %s",
  242. xlock.getErrorText().c_str());
  243. xlock.resetError();
  244. }
  245. p->pixmap = 0;
  246. }
  247. if (p->win) {
  248. p->win = 0;
  249. }
  250. if (p->tex) {
  251. gs_texture_destroy(p->tex);
  252. p->tex = 0;
  253. }
  254. }
  255. static gs_color_format gs_format_from_tex()
  256. {
  257. GLint iformat = 0;
  258. // consider GL_ARB_internalformat_query
  259. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
  260. &iformat);
  261. // These formats are known to be wrong on Intel platforms. We intentionally
  262. // use swapped internal formats here to preserve historic behavior which
  263. // swapped colors accidentally and because D3D11 would not support a
  264. // GS_RGBX format
  265. switch (iformat) {
  266. case GL_RGB:
  267. return GS_BGRX_UNORM;
  268. case GL_RGBA:
  269. return GS_RGBA_UNORM;
  270. default:
  271. return GS_RGBA_UNORM;
  272. }
  273. }
  274. // from libobs-opengl/gl-subsystem.h because we need to handle GLX modifying textures outside libobs.
  275. struct fb_info;
  276. struct gs_texture {
  277. gs_device_t *device;
  278. enum gs_texture_type type;
  279. enum gs_color_format format;
  280. GLenum gl_format;
  281. GLenum gl_target;
  282. GLenum gl_internal_format;
  283. GLenum gl_type;
  284. GLuint texture;
  285. uint32_t levels;
  286. bool is_dynamic;
  287. bool is_render_target;
  288. bool is_dummy;
  289. bool gen_mipmaps;
  290. gs_samplerstate_t *cur_sampler;
  291. struct fbo_info *fbo;
  292. };
  293. // End shitty hack.
  294. void XCompcapMain::updateSettings(obs_data_t *settings)
  295. {
  296. ObsGsContextHolder obsctx;
  297. XErrorLock xlock;
  298. PLock lock(&p->lock);
  299. blog(LOG_DEBUG, "Settings updating");
  300. Window prevWin = p->win;
  301. xcc_cleanup(p);
  302. if (settings) {
  303. /* Settings initialized or changed */
  304. const char *windowName =
  305. obs_data_get_string(settings, "capture_window");
  306. p->windowName = windowName;
  307. p->win = getWindowFromString(windowName);
  308. XCompcap::registerSource(this, p->win);
  309. p->cut_top = obs_data_get_int(settings, "cut_top");
  310. p->cut_left = obs_data_get_int(settings, "cut_left");
  311. p->cut_right = obs_data_get_int(settings, "cut_right");
  312. p->cut_bot = obs_data_get_int(settings, "cut_bot");
  313. p->lockX = obs_data_get_bool(settings, "lock_x");
  314. p->swapRedBlue = obs_data_get_bool(settings, "swap_redblue");
  315. p->show_cursor = obs_data_get_bool(settings, "show_cursor");
  316. p->include_border =
  317. obs_data_get_bool(settings, "include_border");
  318. p->exclude_alpha = obs_data_get_bool(settings, "exclude_alpha");
  319. p->draw_opaque = false;
  320. } else {
  321. /* New Window found (stored in p->win), just re-initialize GL-Mapping */
  322. p->win = prevWin;
  323. }
  324. if (xlock.gotError()) {
  325. blog(LOG_ERROR, "registeringSource failed: %s",
  326. xlock.getErrorText().c_str());
  327. return;
  328. }
  329. XSync(xdisp, 0);
  330. XWindowAttributes attr;
  331. if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
  332. p->win = 0;
  333. p->width = 0;
  334. p->height = 0;
  335. return;
  336. }
  337. if (p->win && p->cursor && p->show_cursor) {
  338. Window child;
  339. int x, y;
  340. XTranslateCoordinates(xdisp, p->win, attr.root, 0, 0, &x, &y,
  341. &child);
  342. xcursor_offset(p->cursor, x, y);
  343. }
  344. const int config_attrs[] = {GLX_BIND_TO_TEXTURE_RGBA_EXT,
  345. GL_TRUE,
  346. GLX_DRAWABLE_TYPE,
  347. GLX_PIXMAP_BIT,
  348. GLX_BIND_TO_TEXTURE_TARGETS_EXT,
  349. GLX_TEXTURE_2D_BIT_EXT,
  350. GLX_DOUBLEBUFFER,
  351. GL_FALSE,
  352. None};
  353. int nelem = 0;
  354. GLXFBConfig *configs = glXChooseFBConfig(
  355. xdisp, XCompcap::getRootWindowScreen(attr.root), config_attrs,
  356. &nelem);
  357. bool found = false;
  358. GLXFBConfig config;
  359. for (int i = 0; i < nelem; i++) {
  360. config = configs[i];
  361. XVisualInfo *visual = glXGetVisualFromFBConfig(xdisp, config);
  362. if (!visual)
  363. continue;
  364. if (attr.depth != visual->depth) {
  365. XFree(visual);
  366. continue;
  367. }
  368. XFree(visual);
  369. found = true;
  370. break;
  371. }
  372. if (!found) {
  373. blog(LOG_ERROR, "no matching fb config found");
  374. p->win = 0;
  375. p->height = 0;
  376. p->width = 0;
  377. XFree(configs);
  378. return;
  379. }
  380. if (p->exclude_alpha || attr.depth != 32) {
  381. p->draw_opaque = true;
  382. }
  383. int inverted;
  384. glXGetFBConfigAttrib(xdisp, config, GLX_Y_INVERTED_EXT, &inverted);
  385. p->inverted = inverted != 0;
  386. p->border = attr.border_width;
  387. if (p->include_border) {
  388. p->width = attr.width + p->border * 2;
  389. p->height = attr.height + p->border * 2;
  390. } else {
  391. p->width = attr.width;
  392. p->height = attr.height;
  393. }
  394. if (p->cut_top + p->cut_bot < (int)p->height) {
  395. p->cur_cut_top = p->cut_top;
  396. p->cur_cut_bot = p->cut_bot;
  397. } else {
  398. p->cur_cut_top = 0;
  399. p->cur_cut_bot = 0;
  400. }
  401. if (p->cut_left + p->cut_right < (int)p->width) {
  402. p->cur_cut_left = p->cut_left;
  403. p->cur_cut_right = p->cut_right;
  404. } else {
  405. p->cur_cut_left = 0;
  406. p->cur_cut_right = 0;
  407. }
  408. // Precautionary since we dont error check every GLX call above.
  409. xlock.resetError();
  410. p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);
  411. if (xlock.gotError()) {
  412. blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
  413. xlock.getErrorText().c_str());
  414. p->pixmap = 0;
  415. XFree(configs);
  416. return;
  417. }
  418. // Should be consistent format with config we are using. Since we searched on RGBA lets use RGBA here.
  419. const int pixmap_attrs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
  420. GLX_TEXTURE_FORMAT_EXT,
  421. GLX_TEXTURE_FORMAT_RGBA_EXT, None};
  422. p->glxpixmap = glXCreatePixmap(xdisp, config, p->pixmap, pixmap_attrs);
  423. if (xlock.gotError()) {
  424. blog(LOG_ERROR, "glXCreatePixmap failed: %s",
  425. xlock.getErrorText().c_str());
  426. XFreePixmap(xdisp, p->pixmap);
  427. XFree(configs);
  428. p->pixmap = 0;
  429. p->glxpixmap = 0;
  430. return;
  431. }
  432. XFree(configs);
  433. // Build an OBS texture to bind the pixmap to.
  434. p->gltex = gs_texture_create(p->width, p->height, GS_RGBA_UNORM, 1, 0,
  435. GS_GL_DUMMYTEX);
  436. GLuint gltex = *(GLuint *)gs_texture_get_obj(p->gltex);
  437. glBindTexture(GL_TEXTURE_2D, gltex);
  438. glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
  439. if (xlock.gotError()) {
  440. blog(LOG_ERROR, "glXBindTexImageEXT failed: %s",
  441. xlock.getErrorText().c_str());
  442. XFreePixmap(xdisp, p->pixmap);
  443. XFree(configs);
  444. p->pixmap = 0;
  445. p->glxpixmap = 0;
  446. return;
  447. }
  448. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  449. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  450. // glxBindTexImageEXT might modify the textures format.
  451. gs_color_format format = gs_format_from_tex();
  452. glBindTexture(GL_TEXTURE_2D, 0);
  453. // sync OBS texture format based on any glxBindTexImageEXT changes
  454. p->gltex->format = format;
  455. // Create a pure OBS texture to use for rendering. Using the same
  456. // format so we can copy instead of drawing from the source gltex.
  457. if (p->tex)
  458. gs_texture_destroy(p->tex);
  459. p->tex = gs_texture_create(width(), height(), format, 1, 0,
  460. GS_GL_DUMMYTEX);
  461. if (p->swapRedBlue) {
  462. GLuint tex = *(GLuint *)gs_texture_get_obj(p->tex);
  463. glBindTexture(GL_TEXTURE_2D, tex);
  464. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
  465. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
  466. glBindTexture(GL_TEXTURE_2D, 0);
  467. }
  468. if (!p->windowName.empty()) {
  469. blog(LOG_INFO,
  470. "[window-capture: '%s'] update settings:\n"
  471. "\ttitle: %s\n"
  472. "\tclass: %s\n"
  473. "\tBit depth: %i\n"
  474. "\tFound proper GLXFBConfig (in %i): %s\n",
  475. obs_source_get_name(p->source),
  476. XCompcap::getWindowName(p->win).c_str(),
  477. XCompcap::getWindowClass(p->win).c_str(), attr.depth,
  478. nelem, found ? "yes" : "no");
  479. }
  480. }
  481. void XCompcapMain::tick(float seconds)
  482. {
  483. if (!obs_source_showing(p->source))
  484. return;
  485. // Must be taken before xlock to prevent deadlock on shutdown
  486. ObsGsContextHolder obsctx;
  487. PLock lock(&p->lock, true);
  488. if (!lock.isLocked())
  489. return;
  490. XCompcap::processEvents();
  491. if (p->win && XCompcap::sourceWasReconfigured(this)) {
  492. p->window_check_time = FIND_WINDOW_INTERVAL;
  493. p->win = 0;
  494. }
  495. XDisplayLock xlock;
  496. XWindowAttributes attr;
  497. if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
  498. p->window_check_time += (double)seconds;
  499. if (p->window_check_time < FIND_WINDOW_INTERVAL)
  500. return;
  501. Window newWin = getWindowFromString(p->windowName);
  502. p->window_check_time = 0.0;
  503. if (newWin && XGetWindowAttributes(xdisp, newWin, &attr)) {
  504. p->win = newWin;
  505. XCompcap::registerSource(this, p->win);
  506. updateSettings(0);
  507. } else {
  508. return;
  509. }
  510. }
  511. if (!p->tex || !p->gltex)
  512. return;
  513. if (p->lockX) {
  514. // XDisplayLock is still live so we should already be locked.
  515. XLockDisplay(xdisp);
  516. XSync(xdisp, 0);
  517. }
  518. if (p->include_border) {
  519. gs_copy_texture_region(p->tex, 0, 0, p->gltex, p->cur_cut_left,
  520. p->cur_cut_top, width(), height());
  521. } else {
  522. gs_copy_texture_region(p->tex, 0, 0, p->gltex,
  523. p->cur_cut_left + p->border,
  524. p->cur_cut_top + p->border, width(),
  525. height());
  526. }
  527. if (p->cursor && p->show_cursor) {
  528. xcursor_tick(p->cursor);
  529. p->cursor_outside =
  530. p->cursor->x < p->cur_cut_left ||
  531. p->cursor->y < p->cur_cut_top ||
  532. p->cursor->x > int(p->width - p->cur_cut_right) ||
  533. p->cursor->y > int(p->height - p->cur_cut_bot);
  534. }
  535. if (p->lockX)
  536. XUnlockDisplay(xdisp);
  537. }
  538. void XCompcapMain::render(gs_effect_t *effect)
  539. {
  540. if (!p->win)
  541. return;
  542. PLock lock(&p->lock, true);
  543. if (p->draw_opaque)
  544. effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
  545. else
  546. effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
  547. if (!lock.isLocked() || !p->tex)
  548. return;
  549. gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
  550. gs_effect_set_texture(image, p->tex);
  551. while (gs_effect_loop(effect, "Draw")) {
  552. gs_draw_sprite(p->tex, 0, 0, 0);
  553. }
  554. if (p->cursor && p->gltex && p->show_cursor && !p->cursor_outside) {
  555. effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
  556. while (gs_effect_loop(effect, "Draw")) {
  557. xcursor_render(p->cursor, -p->cur_cut_left,
  558. -p->cur_cut_top);
  559. }
  560. }
  561. }
  562. uint32_t XCompcapMain::width()
  563. {
  564. if (!p->win)
  565. return 0;
  566. return p->width - p->cur_cut_left - p->cur_cut_right;
  567. }
  568. uint32_t XCompcapMain::height()
  569. {
  570. if (!p->win)
  571. return 0;
  572. return p->height - p->cur_cut_bot - p->cur_cut_top;
  573. }