> ## 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

ストリームの解像度を設定します。

## Syntax

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

### Parameters

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

ストリームの解像度に設定する幅。

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

ストリームの解像度に設定する高さ。

### Return value

型: HRESULT

成功した場合は **S\_OK** を返します。それ以外の場合はエラー コードを返します。

#### 想定されるエラー

| エラー コード                            | エラー値       | エラーの理由                                                                              |
| ---------------------------------- | ---------- | ----------------------------------------------------------------------------------- |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | XGameStreaming ランタイムが初期化されていません。他の API を呼び出す前に XGameStreamingInitialize を呼び出してください。 |
| E\_INVALIDARG                      | 0x80070057 | *width* および/または *height* パラメーターやハードウェアが要件を満たしていませんでした。                              |

エラー コードの一覧については、[Error Codes](/reference/errorcodes) を参照してください。

## Remarks

非標準の解像度でのこの API は、XBOX Game Streaming サーバー、XBOX Series X Dev Kit、および XBOX Series S Test Kit でのみ成功します。720p や 1080p などの標準解像度は、ハードウェアに関係なく成功します。理由は、リテールの XBOX はリモート プレイ経由でのみストリーミングでき、テレビへの映像出力が継続する可能性があるため、非標準の解像度を使用すると歪んだ映像になるからです。

幅と高さは最低 640x360 であり、最大値は [XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails) から取得できる [XGameStreamingDisplayDetails](/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails) の `maxWidth` および `maxHeight` フィールドで確認できます。

`width` \* `height` から計算される最大ピクセル数は、エンコーダーの上限以下である必要があります。上限は [XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails) API を使用して確認できます。この値は将来引き上げられる可能性があります。

`width` と `height` は 8 で割り切れる必要があります。

この API は必要な頻度で呼び出せますが、ストリームの解像度は 200ms ごとに 1 回しか変更できません。その 200ms のウィンドウ内で行われたすべての呼び出しのうち、最後の解像度がウィンドウの経過後に適用されます。

この API は接続されているすべてのクライアントのストリームの解像度を設定する点に注意してください。つまり、複数のクライアントが接続されている場合にゲームにとって最適な選択肢を判断するには、特別な考慮が必要です。標準の 16:9 の解像度を使用する場合もあれば、すべてのクライアントに最も適した解像度を探そうとする場合もあります。

<Note>ストリームの解像度を変更すると、ID3D12CommandQueue::PresentX でのビュー矩形のスケーリングが変更されます。D3D12XBOX\_PRESENT\_PLANE\_PARAMETERS.pDestPlacementBase の 0.0～1.0 のスケール係数は、通常参照される標準的な 1920x1080 または 3840x2160 の解像度ではなく、XGameStreamingSetResolution に渡された高さと幅を参照するようになります。</Note>

## Example

```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);
        }
    }
}

```

## Requirements

**ヘッダー:** xgamestreaming.h\
**ライブラリ:** xgameruntime.lib\
**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members)\
[XGameStreamingDisplayDetails](/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails)\
[XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails)\
[Custom Resolution Overview](/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)


## Related topics

- [XGameStreamingGetDisplayDetails](/ja-jp/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails.md)
- [XGameStreaming](/ja-jp/reference/system/xgamestreaming/xgamestreaming_members.md)
- [ゲーム ストリーミングにおけるカスタム解像度のベスト プラクティス](/ja-jp/build/core-features/common/game-streaming/game-streaming-custom-resolution-best-practices.md)
- [カスタム解像度の概要](/ja-jp/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview.md)
- [XGameStreamingVideoFlags](/ja-jp/reference/system/xgamestreaming/enums/xgamestreamingvideoflags.md)
