1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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/. */
#include "LayersLogging.h"
#include <stdint.h> // for uint8_t
#include "ImageTypes.h" // for ImageFormat
#include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix
#include "mozilla/gfx/Point.h" // for IntSize
#include "nsDebug.h" // for NS_ERROR
#include "nsPoint.h" // for nsIntPoint
#include "nsRect.h" // for mozilla::gfx::IntRect
#include "base/basictypes.h"
using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
void
AppendToString(std::stringstream& aStream, const void* p,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString("%p", p).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, FrameMetrics::ViewID n,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << n;
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const Color& c,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString(
"rgba(%d, %d, %d, %f)",
uint8_t(c.r*255.f), uint8_t(c.g*255.f), uint8_t(c.b*255.f), c.a).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsPoint& p,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsRect& r,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString(
"(x=%d, y=%d, w=%d, h=%d)",
r.x, r.y, r.width, r.height).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsIntPoint& p,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const IntRect& r,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString(
"(x=%d, y=%d, w=%d, h=%d)",
r.x, r.y, r.width, r.height).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsRegion& r,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << "< ";
for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
AppendToString(aStream, iter.Get());
aStream << "; ";
}
aStream << ">";
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsIntRegion& r,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << "< ";
for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
AppendToString(aStream, iter.Get());
aStream << "; ";
}
aStream << ">";
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const EventRegions& e,
const char* pfx, const char* sfx)
{
aStream << pfx << "{";
if (!e.mHitRegion.IsEmpty()) {
AppendToString(aStream, e.mHitRegion, " hitregion=", "");
}
if (!e.mDispatchToContentHitRegion.IsEmpty()) {
AppendToString(aStream, e.mDispatchToContentHitRegion, " dispatchtocontentregion=", "");
}
if (!e.mNoActionRegion.IsEmpty()) {
AppendToString(aStream, e.mNoActionRegion, " NoActionRegion=","");
}
if (!e.mHorizontalPanRegion.IsEmpty()) {
AppendToString(aStream, e.mHorizontalPanRegion, " HorizontalPanRegion=", "");
}
if (!e.mVerticalPanRegion.IsEmpty()) {
AppendToString(aStream, e.mVerticalPanRegion, " VerticalPanRegion=", "");
}
aStream << "}" << sfx;
}
void
AppendToString(std::stringstream& aStream, const ScrollMetadata& m,
const char* pfx, const char* sfx)
{
aStream << pfx;
AppendToString(aStream, m.GetMetrics(), "{ [metrics=");
AppendToString(aStream, m.GetBackgroundColor(), "] [color=");
if (m.GetScrollParentId() != FrameMetrics::NULL_SCROLL_ID) {
AppendToString(aStream, m.GetScrollParentId(), "] [scrollParent=");
}
if (m.HasScrollClip()) {
AppendToString(aStream, m.ScrollClip().GetClipRect(), "] [clip=");
}
aStream << "] }" << sfx;
}
void
AppendToString(std::stringstream& aStream, const FrameMetrics& m,
const char* pfx, const char* sfx, bool detailed)
{
aStream << pfx;
AppendToString(aStream, m.GetCompositionBounds(), "{ [cb=");
AppendToString(aStream, m.GetScrollableRect(), "] [sr=");
AppendToString(aStream, m.GetScrollOffset(), "] [s=");
if (m.GetDoSmoothScroll()) {
AppendToString(aStream, m.GetSmoothScrollOffset(), "] [ss=");
}
AppendToString(aStream, m.GetDisplayPort(), "] [dp=");
AppendToString(aStream, m.GetCriticalDisplayPort(), "] [cdp=");
if (!detailed) {
AppendToString(aStream, m.GetScrollId(), "] [scrollId=");
if (m.IsRootContent()) {
aStream << "] [rcd";
}
AppendToString(aStream, m.GetZoom(), "] [z=", "] }");
} else {
AppendToString(aStream, m.GetDisplayPortMargins(), " [dpm=");
aStream << nsPrintfCString("] um=%d", m.GetUseDisplayPortMargins()).get();
AppendToString(aStream, m.GetRootCompositionSize(), "] [rcs=");
AppendToString(aStream, m.GetViewport(), "] [v=");
aStream << nsPrintfCString("] [z=(ld=%.3f r=%.3f",
m.GetDevPixelsPerCSSPixel().scale,
m.GetPresShellResolution()).get();
AppendToString(aStream, m.GetCumulativeResolution(), " cr=");
AppendToString(aStream, m.GetZoom(), " z=");
AppendToString(aStream, m.GetExtraResolution(), " er=");
aStream << nsPrintfCString(")] [u=(%d %d %lu)",
m.GetScrollUpdateType(), m.GetDoSmoothScroll(),
m.GetScrollGeneration()).get();
aStream << nsPrintfCString("] [i=(%ld %lld %d)] }",
m.GetPresShellId(), m.GetScrollId(), m.IsRootContent()).get();
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s,
const char* pfx, const char* sfx)
{
aStream << pfx
<< nsPrintfCString("{ l=%" PRIu64 ", p=%u, v=%" PRIu64 " }", s.mLayersId, s.mPresShellId, s.mScrollId).get()
<< sfx;
}
void
AppendToString(std::stringstream& aStream, const ZoomConstraints& z,
const char* pfx, const char* sfx)
{
aStream << pfx
<< nsPrintfCString("{ z=%d dt=%d min=%f max=%f }", z.mAllowZoom, z.mAllowDoubleTapZoom, z.mMinZoom.scale, z.mMaxZoom.scale).get()
<< sfx;
}
void
AppendToString(std::stringstream& aStream, const Matrix& m,
const char* pfx, const char* sfx)
{
aStream << pfx;
if (m.IsIdentity()) {
aStream << "[ I ]";
} else {
aStream << nsPrintfCString(
"[ %g %g; %g %g; %g %g; ]",
m._11, m._12, m._21, m._22, m._31, m._32).get();
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const Matrix5x4& m,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString(
"[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]",
m._11, m._12, m._13, m._14,
m._21, m._22, m._23, m._24,
m._31, m._32, m._33, m._34,
m._41, m._42, m._43, m._44,
m._51, m._52, m._53, m._54).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const SamplingFilter filter,
const char* pfx, const char* sfx)
{
aStream << pfx;
switch (filter) {
case SamplingFilter::GOOD: aStream << "SamplingFilter::GOOD"; break;
case SamplingFilter::LINEAR: aStream << "SamplingFilter::LINEAR"; break;
case SamplingFilter::POINT: aStream << "SamplingFilter::POINT"; break;
default:
NS_ERROR("unknown SamplingFilter type");
aStream << "???";
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, TextureFlags flags,
const char* pfx, const char* sfx)
{
aStream << pfx;
if (flags == TextureFlags::NO_FLAGS) {
aStream << "NoFlags";
} else {
#define AppendFlag(test) \
{ \
if (!!(flags & test)) { \
if (previous) { \
aStream << "|"; \
} \
aStream << #test; \
previous = true; \
} \
}
bool previous = false;
AppendFlag(TextureFlags::USE_NEAREST_FILTER);
AppendFlag(TextureFlags::ORIGIN_BOTTOM_LEFT);
AppendFlag(TextureFlags::DISALLOW_BIGIMAGE);
#undef AppendFlag
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, mozilla::gfx::SurfaceFormat format,
const char* pfx, const char* sfx)
{
aStream << pfx;
switch (format) {
case SurfaceFormat::B8G8R8A8: aStream << "SurfaceFormat::B8G8R8A8"; break;
case SurfaceFormat::B8G8R8X8: aStream << "SurfaceFormat::B8G8R8X8"; break;
case SurfaceFormat::R8G8B8A8: aStream << "SurfaceFormat::R8G8B8A8"; break;
case SurfaceFormat::R8G8B8X8: aStream << "SurfaceFormat::R8G8B8X8"; break;
case SurfaceFormat::R5G6B5_UINT16:
aStream << "SurfaceFormat::R5G6B5_UINT16"; break;
case SurfaceFormat::A8: aStream << "SurfaceFormat::A8"; break;
case SurfaceFormat::YUV: aStream << "SurfaceFormat::YUV"; break;
case SurfaceFormat::NV12: aStream << "SurfaceFormat::NV12"; break;
case SurfaceFormat::YUV422: aStream << "SurfaceFormat::YUV422"; break;
case SurfaceFormat::UNKNOWN: aStream << "SurfaceFormat::UNKNOWN"; break;
default:
NS_ERROR("unknown surface format");
aStream << "???";
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, gfx::SurfaceType aType,
const char* pfx, const char* sfx)
{
aStream << pfx;
switch(aType) {
case SurfaceType::DATA:
aStream << "SurfaceType::DATA"; break;
case SurfaceType::D2D1_BITMAP:
aStream << "SurfaceType::D2D1_BITMAP"; break;
case SurfaceType::D2D1_DRAWTARGET:
aStream << "SurfaceType::D2D1_DRAWTARGET"; break;
case SurfaceType::CAIRO:
aStream << "SurfaceType::CAIRO"; break;
case SurfaceType::CAIRO_IMAGE:
aStream << "SurfaceType::CAIRO_IMAGE"; break;
case SurfaceType::COREGRAPHICS_IMAGE:
aStream << "SurfaceType::COREGRAPHICS_IMAGE"; break;
case SurfaceType::COREGRAPHICS_CGCONTEXT:
aStream << "SurfaceType::COREGRAPHICS_CGCONTEXT"; break;
case SurfaceType::SKIA:
aStream << "SurfaceType::SKIA"; break;
case SurfaceType::DUAL_DT:
aStream << "SurfaceType::DUAL_DT"; break;
case SurfaceType::D2D1_1_IMAGE:
aStream << "SurfaceType::D2D1_1_IMAGE"; break;
case SurfaceType::RECORDING:
aStream << "SurfaceType::RECORDING"; break;
case SurfaceType::TILED:
aStream << "SurfaceType::TILED"; break;
default:
NS_ERROR("unknown surface type");
aStream << "???";
}
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, ImageFormat format,
const char* pfx, const char* sfx)
{
aStream << pfx;
switch (format) {
case ImageFormat::PLANAR_YCBCR:
aStream << "ImageFormat::PLANAR_YCBCR"; break;
case ImageFormat::GRALLOC_PLANAR_YCBCR:
aStream << "ImageFormat::GRALLOC_PLANAR_YCBCR"; break;
case ImageFormat::SHARED_RGB:
aStream << "ImageFormat::SHARED_RGB"; break;
case ImageFormat::CAIRO_SURFACE:
aStream << "ImageFormat::CAIRO_SURFACE"; break;
case ImageFormat::MAC_IOSURFACE:
aStream << "ImageFormat::MAC_IOSURFACE"; break;
case ImageFormat::SURFACE_TEXTURE:
aStream << "ImageFormat::SURFACE_TEXTURE"; break;
case ImageFormat::EGLIMAGE:
aStream << "ImageFormat::EGLIMAGE"; break;
case ImageFormat::D3D9_RGB32_TEXTURE:
aStream << "ImageFormat::D3D9_RBG32_TEXTURE"; break;
case ImageFormat::OVERLAY_IMAGE:
aStream << "ImageFormat::OVERLAY_IMAGE"; break;
case ImageFormat::D3D11_SHARE_HANDLE_TEXTURE:
aStream << "ImageFormat::D3D11_SHARE_HANDLE_TEXTURE"; break;
default:
NS_ERROR("unknown image format");
aStream << "???";
}
aStream << sfx;
}
} // namespace layers
} // namespace mozilla
void
print_stderr(std::stringstream& aStr)
{
#if defined(ANDROID)
// On Android logcat output is truncated to 1024 chars per line, and
// we usually use std::stringstream to build up giant multi-line gobs
// of output. So to avoid the truncation we find the newlines and
// print the lines individually.
std::string line;
while (std::getline(aStr, line)) {
printf_stderr("%s\n", line.c_str());
}
#else
printf_stderr("%s", aStr.str().c_str());
#endif
}
void
fprint_stderr(FILE* aFile, std::stringstream& aStr)
{
if (aFile == stderr) {
print_stderr(aStr);
} else {
fprintf_stderr(aFile, "%s", aStr.str().c_str());
}
}
|