gfx/layers/client/SimpleTextureClientPool.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_SIMPLETEXTURECLIENTPOOL_H
     7 #define MOZILLA_GFX_SIMPLETEXTURECLIENTPOOL_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>
    15 #include <list>
    17 namespace mozilla {
    18 namespace layers {
    20 class ISurfaceAllocator;
    22 class SimpleTextureClientPool
    23 {
    24   ~SimpleTextureClientPool()
    25   {
    26     for (auto it = mOutstandingTextureClients.begin(); it != mOutstandingTextureClients.end(); ++it) {
    27       (*it)->ClearRecycleCallback();
    28     }
    29   }
    31 public:
    32   NS_INLINE_DECL_REFCOUNTING(SimpleTextureClientPool)
    34   SimpleTextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
    35                           ISurfaceAllocator *aAllocator);
    37   /**
    38    * If a TextureClient is AutoRecycled, when the last reference is
    39    * released this object will be automatically return to the pool as
    40    * soon as the compositor informs us it is done with it.
    41    */
    42   TemporaryRef<TextureClient> GetTextureClient(bool aAutoRecycle = false);
    43   TemporaryRef<TextureClient> GetTextureClientWithAutoRecycle() { return GetTextureClient(true); }
    45   void ReturnTextureClient(TextureClient *aClient);
    47   void ShrinkToMinimumSize();
    49   void Clear();
    51 private:
    52   // The time in milliseconds before the pool will be shrunk to the minimum
    53   // size after returning a client.
    54   static const uint32_t sShrinkTimeout = 3000;
    56   // The minimum size of the pool (the number of tiles that will be kept after
    57   // shrinking).
    58   static const uint32_t sMinCacheSize = 16;
    60   // This is the number of cached texture clients we don't want to exceed, even
    61   // temporarily (pre-shrink)
    62   static const uint32_t sMaxTextureClients = 50;
    64   static void ShrinkCallback(nsITimer *aTimer, void *aClosure);
    65   static void RecycleCallback(TextureClient* aClient, void* aClosure);
    66   static void WaitForCompositorRecycleCallback(TextureClient* aClient, void* aClosure);
    68   gfx::SurfaceFormat mFormat;
    69   gfx::IntSize mSize;
    71   // We use a std::stack and make sure to use it the following way:
    72   //   new (available to be used) elements are push()'d to the front
    73   //   requests are served from the front via pop()
    74   //     -- the thinking is that recently-used elements are most likely
    75   //     to be in any data cache, so we can get some wins there
    76   //     -- the converse though is that if there is some GPU locking going on
    77   //     the most recently used elements may also have the most contention;
    78   //     if we see that, then we should use push_back() to add new elements
    79   //   when we shrink this list, we use pop(), but should use pop_back() to
    80   //   nuke the oldest.
    81   // We may need to switch to a std::deque
    82   // On b2g gonk, std::queue might be a better choice.
    83   // On ICS, fence wait happens implicitly before drawing.
    84   // Since JB, fence wait happens explicitly when fetching a client from the pool.
    85   std::stack<RefPtr<TextureClient> > mAvailableTextureClients;
    86   std::list<RefPtr<TextureClient> > mOutstandingTextureClients;
    88   nsRefPtr<nsITimer> mTimer;
    89   RefPtr<ISurfaceAllocator> mSurfaceAllocator;
    90 };
    92 }
    93 }
    94 #endif /* MOZILLA_GFX_SIMPLETEXTURECLIENTPOOL_H */

mercurial