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

Side by Side Diff: ui/display/chromeos/x11/display_util.cc

Issue 192483007: Move chromeos/display/* to ui/display/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Include display.gyp into ChromeOS builds only Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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_util.h"
6 6
7 #include <X11/extensions/Xrandr.h> 7 #include <X11/extensions/Xrandr.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 10
11 #include "base/macros.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/x11/edid_parser_x11.h" 13 #include "base/x11/edid_parser_x11.h"
13 14
14 namespace chromeos { 15 namespace ui {
16
15 namespace { 17 namespace {
16 18
17 // Prefixes for the built-in displays. 19 struct OutputTypeMapping {
18 const char kInternal_LVDS[] = "LVDS"; 20 // Prefix of output name.
19 const char kInternal_eDP[] = "eDP"; 21 std::string name;
20 const char kInternal_DSI[] = "DSI"; 22 OutputType type;
23 };
24
25 const OutputTypeMapping kOutputTypeMapping[] = {
26 {"LVDS", OUTPUT_TYPE_INTERNAL},
27 {"eDP", OUTPUT_TYPE_INTERNAL},
28 {"DSI", OUTPUT_TYPE_INTERNAL},
29 {"VGA", OUTPUT_TYPE_VGA},
30 {"HDMI", OUTPUT_TYPE_HDMI},
31 {"DVI", OUTPUT_TYPE_DVI},
32 {"DP", OUTPUT_TYPE_DISPLAYPORT}
33 };
21 34
22 // Gets some useful data from the specified output device, such like 35 // 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 36 // 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. 37 // fails to get those data and doesn't touch manufacturer ID/product code/name.
25 // NULL can be passed for unwanted output parameters. 38 // NULL can be passed for unwanted output parameters.
26 bool GetOutputDeviceData(XID output, 39 bool GetOutputDeviceData(XID output,
27 uint16* manufacturer_id, 40 uint16* manufacturer_id,
28 std::string* human_readable_name) { 41 std::string* human_readable_name) {
29 unsigned long nitems = 0; 42 unsigned long nitems = 0;
30 unsigned char *prop = NULL; 43 unsigned char* prop = NULL;
31 if (!base::GetEDIDProperty(output, &nitems, &prop)) 44 if (!base::GetEDIDProperty(output, &nitems, &prop))
32 return false; 45 return false;
33 46
34 bool result = base::ParseOutputDeviceData( 47 bool result = base::ParseOutputDeviceData(
35 prop, nitems, manufacturer_id, human_readable_name); 48 prop, nitems, manufacturer_id, human_readable_name);
36 XFree(prop); 49 XFree(prop);
37 return result; 50 return result;
38 } 51 }
39 52
40 } // namespace 53 } // namespace
41 54
42 std::string GetDisplayName(XID output_id) { 55 OutputType GetOutputTypeFromName(const std::string& name) {
56 for (unsigned int i = 0; i < arraysize(kOutputTypeMapping); ++i) {
57 if (name.find(kOutputTypeMapping[i].name) == 0) {
58 return kOutputTypeMapping[i].type;
59 }
60 }
61
62 return OUTPUT_TYPE_UNKNOWN;
63 }
64
65 std::string GetDisplayName(const OutputConfigurator::OutputSnapshot& output) {
43 std::string display_name; 66 std::string display_name;
44 GetOutputDeviceData(output_id, NULL, &display_name); 67 GetOutputDeviceData(output.output, NULL, &display_name);
45 return display_name; 68 return display_name;
46 } 69 }
47 70
48 bool GetOutputOverscanFlag(XID output, bool* flag) { 71 bool GetOutputOverscanFlag(const OutputConfigurator::OutputSnapshot& output,
72 bool* flag) {
49 unsigned long nitems = 0; 73 unsigned long nitems = 0;
50 unsigned char *prop = NULL; 74 unsigned char* prop = NULL;
51 if (!base::GetEDIDProperty(output, &nitems, &prop)) 75 if (!base::GetEDIDProperty(output.output, &nitems, &prop))
52 return false; 76 return false;
53 77
54 bool found = ParseOutputOverscanFlag(prop, nitems, flag); 78 bool found = ParseOutputOverscanFlag(prop, nitems, flag);
55 XFree(prop); 79 XFree(prop);
56 return found; 80 return found;
57 } 81 }
58 82
59 bool ParseOutputOverscanFlag(const unsigned char* prop, 83 bool ParseOutputOverscanFlag(const unsigned char* prop,
60 unsigned long nitems, 84 unsigned long nitems,
61 bool *flag) { 85 bool* flag) {
62 // See http://en.wikipedia.org/wiki/Extended_display_identification_data 86 // See http://en.wikipedia.org/wiki/Extended_display_identification_data
63 // for the extension format of EDID. Also see EIA/CEA-861 spec for 87 // 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. 88 // the format of the extensions and how video capability is encoded.
65 // - byte 0: tag. should be 02h. 89 // - byte 0: tag. should be 02h.
66 // - byte 1: revision. only cares revision 3 (03h). 90 // - byte 1: revision. only cares revision 3 (03h).
67 // - byte 4-: data block. 91 // - byte 4-: data block.
68 const unsigned int kExtensionBase = 128; 92 const unsigned int kExtensionBase = 128;
69 const unsigned int kExtensionSize = 128; 93 const unsigned int kExtensionSize = 128;
70 const unsigned int kNumExtensionsOffset = 126; 94 const unsigned int kNumExtensionsOffset = 126;
71 const unsigned int kDataBlockOffset = 4; 95 const unsigned int kDataBlockOffset = 4;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } else { 152 } else {
129 *flag = false; 153 *flag = false;
130 } 154 }
131 return true; 155 return true;
132 } 156 }
133 } 157 }
134 158
135 return false; 159 return false;
136 } 160 }
137 161
138 bool IsInternalOutputName(const std::string& name) { 162 } // namespace ui
139 return name.find(kInternal_LVDS) == 0 || name.find(kInternal_eDP) == 0 ||
140 name.find(kInternal_DSI) == 0;
141 }
142
143 const XRRModeInfo* FindXRRModeInfo(const XRRScreenResources* screen_resources,
144 XID current_mode) {
145 for (int m = 0; m < screen_resources->nmode; m++) {
146 XRRModeInfo *mode = &screen_resources->modes[m];
147 if (mode->id == current_mode)
148 return mode;
149 }
150 return NULL;
151 }
152
153 namespace test {
154
155 XRRModeInfo CreateModeInfo(int id,
156 int width,
157 int height,
158 bool interlaced,
159 float refresh_rate) {
160 XRRModeInfo mode_info = {0};
161 mode_info.id = id;
162 mode_info.width = width;
163 mode_info.height = 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 }
173
174 } // namespace test
175
176 } // namespace chromeos
OLDNEW
« no previous file with comments | « ui/display/chromeos/x11/display_util.h ('k') | ui/display/chromeos/x11/display_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698