michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_CACHED_TEMP_SURFACE_H michael@0: #define GFX_CACHED_TEMP_SURFACE_H michael@0: michael@0: #include "gfxASurface.h" michael@0: #include "nsExpirationTracker.h" michael@0: #include "nsSize.h" michael@0: michael@0: class gfxContext; michael@0: michael@0: /** michael@0: * This class can be used to cache double-buffering back surfaces. michael@0: * michael@0: * Large resource allocations may have an overhead that can be avoided by michael@0: * caching. Caching also alows the system to use history in deciding whether michael@0: * to manage the surfaces in video or system memory. michael@0: * michael@0: * However, because we don't want to set aside megabytes of unused resources michael@0: * unncessarily, these surfaces are released on a timer. michael@0: */ michael@0: michael@0: class gfxCachedTempSurface { michael@0: public: michael@0: /** michael@0: * Returns a context for a surface that can be efficiently copied to michael@0: * |aSimilarTo|. michael@0: * michael@0: * When |aContentType| has an alpha component, the surface will be cleared. michael@0: * For opaque surfaces, the initial surface contents are undefined. michael@0: * When |aContentType| differs in different invocations this is handled michael@0: * appropriately, creating a new surface if necessary. michael@0: * michael@0: * Because the cached surface may have been created during a previous michael@0: * invocation, this will not be efficient if the new |aSimilarTo| has a michael@0: * different format, size, or gfxSurfaceType. michael@0: */ michael@0: already_AddRefed Get(gfxContentType aContentType, michael@0: const gfxRect& aRect, michael@0: gfxASurface* aSimilarTo); michael@0: michael@0: void Expire() { mSurface = nullptr; } michael@0: nsExpirationState* GetExpirationState() { return &mExpirationState; } michael@0: ~gfxCachedTempSurface(); michael@0: michael@0: bool IsSurface(gfxASurface* aSurface) { return mSurface == aSurface; } michael@0: michael@0: private: michael@0: nsRefPtr mSurface; michael@0: gfxIntSize mSize; michael@0: nsExpirationState mExpirationState; michael@0: gfxSurfaceType mType; michael@0: }; michael@0: michael@0: #endif /* GFX_CACHED_TEMP_SURFACE_H */