Files
MuditaOS/module-services/service-gui/WorkerGUI.cpp
Mateusz Piesta 97e9d7b79f [BH-1449] Fix gui/eink dependencies
* Dependencies between service-gui and service-eink
have been correctly defined.
* System close routine was replaced with the sequential one
which should solve many bell issues.
* It also fixes BH-1406 and BH-1442.
* Fixed some weird CMake issues in module-audio and
several other modules.
* Fixed service-gui closing routine
* Removed unneeded messages/states from service-gui/eink.
* Enhanced app-mgr closing routine. Fixed closing action handling.
2022-04-26 13:47:12 +02:00

71 lines
2.2 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "WorkerGUI.hpp"
#include <DrawCommand.hpp>
#include <log/log.hpp>
#include <Service/Worker.hpp>
#include <service-gui/ServiceGUI.hpp>
#include <memory>
#include "messages/RenderingFinished.hpp"
namespace service::gui
{
WorkerGUI::WorkerGUI(ServiceGUI *service) : Worker(service), guiService{service}
{}
void WorkerGUI::notify(Signal command)
{
if (auto queue = getQueueByName(SignallingQueueName); !queue->Overwrite(&command)) {
LOG_ERROR("Unable to overwrite the command in the commands queue.");
}
}
bool WorkerGUI::handleMessage(uint32_t queueID)
{
if (const auto queue = queues[queueID]; queue->GetQueueName() == SignallingQueueName) {
if (sys::WorkerCommand command; queue->Dequeue(&command, 0)) {
handleCommand(static_cast<Signal>(command.command));
}
}
return true;
}
void WorkerGUI::handleCommand(Signal command)
{
switch (command) {
case Signal::Render: {
auto item = guiService->commandsQueue->dequeue();
render(item.commands, item.refreshMode);
break;
}
case Signal::ChangeColorScheme: {
changeColorScheme(guiService->colorSchemeUpdate);
break;
}
default:
LOG_ERROR("Command not valid.");
}
}
void WorkerGUI::render(DrawCommandsQueue::CommandList &commands, ::gui::RefreshModes refreshMode)
{
const auto [contextId, context] = guiService->contextPool->borrowContext(); // Waits for the context.
renderer.render(context, commands);
onRenderingFinished(contextId, refreshMode);
}
void WorkerGUI::changeColorScheme(const std::unique_ptr<::gui::ColorScheme> &scheme)
{
renderer.changeColorScheme(scheme);
}
void WorkerGUI::onRenderingFinished(int contextId, ::gui::RefreshModes refreshMode)
{
auto msg = std::make_shared<service::gui::RenderingFinished>(contextId, refreshMode);
guiService->bus.sendUnicast(std::move(msg), guiService->GetName());
}
} // namespace service::gui