ivi-layermanagement-examples: Add EGLWLInputEventExample example application
authorJames Thomas <james.thomas@codethink.co.uk>
Thu, 31 Jul 2014 08:55:55 +0000 (10:55 +0200)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Wed, 12 Nov 2014 23:34:04 +0000 (08:34 +0900)
Signed-off-by: James Thomas <james.thomas@codethink.co.uk>
16 files changed:
ivi-layermanagement-examples/CMakeLists.txt
ivi-layermanagement-examples/EGLWLInputEventExample/CMakeLists.txt [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WLContext.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEGLSurface.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyes.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WLSurface.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/WaylandServerinfoClientProtocol.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/include/transform.h [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WLContext.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEGLSurface.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyes.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WLSurface.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/WaylandServerinfoProtocol.cpp [new file with mode: 0644]
ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp [new file with mode: 0644]

index 7cc3e7e..7bb1e2a 100644 (file)
@@ -25,3 +25,4 @@ project (ivi-layermanagement-examples)
 #===========================================================================================================
 add_subdirectory(LayerManagerControl)
 add_subdirectory(EGLWLMockNavigation)
+add_subdirectory(EGLWLInputEventExample)
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/CMakeLists.txt b/ivi-layermanagement-examples/EGLWLInputEventExample/CMakeLists.txt
new file mode 100644 (file)
index 0000000..69c2c0a
--- /dev/null
@@ -0,0 +1,91 @@
+############################################################################
+#
+# Copyright 2010-2012 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)
+
+project(EGLWLInputEventExample)
+
+find_package(PkgConfig)
+pkg_check_modules(GLESv2 glesv2 REQUIRED)
+pkg_check_modules(EGL egl REQUIRED)
+pkg_check_modules(WAYLAND_EGL wayland-egl REQUIRED)
+pkg_check_modules(WAYLAND_CLIENT wayland-client REQUIRED)
+
+GET_TARGET_PROPERTY(ILM_CLIENT_INCLUDE_DIRS  ilmClient  INCLUDE_DIRECTORIES)
+GET_TARGET_PROPERTY(ILM_CONTROL_INCLUDE_DIRS ilmControl INCLUDE_DIRECTORIES)
+
+include_directories(
+    ${ILM_CLIENT_INCLUDE_DIRS}
+    ${ILM_CONTROL_INCLUDE_DIRS}
+    ${GLESv2_INCLUDE_DIR}
+    ${EGL_INCLUDE_DIR}
+    ${WAYLAND_CLIENT_INCLUDE_DIR}
+    ${FFI_INCLUDE_DIR}
+    "include"
+)
+
+set (HEADER_FILES
+    include/transform.h
+    include/WaylandServerinfoClientProtocol.h
+    include/WLContext.h
+    include/WLEGLSurface.h
+    include/WLEyes.h
+    include/WLEyesRenderer.h
+    include/WLSurface.h
+)
+
+set (SRC_FILES
+    src/main.cpp
+    src/WaylandServerinfoProtocol.cpp
+    src/WLContext.cpp
+    src/WLEGLSurface.cpp
+    src/WLEyes.cpp
+    src/WLEyesRenderer.cpp
+    src/WLSurface.cpp
+)
+
+add_executable(EGLWLInputEventExample
+    ${SRC_FILES}
+    ${HEADER_FILES}
+)
+
+add_dependencies(EGLWLInputEventExample
+    wayland-client
+    wayland-egl
+    ilmClient
+    ilmControl
+)
+
+set(LIBS
+    ${LIBS}
+    ${GLESv2_LIBRARIES}
+    ${WAYLAND_CLIENT_LIBRARIES}
+    ${WAYLAND_EGL_LIBRARIES}
+    ${FFI_LIBRARIES}
+    ${EGL_LIBRARIES}
+    ilmClient
+    ilmControl
+)
+
+add_definitions(${EGL_CFLAGS})
+
+target_link_libraries(EGLWLInputEventExample ${LIBS})
+
+install (TARGETS EGLWLInputEventExample DESTINATION bin)
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLContext.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLContext.h
new file mode 100644 (file)
index 0000000..6282236
--- /dev/null
@@ -0,0 +1,123 @@
+/**************************************************************************
+ *
+ * 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 _WLCONTEXT_H_
+#define _WLCONTEXT_H_
+
+#include <wayland-client.h>
+#include <wayland-client-protocol.h>
+
+struct serverinfo;
+
+class WLContext
+{
+// properties
+private:
+    struct wl_display*    m_wlDisplay;
+    struct wl_registry*   m_wlRegistry;
+    struct wl_compositor* m_wlCompositor;
+    struct wl_seat*       m_wlSeat;
+    struct wl_pointer*    m_wlPointer;
+    struct wl_keyboard*   m_wlKeyboard;
+    struct wl_touch*      m_wlTouch;
+    struct serverinfo*    m_wlServerInfo;
+    uint32_t m_connectionId;
+
+    struct wl_pointer_listener*  m_wlPointerListener;
+    struct wl_keyboard_listener* m_wlKeyboardListener;
+    struct wl_touch_listener*    m_wlTouchListener;
+
+// methods
+public:
+    WLContext();
+    virtual ~WLContext();
+
+    bool InitWLContext(const struct wl_pointer_listener* wlPointerListener = NULL,
+                       const struct wl_keyboard_listener* wlKeyboardListener = NULL,
+                       const struct wl_touch_listener* wlTouchListener = NULL);
+
+    struct wl_compositor* GetWLCompositor() const;
+    struct wl_display* GetWLDisplay() const;
+    struct wl_registry* GetWLRegistry() const;
+    struct wl_pointer* GetWLPointer() const;
+    struct wl_keyboard* GetWLKeyboard() const;
+    struct wl_touch* GetWLTouch() const;
+    struct wl_seat* GetWLSeat() const;
+    struct wl_pointer_listener* GetWLPointerListener() const;
+    struct wl_keyboard_listener* GetWLKeyboardListener() const;
+    struct wl_touch_listener* GetWLTouchListener() const;
+    uint32_t GetConnectionId() const;
+
+    void SetEventMask(uint32_t mask);
+    void SetWLCompositor(struct wl_compositor* wlCompositor);
+    void SetWLServerInfo(struct serverinfo* wlServerInfo);
+    void SetWLSeat(struct wl_seat* wlSeat);
+    void SetConnectionId(uint32_t connectionId);
+    void SetWLPointer(struct wl_pointer* wlPointer);
+    void SetWLKeyboard(struct wl_keyboard* wlKeyboard);
+    void SetWLTouch(struct wl_touch* wlTouch);
+
+    static void RegistryHandleGlobal(void* data,
+                                     struct wl_registry* registry,
+                                     uint32_t name,
+                                     const char* interface,
+                                     uint32_t version);
+    static void ServerInfoListener(void* data,
+                                   struct serverinfo* serverInfo,
+                                   uint32_t clientHandle);
+    static void SeatHandleCapabilities(void* data,
+                                       struct wl_seat* seat,
+                                       uint32_t caps);
+    static int EventMaskUpdate(uint32_t mask, void* data);
+
+protected:
+    void DestroyWLContext();
+};
+
+inline struct wl_compositor* WLContext::GetWLCompositor() const { return m_wlCompositor; }
+inline struct wl_display* WLContext::GetWLDisplay() const { return m_wlDisplay; }
+inline struct wl_registry* WLContext::GetWLRegistry() const { return m_wlRegistry; }
+inline struct wl_pointer* WLContext::GetWLPointer() const { return m_wlPointer; }
+inline struct wl_keyboard* WLContext::GetWLKeyboard() const { return m_wlKeyboard; }
+inline struct wl_touch* WLContext::GetWLTouch() const { return m_wlTouch; }
+inline struct wl_seat* WLContext::GetWLSeat() const { return m_wlSeat; }
+inline struct wl_pointer_listener* WLContext::GetWLPointerListener() const
+    { return m_wlPointerListener; }
+inline struct wl_keyboard_listener* WLContext::GetWLKeyboardListener() const
+    { return m_wlKeyboardListener; }
+inline struct wl_touch_listener* WLContext::GetWLTouchListener() const
+    { return m_wlTouchListener; }
+inline uint32_t WLContext::GetConnectionId() const { return m_connectionId; }
+
+inline void WLContext::SetWLCompositor(struct wl_compositor* wlCompositor)
+    { m_wlCompositor = wlCompositor; }
+inline void WLContext::SetWLServerInfo(struct serverinfo* wlServerInfo)
+    { m_wlServerInfo = wlServerInfo; }
+inline void WLContext::SetWLSeat(struct wl_seat* wlSeat)
+    { m_wlSeat = wlSeat; }
+inline void WLContext::SetConnectionId(uint32_t connectionId)
+    { m_connectionId = connectionId; }
+inline void WLContext::SetWLPointer(struct wl_pointer* wlPointer)
+    { m_wlPointer = wlPointer; }
+inline void WLContext::SetWLKeyboard(struct wl_keyboard* wlKeyboard)
+    { m_wlKeyboard = wlKeyboard; }
+inline void WLContext::SetWLTouch(struct wl_touch* wlTouch)
+    { m_wlTouch = wlTouch; }
+
+#endif /* _WLCONTEXT_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEGLSurface.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEGLSurface.h
new file mode 100644 (file)
index 0000000..577930d
--- /dev/null
@@ -0,0 +1,54 @@
+/**************************************************************************
+ *
+ * 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 _WLEGLSURFACE_H_
+#define _WLEGLSURFACE_H_
+
+#include <EGL/egl.h>
+#include <wayland-egl.h>
+#include "WLSurface.h"
+
+class WLEGLSurface : public WLSurface
+{
+// properties
+protected:
+    struct wl_egl_window* m_wlEglWindow;
+    EGLDisplay            m_eglDisplay;
+    EGLConfig             m_eglConfig;
+    EGLSurface            m_eglSurface;
+    EGLContext            m_eglContext;
+
+// methods
+public:
+    WLEGLSurface(WLContext* wlContext);
+    virtual ~WLEGLSurface();
+
+    EGLDisplay GetEGLDisplay() const;
+    EGLSurface GetEGLSurface() const;
+    EGLContext GetEGLContext() const;
+
+protected:
+    virtual bool CreatePlatformSurface();
+};
+
+inline EGLDisplay WLEGLSurface::GetEGLDisplay() const { return m_eglDisplay; }
+inline EGLSurface WLEGLSurface::GetEGLSurface() const { return m_eglSurface; }
+inline EGLContext WLEGLSurface::GetEGLContext() const { return m_eglContext; }
+
+#endif /* _WLEGLSURFACE_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyes.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyes.h
new file mode 100644 (file)
index 0000000..0cc062e
--- /dev/null
@@ -0,0 +1,85 @@
+/**************************************************************************
+ *
+ * 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 _WLEYES_H_
+#define _WLEYES_H_
+
+#include "transform.h"
+
+//////////////////////////////////////////////////////////////////////////////
+
+class WLEye
+{
+private:
+    int     m_nPoint;
+    TPoint* m_eyeLiner;
+    int     m_nPupilPoint;
+    TPoint* m_pupil;
+    int     m_nWhiteEyePoint;
+    TPoint* m_whiteEye;
+
+public:
+    WLEye();
+    virtual ~WLEye();
+
+    void CreateEyeLiner(const float& centerX,
+                        const float& centerY,
+                        const float& diam,
+                        const Transform& trans);
+    void CreatePupil(const float& centerX,
+                     const float& centerY,
+                     const float& diam,
+                     const Transform& trans);
+
+    void GetEyeLinerGeom(int* nPoint, float** points);
+    void GetWhiteEyeGeom(int* nPoint, float** points);
+    void GetPupilGeom(int* nPoint, float** points);
+
+private:
+    void CreateWhiteEye(const float& centerX,
+                        const float& centerY,
+                        const float& diam,
+                        const Transform& trans);
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+class WLEyes
+{
+private:
+    WLEye*    m_eyes[2];
+    int       m_width;
+    int       m_height;
+    Transform m_trans;
+
+public:
+    WLEyes(int screenWidth, int screenHeight);
+    virtual ~WLEyes();
+
+    void SetPointOfView(int mousePosX, int mousePosY);
+
+    void GetEyeLinerGeom(int n, int* nPoint, float** points);
+    void GetWhiteEyeGeom(int n, int* nPoint, float** points);
+    void GetPupilGeom(int n, int* nPoint, float** points);
+
+private:
+    WLEyes();
+};
+
+#endif /* _WLEYES_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h
new file mode 100644 (file)
index 0000000..e630ecc
--- /dev/null
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * 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 _WLEYESRENDERER_H_
+#define _WLEYESRENDERER_H_
+
+#include <wayland-client.h>
+#include "WLEGLSurface.h"
+#include "WLEyes.h"
+
+bool InitRenderer();
+bool InitShader();
+bool InitVertexBuffer();
+void WaitForEvent(struct wl_display* wlDisplay);
+void TerminateRenderer();
+
+// Pointer event handler
+void PointerHandleEnter(void*, struct wl_pointer*, uint32_t, struct wl_surface*,
+                        wl_fixed_t, wl_fixed_t);
+void PointerHandleLeave(void*, struct wl_pointer*, uint32_t, struct wl_surface*);
+void PointerHandleMotion(void*, struct wl_pointer*, uint32_t,
+                         wl_fixed_t, wl_fixed_t);
+void PointerHandleButton(void*, struct wl_pointer*, uint32_t, uint32_t, uint32_t,
+                         uint32_t);
+void PointerHandleAxis(void*, struct wl_pointer*, uint32_t, uint32_t, wl_fixed_t);
+
+// Keyboard event handler
+void KeyboardHandleKeymap(void*, struct wl_keyboard*, uint32_t, int, uint32_t);
+void KeyboardHandleEnter(void*, struct wl_keyboard*, uint32_t, struct wl_surface*,
+                         struct wl_array*);
+void KeyboardHandleLeave(void*, struct wl_keyboard*, uint32_t, struct wl_surface*);
+void KeyboardHandleKey(void*, struct wl_keyboard*, uint32_t, uint32_t, uint32_t,
+                       uint32_t);
+void KeyboardHandleModifiers(void*, struct wl_keyboard*, uint32_t, uint32_t,
+                             uint32_t, uint32_t, uint32_t);
+
+// Touch event handler
+void TouchHandleDown(void*, struct wl_touch*, uint32_t, uint32_t, struct wl_surface*,
+                     int32_t, wl_fixed_t, wl_fixed_t);
+void TouchHandleUp(void*, struct wl_touch*, uint32_t, uint32_t, int32_t);
+void TouchHandleMotion(void*, struct wl_touch*, uint32_t, int32_t, wl_fixed_t, wl_fixed_t);
+void TouchHandleFrame(void*, struct wl_touch*);
+void TouchHandleCancel(void*, struct wl_touch*);
+
+bool DrawEyes(WLEGLSurface* surface, WLEyes* eyes);
+void DrawFillPoly(const int nPoint, const float* points, const float color[4]);
+void DrawPoly(const int nPoint, const float* points, const float color[4], int width);
+
+extern const struct wl_pointer_listener PointerListener;
+extern const struct wl_keyboard_listener KeyboardListener;
+extern const struct wl_touch_listener TouchListener;
+
+#endif /* _WLEYESRENDERER_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLSurface.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLSurface.h
new file mode 100644 (file)
index 0000000..d659eac
--- /dev/null
@@ -0,0 +1,59 @@
+/**************************************************************************
+ *
+ * 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 _WLSURFACE_H_
+#define _WLSURFACE_H_
+
+#include "ilm_client.h"
+#include "WLContext.h"
+
+class WLSurface
+{
+// properties
+protected:
+    WLContext*         m_wlContext;
+    struct wl_surface* m_wlSurface;
+    int           m_width;
+    int           m_height;
+    t_ilm_layer   m_ilmLayerId;
+    t_ilm_surface m_ilmSurfaceId;
+
+// methods
+public:
+    WLSurface(WLContext* wlContext);
+    virtual ~WLSurface();
+
+    struct wl_display* GetWLDisplay() const;
+    struct wl_surface* GetWLSurface() const;
+
+    virtual bool CreateSurface(const int width, const int height);
+    virtual bool CreateIlmSurface(t_ilm_surface* surfaceId,
+                                  t_ilm_int width,
+                                  t_ilm_int height);
+    virtual void DestroyIlmSurface();
+
+protected:
+    virtual bool CreatePlatformSurface();
+};
+
+inline struct wl_surface* WLSurface::GetWLSurface() const { return m_wlSurface; }
+inline struct wl_display* WLSurface::GetWLDisplay() const
+    { return m_wlContext->GetWLDisplay(); }
+
+#endif /* _WLSURFACE_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WaylandServerinfoClientProtocol.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WaylandServerinfoClientProtocol.h
new file mode 100644 (file)
index 0000000..b92d672
--- /dev/null
@@ -0,0 +1,92 @@
+/***************************************************************************
+*
+* 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 WAYLANDSERVERINFOCLIENTPROTOCOL_H
+#define WAYLANDSERVERINFOCLIENTPROTOCOL_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 /* WAYLANDSERVERINFOCLIENTPROTOCOL_H */
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/transform.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/transform.h
new file mode 100644 (file)
index 0000000..ebfc01a
--- /dev/null
@@ -0,0 +1,45 @@
+/**************************************************************************
+ *
+ * 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 _TRANSFORM_H_
+#define _TRANSFORM_H_
+
+typedef struct _transform {
+    float mx, bx;
+    float my, by;
+} Transform;
+
+typedef struct _tpoint {
+    float x, y;
+} TPoint;
+
+typedef struct _trectangle {
+    float x, y, width, height;
+} TRectangle;
+
+#define Xx(x,y,t)  ((int)((t)->mx * (x) + (t)->bx + 0.5))
+#define Xy(x,y,t)  ((int)((t)->my * (y) + (t)->by + 0.5))
+#define Xwidth(w,h,t)  ((int)((t)->mx * (w) + 0.5))
+#define Xheight(w,h,t) ((int)((t)->my * (h) + 0.5))
+#define Tx(x,y,t)  ((((float) (x)) - (t)->bx) / (t)->mx)
+#define Ty(x,y,t)  ((((float) (y)) - (t)->by) / (t)->my)
+#define Twidth(w,h,t)  (((float) (w)) / (t)->mx)
+#define Theight(w,h,t) (((float) (h)) / (t)->my)
+
+#endif
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLContext.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLContext.cpp
new file mode 100644 (file)
index 0000000..d8942f5
--- /dev/null
@@ -0,0 +1,197 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "WLContext.h"
+#include "WaylandServerinfoClientProtocol.h"
+
+#define WL_UNUSED(A) (A)=(A)
+
+//////////////////////////////////////////////////////////////////////////////
+
+static struct wl_registry_listener registryListener = {
+    WLContext::RegistryHandleGlobal,
+    NULL
+};
+
+static struct serverinfo_listener serverInfoListenerList = {
+    WLContext::ServerInfoListener,
+};
+
+static struct wl_seat_listener seatListener = {
+    WLContext::SeatHandleCapabilities,
+    NULL
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+WLContext::WLContext()
+: m_wlDisplay(NULL)
+, m_wlRegistry(NULL)
+, m_wlCompositor(NULL)
+, m_wlSeat(NULL)
+, m_wlPointer(NULL)
+, m_wlTouch(NULL)
+, m_wlServerInfo(NULL)
+, m_connectionId(0)
+, m_wlPointerListener(NULL)
+, m_wlKeyboardListener(NULL)
+, m_wlTouchListener(NULL)
+{
+}
+
+WLContext::~WLContext()
+{
+    DestroyWLContext();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void
+WLContext::RegistryHandleGlobal(void* data,
+                                struct wl_registry* registry,
+                                uint32_t name,
+                                const char* interface,
+                                uint32_t version)
+{
+    WL_UNUSED(version);
+
+    WLContext* surface = static_cast<WLContext*>(data);
+    assert(surface);
+
+    do {
+        if (!strcmp(interface, "wl_compositor")){
+            surface->SetWLCompositor(
+                (wl_compositor*)wl_registry_bind(registry,
+                                                name,
+                                                &wl_compositor_interface,
+                                                1));
+            break;
+        }
+
+        if (!strcmp(interface, "serverinfo")){
+            struct serverinfo* wlServerInfo = (struct serverinfo*)wl_registry_bind(
+                registry, name, &serverinfo_interface, 1);
+            serverinfo_add_listener(wlServerInfo, &serverInfoListenerList, data);
+            serverinfo_get_connection_id(wlServerInfo);
+            surface->SetWLServerInfo(wlServerInfo);
+            break;
+        }
+
+        if (!strcmp(interface, "wl_seat")){
+            struct wl_seat* wlSeat = (wl_seat*)wl_registry_bind(
+                registry, name, &wl_seat_interface, 1);
+            wl_seat_add_listener(wlSeat, &seatListener, data);
+            surface->SetWLSeat(wlSeat);
+        }
+    } while (0);
+}
+
+void
+WLContext::ServerInfoListener(void* data,
+                              struct serverinfo* serverInfo,
+                              uint32_t clientHandle)
+{
+    WL_UNUSED(serverInfo);
+
+    WLContext* surface = static_cast<WLContext*>(data);
+    assert(surface);
+
+    surface->SetConnectionId(clientHandle);
+}
+
+void
+WLContext::SeatHandleCapabilities(void* data, struct wl_seat* seat, uint32_t caps)
+{
+    WL_UNUSED(seat);
+
+    WLContext* context = static_cast<WLContext*>(data);
+    assert(context);
+
+    struct wl_seat* wlSeat = context->GetWLSeat();
+    if (!wlSeat)
+        return;
+
+    struct wl_pointer* wlPointer = context->GetWLPointer();
+    if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wlPointer){
+        wlPointer = wl_seat_get_pointer(wlSeat);
+        wl_pointer_set_user_data(wlPointer, data);
+        wl_pointer_add_listener(wlPointer, context->GetWLPointerListener(), data);
+    } else
+    if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wlPointer){
+        wl_pointer_destroy(wlPointer);
+        wlPointer = NULL;
+    }
+    context->SetWLPointer(wlPointer);
+
+    struct wl_keyboard* wlKeyboard = context->GetWLKeyboard();
+    if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wlKeyboard){
+        wlKeyboard = wl_seat_get_keyboard(wlSeat);
+        wl_keyboard_set_user_data(wlKeyboard, data);
+        wl_keyboard_add_listener(wlKeyboard, context->GetWLKeyboardListener(), data);
+    } else
+    if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wlKeyboard){
+        wl_keyboard_destroy(wlKeyboard);
+        wlKeyboard = NULL;
+    }
+    context->SetWLKeyboard(wlKeyboard);
+
+    struct wl_touch* wlTouch = context->GetWLTouch();
+    if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !wlTouch){
+        wlTouch = wl_seat_get_touch(wlSeat);
+        wl_touch_set_user_data(wlTouch, data);
+        wl_touch_add_listener(wlTouch, context->GetWLTouchListener(), data);
+    } else
+    if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && wlTouch){
+        wl_touch_destroy(wlTouch);
+        wlTouch = NULL;
+    }
+    context->SetWLTouch(wlTouch);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+bool
+WLContext::InitWLContext(const struct wl_pointer_listener* wlPointerListener,
+                         const struct wl_keyboard_listener* wlKeyboardListener,
+                         const struct wl_touch_listener* wlTouchListener)
+{
+    m_wlPointerListener = const_cast<wl_pointer_listener*>(wlPointerListener);
+    m_wlKeyboardListener = const_cast<wl_keyboard_listener*>(wlKeyboardListener);
+    m_wlTouchListener = const_cast<wl_touch_listener*>(wlTouchListener);
+
+    m_wlDisplay = wl_display_connect(NULL);
+
+    m_wlRegistry = wl_display_get_registry(m_wlDisplay);
+    wl_registry_add_listener(m_wlRegistry, &registryListener, this);
+    wl_display_dispatch(m_wlDisplay);
+    wl_display_roundtrip(m_wlDisplay);
+
+    return true;
+}
+
+void
+WLContext::DestroyWLContext()
+{
+    if (m_wlCompositor)
+        wl_compositor_destroy(m_wlCompositor);
+}
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEGLSurface.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEGLSurface.cpp
new file mode 100644 (file)
index 0000000..0b28ec6
--- /dev/null
@@ -0,0 +1,107 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "WLEGLSurface.h"
+
+//////////////////////////////////////////////////////////////////////////////
+#define CHECK_EGL_ERROR(FUNC, STAT) \
+    STAT = eglGetError();           \
+    if (STAT != EGL_SUCCESS){       \
+        fprintf(stderr, "[ERROR] %s failed: %d\n", FUNC, STAT); \
+        return false;               \
+    }
+
+//////////////////////////////////////////////////////////////////////////////
+
+WLEGLSurface::WLEGLSurface(WLContext* wlContext)
+: WLSurface(wlContext)
+, m_wlEglWindow(NULL)
+, m_eglDisplay(EGL_NO_DISPLAY)
+, m_eglConfig(0)
+, m_eglSurface(EGL_NO_SURFACE)
+, m_eglContext(EGL_NO_CONTEXT)
+{
+}
+
+WLEGLSurface::~WLEGLSurface()
+{
+    if (m_wlEglWindow)
+        wl_egl_window_destroy(m_wlEglWindow);
+    eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+    eglTerminate(m_eglDisplay);
+}
+
+bool
+WLEGLSurface::CreatePlatformSurface()
+{
+    EGLint eglStat = EGL_SUCCESS;
+    EGLint major, minor;
+    int nConfig;
+    EGLint configAttribs[] = {
+        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_SAMPLE_BUFFERS, 1,
+        //EGL_SAMPLES,        2,
+        EGL_NONE,
+    };
+    EGLint contextAttribs[] = {
+        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_NONE,
+    };
+
+    m_wlEglWindow = wl_egl_window_create(m_wlSurface, m_width, m_height);
+
+    m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_wlContext->GetWLDisplay());
+    CHECK_EGL_ERROR("eglGetDisplay", eglStat);
+
+    if (!eglInitialize(m_eglDisplay, &major, &minor)){
+        CHECK_EGL_ERROR("eglInitialize", eglStat);
+    }
+
+    eglBindAPI(EGL_OPENGL_ES_API);
+    CHECK_EGL_ERROR("eglBindAPI", eglStat);
+
+    if (!eglChooseConfig(m_eglDisplay, configAttribs, &m_eglConfig, 1, &nConfig)
+        || (nConfig != 1)){
+        CHECK_EGL_ERROR("eglChooseConfig", eglStat);
+    }
+
+    m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig,
+                                          (EGLNativeWindowType)m_wlEglWindow, NULL);
+    CHECK_EGL_ERROR("eglCreateWindowSurface", eglStat);
+
+    m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, NULL, contextAttribs);
+    CHECK_EGL_ERROR("eglCreateContext", eglStat);
+
+    eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
+    CHECK_EGL_ERROR("eglMakeCurrent", eglStat);
+
+    //eglSwapInterval(m_eglDisplay, 1);
+    //CHECK_EGL_ERROR("eglSwapInterval", eglStat);
+
+    return true;
+}
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyes.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyes.cpp
new file mode 100644 (file)
index 0000000..887e394
--- /dev/null
@@ -0,0 +1,345 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "WLEyes.h"
+
+#define EYE_X(n)   ((n) * 2.0)
+#define EYE_Y(n)   (0.0)
+#define EYE_OFFSET (0.1)     /* padding between eyes */
+#define EYE_THICK  (0.175)   /* thickness of eye rim */
+#define BALL_DIAM  (0.3)
+#define BALL_PAD   (0.175)
+#define EYE_DIAM   (2.0 - (EYE_THICK + EYE_OFFSET) * 2)
+#define BALL_DIST  ((EYE_DIAM - BALL_DIAM) / 2.0 - BALL_PAD)
+
+//#define W_MIN_X    (-1.0 + EYE_OFFSET)
+//#define W_MAX_X    ( 3.0 - EYE_OFFSET)
+//#define W_MIN_Y    (-1.0 + EYE_OFFSET)
+//#define W_MAX_Y    ( 1.0 - EYE_OFFSET)
+#define W_MIN_X    (-1.05 + EYE_OFFSET)
+#define W_MAX_X    ( 3.05 - EYE_OFFSET)
+#define W_MIN_Y    (-1.05 + EYE_OFFSET)
+#define W_MAX_Y    ( 1.05 - EYE_OFFSET)
+
+#define TPOINT_NONE        (-1000)   /* special value meaning "not yet set" */
+#define TPointEqual(a, b)  ((a).x == (b).x && (a).y == (b).y)
+#define XPointEqual(a, b)  ((a).x == (b).x && (a).y == (b).y)
+#define AngleBetween(A, A0, A1) (A0 <= A1 ? A0 <= A && A <= A1 : \
+                                 A0 <= A || A <= A1)
+
+//////////////////////////////////////////////////////////////////////////////
+
+static void
+SetTransform(Transform* t, int xx1, int xx2, int xy1, int xy2,
+             float tx1, float tx2, float ty1, float ty2)
+{
+    t->mx = ((float) xx2 - xx1) / (tx2 - tx1);
+    t->bx = ((float) xx1) - t->mx * tx1;
+    t->my = ((float) xy2 - xy1) / (ty2 - ty1);
+    t->by = ((float) xy1) - t->my * ty1;
+}
+
+static void
+Trectangle(const Transform *t, const TRectangle *i, TRectangle *o)
+{
+    o->x = t->mx * i->x + t->bx;
+    o->y = t->my * i->y + t->by;
+    o->width = t->mx * i->width;
+    o->height = t->my * i->height;
+    if (o->width < 0) {
+        o->x += o->width;
+        o->width = -o->width;
+    }
+    if (o->height < 0) {
+        o->y += o->height;
+        o->height = -o->height;
+    }
+}
+
+static TPoint
+ComputePupil(int num, TPoint mouse, const TRectangle* screen)
+{
+   float   cx, cy;
+   float   dist;
+   float   angle;
+   float   dx, dy;
+   float   cosa, sina;
+   TPoint   ret;
+
+   cx = EYE_X(num); dx = mouse.x - cx;
+   cy = EYE_Y(num); dy = mouse.y - cy;
+   if (dx == 0 && dy == 0);
+   else {
+      angle = atan2 ((float) dy, (float) dx);
+      cosa = cos (angle);
+      sina = sin (angle);
+      dist = BALL_DIST;
+      if (screen)
+      {
+          /* use distance mapping */
+          float x0, y0, x1, y1;
+          float a[4];
+          x0 = screen->x - cx;
+          y0 = screen->y - cy;
+          x1 = x0 + screen->width;
+          y1 = y0 + screen->height;
+          a[0] = atan2(y0, x0);
+          a[1] = atan2(y1, x0);
+          a[2] = atan2(y1, x1);
+          a[3] = atan2(y0, x1);
+          if (AngleBetween(angle, a[0], a[1]))
+          {
+              /* left */
+              dist *= dx / x0;
+          }
+          else if (AngleBetween(angle, a[1], a[2]))
+          {
+              /* bottom */
+              dist *= dy / y1;
+          }
+          else if (AngleBetween(angle, a[2], a[3]))
+          {
+              /* right */
+              dist *= dx / x1;
+          }
+          else if (AngleBetween(angle, a[3], a[0]))
+          {
+              /* top */
+              dist *= dy / y0;
+          }
+          if (dist > BALL_DIST)
+              dist = BALL_DIST;
+      }
+      if (dist > hypot ((double) dx, (double) dy)) {
+          cx += dx;
+          cy += dy;
+      } else {
+          cx += dist * cosa;
+          cy += dist * sina;
+      }
+   }
+   ret.x =  cx;
+   ret.y = -cy;
+   return ret;
+}
+
+static void
+CreateEllipsePoints(const float& centerX, const float& centerY,
+                    const float& diam, const Transform& trans,
+                    int& nPoint, TPoint*& points)
+{
+    int n, i;
+    float hd, c, s, sx, sy, x, y, px, py;
+
+    const TRectangle tpos = {
+        centerX - diam * 0.5f,
+        centerY - diam * 0.5f,
+        diam, diam };
+    TRectangle pos;
+
+    Trectangle(&trans, &tpos, &pos);
+
+    pos.x = pos.x + pos.width  * 0.5;
+    pos.y = pos.y + pos.height * 0.5;
+
+    hd = hypot(pos.width, pos.height) * 0.5;
+    n = (M_PI / acos(hd / (hd + 1.0))) + 0.5;
+    if (n < 2) n = 2;
+
+    c = cos(M_PI / n);
+    s = sin(M_PI / n);
+    sx = -(pos.width  * s) / pos.height;
+    sy =  (pos.height * s) / pos.width;
+
+    n *= 2;
+    n += 2; // adds center point and first point
+    points = (TPoint*)malloc(sizeof(TPoint) * n);
+    if (!points)
+        return;
+
+    // add center point
+    points[0].x = pos.x;
+    points[0].y = pos.y;
+
+    x = 0;
+    y = pos.height * 0.5;
+    for (i = 1; i < n; ++i){
+        points[i].x = x + pos.x;
+        points[i].y = y + pos.y;
+        px = x;
+        py = y;
+        x = c * px + sx * py;
+        y = c * py + sy * px;
+    }
+
+    // add first point
+    points[n-1] = points[1];
+
+    nPoint = n;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+WLEye::WLEye()
+: m_nPoint(0)
+, m_eyeLiner(NULL)
+, m_nPupilPoint(0)
+, m_pupil(NULL)
+, m_nWhiteEyePoint(0)
+, m_whiteEye(NULL)
+{
+}
+
+WLEye::~WLEye()
+{
+    if (m_nPoint > 0 && m_eyeLiner){
+        free(m_eyeLiner);
+    }
+    if (m_nPupilPoint > 0 && m_pupil){
+        free(m_pupil);
+    }
+    if (m_nWhiteEyePoint > 0 && m_whiteEye){
+        free(m_whiteEye);
+    }
+}
+
+void
+WLEye::CreateEyeLiner(const float& centerX, const float& centerY,
+                      const float& diam, const Transform& trans)
+{
+    if (m_nPoint > 0 && m_eyeLiner){
+        free(m_eyeLiner);
+        m_nPoint = 0;
+    }
+    CreateEllipsePoints(centerX, centerY, diam, trans, m_nPoint, m_eyeLiner);
+
+    CreateWhiteEye(centerX, centerY, diam * 0.8, trans);
+}
+
+void
+WLEye::CreateWhiteEye(const float& centerX, const float& centerY,
+                      const float& diam, const Transform& trans)
+{
+    if (m_nWhiteEyePoint > 0 && m_whiteEye){
+        free(m_whiteEye);
+        m_nWhiteEyePoint = 0;
+    }
+    CreateEllipsePoints(centerX, centerY, diam, trans, m_nWhiteEyePoint, m_whiteEye);
+}
+
+void
+WLEye::CreatePupil(const float& centerX, const float& centerY,
+                   const float& diam, const Transform& trans)
+{
+    if (m_nPupilPoint > 0 && m_pupil){
+        free(m_pupil);
+        m_nPupilPoint = 0;
+    }
+    CreateEllipsePoints(centerX, centerY, diam, trans, m_nPupilPoint, m_pupil);
+}
+
+void
+WLEye::GetEyeLinerGeom(int* nPoint, float** points)
+{
+    *nPoint = m_nPoint;
+    *points = (float*)m_eyeLiner;
+}
+
+void
+WLEye::GetWhiteEyeGeom(int* nPoint, float** points)
+{
+    *nPoint = m_nWhiteEyePoint;
+    *points = (float*)m_whiteEye;
+}
+
+void
+WLEye::GetPupilGeom(int* nPoint, float** points)
+{
+    *nPoint = m_nPupilPoint;
+    *points = (float*)m_pupil;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+WLEyes::WLEyes(int screenWidth, int screenHeight)
+: m_width(screenWidth)
+, m_height(screenHeight)
+{
+    SetTransform(&m_trans, 0, m_width, m_height, 0,
+                 W_MIN_X, W_MAX_X, W_MIN_Y, W_MAX_Y);
+    m_eyes[0] = new WLEye;
+    m_eyes[0]->CreateEyeLiner(0.0, 0.0, EYE_DIAM + 2.0 * EYE_THICK, m_trans);
+
+    m_eyes[1] = new WLEye;
+    m_eyes[1]->CreateEyeLiner(2.0, 0.0, EYE_DIAM + 2.0 * EYE_THICK, m_trans);
+}
+
+WLEyes::~WLEyes()
+{
+    for (int i = 0; i < 2; ++i){
+        if (m_eyes[i]) delete m_eyes[i];
+    }
+}
+
+void
+WLEyes::SetPointOfView(int mousePosX, int mousePosY)
+{
+    TPoint mouse;
+    mouse.x = Tx(mousePosX, mousePosY, &m_trans);
+    mouse.y = Ty(mousePosX, mousePosY, &m_trans);
+
+    for (int i = 0; i < 2; ++i){
+        TPoint newPupil = ComputePupil(i, mouse, NULL);
+        m_eyes[i]->CreatePupil(newPupil.x, newPupil.y, BALL_DIAM, m_trans);
+    }
+}
+
+void
+WLEyes::GetEyeLinerGeom(int n, int* nPoint, float** points)
+{
+    *nPoint = 0;
+    *points = NULL;
+    if (n < 3){
+        m_eyes[n]->GetEyeLinerGeom(nPoint, points);
+    }
+}
+
+void
+WLEyes::GetWhiteEyeGeom(int n, int* nPoint, float** points)
+{
+    *nPoint = 0;
+    *points = NULL;
+    if (n < 3){
+        m_eyes[n]->GetWhiteEyeGeom(nPoint, points);
+    }
+}
+
+void
+WLEyes::GetPupilGeom(int n, int* nPoint, float** points)
+{
+    *nPoint = 0;
+    *points = NULL;
+    if (n < 3){
+        m_eyes[n]->GetPupilGeom(nPoint, points);
+    }
+}
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp
new file mode 100644 (file)
index 0000000..e21f347
--- /dev/null
@@ -0,0 +1,515 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+#include "WLEGLSurface.h"
+#include "WLEyes.h"
+#include "WLEyesRenderer.h"
+
+#define WL_UNUSED(A) (A)=(A)
+
+extern int gNeedRedraw;
+extern int gPointerX;
+extern int gPointerY;
+
+const struct wl_pointer_listener PointerListener = {
+    PointerHandleEnter,
+    PointerHandleLeave,
+    PointerHandleMotion,
+    PointerHandleButton,
+    PointerHandleAxis
+};
+
+const struct wl_keyboard_listener KeyboardListener = {
+    KeyboardHandleKeymap,
+    KeyboardHandleEnter,
+    KeyboardHandleLeave,
+    KeyboardHandleKey,
+    KeyboardHandleModifiers,
+};
+
+const struct wl_touch_listener TouchListener = {
+    TouchHandleDown,
+    TouchHandleUp,
+    TouchHandleMotion,
+    TouchHandleFrame,
+    TouchHandleCancel,
+};
+
+void WaitForEvent(struct wl_display* wlDisplay)
+{
+    wl_display_dispatch_pending(wlDisplay);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void
+PointerHandleEnter(void* data, struct wl_pointer* wlPointer, uint32_t serial,
+                   struct wl_surface* wlSurface, wl_fixed_t sx, wl_fixed_t sy)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(wlPointer);
+    WL_UNUSED(serial);
+    WL_UNUSED(wlSurface);
+    WL_UNUSED(sx);
+    WL_UNUSED(sy);
+    printf("ENTER EGLWLINPUT PointerHandleEnter: x(%d), y(%d)\n", sx, sy);
+}
+
+void
+PointerHandleLeave(void* data, struct wl_pointer* wlPointer, uint32_t serial,
+                   struct wl_surface* wlSurface)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(wlPointer);
+    WL_UNUSED(serial);
+    WL_UNUSED(wlSurface);
+    printf("ENTER EGLWLINPUT PointerHandleLeave: serial(%d)\n", serial);
+}
+
+void
+PointerHandleMotion(void* data, struct wl_pointer* wlPointer, uint32_t time,
+                    wl_fixed_t sx, wl_fixed_t sy)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(wlPointer);
+    WL_UNUSED(time);
+    gPointerX = (int)wl_fixed_to_double(sx);
+    gPointerY = (int)wl_fixed_to_double(sy);
+    printf("ENTER EGLWLINPUT PointerHandleMotion: x(%d), y(%d)\n", gPointerX, gPointerY);
+    gNeedRedraw = 1;
+}
+
+void
+PointerHandleButton(void* data, struct wl_pointer* wlPointer, uint32_t serial,
+                    uint32_t time, uint32_t button, uint32_t state)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(wlPointer);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(button);
+    WL_UNUSED(state);
+    printf("ENTER EGLWLINPUT PointerHandleButton: button(%d), state(%d)\n", button, state);
+}
+
+void
+PointerHandleAxis(void* data, struct wl_pointer* wlPointer, uint32_t time,
+                  uint32_t axis, wl_fixed_t value)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(wlPointer);
+    WL_UNUSED(time);
+    WL_UNUSED(axis);
+    WL_UNUSED(value);
+    printf("ENTER EGLWLINPUT PointerHandleAxis: axis(%d), value(%d)\n", axis, wl_fixed_to_int(value));
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void
+KeyboardHandleKeymap(void* data, struct wl_keyboard* keyboard,
+                     uint32_t format, int fd, uint32_t size)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(keyboard);
+    WL_UNUSED(format);
+    WL_UNUSED(fd);
+    WL_UNUSED(size);
+    printf("ENTER EGLWLINPUT KeyboardHandleKeymap: format(%d), fd(%d), size(%d)\n",
+        format, fd, size);
+}
+
+void
+KeyboardHandleEnter(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+                    struct wl_surface* surface, struct wl_array* keys)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(keyboard);
+    WL_UNUSED(serial);
+    WL_UNUSED(surface);
+    WL_UNUSED(keys);
+    printf("ENTER EGLWLINPUT KeyboardHandleEnter: serial(%d), surface(%p)\n",
+        serial, surface);
+}
+
+void
+KeyboardHandleLeave(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+                    struct wl_surface* surface)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(keyboard);
+    WL_UNUSED(serial);
+    WL_UNUSED(surface);
+    printf("ENTER EGLWLINPUT KeyboardHandleLeave: serial(%d), surface(%p)\n",
+        serial, surface);
+}
+
+void
+KeyboardHandleKey(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+                  uint32_t time, uint32_t key, uint32_t state_w)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(keyboard);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(key);
+    WL_UNUSED(state_w);
+    printf("ENTER EGLWLINPUT KeyboardHandleKey: serial(%d), time(%d), key(%d), state_w(%d)\n",
+        serial, time, key, state_w);
+}
+
+void
+KeyboardHandleModifiers(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+                        uint32_t mods_depressed, uint32_t mods_latched,
+                        uint32_t mods_locked, uint32_t group)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(keyboard);
+    WL_UNUSED(serial);
+    WL_UNUSED(mods_depressed);
+    WL_UNUSED(mods_latched);
+    WL_UNUSED(mods_locked);
+    WL_UNUSED(group);
+    printf("ENTER EGLWLINPUT KeyboardHandleModifiers: serial(%d), mods_depressed(%d)\n"
+          "                               mods_latched(%d), mods_locked(%d)\n"
+           "                               group(%d)\n",
+        serial, mods_depressed, mods_latched, mods_locked, group);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void
+TouchHandleDown(void* data, struct wl_touch* touch, uint32_t serial, uint32_t time,
+                struct wl_surface* surface, int32_t id, wl_fixed_t xw, wl_fixed_t yw)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(surface);
+    WL_UNUSED(id);
+    WL_UNUSED(xw);
+    WL_UNUSED(yw);
+    gPointerX = (int)wl_fixed_to_double(xw);
+    gPointerY = (int)wl_fixed_to_double(yw);
+    gNeedRedraw = 1;
+    printf("ENTER EGLWLINPUT TouchHandleDown id: %d, x: %d,y: %d \n",id,gPointerX,gPointerY);
+}
+
+void
+TouchHandleUp(void* data, struct wl_touch* touch, uint32_t serial, uint32_t time, int32_t id)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(serial);
+    WL_UNUSED(time);
+    WL_UNUSED(id);
+    printf("ENTER EGLWLINPUT TouchHandleUp\n");
+}
+
+void
+TouchHandleMotion(void* data, struct wl_touch* touch, uint32_t time, int32_t id,
+                  wl_fixed_t xw, wl_fixed_t yw)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+    WL_UNUSED(time);
+    WL_UNUSED(id);
+    WL_UNUSED(xw);
+    WL_UNUSED(yw);
+    gPointerX = (int)wl_fixed_to_double(xw);
+    gPointerY = (int)wl_fixed_to_double(yw);
+    printf("ENTER EGLWLINPUT TouchHandleMotion id: %d, x: %d,y: %d \n",id,gPointerX,gPointerY);
+    gNeedRedraw = 1;
+}
+
+void
+TouchHandleFrame(void* data, struct wl_touch* touch)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+}
+
+void
+TouchHandleCancel(void* data, struct wl_touch* touch)
+{
+    WL_UNUSED(data);
+    WL_UNUSED(touch);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+typedef struct _es2shaderobject {
+    GLuint fragmentShaderId;
+    GLuint vertexShaderId;
+    GLuint shaderProgramId;
+    GLint  matrixLocation;
+    GLint  colorLocation;
+} ES2ShaderObject;
+
+typedef struct _es2vertexbufferobject {
+    GLuint vbo;
+} ES2VertexBuffer;
+
+static ES2ShaderObject gShaderObject;
+static ES2VertexBuffer gVertexBuffer;
+
+// Fragment shader code
+const char* sourceFragShader = "  \
+    uniform mediump vec4 u_color; \
+    void main(void)               \
+    {                             \
+        gl_FragColor = u_color;   \
+    }";
+
+// Vertex shader code
+const char* sourceVertexShader = " \
+    attribute highp vec4 a_vertex; \
+    uniform mediump mat4 u_matrix; \
+    void main(void)                \
+    {                              \
+        gl_Position = u_matrix * a_vertex; \
+    }";
+
+//////////////////////////////////////////////////////////////////////////////
+
+bool
+InitRenderer()
+{
+    glViewport(0, 0, 400, 240);
+
+    if (!InitShader()){
+        return false;
+    }
+
+    if (!InitVertexBuffer()){
+        return false;
+    }
+
+    glClearColor(0.2, 0.2, 0.2, 1.0);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glEnable(GL_BLEND);
+    return true;
+}
+
+void
+TerminateRenderer()
+{
+    glDeleteProgram(gShaderObject.shaderProgramId);
+    glDeleteShader(gShaderObject.fragmentShaderId);
+    glDeleteShader(gShaderObject.vertexShaderId);
+
+    glDeleteBuffers(1, &gVertexBuffer.vbo);
+}
+
+char*
+BuildShaderErrorLog(GLuint id)
+{
+    int l, nChar;
+    glGetShaderiv(id, GL_INFO_LOG_LENGTH, &l);
+
+    char* info = (char*)malloc(sizeof(char) * l);
+    glGetShaderInfoLog(id, l, &nChar, info);
+
+    return info;
+}
+
+bool
+InitShader()
+{
+    GLint result = 0;
+    char* log = NULL;
+
+    // Create the fragment shader object
+    gShaderObject.fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
+    glShaderSource(gShaderObject.fragmentShaderId, 1,
+        (const char**)&sourceFragShader, NULL);
+    glCompileShader(gShaderObject.fragmentShaderId);
+
+    glGetShaderiv(gShaderObject.fragmentShaderId, GL_COMPILE_STATUS, &result);
+    if (!result){
+        log = BuildShaderErrorLog(gShaderObject.fragmentShaderId);
+        fprintf(stderr, "Failed to compile fragment shader: %s\n", log);
+        if (log) free(log);
+        return false;
+    }
+
+    // Create the vertex shader object
+    gShaderObject.vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
+    glShaderSource(gShaderObject.vertexShaderId, 1,
+        (const char**)&sourceVertexShader, NULL);
+    glCompileShader(gShaderObject.vertexShaderId);
+
+    glGetShaderiv(gShaderObject.vertexShaderId, GL_COMPILE_STATUS, &result);
+    if (!result){
+        log = BuildShaderErrorLog(gShaderObject.vertexShaderId);
+        fprintf(stderr, "Failed to compile fragment shader: %s\n", log);
+        if (log) free(log);
+        return false;
+    }
+
+    gShaderObject.shaderProgramId = glCreateProgram();
+
+    glAttachShader(gShaderObject.shaderProgramId, gShaderObject.fragmentShaderId);
+    glAttachShader(gShaderObject.shaderProgramId, gShaderObject.vertexShaderId);
+
+    glBindAttribLocation(gShaderObject.shaderProgramId, 0, "a_vertex");
+
+    glLinkProgram(gShaderObject.shaderProgramId);
+
+    glGetProgramiv(gShaderObject.shaderProgramId, GL_LINK_STATUS, &result);
+    if (!result){
+        log = BuildShaderErrorLog(gShaderObject.shaderProgramId);
+        fprintf(stderr, "Failed to compile fragment shader: %s\n", log);
+        if (log) free(log);
+        return false;
+    }
+
+    glUseProgram(gShaderObject.shaderProgramId);
+    gShaderObject.matrixLocation = glGetUniformLocation(
+        gShaderObject.shaderProgramId, "u_matrix");
+    gShaderObject.colorLocation = glGetUniformLocation(
+        gShaderObject.shaderProgramId, "u_color");
+
+    return true;
+}
+
+bool
+InitVertexBuffer()
+{
+    glGenBuffers(1, &gVertexBuffer.vbo);
+    glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer.vbo);
+
+    unsigned int uiSize = 100 * (sizeof(GLfloat) * 2);
+    glBufferData(GL_ARRAY_BUFFER, uiSize, NULL, GL_STATIC_DRAW);
+
+    return true;
+}
+
+void
+AttachVertexBuffer()
+{
+    glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer.vbo);
+    glEnableVertexAttribArray(0);
+    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
+}
+
+void
+DetachVertexBuffer()
+{
+    glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+static void FrameListenerFunc(void*, struct wl_callback* cb, uint32_t)
+{
+    if (cb){
+        wl_callback_destroy(cb);
+    }
+}
+
+static const struct wl_callback_listener FrameListener = {
+    FrameListenerFunc,
+};
+
+void
+DrawFillPoly(const int nPoint, const float* points, const float color[4])
+{
+    glUniform4fv(gShaderObject.colorLocation, 1, color);
+
+    unsigned int uiSize = nPoint * (sizeof(GLfloat) * 2);
+    glBufferSubData(GL_ARRAY_BUFFER, 0, uiSize, points);
+
+    glDrawArrays(GL_TRIANGLE_FAN, 0, nPoint);
+}
+
+void
+DrawPoly(const int nPoint, const float* points, const float color[4], int width)
+{
+    glLineWidth(width);
+
+    glUniform4fv(gShaderObject.colorLocation, 1, color);
+
+    unsigned int uiSize = nPoint * (sizeof(GLfloat) * 2);
+    glBufferSubData(GL_ARRAY_BUFFER, 0, uiSize, points);
+
+    glDrawArrays(GL_LINE_STRIP, 0, nPoint);
+}
+
+bool
+DrawEyes(WLEGLSurface* surface, WLEyes* eyes)
+{
+    glClear(GL_COLOR_BUFFER_BIT);
+    glUseProgram(gShaderObject.shaderProgramId);
+
+    AttachVertexBuffer();
+    {
+        float a = 2.0 / 400.0;
+        float b = 2.0 / 240.0;
+        float mtx[16] = {   a,  0.0, 0.0, 0.0,
+                          0.0,    b, 0.0, 0.0,
+                          0.0,  0.0, 1.0, 0.0,
+                         -1.0, -1.0, 0.0, 1.0};
+
+        glUniformMatrix4fv(gShaderObject.matrixLocation, 1, GL_FALSE, mtx);
+
+        eyes->SetPointOfView(gPointerX, gPointerY);
+
+        float black[] = {0.0, 0.0, 0.0, 1.0};
+        float white[] = {1.0, 1.0, 1.0, 1.0};
+        int nPoint = 0;
+        float* points = NULL;
+        for (int ii = 0; ii < 2; ++ii){
+            // eye liner
+            eyes->GetEyeLinerGeom(ii, &nPoint, &points);
+            if (nPoint <= 0 || points == NULL){
+                continue;
+            }
+            DrawFillPoly(nPoint, points, black);
+
+            // eye shape (white eye)
+            eyes->GetWhiteEyeGeom(ii, &nPoint, &points);
+            if (nPoint <= 0 || points == NULL){
+                continue;
+            }
+            DrawFillPoly(nPoint, points, white);
+
+            // pupil
+            eyes->GetPupilGeom(ii, &nPoint, &points);
+            if (nPoint <= 0 || points == NULL){
+                continue;
+            }
+            DrawFillPoly(nPoint, points, black);
+            /*same array is used for both eyes, execute finish for each eye*/
+            glFinish();
+        }
+    }
+    DetachVertexBuffer();
+    eglSwapBuffers(surface->GetEGLDisplay(), surface->GetEGLSurface());
+
+    struct wl_callback* cb = wl_surface_frame(surface->GetWLSurface());
+    wl_callback_add_listener(cb, &FrameListener, NULL);
+    wl_surface_commit(surface->GetWLSurface());
+    wl_display_flush(surface->GetWLDisplay());
+
+    return true;
+}
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLSurface.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLSurface.cpp
new file mode 100644 (file)
index 0000000..1961777
--- /dev/null
@@ -0,0 +1,114 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "WLSurface.h"
+#include "ilm_control.h"
+
+WLSurface::WLSurface(WLContext* wlContext)
+: m_wlContext(wlContext)
+, m_wlSurface(NULL)
+, m_width(0)
+, m_height(0)
+, m_ilmSurfaceId(0)
+{
+    assert(wlContext);
+}
+
+WLSurface::~WLSurface()
+{
+    if (m_ilmSurfaceId > 0)
+        ilm_surfaceRemove(m_ilmSurfaceId);
+
+    if (m_wlSurface)
+        wl_surface_destroy(m_wlSurface);
+}
+
+bool
+WLSurface::CreateSurface(const int width, const int height)
+{
+    m_width  = width;
+    m_height = height;
+
+    m_wlSurface = (struct wl_surface*)
+        wl_compositor_create_surface(m_wlContext->GetWLCompositor());
+    if (!m_wlSurface){
+        return false;
+    }
+
+    return CreatePlatformSurface();
+}
+
+bool
+WLSurface::CreatePlatformSurface()
+{
+    return true;
+}
+
+bool
+WLSurface::CreateIlmSurface(t_ilm_surface* surfaceId,
+                            t_ilm_int width,
+                            t_ilm_int height)
+{
+    ilmErrorTypes rtnv;
+
+    // Creates surfce
+    rtnv = ilm_surfaceCreate((t_ilm_nativehandle)m_wlSurface,
+                             width, height,
+                             ILM_PIXELFORMAT_RGBA_8888, surfaceId);
+    if (rtnv != ILM_SUCCESS){
+        return false;
+    }
+
+    rtnv = ilm_surfaceSetDestinationRectangle(*surfaceId, 0, 0, width, height);
+    rtnv = ilm_surfaceSetSourceRectangle(*surfaceId, 0, 0, width, height);
+    rtnv = ilm_surfaceSetVisibility(*surfaceId, ILM_TRUE);
+    rtnv = ilm_surfaceSetOpacity(*surfaceId, 1.0f);
+
+    rtnv = ilm_UpdateInputEventAcceptanceOn(*surfaceId,
+                                            ILM_INPUT_DEVICE_POINTER |
+                                            ILM_INPUT_DEVICE_TOUCH |
+                                            ILM_INPUT_DEVICE_KEYBOARD,
+                                            ILM_TRUE);
+    rtnv = ilm_SetKeyboardFocusOn(*surfaceId);
+
+    rtnv = ilm_commitChanges();
+
+    m_ilmSurfaceId = *surfaceId;
+
+    return true;
+}
+
+void
+WLSurface::DestroyIlmSurface()
+{
+    if (m_ilmSurfaceId > 0){
+        ilm_UpdateInputEventAcceptanceOn(m_ilmSurfaceId,
+                                         ILM_INPUT_DEVICE_POINTER |
+                                         ILM_INPUT_DEVICE_TOUCH |
+                                         ILM_INPUT_DEVICE_KEYBOARD,
+                                         ILM_FALSE);
+        ilm_SetKeyboardFocusOn(m_ilmSurfaceId);
+        ilm_commitChanges();
+        ilm_surfaceRemove(m_ilmSurfaceId);
+    }
+}
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WaylandServerinfoProtocol.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WaylandServerinfoProtocol.cpp
new file mode 100644 (file)
index 0000000..13abeb4
--- /dev/null
@@ -0,0 +1,51 @@
+/***************************************************************************
+*
+* 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"
+
+#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
+
+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,
+};
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp
new file mode 100644 (file)
index 0000000..6584c42
--- /dev/null
@@ -0,0 +1,102 @@
+/**************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include "WLContext.h"
+#include "WLEGLSurface.h"
+#include "WLEyes.h"
+#include "WLEyesRenderer.h"
+
+int gRunLoop = 0;
+int gNeedRedraw = 0;
+int gPointerX = 0;
+int gPointerY = 0;
+
+
+static void SigFunc(int)
+{
+    printf("Caught signal\n");
+    gRunLoop = 0;
+}
+
+int main(int argc, char **argv)
+{
+    WLContext* wlContext;
+    WLEGLSurface* eglSurface;
+    WLEyes* eyes;
+    t_ilm_surface surfaceId = 5100;
+
+    argc = argc; // avoid warning
+    argv = argv;
+
+    // signal handling
+    signal(SIGINT,SigFunc);
+
+    wlContext = new WLContext();
+    wlContext->InitWLContext(&PointerListener, &KeyboardListener, &TouchListener);
+
+    ilm_initWithNativedisplay((t_ilm_nativedisplay)wlContext->GetWLDisplay());
+
+    eglSurface = new WLEGLSurface(wlContext);
+    eglSurface->CreateSurface(400, 240);
+    eglSurface->CreateIlmSurface(&surfaceId, 400, 240);
+
+    eyes = new WLEyes(400, 240);
+
+    // initialize eyes renderer
+    if (!InitRenderer()){
+        fprintf(stderr, "Failed to init renderer\n");
+        return -1;
+    }
+
+    // draw eyes once
+    DrawEyes(eglSurface, eyes);
+
+    // wait for input event
+    gRunLoop = 1;
+    gNeedRedraw = 0;
+    while (gRunLoop){
+        WaitForEvent(wlContext->GetWLDisplay());
+        if (gNeedRedraw && gRunLoop){
+            DrawEyes(eglSurface, eyes);
+            gNeedRedraw = 0;
+        }
+        usleep(50);
+    }
+
+    TerminateRenderer();
+    ilm_surfaceRemove(surfaceId);
+    ilm_UpdateInputEventAcceptanceOn(surfaceId,
+                                    ILM_INPUT_DEVICE_POINTER | ILM_INPUT_DEVICE_TOUCH,
+                                    ILM_FALSE);
+    ilm_commitChanges();
+    eglSurface->DestroyIlmSurface();
+    ilm_commitChanges();
+
+    ilm_destroy();
+    delete eyes;
+    delete eglSurface;
+    delete wlContext;
+
+    return 0;
+}