From dd8daa7e3dd5e2e76000d42d7d18a4ad92c02324 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 21 Oct 2017 19:05:21 +0200 Subject: [PATCH] [DEV] update to the new ETK allocator wrapper --- ewol/ewol.cpp | 2 +- ewol/object/Object.hpp | 6 +++--- ewol/resource/FontFreeType.cpp | 18 +++++++----------- ewol/resource/FontFreeType.hpp | 2 +- ewol/resource/ImageDF.cpp | 4 ++-- ewol/resource/Texture.cpp | 5 +++-- ewol/resource/TextureFile.cpp | 4 ++-- ewol/widget/Image.cpp | 12 ++++++------ ewol/widget/Joystick.cpp | 26 +++++++++++++------------- ewol/widget/List.cpp | 18 +++++++++--------- ewol/widget/ListFileSystem.cpp | 4 ++-- sample/CustomWidgets/appl/Main.cpp | 2 +- sample/HelloWord/appl/Main.cpp | 2 +- sample/wallpaper/appl/Main.cpp | 2 +- test/testApplication.cpp | 4 ++-- tools/platform_test/appl/init.cpp | 2 +- tools/visual_test/appl/init.cpp | 2 +- 17 files changed, 56 insertions(+), 59 deletions(-) diff --git a/ewol/ewol.cpp b/ewol/ewol.cpp index f8def8f8..d6303191 100644 --- a/ewol/ewol.cpp +++ b/ewol/ewol.cpp @@ -27,7 +27,7 @@ int32_t ewol::run(ewol::context::Application* _application, int32_t _argc, const char* _argv[]) { etranslate::init(_argc, _argv); - return gale::run(new ewol::Context(_application), _argc, _argv); + return gale::run(ETK_NEW(ewol::Context, _application), _argc, _argv); } diff --git a/ewol/object/Object.hpp b/ewol/object/Object.hpp index 604c9b50..1101bebf 100644 --- a/ewol/object/Object.hpp +++ b/ewol/object/Object.hpp @@ -62,7 +62,7 @@ exit_on_error: #define DECLARE_FACTORY(className) \ template static ememory::SharedPtr create(const EWOL_FACTORY_CREATE_TYPE& ... _all) { \ - ememory::SharedPtr object(new className()); \ + ememory::SharedPtr object(ETK_NEW(className)); \ if (object == nullptr) { \ EWOL_ERROR("Factory error"); \ return nullptr; \ @@ -75,7 +75,7 @@ exit_on_error: return object; \ } \ static ememory::SharedPtr createXml(const exml::Element& _node) { \ - ememory::SharedPtr object(new className()); \ + ememory::SharedPtr object(ETK_NEW(className)); \ if (object == nullptr) { \ EWOL_ERROR("Factory error"); \ return nullptr; \ @@ -102,7 +102,7 @@ exit_on_error: if (object != nullptr) { \ return object; \ } \ - object = ememory::SharedPtr(new className()); \ + object = ememory::SharedPtr(ETK_NEW(className)); \ if (object == nullptr) { \ EWOL_ERROR("Factory error"); \ return nullptr; \ diff --git a/ewol/resource/FontFreeType.cpp b/ewol/resource/FontFreeType.cpp index 398cec42..278aef6e 100644 --- a/ewol/resource/FontFreeType.cpp +++ b/ewol/resource/FontFreeType.cpp @@ -53,7 +53,6 @@ void ewol::resource::freeTypeUnInit() { ewol::resource::FontFreeType::FontFreeType() { addResourceType("ewol::FontFreeType"); m_init = false; - m_FileBuffer = nullptr; m_FileSize = 0; } @@ -75,17 +74,17 @@ void ewol::resource::FontFreeType::init(const etk::String& _fontName) { return; } // allocate data - m_FileBuffer = new FT_Byte[m_FileSize]; - if (m_FileBuffer == nullptr) { + m_FileBuffer.resize(m_FileSize, 0); + if (m_FileBuffer.size() != m_FileSize) { EWOL_ERROR("Error Memory allocation size=" << _fontName); return; } // load data from the file : - myfile.fileRead(m_FileBuffer, 1, m_FileSize); + myfile.fileRead(&m_FileBuffer[0], 1, m_FileSize); // close the file: myfile.fileClose(); // load Face ... - int32_t error = FT_New_Memory_Face( library, m_FileBuffer, m_FileSize, 0, &m_fftFace ); + int32_t error = FT_New_Memory_Face(library, &m_FileBuffer[0], m_FileSize, 0, &m_fftFace ); if( FT_Err_Unknown_File_Format == error) { EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported"); } else if (0 != error) { @@ -101,17 +100,14 @@ void ewol::resource::FontFreeType::init(const etk::String& _fontName) { ewol::resource::FontFreeType::~FontFreeType() { ethread::RecursiveLock lock(m_mutex); // clean the tmp memory - if (nullptr != m_FileBuffer) { - delete[] m_FileBuffer; - m_FileBuffer = nullptr; - } + m_FileBuffer.clear(); // must be deleted fftFace - FT_Done_Face( m_fftFace ); + FT_Done_Face(m_fftFace); } vec2 ewol::resource::FontFreeType::getSize(int32_t _fontSize, const etk::String& _unicodeString) { ethread::RecursiveLock lock(m_mutex); - if(false == m_init) { + if (m_init == false) { return vec2(0,0); } // TODO : ... diff --git a/ewol/resource/FontFreeType.hpp b/ewol/resource/FontFreeType.hpp index 340ad3b0..64ed1463 100644 --- a/ewol/resource/FontFreeType.hpp +++ b/ewol/resource/FontFreeType.hpp @@ -19,7 +19,7 @@ namespace ewol { // show : http://www.freetype.org/freetype2/docs/tutorial/step2.html class FontFreeType : public ewol::resource::FontBase { private: - FT_Byte* m_FileBuffer; + etk::Vector m_FileBuffer; int32_t m_FileSize; FT_Face m_fftFace; bool m_init; diff --git a/ewol/resource/ImageDF.cpp b/ewol/resource/ImageDF.cpp index ef322ba0..e7c0dd0e 100644 --- a/ewol/resource/ImageDF.cpp +++ b/ewol/resource/ImageDF.cpp @@ -156,7 +156,7 @@ static int32_t nextP2(int32_t _value) { ememory::SharedPtr ewol::resource::ImageDF::create(const etk::String& _filename, ivec2 _size) { EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size); if (_filename == "") { - ememory::SharedPtr object(new ewol::resource::ImageDF()); + ememory::SharedPtr object(ETK_NEW(ewol::resource::ImageDF)); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : ??TEX??"); return nullptr; @@ -208,7 +208,7 @@ ememory::SharedPtr ewol::resource::ImageDF::create(cons } EWOL_INFO("CREATE: ImageDF: '" << TmpFilename << "' size=" << _size); // need to crate a new one ... - object = ememory::SharedPtr(new ewol::resource::ImageDF()); + object = ememory::SharedPtr(ETK_NEW(ewol::resource::ImageDF)); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : " << _filename); return nullptr; diff --git a/ewol/resource/Texture.cpp b/ewol/resource/Texture.cpp index f31d5890..1b0c1a91 100644 --- a/ewol/resource/Texture.cpp +++ b/ewol/resource/Texture.cpp @@ -274,7 +274,8 @@ void ewol::resource::Texture::removeContext() { if (m_loaded == true) { // Request remove texture ... EWOL_DEBUG("TEXTURE: Rm [" << getId() << "] texId=" << m_texId); - //glDeleteTextures(1, &m_texId); + // TODO: Check if we are in the correct thread + glDeleteTextures(1, &m_texId); m_loaded = false; } } @@ -311,7 +312,7 @@ void ewol::resource::Texture::set(egami::Image _image) { m_realImageSize = vec2(tmp.x(), tmp.y()); vec2 compatibilityHWSize = vec2(nextP2(tmp.x()), nextP2(tmp.y())); if (m_realImageSize != compatibilityHWSize) { - EWOL_ERROR("RESIZE Image for HArwareCompatibility:" << m_realImageSize << " => " << compatibilityHWSize); + EWOL_VERBOSE("RESIZE Image for HArwareCompatibility:" << m_realImageSize << " => " << compatibilityHWSize); m_data.resize(ivec2(compatibilityHWSize.x(),compatibilityHWSize.y())); } flush(); diff --git a/ewol/resource/TextureFile.cpp b/ewol/resource/TextureFile.cpp index 24f9b157..bc819453 100644 --- a/ewol/resource/TextureFile.cpp +++ b/ewol/resource/TextureFile.cpp @@ -61,7 +61,7 @@ void ewol::resource::TextureFile::init(etk::String _genName, const etk::String& ememory::SharedPtr ewol::resource::TextureFile::create(const etk::String& _filename, ivec2 _size, ivec2 _sizeRegister) { EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size << " sizeRegister=" << _sizeRegister); if (_filename == "") { - ememory::SharedPtr object(new ewol::resource::TextureFile()); + ememory::SharedPtr object(ETK_NEW(ewol::resource::TextureFile)); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : ??TEX??"); return nullptr; @@ -110,7 +110,7 @@ ememory::SharedPtr ewol::resource::TextureFile::cre } EWOL_INFO("CREATE: TextureFile: '" << tmpFilename << "' size=" << _size); // need to crate a new one ... - object = ememory::SharedPtr(new ewol::resource::TextureFile()); + object = ememory::SharedPtr(ETK_NEW(ewol::resource::TextureFile)); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : " << _filename); return nullptr; diff --git a/ewol/widget/Image.cpp b/ewol/widget/Image.cpp index 77aca94c..eacc92f4 100644 --- a/ewol/widget/Image.cpp +++ b/ewol/widget/Image.cpp @@ -124,29 +124,29 @@ void ewol::widget::Image::onRegenerateDisplay() { } void ewol::widget::Image::calculateMinMaxSize() { - EWOL_WARNING("calculate min size: border=" << propertyBorder << " size=" << propertyImageSize << " min-size=" << propertyMinSize); + EWOL_DEBUG("calculate min size: border=" << propertyBorder << " size=" << propertyImageSize << " min-size=" << propertyMinSize); vec2 imageBoder = propertyBorder->getPixel()*2.0f; vec2 imageSize = propertyImageSize->getPixel(); vec2 size = propertyMinSize->getPixel(); - EWOL_WARNING(" ==> border=" << imageBoder << " size=" << imageSize << " min-size=" << size); + EWOL_DEBUG(" ==> border=" << imageBoder << " size=" << imageSize << " min-size=" << size); if (imageSize != vec2(0,0)) { m_minSize = imageBoder+imageSize; m_maxSize = m_minSize; } else { vec2 imageSizeReal = m_compositing.getRealSize(); - EWOL_WARNING(" Real Size = " << imageSizeReal); + EWOL_VERBOSE(" Real Size = " << imageSizeReal); vec2 min1 = imageBoder+propertyMinSize->getPixel(); m_minSize = imageBoder+imageSizeReal; - EWOL_WARNING(" set max : " << m_minSize << " min1=" << min1); + EWOL_VERBOSE(" set max : " << m_minSize << " min1=" << min1); m_minSize.setMax(min1); - EWOL_WARNING(" result : " << m_minSize); + EWOL_VERBOSE(" result : " << m_minSize); m_maxSize = imageBoder+propertyMaxSize->getPixel(); m_minSize.setMin(m_maxSize); } m_imageRenderSize = m_minSize; m_minSize.setMax(size); m_maxSize.setMax(m_minSize); - EWOL_ERROR("set widget min=" << m_minSize << " max=" << m_maxSize << " with real Image size=" << m_imageRenderSize << " img size=" << imageSize << " " << propertyImageSize); + EWOL_DEBUG("set widget min=" << m_minSize << " max=" << m_maxSize << " with real Image size=" << m_imageRenderSize << " img size=" << imageSize << " " << propertyImageSize); markToRedraw(); } diff --git a/ewol/widget/Joystick.cpp b/ewol/widget/Joystick.cpp index cafdce80..2c019c70 100644 --- a/ewol/widget/Joystick.cpp +++ b/ewol/widget/Joystick.cpp @@ -48,7 +48,7 @@ ewol::widget::Joystick::~Joystick() { } void ewol::widget::Joystick::onRegenerateDisplay() { - if (true == needRedraw()) { + if (needRedraw() == true) { // clean the object list ... /* @@ -58,11 +58,11 @@ void ewol::widget::Joystick::onRegenerateDisplay() { // set background if (true == m_displayBackground) { if (m_background == "") { - tmpOObjects = new ewol::OObject2DColored; + tmpOObjects = ne w ewol::OObject2DColored; tmpOObjects->setColor(m_colorBg); tmpOObjects->Disc( m_size.x/2, m_size.y/2, m_size.x/2-1); } else { - tmpOOtexBg = new ewol::OObject2DTextured(m_background, m_size.x, m_size.y); + tmpOOtexBg = n ew ewol::OObject2DTextured(m_background, m_size.x, m_size.y); tmpOOtexBg->rectangle(0, 0, m_size.x, m_size.y); } } @@ -70,13 +70,13 @@ void ewol::widget::Joystick::onRegenerateDisplay() { float sizeElement = m_size.x*m_ratio; if (m_foreground == "") { if (nullptr == tmpOObjects) { - tmpOObjects = new ewol::OObject2DColored; + tmpOObjects = ne w ewol::OObject2DColored; } tmpOObjects->setColor(m_colorFg); tmpOObjects->Disc( ((m_displayPos.x+1.0)/2.0)*(m_size.x-2*sizeElement) + sizeElement, ((m_displayPos.y+1.0)/2.0)*(m_size.y-2*sizeElement) + sizeElement, sizeElement); } else { - tmpOOtexFg = new ewol::OObject2DTextured(m_foreground,sizeElement*2, sizeElement*2); + tmpOOtexFg = ne w ewol::OObject2DTextured(m_foreground,sizeElement*2, sizeElement*2); tmpOOtexFg->rectangle(((m_displayPos.x+1.0)/2.0)*(m_size.x-2*sizeElement), ((m_displayPos.y+1.0)/2.0)*(m_size.y-2*sizeElement), sizeElement*2, sizeElement*2); } @@ -123,7 +123,7 @@ bool ewol::widget::Joystick::onEventInput(const ewol::event::Input& _event) { // clip if needed ... if (m_distance > 1.0) { m_distance = 1.0; - // regenerate new display position : + // regenerate n ew display position : m_displayPos.x = cos(m_angle)*m_distance; m_displayPos.y = sin(m_angle)*m_distance; } @@ -158,19 +158,19 @@ bool ewol::widget::Joystick::onEventInput(const ewol::event::Input& _event) { } -void ewol::widget::Joystick::ratio(float newRatio) { - if (newRatio > 1) { - newRatio = 1; +void ewol::widget::Joystick::ratio(float _newRatio) { + if (_newRatio > 1) { + _newRatio = 1; } - m_ratio = newRatio; + m_ratio = _newRatio; EWOL_INFO("Set default Joystick ratio at " << m_ratio); } -void ewol::widget::Joystick::background(etk::String imageNameInData, bool display) { +void ewol::widget::Joystick::background(etk::String _imageNameInData, bool _display) { // TODO : check if it existed - m_background = imageNameInData; - m_displayBackground = display; + m_background = _imageNameInData; + m_displayBackground = _display; EWOL_INFO("Set default Joystick background at " << m_background << " display it=" << m_displayBackground); } diff --git a/ewol/widget/List.cpp b/ewol/widget/List.cpp index 7e6ced0b..cdcce133 100644 --- a/ewol/widget/List.cpp +++ b/ewol/widget/List.cpp @@ -28,7 +28,7 @@ ewol::widget::List::List() { ewol::widget::List::~List() { //clean all the object for (size_t iii=0; iii= m_listOObject.size() ) { + if ( _pos < 0 + || (size_t)_pos >= m_listOObject.size() ) { m_listOObject.pushBack(_newObject); } else { m_listOObject.insert(m_listOObject.begin()+_pos, _newObject); @@ -84,7 +85,7 @@ void ewol::widget::List::addOObject(ewol::Compositing* _newObject, int32_t _pos) void ewol::widget::List::clearOObjectList() { for (size_t iii=0; iiidraw(); } } @@ -100,8 +101,7 @@ void ewol::widget::List::onDraw() { } void ewol::widget::List::onRegenerateDisplay() { - if (true == needRedraw()) { - + if (needRedraw() == true) { // clean the object list ... clearOObjectList(); //EWOL_DEBUG("OnRegenerateDisplay(" << m_size.x << "," << m_size.y << ")"); @@ -128,7 +128,7 @@ void ewol::widget::List::onRegenerateDisplay() { etk::Vector listSizeColomn; - ewol::compositing::Drawing * BGOObjects = new ewol::compositing::Drawing(); + ewol::compositing::Drawing * BGOObjects = ETK_NEW(ewol::compositing::Drawing); etk::Color<> basicBG = getBasicBG(); BGOObjects->setColor(basicBG); BGOObjects->setPos(vec3(0, 0, 0) ); @@ -170,7 +170,7 @@ void ewol::widget::List::onRegenerateDisplay() { etk::Color<> bg; getElement(jjj, iii, myTextToWrite, fg, bg); - ewol::compositing::Text * tmpText = new ewol::compositing::Text(); + ewol::compositing::Text * tmpText = ETK_NEW(ewol::compositing::Text); if (nullptr != tmpText) { // get font size : int32_t tmpFontHeight = tmpText->calculateSize(char32_t('A')).y(); diff --git a/ewol/widget/ListFileSystem.cpp b/ewol/widget/ListFileSystem.cpp index a154a2f3..2cee46d6 100644 --- a/ewol/widget/ListFileSystem.cpp +++ b/ewol/widget/ListFileSystem.cpp @@ -62,7 +62,7 @@ ewol::widget::ListFileSystem::~ListFileSystem() { void ewol::widget::ListFileSystem::clearList() { for (auto &it : m_list) { if (it != nullptr) { - delete(it); + ETK_DELETE(etk::FSNode, it); it = nullptr; } } @@ -79,7 +79,7 @@ void ewol::widget::ListFileSystem::regenerateView() { m_list.clear(); m_originScrooled.setValue(0,0); etk::FSNode tmpFolder(*propertyPath); - // get the new list : + // get the list: m_list = tmpFolder.folderGetSubList(*propertyShowHidden, *propertyShowFolder, *propertyShowFile, *propertyFilter); // request a redraw ... markToRedraw(); diff --git a/sample/CustomWidgets/appl/Main.cpp b/sample/CustomWidgets/appl/Main.cpp index 75c1ee40..75e5d9ee 100644 --- a/sample/CustomWidgets/appl/Main.cpp +++ b/sample/CustomWidgets/appl/Main.cpp @@ -63,5 +63,5 @@ class MainApplication : public ewol::context::Application { */ int main(int _argc, const char *_argv[]) { // second possibility - return ewol::run(new MainApplication(), _argc, _argv); + return ewol::run(ETK_NEW(appl::MainApplication)(), _argc, _argv); } \ No newline at end of file diff --git a/sample/HelloWord/appl/Main.cpp b/sample/HelloWord/appl/Main.cpp index 0140513d..e868c6de 100644 --- a/sample/HelloWord/appl/Main.cpp +++ b/sample/HelloWord/appl/Main.cpp @@ -95,7 +95,7 @@ namespace appl { */ int main(int _argc, const char *_argv[]) { // second possibility - return ewol::run(new appl::MainApplication(), _argc, _argv); + return ewol::run(ETK_NEW(appl::MainApplication)(), _argc, _argv); } //! [ewol_sample_HW_main_main] diff --git a/sample/wallpaper/appl/Main.cpp b/sample/wallpaper/appl/Main.cpp index d255271c..ccf865b7 100644 --- a/sample/wallpaper/appl/Main.cpp +++ b/sample/wallpaper/appl/Main.cpp @@ -62,5 +62,5 @@ class MainApplication : public ewol::context::Application { */ int main(int _argc, const char *_argv[]) { // second possibility - return ewol::run(new MainApplication(), _argc, _argv); + return ewol::run(ETK_NEW(appl::MainApplication)(), _argc, _argv); } \ No newline at end of file diff --git a/test/testApplication.cpp b/test/testApplication.cpp index 8ff268bf..95305751 100644 --- a/test/testApplication.cpp +++ b/test/testApplication.cpp @@ -10,8 +10,8 @@ #define NAME "Application" TEST(TestEwolApplication, Creation) { - ewol::context::Application* tmpAppl = new ewol::context::Application(); + ewol::context::Application* tmpAppl = ETK_NEW(ewol::context::Application); EXPECT_NE(tmpAppl, nullptr); - delete tmpAppl; + ETK_DELETE(ewol::context::Application, tmpAppl); } diff --git a/tools/platform_test/appl/init.cpp b/tools/platform_test/appl/init.cpp index 7b5c15ab..a9266b32 100644 --- a/tools/platform_test/appl/init.cpp +++ b/tools/platform_test/appl/init.cpp @@ -90,7 +90,7 @@ class MainApplication : public ewol::context::Application { */ int main(int _argc, const char *_argv[]) { // second possibility - return ewol::run(new MainApplication(), _argc, _argv); + return ewol::run(ETK_NEW(appl::MainApplication)(), _argc, _argv); } diff --git a/tools/visual_test/appl/init.cpp b/tools/visual_test/appl/init.cpp index 7b5c15ab..a9266b32 100644 --- a/tools/visual_test/appl/init.cpp +++ b/tools/visual_test/appl/init.cpp @@ -90,7 +90,7 @@ class MainApplication : public ewol::context::Application { */ int main(int _argc, const char *_argv[]) { // second possibility - return ewol::run(new MainApplication(), _argc, _argv); + return ewol::run(ETK_NEW(appl::MainApplication)(), _argc, _argv); }