mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 20:25:12 +00:00
LibEDID: Store EDID version instead of allocating on each getter call
This also let's us use a KString instead of a string when we're in the Kernel, which opens the path for OOM-failure propagation.
This commit is contained in:
parent
5b572393a9
commit
4a15ed6164
3 changed files with 25 additions and 5 deletions
|
@ -462,6 +462,12 @@ ErrorOr<void> Parser::parse()
|
||||||
if (major_version != 1 || m_revision > 4)
|
if (major_version != 1 || m_revision > 4)
|
||||||
return Error::from_string_literal("Unsupported Parser version"sv);
|
return Error::from_string_literal("Unsupported Parser version"sv);
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
m_version = TRY(Kernel::KString::formatted("1.{}", (int)m_revision));
|
||||||
|
#else
|
||||||
|
m_version = String::formatted("1.{}", (int)m_revision);
|
||||||
|
#endif
|
||||||
|
|
||||||
u8 checksum = 0x0;
|
u8 checksum = 0x0;
|
||||||
for (size_t i = 0; i < sizeof(Definitions::EDID); i++)
|
for (size_t i = 0; i < sizeof(Definitions::EDID); i++)
|
||||||
checksum += m_bytes[i];
|
checksum += m_bytes[i];
|
||||||
|
@ -540,9 +546,13 @@ ErrorOr<IterationDecision> Parser::for_each_extension_block(Function<IterationDe
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Parser::version() const
|
StringView Parser::version() const
|
||||||
{
|
{
|
||||||
return String::formatted("1.{}", (int)m_revision);
|
#ifdef KERNEL
|
||||||
|
return m_version->view();
|
||||||
|
#else
|
||||||
|
return m_version;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
String Parser::legacy_manufacturer_id() const
|
String Parser::legacy_manufacturer_id() const
|
||||||
|
|
|
@ -6,17 +6,23 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/ByteReader.h>
|
#include <AK/ByteReader.h>
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/FixedPoint.h>
|
#include <AK/FixedPoint.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <AK/String.h>
|
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibEDID/DMT.h>
|
#include <LibEDID/DMT.h>
|
||||||
#include <LibEDID/VIC.h>
|
#include <LibEDID/VIC.h>
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
# include <Kernel/KString.h>
|
||||||
|
#else
|
||||||
|
# include <AK/String.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace EDID {
|
namespace EDID {
|
||||||
|
|
||||||
namespace Definitions {
|
namespace Definitions {
|
||||||
|
@ -415,7 +421,7 @@ public:
|
||||||
|
|
||||||
bool operator==(Parser const& other) const;
|
bool operator==(Parser const& other) const;
|
||||||
|
|
||||||
String version() const;
|
StringView version() const;
|
||||||
|
|
||||||
auto bytes() const { return m_bytes; }
|
auto bytes() const { return m_bytes; }
|
||||||
|
|
||||||
|
@ -442,6 +448,11 @@ private:
|
||||||
ByteBuffer m_bytes_buffer;
|
ByteBuffer m_bytes_buffer;
|
||||||
ReadonlyBytes m_bytes;
|
ReadonlyBytes m_bytes;
|
||||||
u8 m_revision { 0 };
|
u8 m_revision { 0 };
|
||||||
|
#ifdef KERNEL
|
||||||
|
OwnPtr<Kernel::KString> m_version;
|
||||||
|
#else
|
||||||
|
String m_version;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/String.h>
|
|
||||||
#include <LibEDID/VIC.h>
|
#include <LibEDID/VIC.h>
|
||||||
|
|
||||||
namespace EDID {
|
namespace EDID {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue