kodi
WinSystemOSX.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "threads/CriticalSection.h"
12 #include "threads/SystemClock.h"
13 #include "threads/Timer.h"
14 #include "windowing/WinSystem.h"
15 
16 #include <memory>
17 #include <optional>
18 #include <string>
19 #include <vector>
20 
21 typedef struct _CGLContextObject* CGLContextObj;
22 typedef struct CGRect NSRect;
23 class IDispResource;
24 class CWinEventsOSX;
25 #ifdef __OBJC__
26 @class NSWindowController;
27 @class NSWindow;
28 @class OSXGLView;
29 @class NSEvent;
30 #else
31 struct NSWindow;
32 struct OSXGLView;
33 struct NSEvent;
34 struct NSWindowController;
35 
36 #endif
37 
39 {
40 public:
41  CWinSystemOSX();
42  ~CWinSystemOSX() override;
43 
45  {
46  bool interlaced{false};
47  size_t resWidth{0};
48  size_t resHeight{0};
49  size_t pixelWidth{0};
50  size_t pixelHeight{0};
51  double refreshrate{0.0};
52  };
53 
54  // ITimerCallback interface
55  void OnTimeout() override;
56 
57  // CWinSystemBase
58  bool InitWindowSystem() override;
59  bool DestroyWindowSystem() override;
60  bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) override;
61  bool DestroyWindow() override;
62  bool ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) override;
63  bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) override;
64  void UpdateResolutions() override;
65  bool Minimize() override;
66  bool Restore() override;
67  bool Hide() override;
68  bool HasCursor() override;
69  bool Show(bool raise = true) override;
70  unsigned int GetScreenId(const std::string& screen) override;
71  void MoveToScreen(unsigned int screenIdx) override;
72  void OnMove(int x, int y) override;
73  void OnChangeScreen(unsigned int screenIdx) override;
74  bool HasValidResolution() const;
75 
76  std::string GetClipboardText() override;
77 
78  void Register(IDispResource* resource) override;
79  void Unregister(IDispResource* resource) override;
80 
81  std::unique_ptr<CVideoSync> GetVideoSync(CVideoReferenceClock* clock) override;
82 
83  void WindowChangedScreen();
84 
85  void AnnounceOnLostDevice();
86  void AnnounceOnResetDevice();
87  void HandleOnResetDevice();
88  void StartLostDeviceTimer();
89  void StopLostDeviceTimer();
90 
91  int CheckDisplayChanging(uint32_t flags);
92  void SetFullscreenWillToggle(bool toggle) { m_fullscreenWillToggle = toggle; }
93  bool GetFullscreenWillToggle() { return m_fullscreenWillToggle; }
94  void SignalFullScreenStateChanged(bool fullscreenState);
95 
96  CGLContextObj GetCGLContextObj();
97 
98  std::vector<std::string> GetConnectedOutputs() override;
99 
100  // winevents override
101  bool MessagePump() override;
102 
103  NSRect GetWindowDimensions();
104  void enableInputEvents();
105  void disableInputEvents();
106 
107  void signalMouseEntered();
108  void signalMouseExited();
109  void SendInputEvent(NSEvent* nsEvent);
110 
111 protected:
112  std::unique_ptr<KODI::WINDOWING::IOSScreenSaver> GetOSScreenSaverImpl() override;
113 
114  ScreenResolution GetScreenResolution(unsigned long screenIdx);
115  void EnableVSync(bool enable);
116  bool SwitchToVideoMode(RESOLUTION_INFO& res);
117  void FillInVideoModes();
118  bool FlushBuffer();
119 
120  bool DestroyWindowInternal();
121 
122  std::unique_ptr<CWinEventsOSX> m_winEvents;
123 
124  std::string m_name;
125  NSWindow* m_appWindow;
126  OSXGLView* m_glView;
127  unsigned long m_lastDisplayNr;
128  double m_refreshRate;
129 
130  CCriticalSection m_resourceSection;
131  std::vector<IDispResource*> m_resources;
132  CTimer m_lostDeviceTimer;
133  bool m_delayDispReset;
134  XbmcThreads::EndTime<> m_dispResetTimer;
135  bool m_fullscreenWillToggle;
136  bool m_hasCursor{false};
138  std::optional<unsigned long> m_fullScreenMovingToScreen;
139  CCriticalSection m_critSection;
140 
141 private:
142  NSWindowController* m_appWindowController;
143 };
Definition: WinEventsOSX.h:20
std::optional< unsigned long > m_fullScreenMovingToScreen
Set while moving the fullscreen window to another screen. Stores the target screen id...
Definition: WinSystemOSX.h:138
Definition: WinSystemOSX.h:38
Definition: WinSystem.h:49
void MoveToScreen(unsigned int screenIdx) override
Window was requested to move to the given screen.
Definition: WinSystemOSX.mm:1253
Definition: SystemClock.h:31
Definition: OSXGLView.h:13
Definition: Timer.h:25
unsigned int GetScreenId(const std::string &screen) override
Get the screen ID provided the screen name.
Definition: WinSystemOSX.mm:1248
Definition: DispResource.h:14
Provide info of a resolution.
Definition: Resolution.h:66
Definition: WinSystemOSX.h:44
Definition: VideoReferenceClock.h:19
void OnChangeScreen(unsigned int screenIdx) override
Used to signal the windowing system about the change of the current screen.
Definition: WinSystemOSX.mm:1231
Definition: Timer.h:17