2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-25 11:47:29 +00:00
tdesktop/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.h

169 lines
4.0 KiB
C
Raw Normal View History

/*
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 "calls/group/calls_group_viewport.h"
2021-05-25 12:08:06 +04:00
#include "ui/round_rect.h"
#include "ui/effects/animations.h"
2021-05-25 12:08:06 +04:00
#include "ui/effects/cross_line.h"
2021-06-02 20:36:24 +04:00
#include "ui/gl/gl_primitives.h"
#include "ui/gl/gl_surface.h"
2021-05-25 12:08:06 +04:00
#include "ui/gl/gl_image.h"
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
namespace Webrtc {
struct FrameWithInfo;
} // namespace Webrtc
namespace Calls::Group {
class Viewport::RendererGL final : public Ui::GL::Renderer {
public:
explicit RendererGL(not_null<Viewport*> owner);
void init(
not_null<QOpenGLWidget*> widget,
2021-05-25 12:08:06 +04:00
QOpenGLFunctions &f) override;
void deinit(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions *f) override;
void paint(
not_null<QOpenGLWidget*> widget,
2021-05-25 12:08:06 +04:00
QOpenGLFunctions &f) override;
std::optional<QColor> clearColor() override;
private:
struct TileData {
quintptr id = 0;
2021-05-29 23:22:16 +04:00
not_null<PeerData*> peer;
Ui::GL::Textures<5> textures;
Ui::GL::Framebuffers<2> framebuffers;
Ui::Animations::Simple outlined;
Ui::Animations::Simple paused;
QImage userpicFrame;
QRect nameRect;
2021-05-25 16:10:19 +04:00
int nameVersion = 0;
2021-05-29 23:22:16 +04:00
mutable int trackIndex = -1;
mutable QSize rgbaSize;
mutable QSize textureSize;
mutable QSize textureChromaSize;
mutable QSize textureBlurSize;
2021-05-25 16:10:19 +04:00
bool stale = false;
bool pause = false;
bool outline = false;
2021-05-25 16:10:19 +04:00
};
struct Program {
std::optional<QOpenGLShaderProgram> argb32;
std::optional<QOpenGLShaderProgram> yuv420;
};
void setDefaultViewport(QOpenGLFunctions &f);
void paintTile(
2021-05-25 12:08:06 +04:00
QOpenGLFunctions &f,
GLuint defaultFramebufferObject,
2021-05-25 16:10:19 +04:00
not_null<VideoTile*> tile,
TileData &nameData);
2021-05-25 14:56:26 +04:00
[[nodiscard]] Ui::GL::Rect transformRect(const QRect &raster) const;
[[nodiscard]] Ui::GL::Rect transformRect(
const Ui::GL::Rect &raster) const;
2021-05-25 12:08:06 +04:00
void ensureARGB32Program();
2021-05-25 14:56:26 +04:00
void ensureButtonsImage();
void prepareObjects(
QOpenGLFunctions &f,
TileData &tileData,
QSize blurSize);
void bindFrame(
QOpenGLFunctions &f,
const Webrtc::FrameWithInfo &data,
TileData &tileData,
Program &program);
void drawDownscalePass(
QOpenGLFunctions &f,
TileData &tileData);
void drawFirstBlurPass(
QOpenGLFunctions &f,
TileData &tileData,
QSize blurSize);
void validateDatas();
void validateNoiseTexture(
QOpenGLFunctions &f,
GLuint defaultFramebufferObject);
void validateOutlineAnimation(
not_null<VideoTile*> tile,
TileData &data);
void validatePausedAnimation(
not_null<VideoTile*> tile,
TileData &data);
void validateUserpicFrame(
not_null<VideoTile*> tile,
TileData &tileData);
void uploadTexture(
QOpenGLFunctions &f,
GLint internalformat,
GLint format,
QSize size,
QSize hasSize,
int stride,
const void *data) const;
2021-05-31 21:25:15 +04:00
[[nodiscard]] bool isExpanded(
not_null<VideoTile*> tile,
QSize unscaled,
QSize tileSize) const;
[[nodiscard]] float64 countExpandRatio(
not_null<VideoTile*> tile,
QSize unscaled,
const TileAnimation &animation) const;
const not_null<Viewport*> _owner;
2021-05-24 19:38:52 +04:00
GLfloat _factor = 1.;
QSize _viewport;
bool _rgbaFrame = false;
bool _userpicFrame;
std::optional<QOpenGLBuffer> _frameBuffer;
Program _downscaleProgram;
std::optional<QOpenGLShaderProgram> _blurProgram;
Program _frameProgram;
2021-05-25 12:08:06 +04:00
std::optional<QOpenGLShaderProgram> _imageProgram;
Ui::GL::Textures<1> _noiseTexture;
Ui::GL::Framebuffers<1> _noiseFramebuffer;
QOpenGLShader *_downscaleVertexShader = nullptr;
QOpenGLShader *_frameVertexShader = nullptr;
2021-05-25 14:56:26 +04:00
Ui::GL::Image _buttons;
2021-05-25 12:08:06 +04:00
QRect _pinOn;
QRect _pinOff;
2021-05-30 21:08:54 +04:00
QRect _back;
2021-05-25 14:56:26 +04:00
QRect _muteOn;
QRect _muteOff;
2021-06-08 14:50:41 +04:00
QRect _paused;
2021-05-25 12:08:06 +04:00
2021-05-25 16:10:19 +04:00
Ui::GL::Image _names;
QRect _pausedTextRect;
std::vector<TileData> _tileData;
std::vector<int> _tileDataIndices;
2021-05-25 16:10:19 +04:00
2021-05-25 12:08:06 +04:00
Ui::CrossLineAnimation _pinIcon;
2021-05-25 14:56:26 +04:00
Ui::CrossLineAnimation _muteIcon;
2021-05-25 12:08:06 +04:00
Ui::RoundRect _pinBackground;
rpl::lifetime _lifetime;
};
} // namespace Calls::Group