Bug 211794 - [CG] Change the UTI of the "WebP" image to be "org.webmproject.webp"
Summary: [CG] Change the UTI of the "WebP" image to be "org.webmproject.webp"
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-12 12:26 PDT by Said Abou-Hallawa
Modified: 2020-05-12 19:57 PDT (History)
2 users (show)

See Also:


Attachments
Patch (2.96 KB, patch)
2020-05-12 12:30 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (3.03 KB, patch)
2020-05-12 12:32 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (3.57 KB, patch)
2020-05-12 15:15 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (3.57 KB, patch)
2020-05-12 15:27 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (3.24 KB, patch)
2020-05-12 17:27 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2020-05-12 12:26:29 PDT
See https://developers.google.com/speed/webp/docs/riff_container.
Comment 1 Said Abou-Hallawa 2020-05-12 12:27:01 PDT
<rdar://problem/63031187>
Comment 2 Said Abou-Hallawa 2020-05-12 12:30:41 PDT
Created attachment 399154 [details]
Patch
Comment 3 Said Abou-Hallawa 2020-05-12 12:32:53 PDT
Created attachment 399155 [details]
Patch
Comment 4 Darin Adler 2020-05-12 12:38:24 PDT
Comment on attachment 399155 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=399155&action=review

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:43
> +        const char* defaultSupportedImageTypes[] = {

This is replacing a constant array with a non-constant array. Please add constexpr or a const after the * so this array is constant. I think constexpr is best.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:62
>          RetainPtr<CFArrayRef> systemImageTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());

Why not convert this into a temporary HashSet<String> instead of using it as a CFArrayRef? Because we are doing to be doing the "contains" operation on it, and that’s what a set does.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:66
> +        for (const auto* imageType : defaultSupportedImageTypes) {

We can use "auto", "auto&", "auto*", or "const char*" for this loop variable, but I don’t think "const auto*" is a great choice.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:67
> +            RetainPtr<CFStringRef> string = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, imageType, kCFStringEncodingUTF8));

There’s no good reason to use kCFStringEncodingUTF8 here. I suggest using kCFStringEncodingASCII. But also, lets just make a String directly, and use a HashSet<String> of the system image types instead of doing array searches.
Comment 5 Said Abou-Hallawa 2020-05-12 15:15:17 PDT
Created attachment 399187 [details]
Patch
Comment 6 Said Abou-Hallawa 2020-05-12 15:23:31 PDT
Comment on attachment 399155 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=399155&action=review

>> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:43
>> +        const char* defaultSupportedImageTypes[] = {
> 
> This is replacing a constant array with a non-constant array. Please add constexpr or a const after the * so this array is constant. I think constexpr is best.

I changed this to be a HashSet<String>. Instead of adding the imageTypes from an array to a HashSet, the imageTypes will be removed from this HashSet if the system does not support them. And at the end, we are going to return this HashSet.

>> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:62
>>          RetainPtr<CFArrayRef> systemImageTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());
> 
> Why not convert this into a temporary HashSet<String> instead of using it as a CFArrayRef? Because we are doing to be doing the "contains" operation on it, and that’s what a set does.

Done.
Comment 7 Said Abou-Hallawa 2020-05-12 15:27:48 PDT
Created attachment 399188 [details]
Patch
Comment 8 Darin Adler 2020-05-12 15:55:57 PDT
Comment on attachment 399187 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=399187&action=review

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:44
> +            "com.compuserve.gif",

If we are building a HashSet<String> from this we should leave the _s on them because that will result in not copying the characters in the strings.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:62
> +        RetainPtr<CFArrayRef> systemSupportedCFImageTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());

Should use auto here instead of writing RetainPtr<CFArrayRef>.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:67
> +            String imageType = String(static_cast<CFStringRef>(const_cast<void*>(value)));

No need for String() here, conversion from CFStringRef works. No need for const_cast, CFStringRef is already a const pointer type.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:69
> +            auto& systemSupportedImageTypes = *static_cast<HashSet<String>*>(context);
> +            systemSupportedImageTypes.add(imageType);

Suggest doing it in one line:

    static_cast<HashSet<String>*>(context)->add(imageType);

If we think that’s not clear enough, we could rename context to untypedSystemSupportedImageTypes.

> Source/WebCore/platform/graphics/cg/UTIRegistry.cpp:72
> +        defaultSupportedImageTypes.removeIf([&systemSupportedImageTypes] (String imageType) {

I think writing "const String&" would make this more efficient.
Comment 9 Darin Adler 2020-05-12 15:56:25 PDT
Comment on attachment 399188 [details]
Patch

Please consider the review comments I attached to an earlier version of this patch.
Comment 10 Said Abou-Hallawa 2020-05-12 17:27:40 PDT
Created attachment 399208 [details]
Patch
Comment 11 EWS 2020-05-12 19:57:07 PDT
Committed r261594: <https://trac.webkit.org/changeset/261594>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 399208 [details].