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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/platform/mir/graphics/renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace mir
{

namespace scene { class Surface; }

namespace graphics
{

Expand Down Expand Up @@ -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.

protected:
Renderable() = default;
Renderable(Renderable const&) = delete;
Expand Down
6 changes: 6 additions & 0 deletions src/server/graphics/software_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class mg::detail::CursorRenderable : public mg::Renderable
return true;
}

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

void move_to(geom::Point new_position)
{
std::lock_guard lock{position_mutex};
Expand Down
8 changes: 7 additions & 1 deletion src/server/input/touchspot_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ class mi::TouchspotRenderable : public mg::Renderable
return true;
}

// TouchspotRenderable
auto surface_if_any() const
-> std::optional<mir::scene::Surface const*> override
{
return std::nullopt;
}

// TouchspotRenderable
void move_center_to(geom::Point pos)
{
std::lock_guard lg(guard);
Expand Down
14 changes: 11 additions & 3 deletions src/server/scene/basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,16 @@ class SurfaceSnapshot : public mg::Renderable
std::optional<geom::Rectangle> const& clip_area,
glm::mat4 const& transform,
float alpha,
mg::Renderable::ID id)
mg::Renderable::ID id,
ms::Surface const* surface)
: underlying_buffer_stream{stream},
compositor_id{compositor_id},
alpha_{alpha},
screen_position_(position),
clip_area_(clip_area),
transformation_(transform),
id_(id)
id_(id),
surface{surface}
{
}

Expand Down Expand Up @@ -736,6 +738,11 @@ class SurfaceSnapshot : public mg::Renderable

mg::Renderable::ID id() const override
{ return id_; }

auto surface_if_any() const -> std::optional<mir::scene::Surface const*> override
{
return surface;
}
private:
std::shared_ptr<mc::BufferStream> const underlying_buffer_stream;
std::shared_ptr<mg::Buffer> mutable compositor_buffer;
Expand All @@ -745,6 +752,7 @@ class SurfaceSnapshot : public mg::Renderable
std::optional<geom::Rectangle> const clip_area_;
glm::mat4 const transformation_;
mg::Renderable::ID const id_;
ms::Surface const* surface;
};
}

Expand Down Expand Up @@ -806,7 +814,7 @@ mg::RenderableList ms::BasicSurface::generate_renderables(mc::CompositorID id) c
info.stream, id,
geom::Rectangle{content_top_left_ + info.displacement, std::move(size)},
state->clip_area,
state->transformation_matrix, state->surface_alpha, info.stream.get()));
state->transformation_matrix, state->surface_alpha, info.stream.get(), this));
}
}
return list;
Expand Down
6 changes: 6 additions & 0 deletions src/server/shell/basic_idle_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ struct DimmingRenderable : public mg::Renderable
return false;
}

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

private:
std::shared_ptr<mg::Buffer> const buffer_;
};
Expand Down
6 changes: 6 additions & 0 deletions tests/include/mir/test/doubles/fake_renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class FakeRenderable : public graphics::Renderable
return std::optional<geometry::Rectangle>();
}

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

private:
std::shared_ptr<graphics::Buffer> buf;
mir::geometry::Rectangle rect;
Expand Down
1 change: 1 addition & 0 deletions tests/include/mir/test/doubles/mock_renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct MockRenderable : public graphics::Renderable
MOCK_CONST_METHOD0(transformation, glm::mat4());
MOCK_CONST_METHOD0(visible, bool());
MOCK_CONST_METHOD0(shaped, bool());
MOCK_CONST_METHOD0(surface_if_any, std::optional<mir::scene::Surface const*>());
};
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/include/mir/test/doubles/stub_renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class StubRenderable : public graphics::Renderable
{
return false;
}

auto surface_if_any() const
-> std::optional<mir::scene::Surface const*> override
{
return std::nullopt;
}
private:
std::shared_ptr<graphics::Buffer> make_stub_buffer(geometry::Rectangle const& rect)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ void basic_software_buffer_drawing(
{
this->top_left = top_left;
}

auto surface_if_any() const
-> std::optional<mir::scene::Surface const*> override
{
return std::nullopt;
}
private:
std::shared_ptr<mg::Buffer> const buffer_;
mir::geometry::Point top_left;
Expand Down
Loading