calls_group_viewport_opengl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "calls/group/calls_group_viewport.h"
  9. #include "ui/round_rect.h"
  10. #include "ui/effects/animations.h"
  11. #include "ui/effects/cross_line.h"
  12. #include "ui/gl/gl_primitives.h"
  13. #include "ui/gl/gl_surface.h"
  14. #include "ui/gl/gl_image.h"
  15. #include <QOpenGLBuffer>
  16. #include <QOpenGLShaderProgram>
  17. namespace Webrtc {
  18. struct FrameWithInfo;
  19. } // namespace Webrtc
  20. namespace Calls::Group {
  21. class Viewport::RendererGL final : public Ui::GL::Renderer {
  22. public:
  23. explicit RendererGL(not_null<Viewport*> owner);
  24. void init(
  25. not_null<QOpenGLWidget*> widget,
  26. QOpenGLFunctions &f) override;
  27. void deinit(
  28. not_null<QOpenGLWidget*> widget,
  29. QOpenGLFunctions *f) override;
  30. void paint(
  31. not_null<QOpenGLWidget*> widget,
  32. QOpenGLFunctions &f) override;
  33. std::optional<QColor> clearColor() override;
  34. private:
  35. struct TileData {
  36. quintptr id = 0;
  37. not_null<PeerData*> peer;
  38. Ui::GL::Textures<5> textures;
  39. Ui::GL::Framebuffers<2> framebuffers;
  40. Ui::Animations::Simple outlined;
  41. Ui::Animations::Simple paused;
  42. QImage userpicFrame;
  43. QRect nameRect;
  44. int nameVersion = 0;
  45. mutable int trackIndex = -1;
  46. mutable QSize rgbaSize;
  47. mutable QSize textureSize;
  48. mutable QSize textureChromaSize;
  49. mutable QSize textureBlurSize;
  50. bool stale = false;
  51. bool pause = false;
  52. bool outline = false;
  53. };
  54. struct Program {
  55. std::optional<QOpenGLShaderProgram> argb32;
  56. std::optional<QOpenGLShaderProgram> yuv420;
  57. };
  58. void setDefaultViewport(QOpenGLFunctions &f);
  59. void paintTile(
  60. QOpenGLFunctions &f,
  61. GLuint defaultFramebufferObject,
  62. not_null<VideoTile*> tile,
  63. TileData &nameData);
  64. [[nodiscard]] Ui::GL::Rect transformRect(const QRect &raster) const;
  65. [[nodiscard]] Ui::GL::Rect transformRect(
  66. const Ui::GL::Rect &raster) const;
  67. void ensureARGB32Program();
  68. void ensureButtonsImage();
  69. void prepareObjects(
  70. QOpenGLFunctions &f,
  71. TileData &tileData,
  72. QSize blurSize);
  73. void bindFrame(
  74. QOpenGLFunctions &f,
  75. const Webrtc::FrameWithInfo &data,
  76. TileData &tileData,
  77. Program &program);
  78. void drawDownscalePass(
  79. QOpenGLFunctions &f,
  80. TileData &tileData);
  81. void drawFirstBlurPass(
  82. QOpenGLFunctions &f,
  83. TileData &tileData,
  84. QSize blurSize);
  85. void validateDatas();
  86. void validateNoiseTexture(
  87. QOpenGLFunctions &f,
  88. GLuint defaultFramebufferObject);
  89. void validateOutlineAnimation(
  90. not_null<VideoTile*> tile,
  91. TileData &data);
  92. void validatePausedAnimation(
  93. not_null<VideoTile*> tile,
  94. TileData &data);
  95. void validateUserpicFrame(
  96. not_null<VideoTile*> tile,
  97. TileData &tileData);
  98. void uploadTexture(
  99. QOpenGLFunctions &f,
  100. GLint internalformat,
  101. GLint format,
  102. QSize size,
  103. QSize hasSize,
  104. int stride,
  105. const void *data) const;
  106. [[nodiscard]] bool isExpanded(
  107. not_null<VideoTile*> tile,
  108. QSize unscaled,
  109. QSize tileSize) const;
  110. [[nodiscard]] float64 countExpandRatio(
  111. not_null<VideoTile*> tile,
  112. QSize unscaled,
  113. const TileAnimation &animation) const;
  114. const not_null<Viewport*> _owner;
  115. GLfloat _factor = 1.;
  116. int _ifactor = 1;
  117. QSize _viewport;
  118. bool _rgbaFrame = false;
  119. bool _userpicFrame;
  120. std::optional<QOpenGLBuffer> _frameBuffer;
  121. Program _downscaleProgram;
  122. std::optional<QOpenGLShaderProgram> _blurProgram;
  123. Program _frameProgram;
  124. std::optional<QOpenGLShaderProgram> _imageProgram;
  125. Ui::GL::Textures<1> _noiseTexture;
  126. Ui::GL::Framebuffers<1> _noiseFramebuffer;
  127. QOpenGLShader *_downscaleVertexShader = nullptr;
  128. QOpenGLShader *_frameVertexShader = nullptr;
  129. Ui::GL::Image _buttons;
  130. QRect _pinOn;
  131. QRect _pinOff;
  132. QRect _back;
  133. QRect _muteOn;
  134. QRect _muteOff;
  135. QRect _paused;
  136. Ui::GL::Image _names;
  137. QRect _pausedTextRect;
  138. std::vector<TileData> _tileData;
  139. std::vector<int> _tileDataIndices;
  140. Ui::CrossLineAnimation _pinIcon;
  141. Ui::CrossLineAnimation _muteIcon;
  142. Ui::RoundRect _pinBackground;
  143. rpl::lifetime _lifetime;
  144. };
  145. } // namespace Calls::Group