chromium/services/viz/public/mojom/compositing/frame_sink_bundle.mojom

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

module viz.mojom;

import "mojo/public/mojom/base/shared_memory.mojom";
import "services/viz/public/mojom/compositing/begin_frame_args.mojom";
import "services/viz/public/mojom/compositing/compositor_frame.mojom";
import "services/viz/public/mojom/compositing/compositor_frame_sink.mojom";
import "services/viz/public/mojom/compositing/shared_bitmap_id.mojom";
import "services/viz/public/mojom/compositing/local_surface_id.mojom";
import "services/viz/public/mojom/compositing/frame_timing_details.mojom";
import "services/viz/public/mojom/compositing/returned_resource.mojom";
import "services/viz/public/mojom/hit_test/hit_test_region_list.mojom";

// Encapsulates either a single SubmitCompositorFrame call or a single
// DidNotProduceFrameCall on behalf of a specific frame sink.
struct BundledFrameSubmission {
  // The ID of the frame sink which submitted this data. Scoped to the
  // corresponding bundle's client ID.
  uint32 sink_id;

  // Data detailing the submission.
  BundledFrameSubmissionData data;
};

// Represents data for a batched request equivalent to some CompositorFrameSink
// message.
union BundledFrameSubmissionData {
  // Data for a SubmitCompositorFrame call.
  BundledCompositorFrame frame;

  // Data for a DidNotProduceFrame call.
  BeginFrameAck did_not_produce_frame;

  // Data for a DidDeleteSharedBitmap call.
  SharedBitmapId did_delete_shared_bitmap;
};

// SubmitCompositorFrame parameters, as bundled by BundledFrameSubmissionData
// above. Each field here corresponds to a SubmitCompositorFrame argument.
struct BundledCompositorFrame {
  LocalSurfaceId local_surface_id;
  CompositorFrame frame;
  HitTestRegionList? hit_test_region_list;
  uint64 submit_time;
};

// Controls an endpoint for aggregate communication regarding a collection of
// related frame sinks.
interface FrameSinkBundle {
  // Corresponds to a single message of the same name on CompositorFrameSink
  // for the identified sink.
  InitializeCompositorFrameSinkType(
      uint32 sink_id, CompositorFrameSinkType type);

  // Corresponds to a single message of the same name on CompositorFrameSink
  // for the identified sink.
  SetNeedsBeginFrame(uint32 sink_id, bool needs_begin_frame);

  // Corresponds to a single message of the same name on CompositorFrameSink
  // for the identified sink.
  SetWantsBeginFrameAcks(uint32 sink_id);

  // Corresponds to a series of batched requests equivalent to calls across
  // arbitrary CompositorFrameSinks for frame sinks belonging to this bundle.
  // Can be used to substantially reduce IPC traffic when many related sinks are
  // submitting frames at the same time.
  [UnlimitedSize]
  Submit(array<BundledFrameSubmission> submissions);

  // Corresponds to a single message of the same name on CompositorFrameSink
  // for the identified sink.
  DidAllocateSharedBitmap(
      uint32 sink_id, mojo_base.mojom.ReadOnlySharedMemoryRegion region,
      SharedBitmapId id);

  // Corresponds to a single message of the same name on CompositorFrameSink
  // for the identified sink.
  [EnableIf=is_android]
  SetThreadIds(uint32 sink_id, array<int32> thread_ids);
};

// A set of ReturnedResources belonging to a specific frame sink.
struct BundledReturnedResources {
  uint32 sink_id;
  array<ReturnedResource> resources;
};

// Encapsulates details of an OnBeginFrame() notification for a specific frame
// sink. A batchable equivalent to CompositorFrameSinkClient.OnBeginFrame().
struct BeginFrameInfo {
  uint32 sink_id;
  BeginFrameArgs args;
  map<uint32, FrameTimingDetails> details;
  bool frame_ack;
  array<ReturnedResource> resources;
};

// Client interface for FrameSinkBundle. This behaves as an aggregated
// CompositorFrameSinkClient interface.
interface FrameSinkBundleClient {
  // Flushes a series of batched notifications corresponding to any number of
  // DidReceiveCompositorFrameAck, OnBeginFrame, and/or ReclaimResources
  // messages for individual CompositorFrameSinkClients. Note that although
  // both DidReceiveCompositorFrameAck and ReclaimResources send the same kind
  // of data, we keep them separated since they have different meaning to the
  // client.
  FlushNotifications(array<BundledReturnedResources> acks,
                     array<BeginFrameInfo> begin_frames,
                     array<BundledReturnedResources> reclaimed_resources);

  // Corresponds to a single message of the same name on
  // CompositorFrameSinkClient for the identified sink.
  OnBeginFramePausedChanged(uint32 sink_id, bool paused);

  // Corresponds to a single message of the same name on
  // CompositorFrameSinkClient for the identified sink.
  OnCompositorFrameTransitionDirectiveProcessed(
      uint32 sink_id, uint32 sequence_id);
};