Source code

Revision control

Other Tools

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