Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
++
  • Loading branch information
jonahwilliams committed Nov 11, 2022
commit 06c73cb1dbe827ebf482b630cdf8286d98feaa36
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "impeller/typographer/backends/skia/text_render_context_skia.h"

#include <iostream>
#include <utility>

#include "flutter/fml/logging.h"
Expand Down Expand Up @@ -330,7 +329,6 @@ bool UploadGlyphTextureAtlas(const std::shared_ptr<Texture>& texture,
auto texture_descriptor = texture->GetTextureDescriptor();
if (pixmap.rowBytes() * pixmap.height() !=
texture_descriptor.GetByteSizeOfBaseMipLevel()) {
std::cerr << "descriptor mismatch" << std::endl;
return false;
}

Expand All @@ -341,7 +339,6 @@ bool UploadGlyphTextureAtlas(const std::shared_ptr<Texture>& texture,
);

if (!texture->SetContents(mapping)) {
std::cerr << "contents cant be set" << std::endl;
return false;
}
return true;
Expand Down Expand Up @@ -440,17 +437,11 @@ std::shared_ptr<GlyphAtlas> TextRenderContextSkia::CreateGlyphAtlas(
auto old_texture = last_atlas->GetTexture();
if (old_texture != nullptr &&
old_texture->GetTextureDescriptor().size == atlas_size) {
std::cerr << "reuse atlas" << std::endl;
if (!UploadGlyphTextureAtlas(old_texture, bitmap)) {
return nullptr;
}
glyph_atlas->SetTexture(std::move(old_texture));
} else {
std::cerr << "can't reuse "
<< (old_texture != nullptr
? old_texture->GetTextureDescriptor().size
: ISize(0, 0))
<< " : " << atlas_size << std::endl;
auto texture = CreateGlyphTextureAtlas(GetContext()->GetResourceAllocator(),
atlas_size, format);
if (!texture || !UploadGlyphTextureAtlas(texture, bitmap)) {
Expand Down
28 changes: 28 additions & 0 deletions impeller/typographer/typographer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ TEST_P(TypographerTest, GlyphAtlasIsRecycledIfUnchanged) {
ASSERT_EQ(atlas_context->GetGlyphAtlas(), atlas);
}

TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged) {
auto context = TextRenderContext::Create(GetContext());
auto atlas_context = std::make_shared<GlyphAtlasContext>();
ASSERT_TRUE(context && context->IsValid());
SkFont sk_font;
auto blob = SkTextBlob::MakeFromString("spooky skellingtons", sk_font);
ASSERT_TRUE(blob);
auto atlas =
context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, atlas_context,
TextFrameFromTextBlob(blob));
ASSERT_NE(atlas, nullptr);
ASSERT_NE(atlas->GetTexture(), nullptr);
ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());

auto* first_texture = atlas->GetTexture().get();

// now create a new glyph atlas with a nearly identical blob.

auto blob2 = SkTextBlob::MakeFromString("spooky skellington2", sk_font);
auto next_atlas =
context->CreateGlyphAtlas(GlyphAtlas::Type::kAlphaBitmap, atlas_context,
TextFrameFromTextBlob(blob2));
ASSERT_NE(atlas, next_atlas);
auto* second_texture = next_atlas->GetTexture().get();

ASSERT_EQ(second_texture, first_texture);
}

TEST_P(TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize) {
auto context = TextRenderContext::Create(GetContext());
auto atlas_context = std::make_shared<GlyphAtlasContext>();
Expand Down