Skip to content

Commit

Permalink
[M115] webcodecs: Stop using async VideoFrame.copyTo() for WebGPU arr…
Browse files Browse the repository at this point in the history
…ay buffers

ArrayBufferContents from GPUMappedDOMArrayBuffer doesn't really own
the underlying buffer, that's why default implementation of
ShareNonSharedForInternalUse() doesn't make sense.

(cherry picked from commit 8e8d780)

Bug: 1447839
Change-Id: Iecf7abcb202aa79fa7775814677d7dc5c9ed558b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4575395
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1151466}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4585217
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#391}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Djuffin authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent ea476ce commit f20d094
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Expand Up @@ -116,6 +116,15 @@ bool DOMArrayBuffer::Transfer(v8::Isolate* isolate,
return true;
}

bool DOMArrayBuffer::ShareNonSharedForInternalUse(ArrayBufferContents& result) {
if (!Content()->BackingStore()) {
result.Detach();
return false;
}
Content()->ShareNonSharedForInternalUse(result);
return true;
}

v8::Maybe<bool> DOMArrayBuffer::TransferDetachable(
v8::Isolate* isolate,
v8::Local<v8::Value> detach_key,
Expand Down
13 changes: 3 additions & 10 deletions third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h
Expand Up @@ -79,16 +79,9 @@ class CORE_EXPORT DOMArrayBuffer : public DOMArrayBufferBase {
ExceptionState& exception_state);

// Share the ArrayBuffer, even if it is non-shared. Such sharing is necessary
// for e.g. WebAudio which uses a separate thread for processing the
// ArrayBuffer while at the same time exposing a NonShared Float32Array.
bool ShareNonSharedForInternalUse(ArrayBufferContents& result) {
if (!Content()->BackingStore()) {
result.Detach();
return false;
}
Content()->ShareNonSharedForInternalUse(result);
return true;
}
// for e.g. WebAudio and WebCodecs which use a separate thread for processing
// the ArrayBuffer while at the same time exposing a NonShared TypedArray.
virtual bool ShareNonSharedForInternalUse(ArrayBufferContents& result);

v8::MaybeLocal<v8::Value> Wrap(ScriptState*) override;

Expand Down
Expand Up @@ -16,18 +16,20 @@ ArrayBufferContents PinArrayBufferContent(
if (buffer->IsShared()) {
buffer->Content()->ShareWith(result);
} else {
buffer->Content()->ShareNonSharedForInternalUse(result);
static_cast<blink::DOMArrayBuffer*>(buffer)
->ShareNonSharedForInternalUse(result);
}
}
return result;
}
case AllowSharedBufferSource::ContentType::kArrayBufferViewAllowShared: {
auto* view = buffer_union->GetAsArrayBufferViewAllowShared().Get();
if (view && !view->IsDetached()) {
if (view->IsShared())
if (view->IsShared()) {
view->BufferShared()->Content()->ShareWith(result);
else
view->buffer()->Content()->ShareNonSharedForInternalUse(result);
} else {
view->buffer()->ShareNonSharedForInternalUse(result);
}
}
return result;
}
Expand Down
7 changes: 7 additions & 0 deletions third_party/blink/renderer/modules/webgpu/gpu_buffer.cc
Expand Up @@ -100,6 +100,13 @@ class GPUMappedDOMArrayBuffer : public DOMArrayBuffer {
CHECK(result && IsDetached());
}

// Due to an unusual non-owning backing these array buffers can't be shared
// for internal use.
bool ShareNonSharedForInternalUse(ArrayBufferContents& result) override {
result.Detach();
return false;
}

void Trace(Visitor* visitor) const override {
DOMArrayBuffer::Trace(visitor);
visitor->Trace(owner_);
Expand Down

0 comments on commit f20d094

Please sign in to comment.