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