Skip to content

Commit

Permalink
Decrease GPU usage when window is invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Jul 30, 2021
1 parent 9fb8114 commit 2d3b191
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ addDecorator((storyFn /* , context */) => {
document.body.classList.add('keyboard-mode');
}

document.body.classList.add('page-is-visible');

return (
<div className={styles.container}>
<ClassyProvider themes={['dark']}>
Expand Down
12 changes: 6 additions & 6 deletions stylesheets/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ $loading-height: 16px;
border-color: $color-ios-blue-tint $color-ios-blue-tint $color-gray-02
$color-gray-02 !important;
}

@keyframes rotate {
to {
transform: rotate(360deg);
}
}
}

.x {
Expand Down Expand Up @@ -689,3 +683,9 @@ $loading-height: 16px;
.overflow-hidden {
overflow: hidden;
}

@keyframes rotate {
to {
transform: rotate(360deg);
}
}
8 changes: 8 additions & 0 deletions stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
}
}

// NOTE: As of this writing, this mixin only works in the main window, because this class
// is only applied there.
@mixin only-when-page-is-visible {
.page-is-visible & {
@content;
}
}

// Search results loading

@mixin search-results-loading-pulsating-background {
Expand Down
51 changes: 13 additions & 38 deletions stylesheets/_modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1131,21 +1131,10 @@

.module-message__metadata__status-icon--paused,
.module-message__metadata__status-icon--sending {
animation: module-message__metadata__status-icon--spinning 4s linear infinite;

@include light-theme {
@include color-svg('../images/sending.svg', $color-white);
}
@include dark-theme {
@include color-svg('../images/sending.svg', $color-white);
}
}

@keyframes module-message__metadata__status-icon--spinning {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
@include only-when-page-is-visible {
animation: rotate 4s linear infinite;
}
@include color-svg('../images/sending.svg', $color-white);
}

.module-message__metadata__status-icon--sent {
Expand Down Expand Up @@ -4129,11 +4118,15 @@ button.module-image__border-overlay:focus {
background-color: $color-gray-60;
}

animation: typing-animation 1600ms ease infinite;
@include only-when-page-is-visible {
animation: typing-animation 1600ms ease infinite;
}
}

.module-left-pane .module-typing-animation__dot {
animation-name: typing-animation-bare;
@include only-when-page-is-visible {
animation-name: typing-animation-bare;
}
}

.module-typing-animation__dot--light {
Expand Down Expand Up @@ -4649,7 +4642,7 @@ button.module-image__border-overlay:focus {
height: 100%;
width: 100%;

animation: spinner-arc-animation 1000ms linear infinite;
animation: rotate 1000ms linear infinite;

@include light-theme {
@include color-svg('../images/spinner-56.svg', $color-gray-60);
Expand All @@ -4659,18 +4652,6 @@ button.module-image__border-overlay:focus {
}
}

@keyframes spinner-arc-animation {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(360deg);
}
}

// In these --small and --mini sizes, we're exploding our @color-svg mixin so we don't
// have to duplicate our background colors for the dark/ios/size matrix.

Expand Down Expand Up @@ -6489,8 +6470,9 @@ button.module-image__border-overlay:focus {
}

&--sending {
animation: module-conversation-list__item--contact-or-conversation__contact__message__text__status-icon--spinning
4s linear infinite;
@include only-when-page-is-visible {
animation: rotate 4s linear infinite;
}
@include light-theme {
@include color-svg('../images/sending.svg', $color-gray-60);
}
Expand Down Expand Up @@ -6664,13 +6646,6 @@ button.module-image__border-overlay:focus {
}
}

@keyframes module-conversation-list__item--contact-or-conversation__contact__message__text__status-icon--spinning {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

// Module: Left Pane

.module-left-pane {
Expand Down
10 changes: 1 addition & 9 deletions stylesheets/components/MessageDetail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,11 @@

&--Pending:after {
width: 12px;
animation: module-message-detail__contact-group__header--Pending 4s linear
infinite;
animation: rotate 4s linear infinite;
@include normal-icon('../images/sending.svg');
}
}

@keyframes module-message-detail__contact-group__header--Pending {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

.module-message-detail__contact {
margin-bottom: 8px;
padding: 8px 0;
Expand Down
11 changes: 10 additions & 1 deletion ts/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import React, { useEffect } from 'react';
import classNames from 'classnames';

Expand All @@ -6,6 +9,7 @@ import { Inbox } from './Inbox';
import { Install } from './Install';
import { StandaloneRegistration } from './StandaloneRegistration';
import { ThemeType } from '../types/Util';
import { usePageVisibility } from '../util/hooks';

export type PropsType = {
appView: AppViewType;
Expand All @@ -32,7 +36,7 @@ export const App = ({
contents = <Inbox hasInitialLoadCompleted={hasInitialLoadCompleted} />;
}

// This is here so that themes are properly applied to anything that is
// This are here so that themes are properly applied to anything that is
// created in a portal and exists outside of the <App /> container.
useEffect(() => {
document.body.classList.remove('light-theme');
Expand All @@ -46,6 +50,11 @@ export const App = ({
}
}, [theme]);

const isPageVisible = usePageVisibility();
useEffect(() => {
document.body.classList.toggle('page-is-visible', isPageVisible);
}, [isPageVisible]);

return (
<div
className={classNames({
Expand Down

0 comments on commit 2d3b191

Please sign in to comment.