> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameStreamingSetResolution

> XGameStreamingSetResolution

# XGameStreamingSetResolution

Define a resolução do stream.

## Sintaxe

```cpp theme={null}
HRESULT XGameStreamingSetResolution(
        uint32_t width,
        uint32_t height
)
```

### Parâmetros

*width*   \_In\_\
Tipo: uint32\_t

A largura para a qual definir a resolução do stream.

*height*   \_In\_\
Tipo: uint32\_t

A altura para a qual definir a resolução do stream.

### Valor retornado

Tipo: HRESULT

Retornará **S\_OK** se for bem-sucedido; caso contrário, retornará um código de erro.

#### Erros potenciais

| Código de erro | Valor do erro | Motivo do erro |
| - | - | - |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | O runtime do XGameStreaming não foi inicializado. Chame XGameStreamingInitialize antes de chamar outras APIs. |
| E\_INVALIDARG | 0x80070057 | O parâmetro *width* e/ou *height* ou o hardware não atendeu aos requisitos. |

Para obter uma lista de códigos de erro, consulte [Códigos de erro](/pt-BR/reference/errorcodes).

## Comentários

Esta API com resoluções não padrão só terá êxito em servidores do XBOX Game Streaming, no XBOX Series X Dev Kit e no XBOX Series S Test Kit. Resoluções padrão, como 720p e 1080p, terão êxito independentemente do hardware. O motivo é que um XBOX de varejo só pode fazer streaming por meio do Remote Play e ainda pode estar enviando vídeo para a TV, portanto, usar uma resolução não padrão produziria uma imagem distorcida.

A largura e a altura devem ser de no mínimo 640x360, e o máximo pode ser encontrado nos campos `maxWidth` e `maxHeight` de [XGameStreamingDisplayDetails](/pt-BR/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails), que pode ser obtido de [XGameStreamingGetDisplayDetails](/pt-BR/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails).

O número máximo de pixels, calculado por `width` \* `height`, deve ser igual ou menor que o máximo do codificador. O máximo pode ser encontrado usando a API [XGameStreamingGetDisplayDetails](/pt-BR/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails). Esse valor poderá ser aumentado no futuro.

Os valores de `width` e `height` devem ser divisíveis por 8.

A API pode ser chamada com a frequência desejada; no entanto, a resolução do stream só pode mudar uma vez a cada 200 ms. A última resolução de quaisquer chamadas que ocorrerem dentro dessa janela de 200 ms será aplicada após o término dessa janela.

Esteja ciente de que esta API definirá a resolução do stream para todos os clientes conectados. Isso significa que é preciso ter uma consideração especial para determinar qual é a melhor opção para o jogo quando vários clientes estiverem conectados. Isso pode significar usar uma resolução padrão 16:9 ou tentar encontrar a resolução que melhor se ajuste a todos os clientes.

<Note>Alterar a resolução do stream modifica o dimensionamento do retângulo de exibição em `ID3D12CommandQueue::PresentX`. Os fatores de escala de 0.0 a 1.0 de `D3D12XBOX_PRESENT_PLANE_PARAMETERS.pDestPlacementBase` referem-se à altura e à largura passadas para `XGameStreamingSetResolution`, em vez da resolução padrão de 1920x1080 ou 3840x2160 à qual se refeririam de outra forma.  </Note>

## Exemplo

```C++ theme={null}

#define DEFAULT_GAME_WIDTH 1920
#define DEFAULT_GAME_HEIGHT 1080

#define GAME_WIDEST_SUPPORTED_ASPECT_RATIO 21.5f / 9.0f
#define GAME_TALLEST_SUPPORTED_ASPECT_RATIO 16.0f / 10.0f

static uint32_t s_currentStreamWidth = DEFAULT_GAME_WIDTH;
static uint32_t s_currentStreamHeight = DEFAULT_GAME_HEIGHT;

// Option 1: Event driven. Note: be aware of potential threading issues when using the task queue.
void GameStreamingClientManager::OnConnectionStateChanged(XGameStreamingClientId client, XGameStreamingConnectionState connected)
{
    // Other connection work like registering or unregistering for the client properties change events.
    ...

    UpdateResolutionIfNeeded();
}

void GameStreamingClientManager::OnClientPropertiesChanged(
    XGameStreamingClientId client,
    uint32_t updatedPropertiesCount,
    XGameStreamingClientProperty* updatedProperties)
{
    for (uint32_t i = 0; i < updatedPropertiesCount; ++i)
    {
        switch (updatedProperties[i])
        {
        case XGameStreamingClientProperty::DisplayDetails:
        {
            UpdateResolutionIfNeeded();
            break;
        }

        default:
            // A characteristic we are not tracking - do nothing
            break;
        }
    }
}

// Option 2: Polling.

void Game::Update(DX::StepTimer const& timer)
{
    ...

    gameStreamingClientManager->UpdateResolutionIfNeeded();

    ...
}

void GameStreamingClientManager::UpdateResolutionIfNeeded()
{
    bool changeResolution = false;
    bool useDefaultResolution = true;

    // Only use custom resolution when there is only one streaming client connected.
    if (XGameStreamingGetClientCount() == 1)
    {
        XGameStreamingClientId client;
        uint32_t clientsUsed = 0;
        HRESULT hr = XGameStreamingGetClients(1, &client, &clientsUsed);
        if (SUCCEEDED(hr) && clientsUsed == 1)
        {
            XGameStreamingDisplayDetails displayDetails = {};
            hr = XGameStreamingGetDisplayDetails(client, DEFAULT_GAME_WIDTH * DEFAULT_GAME_HEIGHT, GAME_WIDEST_SUPPORTED_ASPECT_RATIO, GAME_TALLEST_SUPPORTED_ASPECT_RATIO, &displayDetails);

            if (SUCCEEDED(hr))
            {
                useDefaultResolution = false;

                // Assuming the game supports all resolutions, use the stream resolution to the preferred dimensions as provided.
                if (s_currentStreamWidth != displayDetails.preferredWidth || s_currentStreamHeight != displayDetails.preferredHeight)
                {
                    changeResolution = true;
                    s_currentStreamWidth = displayDetails.preferredWidth;
                    s_currentStreamHeight = displayDetails.preferredHeight;
                }
            }
            else
            {
                LogFormat(L"XGameStreamingGetDisplayDetails failed %x", hr);
            }
        }
        else
        {
            LogFormat(L"XGameStreamingGetClients failed hr=%x clientsUsed=%d", hr, clientsUsed);
        }
    }

    if (useDefaultResolution)
    {
        if (s_currentStreamWidth != DEFAULT_GAME_WIDTH || s_currentStreamHeight != DEFAULT_GAME_HEIGHT)
        {
            changeResolution = true;
            s_currentStreamWidth = DEFAULT_GAME_WIDTH;
            s_currentStreamHeight = DEFAULT_GAME_HEIGHT;
        }
    }

    if (changeResolution)
    {
        // Update the stream to the new resolution.
        HRESULT hr = XGameStreamingSetResolution(s_currentStreamWidth, s_currentStreamHeight);
        if (SUCCEEDED(hr))
        {
            // Update the game to render at the new resolution.
        }
        else
        {
            LogFormat(L"XGameStreamingSetResolution failed %x", hr);
        }
    }
}

```

## Requisitos

**Cabeçalho:** xgamestreaming.h\
**Biblioteca:** xgameruntime.lib\
**Plataformas com suporte:** Windows, consoles da família XBOX One e consoles XBOX Series

## Confira também

[XGameStreaming](/pt-BR/reference/system/xgamestreaming/xgamestreaming_members)\
[XGameStreamingDisplayDetails](/pt-BR/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails)\
[XGameStreamingGetDisplayDetails](/pt-BR/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails)\
[Visão geral da resolução personalizada](/pt-BR/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)


## Related topics

- [XGameStreamingSetResolution](/reference/system/xgamestreaming/functions/xgamestreamingsetresolution.md)
- [Best Practices for Game Streaming Custom Resolution](/build/core-features/common/game-streaming/game-streaming-custom-resolution-best-practices.md)
- [Custom Resolution Overview](/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview.md)
- [XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members.md)
- [Testing With Custom Resolution](/build/core-features/common/game-streaming/game-streaming-testing-custom-resolution.md)
