1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/client/TextureClientPool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 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 MOZILLA_GFX_TEXTURECLIENTPOOL_H 1.10 +#define MOZILLA_GFX_TEXTURECLIENTPOOL_H 1.11 + 1.12 +#include "mozilla/gfx/Types.h" 1.13 +#include "mozilla/gfx/Point.h" 1.14 +#include "mozilla/RefPtr.h" 1.15 +#include "TextureClient.h" 1.16 +#include "nsITimer.h" 1.17 +#include <stack> 1.18 + 1.19 +namespace mozilla { 1.20 +namespace layers { 1.21 + 1.22 +class ISurfaceAllocator; 1.23 + 1.24 +class TextureClientPool MOZ_FINAL 1.25 +{ 1.26 + ~TextureClientPool(); 1.27 + 1.28 +public: 1.29 + NS_INLINE_DECL_REFCOUNTING(TextureClientPool) 1.30 + 1.31 + TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize, 1.32 + ISurfaceAllocator *aAllocator); 1.33 + 1.34 + /** 1.35 + * Gets an allocated TextureClient of size and format that are determined 1.36 + * by the initialisation parameters given to the pool. This will either be 1.37 + * a cached client that was returned to the pool, or a newly allocated 1.38 + * client if one isn't available. 1.39 + * 1.40 + * All clients retrieved by this method should be returned using the return 1.41 + * functions, or reported lost so that the pool can manage its size correctly. 1.42 + */ 1.43 + TemporaryRef<TextureClient> GetTextureClient(); 1.44 + 1.45 + /** 1.46 + * Return a TextureClient that is no longer being used and is ready for 1.47 + * immediate re-use or destruction. 1.48 + */ 1.49 + void ReturnTextureClient(TextureClient *aClient); 1.50 + 1.51 + /** 1.52 + * Return a TextureClient that is not yet ready to be reused, but will be 1.53 + * imminently. 1.54 + */ 1.55 + void ReturnTextureClientDeferred(TextureClient *aClient); 1.56 + 1.57 + /** 1.58 + * Attempt to shrink the pool so that there are no more than 1.59 + * sMaxTextureClients clients outstanding. 1.60 + */ 1.61 + void ShrinkToMaximumSize(); 1.62 + 1.63 + /** 1.64 + * Attempt to shrink the pool so that there are no more than sMinCacheSize 1.65 + * unused clients. 1.66 + */ 1.67 + void ShrinkToMinimumSize(); 1.68 + 1.69 + /** 1.70 + * Return any clients to the pool that were previously returned in 1.71 + * ReturnTextureClientDeferred. 1.72 + */ 1.73 + void ReturnDeferredClients(); 1.74 + 1.75 + /** 1.76 + * Report that a client retrieved via GetTextureClient() has become 1.77 + * unusable, so that it will no longer be tracked. 1.78 + */ 1.79 + void ReportClientLost() { mOutstandingClients--; } 1.80 + 1.81 + /** 1.82 + * Calling this will cause the pool to attempt to relinquish any unused 1.83 + * clients. 1.84 + */ 1.85 + void Clear(); 1.86 + 1.87 + gfx::SurfaceFormat GetFormat() { return mFormat; } 1.88 + 1.89 +private: 1.90 + // The time in milliseconds before the pool will be shrunk to the minimum 1.91 + // size after returning a client. 1.92 + static const uint32_t sShrinkTimeout = 1000; 1.93 + 1.94 + // The minimum size of the pool (the number of tiles that will be kept after 1.95 + // shrinking). 1.96 + static const uint32_t sMinCacheSize = 0; 1.97 + 1.98 + // The maximum number of texture clients managed by this pool that we want 1.99 + // to remain active. 1.100 + static const uint32_t sMaxTextureClients = 50; 1.101 + 1.102 + gfx::SurfaceFormat mFormat; 1.103 + gfx::IntSize mSize; 1.104 + 1.105 + uint32_t mOutstandingClients; 1.106 + 1.107 + // On b2g gonk, std::queue might be a better choice. 1.108 + // On ICS, fence wait happens implicitly before drawing. 1.109 + // Since JB, fence wait happens explicitly when fetching a client from the pool. 1.110 + std::stack<RefPtr<TextureClient> > mTextureClients; 1.111 + std::stack<RefPtr<TextureClient> > mTextureClientsDeferred; 1.112 + nsRefPtr<nsITimer> mTimer; 1.113 + RefPtr<ISurfaceAllocator> mSurfaceAllocator; 1.114 +}; 1.115 + 1.116 +} 1.117 +} 1.118 +#endif /* MOZILLA_GFX_TEXTURECLIENTPOOL_H */