Add notion of UI modifications to a capture, saved in .rdc sections

This commit is contained in:
baldurk
2017-11-15 19:28:19 +00:00
parent bb6452c334
commit c00a6ca8ef
8 changed files with 227 additions and 10 deletions
+70
View File
@@ -147,6 +147,8 @@ void CaptureContext::LoadCapture(const QString &captureFile, const QString &orig
{
m_CaptureTemporary = temporary;
m_CaptureMods = CaptureModifications::NoModifications;
QVector<ICaptureViewer *> viewers(m_CaptureViewers);
// make sure we're on a consistent event before invoking viewer forms
@@ -311,6 +313,18 @@ void CaptureContext::LoadCaptureThreaded(const QString &captureFile, const QStri
.arg(origFilename));
}
ICaptureAccess *access = Replay().GetCaptureAccess();
if(access)
{
int idx = access->FindSectionByType(SectionType::ResourceRenames);
if(idx >= 0)
{
bytebuf buf = access->GetSectionContents(idx);
LoadRenames(QString::fromUtf8((const char *)buf.data(), buf.count()));
}
}
m_LoadInProgress = false;
m_CaptureLoaded = true;
}
@@ -596,6 +610,17 @@ bool CaptureContext::SaveCaptureTo(const QString &captureFile)
Replay().ReopenCaptureFile(captureFile);
if(m_CaptureMods & CaptureModifications::Renames)
{
SectionProperties props;
props.type = SectionType::ResourceRenames;
props.version = 1;
Replay().GetCaptureAccess()->WriteSection(props, SaveRenames().toUtf8());
}
m_CaptureMods = CaptureModifications::NoModifications;
return true;
}
@@ -697,6 +722,48 @@ void CaptureContext::AddMessages(const rdcarray<DebugMessage> &msgs)
}
}
QString CaptureContext::SaveRenames()
{
QVariantMap resources;
for(ResourceId id : m_CustomNames.keys())
{
resources[ToQStr(id)] = m_CustomNames[id];
}
QVariantMap root;
root[lit("CustomResourceNames")] = resources;
return VariantToJSON(root);
}
void CaptureContext::LoadRenames(const QString &data)
{
QVariantMap root = JSONToVariant(data);
if(root.contains(lit("CustomResourceNames")))
{
QVariantMap resources = root[lit("CustomResourceNames")].toMap();
for(const QString &str : resources.keys())
{
ResourceId id;
if(str.startsWith(lit("resourceid::")))
{
qulonglong num = str.mid(sizeof("resourceid::") - 1).toULongLong();
memcpy(&id, &num, sizeof(num));
}
else
{
qCritical() << "Unrecognised resourceid encoding" << str;
}
if(id != ResourceId())
m_CustomNames[id] = resources[str].toString();
}
}
}
QString CaptureContext::GetResourceName(ResourceId id)
{
if(id == ResourceId())
@@ -748,6 +815,9 @@ void CaptureContext::SetResourceCustomName(ResourceId id, const QString &name)
m_CustomNameCachedID++;
m_CaptureMods |= CaptureModifications::Renames;
m_MainWindow->captureModified();
RefreshUIStatus({}, true, true);
}
+5
View File
@@ -103,6 +103,7 @@ public:
bool IsCaptureTemporary() override { return m_CaptureTemporary; }
bool IsCaptureLoading() override { return m_LoadInProgress; }
QString GetCaptureFilename() override { return m_CaptureFile; }
CaptureModifications GetCaptureModifications() override { return m_CaptureMods; }
const FrameDescription &FrameInfo() override { return m_FrameInfo; }
const APIProperties &APIProps() override { return m_APIProps; }
uint32_t CurSelectedEvent() override { return m_SelectedEventID; }
@@ -233,6 +234,7 @@ private:
bool m_CaptureLoaded = false, m_LoadInProgress = false, m_CaptureLocal = false,
m_CaptureTemporary = false;
QString m_CaptureFile;
CaptureModifications m_CaptureMods = CaptureModifications::NoModifications;
QVector<DebugMessage> m_DebugMessages;
int m_UnreadMessageCount = 0;
@@ -241,6 +243,9 @@ private:
bool ContainsMarker(const rdcarray<DrawcallDescription> &m_Drawcalls);
void AddFakeProfileMarkers();
QString SaveRenames();
void LoadRenames(const QString &data);
float m_LoadProgress = 0.0f;
float m_PostloadProgress = 0.0f;
float UpdateLoadProgress();
+42
View File
@@ -871,6 +871,40 @@ enum class DockReference : int
ConstantBufferArea,
};
DOCUMENT(R"(Details any changes that have been made to a capture in the UI which can be saved to
disk but currently aren't. Note that detection is conservative - e.g. if a change is made, then
cancelled out by reversing the change, this will still count as 'modified' even if the end result is
the same data. In that sense it's analogous to adding and then deleting some characters in a text
editor, since there is no actual undo system.
This is a bitmask, so several values can be present at once.
.. data:: NoModifications
Fixed value of 0 indicating no modifications have been made.
.. data:: Renames
One or more resources have been given a custom name which hasn't been saved.
.. data:: Bookmarks
Event bookmarks have been added or removed.
.. data:: Notes
The general notes field has been changed.
)");
enum class CaptureModifications : uint32_t
{
NoModifications = 0x0000,
Renames = 0x0001,
Bookmarks = 0x0002,
Notes = 0x0004,
};
BITMASK_OPERATORS(CaptureModifications);
DOCUMENT("The capture context that the python script is running in.")
struct ICaptureContext
{
@@ -998,6 +1032,14 @@ temporary and treated like any other capture.
)");
virtual QString GetCaptureFilename() = 0;
DOCUMENT(R"(Get a bitmask indicating which modifications (if any) have been made to the capture in
the UI which aren't reflected in the capture file on disk.
:return: The modifications (if any) that have been made to the capture.
:rtype: CaptureModifications
)");
virtual CaptureModifications GetCaptureModifications() = 0;
DOCUMENT(R"(Retrieve the :class:`~renderdoc.FrameDescription` for the currently loaded capture.
:return: The frame information.