Bug 215143 - Make GlyphBufferAdvance and GlyphBufferOrigin more robust
Summary: Make GlyphBufferAdvance and GlyphBufferOrigin more robust
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
Depends on:
Blocks: 206208
  Show dependency treegraph
 
Reported: 2020-08-04 15:08 PDT by Myles C. Maxfield
Modified: 2020-09-07 09:49 PDT (History)
13 users (show)

See Also:


Attachments
Patch (49.65 KB, patch)
2020-08-04 16:14 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (47.78 KB, patch)
2020-08-04 16:21 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (45.84 KB, patch)
2020-08-04 21:49 PDT, Myles C. Maxfield
zalan: review+
Details | Formatted Diff | Diff
Patch for committing (51.10 KB, patch)
2020-09-05 21:15 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch for committing (49.37 KB, patch)
2020-09-05 21:34 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch for committing (49.37 KB, patch)
2020-09-06 15:09 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch for committing (54.63 KB, patch)
2020-09-06 16:47 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 2020-08-04 15:08:20 PDT
Make GlyphBufferAdvance and GlyphBufferOrigin more robust
Comment 1 Myles C. Maxfield 2020-08-04 16:14:21 PDT
Created attachment 405957 [details]
Patch
Comment 2 Myles C. Maxfield 2020-08-04 16:21:39 PDT
Created attachment 405959 [details]
Patch
Comment 3 Darin Adler 2020-08-04 16:53:46 PDT
Comment on attachment 405959 [details]
Patch

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

Thanks for considering my suggestion.

> Source/WebCore/platform/graphics/GlyphBuffer.h:90
> +        m_origins.append(createGlyphBufferOrigin());

m_origins.append({ });

> Source/WebCore/platform/graphics/GlyphBuffer.h:110
> +        m_origins.insertVector(location, Vector<GlyphBufferOrigin>(length, createGlyphBufferOrigin()));

Can just use { } here.

> Source/WebCore/platform/graphics/GlyphBuffer.h:153
> +            m_advances[i] = createGlyphBufferAdvance(FloatSize(

Maybe overload makeGlyphBufferAdvance so we don’t need to cast to FloatSize here? And/or just use { } instead of FloatSize().

> Source/WebCore/platform/graphics/GlyphBufferMembers.h:72
> +inline GlyphBufferAdvance createGlyphBufferAdvance(const FloatSize& = FloatSize());
> +inline FloatSize floatSizeFromGlyphBufferAdvance(const GlyphBufferAdvance&);
> +inline void setGlyphBufferAdvanceWidth(GlyphBufferAdvance&, float);
> +inline void setGlyphBufferAdvanceHeight(GlyphBufferAdvance&, float);
> +inline float glyphBufferAdvanceWidth(const GlyphBufferAdvance&);
> +inline float glyphBufferAdvanceHeight(const GlyphBufferAdvance&);
> +inline GlyphBufferOrigin createGlyphBufferOrigin(const FloatPoint& = FloatPoint());
> +inline FloatPoint floatPointFromGlyphBufferOrigin(const GlyphBufferOrigin&);
> +inline void setGlyphBufferOriginX(GlyphBufferOrigin&, float);
> +inline void setGlyphBufferOriginY(GlyphBufferOrigin&, float);
> +inline float glyphBufferOriginX(const GlyphBufferOrigin&);
> +inline float glyphBufferOriginY(const GlyphBufferOrigin&);

In WebKit, I generally suggest reserving the word create for things that are heap-allocated and use make for things that are not. Also, because C++ has overloading, a lot of these functions could have shorter names. I suggest these names:

    makeGlyphBufferAdvance
    size
    setWidth
    setHeight
    width
    height
    makeGlyphBufferOrigin
    point
    setX
    setY
    x
    y

It’s possible these names are *too* short, but I think we should try to get closer to these names. Code won’t be readable if the names are too long.
Comment 4 Myles C. Maxfield 2020-08-04 17:26:55 PDT
Comment on attachment 405959 [details]
Patch

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

>> Source/WebCore/platform/graphics/GlyphBuffer.h:90
>> +        m_origins.append(createGlyphBufferOrigin());
> 
> m_origins.append({ });

Will this actually zero-fill a CGPoint struct?
Comment 5 Darin Adler 2020-08-04 17:54:57 PDT
Comment on attachment 405959 [details]
Patch

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

>>> Source/WebCore/platform/graphics/GlyphBuffer.h:90
>>> +        m_origins.append(createGlyphBufferOrigin());
>> 
>> m_origins.append({ });
> 
> Will this actually zero-fill a CGPoint struct?

Yes.

Roughly speaking, there are only a few ways to *not* initialize scalars, and the mostly get zero-initialized.

In the specific case of CGPoint and { }, this technically is aggregate initialization. Since the number of initializer clauses (0) is less than the number of members (2) the remaining members are value-initialized, which for scalars means they are zero-initialized.
Comment 6 Myles C. Maxfield 2020-08-04 21:49:54 PDT
Created attachment 405984 [details]
Patch
Comment 7 Radar WebKit Bug Importer 2020-08-11 15:09:34 PDT
<rdar://problem/66864884>
Comment 8 Darin Adler 2020-09-05 08:20:05 PDT
Comment on attachment 405984 [details]
Patch

This is great!
Comment 9 Myles C. Maxfield 2020-09-05 21:15:40 PDT
Created attachment 408113 [details]
Patch for committing
Comment 10 Myles C. Maxfield 2020-09-05 21:34:10 PDT
Created attachment 408114 [details]
Patch for committing
Comment 11 Myles C. Maxfield 2020-09-06 15:09:20 PDT
Created attachment 408137 [details]
Patch for committing
Comment 12 Myles C. Maxfield 2020-09-06 16:30:56 PDT
I see what's happening. I need to initialize m_initialAdvance to (0, 0).
Comment 13 Myles C. Maxfield 2020-09-06 16:47:42 PDT
Created attachment 408150 [details]
Patch for committing
Comment 14 Darin Adler 2020-09-06 16:54:58 PDT
Comment on attachment 408150 [details]
Patch for committing

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

> Source/WebCore/platform/graphics/GlyphBuffer.h:216
> +    GlyphBufferAdvance m_initialAdvance { makeGlyphBufferAdvance() };

I would have expected that just empty braces, { }, would do the trick here; surprised that a call to makeGlyphBufferAdvance() is needed.
Comment 15 EWS 2020-09-06 17:52:57 PDT
Committed r266688: <https://trac.webkit.org/changeset/266688>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408150 [details].
Comment 16 Myles C. Maxfield 2020-09-06 18:05:08 PDT
Comment on attachment 408150 [details]
Patch for committing

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

>> Source/WebCore/platform/graphics/GlyphBuffer.h:216
>> +    GlyphBufferAdvance m_initialAdvance { makeGlyphBufferAdvance() };
> 
> I would have expected that just empty braces, { }, would do the trick here; surprised that a call to makeGlyphBufferAdvance() is needed.

Me too! But this looks like the reason why the obsoleted patches were red.
Comment 17 Darin Adler 2020-09-07 09:49:54 PDT
Comment on attachment 408150 [details]
Patch for committing

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

>>> Source/WebCore/platform/graphics/GlyphBuffer.h:216
>>> +    GlyphBufferAdvance m_initialAdvance { makeGlyphBufferAdvance() };
>> 
>> I would have expected that just empty braces, { }, would do the trick here; surprised that a call to makeGlyphBufferAdvance() is needed.
> 
> Me too! But this looks like the reason why the obsoleted patches were red.

In those obsoleted patches there were no braces at all.

That would leave it uninitialized.

My point is that you do need the braces but don’t need the function call.