Skip to content

Commit

Permalink
Merge branch 'platform-API-merge' into platform-API-merge-fix-eglstreams
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Oct 17, 2023
2 parents e93c3ab + 6a40e4d commit 6e64dfc
Show file tree
Hide file tree
Showing 52 changed files with 226 additions and 1,371 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "${build_types}" FORCE)
# Enable cmake-gui to display a drop down list for CMAKE_BUILD_TYPE
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${build_types}")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down
108 changes: 46 additions & 62 deletions include/platform/mir/graphics/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class DisplayInterfaceProvider;

namespace probe
{
/**
* A measure of how well a platform supports a device
*
* \note This is compared as an integer; best + 1 is a valid Result that
* will be used in preference to a module that reports best.
* Platform modules distributed with Mir will never use a priority higher
* than best.
*/
using Result = uint32_t;
Result const unsupported = 0; /**< Unable to function at all on this device */
Result const dummy = 1; /**< Used only for dummy or stub platforms.
Expand All @@ -82,7 +90,7 @@ namespace probe
*/
}

class RendererInterfaceBase
class RenderingProvider
{
public:
class Tag
Expand All @@ -92,7 +100,7 @@ class RendererInterfaceBase
virtual ~Tag() = default;
};

virtual ~RendererInterfaceBase() = default;
virtual ~RenderingProvider() = default;

class FramebufferProvider
{
Expand Down Expand Up @@ -143,10 +151,10 @@ class Texture;
class OutputSurface;
}

class GLRenderingProvider : public RendererInterfaceBase
class GLRenderingProvider : public RenderingProvider
{
public:
class Tag : public RendererInterfaceBase::Tag
class Tag : public RenderingProvider::Tag
{
};

Expand Down Expand Up @@ -190,22 +198,22 @@ class RenderingPlatform
* Since this may result in a runtime probe the call may be costly, and the
* result should be saved rather than re-acquiring an interface each time.
*
* \tparam Interface
* \return On success: an occupied std::shared_ptr<Interface>
* On failure: std::shared_ptr<Interface>{nullptr}
* \tparam Provider
* \return On success: an occupied std::shared_ptr<Provider>
* On failure: std::shared_ptr<Provider>{nullptr}
*/
template<typename Interface>
static auto acquire_interface(std::shared_ptr<RenderingPlatform> platform) -> std::shared_ptr<Interface>
template<typename Provider>
static auto acquire_provider(std::shared_ptr<RenderingPlatform> platform) -> std::shared_ptr<Provider>
{
static_assert(
std::is_convertible_v<Interface*, RendererInterfaceBase*>,
"Can only acquire a Renderer interface; Interface must implement RendererInterfaceBase");
std::is_convertible_v<Provider*, RenderingProvider*>,
"Can only acquire a Renderer interface; Provider must implement RenderingProvider");

if (auto const base_interface = platform->maybe_create_interface(typename Interface::Tag{}))
if (auto const provider = platform->maybe_create_provider(typename Provider::Tag{}))
{
if (auto const requested_interface = std::dynamic_pointer_cast<Interface>(base_interface))
if (auto const requested = std::dynamic_pointer_cast<Provider>(provider))
{
return requested_interface;
return requested;
}
BOOST_THROW_EXCEPTION((
std::logic_error{
Expand All @@ -216,7 +224,7 @@ class RenderingPlatform

protected:
/**
* Acquire a specific hardware interface
* Acquire a specific rendering interface
*
* This should perform any runtime checks necessary to verify the requested interface is
* expected to work and return a pointer to an implementation of that interface.
Expand All @@ -228,14 +236,15 @@ class RenderingPlatform
* \param type_tag [in] An instance of the Tag type for the requested interface.
* Implementations are expected to dynamic_cast<> this to
* discover the specific interface being requested.
* \return A pointer to an implementation of the RenderInterfaceBase-derived
* interface that corresponds to the most-derived type of tag_type.
* \return On success: A pointer to an implementation of the RenderingProvider-derived
* interface that corresponds to the most-derived type of tag_type
* On failure: std::shared_ptr<RenderingProvider>{nullptr}
*/
virtual auto maybe_create_interface(
RendererInterfaceBase::Tag const& type_tag) -> std::shared_ptr<RendererInterfaceBase> = 0;
virtual auto maybe_create_provider(
RenderingProvider::Tag const& type_tag) -> std::shared_ptr<RenderingProvider> = 0;
};

class DisplayInterfaceBase
class DisplayProvider
{
public:
class Tag
Expand All @@ -245,7 +254,7 @@ class DisplayInterfaceBase
virtual ~Tag() = default;
};

virtual ~DisplayInterfaceBase() = default;
virtual ~DisplayProvider() = default;
};


Expand All @@ -262,10 +271,10 @@ class Framebuffer
};


class CPUAddressableDisplayProvider : public DisplayInterfaceBase
class CPUAddressableDisplayProvider : public DisplayProvider
{
public:
class Tag : public DisplayInterfaceBase::Tag
class Tag : public DisplayProvider::Tag
{
};

Expand All @@ -285,10 +294,10 @@ class CPUAddressableDisplayProvider : public DisplayInterfaceBase
-> std::unique_ptr<MappableFB> = 0;
};

class GBMDisplayProvider : public DisplayInterfaceBase
class GBMDisplayProvider : public DisplayProvider
{
public:
class Tag : public DisplayInterfaceBase::Tag
class Tag : public DisplayProvider::Tag
{
};

Expand Down Expand Up @@ -342,10 +351,10 @@ class GBMDisplayProvider : public DisplayInterfaceBase

class DmaBufBuffer;

class DmaBufDisplayProvider : public DisplayInterfaceBase
class DmaBufDisplayProvider : public DisplayProvider
{
public:
class Tag : public DisplayInterfaceBase::Tag
class Tag : public DisplayProvider::Tag
{
};

Expand All @@ -357,10 +366,10 @@ class DmaBufDisplayProvider : public DisplayInterfaceBase
typedef void* EGLStreamKHR;
#endif

class EGLStreamDisplayProvider : public DisplayInterfaceBase
class EGLStreamDisplayProvider : public DisplayProvider
{
public:
class Tag : public DisplayInterfaceBase::Tag
class Tag : public DisplayProvider::Tag
{
};

Expand All @@ -369,10 +378,10 @@ class EGLStreamDisplayProvider : public DisplayInterfaceBase
virtual auto claim_stream() -> EGLStreamKHR = 0;
};

class GenericEGLDisplayProvider : public DisplayInterfaceBase
class GenericEGLDisplayProvider : public DisplayProvider
{
public:
class Tag : public DisplayInterfaceBase::Tag
class Tag : public DisplayProvider::Tag
{
};

Expand Down Expand Up @@ -415,8 +424,8 @@ class DisplayInterfaceProvider : public std::enable_shared_from_this<DisplayInte
auto acquire_interface() -> std::shared_ptr<Interface>
{
static_assert(
std::is_convertible_v<Interface*, DisplayInterfaceBase*>,
"Can only acquire a Display interface; Interface must implement DisplayInterfaceBase");
std::is_convertible_v<Interface*, DisplayProvider*>,
"Can only acquire a Display interface; Interface must implement DisplayProvider");

if (auto const base_interface = maybe_create_interface(typename Interface::Tag{}))
{
Expand Down Expand Up @@ -444,11 +453,11 @@ class DisplayInterfaceProvider : public std::enable_shared_from_this<DisplayInte
* \param type_tag [in] An instance of the Tag type for the requested interface.
* Implementations are expected to dynamic_cast<> this to
* discover the specific interface being requested.
* \return A pointer to an implementation of the DisplayInterfaceBase-derived
* \return A pointer to an implementation of the DisplayProvider-derived
* interface that corresponds to the most-derived type of tag_type.
*/
virtual auto maybe_create_interface(DisplayInterfaceBase::Tag const& type_tag)
-> std::shared_ptr<DisplayInterfaceBase> = 0;
virtual auto maybe_create_interface(DisplayProvider::Tag const& type_tag)
-> std::shared_ptr<DisplayProvider> = 0;
};

class DisplayPlatform : public std::enable_shared_from_this<DisplayPlatform>
Expand Down Expand Up @@ -476,31 +485,6 @@ class DisplayPlatform : public std::enable_shared_from_this<DisplayPlatform>
virtual auto interface_for() -> std::shared_ptr<DisplayInterfaceProvider> = 0;
};

/**
* A measure of how well a platform supports a device
*
* \note This is compared as an integer; best + 1 is a valid PlatformPriority that
* will be used in preference to a module that reports best.
* Platform modules distributed with Mir will never use a priority higher
* than best.
*/
enum PlatformPriority : uint32_t
{
unsupported = 0, /**< Unable to function at all on this device */
dummy = 1, /**< Used only for dummy or stub platforms.
*/
supported = 128, /**< Capable of providing a functioning Platform on this device,
* possibly with degraded performance or features.
*/
hosted = 192, /**< Capable of providing a fully-featured Platform on this device,
* running nested under some other display server rather than with
* exclusive hardware access.
*/
best = 256 /**< Capable of providing a Platform with the best features and
* performance this device is capable of.
*/
};

struct SupportedDevice
{
/**
Expand All @@ -516,7 +500,7 @@ struct SupportedDevice
* particular hardware.
*/
std::unique_ptr<udev::Device> device;
PlatformPriority support_level; /**< How well the platform can support this device */
probe::Result support_level; /**< How well the platform can support this device */

/**
* Platform-private data from probing
Expand Down
1 change: 1 addition & 0 deletions src/include/server/mir/input/vt_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VTFilter : public EventFilter
{
public:
VTFilter(std::unique_ptr<VTSwitcher> switcher);
~VTFilter();

bool handle(MirEvent const& event) override;

Expand Down
2 changes: 2 additions & 0 deletions src/platforms/eglstream-kms/server/buffer_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ mge::GLRenderingProvider::GLRenderingProvider(EGLDisplay dpy, std::unique_ptr<mi
{
}

mge::GLRenderingProvider::~GLRenderingProvider() = default;

auto mir::graphics::eglstream::GLRenderingProvider::as_texture(std::shared_ptr<Buffer> buffer)
-> std::shared_ptr<gl::Texture>
{
Expand Down
1 change: 1 addition & 0 deletions src/platforms/eglstream-kms/server/buffer_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class GLRenderingProvider : public graphics::GLRenderingProvider
{
public:
GLRenderingProvider(EGLDisplay dpy, std::unique_ptr<renderer::gl::Context> ctx);
~GLRenderingProvider();

auto as_texture(std::shared_ptr<Buffer> buffer) -> std::shared_ptr<gl::Texture> override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace mg = mir::graphics;

namespace
{
class DisplayProvider : public mg::EGLStreamDisplayProvider
class DisplayProviderImpl : public mg::EGLStreamDisplayProvider
{
public:
DisplayProvider(EGLDisplay dpy, std::optional<EGLStreamKHR> stream);
DisplayProviderImpl(EGLDisplay dpy, std::optional<EGLStreamKHR> stream);

auto get_egl_display() const -> EGLDisplay override;

Expand All @@ -40,18 +40,18 @@ class DisplayProvider : public mg::EGLStreamDisplayProvider
std::optional<EGLStreamKHR> stream;
};

DisplayProvider::DisplayProvider(EGLDisplay dpy, std::optional<EGLStreamKHR> stream)
DisplayProviderImpl::DisplayProviderImpl(EGLDisplay dpy, std::optional<EGLStreamKHR> stream)
: dpy{dpy},
stream{stream}
{
}

auto DisplayProvider::get_egl_display() const -> EGLDisplay
auto DisplayProviderImpl::get_egl_display() const -> EGLDisplay
{
return dpy;
}

auto DisplayProvider::claim_stream() -> EGLStreamKHR
auto DisplayProviderImpl::claim_stream() -> EGLStreamKHR
{
if (stream)
{
Expand All @@ -74,12 +74,12 @@ mg::eglstream::InterfaceProvider::InterfaceProvider(InterfaceProvider const& fro
{
}

auto mg::eglstream::InterfaceProvider::maybe_create_interface(DisplayInterfaceBase::Tag const& tag)
-> std::shared_ptr<DisplayInterfaceBase>
auto mg::eglstream::InterfaceProvider::maybe_create_interface(DisplayProvider::Tag const& tag)
-> std::shared_ptr<DisplayProvider>
{
if (dynamic_cast<EGLStreamDisplayProvider::Tag const*>(&tag))
{
return std::make_shared<DisplayProvider>(dpy, stream);
return std::make_shared<DisplayProviderImpl>(dpy, stream);
}
if (dynamic_cast<mg::CPUAddressableDisplayProvider::Tag const*>(&tag))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class InterfaceProvider : public DisplayInterfaceProvider
InterfaceProvider(InterfaceProvider const& from, EGLStreamKHR with_stream);

protected:
auto maybe_create_interface(DisplayInterfaceBase::Tag const& tag)
-> std::shared_ptr<DisplayInterfaceBase> override;
auto maybe_create_interface(DisplayProvider::Tag const& tag)
-> std::shared_ptr<DisplayProvider> override;

private:
EGLDisplay dpy;
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/eglstream-kms/server/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ mir::UniqueModulePtr<mg::GraphicBufferAllocator> mge::RenderingPlatform::create_
return mir::make_module_ptr<mge::BufferAllocator>(ctx->make_share_context());
}

auto mge::RenderingPlatform::maybe_create_interface(
RendererInterfaceBase::Tag const& type_tag) -> std::shared_ptr<RendererInterfaceBase>
auto mge::RenderingPlatform::maybe_create_provider(
RenderingProvider::Tag const& type_tag) -> std::shared_ptr<RenderingProvider>
{
if (dynamic_cast<graphics::GLRenderingProvider::Tag const*>(&type_tag))
{
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/eglstream-kms/server/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class RenderingPlatform : public graphics::RenderingPlatform
create_buffer_allocator(Display const& output) override;

protected:
auto maybe_create_interface(
RendererInterfaceBase::Tag const& type_tag) -> std::shared_ptr<RendererInterfaceBase> override;
auto maybe_create_provider(
RenderingProvider::Tag const& type_tag) -> std::shared_ptr<RenderingProvider> override;
private:
EGLDisplay const dpy;
std::unique_ptr<renderer::gl::Context> const ctx;
Expand Down
Loading

0 comments on commit 6e64dfc

Please sign in to comment.