~aleteoryx/muditaos

ref: 37c5c2fcc83cf7382610d8823a5f45e5066be83b muditaos/module-services/service-gui/ServiceGUI.hpp -rw-r--r-- 3.1 KiB
37c5c2fc — Lucjan Bryndza [EGD-5153] Fix errors in generate image script 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
96
97
98
99
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

// module-gui

#include <Common.hpp>
#include <gui/core/Context.hpp>
#include <gui/core/Renderer.hpp>
#include <gui/input/Translator.hpp>
#include <Service/Common.hpp>
#include <Service/Message.hpp>
#include <Service/Service.hpp>

#include <cstdint>
#include <memory>
#include <string>
#include <vector>

namespace gui
{
    class Context;
    class DrawCommand;
} // namespace gui

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::list<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;

        std::unique_ptr<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::MessagePointer 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;

      private:
        sys::MessagePointer handleDrawMessage(sys::Message *message);
        sys::MessagePointer handleGUIRenderingFinished(sys::Message *message);
        sys::MessagePointer handleGUIDisplayReady(sys::Message *message);
    };

} /* namespace sgui */