Wrap up CaptureOptions encoding via string into member util functions

This commit is contained in:
baldurk
2018-02-14 19:21:55 +00:00
parent 1ee01e1f82
commit 468c6c1e80
6 changed files with 38 additions and 53 deletions
+31
View File
@@ -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
+3 -11
View File
@@ -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);
}
+1 -10
View File
@@ -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()));
+1 -19
View File
@@ -746,15 +746,6 @@ uint32_t Process::InjectIntoProcess(uint32_t pid, const rdcarray<EnvironmentModi
// 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)));
}
}
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));
+1 -12
View File
@@ -56,17 +56,6 @@ rdcarray<rdcstr> convertArgs(const std::vector<std::string> &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<string>("capopts").c_str(), &cmdopts);
cmdopts.DecodeFromString(parser.get<string>("capopts"));
RENDERDOC_InitGlobalEnv(m_Env, rdcarray<rdcstr>());
+1 -1
View File
@@ -607,7 +607,7 @@ struct GlobalHookCommand : public Command
string debuglog = parser.get<string>("debuglog");
CaptureOptions cmdopts;
readCapOpts(parser.get<string>("capopts").c_str(), &cmdopts);
cmdopts.DecodeFromString(parser.get<string>("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.