[DEV] add some mutex to protect multithread access
This commit is contained in:
parent
5789abf09b
commit
ad0018be8d
@ -23,6 +23,7 @@ ewol::resource::ColorFile::ColorFile() :
|
||||
}
|
||||
|
||||
void ewol::resource::ColorFile::init(const std::string& _filename) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
gale::Resource::init(_filename);
|
||||
EWOL_DEBUG("CF : load \"" << _filename << "\"");
|
||||
reload();
|
||||
@ -36,6 +37,7 @@ ewol::resource::ColorFile::~ColorFile() {
|
||||
|
||||
|
||||
void ewol::resource::ColorFile::reload() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// remove all previous set of value :
|
||||
for (int32_t iii = 0; iii < m_list.size() ; ++iii) {
|
||||
m_list[iii] = m_errorColor;
|
||||
@ -70,6 +72,7 @@ void ewol::resource::ColorFile::reload() {
|
||||
|
||||
|
||||
int32_t ewol::resource::ColorFile::request(const std::string& _paramName) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// check if the parameters existed :
|
||||
if (m_list.exist(_paramName) == false) {
|
||||
m_list.add(_paramName, m_errorColor);
|
||||
|
@ -25,6 +25,7 @@ ewol::resource::ConfigFile::ConfigFile() :
|
||||
}
|
||||
|
||||
void ewol::resource::ConfigFile::init(const std::string& _filename) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
gale::Resource::init(_filename);
|
||||
EWOL_DEBUG("SFP : load \"" << _filename << "\"");
|
||||
reload();
|
||||
@ -36,6 +37,7 @@ ewol::resource::ConfigFile::~ConfigFile() {
|
||||
}
|
||||
|
||||
void ewol::resource::ConfigFile::reload() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// reset all parameters
|
||||
for (int32_t iii=0; iii<m_list.size(); iii++){
|
||||
if (nullptr != m_list[iii]) {
|
||||
@ -53,6 +55,7 @@ void ewol::resource::ConfigFile::reload() {
|
||||
|
||||
|
||||
int32_t ewol::resource::ConfigFile::request(const std::string& _paramName) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// check if the parameters existed :
|
||||
if (m_list.exist(_paramName) == false) {
|
||||
m_list.add(_paramName, nullptr);
|
||||
@ -65,6 +68,7 @@ int32_t ewol::resource::ConfigFile::request(const std::string& _paramName) {
|
||||
|
||||
|
||||
double ewol::resource::ConfigFile::getNumber(int32_t _id) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if ( _id < 0
|
||||
|| m_list[_id] == nullptr) {
|
||||
return 0.0;
|
||||
@ -77,6 +81,7 @@ double ewol::resource::ConfigFile::getNumber(int32_t _id) {
|
||||
}
|
||||
|
||||
const std::string& ewol::resource::ConfigFile::getString(int32_t _id) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
static const std::string& errorString("");
|
||||
if ( _id < 0
|
||||
|| m_list[_id] == nullptr) {
|
||||
@ -90,6 +95,7 @@ const std::string& ewol::resource::ConfigFile::getString(int32_t _id) {
|
||||
}
|
||||
|
||||
bool ewol::resource::ConfigFile::getBoolean(int32_t _id) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if ( _id < 0
|
||||
|| m_list[_id] == nullptr) {
|
||||
return false;
|
||||
|
@ -36,6 +36,7 @@ ewol::resource::DistanceFieldFont::DistanceFieldFont() :
|
||||
}
|
||||
|
||||
void ewol::resource::DistanceFieldFont::init(const std::string& _fontName) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init(_fontName);
|
||||
std::string localName = _fontName;
|
||||
std::vector<std::string> folderList;
|
||||
@ -130,11 +131,13 @@ ewol::resource::DistanceFieldFont::~DistanceFieldFont() {
|
||||
|
||||
|
||||
float ewol::resource::DistanceFieldFont::getDisplayRatio(float _size) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
return _size / (float)SIZE_GENERATION;
|
||||
}
|
||||
|
||||
|
||||
void ewol::resource::DistanceFieldFont::generateDistanceField(const egami::ImageMono& _input, egami::Image& _output) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
int32_t size = _input.getSize().x() * _input.getSize().y();
|
||||
std::vector<short> xdist(size);
|
||||
std::vector<short> ydist(size);
|
||||
@ -214,6 +217,7 @@ void ewol::resource::DistanceFieldFont::generateDistanceField(const egami::Image
|
||||
}
|
||||
|
||||
bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
bool hasChange = false;
|
||||
if (m_font == nullptr) {
|
||||
return false;
|
||||
@ -295,6 +299,7 @@ bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) {
|
||||
}
|
||||
|
||||
int32_t ewol::resource::DistanceFieldFont::getIndex(char32_t _charcode) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (_charcode < 0x20) {
|
||||
return 0;
|
||||
} else if (_charcode < 0x80) {
|
||||
@ -321,6 +326,7 @@ int32_t ewol::resource::DistanceFieldFont::getIndex(char32_t _charcode) {
|
||||
}
|
||||
|
||||
ewol::GlyphProperty* ewol::resource::DistanceFieldFont::getGlyphPointer(const char32_t& _charcode) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
//EWOL_DEBUG("Get glyph property for mode: " << _displayMode << " == > wrapping index : " << m_modeWraping[_displayMode]);
|
||||
int32_t index = getIndex(_charcode);
|
||||
if( index < 0
|
||||
@ -340,6 +346,7 @@ ewol::GlyphProperty* ewol::resource::DistanceFieldFont::getGlyphPointer(const ch
|
||||
}
|
||||
|
||||
void ewol::resource::DistanceFieldFont::exportOnFile() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
EWOL_DEBUG("EXPORT: DistanceFieldFont : file : '" << m_fileName << ".json'");
|
||||
ejson::Document doc;
|
||||
std::shared_ptr<ejson::Array> tmpList = ejson::Array::create();
|
||||
@ -374,6 +381,7 @@ void ewol::resource::DistanceFieldFont::exportOnFile() {
|
||||
}
|
||||
|
||||
bool ewol::resource::DistanceFieldFont::importFromFile() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
EWOL_DEBUG("IMPORT: DistanceFieldFont : file : '" << m_fileName << ".json'");
|
||||
// test file existance:
|
||||
etk::FSNode fileJSON(m_fileName + ".json");
|
||||
|
@ -60,6 +60,7 @@ ewol::resource::FontFreeType::FontFreeType() {
|
||||
}
|
||||
|
||||
void ewol::resource::FontFreeType::init(const std::string& _fontName) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::FontBase::init(_fontName);
|
||||
etk::FSNode myfile(_fontName);
|
||||
if (false == myfile.exist()) {
|
||||
@ -100,6 +101,7 @@ void ewol::resource::FontFreeType::init(const std::string& _fontName) {
|
||||
}
|
||||
|
||||
ewol::resource::FontFreeType::~FontFreeType() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// clean the tmp memory
|
||||
if (nullptr != m_FileBuffer) {
|
||||
delete[] m_FileBuffer;
|
||||
@ -110,6 +112,7 @@ ewol::resource::FontFreeType::~FontFreeType() {
|
||||
}
|
||||
|
||||
vec2 ewol::resource::FontFreeType::getSize(int32_t _fontSize, const std::string& _unicodeString) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(false == m_init) {
|
||||
return vec2(0,0);
|
||||
}
|
||||
@ -119,13 +122,16 @@ vec2 ewol::resource::FontFreeType::getSize(int32_t _fontSize, const std::string&
|
||||
}
|
||||
|
||||
int32_t ewol::resource::FontFreeType::getHeight(int32_t _fontSize) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
return _fontSize*1.43f; // this is a really "magic" number ...
|
||||
}
|
||||
float ewol::resource::FontFreeType::getSizeWithHeight(float _fontHeight) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
return _fontHeight*0.6993f; // this is a really "magic" number ...
|
||||
}
|
||||
|
||||
bool ewol::resource::FontFreeType::getGlyphProperty(int32_t _fontSize, ewol::GlyphProperty& _property) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(false == m_init) {
|
||||
return false;
|
||||
}
|
||||
@ -170,6 +176,7 @@ bool ewol::resource::FontFreeType::drawGlyph(egami::Image& _imageOut,
|
||||
ivec2 _glyphPosition,
|
||||
ewol::GlyphProperty& _property,
|
||||
int8_t _posInImage) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(false == m_init) {
|
||||
return false;
|
||||
}
|
||||
@ -231,6 +238,7 @@ bool ewol::resource::FontFreeType::drawGlyph(egami::ImageMono& _imageOut,
|
||||
int32_t _fontSize,
|
||||
ewol::GlyphProperty& _property,
|
||||
int32_t _borderSize) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(false == m_init) {
|
||||
return false;
|
||||
}
|
||||
@ -274,7 +282,8 @@ bool ewol::resource::FontFreeType::drawGlyph(egami::ImageMono& _imageOut,
|
||||
|
||||
|
||||
void ewol::resource::FontFreeType::generateKerning(int32_t fontSize, std::vector<ewol::GlyphProperty>& listGlyph) {
|
||||
if(false == m_init) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(m_init == false) {
|
||||
return;
|
||||
}
|
||||
if ((FT_FACE_FLAG_KERNING & m_fftFace->face_flags) == 0) {
|
||||
@ -307,7 +316,8 @@ void ewol::resource::FontFreeType::generateKerning(int32_t fontSize, std::vector
|
||||
|
||||
|
||||
void ewol::resource::FontFreeType::display() {
|
||||
if(false == m_init) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if(m_init == false) {
|
||||
return;
|
||||
}
|
||||
EWOL_INFO(" number of glyph = " << (int)m_fftFace->num_glyphs);
|
||||
|
@ -23,10 +23,12 @@ ewol::resource::TextureFile::TextureFile() {
|
||||
}
|
||||
|
||||
void ewol::resource::TextureFile::init() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init();
|
||||
}
|
||||
|
||||
void ewol::resource::TextureFile::init(std::string _genName, const std::string& _tmpfileName, const ivec2& _size) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init(_genName);
|
||||
EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _tmpfileName=" << _tmpfileName << " size=" << _size);
|
||||
if (false == egami::load(m_data, _tmpfileName, _size)) {
|
||||
|
@ -24,10 +24,12 @@ ewol::resource::ImageDF::ImageDF() {
|
||||
|
||||
|
||||
void ewol::resource::ImageDF::init() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init();
|
||||
}
|
||||
|
||||
void ewol::resource::ImageDF::init(std::string _genName, const std::string& _tmpfileName, const ivec2& _size) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init(_genName);
|
||||
EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _tmpfileName=" << _tmpfileName << " size=" << _size);
|
||||
if (false == egami::load(m_data, _tmpfileName, _size)) {
|
||||
@ -52,6 +54,7 @@ void ewol::resource::ImageDF::init(std::string _genName, const std::string& _tmp
|
||||
|
||||
|
||||
void ewol::resource::ImageDF::generateDistanceField(const egami::ImageMono& _input, egami::Image& _output) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
int32_t size = _input.getSize().x() * _input.getSize().y();
|
||||
std::vector<short> xdist(size);
|
||||
std::vector<short> ydist(size);
|
||||
|
@ -54,6 +54,7 @@ ewol::resource::Texture::~Texture() {
|
||||
#include <egami/wrapperBMP.h>
|
||||
|
||||
void ewol::resource::Texture::updateContext() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (false == m_loaded) {
|
||||
// Request a new texture at openGl :
|
||||
glGenTextures(1, &m_texId);
|
||||
@ -87,6 +88,7 @@ void ewol::resource::Texture::updateContext() {
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::removeContext() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (true == m_loaded) {
|
||||
// Request remove texture ...
|
||||
EWOL_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId);
|
||||
@ -96,16 +98,19 @@ void ewol::resource::Texture::removeContext() {
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::removeContextToLate() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
m_loaded = false;
|
||||
m_texId=0;
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::flush() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this()));
|
||||
}
|
||||
|
||||
void ewol::resource::Texture::setImageSize(ivec2 _newSize) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
_newSize.setValue( nextP2(_newSize.x()), nextP2(_newSize.y()) );
|
||||
m_data.resize(_newSize);
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ ewol::resource::TexturedFont::TexturedFont() {
|
||||
}
|
||||
|
||||
void ewol::resource::TexturedFont::init(const std::string& _fontName) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
ewol::resource::Texture::init(_fontName);
|
||||
EWOL_DEBUG("Load font : '" << _fontName << "'" );
|
||||
|
||||
@ -232,6 +233,7 @@ ewol::resource::TexturedFont::~TexturedFont() {
|
||||
}
|
||||
|
||||
bool ewol::resource::TexturedFont::addGlyph(const char32_t& _val) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
bool hasChange = false;
|
||||
// for each font :
|
||||
for (int32_t iii=0; iii<4 ; iii++) {
|
||||
@ -300,6 +302,7 @@ bool ewol::resource::TexturedFont::addGlyph(const char32_t& _val) {
|
||||
}
|
||||
|
||||
int32_t ewol::resource::TexturedFont::getIndex(char32_t _charcode, const enum ewol::font::mode _displayMode) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (_charcode < 0x20) {
|
||||
return 0;
|
||||
} else if (_charcode < 0x80) {
|
||||
@ -326,6 +329,7 @@ int32_t ewol::resource::TexturedFont::getIndex(char32_t _charcode, const enum ew
|
||||
}
|
||||
|
||||
ewol::GlyphProperty* ewol::resource::TexturedFont::getGlyphPointer(const char32_t& _charcode, const enum ewol::font::mode _displayMode) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
//EWOL_DEBUG("Get glyph property for mode: " << _displayMode << " == > wrapping index : " << m_modeWraping[_displayMode]);
|
||||
int32_t index = getIndex(_charcode, _displayMode);
|
||||
if( index < 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user