Sharing more of trace viewer code.

This commit is contained in:
Ben Vanik
2015-12-13 11:22:47 -08:00
parent 5db84105c4
commit 95b0ecf774
6 changed files with 72 additions and 70 deletions

View File

@@ -24,10 +24,13 @@
#include "xenia/gpu/sampler_info.h"
#include "xenia/gpu/texture_info.h"
#include "xenia/memory.h"
#include "xenia/ui/file_picker.h"
#include "xenia/ui/imgui_drawer.h"
#include "xenia/ui/window.h"
#include "xenia/xbox.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.");
namespace xe {
namespace gpu {
@@ -44,6 +47,57 @@ TraceViewer::TraceViewer() = default;
TraceViewer::~TraceViewer() = default;
int TraceViewer::Main(const std::vector<std::wstring>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
if (!FLAGS_target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(FLAGS_target_trace_file);
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];
}
// If no path passed, ask the user.
if (path.empty()) {
auto file_picker = xe::ui::FilePicker::Create();
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
file_picker->set_type(ui::FilePicker::Type::kFile);
file_picker->set_multi_selection(false);
file_picker->set_title(L"Select Trace File");
file_picker->set_extensions({
{L"Supported Files", L"*.*"}, {L"All Files (*.*)", L"*.*"},
});
if (file_picker->Show()) {
auto selected_files = file_picker->selected_files();
if (!selected_files.empty()) {
path = selected_files[0];
}
}
}
if (path.empty()) {
xe::FatalError("No trace file specified");
return 1;
}
// Normalize the path and make absolute.
auto abs_path = xe::to_absolute_path(path);
if (!Setup()) {
xe::FatalError("Unable to setup trace viewer");
return 1;
}
if (!Load(std::move(abs_path))) {
xe::FatalError("Unable to load trace file; not found?");
return 1;
}
Run();
return 0;
}
bool TraceViewer::Setup() {
// Main display window.
loop_ = ui::Loop::Create();