Skip to content

Commit 0747722

Browse files
committed
Lock the mutex in the external texture related API
* Use find instead of operator[] that can cause unintended insertion Signed-off-by: Boram Bae <boram21.bae@samsung.com>
1 parent 16b80f2 commit 0747722

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

shell/platform/tizen/external_texture_gl.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ ExternalTextureGL::ExternalTextureGL()
5454
texture_id_(nextTextureId++) {}
5555

5656
ExternalTextureGL::~ExternalTextureGL() {
57-
mutex_.lock();
5857
if (state_->gl_texture != 0) {
5958
glDeleteTextures(1, &state_->gl_texture);
6059
}
@@ -65,14 +64,11 @@ ExternalTextureGL::~ExternalTextureGL() {
6564
}
6665

6766
state_.release();
68-
mutex_.unlock();
6967
}
7068

7169
bool ExternalTextureGL::OnFrameAvailable(tbm_surface_h tbm_surface) {
72-
mutex_.lock();
7370
if (!tbm_surface) {
7471
FT_LOGE("[texture id:%ld] tbm_surface is null", texture_id_);
75-
mutex_.unlock();
7672
return false;
7773
}
7874

@@ -81,30 +77,25 @@ bool ExternalTextureGL::OnFrameAvailable(tbm_surface_h tbm_surface) {
8177
"[texture id:%ld] Discard! an available tbm surface that has not yet "
8278
"been used exists",
8379
texture_id_);
84-
mutex_.unlock();
8580
return false;
8681
}
8782

8883
tbm_surface_info_s info;
8984
if (tbm_surface_get_info(tbm_surface, &info) != TBM_SURFACE_ERROR_NONE) {
9085
FT_LOGD("[texture id:%ld] tbm_surface not valid, pass", texture_id_);
91-
mutex_.unlock();
9286
return false;
9387
}
9488

9589
available_tbm_surface_ = tbm_surface;
9690
MarkTbmSurfaceToUse(available_tbm_surface_);
9791

98-
mutex_.unlock();
9992
return true;
10093
}
10194

10295
bool ExternalTextureGL::PopulateTextureWithIdentifier(
10396
size_t width, size_t height, FlutterOpenGLTexture* opengl_texture) {
104-
mutex_.lock();
10597
if (!available_tbm_surface_) {
10698
FT_LOGD("[texture id:%ld] available_tbm_surface_ is null", texture_id_);
107-
mutex_.unlock();
10899
return false;
109100
}
110101
tbm_surface_info_s info;
@@ -113,7 +104,6 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
113104
FT_LOGD("[texture id:%ld] tbm_surface is invalid", texture_id_);
114105
UnmarkTbmSurfaceToUse(available_tbm_surface_);
115106
available_tbm_surface_ = nullptr;
116-
mutex_.unlock();
117107
return false;
118108
}
119109

@@ -124,7 +114,6 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
124114
EVAS_GL_NATIVE_SURFACE_TIZEN, (void*)(intptr_t)available_tbm_surface_,
125115
attribs);
126116
if (!egl_src_image) {
127-
mutex_.unlock();
128117
return false;
129118
}
130119
if (state_->gl_texture == 0) {
@@ -157,7 +146,6 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
157146
if (!egl_src_image) {
158147
FT_LOGE("[texture id:%ld] egl_src_image create fail!!, errorcode == %d",
159148
texture_id_, eglGetError());
160-
mutex_.unlock();
161149
return false;
162150
}
163151
if (state_->gl_texture == 0) {
@@ -196,6 +184,5 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
196184

197185
opengl_texture->width = width;
198186
opengl_texture->height = height;
199-
mutex_.unlock();
200187
return true;
201188
}

shell/platform/tizen/flutter_tizen.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ void FlutterNotifyLowMemoryWarning(FlutterWindowControllerRef controller) {
181181
int64_t FlutterRegisterExternalTexture(
182182
FlutterTextureRegistrarRef texture_registrar) {
183183
FT_LOGD("FlutterDesktopRegisterExternalTexture");
184+
std::lock_guard<std::mutex> lock(texture_registrar->mutex);
184185
auto texture_gl = std::make_unique<ExternalTextureGL>();
185186
int64_t texture_id = texture_gl->TextureId();
186187
texture_registrar->textures[texture_id] = std::move(texture_gl);
@@ -193,16 +194,19 @@ int64_t FlutterRegisterExternalTexture(
193194

194195
bool FlutterUnregisterExternalTexture(
195196
FlutterTextureRegistrarRef texture_registrar, int64_t texture_id) {
197+
std::lock_guard<std::mutex> lock(texture_registrar->mutex);
196198
auto it = texture_registrar->textures.find(texture_id);
197199
if (it != texture_registrar->textures.end())
198200
texture_registrar->textures.erase(it);
199-
return (FlutterEngineUnregisterExternalTexture(
200-
texture_registrar->flutter_engine, texture_id) == kSuccess);
201+
bool ret = FlutterEngineUnregisterExternalTexture(
202+
texture_registrar->flutter_engine, texture_id) == kSuccess;
203+
return ret;
201204
}
202205

203206
bool FlutterMarkExternalTextureFrameAvailable(
204207
FlutterTextureRegistrarRef texture_registrar, int64_t texture_id,
205208
void* tbm_surface) {
209+
std::lock_guard<std::mutex> lock(texture_registrar->mutex);
206210
auto it = texture_registrar->textures.find(texture_id);
207211
if (it == texture_registrar->textures.end()) {
208212
FT_LOGE("can't find texture texture_id = %" PRId64, texture_id);
@@ -213,8 +217,9 @@ bool FlutterMarkExternalTextureFrameAvailable(
213217
// If a texture that has not been used already exists, it can fail
214218
return false;
215219
}
216-
return (FlutterEngineMarkExternalTextureFrameAvailable(
217-
texture_registrar->flutter_engine, texture_id) == kSuccess);
220+
bool ret = FlutterEngineMarkExternalTextureFrameAvailable(
221+
texture_registrar->flutter_engine, texture_id) == kSuccess;
222+
return ret;
218223
}
219224

220225
void FlutterRegisterViewFactory(

shell/platform/tizen/tizen_embedder_engine.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ bool TizenEmbedderEngine::RunEngine(
231231

232232
if (HasTizenRenderer()) {
233233
std::unique_ptr<FlutterTextureRegistrar> textures =
234-
std::make_unique<FlutterTextureRegistrar>();
234+
std::make_unique<FlutterTextureRegistrar>();
235235
textures->flutter_engine = flutter_engine;
236236
plugin_registrar_->texture_registrar = std::move(textures);
237237

@@ -285,9 +285,16 @@ bool TizenEmbedderEngine::OnAcquireExternalTexture(
285285
FlutterOpenGLTexture* texture) {
286286
TizenEmbedderEngine* tizen_embedder_engine =
287287
reinterpret_cast<TizenEmbedderEngine*>(user_data);
288-
return tizen_embedder_engine->plugin_registrar_->texture_registrar
289-
->textures[texture_id]
290-
->PopulateTextureWithIdentifier(width, height, texture);
288+
std::lock_guard<std::mutex> lock(
289+
tizen_embedder_engine->plugin_registrar_->texture_registrar->mutex);
290+
auto it = tizen_embedder_engine->plugin_registrar_->texture_registrar
291+
->textures.find(texture_id);
292+
int ret = false;
293+
if (it != tizen_embedder_engine->plugin_registrar_->texture_registrar
294+
->textures.end()) {
295+
ret = it->second->PopulateTextureWithIdentifier(width, height, texture);
296+
}
297+
return ret;
291298
}
292299

293300
void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height,

shell/platform/tizen/tizen_embedder_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct FlutterTextureRegistrar {
6060

6161
// The texture registrar managing external texture adapters.
6262
std::map<int64_t, std::unique_ptr<ExternalTextureGL>> textures;
63+
std::mutex mutex;
6364
};
6465

6566
using UniqueAotDataPtr = std::unique_ptr<_FlutterEngineAOTData, AOTDataDeleter>;

0 commit comments

Comments
 (0)