From ad380a32f4a4b9fbf61d16c005a4c6b422566ed0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 May 2022 19:13:31 +0900 Subject: [PATCH] internal/glfwwin: split GDK part to a new package internal/microsoftgdk Updates #1162 --- internal/glfwwin/wglcontext_windows.go | 4 +++- internal/glfwwin/win32init_windows.go | 10 ++++++---- internal/glfwwin/win32monitor_windows.go | 14 ++++++++------ internal/glfwwin/win32window_windows.go | 16 +++++++++------- internal/graphicsdriver/opengl/graphics.go | 4 ++++ internal/{glfwwin => microsoftgdk}/dummy.c | 0 .../microsoftgdk_windows.go | 6 +++--- .../notmicrosoftgdk.go} | 12 ++++++------ 8 files changed, 39 insertions(+), 27 deletions(-) rename internal/{glfwwin => microsoftgdk}/dummy.c (100%) rename internal/{glfwwin => microsoftgdk}/microsoftgdk_windows.go (96%) rename internal/{glfwwin/notmicrosoftgdk_windows.go => microsoftgdk/notmicrosoftgdk.go} (72%) diff --git a/internal/glfwwin/wglcontext_windows.go b/internal/glfwwin/wglcontext_windows.go index 1d597eb53..78fff324e 100644 --- a/internal/glfwwin/wglcontext_windows.go +++ b/internal/glfwwin/wglcontext_windows.go @@ -9,6 +9,8 @@ import ( "fmt" "strings" "unsafe" + + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" ) func findPixelFormatAttribValue(attribs []int32, values []int32, attrib int32) int32 { @@ -329,7 +331,7 @@ func destroyContextWGL(window *Window) error { } func initWGL() error { - if isXbox() { + if microsoftgdk.IsXbox() { return fmt.Errorf("glfwwin: WGL is not available in Xbox") } diff --git a/internal/glfwwin/win32init_windows.go b/internal/glfwwin/win32init_windows.go index 7052bd819..092728ee3 100644 --- a/internal/glfwwin/win32init_windows.go +++ b/internal/glfwwin/win32init_windows.go @@ -10,6 +10,8 @@ import ( "unsafe" "golang.org/x/sys/windows" + + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" ) func createKeyTables() { @@ -168,7 +170,7 @@ func createHelperWindow() error { _ShowWindow(_glfw.win32.helperWindowHandle, _SW_HIDE) // Register for HID device notifications - if !isXbox() { + if !microsoftgdk.IsXbox() { _GUID_DEVINTERFACE_HID := windows.GUID{ Data1: 0x4d1e55b2, Data2: 0xf16f, @@ -238,7 +240,7 @@ func platformInit() error { createKeyTables() if isWindows10CreatorsUpdateOrGreaterWin32() { - if !isXbox() { + if !microsoftgdk.IsXbox() { if err := _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) { return err } @@ -258,10 +260,10 @@ func platformInit() error { if err := createHelperWindow(); err != nil { return err } - if isXbox() { + if microsoftgdk.IsXbox() { // On Xbox, APIs to get monitors are not available. // Create a pseudo monitor instance instead. - w, h := monitorResolution() + w, h := microsoftgdk.MonitorResolution() mode := &VidMode{ Width: w, Height: h, diff --git a/internal/glfwwin/win32monitor_windows.go b/internal/glfwwin/win32monitor_windows.go index db907900e..f17345cc3 100644 --- a/internal/glfwwin/win32monitor_windows.go +++ b/internal/glfwwin/win32monitor_windows.go @@ -10,6 +10,8 @@ import ( "unsafe" "golang.org/x/sys/windows" + + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" ) func monitorCallback(handle _HMONITOR, dc _HDC, rect *_RECT, monitor *Monitor /* _LPARAM */) uintptr /* _BOOL */ { @@ -66,7 +68,7 @@ func createMonitor(adapter *_DISPLAY_DEVICEW, display *_DISPLAY_DEVICEW) (*Monit } func pollMonitorsWin32() error { - if isXbox() { + if microsoftgdk.IsXbox() { return nil } @@ -234,7 +236,7 @@ func getMonitorContentScaleWin32(handle _HMONITOR) (xscale, yscale float32, err } func (m *Monitor) platformGetMonitorPos() (xpos, ypos int, ok bool) { - if isXbox() { + if microsoftgdk.IsXbox() { return 0, 0, true } @@ -246,7 +248,7 @@ func (m *Monitor) platformGetMonitorPos() (xpos, ypos int, ok bool) { } func (m *Monitor) platformGetMonitorContentScale() (xscale, yscale float32, err error) { - if isXbox() { + if microsoftgdk.IsXbox() { return 1, 1, nil } @@ -254,8 +256,8 @@ func (m *Monitor) platformGetMonitorContentScale() (xscale, yscale float32, err } func (m *Monitor) platformGetMonitorWorkarea() (xpos, ypos, width, height int) { - if isXbox() { - w, h := monitorResolution() + if microsoftgdk.IsXbox() { + w, h := microsoftgdk.MonitorResolution() return 0, 0, w, h } @@ -320,7 +322,7 @@ loop: } func (m *Monitor) platformGetVideoMode() *VidMode { - if isXbox() { + if microsoftgdk.IsXbox() { return m.modes[0] } diff --git a/internal/glfwwin/win32window_windows.go b/internal/glfwwin/win32window_windows.go index 3dee1c492..01a209ceb 100644 --- a/internal/glfwwin/win32window_windows.go +++ b/internal/glfwwin/win32window_windows.go @@ -13,6 +13,8 @@ import ( "unsafe" "golang.org/x/sys/windows" + + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" ) func (w *Window) getWindowStyle() uint32 { @@ -122,7 +124,7 @@ func createIcon(image *Image, xhot, yhot int, icon bool) (_HICON, error) { } func getFullWindowSize(style uint32, exStyle uint32, contentWidth, contentHeight int, dpi uint32) (fullWidth, fullHeight int, err error) { - if isXbox() { + if microsoftgdk.IsXbox() { return contentWidth, contentHeight, nil } @@ -718,7 +720,7 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) scancode := uint32((_HIWORD(uint32(lParam)) & (_KF_EXTENDED | 0xff))) if scancode == 0 { - if isXbox() { + if microsoftgdk.IsXbox() { break } // NOTE: Some synthetic key messages have a scancode of zero @@ -1215,7 +1217,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er handleToWindow[w.win32.handle] = w - if !isXbox() && _IsWindows7OrGreater() { + if !microsoftgdk.IsXbox() && _IsWindows7OrGreater() { if err := _ChangeWindowMessageFilterEx(w.win32.handle, _WM_DROPFILES, _MSGFLT_ALLOW, nil); err != nil { return err } @@ -1232,7 +1234,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er // Adjust window rect to account for DPI scaling of the window frame and // (if enabled) DPI scaling of the content area // This cannot be done until we know what monitor the window was placed on - if !isXbox() && w.monitor == nil { + if !microsoftgdk.IsXbox() && w.monitor == nil { rect := _RECT{ left: 0, top: 0, @@ -1298,7 +1300,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er } } - if !isXbox() { + if !microsoftgdk.IsXbox() { _DragAcceptFiles(w.win32.handle, true) } @@ -1343,7 +1345,7 @@ func registerWindowClassWin32() error { // In the original GLFW implementation, an embedded resource GLFW_ICON is used if possible. // See https://www.glfw.org/docs/3.3/group__window.html - if !isXbox() { + if !microsoftgdk.IsXbox() { icon, err := _LoadImageW(0, _IDI_APPLICATION, _IMAGE_ICON, 0, 0, _LR_DEFAULTSIZE|_LR_SHARED) if err != nil { return err @@ -2129,7 +2131,7 @@ func (c *Cursor) platformCreateCursor(image *Image, xhot, yhot int) error { } func (c *Cursor) platformCreateStandardCursor(shape StandardCursor) error { - if isXbox() { + if microsoftgdk.IsXbox() { return nil } diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index 92b2e2c2a..2c86ff7fe 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -19,12 +19,16 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/graphics" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" "github.com/hajimehoshi/ebiten/v2/internal/shaderir" ) var theGraphics Graphics func Get() *Graphics { + if microsoftgdk.IsXbox() { + return nil + } return &theGraphics } diff --git a/internal/glfwwin/dummy.c b/internal/microsoftgdk/dummy.c similarity index 100% rename from internal/glfwwin/dummy.c rename to internal/microsoftgdk/dummy.c diff --git a/internal/glfwwin/microsoftgdk_windows.go b/internal/microsoftgdk/microsoftgdk_windows.go similarity index 96% rename from internal/glfwwin/microsoftgdk_windows.go rename to internal/microsoftgdk/microsoftgdk_windows.go index f23b6e4a8..c419f1c91 100644 --- a/internal/glfwwin/microsoftgdk_windows.go +++ b/internal/microsoftgdk/microsoftgdk_windows.go @@ -15,7 +15,7 @@ //go:build microsoftgdk // +build microsoftgdk -package glfwwin +package microsoftgdk // Unfortunately, some functions like XSystemGetDeviceType is not implemented in a DLL, // so LoadLibrary is not available. @@ -40,12 +40,12 @@ const ( _XSystemDeviceType_XboxScarlettDevkit = 0x08 ) -func isXbox() bool { +func IsXbox() bool { t := C.XSystemGetDeviceType() return t != _XSystemDeviceType_Unknown && t != _XSystemDeviceType_Pc } -func monitorResolution() (int, int) { +func MonitorResolution() (int, int) { switch C.XSystemGetDeviceType() { case _XSystemDeviceType_XboxOne, _XSystemDeviceType_XboxOneS: return 1920, 1080 diff --git a/internal/glfwwin/notmicrosoftgdk_windows.go b/internal/microsoftgdk/notmicrosoftgdk.go similarity index 72% rename from internal/glfwwin/notmicrosoftgdk_windows.go rename to internal/microsoftgdk/notmicrosoftgdk.go index 469a27329..f255e4b50 100644 --- a/internal/glfwwin/notmicrosoftgdk_windows.go +++ b/internal/microsoftgdk/notmicrosoftgdk.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !microsoftgdk -// +build !microsoftgdk +//go:build !windows || !microsoftgdk +// +build !windows !microsoftgdk -package glfwwin +package microsoftgdk -func isXbox() bool { +func IsXbox() bool { return false } -func monitorResolution() (int, int) { - panic("glfwwin: monitorResolution is not implemented in this environment") +func MonitorResolution() (int, int) { + panic("microsoftgdk: MonitorResolution is not implemented in this environment") }