• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <signal.h>
24 #include <unistd.h>
25 #include <getopt.h>
26 #include "WLContext.h"
27 #include "WLEGLSurface.h"
28 #include "WLEyes.h"
29 #include "WLEyesRenderer.h"
30 
31 int gRunLoop = 0;
32 int gNeedRedraw = 0;
33 int gPointerX = 0;
34 int gPointerY = 0;
35 
36 
SigFunc(int)37 static void SigFunc(int)
38 {
39     printf("Caught signal\n");
40     gRunLoop = 0;
41 }
42 
main(int argc,char ** argv)43 int main(int argc, char **argv)
44 {
45     WLContext* wlContext;
46     WLEGLSurface* eglSurface;
47     WLEyes* eyes;
48     int surfaceId = 5100;
49     int ret = -1;
50 
51     argc = argc; // avoid warning
52     argv = argv;
53 
54 
55     // Get command-line options
56     while (true){
57         int c;
58         static struct option opts[] = {
59             {"surface", required_argument, NULL, 's'},
60             {0, 0, 0, 0}
61         };
62 
63         c = getopt_long(argc, argv, "s:", opts, NULL);
64 
65         if (c == -1)
66             break;
67 
68         switch(c){
69         case 's':
70             surfaceId = strtol(optarg, NULL, 0);
71             break;
72         default:
73             fprintf(stderr, "Unrecognized option '%s'\n", optarg);
74         }
75     }
76 
77     // signal handling
78     signal(SIGINT,SigFunc);
79 
80     wlContext = new WLContext();
81     wlContext->InitWLContext(&PointerListener, &KeyboardListener, &TouchListener);
82 
83     int const fd = wl_display_get_fd(wlContext->GetWLDisplay());
84 
85     eglSurface = new WLEGLSurface(wlContext);
86     eglSurface->CreateSurface(400, 240, surfaceId);
87 
88     eyes = new WLEyes(400, 240);
89 
90     // initialize eyes renderer
91     if (!InitRenderer()){
92         fprintf(stderr, "Failed to init renderer\n");
93         goto Error;
94     }
95 
96     // draw eyes once
97     DrawEyes(eglSurface, eyes);
98 
99     // wait for input event
100     gRunLoop = 1;
101     gNeedRedraw = 0;
102     while (gRunLoop){
103         if ((WaitForEvent(wlContext->GetWLDisplay(), fd) < 0)){
104             gRunLoop = 0;
105         }
106 
107         if (gNeedRedraw && gRunLoop){
108             DrawEyes(eglSurface, eyes);
109             gNeedRedraw = 0;
110         }
111     }
112 
113     TerminateRenderer();
114     ret = 0;
115 
116 Error:
117     delete eyes;
118     delete eglSurface;
119     delete wlContext;
120 
121     return ret;
122 }
123