5#include "flutter/display_list/testing/dl_test_snippets.h"
6#include "flutter/testing/testing.h"
33 const std::shared_ptr<GlyphAtlasContext>& atlas_context,
36 frame.CollectUniqueFontGlyphPairs(font_glyph_map,
scale);
44 "the quick brown fox jumped over the lazy dog.", font);
47 ASSERT_EQ(
frame->GetRunCount(), 1u);
48 for (
const auto&
run :
frame->GetRuns()) {
49 ASSERT_TRUE(
run.IsValid());
50 ASSERT_EQ(
run.GetGlyphCount(), 45u);
56 ASSERT_TRUE(context && context->IsValid());
61 auto atlas_context = context->CreateGlyphAtlasContext();
62 ASSERT_TRUE(context && context->IsValid());
69 ASSERT_NE(atlas,
nullptr);
70 ASSERT_NE(atlas->GetTexture(),
nullptr);
72 ASSERT_EQ(atlas->GetGlyphCount(), 4llu);
74 std::optional<impeller::ScaledFont> first_scaled_font;
75 std::optional<impeller::Glyph> first_glyph;
77 atlas->IterateGlyphs([&](
const ScaledFont& scaled_font,
const Glyph& glyph,
78 const Rect& rect) ->
bool {
79 first_scaled_font = scaled_font;
85 ASSERT_TRUE(first_scaled_font.has_value());
87 ->FindFontGlyphBounds(
88 {first_scaled_font.value(), first_glyph.value()})
100 SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0);
127 ASSERT_FALSE(color_atlas == bitmap_atlas);
132 auto atlas_context = context->CreateGlyphAtlasContext();
133 ASSERT_TRUE(context && context->IsValid());
140 ASSERT_NE(atlas,
nullptr);
141 ASSERT_NE(atlas->GetTexture(),
nullptr);
143 ASSERT_EQ(atlas->GetTexture()->GetSize().
width,
144 atlas->GetTexture()->GetSize().
height);
149 auto atlas_context = context->CreateGlyphAtlasContext();
150 ASSERT_TRUE(context && context->IsValid());
157 ASSERT_NE(atlas,
nullptr);
158 ASSERT_NE(atlas->GetTexture(),
nullptr);
159 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
166 ASSERT_EQ(atlas, next_atlas);
167 ASSERT_EQ(atlas_context->GetGlyphAtlas(), atlas);
172 auto atlas_context = context->CreateGlyphAtlasContext();
173 ASSERT_TRUE(context && context->IsValid());
175 const char* test_string =
176 "QWERTYUIOPASDFGHJKLZXCVBNMqewrtyuiopasdfghjklzxcvbnm,.<>[]{};':"
177 "2134567890-=!@#$%^&*()_+"
178 "œ∑´®†¥¨ˆøπ““‘‘åß∂ƒ©˙∆˚¬…æ≈ç√∫˜µ≤≥≥≥≥÷¡™£¢∞§¶•ªº–≠⁄€‹›fifl‡°·‚—±Œ„´‰Á¨Ø∏”’/"
186 size_t size_count = 8;
187 for (
size_t index = 0; index < size_count; index += 1) {
189 font_glyph_map, 0.6 * index);
193 atlas_context, font_glyph_map);
194 ASSERT_NE(atlas,
nullptr);
195 ASSERT_NE(atlas->GetTexture(),
nullptr);
197 std::set<uint16_t> unique_glyphs;
198 std::vector<uint16_t> total_glyphs;
199 atlas->IterateGlyphs(
201 unique_glyphs.insert(glyph.
index);
202 total_glyphs.push_back(glyph.
index);
206 EXPECT_EQ(unique_glyphs.size() * size_count, atlas->GetGlyphCount());
207 EXPECT_EQ(total_glyphs.size(), atlas->GetGlyphCount());
216 auto atlas_context = context->CreateGlyphAtlasContext();
217 ASSERT_TRUE(context && context->IsValid());
224 auto old_packer = atlas_context->GetRectPacker();
226 ASSERT_NE(atlas,
nullptr);
227 ASSERT_NE(atlas->GetTexture(),
nullptr);
228 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
230 auto* first_texture = atlas->GetTexture().get();
238 ASSERT_EQ(atlas, next_atlas);
239 auto* second_texture = next_atlas->GetTexture().get();
241 auto new_packer = atlas_context->GetRectPacker();
243 ASSERT_EQ(second_texture, first_texture);
244 ASSERT_EQ(old_packer, new_packer);
249 auto atlas_context = context->CreateGlyphAtlasContext();
250 ASSERT_TRUE(context && context->IsValid());
257 auto old_packer = atlas_context->GetRectPacker();
259 ASSERT_NE(atlas,
nullptr);
260 ASSERT_NE(atlas->GetTexture(),
nullptr);
261 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
263 auto* first_texture = atlas->GetTexture().get();
272 ASSERT_NE(atlas, next_atlas);
273 auto* second_texture = next_atlas->GetTexture().get();
275 auto new_packer = atlas_context->GetRectPacker();
277 ASSERT_NE(second_texture, first_texture);
278 ASSERT_NE(old_packer, new_packer);
285 SkFont sk_font(typeface, 0.5f);
290 ASSERT_FALSE(
frame->MaybeHasOverlapping());
294 ASSERT_FALSE(frame_2->MaybeHasOverlapping());
299 ASSERT_NE(packer,
nullptr);
300 ASSERT_EQ(packer->percentFull(), 0);
305 ASSERT_TRUE(packer->addRect(20, 20, &first_output));
317 ASSERT_TRUE(packer->addRect(140, 90, &second_output));
332 ASSERT_FALSE(packer->addRect(50, 50, &output));
338 ASSERT_EQ(packer->percentFull(), 0);
342 GlyphAtlasTextureIsRecycledWhenContentsAreNotRecreated) {
344 auto atlas_context = context->CreateGlyphAtlasContext();
345 ASSERT_TRUE(context && context->IsValid());
353 auto old_packer = atlas_context->GetRectPacker();
355 ASSERT_NE(atlas,
nullptr);
356 ASSERT_NE(atlas->GetTexture(),
nullptr);
357 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
359 auto* first_texture = atlas->GetTexture().get();
369 ASSERT_NE(atlas, next_atlas);
370 auto* second_texture = next_atlas->GetTexture().get();
372 auto new_packer = atlas_context->GetRectPacker();
374 ASSERT_NE(second_texture, first_texture);
375 ASSERT_NE(old_packer, new_packer);
static constexpr SkFontStyle Normal()
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
To do anything rendering related with Impeller, you need a context.
Type
Describes how the glyphs are represented in the texture.
void AddTextFrame(const TextFrame &frame, Scalar scale)
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas(Context &context, GlyphAtlas::Type type) const
static std::unique_ptr< RectanglePacker > Factory(int width, int height)
Return an empty packer with area specified by width and height.
Represents a collection of shaped text runs.
static std::shared_ptr< TypographerContext > Make()
The graphics context necessary to render text.
virtual std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, GlyphAtlas::Type type, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const FontGlyphMap &font_glyph_map) const =0
SkFont CreateTestFontOfSize(SkScalar scalar)
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
bool NumberNear(double a, double b)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
static std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, const TypographerContext *typographer_context, GlyphAtlas::Type type, Scalar scale, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const TextFrame &frame)
std::unordered_map< ScaledFont, std::unordered_set< Glyph > > FontGlyphMap
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
static bool Intersects(const SkIRect &a, const SkIRect &b)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
The glyph index in the typeface.
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
#define EXPECT_TRUE(handle)