performance 复制按钮
This commit is contained in:
@@ -152,6 +152,25 @@ static std::function<void()> performance_update_callback(const std::shared_ptr<P
|
||||
std::lock_guard<std::mutex> lock(ctx->performance_update_callback_mutex);
|
||||
return ctx->performance_update_callback;
|
||||
}
|
||||
static std::function<void(std::string)> performance_clipboard_callback(const std::shared_ptr<Plot_Render_Context>& ctx) {
|
||||
if (!ctx)
|
||||
return {};
|
||||
std::lock_guard<std::mutex> lock(ctx->performance_clipboard_callback_mutex);
|
||||
return ctx->performance_clipboard_callback;
|
||||
}
|
||||
static std::string performance_snapshot_text(const Performance_Display_Snapshot& snapshot) {
|
||||
std::size_t size = 0;
|
||||
for (const auto& line : snapshot.lines)
|
||||
size += line.size() + 1;
|
||||
std::string text;
|
||||
text.reserve(size);
|
||||
for (std::size_t i = 0; i < snapshot.lines.size(); ++i) {
|
||||
if (i)
|
||||
text.push_back('\n');
|
||||
text += snapshot.lines[i];
|
||||
}
|
||||
return text;
|
||||
}
|
||||
static void request_performance_update(const std::shared_ptr<Performance_Worker_State>& worker) {
|
||||
if (!worker)
|
||||
return;
|
||||
@@ -198,6 +217,7 @@ static std::shared_ptr<Performance_Overlay> attach_performance_overlay_impl(Plot
|
||||
if (options)
|
||||
created_shower->set_options(*options);
|
||||
created_shower->set_update_callback(performance_update_callback(ctx));
|
||||
created_shower->set_clipboard_callback(performance_clipboard_callback(ctx));
|
||||
std::atomic_store_explicit(&ctx->frame_lifecycle_observer, std::static_pointer_cast<Frame_Lifecycle_Observer>(created_shower), std::memory_order_release);
|
||||
return created_shower;
|
||||
}
|
||||
@@ -267,6 +287,18 @@ void set_performance_overlay_update_callback(Plot_Core& plot, std::function<void
|
||||
if (shower)
|
||||
shower->set_update_callback(performance_update_callback(ctx));
|
||||
}
|
||||
void set_performance_overlay_clipboard_callback(Plot_Core& plot, std::function<void(std::string)> callback) {
|
||||
auto ctx = Plot_Core_Context_Access::render_context(plot);
|
||||
if (!ctx)
|
||||
return;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ctx->performance_clipboard_callback_mutex);
|
||||
ctx->performance_clipboard_callback = std::move(callback);
|
||||
}
|
||||
auto shower = performance_overlay_owner(ctx);
|
||||
if (shower)
|
||||
shower->set_clipboard_callback(performance_clipboard_callback(ctx));
|
||||
}
|
||||
void notify_performance_overlay_viewport_changed(Plot_Core& plot) {
|
||||
auto shower = performance_overlay_owner(Plot_Core_Context_Access::render_context(plot));
|
||||
if (!shower || !shower->enabled())
|
||||
@@ -400,7 +432,17 @@ bool Performance_Overlay::handle_wheel(PointF position, double angle_delta_y, do
|
||||
}
|
||||
bool Performance_Overlay::handle_pointer_press(PointF position) {
|
||||
auto snapshot = display_snapshot();
|
||||
if (!snapshot || snapshot->max_scroll_offset <= 0.0)
|
||||
if (!snapshot)
|
||||
return false;
|
||||
if (!snapshot->copy_button_rect.empty() && snapshot->copy_button_rect.contains(position)) {
|
||||
d()->copy_to_clipboard(performance_snapshot_text(*snapshot));
|
||||
return true;
|
||||
}
|
||||
if (!snapshot->close_button_rect.empty() && snapshot->close_button_rect.contains(position)) {
|
||||
set_enabled(false);
|
||||
return true;
|
||||
}
|
||||
if (snapshot->max_scroll_offset <= 0.0)
|
||||
return false;
|
||||
if (snapshot->scroll_thumb_rect.contains(position)) {
|
||||
d()->metrics_worker->drag_anchor_y.store(position.y - snapshot->scroll_thumb_rect.y, std::memory_order_release);
|
||||
@@ -437,6 +479,9 @@ void Performance_Overlay::set_update_callback(std::function<void()> callback) {
|
||||
std::lock_guard<std::mutex> lock(d()->metrics_worker->update_callback_mutex);
|
||||
d()->metrics_worker->update_callback = std::move(callback);
|
||||
}
|
||||
void Performance_Overlay::set_clipboard_callback(std::function<void(std::string)> callback) {
|
||||
d()->set_clipboard_callback(std::move(callback));
|
||||
}
|
||||
void write_frame_performance_log(std::shared_ptr<const Frame_Lifecycle_Record> frame) {
|
||||
if (!frame)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user