Commit b431dc71 authored by Stephen Chenney's avatar Stephen Chenney Committed by Commit Bot

[Image-Orientation] Fix image-orientation for background-repeat

For tiled image painting the image was not correctly oriented.
Fix it by pre-orienting the image before creating the tiling
shader.

The test still fails due to a lack of fuzzy matching, but the
result is now correct. See external/wpt/css/css-images/image-orientation/image-orientation-background-properties.html

Bug: 1066634
Change-Id: Ie0a2f534bf760174d337fdaa6838e82b33280d46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464902Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816126}
parent 73c98bc4
...@@ -226,7 +226,7 @@ void Image::DrawPattern(GraphicsContext& context, ...@@ -226,7 +226,7 @@ void Image::DrawPattern(GraphicsContext& context,
SkBlendMode composite_op, SkBlendMode composite_op,
const FloatRect& dest_rect, const FloatRect& dest_rect,
const FloatSize& repeat_spacing, const FloatSize& repeat_spacing,
RespectImageOrientationEnum) { RespectImageOrientationEnum respect_orientation) {
TRACE_EVENT0("skia", "Image::drawPattern"); TRACE_EVENT0("skia", "Image::drawPattern");
if (dest_rect.IsEmpty()) if (dest_rect.IsEmpty())
...@@ -236,34 +236,48 @@ void Image::DrawPattern(GraphicsContext& context, ...@@ -236,34 +236,48 @@ void Image::DrawPattern(GraphicsContext& context,
if (!image) if (!image)
return; // nothing to draw return; // nothing to draw
// The subset_rect is in source image space, unscaled. // The subset_rect is in source image space, unscaled, unoriented.
IntRect subset_rect = EnclosingIntRect(float_src_rect); IntRect subset_rect = EnclosingIntRect(float_src_rect);
subset_rect.Intersect(IntRect(0, 0, image.width(), image.height())); subset_rect.Intersect(IntRect(0, 0, image.width(), image.height()));
if (subset_rect.IsEmpty()) if (subset_rect.IsEmpty())
return; // nothing to draw return; // nothing to draw
// Apply image orientation, if necessary
FloatSize oriented_scale = scale_src_to_dest;
if (respect_orientation && !HasDefaultOrientation()) {
FloatSize original_image_size(SizeAsFloat(kDoNotRespectImageOrientation));
image = ResizeAndOrientImage(image, CurrentFrameOrientation());
subset_rect = RoundedIntRect(CorrectSrcRectForImageOrientation(
original_image_size, FloatRect(subset_rect)));
// Upstream, the scale_src_to_dest was computed to take an un-oriented size
// and make it oriented. For example, an image that is 100x50 un-oriented
// and 50x100 oriented will have a scale of (0.5,2). Undo this, because the
// scale has now been applied by orienting the image.
oriented_scale.Scale(
original_image_size.Width() / static_cast<float>(image.width()),
original_image_size.Height() / static_cast<float>(image.height()));
}
SkMatrix local_matrix; SkMatrix local_matrix;
// We also need to translate it such that the origin of the pattern is the // We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what Blink expects. Skia uses // origin of the destination rect, which is what Blink expects. Skia uses
// the coordinate system origin as the base for the pattern. If Blink wants // the coordinate system origin as the base for the pattern. If Blink wants
// a shifted image, it will shift it from there using the localMatrix. // a shifted image, it will shift it from there using the localMatrix.
const float adjusted_x = const float adjusted_x = phase.X() + subset_rect.X() * oriented_scale.Width();
phase.X() + subset_rect.X() * scale_src_to_dest.Width();
const float adjusted_y = const float adjusted_y =
phase.Y() + subset_rect.Y() * scale_src_to_dest.Height(); phase.Y() + subset_rect.Y() * oriented_scale.Height();
local_matrix.setTranslate(SkFloatToScalar(adjusted_x), local_matrix.setTranslate(SkFloatToScalar(adjusted_x),
SkFloatToScalar(adjusted_y)); SkFloatToScalar(adjusted_y));
// Apply the scale to have the subset correctly fill the destination. // Apply the scale to have the subset correctly fill the destination.
local_matrix.preScale(scale_src_to_dest.Width(), scale_src_to_dest.Height()); local_matrix.preScale(oriented_scale.Width(), oriented_scale.Height());
// Fetch this now as subsetting may swap the image. // Fetch this now as subsetting may swap the image.
auto image_id = image.stable_id(); auto image_id = image.stable_id();
const FloatSize tile_size( const FloatSize tile_size(
subset_rect.Width() * scale_src_to_dest.Width() + repeat_spacing.Width(), subset_rect.Width() * oriented_scale.Width() + repeat_spacing.Width(),
subset_rect.Height() * scale_src_to_dest.Height() + subset_rect.Height() * oriented_scale.Height() + repeat_spacing.Height());
repeat_spacing.Height());
const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x, const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x,
adjusted_x + tile_size.Width()); adjusted_x + tile_size.Width());
const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y, const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y,
...@@ -273,8 +287,8 @@ void Image::DrawPattern(GraphicsContext& context, ...@@ -273,8 +287,8 @@ void Image::DrawPattern(GraphicsContext& context,
context.ComputeFilterQuality(this, dest_rect, FloatRect(subset_rect)); context.ComputeFilterQuality(this, dest_rect, FloatRect(subset_rect));
sk_sp<PaintShader> tile_shader = CreatePatternShader( sk_sp<PaintShader> tile_shader = CreatePatternShader(
image, local_matrix, quality_to_use, context.ShouldAntialias(), image, local_matrix, quality_to_use, context.ShouldAntialias(),
FloatSize(repeat_spacing.Width() / scale_src_to_dest.Width(), FloatSize(repeat_spacing.Width() / oriented_scale.Width(),
repeat_spacing.Height() / scale_src_to_dest.Height()), repeat_spacing.Height() / oriented_scale.Height()),
tmx, tmy, subset_rect); tmx, tmy, subset_rect);
PaintFlags flags = context.FillFlags(); PaintFlags flags = context.FillFlags();
......
...@@ -319,9 +319,6 @@ wpt_internal/webgpu/* [ Skip ] ...@@ -319,9 +319,6 @@ wpt_internal/webgpu/* [ Skip ]
crbug.com/1018273 [ Mac ] compositing/gestures/gesture-tapHighlight-2-iframe-scrolled-inner.html [ Failure ] crbug.com/1018273 [ Mac ] compositing/gestures/gesture-tapHighlight-2-iframe-scrolled-inner.html [ Failure ]
# Fails due to lack of support for image orientation in tiling shaders.
crbug.com/1066634 external/wpt/css/css-images/image-orientation/image-orientation-background-properties.html [ Failure ]
# Requires support of the image-resolution CSS property # Requires support of the image-resolution CSS property
crbug.com/1086473 external/wpt/css/css-images/image-resolution/* [ Skip ] crbug.com/1086473 external/wpt/css/css-images/image-resolution/* [ Skip ]
...@@ -345,6 +342,7 @@ crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orienta ...@@ -345,6 +342,7 @@ crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orienta
crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orientation-none.html [ Failure ] crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orientation-none.html [ Failure ]
crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orientation-aspect-ratio.html [ Failure ] crbug.com/997202 external/wpt/css/css-images/image-orientation/svg-image-orientation-aspect-ratio.html [ Failure ]
crbug.com/997202 external/wpt/css/css-images/image-orientation/image-orientation-background-position.html [ Failure ] crbug.com/997202 external/wpt/css/css-images/image-orientation/image-orientation-background-position.html [ Failure ]
crbug.com/997202 external/wpt/css/css-images/image-orientation/image-orientation-background-properties.html [ Failure ]
# Ref results are wrong on the background and list case, not sure on border result # Ref results are wrong on the background and list case, not sure on border result
crbug.com/1076121 external/wpt/css/css-images/image-orientation/image-orientation-list-style-image.html [ Failure ] crbug.com/1076121 external/wpt/css/css-images/image-orientation/image-orientation-list-style-image.html [ Failure ]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment