diff --git a/include/platform/mir/graphics/renderable.h b/include/platform/mir/graphics/renderable.h index 6040f6f5225..7cd9fb06bd7 100644 --- a/include/platform/mir/graphics/renderable.h +++ b/include/platform/mir/graphics/renderable.h @@ -25,6 +25,9 @@ namespace mir { + +namespace scene { class Surface; } + namespace graphics { @@ -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 = 0; protected: Renderable() = default; Renderable(Renderable const&) = delete; diff --git a/src/server/graphics/software_cursor.cpp b/src/server/graphics/software_cursor.cpp index 7d3d6fad989..a901d5d1e42 100644 --- a/src/server/graphics/software_cursor.cpp +++ b/src/server/graphics/software_cursor.cpp @@ -100,6 +100,12 @@ class mg::detail::CursorRenderable : public mg::Renderable return true; } + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } + void move_to(geom::Point new_position) { std::lock_guard lock{position_mutex}; diff --git a/src/server/input/touchspot_controller.cpp b/src/server/input/touchspot_controller.cpp index b74d932db06..68eade869a9 100644 --- a/src/server/input/touchspot_controller.cpp +++ b/src/server/input/touchspot_controller.cpp @@ -83,7 +83,13 @@ class mi::TouchspotRenderable : public mg::Renderable return true; } -// TouchspotRenderable + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } + + // TouchspotRenderable void move_center_to(geom::Point pos) { std::lock_guard lg(guard); diff --git a/src/server/scene/basic_surface.cpp b/src/server/scene/basic_surface.cpp index a65cbecd09f..f56e065c598 100644 --- a/src/server/scene/basic_surface.cpp +++ b/src/server/scene/basic_surface.cpp @@ -697,14 +697,16 @@ class SurfaceSnapshot : public mg::Renderable std::optional 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} { } @@ -736,6 +738,11 @@ class SurfaceSnapshot : public mg::Renderable mg::Renderable::ID id() const override { return id_; } + + auto surface_if_any() const -> std::optional override + { + return surface; + } private: std::shared_ptr const underlying_buffer_stream; std::shared_ptr mutable compositor_buffer; @@ -745,6 +752,7 @@ class SurfaceSnapshot : public mg::Renderable std::optional const clip_area_; glm::mat4 const transformation_; mg::Renderable::ID const id_; + ms::Surface const* surface; }; } @@ -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; diff --git a/src/server/shell/basic_idle_handler.cpp b/src/server/shell/basic_idle_handler.cpp index dcc3d3b6a59..13f106ba56a 100644 --- a/src/server/shell/basic_idle_handler.cpp +++ b/src/server/shell/basic_idle_handler.cpp @@ -85,6 +85,12 @@ struct DimmingRenderable : public mg::Renderable return false; } + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } + private: std::shared_ptr const buffer_; }; diff --git a/tests/include/mir/test/doubles/fake_renderable.h b/tests/include/mir/test/doubles/fake_renderable.h index a9ead20ac62..232e40d884e 100644 --- a/tests/include/mir/test/doubles/fake_renderable.h +++ b/tests/include/mir/test/doubles/fake_renderable.h @@ -98,6 +98,12 @@ class FakeRenderable : public graphics::Renderable return std::optional(); } + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } + private: std::shared_ptr buf; mir::geometry::Rectangle rect; diff --git a/tests/include/mir/test/doubles/mock_renderable.h b/tests/include/mir/test/doubles/mock_renderable.h index 53ba4032fb2..0e3b667c29e 100644 --- a/tests/include/mir/test/doubles/mock_renderable.h +++ b/tests/include/mir/test/doubles/mock_renderable.h @@ -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()); }; } } diff --git a/tests/include/mir/test/doubles/stub_renderable.h b/tests/include/mir/test/doubles/stub_renderable.h index b7c43a94b0a..f8ead8e46aa 100644 --- a/tests/include/mir/test/doubles/stub_renderable.h +++ b/tests/include/mir/test/doubles/stub_renderable.h @@ -88,6 +88,12 @@ class StubRenderable : public graphics::Renderable { return false; } + + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } private: std::shared_ptr make_stub_buffer(geometry::Rectangle const& rect) { diff --git a/tests/platform_test_harness/graphics_platform_test_harness.cpp b/tests/platform_test_harness/graphics_platform_test_harness.cpp index fa4601bc8c9..ffb23f9d17a 100644 --- a/tests/platform_test_harness/graphics_platform_test_harness.cpp +++ b/tests/platform_test_harness/graphics_platform_test_harness.cpp @@ -450,6 +450,12 @@ void basic_software_buffer_drawing( { this->top_left = top_left; } + + auto surface_if_any() const + -> std::optional override + { + return std::nullopt; + } private: std::shared_ptr const buffer_; mir::geometry::Point top_left;