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.

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

mercurial