tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageMemoryReporter.h (3473B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_image_ImageMemoryReporter_h
      8 #define mozilla_image_ImageMemoryReporter_h
      9 
     10 #include <cstdint>
     11 #include "nsString.h"
     12 #include "mozilla/layers/SharedSurfacesMemoryReport.h"
     13 
     14 class nsISupports;
     15 class nsIHandleReportCallback;
     16 
     17 namespace mozilla {
     18 namespace image {
     19 struct ImageMemoryCounter;
     20 struct SurfaceMemoryCounter;
     21 
     22 class ImageMemoryReporter final {
     23 public:
     24  /**
     25   * Initializes image related memory reporting in the compositor process when
     26   * using WebRender.
     27   */
     28  static void InitForWebRender();
     29 
     30  /**
     31   * Tears down image related memory reporting in the compositor process when
     32   * using WebRender.
     33   */
     34  static void ShutdownForWebRender();
     35 
     36  /**
     37   * Report all remaining entries in the shared surface's memory report. This
     38   * should be used by the content or main process to allow reporting any
     39   * entries that is was unable to cross reference with the local surface cache.
     40   * These are candidates for having been leaked. This should be used in
     41   * conjunction with AppendSharedSurfacePrefix and/or TrimSharedSurfaces to
     42   * produce the expected result.
     43   */
     44  static void ReportSharedSurfaces(
     45      nsIHandleReportCallback* aHandleReport, nsISupports* aData,
     46      const layers::SharedSurfacesMemoryReport& aSharedSurfaces);
     47 
     48  /**
     49   * Adjust the path prefix for a surface to include any additional metadata for
     50   * the shared surface, if any. It will also remove any corresponding entries
     51   * in the given memory report.
     52   */
     53  static void AppendSharedSurfacePrefix(
     54      nsACString& aPathPrefix, const SurfaceMemoryCounter& aCounter,
     55      layers::SharedSurfacesMemoryReport& aSharedSurfaces);
     56 
     57  /**
     58   * Remove all entries in the memory report for the given set of surfaces for
     59   * an image. This is useful when we aren't reporting on a particular image
     60   * because it isn't notable.
     61   */
     62  static void TrimSharedSurfaces(
     63      const ImageMemoryCounter& aCounter,
     64      layers::SharedSurfacesMemoryReport& aSharedSurfaces);
     65 
     66 private:
     67  /**
     68   * Report all remaining entries in the shared surface's memory report.
     69   *
     70   * aIsForCompositor controls how to interpret what remains in the report. If
     71   * true, this should mirror exactly what is currently in
     72   * SharedSurfacesParent's cache. This will report entries that are currently
     73   * mapped into the compositor process. If false, then we are in a content or
     74   * main process, and it should have removed entries that also exist in its
     75   * local surface cache -- thus any remaining entries are those that are
     76   * candidates for leaks.
     77   */
     78  static void ReportSharedSurfaces(
     79      nsIHandleReportCallback* aHandleReport, nsISupports* aData,
     80      bool aIsForCompositor,
     81      const layers::SharedSurfacesMemoryReport& aSharedSurfaces);
     82 
     83  static void ReportSharedSurface(
     84      nsIHandleReportCallback* aHandleReport, nsISupports* aData,
     85      bool aIsForCompositor, uint64_t aExternalId,
     86      const layers::SharedSurfacesMemoryReport::SurfaceEntry& aEntry);
     87 
     88  class WebRenderReporter;
     89  static WebRenderReporter* sWrReporter;
     90 };
     91 
     92 }  // namespace image
     93 }  // namespace mozilla
     94 
     95 #endif  // mozilla_image_ImageMemoryReporter_h