Leverage QImage's CoW in Linux native notifications

This commit is contained in:
Ilya Fedin 2023-09-12 09:17:34 +04:00 committed by John Preston
parent e946bf5338
commit 0b4ef3214e

View file

@ -355,7 +355,7 @@ public:
void show(); void show();
void close(); void close();
void setImage(const QImage &image); void setImage(QImage image);
private: private:
const not_null<Manager*> _manager; const not_null<Manager*> _manager;
@ -695,7 +695,7 @@ void NotificationData::close() {
_manager->clearNotification(_id); _manager->clearNotification(_id);
} }
void NotificationData::setImage(const QImage &image) { void NotificationData::setImage(QImage image) {
if (_notification) { if (_notification) {
const auto imageData = [&] { const auto imageData = [&] {
QByteArray ba; QByteArray ba;
@ -718,20 +718,22 @@ void NotificationData::setImage(const QImage &image) {
return; return;
} }
const auto convertedImage = image.hasAlphaChannel() if (image.hasAlphaChannel()) {
? image.convertToFormat(QImage::Format_RGBA8888) image.convertTo(QImage::Format_RGBA8888);
: image.convertToFormat(QImage::Format_RGB888); } else {
image.convertTo(QImage::Format_RGB888);
}
_hints[_imageKey] = Glib::create_variant(std::tuple{ _hints[_imageKey] = Glib::create_variant(std::tuple{
convertedImage.width(), image.width(),
convertedImage.height(), image.height(),
int(convertedImage.bytesPerLine()), int(image.bytesPerLine()),
convertedImage.hasAlphaChannel(), image.hasAlphaChannel(),
8, 8,
convertedImage.hasAlphaChannel() ? 4 : 3, image.hasAlphaChannel() ? 4 : 3,
std::vector<uchar>( std::vector<uchar>(
convertedImage.constBits(), image.constBits(),
convertedImage.constBits() + convertedImage.sizeInBytes()), image.constBits() + image.sizeInBytes()),
}); });
} }