Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_display_snapshot.cc
blob96e0a2f4f87b86242f99320e4174c59dc6b986f7
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.
5 #include "ui/ozone/platform/drm/gpu/drm_display_snapshot.h"
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <xf86drmMode.h>
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/gpu/drm_device.h"
16 #include "ui/ozone/platform/drm/gpu/drm_display_mode.h"
17 #include "ui/ozone/platform/drm/gpu/drm_util.h"
19 #if !defined(DRM_MODE_CONNECTOR_DSI)
20 #define DRM_MODE_CONNECTOR_DSI 16
21 #endif
23 namespace ui {
25 namespace {
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;
49 bool IsAspectPreserving(DrmDevice* drm, drmModeConnector* connector) {
50 ScopedDrmPropertyPtr property(drm->GetProperty(connector, "scaling mode"));
51 if (!property)
52 return false;
54 for (int props_i = 0; props_i < connector->count_props; ++props_i) {
55 if (connector->props[props_i] != property->prop_id)
56 continue;
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;
65 return false;
68 } // namespace
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 dpms_property_(drm->GetProperty(connector, "DPMS")) {
88 if (!dpms_property_)
89 VLOG(1) << "Failed to find the DPMS property for connector "
90 << connector->connector_id;
92 ScopedDrmPropertyBlobPtr edid_blob(drm->GetPropertyBlob(connector, "EDID"));
94 if (edid_blob) {
95 std::vector<uint8_t> edid(
96 static_cast<uint8_t*>(edid_blob->data),
97 static_cast<uint8_t*>(edid_blob->data) + edid_blob->length);
99 if (!GetDisplayIdFromEDID(edid, index, &display_id_))
100 display_id_ = index;
102 ParseOutputDeviceData(edid, nullptr, &display_name_, nullptr, nullptr);
103 ParseOutputOverscanFlag(edid, &overscan_flag_);
104 } else {
105 VLOG(1) << "Failed to get EDID blob for connector "
106 << connector->connector_id;
109 for (int i = 0; i < connector->count_modes; ++i) {
110 drmModeModeInfo& mode = connector->modes[i];
111 modes_.push_back(new DrmDisplayMode(mode));
113 if (crtc->mode_valid && SameMode(crtc->mode, mode))
114 current_mode_ = modes_.back();
116 if (mode.type & DRM_MODE_TYPE_PREFERRED)
117 native_mode_ = modes_.back();
120 // If no preferred mode is found then use the first one. Using the first one
121 // since it should be the best mode.
122 if (!native_mode_ && !modes_.empty())
123 native_mode_ = modes_.front();
126 DrmDisplaySnapshot::~DrmDisplaySnapshot() {
129 std::string DrmDisplaySnapshot::ToString() const {
130 return base::StringPrintf(
131 "[type=%d, connector=%" PRIu32 ", crtc=%" PRIu32
132 ", origin=%s, mode=%s, dim=%s]",
133 type_, connector_, crtc_, origin_.ToString().c_str(),
134 current_mode_ ? current_mode_->ToString().c_str() : "NULL",
135 physical_size_.ToString().c_str());
138 } // namespace ui