Bug 1170189 - Simplify TiledContentHost's render loop. r=BenWa

This commit is contained in:
Nicolas Silva 2015-06-10 17:59:19 +02:00
parent 518e4e75b4
commit b40bfed787
3 changed files with 62 additions and 65 deletions

View File

@ -178,6 +178,16 @@ public:
// GetScaledTileSize().width, GetScaledTileSize().height)
Tile& GetTile(int x, int y);
Tile& GetTile(size_t i) { return mRetainedTiles[i]; }
gfx::IntPoint GetTileOffset(TileIntPoint aPosition) const {
gfx::IntSize scaledTileSize = GetScaledTileSize();
return gfx::IntPoint(aPosition.x * scaledTileSize.width,
aPosition.y * scaledTileSize.height);
}
const TilesPlacement& GetPlacement() const { return mTiles; }
int TileIndex(const gfx::IntPoint& aTileOrigin) const;
int TileIndex(int x, int y) const { return x * mTiles.mSize.height + y; }

View File

@ -420,7 +420,6 @@ TiledContentHost::Composite(EffectChain& aEffectChain,
void
TiledContentHost::RenderTile(TileHost& aTile,
const gfxRGBA* aBackgroundColor,
EffectChain& aEffectChain,
float aOpacity,
const gfx::Matrix4x4& aTransform,
@ -431,20 +430,7 @@ TiledContentHost::RenderTile(TileHost& aTile,
const IntSize& aTextureBounds,
const gfx::Rect& aVisibleRect)
{
if (aTile.IsPlaceholderTile()) {
// This shouldn't ever happen, but let's fail semi-gracefully. No need
// to warn, the texture update would have already caught this.
return;
}
if (aBackgroundColor) {
aEffectChain.mPrimaryEffect = new EffectSolidColor(ToColor(*aBackgroundColor));
nsIntRegionRectIterator it(aScreenRegion);
for (const IntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
mCompositor->DrawQuad(graphicsRect, aClipRect, aEffectChain, 1.0, aTransform);
}
}
MOZ_ASSERT(!aTile.IsPlaceholderTile());
AutoLockTextureHost autoLock(aTile.mTextureHost);
AutoLockTextureHost autoLockOnWhite(aTile.mTextureHostOnWhite);
@ -512,9 +498,9 @@ TiledContentHost::RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer,
float resolution = aLayerBuffer.GetResolution();
gfx::Size layerScale(1, 1);
// We assume that the current frame resolution is the one used in our high
// precision layer buffer. Compensate for a changing frame resolution when
// rendering the low precision buffer.
// Make sure we don't render at low resolution where we have valid high
// resolution content, to avoid overdraw and artifacts with semi-transparent
// layers.
if (aLayerBuffer.GetFrameResolution() != mTiledBuffer.GetFrameResolution()) {
const CSSToParentLayerScale2D& layerResolution = aLayerBuffer.GetFrameResolution();
const CSSToParentLayerScale2D& localResolution = mTiledBuffer.GetFrameResolution();
@ -541,55 +527,57 @@ TiledContentHost::RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer,
DiagnosticFlags componentAlphaDiagnostic = DiagnosticFlags::NO_DIAGNOSTIC;
uint32_t rowCount = 0;
uint32_t tileX = 0;
nsIntRegion compositeRegion = aLayerBuffer.GetValidRegion();
compositeRegion.AndWith(aVisibleRegion);
compositeRegion.SubOut(maskRegion);
IntRect visibleRect = aVisibleRegion.GetBounds();
gfx::IntSize scaledTileSize = aLayerBuffer.GetScaledTileSize();
for (int32_t x = visibleRect.x; x < visibleRect.x + visibleRect.width;) {
rowCount++;
int32_t tileStartX = aLayerBuffer.GetTileStart(x, scaledTileSize.width);
int32_t w = scaledTileSize.width - tileStartX;
if (x + w > visibleRect.x + visibleRect.width) {
w = visibleRect.x + visibleRect.width - x;
}
int tileY = 0;
for (int32_t y = visibleRect.y; y < visibleRect.y + visibleRect.height;) {
int32_t tileStartY = aLayerBuffer.GetTileStart(y, scaledTileSize.height);
int32_t h = scaledTileSize.height - tileStartY;
if (y + h > visibleRect.y + visibleRect.height) {
h = visibleRect.y + visibleRect.height - y;
}
nsIntPoint tileOrigin = nsIntPoint(aLayerBuffer.RoundDownToTileEdge(x, scaledTileSize.width),
aLayerBuffer.RoundDownToTileEdge(y, scaledTileSize.height));
TileHost& tileTexture = aLayerBuffer.GetTile(tileOrigin);
if (!tileTexture.IsPlaceholderTile()) {
nsIntRegion tileDrawRegion;
tileDrawRegion.And(IntRect(x, y, w, h), aLayerBuffer.GetValidRegion());
tileDrawRegion.And(tileDrawRegion, aVisibleRegion);
tileDrawRegion.Sub(tileDrawRegion, maskRegion);
if (!tileDrawRegion.IsEmpty()) {
tileDrawRegion.ScaleRoundOut(resolution, resolution);
IntPoint tileOffset((x - tileStartX) * resolution,
(y - tileStartY) * resolution);
gfx::IntSize tileSize = aLayerBuffer.GetTileSize();
RenderTile(tileTexture, aBackgroundColor, aEffectChain, aOpacity, aTransform,
aFilter, aClipRect, tileDrawRegion, tileOffset,
IntSize(tileSize.width, tileSize.height),
gfx::Rect(visibleRect.x, visibleRect.y,
visibleRect.width, visibleRect.height));
if (tileTexture.mTextureHostOnWhite) {
componentAlphaDiagnostic = DiagnosticFlags::COMPONENT_ALPHA;
}
}
}
tileY++;
y += h;
}
tileX++;
x += w;
if (compositeRegion.IsEmpty()) {
return;
}
if (aBackgroundColor) {
nsIntRegion backgroundRegion = compositeRegion;
backgroundRegion.ScaleRoundOut(resolution, resolution);
EffectChain effect;
effect.mPrimaryEffect = new EffectSolidColor(ToColor(*aBackgroundColor));
nsIntRegionRectIterator it(backgroundRegion);
for (const IntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
mCompositor->DrawQuad(graphicsRect, aClipRect, effect, 1.0, aTransform);
}
}
for (size_t i = 0; i < aLayerBuffer.GetTileCount(); ++i) {
TileHost& tile = aLayerBuffer.GetTile(i);
if (tile.IsPlaceholderTile()) {
continue;
}
TileIntPoint tilePosition = aLayerBuffer.GetPlacement().TilePosition(i);
// A sanity check that catches a lot of mistakes.
MOZ_ASSERT(tilePosition.x == tile.x && tilePosition.y == tile.y);
IntPoint tileOffset = aLayerBuffer.GetTileOffset(tilePosition);
nsIntRegion tileDrawRegion = IntRect(tileOffset, aLayerBuffer.GetScaledTileSize());
tileDrawRegion.AndWith(compositeRegion);
if (tileDrawRegion.IsEmpty()) {
continue;
}
tileDrawRegion.ScaleRoundOut(resolution, resolution);
RenderTile(tile, aEffectChain, aOpacity,
aTransform, aFilter, aClipRect, tileDrawRegion,
tileOffset * resolution, aLayerBuffer.GetTileSize(),
gfx::Rect(visibleRect.x, visibleRect.y,
visibleRect.width, visibleRect.height));
if (tile.mTextureHostOnWhite) {
componentAlphaDiagnostic = DiagnosticFlags::COMPONENT_ALPHA;
}
}
gfx::Rect rect(visibleRect.x, visibleRect.y,
visibleRect.width, visibleRect.height);
GetCompositor()->DrawDiagnostics(DiagnosticFlags::CONTENT | componentAlphaDiagnostic,

View File

@ -275,7 +275,6 @@ private:
// Renders a single given tile.
void RenderTile(TileHost& aTile,
const gfxRGBA* aBackgroundColor,
EffectChain& aEffectChain,
float aOpacity,
const gfx::Matrix4x4& aTransform,