Skip to content

Commit

Permalink
Leverage QImage's CoW in Linux native notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Sep 12, 2023
1 parent e946bf5 commit 0b4ef32
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class NotificationData final : public base::has_weak_ptr {

void show();
void close();
void setImage(const QImage &image);
void setImage(QImage image);

private:
const not_null<Manager*> _manager;
Expand Down Expand Up @@ -695,7 +695,7 @@ void NotificationData::close() {
_manager->clearNotification(_id);
}

void NotificationData::setImage(const QImage &image) {
void NotificationData::setImage(QImage image) {
if (_notification) {
const auto imageData = [&] {
QByteArray ba;
Expand All @@ -718,20 +718,22 @@ void NotificationData::setImage(const QImage &image) {
return;
}

const auto convertedImage = image.hasAlphaChannel()
? image.convertToFormat(QImage::Format_RGBA8888)
: image.convertToFormat(QImage::Format_RGB888);
if (image.hasAlphaChannel()) {
image.convertTo(QImage::Format_RGBA8888);
} else {
image.convertTo(QImage::Format_RGB888);
}

_hints[_imageKey] = Glib::create_variant(std::tuple{
convertedImage.width(),
convertedImage.height(),
int(convertedImage.bytesPerLine()),
convertedImage.hasAlphaChannel(),
image.width(),
image.height(),
int(image.bytesPerLine()),
image.hasAlphaChannel(),
8,
convertedImage.hasAlphaChannel() ? 4 : 3,
image.hasAlphaChannel() ? 4 : 3,
std::vector<uchar>(
convertedImage.constBits(),
convertedImage.constBits() + convertedImage.sizeInBytes()),
image.constBits(),
image.constBits() + image.sizeInBytes()),
});
}

Expand Down

0 comments on commit 0b4ef32

Please sign in to comment.