Skip to content

Commit

Permalink
feature: provide surface access via the Renderable (#3355)
Browse files Browse the repository at this point in the history
Alternative to #3349

## What's new?
- Now you can access the `Surface` via the `Renderable`
  • Loading branch information
RAOF authored May 2, 2024
2 parents 3645760 + 4b3450a commit 4113d1d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 4 deletions.
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;
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

0 comments on commit 4113d1d

Please sign in to comment.