chromium/third_party/blink/public/mojom/input/synchronous_compositor.mojom

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

module blink.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_metadata.mojom";
import "services/viz/public/mojom/compositing/frame_timing_details.mojom";
import "services/viz/public/mojom/compositing/local_surface_id.mojom";
import "services/viz/public/mojom/compositing/returned_resource.mojom";
import "services/viz/public/mojom/hit_test/hit_test_region_list.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "ui/gfx/mojom/transform.mojom";

struct SyncCompositorDemandDrawHwParams {
  gfx.mojom.Size viewport_size;
  gfx.mojom.Rect viewport_rect_for_tile_priority;
  gfx.mojom.Transform transform_for_tile_priority;
  bool need_new_local_surface_id;
};

struct SyncCompositorDemandDrawSwParams {
  gfx.mojom.Size size;
  gfx.mojom.Rect clip;
  gfx.mojom.Transform transform;
};

struct SyncCompositorCommonRendererParams {
  uint32 version = 0;
  gfx.mojom.PointF total_scroll_offset;
  gfx.mojom.PointF max_scroll_offset;
  gfx.mojom.SizeF scrollable_size;
  float page_scale_factor = 0;
  float min_page_scale_factor = 0;
  float max_page_scale_factor = 0;
  uint32 need_invalidate_count = 0;
  bool invalidate_needs_draw = true;
  uint32 did_activate_pending_tree_count = 0;
};

// The SynchronousCompositor is an interface that is used by Android Webview
// which must control the compositor synchronously. It does this so that
// java UI is drawn in lock step with content renderer by the webview.
// The SynchronousCompositor is an associated interface with WidgetInputHandler
// because input must be delivered in order with the compositing events.
interface SynchronousCompositor {
  // Hardware draw asynchronously, ReturnFrame will return the result on
  // the associated SynchronousCompositorControlHost.
  DemandDrawHwAsync(SyncCompositorDemandDrawHwParams draw_params);

  // Same as |DemandDrawHwAsync| except it's synchronous and blocks the caller
  // thread.
  [Sync]
  DemandDrawHw(SyncCompositorDemandDrawHwParams draw_params) =>
      (SyncCompositorCommonRendererParams result,
       uint32 layer_tree_frame_sink_id,
       uint32 metadata_version,
       viz.mojom.LocalSurfaceId? local_surface_id,
       viz.mojom.CompositorFrame? frame,
       viz.mojom.HitTestRegionList? hit_test_region_list);

  // Synchronously sets the shared memory used for resourceless software
  // drawing. This mode just has the renderer send over a single bitmap of the
  // final frame, rather than sending over individual tiles (ie. resources)
  // that are then composited by the browser.
  [Sync]
  SetSharedMemory(mojo_base.mojom.WritableSharedMemoryRegion shm_region) =>
      (bool success, SyncCompositorCommonRendererParams result);

  // Synchronously does a software based draw.
  [Sync] DemandDrawSw(SyncCompositorDemandDrawSwParams draw_params) =>
      (SyncCompositorCommonRendererParams result,
       uint32 metadata_version,
       viz.mojom.CompositorFrameMetadata? meta_data);

  // Instead of drawing, allow the compositor to finish the frame and update
  // tiles if needed.
  WillSkipDraw();

  // Zero out the shared memory. This is necessary since most of the time,
  // viewport size doesn't change between draws, it's cheaper to zero out
  // and reuse the shared memory, instead of allocating and mapping a new
  // one each frame.
  ZeroSharedMemory();

  // Synchronously zoom by adjusting the page scale factor by delta around
  // the anchor point.
  [Sync] ZoomBy(float delta, gfx.mojom.Point anchor) =>
      (SyncCompositorCommonRendererParams result);

  // Adjust the memory policy of the compositor. Explicitly how much the
  // compositor can use without changing visibility. ie. The limit on
  // amount of memory used for caching tiles.
  SetMemoryPolicy(uint32 bytes_limit);

  // Attempt to reclaim resources.
  ReclaimResources(uint32 layer_tree_frame_sink_id,
                   array<viz.mojom.ReturnedResource> resources);

  // Notifies the client when a directive for ViewTransition, submitted in
  // a previous CompositorFrame, has finished executing.
  OnCompositorFrameTransitionDirectiveProcessed(uint32 layer_tree_frame_sink_id,
                                                uint32 sequence_id);

  // Adjust the scroll to the given offset.
  SetScroll(gfx.mojom.PointF offset);

  // BeginFrame, update will be pushed via SynchronousCompositorControlHost
  // BeginFrameResponse.
  // |timing_details| is a map from frame token to FrameTimingDetails.
  // Frame token is an incrementing id generated by untrusted viz client
  // (renderer) and sent to viz service (browser) in a frame (see
  // CompositorFrameMetadata). FrameTimingDetails contains info of viz server
  // displaying frames, such as time of display. The index of the map is the
  // frame token of the previously submitted frame that has been displayed.
  // Note that the viz server might choose to skip display some of the
  // previously submitted frames; however, feedback about all previously
  // submitted frames will be sent back once a new frame is displayed.
  BeginFrame(viz.mojom.BeginFrameArgs args,
             map<uint32, viz.mojom.FrameTimingDetails> timing_details);

  // Indicates BeginFrame messages are paused.
  SetBeginFrameSourcePaused(bool paused);
};

// Interface that runs on the UI thread of the browser. To be used
// for responses to most messages.
interface SynchronousCompositorHost {
  // Indicates the layer tree was created.
  LayerTreeFrameSinkCreated();

  // Notification of new compositor information.
  UpdateState(SyncCompositorCommonRendererParams params);

  // Notifies the that a begin frame is needed or not.
  SetNeedsBeginFrames(bool needs_begin_frames);

  // Passes IDs of threads involved in frame production to the compositor.
  // The IDs are then passed through HWUI to the Android PerformanceHint API
  // to dynamically adjust performance.
  // This is similar to CompositorFrameSink.SetThreadIds, but for WebView.
  SetThreadIds(array<int32> thread_ids);
};

// Interface that runs on the IO thread of the browser. To be used for responses
// to messages that need to wait for the response to be available before
// execution continues. Typically the browser UI thread will dispatch some
// messages asynchronously via the SynchronousCompositor interface but then
// reach a point at which a response must be available. For example the
// BeginFrame is sent to all attached WebViews but before the Android VSync
// execution flow (from java) returns the responses from BeginFrames must be
// received.
interface SynchronousCompositorControlHost {
  // Response from DemandDrawHwAsync.
  ReturnFrame(uint32 layer_tree_frame_sink_id,
              uint32 metadata_version,
              viz.mojom.LocalSurfaceId? local_surface_id,
              viz.mojom.CompositorFrame? frame,
              viz.mojom.HitTestRegionList? hit_test_region_list);

  // Response from BeginFrame.
  BeginFrameResponse(SyncCompositorCommonRendererParams params);
};