Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: runtime/embedders/openglui/emulator/emulator_embedder.cc

Issue 12340036: Android improvements: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "embedders/openglui/emulator/emulator_embedder.h" 5 #include "embedders/openglui/emulator/emulator_embedder.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #include "embedders/openglui/common/canvas_context.h" 9 #include "embedders/openglui/common/canvas_context.h"
10 #include "embedders/openglui/common/context.h" 10 #include "embedders/openglui/common/context.h"
11 #include "embedders/openglui/common/dart_host.h" 11 #include "embedders/openglui/common/dart_host.h"
12 #include "embedders/openglui/common/events.h" 12 #include "embedders/openglui/common/events.h"
13 #include "embedders/openglui/common/input_handler.h" 13 #include "embedders/openglui/common/input_handler.h"
14 #include "embedders/openglui/common/log.h"
14 #include "embedders/openglui/common/sound_handler.h" 15 #include "embedders/openglui/common/sound_handler.h"
15 #include "embedders/openglui/common/vm_glue.h" 16 #include "embedders/openglui/common/vm_glue.h"
16 #include "embedders/openglui/emulator/emulator_graphics_handler.h" 17 #include "embedders/openglui/emulator/emulator_graphics_handler.h"
17 18
18 InputHandler* input_handler_ptr; 19 InputHandler* input_handler_ptr;
19 LifeCycleHandler* lifecycle_handler_ptr; 20 LifeCycleHandler* lifecycle_handler_ptr;
20 21
21 struct timeval tvStart; 22 struct timeval tvStart;
22 void tick(int data); 23 void tick(int data);
23 24
(...skipping 24 matching lines...) Expand all
48 glLoadIdentity(); 49 glLoadIdentity();
49 glOrtho(0, width, 0, height, -1, 1); 50 glOrtho(0, width, 0, height, -1, 1);
50 glMatrixMode(GL_MODELVIEW); 51 glMatrixMode(GL_MODELVIEW);
51 glutPostRedisplay(); 52 glutPostRedisplay();
52 } 53 }
53 54
54 void keyboard(unsigned char key, int x, int y) { 55 void keyboard(unsigned char key, int x, int y) {
55 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), 0, key, 0, 0); 56 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), 0, key, 0, 0);
56 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), 0, key, 0, 0); 57 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), 0, key, 0, 0);
57 if (key == 27) { 58 if (key == 27) {
59 lifecycle_handler_ptr->Pause();
60 lifecycle_handler_ptr->Deactivate();
61 lifecycle_handler_ptr->FreeAllResources();
58 exit(0); 62 exit(0);
63 } else if (key == '0') {
64 LOGI("Simulating suspend");
65 lifecycle_handler_ptr->Pause();
66 lifecycle_handler_ptr->Deactivate();
67 } else if (key == '1') {
68 LOGI("Simulating resume");
69 lifecycle_handler_ptr->Activate();
70 lifecycle_handler_ptr->Resume();
71 } else if (key == '+') {
72 LOGI("Simulating focus gain");
73 lifecycle_handler_ptr->Resume();
74 } else if (key == '-') {
75 LOGI("Simulating focus loss");
76 lifecycle_handler_ptr->Pause();
59 } 77 }
60 } 78 }
61 79
62 DART_EXPORT void emulator_main(int argc, char** argv, const char* script) { 80 DART_EXPORT void emulator_main(int argc, char** argv, const char* script) {
63 EmulatorGraphicsHandler graphics_handler(argc, argv); 81 EmulatorGraphicsHandler graphics_handler(argc, argv);
64 if (argc > 0) { 82 if (argc > 0) {
65 int i = argc - 1; 83 int i = argc - 1;
66 size_t len = strlen(argv[i]); 84 size_t len = strlen(argv[i]);
67 if (len > 5 && strcmp(".dart", argv[i] + len - 5) == 0) { 85 if (len > 5 && strcmp(".dart", argv[i] + len - 5) == 0) {
68 script = argv[i]; 86 script = argv[i];
69 } 87 }
70 } 88 }
71 VMGlue vm_glue(&graphics_handler, ".", "gl.dart", script); 89 VMGlue vm_glue(&graphics_handler, ".", "gl.dart", script);
72 InputHandler input_handler(&vm_glue); 90 InputHandler input_handler(&vm_glue);
73 input_handler_ptr = &input_handler; 91 input_handler_ptr = &input_handler;
74 SoundHandler sound_handler; 92 SoundHandler sound_handler;
75 Timer timer; 93 Timer timer;
76 Context app_context; 94 Context app_context;
77 app_context.graphics_handler = &graphics_handler; 95 app_context.graphics_handler = &graphics_handler;
78 app_context.input_handler = &input_handler; 96 app_context.input_handler = &input_handler;
79 app_context.sound_handler = &sound_handler; 97 app_context.sound_handler = &sound_handler;
80 app_context.timer = &timer; 98 app_context.timer = &timer;
81 app_context.vm_glue = &vm_glue; 99 app_context.vm_glue = &vm_glue;
82 DartHost host(&app_context); 100 DartHost host(&app_context);
83 lifecycle_handler_ptr = &host; 101 lifecycle_handler_ptr = &host;
84 glutReshapeFunc(reshape); 102 glutReshapeFunc(reshape);
85 glutDisplayFunc(display); 103 glutDisplayFunc(display);
86 glutKeyboardFunc(keyboard); 104 glutKeyboardFunc(keyboard);
87 lifecycle_handler_ptr->OnActivate(); 105 lifecycle_handler_ptr->OnStart();
106 lifecycle_handler_ptr->Activate();
107 lifecycle_handler_ptr->Resume();
88 gettimeofday(&tvStart, NULL); 108 gettimeofday(&tvStart, NULL);
89 glutTimerFunc(1, tick, 0); 109 glutTimerFunc(1, tick, 0);
90 glutMainLoop(); 110 glutMainLoop();
91 } 111 }
92 112
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/common/vm_glue.cc ('k') | runtime/embedders/openglui/emulator/emulator_graphics_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698