gfx/layers/LayersLogging.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "LayersLogging.h"
michael@0 9 #include <stdint.h> // for uint8_t
michael@0 10 #include "gfx3DMatrix.h" // for gfx3DMatrix
michael@0 11 #include "gfxColor.h" // for gfxRGBA
michael@0 12 #include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix
michael@0 13 #include "nsDebug.h" // for NS_ERROR
michael@0 14 #include "nsPoint.h" // for nsIntPoint
michael@0 15 #include "nsRect.h" // for nsIntRect
michael@0 16 #include "nsSize.h" // for nsIntSize
michael@0 17
michael@0 18 using namespace mozilla::gfx;
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 namespace layers {
michael@0 22
michael@0 23 nsACString&
michael@0 24 AppendToString(nsACString& s, const void* p,
michael@0 25 const char* pfx, const char* sfx)
michael@0 26 {
michael@0 27 s += pfx;
michael@0 28 s += nsPrintfCString("%p", p);
michael@0 29 return s += sfx;
michael@0 30 }
michael@0 31
michael@0 32 nsACString&
michael@0 33 AppendToString(nsACString& s, const GraphicsFilter& f,
michael@0 34 const char* pfx, const char* sfx)
michael@0 35 {
michael@0 36 s += pfx;
michael@0 37 switch (f) {
michael@0 38 case GraphicsFilter::FILTER_FAST: s += "fast"; break;
michael@0 39 case GraphicsFilter::FILTER_GOOD: s += "good"; break;
michael@0 40 case GraphicsFilter::FILTER_BEST: s += "best"; break;
michael@0 41 case GraphicsFilter::FILTER_NEAREST: s += "nearest"; break;
michael@0 42 case GraphicsFilter::FILTER_BILINEAR: s += "bilinear"; break;
michael@0 43 case GraphicsFilter::FILTER_GAUSSIAN: s += "gaussian"; break;
michael@0 44 default:
michael@0 45 NS_ERROR("unknown filter type");
michael@0 46 s += "???";
michael@0 47 }
michael@0 48 return s += sfx;
michael@0 49 }
michael@0 50
michael@0 51 nsACString&
michael@0 52 AppendToString(nsACString& s, FrameMetrics::ViewID n,
michael@0 53 const char* pfx, const char* sfx)
michael@0 54 {
michael@0 55 s += pfx;
michael@0 56 s.AppendInt(n);
michael@0 57 return s += sfx;
michael@0 58 }
michael@0 59
michael@0 60 nsACString&
michael@0 61 AppendToString(nsACString& s, const gfxRGBA& c,
michael@0 62 const char* pfx, const char* sfx)
michael@0 63 {
michael@0 64 s += pfx;
michael@0 65 s += nsPrintfCString(
michael@0 66 "rgba(%d, %d, %d, %g)",
michael@0 67 uint8_t(c.r*255.0), uint8_t(c.g*255.0), uint8_t(c.b*255.0), c.a);
michael@0 68 return s += sfx;
michael@0 69 }
michael@0 70
michael@0 71 nsACString&
michael@0 72 AppendToString(nsACString& s, const nsIntPoint& p,
michael@0 73 const char* pfx, const char* sfx)
michael@0 74 {
michael@0 75 s += pfx;
michael@0 76 s += nsPrintfCString("(x=%d, y=%d)", p.x, p.y);
michael@0 77 return s += sfx;
michael@0 78 }
michael@0 79
michael@0 80 nsACString&
michael@0 81 AppendToString(nsACString& s, const nsIntRect& r,
michael@0 82 const char* pfx, const char* sfx)
michael@0 83 {
michael@0 84 s += pfx;
michael@0 85 s += nsPrintfCString(
michael@0 86 "(x=%d, y=%d, w=%d, h=%d)",
michael@0 87 r.x, r.y, r.width, r.height);
michael@0 88 return s += sfx;
michael@0 89 }
michael@0 90
michael@0 91 nsACString&
michael@0 92 AppendToString(nsACString& s, const nsIntRegion& r,
michael@0 93 const char* pfx, const char* sfx)
michael@0 94 {
michael@0 95 s += pfx;
michael@0 96
michael@0 97 nsIntRegionRectIterator it(r);
michael@0 98 s += "< ";
michael@0 99 while (const nsIntRect* sr = it.Next())
michael@0 100 AppendToString(s, *sr) += "; ";
michael@0 101 s += ">";
michael@0 102
michael@0 103 return s += sfx;
michael@0 104 }
michael@0 105
michael@0 106 nsACString&
michael@0 107 AppendToString(nsACString& s, const nsIntSize& sz,
michael@0 108 const char* pfx, const char* sfx)
michael@0 109 {
michael@0 110 s += pfx;
michael@0 111 s += nsPrintfCString("(w=%d, h=%d)", sz.width, sz.height);
michael@0 112 return s += sfx;
michael@0 113 }
michael@0 114
michael@0 115 nsACString&
michael@0 116 AppendToString(nsACString& s, const FrameMetrics& m,
michael@0 117 const char* pfx, const char* sfx)
michael@0 118 {
michael@0 119 s += pfx;
michael@0 120 AppendToString(s, m.mViewport, "{ viewport=");
michael@0 121 AppendToString(s, m.GetScrollOffset(), " viewportScroll=");
michael@0 122 AppendToString(s, m.mDisplayPort, " displayport=");
michael@0 123 AppendToString(s, m.mScrollableRect, " scrollableRect=");
michael@0 124 AppendToString(s, m.GetScrollId(), " scrollId=", " }");
michael@0 125 return s += sfx;
michael@0 126 }
michael@0 127
michael@0 128 nsACString&
michael@0 129 AppendToString(nsACString& s, const IntSize& size,
michael@0 130 const char* pfx, const char* sfx)
michael@0 131 {
michael@0 132 s += pfx;
michael@0 133 s += nsPrintfCString(
michael@0 134 "(width=%d, height=%d)",
michael@0 135 size.width, size.height);
michael@0 136 return s += sfx;
michael@0 137 }
michael@0 138
michael@0 139 nsACString&
michael@0 140 AppendToString(nsACString& s, const Matrix4x4& m,
michael@0 141 const char* pfx, const char* sfx)
michael@0 142 {
michael@0 143 s += pfx;
michael@0 144 if (m.Is2D()) {
michael@0 145 Matrix matrix = m.As2D();
michael@0 146 if (matrix.IsIdentity()) {
michael@0 147 s += "[ I ]";
michael@0 148 return s += sfx;
michael@0 149 }
michael@0 150 s += nsPrintfCString(
michael@0 151 "[ %g %g; %g %g; %g %g; ]",
michael@0 152 matrix._11, matrix._12, matrix._21, matrix._22, matrix._31, matrix._32);
michael@0 153 } else {
michael@0 154 s += nsPrintfCString(
michael@0 155 "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]",
michael@0 156 m._11, m._12, m._13, m._14,
michael@0 157 m._21, m._22, m._23, m._24,
michael@0 158 m._31, m._32, m._33, m._34,
michael@0 159 m._41, m._42, m._43, m._44);
michael@0 160 }
michael@0 161 return s += sfx;
michael@0 162 }
michael@0 163
michael@0 164 nsACString&
michael@0 165 AppendToString(nsACString& s, const Filter filter,
michael@0 166 const char* pfx, const char* sfx)
michael@0 167 {
michael@0 168 s += pfx;
michael@0 169
michael@0 170 switch (filter) {
michael@0 171 case Filter::GOOD: s += "Filter::GOOD"; break;
michael@0 172 case Filter::LINEAR: s += "Filter::LINEAR"; break;
michael@0 173 case Filter::POINT: s += "Filter::POINT"; break;
michael@0 174 }
michael@0 175 return s += sfx;
michael@0 176 }
michael@0 177
michael@0 178 nsACString&
michael@0 179 AppendToString(nsACString& s, TextureFlags flags,
michael@0 180 const char* pfx, const char* sfx)
michael@0 181 {
michael@0 182 s += pfx;
michael@0 183 if (!flags) {
michael@0 184 s += "NoFlags";
michael@0 185 } else {
michael@0 186
michael@0 187 #define AppendFlag(test) \
michael@0 188 { \
michael@0 189 if (flags & test) { \
michael@0 190 if (previous) { \
michael@0 191 s += "|"; \
michael@0 192 } \
michael@0 193 s += #test; \
michael@0 194 previous = true; \
michael@0 195 } \
michael@0 196 }
michael@0 197 bool previous = false;
michael@0 198 AppendFlag(TEXTURE_USE_NEAREST_FILTER);
michael@0 199 AppendFlag(TEXTURE_NEEDS_Y_FLIP);
michael@0 200 AppendFlag(TEXTURE_DISALLOW_BIGIMAGE);
michael@0 201 AppendFlag(TEXTURE_ALLOW_REPEAT);
michael@0 202 AppendFlag(TEXTURE_NEW_TILE);
michael@0 203
michael@0 204 #undef AppendFlag
michael@0 205 }
michael@0 206 return s += sfx;
michael@0 207 }
michael@0 208
michael@0 209 nsACString&
michael@0 210 AppendToString(nsACString& s, mozilla::gfx::SurfaceFormat format,
michael@0 211 const char* pfx, const char* sfx)
michael@0 212 {
michael@0 213 s += pfx;
michael@0 214 switch (format) {
michael@0 215 case SurfaceFormat::B8G8R8A8: s += "SurfaceFormat::B8G8R8A8"; break;
michael@0 216 case SurfaceFormat::B8G8R8X8: s += "SurfaceFormat::B8G8R8X8"; break;
michael@0 217 case SurfaceFormat::R8G8B8A8: s += "SurfaceFormat::R8G8B8A8"; break;
michael@0 218 case SurfaceFormat::R8G8B8X8: s += "SurfaceFormat::R8G8B8X8"; break;
michael@0 219 case SurfaceFormat::R5G6B5: s += "SurfaceFormat::R5G6B5"; break;
michael@0 220 case SurfaceFormat::A8: s += "SurfaceFormat::A8"; break;
michael@0 221 case SurfaceFormat::YUV: s += "SurfaceFormat::YUV"; break;
michael@0 222 case SurfaceFormat::UNKNOWN: s += "SurfaceFormat::UNKNOWN"; break;
michael@0 223 }
michael@0 224
michael@0 225 return s += sfx;
michael@0 226 }
michael@0 227
michael@0 228 } // namespace
michael@0 229 } // namespace

mercurial