Bug 504071. Allow image drawing to snap to pixel boundaries even if there's scaling, on all platforms. Not only is it faster, it avoids seaming. This is consistent with snapping behavior of other drawing operations. r=joe

This commit is contained in:
Robert O'Callahan 2012-12-05 12:34:19 +13:00
Родитель e9179b9022
Коммит f865c42fba
7 изменённых файлов: 99 добавлений и 8 удалений

Просмотреть файл

@ -3824,15 +3824,20 @@ ComputeSnappedImageDrawingParameters(gfxContext* aCtx,
gfxRect devPixelDirty =
nsLayoutUtils::RectToGfxRect(aDirty, aAppUnitsPerDevPixel);
bool ignoreScale = false;
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
ignoreScale = true;
#endif
gfxRect fill = devPixelFill;
bool didSnap = aCtx->UserToDevicePixelSnapped(fill, ignoreScale);
gfxMatrix currentMatrix = aCtx->CurrentMatrix();
if (didSnap && currentMatrix.HasNonAxisAlignedTransform()) {
// currentMatrix must have some rotation by a multiple of 90 degrees.
gfxRect fill = devPixelFill;
bool didSnap;
// Snap even if we have a scale in the context. But don't snap if
// we have something that's not translation+scale, or if the scale flips in
// the X or Y direction, because snapped image drawing can't handle that yet.
if (!currentMatrix.HasNonAxisAlignedTransform() &&
currentMatrix.xx > 0.0 && currentMatrix.yy > 0.0 &&
aCtx->UserToDevicePixelSnapped(fill, true)) {
didSnap = true;
if (fill.IsEmpty()) {
return SnappedImageDrawingParameters();
}
} else {
didSnap = false;
fill = devPixelFill;
}

Просмотреть файл

@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<style>
body {
background-color:black;
}
div {
transform: scale(0.3);
transform-origin: 0 0;
width: 512px;
height: 256px;
background: white;
}
</style>
<div></div>

Просмотреть файл

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<style>
body {
background-color:black;
}
div {
transform: scale(0.3);
transform-origin: 0 0;
}
</style>
<div>
<!-- Test that drawing of (scaled) single pixel images is snapped -->
<img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAxJREFUCNdj+P//PwAF/gL+3MxZ5wAAAABJRU5ErkJggg=="
><img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAxJREFUCNdj+P//PwAF/gL+3MxZ5wAAAABJRU5ErkJggg==">
</div>

Просмотреть файл

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<style>
body {
background-color:black;
}
div {
transform: scale(0.3);
transform-origin: 0 0;
}
</style>
<div>
<!-- Test that drawing of a 20x20 image with all pixels the same color is snapped -->
<img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAG0lEQVQ4jWP4T2XAMGrgqIGjBo4aOGrgSDUQAOdROhuRCSeMAAAAAElFTkSuQmCC"
><img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAG0lEQVQ4jWP4T2XAMGrgqIGjBo4aOGrgSDUQAOdROhuRCSeMAAAAAElFTkSuQmCC">
</div>

Просмотреть файл

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<style>
body {
background-color:black;
}
div {
transform: scale(0.3);
transform-origin: 0 0;
}
</style>
<div>
<img style="width:412px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAYAAAB/qH1jAAAADklEQVQImWP4jwYY0AEAlpkP8c9bnjkAAAAASUVORK5CYII="
><img style="width:100px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAYAAAB/qH1jAAAADklEQVQImWP4jwYY0AEAlpkP8c9bnjkAAAAASUVORK5CYII="
>
</div>

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<style>
body {
background-color:black;
}
div {
transform: scale(0.3);
transform-origin: 0 0;
}
</style>
<div>
<!-- Test that drawing of nonuniform images is snapped -->
<!-- This is a 2x2 image where the top row is white and the bottom row is transpraent -->
<img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAADklEQVQImWP4DwUMMAAAa6YH+b3nj3MAAAAASUVORK5CYII="
><img style="width:256px; height:256px"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAADklEQVQImWP4DwUMMAAAa6YH+b3nj3MAAAAASUVORK5CYII=">
</div>

Просмотреть файл

@ -1,5 +1,8 @@
random-if(bug685516) fuzzy-if(Android,4,15) == background-image-zoom-1.html background-image-zoom-1-ref.html
== background-image-zoom-2.html about:blank
== image-seam-1a.html image-seam-1-ref.html
== image-seam-1b.html image-seam-1-ref.html
fails-if(cocoaWidget) == image-seam-2.html image-seam-2-ref.html # Quartz doesn't support EXTEND_PAD (bug 567370)
== image-zoom-1.html image-zoom-1-ref.html
== image-zoom-2.html image-zoom-1-ref.html
== invalid-url-image-1.html invalid-url-image-1-ref.html