2014-03-08 01:34:04 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_TEXTURECLIENTPOOL_H
|
|
|
|
#define MOZILLA_GFX_TEXTURECLIENTPOOL_H
|
|
|
|
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "mozilla/gfx/Point.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-03-08 01:34:04 +04:00
|
|
|
#include "TextureClient.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include <stack>
|
2016-04-27 16:30:13 +03:00
|
|
|
#include <list>
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class ISurfaceAllocator;
|
2015-10-06 09:40:13 +03:00
|
|
|
class CompositableForwarder;
|
2016-06-02 12:00:12 +03:00
|
|
|
class TextureReadLock;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2015-07-29 19:01:11 +03:00
|
|
|
class TextureClientAllocator
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual ~TextureClientAllocator() {}
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(TextureClientAllocator)
|
|
|
|
|
|
|
|
virtual already_AddRefed<TextureClient> GetTextureClient() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a TextureClient that is not yet ready to be reused, but will be
|
|
|
|
* imminently.
|
|
|
|
*/
|
2016-06-02 12:00:12 +03:00
|
|
|
virtual void ReturnTextureClientDeferred(TextureClient *aClient, TextureReadLock* aLock) = 0;
|
2015-07-29 19:01:11 +03:00
|
|
|
|
|
|
|
virtual void ReportClientLost() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextureClientPool final : public TextureClientAllocator
|
2014-03-08 01:34:04 +04:00
|
|
|
{
|
2014-04-14 23:04:24 +04:00
|
|
|
~TextureClientPool();
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
public:
|
2015-10-14 09:02:35 +03:00
|
|
|
TextureClientPool(gfx::SurfaceFormat aFormat,
|
|
|
|
TextureFlags aFlags,
|
|
|
|
gfx::IntSize aSize,
|
2014-07-25 23:49:47 +04:00
|
|
|
uint32_t aMaxTextureClients,
|
|
|
|
uint32_t aShrinkTimeoutMsec,
|
2015-10-06 09:40:13 +03:00
|
|
|
CompositableForwarder* aAllocator);
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an allocated TextureClient of size and format that are determined
|
|
|
|
* by the initialisation parameters given to the pool. This will either be
|
|
|
|
* a cached client that was returned to the pool, or a newly allocated
|
|
|
|
* client if one isn't available.
|
|
|
|
*
|
|
|
|
* All clients retrieved by this method should be returned using the return
|
|
|
|
* functions, or reported lost so that the pool can manage its size correctly.
|
|
|
|
*/
|
2015-07-29 19:01:11 +03:00
|
|
|
already_AddRefed<TextureClient> GetTextureClient() override;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a TextureClient that is no longer being used and is ready for
|
|
|
|
* immediate re-use or destruction.
|
|
|
|
*/
|
|
|
|
void ReturnTextureClient(TextureClient *aClient);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a TextureClient that is not yet ready to be reused, but will be
|
|
|
|
* imminently.
|
|
|
|
*/
|
2016-06-02 12:00:12 +03:00
|
|
|
void ReturnTextureClientDeferred(TextureClient *aClient, TextureReadLock* aLock) override;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to shrink the pool so that there are no more than
|
2014-07-25 23:49:47 +04:00
|
|
|
* mMaxTextureClients clients outstanding.
|
2014-03-08 01:34:04 +04:00
|
|
|
*/
|
|
|
|
void ShrinkToMaximumSize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to shrink the pool so that there are no more than sMinCacheSize
|
|
|
|
* unused clients.
|
|
|
|
*/
|
|
|
|
void ShrinkToMinimumSize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return any clients to the pool that were previously returned in
|
|
|
|
* ReturnTextureClientDeferred.
|
|
|
|
*/
|
|
|
|
void ReturnDeferredClients();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report that a client retrieved via GetTextureClient() has become
|
|
|
|
* unusable, so that it will no longer be tracked.
|
|
|
|
*/
|
2015-07-29 19:01:11 +03:00
|
|
|
virtual void ReportClientLost() override;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calling this will cause the pool to attempt to relinquish any unused
|
|
|
|
* clients.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
2014-03-18 08:06:25 +04:00
|
|
|
gfx::SurfaceFormat GetFormat() { return mFormat; }
|
2015-10-14 09:02:35 +03:00
|
|
|
TextureFlags GetFlags() const { return mFlags; }
|
2014-03-18 08:06:25 +04:00
|
|
|
|
2016-04-07 15:35:55 +03:00
|
|
|
/**
|
|
|
|
* Clear the pool and put it in a state where it won't recycle any new texture.
|
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
private:
|
2016-04-27 16:30:13 +03:00
|
|
|
void ReturnUnlockedClients();
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
// The minimum size of the pool (the number of tiles that will be kept after
|
|
|
|
// shrinking).
|
|
|
|
static const uint32_t sMinCacheSize = 0;
|
|
|
|
|
2014-07-25 23:49:47 +04:00
|
|
|
/// Format is passed to the TextureClient for buffer creation.
|
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
|
2015-10-14 09:02:35 +03:00
|
|
|
/// Flags passed to the TextureClient for buffer creation.
|
|
|
|
const TextureFlags mFlags;
|
|
|
|
|
2014-07-25 23:49:47 +04:00
|
|
|
/// The width and height of the tiles to be used.
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
// The maximum number of texture clients managed by this pool that we want
|
|
|
|
// to remain active.
|
2014-07-25 23:49:47 +04:00
|
|
|
uint32_t mMaxTextureClients;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-07-25 23:49:47 +04:00
|
|
|
// The time in milliseconds before the pool will be shrunk to the minimum
|
|
|
|
// size after returning a client.
|
|
|
|
uint32_t mShrinkTimeoutMsec;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-09-16 18:13:52 +04:00
|
|
|
/// This is a total number of clients in the wild and in the stack of
|
|
|
|
/// deferred clients (see below). So, the total number of clients in
|
|
|
|
/// existence is always mOutstandingClients + the size of mTextureClients.
|
2014-03-08 01:34:04 +04:00
|
|
|
uint32_t mOutstandingClients;
|
|
|
|
|
2016-04-27 16:30:13 +03:00
|
|
|
struct TextureClientHolder {
|
|
|
|
RefPtr<TextureClient> mTextureClient;
|
2016-06-02 12:00:12 +03:00
|
|
|
RefPtr<TextureReadLock> mLock;
|
2016-04-27 16:30:13 +03:00
|
|
|
|
2016-06-02 12:00:12 +03:00
|
|
|
TextureClientHolder(TextureClient* aTextureClient, TextureReadLock* aLock)
|
2016-04-27 16:30:13 +03:00
|
|
|
: mTextureClient(aTextureClient), mLock(aLock)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2014-03-27 05:01:15 +04:00
|
|
|
// On b2g gonk, std::queue might be a better choice.
|
|
|
|
// On ICS, fence wait happens implicitly before drawing.
|
|
|
|
// Since JB, fence wait happens explicitly when fetching a client from the pool.
|
2015-10-18 08:24:48 +03:00
|
|
|
std::stack<RefPtr<TextureClient> > mTextureClients;
|
2016-04-27 16:30:13 +03:00
|
|
|
|
|
|
|
std::list<TextureClientHolder> mTextureClientsDeferred;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsITimer> mTimer;
|
|
|
|
RefPtr<CompositableForwarder> mSurfaceAllocator;
|
2014-03-08 01:34:04 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
#endif /* MOZILLA_GFX_TEXTURECLIENTPOOL_H */
|