Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Sep 15, 2022

Conditionally switch the text alas to R8G8B8A8 format if a font/glyph pair claims to have a color. This implies either a bitmap emoji or a color font. Each font-glyph pair also must track whether or not it contains color so we can adjust the vertex shader behavior to drop any specified text color

Before

flutter_01

After

flutter_04

Fixes flutter/flutter#111599
Fixes flutter/flutter#111699

glyph_atlas_sampler,
v_unit_vertex * scale_perspective + offset
).aaaa * v_text_color;
if (frag_info.font_has_color == 1.0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still might not be right, because we can combine COLR and other fonts into a single atlas. When I made this unconditional I noticed that several fonts that were previously specified as white were rendered as black instead in the wonders app

@jonahwilliams jonahwilliams changed the title [Impeller] add support for COLR v0 and v1 fonts [Impeller] add support for COLR fonts and bitmap emojis Sep 16, 2022
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(sk_font);
SkBulkGlyphMetricsAndPaths paths{strikeSpec};
auto sk_glyph = paths.glyph(font_glyph.glyph.index);
*has_color |= sk_glyph->isColor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ask Skia to expose API for this.

static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
size_t atlas_size) {
size_t atlas_size,
bool* has_color) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having this be an out param, we could figure it out based on the colorType of the bitmap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this back into the atlas, because I need to track each font + glyph pair anyway

// Step 6: Upload the atlas as a texture.
// ---------------------------------------------------------------------------
auto format =
has_color ? PixelFormat::kR8G8B8A8UNormInt : PixelFormat::kA8UNormInt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here something like: FromSk(bitmap->colorType())

@jonahwilliams
Copy link
Contributor Author

I've actually already re-written most of this, because I need to track it at the level of the font-glyph pair too so the shader is correct

@jonahwilliams jonahwilliams marked this pull request as ready for review September 16, 2022 01:55
@jonahwilliams
Copy link
Contributor Author

This needs tests, I thiink we should be able to use emojis in playground. and other things...

vec2 scale_perspective = v_atlas_glyph_size / frag_info.atlas_size;
vec2 offset = v_atlas_position / frag_info.atlas_size;
if (v_color_glyph == 1.0) {
frag_color = texture(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ignore text color if we're using a bitmap font or colr font

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dnfield
Copy link
Contributor

dnfield commented Sep 16, 2022

I'm pretty sure we have a playground that has an emoji that wasn't rendering right, and now it should .. so this is tested, right?

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(sk_font);
SkBulkGlyphMetricsAndPaths paths{strikeSpec};
return paths.glyph(font_glyph.glyph.index)->isColor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: file an issue and a TODO here to use some public API from Skia for this.

also nit: maybe this belongs on impeller's Glyph type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo added. I agree this could probably be refactored. Lets see what we need to do for SDF and large glyphs.

@jonahwilliams
Copy link
Contributor Author

Confusingly the test using NotoColorEmoji still doesn't work as expected

jonahwilliams added 2 commits September 15, 2022 21:00
@jonahwilliams jonahwilliams added autosubmit Merge PR when tree becomes green via auto submit App and removed needs tests labels Sep 16, 2022
@auto-submit auto-submit bot merged commit 61896b3 into flutter:main Sep 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2022
@jonahwilliams jonahwilliams deleted the add_impeller_colrv01_support branch September 16, 2022 15:32
jonahwilliams pushed a commit that referenced this pull request Sep 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2022
Oleh-Sv pushed a commit to Oleh-Sv/engine that referenced this pull request Sep 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] emojis do not render properly [Impeller] Support COLRv1 fonts in impeller backend

2 participants