Skip to content

Commit b671034

Browse files
committed
Use AppCapture event instead of polling it multiple times every frame
1 parent 7074e22 commit b671034

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Assets/MRTK/Services/DiagnosticsSystem/MixedRealityToolkitVisualProfiler.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public bool IsVisible
5858

5959
private bool ShouldShowProfiler =>
6060
#if WINDOWS_UWP
61-
(appCapture == null || !appCapture.IsCapturingVideo || showProfilerDuringMRC) &&
61+
(!appCaptureIsCapturingVideo || showProfilerDuringMRC) &&
6262
#endif // WINDOWS_UWP
6363
isVisible;
6464

@@ -217,6 +217,7 @@ private struct FrameRateColor
217217
private Mesh quadMesh;
218218

219219
#if WINDOWS_UWP
220+
private bool appCaptureIsCapturingVideo = false;
220221
private AppCapture appCapture;
221222
#endif // WINDOWS_UWP
222223

@@ -289,11 +290,22 @@ private void Start()
289290

290291
#if WINDOWS_UWP
291292
appCapture = AppCapture.GetForCurrentView();
293+
if (appCapture != null)
294+
{
295+
appCapture.CapturingChanged += AppCapture_CapturingChanged;
296+
}
292297
#endif // WINDOWS_UWP
293298
}
294299

295300
private void OnDestroy()
296301
{
302+
#if WINDOWS_UWP
303+
if (appCapture != null)
304+
{
305+
appCapture.CapturingChanged -= AppCapture_CapturingChanged;
306+
}
307+
#endif // WINDOWS_UWP
308+
297309
if (window != null)
298310
{
299311
Destroy(window.gameObject);
@@ -442,6 +454,10 @@ private void LateUpdate()
442454
}
443455
}
444456

457+
#if WINDOWS_UWP
458+
private void AppCapture_CapturingChanged(AppCapture sender, object args) => appCaptureIsCapturingVideo = sender.IsCapturingVideo;
459+
#endif // WINDOWS_UWP
460+
445461
private static readonly ProfilerMarker CalculateWindowPositionPerfMarker = new ProfilerMarker("[MRTK] MixedRealityToolkitVisualProfiler.CalculateWindowPosition");
446462

447463
private Vector3 CalculateWindowPosition(Transform cameraTransform)

0 commit comments

Comments
 (0)