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