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

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

Issue 1129923004: [1/2][Ozone-Drm] Refactor GPU display management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@handle-display-init2
Patch Set: fixed comments Created 5 years, 7 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 uint32_t GetContentProtectionValue(drmModePropertyRes* property,
spang 2015/05/12 16:58:53 please document
dnicoara 2015/05/12 18:05:02 Done.
31 HDCPState state) {
32 std::string name;
33 for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) {
34 if (kContentProtectionStates[i].state == state) {
35 name = kContentProtectionStates[i].name;
36 break;
37 }
38 }
39
40 for (int i = 0; i < property->count_enums; ++i)
41 if (name == property->enums[i].name)
42 return i;
43
44 NOTREACHED();
45 return 0;
46 }
47
48 std::string GetEnumNameForProperty(drmModeConnector* connector,
49 drmModePropertyRes* property) {
50 for (int prop_idx = 0; prop_idx < connector->count_props; ++prop_idx) {
51 if (connector->props[prop_idx] != property->prop_id)
52 continue;
53
54 for (int enum_idx = 0; enum_idx < property->count_enums; ++enum_idx) {
55 const drm_mode_property_enum& property_enum = property->enums[enum_idx];
56 if (property_enum.value == connector->prop_values[prop_idx])
57 return property_enum.name;
58 }
59 }
60
61 NOTREACHED();
62 return std::string();
63 }
64
65 gfx::Size GetDrmModeSize(const drmModeModeInfo& mode) {
66 return gfx::Size(mode.hdisplay, mode.vdisplay);
67 }
68
69 } // namespace
70
71 DrmDisplay::DrmDisplay(ScreenManager* screen_manager,
72 int64_t display_id,
73 const scoped_refptr<DrmDevice>& drm,
74 uint32_t crtc,
75 uint32_t connector,
76 const std::vector<drmModeModeInfo>& modes)
77 : screen_manager_(screen_manager),
78 display_id_(display_id),
79 drm_(drm),
80 crtc_(crtc),
81 connector_(connector),
82 modes_(modes) {
83 }
84
85 DrmDisplay::~DrmDisplay() {
86 }
87
88 bool DrmDisplay::Configure(const drmModeModeInfo* mode,
89 const gfx::Point& origin) {
90 VLOG(1) << "DRM configuring: device=" << drm_->device_path().value()
91 << " crtc=" << crtc_ << " connector=" << connector_
92 << " origin=" << origin.ToString()
93 << " size=" << (mode ? GetDrmModeSize(*mode).ToString() : "0x0");
94
95 if (mode) {
96 if (!screen_manager_->ConfigureDisplayController(drm_, crtc_, connector_,
97 origin, *mode)) {
98 VLOG(1) << "Failed to configure: device=" << drm_->device_path().value()
99 << " crtc=" << crtc_ << " connector=" << connector_;
100 return false;
101 }
102 } else {
103 if (!screen_manager_->DisableDisplayController(drm_, crtc_)) {
104 VLOG(1) << "Failed to disable device=" << drm_->device_path().value()
105 << " crtc=" << crtc_;
106 return false;
107 }
108 }
109
110 return true;
111 }
112
113 bool DrmDisplay::GetHDCPState(HDCPState* state) {
114 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_));
115 if (!connector) {
116 PLOG(ERROR) << "Failed to get connector " << connector_;
117 return false;
118 }
119
120 ScopedDrmPropertyPtr hdcp_property(
121 drm_->GetProperty(connector.get(), kContentProtection));
122 if (!hdcp_property) {
123 PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
124 return false;
125 }
126
127 std::string name =
128 GetEnumNameForProperty(connector.get(), hdcp_property.get());
129 for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) {
130 if (name == kContentProtectionStates[i].name) {
131 *state = kContentProtectionStates[i].state;
132 VLOG(3) << "HDCP state: " << *state << " (" << name << ")";
133 return true;
134 }
135 }
136
137 LOG(ERROR) << "Unknown content protection value '" << name << "'";
138 return false;
139 }
140
141 bool DrmDisplay::SetHDCPState(HDCPState state) {
142 ScopedDrmConnectorPtr connector(drm_->GetConnector(connector_));
143 if (!connector) {
144 PLOG(ERROR) << "Failed to get connector " << connector_;
145 return false;
146 }
147
148 ScopedDrmPropertyPtr hdcp_property(
149 drm_->GetProperty(connector.get(), kContentProtection));
150 if (!hdcp_property) {
151 PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
spang 2015/05/12 16:58:53 PLOG doesn't make sense here. You can't be sure dr
dnicoara 2015/05/12 18:05:02 Done.
152 return false;
153 }
154
155 return drm_->SetProperty(
156 connector_, hdcp_property->prop_id,
157 GetContentProtectionValue(hdcp_property.get(), state));
158 }
159
160 void DrmDisplay::SetGammaRamp(const std::vector<GammaRampRGBEntry>& lut) {
161 if (!drm_->SetGammaRamp(crtc_, lut)) {
162 LOG(ERROR) << "Failed to set gamma ramp for display: crtc_id = " << crtc_
163 << " size = " << lut.size();
164 }
165 }
166
167 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698