7b73518c3a9333b3abdc3036e22fbf1febbb3bf7
[profile/ivi/layer-management.git] / LayerManagerExamples / EGLWLMockNavigation / include / OpenGLES2App.h
1 /***************************************************************************
2  *
3  * Copyright 2010, 2011 BMW Car IT GmbH 
4  * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #ifndef _OpenGLES2App_h
21 #define _OpenGLES2App_h
22
23 #include "wayland-client.h"
24 #include "wayland-egl.h"
25 #include <GLES2/gl2.h>
26
27 #include "ilm_client.h"
28 #include <EGL/egl.h>
29
30 struct SurfaceConfiguration
31 {
32     unsigned int layerId;
33     unsigned int surfaceId;
34     unsigned int surfaceWidth;
35     unsigned int surfaceHeight;
36     unsigned int surfacePosX;
37     unsigned int surfacePosY;
38     float opacity;
39     bool nosky;
40 };
41
42 class OpenGLES2App
43 {
44 public:
45     OpenGLES2App(float fps, float animationSpeed, SurfaceConfiguration* config);
46     virtual ~OpenGLES2App();
47
48     void mainloop();
49
50     static void serverinfoListener( void *data, struct serverinfo *pServerinfo, uint32_t client_handle );
51     static void display_handle_global(struct wl_display* display, uint32_t id, const char* interface, uint32_t version, void* data);
52     static int event_mask_update(uint32_t mask, void* data);
53     static void frame_listener_func(void *data, struct wl_callback *callback, uint32_t time);
54
55 protected:
56     virtual void update(int currentTimeInMs, int elapsedTimeInMs) = 0;
57     virtual void render() = 0;
58     void swapBuffers();
59
60 private:
61     bool createWLContext(SurfaceConfiguration* config);
62     void destroyWLContext();
63
64     bool createEGLContext();
65     void destroyEglContext();
66
67     bool setupLayerMangement(SurfaceConfiguration* config);
68
69     unsigned int GetTickCount();
70
71 protected:
72     float m_framesPerSecond;
73     float m_animationSpeed;
74     unsigned int m_timerIntervalInMs;
75
76     struct EglContextStruct
77     {
78         EGLNativeDisplayType nativeDisplay;
79         EGLNativeWindowType  nativeWindow;
80         EGLDisplay eglDisplay;
81         EGLConfig eglConfig;
82         EGLSurface eglSurface;
83         EGLContext eglContext;
84     };
85
86     EglContextStruct m_eglContextStruct;
87
88     typedef struct t_wlContextStruct
89     {
90         struct wl_display* wlDisplay;
91         struct wl_compositor* wlCompositor;
92         struct wl_egl_window* wlNativeWindow;
93         struct wl_surface* wlSurface;
94         int width;
95         int height;
96
97         uint32_t mask;
98
99         struct serverinfo* wlExtServerinfo;
100         uint32_t connect_id;
101     } WLContextStruct;
102     WLContextStruct m_wlContextStruct;
103 };
104
105 #endif