Skip to content

obs-core: Port the canvas flag rules - #2546

Merged
zackees merged 7 commits into
masterfrom
fix/rust-port-canvas-flag-rules-and-187
Oct 27, 2026
Merged

zackees merged 7 commits into
masterfrom
fix/rust-port-canvas-flag-rules-and-187

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2544

What and why

Ports the flag rules and setter checks of libobs/obs-canvas.c.h to rust/obs-core, as a new module canvas_rules, next to canvas_draw. Every canvas goes through them: the main canvas, the canvases plugins and the frontend create, the canvases a scene collection loads, and every scene that joins or leaves one.

  • the constructors' flags: MAIN | PROGRAM for the main canvas, and the public mask of obs_canvas_create(), obs_canvas_create_private() and obs_load_canvas();
  • obs_canvas_create_internal() and obs_canvas_reset_video_internal(): the view type (ACTIVATE) and the mix's mix_audio;
  • the public canvas rule: a canvas that is not private is named, unnamed, renamed through the hash table and signalled on the core signal handler;
  • SCENE_REF: whether the canvas holds a reference to each scene in it (obs_canvas_destroy(), _insert_source(), _remove_source());
  • obs_save_canvas(), obs_canvas_has_valid_video_info(), obs_canvas_reset_video(), obs_canvas_rename_source(), obs_canvas_set_channel(), obs_canvas_set_name(), obs_canvas_remove() and obs_canvas_removed(): their refusals and flag checks.

One function per decision, asked where the C made it. canvas->flags is read without a lock and obs_canvas_remove() writes it from any thread, so each check gets the value of its own read, at its point. A check behind a || or && is still asked only where the C reached it: obs_source_is_scene() only on a SCENE_REF canvas, obs_video_active() only for a canvas that may reset, strcmp() only for a canvas that may be renamed, each video info field only after the one before it was set. Seventeen functions cross the C ABI, all hidden.

What stays C, at its point: the allocations and frees, the context data calls, the signal handler setup, the mutexes, the view, the mix and its list under mixes_mutex, HASH_CLEAR and the destroy walk that takes next before each release (the #2038 and #2049 order), every reference and weak reference, the pointer checks, the group walk, the calldata, every signal (a channel_change handler can still replace the source, stored without a new reference), obs_source_activate()/_deactivate(), strcmp(), obs_video_active() and every log. obs_load_canvas() keeps its (uint32_t) cast of the saved int64.

Seven commits:

  1. Move (behaviour-neutral, 882ab259b): the decisions go to libobs/obs-canvas-rules.c.h, declared in the new obs-canvas-rules.h without EXPORT. The header copies the flag values, REMOVED, the public mask, VIDEO_FORMAT_NONE and MAX_CHANNELS, and obs-canvas.c.h checks them with _Static_assert. The file joins libobs.core-source.

    The move was checked against the original code. A scratch harness (not committed) compiles origin/master's obs-canvas.c.h verbatim and this branch's with the moved file, over a stand-in libobs.pch.h that logs every call in order with its arguments (context data, signal setup, mutexes, view, mix and its list, HASH_CLEAR, every signal with its calldata, strong and weak references, the source calls, obs_video_active(), the scene walks, the obs_data calls, blog()); several of them may fail. A concurrent writer may flip any flag bit, the private flag or a video info field of any live canvas at any call, and a channel_change handler may replace the source. Each run makes up to sixteen random calls across the whole canvas API, then tears down as obs_free_data() does. The C++ build also logs every read and write of the flags, the private flag and the video info fields.

    • 6,600,000 runs: GCC and Clang at -O0 and -O2 as C, 1,000,000 each (67,558,889 logged lines each side); G++ at -O0 and -O2 as C++ with the logged reads, 1,000,000 each (95,351,694 each side); ASan and UBSan with no recovery, 200,000 each (GCC -O0, Clang -O2, G++ -O1). The logs are identical in every configuration.
    • gcov takes every branch of the moved decisions both ways, except two no caller reaches (canvas_dosignal() with no core signal name, and obs_canvas_remove() failing to take a reference its caller holds).
    • 34 deliberately broken moves were planted (each rule changed, and every read moved: the destroy walk reading the flags once, obs_video_active() or obs_source_is_scene() asked before the flags, a video info field read early, strcmp() before the MAIN check, the flags read before a canvas signal, the remove check after the reference, the private flag read once, a second read in save). The C++ build fails all 34.
  2. Characterization (19e822006): test_canvas_rules_steps, 11 cases over every combination of the known flags, REMOVED and an unknown bit, every single bit, the load cast, the kinds of canvas, the video info checks, the channel bound, the empty name and removing twice. Passes 11/11 on the C backend and the hybrid.

  3. RED (10aa29a5a): Tier 1 against todo!(); ports the 11 C cases 1:1 and adds 3 proptests over any flags, any saved int64 and any size, format, channel, name byte and private flag.

  4. GREEN (1dc1284ff): the safe core (seventeen functions; it denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock) and seventeen #[no_mangle] shims, in a new libobs.ported-canvas-rules group whose PCH is only the new header. The one pointer is obs_canvas_set_name()'s name: the shim reads its first byte only when it is not NULL. The commit registers the group in its own fragment, libobs/build/ported-source-sets/canvas-rules.json, and updates source-sets.json (the header), the unity lists, the three export lists and ci/test_ported_sources.py. test_canvas_rules_steps has no _rust variant, as for test_canvas_draw_steps: linking it against libobs_rust-static fails with 401 undefined references (108 symbols), because the shims' archive member also holds the rest of obs-core. Its tests.d file says so.

  5. Tier 3 (4d80e4b10): a C oracle of the unchanged file and 7 parity tests that compare shim, C and core byte for byte: every low 16-bit flags word under 16 high words, every combination of the known flags, REMOVED and an unknown bit, 786,432 saved int64 values, sizes, channels and formats around their bounds, NULL and every first byte of a name, each caller's decisions in their order, and proptests (20,000 cases each). Mutation check: 36 mutants (24 in the core, 12 in the shims); 34 fail. The two survivors are equivalent: the resets shim calling renames() (both are "not MAIN"), and the name shim passing a zero byte for NULL (both are empty). The commit message lists each mutant and the tests that catch it.

  6. Docs (254ab94a2): the rust/README.md rows, the crate description and lib.rs docs, the naming.md row, and a port_comparison bench (canvas_rules/create and /setters; create 7.8 µs Rust and 5.4 µs C, setters 16.7 µs Rust and 11.4 µs C per 1024 calls, about 2 to 5 ns more per decision through the exported shims; none of these runs per frame). It allocates nothing, so the per-module allocation check holds; the bench's build.rs finds it in the directory.

  7. Caller characterization (737e1dbfe, from review): test_canvas_rules_callers, 9 cases through the real libobs and its public API, so it runs unchanged against the C backend, the hybrid and libobs-c-reference. It pins what the callers do with the rules: the flags each constructor keeps and what obs_save_canvas() writes or refuses; obs_canvas_reset_video() refusing no video info, the main canvas and active video (a raw video callback on the main mix); obs_canvas_set_name()'s refusals (NULL, "", the same name, the main canvas) and its public and private renames; removing twice; the SCENE_REF rule for a scene, a group and a plain source, and the group walk (a removed group leaves every scene of its canvas, a removed plain source's items stay); the main canvas's global source_rename; and a channel_change handler replacing the source (stored and activated without a reference of its own, and the reference on the source passed in kept: characterized, not endorsed). Linux with OpenGL, graphics suite, under xvfb-run like test_main_mix_before_video. Passes 9/9 on all three.

The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference, the same set as master, with the seventeen functions local in all three. The port changes nothing a user can see, so docs/features.md has no line.

  • Kept, characterized, not endorsed (current behaviour, unchanged): a saved flags value above 32 bits or negative keeps the public flags of its low word, since the int64 is truncated before the mask (-1 loads as every public flag); a video format outside the enum counts as set; a removed canvas can still be reset and renamed.

Upstream's canvases are Dennis Sädtler's work (with tt2468's public-canvas signal rule); the public mask is this fork's (#2151). No upstream issue.

RED → GREEN

  • RED commit: 10aa29a5a. soldr cargo test -p obs-data --test obs-tests-core -- canvas_rules:: passes 1 of 14 (steps_constants) and fails 13 with "not yet implemented". The local gates on it: --lane lint ok; --test-diff origin/master runs 4589 tests, 4576 pass, 13 fail (exactly those), 6 skipped. Runs were on bf9954507.
  • GREEN: Tier 1 canvas_rules:: 14/14; Tier 3 canvas_rules_parity:: 7/7.
    • Tier 2 on the C backend and the hybrid: the full ctest suite, 584 tests each, 9 skipped each (hardware and portal tests). The run had no display, so two tests failed at obs_startup (test_v4l2_busy_signal, test_output_deactivate_state); both pass on each build under a private Xvfb. The canvas tests (test_canvas_rules_steps, test_canvas_flags, test_scene_private_canvas, test_canvas_destroy_scene_refs, test_shutdown_canvas_weak_ref, test_scene_canvas_characterization, test_context_names, test_view) pass on both. test_canvas_rules_callers passes 9/9 on the C backend and the hybrid (three runs in a row each) and against libobs-c-reference, under a private Xvfb.
    • Tier 2 against libobs-c-reference (./unittest's Docker lane) could not run on this host (no Docker access), so PR CI runs it. Its Rust lane passed.
    • Gates: --test-diff origin/master 4596 run, 4596 passed, 6 skipped; --lane lint ok; --lane cross ok; soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings clean; soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes.
    • --test-diff origin/master and --lane lint again on 873552f85: 4596 run, 4596 passed, 6 skipped; lint ok.
    • Runs were on 401b6e798 and 873552f85, on top of fe410a975.
    • After the rebase onto a9344844b (the output stop port in the same shared lists, merged keeping both sides): the CI quick checks, ./lint, --lane lint, --lane cross, the Windows clippy, the port_comparison bench test and the Rust lane of ./unittest (4629 run, 4629 passed, 6 skipped) pass; the export sets are again 1766 and equal on all three with the seventeen functions local; the canvas tests, test_canvas_rules_steps and test_canvas_rules_callers included, pass on the C backend and the hybrid. Runs were on 45e4a4332.
    • After the rebase onto 09f435a55 (master's per-port ported-source-sets/ fragments and generated port_comparison list, build: Let each port register its source groups independently (#1997) #2552 and build: Generate the port_comparison unit list from the directory (#1997) #2554): port_comparison.rs is master's again (the bench is found in the directory), and the group moved into its own fragment. The CI quick checks, ./lint, --lane cross, the Windows clippy, the port_comparison bench test and --test-diff origin/master (4629 run, 4629 passed, 6 skipped) pass. Built with master's new backend switches (OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON), the export sets are 1766 and equal on all three, the seventeen functions local; the hybrid's come from Rust and the group's object is built only for the C backend and libobs-c-reference. Runs were on 737e1dbfe.
    • The local gate could not stamp the head: its Tier 2 lane needs Docker, which this host cannot reach without sudo, so PR CI runs the full suite.
  • Real app (UI, protocol output or logging changes): not applicable, a port with no change in behaviour.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none

@rdoupe
rdoupe force-pushed the fix/rust-port-canvas-flag-rules-and-187 branch from bf99545 to 45e4a43 Compare October 27, 2026 03:03
@rdoupe
rdoupe marked this pull request as ready for review October 27, 2026 03:54
@rdoupe
rdoupe requested a review from zackees as a code owner October 27, 2026 03:54
Behaviour-neutral extraction before the Rust port. The flag rules and
setter checks of obs-canvas.c.h move to libobs/obs-canvas-rules.c.h,
as seventeen functions on plain values declared in the new
libobs/obs-canvas-rules.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- _main_flags() and _public_flags(): MAIN | PROGRAM for
  obs_create_main_canvas(), and the public mask of obs_canvas_create(),
  obs_canvas_create_private() and obs_load_canvas(), which still casts
  the saved int64 to uint32_t itself;
- _main_view() and _mix_audio(): the view type and the mix's
  mix_audio, in obs_canvas_create_internal() and
  obs_canvas_reset_video_internal();
- _public(): a canvas that is not private is named, unnamed, renamed
  through the hash table and signalled on obs->signals
  (canvas_dosignal(), obs_canvas_create_internal(),
  obs_canvas_destroy(), obs_canvas_set_name());
- _holds_scenes(): SCENE_REF, in obs_canvas_destroy(),
  obs_canvas_insert_source() and obs_canvas_remove_source();
- _saves(): neither EPHEMERAL nor REMOVED;
- _size_set() and _format_set(): obs_canvas_has_valid_video_info();
- _resets(), _global_signals(), _channel_ok(), _name_empty(),
  _renames(), _removable(), _mark_removed() and _removed(): the checks
  of obs_canvas_reset_video(), obs_canvas_rename_source(),
  obs_canvas_set_channel(), obs_canvas_set_name(), obs_canvas_remove()
  and obs_canvas_removed().

Split per read, as #2153 did. canvas->flags is read without a lock and
obs_canvas_remove() writes it from any thread, so each check gets the
value of its own read, at its point. Every check behind a || or && is
still asked only where the C reached it: obs_source_is_scene() only on
a SCENE_REF canvas, obs_video_active() only for a canvas that may
reset, strcmp() only for a canvas that may be renamed, and each video
info field only after the one before it was set. The rest stays C at
its point: the allocations and frees, the context data calls, the
signal handler setup, the mutexes, obs_view_init() and _free(), the
mix and its list under mixes_mutex, HASH_CLEAR and the walk that takes
next before each release (the #2038 and #2049 order), every reference
and weak reference, the pointer checks (source, previous source,
canvas, mix, the "already in a canvas" step), the group walk, the
calldata, every signal, obs_source_activate() and _deactivate(),
strcmp() and the logs. The flag values, REMOVED, the public mask,
VIDEO_FORMAT_NONE and MAX_CHANNELS are copied into the header, so it
needs only stdbool.h and stdint.h; obs-canvas.c.h checks them with
_Static_assert. REMOVED and PUBLIC_CANVAS_FLAGS leave obs-canvas.c.h.

Checked in a scratch harness (not committed). It compiles
origin/master's obs-canvas.c.h verbatim, and this branch's with
obs-canvas-rules.c.h, over a stand-in libobs.pch.h whose functions log
every call in order with its arguments: the context data calls (init
may fail), signal_handler_add_array() (may fail), the mutex init (may
fail), every lock and unlock, obs_view_init() and _free(), the mix
create (may fail) and free, the mix list, HASH_CLEAR, every signal
with its calldata, the strong and weak references (a weak get may
fail), obs_source_get_ref() (may return NULL), _release(), _is_scene(),
_is_group(), _activate(), _deactivate(), obs_video_active(), the scene
walks, the obs_data reads and writes, and blog(). A channel_change
handler may replace the source in the calldata. A concurrent writer may
flip any flag bit (MAIN, ACTIVATE, MIX_AUDIO, SCENE_REF, EPHEMERAL,
REMOVED, an unknown bit), the private flag or a video info field of
any live canvas at any call. Each run makes up to sixteen random calls
of the whole canvas API (every constructor with random flags, names and
video info; obs_load_canvas() with saved flags of 0, -1, INT64_MIN,
INT64_MAX, above 32 bits and random; save, the video info check, both
resets, insert, remove and rename of scene, group and plain sources,
set_channel at 0 to 3, 63, 64, 65 and UINT32_MAX with the same, another
or no source, set_name with NULL, "", "Main", the same and other
names, remove, the getters, scene create, remove and move, refs taken
and released, the mix clears and render), then releases everything
and removes the sources left alive, as obs_free_data() does. The C++
build also logs every read and write of the flags, the private flag
and the video info fields.

6,600,000 runs: 1,000,000 each with GCC and Clang at -O0 and -O2 as C
(67,558,889 logged lines each side), 1,000,000 each with G++ at -O0
and -O2 as C++ with the logged reads (95,351,694 each side), and
200,000 each under ASan and UBSan with no recovery (GCC -O0 and Clang
-O2 as C, G++ -O1 as C++). The two logs are identical in every
configuration. gcov over 100,000 runs takes every branch of the moved
decisions both ways, but the two no caller reaches: canvas_dosignal()
with no core signal name, and obs_canvas_remove() failing to take a
reference to a canvas its caller holds.

34 deliberately broken moves were planted, and the C++ build fails all
34: each rule changed (each operand dropped or swapped, a bound off by
one, an inverted result, the REMOVED write dropped), the destroy walk
reading the flags once before it, obs_video_active() asked before the
flags and the flags read without video info, obs_source_is_scene()
asked before the flags, a video info field read early, strcmp() before
the MAIN check, the flags read before the canvas's own signal in
set_channel(), remove_source() and rename_source(), the remove check
after the reference, the private flag read once in set_name(), the
create's mix_audio read from the canvas instead of its argument, and
a second read of the flags in save. The C builds, which see reads only
through the writer, fail 29 of them.

git blame on the moved lines shows upstream commits (3d57b1f
introducing canvases, 66f4792, 1ecea56, 0fd1261) and the fork's
fe75932 (the public mask, #2151); they move as they are.

The new file joins libobs.core-source with libobs.pch.h, which
includes the new header; source-sets.json lists it. The exported
symbol sets are unchanged: 1766 on the C backend, the hybrid and
libobs-c-reference, the same set on all three, with the seventeen
functions local.

Refs #2544.
test_canvas_rules_steps compiles libobs/obs-canvas-rules.c.h (ASan and
UBSan) and calls only its functions through obs-canvas-rules.h. 11
cases:

- the header's copies of the flags, REMOVED, the public mask,
  VIDEO_FORMAT_NONE and MAX_CHANNELS against obs.h;
- the main canvas's flags (MAIN | PROGRAM), and the public mask over
  every single bit and every combination of the five public flags,
  MAIN, REMOVED and an unknown bit;
- obs_load_canvas()'s cast of the saved int64 before the mask, at 0,
  the named flags, 0x80000000, 0xffffffff, above 32 bits, -1, -2, -32
  and the ends of int64;
- every flag rule (view type, mix_audio, scene references, save,
  reset, global signals, rename, remove, removed, the REMOVED write)
  over those 128 combinations and over every single bit;
- the main, program, preview and device canvases, and a caller asking
  for MAIN;
- the public canvas rule, the video info checks (sizes 0, 1, 1920 and
  UINT32_MAX; formats NONE, I420, NV12, P010 and outside the enum),
  the channel bound (0 to 1023, 63, 64, 65, 2^31 and UINT32_MAX), the
  empty name (NULL, "", " ", "a", "Main", "\0b", 0xff) and removing
  twice.

Characterized, not endorsed:
- the saved int64 is truncated before the mask, so bits above 31 are
  dropped silently and a negative value keeps the public flags of its
  low word (-1 loads as every public flag);
- a video format outside the enum counts as set;
- a removed canvas can still be reset and renamed.

It is in the native test graph, in name order, with the header as a
watch input. No assert_in_range or fail_msg, so it builds with cmocka
1.x and 2.x, and no two enum types are compared. Passes 11/11 on the C
backend and the hybrid. test_canvas_flags, test_scene_private_canvas,
test_canvas_destroy_scene_refs, test_shutdown_canvas_weak_ref,
test_scene_canvas_characterization, test_context_names and test_view
cover the callers through the real libobs, and pass on both.

Refs #2544.
RED for the port of libobs/obs-canvas-rules.c.h to a new canvas_rules
module of rust/obs-core, next to canvas_draw. The safe core is a stub
(todo!()): main_flags(), public_flags(), main_view(), mix_audio(),
is_public() (public is the C name; is_public reads better in Rust),
holds_scenes(), saves(), size_set(), format_set(), resets(),
global_signals(), channel_ok(), name_empty(), renames(), removable(),
mark_removed() and removed(), with the flag constants (MAIN, ACTIVATE,
MIX_AUDIO, SCENE_REF, EPHEMERAL, PROGRAM, PREVIEW, DEVICE, REMOVED,
PUBLIC), FORMAT_NONE and MAX_CHANNELS. name_empty() takes the name's
first byte, None for NULL, so the core reads no pointer.

The plan sketched wider steps (reset(has_ovi, flags, video_active),
rename(empty, flags, same), scene_ref(flags, is_scene)). Each would
take a value the C reads or calls only behind a || or &&, so each check
is its own function, asked at its own point, as #2153 did; the pointer
checks, obs_source_is_scene(), obs_video_active() and strcmp() stay C.

tests/obs_core/canvas_rules.rs ports test_canvas_rules_steps 1:1: its
11 cases under the same names (steps_*), in the same order, with the
same values and expectations, the characterized-not-endorsed cases
included. Three new proptests (edge_*, 4096 cases each) check every
rule over any u32 flags, the load over any i64 (truncated as the C's
cast, never keeping MAIN or REMOVED), and the size, format, channel,
name byte and private rules over any value, against models written
from the C's expressions.

soldr cargo test -p obs-data --test obs-tests-core --
canvas_rules:: passes 1 of 14 (the constants) and fails 13 with "not
yet implemented".

Refs #2544.
Ports libobs/obs-canvas-rules.c.h, the canvas flag rules and setter
checks of obs-canvas.c, to the canvas_rules module of rust/obs-core.
obs-canvas.c.h stays C around it: every read of the canvas's flags,
private flag and video info fields at its point, the allocations and
frees, the context data calls, the signal handler setup, the mutexes,
the view, the mix and its list, HASH_CLEAR and the destroy walk (the
#2038 and #2049 order), every reference, the pointer checks, the group
walk, obs_source_is_scene() and _is_group(), obs_video_active(),
strcmp(), the calldata, every signal, the activation calls and the
logs. The hybrid libobs drops the C file and links the Rust shims in
its place.

Safe core (src/canvas_rules.rs), seventeen functions:
- main_flags(): MAIN | PROGRAM; public_flags(): flags & PUBLIC;
- main_view(): ACTIVATE; mix_audio(): MIX_AUDIO; is_public():
  !is_private; holds_scenes(): SCENE_REF;
- saves(): neither EPHEMERAL nor REMOVED; size_set(): not 0;
  format_set(): not FORMAT_NONE (a format outside the enum is set);
- resets() and renames(): not MAIN; global_signals(): MAIN;
  channel_ok(): below MAX_CHANNELS;
- name_empty(): None or a first byte of 0;
- removable(): neither REMOVED nor MAIN; mark_removed(): | REMOVED;
  removed(): REMOVED.
The module denies clippy's arithmetic, indexing, as, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state and
takes no lock.

Shims (src/ffi/canvas_rules.rs): the seventeen C signatures by value;
the flags as u32, the format as int. The one pointer is the name of
obs_canvas_set_name(): the shim reads its first byte only when it is
not NULL, as the C's !name || !*name. No struct is mirrored. No
intentional difference from the C.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-canvas-rules, registered in its own fragment,
libobs/build/ported-source-sets/canvas-rules.json
(LIBOBS_PORTED_SOURCES), so it edits no shared ported list. Its PCH is
only obs-canvas-rules.h; libobs.pch.h keeps the header for
obs-canvas.c.
The functions are not EXPORT, so the shims are hidden: rust-hidden.txt,
the local: list of rust-exports.map and rust-unexports-macos.txt.
libobs-rust already links the crate's ffi. The exported symbol sets
are unchanged and equal: 1766 on the C backend, the hybrid and
libobs-c-reference, the same set as origin/master; the seventeen
functions are local in all three, and the hybrid's come from the Rust
archive (the group's object is built only for libobs-c-reference).
ci/test_ported_sources.py checks the group on every host.

test_canvas_rules_steps still compiles the C file into itself,
unchanged, and passes 11/11. It has no _rust variant: linking it
against libobs_rust-static fails with 401 undefined references (108
symbols), because the shims' archive member (an obs_core codegen unit)
also holds the other obs-core ports, as for test_canvas_draw_steps;
its tests.d file says so. The Tier 3 parity tests compare the shims
with the C instead.

soldr cargo test -p obs-data --test obs-tests-core --
canvas_rules:: passes 14 of 14.

No user-visible change, so no docs/features.md line.

Refs #2544.
rust/obs-c-oracle/oracle/canvas_rules.c compiles the unchanged
libobs/obs-canvas-rules.c.h with its seventeen functions renamed
oracle_*, after obs.h, plus the header's copies, enum
obs_canvas_flags, VIDEO_FORMAT_NONE, MAX_CHANNELS and the type sizes.
tests/obs_core/canvas_rules_parity.rs (7 tests) runs the shim, the C
and the safe core on every input and compares the results exactly: the
C's bool as the byte it returns, the flags as the uint32_t.

- the 23 values and sizes against the C headers, and the main flags;
- exhaustive: every flag rule for every low 16-bit flags word under
  16 high words (bits 16, 17, 30 and 31), every single bit and every
  combination of the known flags, REMOVED and an unknown bit; the load
  for 786,432 saved int64 values (four high words, three top halves,
  every low half) and the ends; the size and channel for 0 to 70,000,
  every 65,521st u32 and the ends; the format for -70,000 to 70,000
  and the ends; the name for NULL and every first byte, through a C
  string;
- each caller's decisions in their order (the three constructors, the
  save, the reset, the channel bound and global signal, the name
  refusals and the public rename, the remove and REMOVED write, the
  video info chain), one copy on each side, for every combination of
  the known flags, REMOVED, an unknown bit, the private flag, six
  channels, four names, three video infos and five formats;
- proptests (20,000 cases each): every decision over any value, and
  the callers over all of it at once.

No input reaches a division or a 128-bit multiply on either side, so
nothing is skipped on MSVC x64. No intentional differences.

The parity module passed 3 runs in a row with fresh seeds.
test_canvas_rules_steps passes 11/11 under ASan and UBSan. The
committed regression files hold the seeds proptest saved while mutants
failed; all pass on the port.

Mutation check (the mutants are not committed): 36 mutants, 24 in the
core and 12 in the shims, each run against Tier 1 (14 tests) and Tier
3 (7). 34 fail. The two that survive are equivalent: the resets shim
calling renames() (both are "not MAIN"), and the name shim passing
Some(0) for NULL (both are empty). Tier 1 does not reach the shims;
Tier 3 kills every other shim mutant. Each mutant and the tests that
fail on it:

 1. core, main_flags: no SCENE_REF
    T1: steps_canvas_kinds, steps_constructor_flags
    T3: callers_every_input, proptest_callers,
        values_match_the_c_headers
 2. core, public_flags: keeps MAIN
    T1: edge_flag_rules_any_flags, edge_load_any_int64,
        steps_canvas_kinds, steps_constructor_flags,
        steps_load_flags_from_int64
    T3: callers_every_input, every_flags_word, every_load,
        proptest_callers, proptest_decisions
 3. core, public_flags: keeps REMOVED
    T1: edge_flag_rules_any_flags, edge_load_any_int64,
        steps_constructor_flags, steps_load_flags_from_int64,
        steps_remove_twice
    T3: callers_every_input, every_flags_word, every_load,
        proptest_callers, proptest_decisions
 4. core, public_flags: drops EPHEMERAL
    T1: edge_flag_rules_any_flags, edge_load_any_int64,
        steps_canvas_kinds, steps_constructor_flags,
        steps_load_flags_from_int64
    T3: callers_every_input, every_flags_word, every_load,
        proptest_callers, proptest_decisions
 5. core, main_view: MIX_AUDIO
    T1: edge_flag_rules_any_flags, steps_canvas_kinds,
        steps_flag_rules_every_bit, steps_flag_rules_every_combination
    T3: callers_every_input, every_flags_word, proptest_callers,
        proptest_decisions
 6. core, mix_audio: ACTIVATE
    T1: as 5; T3: as 5
 7. core, is_public: not negated
    T1: edge_values_any_input, steps_public_rule
    T3: callers_every_input, every_value, proptest_callers,
        proptest_decisions
 8. core, holds_scenes: EPHEMERAL
    T1: edge_flag_rules_any_flags, steps_canvas_kinds,
        steps_flag_rules_every_bit,
        steps_flag_rules_every_combination, steps_remove_twice
    T3: every_flags_word, proptest_decisions
 9. core, saves: ignores REMOVED
    T1: edge_flag_rules_any_flags, steps_flag_rules_every_bit,
        steps_flag_rules_every_combination, steps_remove_twice
    T3: callers_every_input, every_flags_word, proptest_callers,
        proptest_decisions
10. core, saves: ignores EPHEMERAL
    T1: as 5; T3: as 5
11. core, size_set: > 1
    T1: steps_video_info_checks
    T3: every_value
12. core, format_set: > 0
    T1: edge_values_any_input, steps_video_info_checks
    T3: callers_every_input, every_value, proptest_callers,
        proptest_decisions
13. core, resets: always
    T1: as 5; T3: as 5
14. core, global_signals: negated
    T1: edge_flag_rules_any_flags, edge_load_any_int64,
        steps_canvas_kinds, steps_flag_rules_every_bit,
        steps_flag_rules_every_combination
    T3: callers_every_input, every_flags_word, proptest_callers,
        proptest_decisions
15. core, channel_ok: <=
    T1: steps_channel_bound
    T3: callers_every_input, every_value, proptest_callers
16. core, name_empty: NULL only
    T1: edge_values_any_input, steps_name_checks
    T3: callers_every_input, every_value, proptest_callers,
        proptest_decisions
17. core, name_empty: NULL is a name
    T1: as 16; T3: as 16
18. core, renames: always
    T1: as 5; T3: as 5
19. core, removable: ignores REMOVED
    T1: as 9; T3: as 9
20. core, removable: ignores MAIN
    T1: as 5; T3: as 5
21. core, mark_removed: no write
    T1: as 9; T3: as 9
22. core, removed: bit 30
    T1: as 9; T3: as 9
23. core, REMOVED: 1 << 30
    T1: edge_flag_rules_any_flags, steps_constants,
        steps_flag_rules_every_bit
    T3: callers_every_input, every_flags_word, proptest_callers,
        proptest_decisions, values_match_the_c_headers
24. core, MAX_CHANNELS: 63
    T1: steps_channel_bound, steps_constants
    T3: callers_every_input, every_value, proptest_callers,
        values_match_the_c_headers
25. shim, public_flags: main_flags
    T3: callers_every_input, every_flags_word, every_load,
        proptest_callers, proptest_decisions
26. shim, main_view: mix_audio
    T3: callers_every_input, every_flags_word, proptest_callers,
        proptest_decisions
27. shim, public: negated
    T3: callers_every_input, every_value, proptest_callers,
        proptest_decisions
28. shim, saves: removable
    T3: as 26
29. shim, resets: renames: SURVIVES (equivalent)
30. shim, global_signals: removed
    T3: as 26
31. shim, format_set: format & 0x7fffffff
    T3: every_value
32. shim, channel_ok: low byte only
    T3: every_value, proptest_callers, proptest_decisions
33. shim, name_empty: reads the byte, answers Some(1)
    T3: callers_every_input, every_value, proptest_callers,
        proptest_decisions
34. shim, name_empty: NULL as Some(0): SURVIVES (equivalent)
35. shim, mark_removed: public_flags
    T3: as 26
36. shim, removed: removable
    T3: as 26

Refs #2544.
- rust/README.md: the obs-core crate row names
  libobs/obs-canvas-rules.c.h, and a row for the file says what is
  swapped in the hybrid, what obs-canvas.c.h keeps and why each read
  asks its own function, the copied values, the characterized cases,
  why there is no _rust variant, and what Tier 3 covers;
- rust/obs-core: the crate description and the lib.rs docs list the
  module;
- docs/rust-port/naming.md: obs-canvas-rules.c.h, extracted from
  obs-canvas.c.h, maps to rust/obs-core;
- rust/obs-c-oracle/benches/port_comparison/canvas_rules.rs:
  canvas_rules/create and canvas_rules/setters, the constructors' and
  the setters' decisions in their order over 1024 calls on each side,
  folded into a checksum both must match. It allocates nothing, so the
  per-module allocation check holds. The bench's build.rs finds it in
  the directory, so no shared list changes.

port_comparison (x86_64 Linux, GCC, not pinned, load average about
3; criterion's median per 1024 calls): create 7.8 us Rust, 5.4 us C;
setters 16.7 us Rust, 11.4 us C, about 2 to 5 ns more a decision
through the exported shims. These run when a canvas is created, saved,
reset, renamed or removed and when a scene or channel changes, never
per frame.

No docs/features.md line: the port changes no behaviour.

Fixes #2544.
test_canvas_rules_steps pins the seventeen rules on their own, and the
move was checked against the callers only in a scratch harness. This
pins what the callers in obs-canvas.c do with the rules, through the
real libobs and its public API, so it runs unchanged against the C
backend, the hybrid and libobs-c-reference. 9 cases:

- constructor_flags: the main canvas is MAIN | PROGRAM; create and
  create_private drop MAIN, REMOVED and unknown bits; obs_load_canvas()
  keeps the public flags of the saved value's low word;
- save_rules: the saved flags and private flag, a private canvas
  reloaded, and no save for an ephemeral or a removed canvas;
- reset_rules: no video info, the main canvas, and active video (a raw
  video callback on the main mix) are refused, with no video_reset
  signal; otherwise the canvas gets a mix and signals once;
- set_name_rules: NULL, "", the same name and the main canvas are
  refused with no signal; a public canvas is renamed in the name table
  and signals canvas_rename globally; a private one signals only its
  own rename and stays out of the name table;
- remove_rules: one remove signal each, none for a second remove or
  for the main canvas, and the REMOVED bit in the flags;
- scene_refs: a scene on the main canvas (SCENE_REF) outlives its
  creator's reference until it is removed; a plain source on it gets
  no canvas reference; a scene on a canvas without SCENE_REF dies with
  its last reference; a SCENE_REF canvas releases its scenes when it is
  destroyed;
- group_walk: removing a group removes its items from every scene of
  its canvas; a removed plain source leaves the canvas but its items
  stay in the scenes;
- rename_source_signals: a scene rename on the main canvas signals
  source_rename globally, one on another canvas only on that canvas;
- channel_replace: a channel_change handler that replaces the source.

Characterized, not endorsed: the saved int64 is truncated before the
mask; a removed canvas can still be renamed; the handler's replacement
is stored and activated without a reference of its own, so clearing
the channel releases one more reference on it than the canvas took,
and the reference taken on the source passed in is never released.

It needs a display and OpenGL (Linux, the graphics suite, under
xvfb-run like test_main_mix_before_video), and is in the test graph in
name order. No assert_in_range or fail_msg, and no two enum types are
compared. Passes 9/9 three runs in a row on the C backend and the
hybrid, and 9/9 against libobs-c-reference, each under a private Xvfb.

Refs #2544.
@rdoupe
rdoupe force-pushed the fix/rust-port-canvas-flag-rules-and-187 branch from 45e4a43 to 737e1db Compare October 27, 2026 05:58
@zackees
zackees added this pull request to the merge queue Oct 27, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to In merge queue in obs-rust Multiview Oct 27, 2026
Merged via the queue into master with commit 991a433 Oct 27, 2026
36 checks passed
@zackees
zackees deleted the fix/rust-port-canvas-flag-rules-and-187 branch October 27, 2026 08:16
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port the canvas flag rules in obs-canvas.c to obs-core

2 participants