Skip to content

Commit d45b428

Browse files
committed
perf(WidgetManager): reduce capture/render calls
1 parent 5495580 commit d45b428

File tree

1 file changed

+20
-17
lines changed
  • Sources/Widgets/Core/WidgetManager

1 file changed

+20
-17
lines changed

Sources/Widgets/Core/WidgetManager/index.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,27 @@ function vtkWidgetManager(publicAPI, model) {
283283
// Default cursor behavior
284284
model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
285285

286+
let wantRender = false;
286287
if (model.widgetInFocus === widget && widget.hasFocus()) {
287288
activateHandle(widget);
288-
// Ken FIXME
289-
model._interactor.render();
290-
model._interactor.render();
289+
wantRender = true;
291290
} else {
292291
for (let i = 0; i < model.widgets.length; i++) {
293292
const w = model.widgets[i];
294293
if (w === widget && w.getNestedPickable()) {
295294
activateHandle(w);
296295
model.activeWidget = w;
296+
wantRender = true;
297297
} else {
298+
wantRender ||= !!w.get().activeState;
298299
w.deactivateAllHandles();
299300
}
300301
}
301-
// Ken FIXME
302-
model._interactor.render();
303-
model._interactor.render();
302+
if (wantRender) {
303+
// Ken FIXME
304+
model._interactor.render();
305+
model._interactor.render();
306+
}
304307
}
305308
}
306309

@@ -524,17 +527,17 @@ function vtkWidgetManager(publicAPI, model) {
524527
// do we require a new capture?
525528
if (!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE) {
526529
await captureBuffers(x, y, x, y);
527-
}
528-
529-
// or do we need a pixel that is outside the last capture?
530-
const capturedRegion = model._capturedBuffers.area;
531-
if (
532-
x < capturedRegion[0] ||
533-
x > capturedRegion[2] ||
534-
y < capturedRegion[1] ||
535-
y > capturedRegion[3]
536-
) {
537-
await captureBuffers(x, y, x, y);
530+
} else {
531+
// or do we need a pixel that is outside the last capture?
532+
const capturedRegion = model._capturedBuffers.area;
533+
if (
534+
x < capturedRegion[0] ||
535+
x > capturedRegion[2] ||
536+
y < capturedRegion[1] ||
537+
y > capturedRegion[3]
538+
) {
539+
await captureBuffers(x, y, x, y);
540+
}
538541
}
539542

540543
model.selections = model._capturedBuffers.generateSelection(x, y, x, y);

0 commit comments

Comments
 (0)