#include "ui/aura/native_window_occlusion_tracker.h"
#include "base/metrics/field_trial_params.h"
#include "build/build_config.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ui_base_features.h"
#if BUILDFLAG(IS_WIN)
#include "ui/aura/native_window_occlusion_tracker_win.h"
#endif
namespace aura {
void NativeWindowOcclusionTracker::EnableNativeWindowOcclusionTracking(
WindowTreeHost* host) {
#if BUILDFLAG(IS_WIN)
if (host->IsNativeWindowOcclusionEnabled()) {
NativeWindowOcclusionTrackerWin::GetOrCreateInstance()->Enable(
host->window());
}
#endif
}
void NativeWindowOcclusionTracker::DisableNativeWindowOcclusionTracking(
WindowTreeHost* host) {
#if BUILDFLAG(IS_WIN)
if (host->IsNativeWindowOcclusionEnabled()) {
host->SetNativeWindowOcclusionState(Window::OcclusionState::UNKNOWN, {});
host->set_on_current_workspace(std::nullopt);
NativeWindowOcclusionTrackerWin::GetOrCreateInstance()->Disable(
host->window());
}
#endif
}
bool NativeWindowOcclusionTracker::IsNativeWindowOcclusionTrackingAlwaysEnabled(
WindowTreeHost* host) {
#if BUILDFLAG(IS_WIN)
static bool is_headless = getenv("CHROME_HEADLESS") != nullptr;
if ((is_headless &&
!base::FeatureList::IsEnabled(
features::kAlwaysTrackNativeWindowOcclusionForTest)) ||
!host->IsNativeWindowOcclusionEnabled() ||
!base::FeatureList::IsEnabled(
features::kApplyNativeOcclusionToCompositor)) {
return false;
}
if (!base::FeatureList::IsEnabled(features::kCalculateNativeWinOcclusion)) {
return false;
}
const std::string type =
features::kApplyNativeOcclusionToCompositorType.Get();
return type == features::kApplyNativeOcclusionToCompositorTypeRelease ||
type == features::kApplyNativeOcclusionToCompositorTypeThrottle ||
type ==
features::kApplyNativeOcclusionToCompositorTypeThrottleAndRelease;
#else
return false;
#endif
}
}