Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "DrawEventRecorder.h"
7 : #include "PathRecording.h"
8 : #include "RecordingTypes.h"
9 :
10 : namespace mozilla {
11 : namespace gfx {
12 :
13 : using namespace std;
14 :
15 0 : DrawEventRecorderPrivate::DrawEventRecorderPrivate()
16 : {
17 0 : }
18 :
19 : template<class S>
20 : void
21 0 : DrawEventRecorderPrivate::WriteHeader(S &aStream)
22 : {
23 0 : WriteElement(aStream, kMagicInt);
24 0 : WriteElement(aStream, kMajorRevision);
25 0 : WriteElement(aStream, kMinorRevision);
26 0 : }
27 :
28 : void
29 0 : DrawEventRecorderFile::RecordEvent(const RecordedEvent &aEvent)
30 : {
31 0 : WriteElement(mOutputStream, aEvent.mType);
32 :
33 0 : aEvent.RecordToStream(mOutputStream);
34 :
35 0 : Flush();
36 0 : }
37 :
38 : void
39 0 : DrawEventRecorderMemory::RecordEvent(const RecordedEvent &aEvent)
40 : {
41 0 : WriteElement(mOutputStream, aEvent.mType);
42 :
43 0 : aEvent.RecordToStream(mOutputStream);
44 0 : }
45 :
46 0 : DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
47 0 : : mOutputStream(aFilename, ofstream::binary)
48 : {
49 0 : WriteHeader(mOutputStream);
50 0 : }
51 :
52 0 : DrawEventRecorderFile::~DrawEventRecorderFile()
53 : {
54 0 : mOutputStream.close();
55 0 : }
56 :
57 : void
58 0 : DrawEventRecorderFile::Flush()
59 : {
60 0 : mOutputStream.flush();
61 0 : }
62 :
63 : bool
64 0 : DrawEventRecorderFile::IsOpen()
65 : {
66 0 : return mOutputStream.is_open();
67 : }
68 :
69 : void
70 0 : DrawEventRecorderFile::OpenNew(const char *aFilename)
71 : {
72 0 : MOZ_ASSERT(!mOutputStream.is_open());
73 :
74 0 : mOutputStream.open(aFilename, ofstream::binary);
75 0 : WriteHeader(mOutputStream);
76 0 : }
77 :
78 : void
79 0 : DrawEventRecorderFile::Close()
80 : {
81 0 : MOZ_ASSERT(mOutputStream.is_open());
82 :
83 0 : mOutputStream.close();
84 0 : }
85 :
86 0 : DrawEventRecorderMemory::DrawEventRecorderMemory()
87 : {
88 0 : WriteHeader(mOutputStream);
89 0 : }
90 :
91 : void
92 0 : DrawEventRecorderMemory::Flush()
93 : {
94 0 : }
95 :
96 : size_t
97 0 : DrawEventRecorderMemory::RecordingSize()
98 : {
99 0 : return mOutputStream.mLength;
100 : }
101 :
102 : void
103 0 : DrawEventRecorderMemory::WipeRecording()
104 : {
105 0 : mOutputStream = MemStream();
106 :
107 0 : WriteHeader(mOutputStream);
108 0 : }
109 :
110 : } // namespace gfx
111 : } // namespace mozilla
|