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

graphics/MultiplexingDisplay: Add HW cursor support. #3206

Merged
merged 1 commit into from
Feb 16, 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
2 changes: 2 additions & 0 deletions src/server/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_library(
platform_probe.h
multiplexing_display.h
multiplexing_display.cpp
multiplexing_hw_cursor.h
multiplexing_hw_cursor.cpp
)

target_link_libraries(mirgraphics
Expand Down
21 changes: 20 additions & 1 deletion src/server/graphics/multiplexing_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/

#include "multiplexing_display.h"
#include "multiplexing_hw_cursor.h"
#include "mir/graphics/display_configuration.h"
#include "mir/renderer/gl/context.h"
#include "mir/output_type_names.h"
#include "mir/log.h"

#include <boost/throw_exception.hpp>
#include <exception>
#include <stdexcept>
#include <sstream>
#include <functional>
Expand Down Expand Up @@ -319,5 +322,21 @@ void mg::MultiplexingDisplay::resume()

auto mg::MultiplexingDisplay::create_hardware_cursor() -> std::shared_ptr<Cursor>
{
return {};
std::vector<Display*> platform_displays;
for (auto& display : displays)
{
platform_displays.push_back(display.get());
}
try
{
return std::make_shared<MultiplexingCursor>(platform_displays);
}
catch (std::exception const&)
{
mir::log(
mir::logging::Severity::informational,
"display",
"Failed to create hardware cursor");
return nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure why, but I prefer default constructing a shared_ptr<...> (original code) to implicitly constructing it with nullptr.

}
}
68 changes: 68 additions & 0 deletions src/server/graphics/multiplexing_hw_cursor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "multiplexing_hw_cursor.h"

#include "mir/graphics/display.h"
#include <boost/throw_exception.hpp>

namespace mg = mir::graphics;

namespace
{
auto construct_platform_cursors(std::span<mg::Display*> platform_displays) -> std::vector<std::shared_ptr<mg::Cursor>>
{
std::vector<std::shared_ptr<mg::Cursor>> cursors;
for (auto display : platform_displays)
{
cursors.push_back(display->create_hardware_cursor());
if (cursors.back() == nullptr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

operator!() seems more idiomatic operator==(T*)

{
BOOST_THROW_EXCEPTION((std::runtime_error{"Platform failed to create hardware cursor"}));
}
Comment on lines +31 to +35
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not a problem here, but thinking forward: this means that when adding a virtual display we offer different behaviour. (Obviously, fixing that would need something more complex than "hardware cursor" xor "software cursor")

}
return cursors;
}
}

mg::MultiplexingCursor::MultiplexingCursor(std::span<Display*> platform_displays)
: platform_cursors{construct_platform_cursors(platform_displays)}
{
}

void mg::MultiplexingCursor::show(CursorImage const& image)
{
for (auto& cursor : platform_cursors)
{
cursor->show(image);
}
}

void mg::MultiplexingCursor::hide()
{
for (auto& cursor: platform_cursors)
{
cursor->hide();
}
}

void mg::MultiplexingCursor::move_to(geometry::Point position)
{
for (auto& cursor : platform_cursors)
{
cursor->move_to(position);
}
}
38 changes: 38 additions & 0 deletions src/server/graphics/multiplexing_hw_cursor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <vector>
#include <span>

#include "mir/graphics/cursor.h"

namespace mir::graphics
{
class Display;

class MultiplexingCursor : public Cursor
{
public:
explicit MultiplexingCursor(std::span<Display*> platform_displays);

void show(CursorImage const& image) override;
void hide() override;
void move_to(geometry::Point position) override;

private:
std::vector<std::shared_ptr<Cursor>> const platform_cursors;
};
}
Loading