#if SDL_VIDEO_OPENGL_EGL
-#include "SDL_tizenvideo.h"
+#include "SDL_log.h"
#include "SDL_tizenopengles.h"
+#include "SDL_tizenindicator.h"
+#include "SDL_tizenvideo.h"
#include "SDL_tizenwindow.h"
-#include "SDL_tizenevents_c.h"
-
-#include "SDL_ecore_ipc.h"
-
-#include <Ecore.h>
#if SDL_VIDEO_OPENGL
#include "SDL_opengl.h"
#include "SDL_opengles2.h"
#endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
-
-GLfloat vVertices[18]={
- 1.0f, 1.0f, 0.0f,
- -1.0f, 0.92f, 0.0f,
- 1.0f, 0.92f, 0.0f,
- 1.0f, 1.0f, 0.0f,
- -1.0f, 1.0f, 0.0f,
- -1.0f, 0.92f, 0.0f
- };
-
-GLfloat vCoord[12] = {
- 1.0f, 0.0f,
- 0.0f, 1.0f,
- 1.0f, 1.0f,
- 1.0f, 0.0f,
- 0.0f, 0.0f,
- 0.0f, 1.0f};
-
-
-/* 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;
-
-Uint32 _tizen_timer_callback_indicator(void *data)
-{
- 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(wind->indicator_show && wind->indicator_timer == NULL)
- {
- wind->indicator_timer = ecore_timer_add(0.02, _tizen_timer_callback_indicator, NULL);
- }
- else if(!wind->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)
{
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;
- GLint compiled;
-
- shader = Mainctx->glCreateShader(type);
- SDL_Log("shader == %d", shader);
- if(shader == 0)
- return 0;
- Mainctx->glShaderSource(shader, 1, &shaderSrc, NULL);
- Mainctx->glCompileShader(shader);
- Mainctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if(!compiled)
- {
- GLint infoLen = 0;
- Mainctx->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
- if(infoLen > 1)
- {
- char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
- Mainctx->glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
- SDL_Log("Error compiling shader: %s", infoLog );
- free(infoLog);
- }
- Mainctx->glDeleteShader(shader);
- return 0;
- }
- return shader;
-
-}
-
-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;
- matrix->m[0][1] = 0.0f;
- matrix->m[0][2] = 0.0f;
- matrix->m[0][3] = 0.0f;
-
- matrix->m[1][0] = 0.0f;
- matrix->m[1][1] = 1.0f;
- matrix->m[1][2] = 0.0f;
- matrix->m[1][3] = 0.0f;
-
- matrix->m[2][0] = 0.0f;
- matrix->m[2][1] = 0.0f;
- matrix->m[2][2] = 1.0f;
- matrix->m[2][3] = 0.0f;
-
- matrix->m[3][0] = 0.0f;
- matrix->m[3][1] = 0.0f;
- matrix->m[3][2] = 0.0f;
- matrix->m[3][3] = 1.0f;
-}
-
-static void ModelMatrixTranslate(ModelMatrix* matrix, GLfloat x, GLfloat y, GLfloat z)
-{
- matrix->m[3][0] += (matrix->m[0][0] * x + matrix->m[1][0] * y + matrix->m[2][0] * z);
- matrix->m[3][1] += (matrix->m[0][1] * x + matrix->m[1][1] * y + matrix->m[2][1] * z);
- matrix->m[3][2] += (matrix->m[0][2] * x + matrix->m[1][2] * y + matrix->m[2][2] * z);
- matrix->m[3][3] += (matrix->m[0][3] * x + matrix->m[1][3] * y + matrix->m[2][3] * z);
-}
-
-void Tizen_glTexImage2d(int idx)
-{
- GLES2_Context Mainctx;
- LoadContext(&Mainctx);
-
- Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
- 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)
-{
- 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(wdata->last_indicator_showtime + 3000< SDL_GetTicks())
- {
- switch(wdata->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(wdata->last_indicator_showtime + 3500 <SDL_GetTicks()) {
- wdata->indicator_show = SDL_FALSE;
- _tizen_indicator_event_filter();
- }
-
- if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && wdata->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.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;
- ecore_wl_indicator_visible_type_set(wind->window, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
- 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", &shared_info);
- if(!IpcServer)
- {
- SDL_Log("Fail to connect elm_indicator!\n");
- return 0;
- }
-
- GLchar vShaderStr[] =
- "attribute vec4 vVertices;\n"
- "attribute vec2 vCoord;\n"
- "uniform mat4 modelMatrix;\n"
- "varying vec2 Coord;\n"
- "void main()\n"
- "{\n"
- " gl_Position = modelMatrix * vVertices;\n"
- " Coord = vCoord;\n"
- "}\n";
-
- GLchar fShaderStr[] =
- "precision mediump float;\n"
- "varying vec2 Coord;\n"
- "uniform sampler2D s_texture;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = texture2D(s_texture,Coord);\n"
- "}\n";
-
- GLuint vertexShader;
- GLuint fragmentShader;
-
- GLint linked;
-
- GLES2_Context Mainctx;
- LoadContext(&Mainctx);
-
- vertexShader = LoadShader(&Mainctx, vShaderStr, GL_VERTEX_SHADER);
- fragmentShader = LoadShader(&Mainctx, fShaderStr, GL_FRAGMENT_SHADER);
- SDL_Log("The vertex shader is %d", vertexShader);
- SDL_Log("The fragment shader is %d", fragmentShader);
-
- programObject = Mainctx.glCreateProgram();
- if(programObject == 0)
- return 0;
-
- Mainctx.glAttachShader(programObject, vertexShader);
- Mainctx.glAttachShader(programObject, fragmentShader);
-
- Mainctx.glLinkProgram(programObject);
- Mainctx.glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
-
- if(!linked)
- {
- GLint infoLen = 0;
- Mainctx.glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
- if(infoLen > 1)
- {
- char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
- Mainctx.glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
- SDL_Log("Error linking program: %s", infoLog);
- free(infoLog);
- }
- Mainctx.glDeleteProgram(programObject);
- return 0;
- }
-
- Mainctx.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- Mainctx.glEnable(GL_DEPTH_TEST);
-
- vIndex = Mainctx.glGetAttribLocation(programObject, "vVertices");
- cIndex = Mainctx.glGetAttribLocation(programObject, "vCoord");
-
- Mainctx.glBindAttribLocation(programObject, vIndex, "vVertices");
- Mainctx.glBindAttribLocation(programObject, cIndex, "vCoord");
-
- ModelMatrixLoadIdentity(&mMatrix);
-
-
- Mainctx.glGenTextures(1, &textureID);
- Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
-
- Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
- wind->indicator_show = SDL_TRUE;
- wind->last_indicator_showtime = SDL_GetTicks();
-
- ecore_main_loop_iterate();
-
- _tizen_indicator_event_filter();
-
- return 1;
-}
-
SDL_GLContext
Tizen_GLES_CreateContext(_THIS, SDL_Window *window)
{
if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS))
{
- if(!Indicator_GLES_Init(window))
+ SDL_VideoData *data = (SDL_VideoData *) (SDL_GetVideoDevice()->driverdata);
+ if(data->current_thread != SDL_GetThreadID(0))
+ return context;
+ if(!Tizen_Indicator_GLES_Init(window))
{
SDL_Log("Indicator GLES init error!");
}
void
Tizen_GLES_SwapWindow(_THIS, SDL_Window *window)
{
- if(!((SDL_WindowData*)window->driverdata)->indicator_show) {
- drawIndicator(window);
- SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
- }
+ Tizen_DrawIndicator(window);
+ SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
}
int
SDL_EGL_DeleteContext(_this, context);
}
-void
-SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window)
-{
- GLES2_Context Mainctx;
- LoadContext(&Mainctx);
-
- SDL_WindowData *wind = window->driverdata;
-
- if(event->type == SDL_ROTATEEVENT)
- {
- 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;
- }
-
- 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);
-
- ModelMatrixLoadIdentity(&mMatrix);
- wind->indicator_show = SDL_TRUE;
- wind->last_indicator_showtime = SDL_GetTicks();
-
- _tizen_indicator_event_filter();
-
- }
-}
-
#endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */