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
|
// 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 UI_OZONE_PLATFORM_DRM_GPU_DRM_DISPLAY_H_
#define UI_OZONE_PLATFORM_DRM_GPU_DRM_DISPLAY_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <optional>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/hdr_static_metadata.h"
#include "ui/ozone/platform/drm/common/hardware_display_controller_info.h"
#include "ui/ozone/platform/drm/common/scoped_drm_types.h"
#include "ui/ozone/platform/drm/common/tile_property.h"
typedef struct _drmModeModeInfo drmModeModeInfo;
namespace display {
class DisplaySnapshot;
struct ColorTemperatureAdjustment;
struct ColorCalibration;
struct GammaAdjustment;
} // namespace display
namespace ui {
class DrmDevice;
class HardwareDisplayControllerInfo;
class DrmDisplay {
public:
class PrivacyScreenProperty {
public:
explicit PrivacyScreenProperty(const scoped_refptr<DrmDevice>& drm,
drmModeConnector* connector);
PrivacyScreenProperty(const PrivacyScreenProperty&) = delete;
PrivacyScreenProperty& operator=(const PrivacyScreenProperty&) = delete;
~PrivacyScreenProperty();
bool SetPrivacyScreenProperty(bool enabled);
private:
display::PrivacyScreenState GetPrivacyScreenState() const;
bool ValidateCurrentStateAgainst(bool enabled) const;
drmModePropertyRes* GetReadPrivacyScreenProperty() const;
drmModePropertyRes* GetWritePrivacyScreenProperty() const;
const scoped_refptr<DrmDevice> drm_;
raw_ptr<drmModeConnector> connector_ = nullptr; // not owned.
display::PrivacyScreenState property_last_ =
display::kPrivacyScreenStateLast;
ScopedDrmPropertyPtr privacy_screen_hw_state_;
ScopedDrmPropertyPtr privacy_screen_sw_state_;
ScopedDrmPropertyPtr privacy_screen_legacy_;
};
struct CrtcConnectorPair {
CrtcConnectorPair(uint32_t crtc_id,
ScopedDrmConnectorPtr connector,
std::optional<gfx::Point> tile_location);
CrtcConnectorPair(const CrtcConnectorPair& other) = delete;
CrtcConnectorPair& operator=(const CrtcConnectorPair& other) = delete;
CrtcConnectorPair(CrtcConnectorPair&& other) noexcept;
CrtcConnectorPair& operator=(CrtcConnectorPair&& other) noexcept;
~CrtcConnectorPair();
uint32_t crtc_id;
ScopedDrmConnectorPtr connector;
std::optional<gfx::Point> tile_location;
};
// Note that some of |info|'s references ownership will be handed to this
// DrmDisplay instance.
explicit DrmDisplay(const scoped_refptr<DrmDevice>& drm,
HardwareDisplayControllerInfo* info,
const display::DisplaySnapshot& display_snapshot);
DrmDisplay(const DrmDisplay&) = delete;
DrmDisplay& operator=(const DrmDisplay&) = delete;
~DrmDisplay();
int64_t display_id() const { return display_id_; }
int64_t base_connector_id() const { return base_connector_id_; }
scoped_refptr<DrmDevice> drm() const { return drm_; }
uint32_t GetPrimaryCrtcId() const {
return primary_crtc_connector_pair_->crtc_id;
}
uint32_t GetPrimaryConnectorId() const;
const std::vector<CrtcConnectorPair>& crtc_connector_pairs() const;
const std::vector<drmModeModeInfo>& modes() const { return modes_; }
const gfx::Point& origin() { return origin_; }
const std::optional<uint16_t>& vsync_rate_min_from_edid() const {
return vsync_rate_min_from_edid_;
}
bool ContainsCrtc(uint32_t crtc_id) const;
void SetOrigin(const gfx::Point origin) { origin_ = origin; }
bool SetHdcpKeyProp(const std::string& key);
bool GetHDCPState(display::HDCPState* state,
display::ContentProtectionMethod* protection_method);
bool SetHDCPState(display::HDCPState state,
display::ContentProtectionMethod protection_method);
void SetColorTemperatureAdjustment(
const display::ColorTemperatureAdjustment& cta);
void SetColorCalibration(const display::ColorCalibration& calibration);
void SetGammaAdjustment(const display::GammaAdjustment& adjustment);
void SetBackgroundColor(const uint64_t background_color);
bool SetPrivacyScreen(bool enabled);
bool SetHdrOutputMetadata(const gfx::ColorSpace color_space);
bool SetColorspaceProperty(const gfx::ColorSpace color_space);
bool IsVrrCapable() const;
// Replace CRTCs in |crtc_connector_pairs_| according to mapping provided by
// |current_to_new_crtc_ids|. Must replace all CRTCs in
// |crtc_connector_pairs_| in a single call. New CRTC IDs must be unique. All
// new CRTCs should be checked to be compatible with the connectors before the
// call.
bool ReplaceCrtcs(
const base::flat_map<uint32_t /*current_crtc*/, uint32_t /*new_crtc*/>&
current_to_new_crtc_ids);
std::optional<TileProperty> GetTileProperty() const;
const CrtcConnectorPair* GetCrtcConnectorPairForConnectorId(
uint32_t connector_id) const;
private:
gfx::HDRStaticMetadata::Eotf GetEotf(
const gfx::ColorSpace::TransferID transfer_id);
bool ClearHdrOutputMetadata();
const int64_t display_id_;
const int64_t base_connector_id_;
const scoped_refptr<DrmDevice> drm_;
std::vector<CrtcConnectorPair> crtc_connector_pairs_;
// Main CRTC and connector used to identify the display and apply certain
// display-specific properties. If there is only one CrtcConnectorPair pair,
// then that pair would be the primary. Note that
// |primary_crtc_connector_pair_| is a reference to |crtc_connector_pairs_|,
// and thus must be initialized AFTER |crtc_connector_pairs_|.
const raw_ref<const CrtcConnectorPair> primary_crtc_connector_pair_;
std::vector<drmModeModeInfo> modes_;
gfx::Point origin_;
std::optional<gfx::HDRStaticMetadata> hdr_static_metadata_;
std::unique_ptr<PrivacyScreenProperty> privacy_screen_property_;
std::optional<uint16_t> vsync_rate_min_from_edid_;
std::optional<TileProperty> tile_property_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DISPLAY_H_
|