Debian Codegraph @

src/LomiriMetrics/overlay_p.h

raw
1 // Copyright © 2016 Canonical Ltd.
2 // Author: Loïc Molinari <[email protected]>
3 //
4 // This file is part of Lomiri UI Toolkit.
5 //
6 // Lomiri UI Toolkit is free software: you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published by the
8 // Free Software Foundation; version 3.
9 //
10 // Lomiri UI Toolkit is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 // for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with Lomiri UI Toolkit. If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef OVERLAY_P_H
19 #define OVERLAY_P_H
20
21 #include <QtCore/QSize>
22
23 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
24 #include <LomiriMetrics-Qt6/events.h>
25 #else
26 #include <LomiriMetrics/events.h>
27 #endif
28 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
29 #include <LomiriMetrics-Qt6/private/bitmaptext_p.h>
30 #else
31 #include <LomiriMetrics/private/bitmaptext_p.h>
32 #endif
33 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
34 #include <LomiriMetrics-Qt6/private/lomirimetricsglobal_p.h>
35 #else
36 #include <LomiriMetrics/private/lomirimetricsglobal_p.h>
37 #endif
38
39 #if !defined QT_NO_DEBUG
40 class QOpenGLContext;
41 #endif
42
43 // Renders an overlay based on various metrics.
44 class LOMIRI_METRICS_PRIVATE_EXPORT Overlay
45 {
46 public:
47 Overlay(const char* text, int windowId);
48 ~Overlay();
49
50 // Allocates/Deletes the OpenGL resources. finalize() is not called at
51 // destruction, it must be explicitly called to free the resources at the
52 // right time in a thread with the same OpenGL context bound than at
53 // initialize().
54 bool initialize();
55 void finalize();
56
57 // Sets the process event.
58 void setProcessEvent(const UMEvent& processEvent);
59
60 // Renders the overlay. Must be called in a thread with the same OpenGL
61 // context bound than at initialize().
62 void render(const UMEvent& frameEvent, const QSize& frameSize);
63
64 private:
65 void updateFrameMetrics(const UMEvent& frameEvent);
66 void updateWindowMetrics(quint32 windowId, const QSize& frameSize);
67 void updateProcessMetrics();
68 int keywordString(int index, char* buffer, int bufferSize);
69 void parseText();
70
71 enum {
72 Initialized = (1 << 0),
73 DirtyText = (1 << 1),
74 DirtyProcessEvent = (1 << 2)
75 };
76
77 static const int maxMetricsPerType = 16;
78
79 void* m_buffer;
80 char* m_parsedText;
81 #if !defined QT_NO_DEBUG
82 QOpenGLContext* m_context;
83 #endif
84 QString m_text;
85 struct {
86 quint16 index;
87 quint16 textIndex;
88 quint8 width;
89 } m_metrics[UMEvent::TypeCount][maxMetricsPerType];
90 quint8 m_metricsSize[UMEvent::TypeCount];
91 BitmapText m_bitmapText;
92 QSize m_frameSize;
93 quint32 m_windowId;
94 quint8 m_flags;
95 alignas(64) UMEvent m_processEvent;
96 };
97
98 #endif // OVERLAY_P_H