Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_display.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 std::vector<drmModeModeInfo> GetDrmModeVector(drmModeConnector* connector) {
71 std::vector<drmModeModeInfo> modes;
72 for (int i = 0; i < connector->count_modes; ++i)
73 modes.push_back(connector->modes[i]);
74
75 return modes;
76 }
77
78 } // namespace
79
80 DrmDisplay::DrmDisplay(ScreenManager* screen_manager,
81 const scoped_refptr<DrmDevice>& drm)
82 : screen_manager_(screen_manager), drm_(drm) {
83 }
84
85 DrmDisplay::~DrmDisplay() {
86 }
87
88 DisplaySnapshot_Params DrmDisplay::Update(HardwareDisplayControllerInfo* info,
89 size_t display_index) {
90 DisplaySnapshot_Params params =
91 CreateDisplaySnapshotParams(info, drm_->get_fd(), display_index, origin_);
92 crtc_ = info->crtc()->crtc_id;
93 connector_ = info->connector()->connector_id;
94 display_id_ = params.display_id;
95 modes_ = GetDrmModeVector(info->connector());
96 return params;
97 }
98
99 bool DrmDisplay::Configure(const drmModeModeInfo* mode,
100 const gfx::Point& origin) {
101 VLOG(1) << "DRM configuring: device=" << drm_->device_path().value()
102 << " crtc=" << crtc_ << " connector=" << connector_
103 << " origin=" << origin.ToString()
104 << " size=" << (mode ? GetDrmModeSize(*mode).ToString() : "0x0");
105
106 if (mode) {
107 if (!screen_manager_->ConfigureDisplayController(drm_, crtc_, connector_,
108 origin, *mode)) {
109 VLOG(1) << "Failed to configure: device=" << drm_->device_path().value()
110 << " crtc=" << crtc_ << " connector=" << connector_;
111 return false;
112 }
113 } else {
114 if (!screen_manager_->DisableDisplayController(drm_, crtc_)) {
115 VLOG(1) << "Failed to disable device=" << drm_->device_path().value()
116 << " crtc=" << crtc_;
117 return false;
118 }
119 }
120
121 origin_ = origin;
122 return true;
123 }
124
125 bool DrmDisplay::GetHDCPState(HDCPState* state) {
126 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_));
127 if (!connector) {
128 PLOG(ERROR) << "Failed to get connector " << connector_;
129 return false;
130 }
131
132 ScopedDrmPropertyPtr hdcp_property(
133 drm_->GetProperty(connector.get(), kContentProtection));
134 if (!hdcp_property) {
135 PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
136 return false;
137 }
138
139 std::string name =
140 GetEnumNameForProperty(connector.get(), hdcp_property.get());
141 for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) {
142 if (name == kContentProtectionStates[i].name) {
143 *state = kContentProtectionStates[i].state;
144 VLOG(3) << "HDCP state: " << *state << " (" << name << ")";
145 return true;
146 }
147 }
148
149 LOG(ERROR) << "Unknown content protection value '" << name << "'";
150 return false;
151 }
152
153 bool DrmDisplay::SetHDCPState(HDCPState state) {
154 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_));
155 if (!connector) {
156 PLOG(ERROR) << "Failed to get connector " << connector_;
157 return false;
158 }
159
160 ScopedDrmPropertyPtr hdcp_property(
161 drm_->GetProperty(connector.get(), kContentProtection));
162 if (!hdcp_property) {
163 LOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
164 return false;
165 }
166
167 return drm_->SetProperty(
168 connector_, hdcp_property->prop_id,
169 GetContentProtectionValue(hdcp_property.get(), state));
170 }
171
172 void DrmDisplay::SetGammaRamp(const std::vector<GammaRampRGBEntry>& lut) {
173 if (!drm_->SetGammaRamp(crtc_, lut)) {
174 LOG(ERROR) << "Failed to set gamma ramp for display: crtc_id = " << crtc_
175 << " size = " << lut.size();
176 }
177 }
178
179 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_display.h ('k') | ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698