/src/mozilla-central/gfx/2d/DrawEventRecorder.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "DrawEventRecorder.h" |
8 | | #include "PathRecording.h" |
9 | | #include "RecordingTypes.h" |
10 | | #include "RecordedEventImpl.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace gfx { |
14 | | |
15 | | using namespace std; |
16 | | |
17 | | DrawEventRecorderPrivate::DrawEventRecorderPrivate() : mExternalFonts(false) |
18 | 0 | { |
19 | 0 | } |
20 | | |
21 | | void |
22 | | DrawEventRecorderPrivate::StoreExternalSurfaceRecording(SourceSurface* aSurface, |
23 | | uint64_t aKey) |
24 | 0 | { |
25 | 0 | RecordEvent(RecordedExternalSurfaceCreation(aSurface, aKey)); |
26 | 0 | mExternalSurfaces.push_back(aSurface); |
27 | 0 | } |
28 | | |
29 | | void |
30 | | DrawEventRecorderPrivate::StoreSourceSurfaceRecording(SourceSurface *aSurface, |
31 | | const char *aReason) |
32 | 0 | { |
33 | 0 | RefPtr<DataSourceSurface> dataSurf = aSurface->GetDataSurface(); |
34 | 0 | if (dataSurf) { |
35 | 0 | DataSourceSurface::ScopedMap map(dataSurf, DataSourceSurface::READ); |
36 | 0 | RecordEvent( |
37 | 0 | RecordedSourceSurfaceCreation(aSurface, map.GetData(), map.GetStride(), |
38 | 0 | dataSurf->GetSize(), dataSurf->GetFormat())); |
39 | 0 | return; |
40 | 0 | } |
41 | 0 | |
42 | 0 | gfxWarning() << "Recording failed to record SourceSurface for " << aReason; |
43 | 0 | // Insert a bogus source surface. |
44 | 0 | int32_t stride = aSurface->GetSize().width * BytesPerPixel(aSurface->GetFormat()); |
45 | 0 | UniquePtr<uint8_t[]> sourceData(new uint8_t[stride * aSurface->GetSize().height]()); |
46 | 0 | RecordEvent( |
47 | 0 | RecordedSourceSurfaceCreation(aSurface, sourceData.get(), stride, |
48 | 0 | aSurface->GetSize(), aSurface->GetFormat())); |
49 | 0 | } |
50 | | |
51 | | void |
52 | | DrawEventRecorderFile::RecordEvent(const RecordedEvent &aEvent) |
53 | 0 | { |
54 | 0 | WriteElement(mOutputStream, aEvent.mType); |
55 | 0 |
|
56 | 0 | aEvent.RecordToStream(mOutputStream); |
57 | 0 |
|
58 | 0 | Flush(); |
59 | 0 | } |
60 | | |
61 | | void |
62 | | DrawEventRecorderMemory::RecordEvent(const RecordedEvent &aEvent) |
63 | 0 | { |
64 | 0 | WriteElement(mOutputStream, aEvent.mType); |
65 | 0 |
|
66 | 0 | aEvent.RecordToStream(mOutputStream); |
67 | 0 | } |
68 | | |
69 | | DrawEventRecorderFile::DrawEventRecorderFile(const char_type* aFilename) |
70 | | : mOutputStream(aFilename, ofstream::binary) |
71 | 0 | { |
72 | 0 | WriteHeader(mOutputStream); |
73 | 0 | } |
74 | | |
75 | | DrawEventRecorderFile::~DrawEventRecorderFile() |
76 | 0 | { |
77 | 0 | mOutputStream.close(); |
78 | 0 | } |
79 | | |
80 | | void |
81 | | DrawEventRecorderFile::Flush() |
82 | 0 | { |
83 | 0 | mOutputStream.flush(); |
84 | 0 | } |
85 | | |
86 | | bool |
87 | | DrawEventRecorderFile::IsOpen() |
88 | 0 | { |
89 | 0 | return mOutputStream.is_open(); |
90 | 0 | } |
91 | | |
92 | | void |
93 | | DrawEventRecorderFile::OpenNew(const char_type* aFilename) |
94 | 0 | { |
95 | 0 | MOZ_ASSERT(!mOutputStream.is_open()); |
96 | 0 |
|
97 | 0 | mOutputStream.open(aFilename, ofstream::binary); |
98 | 0 | WriteHeader(mOutputStream); |
99 | 0 | } |
100 | | |
101 | | void |
102 | | DrawEventRecorderFile::Close() |
103 | 0 | { |
104 | 0 | MOZ_ASSERT(mOutputStream.is_open()); |
105 | 0 |
|
106 | 0 | mOutputStream.close(); |
107 | 0 | } |
108 | | |
109 | | DrawEventRecorderMemory::DrawEventRecorderMemory() |
110 | 0 | { |
111 | 0 | WriteHeader(mOutputStream); |
112 | 0 | } |
113 | | |
114 | | DrawEventRecorderMemory::DrawEventRecorderMemory(const SerializeResourcesFn &aFn) : |
115 | | mSerializeCallback(aFn) |
116 | 0 | { |
117 | 0 | mExternalFonts = true; |
118 | 0 | WriteHeader(mOutputStream); |
119 | 0 | } |
120 | | |
121 | | |
122 | | void |
123 | | DrawEventRecorderMemory::Flush() |
124 | 0 | { |
125 | 0 | } |
126 | | |
127 | | void |
128 | | DrawEventRecorderMemory::FlushItem(IntRect aRect) |
129 | 0 | { |
130 | 0 | MOZ_RELEASE_ASSERT(!aRect.IsEmpty()); |
131 | 0 | // Detaching our existing resources will add some |
132 | 0 | // destruction events to our stream so we need to do that |
133 | 0 | // first. |
134 | 0 | DetachResources(); |
135 | 0 |
|
136 | 0 | // See moz2d_renderer.rs for a description of the stream format |
137 | 0 | WriteElement(mIndex, mOutputStream.mLength); |
138 | 0 |
|
139 | 0 | // write out the fonts into the extra data section |
140 | 0 | mSerializeCallback(mOutputStream, mScaledFonts); |
141 | 0 | WriteElement(mIndex, mOutputStream.mLength); |
142 | 0 |
|
143 | 0 | WriteElement(mIndex, aRect.x); |
144 | 0 | WriteElement(mIndex, aRect.y); |
145 | 0 | WriteElement(mIndex, aRect.XMost()); |
146 | 0 | WriteElement(mIndex, aRect.YMost()); |
147 | 0 | ClearResources(); |
148 | 0 |
|
149 | 0 | // write out a new header for the next recording in the stream |
150 | 0 | WriteHeader(mOutputStream); |
151 | 0 | } |
152 | | |
153 | | bool |
154 | | DrawEventRecorderMemory::Finish() |
155 | 0 | { |
156 | 0 | // this length might be 0, and things should still work. |
157 | 0 | // for example if there are no items in a particular area |
158 | 0 | size_t indexOffset = mOutputStream.mLength; |
159 | 0 | // write out the index |
160 | 0 | mOutputStream.write(mIndex.mData, mIndex.mLength); |
161 | 0 | bool hasItems = mIndex.mLength != 0; |
162 | 0 | mIndex = MemStream(); |
163 | 0 | // write out the offset of the Index to the end of the output stream |
164 | 0 | WriteElement(mOutputStream, indexOffset); |
165 | 0 | ClearResources(); |
166 | 0 | return hasItems; |
167 | 0 | } |
168 | | |
169 | | |
170 | | size_t |
171 | | DrawEventRecorderMemory::RecordingSize() |
172 | 0 | { |
173 | 0 | return mOutputStream.mLength; |
174 | 0 | } |
175 | | |
176 | | void |
177 | | DrawEventRecorderMemory::WipeRecording() |
178 | 0 | { |
179 | 0 | mOutputStream = MemStream(); |
180 | 0 | mIndex = MemStream(); |
181 | 0 |
|
182 | 0 | WriteHeader(mOutputStream); |
183 | 0 | } |
184 | | |
185 | | } // namespace gfx |
186 | | } // namespace mozilla |