gfx/thebes/gfxCachedTempSurface.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxCachedTempSurface.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_CACHED_TEMP_SURFACE_H
    1.10 +#define GFX_CACHED_TEMP_SURFACE_H
    1.11 +
    1.12 +#include "gfxASurface.h"
    1.13 +#include "nsExpirationTracker.h"
    1.14 +#include "nsSize.h"
    1.15 +
    1.16 +class gfxContext;
    1.17 +
    1.18 +/**
    1.19 + * This class can be used to cache double-buffering back surfaces.
    1.20 + *
    1.21 + * Large resource allocations may have an overhead that can be avoided by
    1.22 + * caching.  Caching also alows the system to use history in deciding whether
    1.23 + * to manage the surfaces in video or system memory.
    1.24 + *
    1.25 + * However, because we don't want to set aside megabytes of unused resources
    1.26 + * unncessarily, these surfaces are released on a timer.
    1.27 + */
    1.28 +
    1.29 +class gfxCachedTempSurface {
    1.30 +public:
    1.31 +  /**
    1.32 +   * Returns a context for a surface that can be efficiently copied to
    1.33 +   * |aSimilarTo|.
    1.34 +   *
    1.35 +   * When |aContentType| has an alpha component, the surface will be cleared.
    1.36 +   * For opaque surfaces, the initial surface contents are undefined.
    1.37 +   * When |aContentType| differs in different invocations this is handled
    1.38 +   * appropriately, creating a new surface if necessary.
    1.39 +   * 
    1.40 +   * Because the cached surface may have been created during a previous
    1.41 +   * invocation, this will not be efficient if the new |aSimilarTo| has a
    1.42 +   * different format, size, or gfxSurfaceType.
    1.43 +   */
    1.44 +  already_AddRefed<gfxContext> Get(gfxContentType aContentType,
    1.45 +                                   const gfxRect& aRect,
    1.46 +                                   gfxASurface* aSimilarTo);
    1.47 +
    1.48 +  void Expire() { mSurface = nullptr; }
    1.49 +  nsExpirationState* GetExpirationState() { return &mExpirationState; }
    1.50 +  ~gfxCachedTempSurface();
    1.51 +
    1.52 +  bool IsSurface(gfxASurface* aSurface) { return mSurface == aSurface; }
    1.53 +
    1.54 +private:
    1.55 +  nsRefPtr<gfxASurface> mSurface;
    1.56 +  gfxIntSize mSize;
    1.57 +  nsExpirationState mExpirationState;
    1.58 +  gfxSurfaceType mType;
    1.59 +};
    1.60 +
    1.61 +#endif /* GFX_CACHED_TEMP_SURFACE_H */

mercurial