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

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 if (has_context_) {
61 active_ = false; 60 vm_glue_->CallShutdown();
62 vm_glue_->FinishMainIsolate();
63 LOGI("Deactivating DartHost");
64 input_handler_->Stop(); 61 input_handler_->Stop();
65 sound_handler_->Stop(); 62 sound_handler_->Stop();
66 graphics_handler_->Stop(); 63 graphics_handler_->Stop();
64 has_context_ = false;
67 } 65 }
68 } 66 }
69 67
70 int32_t DartHost::OnStep() { 68 int32_t DartHost::OnStep() {
71 timer_->Update(); 69 if (active_) {
72 if (vm_glue_->CallUpdate() != 0 || 70 timer_->Update();
73 graphics_handler_->Update() != 0) { 71 if (vm_glue_->CallUpdate() != 0 ||
74 return -1; 72 graphics_handler_->Update() != 0) {
73 return -1;
74 }
75 } 75 }
76 return 0; 76 return 0;
77 } 77 }
78 78
79 void DartHost::OnStart() { 79 int32_t DartHost::Resume() {
80 LOGI("Starting DartHost"); 80 if (!active_) {
81 sound_handler_->Resume();
82 active_ = true;
83 }
84 return 0;
81 } 85 }
82 86
83 void DartHost::OnResume() { 87 void DartHost::Pause() {
84 LOGI("Resuming DartHost"); 88 if (active_) {
89 active_ = false; // This stops update() calls.
90 sound_handler_->Suspend();
91 }
85 } 92 }
86 93
87 void DartHost::OnPause() { 94 void DartHost::FreeAllResources() {
88 LOGI("Pausing DartHost"); 95 if (started_) {
89 } 96 vm_glue_->FinishMainIsolate();
90 97 started_ = false;
91 void DartHost::OnStop() { 98 }
92 LOGI("Stopping DartHost");
93 }
94
95 void DartHost::OnDestroy() {
96 LOGI("Destroying DartHost");
97 } 99 }
98 100
99 void DartHost::OnSaveState(void** data, size_t* size) { 101 void DartHost::OnSaveState(void** data, size_t* size) {
100 LOGI("Saving DartHost state"); 102 LOGI("Saving DartHost state");
101 } 103 }
102 104
103 void DartHost::OnConfigurationChanged() { 105 void DartHost::OnConfigurationChanged() {
104 LOGI("DartHost config changed"); 106 LOGI("DartHost config changed");
105 } 107 }
106 108
107 void DartHost::OnLowMemory() { 109 void DartHost::OnLowMemory() {
108 LOGI("DartHost low on memory"); 110 LOGI("DartHost low on memory");
109 } 111 }
110 112
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

Powered by Google App Engine
This is Rietveld 408576698