Optimize ttl media overlay a bit.

This commit is contained in:
John Preston 2024-01-16 11:56:28 +04:00
parent 93a734eecf
commit 06775b5623
2 changed files with 28 additions and 39 deletions

View file

@ -113,10 +113,7 @@ private:
rpl::variable<QRect> _elementInner;
rpl::lifetime _elementLifetime;
struct {
QImage frame;
bool use = false;
} _last;
QImage _lastFrameCache;
rpl::event_stream<> _closeRequests;
@ -138,6 +135,14 @@ PreviewWrap::PreviewWrap(
std::move(chatWideValue),
[=] { update(_elementGeometry); }))
, _globalViewport(std::move(viewportValue)) {
const auto closeCallback = [=] { _closeRequests.fire({}); };
HistoryView::TTLVoiceStops(
item->fullId()
) | rpl::start_with_next([=] {
_lastFrameCache = Ui::GrabWidgetToImage(this, _elementGeometry);
closeCallback();
}, lifetime());
const auto isRound = _item
&& _item->media()
&& _item->media()->document()
@ -158,8 +163,6 @@ PreviewWrap::PreviewWrap(
}
}, lifetime());
const auto closeCallback = [=] { _closeRequests.fire({}); };
{
const auto close = Ui::CreateChild<Ui::RoundButton>(
this,
@ -252,13 +255,6 @@ PreviewWrap::PreviewWrap(
});
}, tooltip->lifetime());
}
HistoryView::TTLVoiceStops(
item->fullId()
) | rpl::start_with_next([=] {
_last.use = true;
closeCallback();
}, lifetime());
}
rpl::producer<> PreviewWrap::closeRequests() const {
@ -275,31 +271,19 @@ void PreviewWrap::paintEvent(QPaintEvent *e) {
return;
}
auto p = QPainter(this);
//p.fillRect(_viewport, QColor(255, 0, 0, 64));
//p.fillRect(_elementGeometry, QColor(0, 255, 0, 64));
//p.fillRect(_elementInner.current(), QColor(0, 0, 255, 64));
if (!_last.use) {
const auto size = _element->currentSize();
auto result = QImage(
size * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied);
result.fill(Qt::transparent);
result.setDevicePixelRatio(style::DevicePixelRatio());
{
auto q = Painter(&result);
auto context = _theme->preparePaintContext(
_style.get(),
Rect(size),
Rect(size),
!window()->isActiveWindow());
context.outbg = _element->hasOutLayout();
_element->draw(q, context);
}
_last.frame = std::move(result);
}
auto p = Painter(this);
p.translate(_elementGeometry.topLeft());
p.drawImage(0, 0, _last.frame);
if (!_lastFrameCache.isNull()) {
p.drawImage(0, 0, _lastFrameCache);
} else {
auto context = _theme->preparePaintContext(
_style.get(),
Rect(_element->currentSize()),
Rect(_element->currentSize()),
!window()->isActiveWindow());
context.outbg = _element->hasOutLayout();
_element->draw(p, context);
}
}
rpl::producer<QRect> GlobalViewportForWindow(

View file

@ -71,8 +71,13 @@ constexpr auto kAudioVoiceMsgUpdateView = crl::time(100);
st::historyFileInPause.width(),
st::historyFileInPause.height()));
const auto state = lifetime->make_state<State>();
state->start = Lottie::MakeIcon({
.name = u"voice_ttl_start"_q,
//state->start = Lottie::MakeIcon({
// .name = u"voice_ttl_start"_q,
// .color = &st::historyFileInIconFg,
// .sizeOverride = iconSize,
//});
state->idle = Lottie::MakeIcon({
.name = u"voice_ttl_idle"_q,
.color = &st::historyFileInIconFg,
.sizeOverride = iconSize,
});