mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Use QOpenGLWidget on all systems.
This commit is contained in:
parent
b421d0c5cc
commit
c48c4d4283
@ -52,11 +52,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Calls {
|
||||
namespace {
|
||||
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
||||
#define USE_OPENGL_OVERLAY_WIDGET
|
||||
#if 1
|
||||
#define USE_OPENGL_OVERLAY_WIDGET 1
|
||||
#else // Q_OS_MAC && !OS_MAC_OLD
|
||||
#define USE_OPENGL_OVERLAY_WIDGET 0
|
||||
#endif // Q_OS_MAC && !OS_MAC_OLD
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_OVERLAY_WIDGET
|
||||
using IncomingParent = Ui::RpWidgetWrap<QOpenGLWidget>;
|
||||
#else // USE_OPENGL_OVERLAY_WIDGET
|
||||
using IncomingParent = Ui::RpWidget;
|
||||
@ -101,7 +103,7 @@ void Panel::Incoming::paintEvent(QPaintEvent *e) {
|
||||
} else {
|
||||
using namespace Media::View;
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
if (UsePainterRotation(rotation)) {
|
||||
if (UsePainterRotation(rotation, USE_OPENGL_OVERLAY_WIDGET)) {
|
||||
if (rotation) {
|
||||
p.save();
|
||||
p.rotate(rotation);
|
||||
|
@ -200,7 +200,7 @@ void LargeVideo::paint(QRect clip) {
|
||||
const auto left = (size.width() - scaled.width()) / 2;
|
||||
const auto top = (size.height() - scaled.height()) / 2;
|
||||
const auto target = QRect(QPoint(left, top), scaled);
|
||||
if (UsePainterRotation(rotation)) {
|
||||
if (UsePainterRotation(rotation, USE_OPENGL_LARGE_VIDEO)) {
|
||||
if (rotation) {
|
||||
p.save();
|
||||
p.rotate(rotation);
|
||||
|
@ -11,8 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/effects/cross_line.h"
|
||||
#include "ui/effects/animations.h"
|
||||
|
||||
#if defined Q_OS_MAC
|
||||
#define USE_OPENGL_LARGE_VIDEO
|
||||
#if 1
|
||||
#define USE_OPENGL_LARGE_VIDEO 1
|
||||
#else
|
||||
#define USE_OPENGL_LARGE_VIDEO 0
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
namespace style {
|
||||
@ -81,7 +83,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef USE_OPENGL_LARGE_VIDEO
|
||||
#if USE_OPENGL_LARGE_VIDEO
|
||||
using ContentParent = Ui::RpWidgetWrap<QOpenGLWidget>;
|
||||
#else // USE_OPENGL_OVERLAY_WIDGET
|
||||
using ContentParent = Ui::RpWidget;
|
||||
|
@ -466,19 +466,28 @@ void OverlayWidget::updateGeometry() {
|
||||
if (Platform::IsWayland()) {
|
||||
return;
|
||||
}
|
||||
const auto screen = windowHandle() && windowHandle()->screen()
|
||||
? windowHandle()->screen()
|
||||
const auto window = windowHandle();
|
||||
const auto screen = window && window->screen()
|
||||
? window->screen()
|
||||
: QApplication::primaryScreen();
|
||||
const auto available = screen->geometry();
|
||||
if (geometry() == available) {
|
||||
const auto useSizeHack = (USE_OPENGL_OVERLAY_WIDGET
|
||||
&& Platform::IsWindows());
|
||||
const auto use = available.marginsAdded({ 0, 0, 0, 1 });
|
||||
const auto mask = useSizeHack ? QRegion(available) : QRegion();
|
||||
if ((geometry() == use)
|
||||
&& (!useSizeHack || (window && window->mask() == mask))) {
|
||||
return;
|
||||
}
|
||||
DEBUG_LOG(("Viewer Pos: Setting %1, %2, %3, %4")
|
||||
.arg(available.x())
|
||||
.arg(available.y())
|
||||
.arg(available.width())
|
||||
.arg(available.height()));
|
||||
setGeometry(available);
|
||||
.arg(use.x())
|
||||
.arg(use.y())
|
||||
.arg(use.width())
|
||||
.arg(use.height()));
|
||||
setGeometry(use);
|
||||
if (window && useSizeHack) {
|
||||
window->setMask(mask);
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayWidget::moveEvent(QMoveEvent *e) {
|
||||
@ -552,7 +561,7 @@ QImage OverlayWidget::videoFrameForDirectPaint() const {
|
||||
|
||||
const auto result = videoFrame();
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_OVERLAY_WIDGET
|
||||
const auto bytesPerLine = result.bytesPerLine();
|
||||
if (bytesPerLine == result.width() * 4) {
|
||||
return result;
|
||||
@ -3385,7 +3394,7 @@ void OverlayWidget::paintTransformedVideoFrame(Painter &p) {
|
||||
PainterHighQualityEnabler hq(p);
|
||||
|
||||
const auto rotation = contentRotation();
|
||||
if (UsePainterRotation(rotation)) {
|
||||
if (UsePainterRotation(rotation, USE_OPENGL_OVERLAY_WIDGET)) {
|
||||
if (rotation) {
|
||||
p.save();
|
||||
p.rotate(rotation);
|
||||
@ -3415,7 +3424,7 @@ void OverlayWidget::paintTransformedStaticContent(Painter &p) {
|
||||
return;
|
||||
}
|
||||
const auto rotation = contentRotation();
|
||||
if (UsePainterRotation(rotation)) {
|
||||
if (UsePainterRotation(rotation, USE_OPENGL_OVERLAY_WIDGET)) {
|
||||
if (rotation) {
|
||||
p.save();
|
||||
p.rotate(rotation);
|
||||
@ -3444,7 +3453,7 @@ void OverlayWidget::paintRadialLoading(
|
||||
const auto inner = radialRect();
|
||||
Assert(!inner.isEmpty());
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_OVERLAY_WIDGET
|
||||
{
|
||||
if (_radialCache.size() != inner.size() * cIntRetinaFactor()) {
|
||||
_radialCache = QImage(
|
||||
@ -4349,7 +4358,7 @@ bool OverlayWidget::eventFilter(QObject *obj, QEvent *e) {
|
||||
}
|
||||
|
||||
void OverlayWidget::applyHideWindowWorkaround() {
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_OVERLAY_WIDGET
|
||||
// QOpenGLWidget can't properly destroy a child widget if
|
||||
// it is hidden exactly after that, so it must be repainted
|
||||
// before it is hidden without the child widget.
|
||||
|
@ -52,15 +52,17 @@ namespace View {
|
||||
class GroupThumbs;
|
||||
class Pip;
|
||||
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
||||
#define USE_OPENGL_OVERLAY_WIDGET
|
||||
#if 1
|
||||
#define USE_OPENGL_OVERLAY_WIDGET 1
|
||||
#else // Q_OS_MAC && !OS_MAC_OLD
|
||||
#define USE_OPENGL_OVERLAY_WIDGET 0
|
||||
#endif // Q_OS_MAC && !OS_MAC_OLD
|
||||
|
||||
struct OverlayParentTraits : Ui::RpWidgetDefaultTraits {
|
||||
static constexpr bool kSetZeroGeometry = false;
|
||||
};
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_OVERLAY_WIDGET
|
||||
using OverlayParent = Ui::RpWidgetWrap<QOpenGLWidget, OverlayParentTraits>;
|
||||
#else // USE_OPENGL_OVERLAY_WIDGET
|
||||
using OverlayParent = Ui::RpWidgetWrap<QWidget, OverlayParentTraits>;
|
||||
|
@ -354,8 +354,8 @@ QRect RotatedRect(QRect rect, int rotation) {
|
||||
Unexpected("Rotation in RotatedRect.");
|
||||
}
|
||||
|
||||
bool UsePainterRotation(int rotation) {
|
||||
return Platform::IsMac() || !(rotation % 180);
|
||||
bool UsePainterRotation(int rotation, bool opengl) {
|
||||
return opengl || !(rotation % 180);
|
||||
}
|
||||
|
||||
QSize FlipSizeByRotation(QSize size, int rotation) {
|
||||
@ -375,6 +375,9 @@ PipPanel::PipPanel(
|
||||
Fn<void(QPainter&, FrameRequest)> paint)
|
||||
: _parent(parent)
|
||||
, _paint(std::move(paint)) {
|
||||
}
|
||||
|
||||
void PipPanel::init() {
|
||||
setWindowFlags(Qt::Tool
|
||||
| Qt::WindowStaysOnTopHint
|
||||
| Qt::FramelessWindowHint
|
||||
@ -592,8 +595,12 @@ void PipPanel::setPositionOnScreen(Position position, QRect available) {
|
||||
void PipPanel::paintEvent(QPaintEvent *e) {
|
||||
QPainter p(this);
|
||||
|
||||
if (_useTransparency) {
|
||||
Ui::Platform::StartTranslucentPaint(p, e->region());
|
||||
if (_useTransparency && USE_OPENGL_PIP_WIDGET) {
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
for (const auto rect : e->region()) {
|
||||
p.fillRect(rect, Qt::transparent);
|
||||
}
|
||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
}
|
||||
|
||||
auto request = FrameRequest();
|
||||
@ -898,6 +905,7 @@ Pip::Pip(
|
||||
Pip::~Pip() = default;
|
||||
|
||||
void Pip::setupPanel() {
|
||||
_panel.init();
|
||||
const auto size = [&] {
|
||||
if (!_instance.info().video.size.isEmpty()) {
|
||||
return _instance.info().video.size;
|
||||
@ -1196,11 +1204,12 @@ void Pip::paint(QPainter &p, FrameRequest request) {
|
||||
inner.topLeft(),
|
||||
request.outer / style::DevicePixelRatio()
|
||||
};
|
||||
if (UsePainterRotation(_rotation)) {
|
||||
if (UsePainterRotation(_rotation, USE_OPENGL_PIP_WIDGET)) {
|
||||
if (_rotation) {
|
||||
p.save();
|
||||
p.rotate(_rotation);
|
||||
}
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
p.drawImage(RotatedRect(rect, _rotation), image);
|
||||
if (_rotation) {
|
||||
p.restore();
|
||||
@ -1516,7 +1525,7 @@ QImage Pip::videoFrame(const FrameRequest &request) const {
|
||||
QImage Pip::videoFrameForDirectPaint(const FrameRequest &request) const {
|
||||
const auto result = videoFrame(request);
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#ifdef USE_OPENGL_PIP_WIDGET
|
||||
const auto bytesPerLine = result.bytesPerLine();
|
||||
if (bytesPerLine == result.width() * 4) {
|
||||
return result;
|
||||
@ -1545,14 +1554,14 @@ QImage Pip::videoFrameForDirectPaint(const FrameRequest &request) const {
|
||||
from += bytesPerLine;
|
||||
}
|
||||
return cache;
|
||||
#endif // USE_OPENGL_OVERLAY_WIDGET
|
||||
#endif // USE_OPENGL_PIP_WIDGET
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Pip::paintRadialLoading(QPainter &p) const {
|
||||
const auto inner = countRadialRect();
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#ifdef USE_OPENGL_PIP_WIDGET
|
||||
{
|
||||
if (_radialCache.size() != inner.size() * cIntRetinaFactor()) {
|
||||
_radialCache = QImage(
|
||||
@ -1566,9 +1575,9 @@ void Pip::paintRadialLoading(QPainter &p) const {
|
||||
paintRadialLoadingContent(q, inner.translated(-inner.topLeft()));
|
||||
}
|
||||
p.drawImage(inner.topLeft(), _radialCache);
|
||||
#else // USE_OPENGL_OVERLAY_WIDGET
|
||||
#else // USE_OPENGL_PIP_WIDGET
|
||||
paintRadialLoadingContent(p, inner);
|
||||
#endif // USE_OPENGL_OVERLAY_WIDGET
|
||||
#endif // USE_OPENGL_PIP_WIDGET
|
||||
}
|
||||
|
||||
void Pip::paintRadialLoadingContent(QPainter &p, const QRect &inner) const {
|
||||
|
@ -34,19 +34,21 @@ namespace View {
|
||||
class PlaybackProgress;
|
||||
|
||||
[[nodiscard]] QRect RotatedRect(QRect rect, int rotation);
|
||||
[[nodiscard]] bool UsePainterRotation(int rotation);
|
||||
[[nodiscard]] bool UsePainterRotation(int rotation, bool opengl);
|
||||
[[nodiscard]] QSize FlipSizeByRotation(QSize size, int rotation);
|
||||
[[nodiscard]] QImage RotateFrameImage(QImage image, int rotation);
|
||||
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
||||
#define USE_OPENGL_OVERLAY_WIDGET
|
||||
#if 1
|
||||
#define USE_OPENGL_PIP_WIDGET 1
|
||||
#else
|
||||
#define USE_OPENGL_PIP_WIDGET 0
|
||||
#endif // Q_OS_MAC && !OS_MAC_OLD
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_PIP_WIDGET
|
||||
using PipParent = Ui::RpWidgetWrap<QOpenGLWidget>;
|
||||
#else // USE_OPENGL_OVERLAY_WIDGET
|
||||
#else // USE_OPENGL_PIP_WIDGET
|
||||
using PipParent = Ui::RpWidget;
|
||||
#endif // USE_OPENGL_OVERLAY_WIDGET
|
||||
#endif // USE_OPENGL_PIP_WIDGET
|
||||
|
||||
class PipPanel final : public PipParent {
|
||||
public:
|
||||
@ -61,6 +63,7 @@ public:
|
||||
PipPanel(
|
||||
QWidget *parent,
|
||||
Fn<void(QPainter&, FrameRequest)> paint);
|
||||
void init();
|
||||
|
||||
void setAspectRatio(QSize ratio);
|
||||
[[nodiscard]] Position countPosition() const;
|
||||
@ -234,10 +237,10 @@ private:
|
||||
FnMut<void()> _closeAndContinue;
|
||||
FnMut<void()> _destroy;
|
||||
|
||||
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
||||
#if USE_OPENGL_PIP_WIDGET
|
||||
mutable QImage _frameForDirectPaint;
|
||||
mutable QImage _radialCache;
|
||||
#endif // USE_OPENGL_OVERLAY_WIDGET
|
||||
#endif // USE_OPENGL_PIP_WIDGET
|
||||
|
||||
mutable QImage _preparedCoverStorage;
|
||||
mutable FrameRequest _preparedCoverRequest;
|
||||
|
Loading…
Reference in New Issue
Block a user