electron/shell/browser/osr
trop[bot] f5617bbc6a
chore: bump chromium to 142.0.7417.0 (39-x-y) (#48363)
* chore: bump chromium in DEPS to 142.0.7401.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* 6911185: Reland "Send touch moves async immediately after scroll starts."

https://chromium-review.googlesource.com/c/chromium/src/+/6911185

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6906887: mac: click through content area in main window

https://chromium-review.googlesource.com/c/chromium/src/+/6906887

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6916667: Expose helper to eliminate duplicate recipes.

https://chromium-review.googlesource.com/c/chromium/src/+/6916667

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6909842: Switch LegacyRenderWidgetHostHWND from atlcrack.h to msg_util.h.

https://chromium-review.googlesource.com/c/chromium/src/+/6909842

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6884056: Remove the SecKeychain implementation for the Keychain interface

https://chromium-review.googlesource.com/c/chromium/src/+/6884056

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6904906: Remove `WTF::` in renderer/core/[p-x].*/

https://chromium-review.googlesource.com/c/chromium/src/+/6904906

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6556585: [persistent_cache]: PersistentCache for CodeCache

https://chromium-review.googlesource.com/c/chromium/src/+/6556585

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6904864: Layout: Support abort on the text placeholder layout

https://chromium-review.googlesource.com/c/chromium/src/+/6904864

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup patch indices

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: bump chromium in DEPS to 142.0.7402.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* fixup! 6556585: [persistent_cache]: PersistentCache for CodeCache

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup patch indices

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6905244: [api] Remove deprecated `GetIsolate`

https://chromium-review.googlesource.com/c/v8/v8/+/6905244

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6897694: Remove NativeTheme::UserHasContrastPreference().

https://chromium-review.googlesource.com/c/chromium/src/+/6897694

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6897477: Remove GetPlatformHighContrastColorScheme() and enum.

https://chromium-review.googlesource.com/c/chromium/src/+/6897477

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6918198: Reland "Rename display::Screen::GetScreen() to display::Screen::Get()"

https://chromium-review.googlesource.com/c/chromium/src/+/6918198

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6907147: [LNA] add use counter for websocket mixed-content issues

https://chromium-review.googlesource.com/c/chromium/src/+/6907147

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6914538: Replace WTF::String with blink::String

https://chromium-review.googlesource.com/c/website/+/6914538

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6892538: [video pip] Allow touchscreen users to toggle live caption

https://chromium-review.googlesource.com/c/chromium/src/+/6892538

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fix patch

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: bump chromium in DEPS to 142.0.7403.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* build: remove ninja logs

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup patch indices

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6920670: [PDF] Change pdf_extension_util to return dictionaries

https://chromium-review.googlesource.com/c/chromium/src/+/6920670

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6917864: Devirtualize and inline various NativeTheme getters.

https://chromium-review.googlesource.com/c/chromium/src/+/6917864

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6920873: [PDF] Simplify PDFDocumentHelperClient::OnSaveURL()

https://chromium-review.googlesource.com/c/chromium/src/+/6920873

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* build: don't kill blink/web_tests

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6923655: Roll libc++ from 954086abf121 to b87b2bb112f8 (4 revisions)

https://chromium-review.googlesource.com/c/chromium/src/+/6923655

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6905242: Reland "[CSP] Clarify report-only console messages."

https://chromium-review.googlesource.com/c/chromium/src/+/6905242

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* fixup! 6897694: Remove NativeTheme::UserHasContrastPreference().

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: bump chromium in DEPS to 142.0.7405.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* 6910012: [LNA] Enable LNA enforcement by default

https://chromium-review.googlesource.com/c/chromium/src/+/6910012

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6929444: Combine GetInstanceForXXX() implementations.

https://chromium-review.googlesource.com/c/chromium/src/+/6929444

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6927873: Rename native_widget_types.h -> native_ui_types.h

https://chromium-review.googlesource.com/c/chromium/src/+/6927873

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6853978: Init perfetto really early in WebView

https://chromium-review.googlesource.com/c/chromium/src/+/6853978

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6874886: Use only one picker observer to avoid getting duplicate notifications

https://chromium-review.googlesource.com/c/chromium/src/+/6874886

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup patch indices

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* fix: Protocol complex inline dtor

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: bump chromium in DEPS to 142.0.7407.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* chore: bump chromium in DEPS to 142.0.7409.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* chore: bump chromium in DEPS to 142.0.7411.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* chore: bump chromium in DEPS to 142.0.7413.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* fixup! 6905242: Reland "[CSP] Clarify report-only console messages."

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6927233: Remove NativeTheme "use dark colors" bit.

https://chromium-review.googlesource.com/c/chromium/src/+/6927233

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup patch indices

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* 6899206: [PermissionOptions] Multi-state permission subscriptions & setting changes

https://chromium-review.googlesource.com/c/chromium/src/+/6899206

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: bump chromium in DEPS to 142.0.7415.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* 6936895: [headless] Remove headless flag from views::Widget class

https://chromium-review.googlesource.com/c/chromium/src/+/6936895

We should probably followup on this to see if there is a way to do this without reverting this CL.

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* 6937023: Reland "Use new DBus type system in dbus_xdg::Request"

https://chromium-review.googlesource.com/c/chromium/src/+/6937023

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* chore: update patches

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* 6944749: Add GN visibility list to //components/os_crypt/sync

https://chromium-review.googlesource.com/c/chromium/src/+/6944749

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* Further replace sub_capture_target_version with CaptureVersion

https://chromium-review.googlesource.com/c/chromium/src/+/6935455

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* fixup for lint

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* chore: update filenames.libcxx.gni

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* chore: bump chromium in DEPS to 142.0.7417.0

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>

* 6944136: Reorder NativeTheme headers/.cc files.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6944136

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6939701: [DSSC][4] Make FSVCI objects aware of their capture-version-source

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6939701

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6944404: Remove extraneous callback call

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6944404

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6936124: [FPF-CI]: Introduce blink::NoiseToken for fingerprinting protection

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6936124

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* chore: update patches

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* fixup! 6927233: Remove NativeTheme "use dark colors" bit.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6927233

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* fixup! 6917864: Devirtualize and inline various NativeTheme getters.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6917864

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6937588: Add initial OsSettingsProvider object, supplying caret blink interval.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6937588

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* fixup! 6905242: Reland "[CSP] Clarify report-only console messages."

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6905242

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6907515: Replace SingletonHwndObserver with a CallbackList on SingletonHwnd.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6907515

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* 6910482: [Save to Drive] Implement retry functionality

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6910482

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* fixup! 6927233: Remove NativeTheme "use dark colors" bit.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/6927233

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* Revert "build: remove ninja logs"

This reverts commit 72874740fdfca4101404ce7855e976791cfc79ef.

Co-authored-by: Alice Zhao <alicelovescake@anthropic.com>

* test: fix flakey test picked from PR 48205

Co-authored-by: Alice Zhao <alicelovescake@anthropic.com>

* chore: update patches

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Co-authored-by: Alice Zhao <alicelovescake@anthropic.com>
2025-09-24 11:56:54 -04:00
..
osr_host_display_client.cc chore: bump chromium to 134.0.6968.0 (main) (#45172) 2025-01-23 23:07:43 -05:00
osr_host_display_client.h feat: GPU shared texture offscreen rendering (#42953) 2024-08-22 19:23:13 -05:00
osr_host_display_client_mac.mm feat: GPU shared texture offscreen rendering (#42953) 2024-08-22 19:23:13 -05:00
osr_paint_event.cc feat: GPU shared texture offscreen rendering (#42953) 2024-08-22 19:23:13 -05:00
osr_paint_event.h feat: paint event move texture data to handle, add colorSpace (#47315) 2025-08-08 10:13:56 +02:00
osr_render_widget_host_view.cc chore: bump chromium to 142.0.7417.0 (39-x-y) (#48363) 2025-09-24 11:56:54 -04:00
osr_render_widget_host_view.h chore: bump chromium to 141.0.7346.0 (main) (#47983) 2025-08-11 12:57:31 +09:00
osr_video_consumer.cc feat: paint event move texture data to handle, add colorSpace (#47315) 2025-08-08 10:13:56 +02:00
osr_video_consumer.h chore: bump chromium to 142.0.7417.0 (39-x-y) (#48363) 2025-09-24 11:56:54 -04:00
osr_view_proxy.cc refactor: inline simple getters (#41125) 2024-01-29 20:43:28 -06:00
osr_view_proxy.h chore: bump chromium to 141.0.7346.0 (main) (#47983) 2025-08-11 12:57:31 +09:00
osr_web_contents_view.cc refactor: remove CreateViewForWidget patch (#46981) 2025-05-14 21:43:23 +09:00
osr_web_contents_view.h chore: bump chromium to 132.0.6807.0 (main) (#44360) 2024-11-04 09:10:00 -05:00
osr_web_contents_view_mac.mm chore: bump chromium to 136.0.7095.0 (main) (#46118) 2025-04-03 19:02:49 -05:00
README.md docs: add docs about shared texture mode osr (#45670) 2025-02-27 11:10:58 -05:00

Offscreen Rendering

Shared Texture Mode

This section provides a brief summary about how an offscreen frame is generated and how to handle it in native code. This only applies to the GPU-accelerated mode with shared texture, when webPreferences.offscreen.useSharedTexture is set to true.

Life of an Offscreen Frame

This is written at the time of Chromium 134 / Electron 35. The code may change in the future. The following description may not completely reflect the procedure, but it generally describes the process.

Initialization

  1. Electron JS creates a BrowserWindow with webPreferences.offscreen set to true.
  2. Electron C++ creates OffScreenRenderWidgetHostView, a subclass of RenderWidgetHostViewBase.
  3. It instantiates an OffScreenVideoConsumer, passing itself as a reference as view_.
  4. The OffScreenVideoConsumer calls view_->CreateVideoCapturer(), which makes Chromium code use HostFrameSinkManager to communicate with FrameSinkManagerImpl (in the Renderer Process) to create a ClientFrameSinkVideoCapturer and a FrameSinkVideoCapturerImpl (in the Renderer Process). It stores ClientFrameSinkVideoCapturer in video_capturer_.
  5. The OffScreenVideoConsumer registers the capture callback to OffScreenRenderWidgetHostView::OnPaint.
  6. It sets the target FPS, size constraints for capture, and calls video_capturer_->Start with the parameter viz::mojom::BufferFormatPreference::kPreferGpuMemoryBuffer to enable shared texture mode and start capturing.
  7. The FrameSinkVideoCapturerImpl accepts kPreferGpuMemoryBuffer and creates a GpuMemoryBufferVideoFramePool to copy the captured frame. The capacity is kFramePoolCapacity, currently 10, meaning it can capture at most 10 frames if the consumer doesn't consume them in time. It is stored in frame_pool_.
  8. The GpuMemoryBufferVideoFramePool creates a RenderableGpuMemoryBufferVideoFramePool using GmbVideoFramePoolContext as the context provider, responsible for creating GpuMemoryBuffer (or MappableSharedImage, as the Chromium team is removing the concept of GpuMemoryBuffer and may replace it with MappableSI in the future).
  9. The GmbVideoFramePoolContext initializes itself in both the Renderer Process and GPU Process.

Capturing

  1. The FrameSinkVideoCapturerImpl starts a capture when it receives an OnFrameDamaged event or is explicitly requested to refresh the frame. All event sources are evaluated by VideoCaptureOracle to see if the capture frequency meets the limit.
  2. If a frame is determined to be captured, FrameSinkVideoCapturerImpl calls frame_pool_->ReserveVideoFrame() to make the pool allocate a frame. The GmbVideoFramePoolContext then communicates with the GPU Process to create an actual platform-dependent texture (e.g., ID3D11Texture2D or IOSurface) that supports being shared across processes.
  3. The GPU Process wraps it into a GpuMemoryBuffer and sends it back to the Renderer Process, and the pool stores it for further usage.
  4. The FrameSinkVideoCapturerImpl then uses this allocated (or reused) frame to create a CopyOutputRequest and calls resolved_target_->RequestCopyOfOutput to copy the frame to the target texture. The resolved_target_ is a CapturableFrameSink that was previously resolved when calling CreateVideoCapturer using OffScreenRenderWidgetHostView.
  5. The GPU Process receives the request and renders the frame to the target texture using the requested format (e.g., RGBA). It then sends a completed event to the Renderer Process FrameSinkVideoCapturerImpl.
  6. The FrameSinkVideoCapturerImpl receives the completed event, provides feedback to the VideoCaptureOracle, and then calls frame_pool_->CloneHandleForDelivery with the captured frame to get a serializable handle to the frame (HANDLE or IOSurfaceRef). On Windows, it calls DuplicateHandle to create a new handle.
  7. It then creates a VideoFrameInfo with the frame info and the handle and calls consumer_->OnFrameCaptured to deliver the frame to the consumer.

Consuming

  1. OffScreenVideoConsumer::OnFrameCaptured is called when the frame is captured. It creates an Electron C++ struct OffscreenSharedTextureValue to extract the required info and handle from the callback. It then creates an OffscreenReleaserHolder to take ownership of the handle and the mojom remote releaser to prevent releasing.
  2. It calls the callback_ with the OffscreenSharedTextureValue, which goes to OffScreenRenderWidgetHostView::OnPaint. When shared texture mode is enabled, it directly redirects the callback to an OnPaintCallback target set during the initialization of OffScreenRenderWidgetHostView, currently set by OffScreenWebContentsView, whose callback_ is also set during initialization. Finally, it goes to WebContents::OnPaint.
  3. The WebContents::OnPaint uses gin_converter (osr_converter.cc) to convert the OffscreenSharedTextureValue to a v8::Object. It converts most of the value to a corresponding v8::Value, and the handle is converted to a Buffer. It also creates a release function to destroy the releaser and free the frame we previously took ownership of. The frame can now be reused for further capturing. Finally, it creates a release monitor to detect if the release function is called before the garbage collector destroys the JS object; if not, it prints a warning.
  4. The data is then emitted to the paint event of webContents. You can now grab the data and pass it to your native code for further processing. You can pass the textureInfo to other processes using Electron IPC, but you can only release it in the main process. Do not keep it for long, or it will drain the buffer pool.

Native Handling

You now have the texture info for the frame. Here's how you should handle it in native code. Suppose you write a node native addon to handle the shared texture.

Retrieve the handle from the textureInfo.sharedTextureHandle. You can also read the buffer in JS and use other methods.

auto textureInfo = args[0];
auto sharedTextureHandle =
    NAPI_GET_PROPERTY_VALUE(textureInfo, "sharedTextureHandle");

size_t handleBufferSize;
uint8_t* handleBufferData;
napi_get_buffer_info(env, sharedTextureHandle,
                      reinterpret_cast<void**>(&handleBufferData),
                      &handleBufferSize);

Import the handle to your rendering program.

// Windows
HANDLE handle = *reinterpret_cast<HANDLE*>(handleBufferData);
Microsoft::WRL::ComPtr<ID3D11Texture2D> shared_texture = nullptr;
HRESULT hr = device1->OpenSharedResource1(handle, IID_PPV_ARGS(&shared_texture)); 

// Extract the texture description
D3D11_TEXTURE2D_DESC desc;
shared_texture->GetDesc(&desc);

// Cache the staging texture if it does not exist or size has changed
if (!cached_staging_texture || cached_width != desc.Width ||
    cached_height != desc.Height) {
  if (cached_staging_texture) {
    cached_staging_texture->Release();
  }

  desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
  desc.Usage = D3D11_USAGE_STAGING;
  desc.BindFlags = 0;
  desc.MiscFlags = 0;

  std::cout << "Create staging Texture2D width=" << desc.Width
            << " height=" << desc.Height << std::endl;
  hr = device->CreateTexture2D(&desc, nullptr, &cached_staging_texture);

  cached_width = desc.Width;
  cached_height = desc.Height;
}

// Copy to a intermediate texture
context->CopyResource(cached_staging_texture.Get(), shared_texture.Get());
// macOS
IOSurfaceRef handle = *reinterpret_cast<IOSurfaceRef*>(handleBufferData);

// Assume you have created a GL context.

GLuint io_surface_tex;
glGenTextures(1, &io_surface_tex);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, io_surface_tex);

CGLContextObj cgl_context = CGLGetCurrentContext();

GLsizei width = (GLsizei)IOSurfaceGetWidth(io_surface);
GLsizei height = (GLsizei)IOSurfaceGetHeight(io_surface);

CGLTexImageIOSurface2D(cgl_context, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA8, width,
                        height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
                        io_surface, 0);

glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

// Copy to a intermediate texture from io_surface_tex
// ...

As introduced above, the shared texture is not a single fixed texture that Chromium draws on every frame (CEF before Chromium 103 works that like, please note this significate difference). It is a pool of textures, so every frame Chromium may pass a different texture to you. As soon as you call release, the texture will be reused by Chromium and may cause picture corruption if you keep reading from it. It is also wrong to only open the handle once and directly read from that opened texture on later events. Be very careful if you want to cache the opened texture(s), on Windows, the duplicated handle's value will not be a reliable mapping to the actual underlying texture.

The suggested way is always open the handle on every event, and copy the shared texture to a intermediate texture that you own and release it as soon as possible. You can use the copied texture for further rendering whenever you want. Opening a shared texture should only takes couple microseconds, and you can also use the damaged rect to only copy a portion of the texture to speed up.

You can also refer to these examples: