Skip to content

Commit 86d1d74

Browse files
cco3Android Code Review
authored andcommitted
Merge "Add lock before calling initEglImage"
2 parents 44935c2 + 8ecc90d commit 86d1d74

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

services/surfaceflinger/Layer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,16 @@ status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
874874
ssize_t index = mActiveBuffer;
875875
if (index >= 0) {
876876
if (!mFailover) {
877-
Image& texture(mBufferData[index].texture);
878-
err = mTextureManager.initEglImage(&texture, dpy, buffer);
877+
{
878+
// Without that lock, there is a chance of race condition
879+
// where while composing a specific index, requestBuf
880+
// with the same index can be executed and touch the same data
881+
// that is being used in initEglImage.
882+
// (e.g. dirty flag in texture)
883+
Mutex::Autolock _l(mLock);
884+
Image& texture(mBufferData[index].texture);
885+
err = mTextureManager.initEglImage(&texture, dpy, buffer);
886+
}
879887
// if EGLImage fails, we switch to regular texture mode, and we
880888
// free all resources associated with using EGLImages.
881889
if (err == NO_ERROR) {

0 commit comments

Comments
 (0)