From 12247a0f4d9b13e593e34c05bb6378db04ba82da Mon Sep 17 00:00:00 2001 From: "huiyu.eun" Date: Thu, 17 Nov 2016 16:17:12 +0900 Subject: [PATCH] Draw indicator without calling SDL_GL_SwapWindow. Change-Id: Ibcb78ad8a99f534d207e9dd27ca40387dc9984e9 Signed-off-by: huiyu.eun --- src/render/opengles2/SDL_gles2funcs.h | 3 + src/video/tizen/SDL_tizenmouse.c | 4 + src/video/tizen/SDL_tizenopengles.c | 184 +++++++++++++++++++++------------- src/video/tizen/SDL_tizenwindow.h | 3 +- 4 files changed, 121 insertions(+), 73 deletions(-) diff --git a/src/render/opengles2/SDL_gles2funcs.h b/src/render/opengles2/SDL_gles2funcs.h index 0ecfa7f..caebfc5 100644 --- a/src/render/opengles2/SDL_gles2funcs.h +++ b/src/render/opengles2/SDL_gles2funcs.h @@ -73,3 +73,6 @@ SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *)) SDL_PROC(void, glBindBuffer, (GLenum, GLuint)) SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum)) SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *)) + +SDL_PROC(GLboolean , glIsEnabled, (GLenum)) + diff --git a/src/video/tizen/SDL_tizenmouse.c b/src/video/tizen/SDL_tizenmouse.c index fae9019..947068d 100755 --- a/src/video/tizen/SDL_tizenmouse.c +++ b/src/video/tizen/SDL_tizenmouse.c @@ -272,6 +272,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) ModelMatrixLoadIdentity(&mMatrix); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } } else if(window->indicator_type == 1) @@ -282,6 +283,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) ModelMatrixLoadIdentity(&mMatrix); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } } else if(window->indicator_type == 2) @@ -292,6 +294,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) ModelMatrixLoadIdentity(&mMatrix); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } } else if(window->indicator_type == 3) @@ -302,6 +305,7 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) ModelMatrixLoadIdentity(&mMatrix); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } } diff --git a/src/video/tizen/SDL_tizenopengles.c b/src/video/tizen/SDL_tizenopengles.c index b32f8d6..86df032 100755 --- a/src/video/tizen/SDL_tizenopengles.c +++ b/src/video/tizen/SDL_tizenopengles.c @@ -30,6 +30,7 @@ #include "SDL_ecore_ipc.h" +#include #if SDL_VIDEO_OPENGL #include "SDL_opengl.h" @@ -72,6 +73,38 @@ typedef struct GLES2_Context } GLES2_Context; GLuint programObject; +GLuint vIndex; +GLuint cIndex; + +Uint32 _tizen_timer_callback_indicator(void *data) +{ + SDL_Log("[SDL} callbackck ckck clalall!\n"); + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + + drawIndicator(_this->windows); + SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) _this->windows->driverdata)->egl_surface); + + return ECORE_CALLBACK_RENEW; +} + +int +_tizen_indicator_event_filter() +{ + SDL_Window *window = SDL_GetVideoDevice()->windows; + SDL_WindowData *wind = window->driverdata; + + if(window->indicator_show && wind->indicator_timer == NULL) + { + wind->indicator_timer = ecore_timer_add(0.02, _tizen_timer_callback_indicator, NULL); + } + else if(!window->indicator_show && wind->indicator_timer != NULL) + { + ecore_timer_del(wind ->indicator_timer); + wind->indicator_timer = NULL; + } + + return 1; +} int Tizen_GLES_LoadLibrary(_THIS, const char *path) @@ -133,6 +166,7 @@ SharedFileInfo fileInfo; unsigned int textureID; unsigned int indicator_vbo[4], indicator_ibo[4]; unsigned short indicator_index; +ModelMatrix mMatrix; extern void ModelMatrixLoadIdentity(ModelMatrix* matrix) { @@ -176,7 +210,66 @@ void Tizen_glTexImage2d() 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address); } - ModelMatrix mMatrix; +void drawIndicator(SDL_Window *window) +{ + SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; + if (wdata->received_rotation == 1) { + ecore_wl_window_rotation_change_done_send(wdata->window); + wdata->received_rotation = 0; + } + + if(window->last_indicator_showtime + 3000< SDL_GetTicks()) + { + switch(window->indicator_type) + { + case 0://0 + ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f); + break; + case 1://90 + ModelMatrixTranslate(&mMatrix, -0.02f, 0.0f, 0.0f); + break; + case 2://180 + ModelMatrixTranslate(&mMatrix, 0.0f, -0.02f, 0.0f); + break; + case 3://270 + ModelMatrixTranslate(&mMatrix, 0.02f, 0.0f, 0.0f); + break; + } + } + + if(window->last_indicator_showtime + 3500 indicator_show = SDL_FALSE; + _tizen_indicator_event_filter(); + } + + if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && window->indicator_show) + { + GLES2_Context Mainctx; + LoadContext(&Mainctx); + Mainctx.glUseProgram(programObject); + + Mainctx.glBindBuffer(GL_ARRAY_BUFFER, 0); + Mainctx.glVertexAttribPointer(vIndex, 3, GL_FLOAT, GL_FALSE, 0, vVertices); + 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); + + GLboolean isDepthTest = Mainctx.glIsEnabled(GL_DEPTH_TEST); + if(isDepthTest) Mainctx.glDisable(GL_DEPTH_TEST); + Mainctx.glDrawArrays(GL_TRIANGLES, 0, 6); + + if(isDepthTest) Mainctx.glEnable(GL_DEPTH_TEST); + Mainctx.glDisableVertexAttribArray(vIndex); + Mainctx.glDisableVertexAttribArray(cIndex); + } +} + static int Indicator_GLES_Init(SDL_Window* window) { SDL_WindowData *wind = window->driverdata; @@ -251,26 +344,14 @@ static int Indicator_GLES_Init(SDL_Window* window) return 0; } - Mainctx.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Mainctx.glEnable(GL_DEPTH_TEST); - /* Generate buffer object names */ - Mainctx.glGenBuffers(4, indicator_vbo); - /* Bind a named buffer object */ - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[0]); - /* Ceates and initializes a buffer object's data store */ - Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW); - - /* Generate buffer object names */ - Mainctx.glGenBuffers(4, indicator_ibo); - /* Bind a named buffer object */ - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[0]); - /* Ceates and initializes a buffer object's data store */ - Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW); + vIndex = Mainctx.glGetAttribLocation(programObject, "vVertices"); + cIndex = Mainctx.glGetAttribLocation(programObject, "vCoord"); - Mainctx.glBindAttribLocation(programObject, 0, "vVertices"); - Mainctx.glBindAttribLocation(programObject, 1, "vCoord"); + Mainctx.glBindAttribLocation(programObject, vIndex, "vVertices"); + Mainctx.glBindAttribLocation(programObject, cIndex, "vCoord"); ModelMatrixLoadIdentity(&mMatrix); @@ -283,10 +364,15 @@ 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); - Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address); + + 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); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + + _tizen_indicator_event_filter(); + return 1; } @@ -311,62 +397,12 @@ Tizen_GLES_CreateContext(_THIS, SDL_Window *window) void Tizen_GLES_SwapWindow(_THIS, SDL_Window *window) { - SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; - if (wdata->received_rotation == 1) { - ecore_wl_window_rotation_change_done_send(wdata->window); - wdata->received_rotation = 0; - } - - if(window->last_indicator_showtime + 3000 < SDL_GetTicks()) - { - switch(window->indicator_type) - { - case 0://0 - ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f); - break; - case 1://90 - ModelMatrixTranslate(&mMatrix, -0.02f, 0.0f, 0.0f); - break; - case 2://180 - ModelMatrixTranslate(&mMatrix, 0.0f, -0.02f, 0.0f); - break; - case 3://270 - ModelMatrixTranslate(&mMatrix, 0.02f, 0.0f, 0.0f); - break; - } - } - - Uint32 time = window->last_indicator_showtime; - Uint32 getTick = SDL_GetTicks(); - if(time + 3000> getTick && time + 4000 < getTick) - { - window->indicator_show = SDL_FALSE; - } - - if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && window->indicator_show) - { - GLES2_Context Mainctx; - LoadContext(&Mainctx); - Mainctx.glUseProgram(programObject); - - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[window->indicator_type]); - Mainctx.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); - - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[window->indicator_type]); - Mainctx.glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); - - Mainctx.glUniformMatrix4fv(Mainctx.glGetUniformLocation(programObject, "modelMatrix"), 1, GL_FALSE, mMatrix.m); - - 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(0); - Mainctx.glEnableVertexAttribArray(1); - Mainctx.glDrawArrays(GL_TRIANGLES, 0, 6); + if(!window->indicator_show) { + drawIndicator(window); + SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); } - - SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); } - int Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { @@ -521,11 +557,15 @@ SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window) 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); + 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); window->indicator_show = SDL_TRUE; window->last_indicator_showtime = SDL_GetTicks(); + + _tizen_indicator_event_filter(); + } } diff --git a/src/video/tizen/SDL_tizenwindow.h b/src/video/tizen/SDL_tizenwindow.h index 19c6e0e..39b4d0f 100755 --- a/src/video/tizen/SDL_tizenwindow.h +++ b/src/video/tizen/SDL_tizenwindow.h @@ -33,7 +33,6 @@ typedef struct { uint32_t id; - Ecore_Wl_Window *window; struct wl_surface *surface; struct wl_shell_surface *shell_surface; @@ -42,6 +41,8 @@ typedef struct { int rotation; int rotation_supported; int received_rotation; + void *indicator_timer; + } SDL_WindowData; -- 2.7.4