Bug 215057 - Add glyph origins member to GlyphBuffer
Summary: Add glyph origins member to GlyphBuffer
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 214769 215059
  Show dependency treegraph
 
Reported: 2020-08-01 01:36 PDT by Myles C. Maxfield
Modified: 2020-08-04 16:14 PDT (History)
7 users (show)

See Also:


Attachments
Patch (13.24 KB, patch)
2020-08-01 01:42 PDT, Myles C. Maxfield
darin: review+
Details | Formatted Diff | Diff
Rebased (13.38 KB, patch)
2020-08-03 22:08 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Rebased (13.38 KB, patch)
2020-08-03 22: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 2020-08-01 01:36:24 PDT
Add glyph offsets member to GlyphBuffer
Comment 1 Myles C. Maxfield 2020-08-01 01:42:42 PDT
Created attachment 405780 [details]
Patch
Comment 2 Darin Adler 2020-08-01 20:55:20 PDT
Comment on attachment 405780 [details]
Patch

This business where we derive structure from platform structures seems a little strange. Seems like we could do this with some helper functions instead.
Comment 3 Myles C. Maxfield 2020-08-03 15:27:13 PDT
(In reply to Darin Adler from comment #2)
> Comment on attachment 405780 [details]
> Patch
> 
> derive structure from platform structures

Can you explain a little more what you mean by this?
Comment 4 Darin Adler 2020-08-03 15:28:58 PDT
Comment on attachment 405780 [details]
Patch

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

> Source/WebCore/platform/graphics/GlyphBuffer.h:107
> +struct GlyphBufferOrigin : CGPoint {

This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
Comment 5 Myles C. Maxfield 2020-08-03 21:09:46 PDT
Comment on attachment 405780 [details]
Patch

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

>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>> +struct GlyphBufferOrigin : CGPoint {
> 
> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".

Ah, I understand now.

What kind of helper functions did you have in mind?
Comment 6 Myles C. Maxfield 2020-08-03 21:15:09 PDT
Comment on attachment 405780 [details]
Patch

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

>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>> +struct GlyphBufferOrigin : CGPoint {
>> 
>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
> 
> Ah, I understand now.
> 
> What kind of helper functions did you have in mind?

I can think of three possibilities:

1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
3) Keep it as it is now: GlyphBufferOrigin is a CGPoint

Which of these do you think is best? (And why?)
Comment 7 Myles C. Maxfield 2020-08-03 22:08:45 PDT
Created attachment 405902 [details]
Rebased
Comment 8 Myles C. Maxfield 2020-08-03 22:11:05 PDT
Created attachment 405903 [details]
Rebased
Comment 9 Darin Adler 2020-08-04 10:05:21 PDT
Comment on attachment 405780 [details]
Patch

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

>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>> +struct GlyphBufferOrigin : CGPoint {
>>> 
>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>> 
>> Ah, I understand now.
>> 
>> What kind of helper functions did you have in mind?
> 
> I can think of three possibilities:
> 
> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
> 
> Which of these do you think is best? (And why?)

I would prefer (2).

But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?

I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.

I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
Comment 10 Darin Adler 2020-08-04 10:05:55 PDT
Comment on attachment 405903 [details]
Rebased

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

> Source/WebCore/platform/graphics/GlyphBuffer.h:319
> +        GlyphBufferOrigin origin = m_origins[index1];

auto
Comment 11 Myles C. Maxfield 2020-08-04 10:32:49 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>> 
>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>> 
>>> Ah, I understand now.
>>> 
>>> What kind of helper functions did you have in mind?
>> 
>> I can think of three possibilities:
>> 
>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>> 
>> Which of these do you think is best? (And why?)
> 
> I would prefer (2).
> 
> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
> 
> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
> 
> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.

> Is GlyphBufferOrigin a cross-platform abstraction?

Yes. Cocoa ports use CGPoint so it can be passed directly to CTFontShapeGlyphs() or CTFontTransformGlyphsWIthLanguage(). Other ports use FloatPoint, and convert the FloatPoints to the platform-specific types (whatever Harfbuzz requires) later.

> If so, then does its platform-independent interface involve CGFloat?

Yes, but it shouldn't. I can fix it.

> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.

FontCascade::drawGlyphBuffer() is one example.
Comment 12 Myles C. Maxfield 2020-08-04 12:20:08 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>>> 
>>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>>> 
>>>> Ah, I understand now.
>>>> 
>>>> What kind of helper functions did you have in mind?
>>> 
>>> I can think of three possibilities:
>>> 
>>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>>> 
>>> Which of these do you think is best? (And why?)
>> 
>> I would prefer (2).
>> 
>> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
>> 
>> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
>> 
>> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
> 
> 

Aha! I tried (2) but got:

error: static_cast from 'const WebCore::GlyphBufferAdvance *' to 'const CGSize *', which are not related by inheritance, is not allowed

This makes total sense, and I think the weird inheritance thing less bad than a call to reinterpret_cast. I'll keep (3) and commit.
Comment 13 Darin Adler 2020-08-04 12:33:06 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>>>> 
>>>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>>>> 
>>>>> Ah, I understand now.
>>>>> 
>>>>> What kind of helper functions did you have in mind?
>>>> 
>>>> I can think of three possibilities:
>>>> 
>>>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>>>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>>>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>>>> 
>>>> Which of these do you think is best? (And why?)
>>> 
>>> I would prefer (2).
>>> 
>>> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
>>> 
>>> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
>>> 
>>> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
>> 
>> 
> 
> Aha! I tried (2) but got:
> 
> error: static_cast from 'const WebCore::GlyphBufferAdvance *' to 'const CGSize *', which are not related by inheritance, is not allowed
> 
> This makes total sense, and I think the weird inheritance thing less bad than a call to reinterpret_cast. I'll keep (3) and commit.

This shows that we have something very unsafe going on.

We have an array of GlyphBufferAdvance and we pass it to something expecting an array of CGSize. This works only if we have added no data members. If I added a bool to GlyphBufferAdvance we’d have a lot of failures.
Comment 14 Darin Adler 2020-08-04 12:34:56 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>>>>> 
>>>>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>>>>> 
>>>>>> Ah, I understand now.
>>>>>> 
>>>>>> What kind of helper functions did you have in mind?
>>>>> 
>>>>> I can think of three possibilities:
>>>>> 
>>>>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>>>>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>>>>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>>>>> 
>>>>> Which of these do you think is best? (And why?)
>>>> 
>>>> I would prefer (2).
>>>> 
>>>> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
>>>> 
>>>> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
>>>> 
>>>> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
>>> 
>>> 
>> 
>> Aha! I tried (2) but got:
>> 
>> error: static_cast from 'const WebCore::GlyphBufferAdvance *' to 'const CGSize *', which are not related by inheritance, is not allowed
>> 
>> This makes total sense, and I think the weird inheritance thing less bad than a call to reinterpret_cast. I'll keep (3) and commit.
> 
> This shows that we have something very unsafe going on.
> 
> We have an array of GlyphBufferAdvance and we pass it to something expecting an array of CGSize. This works only if we have added no data members. If I added a bool to GlyphBufferAdvance we’d have a lot of failures.

We should use (1).

GlyphBufferAdvance should be:

    using GlyphBufferAdvance = FloatSize;

and

    using GlyphBufferAdvance = CGSize;

on different platforms. Then we should use non-member functions for the things we need to do in cross-platform code that are different between these two.
Comment 15 Myles C. Maxfield 2020-08-04 14:26:07 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>>>>>> 
>>>>>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>>>>>> 
>>>>>>> Ah, I understand now.
>>>>>>> 
>>>>>>> What kind of helper functions did you have in mind?
>>>>>> 
>>>>>> I can think of three possibilities:
>>>>>> 
>>>>>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>>>>>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>>>>>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>>>>>> 
>>>>>> Which of these do you think is best? (And why?)
>>>>> 
>>>>> I would prefer (2).
>>>>> 
>>>>> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
>>>>> 
>>>>> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
>>>>> 
>>>>> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
>>>> 
>>>> 
>>> 
>>> Aha! I tried (2) but got:
>>> 
>>> error: static_cast from 'const WebCore::GlyphBufferAdvance *' to 'const CGSize *', which are not related by inheritance, is not allowed
>>> 
>>> This makes total sense, and I think the weird inheritance thing less bad than a call to reinterpret_cast. I'll keep (3) and commit.
>> 
>> This shows that we have something very unsafe going on.
>> 
>> We have an array of GlyphBufferAdvance and we pass it to something expecting an array of CGSize. This works only if we have added no data members. If I added a bool to GlyphBufferAdvance we’d have a lot of failures.
> 
> We should use (1).
> 
> GlyphBufferAdvance should be:
> 
>     using GlyphBufferAdvance = FloatSize;
> 
> and
> 
>     using GlyphBufferAdvance = CGSize;
> 
> on different platforms. Then we should use non-member functions for the things we need to do in cross-platform code that are different between these two.

Right, the current code is unsafe. I agree that (1) is better than (3).

I did what you suggested, but it turned out to be quite a lot of changes - more than the rest of the patch. So, rather than pollute this one, I'm going to post a second patch to a new bug.
Comment 16 Myles C. Maxfield 2020-08-04 15:02:36 PDT
Committed r265261: <https://trac.webkit.org/changeset/265261>
Comment 17 Radar WebKit Bug Importer 2020-08-04 15:03:22 PDT
<rdar://problem/66543482>
Comment 18 Myles C. Maxfield 2020-08-04 16:14:41 PDT
Comment on attachment 405780 [details]
Patch

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

>>>>>>>>>> Source/WebCore/platform/graphics/GlyphBuffer.h:107
>>>>>>>>>> +struct GlyphBufferOrigin : CGPoint {
>>>>>>>>> 
>>>>>>>>> This is an example of deriving a structure from the Cocoa structure "CGPoint". That’s what I meant by "deriving structures from platform structures".
>>>>>>>> 
>>>>>>>> Ah, I understand now.
>>>>>>>> 
>>>>>>>> What kind of helper functions did you have in mind?
>>>>>>> 
>>>>>>> I can think of three possibilities:
>>>>>>> 
>>>>>>> 1) Typedef CGPoint to something like NativePoint, and make freestanding functions that accept and perform operations on NativePoint
>>>>>>> 2) Make GlyphBufferOrigin own a CGPoint, rather than be a CGPoint
>>>>>>> 3) Keep it as it is now: GlyphBufferOrigin is a CGPoint
>>>>>>> 
>>>>>>> Which of these do you think is best? (And why?)
>>>>>> 
>>>>>> I would prefer (2).
>>>>>> 
>>>>>> But also not sure of the bigger picture. Is GlyphBufferOrigin a cross-platform abstraction? If so, then does it’s platform-independent  interface involve CGFloat?
>>>>>> 
>>>>>> I’d like to see what the cross-platform abstraction is and see some examples of platform-independent code using it.
>>>>>> 
>>>>>> I’ve noticed our platform layer current has a lot of cross-platform non-abstraction. Supposedly platform-independent types and typedefs that don’t actually enable any shared platform-independent code.
>>>>> 
>>>>> 
>>>> 
>>>> Aha! I tried (2) but got:
>>>> 
>>>> error: static_cast from 'const WebCore::GlyphBufferAdvance *' to 'const CGSize *', which are not related by inheritance, is not allowed
>>>> 
>>>> This makes total sense, and I think the weird inheritance thing less bad than a call to reinterpret_cast. I'll keep (3) and commit.
>>> 
>>> This shows that we have something very unsafe going on.
>>> 
>>> We have an array of GlyphBufferAdvance and we pass it to something expecting an array of CGSize. This works only if we have added no data members. If I added a bool to GlyphBufferAdvance we’d have a lot of failures.
>> 
>> We should use (1).
>> 
>> GlyphBufferAdvance should be:
>> 
>>     using GlyphBufferAdvance = FloatSize;
>> 
>> and
>> 
>>     using GlyphBufferAdvance = CGSize;
>> 
>> on different platforms. Then we should use non-member functions for the things we need to do in cross-platform code that are different between these two.
> 
> Right, the current code is unsafe. I agree that (1) is better than (3).
> 
> I did what you suggested, but it turned out to be quite a lot of changes - more than the rest of the patch. So, rather than pollute this one, I'm going to post a second patch to a new bug.

https://bugs.webkit.org/show_bug.cgi?id=215143