File: crtc_controller.cc

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 (126 lines) | stat: -rw-r--r-- 4,374 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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.

#include "ui/ozone/platform/drm/gpu/crtc_controller.h"

#include <memory>

#include "base/logging.h"
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/common/tile_property.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"
#include "ui/ozone/platform/drm/gpu/drm_dumb_buffer.h"
#include "ui/ozone/platform/drm/gpu/drm_framebuffer.h"
#include "ui/ozone/platform/drm/gpu/drm_gpu_util.h"
#include "ui/ozone/platform/drm/gpu/hardware_display_plane.h"
#include "ui/ozone/platform/drm/gpu/page_flip_request.h"

namespace ui {

CrtcController::CrtcController(const scoped_refptr<DrmDevice>& drm,
                               uint32_t crtc,
                               uint32_t connector,
                               std::optional<TileProperty> tile_property)
    : drm_(drm),
      crtc_(crtc),
      connector_(connector),
      state_(drm->plane_manager()->GetCrtcStateForCrtcId(crtc)),
      tile_property_(std::move(tile_property)) {}

CrtcController::~CrtcController() {
  if (is_enabled()) {
    const std::vector<std::unique_ptr<HardwareDisplayPlane>>& all_planes =
        drm_->plane_manager()->planes();
    for (const auto& plane : all_planes) {
      if (plane->owning_crtc() == crtc_) {
        plane->set_owning_crtc(0);
        plane->set_in_use(false);
      }
    }
  }
}

bool CrtcController::AssignOverlayPlanes(HardwareDisplayPlaneList* plane_list,
                                         const DrmOverlayPlaneList& overlays,
                                         bool is_modesetting) {
  // If we're in the process of modesetting, the CRTC is still disabled.
  // Once the modeset is done, we expect it to be enabled.
  DCHECK(is_modesetting || is_enabled());

  const DrmOverlayPlane* primary = DrmOverlayPlane::GetPrimaryPlane(overlays);
  if (primary &&
      !drm_->plane_manager()->ValidatePrimarySize(*primary, state_->mode)) {
    VLOG(2) << "Trying to pageflip a buffer with the wrong size. Expected "
            << ModeSize(state_->mode).ToString() << " got "
            << primary->buffer->size().ToString() << " for"
            << " crtc=" << crtc_ << " connector=" << connector_;
    return true;
  }

  std::optional<gfx::Point> crtc_offset = std::nullopt;
  if (CurrentModeIsTiled()) {
    crtc_offset = GetTileCrtcOffset(*tile_property_);
    crtc_offset->set_x(crtc_offset->x() * -1);
    crtc_offset->set_y(crtc_offset->y() * -1);
  }

  if (!drm_->plane_manager()->AssignOverlayPlanes(plane_list, overlays, crtc_,
                                                  crtc_offset)) {
    return false;
  }

  return true;
}

std::vector<uint64_t> CrtcController::GetFormatModifiers(uint32_t format) {
  return drm_->plane_manager()->GetFormatModifiers(crtc_, format);
}

void CrtcController::SetCursor(uint32_t handle, const gfx::Size& size) {
  if (is_enabled() && !drm_->SetCursor(crtc_, handle, size)) {
    PLOG(ERROR) << "drmModeSetCursor: device " << drm_->device_path().value()
                << " crtc " << crtc_ << " handle " << handle << " size "
                << size.ToString();
  }
}

void CrtcController::MoveCursor(const gfx::Point& location) {
  if (!is_enabled())
    return;

  if (CurrentModeIsTiled()) {
    const gfx::Point tiled_offset = GetTileCrtcOffset(*tile_property_);
    gfx::Point translated_location(location.x() - tiled_offset.x(),
                                   location.y() - tiled_offset.y());

    drm_->MoveCursor(crtc_, translated_location);
    return;
  }

  drm_->MoveCursor(crtc_, location);
}

void CrtcController::WriteIntoTrace(perfetto::TracedValue context) const {
  auto dict = std::move(context).WriteDictionary();

  dict.Add("crtc_id", crtc_);
  dict.Add("connector", connector_);

  DrmWriteIntoTraceHelper(state_->mode, dict.AddItem("mode"));
}

bool CrtcController::CurrentModeIsTiled() const {
  if (!tile_property_.has_value()) {
    return false;
  }

  return mode().hdisplay == tile_property_->tile_size.width() &&
         mode().vdisplay == tile_property_->tile_size.height();
}

}  // namespace ui