gfx/layers/client/SimpleTextureClientPool.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/client/SimpleTextureClientPool.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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_SIMPLETEXTURECLIENTPOOL_H
    1.10 +#define MOZILLA_GFX_SIMPLETEXTURECLIENTPOOL_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 +#include <list>
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace layers {
    1.22 +
    1.23 +class ISurfaceAllocator;
    1.24 +
    1.25 +class SimpleTextureClientPool
    1.26 +{
    1.27 +  ~SimpleTextureClientPool()
    1.28 +  {
    1.29 +    for (auto it = mOutstandingTextureClients.begin(); it != mOutstandingTextureClients.end(); ++it) {
    1.30 +      (*it)->ClearRecycleCallback();
    1.31 +    }
    1.32 +  }
    1.33 +
    1.34 +public:
    1.35 +  NS_INLINE_DECL_REFCOUNTING(SimpleTextureClientPool)
    1.36 +
    1.37 +  SimpleTextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
    1.38 +                          ISurfaceAllocator *aAllocator);
    1.39 +
    1.40 +  /**
    1.41 +   * If a TextureClient is AutoRecycled, when the last reference is
    1.42 +   * released this object will be automatically return to the pool as
    1.43 +   * soon as the compositor informs us it is done with it.
    1.44 +   */
    1.45 +  TemporaryRef<TextureClient> GetTextureClient(bool aAutoRecycle = false);
    1.46 +  TemporaryRef<TextureClient> GetTextureClientWithAutoRecycle() { return GetTextureClient(true); }
    1.47 +
    1.48 +  void ReturnTextureClient(TextureClient *aClient);
    1.49 +
    1.50 +  void ShrinkToMinimumSize();
    1.51 +
    1.52 +  void Clear();
    1.53 +
    1.54 +private:
    1.55 +  // The time in milliseconds before the pool will be shrunk to the minimum
    1.56 +  // size after returning a client.
    1.57 +  static const uint32_t sShrinkTimeout = 3000;
    1.58 +
    1.59 +  // The minimum size of the pool (the number of tiles that will be kept after
    1.60 +  // shrinking).
    1.61 +  static const uint32_t sMinCacheSize = 16;
    1.62 +
    1.63 +  // This is the number of cached texture clients we don't want to exceed, even
    1.64 +  // temporarily (pre-shrink)
    1.65 +  static const uint32_t sMaxTextureClients = 50;
    1.66 +
    1.67 +  static void ShrinkCallback(nsITimer *aTimer, void *aClosure);
    1.68 +  static void RecycleCallback(TextureClient* aClient, void* aClosure);
    1.69 +  static void WaitForCompositorRecycleCallback(TextureClient* aClient, void* aClosure);
    1.70 +
    1.71 +  gfx::SurfaceFormat mFormat;
    1.72 +  gfx::IntSize mSize;
    1.73 +
    1.74 +  // We use a std::stack and make sure to use it the following way:
    1.75 +  //   new (available to be used) elements are push()'d to the front
    1.76 +  //   requests are served from the front via pop()
    1.77 +  //     -- the thinking is that recently-used elements are most likely
    1.78 +  //     to be in any data cache, so we can get some wins there
    1.79 +  //     -- the converse though is that if there is some GPU locking going on
    1.80 +  //     the most recently used elements may also have the most contention;
    1.81 +  //     if we see that, then we should use push_back() to add new elements
    1.82 +  //   when we shrink this list, we use pop(), but should use pop_back() to
    1.83 +  //   nuke the oldest.
    1.84 +  // We may need to switch to a std::deque
    1.85 +  // On b2g gonk, std::queue might be a better choice.
    1.86 +  // On ICS, fence wait happens implicitly before drawing.
    1.87 +  // Since JB, fence wait happens explicitly when fetching a client from the pool.
    1.88 +  std::stack<RefPtr<TextureClient> > mAvailableTextureClients;
    1.89 +  std::list<RefPtr<TextureClient> > mOutstandingTextureClients;
    1.90 +
    1.91 +  nsRefPtr<nsITimer> mTimer;
    1.92 +  RefPtr<ISurfaceAllocator> mSurfaceAllocator;
    1.93 +};
    1.94 +
    1.95 +}
    1.96 +}
    1.97 +#endif /* MOZILLA_GFX_SIMPLETEXTURECLIENTPOOL_H */

mercurial