Fix video messages playback on Retina.

This commit is contained in:
John Preston 2019-03-28 12:51:08 +04:00
parent d3bf489bea
commit 3cd9d4b5ec
3 changed files with 23 additions and 29 deletions

View File

@ -419,8 +419,6 @@ struct Data {
crl::time LastFeaturedStickersUpdate = 0; crl::time LastFeaturedStickersUpdate = 0;
Stickers::Order ArchivedStickerSetsOrder; Stickers::Order ArchivedStickerSetsOrder;
CircleMasksMap CircleMasks;
bool AskDownloadPath = false; bool AskDownloadPath = false;
QString DownloadPath; QString DownloadPath;
QByteArray DownloadPathBookmark; QByteArray DownloadPathBookmark;
@ -553,8 +551,6 @@ DefineRefVar(Global, base::Observable<void>, FeaturedStickerSetsUnreadCountChang
DefineVar(Global, crl::time, LastFeaturedStickersUpdate); DefineVar(Global, crl::time, LastFeaturedStickersUpdate);
DefineVar(Global, Stickers::Order, ArchivedStickerSetsOrder); DefineVar(Global, Stickers::Order, ArchivedStickerSetsOrder);
DefineRefVar(Global, CircleMasksMap, CircleMasks);
DefineVar(Global, bool, AskDownloadPath); DefineVar(Global, bool, AskDownloadPath);
DefineVar(Global, QString, DownloadPath); DefineVar(Global, QString, DownloadPath);
DefineVar(Global, QByteArray, DownloadPathBookmark); DefineVar(Global, QByteArray, DownloadPathBookmark);

View File

@ -264,9 +264,6 @@ DeclareRefVar(base::Observable<void>, PhoneCallsEnabledChanged);
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap; typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages); DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages);
typedef QMap<uint64, QPixmap> CircleMasksMap;
DeclareRefVar(CircleMasksMap, CircleMasks);
DeclareVar(bool, AskDownloadPath); DeclareVar(bool, AskDownloadPath);
DeclareVar(QString, DownloadPath); DeclareVar(QString, DownloadPath);
DeclareVar(QByteArray, DownloadPathBookmark); DeclareVar(QByteArray, DownloadPathBookmark);

View File

@ -14,29 +14,29 @@ TG_FORCE_INLINE uint64 blurGetColors(const uchar *p) {
return (uint64)p[0] + ((uint64)p[1] << 16) + ((uint64)p[2] << 32) + ((uint64)p[3] << 48); return (uint64)p[0] + ((uint64)p[1] << 16) + ((uint64)p[2] << 32) + ((uint64)p[3] << 48);
} }
const QPixmap &circleMask(int width, int height) { const QImage &circleMask(QSize size) {
Assert(Global::started()); Assert(Global::started());
uint64 key = uint64(uint32(width)) << 32 | uint64(uint32(height)); uint64 key = (uint64(uint32(size.width())) << 32)
| uint64(uint32(size.height()));
Global::CircleMasksMap &masks(Global::RefCircleMasks()); static auto masks = base::flat_map<uint64, QImage>();
auto i = masks.constFind(key); const auto i = masks.find(key);
if (i == masks.cend()) { if (i != end(masks)) {
QImage mask(width, height, QImage::Format_ARGB32_Premultiplied); return i->second;
{
Painter p(&mask);
PainterHighQualityEnabler hq(p);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(0, 0, width, height, Qt::transparent);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
p.drawEllipse(0, 0, width, height);
}
mask.setDevicePixelRatio(cRetinaFactor());
i = masks.insert(key, App::pixmapFromImageInPlace(std::move(mask)));
} }
return i.value(); auto mask = QImage(
size,
QImage::Format_ARGB32_Premultiplied);
mask.fill(Qt::transparent);
{
Painter p(&mask);
PainterHighQualityEnabler hq(p);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
p.drawEllipse(QRect(QPoint(), size));
}
return masks.emplace(key, std::move(mask)).first->second;
} }
} // namespace } // namespace
@ -387,14 +387,14 @@ QImage BlurLargeImage(QImage image, int radius) {
void prepareCircle(QImage &img) { void prepareCircle(QImage &img) {
Assert(!img.isNull()); Assert(!img.isNull());
img.setDevicePixelRatio(cRetinaFactor());
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied); img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
Assert(!img.isNull()); Assert(!img.isNull());
QPixmap mask = circleMask(img.width(), img.height());
Painter p(&img); Painter p(&img);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.drawPixmap(0, 0, mask); p.drawImage(
QRect(QPoint(), img.size() / img.devicePixelRatio()),
circleMask(img.size()));
} }
void prepareRound( void prepareRound(
@ -463,6 +463,7 @@ void prepareRound(
Assert((corners & RectPart::AllCorners) == RectPart::AllCorners); Assert((corners & RectPart::AllCorners) == RectPart::AllCorners);
Assert(target.isNull()); Assert(target.isNull());
prepareCircle(image); prepareCircle(image);
return;
} }
Assert(!image.isNull()); Assert(!image.isNull());