| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/display/output_util.h" | 5 #include "ui/display/chromeos/x11/display_snapshot_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/Xrandr.h> | |
| 8 #include <X11/Xatom.h> | |
| 9 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 10 | 8 |
| 11 #include "base/strings/string_util.h" | 9 #include "base/strings/stringprintf.h" |
| 12 #include "base/x11/edid_parser_x11.h" | 10 #include "base/x11/edid_parser_x11.h" |
| 11 #include "ui/display/chromeos/x11/display_mode_x11.h" |
| 13 | 12 |
| 14 namespace chromeos { | 13 namespace ui { |
| 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Prefixes for the built-in displays. | |
| 18 const char kInternal_LVDS[] = "LVDS"; | |
| 19 const char kInternal_eDP[] = "eDP"; | |
| 20 const char kInternal_DSI[] = "DSI"; | |
| 21 | |
| 22 // Gets some useful data from the specified output device, such like | 17 // Gets some useful data from the specified output device, such like |
| 23 // manufacturer's ID, product code, and human readable name. Returns false if it | 18 // manufacturer's ID, product code, and human readable name. Returns false if it |
| 24 // fails to get those data and doesn't touch manufacturer ID/product code/name. | 19 // fails to get those data and doesn't touch manufacturer ID/product code/name. |
| 25 // NULL can be passed for unwanted output parameters. | 20 // NULL can be passed for unwanted output parameters. |
| 26 bool GetOutputDeviceData(XID output, | 21 bool GetOutputDeviceData(XID output, |
| 27 uint16* manufacturer_id, | 22 uint16* manufacturer_id, |
| 28 std::string* human_readable_name) { | 23 std::string* human_readable_name) { |
| 29 unsigned long nitems = 0; | 24 unsigned long nitems = 0; |
| 30 unsigned char *prop = NULL; | 25 unsigned char* prop = NULL; |
| 31 if (!base::GetEDIDProperty(output, &nitems, &prop)) | 26 if (!base::GetEDIDProperty(output, &nitems, &prop)) |
| 32 return false; | 27 return false; |
| 33 | 28 |
| 34 bool result = base::ParseOutputDeviceData( | 29 bool result = base::ParseOutputDeviceData( |
| 35 prop, nitems, manufacturer_id, human_readable_name); | 30 prop, nitems, manufacturer_id, human_readable_name); |
| 36 XFree(prop); | 31 XFree(prop); |
| 37 return result; | 32 return result; |
| 38 } | 33 } |
| 39 | 34 |
| 40 } // namespace | |
| 41 | |
| 42 std::string GetDisplayName(XID output_id) { | |
| 43 std::string display_name; | |
| 44 GetOutputDeviceData(output_id, NULL, &display_name); | |
| 45 return display_name; | |
| 46 } | |
| 47 | |
| 48 bool GetOutputOverscanFlag(XID output, bool* flag) { | |
| 49 unsigned long nitems = 0; | |
| 50 unsigned char *prop = NULL; | |
| 51 if (!base::GetEDIDProperty(output, &nitems, &prop)) | |
| 52 return false; | |
| 53 | |
| 54 bool found = ParseOutputOverscanFlag(prop, nitems, flag); | |
| 55 XFree(prop); | |
| 56 return found; | |
| 57 } | |
| 58 | |
| 59 bool ParseOutputOverscanFlag(const unsigned char* prop, | 35 bool ParseOutputOverscanFlag(const unsigned char* prop, |
| 60 unsigned long nitems, | 36 unsigned long nitems, |
| 61 bool *flag) { | 37 bool* flag) { |
| 62 // See http://en.wikipedia.org/wiki/Extended_display_identification_data | 38 // See http://en.wikipedia.org/wiki/Extended_display_identification_data |
| 63 // for the extension format of EDID. Also see EIA/CEA-861 spec for | 39 // for the extension format of EDID. Also see EIA/CEA-861 spec for |
| 64 // the format of the extensions and how video capability is encoded. | 40 // the format of the extensions and how video capability is encoded. |
| 65 // - byte 0: tag. should be 02h. | 41 // - byte 0: tag. should be 02h. |
| 66 // - byte 1: revision. only cares revision 3 (03h). | 42 // - byte 1: revision. only cares revision 3 (03h). |
| 67 // - byte 4-: data block. | 43 // - byte 4-: data block. |
| 68 const unsigned int kExtensionBase = 128; | 44 const unsigned int kExtensionBase = 128; |
| 69 const unsigned int kExtensionSize = 128; | 45 const unsigned int kExtensionSize = 128; |
| 70 const unsigned int kNumExtensionsOffset = 126; | 46 const unsigned int kNumExtensionsOffset = 126; |
| 71 const unsigned int kDataBlockOffset = 4; | 47 const unsigned int kDataBlockOffset = 4; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } else { | 104 } else { |
| 129 *flag = false; | 105 *flag = false; |
| 130 } | 106 } |
| 131 return true; | 107 return true; |
| 132 } | 108 } |
| 133 } | 109 } |
| 134 | 110 |
| 135 return false; | 111 return false; |
| 136 } | 112 } |
| 137 | 113 |
| 138 bool IsInternalOutputName(const std::string& name) { | 114 } // namespace |
| 139 return name.find(kInternal_LVDS) == 0 || name.find(kInternal_eDP) == 0 || | 115 |
| 140 name.find(kInternal_DSI) == 0; | 116 DisplaySnapshotX11::DisplaySnapshotX11( |
| 117 int64_t display_id, |
| 118 bool has_proper_display_id, |
| 119 const gfx::Point& origin, |
| 120 const gfx::Size& physical_size, |
| 121 OutputType type, |
| 122 bool is_aspect_preserving_scaling, |
| 123 const std::vector<const DisplayMode*>& modes, |
| 124 const DisplayMode* current_mode, |
| 125 const DisplayMode* native_mode, |
| 126 RROutput output, |
| 127 RRCrtc crtc, |
| 128 int index) |
| 129 : DisplaySnapshot(display_id, |
| 130 has_proper_display_id, |
| 131 origin, |
| 132 physical_size, |
| 133 type, |
| 134 is_aspect_preserving_scaling, |
| 135 modes, |
| 136 current_mode, |
| 137 native_mode), |
| 138 output_(output), |
| 139 crtc_(crtc), |
| 140 index_(index) {} |
| 141 |
| 142 DisplaySnapshotX11::~DisplaySnapshotX11() {} |
| 143 |
| 144 std::string DisplaySnapshotX11::GetDisplayName() { |
| 145 std::string display_name; |
| 146 GetOutputDeviceData(output_, NULL, &display_name); |
| 147 return display_name; |
| 141 } | 148 } |
| 142 | 149 |
| 143 const XRRModeInfo* FindXRRModeInfo(const XRRScreenResources* screen_resources, | 150 bool DisplaySnapshotX11::GetOverscanFlag() { |
| 144 XID current_mode) { | 151 unsigned long nitems = 0; |
| 145 for (int m = 0; m < screen_resources->nmode; m++) { | 152 unsigned char* prop = NULL; |
| 146 XRRModeInfo *mode = &screen_resources->modes[m]; | 153 bool flag = false; |
| 147 if (mode->id == current_mode) | 154 if (!base::GetEDIDProperty(output_, &nitems, &prop)) |
| 148 return mode; | 155 return false; |
| 149 } | 156 |
| 150 return NULL; | 157 ParseOutputOverscanFlag(prop, nitems, &flag); |
| 158 XFree(prop); |
| 159 |
| 160 return flag; |
| 151 } | 161 } |
| 152 | 162 |
| 153 namespace test { | 163 std::string DisplaySnapshotX11::ToString() const { |
| 154 | 164 return base::StringPrintf( |
| 155 XRRModeInfo CreateModeInfo(int id, | 165 "[type=%d, output=%ld, crtc=%ld, mode=%ld, dim=%dx%d]", |
| 156 int width, | 166 type_, |
| 157 int height, | 167 output_, |
| 158 bool interlaced, | 168 crtc_, |
| 159 float refresh_rate) { | 169 current_mode_ |
| 160 XRRModeInfo mode_info = {0}; | 170 ? static_cast<const DisplayModeX11*>(current_mode_)->mode_id() |
| 161 mode_info.id = id; | 171 : 0, |
| 162 mode_info.width = width; | 172 physical_size_.width(), |
| 163 mode_info.height = height; | 173 physical_size_.height()); |
| 164 if (interlaced) | |
| 165 mode_info.modeFlags = RR_Interlace; | |
| 166 if (refresh_rate != 0.0f) { | |
| 167 mode_info.hTotal = 1; | |
| 168 mode_info.vTotal = 1; | |
| 169 mode_info.dotClock = refresh_rate; | |
| 170 } | |
| 171 return mode_info; | |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace test | 176 } // namespace ui |
| 175 | |
| 176 } // namespace chromeos | |
| OLD | NEW |