chromium/chromeos/crosapi/mojom/screen_manager.mojom

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module crosapi.mojom;

import "chromeos/crosapi/mojom/bitmap.mojom";
import "chromeos/crosapi/mojom/video_capture.mojom";
import "skia/public/mojom/bitmap.mojom";

// A unique identifier and title for a window (or screen).
[Stable, RenamedFrom="crosapi.mojom.WindowDetails"]
struct SnapshotSource {
  // Guaranteed to be unique and never reused. This represents an ID that is
  // only significant to the SnapshotCapturer, and may not have meaning for
  // identifying any shared windows. (e.g. windows that are Lacros-owned).
  uint64 id@0;

  // The user-visible name of the window or screen in UTF-8 encoding.
  string title@1;

  // The unique id assigned to the window. This ID is shared between
  // Lacros-chrome and Ash-chrome and will thus only be set for Lacros-owned
  // windows, but will allow looking up which owned window this source
  // corresponds to. Will only be set for Lacros-owned windows.
  [MinVersion=1]
  string? window_unique_id@2;

  // Display specific unique identifier that can be used to connect a
  // |SnapshotSource| representing a display to other subsystems like
  // the window placement API.
  [MinVersion=2]
  int64 display_id@3;
};

// This interface is used to capture bitmap snapshots of screens or windows.
// See ScreenManager methods used to create instances of this interface.
[Stable, Uuid="90487679-7dc8-40ad-a1e4-e741def0d79f"]
interface SnapshotCapturer {
  // Returns list of screens or windows that can be captured.
  [Sync]
  ListSources@0() => (array<SnapshotSource> sources);

  // Captures a bitmap snapshot of the specified screen or window. If |success|
  // is false, that may indicate that the specified source no longer exists.
  [Sync]
  TakeSnapshot@1(uint64 id) =>
      (bool success,
       skia.mojom.BitmapMappedFromTrustedProcess? snapshot);
};

// This interface is implemented by ash-chrome. It allows lacros-chrome to query
// information about existing windows, screens, and displays.
//
// This interface cannot be used to make changes to screens, windows or
// displays. That's because Wayland is the protocol for that, and attempting to
// introduce another protocol would require careful synchronization between the
// two, which we'd like to avoid.
//
// TODO(crbug.com/40135428): This is a very simple interface. We will
// likely want to replace it with a more feature-complete and performant
// interface in the future.
[Stable, Uuid="95c3035c-5c63-45e3-8ec8-dd2a344c7dc2"]
interface ScreenManager {
  // DEPRECATED. Unimplemented and unused. Delete this once deletion is
  // supported. https://crbug.com/1156872.
  [Sync]
  DeprecatedTakeScreenSnapshot@0() => (Bitmap snapshot);
  [Sync]
  DeprecatedListWindows@1() => (array<SnapshotSource> windows);
  [Sync]
  DeprecatedTakeWindowSnapshot@2(uint64 id) => (bool success, Bitmap snapshot);

  // Get a SnapshotCapturer instance that can snapshot available screens.
  [MinVersion=1]
  GetScreenCapturer@3(pending_receiver<SnapshotCapturer> capturer);

  // Get a SnapshotCapturer instance that can snapshot available windows.
  [MinVersion=1]
  GetWindowCapturer@4(pending_receiver<SnapshotCapturer> capturer);

  // Get a VideoCaptureDevice instance that can capture a video stream of the
  // specified screen. |screen_id| should be retrieved from the (Screen)
  // SnapshotCapturer::ListSources.
  [MinVersion=2]
  GetScreenVideoCapturer@5(pending_receiver<VideoCaptureDevice> capturer,
                      uint64 screen_id);

  // Get a VideoCaptureDevice instance that can capture a video stream of the
  // specified screen. |window_id| should be retrieved from the (Window)
  // SnapshotCapturer::ListSources.
  [MinVersion=2]
  GetWindowVideoCapturer@6(pending_receiver<VideoCaptureDevice> capturer,
                      uint64 window_id);
};