0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00
Commit Graph

172 Commits

Author SHA1 Message Date
Jim
665180350d
Merge pull request #2657 from hselasky/improvement
libobs: Implement and use better scaling function for 64-bit integers
2020-05-21 18:07:53 -07:00
Exeldro
74b9ae07f3 libobs: Don't allow duplicating scene sources 2020-04-17 12:40:25 +02:00
Hans Petter Selasky
0e4ea14ba1 libobs: Implement and use better scaling function for 64-bit integers
As os_gettime_ns() gets large the current scaling methods, mostly by casting
to uint64_t, may lead to numerical overflows. Sweep the code and use
util_mul_div64() where applicable.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
2020-04-05 20:27:28 +02:00
Richard Stanway
4dfb572547 libobs: Check return value from obs_scene_add_internal
Errors in obs_scene_add_internal would cause a crash as the null item is
passed to various signal handlers.
2020-03-12 00:02:46 +01:00
jp9000
3992bd247c libobs: Fix groups not being recognized as groups
The id of the source was being pointer compared rather than string
compared, so naturally with the source versioning system where the
string is duplicated, the pointers no longer matched.
2020-03-09 17:08:51 -07:00
jp9000
476c332a41 libobs: Compare scene/group ids by strcmp 2020-03-09 05:57:01 -07:00
jp9000
6970cc32c2 libobs: Remove unused variable 2020-02-12 18:31:18 -08:00
jp9000
94d4bfdb1c libobs: Restore order 2020-02-09 18:36:58 -08:00
Ilya Melamed
9f035e430c libobs: fix obs_sceneitem_group_XXX_item API
`obs_sceneitem_group_add_item` and `obs_Sceneitem_group_remove_item`
were leaving the affected scene in an inconsistent state.

To resolve, simplify and make the code more readable, we replace the
manual linked lists mutation with existing `detach_sceneitem` and
`attach_sceneitem` calls.
2020-02-08 13:17:02 +02:00
jp9000
99e639015f libobs: Add group functions that can signal refresh
Adds API:
obs_scene_add_group2
obs_scene_insert_group2
obs_sceneitem_group_ungroup2

These functions should be used by plugins if they need to use these
functions and need to send a refresh signal.  If a major API rework ever
happens the old functions should be removed.  The old functions should
eventually be deprecated.

The reason why specifying a 'signal' parameter is useful is because it's
a bit more seamless for the user interface to be able to have custom
handling of these specific cases.  It looks better and doesn't require
completely erasing/recreating the entire list, which is visually
unappealing.
2020-02-07 16:45:04 -08:00
jp9000
93e2aa1d00 libobs: Make group subitem add/remove funcs signal refresh
Fixes a bug where the UI would not know that a group had been updated.
2020-02-07 16:44:48 -08:00
jp9000
6d0ef75663 libobs: Add refresh signal to scenes
This signal is used to specify when a scene needs a full refresh of its
item list.
2020-02-07 16:35:20 -08:00
jp9000
3aa08c4e0f libobs: Add obs_scene_find_source_recursive
Same as obs_scene_find_source but also searches groups within the scene.
2020-01-27 14:36:53 -08:00
jp9000
3ef5393d42 libobs: Call debug marker after null check, not before 2019-08-29 21:46:13 -07:00
jp9000
7e77294eed libobs: Don't render scene item texture if it's null 2019-08-29 21:44:34 -07:00
jpark37
2c6aac32c8 libobs: Fix benign typo 2019-07-25 21:54:23 -07:00
jpark37
85cc7c84bc libobs: obs-filters: Area upscale shader
Add a separate shader for area upscaling to take advantage of bilinear
filtering. Iterating over texels is unnecessary in the upscale case
because a target pixel can only overlap 1 or 2 texels in X and Y
directions. When only overlapping one texel, adjust UVs to sample texel
center to avoid filtering.

Also add "base_dimension" uniform to avoid unnecessary division.

Intel HD Graphics 530, 644x478 -> 1323x1080: ~836 us -> ~232 us
2019-07-17 21:11:18 -07:00
jp9000
f53df7da64 clang-format: Apply formatting
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.
2019-06-23 23:49:10 -07:00
Chris Angelico
2fe641b8a4 libobs, UI: Implement item_locked event
Similar to item_visible, this event fires whenever a scene item is
locked or unlocked. This allows the UI and libobs to remain in sync
regarding scene elements' statuses.
2019-06-15 16:09:10 -07:00
James Park
ba21fb947e libobs: Fix various alpha issues
There are cases where alpha is multiplied unnecessarily. This change
attempts to use premultiplied alpha blending for composition.

To keep this change simple, The filter chain will continue to use
straight alpha. Otherwise, every source would need to modified to output
premultiplied, and every filter modified for premultiplied input.

"DrawAlphaDivide" shader techniques have been added to convert from
premultiplied alpha to straight alpha for final output. "DrawMatrix"
techniques ignore alpha, so they do not appear to need changing.

One remaining issue is that scale effects are set up here to use the
same shader logic for both scale filters (straight alpha - incorrectly),
and output composition (premultiplied alpha - correctly). A fix could be
made to add additional shaders for straight alpha, but the "real" fix
may be to eliminate the straight alpha path at some point.

For graphics, SrcBlendAlpha and DestBlendAlpha were both ONE, and could
combine together to form alpha values greater than one. This is not as
noticeable of a problem for UNORM targets because the channels are
clamped, but it will likely become a problem in more situations if FLOAT
targets are used.

This change switches DestBlendAlpha to INVSRCALPHA. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.

obs-transitions: Use premultiplied alpha blend, and simplify shaders
because both inputs and outputs use premultiplied alpha now.

Fixes https://obsproject.com/mantis/view.php?id=1108
2019-05-08 20:26:52 -07:00
jp9000
f109d1c2bf Revert "libobs: libobs-d3d11: obs-filters: No excess alpha"
This reverts commit d91bd327d7, which
broke alpha with sources, scenes, and filter, causing them all to become
opaque unintentionally.
2019-04-25 08:36:41 -07:00
James Park
e01fcae133 libobs: UI: Fix rotated line scale
The line drawing functions previously assumed the upper-left 3x3 for
box_transform only held scale. The matrix can also hold rotation, so
pass in scale separately.

Fixes https://obsproject.com/mantis/view.php?id=1442
2019-04-19 06:35:42 -07:00
Jim
f1399b6d18
Merge pull request #1765 from jpark37/blend-alpha
libobs: libobs-d3d11: Fix blend alpha overflow
2019-04-14 00:22:20 -07:00
James Park
21f4dd63d4 libobs: UI: Use graphics debug markers
Add D3D/GL debug markers to make RenderDoc captures easier to tranverse.

Also add obs_source_get_name_no_null() to avoid boilerplate for safe
string formatting.

Closes obsproject/obs-studio#1799
2019-04-08 02:05:37 -07:00
James Park
d91bd327d7 libobs: libobs-d3d11: obs-filters: No excess alpha
Currently SrcBlendAlpha and DestBlendAlpha are both ONE, and can
combine together to form two. This is not a noticeable problem for
UNORM targets because the channels are clamped, but it will likely
become a problem if FLOAT targets are more widely used.

This change switches DestBlendAlpha to INVSRCALPHA, and starts
backgrounds as opaque black instead of transparent black. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.
2019-04-07 18:16:56 -07:00
James Park
c4819678c9 libobs: Fix and simplify Area scale filter
It appears there's a projection flip that is applied in some situations,
like the preview pane in studio mode, and the shader math fails when
it's active causing the output color to be zero. This fixes the math for
GLSL (with a tiny redundancy penalty to HLSL), and cleans up some
unnecessary code along the way.

Use abs() to avoid zero area in case the OpenGL projection flip is
active. Also simplify the math, and remove the unnecessary sampler
state.
2019-04-04 08:39:54 -07:00
James Park
7d811499e0 Add "Area" scale filter
This new scale filter computes pixels by weighing the coverage area of
source pixels over the target pixel. This algorithm works well for both
upsampling and downsampling, but was mainly designed to upscale
high-quality low-resolution sources like RGB/HDMI retro consoles. I've
heard of people using odd workarounds like scaling up to very high
resolutions before scaling back down to preserve pixel shartpness. This
algorithm directly addresses this use-case in a much more direct
fashion.

The Area scale filter does a better job of preserving the thickness of
thin features than the Point filter.

The Area scale filter does not look at source pixels that lie outside
of the target pixel, leading to a much sharper image than Bilinear,
Bicubic, and Lanczos filters.

This filter should interpolate pixels in linear space, but OBS is not
equipped to do that at the moment.

libobs: Add GPU effect, and wire up scene serialization.

obs-filters: Add Area as an option for scale_filter.

UI: Add Area as an option for both scene items, and canvas downscaling.
2019-03-06 20:53:15 -08:00
jp9000
e6dd009386 libobs: Add function to force a sceneitem transform update
Useful when you need to modify transform properties of group sub-items
and have the transform available immediately (group sub-items always
automatically defer their transform update to the next frame).
2018-08-16 08:42:19 -07:00
jp9000
7afe99188e libobs: Fix applying group transform of flipped sources
Fixes a bug where sources that are flipped vertically and/or
horizontally would not maintain their flipped state.
2018-08-15 10:02:05 -07:00
jp9000
caceb62328 libobs: Initialize hotkey pair ID variable properly
The value of 0 can represent a valid hotkey ID, so make sure that when
we initialize a hotkey variable, that we use OBS_INVALID_HOTKEY_ID or
OBS_INVALID_HOTKEY_PAIR_ID and not 0.

This fixes a bug where scene item hotkey pair IDs would be initialized
to 0, and it would unregister valid unrelated hotkeys.  Particularly,
the start/stop streaming hotkey pair ID, which would commonly be the
first hotkey pair created, thus having the hotkey pair ID of 0.  The
start/streaming hotkey pair would unintentionally be unregistered via
code in obs-scene.c.
2018-08-14 13:06:05 -07:00
Richard Stanway
750f0f2ea4
libobs: Remove unnecessary null check 2018-08-11 01:56:08 +02:00
jp9000
8e5a618f03 libobs: When ungrouping groups, duplicate items
Because groups can now be used in multiple scenes at once, it's
important that if the user wishes to ungroup a group, that they must be
able to keep the group intact if it exists in other scenes.  This
requires duplicating all scene items (as well as their hotkey/private
data) instead of just reparenting the subitems.

This fixes an issue where if the user had the group referenced in
multiple scenes, the group would become empty in other scenes.
2018-08-05 04:21:42 -07:00
jp9000
ef40100c64 libobs: Add internal function to dup. scene item data
Adds an internal function to duplicate scene item data.
2018-08-05 04:21:42 -07:00
jp9000
d13bbe6e59 libobs: Always try to update transform in current thread
Due to the recent change in which scene items now only update their
transforms during the next frame's tick, snapping sources would
sometimes jitter and have incorrect snapping.  This fixes that issue by
reverting to the behavior of updating the transform immediately rather
than deferring the update to the next frame tick, but only on non-group
items.

This should not be done on items that are sub-items of groups because we
rely on the obs_scene_item::update_transform variable to update the
parent group's transform in addition.
2018-07-24 02:41:31 -07:00
jp9000
593345a3b1 libobs: Only update scene item texture on frame tick
Instead of updating the scene item texture any time
update_item_transform() is called, only update it when
obs_scene_item::update_transform is called.  Prevents having to lock the
graphics mutex needlessly.
2018-07-24 02:41:31 -07:00
jp9000
8741bfcb8f libobs: Don't assign variables before if/return 2018-07-24 02:41:31 -07:00
jp9000
d11b05a83d libobs: Defer update of scene item texture
If the scene item crop/filtering is updated, instead of
creating/destroying the item texture on the spot, update it in the
graphics thread to prevent potential race conditions (especially when
the crop function for example could be called from within
obs_scene_enum_items in some situations, which would lock the graphics
and scene mutexes in the wrong order).
2018-07-19 00:53:30 -07:00
jp9000
5dfab20a46 libobs: Allow group duplication 2018-07-16 19:03:34 -07:00
jp9000
5993834815 libobs: Change groups to actual public types
(This commit also modifies UI)

Changes groups to their own independent type, "group".  This allows them
to be used like other regular types, and allows the ability to reference
groups in multiple scenes.  Before, a group would always be linked to
the scene it was in.  This made it cumbersome for users to modify groups
if they had a similar group in multiple scenes (they would have to
modify each group in each scene).  Making groups like other source types
makes more sense to solve this issue so they can be referenced in
multiple scenes at once.  This also removes a significant amount of
group-specific handling code required for implementing groups in the
front-end.

One limitation however: due to the way sub-items of groups are
seamlessly modifiable and sortable as part of the whole scene, the user
cannot have multiple references to the same group within one scene.
2018-07-16 19:01:51 -07:00
jp9000
f45247d5c8 libobs: Abstract resize_group to resize_scene_base 2018-07-15 19:01:34 -07:00
jp9000
8f786db5f2 libobs: Refactor creation of scenes
Allows using a different source type (I.E. "group" instead of "scene").
2018-07-15 19:01:28 -07:00
jp9000
35704c4c04 libobs: Remove group_sceneitem from obs_scene struct
(This commit also modifies UI)

Removes obs_scene::group_sceneitem and replaces it with
obs_scene::is_group.  Changes a number of other functions related to
groups so that a group is not inherently tied to a specific scene, and
helps allow a single group to be referenced in multiple scenes if
desired.
2018-07-15 19:01:14 -07:00
Hunter L. Allen
f838585b03 libobs: Remove unused variable 2018-07-01 12:03:26 -04:00
Hunter L. Allen
b797b97bf6 libobs: Remove unused variable 2018-07-01 12:03:22 -04:00
Hunter L. Allen
31ad26ac3c libobs: Fix equality check
Removes a likely unintentional self-comparison.
2018-07-01 12:03:12 -04:00
Hunter L. Allen
6766565928 libobs: Add missing return type
As declared, transform_val is static inline, but it should be marked as
a static inline void since it does not return.
2018-07-01 12:01:47 -04:00
Hunter L. Allen
f78a5426be libobs: Remove unused variable 2018-07-01 12:01:00 -04:00
vokama
4c73e5f6c5 libobs: Update hotkey label on scene item rename 2018-06-05 01:24:42 +03:00
jp9000
26d5560da3 libobs: Add scene item grouping
Allows the ability to group scene items.  Groups internally are
sub-scenes, which allows the ability to add unique filters and
transforms to each group.
2018-06-03 15:04:39 -07:00
jp9000
690f738a76 libobs: Add custom size support to scenes
Allows scenes to have a custom size.  Mainly used for grouping, but can
be extended with public API later.
2018-06-03 15:04:39 -07:00