From c32344ebeb562b35a7eb5f2b33432037933a6528 Mon Sep 17 00:00:00 2001 From: "huiyu.eun" Date: Wed, 30 Nov 2016 19:04:08 +0900 Subject: [PATCH] Add remote surface indicator - If can use 'wayland_egl', client will use remote surface. - It dosesn't draw indicaotr when rotated 180 degree. - Clean-up code Change-Id: I61e002d373bd7312561a33638e8a5e623de9267b Signed-off-by: huiyu.eun --- configure | 6 +- configure.in | 6 +- packaging/SDL2.spec | 3 +- src/events/SDL_events.c | 12 +- src/video/SDL_egl.c | 1 - src/video/tizen/SDL_ecore_ipc.c | 58 ++--- src/video/tizen/SDL_ecore_ipc.h | 11 +- src/video/tizen/SDL_tizenmouse.c | 12 +- src/video/tizen/SDL_tizenopengles.c | 495 +++++++++++++++++++++++------------- src/video/tizen/SDL_tizenopengles.h | 8 +- src/video/tizen/SDL_tizenvideo.c | 4 + src/video/tizen/SDL_tizenwindow.c | 11 +- src/video/tizen/SDL_tizenwindow.h | 1 - 13 files changed, 398 insertions(+), 230 deletions(-) diff --git a/configure b/configure index 3e17be3..96ab610 100755 --- a/configure +++ b/configure @@ -18943,9 +18943,9 @@ $as_echo_n "checking for Tizen support... " >&6; } if test x$PKG_CONFIG != xno && \ test x$video_opengl_egl = xyes && \ test x$video_opengles_v2 = xyes; then - if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm ecore-ipc; then - TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc` - TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc` + if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm ecore-ipc tizen-remote-surface-client; then + TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc tizen-remote-surface-client` + TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc tizen-remote-surface-client` video_tizen=yes fi fi diff --git a/configure.in b/configure.in index bf4049e..ef6ff5a 100755 --- a/configure.in +++ b/configure.in @@ -1269,9 +1269,9 @@ CheckTizen() if test x$PKG_CONFIG != xno && \ test x$video_opengl_egl = xyes && \ test x$video_opengles_v2 = xyes; then - if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm ecore-ipc; then - TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc` - TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc` + if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm ecore-ipc tizen-remote-surface-client; then + TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc tizen-remote-surface-client` + TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf libdrm aul ecore-ipc tizen-remote-surface-client` video_tizen=yes fi fi diff --git a/packaging/SDL2.spec b/packaging/SDL2.spec index bdf6681..3933c98 100755 --- a/packaging/SDL2.spec +++ b/packaging/SDL2.spec @@ -30,6 +30,8 @@ BuildRequires: pkgconfig(wayland-egl) BuildRequires: pkgconfig(text-client) BuildRequires: pkgconfig(xdg-shell-client) BuildRequires: pkgconfig(tizen-extension-client) +BuildRequires: pkgconfig(tizen-remote-surface-client) +BuildRequires: pkgconfig(wayland-tbm-client) Requires: libwayland-extension-client BuildRequires: pkgconfig(xkbcommon) BuildRequires: pkgconfig(libpng) @@ -50,7 +52,6 @@ BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(ecore-imf) BuildRequires: pkgconfig(aul) - BuildRequires: Vulkan-LoaderAndValidationLayers BuildRequires: Vulkan-LoaderAndValidationLayers-devel diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 93a4d41..583c6f3 100755 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -472,17 +472,7 @@ SDL_PushEvent(SDL_Event * event) SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_GestureProcessEvent(event); - const char* hint = SDL_GetHint(SDL_HINT_ORIENTATIONS); - if(event->type == SDL_ROTATEEVENT ) - { - if(hint) - { - if(*hint != '\0') - { - SDL_IndicatorProcessEvent(event, _this->current_glwin); - } - } - } + return 1; } diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index f613829..48c0267 100755 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -265,7 +265,6 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa LOAD_FUNC(eglWaitGL); LOAD_FUNC(eglBindAPI); LOAD_FUNC(eglQueryString); - #if !defined(__WINRT__) _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display); if (!_this->egl_data->egl_display) { diff --git a/src/video/tizen/SDL_ecore_ipc.c b/src/video/tizen/SDL_ecore_ipc.c index 55d420f..e8a7f02 100755 --- a/src/video/tizen/SDL_ecore_ipc.c +++ b/src/video/tizen/SDL_ecore_ipc.c @@ -18,20 +18,16 @@ SharedFile* CreateSharedFile(char* SharedFileName, int size) mode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; sharedFile->fileDescriptor= shm_open( SharedFileName, O_RDONLY, mode ); - SDL_Log("sharedFile->fileDescriptor == %d", sharedFile->fileDescriptor); + SDL_Log("[SDL]sharedFile->fileDescriptor == %d", sharedFile->fileDescriptor); if(sharedFile->fileDescriptor >= 0) { sharedFile->fileName = SharedFileName; sharedFile->size = size; sharedFile->address = mmap( NULL, size, PROT_READ, MAP_SHARED, sharedFile->fileDescriptor, 0 ); if(sharedFile->address != MAP_FAILED) - { return sharedFile; - } else - { return NULL; - } } return sharedFile; @@ -41,14 +37,12 @@ LockFile* CreateLockeFile(char* LockFileName) { LockFile* lockFile = (LockFile*)malloc(sizeof(LockFile)); if(lockFile == NULL) - { return NULL; - } lockFile->fileDescriptor = open(LockFileName, O_RDWR); if(lockFile->fileDescriptor == -1) { - SDL_Log("Fail to open lock file!"); + SDL_Log("[SDL]Fail to open lock file!"); return NULL; } @@ -69,8 +63,8 @@ void SetSharedImageInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorIn 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); + SDL_Log("[SDL]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("[SDL]epcEvent->response: %d", n); } } } @@ -85,8 +79,8 @@ void SetLockFileInfo(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorInfo 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); + SDL_Log("[SDL]SetLockFileInfo: width %d, height %d, filename %s", shared_info->fileInfo[n].ImageWidth, shared_info->fileInfo[n].ImageHeight, shared_info->fileInfo[n].LockFileName); + SDL_Log("[SDL]epcEvent->response: %d", n); } } } @@ -96,7 +90,7 @@ unsigned char* CopyBuffer(SharedFileInfo* fileInfo) return (unsigned char*)fileInfo->sharedFile->address; } -void shared_free(SharedIndicatorInfo *shared_info, int n) +void Tizen_Indicator_SharedFile_Free(SharedIndicatorInfo *shared_info, int n) { LockFile* lockFile = shared_info->fileInfo[n].lockFile; if(lockFile!=NULL) { @@ -107,6 +101,7 @@ void shared_free(SharedIndicatorInfo *shared_info, int n) return; } } + free(lockFile); lockFile = NULL; } @@ -120,7 +115,8 @@ void shared_free(SharedIndicatorInfo *shared_info, int n) sharedFile->fileDescriptor = 1; sharedFile->fileName = NULL; sharedFile->size = 0; - + free(sharedFile); + sharedFile = NULL; } } @@ -132,9 +128,9 @@ void LoadSharedImage(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorInfo if(n < SHARED_FILE_NUMBER) { 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); + SDL_Log("[SDL]The shared file name is %s", sharedFilename); - shared_free(shared_info, n); + Tizen_Indicator_SharedFile_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) @@ -143,7 +139,7 @@ void LoadSharedImage(Ecore_Ipc_Event_Server_Data* epcEvent, SharedIndicatorInfo } else { - SDL_Log("fileInfo->sharedFile == NULL"); + SDL_Log("[SDL]fileInfo->sharedFile == NULL"); } } } @@ -155,31 +151,26 @@ void DataReceived(void* event, SharedIndicatorInfo* shared_info) { case OP_SHM_REF0: { - SDL_Log("Indicator client received: OP_SHM_REF0\n"); + SDL_Log("[SDL]Indicator client received: OP_SHM_REF0\n"); SetSharedImageInfo(epcEvent, shared_info); break; } case OP_SHM_REF1: { - SDL_Log("Indicator client received: OP_SHM_REF1\n"); + SDL_Log("[SDL]Indicator client received: OP_SHM_REF1\n"); SetLockFileInfo(epcEvent, shared_info); break; } case OP_SHM_REF2: { - SDL_Log("Indicator client received: OP_SHM_REF2\n"); + SDL_Log("[SDL]Indicator client received: OP_SHM_REF2\n"); LoadSharedImage(epcEvent, shared_info); break; } - case OP_PIXMAP_REF: - { - SDL_Log("Indicator client received: OP_PIXMAP_REF!\n"); - break; - } case OP_UPDATE: { int n = epcEvent->response; - SDL_Log("Indicator client received: OP_UPDATE : %d\n", n); + SDL_Log("[SDL]Indicator client received: OP_UPDATE : %d\n", n); break; } case OP_UPDATE_DONE: @@ -193,18 +184,27 @@ void DataReceived(void* event, SharedIndicatorInfo* shared_info) && shared_info->fileInfo[n].ImageWidth != 0 && shared_info->fileInfo[n].ImageHeight != 0) { - Tizen_glTexImage2d(n); + Tizen_glTexImage2D(n); } else { - SDL_Log("[SDL] OP_UPDATE_DONE Fail"); + SDL_Log("[SDL] OP_UPDATE_DONE Fail"); } } break; } + case OP_GL_REF: + { + SDL_Log("[SDL] receive socket to client (resource_id:%u)", epcEvent->ref); + if (Tizen_remote_surface_init()) + { + Tizen_remote_indicator(epcEvent->ref); + } + break; + } case OP_RESIZE: { - SDL_Log("Indicator client received: OP_RESIZE\n"); + SDL_Log("[SDL]Indicator client received: OP_RESIZE\n"); break; } } diff --git a/src/video/tizen/SDL_ecore_ipc.h b/src/video/tizen/SDL_ecore_ipc.h index bcd859b..09a27ae 100755 --- a/src/video/tizen/SDL_ecore_ipc.h +++ b/src/video/tizen/SDL_ecore_ipc.h @@ -39,6 +39,14 @@ typedef struct typedef struct { SharedFileInfo fileInfo[2]; + + /* for tizen remote manager */ + struct tizen_remote_surface_manager *tizen_rsm; + struct tizen_remote_surface *tizen_rs; + struct wayland_tbm_client *tbm_client; + struct wl_tbm *wl_tbm; + + void* eglImage_Indicator; int cur_idx; }SharedIndicatorInfo; @@ -70,11 +78,12 @@ enum // opcodes OP_EV_HOLD, OP_MSG_PARENT, OP_MSG, - OP_PIXMAP_REF, + OP_GL_REF, }; unsigned char* CopyBuffer(SharedFileInfo* fileInfo); Ecore_Ipc_Server* serverConnection(const char* serviceName, SharedIndicatorInfo* shared_info); +void Tizen_Indicator_SharedFile_Free(SharedIndicatorInfo *shared_info, int n); #endif diff --git a/src/video/tizen/SDL_tizenmouse.c b/src/video/tizen/SDL_tizenmouse.c index e365853..27e5846 100755 --- a/src/video/tizen/SDL_tizenmouse.c +++ b/src/video/tizen/SDL_tizenmouse.c @@ -266,7 +266,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) wind = window->driverdata; SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "mouse down (%d x %d)",e->x,e->y); - if(wind->indicator_type == 0) + if(wind->rotation == 0) { if(e->x > window->x && e->x < window->x + window->w && e->y > window->y && e->y < window->y + 52) @@ -277,7 +277,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) _tizen_indicator_event_filter(); } } - else if(wind->indicator_type == 1) + else if(wind->rotation == 90) { if(e->x > window->x && e->x < window->x + 52 && e->y > window->y && e->y < window->y + window->h) @@ -287,8 +287,8 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) wind->last_indicator_showtime = SDL_GetTicks(); _tizen_indicator_event_filter(); } - } - else if(wind->indicator_type == 2) + }/* + else if(wind->rotation == 180) { if(e->x > window->x && e->x < window->x + window->w && e->y > window->y + window->h -52 && e->y < window->y + window->h) @@ -298,8 +298,8 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) wind->last_indicator_showtime = SDL_GetTicks(); _tizen_indicator_event_filter(); } - } - else if(wind->indicator_type == 3) + }*/ + else if(wind->rotation == 270) { if(e->x > window->x + window->w -52 && e->x < window->x + window->w && e->y > window->y && e->y < window->y + window->h) diff --git a/src/video/tizen/SDL_tizenopengles.c b/src/video/tizen/SDL_tizenopengles.c index 0a65747..9928633 100755 --- a/src/video/tizen/SDL_tizenopengles.c +++ b/src/video/tizen/SDL_tizenopengles.c @@ -29,8 +29,12 @@ #include "SDL_tizenevents_c.h" #include "SDL_ecore_ipc.h" +#include "SDL_tizenvideo.h" -#include +#include +#include +#include +#include #if SDL_VIDEO_OPENGL #include "SDL_opengl.h" @@ -45,6 +49,13 @@ #include "SDL_opengles2.h" #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */ +/* EGL implementation of SDL OpenGL ES support */ +typedef struct GLES2_Context +{ + #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; + #include "../../render/opengles2/SDL_gles2funcs.h" + #undef SDL_PROC +} GLES2_Context; GLfloat vVertices[18]={ 1.0f, 1.0f, 0.0f, @@ -63,24 +74,101 @@ GLfloat vCoord[12] = { 0.0f, 0.0f, 0.0f, 1.0f}; +PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = NULL; +PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = NULL; +PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = NULL; + +SharedIndicatorInfo shared_info; +unsigned int textureID; +unsigned int indicator_vbo[4], indicator_ibo[4]; +ModelMatrix mMatrix; -/* EGL implementation of SDL OpenGL ES support */ -typedef struct GLES2_Context -{ - #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; - #include "../../render/opengles2/SDL_gles2funcs.h" - #undef SDL_PROC -} GLES2_Context; GLuint programObject; GLuint vIndex; GLuint cIndex; + +static int LoadContext(GLES2_Context * data) +{ + #define SDL_PROC(ret,func,params) \ + do { \ + data->func = SDL_GL_GetProcAddress(#func); \ + if ( ! data->func ) { \ + return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ + } \ + } while ( 0 ); + + #include "../../render/opengles2/SDL_gles2funcs.h" + #undef SDL_PROC + + return 0; +} + +static void +_tizen_rs_cb_buffer_update(void *data, struct tizen_remote_surface *trs, struct wl_buffer *buffer, uint32_t time) +{ + tizen_remote_surface_transfer_visibility(trs, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE); + tbm_surface_h tbmSurface= wl_buffer_get_user_data(buffer); + + if(eglCreateImageKHR != NULL && glEGLImageTargetTexture2DOES != NULL && eglDestroyImageKHR != NULL) + { + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + + if(shared_info.eglImage_Indicator != NULL) + eglDestroyImageKHR(_this->egl_data->egl_display, shared_info.eglImage_Indicator); + + shared_info.eglImage_Indicator = eglCreateImageKHR(_this->egl_data->egl_display, + EGL_NO_CONTEXT, EGL_NATIVE_SURFACE_TIZEN, tbmSurface, NULL); + + if(shared_info.eglImage_Indicator == NULL) + { + SDL_Log("[SDL] eglImage is NULL"); + return; + } + SDL_Log("[SDL] eglImage : %p", shared_info.eglImage_Indicator); + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, shared_info.eglImage_Indicator); + } + else + { + tbm_surface_info_s info; + tbm_surface_map(tbmSurface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info); + + SDL_Log("[SDL] Buffer Update %p %p (%dx%d), format:%d", buffer, tbmSurface, info.width, info.height, info.format); + SDL_Log("[SDL] Info size:%d, offset:%d, stride:%d", info.planes[0].size, info.planes[0].offset, info.planes[0].stride); + + GLES2_Context Mainctx; + LoadContext(&Mainctx); + + Mainctx.glBindTexture(GL_TEXTURE_2D, textureID); + Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, info.planes[0].stride/4, info.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned int*)info.planes[0].ptr); + + if (tbm_surface_unmap (tbmSurface) != TBM_SURFACE_ERROR_NONE) + SDL_Log("Failed to unmap tbm_surface\n"); + } + + if (tbm_surface_destroy (tbmSurface) != TBM_SURFACE_ERROR_NONE) + SDL_Log("Failed to destroy tbm_surface\n"); + +} + +static void +_tizen_rs_cb_missing(void *data, struct tizen_remote_surface *trs) +{ + SDL_Log("Plug is missing...! "); +} + +static const struct tizen_remote_surface_listener _extn_gl_plug_listener = +{ + _tizen_rs_cb_buffer_update, + _tizen_rs_cb_missing, +}; + Uint32 _tizen_timer_callback_indicator(void *data) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - drawIndicator(_this->windows); + Tizen_DrawIndicator(_this->windows); SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) _this->windows->driverdata)->egl_surface); return ECORE_CALLBACK_RENEW; @@ -114,22 +202,6 @@ Tizen_GLES_LoadLibrary(_THIS, const char *path) return ret; } -static int LoadContext(GLES2_Context * data) -{ - #define SDL_PROC(ret,func,params) \ - do { \ - data->func = SDL_GL_GetProcAddress(#func); \ - if ( ! data->func ) { \ - return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ - } \ - } while ( 0 ); - - #include "../../render/opengles2/SDL_gles2funcs.h" - #undef SDL_PROC - - return 0; -} - static GLuint LoadShader(GLES2_Context* Mainctx, const char *shaderSrc, GLenum type) { GLuint shader; @@ -160,12 +232,6 @@ static GLuint LoadShader(GLES2_Context* Mainctx, const char *shaderSrc, GLenum t } -SharedIndicatorInfo shared_info; -unsigned int textureID; -unsigned int indicator_vbo[4], indicator_ibo[4]; -unsigned short indicator_index; -ModelMatrix mMatrix; - extern void ModelMatrixLoadIdentity(ModelMatrix* matrix) { matrix->m[0][0] = 1.0f; @@ -197,7 +263,22 @@ 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(int idx) +void Tizen_remote_indicator(int res_id) +{ + if(!shared_info.tizen_rs) { + //create tizen_remote_surface + shared_info.tizen_rs = tizen_remote_surface_manager_create_surface(shared_info.tizen_rsm, res_id, shared_info.wl_tbm); + if(!shared_info.tizen_rs) + { + SDL_Log("tizen_rs is NULL"); + return; + } + tizen_remote_surface_add_listener(shared_info.tizen_rs, &_extn_gl_plug_listener, NULL); + tizen_remote_surface_redirect(shared_info.tizen_rs); + } +} + +void Tizen_glTexImage2D(int idx) { GLES2_Context Mainctx; LoadContext(&Mainctx); @@ -207,7 +288,7 @@ void Tizen_glTexImage2d(int idx) 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)(shared_info.fileInfo[idx].sharedFile->address)); } -void drawIndicator(SDL_Window *window) +void Tizen_DrawIndicator(SDL_Window *window) { SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; if (wdata->received_rotation == 1) { @@ -217,18 +298,18 @@ void drawIndicator(SDL_Window *window) if(wdata->last_indicator_showtime + 3000< SDL_GetTicks()) { - switch(wdata->indicator_type) + switch(wdata->rotation) { - case 0://0 + case 0: ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f); break; - case 1://90 + case 90: ModelMatrixTranslate(&mMatrix, -0.02f, 0.0f, 0.0f); break; - case 2://180 + case 180: ModelMatrixTranslate(&mMatrix, 0.0f, -0.02f, 0.0f); break; - case 3://270 + case 270: ModelMatrixTranslate(&mMatrix, 0.02f, 0.0f, 0.0f); break; } @@ -263,7 +344,80 @@ void drawIndicator(SDL_Window *window) } } -static int Indicator_GLES_Init(SDL_Window* window) +SDL_bool Tizen_remote_surface_init(void) +{ + Eina_Inlist *globals; + Ecore_Wl_Global *global; + struct wl_registry *registry; + if (!shared_info.tizen_rsm) + { + registry = ecore_wl_registry_get(); + globals = ecore_wl_globals_get(); + + if (!registry || !globals) + { + SDL_Log( "Could not get registry(%p) or global list(%p)\n", registry, globals); + return SDL_FALSE; + } + + EINA_INLIST_FOREACH(globals, global) + { + if (!strcmp(global->interface, "tizen_remote_surface_manager")) + { + shared_info.tizen_rsm = wl_registry_bind(registry, global->id, + &tizen_remote_surface_manager_interface, 1); + SDL_Log("[SDL] Create tizen_rsm : %p",shared_info.tizen_rsm); + } + } + shared_info.tizen_rs = NULL; + } + if (!shared_info.tizen_rsm) + { + SDL_Log("Could not bind tizen_remote_surface_manager"); + return SDL_FALSE; + } + + if(!shared_info.tbm_client) + { + shared_info.tbm_client = (struct wayland_tbm_client *)wayland_tbm_client_init(ecore_wl_display_get()); + shared_info.wl_tbm = (struct wl_tbm *)wayland_tbm_client_get_wl_tbm(shared_info.tbm_client); + if (!shared_info.wl_tbm) + { + SDL_Log("[SDL]wl_tbm is NULL"); + return SDL_FALSE; + } + } + + eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("eglCreateImageKHR"); + eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("eglDestroyImageKHR"); + glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("glEGLImageTargetTexture2DOES"); + + return SDL_TRUE; +} + +int Tizen_FiniIndicator() +{ + int n; + for (n=0; n < SHARED_FILE_NUMBER; n++) + Tizen_Indicator_SharedFile_Free(&shared_info, n); + + if(shared_info.eglImage_Indicator != NULL) + eglDestroyImageKHR(SDL_GetVideoDevice()->egl_data->egl_display, shared_info.eglImage_Indicator); + + if (shared_info.tizen_rs) + tizen_remote_surface_destroy(shared_info.tizen_rs); + if (shared_info.tbm_client) + wayland_tbm_client_deinit(shared_info.tbm_client); + if (shared_info.tizen_rsm) + tizen_remote_surface_manager_destroy(shared_info.tizen_rsm); + + GLES2_Context Mainctx; + LoadContext(&Mainctx); + Mainctx.glDeleteProgram(programObject); + return SDL_TRUE; +} + +int Indicator_GLES_Init(SDL_Window* window) { SDL_WindowData *wind = window->driverdata; ecore_wl_indicator_visible_type_set(wind->window, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN); @@ -359,6 +513,7 @@ static int Indicator_GLES_Init(SDL_Window* window) wind->last_indicator_showtime = SDL_GetTicks(); ecore_main_loop_iterate(); + SDL_IndicatorProcessEvent(window, wind->rotation); _tizen_indicator_event_filter(); @@ -387,7 +542,7 @@ void Tizen_GLES_SwapWindow(_THIS, SDL_Window *window) { if(!((SDL_WindowData*)window->driverdata)->indicator_show) { - drawIndicator(window); + Tizen_DrawIndicator(window); SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); } } @@ -413,146 +568,144 @@ Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context) } void -SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window) +SDL_IndicatorProcessEvent(SDL_Window *window, int rot) { GLES2_Context Mainctx; LoadContext(&Mainctx); - SDL_WindowData *wind = window->driverdata; - - if(event->type == SDL_ROTATEEVENT) + SDL_WindowData *wind = window->driverdata; + if( rot == 0) { - wind->indicator_type = ((int)event->user.data1) / 90; - if( wind->indicator_type == 0) - { - SDL_Log("===rotate 0 degree!\n"); - vVertices[0] = 1.0f; - vVertices[1] = 1.0f; - vVertices[3] = -1.0f; - vVertices[4] = 0.92f; - vVertices[6] = 1.0f; - vVertices[7] = 0.92f; - vVertices[9] = 1.0f; - vVertices[10] = 1.0f; - vVertices[12] = -1.0f; - vVertices[13] = 1.0f; - vVertices[15] = -1.0f; - vVertices[16] = 0.92f; - - vCoord[0] = 1.0f; - vCoord[1] = 0.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 1.0f; - vCoord[6] = 1.0f; - vCoord[7] = 0.0f; - vCoord[8] = 0.0f; - vCoord[9] = 0.0f; - vCoord[10] = 0.0f; - vCoord[11] = 1.0f; - - } - else if(wind->indicator_type == 1) - { - SDL_Log("===rotate 90 degree!\n"); - vVertices[0] = -0.86f; - vVertices[1] = 1.0f; - vVertices[3] = -0.86f; - vVertices[4] = -1.0f; - vVertices[6] = -1.0f; - vVertices[7] = 1.0f; - vVertices[9] = -1.0f; - vVertices[10] = -1.0f; - vVertices[12] = -0.86f; - vVertices[13] = -1.0f; - vVertices[15] = -1.0f; - vVertices[16] = 1.0f; - - vCoord[0] = 1.0f; - vCoord[1] = 1.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 0.0f; - vCoord[6] = 0.0f; - vCoord[7] = 0.0f; - vCoord[8] = 0.0f; - vCoord[9] = 1.0f; - vCoord[10] = 1.0f; - vCoord[11] = 0.0f; - } - else if(wind->indicator_type == 2) - { - SDL_Log("===rotate 180 degree!\n"); - vVertices[0] = -1.0f; - vVertices[1] = -1.0f; - vVertices[3] = -1.0f; - vVertices[4] = -0.92f; - vVertices[6] = 1.0f; - vVertices[7] = -1.0f; - vVertices[9] = 1.0f; - vVertices[10] = -0.92f; - vVertices[12] = -1.0f; - vVertices[13] = -0.92f; - vVertices[15] = 1.0f; - vVertices[16] = -1.0f; - - vCoord[0] = 1.0f; - vCoord[1] = 0.0f; - vCoord[2] = 1.0f; - vCoord[3] = 1.0f; - vCoord[4] = 0.0f; - vCoord[5] = 0.0f; - vCoord[6] = 0.0f; - vCoord[7] = 1.0f; - vCoord[8] = 1.0f; - vCoord[9] = 1.0f; - vCoord[10] = 0.0f; - vCoord[11] = 0.0f; - } - else if(wind->indicator_type == 3) - { - SDL_Log("===rotate 270 degree!\n"); - vVertices[0] = 1.0f; - vVertices[1] = 1.0f; - vVertices[3] = 0.86f; - vVertices[4] = 1.0f; - vVertices[6] = 1.0f; - vVertices[7] = -1.0f; - vVertices[9] = 0.86f; - vVertices[10] = -1.0f; - vVertices[12] = 0.86f; - vVertices[13] = 1.0f; - vVertices[15] = 1.0f; - vVertices[16] = -1.0f; - - vCoord[0] = 0.0f; - vCoord[1] = 0.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 0.0f; - vCoord[6] = 1.0f; - vCoord[7] = 1.0f; - vCoord[8] = 0.0f; - vCoord[9] = 1.0f; - vCoord[10] = 1.0f; - vCoord[11] = 0.0f; - } + SDL_Log("===rotate 0 degree!\n"); + vVertices[0] = 1.0f; + vVertices[1] = 1.0f; + vVertices[3] = -1.0f; + vVertices[4] = 0.92f; + vVertices[6] = 1.0f; + vVertices[7] = 0.92f; + vVertices[9] = 1.0f; + vVertices[10] = 1.0f; + vVertices[12] = -1.0f; + vVertices[13] = 1.0f; + vVertices[15] = -1.0f; + vVertices[16] = 0.92f; + + vCoord[0] = 1.0f; + vCoord[1] = 0.0f; + vCoord[2] = 0.0f; + vCoord[3] = 1.0f; + vCoord[4] = 1.0f; + vCoord[5] = 1.0f; + vCoord[6] = 1.0f; + vCoord[7] = 0.0f; + vCoord[8] = 0.0f; + vCoord[9] = 0.0f; + vCoord[10] = 0.0f; + vCoord[11] = 1.0f; + } + else if(rot == 90) + { + SDL_Log("===rotate 90 degree!\n"); + vVertices[0] = -0.86f; + vVertices[1] = 1.0f; + vVertices[3] = -0.86f; + vVertices[4] = -1.0f; + vVertices[6] = -1.0f; + vVertices[7] = 1.0f; + vVertices[9] = -1.0f; + vVertices[10] = -1.0f; + vVertices[12] = -0.86f; + vVertices[13] = -1.0f; + vVertices[15] = -1.0f; + vVertices[16] = 1.0f; + + vCoord[0] = 1.0f; + vCoord[1] = 1.0f; + vCoord[2] = 0.0f; + vCoord[3] = 1.0f; + vCoord[4] = 1.0f; + vCoord[5] = 0.0f; + vCoord[6] = 0.0f; + vCoord[7] = 0.0f; + vCoord[8] = 0.0f; + vCoord[9] = 1.0f; + vCoord[10] = 1.0f; + vCoord[11] = 0.0f; + } + else if(rot == 180) + { + SDL_Log("===rotate 180 degree!\n"); + vVertices[0] = -1.0f; + vVertices[1] = -1.0f; + vVertices[3] = -1.0f; + vVertices[4] = -0.92f; + vVertices[6] = 1.0f; + vVertices[7] = -1.0f; + vVertices[9] = 1.0f; + vVertices[10] = -0.92f; + vVertices[12] = -1.0f; + vVertices[13] = -0.92f; + vVertices[15] = 1.0f; + vVertices[16] = -1.0f; + + vCoord[0] = 1.0f; + vCoord[1] = 0.0f; + vCoord[2] = 1.0f; + vCoord[3] = 1.0f; + vCoord[4] = 0.0f; + vCoord[5] = 0.0f; + vCoord[6] = 0.0f; + vCoord[7] = 1.0f; + vCoord[8] = 1.0f; + vCoord[9] = 1.0f; + vCoord[10] = 0.0f; + vCoord[11] = 0.0f; + } + else if(rot == 270) + { + SDL_Log("===rotate 270 degree!\n"); + vVertices[0] = 1.0f; + vVertices[1] = 1.0f; + vVertices[3] = 0.86f; + vVertices[4] = 1.0f; + vVertices[6] = 1.0f; + vVertices[7] = -1.0f; + vVertices[9] = 0.86f; + vVertices[10] = -1.0f; + vVertices[12] = 0.86f; + vVertices[13] = 1.0f; + vVertices[15] = 1.0f; + vVertices[16] = -1.0f; + + vCoord[0] = 0.0f; + vCoord[1] = 0.0f; + vCoord[2] = 0.0f; + vCoord[3] = 1.0f; + vCoord[4] = 1.0f; + vCoord[5] = 0.0f; + vCoord[6] = 1.0f; + vCoord[7] = 1.0f; + vCoord[8] = 0.0f; + vCoord[9] = 1.0f; + vCoord[10] = 1.0f; + vCoord[11] = 0.0f; + + //Invisible Indicator + wind->indicator_show = SDL_FALSE; + _tizen_indicator_event_filter(); + } - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[wind->indicator_type]); - Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW); - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[wind->indicator_type]); - Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW); + Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[wind->rotation/90]); + Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW); + Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[wind->rotation/90]); + Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW); - ModelMatrixLoadIdentity(&mMatrix); - wind->indicator_show = SDL_TRUE; - wind->last_indicator_showtime = SDL_GetTicks(); + ModelMatrixLoadIdentity(&mMatrix); + wind->indicator_show = SDL_TRUE; + wind->last_indicator_showtime = SDL_GetTicks(); - _tizen_indicator_event_filter(); + _tizen_indicator_event_filter(); - } } #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */ diff --git a/src/video/tizen/SDL_tizenopengles.h b/src/video/tizen/SDL_tizenopengles.h index cd7222d..be66998 100755 --- a/src/video/tizen/SDL_tizenopengles.h +++ b/src/video/tizen/SDL_tizenopengles.h @@ -40,14 +40,18 @@ typedef struct SDL_PrivateGLESData { #define Tizen_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define Tizen_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -extern void Tizen_glTexImage2d(int idx); -extern void SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window* window); +extern void Tizen_glTexImage2D(int idx); +extern void SDL_IndicatorProcessEvent(SDL_Window* window, int rot); extern int Tizen_GLES_LoadLibrary(_THIS, const char *path); extern SDL_GLContext Tizen_GLES_CreateContext(_THIS, SDL_Window *window); extern void Tizen_GLES_SwapWindow(_THIS, SDL_Window *window); extern int Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context); extern void Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context); +extern int Tizen_FiniIndicator(); + +extern SDL_bool Tizen_remote_surface_init(void); +extern void Tizen_remote_indicator(int res_id); typedef struct { diff --git a/src/video/tizen/SDL_tizenvideo.c b/src/video/tizen/SDL_tizenvideo.c index 7e6dd88..dacdd59 100755 --- a/src/video/tizen/SDL_tizenvideo.c +++ b/src/video/tizen/SDL_tizenvideo.c @@ -192,9 +192,13 @@ Tizen_VideoQuit(_THIS) { SDL_VideoData *data = _this->driverdata; + Tizen_FiniIndicator(); + Tizen_DeinitWindow(_this); Tizen_FiniKeyboard(); Tizen_FiniMouse(); + + SDL_tizen_app_exit(); ecore_wl_shutdown(); free(data); diff --git a/src/video/tizen/SDL_tizenwindow.c b/src/video/tizen/SDL_tizenwindow.c index b329cdc..4df67c5 100755 --- a/src/video/tizen/SDL_tizenwindow.c +++ b/src/video/tizen/SDL_tizenwindow.c @@ -191,7 +191,6 @@ Tizen_CreateWindow(_THIS, SDL_Window *window) wind->rotation = 0; wind->rotation_supported = 0; wind->received_rotation = 0; - wind->indicator_type = 0; ecore_wl_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h); #if SDL_VIDEO_OPENGL_EGL @@ -420,6 +419,16 @@ _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->h, window->w); } wind->received_rotation = 1; + + const char* hint = SDL_GetHint(SDL_HINT_ORIENTATIONS); + if(hint) + { + if(*hint != '\0') + { + SDL_IndicatorProcessEvent(_this->current_glwin, wind->rotation); + } + } + return ECORE_CALLBACK_PASS_ON; } diff --git a/src/video/tizen/SDL_tizenwindow.h b/src/video/tizen/SDL_tizenwindow.h index 1ee4e91..1defe7d 100755 --- a/src/video/tizen/SDL_tizenwindow.h +++ b/src/video/tizen/SDL_tizenwindow.h @@ -45,7 +45,6 @@ typedef struct { SDL_bool indicator_show; Uint32 last_indicator_showtime; - int indicator_type; } SDL_WindowData; -- 2.7.4