#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"
-
#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;
-
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;
-
-}
-
-SharedFileInfo fileInfo;
-
-unsigned int textureID;
-unsigned int indicator_vbo[4], indicator_ibo[4];
-unsigned short indicator_index;
-
-
-void Tizen_glTexImage2d()
-{
-
- 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);
-}
-
-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", &fileInfo);
- if(!IpcServer)
- {
- SDL_Log("Fail to connect elm_indicator!\n");
- return 0;
- }
-
- GLchar vShaderStr[] =
- "attribute vec4 vVertices;\n"
- "attribute vec2 vCoord;\n"
- "varying vec2 Coord;\n"
- "void main()\n"
- "{\n"
- " gl_Position = 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";
-
- ecore_main_loop_iterate();
-
- 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.glBindAttribLocation(programObject, 0, "vVertices");
- Mainctx.glBindAttribLocation(programObject, 1, "vCoord");
-
- 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);
-
- /* 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);
-
-
-
- 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);
-
- 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();
- 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)
{
- 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())
- {
- 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.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);
- }
-
+ Tizen_DrawIndicator(window);
SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
}
-
int
Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
{
SDL_EGL_DeleteContext(_this, context);
}
-void
-SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window)
-{
- GLES2_Context Mainctx;
- LoadContext(&Mainctx);
-
- if(event->type == SDL_ROTATEEVENT)
- {
- window->indicator_type = ((int)event->user.data1) / 90;
- if( window->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(window->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(window->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(window->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[window->indicator_type]);
- Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW);
- Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[window->indicator_type]);
- Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW);
-
- 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);
- window->indicator_show = SDL_TRUE;
- window->last_indicator_showtime = SDL_GetTicks();
- }
-}
-
#endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */