For surface with parent backend should be fixed.

This commit is contained in:
John Preston 2021-06-08 15:51:52 +04:00
parent e41fb0d8fd
commit c5a46d9d1b
11 changed files with 91 additions and 55 deletions

View file

@ -56,7 +56,8 @@ class Panel::Incoming final {
public: public:
Incoming( Incoming(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Webrtc::VideoTrack*> track); not_null<Webrtc::VideoTrack*> track,
Ui::GL::Backend backend);
[[nodiscard]] not_null<QWidget*> widget() const; [[nodiscard]] not_null<QWidget*> widget() const;
[[nodiscard]] not_null<Ui::RpWidgetWrap* > rp() const; [[nodiscard]] not_null<Ui::RpWidgetWrap* > rp() const;
@ -69,7 +70,7 @@ private:
void fillBottomShadow(QPainter &p); void fillBottomShadow(QPainter &p);
[[nodiscard]] Ui::GL::ChosenRenderer chooseRenderer( [[nodiscard]] Ui::GL::ChosenRenderer chooseRenderer(
Ui::GL::Capabilities capabilities); Ui::GL::Backend backend);
const std::unique_ptr<Ui::RpWidgetWrap> _surface; const std::unique_ptr<Ui::RpWidgetWrap> _surface;
const not_null<Webrtc::VideoTrack*> _track; const not_null<Webrtc::VideoTrack*> _track;
@ -79,12 +80,9 @@ private:
Panel::Incoming::Incoming( Panel::Incoming::Incoming(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Webrtc::VideoTrack*> track) not_null<Webrtc::VideoTrack*> track,
: _surface(Ui::GL::CreateSurface( Ui::GL::Backend backend)
parent, : _surface(Ui::GL::CreateSurface(parent, chooseRenderer(backend)))
[=](Ui::GL::Capabilities capabilities) {
return chooseRenderer(capabilities);
}))
, _track(track) { , _track(track) {
initBottomShadow(); initBottomShadow();
widget()->setAttribute(Qt::WA_OpaquePaintEvent); widget()->setAttribute(Qt::WA_OpaquePaintEvent);
@ -100,7 +98,7 @@ not_null<Ui::RpWidgetWrap*> Panel::Incoming::rp() const {
} }
Ui::GL::ChosenRenderer Panel::Incoming::chooseRenderer( Ui::GL::ChosenRenderer Panel::Incoming::chooseRenderer(
Ui::GL::Capabilities capabilities) { Ui::GL::Backend backend) {
class Renderer : public Ui::GL::Renderer { class Renderer : public Ui::GL::Renderer {
public: public:
Renderer(not_null<Panel::Incoming*> owner) : _owner(owner) { Renderer(not_null<Panel::Incoming*> owner) : _owner(owner) {
@ -121,15 +119,9 @@ Ui::GL::ChosenRenderer Panel::Incoming::chooseRenderer(
}; };
const auto use = Platform::IsMac()
? true
: Platform::IsWindows()
? capabilities.supported
: capabilities.transparency;
LOG(("OpenGL: %1 (Incoming)").arg(Logs::b(use)));
return { return {
.renderer = std::make_unique<Renderer>(this), .renderer = std::make_unique<Renderer>(this),
.backend = (use ? Ui::GL::Backend::OpenGL : Ui::GL::Backend::Raster), .backend = backend,
}; };
} }
@ -258,6 +250,25 @@ Panel::Panel(not_null<Call*> call)
Panel::~Panel() = default; Panel::~Panel() = default;
std::unique_ptr<Ui::Window> Panel::createWindow() {
auto result = std::make_unique<Ui::Window>();
const auto capabilities = Ui::GL::CheckCapabilities(result.get());
const auto use = Platform::IsMac()
? true
: Platform::IsWindows()
? capabilities.supported
: capabilities.transparency;
LOG(("OpenGL: %1 (Incoming)").arg(Logs::b(use)));
_backend = use ? Ui::GL::Backend::OpenGL : Ui::GL::Backend::Raster;
if (use) {
return result;
}
// We have to create a new window, if OpenGL initialization failed.
return std::make_unique<Ui::Window>();
}
bool Panel::isActive() const { bool Panel::isActive() const {
return _window->isActiveWindow() return _window->isActiveWindow()
&& _window->isVisible() && _window->isVisible()
@ -491,7 +502,8 @@ void Panel::reinitWithCall(Call *call) {
_call->videoOutgoing()); _call->videoOutgoing());
_incoming = std::make_unique<Incoming>( _incoming = std::make_unique<Incoming>(
widget(), widget(),
_call->videoIncoming()); _call->videoIncoming(),
_backend);
_incoming->widget()->hide(); _incoming->widget()->hide();
_call->mutedValue( _call->mutedValue(

View file

@ -30,6 +30,9 @@ class FadeWrap;
template <typename Widget> template <typename Widget>
class PaddingWrap; class PaddingWrap;
class Window; class Window;
namespace GL {
enum class Backend;
} // namespace GL
namespace Platform { namespace Platform {
class TitleControls; class TitleControls;
} // namespace Platform } // namespace Platform
@ -67,6 +70,7 @@ private:
Redial, Redial,
}; };
std::unique_ptr<Ui::Window> createWindow();
[[nodiscard]] not_null<Ui::RpWidget*> widget() const; [[nodiscard]] not_null<Ui::RpWidget*> widget() const;
void paint(QRect clip); void paint(QRect clip);
@ -80,9 +84,6 @@ private:
void handleClose(); void handleClose();
QRect signalBarsRect() const;
void paintSignalBarsBg(Painter &p);
void updateControlsGeometry(); void updateControlsGeometry();
void updateHangupGeometry(); void updateHangupGeometry();
void updateStatusGeometry(); void updateStatusGeometry();
@ -105,6 +106,7 @@ private:
Call *_call = nullptr; Call *_call = nullptr;
not_null<UserData*> _user; not_null<UserData*> _user;
Ui::GL::Backend _backend = Ui::GL::Backend();
const std::unique_ptr<Ui::Window> _window; const std::unique_ptr<Ui::Window> _window;
std::unique_ptr<Incoming> _incoming; std::unique_ptr<Incoming> _incoming;

View file

@ -1461,7 +1461,8 @@ std::unique_ptr<Row> Members::Controller::createInvitedRow(
Members::Members( Members::Members(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<GroupCall*> call, not_null<GroupCall*> call,
PanelMode mode) PanelMode mode,
Ui::GL::Backend backend)
: RpWidget(parent) : RpWidget(parent)
, _call(call) , _call(call)
, _mode(mode) , _mode(mode)
@ -1473,7 +1474,8 @@ Members::Members(
, _viewport( , _viewport(
std::make_unique<Viewport>( std::make_unique<Viewport>(
_videoWrap.get(), _videoWrap.get(),
PanelMode::Default)) { PanelMode::Default,
backend)) {
setupList(); setupList();
setupAddMember(call); setupAddMember(call);
setContent(_list); setContent(_list);

View file

@ -14,6 +14,9 @@ class RpWidget;
class ScrollArea; class ScrollArea;
class VerticalLayout; class VerticalLayout;
class SettingsButton; class SettingsButton;
namespace GL {
enum class Backend;
} // namespace GL
} // namespace Ui } // namespace Ui
namespace Data { namespace Data {
@ -39,7 +42,8 @@ public:
Members( Members(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<GroupCall*> call, not_null<GroupCall*> call,
PanelMode mode); PanelMode mode,
Ui::GL::Backend backend);
~Members(); ~Members();
[[nodiscard]] not_null<Viewport*> viewport() const; [[nodiscard]] not_null<Viewport*> viewport() const;

View file

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/dropdown_menu.h" #include "ui/widgets/dropdown_menu.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/widgets/tooltip.h" #include "ui/widgets/tooltip.h"
#include "ui/gl/gl_detection.h"
#include "ui/chat/group_call_bar.h" #include "ui/chat/group_call_bar.h"
#include "ui/layers/layer_manager.h" #include "ui/layers/layer_manager.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
@ -46,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/platform/base_platform_info.h"
#include "base/qt_signal_producer.h" #include "base/qt_signal_producer.h"
#include "base/timer_rpl.h" #include "base/timer_rpl.h"
#include "app.h" #include "app.h"
@ -85,14 +87,14 @@ struct Panel::ControlsBackgroundNarrow {
Panel::Panel(not_null<GroupCall*> call) Panel::Panel(not_null<GroupCall*> call)
: _call(call) : _call(call)
, _peer(call->peer()) , _peer(call->peer())
, _window(std::make_unique<Ui::Window>()) , _window(createWindow())
, _layerBg(std::make_unique<Ui::LayerManager>(_window->body())) , _layerBg(std::make_unique<Ui::LayerManager>(_window->body()))
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
, _controls(std::make_unique<Ui::Platform::TitleControls>( , _controls(std::make_unique<Ui::Platform::TitleControls>(
_window->body(), _window->body(),
st::groupCallTitle)) st::groupCallTitle))
#endif // !Q_OS_MAC #endif // !Q_OS_MAC
, _viewport(std::make_unique<Viewport>(widget(), PanelMode::Wide)) , _viewport(std::make_unique<Viewport>(widget(), PanelMode::Wide, _backend))
, _mute(std::make_unique<Ui::CallMuteButton>( , _mute(std::make_unique<Ui::CallMuteButton>(
widget(), widget(),
st::callMuteButton, st::callMuteButton,
@ -137,6 +139,25 @@ Panel::~Panel() {
_viewport = nullptr; _viewport = nullptr;
} }
std::unique_ptr<Ui::Window> Panel::createWindow() {
auto result = std::make_unique<Ui::Window>();
const auto capabilities = Ui::GL::CheckCapabilities(result.get());
const auto use = Platform::IsMac()
? true
: Platform::IsWindows()
? capabilities.supported
: capabilities.transparency;
LOG(("OpenGL: %1 (Calls::Group::Viewport)").arg(Logs::b(use)));
_backend = use ? Ui::GL::Backend::OpenGL : Ui::GL::Backend::Raster;
if (use) {
return result;
}
// We have to create a new window, if OpenGL initialization failed.
return std::make_unique<Ui::Window>();
}
void Panel::setupRealCallViewers() { void Panel::setupRealCallViewers() {
_call->real( _call->real(
) | rpl::start_with_next([=](not_null<Data::GroupCall*> real) { ) | rpl::start_with_next([=](not_null<Data::GroupCall*> real) {
@ -679,7 +700,7 @@ void Panel::setupMembers() {
_countdown.destroy(); _countdown.destroy();
_startsWhen.destroy(); _startsWhen.destroy();
_members.create(widget(), _call, mode()); _members.create(widget(), _call, mode(), _backend);
setupVideo(_viewport.get()); setupVideo(_viewport.get());
setupVideo(_members->viewport()); setupVideo(_members->viewport());

View file

@ -42,6 +42,9 @@ class ScrollArea;
class GenericBox; class GenericBox;
class LayerManager; class LayerManager;
class GroupCallScheduledLeft; class GroupCallScheduledLeft;
namespace GL {
enum class Backend;
} // namespace GL
namespace Toast { namespace Toast {
class Instance; class Instance;
} // namespace Toast } // namespace Toast
@ -81,6 +84,7 @@ private:
using State = GroupCall::State; using State = GroupCall::State;
struct ControlsBackgroundNarrow; struct ControlsBackgroundNarrow;
std::unique_ptr<Ui::Window> createWindow();
[[nodiscard]] not_null<Ui::RpWidget*> widget() const; [[nodiscard]] not_null<Ui::RpWidget*> widget() const;
[[nodiscard]] PanelMode mode() const; [[nodiscard]] PanelMode mode() const;
@ -151,6 +155,7 @@ private:
const not_null<GroupCall*> _call; const not_null<GroupCall*> _call;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
Ui::GL::Backend _backend = Ui::GL::Backend();
const std::unique_ptr<Ui::Window> _window; const std::unique_ptr<Ui::Window> _window;
const std::unique_ptr<Ui::LayerManager> _layerBg; const std::unique_ptr<Ui::LayerManager> _layerBg;
rpl::variable<PanelMode> _mode; rpl::variable<PanelMode> _mode;

View file

@ -47,13 +47,12 @@ namespace {
} // namespace } // namespace
Viewport::Viewport(not_null<QWidget*> parent, PanelMode mode) Viewport::Viewport(
not_null<QWidget*> parent,
PanelMode mode,
Ui::GL::Backend backend)
: _mode(mode) : _mode(mode)
, _content(Ui::GL::CreateSurface( , _content(Ui::GL::CreateSurface(parent, chooseRenderer(backend))) {
parent,
[=](Ui::GL::Capabilities capabilities) {
return chooseRenderer(capabilities);
})) {
setup(); setup();
} }
@ -796,25 +795,14 @@ void Viewport::setPressed(Selection value) {
_pressed = value; _pressed = value;
} }
Ui::GL::ChosenRenderer Viewport::chooseRenderer( Ui::GL::ChosenRenderer Viewport::chooseRenderer(Ui::GL::Backend backend) {
Ui::GL::Capabilities capabilities) { _opengl = (backend == Ui::GL::Backend::OpenGL);
const auto use = Platform::IsMac()
? true
: Platform::IsWindows()
? capabilities.supported
: capabilities.transparency;
LOG(("OpenGL: %1 (Calls::Group::Viewport)").arg(Logs::b(use)));
if (use) {
auto renderer = std::make_unique<RendererGL>(this);
_opengl = true;
return {
.renderer = std::move(renderer),
.backend = Ui::GL::Backend::OpenGL,
};
}
return { return {
.renderer = std::make_unique<RendererSW>(this), .renderer = (_opengl
.backend = Ui::GL::Backend::Raster, ? std::unique_ptr<Ui::GL::Renderer>(
std::make_unique<RendererGL>(this))
: std::make_unique<RendererSW>(this)),
.backend = backend,
}; };
} }

View file

@ -14,6 +14,7 @@ namespace Ui {
class AbstractButton; class AbstractButton;
class RpWidgetWrap; class RpWidgetWrap;
namespace GL { namespace GL {
enum class Backend;
struct Capabilities; struct Capabilities;
struct ChosenRenderer; struct ChosenRenderer;
} // namespace GL } // namespace GL
@ -58,7 +59,10 @@ struct VideoTileTrack {
class Viewport final { class Viewport final {
public: public:
Viewport(not_null<QWidget*> parent, PanelMode mode); Viewport(
not_null<QWidget*> parent,
PanelMode mode,
Ui::GL::Backend backend);
~Viewport(); ~Viewport();
[[nodiscard]] not_null<QWidget*> widget() const; [[nodiscard]] not_null<QWidget*> widget() const;
@ -159,7 +163,7 @@ private:
void updateSelected(); void updateSelected();
[[nodiscard]] Ui::GL::ChosenRenderer chooseRenderer( [[nodiscard]] Ui::GL::ChosenRenderer chooseRenderer(
Ui::GL::Capabilities capabilities); Ui::GL::Backend backend);
PanelMode _mode = PanelMode(); PanelMode _mode = PanelMode();
bool _opengl = false; bool _opengl = false;

View file

@ -289,7 +289,6 @@ OverlayWidget::PipWrap::PipWrap(
OverlayWidget::OverlayWidget() OverlayWidget::OverlayWidget()
: _surface(Ui::GL::CreateSurface( : _surface(Ui::GL::CreateSurface(
nullptr, // No parent for the window in Qt parent-child sense.
[=](Ui::GL::Capabilities capabilities) { [=](Ui::GL::Capabilities capabilities) {
return chooseRenderer(capabilities); return chooseRenderer(capabilities);
})) }))

View file

@ -375,7 +375,6 @@ PipPanel::PipPanel(
QWidget *parent, QWidget *parent,
Fn<void(QPainter&, FrameRequest, bool)> paint) Fn<void(QPainter&, FrameRequest, bool)> paint)
: _content(Ui::GL::CreateSurface( : _content(Ui::GL::CreateSurface(
nullptr, // No parent for the window in Qt parent-child sense.
[=](Ui::GL::Capabilities capabilities) { [=](Ui::GL::Capabilities capabilities) {
return chooseRenderer(capabilities); return chooseRenderer(capabilities);
})) }))

@ -1 +1 @@
Subproject commit cbb65009ffc443bc88137f2758228c1b185d8d20 Subproject commit 7bc9e1261498af07475f4bac0d8bcd8721202177