Skip to content

Commit

Permalink
platform/DRMFormat: Don't require a FormatInfo for each format. (#3463
Browse files Browse the repository at this point in the history
)

We're now using `DRMFormat` in a situation (linux-dmabuf) where:
* We don't actually need to care about many the properties of the
format, and
* We're processing formats submitted by cilents.

This means that the existing “throw an exception if we haven't got a
`FormatInfo`” approach works badly; we will disconnect clients with a
Wayland internal error if they submit buffers in a format we haven't
explicitly listed, even though it *would* work if we just treated the
format as an opaque identifier.

So, don't do that anymore. Instead, store the fourcc code directly in
`DRMFormat`, only look up the `FormatInfo` (now `DRMFormat::Info`) when
code asks for it.

Additionally, we log the first time code asks for the `DRMFormat::Info`
for a format we haven't got info for; this way we can fill out the
needed formats on an as-noticed basis.

Fixes: #3462
  • Loading branch information
RAOF authored Jul 15, 2024
2 parents 5557be6 + 2d01c22 commit 538f6b0
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 111 deletions.
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Description: Display server for Ubuntu - server library
.
Contains the shared library needed by server applications for Mir.

Package: libmirplatform28
Package: libmirplatform29
Section: libs
Architecture: linux-any
Multi-Arch: same
Expand Down Expand Up @@ -140,7 +140,7 @@ Section: libdevel
Architecture: linux-any
Multi-Arch: same
Pre-Depends: ${misc:Pre-Depends}
Depends: libmirplatform28 (= ${binary:Version}),
Depends: libmirplatform29 (= ${binary:Version}),
libmircommon-dev (= ${binary:Version}),
libboost-program-options-dev,
${misc:Depends},
Expand Down
1 change: 0 additions & 1 deletion debian/libmirplatform28.install

This file was deleted.

1 change: 1 addition & 0 deletions debian/libmirplatform29.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/libmirplatform.so.29
43 changes: 28 additions & 15 deletions include/platform/mir/graphics/drm_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,47 @@ namespace mir::graphics
class DRMFormat
{
public:
struct RGBComponentInfo
struct FormatInfo;
class Info
{
uint32_t red_bits;
uint32_t green_bits;
uint32_t blue_bits;
std::optional<uint32_t> alpha_bits;
};
public:
struct RGBComponentInfo
{
uint32_t red_bits;
uint32_t green_bits;
uint32_t blue_bits;
std::optional<uint32_t> alpha_bits;
};

// This could be constexpr, at the cost of moving a bunch of implementation into the header
explicit DRMFormat(uint32_t fourcc_format);
auto opaque_equivalent() const -> std::optional<DRMFormat>;
auto alpha_equivalent() const -> std::optional<DRMFormat>;

auto name() const -> char const*;
bool has_alpha() const;

auto opaque_equivalent() const -> std::optional<DRMFormat> const;
auto alpha_equivalent() const -> std::optional<DRMFormat> const;
auto components() const -> std::optional<RGBComponentInfo> const&;
private:
friend class DRMFormat;
Info(FormatInfo const* info);

bool has_alpha() const;
FormatInfo const* info;
};

auto components() const -> std::optional<RGBComponentInfo> const&;
constexpr explicit DRMFormat(uint32_t fourcc_format)
: fourcc{fourcc_format}
{
}

auto name() const -> char const*;

auto info() const -> std::optional<Info const>;

operator uint32_t() const;

auto as_mir_format() const -> std::optional<MirPixelFormat>;
static auto from_mir_format(MirPixelFormat format) -> DRMFormat;

struct FormatInfo;
private:
FormatInfo const* info;
uint32_t fourcc;
};

auto drm_modifier_to_string(uint64_t modifier) -> std::string;
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# We need MIRPLATFORM_ABI in both libmirplatform and the platform implementations.
set(MIRPLATFORM_ABI 28)
set(MIRPLATFORM_ABI 29)

set(MIRAL_VERSION_MAJOR 5)
set(MIRAL_VERSION_MINOR 1)
Expand Down
Loading

0 comments on commit 538f6b0

Please sign in to comment.