gfx/layers/client/TextureClientPool.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2 * This Source Code Form is subject to the terms of the Mozilla Public
     3 * License, v. 2.0. If a copy of the MPL was not distributed with this
     4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef MOZILLA_GFX_TEXTURECLIENTPOOL_H
     7 #define MOZILLA_GFX_TEXTURECLIENTPOOL_H
     9 #include "mozilla/gfx/Types.h"
    10 #include "mozilla/gfx/Point.h"
    11 #include "mozilla/RefPtr.h"
    12 #include "TextureClient.h"
    13 #include "nsITimer.h"
    14 #include <stack>
    16 namespace mozilla {
    17 namespace layers {
    19 class ISurfaceAllocator;
    21 class TextureClientPool MOZ_FINAL
    22 {
    23   ~TextureClientPool();
    25 public:
    26   NS_INLINE_DECL_REFCOUNTING(TextureClientPool)
    28   TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
    29                     ISurfaceAllocator *aAllocator);
    31   /**
    32    * Gets an allocated TextureClient of size and format that are determined
    33    * by the initialisation parameters given to the pool. This will either be
    34    * a cached client that was returned to the pool, or a newly allocated
    35    * client if one isn't available.
    36    *
    37    * All clients retrieved by this method should be returned using the return
    38    * functions, or reported lost so that the pool can manage its size correctly.
    39    */
    40   TemporaryRef<TextureClient> GetTextureClient();
    42   /**
    43    * Return a TextureClient that is no longer being used and is ready for
    44    * immediate re-use or destruction.
    45    */
    46   void ReturnTextureClient(TextureClient *aClient);
    48   /**
    49    * Return a TextureClient that is not yet ready to be reused, but will be
    50    * imminently.
    51    */
    52   void ReturnTextureClientDeferred(TextureClient *aClient);
    54   /**
    55    * Attempt to shrink the pool so that there are no more than
    56    * sMaxTextureClients clients outstanding.
    57    */
    58   void ShrinkToMaximumSize();
    60   /**
    61    * Attempt to shrink the pool so that there are no more than sMinCacheSize
    62    * unused clients.
    63    */
    64   void ShrinkToMinimumSize();
    66   /**
    67    * Return any clients to the pool that were previously returned in
    68    * ReturnTextureClientDeferred.
    69    */
    70   void ReturnDeferredClients();
    72   /**
    73    * Report that a client retrieved via GetTextureClient() has become
    74    * unusable, so that it will no longer be tracked.
    75    */
    76   void ReportClientLost() { mOutstandingClients--; }
    78   /**
    79    * Calling this will cause the pool to attempt to relinquish any unused
    80    * clients.
    81    */
    82   void Clear();
    84   gfx::SurfaceFormat GetFormat() { return mFormat; }
    86 private:
    87   // The time in milliseconds before the pool will be shrunk to the minimum
    88   // size after returning a client.
    89   static const uint32_t sShrinkTimeout = 1000;
    91   // The minimum size of the pool (the number of tiles that will be kept after
    92   // shrinking).
    93   static const uint32_t sMinCacheSize = 0;
    95   // The maximum number of texture clients managed by this pool that we want
    96   // to remain active.
    97   static const uint32_t sMaxTextureClients = 50;
    99   gfx::SurfaceFormat mFormat;
   100   gfx::IntSize mSize;
   102   uint32_t mOutstandingClients;
   104   // On b2g gonk, std::queue might be a better choice.
   105   // On ICS, fence wait happens implicitly before drawing.
   106   // Since JB, fence wait happens explicitly when fetching a client from the pool.
   107   std::stack<RefPtr<TextureClient> > mTextureClients;
   108   std::stack<RefPtr<TextureClient> > mTextureClientsDeferred;
   109   nsRefPtr<nsITimer> mTimer;
   110   RefPtr<ISurfaceAllocator> mSurfaceAllocator;
   111 };
   113 }
   114 }
   115 #endif /* MOZILLA_GFX_TEXTURECLIENTPOOL_H */

mercurial