5#include "flutter/display_list/testing/dl_test_snippets.h"
6#include "flutter/testing/testing.h"
7#include "gtest/gtest.h"
38 const std::shared_ptr<GlyphAtlasContext>& atlas_context,
41 frame.CollectUniqueFontGlyphPairs(font_glyph_map,
scale, {0, 0}, {});
43 atlas_context, font_glyph_map);
52 const std::shared_ptr<GlyphAtlasContext>& atlas_context,
53 const std::vector<std::shared_ptr<TextFrame>>& frames,
54 const std::vector<GlyphProperties>& properties) {
57 for (
auto&
frame : frames) {
58 frame->CollectUniqueFontGlyphPairs(font_glyph_map,
scale, {0, 0},
62 atlas_context, font_glyph_map);
68 "the quick brown fox jumped over the lazy dog.",
font);
71 ASSERT_EQ(
frame->GetRunCount(), 1u);
72 for (
const auto&
run :
frame->GetRuns()) {
73 ASSERT_TRUE(
run.IsValid());
74 ASSERT_EQ(
run.GetGlyphCount(), 45u);
80 ASSERT_TRUE(context && context->IsValid());
88 ASSERT_TRUE(context && context->IsValid());
96 ASSERT_NE(
atlas,
nullptr);
97 ASSERT_NE(
atlas->GetTexture(),
nullptr);
99 ASSERT_EQ(
atlas->GetGlyphCount(), 4llu);
101 std::optional<impeller::ScaledFont> first_scaled_font;
102 std::optional<impeller::SubpixelGlyph> first_glyph;
107 first_scaled_font = scaled_font;
113 ASSERT_TRUE(first_scaled_font.has_value());
115 ->FindFontGlyphBounds(
116 {first_scaled_font.value(), first_glyph.value()})
127 ASSERT_TRUE(mapping);
156 ASSERT_FALSE(color_atlas == bitmap_atlas);
164 ASSERT_TRUE(context && context->IsValid());
172 ASSERT_NE(
atlas,
nullptr);
173 ASSERT_NE(
atlas->GetTexture(),
nullptr);
175 EXPECT_EQ(
atlas->GetTexture()->GetSize().
width, 4096u);
176 EXPECT_EQ(
atlas->GetTexture()->GetSize().
height, 1024u);
184 ASSERT_TRUE(context && context->IsValid());
192 ASSERT_NE(
atlas,
nullptr);
193 ASSERT_NE(
atlas->GetTexture(),
nullptr);
194 ASSERT_EQ(
atlas, atlas_context->GetGlyphAtlas());
202 ASSERT_EQ(
atlas, next_atlas);
203 ASSERT_EQ(atlas_context->GetGlyphAtlas(),
atlas);
211 ASSERT_TRUE(context && context->IsValid());
213 const char* test_string =
214 "QWERTYUIOPASDFGHJKLZXCVBNMqewrtyuiopasdfghjklzxcvbnm,.<>[]{};':"
215 "2134567890-=!@#$%^&*()_+"
216 "œ∑´®†¥¨ˆøπ““‘‘åß∂ƒ©˙∆˚¬…æ≈ç√∫˜µ≤≥≥≥≥÷¡™£¢∞§¶•ªº–≠⁄€‹›fifl‡°·‚—±Œ„´‰Á¨Ø∏”’/"
224 size_t size_count = 8;
225 for (
size_t index = 0; index < size_count; index += 1) {
227 font_glyph_map, 0.6 * index, {0, 0}, {});
231 *host_buffer, atlas_context, font_glyph_map);
232 ASSERT_NE(
atlas,
nullptr);
233 ASSERT_NE(
atlas->GetTexture(),
nullptr);
235 std::set<uint16_t> unique_glyphs;
236 std::vector<uint16_t> total_glyphs;
245 EXPECT_LE(unique_glyphs.size() * size_count,
atlas->GetGlyphCount());
246 EXPECT_EQ(total_glyphs.size(),
atlas->GetGlyphCount());
258 ASSERT_TRUE(context && context->IsValid());
266 auto old_packer = atlas_context->GetRectPacker();
268 ASSERT_NE(
atlas,
nullptr);
269 ASSERT_NE(
atlas->GetTexture(),
nullptr);
270 ASSERT_EQ(
atlas, atlas_context->GetGlyphAtlas());
272 auto* first_texture =
atlas->GetTexture().get();
281 ASSERT_EQ(
atlas, next_atlas);
282 auto* second_texture = next_atlas->GetTexture().get();
284 auto new_packer = atlas_context->GetRectPacker();
286 ASSERT_EQ(second_texture, first_texture);
287 ASSERT_EQ(old_packer, new_packer);
297 ASSERT_TRUE(mapping);
319 {frame, frame_2}, properties);
321 EXPECT_EQ(next_atlas->GetGlyphCount(), 2u);
329 SkFont sk_font(typeface, 0.5f);
349 {frame, frame_2}, properties);
351 EXPECT_EQ(next_atlas->GetGlyphCount(), 1u);
356 ASSERT_NE(packer,
nullptr);
357 ASSERT_EQ(packer->PercentFull(), 0);
362 ASSERT_TRUE(packer->AddRect(20, 20, &first_output));
374 ASSERT_TRUE(packer->AddRect(140, 90, &second_output));
389 ASSERT_FALSE(packer->AddRect(50, 50, &
output));
395 ASSERT_EQ(packer->PercentFull(), 0);
403 for (
auto i = 0u;
i < 16;
i++) {
404 skyline->AddRect(16, 16, &loc);
407 EXPECT_EQ(loc.
x(), 256 - 16);
408 EXPECT_EQ(loc.
y(), 0);
411 for (
auto i = 0u;
i < 16;
i++) {
412 skyline->AddRect(16, 16, &loc);
415 EXPECT_EQ(loc.
x(), 256 - 16);
416 EXPECT_EQ(loc.
y(), 16);
421 GTEST_SKIP() <<
"Atlas growth isn't supported for OpenGLES currently.";
428 ASSERT_TRUE(context && context->IsValid());
440 constexpr ISize expected_sizes[13] = {
456 for (
int i = 0;
i < 13;
i++) {
464 ASSERT_TRUE(!!
atlas);
465 EXPECT_EQ(
atlas->GetTexture()->GetTextureDescriptor().size,
sk_sp< SkTypeface > makeFromData(sk_sp< SkData >, int ttcIndex=0) const
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
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.
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator)
const std::shared_ptr< GlyphAtlas > & CreateOrGetGlyphAtlas(Context &context, HostBuffer &host_buffer, GlyphAtlas::Type type) const
void AddTextFrame(const TextFrame &frame, Scalar scale, Point offset, const GlyphProperties &properties)
static std::shared_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, HostBuffer &host_buffer, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const FontGlyphMap &font_glyph_map) const =0
SK_API GrDirectContext * GetContext(const SkImage *src)
sk_sp< const SkImage > atlas
sk_sp< SkBlender > blender SkRect rect
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)
font
Font Metadata and Metrics.
TEST(AiksCanvasTest, EmptyCullRect)
static std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, const TypographerContext *typographer_context, HostBuffer &host_buffer, GlyphAtlas::Type type, Scalar scale, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const TextFrame &frame)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
std::unordered_map< ScaledFont, std::unordered_set< SubpixelGlyph > > FontGlyphMap
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
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)
static constexpr Color Red()
static constexpr Color Blue()
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.
#define EXPECT_TRUE(handle)