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

Image-Orientation: Use the DrawRRect shader fast path where possible

The previous code disabled the shader fast path whenever respecting
image orientation, even when the orientation would not make any
different (i.e. for non bitmaps or the default orientation).

Fix this by adding Image::HasDefaultOrientation and using it where
possible.

Bug: 1036181
Change-Id: Ifb8f9163caf6a4352b0c1516664427c5b49d48a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993840
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#730191}
parent e627aa25
......@@ -376,13 +376,11 @@ FloatRect ComputeSubsetForBackground(const FloatRect& phase_and_size,
FloatRect CorrectSrcRectForImageOrientation(BitmapImage* image,
FloatRect original_rect) {
ImageOrientation orientation = image->CurrentFrameOrientation();
if (orientation != kDefaultImageOrientation) {
AffineTransform forward_map =
orientation.TransformFromDefault(original_rect.Size());
AffineTransform inverse_map = forward_map.Inverse();
return inverse_map.MapRect(original_rect);
}
return original_rect;
DCHECK(orientation != kDefaultImageOrientation);
AffineTransform forward_map =
orientation.TransformFromDefault(original_rect.Size());
AffineTransform inverse_map = forward_map.Inverse();
return inverse_map.MapRect(original_rect);
}
// The unsnapped_subset_size should be the target painting area implied by the
......@@ -441,7 +439,7 @@ void DrawTiledBackground(GraphicsContext& context,
// rect to be in the unrotated image space, but we have computed it here in
// the rotated space in order to position and size the background. Undo the
// src rect rotation if necessaary.
if (respect_orientation && image->IsBitmapImage()) {
if (respect_orientation && !image->HasDefaultOrientation()) {
visible_src_rect = CorrectSrcRectForImageOrientation(ToBitmapImage(image),
visible_src_rect);
}
......@@ -559,6 +557,7 @@ inline bool PaintFastBottomLayer(Node* node,
!has_intrinsic_size
? image_tile.Size()
: FloatSize(image->Size(info.respect_image_orientation));
// Subset computation needs the same location as was used with
// ComputePhaseForBackground above, but needs the unsnapped destination
// size to correctly calculate sprite subsets in the presence of zoom. But if
......@@ -584,7 +583,7 @@ inline bool PaintFastBottomLayer(Node* node,
// to be in the unrotated image space, but we have computed it here in the
// rotated space in order to position and size the background. Undo the src
// rect rotation if necessaary.
if (info.respect_image_orientation && image->IsBitmapImage()) {
if (info.respect_image_orientation && !image->HasDefaultOrientation()) {
src_rect =
CorrectSrcRectForImageOrientation(ToBitmapImage(image), src_rect);
}
......
......@@ -156,6 +156,11 @@ IntSize BitmapImage::SizeRespectingOrientation() const {
return size_respecting_orientation_;
}
bool BitmapImage::HasDefaultOrientation() const {
ImageOrientation orientation = CurrentFrameOrientation();
return orientation == kDefaultImageOrientation;
}
bool BitmapImage::GetHotSpot(IntPoint& hot_spot) const {
return decoder_ && decoder_->HotSpot(hot_spot);
}
......
......@@ -66,6 +66,7 @@ class PLATFORM_EXPORT BitmapImage final : public Image {
IntSize Size() const override;
IntSize SizeRespectingOrientation() const;
bool HasDefaultOrientation() const override;
bool GetHotSpot(IntPoint&) const override;
String FilenameExtension() const override;
......
......@@ -1021,7 +1021,8 @@ void GraphicsContext::DrawImageRRect(
&image_flags);
bool use_shader = (visible_src == src_rect) &&
(respect_orientation == kDoNotRespectImageOrientation);
(respect_orientation == kDoNotRespectImageOrientation ||
image->HasDefaultOrientation());
if (use_shader) {
const SkMatrix local_matrix = SkMatrix::MakeRectToRect(
visible_src, dest.Rect(), SkMatrix::kFill_ScaleToFit);
......
......@@ -114,6 +114,9 @@ class PLATFORM_EXPORT Image : public ThreadSafeRefCounted<Image> {
IntRect Rect() const { return IntRect(IntPoint(), Size()); }
int width() const { return Size().Width(); }
int height() const { return Size().Height(); }
virtual bool HasDefaultOrientation() const { return true; }
virtual bool GetHotSpot(IntPoint&) const { return false; }
enum SizeAvailability {
......
......@@ -7179,7 +7179,6 @@ crbug.com/1039401 [ Linux ] external/wpt/css/css-images/image-orientation/image-
crbug.com/1039401 [ Linux ] external/wpt/css/css-images/image-orientation/image-orientation-none.html [ Failure ]
crbug.com/1039401 [ Linux ] external/wpt/css/css-text-decor/text-decoration-subelements-002.html [ Failure ]
crbug.com/1039401 [ Linux ] external/wpt/css/css-text-decor/text-decoration-subelements-003.html [ Failure ]
crbug.com/1039401 [ Linux ] fast/backgrounds/background-svg-scaling.html [ Failure ]
crbug.com/1039401 [ Linux ] fast/backgrounds/size/contain-and-cover.html [ Failure ]
crbug.com/1039401 [ Linux ] fast/dom/HTMLMeterElement/meter-boundary-values.html [ Failure ]
crbug.com/1039401 [ Linux ] fast/dom/HTMLMeterElement/meter-optimums.html [ Failure ]
......@@ -7188,7 +7187,6 @@ crbug.com/1039401 [ Linux ] fast/forms/select/input-select-after-resize.html [ F
crbug.com/1039401 [ Linux ] paint/invalidation/forms/range-focus-by-mouse-then-keydown.html [ Failure ]
crbug.com/1039401 [ Linux ] svg/W3C-SVG-1.1/filters-turb-01-f.svg [ Failure ]
crbug.com/1039401 [ Linux ] svg/as-background-image/background-image-preserveaspectRatio-support.html [ Failure ]
crbug.com/1039401 [ Linux ] svg/as-image/image-respects-deviceScaleFactor.html [ Failure ]
crbug.com/1039401 [ Linux ] svg/zoom/page/zoom-background-image-tiled.html [ Failure ]
crbug.com/1039401 [ Linux ] svg/zoom/page/zoom-background-images.html [ Failure ]
crbug.com/1039401 [ Linux ] svg/zoom/page/zoom-img-preserveAspectRatio-support-1.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