Repository: microsoft/terminal
File: src/host/srvinit.cpp (C++)

Code before:

    Globals.pFontDefaultList = new RenderFontDefaults();

    FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

    // Check if this conhost is allowed to delegate its activities to another.
    // If so, look up the registered default console handler.
    bool isEnabled = false;
    if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled)) && isEnabled)
    {
        IID delegationClsid;
        if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
        {
            Globals.handoffConsoleClsid = delegationClsid;
        }
        if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
        {
            Globals.handoffTerminalClsid = delegationClsid;
        }
    }

    if (args->InConptyMode())
    {
        // If we're in ConPTY mode... set the no-op accessibility notifier
        // to prevent sending expensive legacy MSAA events when we won't even be
        // responsible for the terminal user interface.
        std::unique_ptr<IAccessibilityNotifier> noOpNotifier = std::make_unique<Microsoft::Console::Interactivity::NoOpAccessibilityNotifier>();
        RETURN_IF_NTSTATUS_FAILED(ServiceLocator::SetAccessibilityNotifier(std::move(noOpNotifier)));
    }

    // Removed allocation of scroll buffer here.
    return S_OK;
}
CATCH_RETURN()

static bool s_IsOnDesktop()
{
    // Persist this across calls so we don't dig it out a whole bunch of times. Once is good enough for the system.
    static bool fAlreadyQueried = false;
    static bool fIsDesktop = false;

    if (!fAlreadyQueried)
    {
        Microsoft::Console::Interactivity::ApiLevel level;
        const NTSTATUS status = Microsoft::Console::Interactivity::ApiDetector::DetectNtUserWindow(&level);
        LOG_IF_NTSTATUS_FAILED(status);

        if (NT_SUCCESS(status))
        {
            switch (level)
            {

Review comment (suggestion):
We may want to audit the places where IAccessibilityNotifier is used, in addition to having the no-op interface.

I say this because ... the one that notifies about buffer changes reads the buffer first, before calling out to IAN. It's a waste of time if IAN is a no-op, which still increases our output time burden.

Code after:

    Globals.pFontDefaultList = new RenderFontDefaults();

    FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

    // Check if this conhost is allowed to delegate its activities to another.
    // If so, look up the registered default console handler.
    bool isEnabled = false;
    if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled)) && isEnabled)
    {
        IID delegationClsid;
        if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
        {
            Globals.handoffConsoleClsid = delegationClsid;
        }
        if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
        {
            Globals.handoffTerminalClsid = delegationClsid;
        }
    }

    // Create the accessibility notifier early in the startup process.
    // Only create if we're not in PTY mode.
    // The notifiers use expensive legacy MSAA events and the PTY isn't even responsible
    // for the terminal user interface, so we should set ourselves up to skip all
    // those notifications and the mathematical calculations required to send those events
    // for performance reasons.
    if (!args->InConptyMode())
    {
        RETURN_IF_FAILED(ServiceLocator::CreateAccessibilityNotifier());
    }

    // Removed allocation of scroll buffer here.
    return S_OK;
}
CATCH_RETURN()

static bool s_IsOnDesktop()
{
    // Persist this across calls so we don't dig it out a whole bunch of times. Once is good enough for the system.
    static bool fAlreadyQueried = false;
    static bool fIsDesktop = false;

    if (!fAlreadyQueried)
    {
        Microsoft::Console::Interactivity::ApiLevel level;
        const NTSTATUS status = Microsoft::Console::Interactivity::ApiDetector::DetectNtUserWindow(&level);
        LOG_IF_NTSTATUS_FAILED(status);

        if (NT_SUCCESS(status))
        {