From 9b82b829a4f0d6eb9d15d6b1a3657ddf20798db2 Mon Sep 17 00:00:00 2001 From: Marcello Salomao Date: Mon, 14 Aug 2023 04:11:59 +0000 Subject: [PATCH] [MirrorSync] Reimplement performant smooth pie progress Reimplement pie progress smooth transitions using pure CSS transitions for improved rendering performance. This CL has been stress tested by running 50 Drive uploads in parallel and observing its performance impact on the "Performance" tab of Chrome Dev Tools. Bug: b:289167014 Test: Manual performance test of 50 files uploading in parallel using Dev Tools' Performance tab Change-Id: I846497d66311b854271ef925bbdde3ebfb345d38 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4654508 Reviewed-by: Ben Reich Commit-Queue: Ben Reich Auto-Submit: Marcello Salomao Cr-Commit-Position: refs/heads/main@{#1182954} --- .../file_manager/widgets/xf_pie_progress.ts | 124 +++++++----------- 1 file changed, 49 insertions(+), 75 deletions(-) diff --git a/ui/file_manager/file_manager/widgets/xf_pie_progress.ts b/ui/file_manager/file_manager/widgets/xf_pie_progress.ts index a9583a3eecfc9..0632a861b977b 100644 --- a/ui/file_manager/file_manager/widgets/xf_pie_progress.ts +++ b/ui/file_manager/file_manager/widgets/xf_pie_progress.ts @@ -6,9 +6,6 @@ import {addCSSPrefixSelector} from '../common/js/dom_utils.js'; import {css, customElement, html, property, svg, XfBase} from './xf_base.js'; -const TWO_PI = 2.0 * Math.PI; -const HALF_PI = 0.5 * Math.PI; - /** * Displays a pie shaped progress indicator. * Accepts a `progress` property ranging from 0 to 1. @@ -22,20 +19,29 @@ export class XfPieProgress extends XfBase { private center = this.size / 2.0; // Center of the pie circle (both X and Y). private radius = 5.4; // Radius of the pie circle. - private outlineShape = svg``; - private queuedShape = svg``; + private queuedShape = svg` + ;`; + />`; + private edgeShape = svg` + `; static override get styles() { return getCSS(); @@ -44,59 +50,29 @@ export class XfPieProgress extends XfBase { override render() { const {progress, size, center, radius} = this; - let contents = svg``; - - if (progress === 0) { - // Display the queued shape. - contents = this.queuedShape; - } else if (progress >= 0.99) { - // The completed pie is easier to draw. - contents = svg` - - `; - } else { - // Finishing angle of the pie arc. Notice that the starting angle is - // always -PI/2. I.e., the pie is drawn starting from the top of the - // circle and it advances in a clockwise fashion. - const radians = TWO_PI * progress - HALF_PI; - - // Finishing cartesian coordinates of the pie arc. Notice that the - // starting coordinates are always <0, -radius> (the top of the circle). - const x = center + radius * Math.cos(radians); - const y = center + radius * Math.sin(radians); - - // Determines which arc fitting the other arguments should be rendered. - // Render the smaller one until we are drawing an arc with an angle - // greater than 180 degrees. More info: - // https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands - const largeArcFlag = progress <= 0.5 ? '0' : '1'; - - contents = svg` - `; - } + const isQueued = progress === 0; + + // The progress pie is drawn as an arc with a thick stroke width (as thick + // as the radius of the pie). + const arcRadius = radius * 0.5; + const maxArcLength = 2.0 * Math.PI * arcRadius; + const pie = svg` + `; + + const edge = isQueued ? this.queuedShape : this.edgeShape; return html` - ${this.outlineShape} ${contents} + ${this.outlineShape} ${pie} ${edge} `; } @@ -110,6 +86,7 @@ function getCSS() { } .queued { + fill: none; stroke: var(--cros-icon-color-secondary); } @@ -118,17 +95,15 @@ function getCSS() { stroke: var(--cros-icon-color-prominent); } - .full { - fill: var(--cros-icon-color-prominent); - } - .pie { - fill: var(--cros-icon-color-prominent); - stroke: none; + fill: none; + stroke: var(--cros-icon-color-prominent); + transition: stroke-dashoffset 1s ease-out; } .outline { fill: var(--xf-icon-color-outline, transparent); + stroke: none; } `; @@ -139,6 +114,7 @@ function getCSS() { } .queued { + fill: none; stroke: currentColor } @@ -147,17 +123,15 @@ function getCSS() { stroke: var(--cros-sys-progress); } - .full { - fill: var(--cros-sys-progress); - } - .pie { - fill: var(--cros-sys-progress); - stroke: none; + fill: none; + stroke: var(--cros-sys-progress); + transition: stroke-dashoffset 1s ease-out; } .outline { fill: var(--xf-icon-color-outline, transparent); + stroke: none; } `;