mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
* chore: bump chromium in DEPS to 145.0.7562.0 * fix(patch-conflict): update code cache patch for PersistentCache refactor Upstream refactored code cache to use PersistentCache with new class-based implementation (NoopCodeCacheHost, LocalCodeCacheHost, CodeCacheWithPersistentCacheHost). Updated patch to integrate custom scheme support into the new structure while preserving ProcessLockURLIsCodeCacheScheme checks for embedder-registered schemes. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7044986 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(patch-conflict): update dialog patch for RequestXdgDesktopPortal API Upstream changed from SetSystemdScopeUnitNameForXdgPortal to RequestXdgDesktopPortal API pattern. Updated OnServiceStarted signature and kept OnSystemdUnitStarted callback that calls Electron's file_dialog::StartPortalAvailabilityTestInBackground(). Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7204285 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(patch-conflict): remove reference to deleted AbortByPlaceholderLayout flag Upstream removed the AbortByPlaceholderLayout runtime flag from runtime_enabled_features.json5. Updated patch to only add ElectronCSSCornerSmoothing without the removed flag reference. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7226494 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * chore: update patch hunk headers Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(build): guard media_file_system_registry for ChromeOS only Upstream CL https://chromium-review.googlesource.com/c/chromium/src/+/7100719 moved media_file_system_registry to be ChromeOS-only since Media Galleries is a Chrome Apps API and Chrome Apps are only available on Chrome OS now. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(build): update VideoPixelFormat API for SharedImageFormat Upstream CL https://chromium-review.googlesource.com/c/chromium/src/+/7207153 removed VideoPixelFormatToGfxBufferFormat as part of migration to SharedImageFormat. Update to use VideoPixelFormatToSharedImageFormat which directly returns the SharedImageFormat. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(build): extend profile methods patch for ShouldEnableXfaForms The ShouldEnableXfaForms function uses Profile::FromBrowserContext() which is not available in Electron. Wrap the profile-dependent code in #if 0 to fall through to the feature flag default. Co-Authored-By: Claude <noreply@anthropic.com> * chore: bump chromium in DEPS to 145.0.7563.0 * chore: bump chromium in DEPS to 145.0.7565.0 * chore: bump chromium in DEPS to 145.0.7567.0 * chore: bump chromium in DEPS to 145.0.7568.0 * fix(patch-conflict): update content_main_delegate.h context for IsInitFeatureListEarly Upstream added a new IsInitFeatureListEarly() virtual method to ContentMainDelegate just before where our GetBrowserV8SnapshotFilename() method is added. Updated patch context to account for this new method. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7092856 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * chore: update patch hunk headers Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(patch-update): include v8-cppgc.h for CppHeap complete type The std::unique_ptr<v8::CppHeap> default argument in node.h requires the complete CppHeap type definition for the destructor. Added the v8-cppgc.h include to provide the full type definition. Ref: Unable to locate CL - libc++ unique_ptr requires complete type for destructor Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * chore: update patch hunk headers Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(build): move NativeAppWindowFrameViewMacClient before constructor The std::unique_ptr<NativeAppWindowFrameViewMacClient> member requires the complete type definition to be visible at the point of the constructor because the unique_ptr destructor may be instantiated during exception handling. Moved the class definition before the NativeWindowMac constructor. Ref: Unable to locate CL - libc++ unique_ptr requires complete type for destructor Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * fix(patch-conflict): update create_browser_v8_snapshot_file_name_fuse context for IsInitFeatureListEarly The upstream added IsInitFeatureListEarly() virtual method declaration to ContentMainDelegate class. Updated the patch context to account for this new function being present before the GetBrowserV8SnapshotFilename() declaration we add. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7092856 Co-Authored-By: Claude <noreply@anthropic.com> * chore: update patch hunk headers Co-Authored-By: Claude <noreply@anthropic.com> * fix(patch-update): remove reverted IsInitFeatureListEarly from v8 snapshot patch The upstream added IsInitFeatureListEarly() was reverted, so the patch should not include this declaration. Only GetBrowserV8SnapshotFilename() should be added by the create_browser_v8_snapshot_file_name_fuse patch. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7230430 Co-Authored-By: Claude <noreply@anthropic.com> * 6171655: include single_thread_task_runner.h for complete type Added include for base/task/single_thread_task_runner.h in osr_converter.cc to resolve incomplete type error when using base::SingleThreadTaskRunner::GetCurrentDefault(). Ref: https://chromium-review.googlesource.com/c/chromium/src/+/6171655 Co-Authored-By: Claude <noreply@anthropic.com> * 7224136: use CHROMIUM_GIT_REVISION directly instead of removed function Upstream removed GetChromiumGitRevision() function from embedder_support. Updated to use CHROMIUM_GIT_REVISION macro directly via build/util/chromium_git_revision.h as recommended in the Chromium CL. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7224136 Co-Authored-By: Claude <noreply@anthropic.com> * fixup! 7224136: use CHROMIUM_GIT_REVISION directly instead of removed function * fix(build): add missing include `components/dbus/xdg/systemd.h` for `void OnSystemdUnitStarted(dbus_xdg::SystemdUnitStatus)` in the same patch. * fix(build): adapt to string-view-ification change in windows jump_list.cc 7186922: Fix unsafe buffer usage in base/win/win_util.cc https://chromium-review.googlesource.com/c/chromium/src/+/7186922 * chore: update libc++ filenames * fixup! fix(build): add missing include * fixup! fix(build): extend profile methods patch for ShouldEnableXfaForms * fixup! fix(build): guard media_file_system_registry for ChromeOS only * fixup! fixup! fix(build): extend profile methods patch for ShouldEnableXfaForms --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: Claude <svc-devxp-claude@slack-corp.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: clavin <clavin@electronjs.org>
195 lines
6.9 KiB
C++
195 lines
6.9 KiB
C++
// Copyright (c) 2025 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/gin_converters/osr_converter.h"
|
|
|
|
#include "gin/dictionary.h"
|
|
#include "v8-external.h"
|
|
#include "v8-function.h"
|
|
|
|
#include <string>
|
|
|
|
#include "base/containers/to_vector.h"
|
|
#include "base/task/single_thread_task_runner.h"
|
|
#if BUILDFLAG(IS_LINUX)
|
|
#include "base/strings/string_number_conversions.h"
|
|
#endif
|
|
#include "shell/common/gin_converters/gfx_converter.h"
|
|
#include "shell/common/gin_converters/optional_converter.h"
|
|
#include "shell/common/node_includes.h"
|
|
#include "shell/common/node_util.h"
|
|
|
|
namespace gin {
|
|
|
|
namespace {
|
|
std::string OsrVideoPixelFormatToString(media::VideoPixelFormat format) {
|
|
switch (format) {
|
|
case media::PIXEL_FORMAT_ARGB:
|
|
return "bgra";
|
|
case media::PIXEL_FORMAT_ABGR:
|
|
return "rgba";
|
|
case media::PIXEL_FORMAT_RGBAF16:
|
|
return "rgbaf16";
|
|
default:
|
|
NOTREACHED();
|
|
}
|
|
}
|
|
|
|
std::string OsrWidgetTypeToString(content::WidgetType type) {
|
|
switch (type) {
|
|
case content::WidgetType::kPopup:
|
|
return "popup";
|
|
case content::WidgetType::kFrame:
|
|
return "frame";
|
|
default:
|
|
NOTREACHED();
|
|
}
|
|
}
|
|
|
|
struct OffscreenReleaseHolderMonitor {
|
|
explicit OffscreenReleaseHolderMonitor(
|
|
electron::OffscreenReleaserHolder* holder)
|
|
: holder_(holder) {
|
|
CHECK(holder);
|
|
}
|
|
|
|
void ReleaseTexture() {
|
|
delete holder_;
|
|
holder_ = nullptr;
|
|
}
|
|
|
|
[[nodiscard]] bool IsTextureReleased() const { return holder_ == nullptr; }
|
|
|
|
v8::Persistent<v8::Value>* CreatePersistent(v8::Isolate* isolate,
|
|
v8::Local<v8::Value> value) {
|
|
persistent_ = std::make_unique<v8::Persistent<v8::Value>>(isolate, value);
|
|
return persistent_.get();
|
|
}
|
|
|
|
void ResetPersistent() const { persistent_->Reset(); }
|
|
|
|
private:
|
|
raw_ptr<electron::OffscreenReleaserHolder> holder_;
|
|
std::unique_ptr<v8::Persistent<v8::Value>> persistent_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
v8::Local<v8::Value> Converter<electron::OffscreenSharedTextureValue>::ToV8(
|
|
v8::Isolate* isolate,
|
|
const electron::OffscreenSharedTextureValue& val) {
|
|
gin::Dictionary root(isolate, v8::Object::New(isolate));
|
|
|
|
// Create a monitor to hold the releaser holder, which enables us to
|
|
// monitor whether the user explicitly released the texture before
|
|
// GC collects the object.
|
|
auto* monitor = new OffscreenReleaseHolderMonitor(val.releaser_holder);
|
|
|
|
auto releaserHolder = v8::External::New(isolate, monitor);
|
|
auto releaserFunc = [](const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
auto* mon = static_cast<OffscreenReleaseHolderMonitor*>(
|
|
info.Data().As<v8::External>()->Value());
|
|
// Release the shared texture, so that future frames can be generated.
|
|
mon->ReleaseTexture();
|
|
// Release the monitor happens at GC, don't release here.
|
|
};
|
|
auto releaser = v8::Function::New(isolate->GetCurrentContext(), releaserFunc,
|
|
releaserHolder)
|
|
.ToLocalChecked();
|
|
|
|
root.Set("release", releaser);
|
|
|
|
gin::Dictionary dict(isolate, v8::Object::New(isolate));
|
|
dict.Set("pixelFormat", OsrVideoPixelFormatToString(val.pixel_format));
|
|
dict.Set("codedSize", val.coded_size);
|
|
dict.Set("visibleRect", val.visible_rect);
|
|
dict.Set("contentRect", val.content_rect);
|
|
dict.Set("timestamp", val.timestamp);
|
|
dict.Set("colorSpace", val.color_space);
|
|
dict.Set("widgetType", OsrWidgetTypeToString(val.widget_type));
|
|
|
|
gin::Dictionary metadata(isolate, v8::Object::New(isolate));
|
|
metadata.Set("captureUpdateRect", val.capture_update_rect);
|
|
metadata.Set("regionCaptureRect", val.region_capture_rect);
|
|
metadata.Set("sourceSize", val.source_size);
|
|
metadata.Set("frameCount", val.frame_count);
|
|
dict.Set("metadata", ConvertToV8(isolate, metadata));
|
|
|
|
gin::Dictionary sharedTexture(isolate, v8::Object::New(isolate));
|
|
#if BUILDFLAG(IS_WIN)
|
|
sharedTexture.Set(
|
|
"ntHandle",
|
|
electron::Buffer::Copy(
|
|
isolate, base::byte_span_from_ref(val.shared_texture_handle))
|
|
.ToLocalChecked());
|
|
#elif BUILDFLAG(IS_MAC)
|
|
sharedTexture.Set(
|
|
"ioSurface",
|
|
electron::Buffer::Copy(
|
|
isolate, base::byte_span_from_ref(val.shared_texture_handle))
|
|
.ToLocalChecked());
|
|
#elif BUILDFLAG(IS_LINUX)
|
|
gin::Dictionary nativePixmap(isolate, v8::Object::New(isolate));
|
|
auto v8_planes = base::ToVector(val.planes, [isolate](const auto& plane) {
|
|
gin::Dictionary v8_plane(isolate, v8::Object::New(isolate));
|
|
v8_plane.Set("stride", plane.stride);
|
|
v8_plane.Set("offset", plane.offset);
|
|
v8_plane.Set("size", plane.size);
|
|
v8_plane.Set("fd", plane.fd);
|
|
return v8_plane;
|
|
});
|
|
nativePixmap.Set("planes", v8_planes);
|
|
nativePixmap.Set("modifier", base::NumberToString(val.modifier));
|
|
nativePixmap.Set("supportsZeroCopyWebGpuImport",
|
|
val.supports_zero_copy_webgpu_import);
|
|
sharedTexture.Set("nativePixmap", ConvertToV8(isolate, nativePixmap));
|
|
#endif
|
|
|
|
dict.Set("handle", ConvertToV8(isolate, sharedTexture));
|
|
root.Set("textureInfo", ConvertToV8(isolate, dict));
|
|
auto root_local = ConvertToV8(isolate, root);
|
|
|
|
// Create a persistent reference of the object, so that we can check the
|
|
// monitor again when GC collects this object.
|
|
auto* tex_persistent = monitor->CreatePersistent(isolate, root_local);
|
|
tex_persistent->SetWeak(
|
|
monitor,
|
|
[](const v8::WeakCallbackInfo<OffscreenReleaseHolderMonitor>& data) {
|
|
auto* monitor = data.GetParameter();
|
|
if (!monitor->IsTextureReleased()) {
|
|
// Emit a warning when user didn't properly manually release the
|
|
// texture, output it in second pass callback.
|
|
data.SetSecondPassCallback([](const v8::WeakCallbackInfo<
|
|
OffscreenReleaseHolderMonitor>& data) {
|
|
// Emit warning only once
|
|
static std::once_flag flag;
|
|
std::call_once(flag, [=] {
|
|
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
|
FROM_HERE, base::BindOnce([] {
|
|
electron::util::EmitWarning(
|
|
"Offscreen rendering shared texture was garbage "
|
|
"collected before calling `release()`. When using OSR "
|
|
"with `useSharedTexture: true`, `texture.release()` "
|
|
"must be called explicitly as soon as the texture is "
|
|
"copied to your rendering system. Otherwise, it will "
|
|
"soon drain the underlying frame pool and prevent "
|
|
"future frames from being sent.",
|
|
"OSRSharedTextureNotReleased");
|
|
}));
|
|
});
|
|
});
|
|
}
|
|
// We are responsible for resetting the persistent handle.
|
|
monitor->ResetPersistent();
|
|
// Finally, release the holder monitor.
|
|
delete monitor;
|
|
},
|
|
v8::WeakCallbackType::kParameter);
|
|
|
|
return root_local;
|
|
}
|
|
|
|
} // namespace gin
|