diff --git a/renderdoc/api/replay/capture_options.h b/renderdoc/api/replay/capture_options.h index a54badc92..f56f43448 100644 --- a/renderdoc/api/replay/capture_options.h +++ b/renderdoc/api/replay/capture_options.h @@ -39,6 +39,37 @@ struct CaptureOptions CaptureOptions(); #endif + DOCUMENT(R"(Encode the current options to a string suitable for passing around between processes. + +:return: The encoded string, suitable for passing to :meth:`DecodeFromString`. +:rtype: ``str`` +)"); + inline rdcstr EncodeAsString() const + { + rdcstr optstr; + optstr.reserve(sizeof(CaptureOptions) * 2 + 1); + byte *b = (byte *)this; + for(size_t i = 0; i < sizeof(CaptureOptions); i++) + { + optstr.push_back(char('a' + ((b[i] >> 4) & 0xf))); + optstr.push_back(char('a' + ((b[i]) & 0xf))); + } + + return optstr; + } + + DOCUMENT("Decode the options from a string, as returned by :meth:`EncodeAsString`."); + inline void DecodeFromString(const rdcstr &str) + { + if(str.size() < sizeof(CaptureOptions)) + return; + + // serialise from string with two chars per byte + byte *b = (byte *)this; + for(size_t i = 0; i < sizeof(CaptureOptions); i++) + *(b++) = (byte(str[i * 2 + 0] - 'a') << 4) | byte(str[i * 2 + 1] - 'a'); + } + DOCUMENT(R"(Allow the application to enable vsync. Default - enabled diff --git a/renderdoc/os/posix/posix_libentry.cpp b/renderdoc/os/posix/posix_libentry.cpp index 22723ed1c..ff0436ee9 100644 --- a/renderdoc/os/posix/posix_libentry.cpp +++ b/renderdoc/os/posix/posix_libentry.cpp @@ -28,14 +28,6 @@ void dlopen_hook_init(); -void readCapOpts(const char *str, CaptureOptions *opts) -{ - // serialise from string with two chars per byte - byte *b = (byte *)opts; - for(size_t i = 0; i < sizeof(CaptureOptions); i++) - *(b++) = (byte(str[i * 2 + 0] - 'a') << 4) | byte(str[i * 2 + 1] - 'a'); -} - // DllMain equivalent void library_loaded() { @@ -61,10 +53,10 @@ void library_loaded() if(opts) { - string optstr = opts; - CaptureOptions optstruct; - readCapOpts(optstr.c_str(), &optstruct); + optstruct.DecodeFromString(opts); + + RDCLOG("Using delay for debugger %u", optstruct.delayForDebugger); RenderDoc::Inst().SetCaptureOptions(optstruct); } diff --git a/renderdoc/os/posix/posix_process.cpp b/renderdoc/os/posix/posix_process.cpp index 8c5f90823..c7638514a 100644 --- a/renderdoc/os/posix/posix_process.cpp +++ b/renderdoc/os/posix/posix_process.cpp @@ -516,16 +516,7 @@ uint32_t Process::LaunchAndInjectIntoProcess(const char *app, const char *workin #endif } - string optstr; - { - optstr.reserve(sizeof(CaptureOptions) * 2 + 1); - byte *b = (byte *)&opts; - for(size_t i = 0; i < sizeof(CaptureOptions); i++) - { - optstr.push_back(char('a' + ((b[i] >> 4) & 0xf))); - optstr.push_back(char('a' + ((b[i]) & 0xf))); - } - } + string optstr = opts.EncodeAsString(); modifications.push_back(EnvironmentModification(EnvMod::Append, EnvSep::Platform, "LD_LIBRARY_PATH", binpath.c_str())); diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index ea6b55647..4b511b717 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -746,15 +746,6 @@ uint32_t Process::InjectIntoProcess(uint32_t pid, const rdcarray> 4) & 0xf))); - optstr.push_back(char('a' + ((b[i]) & 0xf))); - } - } wchar_t *paramsAlloc = new wchar_t[2048]; @@ -1404,16 +1395,7 @@ bool Process::StartGlobalHook(const char *pathmatch, const char *logfile, const paramsAlloc.resize(2048); // serialise to string with two chars per byte - string optstr; - { - optstr.reserve(sizeof(CaptureOptions) * 2 + 1); - byte *b = (byte *)&opts; - for(size_t i = 0; i < sizeof(CaptureOptions); i++) - { - optstr.push_back(char('a' + ((b[i] >> 4) & 0xf))); - optstr.push_back(char('a' + ((b[i]) & 0xf))); - } - } + string optstr = opts.EncodeAsString(); wstring wlogfile = logfile == NULL ? L"" : StringFormat::UTF82Wide(string(logfile)); wstring wpathmatch = StringFormat::UTF82Wide(string(pathmatch)); diff --git a/renderdoccmd/renderdoccmd.cpp b/renderdoccmd/renderdoccmd.cpp index 302aa6b90..e6fa7b8a1 100644 --- a/renderdoccmd/renderdoccmd.cpp +++ b/renderdoccmd/renderdoccmd.cpp @@ -56,17 +56,6 @@ rdcarray convertArgs(const std::vector &args) return ret; } -void readCapOpts(const std::string &str, CaptureOptions *opts) -{ - if(str.length() < sizeof(CaptureOptions)) - return; - - // serialise from string with two chars per byte - byte *b = (byte *)opts; - for(size_t i = 0; i < sizeof(CaptureOptions); i++) - *(b++) = (byte(str[i * 2 + 0] - 'a') << 4) | byte(str[i * 2 + 1] - 'a'); -} - void DisplayRendererPreview(IReplayController *renderer, uint32_t width, uint32_t height) { if(renderer == NULL) @@ -805,7 +794,7 @@ struct CapAltBitCommand : public Command virtual int Execute(cmdline::parser &parser, const CaptureOptions &) { CaptureOptions cmdopts; - readCapOpts(parser.get("capopts").c_str(), &cmdopts); + cmdopts.DecodeFromString(parser.get("capopts")); RENDERDOC_InitGlobalEnv(m_Env, rdcarray()); diff --git a/renderdoccmd/renderdoccmd_win32.cpp b/renderdoccmd/renderdoccmd_win32.cpp index cc4d551a5..6248d90e0 100644 --- a/renderdoccmd/renderdoccmd_win32.cpp +++ b/renderdoccmd/renderdoccmd_win32.cpp @@ -607,7 +607,7 @@ struct GlobalHookCommand : public Command string debuglog = parser.get("debuglog"); CaptureOptions cmdopts; - readCapOpts(parser.get("capopts").c_str(), &cmdopts); + cmdopts.DecodeFromString(parser.get("capopts")); // make sure the user doesn't accidentally run this with 'a' as a parameter or something. // "a.exe" is over 4 characters so this limit should not be a problem.