OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ozone/platform/drm/gpu/drm_display.h" |
| 6 |
| 7 #include <xf86drmMode.h> |
| 8 |
| 9 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
| 10 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 11 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 12 #include "ui/ozone/platform/drm/gpu/screen_manager.h" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kContentProtection[] = "Content Protection"; |
| 19 |
| 20 struct ContentProtectionMapping { |
| 21 const char* name; |
| 22 HDCPState state; |
| 23 }; |
| 24 |
| 25 const ContentProtectionMapping kContentProtectionStates[] = { |
| 26 {"Undesired", HDCP_STATE_UNDESIRED}, |
| 27 {"Desired", HDCP_STATE_DESIRED}, |
| 28 {"Enabled", HDCP_STATE_ENABLED}}; |
| 29 |
| 30 // Converts |state| to the DRM value associated with the it. |
| 31 uint32_t GetContentProtectionValue(drmModePropertyRes* property, |
| 32 HDCPState state) { |
| 33 std::string name; |
| 34 for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) { |
| 35 if (kContentProtectionStates[i].state == state) { |
| 36 name = kContentProtectionStates[i].name; |
| 37 break; |
| 38 } |
| 39 } |
| 40 |
| 41 for (int i = 0; i < property->count_enums; ++i) |
| 42 if (name == property->enums[i].name) |
| 43 return i; |
| 44 |
| 45 NOTREACHED(); |
| 46 return 0; |
| 47 } |
| 48 |
| 49 std::string GetEnumNameForProperty(drmModeConnector* connector, |
| 50 drmModePropertyRes* property) { |
| 51 for (int prop_idx = 0; prop_idx < connector->count_props; ++prop_idx) { |
| 52 if (connector->props[prop_idx] != property->prop_id) |
| 53 continue; |
| 54 |
| 55 for (int enum_idx = 0; enum_idx < property->count_enums; ++enum_idx) { |
| 56 const drm_mode_property_enum& property_enum = property->enums[enum_idx]; |
| 57 if (property_enum.value == connector->prop_values[prop_idx]) |
| 58 return property_enum.name; |
| 59 } |
| 60 } |
| 61 |
| 62 NOTREACHED(); |
| 63 return std::string(); |
| 64 } |
| 65 |
| 66 gfx::Size GetDrmModeSize(const drmModeModeInfo& mode) { |
| 67 return gfx::Size(mode.hdisplay, mode.vdisplay); |
| 68 } |
| 69 |
| 70 } // namespace |
| 71 |
| 72 DrmDisplay::DrmDisplay(ScreenManager* screen_manager, |
| 73 int64_t display_id, |
| 74 const scoped_refptr<DrmDevice>& drm, |
| 75 uint32_t crtc, |
| 76 uint32_t connector, |
| 77 const std::vector<drmModeModeInfo>& modes) |
| 78 : screen_manager_(screen_manager), |
| 79 display_id_(display_id), |
| 80 drm_(drm), |
| 81 crtc_(crtc), |
| 82 connector_(connector), |
| 83 modes_(modes) { |
| 84 } |
| 85 |
| 86 DrmDisplay::~DrmDisplay() { |
| 87 } |
| 88 |
| 89 bool DrmDisplay::Configure(const drmModeModeInfo* mode, |
| 90 const gfx::Point& origin) { |
| 91 VLOG(1) << "DRM configuring: device=" << drm_->device_path().value() |
| 92 << " crtc=" << crtc_ << " connector=" << connector_ |
| 93 << " origin=" << origin.ToString() |
| 94 << " size=" << (mode ? GetDrmModeSize(*mode).ToString() : "0x0"); |
| 95 |
| 96 if (mode) { |
| 97 if (!screen_manager_->ConfigureDisplayController(drm_, crtc_, connector_, |
| 98 origin, *mode)) { |
| 99 VLOG(1) << "Failed to configure: device=" << drm_->device_path().value() |
| 100 << " crtc=" << crtc_ << " connector=" << connector_; |
| 101 return false; |
| 102 } |
| 103 } else { |
| 104 if (!screen_manager_->DisableDisplayController(drm_, crtc_)) { |
| 105 VLOG(1) << "Failed to disable device=" << drm_->device_path().value() |
| 106 << " crtc=" << crtc_; |
| 107 return false; |
| 108 } |
| 109 } |
| 110 |
| 111 return true; |
| 112 } |
| 113 |
| 114 bool DrmDisplay::GetHDCPState(HDCPState* state) { |
| 115 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_)); |
| 116 if (!connector) { |
| 117 PLOG(ERROR) << "Failed to get connector " << connector_; |
| 118 return false; |
| 119 } |
| 120 |
| 121 ScopedDrmPropertyPtr hdcp_property( |
| 122 drm_->GetProperty(connector.get(), kContentProtection)); |
| 123 if (!hdcp_property) { |
| 124 PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist."; |
| 125 return false; |
| 126 } |
| 127 |
| 128 std::string name = |
| 129 GetEnumNameForProperty(connector.get(), hdcp_property.get()); |
| 130 for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) { |
| 131 if (name == kContentProtectionStates[i].name) { |
| 132 *state = kContentProtectionStates[i].state; |
| 133 VLOG(3) << "HDCP state: " << *state << " (" << name << ")"; |
| 134 return true; |
| 135 } |
| 136 } |
| 137 |
| 138 LOG(ERROR) << "Unknown content protection value '" << name << "'"; |
| 139 return false; |
| 140 } |
| 141 |
| 142 bool DrmDisplay::SetHDCPState(HDCPState state) { |
| 143 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_)); |
| 144 if (!connector) { |
| 145 PLOG(ERROR) << "Failed to get connector " << connector_; |
| 146 return false; |
| 147 } |
| 148 |
| 149 ScopedDrmPropertyPtr hdcp_property( |
| 150 drm_->GetProperty(connector.get(), kContentProtection)); |
| 151 if (!hdcp_property) { |
| 152 LOG(ERROR) << "'" << kContentProtection << "' property doesn't exist."; |
| 153 return false; |
| 154 } |
| 155 |
| 156 return drm_->SetProperty( |
| 157 connector_, hdcp_property->prop_id, |
| 158 GetContentProtectionValue(hdcp_property.get(), state)); |
| 159 } |
| 160 |
| 161 void DrmDisplay::SetGammaRamp(const std::vector<GammaRampRGBEntry>& lut) { |
| 162 if (!drm_->SetGammaRamp(crtc_, lut)) { |
| 163 LOG(ERROR) << "Failed to set gamma ramp for display: crtc_id = " << crtc_ |
| 164 << " size = " << lut.size(); |
| 165 } |
| 166 } |
| 167 |
| 168 } // namespace ui |
OLD | NEW |