Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/dear-imgui/cpp/app/include/xframes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class XFrames {
std::mutex m_commitMutex;
uint64_t m_nativeSequence = 0;
uint64_t m_nativeRevision = 0;
std::atomic<uint64_t> m_visibleRevision{0};
std::unordered_set<int> m_publicationOwnedIds;
std::atomic<bool> m_surfaceQuarantined{false};
std::atomic<bool> m_runtimeDisposed{false};
Expand Down Expand Up @@ -197,6 +198,10 @@ class XFrames {
// Synchronous structural API. uint64 counters use decimal strings on the wire.
xframes::CommitResult ApplyCommit(std::string_view serializedCommit);
json GetCommitState();
// The native revision of the tree that frames show: stored where the revision
// advances, under the visibility locks. An event raised while a frame is built
// belongs to this tree. Safe to read from any thread.
uint64_t VisibleRevision() const { return m_visibleRevision.load(std::memory_order_acquire); }



Expand Down
1 change: 1 addition & 0 deletions packages/dear-imgui/cpp/app/src/xframes_commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ CommitResult XFrames::ApplyCommitOperations(CommitBatch& batch) {
if (!m_frameScheduler.Invalidate(FrameReason::Publication))
throw std::overflow_error("Invalidation generation exhausted during publication");
result.nativeRevision = ++m_nativeRevision;
m_visibleRevision.store(m_nativeRevision, std::memory_order_release);
result.status = "applied";
} catch (const std::exception& error) {
// Quarantine is established under the visibility locks even if
Expand Down
17 changes: 16 additions & 1 deletion packages/dear-imgui/cpp/tests/xframes_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class XFramesTest : public ::testing::Test {
};
}
void Internal(int id, const json& operation) { auto payload = operation.dump(); xf->QueueElementInternalOp(id, payload); }
void SetCounters(uint64_t sequence, uint64_t revision) { xf->m_nativeSequence = sequence; xf->m_nativeRevision = revision; }
void SetCounters(uint64_t sequence, uint64_t revision) {
xf->m_nativeSequence = sequence; xf->m_nativeRevision = revision; xf->m_visibleRevision = revision;
}
bool LastRequestExpired() {
bool expired = false;
auto subscription = rpp::composite_disposable_wrapper::make();
Expand Down Expand Up @@ -317,6 +319,19 @@ TEST_F(XFramesTest, PublicationCompetingWritersCannotOverwriteAStaleTree) {
EXPECT_EQ(xf->GetCommitState()["nativeRevision"], "2");
}

// Events are stamped with the visible revision: the tree every frame drawn since
// the last applied publication shows. It moves only when a publication applies.
TEST_F(XFramesTest, VisibleRevisionFollowsAppliedPublicationsOnly) {
EXPECT_EQ(xf->VisibleRevision(), 0u);
Publish({{0, {1}}, {1, {}}}, {Create(1)});
EXPECT_EQ(xf->VisibleRevision(), 1u);
Reject(Wire({{0, {1}}, {1, {}}}, {Create(1)}), "duplicate_id", 0);
EXPECT_EQ(xf->VisibleRevision(), 1u);
Publish();
EXPECT_EQ(xf->VisibleRevision(), 2u);
EXPECT_EQ(std::to_string(xf->VisibleRevision()), xf->GetCommitState()["nativeRevision"].get<std::string>());
}

// "childLists": "changed" carries only the child lists that changed. An omitted
// list is the previous one; a created node without an assignment has none.
namespace {
Expand Down
Loading