#ifndef TileLayerPool_h
#define TileLayerPool_h
#include "IntSize.h"
#include "IntSizeHash.h"
#include "Timer.h"
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
@class TileLayer;
namespace WebCore {
class TileLayerPool {
WTF_MAKE_NONCOPYABLE(TileLayerPool);
public:
static TileLayerPool* sharedPool();
void addLayer(const RetainPtr<TileLayer>&);
RetainPtr<TileLayer> takeLayerWithSize(const IntSize&);
unsigned capacity() const { return m_capacity; }
void setCapacity(unsigned);
void drain();
unsigned decayedCapacity() const;
static unsigned bytesBackingLayerWithPixelSize(const IntSize& size);
private:
TileLayerPool();
typedef Deque<RetainPtr<TileLayer> > LayerList;
bool canReuseLayerWithSize(const IntSize& size) const { return m_capacity && !size.isEmpty(); }
void schedulePrune();
void prune();
typedef enum { LeaveUnchanged, MarkAsUsed } AccessType;
LayerList& listOfLayersWithSize(const IntSize&, AccessType accessType = LeaveUnchanged);
HashMap<IntSize, LayerList> m_reuseLists;
Vector<IntSize> m_sizesInPruneOrder;
unsigned m_totalBytes;
unsigned m_capacity;
Mutex m_layerPoolMutex;
double m_lastAddTime;
bool m_needsPrune;
};
}
#endif