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

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

Issue 13042015: Various OpenGLUI changes: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 <time.h>
9 #include "embedders/openglui/common/canvas_context.h" 10 #include "embedders/openglui/common/canvas_context.h"
10 #include "embedders/openglui/common/context.h" 11 #include "embedders/openglui/common/context.h"
11 #include "embedders/openglui/common/dart_host.h" 12 #include "embedders/openglui/common/dart_host.h"
12 #include "embedders/openglui/common/events.h" 13 #include "embedders/openglui/common/events.h"
13 #include "embedders/openglui/common/input_handler.h" 14 #include "embedders/openglui/common/input_handler.h"
14 #include "embedders/openglui/common/log.h" 15 #include "embedders/openglui/common/log.h"
15 #include "embedders/openglui/common/sound_handler.h" 16 #include "embedders/openglui/common/sound_handler.h"
16 #include "embedders/openglui/common/vm_glue.h" 17 #include "embedders/openglui/common/vm_glue.h"
17 #include "embedders/openglui/emulator/emulator_graphics_handler.h" 18 #include "embedders/openglui/emulator/emulator_graphics_handler.h"
19 #include "embedders/openglui/emulator/emulator_resource.h"
18 20
19 InputHandler* input_handler_ptr; 21 InputHandler* input_handler_ptr;
20 LifeCycleHandler* lifecycle_handler_ptr; 22 LifeCycleHandler* lifecycle_handler_ptr;
21 23
22 struct timeval tvStart; 24 struct timeval tvStart;
23 void tick(int data); 25 void tick(int data);
24 26
27 Resource* MakePlatformResource(const char *path) {
28 return new EmulatorResource(path);
29 }
30
25 void display() { 31 void display() {
26 // Get number of msecs since last call. 32 // Get number of msecs since last call.
27 struct timeval tvEnd; 33 struct timeval tvEnd;
28 gettimeofday(&tvEnd, NULL); 34 gettimeofday(&tvEnd, NULL);
29 uint64_t elapsed = (tvEnd.tv_usec + 1000000 * tvEnd.tv_sec) - 35 uint64_t now = (tvEnd.tv_usec + 1000000 * tvEnd.tv_sec)
30 (tvStart.tv_usec + 1000000 * tvStart.tv_sec);
31 36
32 if (lifecycle_handler_ptr->OnStep() != 0) { 37 if (lifecycle_handler_ptr->OnStep() != 0) {
33 exit(-1); 38 exit(-1);
34 } 39 }
35 // Schedule next call, trying to aim for 60fps. 40 // Schedule next call, trying to aim for 60fps.
41 uint64_t elapsed = now - (tvStart.tv_usec + 1000000 * tvStart.tv_sec);
36 int delay = 1000 / 60 - (elapsed / 1000); 42 int delay = 1000 / 60 - (elapsed / 1000);
37 if (delay < 0) delay = 0; 43 if (delay < 0) delay = 0;
38 tvStart = tvEnd; 44 tvStart = tvEnd;
39 glutTimerFunc(delay, tick, 0); 45 glutTimerFunc(delay, tick, 0);
40 } 46 }
41 47
42 void tick(int data) { 48 void tick(int data) {
43 display(); 49 display();
44 } 50 }
45 51
46 void reshape(int width, int height) { 52 void reshape(int width, int height) {
47 glViewport(0, 0, width, height); 53 glViewport(0, 0, width, height);
48 glMatrixMode(GL_PROJECTION); 54 glMatrixMode(GL_PROJECTION);
49 glLoadIdentity(); 55 glLoadIdentity();
50 glOrtho(0, width, 0, height, -1, 1); 56 glOrtho(0, width, 0, height, -1, 1);
51 glMatrixMode(GL_MODELVIEW); 57 glMatrixMode(GL_MODELVIEW);
52 glutPostRedisplay(); 58 glutPostRedisplay();
53 } 59 }
54 60
55 void keyboard(unsigned char key, int x, int y) { 61 void keyboard(unsigned char key, int x, int y) {
56 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), key, false, false, false, 0); 62 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), key, false, false, false, 0);
57 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), key, false, false, false, 0); 63 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), key, false, false, false, 0);
58 if (key == 27) { 64 if (key == 'Q') {
59 lifecycle_handler_ptr->Pause(); 65 lifecycle_handler_ptr->Pause();
60 lifecycle_handler_ptr->Deactivate(); 66 lifecycle_handler_ptr->Deactivate();
61 lifecycle_handler_ptr->FreeAllResources(); 67 lifecycle_handler_ptr->FreeAllResources();
62 exit(0); 68 exit(0);
63 } else if (key == '0') { 69 } else if (key == 'S') {
64 LOGI("Simulating suspend"); 70 LOGI("Simulating suspend");
65 lifecycle_handler_ptr->Pause(); 71 lifecycle_handler_ptr->Pause();
66 lifecycle_handler_ptr->Deactivate(); 72 lifecycle_handler_ptr->Deactivate();
67 } else if (key == '1') { 73 } else if (key == 'R') {
68 LOGI("Simulating resume"); 74 LOGI("Simulating resume");
69 lifecycle_handler_ptr->Activate(); 75 lifecycle_handler_ptr->Activate();
70 lifecycle_handler_ptr->Resume(); 76 lifecycle_handler_ptr->Resume();
71 } else if (key == '+') { 77 } else if (key == '+') {
72 LOGI("Simulating focus gain"); 78 LOGI("Simulating focus gain");
73 lifecycle_handler_ptr->Resume(); 79 lifecycle_handler_ptr->Resume();
74 } else if (key == '-') { 80 } else if (key == '-') {
75 LOGI("Simulating focus loss"); 81 LOGI("Simulating focus loss");
76 lifecycle_handler_ptr->Pause(); 82 lifecycle_handler_ptr->Pause();
77 } 83 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 glutMouseFunc(mouse); 123 glutMouseFunc(mouse);
118 glutMotionFunc(motion); 124 glutMotionFunc(motion);
119 lifecycle_handler_ptr->OnStart(); 125 lifecycle_handler_ptr->OnStart();
120 lifecycle_handler_ptr->Activate(); 126 lifecycle_handler_ptr->Activate();
121 lifecycle_handler_ptr->Resume(); 127 lifecycle_handler_ptr->Resume();
122 gettimeofday(&tvStart, NULL); 128 gettimeofday(&tvStart, NULL);
123 glutTimerFunc(1, tick, 0); 129 glutTimerFunc(1, tick, 0);
124 glutMainLoop(); 130 glutMainLoop();
125 } 131 }
126 132
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698