mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
This reverts commit8e6a222bff. Reason for revert: breaks the overlay (crbug/1281801) Original change's description: > Reland "Batch rendering commands and skip rendering if commands are same" > > This is a reland of2288c1657c+ a fix > for the issue when hiding and showing the same overlay lead to the > overlay not being painted. > > Note: on my CPU this optimization reduces cpu usage from ~60% to ~30% > when inspecting a single element that does not change. > > Original change's description: > > Batch rendering commands and skip rendering if commands are same > > > > Bug: 1062574 > > Change-Id: I2bd2d02055f36a318ecd56194817fb531eb614b9 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3301392 > > Reviewed-by: Simon Zünd <szuend@chromium.org> > > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> > > Bug: 1062574 > Change-Id: I82e6ed03cd7c44f0e8ac7fd78f3623bed8e23187 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3308808 > Reviewed-by: Simon Zünd <szuend@chromium.org> > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Bug: 1062574 Change-Id: I88848f84d5b7d588877e513a02d7cc23a3a5a598 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3352204 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Auto-Submit: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org>
108 lines
4.4 KiB
TypeScript
108 lines
4.4 KiB
TypeScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import commonStyle from './common.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
import {adoptStyleSheet} from './common.js';
|
|
import {gridStyle} from './highlight_grid_common.js';
|
|
import {DistancesOverlay} from './tool_distances.js';
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import highlightGridStyle from './tool_grid.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import highlightStyle from './tool_highlight.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
import {HighlightOverlay} from './tool_highlight.js';
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import pausedStyle from './tool_paused.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
import type {PausedToolMessage} from './tool_paused.js';
|
|
import {PausedOverlay} from './tool_paused.js';
|
|
import type {PersistentToolMessage} from './tool_persistent.js';
|
|
import {PersistentOverlay} from './tool_persistent.js';
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import screenshotStyle from './tool_screenshot.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
import {ScreenshotOverlay} from './tool_screenshot.js';
|
|
import type {ScreenshotToolMessage} from './tool_screenshot.js';
|
|
// @ts-ignore Importing CSS is handled in Rollup.
|
|
import sourceOrderStyle from './tool_source_order.css'; // eslint-disable-line rulesdir/es_modules_import
|
|
import {SourceOrderOverlay} from './tool_source_order.js';
|
|
import {ViewportSizeOverlay} from './tool_viewport_size.js';
|
|
|
|
declare global {
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
interface Window {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
InspectorOverlayHost: {send(data: PausedToolMessage|PersistentToolMessage|ScreenshotToolMessage|string): void};
|
|
}
|
|
}
|
|
|
|
adoptStyleSheet(commonStyle);
|
|
|
|
const gridStyleSheet = new CSSStyleSheet();
|
|
gridStyleSheet.replaceSync(gridStyle);
|
|
|
|
const highlightOverlay = new HighlightOverlay(window, [highlightStyle, gridStyleSheet]);
|
|
const persistentOverlay = new PersistentOverlay(window, [highlightGridStyle, gridStyleSheet]);
|
|
const distancesOverlay = new DistancesOverlay(window);
|
|
const pausedOverlay = new PausedOverlay(window, pausedStyle);
|
|
const screenshotOverlay = new ScreenshotOverlay(window, screenshotStyle);
|
|
const sourceOrderOverlay = new SourceOrderOverlay(window, sourceOrderStyle);
|
|
const viewportSizeOverlay = new ViewportSizeOverlay(window);
|
|
|
|
interface Overlays {
|
|
distances: DistancesOverlay;
|
|
highlight: HighlightOverlay;
|
|
persistent: PersistentOverlay;
|
|
paused: PausedOverlay;
|
|
screenshot: ScreenshotOverlay;
|
|
sourceOrder: SourceOrderOverlay;
|
|
viewportSize: ViewportSizeOverlay;
|
|
}
|
|
|
|
type PlatformName = string;
|
|
|
|
// Key in this object is the name the backend refers to a particular overlay by.
|
|
const overlays: Overlays = {
|
|
distances: distancesOverlay,
|
|
highlight: highlightOverlay,
|
|
persistent: persistentOverlay,
|
|
paused: pausedOverlay,
|
|
screenshot: screenshotOverlay,
|
|
sourceOrder: sourceOrderOverlay,
|
|
viewportSize: viewportSizeOverlay,
|
|
};
|
|
|
|
let currentOverlay: Overlays[keyof Overlays];
|
|
let platformName: PlatformName;
|
|
|
|
type MessageLookup = {
|
|
'setOverlay': keyof Overlays,
|
|
'setPlatform': PlatformName,
|
|
drawingFinished: '',
|
|
};
|
|
|
|
const dispatch = <K extends keyof MessageLookup>(message: [a: K, b: MessageLookup[K]]) => {
|
|
const functionName = message[0];
|
|
if (functionName === 'setOverlay') {
|
|
const overlayName = message[1] as keyof Overlays;
|
|
if (currentOverlay) {
|
|
currentOverlay.uninstall();
|
|
}
|
|
currentOverlay = overlays[overlayName];
|
|
currentOverlay.setPlatform(platformName);
|
|
// TODO: setPlatform invokes install() for compatibility with the backend.
|
|
// The call to install() can be removed from setPlatform() after the backend is updated.
|
|
if (!currentOverlay.installed) {
|
|
currentOverlay.install();
|
|
}
|
|
} else if (functionName === 'setPlatform') {
|
|
platformName = message[1];
|
|
} else if (functionName === 'drawingFinished') {
|
|
// TODO The logic needs to be added here once the backend starts sending this event.
|
|
} else {
|
|
currentOverlay.dispatch(message);
|
|
}
|
|
};
|
|
|
|
// Window has an additional dispatch function added, so retype as unknown first
|
|
(window as unknown as {dispatch: Function}).dispatch = dispatch;
|