| Index: samples/android_sample/jni/dart_host.cc
|
| ===================================================================
|
| --- samples/android_sample/jni/dart_host.cc (revision 0)
|
| +++ samples/android_sample/jni/dart_host.cc (revision 0)
|
| @@ -0,0 +1,125 @@
|
| +#include "dart_host.h"
|
| +
|
| +#include <unistd.h>
|
| +#include <math.h>
|
| +
|
| +#include "vm/flags.h"
|
| +#include "bin/eventhandler.h"
|
| +#include "bin/isolate_data.h"
|
| +#include "bin/log.h"
|
| +#include "bin/platform.h"
|
| +#include "bin/process.h"
|
| +
|
| +DartHost::DartHost(Context *pContext) :
|
| + mInputHandler(pContext->mInputHandler),
|
| + mTimer(pContext->mTimer),
|
| + mGraphics(pContext->mGraphics),
|
| + mVmGlue(pContext->mVmGlue),
|
| + mActive(false) {
|
| + Log::Print("Creating DartHost");
|
| +}
|
| +
|
| +DartHost::~DartHost() {
|
| + Log::Print("Freeing DartHost");
|
| +}
|
| +
|
| +int32_t DartHost::onActivate() {
|
| + return activate();
|
| +}
|
| +
|
| +int32_t DartHost::activate() {
|
| + if (!mActive) {
|
| + Log::Print("Activating DartHost");
|
| + if (mGraphics->start() != 0) {
|
| + return -1;
|
| + }
|
| + if (mInputHandler->start() != 0) {
|
| + return -1;
|
| + }
|
| + mTimer->reset();
|
| + Log::Print("Starting main isolate");
|
| + int result = mVmGlue->startMainIsolate();
|
| + if (result != 0) {
|
| + Log::PrintErr("startMainIsolate returned %d", result);
|
| + return -1;
|
| + }
|
| + mActive = true;
|
| + mVmGlue->callSetup();
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +void DartHost::onDeactivate() {
|
| + deactivate();
|
| +}
|
| +
|
| +void DartHost::deactivate() {
|
| + if (mActive) {
|
| + mActive = false;
|
| + mVmGlue->finishMainIsolate();
|
| + Log::Print("Deactivating DartHost");
|
| + mGraphics->stop();
|
| + }
|
| +}
|
| +
|
| +int32_t DartHost::onStep() {
|
| + mTimer->update();
|
| + mVmGlue->callUpdate();
|
| + if (mGraphics->update() != 0) {
|
| + return -1;
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +void DartHost::onStart() {
|
| + Log::Print("Starting DartHost");
|
| +}
|
| +
|
| +void DartHost::onResume() {
|
| + Log::Print("Resuming DartHost");
|
| +}
|
| +
|
| +void DartHost::onPause() {
|
| + Log::Print("Pausing DartHost");
|
| +}
|
| +
|
| +void DartHost::onStop() {
|
| + Log::Print("Stopping DartHost");
|
| +}
|
| +
|
| +void DartHost::onDestroy() {
|
| + Log::Print("Destroying DartHost");
|
| +}
|
| +
|
| +void DartHost::onSaveState(void** pData, int32_t pSize) {
|
| + Log::Print("Saving DartHost state");
|
| +}
|
| +
|
| +void DartHost::onConfigurationChanged() {
|
| + Log::Print("DartHost config changed");
|
| +}
|
| +
|
| +void DartHost::onLowMemory() {
|
| + Log::Print("DartHost low on memory");
|
| +}
|
| +
|
| +void DartHost::onCreateWindow() {
|
| + Log::Print("DartHost creating window");
|
| +}
|
| +
|
| +void DartHost::onDestroyWindow() {
|
| + Log::Print("DartHost destroying window");
|
| +}
|
| +
|
| +void DartHost::onGainedFocus() {
|
| + Log::Print("DartHost gained focus");
|
| +}
|
| +
|
| +void DartHost::onLostFocus() {
|
| + Log::Print("DartHost lost focus");
|
| +}
|
| +
|
| +void DartHost::clear() {
|
| + memset(mWindowBuffer.bits, 0,
|
| + mWindowBuffer.stride * mWindowBuffer.height * sizeof(int32_t));
|
| +}
|
|
|