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

Side by Side Diff: runtime/embedders/openglui/common/dart_host.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/common/dart_host.h" 5 #include "embedders/openglui/common/dart_host.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "embedders/openglui/common/log.h" 10 #include "embedders/openglui/common/log.h"
11 11
12 DartHost::DartHost(Context *context) 12 DartHost::DartHost(Context *context)
13 : graphics_handler_(context->graphics_handler), 13 : graphics_handler_(context->graphics_handler),
14 input_handler_(context->input_handler), 14 input_handler_(context->input_handler),
15 sound_handler_(context->sound_handler), 15 sound_handler_(context->sound_handler),
16 timer_(context->timer), 16 timer_(context->timer),
17 vm_glue_(context->vm_glue), 17 vm_glue_(context->vm_glue),
18 has_context_(false),
19 started_(false),
18 active_(false) { 20 active_(false) {
19 LOGI("Creating DartHost");
20 } 21 }
21 22
22 DartHost::~DartHost() { 23 DartHost::~DartHost() {
23 LOGI("Freeing DartHost");
24 } 24 }
25 25
26 int32_t DartHost::OnActivate() { 26 int32_t DartHost::OnStart() {
27 return Activate(); 27 int result = vm_glue_->StartMainIsolate();
28 if (result != 0) {
29 LOGE("startMainIsolate returned %d", result);
30 return -1;
31 }
32 started_ = true;
33 return 0;
28 } 34 }
29 35
30 int32_t DartHost::Activate() { 36 int32_t DartHost::Activate() {
31 if (!active_) { 37 if (!has_context_) {
32 LOGI("Activating DartHost");
33 if (graphics_handler_->Start() != 0) { 38 if (graphics_handler_->Start() != 0) {
34 return -1; 39 return -1;
35 } 40 }
36 if (sound_handler_->Start() != 0) { 41 if (sound_handler_->Start() != 0) {
42 graphics_handler_->Stop();
37 return -1; 43 return -1;
38 } 44 }
39 if (input_handler_->Start() != 0) { 45 if (input_handler_->Start() != 0) {
46 sound_handler_->Stop();
47 graphics_handler_->Stop();
40 return -1; 48 return -1;
41 } 49 }
50 int32_t rtn = vm_glue_->CallSetup(true);
42 timer_->Reset(); 51 timer_->Reset();
43 LOGI("Starting main isolate"); 52 has_context_ = true;
44 int result = vm_glue_->StartMainIsolate(); 53 return rtn;
45 if (result != 0) {
46 LOGE("startMainIsolate returned %d", result);
47 return -1;
48 }
49 active_ = true;
50 return vm_glue_->CallSetup();
51 } 54 }
52 return 0; 55 return 0;
53 } 56 }
54 57
55 void DartHost::OnDeactivate() {
56 Deactivate();
57 }
58
59 void DartHost::Deactivate() { 58 void DartHost::Deactivate() {
60 if (active_) { 59 Pause();
61 active_ = false; 60 if (has_context_) {
62 vm_glue_->FinishMainIsolate(); 61 vm_glue_->CallShutdown();
63 LOGI("Deactivating DartHost");
64 input_handler_->Stop(); 62 input_handler_->Stop();
65 sound_handler_->Stop(); 63 sound_handler_->Stop();
66 graphics_handler_->Stop(); 64 graphics_handler_->Stop();
65 has_context_ = false;
67 } 66 }
68 } 67 }
69 68
70 int32_t DartHost::OnStep() { 69 int32_t DartHost::OnStep() {
71 timer_->Update(); 70 if (active_) {
72 if (vm_glue_->CallUpdate() != 0 || 71 timer_->Update();
73 graphics_handler_->Update() != 0) { 72 if (vm_glue_->CallUpdate() != 0 ||
74 return -1; 73 graphics_handler_->Update() != 0) {
74 return -1;
75 }
75 } 76 }
76 return 0; 77 return 0;
77 } 78 }
78 79
79 void DartHost::OnStart() { 80 int32_t DartHost::Resume() {
80 LOGI("Starting DartHost"); 81 if (!active_) {
82 if (Activate() == 0) {
83 sound_handler_->Resume();
84 active_ = true;
85 }
86 }
87 return 0;
81 } 88 }
82 89
83 void DartHost::OnResume() { 90 void DartHost::Pause() {
84 LOGI("Resuming DartHost"); 91 if (active_) {
92 active_ = false; // This stops update() calls.
93 sound_handler_->Suspend();
94 }
85 } 95 }
86 96
87 void DartHost::OnPause() { 97 void DartHost::FreeAllResources() {
88 LOGI("Pausing DartHost"); 98 if (started_) {
89 } 99 vm_glue_->FinishMainIsolate();
90 100 started_ = false;
91 void DartHost::OnStop() { 101 }
92 LOGI("Stopping DartHost");
93 }
94
95 void DartHost::OnDestroy() {
96 LOGI("Destroying DartHost");
97 } 102 }
98 103
99 void DartHost::OnSaveState(void** data, size_t* size) { 104 void DartHost::OnSaveState(void** data, size_t* size) {
100 LOGI("Saving DartHost state"); 105 LOGI("Saving DartHost state");
101 } 106 }
102 107
103 void DartHost::OnConfigurationChanged() { 108 void DartHost::OnConfigurationChanged() {
104 LOGI("DartHost config changed"); 109 LOGI("DartHost config changed");
105 } 110 }
106 111
107 void DartHost::OnLowMemory() { 112 void DartHost::OnLowMemory() {
108 LOGI("DartHost low on memory"); 113 LOGI("DartHost low on memory");
109 } 114 }
110 115
111 void DartHost::OnCreateWindow() {
112 LOGI("DartHost creating window");
113 }
114
115 void DartHost::OnDestroyWindow() {
116 LOGI("DartHost destroying window");
117 }
118
119 void DartHost::OnGainedFocus() {
120 LOGI("DartHost gained focus");
121 }
122
123 void DartHost::OnLostFocus() {
124 LOGI("DartHost lost focus");
125 }
126
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/common/dart_host.h ('k') | runtime/embedders/openglui/common/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698