Fix black indicator. 52/100652/2
authorhuiyu.eun <huiyu.eun@samsung.com>
Tue, 29 Nov 2016 01:57:11 +0000 (10:57 +0900)
committerhuiyu.eun <huiyu.eun@samsung.com>
Tue, 29 Nov 2016 02:27:31 +0000 (11:27 +0900)
[Problem]Have drawn black indicator when rotate device.
[Solution]
 1. Use two shared file structure.
 2. Call glTexSubImage2D after received 'OP_UPDATE_DONE' event.

Change-Id: Ifebaef4e331ec1f0632c2344271400a85881afa9
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/video/tizen/SDL_ecore_ipc.c
src/video/tizen/SDL_ecore_ipc.h
src/video/tizen/SDL_tizenopengles.c
src/video/tizen/SDL_tizenopengles.h

index 21225fc..55d420f 100755 (executable)
@@ -59,33 +59,33 @@ LockFile* CreateLockeFile(char* LockFileName)
 }
 
 
-void SetSharedImageInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedFileInfo* fileInfo)
+void SetSharedImageInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorInfo* shared_info)
 {
     if ( (epcEvent->data) && (epcEvent->size > 0) && (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
     {
         int n = epcEvent->response;
-        if(n == 0 /*&& n < SHARED_FILE_NUMBER*/)
+        if( n < SHARED_FILE_NUMBER)
         {
-            fileInfo->SharedFileName = (char*)epcEvent->data;
-            fileInfo->SharedFileID = epcEvent->ref;
-            fileInfo->SharedFileNumber = epcEvent->ref_to;
-            SDL_Log("SetSharedImageInfo: shared file name: %s, shared file id: %d, shared file number: %d", fileInfo->SharedFileName, fileInfo->SharedFileID, fileInfo->SharedFileNumber);
+            shared_info->fileInfo[n].SharedFileName = (char*)epcEvent->data;
+            shared_info->fileInfo[n].SharedFileID = epcEvent->ref;
+            shared_info->fileInfo[n].SharedFileNumber = epcEvent->ref_to;
+            SDL_Log("SetSharedImageInfo: shared file name: %s, shared file id: %d, shared file number: %d", shared_info->fileInfo[n].SharedFileName, shared_info->fileInfo[n].SharedFileID, shared_info->fileInfo[n].SharedFileNumber);
             SDL_Log("epcEvent->response: %d", n);
         }
     }
 }
 
-void SetLockFileInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedFileInfo *fileInfo)
+void SetLockFileInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorInfo *shared_info)
 {
     if((epcEvent->ref > 0) && (epcEvent->ref_to > 0) && (epcEvent->data) &&  (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0))
     {
         int n = epcEvent->response;
-        if(n == 0/* && n < SHARED_FILE_NUMBER*/)
+        if(n < SHARED_FILE_NUMBER)
         {
-            fileInfo->ImageWidth = epcEvent->ref;
-            fileInfo->ImageHeight = epcEvent->ref_to;
-            fileInfo->LockFileName = epcEvent->data;
-            SDL_Log("SetLockFileInfo: width %d, height %d, filename %s", fileInfo->ImageWidth, fileInfo->ImageHeight, fileInfo->LockFileName);
+            shared_info->fileInfo[n].ImageWidth = epcEvent->ref;
+            shared_info->fileInfo[n].ImageHeight = epcEvent->ref_to;
+            shared_info->fileInfo[n].LockFileName = epcEvent->data;
+            SDL_Log("SetLockFileInfo: width %d, height %d, filename %s", shared_info->fileInfo[n].ImageWidth, shared_info->fileInfo[n].ImageHeight, shared_info->fileInfo[n].LockFileName);
             SDL_Log("epcEvent->response: %d", n);
         }
     }
@@ -96,18 +96,50 @@ unsigned char* CopyBuffer(SharedFileInfo* fileInfo)
     return (unsigned char*)fileInfo->sharedFile->address;
 }
 
-void LoadSharedImage(Ecore_Ipc_Event_Server_Data*  epcEvent, SharedFileInfo *fileInfo)
+void shared_free(SharedIndicatorInfo *shared_info, int n)
+{
+    LockFile* lockFile = shared_info->fileInfo[n].lockFile;
+    if(lockFile!=NULL) {
+        if(lockFile->fileDescriptor>=0) {
+            if(lockf(lockFile->fileDescriptor, F_ULOCK, 0) <0 )
+            {
+               SDL_Log("[SDL] Lock release fail");
+               return;
+            }
+        }
+        lockFile = NULL;
+    }
+
+    SharedFile* sharedFile = shared_info->fileInfo[n].sharedFile;
+
+    if(sharedFile!=NULL) {
+        if (sharedFile->address != MAP_FAILED) munmap(sharedFile->address, sharedFile->size);
+        if (sharedFile->fileDescriptor >= 0) close(sharedFile->fileDescriptor);
+
+       sharedFile->address = MAP_FAILED;
+       sharedFile->fileDescriptor = 1;
+       sharedFile->fileName = NULL;
+       sharedFile->size = 0;
+
+    }
+}
+
+void LoadSharedImage(Ecore_Ipc_Event_Server_Data*  epcEvent, SharedIndicatorInfo *shared_info)
 {
     char sharedFilename[256];
     int n = epcEvent->response;
-    if(n == 0 /*&& n < SHARED_FILE_NUMBER*/)
+    SDL_Log("[SDL] LoadSharedImage print n: %d\n",n);
+    if(n < SHARED_FILE_NUMBER)
     {
-        snprintf(sharedFilename, 256, "/%s-%d.%d", fileInfo->SharedFileName, fileInfo->SharedFileID, fileInfo->SharedFileNumber);
+        snprintf(sharedFilename, 256, "/%s-%d.%d", shared_info->fileInfo[n].SharedFileName, shared_info->fileInfo[n].SharedFileID, shared_info->fileInfo[n].SharedFileNumber);
         SDL_Log("The shared file name is %s", sharedFilename);
-        fileInfo->sharedFile = CreateSharedFile(sharedFilename, fileInfo->ImageWidth * fileInfo->ImageHeight * 4);
-        if(fileInfo->sharedFile != NULL)
+
+        shared_free(shared_info, n);
+
+        shared_info->fileInfo[n].sharedFile = CreateSharedFile(sharedFilename, shared_info->fileInfo[n].ImageWidth * shared_info->fileInfo[n].ImageHeight * 4);
+        if(shared_info->fileInfo[n].sharedFile != NULL)
         {
-            fileInfo->lockFile = CreateLockeFile(fileInfo->LockFileName);
+            shared_info->fileInfo[n].lockFile = CreateLockeFile(shared_info->fileInfo[n].LockFileName);
         }
         else
         {
@@ -116,8 +148,7 @@ void LoadSharedImage(Ecore_Ipc_Event_Server_Data*  epcEvent, SharedFileInfo *fil
     }
 }
 
-
-void DataReceived(void* event, SharedFileInfo* fileInfo)
+void DataReceived(void* event, SharedIndicatorInfo* shared_info)
 {
     Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)event;
     switch(epcEvent->minor)
@@ -125,19 +156,19 @@ void DataReceived(void* event, SharedFileInfo* fileInfo)
         case OP_SHM_REF0:
         {
             SDL_Log("Indicator client received: OP_SHM_REF0\n");
-            SetSharedImageInfo(epcEvent, fileInfo);
+            SetSharedImageInfo(epcEvent, shared_info);
             break;
         }
         case OP_SHM_REF1:
         {
             SDL_Log("Indicator client received: OP_SHM_REF1\n");
-            SetLockFileInfo(epcEvent, fileInfo);
+            SetLockFileInfo(epcEvent, shared_info);
             break;
         }
         case OP_SHM_REF2:
         {
             SDL_Log("Indicator client received: OP_SHM_REF2\n");
-            LoadSharedImage(epcEvent, fileInfo);
+            LoadSharedImage(epcEvent, shared_info);
             break;
         }
         case OP_PIXMAP_REF:
@@ -147,8 +178,33 @@ void DataReceived(void* event, SharedFileInfo* fileInfo)
         }
         case OP_UPDATE:
         {
-//            Tizen_glTexImage2d();
-            SDL_Log("Indicator client received: OP_UPDATE\n");
+            int n = epcEvent->response;
+            SDL_Log("Indicator client received: OP_UPDATE : %d\n", n);
+            break;
+        }
+        case OP_UPDATE_DONE:
+        {
+            int n = epcEvent->response;
+            SDL_Log("[SDL] OP_UPDATE_DONE n: %d\n", n);
+            if( n < SHARED_FILE_NUMBER)
+            {
+                shared_info->cur_idx = n;
+                if(shared_info->fileInfo[n].sharedFile
+                   && shared_info->fileInfo[n].ImageWidth != 0
+                   && shared_info->fileInfo[n].ImageHeight != 0)
+                {
+                    Tizen_glTexImage2d(n);
+                }
+                else
+                {
+                 SDL_Log("[SDL] OP_UPDATE_DONE Fail");
+                }
+            }
+            break;
+        }
+        case OP_RESIZE:
+        {
+                SDL_Log("Indicator client received: OP_RESIZE\n");
             break;
         }
     }
@@ -171,14 +227,13 @@ int handler_server_del(void *data, int ev_type, void *ev)
 int handler_server_data(void *data, int ev_type, void *ev)
 {
     Ecore_Ipc_Event_Server_Data *e = (Ecore_Ipc_Event_Server_Data *)ev;
-    SharedFileInfo* fileInfo = (SharedFileInfo*)data;
-    DataReceived(ev, fileInfo);
+    SharedIndicatorInfo* shared_info = (SharedIndicatorInfo*)data;
+    DataReceived(ev, shared_info);
     return 1;
 }
 
-Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedFileInfo* fileInfo)
+Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedIndicatorInfo* shared_info)
 {
-    Ecore_Ipc_Server* IpcServer;
     Ecore_Ipc_Type ipctype = ECORE_IPC_LOCAL_USER;
 
     if(!ecore_ipc_init())
@@ -188,13 +243,13 @@ Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedFileInfo* file
         return NULL;
     }
 
-    IpcServer = ecore_ipc_server_connect(ipctype, (char*)serviceName, 0, NULL);
+    Ecore_Ipc_Server* IpcServer = ecore_ipc_server_connect(ipctype, (char*)serviceName, 0, NULL);
 
     if(IpcServer)
     {
         ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, handler_server_add, NULL);
         ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, handler_server_del, NULL);
-        ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, handler_server_data, fileInfo);
+        ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, handler_server_data, shared_info);
     }
     else
     {
index b8624b2..bcd859b 100755 (executable)
@@ -36,6 +36,12 @@ typedef struct
 
 }SharedFileInfo;
 
+typedef struct
+{
+    SharedFileInfo fileInfo[2];
+    int cur_idx;
+}SharedIndicatorInfo;
+
 enum // opcodes
 {
    OP_RESIZE,
@@ -69,6 +75,6 @@ enum // opcodes
 
 
 unsigned char* CopyBuffer(SharedFileInfo* fileInfo);
-Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedFileInfo* fileInfo);
+Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedIndicatorInfo* shared_info);
 
 #endif
index 34f8d26..0a65747 100755 (executable)
@@ -78,7 +78,6 @@ GLuint cIndex;
 
 Uint32 _tizen_timer_callback_indicator(void *data)
 {
-    SDL_Log("[SDL} callbackck ckck clalall!\n");
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     drawIndicator(_this->windows);
@@ -161,8 +160,7 @@ static GLuint LoadShader(GLES2_Context* Mainctx, const char *shaderSrc, GLenum t
 
 }
 
-SharedFileInfo fileInfo;
-
+SharedIndicatorInfo shared_info;
 unsigned int textureID;
 unsigned int indicator_vbo[4], indicator_ibo[4];
 unsigned short indicator_index;
@@ -199,15 +197,14 @@ static void ModelMatrixTranslate(ModelMatrix* matrix, GLfloat x, GLfloat y, GLfl
     matrix->m[3][3] += (matrix->m[0][3] * x + matrix->m[1][3] * y + matrix->m[2][3] * z);
 }
 
-void Tizen_glTexImage2d()
+void Tizen_glTexImage2d(int idx)
 {
-
     GLES2_Context Mainctx;
     LoadContext(&Mainctx);
 
     Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
-    Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,
-                      0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
+    Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shared_info.fileInfo[idx].ImageWidth, shared_info.fileInfo[idx].ImageHeight,
+                      0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)(shared_info.fileInfo[idx].sharedFile->address));
 }
 
 void drawIndicator(SDL_Window *window)
@@ -253,10 +250,6 @@ void drawIndicator(SDL_Window *window)
         Mainctx.glVertexAttribPointer(cIndex, 2, GL_FLOAT, GL_FALSE, 0, vCoord);
         Mainctx.glUniformMatrix4fv(Mainctx.glGetUniformLocation(programObject,  "modelMatrix"), 1, GL_FALSE, mMatrix.m);
 
-        Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
-        if(fileInfo.ImageWidth!=0 && fileInfo.ImageHeight!=0)
-            Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
-
         Mainctx.glEnableVertexAttribArray(vIndex);
         Mainctx.glEnableVertexAttribArray(cIndex);
 
@@ -277,7 +270,7 @@ static int Indicator_GLES_Init(SDL_Window* window)
     ecore_wl_window_indicator_opacity_set(wind->window, ECORE_WL_INDICATOR_OPAQUE);
     ecore_wl_window_indicator_state_set(wind->window, ECORE_WL_INDICATOR_STATE_ON);
 
-    Ecore_Ipc_Server* IpcServer = serverConnection("elm_indicator", &fileInfo);
+    Ecore_Ipc_Server* IpcServer = serverConnection("elm_indicator", &shared_info);
     if(!IpcServer)
     {
         SDL_Log("Fail to connect elm_indicator!\n");
@@ -304,8 +297,6 @@ static int Indicator_GLES_Init(SDL_Window* window)
         " gl_FragColor = texture2D(s_texture,Coord);\n"
         "}\n";
 
-    ecore_main_loop_iterate();
-
     GLuint vertexShader;
     GLuint fragmentShader;
 
@@ -364,13 +355,11 @@ static int Indicator_GLES_Init(SDL_Window* window)
     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
-
-    if(fileInfo.ImageWidth != 0 && fileInfo.ImageHeight != 0)
-        Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
-
     wind->indicator_show = SDL_TRUE;
     wind->last_indicator_showtime = SDL_GetTicks();
 
+    ecore_main_loop_iterate();
+
     _tizen_indicator_event_filter();
 
     return 1;
@@ -557,11 +546,6 @@ SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window)
         Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[wind->indicator_type]);
         Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW);
 
-        Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
-
-        if(fileInfo.ImageWidth != 0 && fileInfo.ImageHeight != 0)
-            Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
-
         ModelMatrixLoadIdentity(&mMatrix);
         wind->indicator_show = SDL_TRUE;
         wind->last_indicator_showtime = SDL_GetTicks();
index db7ac37..cd7222d 100755 (executable)
@@ -40,7 +40,7 @@ typedef struct SDL_PrivateGLESData {
 #define Tizen_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
 #define Tizen_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
 
-extern void Tizen_glTexImage2d();
+extern void Tizen_glTexImage2d(int idx);
 extern void  SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window* window);
 
 extern int Tizen_GLES_LoadLibrary(_THIS, const char *path);