Bug 1156742 Part 4: Add an in memory DrawEventRecorder. r=bas

This commit is contained in:
Bob Owen 2015-12-21 20:33:13 +00:00
parent 2ce74bca79
commit e0674961f5
2 changed files with 85 additions and 3 deletions

View File

@ -18,6 +18,14 @@ DrawEventRecorderPrivate::DrawEventRecorderPrivate(std::ostream *aStream)
{
}
void
DrawEventRecorderPrivate::WriteHeader()
{
WriteElement(*mOutputStream, kMagicInt);
WriteElement(*mOutputStream, kMajorRevision);
WriteElement(*mOutputStream, kMinorRevision);
}
void
DrawEventRecorderPrivate::RecordEvent(const RecordedEvent &aEvent)
{
@ -34,9 +42,7 @@ DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
{
mOutputStream = &mOutputFile;
WriteElement(*mOutputStream, kMagicInt);
WriteElement(*mOutputStream, kMajorRevision);
WriteElement(*mOutputStream, kMinorRevision);
WriteHeader();
}
DrawEventRecorderFile::~DrawEventRecorderFile()
@ -50,5 +56,40 @@ DrawEventRecorderFile::Flush()
mOutputFile.flush();
}
DrawEventRecorderMemory::DrawEventRecorderMemory()
: DrawEventRecorderPrivate(nullptr)
{
mOutputStream = &mMemoryStream;
WriteHeader();
}
void
DrawEventRecorderMemory::Flush()
{
mOutputStream->flush();
}
size_t
DrawEventRecorderMemory::RecordingSize()
{
return mMemoryStream.tellp();
}
bool
DrawEventRecorderMemory::CopyRecording(char* aBuffer, size_t aBufferLen)
{
return !!mMemoryStream.read(aBuffer, aBufferLen);
}
void
DrawEventRecorderMemory::WipeRecording()
{
mMemoryStream.str(std::string());
mMemoryStream.clear();
WriteHeader();
}
} // namespace gfx
} // namespace mozilla

View File

@ -29,6 +29,8 @@ public:
explicit DrawEventRecorderPrivate(std::ostream *aStream);
virtual ~DrawEventRecorderPrivate() { }
void WriteHeader();
void RecordEvent(const RecordedEvent &aEvent);
void WritePath(const PathRecording *aPath);
@ -71,6 +73,45 @@ private:
std::ofstream mOutputFile;
};
class DrawEventRecorderMemory final : public DrawEventRecorderPrivate
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderMemory)
/**
* Constructs a DrawEventRecorder that stores the recording in memory.
*/
DrawEventRecorderMemory();
/**
* @return the current size of the recording (in chars).
*/
size_t RecordingSize();
/**
* Copies at most aBufferLen chars of the recording into aBuffer.
*
* @param aBuffer buffer to receive the recording chars
* @param aBufferLen length of aBuffer
* @return true if copied successfully
*/
bool CopyRecording(char* aBuffer, size_t aBufferLen);
/**
* Wipes the internal recording buffer, but the recorder does NOT forget which
* objects it has recorded. This can be used so that a recording can be copied
* and processed in chunks, releasing memory as it goes.
*/
void WipeRecording();
private:
~DrawEventRecorderMemory() {};
void Flush() final;
std::stringstream mMemoryStream;
};
} // namespace gfx
} // namespace mozilla