From 2200a70e8d8debc59f7d8d315b17e208393def2a Mon Sep 17 00:00:00 2001 From: reito Date: Fri, 21 Nov 2025 23:32:29 +0800 Subject: [PATCH] feat: import shared texture supports nv12. (#48922) --- .../structures/shared-texture-import-texture-info.md | 1 + shell/common/api/electron_api_shared_texture.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/api/structures/shared-texture-import-texture-info.md b/docs/api/structures/shared-texture-import-texture-info.md index 47c9338c8f..813aa70c5e 100644 --- a/docs/api/structures/shared-texture-import-texture-info.md +++ b/docs/api/structures/shared-texture-import-texture-info.md @@ -4,6 +4,7 @@ * `bgra` - 32bpp BGRA (byte-order), 1 plane. * `rgba` - 32bpp RGBA (byte-order), 1 plane. * `rgbaf16` - Half float RGBA, 1 plane. + * `nv12` - 12bpp with Y plane followed by a 2x2 interleaved UV plane. * `colorSpace` [ColorSpace](color-space.md) (optional) - The color space of the texture. * `codedSize` [Size](size.md) - The full dimensions of the shared texture. * `visibleRect` [Rectangle](rectangle.md) (optional) - A subsection of [0, 0, codedSize.width, codedSize.height]. In common cases, it is the full section area. diff --git a/shell/common/api/electron_api_shared_texture.cc b/shell/common/api/electron_api_shared_texture.cc index f8b825bb10..626d4eb8ab 100644 --- a/shell/common/api/electron_api_shared_texture.cc +++ b/shell/common/api/electron_api_shared_texture.cc @@ -126,6 +126,8 @@ std::string TransferVideoPixelFormatToString(media::VideoPixelFormat format) { return "rgba"; case media::PIXEL_FORMAT_RGBAF16: return "rgbaf16"; + case media::PIXEL_FORMAT_NV12: + return "nv12"; default: NOTREACHED(); } @@ -566,6 +568,8 @@ struct Converter { out->pixel_format = media::PIXEL_FORMAT_ABGR; else if (pixel_format_str == "rgbaf16") out->pixel_format = media::PIXEL_FORMAT_RGBAF16; + else if (pixel_format_str == "nv12") + out->pixel_format = media::PIXEL_FORMAT_NV12; else return false; } @@ -730,6 +734,14 @@ v8::Local ImportSharedTexture(v8::Isolate* isolate, shared_image_usage, "SharedTextureVideoFrame"}, std::move(gmb_handle)); + if (!si) { + gin_helper::ErrorThrower(isolate).ThrowTypeError( + "Failed to create shared image from shared texture handle. Texture " + "format or dimension might not be supported on current device or " + "platform."); + return v8::Null(isolate); + } + ImportedSharedTexture* imported = new ImportedSharedTexture(); imported->pixel_format = shared_texture.pixel_format; imported->coded_size = shared_texture.coded_size;