Bumping manifests a=b2g-bump
[gecko.git] / gfx / layers / LayersLogging.cpp
blob7d68e8f692f6c81ac0e68324427aabdfae350d42
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 */
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;
19 namespace mozilla {
20 namespace layers {
22 void
23 AppendToString(std::stringstream& aStream, const void* p,
24 const char* pfx, const char* sfx)
26 aStream << pfx;
27 aStream << nsPrintfCString("%p", p).get();
28 aStream << sfx;
31 void
32 AppendToString(std::stringstream& aStream, const GraphicsFilter& f,
33 const char* pfx, const char* sfx)
35 aStream << pfx;
36 switch (f) {
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;
43 default:
44 NS_ERROR("unknown filter type");
45 aStream << "???";
47 aStream << sfx;
50 void
51 AppendToString(std::stringstream& aStream, FrameMetrics::ViewID n,
52 const char* pfx, const char* sfx)
54 aStream << pfx;
55 aStream << n;
56 aStream << sfx;
59 void
60 AppendToString(std::stringstream& aStream, const gfxRGBA& c,
61 const char* pfx, const char* sfx)
63 aStream << pfx;
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();
67 aStream << sfx;
70 void
71 AppendToString(std::stringstream& aStream, const nsPoint& p,
72 const char* pfx, const char* sfx)
74 aStream << pfx;
75 aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
76 aStream << sfx;
79 void
80 AppendToString(std::stringstream& aStream, const nsRect& r,
81 const char* pfx, const char* sfx)
83 aStream << pfx;
84 aStream << nsPrintfCString(
85 "(x=%d, y=%d, w=%d, h=%d)",
86 r.x, r.y, r.width, r.height).get();
87 aStream << sfx;
90 void
91 AppendToString(std::stringstream& aStream, const nsIntPoint& p,
92 const char* pfx, const char* sfx)
94 aStream << pfx;
95 aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
96 aStream << sfx;
99 void
100 AppendToString(std::stringstream& aStream, const nsIntRect& r,
101 const char* pfx, const char* sfx)
103 aStream << pfx;
104 aStream << nsPrintfCString(
105 "(x=%d, y=%d, w=%d, h=%d)",
106 r.x, r.y, r.width, r.height).get();
107 aStream << sfx;
110 void
111 AppendToString(std::stringstream& aStream, const nsRegion& r,
112 const char* pfx, const char* sfx)
114 aStream << pfx;
116 nsRegionRectIterator it(r);
117 aStream << "< ";
118 while (const nsRect* sr = it.Next()) {
119 AppendToString(aStream, *sr);
120 aStream << "; ";
122 aStream << ">";
124 aStream << sfx;
127 void
128 AppendToString(std::stringstream& aStream, const nsIntRegion& r,
129 const char* pfx, const char* sfx)
131 aStream << pfx;
133 nsIntRegionRectIterator it(r);
134 aStream << "< ";
135 while (const nsIntRect* sr = it.Next()) {
136 AppendToString(aStream, *sr);
137 aStream << "; ";
139 aStream << ">";
141 aStream << sfx;
144 void
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;
158 void
159 AppendToString(std::stringstream& aStream, const nsIntSize& sz,
160 const char* pfx, const char* sfx)
162 aStream << pfx;
163 aStream << nsPrintfCString("(w=%d, h=%d)", sz.width, sz.height).get();
164 aStream << sfx;
167 void
168 AppendToString(std::stringstream& aStream, const FrameMetrics& m,
169 const char* pfx, const char* sfx, bool detailed)
171 aStream << pfx;
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=");
181 if (!detailed) {
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();
187 } else {
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();
203 aStream << sfx;
206 void
207 AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s,
208 const char* pfx, const char* sfx)
210 aStream << pfx
211 << nsPrintfCString("{ l=%llu, p=%u, v=%llu }", s.mLayersId, s.mPresShellId, s.mScrollId).get()
212 << sfx;
215 void
216 AppendToString(std::stringstream& aStream, const Matrix4x4& m,
217 const char* pfx, const char* sfx)
219 aStream << pfx;
220 if (m.Is2D()) {
221 Matrix matrix = m.As2D();
222 if (matrix.IsIdentity()) {
223 aStream << "[ I ]";
224 aStream << sfx;
225 return;
227 aStream << nsPrintfCString(
228 "[ %g %g; %g %g; %g %g; ]",
229 matrix._11, matrix._12, matrix._21, matrix._22, matrix._31, matrix._32).get();
230 } else {
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();
238 aStream << sfx;
241 void
242 AppendToString(std::stringstream& aStream, const Matrix5x4& m,
243 const char* pfx, const char* sfx)
245 aStream << pfx;
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();
253 aStream << sfx;
257 void
258 AppendToString(std::stringstream& aStream, const Filter filter,
259 const char* pfx, const char* sfx)
261 aStream << pfx;
263 switch (filter) {
264 case Filter::GOOD: aStream << "Filter::GOOD"; break;
265 case Filter::LINEAR: aStream << "Filter::LINEAR"; break;
266 case Filter::POINT: aStream << "Filter::POINT"; break;
268 aStream << sfx;
271 void
272 AppendToString(std::stringstream& aStream, TextureFlags flags,
273 const char* pfx, const char* sfx)
275 aStream << pfx;
276 if (flags == TextureFlags::NO_FLAGS) {
277 aStream << "NoFlags";
278 } else {
280 #define AppendFlag(test) \
282 if (!!(flags & test)) { \
283 if (previous) { \
284 aStream << "|"; \
286 aStream << #test; \
287 previous = true; \
290 bool previous = false;
291 AppendFlag(TextureFlags::USE_NEAREST_FILTER);
292 AppendFlag(TextureFlags::ORIGIN_BOTTOM_LEFT);
293 AppendFlag(TextureFlags::DISALLOW_BIGIMAGE);
295 #undef AppendFlag
297 aStream << sfx;
300 void
301 AppendToString(std::stringstream& aStream, mozilla::gfx::SurfaceFormat format,
302 const char* pfx, const char* sfx)
304 aStream << pfx;
305 switch (format) {
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;
316 aStream << sfx;
319 } // namespace
320 } // namespace
322 void
323 print_stderr(std::stringstream& aStr)
325 #if defined(ANDROID)
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.
330 std::string line;
331 while (std::getline(aStr, line)) {
332 printf_stderr("%s\n", line.c_str());
334 #else
335 printf_stderr("%s", aStr.str().c_str());
336 #endif
339 void
340 fprint_stderr(FILE* aFile, std::stringstream& aStr)
342 if (aFile == stderr) {
343 print_stderr(aStr);
344 } else {
345 fprintf_stderr(aFile, "%s", aStr.str().c_str());