gfx/thebes/gfxCachedTempSurface.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial