/work/obj-fuzz/dist/include/LayersLogging.h
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 | | #ifndef GFX_LAYERSLOGGING_H |
8 | | #define GFX_LAYERSLOGGING_H |
9 | | |
10 | | #include "FrameMetrics.h" // for FrameMetrics, etc |
11 | | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
12 | | #include "mozilla/gfx/Point.h" // for IntSize, etc |
13 | | #include "mozilla/gfx/TiledRegion.h" // for TiledRegion |
14 | | #include "mozilla/gfx/Types.h" // for SamplingFilter, SurfaceFormat |
15 | | #include "mozilla/layers/CompositorTypes.h" // for TextureFlags |
16 | | #include "mozilla/layers/WebRenderLayersLogging.h" |
17 | | #include "nsAString.h" |
18 | | #include "nsPrintfCString.h" // for nsPrintfCString |
19 | | #include "nsRegion.h" // for nsRegion, nsIntRegion |
20 | | #include "nscore.h" // for nsACString, etc |
21 | | |
22 | | struct nsRectAbsolute; |
23 | | |
24 | | namespace mozilla { |
25 | | |
26 | | namespace gfx { |
27 | | template <class units, class F> struct RectTyped; |
28 | | } // namespace gfx |
29 | | |
30 | | enum class ImageFormat; |
31 | | |
32 | | namespace layers { |
33 | | |
34 | | void |
35 | | AppendToString(std::stringstream& aStream, const void* p, |
36 | | const char* pfx="", const char* sfx=""); |
37 | | |
38 | | void |
39 | | AppendToString(std::stringstream& aStream, FrameMetrics::ViewID n, |
40 | | const char* pfx="", const char* sfx=""); |
41 | | |
42 | | void |
43 | | AppendToString(std::stringstream& aStream, const gfx::Color& c, |
44 | | const char* pfx="", const char* sfx=""); |
45 | | |
46 | | void |
47 | | AppendToString(std::stringstream& aStream, const nsPoint& p, |
48 | | const char* pfx="", const char* sfx=""); |
49 | | |
50 | | void |
51 | | AppendToString(std::stringstream& aStream, const nsRect& r, |
52 | | const char* pfx="", const char* sfx=""); |
53 | | |
54 | | void |
55 | | AppendToString(std::stringstream& aStream, const nsRectAbsolute& r, |
56 | | const char* pfx="", const char* sfx=""); |
57 | | |
58 | | template<class T> |
59 | | void |
60 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::PointTyped<T>& p, |
61 | | const char* pfx="", const char* sfx="") |
62 | | { |
63 | | aStream << pfx << p << sfx; |
64 | | } |
65 | | |
66 | | template<class T> |
67 | | void |
68 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::Point3DTyped<T>& p, |
69 | | const char* pfx="", const char* sfx="") |
70 | | { |
71 | | aStream << pfx << p << sfx; |
72 | | } |
73 | | |
74 | | template<class T> |
75 | | void |
76 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::IntPointTyped<T>& p, |
77 | | const char* pfx="", const char* sfx="") |
78 | | { |
79 | | aStream << pfx << p << sfx; |
80 | | } |
81 | | |
82 | | template<class T> |
83 | | void |
84 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::RectTyped<T>& r, |
85 | | const char* pfx="", const char* sfx="") |
86 | | { |
87 | | aStream << pfx; |
88 | | aStream << nsPrintfCString( |
89 | | "(x=%f, y=%f, w=%f, h=%f)", |
90 | | r.X(), r.Y(), r.Width(), r.Height()).get(); |
91 | | aStream << sfx; |
92 | | } |
93 | | |
94 | | template<class T> |
95 | | void |
96 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::IntRectTyped<T>& r, |
97 | | const char* pfx="", const char* sfx="") |
98 | | { |
99 | | aStream << pfx; |
100 | | aStream << nsPrintfCString( |
101 | | "(x=%d, y=%d, w=%d, h=%d)", |
102 | | r.X(), r.Y(), r.Width(), r.Height()).get(); |
103 | | aStream << sfx; |
104 | | } |
105 | | |
106 | | template<class T> |
107 | | void |
108 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::RectAbsoluteTyped<T>& r, |
109 | | const char* pfx="", const char* sfx="") |
110 | | { |
111 | | aStream << pfx; |
112 | | aStream << nsPrintfCString( |
113 | | "(l=%f, t=%f, r=%f, b=%f)", |
114 | | r.Left(), r.Top(), r.Right(), r.Bottom()).get(); |
115 | | aStream << sfx; |
116 | | } |
117 | | |
118 | | template<class T> |
119 | | void |
120 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::IntRectAbsoluteTyped<T>& r, |
121 | | const char* pfx="", const char* sfx="") |
122 | | { |
123 | | aStream << pfx; |
124 | | aStream << nsPrintfCString( |
125 | | "(l=%d, t=%d, r=%d, b=%d)", |
126 | | r.Left(), r.Top(), r.Right(), r.Bottom()).get(); |
127 | | aStream << sfx; |
128 | | } |
129 | | |
130 | | void |
131 | | AppendToString(std::stringstream& aStream, const wr::ColorF& c, |
132 | | const char* pfx="", const char* sfx=""); |
133 | | |
134 | | void |
135 | | AppendToString(std::stringstream& aStream, const wr::LayoutRect& r, |
136 | | const char* pfx="", const char* sfx=""); |
137 | | |
138 | | void |
139 | | AppendToString(std::stringstream& aStream, const wr::LayoutSize& s, |
140 | | const char* pfx="", const char* sfx=""); |
141 | | |
142 | | void |
143 | | AppendToString(std::stringstream& aStream, const nsSize& sz, |
144 | | const char* pfx="", const char* sfx=""); |
145 | | |
146 | | void |
147 | | AppendToString(std::stringstream& aStream, const wr::StickyOffsetBounds& s, |
148 | | const char* pfx="", const char* sfx=""); |
149 | | |
150 | | void |
151 | | AppendToString(std::stringstream& aStream, const nsRegion& r, |
152 | | const char* pfx="", const char* sfx=""); |
153 | | |
154 | | void |
155 | | AppendToString(std::stringstream& aStream, const nsIntRegion& r, |
156 | | const char* pfx="", const char* sfx=""); |
157 | | |
158 | | template <typename units> |
159 | | void |
160 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::IntRegionTyped<units>& r, |
161 | | const char* pfx="", const char* sfx="") |
162 | | { |
163 | | aStream << pfx; |
164 | | |
165 | | aStream << "< "; |
166 | | for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) { |
167 | | AppendToString(aStream, iter.Get()); |
168 | | aStream << "; "; |
169 | | } |
170 | | aStream << ">"; |
171 | | |
172 | | aStream << sfx; |
173 | | } |
174 | | |
175 | | template <typename T> |
176 | | void |
177 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::TiledRegion<T>& r, |
178 | | const char* pfx="", const char* sfx="") |
179 | | { |
180 | | aStream << pfx; |
181 | | AppendToString(aStream, r.GetRegion()); |
182 | | aStream << " (bounds="; |
183 | | AppendToString(aStream, r.GetBounds()); |
184 | | aStream << ", covers=" << r.CoversBounds() << ")" << sfx; |
185 | | } |
186 | | |
187 | | void |
188 | | AppendToString(std::stringstream& aStream, const EventRegions& e, |
189 | | const char* pfx="", const char* sfx=""); |
190 | | |
191 | | void |
192 | | AppendToString(std::stringstream& aStream, OverscrollBehavior aBehavior, |
193 | | const char* pfx="", const char* sfx=""); |
194 | | |
195 | | void |
196 | | AppendToString(std::stringstream& aStream, const ScrollMetadata& m, |
197 | | const char* pfx="", const char* sfx=""); |
198 | | |
199 | | void |
200 | | AppendToString(std::stringstream& aStream, const FrameMetrics& m, |
201 | | const char* pfx="", const char* sfx="", bool detailed = false); |
202 | | |
203 | | void |
204 | | AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s, |
205 | | const char* pfx="", const char* sfx=""); |
206 | | |
207 | | void |
208 | | AppendToString(std::stringstream& aStream, const ZoomConstraints& z, |
209 | | const char* pfx="", const char* sfx=""); |
210 | | |
211 | | template<class T> |
212 | | void |
213 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::MarginTyped<T>& m, |
214 | | const char* pfx="", const char* sfx="") |
215 | | { |
216 | | aStream << pfx; |
217 | | aStream << nsPrintfCString( |
218 | | "(l=%f, t=%f, r=%f, b=%f)", |
219 | | m.left, m.top, m.right, m.bottom).get(); |
220 | | aStream << sfx; |
221 | | } |
222 | | |
223 | | template<class T> |
224 | | void |
225 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::SizeTyped<T>& sz, |
226 | | const char* pfx="", const char* sfx="") |
227 | | { |
228 | | aStream << pfx; |
229 | | aStream << nsPrintfCString( |
230 | | "(w=%f, h=%f)", |
231 | | sz.width, sz.height).get(); |
232 | | aStream << sfx; |
233 | | } |
234 | | |
235 | | template<class T> |
236 | | void |
237 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::IntSizeTyped<T>& sz, |
238 | | const char* pfx="", const char* sfx="") |
239 | | { |
240 | | aStream << pfx; |
241 | | aStream << nsPrintfCString( |
242 | | "(w=%d, h=%d)", |
243 | | sz.width, sz.height).get(); |
244 | | aStream << sfx; |
245 | | } |
246 | | |
247 | | template<class src, class dst> |
248 | | void |
249 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::ScaleFactors2D<src, dst>& scale, |
250 | | const char* pfx="", const char* sfx="") |
251 | | { |
252 | | aStream << pfx; |
253 | | std::streamsize oldPrecision = aStream.precision(3); |
254 | | if (scale.AreScalesSame()) { |
255 | | aStream << scale.xScale; |
256 | | } else { |
257 | | aStream << '(' << scale.xScale << ',' << scale.yScale << ')'; |
258 | | } |
259 | | aStream.precision(oldPrecision); |
260 | | aStream << sfx; |
261 | | } |
262 | | |
263 | | void |
264 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::Matrix& m, |
265 | | const char* pfx="", const char* sfx=""); |
266 | | |
267 | | template<class SourceUnits, class TargetUnits> |
268 | | void |
269 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::Matrix4x4Typed<SourceUnits, TargetUnits>& m, |
270 | | const char* pfx="", const char* sfx="") |
271 | | { |
272 | | if (m.Is2D()) { |
273 | | mozilla::gfx::Matrix matrix = m.As2D(); |
274 | | AppendToString(aStream, matrix, pfx, sfx); |
275 | | return; |
276 | | } |
277 | | |
278 | | aStream << pfx; |
279 | | aStream << nsPrintfCString( |
280 | | "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]", |
281 | | m._11, m._12, m._13, m._14, |
282 | | m._21, m._22, m._23, m._24, |
283 | | m._31, m._32, m._33, m._34, |
284 | | m._41, m._42, m._43, m._44).get(); |
285 | | aStream << sfx; |
286 | | } |
287 | | |
288 | | void |
289 | | AppendToString(std::stringstream& aStream, const mozilla::gfx::Matrix5x4& m, |
290 | | const char* pfx="", const char* sfx=""); |
291 | | |
292 | | void |
293 | | AppendToString(std::stringstream& aStream, |
294 | | const mozilla::gfx::SamplingFilter samplingFilter, |
295 | | const char* pfx="", const char* sfx=""); |
296 | | |
297 | | void |
298 | | AppendToString(std::stringstream& aStream, mozilla::layers::TextureFlags flags, |
299 | | const char* pfx="", const char* sfx=""); |
300 | | |
301 | | void |
302 | | AppendToString(std::stringstream& aStream, mozilla::gfx::SurfaceFormat format, |
303 | | const char* pfx="", const char* sfx=""); |
304 | | |
305 | | void |
306 | | AppendToString(std::stringstream& aStream, gfx::SurfaceType format, |
307 | | const char* pfx="", const char* sfx=""); |
308 | | |
309 | | void |
310 | | AppendToString(std::stringstream& aStream, ImageFormat format, |
311 | | const char* pfx="", const char* sfx=""); |
312 | | |
313 | | // Sometimes, you just want a string from a single value. |
314 | | template <typename T> |
315 | | std::string |
316 | | Stringify(const T& obj) |
317 | 0 | { |
318 | 0 | std::stringstream ss; |
319 | 0 | AppendToString(ss, obj); |
320 | 0 | return ss.str(); |
321 | 0 | } |
322 | | |
323 | | } // namespace layers |
324 | | } // namespace mozilla |
325 | | |
326 | | // versions of printf_stderr and fprintf_stderr that deal with line |
327 | | // truncation on android by printing individual lines out of the |
328 | | // stringstream as separate calls to logcat. |
329 | | void print_stderr(std::stringstream& aStr); |
330 | | void fprint_stderr(FILE* aFile, std::stringstream& aStr); |
331 | | |
332 | | #endif /* GFX_LAYERSLOGGING_H */ |