OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_snapshot.h" | |
6 | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <xf86drmMode.h> | |
10 | |
11 #include "base/format_macros.h" | |
12 #include "base/logging.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "ui/display/util/edid_parser.h" | |
15 #include "ui/ozone/platform/drm/common/drm_util.h" | |
16 #include "ui/ozone/platform/drm/gpu/drm_device.h" | |
17 #include "ui/ozone/platform/drm/gpu/drm_display_mode.h" | |
18 | |
19 #if !defined(DRM_MODE_CONNECTOR_DSI) | |
20 #define DRM_MODE_CONNECTOR_DSI 16 | |
21 #endif | |
22 | |
23 namespace ui { | |
24 | |
25 namespace { | |
26 | |
27 DisplayConnectionType GetDisplayType(drmModeConnector* connector) { | |
28 switch (connector->connector_type) { | |
29 case DRM_MODE_CONNECTOR_VGA: | |
30 return DISPLAY_CONNECTION_TYPE_VGA; | |
31 case DRM_MODE_CONNECTOR_DVII: | |
32 case DRM_MODE_CONNECTOR_DVID: | |
33 case DRM_MODE_CONNECTOR_DVIA: | |
34 return DISPLAY_CONNECTION_TYPE_DVI; | |
35 case DRM_MODE_CONNECTOR_LVDS: | |
36 case DRM_MODE_CONNECTOR_eDP: | |
37 case DRM_MODE_CONNECTOR_DSI: | |
38 return DISPLAY_CONNECTION_TYPE_INTERNAL; | |
39 case DRM_MODE_CONNECTOR_DisplayPort: | |
40 return DISPLAY_CONNECTION_TYPE_DISPLAYPORT; | |
41 case DRM_MODE_CONNECTOR_HDMIA: | |
42 case DRM_MODE_CONNECTOR_HDMIB: | |
43 return DISPLAY_CONNECTION_TYPE_HDMI; | |
44 default: | |
45 return DISPLAY_CONNECTION_TYPE_UNKNOWN; | |
46 } | |
47 } | |
48 | |
49 bool IsAspectPreserving(DrmDevice* drm, drmModeConnector* connector) { | |
50 ScopedDrmPropertyPtr property(drm->GetProperty(connector, "scaling mode")); | |
51 if (!property) | |
52 return false; | |
53 | |
54 for (int props_i = 0; props_i < connector->count_props; ++props_i) { | |
55 if (connector->props[props_i] != property->prop_id) | |
56 continue; | |
57 | |
58 for (int enums_i = 0; enums_i < property->count_enums; ++enums_i) { | |
59 if (property->enums[enums_i].value == connector->prop_values[props_i] && | |
60 strcmp(property->enums[enums_i].name, "Full aspect") == 0) | |
61 return true; | |
62 } | |
63 } | |
64 | |
65 return false; | |
66 } | |
67 | |
68 } // namespace | |
69 | |
70 DrmDisplaySnapshot::DrmDisplaySnapshot(const scoped_refptr<DrmDevice>& drm, | |
71 drmModeConnector* connector, | |
72 drmModeCrtc* crtc, | |
73 uint32_t index) | |
74 : DisplaySnapshot(index, | |
75 gfx::Point(crtc->x, crtc->y), | |
76 gfx::Size(connector->mmWidth, connector->mmHeight), | |
77 GetDisplayType(connector), | |
78 IsAspectPreserving(drm.get(), connector), | |
79 false, | |
80 std::string(), | |
81 std::vector<const DisplayMode*>(), | |
82 nullptr, | |
83 nullptr), | |
84 drm_(drm), | |
85 connector_(connector->connector_id), | |
86 crtc_(crtc->crtc_id) { | |
87 ScopedDrmPropertyBlobPtr edid_blob(drm->GetPropertyBlob(connector, "EDID")); | |
88 | |
89 if (edid_blob) { | |
90 std::vector<uint8_t> edid( | |
91 static_cast<uint8_t*>(edid_blob->data), | |
92 static_cast<uint8_t*>(edid_blob->data) + edid_blob->length); | |
93 | |
94 if (!GetDisplayIdFromEDID(edid, index, &display_id_)) | |
95 display_id_ = index; | |
96 | |
97 ParseOutputDeviceData(edid, nullptr, &display_name_, nullptr, nullptr); | |
98 ParseOutputOverscanFlag(edid, &overscan_flag_); | |
99 } else { | |
100 VLOG(1) << "Failed to get EDID blob for connector " | |
101 << connector->connector_id; | |
102 } | |
103 | |
104 for (int i = 0; i < connector->count_modes; ++i) { | |
105 drmModeModeInfo& mode = connector->modes[i]; | |
106 modes_.push_back(new DrmDisplayMode(mode)); | |
107 | |
108 if (crtc->mode_valid && SameMode(crtc->mode, mode)) | |
109 current_mode_ = modes_.back(); | |
110 | |
111 if (mode.type & DRM_MODE_TYPE_PREFERRED) | |
112 native_mode_ = modes_.back(); | |
113 } | |
114 | |
115 // If no preferred mode is found then use the first one. Using the first one | |
116 // since it should be the best mode. | |
117 if (!native_mode_ && !modes_.empty()) | |
118 native_mode_ = modes_.front(); | |
119 } | |
120 | |
121 DrmDisplaySnapshot::~DrmDisplaySnapshot() { | |
122 } | |
123 | |
124 std::string DrmDisplaySnapshot::ToString() const { | |
125 return base::StringPrintf( | |
126 "[type=%d, connector=%" PRIu32 ", crtc=%" PRIu32 | |
127 ", origin=%s, mode=%s, dim=%s]", | |
128 type_, connector_, crtc_, origin_.ToString().c_str(), | |
129 current_mode_ ? current_mode_->ToString().c_str() : "NULL", | |
130 physical_size_.ToString().c_str()); | |
131 } | |
132 | |
133 } // namespace ui | |
OLD | NEW |