#include "config.h"
#include "Tile.h"
#if USE(COORDINATED_GRAPHICS)
#include "GraphicsContext.h"
#include "SurfaceUpdateInfo.h"
#include "TiledBackingStore.h"
#include "TiledBackingStoreClient.h"
namespace WebCore {
static const uint32_t InvalidTileID = 0;
Tile::Tile(TiledBackingStore& tiledBackingStore, const Coordinate& tileCoordinate)
: m_tiledBackingStore(tiledBackingStore)
, m_coordinate(tileCoordinate)
, m_rect(tiledBackingStore.tileRectForCoordinate(tileCoordinate))
, m_ID(InvalidTileID)
, m_dirtyRect(m_rect)
{
}
Tile::~Tile()
{
if (m_ID != InvalidTileID)
m_tiledBackingStore.client()->removeTile(m_ID);
}
bool Tile::isDirty() const
{
return !m_dirtyRect.isEmpty();
}
void Tile::invalidate(const IntRect& dirtyRect)
{
IntRect tileDirtyRect = intersection(dirtyRect, m_rect);
if (tileDirtyRect.isEmpty())
return;
m_dirtyRect.unite(tileDirtyRect);
}
bool Tile::updateBackBuffer()
{
if (!isDirty())
return false;
SurfaceUpdateInfo updateInfo;
if (!m_tiledBackingStore.client()->paintToSurface(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset, *this))
return false;
updateInfo.updateRect = m_dirtyRect;
updateInfo.updateRect.move(-m_rect.x(), -m_rect.y());
static uint32_t id = 1;
if (m_ID == InvalidTileID) {
m_ID = id++;
if (m_ID == InvalidTileID)
m_ID = id++;
m_tiledBackingStore.client()->createTile(m_ID, m_tiledBackingStore.contentsScale());
}
m_tiledBackingStore.client()->updateTile(m_ID, updateInfo, m_rect);
m_dirtyRect = IntRect();
return true;
}
void Tile::paintToSurfaceContext(GraphicsContext& context)
{
context.translate(-m_dirtyRect.x(), -m_dirtyRect.y());
context.scale(FloatSize(m_tiledBackingStore.contentsScale(), m_tiledBackingStore.contentsScale()));
m_tiledBackingStore.client()->tiledBackingStorePaint(context, m_tiledBackingStore.mapToContents(m_dirtyRect));
}
bool Tile::isReadyToPaint() const
{
return m_ID != InvalidTileID;
}
void Tile::resize(const IntSize& newSize)
{
m_rect = IntRect(m_rect.location(), newSize);
m_dirtyRect = m_rect;
}
}
#endif // USE(COORDINATED_GRAPHICS)