Skip to content
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

feature: provide surface access via the Renderable #3355

Merged
merged 1 commit into from
May 2, 2024

Conversation

mattkae
Copy link
Contributor

@mattkae mattkae commented Apr 26, 2024

Alternative to #3349

What's new?

  • Now you can access the Surface via the Renderable

@mattkae mattkae requested a review from a team as a code owner April 26, 2024 19:24
@mattkae mattkae requested a review from AlanGriffiths April 26, 2024 19:25
@RAOF
Copy link
Contributor

RAOF commented Apr 29, 2024

So, I'm torn on this whole enterprise.

On one hand, this is the wrong spot to do this. Particularly, there's no guarantee that the compositor is actually going to call your Renderer; the MultiThreadedCompositor only calls into the renderer when it hasn't been able to place everything on a hardware plane¹.

On the other hand, even the Compositor only has access to a list of SceneElements, which doesn't include what you're after anyway.

On the third hand, the eternal scenegraph discussion. 🤷‍♀️

¹: Which, to be fair, it won't be able to at the moment, as that's not properly implemented.

@@ -69,6 +72,9 @@ class Renderable
virtual glm::mat4 transformation() const = 0;

virtual bool shaped() const = 0; // meaning the pixel format has alpha

virtual auto surface_if_any() const
-> std::optional<mir::scene::Surface const*> = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::optional<pointer const*> is not super different to plain pointer const*; I could go either way on this; we should probably have an actual style guide decision on this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long as we adhere to the Core Guidelines:

R.2: In interfaces, use raw pointers to denote individual objects (only)
R.3: A raw pointer (a T*) is non-owning

I'm also fine with a named Foo cont* provided that there's a clear indication (like _if_any) when nullptr is possible.

For reference, Sophie was keen on std::optional<>, so there's some of that around the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like std::optional personally because it shows intent. We don't null-check every shared_ptr in the repo, so I would assume that when we're accessing any pointer, we can assume that it is probably set.

@RAOF
Copy link
Contributor

RAOF commented Apr 29, 2024

To be clear: this seems like a pragmatic solution to get something working; we've not prioritised getting a nice API for this so waiting for that is unreasonable.

Copy link
Collaborator

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are not problems in this code, but thinking on the usecase you mention...

Keeping pointer values in any sort of lookup needs care: a pointer is only valid until the memory it references is deallocated (typically part of deleting the referenced object). After that just accessing (not dereferencing) the pointer is undefined behaviour.

(Not merging pending discussion on std::optional<>)

auto surface_if_any() const
-> std::optional<mir::scene::Surface const*> override
{
return {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {};
return std::nullopt;

@mattkae
Copy link
Contributor Author

mattkae commented Apr 29, 2024

So, I'm torn on this whole enterprise.

On one hand, this is the wrong spot to do this. Particularly, there's no guarantee that the compositor is actually going to call your Renderer; the MultiThreadedCompositor only calls into the renderer when it hasn't been able to place everything on a hardware plane¹.

I was not aware that we wanted to do this! Would this mean that instead of going through the GL renderer, surfaces (somehow) just get blipped onto a hardware plane?

On the other hand, even the Compositor only has access to a list of SceneElements, which doesn't include what you're after anyway.

👍

On the third hand, the eternal scenegraph discussion. 🤷‍♀️

Yeah this might be the better solution, but I am afraid I would wait around a while for it, huh?

@mattkae mattkae force-pushed the feature/surface_access_in_renderer branch from 8eb9382 to 4b3450a Compare April 29, 2024 19:04
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 18.75000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 77.33%. Comparing base (25ade62) to head (4b3450a).

Files Patch % Lines
src/server/graphics/software_cursor.cpp 0.00% 2 Missing ⚠️
src/server/input/touchspot_controller.cpp 0.00% 2 Missing ⚠️
src/server/scene/basic_surface.cpp 60.00% 2 Missing ⚠️
src/server/shell/basic_idle_handler.cpp 0.00% 2 Missing ⚠️
tests/include/mir/test/doubles/fake_renderable.h 0.00% 2 Missing ⚠️
tests/include/mir/test/doubles/stub_renderable.h 0.00% 2 Missing ⚠️
tests/include/mir/test/doubles/mock_renderable.h 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3355      +/-   ##
==========================================
- Coverage   77.36%   77.33%   -0.04%     
==========================================
  Files        1075     1065      -10     
  Lines       68268    67883     -385     
==========================================
- Hits        52813    52494     -319     
+ Misses      15455    15389      -66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattkae
Copy link
Contributor Author

mattkae commented Apr 29, 2024

There are not problems in this code, but thinking on the usecase you mention...

Keeping pointer values in any sort of lookup needs care: a pointer is only valid until the memory it references is deallocated (typically part of deleting the referenced object). After that just accessing (not dereferencing) the pointer is undefined behaviour.

(Not merging pending discussion on std::optional<>)

For my use case, I won't be storing these references, but rather using them when they come to me to resolve back to the Window and its userdata. The pointer won't be invalidated by the time the render happens, so I should be okay on that front

@mattkae mattkae requested a review from RAOF April 30, 2024 14:09
Copy link
Contributor

@RAOF RAOF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. As I say, a pragmatic hack!

@RAOF RAOF added this pull request to the merge queue May 2, 2024
Merged via the queue into main with commit 4113d1d May 2, 2024
22 of 25 checks passed
@RAOF RAOF deleted the feature/surface_access_in_renderer branch May 2, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants