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

Commit a6735d6

Browse files
committed
Address comments
1 parent c0928a0 commit a6735d6

16 files changed

+248
-135
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,12 +1705,16 @@ ORIGIN: ../../../flutter/impeller/toolkit/egl/surface.cc + ../../../flutter/LICE
17051705
ORIGIN: ../../../flutter/impeller/toolkit/egl/surface.h + ../../../flutter/LICENSE
17061706
ORIGIN: ../../../flutter/impeller/toolkit/gles/gles.h + ../../../flutter/LICENSE
17071707
ORIGIN: ../../../flutter/impeller/toolkit/gles/texture.h + ../../../flutter/LICENSE
1708+
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/glyph_atlas_context_skia.cc + ../../../flutter/LICENSE
1709+
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/glyph_atlas_context_skia.h + ../../../flutter/LICENSE
17081710
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/text_frame_skia.cc + ../../../flutter/LICENSE
17091711
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/text_frame_skia.h + ../../../flutter/LICENSE
17101712
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/typeface_skia.cc + ../../../flutter/LICENSE
17111713
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/typeface_skia.h + ../../../flutter/LICENSE
17121714
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/typographer_context_skia.cc + ../../../flutter/LICENSE
17131715
ORIGIN: ../../../flutter/impeller/typographer/backends/skia/typographer_context_skia.h + ../../../flutter/LICENSE
1716+
ORIGIN: ../../../flutter/impeller/typographer/backends/stb/glyph_atlas_context_stb.cc + ../../../flutter/LICENSE
1717+
ORIGIN: ../../../flutter/impeller/typographer/backends/stb/glyph_atlas_context_stb.h + ../../../flutter/LICENSE
17141718
ORIGIN: ../../../flutter/impeller/typographer/backends/stb/text_frame_stb.cc + ../../../flutter/LICENSE
17151719
ORIGIN: ../../../flutter/impeller/typographer/backends/stb/text_frame_stb.h + ../../../flutter/LICENSE
17161720
ORIGIN: ../../../flutter/impeller/typographer/backends/stb/typeface_stb.cc + ../../../flutter/LICENSE
@@ -4442,12 +4446,16 @@ FILE: ../../../flutter/impeller/toolkit/gles/gles.h
44424446
FILE: ../../../flutter/impeller/toolkit/gles/texture.cc
44434447
FILE: ../../../flutter/impeller/toolkit/gles/texture.h
44444448
FILE: ../../../flutter/impeller/tools/malioc.json
4449+
FILE: ../../../flutter/impeller/typographer/backends/skia/glyph_atlas_context_skia.cc
4450+
FILE: ../../../flutter/impeller/typographer/backends/skia/glyph_atlas_context_skia.h
44454451
FILE: ../../../flutter/impeller/typographer/backends/skia/text_frame_skia.cc
44464452
FILE: ../../../flutter/impeller/typographer/backends/skia/text_frame_skia.h
44474453
FILE: ../../../flutter/impeller/typographer/backends/skia/typeface_skia.cc
44484454
FILE: ../../../flutter/impeller/typographer/backends/skia/typeface_skia.h
44494455
FILE: ../../../flutter/impeller/typographer/backends/skia/typographer_context_skia.cc
44504456
FILE: ../../../flutter/impeller/typographer/backends/skia/typographer_context_skia.h
4457+
FILE: ../../../flutter/impeller/typographer/backends/stb/glyph_atlas_context_stb.cc
4458+
FILE: ../../../flutter/impeller/typographer/backends/stb/glyph_atlas_context_stb.h
44514459
FILE: ../../../flutter/impeller/typographer/backends/stb/text_frame_stb.cc
44524460
FILE: ../../../flutter/impeller/typographer/backends/stb/text_frame_stb.h
44534461
FILE: ../../../flutter/impeller/typographer/backends/stb/typeface_stb.cc

impeller/typographer/backends/skia/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import("//flutter/impeller/tools/impeller.gni")
66

77
impeller_component("typographer_skia_backend") {
88
sources = [
9+
"glyph_atlas_context_skia.cc",
10+
"glyph_atlas_context_skia.h",
911
"text_frame_skia.cc",
1012
"text_frame_skia.h",
1113
"typeface_skia.cc",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/typographer/backends/skia/glyph_atlas_context_skia.h"
6+
7+
#include "third_party/skia/include/core/SkBitmap.h"
8+
9+
namespace impeller {
10+
11+
GlyphAtlasContextSkia::GlyphAtlasContextSkia() = default;
12+
13+
GlyphAtlasContextSkia::~GlyphAtlasContextSkia() = default;
14+
15+
std::shared_ptr<SkBitmap> GlyphAtlasContextSkia::GetBitmap() const {
16+
return bitmap_;
17+
}
18+
19+
void GlyphAtlasContextSkia::UpdateBitmap(std::shared_ptr<SkBitmap> bitmap) {
20+
bitmap_ = std::move(bitmap);
21+
}
22+
23+
} // namespace impeller
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include "impeller/base/backend_cast.h"
8+
#include "impeller/typographer/glyph_atlas.h"
9+
10+
class SkBitmap;
11+
12+
namespace impeller {
13+
14+
//------------------------------------------------------------------------------
15+
/// @brief A container for caching a glyph atlas across frames.
16+
///
17+
class GlyphAtlasContextSkia
18+
: public GlyphAtlasContext,
19+
public BackendCast<GlyphAtlasContextSkia, GlyphAtlasContext> {
20+
public:
21+
GlyphAtlasContextSkia();
22+
23+
~GlyphAtlasContextSkia() override;
24+
25+
//----------------------------------------------------------------------------
26+
/// @brief Retrieve the previous (if any) SkBitmap instance.
27+
std::shared_ptr<SkBitmap> GetBitmap() const;
28+
29+
void UpdateBitmap(std::shared_ptr<SkBitmap> bitmap);
30+
31+
private:
32+
std::shared_ptr<SkBitmap> bitmap_;
33+
34+
FML_DISALLOW_COPY_AND_ASSIGN(GlyphAtlasContextSkia);
35+
};
36+
37+
} // namespace impeller

impeller/typographer/backends/skia/typographer_context_skia.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "flutter/fml/trace_event.h"
1111
#include "impeller/base/allocation.h"
1212
#include "impeller/core/allocator.h"
13+
#include "impeller/typographer/backends/skia/glyph_atlas_context_skia.h"
1314
#include "impeller/typographer/backends/skia/typeface_skia.h"
1415
#include "impeller/typographer/rectangle_packer.h"
1516
#include "impeller/typographer/typographer_context.h"
@@ -36,6 +37,11 @@ TypographerContextSkia::TypographerContextSkia() = default;
3637

3738
TypographerContextSkia::~TypographerContextSkia() = default;
3839

40+
std::shared_ptr<GlyphAtlasContext>
41+
TypographerContextSkia::CreateGlyphAtlasContext() const {
42+
return std::make_shared<GlyphAtlasContextSkia>();
43+
}
44+
3945
static size_t PairsFitInAtlasOfSize(
4046
const FontGlyphPair::Set& pairs,
4147
const ISize& atlas_size,
@@ -107,8 +113,7 @@ static bool CanAppendToExistingAtlas(
107113
return true;
108114
}
109115

110-
namespace {
111-
ISize OptimumAtlasSizeForFontGlyphPairs(
116+
static ISize OptimumAtlasSizeForFontGlyphPairs(
112117
const FontGlyphPair::Set& pairs,
113118
std::vector<Rect>& glyph_positions,
114119
const std::shared_ptr<GlyphAtlasContext>& atlas_context,
@@ -146,7 +151,6 @@ ISize OptimumAtlasSizeForFontGlyphPairs(
146151
current_size.height <= kMaxAtlasSize);
147152
return ISize{0, 0};
148153
}
149-
} // namespace
150154

151155
static void DrawGlyph(SkCanvas* canvas,
152156
const FontGlyphPair& font_glyph,
@@ -314,6 +318,7 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
314318
if (!IsValid()) {
315319
return nullptr;
316320
}
321+
auto& atlas_context_skia = GlyphAtlasContextSkia::Cast(*atlas_context);
317322
std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
318323

319324
if (font_glyph_pairs.empty()) {
@@ -358,7 +363,7 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
358363
// ---------------------------------------------------------------------------
359364
// Step 4a: Draw new font-glyph pairs into the existing bitmap.
360365
// ---------------------------------------------------------------------------
361-
auto bitmap = atlas_context->GetBitmap();
366+
auto bitmap = atlas_context_skia.GetBitmap();
362367
if (!UpdateAtlasBitmap(*last_atlas, bitmap, new_glyphs)) {
363368
return nullptr;
364369
}
@@ -412,7 +417,7 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
412417
if (!bitmap) {
413418
return nullptr;
414419
}
415-
atlas_context->UpdateBitmap(bitmap);
420+
atlas_context_skia.UpdateBitmap(bitmap);
416421

417422
// ---------------------------------------------------------------------------
418423
// Step 7b: Upload the atlas as a texture.

impeller/typographer/backends/skia/typographer_context_skia.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class TypographerContextSkia : public TypographerContext {
1717

1818
~TypographerContextSkia() override;
1919

20+
// |TypographerContext|
21+
std::shared_ptr<GlyphAtlasContext> CreateGlyphAtlasContext() const override;
22+
2023
// |TypographerContext|
2124
std::shared_ptr<GlyphAtlas> CreateGlyphAtlas(
2225
Context& context,

impeller/typographer/backends/stb/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ impeller_component("typographer_stb_backend") {
88
testonly = true
99

1010
sources = [
11+
"glyph_atlas_context_stb.cc",
12+
"glyph_atlas_context_stb.h",
1113
"text_frame_stb.cc",
1214
"text_frame_stb.h",
1315
"typeface_stb.cc",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/typographer/backends/stb/glyph_atlas_context_stb.h"
6+
7+
namespace impeller {
8+
9+
BitmapSTB::BitmapSTB() = default;
10+
11+
BitmapSTB::~BitmapSTB() = default;
12+
13+
BitmapSTB::BitmapSTB(size_t width, size_t height, size_t bytes_per_pixel)
14+
: width_(width),
15+
height_(height),
16+
bytes_per_pixel_(bytes_per_pixel),
17+
pixels_(std::vector<uint8_t>(width * height * bytes_per_pixel, 0)) {}
18+
19+
uint8_t* BitmapSTB::GetPixels() {
20+
return pixels_.data();
21+
}
22+
23+
uint8_t* BitmapSTB::GetPixelAddress(TPoint<size_t> coords) {
24+
FML_DCHECK(coords.x < width_);
25+
FML_DCHECK(coords.x < height_);
26+
27+
return &pixels_.data()[(coords.x + width_ * coords.y) * bytes_per_pixel_];
28+
}
29+
30+
size_t BitmapSTB::GetRowBytes() const {
31+
return width_ * bytes_per_pixel_;
32+
}
33+
34+
size_t BitmapSTB::GetWidth() const {
35+
return width_;
36+
}
37+
38+
size_t BitmapSTB::GetHeight() const {
39+
return height_;
40+
}
41+
42+
size_t BitmapSTB::GetSize() const {
43+
return width_ * height_ * bytes_per_pixel_;
44+
}
45+
46+
GlyphAtlasContextSTB::GlyphAtlasContextSTB() = default;
47+
48+
GlyphAtlasContextSTB::~GlyphAtlasContextSTB() = default;
49+
50+
std::shared_ptr<BitmapSTB> GlyphAtlasContextSTB::GetBitmap() const {
51+
return bitmap_;
52+
}
53+
54+
void GlyphAtlasContextSTB::UpdateBitmap(std::shared_ptr<BitmapSTB> bitmap) {
55+
bitmap_ = std::move(bitmap);
56+
}
57+
58+
} // namespace impeller
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include "impeller/base/backend_cast.h"
8+
#include "impeller/typographer/glyph_atlas.h"
9+
10+
namespace impeller {
11+
12+
class BitmapSTB {
13+
public:
14+
BitmapSTB();
15+
16+
~BitmapSTB();
17+
18+
BitmapSTB(size_t width, size_t height, size_t bytes_per_pixel);
19+
20+
uint8_t* GetPixels();
21+
22+
uint8_t* GetPixelAddress(TPoint<size_t> coords);
23+
24+
size_t GetRowBytes() const;
25+
26+
size_t GetWidth() const;
27+
28+
size_t GetHeight() const;
29+
30+
size_t GetSize() const;
31+
32+
private:
33+
size_t width_ = 0;
34+
size_t height_ = 0;
35+
size_t bytes_per_pixel_ = 0;
36+
std::vector<uint8_t> pixels_;
37+
};
38+
39+
class GlyphAtlasContextSTB
40+
: public GlyphAtlasContext,
41+
public BackendCast<GlyphAtlasContextSTB, GlyphAtlasContext> {
42+
public:
43+
GlyphAtlasContextSTB();
44+
45+
~GlyphAtlasContextSTB() override;
46+
47+
//----------------------------------------------------------------------------
48+
/// @brief Retrieve the previous (if any) BitmapSTB instance.
49+
std::shared_ptr<BitmapSTB> GetBitmap() const;
50+
51+
void UpdateBitmap(std::shared_ptr<BitmapSTB> bitmap);
52+
53+
private:
54+
std::shared_ptr<BitmapSTB> bitmap_;
55+
56+
FML_DISALLOW_COPY_AND_ASSIGN(GlyphAtlasContextSTB);
57+
};
58+
59+
} // namespace impeller

0 commit comments

Comments
 (0)