Lagrange
Loading...
Searching...
No Matches
progress_bridge.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <array>
15#include <atomic>
16#include <cstddef>
17#include <exception>
18#include <functional>
19#include <mutex>
20#include <string>
21
22#include <xatlas/xatlas.h>
23
24namespace lagrange::xatlas::internal {
25
35class ProgressBridge
36{
37public:
38 ProgressBridge(
39 std::function<void(const std::string&, float)> notification_func,
40 const std::atomic_bool* cancel) noexcept;
41
43 void install(::xatlas::Atlas* atlas) noexcept;
44
46 bool was_cancelled() const noexcept { return m_was_cancelled.load(); }
47
49 void rethrow_if_pending();
50
51private:
52 static bool progress_thunk(::xatlas::ProgressCategory category, int progress, void* user_data);
53
54 std::function<void(const std::string&, float)> m_notification_func;
55 const std::atomic_bool* m_cancel;
56 std::atomic_bool m_was_cancelled{false};
57
58 static constexpr size_t kNumCategories = 4;
59 std::array<int, kNumCategories> m_last_progress;
60
61 std::mutex m_callback_mutex;
62 std::exception_ptr m_pending_exception;
63};
64
65} // namespace lagrange::xatlas::internal
void rethrow_if_pending()
Rethrow any exception captured from the user notification callback.
Definition progress_bridge.cpp:62
void install(::xatlas::Atlas *atlas) noexcept
Install on an atlas (no-op if both members are null).
Definition progress_bridge.cpp:55
bool was_cancelled() const noexcept
True if the user requested cancellation, or the bridge cancelled due to a user exception.
Definition progress_bridge.h:46