--- /dev/null
+############################################################################
+#
+# Copyright 2010, 2011 BMW Car IT GmbH
+# Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+############################################################################
+
+cmake_minimum_required (VERSION 2.6)
+
+include_directories ("include")
+include_directories ("../../LayerManagerClient/ilmClient/include")
+include_directories ("../LayerSceneDescriptionExample/include")
+include_directories ("../../LayerManagerUtils/include")
+
+link_directories ("${PROJECT_SOURCE_DIR}/LayerManagerUtils/bin")
+
+add_executable(EGLWLApplicationExample src/egl_helper.cpp src/eglWL_application.cpp src/gles2application.cpp src/WaylandServerinfoProtocol.cpp)
+
+add_dependencies(EGLWLApplicationExample ilmClient)
+add_dependencies(EGLWLApplicationExample LayerManagerUtils)
+
+find_package (GLESv2 REQUIRED)
+include_directories(${GLESv2_INCLUDE_DIR})
+
+find_package (EGL REQUIRED)
+include_directories(${EGL_INCLUDE_DIR})
+
+find_package (Wayland REQUIRED)
+include_directories(${WAYLAND_CLIENT_INCLUDE_DIR} ${FFI_INCLUDE_DIR})
+add_dependencies(EGLWLApplicationExample wayland-client)
+
+set(LIBS ${LIBS} ${GLESv2_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${FFI_LIBRARIES} ${EGL_LIBRARY} LayerManagerUtils)
+target_link_libraries(EGLWLApplicationExample ${LIBS} ilmClient wayland-client wayland-egl -ldl)
+
+install (TARGETS EGLWLApplicationExample DESTINATION bin)
--- /dev/null
+/***************************************************************************
+*
+* Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*
+****************************************************************************/
+
+#ifndef WAYLAND_SERVERINFO_CLIENT_PROTOCOL_H
+#define WAYLAND_SERVERINFO_CLIENT_PROTOCOL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-util.h"
+
+struct wl_client;
+struct wl_resource;
+
+struct serverinfo;
+
+extern const struct wl_interface serverinfo_interface;
+
+struct serverinfo_listener {
+ void (*connection_id)(void *data,
+ struct serverinfo *serverinfo,
+ uint32_t connection_id);
+};
+
+static inline int
+serverinfo_add_listener(struct serverinfo *serverinfo,
+ const struct serverinfo_listener *listener, void *data)
+{
+ return wl_proxy_add_listener((struct wl_proxy *) serverinfo,
+ (void (**)(void)) listener, data);
+}
+
+#define SERVERINFO_GET_CONNECTION_ID 0
+
+static inline void
+serverinfo_set_user_data(struct serverinfo *serverinfo, void *user_data)
+{
+ wl_proxy_set_user_data((struct wl_proxy *) serverinfo, user_data);
+}
+
+static inline void *
+serverinfo_get_user_data(struct serverinfo *serverinfo)
+{
+ return wl_proxy_get_user_data((struct wl_proxy *) serverinfo);
+}
+
+static inline void
+serverinfo_destroy(struct serverinfo *serverinfo)
+{
+ wl_proxy_destroy((struct wl_proxy *) serverinfo);
+}
+
+static inline void
+serverinfo_get_connection_id(struct serverinfo *serverinfo)
+{
+ wl_proxy_marshal((struct wl_proxy *) serverinfo,
+ SERVERINFO_GET_CONNECTION_ID);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/***************************************************************************
+*
+* Copyright 2010, 2011 BMW Car IT GmbH
+* Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#ifndef _EGL_HELPER_H_
+#define _EGL_HELPER_H_
+
+#include "wayland-client.h"
+#include "wayland-egl.h"
+#include "ilm_client.h"
+#include <EGL/egl.h>
+
+t_ilm_uint GetTickCount();
+t_ilm_bool createWLContext(t_ilm_int width, t_ilm_int height);
+t_ilm_bool createEGLContext(t_ilm_int width, t_ilm_int height);
+void destroyEglContext();
+void destroyWLContext();
+void swapBuffers();
+
+#endif /* _EGL_HELPER_H_ */
--- /dev/null
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#ifndef _GLES2APPLICATION_H_
+#define _GLES2APPLICATION_H_
+
+#include "ilm_client.h"
+#include <GLES2/gl2.h>
+
+t_ilm_bool initGlApplication();
+t_ilm_bool initShader();
+t_ilm_bool destroyShader();
+t_ilm_bool initVertexBuffer();
+
+void attachVertexBuffer();
+void detachVertexBuffer();
+void destroyVertexBuffer();
+
+void draw(t_ilm_uint animTime);
+
+void destroyGlApplication();
+
+#endif /* _GLES2APPLICATION_H_ */
--- /dev/null
+/***************************************************************************
+*
+* Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*
+****************************************************************************/
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "wayland-util.h"
+
+
+static const struct wl_interface *types[] = {
+ NULL,
+};
+
+static const struct wl_message serverinfo_requests[] = {
+ { "get_connection_id", "", types + 0 },
+};
+
+static const struct wl_message serverinfo_events[] = {
+ { "connection_id", "u", types + 0 },
+};
+
+extern "C" WL_EXPORT const struct wl_interface serverinfo_interface = {
+ "serverinfo", 1,
+ ARRAY_LENGTH(serverinfo_requests), serverinfo_requests,
+ ARRAY_LENGTH(serverinfo_events), serverinfo_events,
+};
+
--- /dev/null
+/***************************************************************************
+ *
+ * Copyright 2010, 2011 BMW Car IT GmbH
+ * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "ilm_client.h"
+#include "egl_helper.h"
+#include "gles2application.h"
+#include <stdio.h>
+#include <unistd.h>
+
+/********************* DEFINES **********************************************/
+// Max width and height of the window
+#define SURFACE_WIDTH 320
+#define SURFACE_HEIGHT 240
+
+#define LAYER_WIDTH 800
+#define LAYER_HEIGHT 480
+/****************************************************************************/
+
+/********************* TYPEDEFS **********************************************/
+
+/****************************************************************************/
+int main(void)
+{
+ printf("Starting demo EGL Wayland Application Example\n");
+
+ if (ilm_init() == ILM_FAILED)
+ {
+ printf("Can't Init LayerManagement Communication\n");
+ return -1;
+ }
+
+ if (!createWLContext(SURFACE_WIDTH, SURFACE_HEIGHT))
+ {
+ printf("Can't Create Wayland Context\n");
+ return -1;
+ }
+
+ if (!createEGLContext(SURFACE_WIDTH, SURFACE_HEIGHT))
+ {
+ printf("Can't Create EGL Context\n");
+ return -1;
+ }
+
+ if (!initGlApplication())
+ {
+ printf("Can't Init GL Application\n");
+ return -1;
+ }
+
+ while (ILM_TRUE)
+ {
+ draw(33);
+ usleep(1000);
+ }
+
+ destroyEglContext();
+ destroyWLContext();
+ destroyGlApplication();
+ ilm_destroy();
+ return 0;
+}
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2010, 2011 BMW Car IT GmbH
+ * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "egl_helper.h"
+#include "LayerScene.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <linux/fb.h>
+
+#include "WaylandServerinfoClientProtocol.h"
+
+/* #define USE_PIXMAP */
+typedef struct t_eglContextStruct
+{
+ EGLNativeDisplayType nativeDisplay;
+ EGLNativeWindowType nativeWindow;
+ EGLDisplay eglDisplay;
+ EGLConfig eglConfig;
+ EGLSurface eglSurface;
+ EGLContext eglContext;
+} EglContextStruct;
+
+typedef struct t_wlContextStruct
+{
+ struct wl_display* wlDisplay;
+ struct wl_compositor* wlCompositor;
+
+ struct wl_surface* wlSurface;
+ struct wl_egl_window* wlNativeWindow;
+ int width;
+ int height;
+
+ uint32_t mask;
+
+ struct serverinfo* wlExtServerinfo;
+ uint32_t connect_id;
+} WLContextStruct;
+
+static EglContextStruct g_eglContextStruct;
+static WLContextStruct g_wlContextStruct;
+
+static void serverinfoListener(void *data, struct serverinfo *pServerinfo, uint32_t client_handle)
+{
+ pServerinfo = pServerinfo; // TODO:to avoid warning
+ WLContextStruct* p_wlCtx = (WLContextStruct*)data;
+ p_wlCtx->connect_id = client_handle;
+ fprintf( stderr, "notified wayland connection : id=%d\n", p_wlCtx->connect_id);
+}
+
+struct serverinfo_listener serverinfo_listener_list = {
+ serverinfoListener
+};
+
+static void display_handle_global(struct wl_display* display, uint32_t id, const char* interface, uint32_t version, void* data)
+{
+ version = version; // TODO: to avoid warning
+ WLContextStruct* p_wlCtx = (WLContextStruct*)data;
+ int ans_strcmp = 0;
+
+ do
+ {
+ ans_strcmp = strcmp(interface, "wl_compositor");
+ if (0 == ans_strcmp)
+ {
+ p_wlCtx->wlCompositor = (wl_compositor*)wl_display_bind(display, id, &wl_compositor_interface);
+ break;
+ }
+
+ ans_strcmp = strcmp(interface, "serverinfo");
+ if (0 == ans_strcmp)
+ {
+ p_wlCtx->wlExtServerinfo = (struct serverinfo*)wl_display_bind(display, id, &serverinfo_interface);
+ serverinfo_add_listener(p_wlCtx->wlExtServerinfo, &serverinfo_listener_list, data);
+ serverinfo_get_connection_id(p_wlCtx->wlExtServerinfo);
+ }
+ } while(0);
+}
+
+static int
+event_mask_update(uint32_t mask, void* data)
+{
+ WLContextStruct* p_wlCtx = (WLContextStruct*)data;
+ p_wlCtx->mask = mask;
+ return 0;
+}
+
+t_ilm_bool createWLContext(t_ilm_int width, t_ilm_int height)
+{
+ t_ilm_bool result = ILM_TRUE;
+
+ memset(&g_wlContextStruct, 0, sizeof(g_wlContextStruct));
+
+ g_wlContextStruct.width = width;
+ g_wlContextStruct.height = height;
+ g_wlContextStruct.wlDisplay = wl_display_connect(NULL);
+ if (NULL == g_wlContextStruct.wlDisplay)
+ {
+ printf("Error: wl_display_connect() failed.\n");
+ }
+
+ wl_display_add_global_listener(g_wlContextStruct.wlDisplay, display_handle_global, &g_wlContextStruct);
+ wl_display_get_fd(g_wlContextStruct.wlDisplay, event_mask_update, &g_wlContextStruct);
+ wl_display_iterate(g_wlContextStruct.wlDisplay, WL_DISPLAY_READABLE);
+ wl_display_roundtrip(g_wlContextStruct.wlDisplay);
+
+ g_wlContextStruct.wlSurface = wl_compositor_create_surface(g_wlContextStruct.wlCompositor);
+ if (NULL == g_wlContextStruct.wlSurface)
+ {
+ printf("Error: wl_compositor_create_surface() failed.\n");
+ destroyWLContext();
+ }
+
+ g_wlContextStruct.wlNativeWindow = wl_egl_window_create(g_wlContextStruct.wlSurface, width, height);
+ if (NULL == g_wlContextStruct.wlNativeWindow)
+ {
+ printf("Error: wl_egl_window_create() failed.\n");
+ destroyWLContext();
+ }
+
+ return result;
+}
+
+EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+
+t_ilm_bool createEGLContext(t_ilm_int width, t_ilm_int height)
+{
+ t_ilm_bool result = ILM_TRUE;
+ g_eglContextStruct.eglDisplay = NULL;
+ g_eglContextStruct.eglSurface = NULL;
+ g_eglContextStruct.eglContext = NULL;
+ ilmErrorTypes error = ILM_FAILED;
+ uint32_t native_ilm_handle = 0;
+ EGLint eglstatus = EGL_SUCCESS;
+
+ g_eglContextStruct.eglDisplay = eglGetDisplay(g_wlContextStruct.wlDisplay);
+ eglstatus = eglGetError();
+ if (!g_eglContextStruct.eglDisplay)
+ {
+ printf("Error: eglGetDisplay() failed.\n");
+ }
+
+ EGLint iMajorVersion, iMinorVersion;
+ if (!eglInitialize(g_eglContextStruct.eglDisplay, &iMajorVersion,
+ &iMinorVersion))
+ {
+ printf("Error: eglInitialize() failed.\n");
+ }
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+ eglstatus = eglGetError();
+ if (eglstatus != EGL_SUCCESS)
+ {
+ printf("Error: eglBindAPI() failed.\n");
+ }
+ EGLint pi32ConfigAttribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_NONE
+ };
+ int iConfigs;
+
+ if (!eglChooseConfig(g_eglContextStruct.eglDisplay, pi32ConfigAttribs, &g_eglContextStruct.eglConfig, 1, &iConfigs) || (iConfigs != 1))
+ {
+ printf("Error: eglChooseConfig() failed.\n");
+ }
+ eglstatus = eglGetError();
+ if (eglstatus != EGL_SUCCESS)
+ {
+ printf("Error: eglChooseConfig() failed. EGLStatus:0x%x\n", (unsigned int)eglstatus); // TODO: do not use printf directly here
+ }
+
+ g_eglContextStruct.eglSurface = eglCreateWindowSurface(
+ g_eglContextStruct.eglDisplay, g_eglContextStruct.eglConfig,
+ g_wlContextStruct.wlNativeWindow, NULL);
+ eglstatus = eglGetError();
+
+ if (eglstatus != EGL_SUCCESS)
+ {
+ printf("Error: eglCreateWindowSurface() failed. EGLStatus:0x%u\n", (unsigned int)eglstatus); // TODO: do not use printf directly here
+ }
+
+ g_eglContextStruct.eglContext = eglCreateContext(
+ g_eglContextStruct.eglDisplay, g_eglContextStruct.eglConfig, NULL,
+ contextAttribs);
+
+ eglstatus = eglGetError();
+ if (eglstatus != EGL_SUCCESS)
+ {
+ printf("Error: eglCreateContext() failed.\n");
+ }
+
+ eglMakeCurrent(g_eglContextStruct.eglDisplay,
+ g_eglContextStruct.eglSurface, g_eglContextStruct.eglSurface,
+ g_eglContextStruct.eglContext);
+ eglSwapInterval(g_eglContextStruct.eglDisplay, 1);
+ eglstatus = eglGetError();
+ if (eglstatus != EGL_SUCCESS)
+ {
+ printf("Error: eglMakeCurrent() failed.\n");
+ }
+
+ // register surfaces to layermanager
+ t_ilm_layer layerid = (t_ilm_layer)LAYER_EXAMPLE_VIDEO_APPLICATIONS;
+ t_ilm_surface surfaceid = (t_ilm_surface)SURFACE_EXAMPLE_EGLX11_APPLICATION;
+
+ // TODO: if (error == ILM_FAILED) return ILM_FALSE;
+
+ // TODO: auto generate surface id
+ struct wl_object* p_obj = (struct wl_object*)g_wlContextStruct.wlSurface;
+ native_ilm_handle = (g_wlContextStruct.connect_id << 16) | (uint32_t)p_obj->id;
+ error = ilm_surfaceCreate( (t_ilm_nativehandle) native_ilm_handle, width, height,
+ ILM_PIXELFORMAT_RGBA_8888, &surfaceid);
+
+ if (error == ILM_FAILED)
+ {
+ printf("ERROR: create a surface\n");
+ }
+ // TODO: if (error == ILM_FAILED) return ILM_FALSE;
+
+ printf("set surface dest region\n");
+ error = ilm_surfaceSetDestinationRectangle(surfaceid, 0, 0, width, height);
+
+ // TODO: if (error == ILM_FAILED) return ILM_FALSE;
+
+ printf("set surface src region\n");
+ //error = ilm_surfaceSetSourceRectangle(surfaceid, 0, 0, width, height);
+ error = ilm_surfaceSetSourceRectangle(surfaceid, 0, 0, width, height);
+
+ // TODO: if (error == ILM_FAILED) return ILM_FALSE;
+
+ printf("add surface to layer\n");
+ error = ilm_layerAddSurface(layerid, surfaceid);
+ printf("Set surface visible\n");
+ error = ilm_surfaceSetVisibility(surfaceid, ILM_TRUE);
+ printf("Set surface opacity\n");
+ error = ilm_surfaceSetOpacity(surfaceid, 0.75f);
+
+ //if (error == ILM_FAILED) return ILM_FALSE;
+
+ printf("commit\n");
+ error = ilm_commitChanges();
+
+ //if (error == ILM_FAILED) return ILM_FALSE;
+
+ return result;
+}
+
+void destroyEglContext()
+{
+ if (g_eglContextStruct.eglDisplay != NULL)
+ {
+ eglMakeCurrent(g_eglContextStruct.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglTerminate(g_eglContextStruct.eglDisplay);
+ }
+}
+
+void destroyWLContext()
+{
+ if (g_wlContextStruct.wlNativeWindow)
+ {
+ wl_egl_window_destroy(g_wlContextStruct.wlNativeWindow);
+ }
+ if (g_wlContextStruct.wlSurface)
+ {
+ wl_surface_destroy(g_wlContextStruct.wlSurface);
+ }
+ if (g_wlContextStruct.wlCompositor)
+ {
+ wl_compositor_destroy(g_wlContextStruct.wlCompositor);
+ }
+}
+
+t_ilm_uint GetTickCount()
+{
+ struct timeval ts;
+ gettimeofday(&ts, 0);
+ return (t_ilm_uint) (ts.tv_sec * 1000 + (ts.tv_usec / 1000));
+}
+
+static void frame_listener_func(void *data, struct wl_callback *callback, uint32_t time)
+{
+ data = data; // TODO:to avoid warning
+ time = time; // TODO:to avoid warining
+ if (callback)
+ {
+ wl_callback_destroy(callback);
+ }
+}
+
+static const struct wl_callback_listener frame_listener = {
+ frame_listener_func
+};
+
+void swapBuffers()
+{
+ eglSwapBuffers(g_eglContextStruct.eglDisplay, g_eglContextStruct.eglSurface);
+
+ struct wl_callback* callback = wl_surface_frame(g_wlContextStruct.wlSurface);
+ wl_callback_add_listener(callback, &frame_listener, NULL);
+ wl_display_flush(g_wlContextStruct.wlDisplay);
+}
--- /dev/null
+/***************************************************************************
+ *
+ * Copyright 2010,2011 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "egl_helper.h"
+#include "gles2application.h"
+#include "IlmMatrix.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+typedef struct t_shaderObject
+{
+ GLuint fragmentShaderId;
+ GLuint vertexShaderId;
+ GLuint shaderProgramId;
+ GLint matrixLocation;
+ GLint colorLocation;
+} gles2Shader;
+
+typedef struct vertexBufferObject
+{
+ GLuint vbo;
+} gles2VertexBuffer;
+
+static gles2Shader shader;
+static gles2VertexBuffer vertexBuffer;
+
+// Fragment and vertex shaders code
+const char * sourceFragShader = "\
+ uniform mediump vec4 u_color;\
+ void main (void)\
+ {\
+ gl_FragColor = u_color;\
+ }";
+
+const char * sourceVertShader = "\
+ attribute highp vec4 a_vertex;\
+ uniform mediump mat4 u_matrix;\
+ void main(void)\
+ {\
+ gl_Position = u_matrix*a_vertex;\
+ }";
+
+GLfloat triangleVertexData[] =
+{
+ -0.4f, -0.4f, 0.0f, -0.2f, -0.4f, 0.0f, -0.3f, -0.2f, 0.0f,
+ -0.2f, -0.4f, 0.0f, -0.0f, -0.4f, 0.0f, -0.1f, -0.2f, 0.0f,
+ -0.0f, -0.4f, 0.0f, 0.2f, -0.4f, 0.0f, 0.1f, -0.2f, 0.0f,
+ 0.2f, -0.4f, 0.0f, 0.4f, -0.4f, 0.0f, 0.3f, -0.2f, 0.0f,
+ -0.3f, -0.2f, 0.0f, -0.1f, -0.2f, 0.0f, -0.2f, -0.0f, 0.0f,
+ 0.1f, -0.2f, 0.0f, 0.3f, -0.2f, 0.0f, 0.2f, -0.0f, 0.0f,
+ -0.2f, -0.0f, 0.0f, -0.0f, -0.0f, 0.0f, -0.1f, 0.2f, 0.0f,
+ 0.0f, -0.0f, 0.0f, 0.2f, -0.0f, 0.0f, 0.1f, 0.2f, 0.0f,
+ -0.1f, 0.2f, 0.0f, 0.1f, 0.2f, 0.0f, 0.0f, 0.4f, 0.0f
+};
+
+t_ilm_bool initGlApplication()
+{
+ if (!initShader())
+ {
+ return ILM_FALSE;
+ }
+
+ if (!initVertexBuffer())
+ {
+ return ILM_FALSE;
+ }
+
+ glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ return ILM_TRUE;
+}
+
+t_ilm_bool initShader()
+{
+ t_ilm_bool result = ILM_TRUE;
+
+ // Create the fragment shader object
+ shader.fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
+
+ // Load Fragment Source
+ glShaderSource(shader.fragmentShaderId, 1, (const char**) &sourceFragShader, NULL);
+
+ // Compile the source code of fragment shader
+ glCompileShader(shader.fragmentShaderId);
+
+ glGetShaderiv(shader.fragmentShaderId, GL_COMPILE_STATUS, (GLint*) &result);
+
+ if (!result)
+ {
+ t_ilm_int infoLength, numberChars;
+ glGetShaderiv(shader.fragmentShaderId, GL_INFO_LOG_LENGTH, &infoLength);
+
+ // Allocate Log Space
+ char* info = (char*) malloc(sizeof(char) * infoLength);
+ glGetShaderInfoLog(shader.fragmentShaderId, infoLength, &numberChars, info);
+
+ // Print the error
+ printf("Failed to compile fragment shader: %s\n", info);
+ free(info);
+ return ILM_FALSE;
+ }
+
+ // Create the fragment shader object
+ shader.vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
+
+ // Load Fragment Source
+ glShaderSource(shader.vertexShaderId, 1, (const char**) &sourceVertShader, NULL);
+
+ // Compile the source code of fragment shader
+ glCompileShader(shader.vertexShaderId);
+
+ glGetShaderiv(shader.vertexShaderId, GL_COMPILE_STATUS, (GLint*) &result);
+
+ if (!result)
+ {
+ t_ilm_int infoLength, numberChars;
+ glGetShaderiv(shader.vertexShaderId, GL_INFO_LOG_LENGTH, &infoLength);
+
+ // Allocate Log Space
+ char* info = (char*) malloc(sizeof(char) * infoLength);
+ glGetShaderInfoLog(shader.vertexShaderId, infoLength, &numberChars, info);
+
+ // Print the error
+ printf("Failed to compile vertex shader: %s\n", info);
+ free(info);
+ return ILM_FALSE;
+ }
+
+ shader.shaderProgramId = glCreateProgram();
+
+ glAttachShader(shader.shaderProgramId, shader.fragmentShaderId);
+ glAttachShader(shader.shaderProgramId, shader.vertexShaderId);
+
+ glBindAttribLocation(shader.shaderProgramId, 0, "a_vertex");
+
+ glLinkProgram(shader.shaderProgramId);
+
+ glGetProgramiv(shader.shaderProgramId, GL_LINK_STATUS, (GLint*) &result);
+
+ if (!result)
+ {
+ t_ilm_int infoLength, numberChars;
+ glGetShaderiv(shader.shaderProgramId, GL_INFO_LOG_LENGTH, &infoLength);
+
+ // Allocate Log Space
+ char* info = (char*) malloc(sizeof(char) * infoLength);
+ glGetShaderInfoLog(shader.shaderProgramId, infoLength, &numberChars,
+ info);
+
+ // Print the error
+ printf("Failed to link program: %s\n", info);
+ free(info);
+ return ILM_FALSE;
+ }
+ glUseProgram(shader.shaderProgramId);
+ shader.matrixLocation = glGetUniformLocation(shader.shaderProgramId, "u_matrix");
+ shader.colorLocation = glGetUniformLocation(shader.shaderProgramId, "u_color");
+ return result;
+}
+
+t_ilm_bool destroyShader()
+{
+ t_ilm_bool result = ILM_TRUE;
+ glDeleteProgram(shader.shaderProgramId);
+ glDeleteShader(shader.fragmentShaderId);
+ glDeleteShader(shader.vertexShaderId);
+ return result;
+}
+
+t_ilm_bool initVertexBuffer()
+{
+ t_ilm_bool result = ILM_TRUE;
+
+ glGenBuffers(1, &vertexBuffer.vbo);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.vbo);
+
+ unsigned int uiSize = 27 * (sizeof(GLfloat) * 3); // TODO: remove hard coded values
+ glBufferData(GL_ARRAY_BUFFER, uiSize, &triangleVertexData[0], GL_STATIC_DRAW);
+
+ return result;
+}
+
+void attachVertexBuffer()
+{
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.vbo);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
+
+}
+
+void detachVertexBuffer()
+{
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+void destroyVertexBuffer()
+{
+ glDeleteBuffers(1, &vertexBuffer.vbo);
+}
+
+void draw(t_ilm_uint animTime)
+{
+ static t_ilm_uint startTime = 0;
+ static t_ilm_uint currentTime = 0;
+ static float angle = 0;
+ IlmMatrix matrix;
+
+ currentTime = GetTickCount();
+
+printf("currentTime=%d, startTime=%d, animTime=%d\n", currentTime, startTime, animTime);
+ if ((currentTime - startTime) > animTime)
+ {
+ float currentAngle = 0;
+ int i = 0;
+ glClear(GL_COLOR_BUFFER_BIT);
+ glUseProgram(shader.shaderProgramId);
+ attachVertexBuffer();
+ for (i = 10; i > 0; i--)
+ {
+ currentAngle = angle - ((float) i) * 10.0f;
+ IlmMatrixIdentity(matrix);
+ IlmMatrixRotateZ(matrix, currentAngle);
+ float color[4] = { 0.0, 1.0, 1.0, 0.5 + (0.3 / (float) i) };
+ float lineColor[4] = { 0.0, 0.0, 0.0, 0.5 + (0.4 / (float) i) };
+
+ glUniformMatrix4fv(shader.matrixLocation, 1, GL_FALSE, &matrix.f[0]);
+ glUniform4fv(shader.colorLocation, 1, &color[0]);
+ glDrawArrays(GL_TRIANGLES, 0, 27); // TODO: remove hard coded values
+
+ glUniform4fv(shader.colorLocation, 1, &lineColor[0]);
+ int j = 0;
+ for (j = 0; j < 9; j++) // TODO: remove hard coded values
+ {
+ glDrawArrays(GL_LINE_LOOP, j * 3, 3); // TODO: remove hard coded values
+ }
+ }
+ angle += 10.0f;
+ detachVertexBuffer();
+ swapBuffers();
+ startTime = currentTime;
+ }
+
+}
+
+void destroyGlApplication()
+{
+ destroyShader();
+ destroyVertexBuffer();
+}