TextureCacheCompositingThread.h [plain text]
#ifndef TextureCacheCompositingThread_h
#define TextureCacheCompositingThread_h
#if USE(ACCELERATED_COMPOSITING)
#include "Color.h"
#include "LayerTexture.h"
#include "LayerTileIndex.h"
#include <BlackBerryPlatformGraphics.h>
#include <wtf/HashMap.h>
#include <wtf/ListHashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class IntRect;
class TextureCacheCompositingThread {
WTF_MAKE_NONCOPYABLE(TextureCacheCompositingThread);
WTF_MAKE_FAST_ALLOCATED;
public:
friend TextureCacheCompositingThread* textureCacheCompositingThread();
PassRefPtr<LayerTexture> createTexture()
{
return LayerTexture::create();
}
PassRefPtr<LayerTexture> textureForContents(BlackBerry::Platform::Graphics::Buffer*);
PassRefPtr<LayerTexture> textureForColor(const Color&);
PassRefPtr<LayerTexture> updateContents(const RefPtr<LayerTexture>&, BlackBerry::Platform::Graphics::Buffer*);
size_t memoryUsage() const { return m_memoryUsage; }
size_t memoryLimit() const { return m_memoryLimit; }
void setMemoryLimit(size_t limit) { m_memoryLimit = limit; }
void prune(size_t limit);
void prune() { prune(memoryLimit()); }
void clear();
void textureAccessed(LayerTexture*);
void collectGarbage();
void textureDestroyed(LayerTexture*);
void textureResized(LayerTexture*, const IntSize& oldSize);
void textureSizeInBytesChanged(LayerTexture*, int delta);
bool install(LayerTexture*, const IntSize& textureSize = IntSize(0, 0), BlackBerry::Platform::Graphics::BufferType = BlackBerry::Platform::Graphics::BackedWhenNecessary);
bool resizeTexture(LayerTexture*, const IntSize& newSize, BlackBerry::Platform::Graphics::BufferType = BlackBerry::Platform::Graphics::BackedWhenNecessary);
private:
struct ZombieTexture {
explicit ZombieTexture(LayerTexture* texture)
: buffer(texture->buffer())
, size(texture->size())
, sizeInBytes(texture->sizeInBytes())
{
}
BlackBerry::Platform::Graphics::Buffer* buffer;
IntSize size;
size_t sizeInBytes;
};
typedef ListHashSet<LayerTexture* > TextureSet;
typedef HashMap<TileIndex, RefPtr<LayerTexture> > TextureMap;
typedef Vector<ZombieTexture> Garbage;
TextureCacheCompositingThread();
~TextureCacheCompositingThread();
BlackBerry::Platform::Graphics::Buffer* createBuffer(const IntSize& textureSize, BlackBerry::Platform::Graphics::BufferType);
void incMemoryUsage(int delta) { setMemoryUsage(memoryUsage() + delta); }
void decMemoryUsage(int delta) { setMemoryUsage(memoryUsage() - delta); }
void setMemoryUsage(size_t);
void evict(const TextureSet::iterator&);
TextureSet m_textures;
size_t m_memoryUsage;
size_t m_memoryLimit;
struct ColorHash {
static unsigned hash(const Color& key) { return WTF::intHash(key.rgb()); }
static bool equal(const Color& a, const Color& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
struct ColorHashTraits : WTF::GenericHashTraits<Color> {
static const bool emptyValueIsZero = true;
static void constructDeletedValue(Color& slot) { new (&slot) Color(); *reinterpret_cast<RGBA32*>(&slot) = Color::white; }
static bool isDeletedValue(const Color& value) { return !value.isValid() && value.rgb() == Color::white; }
};
typedef HashMap<Color, RefPtr<LayerTexture>, ColorHash, ColorHashTraits> ColorTextureMap;
ColorTextureMap m_colors;
Garbage m_garbage;
};
TextureCacheCompositingThread* textureCacheCompositingThread();
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif // TextureCacheCompositingThread_h