Bug 157694 - Support ArrayBufferViews in the CSS Font Loading API
Summary: Support ArrayBufferViews in the CSS Font Loading API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
: 154624 (view as bug list)
Depends on:
Blocks: 153346
  Show dependency treegraph
 
Reported: 2016-05-13 16:47 PDT by Myles C. Maxfield
Modified: 2016-06-20 14:37 PDT (History)
8 users (show)

See Also:


Attachments
WIP (10.29 KB, patch)
2016-05-13 16:48 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (15.20 KB, patch)
2016-05-13 17:45 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (15.21 KB, patch)
2016-05-13 19:19 PDT, Myles C. Maxfield
darin: review+
Details | Formatted Diff | Diff
Patch for committing (21.47 KB, patch)
2016-05-14 11:11 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2016-05-13 16:47:41 PDT
Support ArrayBufferViews in the CSS Font Loading API
Comment 1 Myles C. Maxfield 2016-05-13 16:48:14 PDT
Created attachment 278894 [details]
WIP
Comment 2 Myles C. Maxfield 2016-05-13 17:45:41 PDT
Created attachment 278902 [details]
Patch
Comment 3 Myles C. Maxfield 2016-05-13 17:46:06 PDT
<rdar://problem/25554267>
Comment 4 Myles C. Maxfield 2016-05-13 19:19:07 PDT
Created attachment 278909 [details]
Patch
Comment 5 Darin Adler 2016-05-14 09:03:40 PDT
Comment on attachment 278909 [details]
Patch

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

> Source/WebCore/css/CSSFontFaceSource.cpp:71
> +CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CachedFont* font, SVGFontFaceElement* fontFace, RefPtr<JSC::ArrayBufferView> arrayBufferView)

This should be RefPtr&&; that’s the correct idiom for something that a function takes ownership of with WTFMove.

> Source/WebCore/css/CSSFontFaceSource.cpp:144
> +                RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>(m_immediateSource->baseAddress()), m_immediateSource->byteLength());
> +                ASSERT(buffer);

This construction is wasteful. This SharedBuffer::create function returns a Ref, not a RefPtr, and we should use auto to accommodate that. And Ref explicitly states that the value is never null; it would obviate the need for an assertion.

> Source/WebCore/css/FontFace.cpp:44
> +    bool immediateData = false;

What does the term "immediate data" mean? I guess it means local data that does not require loading. Is there a more precise term for this? Maybe dataRequiresAsynchronousLoading, initialized to true?

> Source/WebCore/css/FontFace.cpp:59
> +        std::unique_ptr<CSSFontFaceSource> source = std::make_unique<CSSFontFaceSource>(result->backing(), String(), nullptr, nullptr, arrayBufferView);

This line is super-long and would be shorter and less repetitive with auto and { }:

    auto source = std::make_unique<CSSFontFaceSource>(result->backing(), { }, nullptr, nullptr, arrayBufferView);

> Source/WebCore/css/FontFace.cpp:63
> +    } else if (auto arrayBuffer = toArrayBuffer(source)) {
> +        auto arrayBufferView = JSC::Uint8Array::create(arrayBuffer, 0, arrayBuffer->byteLength());

I suggest making a helper function that combines the toArrayBufferView and toArrayBuffer cases and returns a Ref<ArrayBufferView> so don’t need to repeat code.

Another possibility would be a helper function that makes the CSSFontFaceSource, which could help us avoid the local variable and the WTFMove.

> Source/WebCore/css/FontFace.cpp:64
> +        std::unique_ptr<CSSFontFaceSource> source = std::make_unique<CSSFontFaceSource>(result->backing(), String(), nullptr, nullptr, arrayBufferView);

This line is super-long and would be shorter and less repetitive with auto and { }:

    auto source = std::make_unique<CSSFontFaceSource>(result->backing(), { }, nullptr, nullptr, arrayBufferView);

> Source/WebCore/loader/cache/CachedFont.cpp:118
> +#if !PLATFORM(COCOA)
> +    if (isWOFF(buffer.get())) {
> +        Vector<char> convertedFont;
> +        if (!convertWOFFToSfnt(buffer.get(), convertedFont))
> +            buffer = nullptr;
> +        else
> +            buffer = SharedBuffer::adoptVector(convertedFont);
> +        wrapping = false;
> +    } else
> +#endif
> +        wrapping = true;

This construction with an else that goes across #endif is not great. I think we should just set wrapping to true before the #if, and then set it to false inside the if statement body and not worry about the dead store.

It’s strange that isWOFF takes a SharedBuffer* instead of SharedBuffer&.
Comment 6 Darin Adler 2016-05-14 09:05:18 PDT
Comment on attachment 278909 [details]
Patch

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

>> Source/WebCore/css/FontFace.cpp:64
>> +        std::unique_ptr<CSSFontFaceSource> source = std::make_unique<CSSFontFaceSource>(result->backing(), String(), nullptr, nullptr, arrayBufferView);
> 
> This line is super-long and would be shorter and less repetitive with auto and { }:
> 
>     auto source = std::make_unique<CSSFontFaceSource>(result->backing(), { }, nullptr, nullptr, arrayBufferView);

I also think this should be WTFMove(arrayBufferView) to avoid one round of reference count churn.
Comment 7 Myles C. Maxfield 2016-05-14 11:06:35 PDT
Comment on attachment 278909 [details]
Patch

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

>> Source/WebCore/css/CSSFontFaceSource.cpp:144
>> +                ASSERT(buffer);
> 
> This construction is wasteful. This SharedBuffer::create function returns a Ref, not a RefPtr, and we should use auto to accommodate that. And Ref explicitly states that the value is never null; it would obviate the need for an assertion.

Unfortunately, it currently returns a PassRefPtr :(

I'd like to fix that, but think that's outside the scope of this patch.

>> Source/WebCore/css/FontFace.cpp:44
>> +    bool immediateData = false;
> 
> What does the term "immediate data" mean? I guess it means local data that does not require loading. Is there a more precise term for this? Maybe dataRequiresAsynchronousLoading, initialized to true?

I was going for the sense of "immediate" that is used in assembly instructions, meaning that the data is right here and you don't have to do anything to get to it. I'm happy with dataRequiresAsynchronousLoading too.

>> Source/WebCore/css/FontFace.cpp:59
>> +        std::unique_ptr<CSSFontFaceSource> source = std::make_unique<CSSFontFaceSource>(result->backing(), String(), nullptr, nullptr, arrayBufferView);
> 
> This line is super-long and would be shorter and less repetitive with auto and { }:
> 
>     auto source = std::make_unique<CSSFontFaceSource>(result->backing(), { }, nullptr, nullptr, arrayBufferView);

It looks like the { } causes a compilation failure.
Comment 8 Myles C. Maxfield 2016-05-14 11:11:07 PDT
Created attachment 278935 [details]
Patch for committing
Comment 9 WebKit Commit Bot 2016-05-14 11:12:09 PDT
Attachment 278935 [details] did not pass style-queue:


ERROR: Source/WebCore/loader/cache/CachedFont.cpp:107:  'buffer' is incorrectly named. It should be named 'protector' or 'protectedBytes'.  [readability/naming/protected] [4]
Total errors found: 1 in 11 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 WebKit Commit Bot 2016-05-14 12:17:41 PDT
Comment on attachment 278935 [details]
Patch for committing

Clearing flags on attachment: 278935

Committed r200921: <http://trac.webkit.org/changeset/200921>
Comment 11 Brady Eidson 2016-05-16 08:40:01 PDT
(In reply to comment #9)
> Attachment 278935 [details] did not pass style-queue:
> 
> 
> ERROR: Source/WebCore/loader/cache/CachedFont.cpp:107:  'buffer' is
> incorrectly named. It should be named 'protector' or 'protectedBytes'. 
> [readability/naming/protected] [4]
> Total errors found: 1 in 11 files


While the intention of this RefPtr was not to be a protector, and therefore the style checker incorrectly flagged it...  the RefPtr is actually a misuse of RefPtr because it is entirely unnecessary.

I'm considering ways to detect RefPtr misuse, though as long as we style check line-by-line that may be difficult.
Comment 12 Myles C. Maxfield 2016-06-20 14:37:12 PDT
*** Bug 154624 has been marked as a duplicate of this bug. ***