From 5fcd1da3e868825b3aaaa21aec9264040d24e61a Mon Sep 17 00:00:00 2001
From: YuraIz <7516890@gmail.com>
Date: Sun, 11 Jun 2023 11:43:29 +0300
Subject: [PATCH] perf(chat-history): Render the shader directly to bubbles
Rendering big texture into a lot of small bubbles results into bad
performance (30fps on my laptop while scrolling). Rendering the shader
to small bubbles fixes that issue.
---
src/session/content/background.rs | 103 ++++++++++++----------
src/session/content/message_row/bubble.rs | 12 ++-
2 files changed, 67 insertions(+), 48 deletions(-)
diff --git a/src/session/content/background.rs b/src/session/content/background.rs
index bfe3ce6e4..634449c0e 100644
--- a/src/session/content/background.rs
+++ b/src/session/content/background.rs
@@ -14,15 +14,20 @@ uniform vec3 color1;
uniform vec3 color2;
uniform vec3 color3;
uniform vec3 color4;
-uniform vec2 p1;
-uniform vec2 p2;
-uniform vec2 p3;
-uniform vec2 p4;
+uniform vec4 p12;
+uniform vec4 p34;
+uniform vec4 gradient_bounds;
void mainImage(out vec4 fragColor,
in vec2 fragCoord,
in vec2 resolution,
in vec2 uv) {
+ vec2 p1 = p12.xy;
+ vec2 p2 = p12.zw;
+ vec2 p3 = p34.xy;
+ vec2 p4 = p34.zw;
+
+ uv = (fragCoord - gradient_bounds.xy) / gradient_bounds.zw;
uv.y = 1.0 - uv.y;
float dp1 = distance(uv, p1);
@@ -51,7 +56,6 @@ mod imp {
#[derive(Default)]
pub(crate) struct Background {
pub(super) background_texture: RefCell