Repository: electron/electron
File: shell/browser/osr/osr_video_consumer.cc (C++)

Code before:
  // there's no need to call the callbacks, see in_flight_frame_delivery.cc
  // The destructor will call Done for us once the pipe closed.

  // Offscreen using GPU shared texture
  if (view_->offscreen_use_shared_texture()) {
    CHECK(data->is_gpu_memory_buffer_handle());

    auto& orig_handle = data->get_gpu_memory_buffer_handle();
    CHECK(!orig_handle.is_null());

    // Clone the handle to support keep the handle alive after the callback
    auto gmb_handle = orig_handle.Clone();

    OffscreenSharedTextureValue texture;
    texture.pixel_format = info->pixel_format;
    texture.coded_size = info->coded_size;
    texture.visible_rect = info->visible_rect;
    texture.content_rect = content_rect;
    texture.color_space = info->color_space;
    texture.timestamp = info->timestamp.InMicroseconds();
    texture.frame_count = info->metadata.capture_counter.value_or(0);
    texture.capture_update_rect = info->metadata.capture_update_rect;
    texture.source_size = info->metadata.source_size;
    texture.region_capture_rect = info->metadata.region_capture_rect;
    texture.widget_type = view_->GetWidgetType();
    texture.is_webgpu_compatible = info->metadata.is_webgpu_compatible;

#if BUILDFLAG(IS_WIN)
    texture.shared_texture_handle =
        reinterpret_cast<uintptr_t>(gmb_handle.dxgi_handle().buffer_handle());
#elif BUILDFLAG(IS_APPLE)
    texture.shared_texture_handle =
        reinterpret_cast<uintptr_t>(gmb_handle.io_surface().get());
#elif BUILDFLAG(IS_LINUX)
    const auto& native_pixmap = gmb_handle.native_pixmap_handle();
    texture.modifier = native_pixmap.modifier;
    texture.supports_zero_copy_webgpu_import =
        native_pixmap.supports_zero_copy_webgpu_import;
    for (const auto& plane : native_pixmap.planes) {
      texture.planes.emplace_back(plane.stride, plane.offset, plane.size,
                                  plane.fd.get());
    }
#endif

    // The release holder will be released from JS side when `release` called
    texture.releaser_holder = new OffscreenReleaserHolder(std::move(gmb_handle),
                                                          std::move(callbacks));

    callback_.Run(content_rect, {}, std::move(texture));
    return;
  }

Review comment (suggestion):
Are `is_webgpu_compatible` and `supports_zero_copy_webgpu_import` exposed/used anywhere? I see them being copied, but I don't see any other code that references them.

Code after:
  // there's no need to call the callbacks, see in_flight_frame_delivery.cc
  // The destructor will call Done for us once the pipe closed.

  // Offscreen using GPU shared texture
  if (view_->offscreen_use_shared_texture()) {
    CHECK(data->is_gpu_memory_buffer_handle());

    auto& orig_handle = data->get_gpu_memory_buffer_handle();
    CHECK(!orig_handle.is_null());

    // Clone the handle to support keep the handle alive after the callback
    auto gmb_handle = orig_handle.Clone();

    OffscreenSharedTextureValue texture;
    texture.pixel_format = info->pixel_format;
    texture.coded_size = info->coded_size;
    texture.visible_rect = info->visible_rect;
    texture.content_rect = content_rect;
    texture.color_space = info->color_space;
    texture.timestamp = info->timestamp.InMicroseconds();
    texture.frame_count = info->metadata.capture_counter.value_or(0);
    texture.capture_update_rect = info->metadata.capture_update_rect;
    texture.source_size = info->metadata.source_size;
    texture.region_capture_rect = info->metadata.region_capture_rect;
    texture.widget_type = view_->GetWidgetType();

#if BUILDFLAG(IS_WIN)
    texture.shared_texture_handle =
        reinterpret_cast<uintptr_t>(gmb_handle.dxgi_handle().buffer_handle());
#elif BUILDFLAG(IS_APPLE)
    texture.shared_texture_handle =
        reinterpret_cast<uintptr_t>(gmb_handle.io_surface().get());
#elif BUILDFLAG(IS_LINUX)
    const auto& native_pixmap = gmb_handle.native_pixmap_handle();
    texture.modifier = native_pixmap.modifier;
    texture.supports_zero_copy_webgpu_import =
        native_pixmap.supports_zero_copy_webgpu_import;
    for (const auto& plane : native_pixmap.planes) {
      texture.planes.emplace_back(plane.stride, plane.offset, plane.size,
                                  plane.fd.get());
    }
#endif

    // The release holder will be released from JS side when `release` called
    texture.releaser_holder = new OffscreenReleaserHolder(std::move(gmb_handle),
                                                          std::move(callbacks));

    callback_.Run(content_rect, {}, std::move(texture));
    return;
  }