Optimize background painting in OpenGL renderers.

This commit is contained in:
John Preston 2021-06-10 23:37:09 +04:00
parent f9f98975a1
commit 2f986660ff
9 changed files with 57 additions and 135 deletions

View File

@ -319,6 +319,8 @@ PRIVATE
calls/calls_userpic.h
calls/calls_video_bubble.cpp
calls/calls_video_bubble.h
calls/calls_video_incoming.cpp
calls/calls_video_incoming.h
chat_helpers/bot_keyboard.cpp
chat_helpers/bot_keyboard.h
chat_helpers/emoji_keywords.cpp

View File

@ -53,12 +53,6 @@ public:
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
void resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) override;
void paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
@ -183,24 +177,6 @@ void Panel::Incoming::RendererGL::deinit(
_contentBuffer = std::nullopt;
}
void Panel::Incoming::RendererGL::resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) {
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsShadowImage.invalidate();
}
_viewport = QSize{ w, h };
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
const auto size = _viewport * _factor;
f.glViewport(0, 0, size.width(), size.height());
}
void Panel::Incoming::RendererGL::paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
@ -211,6 +187,17 @@ void Panel::Incoming::RendererGL::paint(
if (data.format == Webrtc::FrameFormat::None) {
return;
}
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsShadowImage.invalidate();
}
_viewport = widget->size();
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
const auto rgbaFrame = (data.format == Webrtc::FrameFormat::ARGB32);
const auto upload = (_trackFrameIndex != data.index);
_trackFrameIndex = data.index;

View File

@ -374,8 +374,6 @@ void Viewport::RendererGL::init(
}));
validateNoiseTexture(f, 0);
_background.init(f);
}
void Viewport::RendererGL::ensureARGB32Program() {
@ -403,8 +401,6 @@ void Viewport::RendererGL::ensureARGB32Program() {
void Viewport::RendererGL::deinit(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
_background.deinit(f);
_frameBuffer = std::nullopt;
_frameVertexShader = nullptr;
_imageProgram = std::nullopt;
@ -423,16 +419,6 @@ void Viewport::RendererGL::deinit(
_buttons.destroy(f);
}
void Viewport::RendererGL::resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) {
_factor = widget->devicePixelRatio();
_viewport = QSize(w, h);
setDefaultViewport(f);
}
void Viewport::RendererGL::setDefaultViewport(QOpenGLFunctions &f) {
const auto size = _viewport * _factor;
f.glViewport(0, 0, size.width(), size.height());
@ -442,10 +428,11 @@ void Viewport::RendererGL::paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
_factor = widget->devicePixelRatio();
_viewport = widget->size();
const auto defaultFramebufferObject = widget->defaultFramebufferObject();
validateDatas();
fillBackground(f);
auto index = 0;
for (const auto &tile : _owner->_tiles) {
if (!tile->shown()) {
@ -460,16 +447,8 @@ void Viewport::RendererGL::paint(
}
}
void Viewport::RendererGL::fillBackground(QOpenGLFunctions &f) {
const auto radius = st::roundRadiusLarge;
const auto radiuses = QMargins{ radius, radius, radius, radius };
auto region = QRegion(QRect(QPoint(), _viewport));
for (const auto &tile : _owner->_tiles) {
if (tile->shown()) {
region -= tile->geometry().marginsRemoved(radiuses);
}
}
_background.fill(f, region, _viewport, _factor, st::groupCallBg);
std::optional<QColor> Viewport::RendererGL::clearColor() {
return st::groupCallBg->c;
}
void Viewport::RendererGL::validateUserpicFrame(

View File

@ -36,16 +36,12 @@ public:
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
void resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) override;
void paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
std::optional<QColor> clearColor() override;
private:
struct TileData {
quintptr id = 0;
@ -72,7 +68,6 @@ private:
};
void setDefaultViewport(QOpenGLFunctions &f);
void fillBackground(QOpenGLFunctions &f);
void paintTile(
QOpenGLFunctions &f,
GLuint defaultFramebufferObject,
@ -138,7 +133,6 @@ private:
QSize _viewport;
bool _rgbaFrame = false;
bool _userpicFrame;
Ui::GL::BackgroundFiller _background;
std::optional<QOpenGLBuffer> _frameBuffer;
Program _downscaleProgram;
std::optional<QOpenGLShaderProgram> _blurProgram;

View File

@ -119,14 +119,11 @@ void OverlayWidget::RendererGL::init(
FragmentSampleARGB32Texture(),
FragmentGlobalOpacity(),
}));
_background.init(f);
}
void OverlayWidget::RendererGL::deinit(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
_background.deinit(f);
_textures.destroy(f);
_imageProgram = std::nullopt;
_texturedVertexShader = nullptr;
@ -137,61 +134,43 @@ void OverlayWidget::RendererGL::deinit(
_contentBuffer = std::nullopt;
}
void OverlayWidget::RendererGL::resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) {
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsImage.invalidate();
}
_viewport = QSize{ w, h };
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
setDefaultViewport(f);
}
void OverlayWidget::RendererGL::setDefaultViewport(QOpenGLFunctions &f) {
f.glViewport(0, 0, _uniformViewport.x(), _uniformViewport.y());
}
void OverlayWidget::RendererGL::paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
if (handleHideWorkaround(f)) {
return;
}
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsImage.invalidate();
}
_viewport = widget->size();
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
_f = &f;
_owner->paint(this);
_f = nullptr;
}
bool OverlayWidget::RendererGL::handleHideWorkaround(QOpenGLFunctions &f) {
if (!Platform::IsWindows() || !_owner->_hideWorkaround) {
return false;
std::optional<QColor> OverlayWidget::RendererGL::clearColor() {
if (Platform::IsWindows() && _owner->_hideWorkaround) {
return QColor(0, 0, 0, 0);
} else if (_owner->_fullScreenVideo) {
return st::mediaviewVideoBg->c;
} else {
return st::mediaviewBg->c;
}
}
bool OverlayWidget::RendererGL::handleHideWorkaround(QOpenGLFunctions &f) {
// This is needed on Windows,
// because on reopen it blinks with the last shown content.
f.glClearColor(0., 0., 0., 0.);
f.glClear(GL_COLOR_BUFFER_BIT);
return true;
return Platform::IsWindows() && _owner->_hideWorkaround;
}
void OverlayWidget::RendererGL::paintBackground() {
const auto &bg = _owner->_fullScreenVideo
? st::mediaviewVideoBg
: st::mediaviewBg;
auto fill = QRegion(QRect(QPoint(), _viewport));
toggleBlending(false);
_background.fill(
*_f,
fill,
_viewport,
_factor,
bg);
_contentBuffer->bind();
}

View File

@ -27,23 +27,18 @@ public:
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
void resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) override;
void paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
std::optional<QColor> clearColor() override;
private:
struct Control {
int index = -1;
not_null<const style::icon*> icon;
};
bool handleHideWorkaround(QOpenGLFunctions &f);
void setDefaultViewport(QOpenGLFunctions &f);
void paintBackground() override;
void paintTransformedVideoFrame(ContentGeometry geometry) override;
@ -102,7 +97,6 @@ private:
const not_null<OverlayWidget*> _owner;
QOpenGLFunctions *_f = nullptr;
Ui::GL::BackgroundFiller _background;
QSize _viewport;
float _factor = 1.;
QVector2D _uniformViewport;

View File

@ -235,27 +235,6 @@ void Pip::RendererGL::deinit(
_contentBuffer = std::nullopt;
}
void Pip::RendererGL::resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h) {
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsImage.invalidate();
}
_viewport = QSize{ w, h };
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
setDefaultViewport(f);
}
void Pip::RendererGL::setDefaultViewport(QOpenGLFunctions &f) {
f.glViewport(0, 0, _uniformViewport.x(), _uniformViewport.y());
}
void Pip::RendererGL::createShadowTexture() {
const auto &shadow = st::callShadow;
const auto size = 2 * st::callShadow.topLeft.size()
@ -279,11 +258,24 @@ void Pip::RendererGL::createShadowTexture() {
void Pip::RendererGL::paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
const auto factor = widget->devicePixelRatio();
if (_factor != factor) {
_factor = factor;
_controlsImage.invalidate();
}
_viewport = widget->size();
_uniformViewport = QVector2D(
_viewport.width() * _factor,
_viewport.height() * _factor);
_f = &f;
_owner->paint(this);
_f = nullptr;
}
std::optional<QColor> Pip::RendererGL::clearColor() {
return QColor(0, 0, 0, 0);
}
void Pip::RendererGL::paintTransformedVideoFrame(
ContentGeometry geometry) {
const auto data = _owner->videoFrameWithInfo();

View File

@ -27,23 +27,18 @@ public:
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
void resize(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f,
int w,
int h);
void paint(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) override;
std::optional<QColor> clearColor() override;
private:
struct Control {
int index = -1;
not_null<const style::icon*> icon;
not_null<const style::icon*> iconOver;
};
void setDefaultViewport(QOpenGLFunctions &f);
void createShadowTexture();
void paintTransformedVideoFrame(ContentGeometry geometry) override;

@ -1 +1 @@
Subproject commit 1c004580ebb1380d3cb19fadb017f416c85a0eef
Subproject commit 098eb59f2f4635640f8a5f2e53bee2f689f2d0b3