Merge "Add remote surface indicator" into tizen
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenopengles.c
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4   Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5
6   This software is provided 'as-is', without any express or implied
7   warranty.  In no event will the authors be held liable for any damages
8   arising from the use of this software.
9
10   Permission is granted to anyone to use this software for any purpose,
11   including commercial applications, and to alter it and redistribute it
12   freely, subject to the following restrictions:
13
14   1. The origin of this software must not be misrepresented; you must not
15      claim that you wrote the original software. If you use this software
16      in a product, an acknowledgment in the product documentation would be
17      appreciated but is not required.
18   2. Altered source versions must be plainly marked as such, and must not be
19      misrepresented as being the original software.
20   3. This notice may not be removed or altered from any source distribution.
21 */
22 #include "../../SDL_internal.h"
23
24 #if SDL_VIDEO_OPENGL_EGL
25
26 #include "SDL_tizenvideo.h"
27 #include "SDL_tizenopengles.h"
28 #include "SDL_tizenwindow.h"
29 #include "SDL_tizenevents_c.h"
30
31 #include "SDL_ecore_ipc.h"
32 #include "SDL_tizenvideo.h"
33
34 #include <wayland-extension/tizen-remote-surface-client-protocol.h>
35 #include <wayland-tbm-client.h>
36 #include <Ecore_Wayland.h>
37 #include <SDL_egl.h>
38
39 #if SDL_VIDEO_OPENGL
40 #include "SDL_opengl.h"
41 #endif /* SDL_VIDEO_OPENGL */
42
43 #if SDL_VIDEO_OPENGL_ES
44 #include "SDL_opengles.h"
45 #endif /* SDL_VIDEO_OPENGL_ES */
46
47 /* GL and GLES2 headers conflict on Linux 32 bits */
48 #if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
49 #include "SDL_opengles2.h"
50 #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
51
52 /* EGL implementation of SDL OpenGL ES support */
53 typedef struct GLES2_Context
54 {
55     #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
56     #include "../../render/opengles2/SDL_gles2funcs.h"
57     #undef SDL_PROC
58 } GLES2_Context;
59
60 GLfloat vVertices[18]={
61      1.0f, 1.0f,  0.0f,
62     -1.0f, 0.92f, 0.0f,
63      1.0f, 0.92f, 0.0f,
64      1.0f, 1.0f,  0.0f,
65     -1.0f, 1.0f,  0.0f,
66     -1.0f, 0.92f, 0.0f
67     };
68
69 GLfloat vCoord[12] = {
70     1.0f, 0.0f,
71     0.0f, 1.0f,
72     1.0f, 1.0f,
73     1.0f, 0.0f,
74     0.0f, 0.0f,
75     0.0f, 1.0f};
76
77 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = NULL;
78 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = NULL;
79 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = NULL;
80
81 SharedIndicatorInfo shared_info;
82 unsigned int textureID;
83 unsigned int indicator_vbo[4], indicator_ibo[4];
84 ModelMatrix mMatrix;
85
86
87 GLuint programObject;
88 GLuint vIndex;
89 GLuint cIndex;
90
91
92 static int LoadContext(GLES2_Context * data)
93 {
94     #define SDL_PROC(ret,func,params) \
95     do { \
96         data->func = SDL_GL_GetProcAddress(#func); \
97         if ( ! data->func ) { \
98             return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
99         } \
100     } while ( 0 );
101
102     #include "../../render/opengles2/SDL_gles2funcs.h"
103     #undef SDL_PROC
104
105     return 0;
106 }
107
108 static void
109 _tizen_rs_cb_buffer_update(void *data, struct tizen_remote_surface *trs, struct wl_buffer *buffer, uint32_t time)
110 {
111     tizen_remote_surface_transfer_visibility(trs, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
112     tbm_surface_h tbmSurface= wl_buffer_get_user_data(buffer);
113
114     if(eglCreateImageKHR != NULL && glEGLImageTargetTexture2DOES != NULL && eglDestroyImageKHR != NULL)
115     {
116         SDL_VideoDevice *_this = SDL_GetVideoDevice();
117
118         if(shared_info.eglImage_Indicator != NULL)
119             eglDestroyImageKHR(_this->egl_data->egl_display, shared_info.eglImage_Indicator);
120
121         shared_info.eglImage_Indicator = eglCreateImageKHR(_this->egl_data->egl_display,
122                             EGL_NO_CONTEXT, EGL_NATIVE_SURFACE_TIZEN, tbmSurface, NULL);
123
124         if(shared_info.eglImage_Indicator == NULL)
125         {
126             SDL_Log("[SDL] eglImage is NULL");
127             return;
128         }
129         SDL_Log("[SDL] eglImage : %p", shared_info.eglImage_Indicator);
130         glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, shared_info.eglImage_Indicator);
131     }
132     else
133     {
134         tbm_surface_info_s info;
135         tbm_surface_map(tbmSurface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info);
136
137         SDL_Log("[SDL] Buffer Update %p %p (%dx%d), format:%d", buffer, tbmSurface, info.width, info.height, info.format);
138         SDL_Log("[SDL] Info size:%d, offset:%d, stride:%d", info.planes[0].size, info.planes[0].offset, info.planes[0].stride);
139
140         GLES2_Context Mainctx;
141         LoadContext(&Mainctx);
142
143         Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
144         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);
145
146         if (tbm_surface_unmap (tbmSurface) != TBM_SURFACE_ERROR_NONE)
147             SDL_Log("Failed to unmap tbm_surface\n");
148     }
149
150     if (tbm_surface_destroy (tbmSurface) != TBM_SURFACE_ERROR_NONE)
151         SDL_Log("Failed to destroy tbm_surface\n");
152
153 }
154
155 static void
156 _tizen_rs_cb_missing(void *data, struct tizen_remote_surface *trs)
157 {
158     SDL_Log("Plug is missing...! ");
159 }
160
161 static const struct tizen_remote_surface_listener _extn_gl_plug_listener =
162 {
163     _tizen_rs_cb_buffer_update,
164     _tizen_rs_cb_missing,
165 };
166
167 Uint32 _tizen_timer_callback_indicator(void *data)
168 {
169     SDL_VideoDevice *_this = SDL_GetVideoDevice();
170
171     Tizen_DrawIndicator(_this->windows);
172     SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) _this->windows->driverdata)->egl_surface);
173
174     return  ECORE_CALLBACK_RENEW;
175 }
176
177 int
178 _tizen_indicator_event_filter()
179 {
180     SDL_Window *window = SDL_GetVideoDevice()->windows;
181     SDL_WindowData *wind = window->driverdata;
182
183     if(wind->indicator_show && wind->indicator_timer == NULL)
184     {
185         wind->indicator_timer = ecore_timer_add(0.02, _tizen_timer_callback_indicator, NULL);
186     }
187     else if(!wind->indicator_show && wind->indicator_timer != NULL)
188     {
189         ecore_timer_del(wind ->indicator_timer);
190         wind->indicator_timer = NULL;
191     }
192
193     return 1;
194 }
195
196 int
197 Tizen_GLES_LoadLibrary(_THIS, const char *path)
198 {
199     int ret;
200
201     ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)ecore_wl_display_get());
202     return ret;
203 }
204
205 static GLuint LoadShader(GLES2_Context* Mainctx, const char *shaderSrc, GLenum type)
206 {
207     GLuint shader;
208     GLint compiled;
209
210     shader = Mainctx->glCreateShader(type);
211     SDL_Log("shader == %d", shader);
212     if(shader == 0)
213         return 0;
214     Mainctx->glShaderSource(shader, 1, &shaderSrc, NULL);
215     Mainctx->glCompileShader(shader);
216     Mainctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
217     if(!compiled)
218     {
219         GLint infoLen = 0;
220         Mainctx->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
221         if(infoLen > 1)
222         {
223             char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
224             Mainctx->glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
225             SDL_Log("Error compiling shader: %s", infoLog );
226             free(infoLog);
227         }
228         Mainctx->glDeleteShader(shader);
229         return 0;
230     }
231     return shader;
232
233 }
234
235 extern void ModelMatrixLoadIdentity(ModelMatrix* matrix)
236 {
237     matrix->m[0][0] = 1.0f;
238     matrix->m[0][1] = 0.0f;
239     matrix->m[0][2] = 0.0f;
240     matrix->m[0][3] = 0.0f;
241
242     matrix->m[1][0] = 0.0f;
243     matrix->m[1][1] = 1.0f;
244     matrix->m[1][2] = 0.0f;
245     matrix->m[1][3] = 0.0f;
246
247     matrix->m[2][0] = 0.0f;
248     matrix->m[2][1] = 0.0f;
249     matrix->m[2][2] = 1.0f;
250     matrix->m[2][3] = 0.0f;
251
252     matrix->m[3][0] = 0.0f;
253     matrix->m[3][1] = 0.0f;
254     matrix->m[3][2] = 0.0f;
255     matrix->m[3][3] = 1.0f;
256 }
257
258 static void ModelMatrixTranslate(ModelMatrix* matrix, GLfloat x, GLfloat y, GLfloat z)
259 {
260     matrix->m[3][0] += (matrix->m[0][0] * x + matrix->m[1][0] * y + matrix->m[2][0] * z);
261     matrix->m[3][1] += (matrix->m[0][1] * x + matrix->m[1][1] * y + matrix->m[2][1] * z);
262     matrix->m[3][2] += (matrix->m[0][2] * x + matrix->m[1][2] * y + matrix->m[2][2] * z);
263     matrix->m[3][3] += (matrix->m[0][3] * x + matrix->m[1][3] * y + matrix->m[2][3] * z);
264 }
265
266 void Tizen_remote_indicator(int res_id)
267 {
268     if(!shared_info.tizen_rs) {
269         //create tizen_remote_surface
270         shared_info.tizen_rs = tizen_remote_surface_manager_create_surface(shared_info.tizen_rsm, res_id, shared_info.wl_tbm);
271         if(!shared_info.tizen_rs)
272         {
273             SDL_Log("tizen_rs is NULL");
274             return;
275         }
276         tizen_remote_surface_add_listener(shared_info.tizen_rs, &_extn_gl_plug_listener, NULL);
277         tizen_remote_surface_redirect(shared_info.tizen_rs);
278     }
279 }
280
281 void Tizen_glTexImage2D(int idx)
282 {
283     GLES2_Context Mainctx;
284     LoadContext(&Mainctx);
285
286     Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
287     Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shared_info.fileInfo[idx].ImageWidth, shared_info.fileInfo[idx].ImageHeight,
288                       0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)(shared_info.fileInfo[idx].sharedFile->address));
289 }
290
291 void Tizen_DrawIndicator(SDL_Window *window)
292 {
293     SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata;
294     if (wdata->received_rotation == 1) {
295         ecore_wl_window_rotation_change_done_send(wdata->window);
296         wdata->received_rotation = 0;
297     }
298
299     if(wdata->last_indicator_showtime + 3000< SDL_GetTicks())
300     {
301         switch(wdata->rotation)
302         {
303         case 0:
304             ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f);
305         break;
306         case 90:
307             ModelMatrixTranslate(&mMatrix, -0.02f, 0.0f, 0.0f);
308         break;
309         case 180:
310             ModelMatrixTranslate(&mMatrix, 0.0f, -0.02f, 0.0f);
311         break;
312         case 270:
313             ModelMatrixTranslate(&mMatrix, 0.02f, 0.0f, 0.0f);
314         break;
315         }
316     }
317
318     if(wdata->last_indicator_showtime + 3500 <SDL_GetTicks()) {
319         wdata->indicator_show = SDL_FALSE;
320         _tizen_indicator_event_filter();
321     }
322
323     if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && wdata->indicator_show)
324     {
325         GLES2_Context Mainctx;
326         LoadContext(&Mainctx);
327         Mainctx.glUseProgram(programObject);
328
329         Mainctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
330         Mainctx.glVertexAttribPointer(vIndex, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
331         Mainctx.glVertexAttribPointer(cIndex, 2, GL_FLOAT, GL_FALSE, 0, vCoord);
332         Mainctx.glUniformMatrix4fv(Mainctx.glGetUniformLocation(programObject,  "modelMatrix"), 1, GL_FALSE, mMatrix.m);
333
334         Mainctx.glEnableVertexAttribArray(vIndex);
335         Mainctx.glEnableVertexAttribArray(cIndex);
336
337         GLboolean isDepthTest = Mainctx.glIsEnabled(GL_DEPTH_TEST);
338         if(isDepthTest) Mainctx.glDisable(GL_DEPTH_TEST);
339         Mainctx.glDrawArrays(GL_TRIANGLES, 0, 6);
340
341         if(isDepthTest) Mainctx.glEnable(GL_DEPTH_TEST);
342         Mainctx.glDisableVertexAttribArray(vIndex);
343         Mainctx.glDisableVertexAttribArray(cIndex);
344     }
345 }
346
347 SDL_bool Tizen_remote_surface_init(void)
348 {
349     Eina_Inlist *globals;
350     Ecore_Wl_Global *global;
351     struct wl_registry *registry;
352     if (!shared_info.tizen_rsm)
353     {
354         registry = ecore_wl_registry_get();
355         globals = ecore_wl_globals_get();
356
357         if (!registry || !globals)
358           {
359              SDL_Log( "Could not get registry(%p) or global list(%p)\n", registry, globals);
360              return SDL_FALSE;
361           }
362
363         EINA_INLIST_FOREACH(globals, global)
364           {
365              if (!strcmp(global->interface, "tizen_remote_surface_manager"))
366                {
367                   shared_info.tizen_rsm = wl_registry_bind(registry, global->id,
368                                       &tizen_remote_surface_manager_interface, 1);
369                    SDL_Log("[SDL] Create tizen_rsm : %p",shared_info.tizen_rsm);
370                }
371           }
372         shared_info.tizen_rs = NULL;
373     }
374     if (!shared_info.tizen_rsm)
375     {
376         SDL_Log("Could not bind tizen_remote_surface_manager");
377         return SDL_FALSE;
378     }
379
380     if(!shared_info.tbm_client)
381     {
382         shared_info.tbm_client = (struct wayland_tbm_client *)wayland_tbm_client_init(ecore_wl_display_get());
383         shared_info.wl_tbm = (struct wl_tbm *)wayland_tbm_client_get_wl_tbm(shared_info.tbm_client);
384         if (!shared_info.wl_tbm)
385         {
386             SDL_Log("[SDL]wl_tbm is NULL");
387             return SDL_FALSE;
388         }
389     }
390
391     eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("eglCreateImageKHR");
392     eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("eglDestroyImageKHR");
393     glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)SDL_GetVideoDevice()->egl_data->eglGetProcAddress("glEGLImageTargetTexture2DOES");
394
395     return SDL_TRUE;
396 }
397
398 int Tizen_FiniIndicator()
399 {
400     int n;
401     for (n=0; n < SHARED_FILE_NUMBER; n++)
402         Tizen_Indicator_SharedFile_Free(&shared_info, n);
403
404     if(shared_info.eglImage_Indicator != NULL)
405         eglDestroyImageKHR(SDL_GetVideoDevice()->egl_data->egl_display, shared_info.eglImage_Indicator);
406
407     if (shared_info.tizen_rs)
408         tizen_remote_surface_destroy(shared_info.tizen_rs);
409     if (shared_info.tbm_client)
410         wayland_tbm_client_deinit(shared_info.tbm_client);
411     if (shared_info.tizen_rsm)
412         tizen_remote_surface_manager_destroy(shared_info.tizen_rsm);
413
414     GLES2_Context Mainctx;
415     LoadContext(&Mainctx);
416     Mainctx.glDeleteProgram(programObject);
417     return SDL_TRUE;
418 }
419
420 int Indicator_GLES_Init(SDL_Window* window)
421 {
422     SDL_WindowData *wind = window->driverdata;
423     ecore_wl_indicator_visible_type_set(wind->window, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
424     ecore_wl_window_indicator_opacity_set(wind->window, ECORE_WL_INDICATOR_OPAQUE);
425     ecore_wl_window_indicator_state_set(wind->window, ECORE_WL_INDICATOR_STATE_ON);
426
427     Ecore_Ipc_Server* IpcServer = serverConnection("elm_indicator", &shared_info);
428     if(!IpcServer)
429     {
430         SDL_Log("Fail to connect elm_indicator!\n");
431         return 0;
432     }
433
434     GLchar vShaderStr[] =
435         "attribute vec4 vVertices;\n"
436         "attribute vec2 vCoord;\n"
437         "uniform mat4 modelMatrix;\n"
438         "varying vec2 Coord;\n"
439         "void main()\n"
440         "{\n"
441         "    gl_Position = modelMatrix * vVertices;\n"
442         "    Coord = vCoord;\n"
443         "}\n";
444
445     GLchar fShaderStr[] =
446         "precision mediump float;\n"
447         "varying vec2 Coord;\n"
448         "uniform sampler2D s_texture;\n"
449         "void main()\n"
450         "{\n"
451         " gl_FragColor = texture2D(s_texture,Coord);\n"
452         "}\n";
453
454     GLuint vertexShader;
455     GLuint fragmentShader;
456
457     GLint linked;
458
459     GLES2_Context Mainctx;
460     LoadContext(&Mainctx);
461
462     vertexShader = LoadShader(&Mainctx, vShaderStr, GL_VERTEX_SHADER);
463     fragmentShader = LoadShader(&Mainctx, fShaderStr, GL_FRAGMENT_SHADER);
464     SDL_Log("The vertex shader is %d", vertexShader);
465     SDL_Log("The fragment shader is %d", fragmentShader);
466
467     programObject = Mainctx.glCreateProgram();
468     if(programObject == 0)
469         return 0;
470
471     Mainctx.glAttachShader(programObject, vertexShader);
472     Mainctx.glAttachShader(programObject, fragmentShader);
473
474     Mainctx.glLinkProgram(programObject);
475     Mainctx.glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
476
477     if(!linked)
478     {
479         GLint infoLen = 0;
480         Mainctx.glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
481         if(infoLen > 1)
482         {
483             char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
484             Mainctx.glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
485             SDL_Log("Error linking program: %s", infoLog);
486             free(infoLog);
487         }
488         Mainctx.glDeleteProgram(programObject);
489         return 0;
490     }
491
492     Mainctx.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
493     Mainctx.glEnable(GL_DEPTH_TEST);
494
495     vIndex = Mainctx.glGetAttribLocation(programObject, "vVertices");
496     cIndex = Mainctx.glGetAttribLocation(programObject, "vCoord");
497
498     Mainctx.glBindAttribLocation(programObject, vIndex, "vVertices");
499     Mainctx.glBindAttribLocation(programObject, cIndex, "vCoord");
500
501     ModelMatrixLoadIdentity(&mMatrix);
502
503
504     Mainctx.glGenTextures(1, &textureID);
505     Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
506
507     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
508     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
509     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
510     Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
511
512     wind->indicator_show = SDL_TRUE;
513     wind->last_indicator_showtime = SDL_GetTicks();
514
515     ecore_main_loop_iterate();
516     SDL_IndicatorProcessEvent(window, wind->rotation);
517
518     _tizen_indicator_event_filter();
519
520     return 1;
521 }
522
523 SDL_GLContext
524 Tizen_GLES_CreateContext(_THIS, SDL_Window *window)
525 {
526     SDL_GLContext context;
527
528     context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
529
530     if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS))
531     {
532         if(!Indicator_GLES_Init(window))
533         {
534             SDL_Log("Indicator GLES init error!");
535         }
536     }
537
538     return context;
539 }
540
541 void
542 Tizen_GLES_SwapWindow(_THIS, SDL_Window *window)
543 {
544     if(!((SDL_WindowData*)window->driverdata)->indicator_show) {
545         Tizen_DrawIndicator(window);
546         SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
547     }
548 }
549
550 int
551 Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
552 {
553     int ret;
554
555     if (window && context) {
556         ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
557     } else {
558         ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
559     }
560
561     return ret;
562 }
563
564 void
565 Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context)
566 {
567     SDL_EGL_DeleteContext(_this, context);
568 }
569
570 void
571 SDL_IndicatorProcessEvent(SDL_Window *window, int rot)
572 {
573     GLES2_Context Mainctx;
574     LoadContext(&Mainctx);
575
576     SDL_WindowData *wind = window->driverdata;
577     if( rot == 0)
578     {
579         SDL_Log("===rotate 0 degree!\n");
580         vVertices[0] = 1.0f;
581         vVertices[1] = 1.0f;
582         vVertices[3] = -1.0f;
583         vVertices[4] = 0.92f;
584         vVertices[6] = 1.0f;
585         vVertices[7] = 0.92f;
586         vVertices[9] = 1.0f;
587         vVertices[10] = 1.0f;
588         vVertices[12] =  -1.0f;
589         vVertices[13] =  1.0f;
590         vVertices[15] = -1.0f;
591         vVertices[16] = 0.92f;
592
593         vCoord[0] = 1.0f;
594         vCoord[1] = 0.0f;
595         vCoord[2] = 0.0f;
596         vCoord[3] = 1.0f;
597         vCoord[4] = 1.0f;
598         vCoord[5] = 1.0f;
599         vCoord[6] = 1.0f;
600         vCoord[7] = 0.0f;
601         vCoord[8] = 0.0f;
602         vCoord[9] = 0.0f;
603         vCoord[10] = 0.0f;
604         vCoord[11] = 1.0f;
605     }
606     else if(rot == 90)
607     {
608         SDL_Log("===rotate 90 degree!\n");
609         vVertices[0] = -0.86f;
610         vVertices[1] = 1.0f;
611         vVertices[3] = -0.86f;
612         vVertices[4] = -1.0f;
613         vVertices[6] = -1.0f;
614         vVertices[7] = 1.0f;
615         vVertices[9] = -1.0f;
616         vVertices[10] = -1.0f;
617         vVertices[12] =  -0.86f;
618         vVertices[13] = -1.0f;
619         vVertices[15] = -1.0f;
620         vVertices[16] = 1.0f;
621
622         vCoord[0] = 1.0f;
623         vCoord[1] = 1.0f;
624         vCoord[2] = 0.0f;
625         vCoord[3] = 1.0f;
626         vCoord[4] = 1.0f;
627         vCoord[5] = 0.0f;
628         vCoord[6] = 0.0f;
629         vCoord[7] = 0.0f;
630         vCoord[8] = 0.0f;
631         vCoord[9] = 1.0f;
632         vCoord[10] = 1.0f;
633         vCoord[11] = 0.0f;
634     }
635     else if(rot == 180)
636     {
637         SDL_Log("===rotate 180 degree!\n");
638         vVertices[0] = -1.0f;
639         vVertices[1] = -1.0f;
640         vVertices[3] = -1.0f;
641         vVertices[4] = -0.92f;
642         vVertices[6] = 1.0f;
643         vVertices[7] = -1.0f;
644         vVertices[9] = 1.0f;
645         vVertices[10] = -0.92f;
646         vVertices[12] =  -1.0f;
647         vVertices[13] = -0.92f;
648         vVertices[15] = 1.0f;
649         vVertices[16] = -1.0f;
650
651         vCoord[0] = 1.0f;
652         vCoord[1] = 0.0f;
653         vCoord[2] = 1.0f;
654         vCoord[3] = 1.0f;
655         vCoord[4] = 0.0f;
656         vCoord[5] = 0.0f;
657         vCoord[6] = 0.0f;
658         vCoord[7] = 1.0f;
659         vCoord[8] = 1.0f;
660         vCoord[9] = 1.0f;
661         vCoord[10] = 0.0f;
662         vCoord[11] = 0.0f;
663     }
664     else if(rot == 270)
665     {
666         SDL_Log("===rotate 270 degree!\n");
667         vVertices[0] = 1.0f;
668         vVertices[1] = 1.0f;
669         vVertices[3] = 0.86f;
670         vVertices[4] = 1.0f;
671         vVertices[6] = 1.0f;
672         vVertices[7] = -1.0f;
673         vVertices[9] = 0.86f;
674         vVertices[10] = -1.0f;
675         vVertices[12] =  0.86f;
676         vVertices[13] = 1.0f;
677         vVertices[15] = 1.0f;
678         vVertices[16] = -1.0f;
679
680         vCoord[0] = 0.0f;
681         vCoord[1] = 0.0f;
682         vCoord[2] = 0.0f;
683         vCoord[3] = 1.0f;
684         vCoord[4] = 1.0f;
685         vCoord[5] = 0.0f;
686         vCoord[6] = 1.0f;
687         vCoord[7] = 1.0f;
688         vCoord[8] = 0.0f;
689         vCoord[9] = 1.0f;
690         vCoord[10] = 1.0f;
691         vCoord[11] = 0.0f;
692
693         //Invisible Indicator
694         wind->indicator_show = SDL_FALSE;
695         _tizen_indicator_event_filter();
696     }
697
698     Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[wind->rotation/90]);
699     Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW);
700     Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[wind->rotation/90]);
701     Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW);
702
703     ModelMatrixLoadIdentity(&mMatrix);
704     wind->indicator_show = SDL_TRUE;
705     wind->last_indicator_showtime = SDL_GetTicks();
706
707     _tizen_indicator_event_filter();
708
709 }
710
711 #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
712
713 /* vi: set ts=4 sw=4 expandtab: */