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
#include "LayersLogging.h"
8
#include <stdint.h> // for uint8_t
9
#include "FrameMetrics.h" // for FrameMetrics, etc
10
#include "ImageTypes.h" // for ImageFormat
11
#include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix
12
#include "mozilla/gfx/Point.h" // for IntSize
13
#include "nsDebug.h" // for NS_ERROR
14
#include "nsPoint.h" // for nsPoint
15
#include "nsRect.h" // for nsRect
16
#include "nsRectAbsolute.h" // for nsRectAbsolute
17
#include "base/basictypes.h"
18
19
using namespace mozilla::gfx;
20
21
namespace mozilla {
22
namespace layers {
23
24
void AppendToString(std::stringstream& aStream, const void* p, const char* pfx,
25
const char* sfx) {
26
aStream << pfx;
27
aStream << nsPrintfCString("%p", p).get();
28
aStream << sfx;
29
}
30
31
void AppendToString(std::stringstream& aStream, ScrollableLayerGuid::ViewID n,
32
const char* pfx, const char* sfx) {
33
aStream << pfx;
34
aStream << n;
35
aStream << sfx;
36
}
37
38
void AppendToString(std::stringstream& aStream, const sRGBColor& c,
39
const char* pfx, const char* sfx) {
40
aStream << pfx;
41
aStream << nsPrintfCString("rgba(%d, %d, %d, %f)", uint8_t(c.r * 255.f),
42
uint8_t(c.g * 255.f), uint8_t(c.b * 255.f), c.a)
43
.get();
44
aStream << sfx;
45
}
46
47
void AppendToString(std::stringstream& aStream, const DeviceColor& c,
48
const char* pfx, const char* sfx) {
49
aStream << pfx;
50
aStream << nsPrintfCString("dev_rgba(%d, %d, %d, %f)", uint8_t(c.r * 255.f),
51
uint8_t(c.g * 255.f), uint8_t(c.b * 255.f), c.a)
52
.get();
53
aStream << sfx;
54
}
55
56
void AppendToString(std::stringstream& aStream, const nsPoint& p,
57
const char* pfx, const char* sfx) {
58
aStream << pfx;
59
aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
60
aStream << sfx;
61
}
62
63
void AppendToString(std::stringstream& aStream, const nsRect& r,
64
const char* pfx, const char* sfx) {
65
aStream << pfx;
66
aStream << nsPrintfCString("(x=%d, y=%d, w=%d, h=%d)", r.X(), r.Y(),
67
r.Width(), r.Height())
68
.get();
69
aStream << sfx;
70
}
71
72
void AppendToString(std::stringstream& aStream, const nsRectAbsolute& r,
73
const char* pfx, const char* sfx) {
74
aStream << pfx;
75
aStream << nsPrintfCString("(l=%d, t=%d, r=%d, b=%d)", r.Left(), r.Top(),
76
r.Right(), r.Bottom())
77
.get();
78
aStream << sfx;
79
}
80
81
void AppendToString(std::stringstream& aStream, const wr::ColorF& c,
82
const char* pfx, const char* sfx) {
83
aStream << pfx;
84
aStream << nsPrintfCString("rgba(%d, %d, %d, %f)", uint8_t(c.r * 255.f),
85
uint8_t(c.g * 255.f), uint8_t(c.b * 255.f), c.a)
86
.get();
87
aStream << sfx;
88
}
89
90
void AppendToString(std::stringstream& aStream, const wr::LayoutRect& r,
91
const char* pfx, const char* sfx) {
92
aStream << pfx;
93
aStream << nsPrintfCString("(x=%f, y=%f, w=%f, h=%f)", r.origin.x, r.origin.y,
94
r.size.width, r.size.height)
95
.get();
96
aStream << sfx;
97
}
98
99
void AppendToString(std::stringstream& aStream, const wr::LayoutSize& s,
100
const char* pfx, const char* sfx) {
101
aStream << pfx;
102
aStream << nsPrintfCString("(w=%f, h=%f)", s.width, s.height).get();
103
aStream << sfx;
104
}
105
106
void AppendToString(std::stringstream& aStream, const nsSize& sz,
107
const char* pfx, const char* sfx) {
108
aStream << pfx;
109
aStream << nsPrintfCString("(w=%d, h=%d)", sz.width, sz.height).get();
110
aStream << sfx;
111
}
112
113
void AppendToString(std::stringstream& aStream, const wr::StickyOffsetBounds& s,
114
const char* pfx, const char* sfx) {
115
aStream << pfx;
116
aStream << nsPrintfCString("(min=%f max=%f)", s.min, s.max).get();
117
aStream << sfx;
118
}
119
120
void AppendToString(std::stringstream& aStream, const nsRegion& r,
121
const char* pfx, const char* sfx) {
122
aStream << pfx;
123
124
aStream << "< ";
125
for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
126
AppendToString(aStream, iter.Get());
127
aStream << "; ";
128
}
129
aStream << ">";
130
131
aStream << sfx;
132
}
133
134
void AppendToString(std::stringstream& aStream, const nsIntRegion& r,
135
const char* pfx, const char* sfx) {
136
aStream << pfx;
137
138
aStream << "< ";
139
for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
140
AppendToString(aStream, iter.Get());
141
aStream << "; ";
142
}
143
aStream << ">";
144
145
aStream << sfx;
146
}
147
148
void AppendToString(std::stringstream& aStream, const EventRegions& e,
149
const char* pfx, const char* sfx) {
150
aStream << pfx << "{";
151
if (!e.mHitRegion.IsEmpty()) {
152
AppendToString(aStream, e.mHitRegion, " hitregion=", "");
153
}
154
if (!e.mDispatchToContentHitRegion.IsEmpty()) {
155
AppendToString(aStream, e.mDispatchToContentHitRegion,
156
" dispatchtocontentregion=", "");
157
}
158
if (!e.mNoActionRegion.IsEmpty()) {
159
AppendToString(aStream, e.mNoActionRegion, " NoActionRegion=", "");
160
}
161
if (!e.mHorizontalPanRegion.IsEmpty()) {
162
AppendToString(aStream, e.mHorizontalPanRegion,
163
" HorizontalPanRegion=", "");
164
}
165
if (!e.mVerticalPanRegion.IsEmpty()) {
166
AppendToString(aStream, e.mVerticalPanRegion, " VerticalPanRegion=", "");
167
}
168
aStream << "}" << sfx;
169
}
170
171
void AppendToString(std::stringstream& aStream, OverscrollBehavior aBehavior,
172
const char* pfx, const char* sfx) {
173
aStream << pfx;
174
switch (aBehavior) {
175
case OverscrollBehavior::Auto: {
176
aStream << "auto";
177
break;
178
}
179
case OverscrollBehavior::Contain: {
180
aStream << "contain";
181
break;
182
}
183
case OverscrollBehavior::None: {
184
aStream << "none";
185
break;
186
}
187
}
188
aStream << sfx;
189
}
190
191
void AppendToString(std::stringstream& aStream, const ScrollMetadata& m,
192
const char* pfx, const char* sfx) {
193
aStream << pfx;
194
AppendToString(aStream, m.GetMetrics(), "{ [metrics=");
195
AppendToString(aStream, m.GetBackgroundColor(), "] [color=");
196
if (m.GetScrollParentId() != ScrollableLayerGuid::NULL_SCROLL_ID) {
197
AppendToString(aStream, m.GetScrollParentId(), "] [scrollParent=");
198
}
199
if (m.HasScrollClip()) {
200
AppendToString(aStream, m.ScrollClip().GetClipRect(), "] [clip=");
201
}
202
if (m.HasMaskLayer()) {
203
AppendToString(aStream, m.ScrollClip().GetMaskLayerIndex().value(),
204
"] [mask=");
205
}
206
OverscrollBehavior overscrollX = m.GetOverscrollBehavior().mBehaviorX;
207
OverscrollBehavior overscrollY = m.GetOverscrollBehavior().mBehaviorY;
208
if (overscrollX == overscrollY && overscrollX != OverscrollBehavior::Auto) {
209
AppendToString(aStream, overscrollX, "] [overscroll=");
210
} else {
211
if (overscrollX != OverscrollBehavior::Auto) {
212
AppendToString(aStream, overscrollX, "] [overscroll-x=");
213
}
214
if (overscrollY != OverscrollBehavior::Auto) {
215
AppendToString(aStream, overscrollY, "] [overscroll-y=");
216
}
217
}
218
aStream << "] }" << sfx;
219
}
220
221
void AppendToString(std::stringstream& aStream, const FrameMetrics& m,
222
const char* pfx, const char* sfx, bool detailed) {
223
aStream << pfx;
224
AppendToString(aStream, m.GetCompositionBounds(), "{ [cb=");
225
AppendToString(aStream, m.GetScrollableRect(), "] [sr=");
226
AppendToString(aStream, m.GetScrollOffset(), "] [s=");
227
if (m.GetDoSmoothScroll()) {
228
AppendToString(aStream, m.GetSmoothScrollOffset(), "] [ss=");
229
}
230
AppendToString(aStream, m.GetDisplayPort(), "] [dp=");
231
AppendToString(aStream, m.GetCriticalDisplayPort(), "] [cdp=");
232
if (!detailed) {
233
AppendToString(aStream, m.GetScrollId(), "] [scrollId=");
234
if (m.IsRootContent()) {
235
aStream << "] [rcd";
236
}
237
AppendToString(aStream, m.GetZoom(), "] [z=", "] }");
238
} else {
239
AppendToString(aStream, m.GetDisplayPortMargins(), " [dpm=");
240
AppendToString(aStream, m.GetRootCompositionSize(), "] [rcs=");
241
AppendToString(aStream, m.GetLayoutViewport(), "] [v=");
242
aStream << nsPrintfCString("] [z=(ld=%.3f r=%.3f",
243
m.GetDevPixelsPerCSSPixel().scale,
244
m.GetPresShellResolution())
245
.get();
246
AppendToString(aStream, m.GetCumulativeResolution(), " cr=");
247
AppendToString(aStream, m.GetZoom(), " z=");
248
AppendToString(aStream, m.GetExtraResolution(), " er=");
249
aStream << nsPrintfCString(")] [u=(%d %d %" PRIu32 ")",
250
m.GetScrollUpdateType(), m.GetDoSmoothScroll(),
251
m.GetScrollGeneration())
252
.get();
253
aStream << nsPrintfCString("] [i=(%" PRIu32 " %" PRIu64 " %d)] }",
254
m.GetPresShellId(), m.GetScrollId(),
255
m.IsRootContent())
256
.get();
257
}
258
aStream << sfx;
259
}
260
261
void AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s,
262
const char* pfx, const char* sfx) {
263
aStream << pfx
264
<< nsPrintfCString("{ l=0x%" PRIx64 ", p=%u, v=%" PRIu64 " }",
265
uint64_t(s.mLayersId), s.mPresShellId, s.mScrollId)
266
.get()
267
<< sfx;
268
}
269
270
void AppendToString(std::stringstream& aStream, const ZoomConstraints& z,
271
const char* pfx, const char* sfx) {
272
aStream << pfx
273
<< nsPrintfCString("{ z=%d dt=%d min=%f max=%f }", z.mAllowZoom,
274
z.mAllowDoubleTapZoom, z.mMinZoom.scale,
275
z.mMaxZoom.scale)
276
.get()
277
<< sfx;
278
}
279
280
void AppendToString(std::stringstream& aStream, const Matrix& m,
281
const char* pfx, const char* sfx) {
282
aStream << pfx;
283
if (m.IsIdentity()) {
284
aStream << "[ I ]";
285
} else {
286
aStream << nsPrintfCString("[ %g %g; %g %g; %g %g; ]", m._11, m._12, m._21,
287
m._22, m._31, m._32)
288
.get();
289
}
290
aStream << sfx;
291
}
292
293
void AppendToString(std::stringstream& aStream, const Matrix5x4& m,
294
const char* pfx, const char* sfx) {
295
aStream << pfx;
296
aStream << nsPrintfCString(
297
"[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g "
298
"%g %g]",
299
m._11, m._12, m._13, m._14, m._21, m._22, m._23, m._24, m._31,
300
m._32, m._33, m._34, m._41, m._42, m._43, m._44, m._51, m._52,
301
m._53, m._54)
302
.get();
303
aStream << sfx;
304
}
305
306
void AppendToString(std::stringstream& aStream, const SamplingFilter filter,
307
const char* pfx, const char* sfx) {
308
aStream << pfx;
309
310
switch (filter) {
311
case SamplingFilter::GOOD:
312
aStream << "SamplingFilter::GOOD";
313
break;
314
case SamplingFilter::LINEAR:
315
aStream << "SamplingFilter::LINEAR";
316
break;
317
case SamplingFilter::POINT:
318
aStream << "SamplingFilter::POINT";
319
break;
320
default:
321
NS_ERROR("unknown SamplingFilter type");
322
aStream << "???";
323
}
324
aStream << sfx;
325
}
326
327
void AppendToString(std::stringstream& aStream, TextureFlags flags,
328
const char* pfx, const char* sfx) {
329
aStream << pfx;
330
if (flags == TextureFlags::NO_FLAGS) {
331
aStream << "NoFlags";
332
} else {
333
#define AppendFlag(test) \
334
{ \
335
if (!!(flags & test)) { \
336
if (previous) { \
337
aStream << "|"; \
338
} \
339
aStream << #test; \
340
previous = true; \
341
} \
342
}
343
bool previous = false;
344
AppendFlag(TextureFlags::USE_NEAREST_FILTER);
345
AppendFlag(TextureFlags::ORIGIN_BOTTOM_LEFT);
346
AppendFlag(TextureFlags::DISALLOW_BIGIMAGE);
347
348
#undef AppendFlag
349
}
350
aStream << sfx;
351
}
352
353
void AppendToString(std::stringstream& aStream,
354
mozilla::gfx::SurfaceFormat format, const char* pfx,
355
const char* sfx) {
356
aStream << pfx;
357
switch (format) {
358
case SurfaceFormat::B8G8R8A8:
359
aStream << "SurfaceFormat::B8G8R8A8";
360
break;
361
case SurfaceFormat::B8G8R8X8:
362
aStream << "SurfaceFormat::B8G8R8X8";
363
break;
364
case SurfaceFormat::R8G8B8A8:
365
aStream << "SurfaceFormat::R8G8B8A8";
366
break;
367
case SurfaceFormat::R8G8B8X8:
368
aStream << "SurfaceFormat::R8G8B8X8";
369
break;
370
case SurfaceFormat::R5G6B5_UINT16:
371
aStream << "SurfaceFormat::R5G6B5_UINT16";
372
break;
373
case SurfaceFormat::A8:
374
aStream << "SurfaceFormat::A8";
375
break;
376
case SurfaceFormat::YUV:
377
aStream << "SurfaceFormat::YUV";
378
break;
379
case SurfaceFormat::NV12:
380
aStream << "SurfaceFormat::NV12";
381
break;
382
case SurfaceFormat::P010:
383
aStream << "SurfaceFormat::P010";
384
break;
385
case SurfaceFormat::P016:
386
aStream << "SurfaceFormat::P016";
387
break;
388
case SurfaceFormat::YUV422:
389
aStream << "SurfaceFormat::YUV422";
390
break;
391
case SurfaceFormat::UNKNOWN:
392
aStream << "SurfaceFormat::UNKNOWN";
393
break;
394
default:
395
NS_ERROR("unknown surface format");
396
aStream << "???";
397
}
398
399
aStream << sfx;
400
}
401
402
void AppendToString(std::stringstream& aStream, gfx::SurfaceType aType,
403
const char* pfx, const char* sfx) {
404
aStream << pfx;
405
switch (aType) {
406
case SurfaceType::DATA:
407
aStream << "SurfaceType::DATA";
408
break;
409
case SurfaceType::D2D1_BITMAP:
410
aStream << "SurfaceType::D2D1_BITMAP";
411
break;
412
case SurfaceType::D2D1_DRAWTARGET:
413
aStream << "SurfaceType::D2D1_DRAWTARGET";
414
break;
415
case SurfaceType::CAIRO:
416
aStream << "SurfaceType::CAIRO";
417
break;
418
case SurfaceType::CAIRO_IMAGE:
419
aStream << "SurfaceType::CAIRO_IMAGE";
420
break;
421
case SurfaceType::COREGRAPHICS_IMAGE:
422
aStream << "SurfaceType::COREGRAPHICS_IMAGE";
423
break;
424
case SurfaceType::COREGRAPHICS_CGCONTEXT:
425
aStream << "SurfaceType::COREGRAPHICS_CGCONTEXT";
426
break;
427
case SurfaceType::SKIA:
428
aStream << "SurfaceType::SKIA";
429
break;
430
case SurfaceType::DUAL_DT:
431
aStream << "SurfaceType::DUAL_DT";
432
break;
433
case SurfaceType::D2D1_1_IMAGE:
434
aStream << "SurfaceType::D2D1_1_IMAGE";
435
break;
436
case SurfaceType::RECORDING:
437
aStream << "SurfaceType::RECORDING";
438
break;
439
case SurfaceType::WRAP_AND_RECORD:
440
aStream << "SurfaceType::WRAP_AND_RECORD";
441
break;
442
case SurfaceType::TILED:
443
aStream << "SurfaceType::TILED";
444
break;
445
case SurfaceType::DATA_SHARED:
446
aStream << "SurfaceType::DATA_SHARED";
447
break;
448
case SurfaceType::DATA_RECYCLING_SHARED:
449
aStream << "SurfaceType::DATA_RECYCLING_SHARED";
450
break;
451
case SurfaceType::DATA_ALIGNED:
452
aStream << "SurfaceType::DATA_ALIGNED";
453
break;
454
default:
455
NS_ERROR("unknown surface type");
456
aStream << "???";
457
}
458
aStream << sfx;
459
}
460
461
void AppendToString(std::stringstream& aStream, ImageFormat format,
462
const char* pfx, const char* sfx) {
463
aStream << pfx;
464
switch (format) {
465
case ImageFormat::PLANAR_YCBCR:
466
aStream << "ImageFormat::PLANAR_YCBCR";
467
break;
468
case ImageFormat::SHARED_RGB:
469
aStream << "ImageFormat::SHARED_RGB";
470
break;
471
case ImageFormat::CAIRO_SURFACE:
472
aStream << "ImageFormat::CAIRO_SURFACE";
473
break;
474
case ImageFormat::MAC_IOSURFACE:
475
aStream << "ImageFormat::MAC_IOSURFACE";
476
break;
477
case ImageFormat::SURFACE_TEXTURE:
478
aStream << "ImageFormat::SURFACE_TEXTURE";
479
break;
480
case ImageFormat::D3D9_RGB32_TEXTURE:
481
aStream << "ImageFormat::D3D9_RBG32_TEXTURE";
482
break;
483
case ImageFormat::OVERLAY_IMAGE:
484
aStream << "ImageFormat::OVERLAY_IMAGE";
485
break;
486
case ImageFormat::D3D11_SHARE_HANDLE_TEXTURE:
487
aStream << "ImageFormat::D3D11_SHARE_HANDLE_TEXTURE";
488
break;
489
default:
490
NS_ERROR("unknown image format");
491
aStream << "???";
492
}
493
494
aStream << sfx;
495
}
496
497
} // namespace layers
498
} // namespace mozilla
499
500
void print_stderr(std::stringstream& aStr) {
501
#if defined(ANDROID)
502
// On Android logcat output is truncated to 1024 chars per line, and
503
// we usually use std::stringstream to build up giant multi-line gobs
504
// of output. So to avoid the truncation we find the newlines and
505
// print the lines individually.
506
std::string line;
507
while (std::getline(aStr, line)) {
508
printf_stderr("%s\n", line.c_str());
509
}
510
#else
511
printf_stderr("%s", aStr.str().c_str());
512
#endif
513
}
514
515
void fprint_stderr(FILE* aFile, std::stringstream& aStr) {
516
if (aFile == stderr) {
517
print_stderr(aStr);
518
} else {
519
fprintf_stderr(aFile, "%s", aStr.str().c_str());
520
}
521
}