-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
experiment: providing a gateway for writing your own renderer through MirAL #3338
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3338 +/- ##
==========================================
- Coverage 77.33% 77.33% -0.01%
==========================================
Files 1062 1063 +1
Lines 67817 67826 +9
==========================================
+ Hits 52449 52451 +2
- Misses 15368 15375 +7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd tweak the MirAL API slightly to be more consistent with other MirAL APIs, but I don't think there's anything problematic about the semantics.
However, my question is whether it is possible to implement the CustomRender::Builder
with the APIs we make available? (I suspect that might need "internal" APIs)
class RendererFactory; | ||
namespace gl | ||
{ | ||
class RenderTarget; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class RendererFactory; | |
namespace gl | |
{ | |
class RenderTarget; | |
} | |
} | |
} | |
} | |
} |
typedef std::function<std::unique_ptr<mir::renderer::Renderer> | ||
(std::unique_ptr<mir::graphics::gl::OutputSurface>, | ||
std::shared_ptr<mir::graphics::GLRenderingProvider>)> CreateRenderer; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef std::function<std::unique_ptr<mir::renderer::Renderer> | |
(std::unique_ptr<mir::graphics::gl::OutputSurface>, | |
std::shared_ptr<mir::graphics::GLRenderingProvider>)> CreateRenderer; |
class CustomRenderer | ||
{ | ||
public: | ||
explicit CustomRenderer(CreateRenderer const& renderer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit CustomRenderer(CreateRenderer const& renderer); | |
using Builder = std::function< | |
std::unique_ptr<mir::renderer::Renderer>( | |
std::unique_ptr<mir::graphics::gl::OutputSurface>, std::shared_ptr<mir::graphics::GLRenderingProvider>) | |
>; | |
explicit CustomRenderer(Builder&& renderer); |
explicit CustomRenderer(CreateRenderer const& renderer); | ||
void operator()(mir::Server& server) const; | ||
private: | ||
std::shared_ptr<mir::renderer::RendererFactory> factory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr<mir::renderer::RendererFactory> factory; | |
struct Self; | |
std::shared_ptr<Self> self; |
I was able to copy over the entire GL renderer into It is a really rough copy, but I only required |
b90d9d5
to
48789f6
Compare
48789f6
to
2191081
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think miral::CustomRenderer
should do one thing, not two
std::unique_ptr<mir::graphics::gl::OutputSurface>, std::shared_ptr<mir::graphics::GLRenderingProvider>) | ||
>; | ||
|
||
CustomRenderer(Builder&& renderer, std::shared_ptr<mir::graphics::GLConfig> const&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we passing a GLConfig here?
There is prior art in miroil::OpenGLContext
for doing this independently and that seems like a more flexible approach.
If we don't want to add a dependency on MirOil, then a miral::CustomGLContext
seems like a cleaner approach. (What happens when there is another feature that wants to override the GL config?)
src/miral/custom_renderer.cpp
Outdated
} | ||
|
||
private: | ||
miral::CustomRenderer::Builder const& renderer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this really be a reference?
src/miral/custom_renderer.cpp
Outdated
|
||
struct miral::CustomRenderer::Self | ||
{ | ||
Self(Builder const& renderer, std::shared_ptr<mir::graphics::GLConfig> const& config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self(Builder const& renderer, std::shared_ptr<mir::graphics::GLConfig> const& config) | |
Self(Builder&& renderer, std::shared_ptr<mir::graphics::GLConfig> const& config) |
src/miral/custom_renderer.cpp
Outdated
|
||
miral::CustomRenderer::CustomRenderer( | ||
Builder&& renderer, std::shared_ptr<mir::graphics::GLConfig> const& config) | ||
: self{std::make_shared<Self>(renderer, config)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: self{std::make_shared<Self>(renderer, config)} | |
: self{std::make_shared<Self>(std::move(renderer), config)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the code could be a little clearer. But otherwise fine.
(Approving, but not merging to allow tweak)
src/miral/custom_renderer.cpp
Outdated
struct miral::CustomRenderer::Self | ||
{ | ||
explicit Self(Builder&& renderer) | ||
: factory(std::make_shared<RendererFactory>(std::move(renderer))) | ||
{ | ||
} | ||
|
||
std::shared_ptr<mir::renderer::RendererFactory> factory; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be simpler (fewer classes, less forwarding code) if miral::CustomRenderer::Self
IsA mir::renderer::RendererFactory
, not HasA. Vis:
struct miral::CustomRenderer::Self | |
{ | |
explicit Self(Builder&& renderer) | |
: factory(std::make_shared<RendererFactory>(std::move(renderer))) | |
{ | |
} | |
std::shared_ptr<mir::renderer::RendererFactory> factory; | |
}; | |
struct miral::CustomRenderer::Self : public mir::renderer::RendererFactory | |
{ | |
explicit Self(Builder&& renderer) | |
: factory(std::move(renderer)) | |
{ | |
} | |
[[nodiscard]] auto create_renderer_for( | |
std::unique_ptr<mir::graphics::gl::OutputSurface> output_surface, | |
std::shared_ptr<mir::graphics::GLRenderingProvider> gl_provider) const | |
-> std::unique_ptr<mir::renderer::Renderer> override | |
{ | |
return renderer(std::move(output_surface), std::move(gl_provider)); | |
} | |
private: | |
miral::CustomRenderer::Builder const renderer; | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, Self::factory
should be const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that change!
Signed-off-by: Matthew Kosarek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More nits
Co-authored-by: Alan Griffiths <[email protected]>
Co-authored-by: Alan Griffiths <[email protected]>
WARNING: Highly experimental, but it works
What's new?
CustomRenderer
tomiral
which gives them the rites to entirely replace the existing renderer