@geastack/engine 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/node_text.h ADDED
@@ -0,0 +1,84 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+ #include "storage_usage.h"
4
+ #include <cstdint>
5
+ #include <string>
6
+
7
+ namespace gea::embedded::ui
8
+ {
9
+ // Empty nodes own no string storage. Nonempty text lives in stable pooled
10
+ // records, preserving c_str() addresses while other nodes are created/removed.
11
+ // Copies own independent records: retained display commands can scrub one
12
+ // node's old buffer without invalidating a clone's unchanged text.
13
+ class NodeText
14
+ {
15
+ public:
16
+ NodeText() = default;
17
+ NodeText(const NodeText &other);
18
+ NodeText(NodeText &&other) noexcept;
19
+ ~NodeText();
20
+ NodeText &operator=(const NodeText &other);
21
+ NodeText &operator=(NodeText &&other) noexcept;
22
+ NodeText &operator=(const std::string &text)
23
+ {
24
+ assign(text.c_str());
25
+ return *this;
26
+ }
27
+ NodeText &operator=(const char *text)
28
+ {
29
+ assign(text);
30
+ return *this;
31
+ }
32
+ // Pool allocation payload (including spare slots/map), excluding string
33
+ // character buffers and allocator metadata. Useful alongside heap census.
34
+ static std::size_t storageBytes();
35
+ static StorageUsage storageUsage();
36
+ void clear();
37
+ void assign(const char *text);
38
+ bool empty() const { return handle_ == kEmpty; }
39
+ const std::string &str() const;
40
+ operator const std::string &() const { return str(); }
41
+ const char *c_str() const { return str().c_str(); }
42
+ const char *data() const { return c_str(); }
43
+ std::size_t size() const { return str().size(); }
44
+ char operator[](std::size_t i) const { return str()[i]; }
45
+ std::size_t find(char c) const { return str().find(c); }
46
+ std::size_t find_first_not_of(const char *chars) const
47
+ {
48
+ return str().find_first_not_of(chars);
49
+ }
50
+ std::string substr(std::size_t pos,
51
+ std::size_t count = std::string::npos) const
52
+ {
53
+ return str().substr(pos, count);
54
+ }
55
+ friend bool operator==(const NodeText &a, const NodeText &b)
56
+ {
57
+ return a.str() == b.str();
58
+ }
59
+ friend bool operator==(const NodeText &a, const std::string &b)
60
+ {
61
+ return a.str() == b;
62
+ }
63
+ friend bool operator==(const NodeText &a, const char *b)
64
+ {
65
+ return a.str() == b;
66
+ }
67
+ friend bool operator!=(const NodeText &a, const NodeText &b)
68
+ {
69
+ return !(a == b);
70
+ }
71
+ friend bool operator!=(const NodeText &a, const std::string &b)
72
+ {
73
+ return !(a == b);
74
+ }
75
+ friend bool operator!=(const NodeText &a, const char *b)
76
+ {
77
+ return !(a == b);
78
+ }
79
+
80
+ private:
81
+ static constexpr std::uint32_t kEmpty = UINT32_MAX;
82
+ std::uint32_t handle_ = kEmpty;
83
+ };
84
+ } // namespace gea::embedded::ui
package/ui/refresh_perf.h CHANGED
@@ -112,6 +112,11 @@ struct RefreshPerfStats {
112
112
  int treeScopedRejectNode = -1;
113
113
  int treeLayoutRepositionCalls = 0;
114
114
  std::int64_t treeLayoutTextUs = 0;
115
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
116
+ // Deterministic work budgets for animation regressions; absent with perf off.
117
+ int treeIntegerPositionFastCalls = 0;
118
+ int treeTranslateClipChecks = 0;
119
+ #endif
115
120
  int treeSetStyleCalls = 0;
116
121
  int treeSetStyleChanged = 0;
117
122
  int treeSetStyleNoop = 0;
@@ -125,6 +130,8 @@ struct RefreshPerfStats {
125
130
  int treeMarkDisplayListDirtyCalls = 0;
126
131
  int treeMarkDisplayListContentDirtyCalls = 0;
127
132
  int treeMarkNodeCommandDirtyCalls = 0;
133
+ int treeAbsContainingAreaCalls = 0;
134
+ int treeAbsContainingAreaHits = 0;
128
135
  int treeAbsModeCalls = 0;
129
136
  int treeAbsModeFast = 0;
130
137
  int treeAbsModeFull = 0;
@@ -201,35 +208,30 @@ inline std::int64_t refreshPerfNowUs()
201
208
  #endif
202
209
  }
203
210
 
211
+ // Diagnostic writes must be compiled out, not redirected to a throwaway object:
212
+ // the latter still performs loads/stores in every style update and replay scan.
213
+ // A statement macro preserves surrounding if/else binding and does not evaluate
214
+ // its arguments when profiling is off.
215
+ #define GEA_REFRESH_PERF(...) \
216
+ do { if constexpr (GEA_EMBEDDED_UI_REFRESH_PERF) { __VA_ARGS__; } } while (false)
217
+
204
218
  inline RefreshPerfStats &refreshPerfStatsMutable()
205
219
  {
206
- #if GEA_EMBEDDED_UI_REFRESH_PERF
207
220
  return gRefreshPerfStats;
208
- #else
209
- // Perf off: the timer-derived `… += refreshPerfNowUs() - start` writes already
210
- // fold to `+= 0` (refreshPerfNowUs() returns 0), and the ScopedRefreshStat
211
- // guards optimize away. The few remaining bare counters in tree_render/render
212
- // (`treePanReplayCalls++`, `treePanRepaintArea += …`) are routed to a throwaway
213
- // that nothing reads, so they never touch live state.
214
- #if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
215
- // On the heap, not static: the -1 sentinels make the throwaway a .data
216
- // object (see state_init.h).
217
- static RefreshPerfStats &discard = *new RefreshPerfStats();
218
- #else
219
- static RefreshPerfStats discard;
220
- #endif
221
- return discard;
222
- #endif
223
221
  }
224
222
 
225
223
  inline void refreshPerfStatsReset()
226
224
  {
227
- gRefreshPerfStats = {};
225
+ GEA_REFRESH_PERF(gRefreshPerfStats = {});
228
226
  }
229
227
 
230
228
  inline RefreshPerfStats refreshPerfStatsRead()
231
229
  {
230
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
232
231
  return gRefreshPerfStats;
232
+ #else
233
+ return {};
234
+ #endif
233
235
  }
234
236
 
235
237
  } // namespace gea::embedded::ui