ZaStoGram_desktop/Telegram/SourceFiles/calls/group/calls_group_viewport.h
loop-uh 0e40e4b8a9 Merge upstream tdesktop a8de5f928b (v7.3.4 + 51: Update brotli to 1.2.1)
Ручное слияние для Windows-клиента: оригинал в dev не попадал с v7.3.1, так как
синхронизация v7.3.2-v7.3.4 встала на конфликте lib_ui. Таймер upstream-sync на
время слияния остановлен.

- lib_ui: форк 7e5d8bc (слияние с оригиналом 1ff7be7).
- Версия 7.3.4 без бета-признака: BetaChannel 0, AppBetaVersion false.
- mtproto: «плохая конфигурация прокси» теперь учитывает прокси (колбэк рантайма,
  делегат сессии, соединение); правки session_private перенесены в
  mtproto/session/private/* (лимиты длины, пустые RPC-ответы, DEBUG_LOG дампов).
- update_checker: ограничение размера ответа и отключение HTTP/2 оригинала поверх
  гонки зеркал форка.
- thanos_effect_renderer: версия оригинала (R32F вместо RGBA32F); проверка
  возможностей — по compute.
- download_manager_mtproto: проверка слишком большой части оригинала.
- prepare.py: патчи qtsvg и Windows 7 оригинала вместе с patches_extra форка.
- Файлы .agents/.claude/.github, удалённые форком, остаются удалёнными.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 16:07:40 -05:00

272 lines
7.2 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
*/
#pragma once
#include "ui/rp_widget.h"
#include "ui/effects/animations.h"
class Painter;
class QOpenGLFunctions;
class QRhi;
class QRhiRenderTarget;
class QRhiCommandBuffer;
class QRhiResourceUpdateBatch;
class QRhiGraphicsPipeline;
class QRhiShaderResourceBindings;
class QRhiBuffer;
namespace Ui {
class AbstractButton;
class RpWidgetWrap;
} // namespace Ui
namespace Ui::Rhi {
class Renderer;
} // namespace Ui::Rhi
namespace Ui::GL {
enum class Backend;
struct Capabilities;
struct ChosenRenderer;
class Renderer;
} // namespace Ui::GL
namespace Calls {
class GroupCall;
struct VideoEndpoint;
struct VideoQualityRequest;
} // namespace Calls
namespace Webrtc {
class VideoTrack;
} // namespace Webrtc
namespace Calls::Group {
class MembersRow;
enum class PanelMode;
enum class VideoQuality;
// A draw recorded by the borrowed RHI renderer for replaying inside an
// external (media viewer) render pass.
struct BorrowedRhiDraw {
QRhiGraphicsPipeline *pipeline = nullptr;
QRhiShaderResourceBindings *srb = nullptr;
QRhiBuffer *vertexBuffer = nullptr;
int vertexOffset = 0;
};
struct VideoTileTrack {
Webrtc::VideoTrack *track = nullptr;
MembersRow *row = nullptr;
rpl::variable<QSize> trackSize;
[[nodiscard]] explicit operator bool() const {
return track != nullptr;
}
};
[[nodiscard]] inline bool operator==(
VideoTileTrack a,
VideoTileTrack b) noexcept {
return (a.track == b.track) && (a.row == b.row);
}
[[nodiscard]] inline bool operator!=(
VideoTileTrack a,
VideoTileTrack b) noexcept {
return !(a == b);
}
class Viewport final {
public:
Viewport(
not_null<QWidget*> parent,
PanelMode mode,
Ui::GL::Backend backend,
Ui::RpWidgetWrap *borrowedRp = nullptr,
bool borrowedOpenGL = false);
~Viewport();
[[nodiscard]] not_null<QWidget*> widget() const;
[[nodiscard]] not_null<Ui::RpWidgetWrap*> rp() const;
void setMode(PanelMode mode, not_null<QWidget*> parent);
void setControlsShown(float64 shown);
void setCursorShown(bool shown);
void setGeometry(bool fullscreen, QRect geometry);
void resizeToWidth(int newWidth);
void setScrollTop(int scrollTop);
void add(
const VideoEndpoint &endpoint,
VideoTileTrack track,
rpl::producer<QSize> trackSize,
rpl::producer<bool> pinned,
bool self,
bool shown);
void remove(const VideoEndpoint &endpoint);
void removeByRow(not_null<MembersRow*> row);
void showLarge(const VideoEndpoint &endpoint);
[[nodiscard]] bool requireARGB32() const;
[[nodiscard]] int fullHeight() const;
[[nodiscard]] rpl::producer<int> fullHeightValue() const;
[[nodiscard]] rpl::producer<bool> pinToggled() const;
[[nodiscard]] rpl::producer<VideoEndpoint> clicks() const;
[[nodiscard]] rpl::producer<VideoQualityRequest> qualityRequests() const;
[[nodiscard]] rpl::producer<bool> mouseInsideValue() const;
void ensureBorrowedRenderer(QOpenGLFunctions &f);
void ensureBorrowedCleared(QOpenGLFunctions *f);
void borrowedPaint(QOpenGLFunctions &f);
void ensureBorrowedRenderer();
void ensureBorrowedCleared();
void borrowedPaint(Painter &p, const QRegion &clip);
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) && !defined DESKTOP_APP_DISABLE_PRIVATE_QT_API
// Borrowed rendering happens inside an external (media viewer) render
// pass, so it is split in phases: offscreen passes and resource
// updates must be finished BEFORE the external beginPass, while the
// recorded draws are replayed by the external pass itself.
void borrowedPaintOffscreen(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuffer *cb);
[[nodiscard]] QRhiResourceUpdateBatch *borrowedPrepareOnscreen(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuffer *cb);
[[nodiscard]] std::vector<BorrowedRhiDraw> borrowedTakeOnscreenDraws();
private:
[[nodiscard]] Ui::Rhi::Renderer *ensureBorrowedRhi(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuffer *cb);
public:
#endif
[[nodiscard]] QPoint borrowedOrigin() const;
[[nodiscard]] rpl::lifetime &lifetime();
static constexpr auto kShadowMaxAlpha = 80;
private:
struct Textures;
class VideoTile;
class RendererSW;
class RendererGL;
class RendererRhi;
using TileId = quintptr;
struct Geometry {
VideoTile *tile = nullptr;
QSize size;
QRect rows;
QRect columns;
};
struct Layout {
std::vector<Geometry> list;
QSize outer;
bool useColumns = false;
};
struct TileAnimation {
QSize from;
QSize to;
float64 ratio = -1.;
};
struct Selection {
enum class Element {
None,
Tile,
PinButton,
BackButton,
};
VideoTile *tile = nullptr;
Element element = Element::None;
inline bool operator==(Selection other) const {
return (tile == other.tile) && (element == other.element);
}
};
void setup();
[[nodiscard]] bool wide() const;
[[nodiscard]] bool videoStream() const;
void updateCursor();
void updateTilesGeometry();
void updateTilesGeometry(int outerWidth);
void updateTilesGeometryWide(int outerWidth, int outerHeight);
void updateTilesGeometryNarrow(int outerWidth);
void updateTilesGeometryColumn(int outerWidth);
void setTileGeometry(not_null<VideoTile*> tile, QRect geometry);
void refreshHasTwoOrMore();
void updateTopControlsVisibility();
void prepareLargeChangeAnimation();
void startLargeChangeAnimation();
void updateTilesAnimated();
[[nodiscard]] Layout countWide(int outerWidth, int outerHeight) const;
[[nodiscard]] Layout applyLarge(Layout layout) const;
void setSelected(Selection value);
void setPressed(Selection value);
void handleMousePress(QPoint position, Qt::MouseButton button);
void handleMouseRelease(QPoint position, Qt::MouseButton button);
void handleMouseMove(QPoint position);
void updateSelected(QPoint position);
void updateSelected();
[[nodiscard]] Ui::GL::ChosenRenderer chooseRenderer(
Ui::GL::Backend backend);
[[nodiscard]] std::unique_ptr<Ui::GL::Renderer> makeRenderer();
void updateMyWidgetPart();
PanelMode _mode = PanelMode();
bool _opengl = false;
bool _qrhi = false;
std::unique_ptr<Ui::RpWidgetWrap> _content;
std::vector<std::unique_ptr<VideoTile>> _tiles;
std::vector<not_null<VideoTile*>> _tilesForOrder;
rpl::variable<int> _fullHeight = 0;
bool _hasTwoOrMore = false;
bool _fullscreen = false;
bool _cursorHidden = false;
int _scrollTop = 0;
QImage _shadow;
rpl::event_stream<VideoEndpoint> _clicks;
rpl::event_stream<bool> _pinToggles;
rpl::event_stream<VideoQualityRequest> _qualityRequests;
float64 _controlsShownRatio = 1.;
VideoTile *_large = nullptr;
Fn<void()> _updateLargeScheduled;
Ui::Animations::Simple _largeChangeAnimation;
Layout _startTilesLayout;
Layout _finishTilesLayout;
Selection _selected;
Selection _pressed;
rpl::variable<bool> _mouseInside = false;
Ui::RpWidgetWrap * const _borrowed = nullptr;
QRect _borrowedGeometry;
std::unique_ptr<Ui::GL::Renderer> _borrowedRenderer;
QRhi *_borrowedRhi = nullptr;
QMetaObject::Connection _borrowedConnection;
rpl::lifetime _lifetime;
};
[[nodiscard]] QImage GenerateShadow(
int height,
int topAlpha,
int bottomAlpha,
QColor color = QColor(0, 0, 0));
[[nodiscard]] rpl::producer<QString> MuteButtonTooltip(
not_null<GroupCall*> call);
} // namespace Calls::Group