Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[image-set] Pick first choice when identical resolutions are found
https://bugs.webkit.org/show_bug.cgi?id=257100
rdar://109619779

Reviewed by Tim Nguyen.

Step 2 of the image-set selection algorithm [0] specifies that we should
drop any <image-set-option> whose resolution we have already seen. This
can be acheived by comparing the resolution against the `result` that we
have selected in the loop. This works because the Vector is sorted by
resolution and we bail out of the loop the first time we find an image
whose resolution is greater or equal to device resolution.

While here, also fix up a bug where we were checking if the
ImageWithScale object had a non-null pointer to an image rather than
checking if the pointer was to a StyleInvalidImage object. The
ImageWithScale defaults to having a StyleInvalidImage rather than a null
pointer.

[0] https://drafts.csswg.org/css-images-4/#image-set-notation

* LayoutTests/TestExpectations:
* LayoutTests/platform/ios/TestExpectations:
* Source/WebCore/rendering/style/StyleImageSet.cpp:
(WebCore::StyleImageSet::bestImageForScaleFactor):

Canonical link: https://commits.webkit.org/264481@main
  • Loading branch information
rreno committed May 24, 2023
1 parent cb0b8f5 commit 56e5d7c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 0 additions & 2 deletions LayoutTests/TestExpectations
Expand Up @@ -3397,8 +3397,6 @@ imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-eleme

imported/w3c/web-platform-tests/css/css-images/multiple-position-color-stop-conic.html [ ImageOnlyFailure ]

imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-first-match-rendering.html [ ImageOnlyFailure ]

webkit.org/b/187773 http/tests/webAPIStatistics [ Skip ]

# This is fallout from turning Web Animations on.
Expand Down
1 change: 0 additions & 1 deletion LayoutTests/platform/ios/TestExpectations
Expand Up @@ -3600,7 +3600,6 @@ webkit.org/b/237694 [ Debug ] webgl/1.0.3/conformance/uniforms/uniform-samplers-

# image-set failing only on iOS
webkit.org/b/253095 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-rendering-2.html [ ImageOnlyFailure ]
webkit.org/b/253095 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-first-match-rendering.html [ ImageOnlyFailure ]

[ Release ] editing/spelling/toggle-spellchecking.html [ Failure Pass ]
pointerevents/mouse/pointer-event-basic-properties.html [ Timeout ]
Expand Down
6 changes: 4 additions & 2 deletions Source/WebCore/rendering/style/StyleImageSet.cpp
Expand Up @@ -90,14 +90,16 @@ ImageWithScale StyleImageSet::bestImageForScaleFactor()
const auto& image = m_images[index];
if (!image.mimeType.isNull() && !MIMETypeRegistry::isSupportedImageMIMEType(image.mimeType))
continue;

if (!result.image->isInvalidImage() && result.scaleFactor == image.scaleFactor)
continue;
if (image.scaleFactor >= m_deviceScaleFactor)
return image;

result = image;
}

ASSERT(result.scaleFactor >= 0);
if (!result.image || !result.scaleFactor)
if (result.image->isInvalidImage() || !result.scaleFactor)
result = ImageWithScale { StyleInvalidImage::create(), 1, String() };

return result;
Expand Down

0 comments on commit 56e5d7c

Please sign in to comment.