1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57

cc / slim / delayed_scheduler.h [blame]

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

#ifndef CC_SLIM_DELAYED_SCHEDULER_H_
#define CC_SLIM_DELAYED_SCHEDULER_H_

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "cc/slim/scheduler.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"

namespace cc::slim {

// DelayedScheduler is optimized specifically for the case of renderer-driven
// scrolling of browser controls in the browser compositor on Android.
// The design aims to immediately submit frame whenever scroll offset arrives
// from the renderer:
// * Expect `MaybeCompositeNow` to be called when scroll offset from renderer
//   arrives.
// * Cache BeginFrameArgs from `OnBeginFrameFromViz` and wait until either
//   `MaybeCompositeNow` or until the next `OnBeginFrameFromViz`. This increases
//   the latency for other cases that does not call `MaybeCompositeNow` by one
//   frame.
// * If `MaybeCompositeNow` is blocked from producing a frame due to some
//   condition, immediately attempt producing from again if the condition
//   changes.
// TODO(boliu): Move this to //content after slim is enabled for browser
// compositor on android.
class COMPONENT_EXPORT(CC_SLIM) DelayedScheduler : public Scheduler {
 public:
  DelayedScheduler();
  ~DelayedScheduler() override;

  void Initialize(SchedulerClient* client) override;
  void OnBeginFrameFromViz(
      const viz::BeginFrameArgs& begin_frame_args) override;
  void OnBeginFramePausedChanged(bool paused) override;
  void SetNeedsBeginFrame(bool needs_begin_frame) override;
  void SetIsSwapThrottled(bool is_swap_throttled) override;
  void MaybeCompositeNow() override;

 private:
  void BeginFrameAndResetArgs(viz::BeginFrameArgs& args);
  void SendDidNotProduceFrameAndResetArgs(viz::BeginFrameArgs& args);

  raw_ptr<SchedulerClient> client_ = nullptr;

  viz::BeginFrameArgs unused_args_;
  bool needs_begin_frame_ = false;
  bool is_swap_throttled_ = false;
  bool missed_composite_now_ = false;
};

}  // namespace cc::slim

#endif  // CC_SLIM_DELAYED_SCHEDULER_H_