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

Unified Diff: ui/base/x/x11_util.cc

Issue 11725005: Checks the possibility of overscans from EDID extension data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
« ui/base/x/x11_util.h ('K') | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/x/x11_util.cc
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 539c87910e3debd24cf29925efad308cd124d7e6..eb8811b7b0082a8fff33332b8c9f48599b2482fd 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -331,6 +331,48 @@ bool IsShapeAvailable() {
}
+bool GetEDIDProperty(XID output, unsigned long* nitems, unsigned char* prop) {
Daniel Erat 2013/01/03 19:04:19 nit: add a comment stating that the caller must fr
Jun Mukai 2013/01/03 21:37:37 Done.
+ if (!IsRandRAvailable())
+ return false;
+
+ static Atom edid_property = GetAtom(RR_PROPERTY_RANDR_EDID);
+
+ Display* display = GetXDisplay();
+
+ bool has_edid_property = false;
+ int num_properties = 0;
+ Atom* properties = XRRListOutputProperties(display, output, &num_properties);
+ for (int i = 0; i < num_properties; ++i) {
+ if (properties[i] == edid_property) {
+ has_edid_property = true;
+ break;
+ }
+ }
+ XFree(properties);
+ if (!has_edid_property)
+ return false;
+
+ Atom actual_type;
+ int actual_format;
+ unsigned long bytes_after;
+ XRRGetOutputProperty(display,
+ output,
+ edid_property,
+ 0, // offset
+ 128, // length
+ false, // _delete
+ false, // pending
+ AnyPropertyType, // req_type
+ &actual_type,
+ &actual_format,
+ nitems,
+ &bytes_after,
+ &prop);
+ DCHECK_EQ(XA_INTEGER, actual_type);
+ DCHECK_EQ(8, actual_format);
+ return true;
+}
+
} // namespace
bool XDisplayExists() {
@@ -1248,47 +1290,11 @@ bool GetOutputDeviceData(XID output,
uint16* manufacturer_id,
uint32* serial_number,
std::string* human_readable_name) {
- if (!IsRandRAvailable())
- return false;
-
- static Atom edid_property = GetAtom(RR_PROPERTY_RANDR_EDID);
-
- Display* display = GetXDisplay();
-
- bool has_edid_property = false;
- int num_properties = 0;
- Atom* properties = XRRListOutputProperties(display, output, &num_properties);
- for (int i = 0; i < num_properties; ++i) {
- if (properties[i] == edid_property) {
- has_edid_property = true;
- break;
- }
- }
- XFree(properties);
- if (!has_edid_property)
+ unsigned long nitems = 0;
+ unsigned char *prop = NULL;
+ if (!GetEDIDProperty(output, &nitems, prop))
sadrul 2013/01/03 19:08:32 This doesn't actually set the value of |prop|, doe
Jun Mukai 2013/01/03 21:37:37 aww, right. Fixed.
return false;
- Atom actual_type;
- int actual_format;
- unsigned long nitems;
- unsigned long bytes_after;
- unsigned char *prop;
- XRRGetOutputProperty(display,
- output,
- edid_property,
- 0, // offset
- 128, // length
- false, // _delete
- false, // pending
- AnyPropertyType, // req_type
- &actual_type,
- &actual_format,
- &nitems,
- &bytes_after,
- &prop);
- DCHECK_EQ(XA_INTEGER, actual_type);
- DCHECK_EQ(8, actual_format);
-
// See http://en.wikipedia.org/wiki/Extended_display_identification_data
// for the details of EDID data format. We use the following data:
// bytes 8-9: manufacturer EISA ID, in big-endian
@@ -1372,6 +1378,85 @@ bool GetOutputDeviceData(XID output,
return true;
}
+bool GetOutputOverscanFlag(XID output) {
Daniel Erat 2013/01/03 19:04:19 since this code does a lot of tricky byte-reading,
Jun Mukai 2013/01/03 21:37:37 Added.
+ unsigned long nitems = 0;
+ unsigned char *prop = NULL;
+ if (!GetEDIDProperty(output, &nitems, prop))
+ return false;
+
+ const unsigned int kNumExtensionsOffset = 126;
+ if (nitems < kNumExtensionsOffset) {
+ XFree(prop);
+ return false;
+ }
+
+ // See http://en.wikipedia.org/wiki/Extended_display_identification_data
+ // for the extension format of EDID. Also see
+ // http://blogimg.chinaunix.net/blog/upfile2/090903185737.pdf pg.87-
+ // for the format of the extensions and how video capability is encoded.
+ // - byte 0: tag. should be 02h.
+ // - byte 1: revision. only cares revision 3 (03h).
+ // - byte 4-: data block.
+ const unsigned int kExtensionBase = 128;
+ const unsigned int kExtensionSize = 128;
+ const unsigned int kDataBlockOffset = 4;
+ const unsigned char kCEAExtensionTag = '\x02';
+ const unsigned char kExpectedExtensionRevision = '\x03';
+ const unsigned char kExtendedTag = 7;
+ const unsigned char kExtendedVideoCapabilityTag = 0;
+ const unsigned int kPTOverscan = 4;
+ const unsigned int kITOverscan = 2;
+ const unsigned int kCEOverscan = 0;
+
+ unsigned char num_extensions = prop[kNumExtensionsOffset];
+ bool result = false;
+ bool found = false;
+
+ for (size_t i = 0; i < num_extensions && !found; ++i) {
+ unsigned char* extension = prop + kExtensionBase + i * kExtensionSize;
+ unsigned char tag = extension[0];
+ unsigned char revision = extension[1];
+ if (tag != kCEAExtensionTag || revision != kExpectedExtensionRevision)
+ continue;
+
+ unsigned char timing_descriptors_start = extension[2];
+ unsigned char* data_block = extension + kDataBlockOffset;
+ while (data_block < extension + timing_descriptors_start) {
+ // a data block is encoded as:
+ // - byte 1 high 3 bits: tag. '07' for extended tags.
+ // - byte 1 remaining bits: the length of data block.
+ // - byte 2: the extended tag. '0' for video capability.
+ // - byte 3: the capability.
+ unsigned char tag = data_block[0] >> 5;
+ unsigned char payload_length = data_block[0] & 0x1f;
+ if (tag != kExtendedTag && payload_length < 2) {
+ data_block += payload_length + 1;
+ continue;
+ }
+
+ unsigned char extended_tag_code = data_block[1];
+ // Here doesn't care the difference between preferred video format /
Daniel Erat 2013/01/03 19:04:19 nit: reword this to something like: // The differ
Jun Mukai 2013/01/03 21:37:37 Sorry, the comment location was wrong. Moved to th
+ // IT video format / CE video format, since it just checks the
+ // possibility.
+ if (extended_tag_code != kExtendedVideoCapabilityTag) {
+ data_block += payload_length;
+ continue;
+ }
+
+ found = true;
+ if ((data_block[2] & (1 << kPTOverscan)) ||
+ (data_block[2] & (1 << kITOverscan)) ||
+ (data_block[2] & (1 << kCEOverscan))) {
+ result = true;
+ }
+ break;
+ }
+ }
+
+ XFree(prop);
+ return result;
+}
+
std::vector<std::string> GetDisplayNames(const std::vector<XID>& output_ids) {
std::vector<std::string> names;
for (size_t i = 0; i < output_ids.size(); ++i) {
« ui/base/x/x11_util.h ('K') | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698