~aleteoryx/muditaos

ref: ac2c954d93e63b0218a2234d565133bba878a966 muditaos/module-services/service-gui/WorkerGUI.cpp -rw-r--r-- 2.0 KiB
ac2c954d — Bartosz Cichocki [EGD-3772] added HSP sink and source (#918) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2017-2020, 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 <MessageType.hpp>
#include <projdefs.h>
#include <queue.h>
#include <Renderer.hpp>
#include <semphr.h>
#include <Service/Bus.hpp>
#include <Service/Message.hpp>
#include <Service/Service.hpp>
#include <Service/Worker.hpp>
#include <service-gui/ServiceGUI.hpp>

#include <memory>
#include <utility>
#include <vector>

namespace sgui
{

    WorkerGUI::WorkerGUI(ServiceGUI *service) : Worker(service)
    {}

    bool WorkerGUI::handleMessage(uint32_t queueID)
    {
        QueueHandle_t queue = queues[queueID];

        sgui::ServiceGUI *serviceGUI = reinterpret_cast<sgui::ServiceGUI *>(service);

        // queue for receiving rendering commands
        if (queueID == 0) {
            //		LOG_INFO("Received rendering commands");

            sys::WorkerCommand received;
            xQueueReceive(queue, &received, 0);

            // take all unique pointers
            std::list<std::unique_ptr<gui::DrawCommand>> uniqueCommands;

            if (xSemaphoreTake(serviceGUI->semCommands, pdMS_TO_TICKS(1000)) == pdTRUE) {
                uniqueCommands = std::move(serviceGUI->commands);
                xSemaphoreGive(serviceGUI->semCommands);
            }
            else {
                LOG_ERROR("Failed to acquire semaphore");
            }

            //		uint32_t start_tick = xTaskGetTickCount();
            serviceGUI->renderer.render(serviceGUI->renderContext, uniqueCommands);
            //		uint32_t end_tick = xTaskGetTickCount();
            //		LOG_INFO("[WorkerGUI] RenderingTime: %d", end_tick - start_tick);


            // notify gui service that rendering is complete
            auto message = std::make_shared<sys::DataMessage>(MessageType::GUIRenderingFinished);
            sys::Bus::SendUnicast(message, this->service->GetName(), this->service);
        }
        return true;
    }

} /* namespace sgui */