diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/windowing/ios | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/windowing/ios')
-rw-r--r-- | xbmc/windowing/ios/CMakeLists.txt | 8 | ||||
-rw-r--r-- | xbmc/windowing/ios/VideoSyncIos.cpp | 95 | ||||
-rw-r--r-- | xbmc/windowing/ios/VideoSyncIos.h | 43 | ||||
-rw-r--r-- | xbmc/windowing/ios/WinEventsIOS.h | 20 | ||||
-rw-r--r-- | xbmc/windowing/ios/WinEventsIOS.mm | 55 | ||||
-rw-r--r-- | xbmc/windowing/ios/WinSystemIOS.h | 97 | ||||
-rw-r--r-- | xbmc/windowing/ios/WinSystemIOS.mm | 501 |
7 files changed, 819 insertions, 0 deletions
diff --git a/xbmc/windowing/ios/CMakeLists.txt b/xbmc/windowing/ios/CMakeLists.txt new file mode 100644 index 0000000..0cdd0d6 --- /dev/null +++ b/xbmc/windowing/ios/CMakeLists.txt @@ -0,0 +1,8 @@ +set(SOURCES WinEventsIOS.mm + WinSystemIOS.mm + VideoSyncIos.cpp) +set(HEADERS WinEventsIOS.h + WinSystemIOS.h + VideoSyncIos.h) + +core_add_library(windowing_ios) diff --git a/xbmc/windowing/ios/VideoSyncIos.cpp b/xbmc/windowing/ios/VideoSyncIos.cpp new file mode 100644 index 0000000..a3cac13 --- /dev/null +++ b/xbmc/windowing/ios/VideoSyncIos.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "VideoSyncIos.h" + +#include "cores/VideoPlayer/VideoReferenceClock.h" +#include "utils/MathUtils.h" +#include "utils/TimeUtils.h" +#include "utils/log.h" +#include "windowing/GraphicContext.h" +#include "windowing/ios/WinSystemIOS.h" + +bool CVideoSyncIos::Setup(PUPDATECLOCK func) +{ + CLog::Log(LOGDEBUG, "CVideoSyncIos::{} setting up OSX", __FUNCTION__); + + //init the vblank timestamp + m_LastVBlankTime = CurrentHostCounter(); + UpdateClock = func; + m_abortEvent.Reset(); + + bool setupOk = InitDisplayLink(); + if (setupOk) + { + m_winSystem.Register(this); + } + + return setupOk; +} + +void CVideoSyncIos::Run(CEvent& stopEvent) +{ + //because cocoa has a vblank callback, we just keep sleeping until we're asked to stop the thread + XbmcThreads::CEventGroup waitGroup{&stopEvent, &m_abortEvent}; + waitGroup.wait(); +} + +void CVideoSyncIos::Cleanup() +{ + CLog::Log(LOGDEBUG, "CVideoSyncIos::{} cleaning up OSX", __FUNCTION__); + DeinitDisplayLink(); + m_winSystem.Unregister(this); +} + +float CVideoSyncIos::GetFps() +{ + m_fps = CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS(); + CLog::Log(LOGDEBUG, "CVideoSyncIos::{} Detected refreshrate: {:f} hertz", __FUNCTION__, m_fps); + return m_fps; +} + +void CVideoSyncIos::OnResetDisplay() +{ + m_abortEvent.Set(); +} + +void CVideoSyncIos::IosVblankHandler() +{ + int NrVBlanks; + double VBlankTime; + int64_t nowtime = CurrentHostCounter(); + + //calculate how many vblanks happened + VBlankTime = (double)(nowtime - m_LastVBlankTime) / (double)CurrentHostFrequency(); + NrVBlanks = MathUtils::round_int(VBlankTime * static_cast<double>(m_fps)); + + //save the timestamp of this vblank so we can calculate how many happened next time + m_LastVBlankTime = nowtime; + + //update the vblank timestamp, update the clock and send a signal that we got a vblank + UpdateClock(NrVBlanks, nowtime, m_refClock); +} + +bool CVideoSyncIos::InitDisplayLink() +{ + bool ret = true; + CLog::Log(LOGDEBUG, "CVideoSyncIos: setting up displaylink"); + if (!m_winSystem.InitDisplayLink(this)) + { + CLog::Log(LOGDEBUG, "CVideoSyncIos: InitDisplayLink failed"); + ret = false; + } + return ret; +} + +void CVideoSyncIos::DeinitDisplayLink() +{ + m_winSystem.DeinitDisplayLink(); +} + diff --git a/xbmc/windowing/ios/VideoSyncIos.h b/xbmc/windowing/ios/VideoSyncIos.h new file mode 100644 index 0000000..0828e34 --- /dev/null +++ b/xbmc/windowing/ios/VideoSyncIos.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "guilib/DispResource.h" +#include "windowing/VideoSync.h" + +class CWinSystemIOS; + +class CVideoSyncIos : public CVideoSync, IDispResource +{ +public: + CVideoSyncIos(void *clock, CWinSystemIOS &winSystem) : + CVideoSync(clock), m_winSystem(winSystem) {} + + // CVideoSync interface + bool Setup(PUPDATECLOCK func) override; + void Run(CEvent& stopEvent) override; + void Cleanup() override; + float GetFps() override; + + // IDispResource interface + void OnResetDisplay() override; + + // used in the displaylink callback + void IosVblankHandler(); + +private: + // CVideoSyncDarwin interface + virtual bool InitDisplayLink(); + virtual void DeinitDisplayLink(); + + int64_t m_LastVBlankTime = 0; //timestamp of the last vblank, used for calculating how many vblanks happened + CEvent m_abortEvent; + CWinSystemIOS &m_winSystem; +}; + diff --git a/xbmc/windowing/ios/WinEventsIOS.h b/xbmc/windowing/ios/WinEventsIOS.h new file mode 100644 index 0000000..98ec4dc --- /dev/null +++ b/xbmc/windowing/ios/WinEventsIOS.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2012-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "windowing/WinEvents.h" + +class CWinEventsIOS : public IWinEvents +{ +public: + bool MessagePump() override; +private: + size_t GetQueueSize(); +}; + diff --git a/xbmc/windowing/ios/WinEventsIOS.mm b/xbmc/windowing/ios/WinEventsIOS.mm new file mode 100644 index 0000000..ec416a6 --- /dev/null +++ b/xbmc/windowing/ios/WinEventsIOS.mm @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "WinEventsIOS.h" + +#include "application/AppInboundProtocol.h" +#include "guilib/GUIWindowManager.h" +#include "input/InputManager.h" +#include "input/XBMC_vkeys.h" +#include "threads/CriticalSection.h" +#include "utils/log.h" + +#include <list> +#include <mutex> + +static CCriticalSection g_inputCond; + +static std::list<XBMC_Event> events; + +bool CWinEventsIOS::MessagePump() +{ + bool ret = false; + std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort(); + + // Do not always loop, only pump the initial queued count events. else if ui keep pushing + // events the loop won't finish then it will block xbmc main message loop. + for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) + { + // Pop up only one event per time since in App::OnEvent it may init modal dialog which init + // deeper message loop and call the deeper MessagePump from there. + XBMC_Event pumpEvent; + { + std::unique_lock<CCriticalSection> lock(g_inputCond); + if (events.empty()) + return ret; + pumpEvent = events.front(); + events.pop_front(); + } + + if (appPort) + ret = appPort->OnEvent(pumpEvent); + } + return ret; +} + +size_t CWinEventsIOS::GetQueueSize() +{ + std::unique_lock<CCriticalSection> lock(g_inputCond); + return events.size(); +} diff --git a/xbmc/windowing/ios/WinSystemIOS.h b/xbmc/windowing/ios/WinSystemIOS.h new file mode 100644 index 0000000..8320b60 --- /dev/null +++ b/xbmc/windowing/ios/WinSystemIOS.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "rendering/gles/RenderSystemGLES.h" +#include "threads/CriticalSection.h" +#include "windowing/WinSystem.h" + +#include <string> +#include <vector> + +#include <CoreVideo/CVOpenGLESTextureCache.h> + +class IDispResource; +class CVideoSyncIos; +struct CADisplayLinkWrapper; + +class CWinSystemIOS : public CWinSystemBase, public CRenderSystemGLES +{ +public: + CWinSystemIOS(); + ~CWinSystemIOS() override; + + static void Register(); + static std::unique_ptr<CWinSystemBase> CreateWinSystem(); + + int GetDisplayIndexFromSettings(); + // Implementation of CWinSystemBase + CRenderSystemBase *GetRenderSystem() override { return this; } + bool InitWindowSystem() override; + bool DestroyWindowSystem() override; + bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) override; + bool DestroyWindow() override; + bool ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) override; + bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) override; + void UpdateResolutions() override; + bool CanDoWindowed() override { return false; } + + void ShowOSMouse(bool show) override {} + bool HasCursor() override; + + void NotifyAppActiveChange(bool bActivated) override; + + bool Minimize() override; + bool Restore() override; + bool Hide() override; + bool Show(bool raise = true) override; + + bool IsExtSupported(const char* extension) const override; + + bool BeginRender() override; + bool EndRender() override; + + void Register(IDispResource *resource) override; + void Unregister(IDispResource *resource) override; + + std::unique_ptr<CVideoSync> GetVideoSync(void* clock) override; + + std::vector<std::string> GetConnectedOutputs() override; + + bool InitDisplayLink(CVideoSyncIos *syncImpl); + void DeinitDisplayLink(void); + void OnAppFocusChange(bool focus); + bool IsBackgrounded() const { return m_bIsBackgrounded; } + CVEAGLContext GetEAGLContextObj(); + void MoveToTouchscreen(); + + // winevents override + bool MessagePump() override; + +protected: + void PresentRenderImpl(bool rendered) override; + void SetVSyncImpl(bool enable) override {} + + void *m_glView; // EAGLView opaque + void *m_WorkingContext; // shared EAGLContext opaque + bool m_bWasFullScreenBeforeMinimize; + std::string m_eglext; + CCriticalSection m_resourceSection; + std::vector<IDispResource*> m_resources; + bool m_bIsBackgrounded; + +private: + bool GetScreenResolution(int* w, int* h, double* fps, int screenIdx); + void FillInVideoModes(int screenIdx); + bool SwitchToVideoMode(int width, int height, double refreshrate); + CADisplayLinkWrapper *m_pDisplayLink; + int m_internalTouchscreenResolutionWidth = -1; + int m_internalTouchscreenResolutionHeight = -1; +}; + diff --git a/xbmc/windowing/ios/WinSystemIOS.mm b/xbmc/windowing/ios/WinSystemIOS.mm new file mode 100644 index 0000000..805c573 --- /dev/null +++ b/xbmc/windowing/ios/WinSystemIOS.mm @@ -0,0 +1,501 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "WinSystemIOS.h" + +#include "ServiceBroker.h" +#include "VideoSyncIos.h" +#include "WinEventsIOS.h" +#include "cores/AudioEngine/Sinks/AESinkDARWINIOS.h" +#include "cores/RetroPlayer/process/ios/RPProcessInfoIOS.h" +#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGLES.h" +#include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h" +#include "cores/VideoPlayer/DVDCodecs/Video/VTB.h" +#include "cores/VideoPlayer/Process/ios/ProcessInfoIOS.h" +#include "cores/VideoPlayer/VideoRenderers/HwDecRender/RendererVTBGLES.h" +#include "cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h" +#include "cores/VideoPlayer/VideoRenderers/RenderFactory.h" +#include "filesystem/SpecialProtocol.h" +#include "guilib/DispResource.h" +#include "guilib/Texture.h" +#include "messaging/ApplicationMessenger.h" +#include "rendering/gles/ScreenshotSurfaceGLES.h" +#include "settings/DisplaySettings.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" +#include "utils/StringUtils.h" +#include "utils/log.h" +#include "windowing/GraphicContext.h" +#include "windowing/WindowSystemFactory.h" + +#import "platform/darwin/ios/IOSScreenManager.h" +#import "platform/darwin/ios/XBMCController.h" + +#include <mutex> +#include <vector> + +#import <Foundation/Foundation.h> +#import <OpenGLES/ES2/gl.h> +#import <OpenGLES/ES2/glext.h> +#import <QuartzCore/CADisplayLink.h> +#import <dlfcn.h> + +#define CONST_TOUCHSCREEN "Touchscreen" +#define CONST_EXTERNAL "External" + +// IOSDisplayLinkCallback is declared in the lower part of the file +@interface IOSDisplayLinkCallback : NSObject +{ +@private CVideoSyncIos *_videoSyncImpl; +} +@property (nonatomic, setter=SetVideoSyncImpl:) CVideoSyncIos *_videoSyncImpl; +- (void) runDisplayLink; +@end + +using namespace KODI; +using namespace MESSAGING; + +struct CADisplayLinkWrapper +{ + CADisplayLink* impl; + IOSDisplayLinkCallback *callbackClass; +}; + +void CWinSystemIOS::Register() +{ + KODI::WINDOWING::CWindowSystemFactory::RegisterWindowSystem(CreateWinSystem); +} + +std::unique_ptr<CWinSystemBase> CWinSystemIOS::CreateWinSystem() +{ + return std::make_unique<CWinSystemIOS>(); +} + +int CWinSystemIOS::GetDisplayIndexFromSettings() +{ + std::string currentScreen = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_VIDEOSCREEN_MONITOR); + + int screenIdx = 0; + if (currentScreen == CONST_EXTERNAL) + { + if ([[UIScreen screens] count] > 1) + { + screenIdx = 1; + } + else// screen 1 is setup but not connected + { + // force internal screen + MoveToTouchscreen(); + } + } + + return screenIdx; +} + +CWinSystemIOS::CWinSystemIOS() : CWinSystemBase() +{ + m_bIsBackgrounded = false; + m_pDisplayLink = new CADisplayLinkWrapper; + m_pDisplayLink->callbackClass = [[IOSDisplayLinkCallback alloc] init]; + m_winEvents.reset(new CWinEventsIOS()); + + CAESinkDARWINIOS::Register(); +} + +CWinSystemIOS::~CWinSystemIOS() +{ + delete m_pDisplayLink; +} + +bool CWinSystemIOS::InitWindowSystem() +{ + return CWinSystemBase::InitWindowSystem(); +} + +bool CWinSystemIOS::DestroyWindowSystem() +{ + return true; +} + +bool CWinSystemIOS::CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) +{ + //NSLog(@"%s", __PRETTY_FUNCTION__); + + if(!SetFullScreen(fullScreen, res, false)) + return false; + + [g_xbmcController setFramebuffer]; + + m_bWindowCreated = true; + + m_eglext = " "; + + const char *tmpExtensions = (const char*) glGetString(GL_EXTENSIONS); + if (tmpExtensions != NULL) + { + m_eglext += tmpExtensions; + } + + m_eglext += " "; + + CLog::Log(LOGDEBUG, "EGL_EXTENSIONS:{}", m_eglext); + + // register platform dependent objects + CDVDFactoryCodec::ClearHWAccels(); + VTB::CDecoder::Register(); + VIDEOPLAYER::CRendererFactory::ClearRenderer(); + CLinuxRendererGLES::Register(); + CRendererVTB::Register(); + VIDEOPLAYER::CProcessInfoIOS::Register(); + RETRO::CRPProcessInfoIOS::Register(); + RETRO::CRPProcessInfoIOS::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGLES); + CScreenshotSurfaceGLES::Register(); + + return true; +} + +bool CWinSystemIOS::DestroyWindow() +{ + return true; +} + +bool CWinSystemIOS::ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) +{ + //NSLog(@"%s", __PRETTY_FUNCTION__); + + if (m_nWidth != newWidth || m_nHeight != newHeight) + { + m_nWidth = newWidth; + m_nHeight = newHeight; + } + + CRenderSystemGLES::ResetRenderSystem(newWidth, newHeight); + + return true; +} + +bool CWinSystemIOS::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) +{ + //NSLog(@"%s", __PRETTY_FUNCTION__); + + m_nWidth = res.iWidth; + m_nHeight = res.iHeight; + m_bFullScreen = fullScreen; + + CLog::Log(LOGDEBUG, "About to switch to {} x {}", m_nWidth, m_nHeight); + SwitchToVideoMode(res.iWidth, res.iHeight, static_cast<double>(res.fRefreshRate)); + CRenderSystemGLES::ResetRenderSystem(res.iWidth, res.iHeight); + + return true; +} + +UIScreenMode *getModeForResolution(int width, int height, unsigned int screenIdx) +{ + auto screen = UIScreen.screens[screenIdx]; + for (UIScreenMode* mode in screen.availableModes) + { + //for main screen also find modes where width and height are + //exchanged (because of the 90°degree rotated buildinscreens) + auto modeSize = mode.size; + if ((modeSize.width == width && modeSize.height == height) || + (screenIdx == 0 && modeSize.width == height && modeSize.height == width)) + { + CLog::Log(LOGDEBUG, "Found matching mode: {} x {}", modeSize.width, modeSize.height); + return mode; + } + } + CLog::Log(LOGERROR,"No matching mode found!"); + return nil; +} + +bool CWinSystemIOS::SwitchToVideoMode(int width, int height, double refreshrate) +{ + bool ret = false; + int screenIdx = GetDisplayIndexFromSettings(); + + //get the mode to pass to the controller + UIScreenMode *newMode = getModeForResolution(width, height, screenIdx); + + if(newMode) + { + ret = [g_xbmcController changeScreen:screenIdx withMode:newMode]; + } + return ret; +} + +bool CWinSystemIOS::GetScreenResolution(int* w, int* h, double* fps, int screenIdx) +{ + UIScreen *screen = [[UIScreen screens] objectAtIndex:screenIdx]; + CGSize screenSize = [screen currentMode].size; + *w = screenSize.width; + *h = screenSize.height; + *fps = 0.0; + + //if current mode is 0x0 (happens with external screens which aren't active) + //then use the preferred mode + if(*h == 0 || *w ==0) + { + UIScreenMode *firstMode = [screen preferredMode]; + *w = firstMode.size.width; + *h = firstMode.size.height; + } + + // for mainscreen use the eagl bounds from xbmcController + // because mainscreen is might be 90° rotate dependend on + // the device and eagl gives the correct values in all cases. + if(screenIdx == 0) + { + // at very first start up we cache the internal screen resolution + // because when using external screens and need to go back + // to internal we are not able to determine the eagl bounds + // before we really switched back to internal + // but display settings ask for the internal resolution before + // switching. So we give the cached values back in that case. + if (m_internalTouchscreenResolutionWidth == -1 && + m_internalTouchscreenResolutionHeight == -1) + { + m_internalTouchscreenResolutionWidth = [g_xbmcController getScreenSize].width; + m_internalTouchscreenResolutionHeight = [g_xbmcController getScreenSize].height; + } + + *w = m_internalTouchscreenResolutionWidth; + *h = m_internalTouchscreenResolutionHeight; + } + CLog::Log(LOGDEBUG, "Current resolution Screen: {} with {} x {}", screenIdx, *w, *h); + return true; +} + +void CWinSystemIOS::UpdateResolutions() +{ + // Add display resolution + int w, h; + double fps; + CWinSystemBase::UpdateResolutions(); + + int screenIdx = GetDisplayIndexFromSettings(); + + //first screen goes into the current desktop mode + if(GetScreenResolution(&w, &h, &fps, screenIdx)) + UpdateDesktopResolution(CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP), screenIdx == 0 ? CONST_TOUCHSCREEN : CONST_EXTERNAL, w, h, fps, 0); + + CDisplaySettings::GetInstance().ClearCustomResolutions(); + + //now just fill in the possible resolutions for the attached screens + //and push to the resolution info vector + FillInVideoModes(screenIdx); +} + +void CWinSystemIOS::FillInVideoModes(int screenIdx) +{ + // Add full screen settings for additional monitors + RESOLUTION_INFO res; + int w, h; + // atm we don't get refreshrate info from iOS + // but this may change in the future. In that case + // we will adapt this code for filling some + // useful info into this local var :) + double refreshrate = 0.0; + //screen 0 is mainscreen - 1 has to be the external one... + UIScreen *aScreen = [[UIScreen screens]objectAtIndex:screenIdx]; + //found external screen + for ( UIScreenMode *mode in [aScreen availableModes] ) + { + w = mode.size.width; + h = mode.size.height; + + UpdateDesktopResolution(res, screenIdx == 0 ? CONST_TOUCHSCREEN : CONST_EXTERNAL, w, h, refreshrate, 0); + CLog::Log(LOGINFO, "Found possible resolution for display {} with {} x {}", screenIdx, w, h); + + CServiceBroker::GetWinSystem()->GetGfxContext().ResetOverscan(res); + CDisplaySettings::GetInstance().AddResolutionInfo(res); + } +} + +bool CWinSystemIOS::IsExtSupported(const char* extension) const +{ + if(strncmp(extension, "EGL_", 4) != 0) + return CRenderSystemGLES::IsExtSupported(extension); + + std::string name; + + name = " "; + name += extension; + name += " "; + + return m_eglext.find(name) != std::string::npos; +} + +bool CWinSystemIOS::BeginRender() +{ + bool rtn; + + [g_xbmcController setFramebuffer]; + + rtn = CRenderSystemGLES::BeginRender(); + return rtn; +} + +bool CWinSystemIOS::EndRender() +{ + bool rtn; + + rtn = CRenderSystemGLES::EndRender(); + return rtn; +} + +void CWinSystemIOS::Register(IDispResource *resource) +{ + std::unique_lock<CCriticalSection> lock(m_resourceSection); + m_resources.push_back(resource); +} + +void CWinSystemIOS::Unregister(IDispResource* resource) +{ + std::unique_lock<CCriticalSection> lock(m_resourceSection); + std::vector<IDispResource*>::iterator i = find(m_resources.begin(), m_resources.end(), resource); + if (i != m_resources.end()) + m_resources.erase(i); +} + +void CWinSystemIOS::OnAppFocusChange(bool focus) +{ + std::unique_lock<CCriticalSection> lock(m_resourceSection); + m_bIsBackgrounded = !focus; + CLog::Log(LOGDEBUG, "CWinSystemIOS::OnAppFocusChange: {}", focus ? 1 : 0); + for (std::vector<IDispResource *>::iterator i = m_resources.begin(); i != m_resources.end(); i++) + (*i)->OnAppFocusChange(focus); +} + +//-------------------------------------------------------------- +//-------------------DisplayLink stuff +@implementation IOSDisplayLinkCallback +@synthesize _videoSyncImpl; +//-------------------------------------------------------------- +- (void) runDisplayLink +{ + @autoreleasepool + { + if (_videoSyncImpl != nil) + { + _videoSyncImpl->IosVblankHandler(); + } + } +} +@end + +bool CWinSystemIOS::InitDisplayLink(CVideoSyncIos *syncImpl) +{ + //init with the appropriate display link for the + //used screen + if([[IOSScreenManager sharedInstance] isExternalScreen]) + { + fprintf(stderr,"InitDisplayLink on external"); + } + else + { + fprintf(stderr,"InitDisplayLink on internal"); + } + + unsigned int currentScreenIdx = [[IOSScreenManager sharedInstance] GetScreenIdx]; + UIScreen * currentScreen = [[UIScreen screens] objectAtIndex:currentScreenIdx]; + [m_pDisplayLink->callbackClass SetVideoSyncImpl:syncImpl]; + m_pDisplayLink->impl = [currentScreen displayLinkWithTarget:m_pDisplayLink->callbackClass selector:@selector(runDisplayLink)]; + + [m_pDisplayLink->impl setPreferredFramesPerSecond:0]; + [m_pDisplayLink->impl addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; + return m_pDisplayLink->impl != nil; +} + +void CWinSystemIOS::DeinitDisplayLink(void) +{ + if (m_pDisplayLink->impl) + { + [m_pDisplayLink->impl invalidate]; + m_pDisplayLink->impl = nil; + [m_pDisplayLink->callbackClass SetVideoSyncImpl:nil]; + } +} +//------------DisplayLink stuff end +//-------------------------------------------------------------- + +void CWinSystemIOS::PresentRenderImpl(bool rendered) +{ + //glFlush; + if (rendered) + [g_xbmcController presentFramebuffer]; +} + +bool CWinSystemIOS::HasCursor() +{ + // apple touch devices + return false; +} + +void CWinSystemIOS::NotifyAppActiveChange(bool bActivated) +{ + if (bActivated && m_bWasFullScreenBeforeMinimize && !CServiceBroker::GetWinSystem()->GetGfxContext().IsFullScreenRoot()) + CServiceBroker::GetAppMessenger()->PostMsg(TMSG_TOGGLEFULLSCREEN); +} + +bool CWinSystemIOS::Minimize() +{ + m_bWasFullScreenBeforeMinimize = CServiceBroker::GetWinSystem()->GetGfxContext().IsFullScreenRoot(); + if (m_bWasFullScreenBeforeMinimize) + CServiceBroker::GetAppMessenger()->PostMsg(TMSG_TOGGLEFULLSCREEN); + + return true; +} + +bool CWinSystemIOS::Restore() +{ + return false; +} + +bool CWinSystemIOS::Hide() +{ + return true; +} + +bool CWinSystemIOS::Show(bool raise) +{ + return true; +} + +CVEAGLContext CWinSystemIOS::GetEAGLContextObj() +{ + return [g_xbmcController getEAGLContextObj]; +} + +std::vector<std::string> CWinSystemIOS::GetConnectedOutputs() +{ + std::vector<std::string> outputs; + outputs.emplace_back("Default"); + outputs.emplace_back(CONST_TOUCHSCREEN); + if ([[UIScreen screens] count] > 1) + { + outputs.emplace_back(CONST_EXTERNAL); + } + + return outputs; +} + +void CWinSystemIOS::MoveToTouchscreen() +{ + CDisplaySettings::GetInstance().SetMonitor(CONST_TOUCHSCREEN); +} + +std::unique_ptr<CVideoSync> CWinSystemIOS::GetVideoSync(void *clock) +{ + std::unique_ptr<CVideoSync> pVSync(new CVideoSyncIos(clock, *this)); + return pVSync; +} + +bool CWinSystemIOS::MessagePump() +{ + return m_winEvents->MessagePump(); +} |