mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix video rotation apply in PiP player.
This commit is contained in:
parent
fc94045f41
commit
112c597556
4 changed files with 70 additions and 46 deletions
|
@ -2395,44 +2395,44 @@ void OverlayWidget::displayDocument(
|
||||||
|
|
||||||
refreshMediaViewer();
|
refreshMediaViewer();
|
||||||
if (_document) {
|
if (_document) {
|
||||||
if (_document->sticker()) {
|
if (_document->sticker()) {
|
||||||
if (const auto image = _documentMedia->getStickerLarge()) {
|
if (const auto image = _documentMedia->getStickerLarge()) {
|
||||||
setStaticContent(image->original());
|
setStaticContent(image->original());
|
||||||
} else if (const auto thumbnail = _documentMedia->thumbnail()) {
|
} else if (const auto thumbnail = _documentMedia->thumbnail()) {
|
||||||
setStaticContent(thumbnail->pixBlurred(
|
setStaticContent(thumbnail->pixBlurred(
|
||||||
_document->dimensions.width(),
|
_document->dimensions.width(),
|
||||||
_document->dimensions.height()
|
_document->dimensions.height()
|
||||||
).toImage());
|
).toImage());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (_documentMedia->canBePlayed()
|
|
||||||
&& initStreaming(continueStreaming)) {
|
|
||||||
} else if (_document->isVideoFile()) {
|
|
||||||
_documentMedia->automaticLoad(fileOrigin(), item);
|
|
||||||
initStreamingThumbnail();
|
|
||||||
} else if (_document->isTheme()) {
|
|
||||||
_documentMedia->automaticLoad(fileOrigin(), item);
|
|
||||||
initThemePreview();
|
|
||||||
} else {
|
|
||||||
_documentMedia->automaticLoad(fileOrigin(), item);
|
|
||||||
_document->saveFromDataSilent();
|
|
||||||
auto &location = _document->location(true);
|
|
||||||
if (location.accessEnable()) {
|
|
||||||
const auto &path = location.name();
|
|
||||||
if (QImageReader(path).canRead()) {
|
|
||||||
setStaticContent(PrepareStaticImage(path));
|
|
||||||
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
|
||||||
}
|
}
|
||||||
} else if (!_documentMedia->bytes().isEmpty()) {
|
} else {
|
||||||
setStaticContent(
|
if (_documentMedia->canBePlayed()
|
||||||
PrepareStaticImage(_documentMedia->bytes()));
|
&& initStreaming(continueStreaming)) {
|
||||||
if (!_staticContent.isNull()) {
|
} else if (_document->isVideoFile()) {
|
||||||
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
_documentMedia->automaticLoad(fileOrigin(), item);
|
||||||
|
initStreamingThumbnail();
|
||||||
|
} else if (_document->isTheme()) {
|
||||||
|
_documentMedia->automaticLoad(fileOrigin(), item);
|
||||||
|
initThemePreview();
|
||||||
|
} else {
|
||||||
|
_documentMedia->automaticLoad(fileOrigin(), item);
|
||||||
|
_document->saveFromDataSilent();
|
||||||
|
auto &location = _document->location(true);
|
||||||
|
if (location.accessEnable()) {
|
||||||
|
const auto &path = location.name();
|
||||||
|
if (QImageReader(path).canRead()) {
|
||||||
|
setStaticContent(PrepareStaticImage(path));
|
||||||
|
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||||
|
}
|
||||||
|
} else if (!_documentMedia->bytes().isEmpty()) {
|
||||||
|
setStaticContent(
|
||||||
|
PrepareStaticImage(_documentMedia->bytes()));
|
||||||
|
if (!_staticContent.isNull()) {
|
||||||
|
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
location.accessDisable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
location.accessDisable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
refreshCaption(item);
|
refreshCaption(item);
|
||||||
|
|
||||||
|
@ -2503,6 +2503,9 @@ if (_document->sticker()) {
|
||||||
_h = contentSize.height();
|
_h = contentSize.height();
|
||||||
}
|
}
|
||||||
contentSizeChanged();
|
contentSizeChanged();
|
||||||
|
if (videoShown()) {
|
||||||
|
applyVideoSize();
|
||||||
|
}
|
||||||
refreshFromLabel(item);
|
refreshFromLabel(item);
|
||||||
_blurred = false;
|
_blurred = false;
|
||||||
if (_showAsPip && _streamed && !videoIsGifOrUserpic()) {
|
if (_showAsPip && _streamed && !videoIsGifOrUserpic()) {
|
||||||
|
@ -2682,8 +2685,9 @@ void OverlayWidget::initStreamingThumbnail() {
|
||||||
void OverlayWidget::streamingReady(Streaming::Information &&info) {
|
void OverlayWidget::streamingReady(Streaming::Information &&info) {
|
||||||
if (videoShown()) {
|
if (videoShown()) {
|
||||||
applyVideoSize();
|
applyVideoSize();
|
||||||
|
} else {
|
||||||
|
updateContentRect();
|
||||||
}
|
}
|
||||||
updateContentRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::applyVideoSize() {
|
void OverlayWidget::applyVideoSize() {
|
||||||
|
@ -2694,6 +2698,7 @@ void OverlayWidget::applyVideoSize() {
|
||||||
_h = contentSize.height();
|
_h = contentSize.height();
|
||||||
contentSizeChanged();
|
contentSizeChanged();
|
||||||
}
|
}
|
||||||
|
updateContentRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OverlayWidget::createStreamingObjects() {
|
bool OverlayWidget::createStreamingObjects() {
|
||||||
|
@ -2958,7 +2963,6 @@ void OverlayWidget::playbackControlsRotate() {
|
||||||
_rotation = storage.get(_document);
|
_rotation = storage.get(_document);
|
||||||
if (videoShown()) {
|
if (videoShown()) {
|
||||||
applyVideoSize();
|
applyVideoSize();
|
||||||
updateContentRect();
|
|
||||||
} else {
|
} else {
|
||||||
redisplayContent();
|
redisplayContent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1119,6 +1119,7 @@ void Pip::volumeControllerUpdate(QPoint position) {
|
||||||
/ float64(_volumeController.icon.width());
|
/ float64(_volumeController.icon.width());
|
||||||
const auto value = std::clamp(unbound, 0., 1.);
|
const auto value = std::clamp(unbound, 0., 1.);
|
||||||
volumeChanged(value);
|
volumeChanged(value);
|
||||||
|
_panel.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pip::setupButtons() {
|
void Pip::setupButtons() {
|
||||||
|
@ -1191,8 +1192,12 @@ void Pip::setupButtons() {
|
||||||
rect.y() + (rect.height() - st::pipPlayIcon.height()) / 2,
|
rect.y() + (rect.height() - st::pipPlayIcon.height()) / 2,
|
||||||
st::pipPlayIcon.width(),
|
st::pipPlayIcon.width(),
|
||||||
st::pipPlayIcon.height());
|
st::pipPlayIcon.height());
|
||||||
_volumeController.icon = _volumeController.area.marginsRemoved(
|
const auto volumeArea = _volumeController.area;
|
||||||
{ volumeSkip, volumeSkip, volumeSkip, volumeSkip });
|
_volumeController.icon = (volumeArea.width() > 2 * volumeSkip
|
||||||
|
&& volumeArea.height() > 2 * volumeSkip)
|
||||||
|
? volumeArea.marginsRemoved(
|
||||||
|
{ volumeSkip, volumeSkip, volumeSkip, volumeSkip })
|
||||||
|
: QRect();
|
||||||
const auto playbackSkip = st::pipPlaybackSkip;
|
const auto playbackSkip = st::pipPlaybackSkip;
|
||||||
const auto playbackHeight = 2 * playbackSkip + st::pipPlaybackWide;
|
const auto playbackHeight = 2 * playbackSkip + st::pipPlaybackWide;
|
||||||
_playback.area = QRect(
|
_playback.area = QRect(
|
||||||
|
@ -1258,7 +1263,7 @@ Ui::GL::ChosenRenderer Pip::chooseRenderer(
|
||||||
void Pip::paint(not_null<Renderer*> renderer) const {
|
void Pip::paint(not_null<Renderer*> renderer) const {
|
||||||
const auto controlsShown = _controlsShown.value(
|
const auto controlsShown = _controlsShown.value(
|
||||||
(_over != OverState::None) ? 1. : 0.);
|
(_over != OverState::None) ? 1. : 0.);
|
||||||
const auto geometry = ContentGeometry{
|
auto geometry = ContentGeometry{
|
||||||
.inner = _panel.inner(),
|
.inner = _panel.inner(),
|
||||||
.attached = (_panel.useTransparency()
|
.attached = (_panel.useTransparency()
|
||||||
? _panel.attached()
|
? _panel.attached()
|
||||||
|
@ -1266,12 +1271,17 @@ void Pip::paint(not_null<Renderer*> renderer) const {
|
||||||
.fade = controlsShown,
|
.fade = controlsShown,
|
||||||
.outer = _panel.widget()->size(),
|
.outer = _panel.widget()->size(),
|
||||||
.rotation = _rotation,
|
.rotation = _rotation,
|
||||||
|
.videoRotation = _instance.info().video.rotation,
|
||||||
.useTransparency = _panel.useTransparency(),
|
.useTransparency = _panel.useTransparency(),
|
||||||
};
|
};
|
||||||
if (canUseVideoFrame()) {
|
if (canUseVideoFrame()) {
|
||||||
renderer->paintTransformedVideoFrame(geometry);
|
renderer->paintTransformedVideoFrame(geometry);
|
||||||
_instance.markFrameShown();
|
_instance.markFrameShown();
|
||||||
} else {
|
} else {
|
||||||
|
const auto content = staticContent();
|
||||||
|
if (_preparedCoverState == ThumbState::Cover) {
|
||||||
|
geometry.rotation += base::take(geometry.videoRotation);
|
||||||
|
}
|
||||||
renderer->paintTransformedStaticContent(staticContent(), geometry);
|
renderer->paintTransformedStaticContent(staticContent(), geometry);
|
||||||
}
|
}
|
||||||
if (_instance.waitingShown()) {
|
if (_instance.waitingShown()) {
|
||||||
|
@ -1426,7 +1436,7 @@ void Pip::paintPlaybackTexts(QPainter &p, QRect outer) const {
|
||||||
void Pip::paintVolumeController(
|
void Pip::paintVolumeController(
|
||||||
not_null<Renderer*> renderer,
|
not_null<Renderer*> renderer,
|
||||||
float64 shown) const {
|
float64 shown) const {
|
||||||
if (!_volumeController.icon.width()) {
|
if (_volumeController.icon.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
renderer->paintVolumeController(_volumeController.icon, shown);
|
renderer->paintVolumeController(_volumeController.icon, shown);
|
||||||
|
|
|
@ -162,6 +162,7 @@ private:
|
||||||
float64 fade = 0.;
|
float64 fade = 0.;
|
||||||
QSize outer;
|
QSize outer;
|
||||||
int rotation = 0;
|
int rotation = 0;
|
||||||
|
int videoRotation = 0;
|
||||||
bool useTransparency = false;
|
bool useTransparency = false;
|
||||||
};
|
};
|
||||||
struct StaticContent {
|
struct StaticContent {
|
||||||
|
|
|
@ -291,6 +291,7 @@ void Pip::RendererGL::paintTransformedVideoFrame(
|
||||||
if (data.format == Streaming::FrameFormat::None) {
|
if (data.format == Streaming::FrameFormat::None) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
geometry.rotation = (geometry.rotation + geometry.videoRotation) % 360;
|
||||||
if (data.format == Streaming::FrameFormat::ARGB32) {
|
if (data.format == Streaming::FrameFormat::ARGB32) {
|
||||||
Assert(!data.original.isNull());
|
Assert(!data.original.isNull());
|
||||||
paintTransformedStaticContent(data.original, geometry);
|
paintTransformedStaticContent(data.original, geometry);
|
||||||
|
@ -378,23 +379,31 @@ void Pip::RendererGL::paintTransformedStaticContent(
|
||||||
void Pip::RendererGL::paintTransformedContent(
|
void Pip::RendererGL::paintTransformedContent(
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
ContentGeometry geometry) {
|
ContentGeometry geometry) {
|
||||||
const auto rect = transformRect(geometry.inner);
|
std::array<std::array<GLfloat, 2>, 4> rect = { {
|
||||||
|
{ { -1.f, 1.f } },
|
||||||
|
{ { 1.f, 1.f } },
|
||||||
|
{ { 1.f, -1.f } },
|
||||||
|
{ { -1.f, -1.f } },
|
||||||
|
} };
|
||||||
|
if (const auto shift = (geometry.rotation / 90); shift != 0) {
|
||||||
|
std::rotate(begin(rect), begin(rect) + shift, end(rect));
|
||||||
|
}
|
||||||
const auto xscale = 1.f / geometry.inner.width();
|
const auto xscale = 1.f / geometry.inner.width();
|
||||||
const auto yscale = 1.f / geometry.inner.height();
|
const auto yscale = 1.f / geometry.inner.height();
|
||||||
const GLfloat coords[] = {
|
const GLfloat coords[] = {
|
||||||
-1.f, 1.f,
|
rect[0][0], rect[0][1],
|
||||||
-geometry.inner.x() * xscale,
|
-geometry.inner.x() * xscale,
|
||||||
-geometry.inner.y() * yscale,
|
-geometry.inner.y() * yscale,
|
||||||
|
|
||||||
1.f, 1.f,
|
rect[1][0], rect[1][1],
|
||||||
(geometry.outer.width() - geometry.inner.x()) * xscale,
|
(geometry.outer.width() - geometry.inner.x()) * xscale,
|
||||||
-geometry.inner.y() * yscale,
|
-geometry.inner.y() * yscale,
|
||||||
|
|
||||||
1.f, -1.f,
|
rect[2][0], rect[2][1],
|
||||||
(geometry.outer.width() - geometry.inner.x()) * xscale,
|
(geometry.outer.width() - geometry.inner.x()) * xscale,
|
||||||
(geometry.outer.height() - geometry.inner.y()) * yscale,
|
(geometry.outer.height() - geometry.inner.y()) * yscale,
|
||||||
|
|
||||||
-1.f, -1.f,
|
rect[3][0], rect[3][1],
|
||||||
-geometry.inner.x() * xscale,
|
-geometry.inner.x() * xscale,
|
||||||
(geometry.outer.height() - geometry.inner.y()) * yscale,
|
(geometry.outer.height() - geometry.inner.y()) * yscale,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue