RandR has two sets of screen geometry information:
1. CRTC. These are the physical scanout engines in the hardware
2. Monitors. These are the logical partitions of the screen.
By default, each CRTC gets mapped to a Monitor. However, some monitors
actually require two CRTCs to drive them due to limitations in the
scanout hardware. Users can also create 'virtual' monitors to support
VNC or other systems.
This patch makes the RandR code prefer the Monitor mechanism to the
older CRTC mechanism. If the server doesn't support a new enough RandR
version, the existing CRTC code is used instead.
The name of the monitor is also provided in place of the arbitrary
number to help users select the desired source.
Signed-off-by: Keith Packard <keithp@keithp.com>
When cropping the left or top of a window capture, OBS would misalign
the drawn cursor, placing it as if the entire window were being
captured. Instead, offset the captured cursor by the same number of
pixels, thus placing the cursor back where it belongs.
Move xlock after initial window listing
- XErrorLock uses static fields so when you use them recursively
they collide and do weird things. This keeps the two xlocks from
colliding.
Build obs textures based on returned pixmap texture types to ensure
compatibility during copies. (prevents glCopyImageSubData failed due to
texture incompatibilities)
Fix alpha check by using pixmap depth instead of checking channel sizes
(wrong on nvidia and maybe amd hardware)
Fix X error checking, now you will get 1 BadAlloc when pixmap allocation
fails instead "glCopyImageSubData failed" every frame. (occurs on Gnome
under special circumstances)
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed. Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
Rather than inheriting the exact visuals from the window,
find whether the color buffer has alpha, find a config with
the necessary attributes for capture, and match its depth to
the depth of the window instead of the color buffer. Also,
cleanup glxpixmap texture binding before destroying the texture.
Update: Style conformancy changes
Previously toggled swapRedBlue every update regardless of settings being set, which resulted in
moving or resizing of windows causing undesired color-swapping behavior. Also now use more direct
method of comparing visualIDs without type-casting and base the glxpixmap attributes on texture
format being used rather than the bit-depth of the window.
Adds support for windows with alpha channels as well as swapping red
and blue when using GS_BGRX. glXFBConfig now attempts to inherit
its format from the captured window when possible.
Change log message
Some window managers like i3 don't issue Expose events when switching
between workspaces, but send VisibilityNotify events. This causes the
stream to freeze even when the workspace is switched back.
Related issue: #863
It seems that it is not possible to create multiple OpenGL textures
for the same window. When sources are duplicated in studio mode this
causes window capture sources to become black. The
OBS_SOURCE_DO_NOT_DUPLICATE flag prevents that this happens.
If window capture fails to find a window with a matching title, search
for a window with the same window class additionally as a backup.
Replaces the third part of the internal window string with the class
name instead of the program path due to the fact that the program path
rarely seemed to work.
The xcomposite window capture crashes were due to a few factors:
-------------------------------
1.) The source's X error handler was possibly being overwritten by
another part of the program despite us locking the display, presumably
something in Qt which isn't locking the display when pushing/popping its
own error handler (though this is not yet certain). The source's calls
to X functions happen in the graphics thread, which is separate from the
UI thread, and it was noticed that somehow the error handler would be
overwritten almost seemingly at random, indicating that something else
in the program outside of OBS code was not locking the display while
pushing/popping the error handler.
To replicate this, make it so that the source cannot find the target
window and so it continually searches for it each video_tick call, then
resize the main OBS window continually (which causes Qt to push/pop its
own error handlers). A crash will almost always occur due to BadWindow
despite our error handling.
2.) Calling X functions with a window ID that no longer exists,
particularly XGetWindowAttributes, in conjunction the unknown error
handler set in case #1 would cause the program to outright crash because
that error handler is programmed to crash on BadWindow for whatever
reason. The source would call X functions without even checking if
'win' was 0.
3.) The source stored window IDs (in JSON, even if they've long since
become invalid/pointless, such as system restarts). This is a bad
practice and will result in more cases of BadWindow.
Fixing the problem (reducing the possibility of getting BadWindow):
-------------------------------
Step 1.) Deprecate and ignore window IDs in stored settings. Instead of
using window IDs to find the window, we now must always search the
windows and find the target window via the window name exclusively.
This helps ensure that we actually consistently have a working window
ID.
Step 2.) Do not call any X functions if the window ID is 0.
Step 3.) Reset the window ID to 0 any time the window has updated, and
make the source find the window again to ensure it still exists before
attempting to use any X functions on the window ID again.
This is to work around a Mesa issue that prevents copying
between RGB and RGBA textures. Other drivers seem to allow
this, even though it's technically not allowed by the GL
spec.
Closesjp9000/obs-studio#514