Skip to content

media: Stack punch-out videos by compositor order - #13623

Merged
borongc merged 6 commits into
youtube:mainfrom
borongc:video-zorder-epoch
Nov 6, 2026
Merged

borongc merged 6 commits into
youtube:mainfrom
borongc:video-zorder-epoch

Conversation

@borongc

@borongc borongc commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Previously, SbPlayerBridge used a process-wide atomic counter to assign
z-indices to video layers. This caused incorrect stacking when multiple
players were active, such as when an encrypted fullscreen video
initialized after a clear inset video and inadvertently covered it.

This change updates the Viz compositor to report all video holes in a
frame simultaneously, ordered from front-most to back-most. The
VideoGeometrySetterService now derives relative z-indices based on this
explicit order. These z-indices are propagated through the
StarboardRenderer to SbPlayerBridge::SetBounds, replacing the legacy
static counter.

The service only notifies clients when geometry or stacking order
changes, ensuring efficient updates. This ensures that video layer
stacking consistently matches the intended compositor order across all
platforms.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1

Co-authored-by: Andrew Savage andrewsavage@google.com

@borongc
borongc requested review from a team as code owners October 26, 2026 22:50
@borongc
borongc requested a review from jellefoks October 26, 2026 22:50
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ✅ PASS All checks passed
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ✅ PASS Passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


media: Stack punch-out videos by compositor order

Previously, SbPlayerBridge used a process-wide atomic counter to assign
z-indices to video layers. This caused incorrect stacking when multiple
players were active, such as when an encrypted fullscreen video
initialized after a clear inset video and inadvertently covered it.

This change updates the Viz compositor to report all video holes in a
frame simultaneously, ordered from front-most to back-most. The
VideoGeometrySetterService now derives relative z-indices based on this
explicit order. These z-indices are propagated through the
StarboardRenderer to SbPlayerBridge::SetBounds, replacing the legacy
static counter.

The service only notifies clients when geometry or stacking order
changes, ensuring efficient updates. This ensures that video layer
stacking consistently matches the intended compositor order across all
platforms.

Bug: 575352027
Bug: 575875272

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the VideoGeometrySetter interface and its service implementation to support batching and setting multiple video geometries at once, allowing the service to derive and propagate correct z-index stacking orders to clients like StarboardRenderer. The review feedback recommends adhering to the Chromium C++ style guide by replacing raw_ptr with a standard raw pointer for the stack-allocated previous_batch_ member in ScopedVideoHoleGeometryBatch. Additionally, it suggests resetting the z-index counters to zero when no active video geometries remain to prevent potential integer overflow during long-running sessions.

@borongc borongc changed the title media: Stack punch-out videos by their order in the compositor Oct 26, 2026
@borongc
borongc requested review from andrewsavage1 and removed request for jellefoks October 27, 2026 17:07

@johnedocampo johnedocampo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % small nits. Will leave approval to senior @youtube/cobalt-media members.

@borongc
borongc force-pushed the video-zorder-epoch branch from 8810e09 to bb897cf Compare October 28, 2026 17:59
@borongc
borongc requested a review from a team October 28, 2026 18:04
@borongc
borongc force-pushed the video-zorder-epoch branch from bb897cf to 26d8246 Compare November 2, 2026 17:09
@borongc
borongc requested a review from a team as a code owner November 2, 2026 17:09
borongc and others added 6 commits November 6, 2026 10:49
Fix the stacking order of multiple punch-out videos, e.g. the YTS dual
video tests where a clear inset video is in front of an encrypted
fullscreen video.

SbPlayerBridge::SetBounds() took the z-index from a process-wide
counter, so z only reflected which player set its bounds last.
StarboardRenderer skips unchanged rects, and the encrypted player's
SbPlayer is created ~0.5 s later (after its CDM), so the fullscreen
video ended up on top of the inset on platforms that stack video
windows by z-index.

Instead, the compositor now reports the stacking order explicitly:

- Viz reports all the video holes of a frame in one
  VideoGeometrySetter::SetVideoGeometries() call, front-most first.
  ScopedVideoHoleGeometryBatch collects them for both
  OverlayStrategyUnderlayStarboard and CALayerOverlayProcessor (tvOS).
- VideoGeometrySetterService derives the z-indices from that order. The
  front-most video gets the largest z-index, as SbPlayerSetBounds()
  expects. z-indices only change when the order changes, and each new
  order gets values larger than any handed out before, so a video whose
  hole is missing from the latest frame stays below the present ones.
- The service only notifies clients whose geometry or z-index changed,
  and keeps the latest geometry for clients that subscribe after their
  hole was reported. Previously, that update was dropped.
- z_index flows through VideoGeometryChangeClient::OnVideoGeometryChange()
  to StarboardRenderer, which skips an update only when both its rect
  and z-index are unchanged, and then to SbPlayerBridge::SetBounds().
  The static counter is removed.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1

Co-authored-by: Andrew Savage <andrewsavage@google.com>
Use a plain pointer for ScopedVideoHoleGeometryBatch::previous_batch_
and mark the class STACK_ALLOCATED(), since raw_ptr is not meant for
fields of classes that only live on the stack.

Restart the z-indices handed out by VideoGeometrySetterService from 0
once no video holds one anymore, so they don't keep growing across
playback sessions.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1
Drop the restart of the z-indices from 0 once no video holds one, and
keep them increasing like Cobalt's previous per-call counter did.

The broker only learns asynchronously that a player is gone, and the
platform may still be tearing down that player's window while the next
video starts. With a restart, the next video could get a smaller
z-index than the old window. Overflow is not a practical concern: the
values only grow when the order of the video holes changes, far slower
than the old counter that grew on every SetBounds() call.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1
Fix the gn check failure on configs without Starboard media (e.g.
linux-x64x11-no-starboard): mark the conditional Cobalt mojom include in
overlay_unittest.cc as nogncheck.

VideoGeometrySetterService takes each SetVideoGeometries() call as all
the video holes of a frame, so ScopedVideoHoleGeometryBatch now CHECKs
that video holes are only added to a live batch and that batches aren't
nested, instead of reporting a frame in several calls. Add unit tests
for the batch.

Use CheckedNumeric for the growing z-index and drop the redundant
z_index_base_. Document in the mojom that a single reporter makes one
call per frame and that the broker lives in the GPU process. Update the
StarboardRenderer test to the z-indices the service hands out, and
tighten the service tests.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1
Test that consecutive ScopedVideoHoleGeometryBatches are reported in
separate calls, so a batch that doesn't reset the current one fails in
its own test. CHECK in the destructor too, like the constructor and
Add() do.

Document what a VideoGeometryChangeClient receives now that the service
only sends changes, explain why OverlayStrategyUnderlayStarboard's
CommitCandidate() is only called inside a batch, and comment the test
fixtures.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1
Use a nested namespace definition in
video_geometry_setter_service_unittest.cc, and name the condition of
each Cobalt #endif in overlay_unittest.cc.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1
@borongc borongc added the cp-27.lts Cherry Pick to the 27.lts branch label Nov 6, 2026
@borongc
borongc merged commit 78ed2ad into youtube:main Nov 6, 2026
766 of 776 checks passed
@borongc
borongc deleted the video-zorder-epoch branch November 6, 2026 20:51
aelzeiny added a commit to aelzeiny/cobalt-browser that referenced this pull request Nov 18, 2026
Extend H5vccWasmImports for Starling-lite (Cobalt Hybrid-lite) on 27.lts:
- Expose H5vccWasmImports.discardPages(offset, size) backed by
  GuestMemory::DiscardPages() (madvise(MADV_DONTNEED) on page-aligned
  non-shared Wasm linear memory) and allow bindMemory(null) on teardown.
- Add H5vccWasmNet (imports.net) with adoptResponse(Response),
  [NoAllocDirectCall] read(streamId, dstOffset, capacity), and
  [NoAllocDirectCall] close(streamId), pulling directly from Blink's
  CORS-filtered BodyStreamBuffer BytesConsumer into guest memory and
  signaling kWasmSbEventNetReady via EventQueue::PushAndWake.
- Update WasmPlayerHost::OnVideoGeometryChange for 3-arg compositor
  z_index (PR youtube#13623) and set surface video size before handing sample
  buffers to Starboard.
aelzeiny added a commit to aelzeiny/cobalt-browser that referenced this pull request Nov 18, 2026
Extend H5vccWasmImports for Starling-lite (Cobalt Hybrid-lite) on 27.lts:
- Expose H5vccWasmImports.discardPages(offset, size) backed by
  GuestMemory::DiscardPages() (madvise(MADV_DONTNEED) on page-aligned
  non-shared Wasm linear memory) and allow bindMemory(null) on teardown.
- Add H5vccWasmNet (imports.net) with adoptResponse(Response),
  [NoAllocDirectCall] read(streamId, dstOffset, capacity), and
  [NoAllocDirectCall] close(streamId), pulling directly from Blink's
  CORS-filtered BodyStreamBuffer BytesConsumer into guest memory and
  signaling kWasmSbEventNetReady via EventQueue::PushAndWake.
- Update WasmPlayerHost::OnVideoGeometryChange for 3-arg compositor
  z_index (PR youtube#13623) and set surface video size before handing sample
  buffers to Starboard.
andrewsavage1 added a commit that referenced this pull request Nov 24, 2026
…mpositor order (#14246)

Refer to original PR: #13623

Previously, SbPlayerBridge used a process-wide atomic counter to assign
z-indices to video layers. This caused incorrect stacking when multiple
players were active, such as when an encrypted fullscreen video
initialized after a clear inset video and inadvertently covered it.

This change updates the Viz compositor to report all video holes in a
frame simultaneously, ordered from front-most to back-most. The
VideoGeometrySetterService now derives relative z-indices based on this
explicit order. These z-indices are propagated through the
StarboardRenderer to SbPlayerBridge::SetBounds, replacing the legacy
static counter.

The service only notifies clients when geometry or stacking order
changes, ensuring efficient updates. This ensures that video layer
stacking consistently matches the intended compositor order across all
platforms.

Bug: 575352027
Bug: 575875272
TAG=agy
CONV=2c527c1f-f04a-407e-84b3-18d0235b82d1

Co-authored-by: Andrew Savage <andrewsavage@google.com>

---------

Co-authored-by: Andrew Savage <andrewsavage@google.com>

(cherry picked from commit 78ed2ad)

---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

---------

Co-authored-by: Bo-Rong Chen <borongchen@google.com>
Co-authored-by: Andrew Savage <andrewsavage@google.com>
andrewsavage1 added a commit that referenced this pull request Nov 24, 2026
- Pre-Commit: apply staging's clang-format / google-java-format to lines
  added by rolled commits (decoder buffer allocator strategy, reuse
  allocator constructors, JavaSwitchesTest).
- #13747 (DecoderBufferAllocator decommit on memory pressure): staging's
  base::MemoryPressureListener is an abstract observer registered through
  (Async)MemoryPressureListenerRegistration, and the level enum is
  base::MemoryPressureLevel. Use a small MemoryPressureObserver with an
  AsyncMemoryPressureListenerRegistration (same per-sequence async
  delivery as main's callback listener) and add a
  kCobaltDecoderBufferAllocator listener tag.
- #13623 (video_geometry_setter_service.cc): base/containers/contains.h
  no longer exists on staging; use std::ranges::contains.
andrewsavage1 added a commit that referenced this pull request Nov 24, 2026
- Pre-Commit: apply staging's clang-format / google-java-format to lines
  added by rolled commits (decoder buffer allocator strategy, reuse
  allocator constructors, JavaSwitchesTest).
- #13747 (DecoderBufferAllocator decommit on memory pressure): staging's
  base::MemoryPressureListener is an abstract observer registered through
  (Async)MemoryPressureListenerRegistration, and the level enum is
  base::MemoryPressureLevel. Use a small MemoryPressureObserver with an
  AsyncMemoryPressureListenerRegistration (same per-sequence async
  delivery as main's callback listener) and add a
  kCobaltDecoderBufferAllocator listener tag.
- #13623 (video_geometry_setter_service.cc): base/containers/contains.h
  no longer exists on staging; use std::ranges::contains.
- starboard_renderer_unittest.cc (secondary player test): staging's
  MediaResource::GetAllStreams() returns std::vector<raw_ptr<DemuxerStream>>.
andrewsavage1 added a commit that referenced this pull request Nov 24, 2026
- Pre-Commit: apply staging's clang-format / google-java-format to lines
  added by rolled commits (decoder buffer allocator strategy, reuse
  allocator constructors, JavaSwitchesTest).
- #13747 (DecoderBufferAllocator decommit on memory pressure): staging's
  base::MemoryPressureListener is an abstract observer registered through
  (Async)MemoryPressureListenerRegistration, and the level enum is
  base::MemoryPressureLevel. Use a small MemoryPressureObserver with an
  AsyncMemoryPressureListenerRegistration (same per-sequence async
  delivery as main's callback listener) and add a
  kCobaltDecoderBufferAllocator listener tag.
- #13623 (video_geometry_setter_service.cc): base/containers/contains.h
  no longer exists on staging; use std::ranges::contains.
- starboard_renderer_unittest.cc (secondary player test): staging's
  MediaResource::GetAllStreams() returns std::vector<raw_ptr<DemuxerStream>>.
- starboard/BUILD.gn: in non-hermetic builds (linux-x64x11) both the
  starboard_unittests source_set and test("starboard_unittests_wrapper")
  write out/<cfg>/starboard_unittests_wrapper.runtime_deps. With the
  rolled GN changes the source_set's file (no test binary, no bin/run_*
  script) won, so the test archive lacked starboard_unittests_wrapper and
  every linux on-host shard failed with 'No such file or directory'. Only
  write it from the hermetic executable.
andrewsavage1 added a commit that referenced this pull request Nov 25, 2026
Automated cherry-pick roll to staging.

Original pull requests:
- #13847
- #13771
- #13851
- #13774
- #13862
- #13852
- #13623
- #13839
- #13854
- #13731
- #13162
- #13841
- #13546
- #13754
- #13277
- #13857
- #13604
- #13805
- #13859
- #13758
- #13902
- #13899
- #13910
- #13825
- #13881
- #13883
- #13914
- #13656
- #13929
- #13558
- #13932
- #13863
- #13845
- #13747
- #13927
- #13885
- #13912
- #13898
- #13879
- #13844
- #13855
- #13715
- #13920
- #13860
- #13924
- #13949
- #13936
- #13553
- #13867
- #13868
- #13945
- #13930

To merge these changes, run the autoroll script:

```bash
GITHUB_REPOSITORY=youtube/cobalt python3 cobalt/devinfra/github/autoroll/merge_autoroll.py \
  --source-branch main \
  --target-branch staging
```

---------

Co-authored-by: johnx <johnx@google.com>
Co-authored-by: Adam Walls <avvall@google.com>
Co-authored-by: Kyujung Youn <kjyoun@google.com>
Co-authored-by: Jesus Horta <jshorta@google.com>
Co-authored-by: Xinan Lin <65635777+linxinan-yt@users.noreply.github.com>
Co-authored-by: fayev-g <fayev@google.com>
Co-authored-by: Austin Osagie <austinosagie@google.com>
Co-authored-by: Raphael Kubo da Costa <kubo@igalia.com>
Co-authored-by: Yavor Goulishev <yavor@google.com>
Co-authored-by: Sunny Tang <tasunny@google.com>
Co-authored-by: Xiaoming Shi <xiaomings@google.com>
Co-authored-by: Orko Garai <orko@igalia.com>
Co-authored-by: Henrique Ferreiro <hferreiro@igalia.com>
Co-authored-by: Jelle Foks <jfoks@google.com>
Co-authored-by: Bo-Rong Chen <borongchen@google.com>
Co-authored-by: Abhijeet Kandalkar <abhijeet@igalia.com>
Co-authored-by: Jeremmy <34620271+a8901147@users.noreply.github.com>
Co-authored-by: Igor Sarkisov <isarkisov@google.com>
Co-authored-by: Vinish Chamrani <vinishc@google.com>
Co-authored-by: Roger Zanoni <rzanoni@igalia.com>
Co-authored-by: Sherry Zhou <sherryzy@google.com>
Co-authored-by: AIdrifter(Pinkus) <aidrifter@gmail.com>
Co-authored-by: Andrew Savage <andrewsavage@google.com>
Co-authored-by: Charley Kim <charleykim@google.com>
Co-authored-by: Ying Yu <yuying@google.com>
Co-authored-by: Hao <131711973+haozheng-cobalt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cp-27.lts Cherry Pick to the 27.lts branch kokoro:run

5 participants