[UI] Loop thread to main thread WindowedAppContext
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
||||
* Copyright 2021 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -13,10 +13,12 @@
|
||||
|
||||
#include "third_party/half/include/half.hpp"
|
||||
#include "third_party/imgui/imgui.h"
|
||||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/clock.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/base/system.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/gpu/command_processor.h"
|
||||
#include "xenia/gpu/gpu_flags.h"
|
||||
@@ -30,6 +32,7 @@
|
||||
#include "xenia/ui/imgui_drawer.h"
|
||||
#include "xenia/ui/virtual_key.h"
|
||||
#include "xenia/ui/window.h"
|
||||
#include "xenia/ui/windowed_app_context.h"
|
||||
#include "xenia/xbox.h"
|
||||
|
||||
DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU");
|
||||
@@ -46,22 +49,16 @@ static const ImVec4 kColorComment =
|
||||
static const ImVec4 kColorIgnored =
|
||||
ImVec4(100 / 255.0f, 100 / 255.0f, 100 / 255.0f, 255 / 255.0f);
|
||||
|
||||
TraceViewer::TraceViewer() = default;
|
||||
TraceViewer::TraceViewer(xe::ui::WindowedAppContext& app_context,
|
||||
const std::string_view name)
|
||||
: xe::ui::WindowedApp(app_context, name, "some.trace") {
|
||||
AddPositionalOption("target_trace_file");
|
||||
}
|
||||
|
||||
TraceViewer::~TraceViewer() = default;
|
||||
|
||||
int TraceViewer::Main(const std::vector<std::string>& args) {
|
||||
// Grab path from the flag or unnamed argument.
|
||||
std::filesystem::path path;
|
||||
if (!cvars::target_trace_file.empty()) {
|
||||
// Passed as a named argument.
|
||||
// TODO(benvanik): find something better than gflags that supports
|
||||
// unicode.
|
||||
path = cvars::target_trace_file;
|
||||
} else if (args.size() >= 2) {
|
||||
// Passed as an unnamed argument.
|
||||
path = xe::to_path(args[1]);
|
||||
}
|
||||
bool TraceViewer::OnInitialize() {
|
||||
std::filesystem::path path = cvars::target_trace_file;
|
||||
|
||||
// If no path passed, ask the user.
|
||||
if (path.empty()) {
|
||||
@@ -83,42 +80,37 @@ int TraceViewer::Main(const std::vector<std::string>& args) {
|
||||
}
|
||||
|
||||
if (path.empty()) {
|
||||
xe::FatalError("No trace file specified");
|
||||
return 1;
|
||||
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Warning,
|
||||
"No trace file specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Normalize the path and make absolute.
|
||||
auto abs_path = std::filesystem::absolute(path);
|
||||
|
||||
if (!Setup()) {
|
||||
xe::FatalError("Unable to setup trace viewer");
|
||||
return 1;
|
||||
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error,
|
||||
"Unable to setup trace viewer");
|
||||
return false;
|
||||
}
|
||||
if (!Load(std::move(abs_path))) {
|
||||
xe::FatalError("Unable to load trace file; not found?");
|
||||
return 1;
|
||||
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error,
|
||||
"Unable to load trace file; not found?");
|
||||
return false;
|
||||
}
|
||||
Run();
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TraceViewer::Setup() {
|
||||
// Main display window.
|
||||
loop_ = ui::Loop::Create();
|
||||
window_ = xe::ui::Window::Create(loop_.get(), "xenia-gpu-trace-viewer");
|
||||
loop_->PostSynchronous([&]() {
|
||||
xe::threading::set_name("Win32 Loop");
|
||||
if (!window_->Initialize()) {
|
||||
xe::FatalError("Failed to initialize main window");
|
||||
return;
|
||||
}
|
||||
});
|
||||
window_->on_closed.AddListener([&](xe::ui::UIEvent* e) {
|
||||
loop_->Quit();
|
||||
XELOGI("User-initiated death!");
|
||||
exit(1);
|
||||
});
|
||||
loop_->on_quit.AddListener([&](xe::ui::UIEvent* e) { window_.reset(); });
|
||||
assert_true(app_context().IsInUIThread());
|
||||
window_ = xe::ui::Window::Create(app_context(), "xenia-gpu-trace-viewer");
|
||||
if (!window_->Initialize()) {
|
||||
XELOGE("Failed to initialize main window");
|
||||
return false;
|
||||
}
|
||||
window_->on_closed.AddListener(
|
||||
[this](xe::ui::UIEvent* e) { app_context().QuitFromUIThread(); });
|
||||
window_->Resize(1920, 1200);
|
||||
|
||||
// Create the emulator but don't initialize so we can setup the window.
|
||||
@@ -142,9 +134,9 @@ bool TraceViewer::Setup() {
|
||||
}
|
||||
});
|
||||
|
||||
player_ = std::make_unique<TracePlayer>(loop_.get(), graphics_system_);
|
||||
player_ = std::make_unique<TracePlayer>(graphics_system_);
|
||||
|
||||
window_->on_painting.AddListener([&](xe::ui::UIEvent* e) {
|
||||
window_->on_painting.AddListener([this](xe::ui::UIEvent* e) {
|
||||
DrawUI();
|
||||
|
||||
// Continuous paint.
|
||||
@@ -167,16 +159,6 @@ bool TraceViewer::Load(const std::filesystem::path& trace_file_path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceViewer::Run() {
|
||||
// Wait until we are exited.
|
||||
loop_->AwaitQuit();
|
||||
|
||||
player_.reset();
|
||||
emulator_.reset();
|
||||
window_.reset();
|
||||
loop_.reset();
|
||||
}
|
||||
|
||||
void TraceViewer::DrawMultilineString(const std::string_view str) {
|
||||
size_t i = 0;
|
||||
bool done = false;
|
||||
|
||||
Reference in New Issue
Block a user