mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-22 01:25:10 -07:00
[VDS] Cache mana symbol renders and skip redundant resizes (#7167)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
* [VDS] Cache mana symbol renders and skip redundant resizes - Render each mana symbol once at a bounded master size and derive every requested size from the cached master, avoiding repeated full-size SVG rasterization on the GUI thread - Share scaled results through a process-wide cache keyed by symbol and size, so repeated widget creation and rescales don't redo the work - Skip redundant resize work in ColorIdentityWidget and ManaSymbolWidget when sizes did not change Took 8 minutes Took 50 seconds * Move to pixmap generator Took 8 minutes Took 4 seconds --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
b13c682a7a
commit
24d8d8be3b
9 changed files with 127 additions and 56 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "card_completer_delegate.h"
|
||||
|
||||
#include "../../pixel_map_generator.h"
|
||||
#include "../cards/additional_info/mana_cost_widget.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
|
@ -84,7 +85,6 @@ QColor CardCompleterDelegate::accentForColors(const QString &colors)
|
|||
|
||||
CardCompleterDelegate::CardCompleterDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
symbolCache.setMaxCost(64);
|
||||
setCodeCache.setMaxCost(64);
|
||||
}
|
||||
|
||||
|
|
@ -108,36 +108,16 @@ QSize CardCompleterDelegate::sizeHint(const QStyleOptionViewItem &option, const
|
|||
// Mana symbol painting
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const QPixmap *CardCompleterDelegate::cachedSymbolPixmap(const QString &symbol, int size) const
|
||||
{
|
||||
const QString key = symbol + QString::number(size);
|
||||
|
||||
if (symbolCache.contains(key)) {
|
||||
return symbolCache[key];
|
||||
}
|
||||
|
||||
QPixmap src(QString("theme:icons/mana/%1").arg(symbol));
|
||||
|
||||
if (!src.isNull()) {
|
||||
auto *pm = new QPixmap(src.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
|
||||
symbolCache.insert(key, pm);
|
||||
return pm;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void CardCompleterDelegate::drawManaSymbol(QPainter *p, QPoint centre, const QString &symbol, int radius) const
|
||||
{
|
||||
const QRect pip(centre.x() - radius, centre.y() - radius, radius * 2, radius * 2);
|
||||
|
||||
const QPixmap *px = cachedSymbolPixmap(symbol, radius * 2);
|
||||
const QPixmap px = ManaSymbolPixmapGenerator::generatePixmap(symbol, QSize(radius * 2, radius * 2));
|
||||
|
||||
if (px && !px->isNull()) {
|
||||
p->drawPixmap(pip, *px);
|
||||
if (!px.isNull()) {
|
||||
p->drawPixmap(pip, px);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ public:
|
|||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
// Mana symbol pixmaps, loaded once and cached
|
||||
mutable QCache<QString, QPixmap> symbolCache;
|
||||
|
||||
// Set short codes, resolved once per card name and cached
|
||||
mutable QCache<QString, QString> setCodeCache;
|
||||
|
||||
|
|
@ -47,9 +44,6 @@ private:
|
|||
// adventure costs ("1W // W") are drawn as separate groups. Returns the left-most x used
|
||||
int drawManaCost(QPainter *p, const QRect &row, const QString &manaCost, int radius) const;
|
||||
|
||||
// Load (or return cached) a mana icon pixmap; falls back to painted circle
|
||||
const QPixmap *cachedSymbolPixmap(const QString &symbol, int size) const;
|
||||
|
||||
// Resolve the preferred printing's set short code for a card
|
||||
QString setCodeForCard(const QSharedPointer<CardInfo> &card) const;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue