~aleteoryx/muditaos

ref: 2276ceed679b93a3a891e4f5739ade9e13991c5a muditaos/module-services/service-gui/ServiceGUI.hpp -rw-r--r-- 2.9 KiB
2276ceed — Radoslaw Wicik [EGD-3743] Update copyrights in fies 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * ServiceGUI.hpp
 *
 *  Created on: 22 maj 2019
 *      Author: robert
 */

#ifndef MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_
#define MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_

#include <memory>

// module-gui
#include "gui/core/Context.hpp"
#include "gui/core/Renderer.hpp"
#include "gui/input/Translator.hpp"
#include "messages/DrawMessage.hpp"

#include "Service/Service.hpp"
#include "Service/Message.hpp"
#include "WorkerGUI.hpp"

namespace sgui
{

    class WorkerGUI;

    class ServiceGUI : public sys::Service
    {
        friend WorkerGUI;

      protected:
        // this is where every incomming frame is painted.
        gui::Context *renderContext;
        // this buffer is provided to eink
        gui::Context *transferContext;
        // ID of the last rendered frame
        uint32_t renderFrameCounter;
        // ID of the last frame sent to eink for rendering
        uint32_t transferedFrameCounter;
        // Horizontal size of the screen in pixels
        uint32_t screenWidth;
        // vertical size of the screen in pixels
        uint32_t screenHeight;
        // object responsible for rendering images to context
        gui::Renderer renderer;
        // flag that defines whether eink is ready for new frame buffer
        volatile bool einkReady   = false;
        volatile bool requestSent = false;
        volatile bool rendering   = false;
        // set of commands recently received. If this vector is not empty and new set of commands is received
        // previous commands are removed.
        std::vector<std::unique_ptr<gui::DrawCommand>> commands;
        //	uint32_t timer_id= 0;
        gui::RefreshModes mode = gui::RefreshModes::GUI_REFRESH_DEEP;

        // semaphore used to protect commands vector while commands are taken from service to worker.
        SemaphoreHandle_t semCommands;

        WorkerGUI *worker;

        /**
         * Flag controls process of redrawing screen when suspend is in progress.
         */
        bool suspendInProgress = false;
        /**
         * Flag controls process of redrawing screen when phone is shutting down.
         */
        bool shutdownInProgress = false;

        void sendBuffer();
        void sendToRender();

      public:
        ServiceGUI(const std::string &name,
                   std::string parent    = "",
                   uint32_t screenWidth  = 480,
                   uint32_t screenHeight = 600);
        ~ServiceGUI();

        sys::Message_t DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;

        sys::ReturnCodes InitHandler() override;

        sys::ReturnCodes DeinitHandler() override;

        sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final;
    };

} /* namespace sgui */

#endif /* MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_ */