mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 04:05:32 +00:00
680815cd6e
This patch was generated automatically by the "modeline.py" script, available here: https://github.com/amccreight/moz-source-tools/blob/master/modeline.py For every file that is modified in this patch, the changes are as follows: (1) The patch changes the file to use the exact C++ mode lines from the Mozilla coding style guide, available here: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Mode_Line (2) The patch deletes any blank lines between the mode line & the MPL boilerplate comment. (3) If the file previously had the mode lines and MPL boilerplate in a single contiguous C++ comment, then the patch splits them into separate C++ comments, to match the boilerplate in the coding style. MozReview-Commit-ID: EuRsDue63tK --HG-- extra : rebase_source : 3356d4b80ff6213935192e87cdbc9103fec6084c
104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#ifndef mozilla_layout_printing_DrawEventRecorder_h
|
|
#define mozilla_layout_printing_DrawEventRecorder_h
|
|
|
|
#include "mozilla/gfx/DrawEventRecorder.h"
|
|
#include "mozilla/gfx/RecordingTypes.h"
|
|
#include "prio.h"
|
|
|
|
namespace mozilla {
|
|
namespace layout {
|
|
|
|
class PRFileDescStream : public mozilla::gfx::EventStream {
|
|
public:
|
|
PRFileDescStream() : mFd(nullptr), mGood(true) {}
|
|
|
|
void OpenFD(PRFileDesc* aFd) {
|
|
MOZ_ASSERT(!IsOpen());
|
|
mFd = aFd;
|
|
mGood = true;
|
|
}
|
|
|
|
void Close() {
|
|
PR_Close(mFd);
|
|
mFd = nullptr;
|
|
}
|
|
|
|
bool IsOpen() {
|
|
return mFd != nullptr;
|
|
}
|
|
|
|
void Flush() {
|
|
// For std::ostream this flushes any internal buffers. PRFileDesc's IO isn't
|
|
// buffered, so nothing to do here.
|
|
}
|
|
|
|
void Seek(PRInt32 aOffset, PRSeekWhence aWhence) {
|
|
PR_Seek(mFd, aOffset, aWhence);
|
|
}
|
|
|
|
void write(const char* aData, size_t aSize) {
|
|
// We need to be API compatible with std::ostream, and so we silently handle
|
|
// writes on a closed FD.
|
|
if (IsOpen()) {
|
|
PR_Write(mFd, static_cast<const void*>(aData), aSize);
|
|
}
|
|
}
|
|
|
|
void read(char* aOut, size_t aSize) {
|
|
PRInt32 res = PR_Read(mFd, static_cast<void*>(aOut), aSize);
|
|
mGood = res >= 0 && ((size_t)res == aSize);
|
|
}
|
|
|
|
bool good() {
|
|
return mGood;
|
|
}
|
|
|
|
private:
|
|
PRFileDesc* mFd;
|
|
bool mGood;
|
|
};
|
|
|
|
class DrawEventRecorderPRFileDesc : public gfx::DrawEventRecorderPrivate
|
|
{
|
|
public:
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderPRFileDesc, override)
|
|
explicit DrawEventRecorderPRFileDesc() { };
|
|
~DrawEventRecorderPRFileDesc();
|
|
|
|
void RecordEvent(const gfx::RecordedEvent& aEvent) override;
|
|
|
|
/**
|
|
* Returns whether a recording file is currently open.
|
|
*/
|
|
bool IsOpen();
|
|
|
|
/**
|
|
* Opens the recorder with the provided PRFileDesc *.
|
|
*/
|
|
void OpenFD(PRFileDesc* aFd);
|
|
|
|
/**
|
|
* Closes the file so that it can be processed. The recorder does NOT forget
|
|
* which objects it has recorded. This can be used with OpenNew, so that a
|
|
* recording can be processed in chunks. The file must be open.
|
|
*/
|
|
void Close();
|
|
|
|
private:
|
|
void Flush() override;
|
|
|
|
PRFileDescStream mOutputStream;
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* mozilla_layout_printing_DrawEventRecorder_h */
|