2021-06-02 16:36:24 +00:00
|
|
|
/*
|
|
|
|
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 "media/view/media_view_overlay_renderer.h"
|
2021-06-03 07:11:35 +00:00
|
|
|
#include "ui/gl/gl_image.h"
|
2021-06-02 16:36:24 +00:00
|
|
|
#include "ui/gl/gl_primitives.h"
|
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
#include <QOpenGLBuffer>
|
2021-06-03 07:11:35 +00:00
|
|
|
|
2021-06-02 16:36:24 +00:00
|
|
|
namespace Media::View {
|
|
|
|
|
2023-05-10 10:33:17 +00:00
|
|
|
class OverlayWidget::RendererGL final
|
|
|
|
: public OverlayWidget::Renderer
|
|
|
|
, public base::has_weak_ptr {
|
2021-06-02 16:36:24 +00:00
|
|
|
public:
|
2021-06-03 07:11:35 +00:00
|
|
|
explicit RendererGL(not_null<OverlayWidget*> owner);
|
2021-06-02 16:36:24 +00:00
|
|
|
|
|
|
|
void init(
|
|
|
|
not_null<QOpenGLWidget*> widget,
|
|
|
|
QOpenGLFunctions &f) override;
|
|
|
|
|
|
|
|
void deinit(
|
|
|
|
not_null<QOpenGLWidget*> widget,
|
2021-09-03 18:46:12 +00:00
|
|
|
QOpenGLFunctions *f) override;
|
2021-06-02 16:36:24 +00:00
|
|
|
|
|
|
|
void paint(
|
|
|
|
not_null<QOpenGLWidget*> widget,
|
|
|
|
QOpenGLFunctions &f) override;
|
|
|
|
|
2021-06-10 19:37:09 +00:00
|
|
|
std::optional<QColor> clearColor() override;
|
|
|
|
|
2021-06-02 16:36:24 +00:00
|
|
|
private:
|
2021-06-04 15:14:42 +00:00
|
|
|
struct Control {
|
|
|
|
int index = -1;
|
|
|
|
not_null<const style::icon*> icon;
|
|
|
|
};
|
2021-06-02 16:36:24 +00:00
|
|
|
bool handleHideWorkaround(QOpenGLFunctions &f);
|
|
|
|
|
2021-06-07 06:27:30 +00:00
|
|
|
void paintBackground() override;
|
2021-06-04 15:42:02 +00:00
|
|
|
void paintTransformedVideoFrame(ContentGeometry geometry) override;
|
2021-06-02 16:36:24 +00:00
|
|
|
void paintTransformedStaticContent(
|
|
|
|
const QImage &image,
|
2021-06-04 15:42:02 +00:00
|
|
|
ContentGeometry geometry,
|
2021-06-14 11:28:39 +00:00
|
|
|
bool semiTransparent,
|
2023-05-11 14:36:59 +00:00
|
|
|
bool fillTransparentBackground,
|
|
|
|
int index = 0) override;
|
2021-06-03 12:57:48 +00:00
|
|
|
void paintTransformedContent(
|
|
|
|
not_null<QOpenGLShaderProgram*> program,
|
2023-05-10 19:32:32 +00:00
|
|
|
ContentGeometry geometry,
|
|
|
|
bool fillTransparentBackground);
|
2021-06-02 16:36:24 +00:00
|
|
|
void paintRadialLoading(
|
|
|
|
QRect inner,
|
|
|
|
bool radial,
|
|
|
|
float64 radialOpacity) override;
|
|
|
|
void paintThemePreview(QRect outer) override;
|
|
|
|
void paintDocumentBubble(QRect outer, QRect icon) override;
|
|
|
|
void paintSaveMsg(QRect outer) override;
|
2021-06-04 15:14:42 +00:00
|
|
|
void paintControlsStart() override;
|
2021-06-02 16:36:24 +00:00
|
|
|
void paintControl(
|
2023-06-12 16:41:26 +00:00
|
|
|
Over control,
|
2023-02-28 13:49:18 +00:00
|
|
|
QRect over,
|
|
|
|
float64 overOpacity,
|
2021-06-02 16:36:24 +00:00
|
|
|
QRect inner,
|
|
|
|
float64 innerOpacity,
|
|
|
|
const style::icon &icon) override;
|
|
|
|
void paintFooter(QRect outer, float64 opacity) override;
|
|
|
|
void paintCaption(QRect outer, float64 opacity) override;
|
|
|
|
void paintGroupThumbs(QRect outer, float64 opacity) override;
|
2023-02-17 08:11:32 +00:00
|
|
|
void paintRoundedCorners(int radius) override;
|
2023-05-11 14:36:59 +00:00
|
|
|
void paintStoriesSiblingPart(
|
|
|
|
int index,
|
|
|
|
const QImage &image,
|
|
|
|
QRect rect,
|
|
|
|
float64 opacity = 1.) override;
|
2021-06-02 16:36:24 +00:00
|
|
|
|
2023-02-24 15:25:12 +00:00
|
|
|
//void invalidate();
|
2021-06-03 12:57:48 +00:00
|
|
|
|
2021-06-03 07:11:35 +00:00
|
|
|
void paintUsingRaster(
|
|
|
|
Ui::GL::Image &image,
|
|
|
|
QRect rect,
|
2021-06-02 16:36:24 +00:00
|
|
|
Fn<void(Painter&&)> method,
|
2021-06-03 07:11:35 +00:00
|
|
|
int bufferOffset,
|
|
|
|
bool transparent = false);
|
|
|
|
|
2023-02-24 15:25:12 +00:00
|
|
|
void validateControlsFade();
|
2021-06-04 15:14:42 +00:00
|
|
|
void validateControls();
|
|
|
|
void invalidateControls();
|
2021-06-03 07:11:35 +00:00
|
|
|
void toggleBlending(bool enabled);
|
|
|
|
|
|
|
|
[[nodiscard]] Ui::GL::Rect transformRect(const QRect &raster) const;
|
2021-06-04 15:42:02 +00:00
|
|
|
[[nodiscard]] Ui::GL::Rect transformRect(const QRectF &raster) const;
|
2021-06-03 07:11:35 +00:00
|
|
|
[[nodiscard]] Ui::GL::Rect transformRect(
|
|
|
|
const Ui::GL::Rect &raster) const;
|
2023-07-25 13:59:53 +00:00
|
|
|
[[nodiscard]] Ui::GL::Rect scaleRect(
|
|
|
|
const Ui::GL::Rect &unscaled,
|
|
|
|
float64 scale) const;
|
2021-06-03 07:11:35 +00:00
|
|
|
|
|
|
|
void uploadTexture(
|
|
|
|
GLint internalformat,
|
|
|
|
GLint format,
|
|
|
|
QSize size,
|
|
|
|
QSize hasSize,
|
|
|
|
int stride,
|
|
|
|
const void *data) const;
|
2021-06-02 16:36:24 +00:00
|
|
|
|
|
|
|
const not_null<OverlayWidget*> _owner;
|
|
|
|
|
|
|
|
QOpenGLFunctions *_f = nullptr;
|
|
|
|
QSize _viewport;
|
|
|
|
float _factor = 1.;
|
2023-08-17 12:22:04 +00:00
|
|
|
int _ifactor = 1;
|
2021-06-04 15:14:42 +00:00
|
|
|
QVector2D _uniformViewport;
|
2021-06-02 16:36:24 +00:00
|
|
|
|
2021-06-03 07:11:35 +00:00
|
|
|
std::optional<QOpenGLBuffer> _contentBuffer;
|
|
|
|
std::optional<QOpenGLShaderProgram> _imageProgram;
|
2023-02-24 15:25:12 +00:00
|
|
|
std::optional<QOpenGLShaderProgram> _staticContentProgram;
|
2021-06-03 12:57:48 +00:00
|
|
|
QOpenGLShader *_texturedVertexShader = nullptr;
|
|
|
|
std::optional<QOpenGLShaderProgram> _withTransparencyProgram;
|
|
|
|
std::optional<QOpenGLShaderProgram> _yuv420Program;
|
2022-03-22 15:50:23 +00:00
|
|
|
std::optional<QOpenGLShaderProgram> _nv12Program;
|
2021-06-04 15:14:42 +00:00
|
|
|
std::optional<QOpenGLShaderProgram> _fillProgram;
|
|
|
|
std::optional<QOpenGLShaderProgram> _controlsProgram;
|
2023-02-17 08:11:32 +00:00
|
|
|
std::optional<QOpenGLShaderProgram> _roundedCornersProgram;
|
2023-05-11 14:36:59 +00:00
|
|
|
Ui::GL::Textures<6> _textures; // image, sibling, right sibling, y, u, v
|
2023-05-30 13:57:11 +00:00
|
|
|
QSize _rgbaSize[3];
|
2021-06-03 12:57:48 +00:00
|
|
|
QSize _lumaSize;
|
|
|
|
QSize _chromaSize;
|
2023-05-11 14:36:59 +00:00
|
|
|
qint64 _cacheKeys[3] = { 0 }; // image, sibling, right sibling
|
2021-06-03 12:57:48 +00:00
|
|
|
int _trackFrameIndex = 0;
|
|
|
|
int _streamedIndex = 0;
|
2022-03-30 13:07:35 +00:00
|
|
|
bool _chromaNV12 = false;
|
2021-06-03 07:11:35 +00:00
|
|
|
|
2023-02-24 15:25:12 +00:00
|
|
|
Ui::GL::Image _controlsFadeImage;
|
2021-06-03 07:11:35 +00:00
|
|
|
Ui::GL::Image _radialImage;
|
|
|
|
Ui::GL::Image _documentBubbleImage;
|
|
|
|
Ui::GL::Image _themePreviewImage;
|
|
|
|
Ui::GL::Image _saveMsgImage;
|
|
|
|
Ui::GL::Image _footerImage;
|
|
|
|
Ui::GL::Image _captionImage;
|
|
|
|
Ui::GL::Image _groupThumbsImage;
|
2021-06-04 15:14:42 +00:00
|
|
|
Ui::GL::Image _controlsImage;
|
|
|
|
|
2023-05-11 14:36:59 +00:00
|
|
|
static constexpr auto kStoriesSiblingPartsCount = 4;
|
|
|
|
Ui::GL::Image _storiesSiblingParts[kStoriesSiblingPartsCount];
|
|
|
|
|
2023-06-12 16:41:26 +00:00
|
|
|
static constexpr auto kControlsCount = 6;
|
2023-08-02 19:41:58 +00:00
|
|
|
[[nodiscard]] Control controlMeta(Over control) const;
|
2023-02-28 13:49:18 +00:00
|
|
|
|
|
|
|
// Last one is for the over circle image.
|
|
|
|
std::array<QRect, kControlsCount + 1> _controlsTextures;
|
2021-06-04 15:14:42 +00:00
|
|
|
|
2023-05-12 09:41:25 +00:00
|
|
|
bool _shadowTopFlip = false;
|
|
|
|
bool _shadowsForStories = false;
|
2021-06-03 07:11:35 +00:00
|
|
|
bool _blendingEnabled = false;
|
|
|
|
|
2023-08-02 19:41:58 +00:00
|
|
|
rpl::lifetime _storiesLifetime;
|
2021-06-03 07:11:35 +00:00
|
|
|
rpl::lifetime _lifetime;
|
2021-06-02 16:36:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Media::View
|