gfx/thebes/gfxCachedTempSurface.h

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: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef GFX_CACHED_TEMP_SURFACE_H
     7 #define GFX_CACHED_TEMP_SURFACE_H
     9 #include "gfxASurface.h"
    10 #include "nsExpirationTracker.h"
    11 #include "nsSize.h"
    13 class gfxContext;
    15 /**
    16  * This class can be used to cache double-buffering back surfaces.
    17  *
    18  * Large resource allocations may have an overhead that can be avoided by
    19  * caching.  Caching also alows the system to use history in deciding whether
    20  * to manage the surfaces in video or system memory.
    21  *
    22  * However, because we don't want to set aside megabytes of unused resources
    23  * unncessarily, these surfaces are released on a timer.
    24  */
    26 class gfxCachedTempSurface {
    27 public:
    28   /**
    29    * Returns a context for a surface that can be efficiently copied to
    30    * |aSimilarTo|.
    31    *
    32    * When |aContentType| has an alpha component, the surface will be cleared.
    33    * For opaque surfaces, the initial surface contents are undefined.
    34    * When |aContentType| differs in different invocations this is handled
    35    * appropriately, creating a new surface if necessary.
    36    * 
    37    * Because the cached surface may have been created during a previous
    38    * invocation, this will not be efficient if the new |aSimilarTo| has a
    39    * different format, size, or gfxSurfaceType.
    40    */
    41   already_AddRefed<gfxContext> Get(gfxContentType aContentType,
    42                                    const gfxRect& aRect,
    43                                    gfxASurface* aSimilarTo);
    45   void Expire() { mSurface = nullptr; }
    46   nsExpirationState* GetExpirationState() { return &mExpirationState; }
    47   ~gfxCachedTempSurface();
    49   bool IsSurface(gfxASurface* aSurface) { return mSurface == aSurface; }
    51 private:
    52   nsRefPtr<gfxASurface> mSurface;
    53   gfxIntSize mSize;
    54   nsExpirationState mExpirationState;
    55   gfxSurfaceType mType;
    56 };
    58 #endif /* GFX_CACHED_TEMP_SURFACE_H */

mercurial