2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Reuse global emoji large images.

This commit is contained in:
John Preston
2019-08-05 15:08:20 +01:00
parent e479daca03
commit 1b1b1780db
7 changed files with 98 additions and 24 deletions

View File

@@ -68,6 +68,7 @@ auto SpritesCount = -1;
auto InstanceNormal = std::unique_ptr<Instance>();
auto InstanceLarge = std::unique_ptr<Instance>();
auto Universal = std::shared_ptr<UniversalImages>();
auto CanClearUniversal = false;
auto Updates = rpl::event_stream<>();
auto UpdatesRecent = rpl::event_stream<>();
@@ -148,6 +149,7 @@ void SwitchToSetPrepared(int id, std::shared_ptr<UniversalImages> images) {
stream << qint32(id);
}
Universal = std::move(images);
CanClearUniversal = false;
MainEmojiMap.clear();
OtherEmojiMap.clear();
Updates.fire({});
@@ -383,7 +385,10 @@ EmojiPtr FindReplacement(const QChar *start, const QChar *end, int *outLength) {
void ClearUniversalChecked() {
Expects(InstanceNormal != nullptr && InstanceLarge != nullptr);
if (InstanceNormal->cached() && InstanceLarge->cached() && Universal) {
if (CanClearUniversal
&& Universal
&& InstanceNormal->cached()
&& InstanceLarge->cached()) {
Universal->clear();
}
}
@@ -507,6 +512,7 @@ void Init() {
SizeNormal = ConvertScale(18, cScale() * cIntRetinaFactor());
SizeLarge = int(ConvertScale(18 * 4 / 3., cScale() * cIntRetinaFactor()));
Universal = std::make_shared<UniversalImages>(ReadCurrentSetId());
CanClearUniversal = false;
InstanceNormal = std::make_unique<Instance>(SizeNormal);
InstanceLarge = std::make_unique<Instance>(SizeLarge);
@@ -1007,5 +1013,24 @@ void Instance::pushSprite(QImage &&data) {
_sprites.back().setDevicePixelRatio(cRetinaFactor());
}
const std::shared_ptr<UniversalImages> &SourceImages() {
return Universal;
}
void ClearSourceImages(const std::shared_ptr<UniversalImages> &images) {
if (images == Universal) {
CanClearUniversal = true;
ClearUniversalChecked();
}
}
void ReplaceSourceImages(std::shared_ptr<UniversalImages> images) {
Expects(images != nullptr);
if (Universal->id() == images->id()) {
Universal = std::move(images);
}
}
} // namespace Emoji
} // namespace Ui

View File

@@ -182,10 +182,13 @@ public:
QImage generate(int size, int index) const;
private:
int _id = 0;
const int _id = 0;
std::vector<QImage> _sprites;
};
const std::shared_ptr<UniversalImages> &SourceImages();
void ClearSourceImages(const std::shared_ptr<UniversalImages> &images);
} // namespace Emoji
} // namespace Ui