diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index e0300e20f..cd49e09eb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -195,14 +195,10 @@ void Location::draw(Painter &p, const PaintContext &context) const { } ensureMediaCreated(); - //if (const auto thumbnail = _media->image()) { - // p.drawPixmap(rthumb.topLeft(), thumbnail->pixSingle( - // rthumb.size(), - // { - // .options = Images::RoundOptions(roundRadius, roundCorners), - // .outer = rthumb.size(), - // })); - //} else if (!bubble) { + validateImageCache(rthumb.size(), rounding); + if (!_imageCache.isNull()) { + p.drawImage(rthumb.topLeft(), _imageCache); + } else if (!bubble) { Ui::PaintBubble( p, Ui::SimpleBubble{ @@ -215,7 +211,7 @@ void Location::draw(Painter &p, const PaintContext &context) const { .outbg = context.outbg, .rounding = rounding, }); - //} + } const auto paintMarker = [&](const style::icon &icon) { icon.paint( p, @@ -247,6 +243,28 @@ void Location::draw(Painter &p, const PaintContext &context) const { } } +void Location::validateImageCache( + QSize outer, + Ui::BubbleRounding rounding) const { + const auto ratio = style::DevicePixelRatio(); + if (_imageCache.size() == (outer * ratio) + && _imageCacheRounding == rounding) { + return; + } + const auto thumbnail = _media->image(); + if (!thumbnail) { + return; + } + _imageCache = Images::Round( + thumbnail->original().scaled( + outer * ratio, + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation), + MediaRoundingMask(rounding)); + _imageCache.setDevicePixelRatio(ratio); + _imageCacheRounding = rounding; +} + TextState Location::textState(QPoint point, StateRequest request) const { auto result = TextState(_parent); auto symbolAdd = 0; diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.h b/Telegram/SourceFiles/history/view/media/history_view_location.h index 84682c049..46f49caf9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.h +++ b/Telegram/SourceFiles/history/view/media/history_view_location.h @@ -65,19 +65,28 @@ public: private: void ensureMediaCreated() const; + void validateImageCache( + QSize outer, + Ui::BubbleRounding rounding) const; + QSize countOptimalSize() override; QSize countCurrentSize(int newWidth) override; - TextSelection toDescriptionSelection(TextSelection selection) const; - TextSelection fromDescriptionSelection(TextSelection selection) const; + [[nodiscard]] TextSelection toDescriptionSelection( + TextSelection selection) const; + [[nodiscard]] TextSelection fromDescriptionSelection( + TextSelection selection) const; + + [[nodiscard]] int fullWidth() const; + [[nodiscard]] int fullHeight() const; const not_null _data; mutable std::shared_ptr _media; Ui::Text::String _title, _description; ClickHandlerPtr _link; - int fullWidth() const; - int fullHeight() const; + mutable QImage _imageCache; + mutable Ui::BubbleRounding _imageCacheRounding; }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.h b/Telegram/SourceFiles/history/view/media/history_view_photo.h index c3e878235..23f8c8d3d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.h +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.h @@ -149,8 +149,8 @@ private: mutable std::shared_ptr _dataMedia; mutable std::unique_ptr _streamed; mutable QImage _imageCache; - int _serviceWidth = 0; mutable std::optional _imageCacheRounding; + int _serviceWidth = 0; mutable bool _imageCacheBlurred = false; };