media_view_pip_opengl.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "media/view/media_view_pip_renderer.h"
  9. #include "ui/gl/gl_image.h"
  10. #include "ui/gl/gl_primitives.h"
  11. #include <QOpenGLBuffer>
  12. namespace Media::View {
  13. class Pip::RendererGL final : public Pip::Renderer {
  14. public:
  15. explicit RendererGL(not_null<Pip*> owner);
  16. void init(
  17. not_null<QOpenGLWidget*> widget,
  18. QOpenGLFunctions &f) override;
  19. void deinit(
  20. not_null<QOpenGLWidget*> widget,
  21. QOpenGLFunctions *f) override;
  22. void paint(
  23. not_null<QOpenGLWidget*> widget,
  24. QOpenGLFunctions &f) override;
  25. std::optional<QColor> clearColor() override;
  26. private:
  27. struct Control {
  28. int index = -1;
  29. not_null<const style::icon*> icon;
  30. not_null<const style::icon*> iconOver;
  31. };
  32. void createShadowTexture();
  33. void paintTransformedVideoFrame(ContentGeometry geometry) override;
  34. void paintTransformedStaticContent(
  35. const QImage &image,
  36. ContentGeometry geometry) override;
  37. void paintTransformedContent(
  38. not_null<QOpenGLShaderProgram*> program,
  39. ContentGeometry geometry);
  40. void paintRadialLoading(
  41. QRect inner,
  42. float64 controlsShown) override;
  43. void paintButtonsStart() override;
  44. void paintButton(
  45. const Button &button,
  46. int outerWidth,
  47. float64 shown,
  48. float64 over,
  49. const style::icon &icon,
  50. const style::icon &iconOver) override;
  51. void paintPlayback(QRect outer, float64 shown) override;
  52. void paintVolumeController(QRect outer, float64 shown) override;
  53. void paintUsingRaster(
  54. Ui::GL::Image &image,
  55. QRect rect,
  56. Fn<void(QPainter&&)> method,
  57. int bufferOffset,
  58. bool transparent = false);
  59. void validateControls();
  60. void invalidateControls();
  61. void toggleBlending(bool enabled);
  62. [[nodiscard]] QRect RoundingRect(ContentGeometry geometry);
  63. [[nodiscard]] Ui::GL::Rect transformRect(const QRect &raster) const;
  64. [[nodiscard]] Ui::GL::Rect transformRect(const QRectF &raster) const;
  65. [[nodiscard]] Ui::GL::Rect transformRect(
  66. const Ui::GL::Rect &raster) const;
  67. void uploadTexture(
  68. GLint internalformat,
  69. GLint format,
  70. QSize size,
  71. QSize hasSize,
  72. int stride,
  73. const void *data) const;
  74. const not_null<Pip*> _owner;
  75. QOpenGLFunctions *_f = nullptr;
  76. QSize _viewport;
  77. float _factor = 1.;
  78. int _ifactor = 1;
  79. QVector2D _uniformViewport;
  80. std::optional<QOpenGLBuffer> _contentBuffer;
  81. std::optional<QOpenGLShaderProgram> _imageProgram;
  82. std::optional<QOpenGLShaderProgram> _controlsProgram;
  83. QOpenGLShader *_texturedVertexShader = nullptr;
  84. std::optional<QOpenGLShaderProgram> _argb32Program;
  85. std::optional<QOpenGLShaderProgram> _yuv420Program;
  86. std::optional<QOpenGLShaderProgram> _nv12Program;
  87. Ui::GL::Textures<4> _textures;
  88. QSize _rgbaSize;
  89. QSize _lumaSize;
  90. QSize _chromaSize;
  91. quint64 _cacheKey = 0;
  92. int _trackFrameIndex = 0;
  93. bool _chromaNV12 = false;
  94. Ui::GL::Image _radialImage;
  95. Ui::GL::Image _controlsImage;
  96. Ui::GL::Image _playbackImage;
  97. Ui::GL::Image _volumeControllerImage;
  98. Ui::GL::Image _shadowImage;
  99. static constexpr auto kControlsCount = 7;
  100. [[nodiscard]] static Control ControlMeta(
  101. OverState control,
  102. int index = 0);
  103. std::array<QRect, kControlsCount * 2> _controlsTextures;
  104. bool _blendingEnabled = false;
  105. rpl::lifetime _lifetime;
  106. };
  107. } // namespace Media::View