This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] add support for COLR fonts and bitmap emojis #36161
Merged
auto-submit
merged 7 commits into
flutter:main
from
jonahwilliams:add_impeller_colrv01_support
Sep 16, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a4a961
[Impeller] add support for COLR v0 and v1 fonts
e0944c5
add emoji support
d047bb7
++
3d2654b
++
0e9f05f
Merge branch 'master' of github.com:flutter/engine into add_impeller_…
657f2f7
++
8f613f3
add 'test'
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,9 @@ | |
| #include "third_party/skia/include/core/SkFontMetrics.h" | ||
| #include "third_party/skia/include/core/SkRSXform.h" | ||
| #include "third_party/skia/include/core/SkSurface.h" | ||
| #include "third_party/skia/src/core/SkIPoint16.h" //nogncheck | ||
| #include "third_party/skia/src/gpu/GrRectanizer.h" //nogncheck | ||
| #include "third_party/skia/src/core/SkIPoint16.h" //nogncheck | ||
| #include "third_party/skia/src/core/SkStrikeSpec.h" // nogncheck | ||
| #include "third_party/skia/src/gpu/GrRectanizer.h" //nogncheck | ||
|
|
||
| namespace impeller { | ||
|
|
||
|
|
@@ -107,7 +108,9 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas, | |
| size_t atlas_size) { | ||
| TRACE_EVENT0("impeller", __FUNCTION__); | ||
| auto bitmap = std::make_shared<SkBitmap>(); | ||
| auto image_info = SkImageInfo::MakeA8(atlas_size, atlas_size); | ||
| auto image_info = atlas.ContainsColorGlyph() | ||
| ? SkImageInfo::MakeN32Premul(atlas_size, atlas_size) | ||
| : SkImageInfo::MakeA8(atlas_size, atlas_size); | ||
| if (!bitmap->tryAllocPixels(image_info)) { | ||
| return nullptr; | ||
| } | ||
|
|
@@ -122,24 +125,21 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas, | |
|
|
||
| atlas.IterateGlyphs([canvas](const FontGlyphPair& font_glyph, | ||
| const Rect& location) -> bool { | ||
| const auto position = | ||
| SkPoint::Make(location.origin.x / font_glyph.font.GetMetrics().scale, | ||
| location.origin.y / font_glyph.font.GetMetrics().scale); | ||
| const auto& metrics = font_glyph.font.GetMetrics(); | ||
| const auto position = SkPoint::Make(location.origin.x / metrics.scale, | ||
| location.origin.y / metrics.scale); | ||
| SkGlyphID glyph_id = font_glyph.glyph.index; | ||
|
|
||
| SkFont sk_font( | ||
| TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(), | ||
| font_glyph.font.GetMetrics().point_size); | ||
|
|
||
| const auto& metrics = font_glyph.font.GetMetrics(); | ||
| metrics.point_size); | ||
|
|
||
| auto glyph_color = SK_ColorWHITE; | ||
|
|
||
| SkPaint glyph_paint; | ||
| glyph_paint.setColor(glyph_color); | ||
| canvas->resetMatrix(); | ||
| canvas->scale(font_glyph.font.GetMetrics().scale, | ||
| font_glyph.font.GetMetrics().scale); | ||
| canvas->scale(metrics.scale, metrics.scale); | ||
| canvas->drawGlyphs(1u, // count | ||
| &glyph_id, // glyphs | ||
| &position, // positions | ||
|
|
@@ -157,7 +157,8 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas, | |
| static std::shared_ptr<Texture> UploadGlyphTextureAtlas( | ||
| std::shared_ptr<Allocator> allocator, | ||
| std::shared_ptr<SkBitmap> bitmap, | ||
| size_t atlas_size) { | ||
| size_t atlas_size, | ||
| PixelFormat format) { | ||
| TRACE_EVENT0("impeller", __FUNCTION__); | ||
| if (!allocator) { | ||
| return nullptr; | ||
|
|
@@ -168,7 +169,7 @@ static std::shared_ptr<Texture> UploadGlyphTextureAtlas( | |
|
|
||
| TextureDescriptor texture_descriptor; | ||
| texture_descriptor.storage_mode = StorageMode::kHostVisible; | ||
| texture_descriptor.format = PixelFormat::kA8UNormInt; | ||
| texture_descriptor.format = format; | ||
| texture_descriptor.size = ISize::MakeWH(atlas_size, atlas_size); | ||
|
|
||
| if (pixmap.rowBytes() * pixmap.height() != | ||
|
|
@@ -202,6 +203,16 @@ std::shared_ptr<GlyphAtlas> TextRenderContextSkia::CreateGlyphAtlas( | |
| } | ||
|
|
||
| auto glyph_atlas = std::make_shared<GlyphAtlas>(); | ||
| glyph_atlas->SetFontColorCallback([](const FontGlyphPair& font_glyph) { | ||
| // TODO(jonahwilliams): ask Skia for a public API to look this up. | ||
| SkFont sk_font( | ||
| TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(), | ||
| font_glyph.font.GetMetrics().point_size); | ||
|
|
||
| SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(sk_font); | ||
| SkBulkGlyphMetricsAndPaths paths{strikeSpec}; | ||
| return paths.glyph(font_glyph.glyph.index)->isColor(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Step 1: Collect unique font-glyph pairs in the frame. | ||
|
|
@@ -251,8 +262,11 @@ std::shared_ptr<GlyphAtlas> TextRenderContextSkia::CreateGlyphAtlas( | |
| // --------------------------------------------------------------------------- | ||
| // Step 6: Upload the atlas as a texture. | ||
| // --------------------------------------------------------------------------- | ||
| auto format = glyph_atlas->ContainsColorGlyph() | ||
| ? PixelFormat::kR8G8B8A8UNormInt | ||
| : PixelFormat::kA8UNormInt; | ||
| auto texture = UploadGlyphTextureAtlas(GetContext()->GetResourceAllocator(), | ||
| bitmap, atlas_size); | ||
| bitmap, atlas_size, format); | ||
| if (!texture) { | ||
| return nullptr; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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