File: presenter.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (175 lines) | stat: -rw-r--r-- 6,349 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GL_PRESENTER_H_
#define UI_GL_PRESENTER_H_

#include <optional>

#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/gfx/delegated_ink_metadata.h"
#include "ui/gfx/frame_data.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h"
#include "ui/gl/gl_export.h"

#if BUILDFLAG(IS_OZONE)
#include "ui/gfx/native_pixmap.h"
#endif

#if BUILDFLAG(IS_APPLE)
#include "ui/gfx/mac/io_surface.h"
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/scoped_hardware_buffer_fence_sync.h"
#include "ui/gfx/android/surface_control_frame_rate.h"
#endif

#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#endif

namespace gfx {
namespace mojom {
class DelegatedInkPointRenderer;
}  // namespace mojom
class ColorSpace;
class GpuFence;
struct OverlayPlaneData;
}  // namespace gfx

namespace ui {
struct CARendererLayerParams;
}  // namespace ui

namespace gl {
struct DCLayerOverlayParams;

// OverlayImage is a platform specific type for overlay plane image data.
#if BUILDFLAG(IS_OZONE)
using OverlayImage = scoped_refptr<gfx::NativePixmap>;
#elif BUILDFLAG(IS_APPLE)
using OverlayImage = gfx::ScopedIOSurface;
#elif BUILDFLAG(IS_ANDROID)
using OverlayImage =
    std::unique_ptr<base::android::ScopedHardwareBufferFenceSync>;
#else
struct OverlayImage {};
#endif

// Provides an abstraction around system api for presentation of the overlay
// planes and control presentations parameters (e.g frame rate). Temporarily is
// in ui/gl. Once its GL deps are resolved, it will be moved to ui/gfx.
class GL_EXPORT Presenter : public base::RefCounted<Presenter> {
 public:
  // Called not earlier than when the buffers from corresponding Present() call
  // are visible on screen. Note, that on some platforms there is no exact
  // signal of when the frame is on screen or presenter has to poll some system
  // flag, so this callback can come back reasonably later and should be used
  // only for metrics purpose.
  using PresentationCallback =
      base::OnceCallback<void(const gfx::PresentationFeedback& feedback)>;
  // Called when the system compositor or display controller latched new buffers
  // and they are going to be displayed at next scanout.
  using SwapCompletionCallback =
      base::OnceCallback<void(gfx::SwapCompletionResult)>;

  Presenter();

  virtual bool SupportsOverridePlatformSize() const;
  virtual bool SupportsViewporter() const;
  virtual bool SupportsPlaneGpuFences() const;

  virtual void SetVSyncDisplayID(int64_t display_id) {}

  // Resizes the presenter, returning success.
  virtual bool Resize(const gfx::Size& size,
                      float scale_factor,
                      const gfx::ColorSpace& color_space,
                      bool has_alpha);

  // Schedule an overlay plane to be shown on the next Present() call. Should be
  // called for each overlay plane that is present in a frame before
  // the corresponding Present() call. Note, that this method doesn't put
  // anything on screen by itself, it's just adds the overlay to the current
  // frame, presentation of all planes is handled atomically by Present().
  // |image| to be presented by the overlay. |gpu_fence| is a fence for display
  // controller to wait before present. |overlay_plane_data| specifies overlay
  // data such as opacity, z_order, size, etc.
  virtual bool ScheduleOverlayPlane(
      OverlayImage image,
      std::unique_ptr<gfx::GpuFence> gpu_fence,
      const gfx::OverlayPlaneData& overlay_plane_data);

  // Schedule a CALayer to be shown at next Present(). Semantics is similar to
  // ScheduleOverlayPlane() above. All arguments correspond to their CALayer
  // properties.
  virtual bool ScheduleCALayer(const ui::CARendererLayerParams& params);

#if BUILDFLAG(IS_WIN)
  // Schedule a list of DCLayers to be shown at next Present(). Semantics is
  // similar to calling ScheduleOverlayPlane() for every overlay in a frame. All
  // arguments correspond to their DCLayer properties.
  virtual void ScheduleDCLayers(std::vector<DCLayerOverlayParams> overlays);

  // Destroy all visual tree resources and commit, returning true on success.
  virtual bool DestroyDCLayerTree();
#endif

  // Presents current frame asynchronously. `completion_callback` will be called
  // once all necessary steps were taken to display the frame.
  // `presentation_callback` will be called once frame was displayed and
  // presentation feedback was collected.
  virtual void Present(SwapCompletionCallback completion_callback,
                       PresentationCallback presentation_callback,
                       gfx::FrameData data) = 0;

#if BUILDFLAG(IS_APPLE)
  virtual void SetMaxPendingSwaps(int max_pending_swaps) {}
#endif

#if BUILDFLAG(IS_ANDROID)
  // Sets preferred frame rate
  virtual void SetFrameRate(gfx::SurfaceControlFrameRate frame_rate) {}
#endif

  // Android specific. Sets vsync_id of the corresponding Choreographer frame.
  virtual void SetChoreographerVsyncIdForNextFrame(
      std::optional<int64_t> choreographer_vsync_id) {}

  // Android specific. Request to not clean-up surface control tree, relying on
  // Android to do so after app switching animation is done.
  virtual void PreserveChildSurfaceControls() {}

#if BUILDFLAG(IS_WIN)
  virtual bool SupportsDelegatedInk() = 0;
  virtual void SetDelegatedInkTrailStartPoint(
      std::unique_ptr<gfx::DelegatedInkMetadata> metadata) {}
  virtual void InitDelegatedInkPointRendererReceiver(
      mojo::PendingReceiver<gfx::mojom::DelegatedInkPointRenderer>
          pending_receiver) {}
  virtual HWND GetWindow() const = 0;
#endif

  // Tells the presenter to rely on implicit sync when presenting buffers.
  virtual void SetRelyOnImplicitSync() {}

  // Tells the presenter to send
  // gfx::SwapResult::SWAP_NON_SIMPLE_OVERLAYS_FAILED if a non-simple overlay
  // submission fails (see gfx::OverlayType).
  virtual void SetNotifyNonSimpleOverlayFailure() {}

 protected:
  friend class base::RefCounted<Presenter>;
  virtual ~Presenter();
};

}  // namespace gl

#endif  // UI_GL_PRESENTER_H_