Change update machanism more efficiently
authorYunchan Cho <yunchan.cho@samsung.com>
Sun, 19 May 2013 23:00:06 +0000 (08:00 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Sun, 19 May 2013 23:27:52 +0000 (08:27 +0900)
[Issue#] N/A
[Problem] This can cause the box' update be starvated.
[Cause] When a box is on background, that box's update timer is just freezed.
[Solution] Even if a box is on background, its timer continues to work.
           And if the timer expires, update is delayed until the box gose to foreground.

Change-Id: Id06683b6133d42678999a223895739443fad353e

src/Core/Box.cpp
src/Core/Box.h

index cefcce6..e20c7d6 100644 (file)
@@ -40,6 +40,8 @@ Box::Box(BoxInfoPtr boxInfo, IBoxPluginFactoryPtr factory, EwkContextPtr ewkCont
     : m_boxInfo(boxInfo)
     , m_factory(factory)
     , m_currentTab(true)
+    , m_paused(false)
+    , m_updateNeeded(false)
 {
     LogD("enter");
     try {
@@ -140,8 +142,14 @@ bool Box::resume()
 
     try {
         m_currentTab = true;
-        m_updateTimer->resume();
-        m_view->resumeBox();
+        m_paused = false;
+
+        if (m_updateNeeded) {
+            m_updateNeeded = false;
+            return update();
+        } else {
+            m_view->resumeBox();
+        }
     } catch (...) {
         return false;
     }
@@ -159,7 +167,7 @@ bool Box::pause(bool background)
         if (!background) {
             m_currentTab = false;
         }
-        m_updateTimer->pause();
+        m_paused = true;
         m_view->pauseBox();
     } catch (...) {
         return false;
@@ -206,7 +214,7 @@ bool Box::closePd()
     try {
         m_view->hidePd();
         m_pdBuffer->free();
-        m_updateTimer->start();
+        m_updateTimer->restart();
     } catch (...) {
         return false;
     }
@@ -219,6 +227,12 @@ bool Box::update()
 {
     LogD("enter");
 
+    if (m_paused) {
+        // update is dalayed until this box goes to current tab
+        m_updateNeeded = true;
+        return true;
+    }
+
     m_boxBuffer->startCanvasUpdate();
     RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
     m_view->showBox(renderInfo);
index 0ab2f18..42596d4 100644 (file)
@@ -75,7 +75,12 @@ class Box: public IBox, public IBoxContext {
         IRenderBufferPtr m_pdBuffer;
         IRenderViewPtr m_view;
         ITimerPtr m_updateTimer;
+        // flag for knowing this box is on current tab
         bool m_currentTab;
+        // flag for knowing this box has been already paused
+        bool m_paused;
+        // flag for knowing this box should be updated when the box is resumed
+        bool m_updateNeeded;
         //IBoxStatePtr m_state;
 
         friend class BoxSchemeHandler;