Implement XRMediaBinding and accelerated video-frame copy for Media Layers [chromium/src : main]

0 views
Skip to first unread message

Yong Li (xWF) (Gerrit)

unread,
Jun 1, 2026, 4:19:59 PM (yesterday) Jun 1
to Alexander Cooper, Brandon Jones, chromium...@chromium.org, Dirk Schulze, Kentaro Hara, Raphael Kubo da Costa, CJ DiMeglio, Stephen Chenney, blink-revie...@chromium.org, blink-reviews-p...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, drott+bl...@chromium.org, feature-me...@chromium.org, feature-v...@chromium.org, fmalit...@chromium.org, fserb...@chromium.org, ipc-securi...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org
Attention needed from Alexander Cooper and Brandon Jones

Yong Li (xWF) added 12 comments

File third_party/blink/renderer/modules/xr/DEPS
Line 25, Patchset 14: "+ui/gfx/gpu_fence.h",
Alexander Cooper . resolved

I don't think this is used anymore?

Yong Li (xWF)

Done

File third_party/blink/renderer/modules/xr/xr_media_binding.cc
Line 102, Patchset 14: nullptr, drawing_context);
Alexander Cooper . unresolved

I'm not seeing an update to https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/xr/xr_frame_provider.cc;drc=94b8dff8418534977a39c201e209e2efc30b48d7;l=770, which looks to (now) mistakenly expect that binding is always set.

Yong Li (xWF)

The input is a XRProjectionLayer where the binding should always exist.

File third_party/blink/renderer/modules/xr/xr_media_drawing_context.cc
Line 42, Patchset 14: uint16_t w = video_->videoWidth();
uint16_t h = video_->videoHeight();
Alexander Cooper . resolved

Chromium style generally frowns on this kind of name shortening, please use `width` and `height` instead of `w` and `h`.

Yong Li (xWF)

Done

Line 45, Patchset 14: double scale = std::min(static_cast<double>(max_texture_size_) / w,
static_cast<double>(max_texture_size_) / h);
width_ = std::max(base::checked_cast<uint16_t>(1),
base::checked_cast<uint16_t>(w * scale));
height_ = std::max(base::checked_cast<uint16_t>(1),
Alexander Cooper . unresolved

I think max_texture_size_ *must* be greater than 0 here; so therefore w, h, and scale all have to be as well. `checked_cast` will CHECK/crash in the event of an overflow, not return 0, so the std::max's are not necessary..

Yong Li (xWF)

In extreme case, e.g. height is very big, but width is small, width could be 0 after being converted to integer. Let's say width is 1, and height is 3x max size. In reality it probably will never happen, but still possible

Line 70, Patchset 14: if (auto* wmp = video_->GetWebMediaPlayer()) {
Alexander Cooper . resolved

See earlier comment re: name shortenings, `player` would be acceptable here though.

Yong Li (xWF)

Done

Line 75, Patchset 14: if (!media_video_frame) {
return;
}
Alexander Cooper . resolved

The presence of this check means that I think you can just turn 70 into an early return as well, and then you don't have to default initialize the two values in it's if block. If you can't get a media player, you'll always early return here. (Though obviously still need to check here).

Yong Li (xWF)

Done

Line 84, Patchset 14: gpu::raster::RasterInterface* ri =
Alexander Cooper . resolved

Can't shorten names.

Yong Li (xWF)

Done

Line 103, Patchset 14: // This 2-copy solution is the best we can do for now without a big
Alexander Cooper . resolved

😮

Brandon Jones

This made me 😮 too, but looking through the rest of the code I believe this path should only kick in when the video is larger than the max texture size? (Which... I'm somewhat skeptical that could even happen normally?) In fact, I'm tempted to say that we should consider adding validation to the spec that rejects in that case, but that's for a later discussion.

In any case, the large texture size will make this brutally slow BUT you're also already pushing the limits of what most GPUs will handle at that point, so you're in for a bad time whether or not this scaling needs to take place.

I would recommend adding something to the comment to explain that this path should only kick in in extreme circumstances.

Yong Li (xWF)

Yeah, there is no good solution for now in such a case. Will add more comments

Yong Li (xWF)

BTW, in reality, the limit is usually 8192

Yong Li (xWF)

Done

File third_party/blink/renderer/modules/xr/xr_session.h
Line 204, Patchset 14:
XRGraphicsBinding* GetGraphicsBinding() const {
if (graphics_bindings_.empty()) {
return nullptr;
}
return graphics_bindings_.begin()->Get();
}
Alexander Cooper . resolved

Doesn't seem to be used anymore. Further, something like this isn't really right either.

Brandon Jones

Agreed. It's not clear under which circumstances it would be useful to know whatever the first registered graphics binding is.

Yong Li (xWF)

Done

File third_party/blink/renderer/modules/xr/xr_webgl_binding.cc
Line 289, Patchset 14: if (!init->hasWidth()) {
exception_state.ThrowTypeError("width is required.");
return nullptr;
}
if (!init->hasHeight()) {
exception_state.ThrowTypeError("height is required.");
return nullptr;
}
Alexander Cooper . unresolved

Can be removed like the other items since `Validate` should check this now?

Edit: Actually, it doesn't look like validate checks that width/height exist, which feels like it should do so.

Yong Li (xWF)

The Validate method doesn't check these because video layer has video width/height. The spec says width/height are optional

Line 333, Patchset 14: if (!ValidateCylinderLayerInit(init, exception_state)) {
Alexander Cooper . unresolved

This doesn't validate that the required items are set.

Yong Li (xWF)

those are not required. The spec provides default values for those. We didn't follow the spec last time

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 6929, Patchset 14: status: "stable",
Alexander Cooper . resolved

Shouldn't be stable yet; should leave it as experimental until we can do a chromestatus for it.

Yong Li (xWF)

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Cooper
  • Brandon Jones
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I32ca0be6c8fff3eb614ac9a8fa051a6e47cb9ef0
Gerrit-Change-Number: 7841399
Gerrit-PatchSet: 14
Gerrit-Owner: Yong Li (xWF) <yyon...@google.com>
Gerrit-Reviewer: Alexander Cooper <alco...@chromium.org>
Gerrit-Reviewer: Brandon Jones <baj...@chromium.org>
Gerrit-CC: CJ DiMeglio <lethala...@chromium.org>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Frank Liberato <libe...@chromium.org>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-CC: Raphael Kubo da Costa <ku...@igalia.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Brandon Jones <baj...@chromium.org>
Gerrit-Attention: Alexander Cooper <alco...@chromium.org>
Gerrit-Comment-Date: Mon, 01 Jun 2026 20:19:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Yong Li (xWF) <yyon...@google.com>
Comment-In-Reply-To: Brandon Jones <baj...@chromium.org>
Comment-In-Reply-To: Alexander Cooper <alco...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Yong Li (xWF) (Gerrit)

unread,
Jun 1, 2026, 4:20:39 PM (yesterday) Jun 1
to Alexander Cooper, Brandon Jones, chromium...@chromium.org, Dirk Schulze, Kentaro Hara, Raphael Kubo da Costa, CJ DiMeglio, Stephen Chenney, blink-revie...@chromium.org, blink-reviews-p...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, drott+bl...@chromium.org, feature-me...@chromium.org, feature-v...@chromium.org, fmalit...@chromium.org, fserb...@chromium.org, ipc-securi...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org
Attention needed from Alexander Cooper and Brandon Jones

Yong Li (xWF) added 1 comment

Commit Message
Line 7, Patchset 14:Implement XRMediaBinding and media layers
Alexander Cooper . resolved

More of a description about how we're implementing it would be good.

Yong Li (xWF)

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Cooper
  • Brandon Jones
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I32ca0be6c8fff3eb614ac9a8fa051a6e47cb9ef0
Gerrit-Change-Number: 7841399
Gerrit-PatchSet: 15
Gerrit-Owner: Yong Li (xWF) <yyon...@google.com>
Gerrit-Reviewer: Alexander Cooper <alco...@chromium.org>
Gerrit-Reviewer: Brandon Jones <baj...@chromium.org>
Gerrit-CC: CJ DiMeglio <lethala...@chromium.org>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Frank Liberato <libe...@chromium.org>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-CC: Raphael Kubo da Costa <ku...@igalia.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Brandon Jones <baj...@chromium.org>
Gerrit-Attention: Alexander Cooper <alco...@chromium.org>
Gerrit-Comment-Date: Mon, 01 Jun 2026 20:20:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Alexander Cooper <alco...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Yong Li (xWF) (Gerrit)

unread,
Jun 1, 2026, 4:37:14 PM (yesterday) Jun 1
to Alexander Cooper, Brandon Jones, chromium...@chromium.org, Dirk Schulze, Kentaro Hara, Raphael Kubo da Costa, CJ DiMeglio, Stephen Chenney, blink-revie...@chromium.org, blink-reviews-p...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, drott+bl...@chromium.org, feature-me...@chromium.org, feature-v...@chromium.org, fmalit...@chromium.org, fserb...@chromium.org, ipc-securi...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org
Attention needed from Alexander Cooper and Brandon Jones

Yong Li (xWF) added 1 comment

File third_party/blink/renderer/modules/xr/xr_media_drawing_context.cc
Line 143, Patchset 14:
// Flush the commands to ensure the GPU executes the copy before OpenXR
// consumes it.
ri->Flush();
Alexander Cooper . unresolved

I *think* plumbing the sync tokens down would do the same thing and wouldn't introduce a potential sync action here that can hang things.

Yong Li (xWF)

It seems this is required because it uses a different context (SharedGpuContext). So flushing with the GL context is not enough.

Gerrit-Comment-Date: Mon, 01 Jun 2026 20:37:02 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Cooper (Gerrit)

unread,
Jun 1, 2026, 5:50:51 PM (yesterday) Jun 1
to Yong Li (xWF), Brandon Jones, chromium...@chromium.org, Dirk Schulze, Kentaro Hara, Raphael Kubo da Costa, CJ DiMeglio, Stephen Chenney, blink-revie...@chromium.org, blink-reviews-p...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, drott+bl...@chromium.org, feature-me...@chromium.org, feature-v...@chromium.org, fmalit...@chromium.org, fserb...@chromium.org, ipc-securi...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org
Attention needed from Brandon Jones and Yong Li (xWF)

Alexander Cooper added 6 comments

File third_party/blink/renderer/modules/xr/xr_media_binding.cc
Line 102, Patchset 14: nullptr, drawing_context);
Alexander Cooper . resolved

I'm not seeing an update to https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/xr/xr_frame_provider.cc;drc=94b8dff8418534977a39c201e209e2efc30b48d7;l=770, which looks to (now) mistakenly expect that binding is always set.

Yong Li (xWF)

The input is a XRProjectionLayer where the binding should always exist.

Alexander Cooper

Acknowledged. Missed that part of it.

File third_party/blink/renderer/modules/xr/xr_media_drawing_context.cc
Line 45, Patchset 14: double scale = std::min(static_cast<double>(max_texture_size_) / w,
static_cast<double>(max_texture_size_) / h);
width_ = std::max(base::checked_cast<uint16_t>(1),
base::checked_cast<uint16_t>(w * scale));
height_ = std::max(base::checked_cast<uint16_t>(1),
Alexander Cooper . unresolved

I think max_texture_size_ *must* be greater than 0 here; so therefore w, h, and scale all have to be as well. `checked_cast` will CHECK/crash in the event of an overflow, not return 0, so the std::max's are not necessary..

Yong Li (xWF)

In extreme case, e.g. height is very big, but width is small, width could be 0 after being converted to integer. Let's say width is 1, and height is 3x max size. In reality it probably will never happen, but still possible

Alexander Cooper

Add a comment please, I thought at first this was some kind of underflow protection. Further, I don't think you need a `checked_cast` to uint16_t with 1. There should be a suffix or you can probably specialize std::max to uint16_t to clean it up and avoid the one cast at least.

Line 87, Patchset 15 (Latest): media::VideoFrameSharedImageCache* yuv_shared_image_cache = nullptr;
scoped_refptr<media::VideoFrame> media_video_frame;

if (auto* media_layer = video_->GetWebMediaPlayer()) {
media_video_frame = media_layer->GetCurrentFrameThenUpdate();
yuv_shared_image_cache = media_layer->GetYUVSharedImageCache();
}

if (!media_video_frame) {
return;
}
Alexander Cooper . unresolved
```suggestion
auto* media_layer = video_->GetMediaWebPlayer();
if (!media_layer) {
return;
}
  auto* media_video_frame = media_layer->GetCurrentFrameThenUpdate();
if (!media_video_frame) {
return;
}
  auto yuv_shared_image_cache = media_layer->GetYUVSharedImageCache();
```
Line 143, Patchset 14:
// Flush the commands to ensure the GPU executes the copy before OpenXR
// consumes it.
ri->Flush();
Alexander Cooper . unresolved

I *think* plumbing the sync tokens down would do the same thing and wouldn't introduce a potential sync action here that can hang things.

Yong Li (xWF)

It seems this is required because it uses a different context (SharedGpuContext). So flushing with the GL context is not enough.

Alexander Cooper

@baj...@chromium.org for his thoughts here, because I thought `flush()` was typically a slow, synchronous operation that we wouldn't want as part of this hot path.

File third_party/blink/renderer/modules/xr/xr_webgl_binding.cc
Line 289, Patchset 14: if (!init->hasWidth()) {
exception_state.ThrowTypeError("width is required.");
return nullptr;
}
if (!init->hasHeight()) {
exception_state.ThrowTypeError("height is required.");
return nullptr;
}
Alexander Cooper . unresolved

Can be removed like the other items since `Validate` should check this now?

Edit: Actually, it doesn't look like validate checks that width/height exist, which feels like it should do so.

Yong Li (xWF)

The Validate method doesn't check these because video layer has video width/height. The spec says width/height are optional

Alexander Cooper

Actually looks like for base quad layers there's a default of 1 as well, similar to the comment you have about cylinder layers.

Line 333, Patchset 14: if (!ValidateCylinderLayerInit(init, exception_state)) {
Alexander Cooper . resolved

This doesn't validate that the required items are set.

Yong Li (xWF)

those are not required. The spec provides default values for those. We didn't follow the spec last time

Alexander Cooper

Acknowledged, looks like maybe this should be updated for Quad as well as it seems to also have a default.

Open in Gerrit

Related details

Attention is currently required from:
  • Brandon Jones
  • Yong Li (xWF)
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I32ca0be6c8fff3eb614ac9a8fa051a6e47cb9ef0
Gerrit-Change-Number: 7841399
Gerrit-PatchSet: 15
Gerrit-Owner: Yong Li (xWF) <yyon...@google.com>
Gerrit-Reviewer: Alexander Cooper <alco...@chromium.org>
Gerrit-Reviewer: Brandon Jones <baj...@chromium.org>
Gerrit-CC: CJ DiMeglio <lethala...@chromium.org>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Frank Liberato <libe...@chromium.org>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-CC: Raphael Kubo da Costa <ku...@igalia.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Yong Li (xWF) <yyon...@google.com>
Gerrit-Attention: Brandon Jones <baj...@chromium.org>
Gerrit-Comment-Date: Mon, 01 Jun 2026 21:50:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Yong Li (xWF) <yyon...@google.com>
Comment-In-Reply-To: Alexander Cooper <alco...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages