From 54cd4828dfc96f31fc565ef3ae52f9a6f1a034f9 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 10 May 2014 19:08:39 +0200 Subject: [PATCH] [DEV] correct start and stop application for IOS --- external/etk | 2 +- sources/ewol/context/Context.cpp | 49 +++++++++++++++++++++++-- sources/ewol/context/Context.h | 9 +++++ sources/ewol/context/IOs/AppDelegate.mm | 10 +++++ sources/ewol/context/IOs/Context.cpp | 41 +++++++++++++++++++++ sources/ewol/context/IOs/Context.h | 6 +++ sources/ewol/context/IOs/OpenglView.h | 8 +++- sources/ewol/context/IOs/OpenglView.mm | 35 +++++++++++++++--- sources/ewol/widget/Windows.h | 4 ++ 9 files changed, 154 insertions(+), 10 deletions(-) diff --git a/external/etk b/external/etk index c6fe3295..6a3d2d12 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit c6fe3295f449ddb300cb26c51482b89626fbff7c +Subproject commit 6a3d2d129e5097a1060b05ec0a266b951c32cecb diff --git a/sources/ewol/context/Context.cpp b/sources/ewol/context/Context.cpp index 5333a95f..c75c5ea9 100644 --- a/sources/ewol/context/Context.cpp +++ b/sources/ewol/context/Context.cpp @@ -674,24 +674,67 @@ void ewol::Context::setWindows(ewol::widget::Windows* _windows) { } void ewol::Context::forceRedrawAll(void) { - if (NULL != m_windowsCurrent) { - m_windowsCurrent->calculateSize(vec2(m_windowsSize.x(), m_windowsSize.y())); + if (m_windowsCurrent == NULL) { + return; } + m_windowsCurrent->calculateSize(vec2(m_windowsSize.x(), m_windowsSize.y())); } void ewol::Context::OS_Stop(void) { - if (NULL != m_windowsCurrent) { + // set the curent interface : + lockContext(); + EWOL_INFO("OS_Stop..."); + if (m_windowsCurrent != NULL) { m_windowsCurrent->sysOnKill(); } + // release the curent interface : + unLockContext(); } void ewol::Context::OS_Suspend(void) { + // set the curent interface : + lockContext(); + EWOL_INFO("OS_Suspend..."); m_previousDisplayTime = -1; + if (m_windowsCurrent != NULL) { + m_windowsCurrent->onStateSuspend(); + } + // release the curent interface : + unLockContext(); } void ewol::Context::OS_Resume(void) { + // set the curent interface : + lockContext(); + EWOL_INFO("OS_Resume..."); m_previousDisplayTime = ewol::getTime(); m_widgetManager.periodicCallResume(m_previousDisplayTime); + if (m_windowsCurrent != NULL) { + m_windowsCurrent->onStateResume(); + } + // release the curent interface : + unLockContext(); +} +void ewol::Context::OS_Foreground(void) { + // set the curent interface : + lockContext(); + EWOL_INFO("OS_Foreground..."); + if (m_windowsCurrent != NULL) { + m_windowsCurrent->onStateForeground(); + } + // release the curent interface : + unLockContext(); +} + +void ewol::Context::OS_Background(void) { + // set the curent interface : + lockContext(); + EWOL_INFO("OS_Background..."); + if (m_windowsCurrent != NULL) { + m_windowsCurrent->onStateBackground(); + } + // release the curent interface : + unLockContext(); } diff --git a/sources/ewol/context/Context.h b/sources/ewol/context/Context.h index 1b22f110..3c9f7c86 100644 --- a/sources/ewol/context/Context.h +++ b/sources/ewol/context/Context.h @@ -121,6 +121,15 @@ namespace ewol { * @brief The current context is resumed */ virtual void OS_Resume(void); + + /** + * @brief The current context is set in foreground (framerate is maximum speed) + */ + virtual void OS_Foreground(void); + /** + * @brief The current context is set in background (framerate is slowing down (max fps)/5 # 4fps) + */ + virtual void OS_Background(void); void requestUpdateSize(void); diff --git a/sources/ewol/context/IOs/AppDelegate.mm b/sources/ewol/context/IOs/AppDelegate.mm index 665fe910..fa22f36a 100644 --- a/sources/ewol/context/IOs/AppDelegate.mm +++ b/sources/ewol/context/IOs/AppDelegate.mm @@ -37,6 +37,7 @@ NSLog(@"CREATE EWOL interface creation\n"); IOs::createInterface(); IOs::resize(currentSize.width, currentSize.height); + IOs::start(); } /* - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -50,28 +51,37 @@ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. EWOL_INFO("move windows in applicationWillResignActive"); + [glView speedSlow]; + IOs::background(); } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. EWOL_INFO("move windows in applicationDidEnterBackground"); + [glView stopDisplayLink]; + IOs::suspend(); } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. EWOL_INFO("move windows in applicationWillEnterForeground"); + IOs::resume(); + [glView startDisplayLink]; } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. EWOL_INFO("move windows in applicationDidBecomeActive"); + [glView speedNormal]; + IOs::foreground(); } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Create interface of ewol here .... EWOL_INFO("move windows in applicationWillTerminate"); + IOs::stop(); IOs::releaseInterface(); } diff --git a/sources/ewol/context/IOs/Context.cpp b/sources/ewol/context/IOs/Context.cpp index 7af92a98..6af2ac73 100644 --- a/sources/ewol/context/IOs/Context.cpp +++ b/sources/ewol/context/IOs/Context.cpp @@ -186,6 +186,47 @@ void IOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::key interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown); } +void IOs::start(void) { + if (interface == NULL) { + return; + } + //interface->OS_Start(); +} + +void IOs::resume(void) { + if (interface == NULL) { + return; + } + interface->OS_Resume(); +} + +void IOs::suspend(void) { + if (interface == NULL) { + return; + } + interface->OS_Suspend(); +} + +void IOs::stop(void) { + if (interface == NULL) { + return; + } + interface->OS_Stop(); +} +void IOs::background(void) { + if (interface == NULL) { + return; + } + interface->OS_Background(); +} +void IOs::foreground(void) { + if (interface == NULL) { + return; + } + interface->OS_Foreground(); +} + + static int l_argc = 0; static const char **l_argv = NULL; /** diff --git a/sources/ewol/context/IOs/Context.h b/sources/ewol/context/IOs/Context.h index 9cd5b3ec..11b37532 100644 --- a/sources/ewol/context/IOs/Context.h +++ b/sources/ewol/context/IOs/Context.h @@ -28,6 +28,12 @@ namespace IOs { void setInputMotion(int32_t _id, float _x, float _y); void setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey); void setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown); + void start(void); + void stop(void); + void foreground(void); + void background(void); + void resume(void); + void suspend(void); }; diff --git a/sources/ewol/context/IOs/OpenglView.h b/sources/ewol/context/IOs/OpenglView.h index ded8ad0b..7726cace 100644 --- a/sources/ewol/context/IOs/OpenglView.h +++ b/sources/ewol/context/IOs/OpenglView.h @@ -31,6 +31,12 @@ /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */ GLuint depthRenderbuffer; CGSize m_currentSize; + CADisplayLink* displayLink; //!< link to start and stop display of the view... + int deltaDisplay; + int displayCounter; } - +- (void)stopDisplayLink; +- (void)startDisplayLink; +- (void)speedSlow; +- (void)speedNormal; @end diff --git a/sources/ewol/context/IOs/OpenglView.mm b/sources/ewol/context/IOs/OpenglView.mm index 4657f1fc..66f6d32c 100644 --- a/sources/ewol/context/IOs/OpenglView.mm +++ b/sources/ewol/context/IOs/OpenglView.mm @@ -185,16 +185,41 @@ } - (void)render:(CADisplayLink*)displayLink { - IOs::draw(true); - [_context presentRenderbuffer:GL_RENDERBUFFER]; + displayCounter++; + if (displayCounter >= deltaDisplay) { + displayCounter = 0; + IOs::draw(true); + [_context presentRenderbuffer:GL_RENDERBUFFER]; + } } -- (void)setupDisplayLink { - CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)]; +- (void)speedSlow { + deltaDisplay = 5; +} + +- (void)speedNormal { + deltaDisplay = 1; +} + +- (void)startDisplayLink { + if (displayLink != NULL) { + return; + } + displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)]; [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } +- (void)stopDisplayLink { + if (displayLink == NULL) { + return; + } + [displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + displayLink = NULL; +} + - (id)initWithFrame:(CGRect)frame { + deltaDisplay = 1; + displayCounter = 0; NSLog(@"INIT with size : %fx%f, %fx%f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); self = [super initWithFrame:frame]; self.contentScaleFactor = 1.0f; @@ -207,7 +232,7 @@ [self setupDepthBuffer]; [self setupRenderBuffer]; [self setupFrameBuffer]; - [self setupDisplayLink]; + [self startDisplayLink]; } return self; } diff --git a/sources/ewol/widget/Windows.h b/sources/ewol/widget/Windows.h index cec8a905..f517685a 100644 --- a/sources/ewol/widget/Windows.h +++ b/sources/ewol/widget/Windows.h @@ -40,6 +40,10 @@ namespace ewol { return true; }; virtual void onReduce(void) { }; + virtual void onStateBackground(void) {}; + virtual void onStateForeground(void) {}; + virtual void onStateSuspend(void) {}; + virtual void onStateResume(void) {}; virtual void on(void) { }; private: bool m_hasDecoration;