OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 * |
| 7 */ |
| 8 |
| 9 #include <android_native_app_glue.h> |
| 10 |
| 11 #include "SkApplication.h" |
| 12 #include "VisualBench.h" |
| 13 |
| 14 /** |
| 15 * Shared state for our app. |
| 16 */ |
| 17 struct VisualBenchState { |
| 18 VisualBenchState() : fApp(NULL), fWindow(NULL) {} |
| 19 struct android_app* fApp; |
| 20 SkOSWindow* fWindow; |
| 21 SkTArray<SkString> fFlags; |
| 22 }; |
| 23 |
| 24 static void handle_cmd(struct android_app* app, int32_t cmd) { |
| 25 struct VisualBenchState* state = (struct VisualBenchState*)app->userData; |
| 26 switch (cmd) { |
| 27 case APP_CMD_INIT_WINDOW: |
| 28 // The window is being shown, get it ready. |
| 29 if (state->fApp->window != NULL) { |
| 30 if (state->fWindow) { |
| 31 SkDELETE(state->fWindow); |
| 32 application_term(); |
| 33 } |
| 34 |
| 35 // drain any events that occurred before |window| was assigned. |
| 36 while (SkEvent::ProcessEvent()); |
| 37 |
| 38 // Start normal Skia sequence |
| 39 application_init(); |
| 40 |
| 41 SkTArray<const char*> args; |
| 42 args.push_back("VisualBench"); |
| 43 for (int i = 0; i < state->fFlags.count(); i++) { |
| 44 SkDebugf(state->fFlags[i].c_str()); |
| 45 args.push_back(state->fFlags[i].c_str()); |
| 46 } |
| 47 |
| 48 state->fWindow = create_sk_window((void*)state->fApp->window, |
| 49 args.count(), |
| 50 const_cast<char**>(args.begin(
))); |
| 51 } |
| 52 break; |
| 53 case APP_CMD_TERM_WINDOW: |
| 54 SkDELETE(state->fWindow); |
| 55 state->fWindow = NULL; |
| 56 application_term(); |
| 57 break; |
| 58 } |
| 59 } |
| 60 |
| 61 void android_main(struct android_app* state) { |
| 62 struct VisualBenchState visualBenchState; |
| 63 |
| 64 // Make sure glue isn't stripped. |
| 65 app_dummy(); |
| 66 |
| 67 state->userData = &visualBenchState; |
| 68 state->onAppCmd = handle_cmd; |
| 69 visualBenchState.fApp = state; |
| 70 |
| 71 // Get command line arguments |
| 72 JavaVM* jvm = state->activity->vm; |
| 73 JNIEnv *env; |
| 74 jvm->AttachCurrentThread(&env, 0); |
| 75 |
| 76 jobject me = state->activity->clazz; |
| 77 |
| 78 jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity |
| 79 jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Inte
nt;"); |
| 80 jobject intent = env->CallObjectMethod(me, giid); //Got our intent |
| 81 |
| 82 jclass icl = env->GetObjectClass(intent); //class pointer of Intent |
| 83 jmethodID gseid = env->GetMethodID(icl, "getStringExtra", |
| 84 "(Ljava/lang/String;)Ljava/lang/String;")
; |
| 85 |
| 86 jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, |
| 87 env->NewStringUTF("cmdLine
Arguments")); |
| 88 if (jsParam1) { |
| 89 const char* flags = env->GetStringUTFChars(jsParam1, 0); |
| 90 SkTArray<SkString> flagEntries; |
| 91 SkStrSplit(flags, " ", &visualBenchState.fFlags); |
| 92 env->ReleaseStringUTFChars(jsParam1, flags); |
| 93 } |
| 94 jvm->DetachCurrentThread(); |
| 95 |
| 96 while (1) { |
| 97 // Read all pending events. |
| 98 int ident; |
| 99 int events; |
| 100 struct android_poll_source* source; |
| 101 |
| 102 // We loop until all events are read, then continue to draw the next fra
me of animation. |
| 103 while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
{ |
| 104 // Process this event. |
| 105 if (source != NULL) { |
| 106 source->process(state, source); |
| 107 } |
| 108 |
| 109 // Check if we are exiting. |
| 110 if (state->destroyRequested != 0) { |
| 111 SkDELETE(visualBenchState.fWindow); |
| 112 application_term(); |
| 113 return; |
| 114 } |
| 115 } |
| 116 |
| 117 if (visualBenchState.fWindow) { |
| 118 if (visualBenchState.fWindow->destroyRequested()) { |
| 119 SkDELETE(visualBenchState.fWindow); |
| 120 visualBenchState.fWindow = NULL; |
| 121 application_term(); |
| 122 break; |
| 123 } |
| 124 visualBenchState.fWindow->update(NULL); |
| 125 } |
| 126 } |
| 127 ANativeActivity_finish(state->activity); |
| 128 } |
OLD | NEW |