Try to use TextBlobs to paint ui::Style's text layers

This commit is contained in:
David Capello 2024-11-29 23:18:05 -03:00
parent 9e51e04606
commit 3f591aa5df
2 changed files with 25 additions and 4 deletions

View File

@ -103,6 +103,7 @@ PaintWidgetPartInfo::PaintWidgetPartInfo()
bgColor = gfx::ColorNone;
styleFlags = 0;
text = nullptr;
textBlob = nullptr;
mnemonic = 0;
icon = nullptr;
}
@ -114,6 +115,7 @@ PaintWidgetPartInfo::PaintWidgetPartInfo(const Widget* widget)
gfx::ColorNone);
styleFlags = PaintWidgetPartInfo::getStyleFlagsForWidget(widget);
text = &widget->text();
textBlob = widget->textBlob();
mnemonic = widget->mnemonic();
icon = nullptr;
if (const Style::Layer::IconSurfaceProvider* iconProvider = dynamic_cast<const Style::Layer::IconSurfaceProvider*>(widget)) {
@ -210,6 +212,7 @@ void Theme::paintWidgetPart(Graphics* g,
(const Style::Layer& layer) {
paintLayer(g, style, layer,
(info.text ? *info.text: std::string()),
info.textBlob,
info.mnemonic, info.icon, rc, outBgColor);
});
}
@ -326,6 +329,7 @@ void Theme::paintLayer(Graphics* g,
const Style* style,
const Style::Layer& layer,
const std::string& text,
const text::TextBlobRef& textBlob,
const int mnemonic,
os::Surface* providedIcon,
gfx::Rect& rc,
@ -481,10 +485,25 @@ void Theme::paintLayer(Graphics* g,
pt += layer.offset();
g->drawUIText(text,
layer.color(),
bgColor,
pt, style->mnemonics() ? mnemonic : 0);
// Fast path with TextBlobs
if ((textBlob) &&
(!style->mnemonics() || mnemonic == 0) &&
(style->font() == nullptr)) {
Paint paint;
if (gfx::geta(bgColor) > 0) { // Paint background
paint.color(bgColor);
paint.style(os::Paint::Fill);
g->drawRect(gfx::RectF(textBlob->bounds()).offset(pt), paint);
}
paint.color(layer.color());
g->drawTextBlob(textBlob, gfx::PointF(pt), paint);
}
else {
g->drawUIText(text,
layer.color(),
bgColor,
pt, style->mnemonics() ? mnemonic : 0);
}
}
if (style->font())

View File

@ -48,6 +48,7 @@ namespace ui {
gfx::Color bgColor;
int styleFlags; // ui::Style::Layer flags
const std::string* text;
text::TextBlobRef textBlob;
int mnemonic;
os::Surface* icon;
@ -154,6 +155,7 @@ namespace ui {
const Style* style,
const Style::Layer& layer,
const std::string& text,
const text::TextBlobRef& textBlob,
const int mnemonic,
os::Surface* icon,
gfx::Rect& rc,