Bug 1118876 - Add edge padding with DrawTargetTiled. r=jrmuizel

This commit is contained in:
Nicolas Silva 2015-07-12 11:11:30 +02:00
parent 826c9eb48e
commit e53235174e
4 changed files with 56 additions and 55 deletions

View File

@ -1048,33 +1048,6 @@ void PadDrawTargetOutFromRegion(RefPtr<DrawTarget> drawTarget, nsIntRegion &regi
}
}
void
ClientTiledLayerBuffer::PostValidate(const nsIntRegion& aPaintRegion,
const nsIntRegion& aDirtyRegion)
{
if (gfxPrefs::TiledDrawTargetEnabled() && mMoz2DTiles.size() > 0) {
gfx::TileSet tileset;
for (size_t i = 0; i < mMoz2DTiles.size(); ++i) {
mMoz2DTiles[i].mTileOrigin -= mTilingOrigin;
}
tileset.mTiles = &mMoz2DTiles[0];
tileset.mTileCount = mMoz2DTiles.size();
RefPtr<DrawTarget> drawTarget = gfx::Factory::CreateTiledDrawTarget(tileset);
drawTarget->SetTransform(Matrix());
RefPtr<gfxContext> ctx = new gfxContext(drawTarget);
ctx->SetMatrix(
ctx->CurrentMatrix().Scale(mResolution, mResolution).Translate(ThebesPoint(-mTilingOrigin)));
mCallback(mPaintedLayer, ctx, aPaintRegion, aDirtyRegion,
DrawRegionClip::DRAW, nsIntRegion(), mCallbackData);
mMoz2DTiles.clear();
// Reset:
mTilingOrigin = IntPoint(std::numeric_limits<int32_t>::max(),
std::numeric_limits<int32_t>::max());
}
}
void
ClientTiledLayerBuffer::UnlockTile(TileClient& aTile)
{
@ -1150,9 +1123,61 @@ void ClientTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
}
}
PostValidate(aPaintRegion, aDirtyRegion);
if (gfxPrefs::TiledDrawTargetEnabled() && mMoz2DTiles.size() > 0) {
gfx::TileSet tileset;
for (size_t i = 0; i < mMoz2DTiles.size(); ++i) {
mMoz2DTiles[i].mTileOrigin -= mTilingOrigin;
}
tileset.mTiles = &mMoz2DTiles[0];
tileset.mTileCount = mMoz2DTiles.size();
RefPtr<DrawTarget> drawTarget = gfx::Factory::CreateTiledDrawTarget(tileset);
drawTarget->SetTransform(Matrix());
for (TileClient& tile : mRetainedTiles) {
RefPtr<gfxContext> ctx = new gfxContext(drawTarget);
ctx->SetMatrix(
ctx->CurrentMatrix().Scale(mResolution, mResolution).Translate(ThebesPoint(-mTilingOrigin)));
mCallback(mPaintedLayer, ctx, aPaintRegion, aDirtyRegion,
DrawRegionClip::DRAW, nsIntRegion(), mCallbackData);
mMoz2DTiles.clear();
// Reset:
mTilingOrigin = IntPoint(std::numeric_limits<int32_t>::max(),
std::numeric_limits<int32_t>::max());
}
bool edgePaddingEnabled = gfxPrefs::TileEdgePaddingEnabled();
for (uint32_t i = 0; i < mRetainedTiles.Length(); ++i) {
TileClient& tile = mRetainedTiles[i];
// Only worry about padding when not doing low-res because it simplifies
// the math and the artifacts won't be noticable
// Edge padding prevents sampling artifacts when compositing.
if (edgePaddingEnabled && mResolution == 1 &&
tile.mFrontBuffer && tile.mFrontBuffer->IsLocked()) {
const TileIntPoint tilePosition = newTiles.TilePosition(i);
IntPoint tileOffset = GetTileOffset(tilePosition);
// Strictly speakig we want the unscaled rect here, but it doesn't matter
// because we only run this code when the resolution is equal to 1.
IntRect tileRect = IntRect(tileOffset.x, tileOffset.y,
GetTileSize().width, GetTileSize().height);
nsIntRegion tileDrawRegion = IntRect(tileOffset, scaledTileSize);
tileDrawRegion.AndWith(aPaintRegion);
nsIntRegion tileValidRegion = mValidRegion;
tileValidRegion.OrWith(tileDrawRegion);
// We only need to pad out if the tile has area that's not valid
if (!tileValidRegion.Contains(tileRect)) {
tileValidRegion = tileValidRegion.Intersect(tileRect);
// translate the region into tile space and pad
tileValidRegion.MoveBy(-IntPoint(tileOffset.x, tileOffset.y));
RefPtr<DrawTarget> drawTarget = tile.mFrontBuffer->BorrowDrawTarget();
PadDrawTargetOutFromRegion(drawTarget, tileValidRegion);
}
}
UnlockTile(tile);
}
@ -1240,7 +1265,6 @@ ClientTiledLayerBuffer::ValidateTile(TileClient& aTile,
}
}
// prepare an array of Moz2D tiles that will be painted into in PostValidate
gfx::Tile moz2DTile;
RefPtr<DrawTarget> dt = backBuffer->BorrowDrawTarget();
RefPtr<DrawTarget> dtOnWhite;
@ -1326,26 +1350,6 @@ ClientTiledLayerBuffer::ValidateTile(TileClient& aTile,
aTile.mInvalidFront.Or(aTile.mInvalidFront, IntRect(copyTarget.x, copyTarget.y, copyRect.width, copyRect.height));
}
// only worry about padding when not doing low-res
// because it simplifies the math and the artifacts
// won't be noticable
if (mResolution == 1) {
IntRect unscaledTile = IntRect(aTileOrigin.x,
aTileOrigin.y,
GetTileSize().width,
GetTileSize().height);
nsIntRegion tileValidRegion = GetValidRegion();
tileValidRegion.Or(tileValidRegion, aDirtyRegion);
// We only need to pad out if the tile has area that's not valid
if (!tileValidRegion.Contains(unscaledTile)) {
tileValidRegion = tileValidRegion.Intersect(unscaledTile);
// translate the region into tile space and pad
tileValidRegion.MoveBy(-nsIntPoint(unscaledTile.x, unscaledTile.y));
PadDrawTargetOutFromRegion(drawTarget, tileValidRegion);
}
}
// The new buffer is now validated, remove the dirty region from it.
aTile.mInvalidBack.SubOut(offsetScaledDirtyRegion);
@ -1364,7 +1368,6 @@ ClientTiledLayerBuffer::ValidateTile(TileClient& aTile,
tileRegion.SubOut(GetValidRegion());
tileRegion.SubOut(aDirtyRegion); // Has now been validated
backBuffer->Unlock();
backBuffer->SetWaste(tileRegion.Area() * mResolution * mResolution);
if (createdTextureClient) {

View File

@ -277,7 +277,6 @@ struct TileClient
nsIntRegion mInvalidFront;
nsIntRegion mInvalidBack;
nsExpirationState mExpirationState;
private:
// Copies dirty pixels from the front buffer into the back buffer,
// and records the copied region in aAddPaintedRegion.
@ -469,9 +468,6 @@ protected:
const nsIntPoint& aTileRect,
const nsIntRegion& dirtyRect);
void PostValidate(const nsIntRegion& aPaintRegion,
const nsIntRegion& aDirtyRegion);
void UnlockTile(TileClient& aTile);
TileClient GetPlaceholderTile() const { return TileClient(); }

View File

@ -345,6 +345,7 @@ private:
DECL_GFX_PREF(Once, "layers.tile-shrink-pool-timeout", LayersTileShrinkPoolTimeout, uint32_t, (uint32_t)1000);
DECL_GFX_PREF(Once, "layers.tiled-drawtarget.enabled", TiledDrawTargetEnabled, bool, false);
DECL_GFX_PREF(Once, "layers.tiles.adjust", LayersTilesAdjust, bool, true);
DECL_GFX_PREF(Once, "layers.tiles.edge-padding", TileEdgePaddingEnabled, bool, true);
DECL_GFX_PREF(Live, "layers.transaction.warning-ms", LayerTransactionWarning, uint32_t, 200);
DECL_GFX_PREF(Once, "layers.uniformity-info", UniformityInfo, bool, false);
DECL_GFX_PREF(Once, "layers.use-image-offscreen-surfaces", UseImageOffscreenSurfaces, bool, false);

View File

@ -4261,6 +4261,7 @@ pref("layers.async-pan-zoom.enabled", true);
#ifdef XP_MACOSX
pref("layers.enable-tiles", true);
pref("layers.tiled-drawtarget.enabled", true);
pref("layers.tiles.edge-padding", false);
#endif