Skip to content

Commit b5345ea

Browse files
WebGPU: Added macOS backing size auto-detection in swap chain configuration
1 parent 3d5f697 commit b5345ea

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Graphics/GraphicsEngineWebGPU/src/SwapChainWebGPUImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2025 Diligent Graphics LLC
2+
* Copyright 2023-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -262,6 +262,8 @@ void SwapChainWebGPUImpl::ConfigureSurface()
262262

263263
m_SwapChainDesc.Width = WindowRect.right - WindowRect.left;
264264
m_SwapChainDesc.Height = WindowRect.bottom - WindowRect.top;
265+
#elif PLATFORM_MACOS
266+
m_NativeWindow.GetBackingSize(m_SwapChainDesc.Width, m_SwapChainDesc.Height);
265267
#elif PLATFORM_WEB
266268
int32_t CanvasWidth = 0;
267269
int32_t CanvasHeight = 0;

Platforms/Apple/interface/MacOSNativeWindow.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@
2828
#pragma once
2929

3030
#include "../../../Primitives/interface/CommonDefinitions.h"
31+
#include "../../../Primitives/interface/BasicTypes.h"
3132

3233
DILIGENT_BEGIN_NAMESPACE(Diligent)
3334

@@ -44,6 +45,8 @@ struct MacOSNativeWindow
4445
{}
4546

4647
void* GetLayer() const;
48+
49+
void GetBackingSize(Uint32& Width, Uint32& Height) const;
4750
#endif
4851
};
4952

Platforms/Apple/src/MacOSNativeWindow.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "MacOSNativeWindow.h"
26+
#include "BasicTypes.h"
2627

2728
#import <AppKit/AppKit.h>
2829

@@ -34,4 +35,20 @@
3435
return pNSView ? (__bridge void*)((__bridge NSView*)pNSView).layer : nullptr;
3536
}
3637

38+
void MacOSNativeWindow::GetBackingSize(Uint32& Width, Uint32& Height) const
39+
{
40+
if (pNSView)
41+
{
42+
NSView* nsView = (__bridge NSView*)pNSView;
43+
NSRect viewRectPixels = [nsView convertRectToBacking:[nsView bounds]];
44+
Width = static_cast<Uint32>(viewRectPixels.size.width);
45+
Height = static_cast<Uint32>(viewRectPixels.size.height);
46+
}
47+
else
48+
{
49+
Width = 0;
50+
Height = 0;
51+
}
52+
}
53+
3754
} // namespace Diligent

0 commit comments

Comments
 (0)