2012-09-24 19:02:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "DrawEventRecorder.h"
|
|
|
|
#include "PathRecording.h"
|
2016-01-05 13:08:57 +03:00
|
|
|
#include "RecordingTypes.h"
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-10-28 01:21:26 +03:00
|
|
|
DrawEventRecorderPrivate::DrawEventRecorderPrivate() : mExternalFonts(false)
|
2012-09-24 19:02:50 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-22 20:39:28 +03:00
|
|
|
DrawEventRecorderFile::RecordEvent(const RecordedEvent &aEvent)
|
2012-09-24 19:02:50 +04:00
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
WriteElement(mOutputStream, aEvent.mType);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
aEvent.RecordToStream(mOutputStream);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
void
|
|
|
|
DrawEventRecorderMemory::RecordEvent(const RecordedEvent &aEvent)
|
2012-09-24 19:02:50 +04:00
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
WriteElement(mOutputStream, aEvent.mType);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
aEvent.RecordToStream(mOutputStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
|
|
|
|
: mOutputStream(aFilename, ofstream::binary)
|
|
|
|
{
|
|
|
|
WriteHeader(mOutputStream);
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DrawEventRecorderFile::~DrawEventRecorderFile()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
mOutputStream.close();
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawEventRecorderFile::Flush()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
mOutputStream.flush();
|
2012-09-24 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
2016-11-22 17:06:46 +03:00
|
|
|
bool
|
|
|
|
DrawEventRecorderFile::IsOpen()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
return mOutputStream.is_open();
|
2016-11-22 17:06:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawEventRecorderFile::OpenNew(const char *aFilename)
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
MOZ_ASSERT(!mOutputStream.is_open());
|
2016-11-22 17:06:46 +03:00
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
mOutputStream.open(aFilename, ofstream::binary);
|
|
|
|
WriteHeader(mOutputStream);
|
2016-11-22 17:06:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawEventRecorderFile::Close()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
MOZ_ASSERT(mOutputStream.is_open());
|
2016-11-22 17:06:46 +03:00
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
mOutputStream.close();
|
2016-11-22 17:06:46 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 23:31:59 +03:00
|
|
|
DrawEventRecorderMemory::DrawEventRecorderMemory()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
WriteHeader(mOutputStream);
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 01:21:27 +03:00
|
|
|
DrawEventRecorderMemory::DrawEventRecorderMemory(const SerializeResourcesFn &aFn) :
|
|
|
|
mSerializeCallback(aFn)
|
|
|
|
{
|
|
|
|
mExternalFonts = true;
|
|
|
|
WriteHeader(mOutputStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-26 23:31:59 +03:00
|
|
|
void
|
|
|
|
DrawEventRecorderMemory::Flush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-28 01:21:27 +03:00
|
|
|
void
|
|
|
|
DrawEventRecorderMemory::FlushItem(IntRect aRect)
|
|
|
|
{
|
|
|
|
DetatchResources();
|
|
|
|
WriteElement(mIndex, mOutputStream.mLength);
|
|
|
|
mSerializeCallback(mOutputStream, mUnscaledFonts);
|
|
|
|
WriteElement(mIndex, mOutputStream.mLength);
|
|
|
|
ClearResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawEventRecorderMemory::Finish()
|
|
|
|
{
|
|
|
|
size_t indexOffset = mOutputStream.mLength;
|
|
|
|
// write out the index
|
|
|
|
mOutputStream.write(mIndex.mData, mIndex.mLength);
|
|
|
|
mIndex = MemStream();
|
|
|
|
// write out the offset of the Index to the end of the output stream
|
|
|
|
WriteElement(mOutputStream, indexOffset);
|
|
|
|
ClearResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-26 23:31:59 +03:00
|
|
|
size_t
|
|
|
|
DrawEventRecorderMemory::RecordingSize()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
return mOutputStream.mLength;
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawEventRecorderMemory::WipeRecording()
|
|
|
|
{
|
2017-06-22 20:39:28 +03:00
|
|
|
mOutputStream = MemStream();
|
2017-10-28 01:21:27 +03:00
|
|
|
mIndex = MemStream();
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2017-06-22 20:39:28 +03:00
|
|
|
WriteHeader(mOutputStream);
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|