michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "LayersLogging.h" michael@0: #include // for uint8_t michael@0: #include "gfx3DMatrix.h" // for gfx3DMatrix michael@0: #include "gfxColor.h" // for gfxRGBA michael@0: #include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix michael@0: #include "nsDebug.h" // for NS_ERROR michael@0: #include "nsPoint.h" // for nsIntPoint michael@0: #include "nsRect.h" // for nsIntRect michael@0: #include "nsSize.h" // for nsIntSize michael@0: michael@0: using namespace mozilla::gfx; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const void* p, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString("%p", p); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const GraphicsFilter& f, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: switch (f) { michael@0: case GraphicsFilter::FILTER_FAST: s += "fast"; break; michael@0: case GraphicsFilter::FILTER_GOOD: s += "good"; break; michael@0: case GraphicsFilter::FILTER_BEST: s += "best"; break; michael@0: case GraphicsFilter::FILTER_NEAREST: s += "nearest"; break; michael@0: case GraphicsFilter::FILTER_BILINEAR: s += "bilinear"; break; michael@0: case GraphicsFilter::FILTER_GAUSSIAN: s += "gaussian"; break; michael@0: default: michael@0: NS_ERROR("unknown filter type"); michael@0: s += "???"; michael@0: } michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, FrameMetrics::ViewID n, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s.AppendInt(n); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const gfxRGBA& c, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString( michael@0: "rgba(%d, %d, %d, %g)", michael@0: uint8_t(c.r*255.0), uint8_t(c.g*255.0), uint8_t(c.b*255.0), c.a); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const nsIntPoint& p, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString("(x=%d, y=%d)", p.x, p.y); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const nsIntRect& r, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString( michael@0: "(x=%d, y=%d, w=%d, h=%d)", michael@0: r.x, r.y, r.width, r.height); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const nsIntRegion& r, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: michael@0: nsIntRegionRectIterator it(r); michael@0: s += "< "; michael@0: while (const nsIntRect* sr = it.Next()) michael@0: AppendToString(s, *sr) += "; "; michael@0: s += ">"; michael@0: michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const nsIntSize& sz, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString("(w=%d, h=%d)", sz.width, sz.height); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const FrameMetrics& m, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: AppendToString(s, m.mViewport, "{ viewport="); michael@0: AppendToString(s, m.GetScrollOffset(), " viewportScroll="); michael@0: AppendToString(s, m.mDisplayPort, " displayport="); michael@0: AppendToString(s, m.mScrollableRect, " scrollableRect="); michael@0: AppendToString(s, m.GetScrollId(), " scrollId=", " }"); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const IntSize& size, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: s += nsPrintfCString( michael@0: "(width=%d, height=%d)", michael@0: size.width, size.height); michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const Matrix4x4& m, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: if (m.Is2D()) { michael@0: Matrix matrix = m.As2D(); michael@0: if (matrix.IsIdentity()) { michael@0: s += "[ I ]"; michael@0: return s += sfx; michael@0: } michael@0: s += nsPrintfCString( michael@0: "[ %g %g; %g %g; %g %g; ]", michael@0: matrix._11, matrix._12, matrix._21, matrix._22, matrix._31, matrix._32); michael@0: } else { michael@0: s += nsPrintfCString( michael@0: "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]", michael@0: m._11, m._12, m._13, m._14, michael@0: m._21, m._22, m._23, m._24, michael@0: m._31, m._32, m._33, m._34, michael@0: m._41, m._42, m._43, m._44); michael@0: } michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, const Filter filter, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: michael@0: switch (filter) { michael@0: case Filter::GOOD: s += "Filter::GOOD"; break; michael@0: case Filter::LINEAR: s += "Filter::LINEAR"; break; michael@0: case Filter::POINT: s += "Filter::POINT"; break; michael@0: } michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, TextureFlags flags, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: if (!flags) { michael@0: s += "NoFlags"; michael@0: } else { michael@0: michael@0: #define AppendFlag(test) \ michael@0: { \ michael@0: if (flags & test) { \ michael@0: if (previous) { \ michael@0: s += "|"; \ michael@0: } \ michael@0: s += #test; \ michael@0: previous = true; \ michael@0: } \ michael@0: } michael@0: bool previous = false; michael@0: AppendFlag(TEXTURE_USE_NEAREST_FILTER); michael@0: AppendFlag(TEXTURE_NEEDS_Y_FLIP); michael@0: AppendFlag(TEXTURE_DISALLOW_BIGIMAGE); michael@0: AppendFlag(TEXTURE_ALLOW_REPEAT); michael@0: AppendFlag(TEXTURE_NEW_TILE); michael@0: michael@0: #undef AppendFlag michael@0: } michael@0: return s += sfx; michael@0: } michael@0: michael@0: nsACString& michael@0: AppendToString(nsACString& s, mozilla::gfx::SurfaceFormat format, michael@0: const char* pfx, const char* sfx) michael@0: { michael@0: s += pfx; michael@0: switch (format) { michael@0: case SurfaceFormat::B8G8R8A8: s += "SurfaceFormat::B8G8R8A8"; break; michael@0: case SurfaceFormat::B8G8R8X8: s += "SurfaceFormat::B8G8R8X8"; break; michael@0: case SurfaceFormat::R8G8B8A8: s += "SurfaceFormat::R8G8B8A8"; break; michael@0: case SurfaceFormat::R8G8B8X8: s += "SurfaceFormat::R8G8B8X8"; break; michael@0: case SurfaceFormat::R5G6B5: s += "SurfaceFormat::R5G6B5"; break; michael@0: case SurfaceFormat::A8: s += "SurfaceFormat::A8"; break; michael@0: case SurfaceFormat::YUV: s += "SurfaceFormat::YUV"; break; michael@0: case SurfaceFormat::UNKNOWN: s += "SurfaceFormat::UNKNOWN"; break; michael@0: } michael@0: michael@0: return s += sfx; michael@0: } michael@0: michael@0: } // namespace michael@0: } // namespace