Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ca92101

Browse files
author
Dariusz Niemczyk
committed
Optimize and rewrite backdrop rendering
1 parent 51b5b01 commit ca92101

File tree

6 files changed

+45
-71
lines changed

6 files changed

+45
-71
lines changed

res/css/structures/_BackdropPanel.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ limitations under the License.
2121
height: 100vh;
2222
width: 100%;
2323
overflow: hidden;
24-
25-
&::before {
26-
content: " ";
27-
position: absolute;
28-
left: 0;
29-
top: 0;
30-
height: 100vh;
31-
width: 100%;
32-
background-color: var(--lp-background-overlay);
33-
}
3424
}
3525

3626
.mx_BackdropPanel--canvas {

res/css/structures/_LeftPanel.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,37 @@ $roomListCollapsedWidth: 68px;
2727
.mx_LeftPanel_wrapper {
2828
display: flex;
2929
max-width: 50%;
30+
31+
.mx_LeftPanel_background {
32+
33+
&::before {
34+
content: " ";
35+
position: absolute;
36+
left: 0;
37+
top: 0;
38+
height: 100vh;
39+
width: 100%;
40+
background-color: var(--lp-background-overlay);
41+
}
42+
43+
position: absolute;
44+
left: 0;
45+
top: 0;
46+
width: 100%;
47+
height: 100%;
48+
background-color: $roomlist-bg-color;
49+
opacity: 0.5;
50+
}
51+
52+
.mx_LeftPanel_wrapper--user {
53+
display: flex;
54+
overflow: hidden;
55+
position: relative;
56+
}
3057
}
3158

59+
60+
3261
.mx_LeftPanel {
3362
background-color: $roomlist-bg-color;
3463
// TODO decrease this once Spaces launches as it'll no longer need to include the 56px Community Panel

res/themes/dark/css/_dark.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ $appearance-tab-border-color: $room-highlight-color;
240240

241241
// blur amounts for left left panel (only for element theme)
242242
:root {
243-
--llp-background-blur: 160px;
244243
--lp-background-blur: 90px;
245244
--lp-background-overlay: rgba(255, 255, 255, 0.055);
246245
}

res/themes/light/css/_light.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ $appearance-tab-border-color: $input-darker-bg-color;
363363

364364
// blur amounts for left left panel (only for element theme)
365365
:root {
366-
--llp-background-blur: 120px;
367366
--lp-background-blur: 60px;
368367
--lp-background-overlay: rgba(0, 0, 0, 0.055);
369368
}

src/components/structures/BackdropPanel.tsx

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { createRef } from "react";
17+
import React from "react";
1818
import "context-filter-polyfill";
1919

2020
import UIStore from "../../stores/UIStore";
@@ -31,24 +31,15 @@ interface IState {
3131
}
3232

3333
export default class BackdropPanel extends React.PureComponent<IProps, IState> {
34-
private sizes = {
35-
leftLeftPanelWidth: 0,
36-
leftPanelWidth: 0,
37-
height: 0,
38-
};
3934
private style = getComputedStyle(document.documentElement);
4035

4136
public state: IState = {};
4237

4338
public componentDidMount() {
44-
UIStore.instance.on("SpacePanel", this.onResize);
45-
UIStore.instance.on("GroupFilterPanelContainer", this.onResize);
4639
this.onResize();
4740
}
4841

4942
public componentWillUnmount() {
50-
UIStore.instance.off("SpacePanel", this.onResize);
51-
UIStore.instance.on("GroupFilterPanelContainer", this.onResize);
5243
}
5344

5445
public componentDidUpdate(prevProps: IProps) {
@@ -73,76 +64,37 @@ export default class BackdropPanel extends React.PureComponent<IProps, IState> {
7364
};
7465

7566
private refreshBackdropImage = (): void => {
76-
const leftLeftPanelCanvas = document.createElement('canvas');
7767
const leftPanelCanvas = document.createElement('canvas');
78-
const leftLeftPanelContext = leftLeftPanelCanvas.getContext("2d");
7968
const leftPanelContext = leftPanelCanvas.getContext("2d");
8069
const { backgroundImage } = this.props;
81-
const { leftLeftPanelWidth, leftPanelWidth, height } = this.sizes;
82-
const width = leftLeftPanelWidth + leftPanelWidth;
8370

8471
const imageWidth = (backgroundImage as ImageBitmap).width;
8572
const imageHeight = (backgroundImage as ImageBitmap).height;
8673

87-
const contentRatio = imageWidth / imageHeight;
88-
const containerRatio = width / height;
89-
let resultHeight;
90-
let resultWidth;
91-
if (contentRatio > containerRatio) {
92-
resultHeight = height;
93-
resultWidth = height * contentRatio;
94-
} else {
95-
resultWidth = width;
96-
resultHeight = width / contentRatio;
97-
}
98-
99-
// This value has been chosen to be as close with rendering as the css-only
100-
// backdrop-filter: blur effect was, mostly takes effect for vertical pictures.
101-
const x = width * 0.1;
102-
const y = (height - resultHeight) / 2;
103-
104-
leftLeftPanelCanvas.width = leftLeftPanelWidth;
105-
leftLeftPanelCanvas.height = height;
10674
leftPanelCanvas.width = window.screen.width * 0.5;
107-
leftPanelCanvas.height = height;
75+
leftPanelCanvas.height = window.screen.height;
10876

109-
const spacesBlur = this.style.getPropertyValue('--llp-background-blur');
11077
const roomListBlur = this.style.getPropertyValue('--lp-background-blur');
11178

112-
leftLeftPanelContext.filter = `blur(${spacesBlur})`;
11379
leftPanelContext.filter = `blur(${roomListBlur})`;
114-
leftLeftPanelContext.drawImage(
115-
backgroundImage,
116-
0, 0,
117-
imageWidth, imageHeight,
118-
x,
119-
y,
120-
resultWidth,
121-
resultHeight,
122-
);
12380
leftPanelContext.drawImage(
12481
backgroundImage,
12582
0, 0,
12683
imageWidth, imageHeight,
127-
x - leftLeftPanelWidth,
128-
y,
129-
resultWidth,
130-
resultHeight,
84+
0,
85+
0,
86+
window.screen.width * 0.5,
87+
window.screen.height,
13188
);
13289
this.setState({
13390
lpImage: leftPanelCanvas.toDataURL('image/jpeg', 1),
134-
llpImage: leftLeftPanelCanvas.toDataURL('image/jpeg', 1),
13591

13692
});
13793
};
13894

13995
public render() {
14096
if (!this.props.backgroundImage) return null;
14197
return <div className="mx_BackdropPanel">
142-
{ this.state?.llpImage !== 'data:,' && <img
143-
className="mx_BackdropPanel--canvas"
144-
src={this.state.llpImage} /> }
145-
14698
{ this.state?.lpImage !== 'data:,' && <img
14799
className="mx_BackdropPanel--canvas"
148100
src={this.state.lpImage} /> }

src/components/structures/LoggedInView.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,21 @@ class LoggedInView extends React.Component<IProps, IState> {
645645
>
646646
<ToastContainer />
647647
<div className={bodyClasses}>
648-
<div ref={this._resizeContainer} className='mx_LeftPanel_wrapper'>
648+
<div className='mx_LeftPanel_wrapper'>
649649
<BackdropPanel
650650
backgroundImage={this.state.backgroundImage}
651651
/>
652652
{ SpaceStore.spacesEnabled ? <SpacePanel /> : null }
653-
<LeftPanel
654-
isMinimized={this.props.collapseLhs || false}
655-
resizeNotifier={this.props.resizeNotifier}
656-
/>
653+
<div
654+
ref={this._resizeContainer}
655+
className="mx_LeftPanel_wrapper--user">
656+
<div className="mx_LeftPanel_background" />
657+
<LeftPanel
658+
isMinimized={this.props.collapseLhs || false}
659+
resizeNotifier={this.props.resizeNotifier}
660+
/>
657661
<ResizeHandle id="lp-resizer" />
662+
</div>
658663
</div>
659664
<div className="mx_RoomView_wrapper">
660665
{ pageElement }

0 commit comments

Comments
 (0)