Coverage Report

Created: 2018-09-25 14:53

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