File: image_transport_surface_overlay_mac.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (124 lines) | stat: -rw-r--r-- 4,067 bytes parent folder | download | duplicates (5)
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
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
#define GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_

#include <vector>

#include "base/memory/weak_ptr.h"
#include "gpu/ipc/service/command_buffer_stub.h"
#include "gpu/ipc/service/image_transport_surface.h"
#include "ui/gfx/ca_layer_result.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/presenter.h"

// Put ui/display/mac/display_link_mac.h after ui/gl/gl_xxx.h. There is a
// conflict between macOS sdk gltypes.h and third_party/mesa_headers/GL/glext.h.
#if BUILDFLAG(IS_MAC)
#include "ui/display/mac/display_link_mac.h"
#include "ui/display/types/display_constants.h"
#endif

#if BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_IOS_TVOS)
#include <BrowserEngineKit/BrowserEngineKit.h>
#endif

@class CAContext;
@class CALayer;

namespace ui {
class CALayerTreeCoordinator;
struct CARendererLayerParams;
}

namespace gpu {

class ImageTransportSurfaceOverlayMacEGL : public gl::Presenter {
 public:
  ImageTransportSurfaceOverlayMacEGL(
      scoped_refptr<SharedContextState> context_state,
      SurfaceHandle surface_handle);

  // Presenter implementation
  bool Resize(const gfx::Size& size,
              float scale_factor,
              const gfx::ColorSpace& color_space,
              bool has_alpha) override;

  void Present(SwapCompletionCallback completion_callback,
               PresentationCallback presentation_callback,
               gfx::FrameData data) override;

  bool ScheduleOverlayPlane(
      gl::OverlayImage image,
      std::unique_ptr<gfx::GpuFence> gpu_fence,
      const gfx::OverlayPlaneData& overlay_plane_data) override;

  bool ScheduleCALayer(const ui::CARendererLayerParams& params) override;

  void SetMaxPendingSwaps(int max_pending_swaps) override;

#if BUILDFLAG(IS_MAC)
  // GLSurface override
  void SetVSyncDisplayID(int64_t display_id) override;

  void OnVSyncPresentation(ui::VSyncParamsMac params);
#endif

 private:
  ~ImageTransportSurfaceOverlayMacEGL() override;

  gfx::SwapResult SwapBuffersInternal(
      gl::GLSurface::SwapCompletionCallback completion_callback,
      gl::GLSurface::PresentationCallback presentation_callback);

  void BufferPresented(gl::GLSurface::PresentationCallback callback,
                       const gfx::PresentationFeedback& feedback);

  void CommitPresentedFrameToCA();

  std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;

#if BUILDFLAG(IS_MAC)
  // The expected display time from CVDisplayLinkCallback for the frame being
  // committed.
  base::TimeTicks GetDisplaytime(base::TimeTicks latch_time);

  // CGDirectDisplayID of the current monitor used for Creating CVDisplayLink.
  int64_t display_id_ = display::kInvalidDisplayId;
  scoped_refptr<ui::DisplayLinkMac> display_link_mac_;
  std::unique_ptr<ui::VSyncCallbackMac> vsync_callback_mac_;

  // This is the number of vsync_callbacks running without populating CaLayer
  // parameters, used for detecting consecutive frames.
  int vsync_callback_mac_keep_alive_counter_ = 0;

  // Ensure vsync_callback_mac_ is still alive in the case of frame rate
  // throttling such as 30 fps video playback.
  // With a reduced frame rate from 60 fps to 30 fps, we skip every other
  // VSyncCallback. To prevent VSyncCallback from being turning on and off, this
  // keep_alive_counter is added.
  constexpr static int kMaxKeepAliveCounter = 8;

  // Parameters from CVDisplayLinkCallback
  base::TimeTicks current_display_time_;
  base::TimeTicks next_display_time_;
  base::TimeDelta frame_interval_;
#endif

#if BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_IOS_TVOS)
  BELayerHierarchy* __strong layer_hierarchy_;
#endif

  int cap_max_pending_swaps_ = 1;

  base::WeakPtrFactory<ImageTransportSurfaceOverlayMacEGL> weak_ptr_factory_;
};

}  // namespace gpu

#endif  // GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_