1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "LayersLogging.h"
9 #include <stdint.h> // for uint8_t
10 #include "gfxColor.h" // for gfxRGBA
11 #include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix
12 #include "nsDebug.h" // for NS_ERROR
13 #include "nsPoint.h" // for nsIntPoint
14 #include "nsRect.h" // for nsIntRect
15 #include "nsSize.h" // for nsIntSize
17 using namespace mozilla::gfx
;
23 AppendToString(std::stringstream
& aStream
, const void* p
,
24 const char* pfx
, const char* sfx
)
27 aStream
<< nsPrintfCString("%p", p
).get();
32 AppendToString(std::stringstream
& aStream
, const GraphicsFilter
& f
,
33 const char* pfx
, const char* sfx
)
37 case GraphicsFilter::FILTER_FAST
: aStream
<< "fast"; break;
38 case GraphicsFilter::FILTER_GOOD
: aStream
<< "good"; break;
39 case GraphicsFilter::FILTER_BEST
: aStream
<< "best"; break;
40 case GraphicsFilter::FILTER_NEAREST
: aStream
<< "nearest"; break;
41 case GraphicsFilter::FILTER_BILINEAR
: aStream
<< "bilinear"; break;
42 case GraphicsFilter::FILTER_GAUSSIAN
: aStream
<< "gaussian"; break;
44 NS_ERROR("unknown filter type");
51 AppendToString(std::stringstream
& aStream
, FrameMetrics::ViewID n
,
52 const char* pfx
, const char* sfx
)
60 AppendToString(std::stringstream
& aStream
, const gfxRGBA
& c
,
61 const char* pfx
, const char* sfx
)
64 aStream
<< nsPrintfCString(
65 "rgba(%d, %d, %d, %g)",
66 uint8_t(c
.r
*255.0), uint8_t(c
.g
*255.0), uint8_t(c
.b
*255.0), c
.a
).get();
71 AppendToString(std::stringstream
& aStream
, const nsPoint
& p
,
72 const char* pfx
, const char* sfx
)
75 aStream
<< nsPrintfCString("(x=%d, y=%d)", p
.x
, p
.y
).get();
80 AppendToString(std::stringstream
& aStream
, const nsRect
& r
,
81 const char* pfx
, const char* sfx
)
84 aStream
<< nsPrintfCString(
85 "(x=%d, y=%d, w=%d, h=%d)",
86 r
.x
, r
.y
, r
.width
, r
.height
).get();
91 AppendToString(std::stringstream
& aStream
, const nsIntPoint
& p
,
92 const char* pfx
, const char* sfx
)
95 aStream
<< nsPrintfCString("(x=%d, y=%d)", p
.x
, p
.y
).get();
100 AppendToString(std::stringstream
& aStream
, const nsIntRect
& r
,
101 const char* pfx
, const char* sfx
)
104 aStream
<< nsPrintfCString(
105 "(x=%d, y=%d, w=%d, h=%d)",
106 r
.x
, r
.y
, r
.width
, r
.height
).get();
111 AppendToString(std::stringstream
& aStream
, const nsRegion
& r
,
112 const char* pfx
, const char* sfx
)
116 nsRegionRectIterator
it(r
);
118 while (const nsRect
* sr
= it
.Next()) {
119 AppendToString(aStream
, *sr
);
128 AppendToString(std::stringstream
& aStream
, const nsIntRegion
& r
,
129 const char* pfx
, const char* sfx
)
133 nsIntRegionRectIterator
it(r
);
135 while (const nsIntRect
* sr
= it
.Next()) {
136 AppendToString(aStream
, *sr
);
145 AppendToString(std::stringstream
& aStream
, const EventRegions
& e
,
146 const char* pfx
, const char* sfx
)
148 aStream
<< pfx
<< "{";
149 if (!e
.mHitRegion
.IsEmpty()) {
150 AppendToString(aStream
, e
.mHitRegion
, " hitregion=", "");
152 if (!e
.mDispatchToContentHitRegion
.IsEmpty()) {
153 AppendToString(aStream
, e
.mDispatchToContentHitRegion
, " dispatchtocontentregion=", "");
155 aStream
<< "}" << sfx
;
159 AppendToString(std::stringstream
& aStream
, const nsIntSize
& sz
,
160 const char* pfx
, const char* sfx
)
163 aStream
<< nsPrintfCString("(w=%d, h=%d)", sz
.width
, sz
.height
).get();
168 AppendToString(std::stringstream
& aStream
, const FrameMetrics
& m
,
169 const char* pfx
, const char* sfx
, bool detailed
)
172 AppendToString(aStream
, m
.mCompositionBounds
, "{ [cb=");
173 AppendToString(aStream
, m
.GetScrollableRect(), "] [sr=");
174 AppendToString(aStream
, m
.GetScrollOffset(), "] [s=");
175 if (m
.GetDoSmoothScroll()) {
176 AppendToString(aStream
, m
.GetSmoothScrollOffset(), "] [ss=");
178 AppendToString(aStream
, m
.GetDisplayPort(), "] [dp=");
179 AppendToString(aStream
, m
.GetCriticalDisplayPort(), "] [cdp=");
180 AppendToString(aStream
, m
.GetBackgroundColor(), "] [color=");
182 AppendToString(aStream
, m
.GetScrollId(), "] [scrollId=");
183 if (m
.GetScrollParentId() != FrameMetrics::NULL_SCROLL_ID
) {
184 AppendToString(aStream
, m
.GetScrollParentId(), "] [scrollParent=");
186 aStream
<< nsPrintfCString("] [z=%.3f] }", m
.GetZoom().scale
).get();
188 AppendToString(aStream
, m
.GetDisplayPortMargins(), " [dpm=");
189 aStream
<< nsPrintfCString("] um=%d", m
.GetUseDisplayPortMargins()).get();
190 AppendToString(aStream
, m
.GetRootCompositionSize(), "] [rcs=");
191 AppendToString(aStream
, m
.GetViewport(), "] [v=");
192 aStream
<< nsPrintfCString("] [z=(ld=%.3f r=%.3f cr=%.3f z=%.3f er=%.3f)",
193 m
.GetDevPixelsPerCSSPixel().scale
, m
.mPresShellResolution
,
194 m
.GetCumulativeResolution().scale
, m
.GetZoom().scale
,
195 m
.GetExtraResolution().scale
).get();
196 aStream
<< nsPrintfCString("] [u=(%d %d %lu)",
197 m
.GetScrollOffsetUpdated(), m
.GetDoSmoothScroll(),
198 m
.GetScrollGeneration()).get();
199 AppendToString(aStream
, m
.GetScrollParentId(), "] [p=");
200 aStream
<< nsPrintfCString("] [i=(%ld %lld)] }",
201 m
.GetPresShellId(), m
.GetScrollId()).get();
207 AppendToString(std::stringstream
& aStream
, const ScrollableLayerGuid
& s
,
208 const char* pfx
, const char* sfx
)
211 << nsPrintfCString("{ l=%llu, p=%u, v=%llu }", s
.mLayersId
, s
.mPresShellId
, s
.mScrollId
).get()
216 AppendToString(std::stringstream
& aStream
, const Matrix4x4
& m
,
217 const char* pfx
, const char* sfx
)
221 Matrix matrix
= m
.As2D();
222 if (matrix
.IsIdentity()) {
227 aStream
<< nsPrintfCString(
228 "[ %g %g; %g %g; %g %g; ]",
229 matrix
._11
, matrix
._12
, matrix
._21
, matrix
._22
, matrix
._31
, matrix
._32
).get();
231 aStream
<< nsPrintfCString(
232 "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]",
233 m
._11
, m
._12
, m
._13
, m
._14
,
234 m
._21
, m
._22
, m
._23
, m
._24
,
235 m
._31
, m
._32
, m
._33
, m
._34
,
236 m
._41
, m
._42
, m
._43
, m
._44
).get();
242 AppendToString(std::stringstream
& aStream
, const Matrix5x4
& m
,
243 const char* pfx
, const char* sfx
)
246 aStream
<< nsPrintfCString(
247 "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]",
248 m
._11
, m
._12
, m
._13
, m
._14
,
249 m
._21
, m
._22
, m
._23
, m
._24
,
250 m
._31
, m
._32
, m
._33
, m
._34
,
251 m
._41
, m
._42
, m
._43
, m
._44
,
252 m
._51
, m
._52
, m
._53
, m
._54
).get();
258 AppendToString(std::stringstream
& aStream
, const Filter filter
,
259 const char* pfx
, const char* sfx
)
264 case Filter::GOOD
: aStream
<< "Filter::GOOD"; break;
265 case Filter::LINEAR
: aStream
<< "Filter::LINEAR"; break;
266 case Filter::POINT
: aStream
<< "Filter::POINT"; break;
272 AppendToString(std::stringstream
& aStream
, TextureFlags flags
,
273 const char* pfx
, const char* sfx
)
276 if (flags
== TextureFlags::NO_FLAGS
) {
277 aStream
<< "NoFlags";
280 #define AppendFlag(test) \
282 if (!!(flags & test)) { \
290 bool previous
= false;
291 AppendFlag(TextureFlags::USE_NEAREST_FILTER
);
292 AppendFlag(TextureFlags::ORIGIN_BOTTOM_LEFT
);
293 AppendFlag(TextureFlags::DISALLOW_BIGIMAGE
);
301 AppendToString(std::stringstream
& aStream
, mozilla::gfx::SurfaceFormat format
,
302 const char* pfx
, const char* sfx
)
306 case SurfaceFormat::B8G8R8A8
: aStream
<< "SurfaceFormat::B8G8R8A8"; break;
307 case SurfaceFormat::B8G8R8X8
: aStream
<< "SurfaceFormat::B8G8R8X8"; break;
308 case SurfaceFormat::R8G8B8A8
: aStream
<< "SurfaceFormat::R8G8B8A8"; break;
309 case SurfaceFormat::R8G8B8X8
: aStream
<< "SurfaceFormat::R8G8B8X8"; break;
310 case SurfaceFormat::R5G6B5
: aStream
<< "SurfaceFormat::R5G6B5"; break;
311 case SurfaceFormat::A8
: aStream
<< "SurfaceFormat::A8"; break;
312 case SurfaceFormat::YUV
: aStream
<< "SurfaceFormat::YUV"; break;
313 case SurfaceFormat::UNKNOWN
: aStream
<< "SurfaceFormat::UNKNOWN"; break;
323 print_stderr(std::stringstream
& aStr
)
326 // On Android logcat output is truncated to 1024 chars per line, and
327 // we usually use std::stringstream to build up giant multi-line gobs
328 // of output. So to avoid the truncation we find the newlines and
329 // print the lines individually.
331 while (std::getline(aStr
, line
)) {
332 printf_stderr("%s\n", line
.c_str());
335 printf_stderr("%s", aStr
.str().c_str());
340 fprint_stderr(FILE* aFile
, std::stringstream
& aStr
)
342 if (aFile
== stderr
) {
345 fprintf_stderr(aFile
, "%s", aStr
.str().c_str());