From c91eb1bece864f820e6b580e66938982fb0850ea Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 14 Aug 2012 08:56:17 +0200 Subject: [PATCH] draw on PC only when needed --- Sources/libewol/ewol/Widget.cpp | 11 +++++++++++ Sources/libewol/ewol/Widget.h | 2 +- Sources/libewol/ewol/WidgetManager.cpp | 21 +++++++++++++++------ Sources/libewol/ewol/WidgetManager.h | 2 ++ Sources/libewol/ewol/base/gui.cpp | 5 +++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Sources/libewol/ewol/Widget.cpp b/Sources/libewol/ewol/Widget.cpp index 4dafb45e..8160bb68 100644 --- a/Sources/libewol/ewol/Widget.cpp +++ b/Sources/libewol/ewol/Widget.cpp @@ -291,3 +291,14 @@ void ewol::Widget::PeriodicCallSet(bool statusToSet) ewol::widgetManager::PeriodicCallRm(this); } } + +/** + * @brief The widget mark itself that it need to regenerate the nest time. + * @param --- + * @return --- + */ +void ewol::Widget::MarkToReedraw(void) +{ + m_needRegenerateDisplay = true; + ewol::widgetManager::MarkDrawingIsNeeded(); +}; diff --git a/Sources/libewol/ewol/Widget.h b/Sources/libewol/ewol/Widget.h index 8921e4db..f5a51c1b 100644 --- a/Sources/libewol/ewol/Widget.h +++ b/Sources/libewol/ewol/Widget.h @@ -415,7 +415,7 @@ namespace ewol { * @param --- * @return --- */ - void MarkToReedraw(void) { m_needRegenerateDisplay = true; }; + void MarkToReedraw(void); /** * @brief Get the need of the redrawing of the widget and reset it to false * @param --- diff --git a/Sources/libewol/ewol/WidgetManager.cpp b/Sources/libewol/ewol/WidgetManager.cpp index f7ffd51d..e37d881d 100644 --- a/Sources/libewol/ewol/WidgetManager.cpp +++ b/Sources/libewol/ewol/WidgetManager.cpp @@ -32,7 +32,6 @@ #undef __class__ #define __class__ "WidgetManager" -static pthread_mutex_t localMutex; static bool IsInit = false; // For the focus Management @@ -41,17 +40,17 @@ static ewol::Widget * m_focusWidgetCurrent = NULL; static etk::VectorType l_listOfPeriodicWidget; static bool l_havePeriodic = false; +static bool l_haveRedraw = true; + void ewol::widgetManager::Init(void) { EWOL_DEBUG("==> Init Widget-Manager"); - // create interface mutex : - int ret = pthread_mutex_init(&localMutex, NULL); - EWOL_ASSERT(ret == 0, "Error creating Mutex ..."); // prevent android error ==> can create memory leak but I prefer m_focusWidgetDefault = NULL; m_focusWidgetCurrent = NULL; l_listOfPeriodicWidget.Clear(); l_havePeriodic = false; + l_haveRedraw = true; // init all the widget global parameters : ewol::WIDGET_JoystickInit(); ewol::WIDGET_ButtonInit(); @@ -70,8 +69,6 @@ void ewol::widgetManager::UnInit(void) IsInit = false; l_listOfPeriodicWidget.Clear(); - int ret = pthread_mutex_destroy(&localMutex); - EWOL_ASSERT(ret == 0, "Error destroying Mutex ..."); } void ewol::widgetManager::Rm(ewol::Widget * newWidget) @@ -214,3 +211,15 @@ bool ewol::widgetManager::PeriodicCallHave(void) return l_havePeriodic; } + +void ewol::widgetManager::MarkDrawingIsNeeded(void) +{ + l_haveRedraw = true; +} + +bool ewol::widgetManager::IsDrawingNeeded(void) +{ + bool tmp = l_haveRedraw; + l_haveRedraw = false; + return tmp; +} diff --git a/Sources/libewol/ewol/WidgetManager.h b/Sources/libewol/ewol/WidgetManager.h index cfa3e05f..2d88e690 100644 --- a/Sources/libewol/ewol/WidgetManager.h +++ b/Sources/libewol/ewol/WidgetManager.h @@ -49,6 +49,8 @@ namespace ewol { void PeriodicCall(int64_t localTime); bool PeriodicCallHave(void); + void MarkDrawingIsNeeded(void); + bool IsDrawingNeeded(void); }; }; diff --git a/Sources/libewol/ewol/base/gui.cpp b/Sources/libewol/ewol/base/gui.cpp index a1c9cdf1..bc0921c9 100644 --- a/Sources/libewol/ewol/base/gui.cpp +++ b/Sources/libewol/ewol/base/gui.cpp @@ -254,8 +254,9 @@ void EWOL_GenericDraw(bool everyTime) display = true; } int64_t currentTime3 = GetCurrentTime(); - // TODO : Check if somthink has regenerate his display befor redraw ... - { + // check if the regenerate is needed ... + if( true == ewol::widgetManager::IsDrawingNeeded() + || true == everyTime) { ewol::texture::UpdateContext(); nbDisplayTime++; gui_uniqueWindows->SysDraw();