diff options
author | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-08-01 22:29:05 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-08-03 18:11:01 +0000 |
commit | e201878b936eefc7ebdab9d30198e2584e5b5617 (patch) | |
tree | 6504cc7f82406930ae4866971adf9bc66bbdfd6d /src/platformsupport | |
parent | 5273604dac6200a03d2d044254f0b7006b077688 (diff) |
Fix manufacturer parsing from EDID
The code was quite dubious, in the edid data, the manufacturer is
encoded with a three letter shortcut. In addition it can be set by the
extra data strings, which is not often the case. We would randomly
overwrite the identifier string, so clearly separate the pnpId (3 letter
ID) out and use the fallback table we have.
Also looking up the manufacturer string twice is pointless (contains and
then operator[]).
Change-Id: I18882a78d69b9f3dfc2af31e646ded44f2b70a50
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r-- | src/platformsupport/edid/qedidparser.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/platformsupport/edid/qedidparser.cpp b/src/platformsupport/edid/qedidparser.cpp index 1cc16b47f8..ccaa50704c 100644 --- a/src/platformsupport/edid/qedidparser.cpp +++ b/src/platformsupport/edid/qedidparser.cpp @@ -100,11 +100,11 @@ bool QEdidParser::parse(const QByteArray &blob) * 7654321076543210 * |\---/\---/\---/ * R C1 C2 C3 */ - char id[3]; - id[0] = 'A' + ((data[EDID_OFFSET_PNP_ID] & 0x7c) / 4) - 1; - id[1] = 'A' + ((data[EDID_OFFSET_PNP_ID] & 0x3) * 8) + ((data[EDID_OFFSET_PNP_ID + 1] & 0xe0) / 32) - 1; - id[2] = 'A' + (data[EDID_OFFSET_PNP_ID + 1] & 0x1f) - 1; - identifier = QString::fromLatin1(id, 3); + char pnpId[3]; + pnpId[0] = 'A' + ((data[EDID_OFFSET_PNP_ID] & 0x7c) / 4) - 1; + pnpId[1] = 'A' + ((data[EDID_OFFSET_PNP_ID] & 0x3) * 8) + ((data[EDID_OFFSET_PNP_ID + 1] & 0xe0) / 32) - 1; + pnpId[2] = 'A' + (data[EDID_OFFSET_PNP_ID + 1] & 0x1f) - 1; + QString pnpIdString = QString::fromLatin1(pnpId, 3); // Clear manufacturer manufacturer = QString(); @@ -136,12 +136,11 @@ bool QEdidParser::parse(const QByteArray &blob) } // Try to use cache first because it is potentially more updated - if (m_vendorCache.contains(identifier)) { - manufacturer = m_vendorCache[identifier]; - } else { + manufacturer = m_vendorCache.value(pnpIdString); + if (manufacturer.isEmpty()) { // Find the manufacturer from the vendor lookup table for (size_t i = 0; i < ARRAY_LENGTH(q_edidVendorTable); i++) { - if (strcmp(q_edidVendorTable[i].id, identifier.toLatin1().constData()) == 0) { + if (strncmp(q_edidVendorTable[i].id, pnpId, 3) == 0) { manufacturer = QString::fromUtf8(q_edidVendorTable[i].name); break; } @@ -150,7 +149,7 @@ bool QEdidParser::parse(const QByteArray &blob) // If we don't know the manufacturer, fallback to PNP ID if (manufacturer.isEmpty()) - manufacturer = identifier; + manufacturer = pnpIdString; // Physical size physicalSize = QSizeF(data[EDID_PHYSICAL_WIDTH], data[EDID_OFFSET_PHYSICAL_HEIGHT]) * 10; |