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
wip texture format.
  • Loading branch information
jonahwilliams committed Feb 13, 2024
commit fdea14a46d292e726804d7dfd173f1d3e0d8bd5f
2 changes: 1 addition & 1 deletion impeller/entity/shaders/glyph_atlas.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ out f16vec4 frag_color;

void main() {
f16vec4 value = texture(glyph_atlas_sampler, v_uv);
frag_color = value.rrrr * v_text_color;
frag_color = max(value.rrrr, value.aaaa) * v_text_color;
}
20 changes: 18 additions & 2 deletions impeller/renderer/capabilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "impeller/renderer/capabilities.h"
#include "impeller/core/formats.h"

namespace impeller {

Expand Down Expand Up @@ -74,10 +75,16 @@ class StandardCapabilities final : public Capabilities {
return default_depth_stencil_format_;
}

// |Capabilities|
bool SupportsDeviceTransientTextures() const override {
return supports_device_transient_textures_;
}

// |Capabilities|
PixelFormat GetDefaultGlyphAtlasFormat() const override {
return default_glyph_atlas_format_;
}

private:
StandardCapabilities(bool supports_offscreen_msaa,
bool supports_ssbo,
Expand All @@ -91,7 +98,8 @@ class StandardCapabilities final : public Capabilities {
bool supports_device_transient_textures,
PixelFormat default_color_format,
PixelFormat default_stencil_format,
PixelFormat default_depth_stencil_format)
PixelFormat default_depth_stencil_format,
PixelFormat default_glyph_atlas_format)
: supports_offscreen_msaa_(supports_offscreen_msaa),
supports_ssbo_(supports_ssbo),
supports_buffer_to_texture_blits_(supports_buffer_to_texture_blits),
Expand Down Expand Up @@ -122,6 +130,7 @@ class StandardCapabilities final : public Capabilities {
PixelFormat default_color_format_ = PixelFormat::kUnknown;
PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
PixelFormat default_glyph_atlas_format_ = PixelFormat::kUnknown;

StandardCapabilities(const StandardCapabilities&) = delete;

Expand Down Expand Up @@ -207,6 +216,12 @@ CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsDeviceTransientTextures(
return *this;
}

CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultGlyphAtlasFormat(
PixelFormat value) {
default_glyph_atlas_format_ = value;
return *this;
}

std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
return std::unique_ptr<StandardCapabilities>(new StandardCapabilities( //
supports_offscreen_msaa_, //
Expand All @@ -221,7 +236,8 @@ std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
supports_device_transient_textures_, //
default_color_format_.value_or(PixelFormat::kUnknown), //
default_stencil_format_.value_or(PixelFormat::kUnknown), //
default_depth_stencil_format_.value_or(PixelFormat::kUnknown) //
default_depth_stencil_format_.value_or(PixelFormat::kUnknown), //
default_glyph_atlas_format_.value_or(PixelFormat::kUnknown) //
));
}

Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class Capabilities {
/// format was found.
virtual PixelFormat GetDefaultDepthStencilFormat() const = 0;

/// @brief Returns the default pixel format for the alpha bitmap glyph atlas.
///
/// Some backends may use Red channel while others use grey. This
/// should not have any impact
virtual PixelFormat GetDefaultGlyphAtlasFormat() const = 0;

protected:
Capabilities();

Expand Down Expand Up @@ -145,6 +151,8 @@ class CapabilitiesBuilder {

CapabilitiesBuilder& SetSupportsDeviceTransientTextures(bool value);

CapabilitiesBuilder& SetDefaultGlyphAtlasFormat(PixelFormat value);

std::unique_ptr<Capabilities> Build();

private:
Expand All @@ -161,6 +169,7 @@ class CapabilitiesBuilder {
std::optional<PixelFormat> default_color_format_ = std::nullopt;
std::optional<PixelFormat> default_stencil_format_ = std::nullopt;
std::optional<PixelFormat> default_depth_stencil_format_ = std::nullopt;
std::optional<PixelFormat> default_glyph_atlas_format_ = std::nullopt;

CapabilitiesBuilder(const CapabilitiesBuilder&) = delete;

Expand Down
17 changes: 8 additions & 9 deletions impeller/typographer/backends/skia/typographer_context_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ static ISize OptimumAtlasSizeForFontGlyphPairs(
GlyphAtlas::Type type,
const ISize& max_texture_size) {
static constexpr auto kMinAtlasSize = 8u;
static constexpr auto kMinRedBitmapSize = 1024u;
static constexpr auto kMinAlphaBitmapSize = 1024u;

TRACE_EVENT0("impeller", __FUNCTION__);

ISize current_size = type == GlyphAtlas::Type::kRedBitmap
? ISize(kMinRedBitmapSize, kMinRedBitmapSize)
ISize current_size = type == GlyphAtlas::Type::kAlphaBitmap
? ISize(kMinAlphaBitmapSize, kMinAlphaBitmapSize)
: ISize(kMinAtlasSize, kMinAtlasSize);
size_t total_pairs = pairs.size() + 1;
do {
Expand Down Expand Up @@ -171,7 +171,7 @@ static void DrawGlyph(SkCanvas* canvas,
sk_font.setHinting(SkFontHinting::kSlight);
sk_font.setEmbolden(metrics.embolden);

auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorRED;
auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorBLACK;

SkPaint glyph_paint;
glyph_paint.setColor(glyph_color);
Expand Down Expand Up @@ -221,11 +221,10 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
SkImageInfo image_info;

switch (atlas.GetType()) {
case GlyphAtlas::Type::kRedBitmap:
case GlyphAtlas::Type::kAlphaBitmap:
image_info =
SkImageInfo::Make(SkISize{static_cast<int32_t>(atlas_size.width),
static_cast<int32_t>(atlas_size.height)},
kR8_unorm_SkColorType, kPremul_SkAlphaType);
SkImageInfo::MakeA8(SkISize{static_cast<int32_t>(atlas_size.width),
static_cast<int32_t>(atlas_size.height)});
break;
case GlyphAtlas::Type::kColorBitmap:
image_info =
Expand Down Expand Up @@ -470,7 +469,7 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
// ---------------------------------------------------------------------------
PixelFormat format;
switch (type) {
case GlyphAtlas::Type::kRedBitmap:
case GlyphAtlas::Type::kAlphaBitmap:
format = PixelFormat::kR8UNormInt;
break;
case GlyphAtlas::Type::kColorBitmap:
Expand Down
8 changes: 4 additions & 4 deletions impeller/typographer/backends/stb/typographer_context_stb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ static ISize OptimumAtlasSizeForFontGlyphPairs(
GlyphAtlas::Type type,
const ISize& max_texture_size) {
static constexpr auto kMinAtlasSize = 8u;
static constexpr auto kMinRedBitmapSize = 1024u;
static constexpr auto kMinAlphaBitmapSize = 1024u;

TRACE_EVENT0("impeller", __FUNCTION__);

ISize current_size = type == GlyphAtlas::Type::kRedBitmap
? ISize(kMinRedBitmapSize, kMinRedBitmapSize)
ISize current_size = type == GlyphAtlas::Type::kAlphaBitmap
? ISize(kMinAlphaBitmapSize, kMinAlphaBitmapSize)
: ISize(kMinAtlasSize, kMinAtlasSize);
size_t total_pairs = pairs.size() + 1;
do {
Expand Down Expand Up @@ -515,7 +515,7 @@ std::shared_ptr<GlyphAtlas> TypographerContextSTB::CreateGlyphAtlas(
// ---------------------------------------------------------------------------
PixelFormat format;
switch (type) {
case GlyphAtlas::Type::kRedBitmap:
case GlyphAtlas::Type::kAlphaBitmap:
format = PixelFormat::kR8UNormInt;
break;
case GlyphAtlas::Type::kColorBitmap:
Expand Down
5 changes: 2 additions & 3 deletions impeller/typographer/glyph_atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <optional>
#include <unordered_map>

#include "flutter/fml/macros.h"
#include "impeller/core/texture.h"
#include "impeller/geometry/rect.h"
#include "impeller/renderer/pipeline.h"
Expand All @@ -33,9 +32,9 @@ class GlyphAtlas {
enum class Type {
//--------------------------------------------------------------------------
/// The glyphs are reprsented at their requested size using only an 8-bit
/// red channel.
/// alpha or red channel.
///
kRedBitmap,
kAlphaBitmap,

//--------------------------------------------------------------------------
/// The glyphs are reprsented at their requested size using N32 premul
Expand Down