Files
tdesktop/Telegram/SourceFiles/media/streaming/media_streaming_round_preview.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

63 lines
1.5 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "media/streaming/media_streaming_round_preview.h"
namespace Media::Streaming {
RoundPreview::RoundPreview(const QByteArray &bytes, int size)
: _bytes(bytes)
, _reader(
Clip::MakeReader(_bytes, [=](Clip::Notification update) {
clipCallback(update);
}))
, _size(size) {
}
std::shared_ptr<Ui::DynamicImage> RoundPreview::clone() {
Unexpected("RoundPreview::clone.");
}
QImage RoundPreview::image(int size) {
if (!_reader || !_reader->started()) {
return QImage();
}
return _reader->current({
.frame = QSize(_size, _size),
.factor = style::DevicePixelRatio(),
.radius = ImageRoundRadius::Ellipse,
}, crl::now());
}
void RoundPreview::subscribeToUpdates(Fn<void()> callback) {
_repaint = std::move(callback);
}
void RoundPreview::clipCallback(Clip::Notification notification) {
switch (notification) {
case Clip::Notification::Reinit: {
if (_reader->state() == ::Media::Clip::State::Error) {
_reader.setBad();
} else if (_reader->ready() && !_reader->started()) {
_reader->start({
.frame = QSize(_size, _size),
.factor = style::DevicePixelRatio(),
.radius = ImageRoundRadius::Ellipse,
});
}
} break;
case Clip::Notification::Repaint: break;
}
if (const auto onstack = _repaint) {
onstack();
}
}
} // namespace Media::Streaming