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 MOZILLA_GFX_TEXTURECLIENTPOOL_H michael@0: #define MOZILLA_GFX_TEXTURECLIENTPOOL_H michael@0: michael@0: #include "mozilla/gfx/Types.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "TextureClient.h" michael@0: #include "nsITimer.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class ISurfaceAllocator; michael@0: michael@0: class TextureClientPool MOZ_FINAL michael@0: { michael@0: ~TextureClientPool(); michael@0: michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(TextureClientPool) michael@0: michael@0: TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize, michael@0: ISurfaceAllocator *aAllocator); michael@0: michael@0: /** michael@0: * Gets an allocated TextureClient of size and format that are determined michael@0: * by the initialisation parameters given to the pool. This will either be michael@0: * a cached client that was returned to the pool, or a newly allocated michael@0: * client if one isn't available. michael@0: * michael@0: * All clients retrieved by this method should be returned using the return michael@0: * functions, or reported lost so that the pool can manage its size correctly. michael@0: */ michael@0: TemporaryRef GetTextureClient(); michael@0: michael@0: /** michael@0: * Return a TextureClient that is no longer being used and is ready for michael@0: * immediate re-use or destruction. michael@0: */ michael@0: void ReturnTextureClient(TextureClient *aClient); michael@0: michael@0: /** michael@0: * Return a TextureClient that is not yet ready to be reused, but will be michael@0: * imminently. michael@0: */ michael@0: void ReturnTextureClientDeferred(TextureClient *aClient); michael@0: michael@0: /** michael@0: * Attempt to shrink the pool so that there are no more than michael@0: * sMaxTextureClients clients outstanding. michael@0: */ michael@0: void ShrinkToMaximumSize(); michael@0: michael@0: /** michael@0: * Attempt to shrink the pool so that there are no more than sMinCacheSize michael@0: * unused clients. michael@0: */ michael@0: void ShrinkToMinimumSize(); michael@0: michael@0: /** michael@0: * Return any clients to the pool that were previously returned in michael@0: * ReturnTextureClientDeferred. michael@0: */ michael@0: void ReturnDeferredClients(); michael@0: michael@0: /** michael@0: * Report that a client retrieved via GetTextureClient() has become michael@0: * unusable, so that it will no longer be tracked. michael@0: */ michael@0: void ReportClientLost() { mOutstandingClients--; } michael@0: michael@0: /** michael@0: * Calling this will cause the pool to attempt to relinquish any unused michael@0: * clients. michael@0: */ michael@0: void Clear(); michael@0: michael@0: gfx::SurfaceFormat GetFormat() { return mFormat; } michael@0: michael@0: private: michael@0: // The time in milliseconds before the pool will be shrunk to the minimum michael@0: // size after returning a client. michael@0: static const uint32_t sShrinkTimeout = 1000; michael@0: michael@0: // The minimum size of the pool (the number of tiles that will be kept after michael@0: // shrinking). michael@0: static const uint32_t sMinCacheSize = 0; michael@0: michael@0: // The maximum number of texture clients managed by this pool that we want michael@0: // to remain active. michael@0: static const uint32_t sMaxTextureClients = 50; michael@0: michael@0: gfx::SurfaceFormat mFormat; michael@0: gfx::IntSize mSize; michael@0: michael@0: uint32_t mOutstandingClients; michael@0: michael@0: // On b2g gonk, std::queue might be a better choice. michael@0: // On ICS, fence wait happens implicitly before drawing. michael@0: // Since JB, fence wait happens explicitly when fetching a client from the pool. michael@0: std::stack > mTextureClients; michael@0: std::stack > mTextureClientsDeferred; michael@0: nsRefPtr mTimer; michael@0: RefPtr mSurfaceAllocator; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: #endif /* MOZILLA_GFX_TEXTURECLIENTPOOL_H */