File: drm_device.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 (107 lines) | stat: -rw-r--r-- 3,487 bytes parent folder | download | duplicates (6)
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
// Copyright 2014 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_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_
#define UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_

#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
#include "ui/ozone/platform/drm/common/drm_wrapper.h"
#include "ui/ozone/platform/drm/common/scoped_drm_types.h"
#include "ui/ozone/platform/drm/gpu/page_flip_request.h"

namespace ui {

class HardwareDisplayPlaneManager;
class GbmDevice;

class DrmDevice : public DrmWrapper,
                  public base::RefCountedThreadSafe<DrmDevice> {
 public:
  using PageFlipCallback =
      base::OnceCallback<void(unsigned int /* frame */,
                              base::TimeTicks /* timestamp */)>;

  DrmDevice(const base::FilePath& device_path,
            base::ScopedFD fd,
            bool is_primary_device,
            std::unique_ptr<GbmDevice> gbm_device);

  DrmDevice(const DrmDevice&) = delete;
  DrmDevice& operator=(const DrmDevice&) = delete;

  // Open device.
  bool Initialize() override;

  bool SetCrtc(uint32_t crtc_id,
               uint32_t framebuffer,
               std::vector<uint32_t> connectors,
               const drmModeModeInfo& mode) override;

  // Schedules a pageflip for CRTC |crtc_id|. This function will return
  // immediately. Upon completion of the pageflip event, the CRTC will be
  // displaying the buffer with ID |framebuffer| and will have a DRM event
  // queued on |fd_|.
  //
  // On success, true is returned and |page_flip_request| will receive a
  // callback signalling completion of the flip.
  virtual bool PageFlip(uint32_t crtc_id,
                        uint32_t framebuffer,
                        scoped_refptr<PageFlipRequest> page_flip_request);

  // On success, true is returned and |page_flip_request| will receive a
  // callback signalling completion of the flip, if provided.
  virtual bool CommitProperties(
      drmModeAtomicReq* properties,
      uint32_t flags,
      uint32_t crtc_count,
      scoped_refptr<PageFlipRequest> page_flip_request);

  // Adds trace records to |context|.
  void WriteIntoTrace(perfetto::TracedDictionary dict) const override;

  display::DrmFormatsAndModifiers GetFormatsAndModifiersForCrtc(
      uint32_t crtc_id) const override;

  virtual int modeset_sequence_id() const;
  HardwareDisplayPlaneManager* plane_manager() { return plane_manager_.get(); }
  const HardwareDisplayPlaneManager* plane_manager() const {
    return plane_manager_.get();
  }
  GbmDevice* gbm_device() const { return gbm_.get(); }

 protected:
  friend class base::RefCountedThreadSafe<DrmDevice>;

  ~DrmDevice() override;

  std::unique_ptr<HardwareDisplayPlaneManager> plane_manager_;

 private:
  class IOWatcher;
  class PageFlipManager;

  // Sequence ID incremented at each modeset.
  // Currently used by DRM Framebuffer to indicate when was the fb initialized
  // wrt the preceding modeset.
  int modeset_sequence_id_ = 0;

  std::unique_ptr<PageFlipManager> page_flip_manager_;

  // Watcher for |fd_| listening for page flip events.
  std::unique_ptr<IOWatcher> watcher_;

  const std::unique_ptr<GbmDevice> gbm_;
};

}  // namespace ui

#endif  // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_