Chromium Code Reviews| 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("SampleApp"); | |
|
djsollen
2015/06/11 20:35:43
VisualBench?
joshualitt
2015/06/12 15:40:35
Acknowledged.
| |
| 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 state->fWindow->forceInvalAll(); | |
| 52 } | |
| 53 break; | |
| 54 case APP_CMD_TERM_WINDOW: | |
| 55 SkDELETE(state->fWindow); | |
| 56 state->fWindow = NULL; | |
| 57 application_term(); | |
| 58 break; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void android_main(struct android_app* state) { | |
| 63 struct VisualBenchState visualBenchState; | |
| 64 | |
| 65 // Make sure glue isn't stripped. | |
| 66 app_dummy(); | |
| 67 | |
| 68 state->userData = &visualBenchState; | |
| 69 state->onAppCmd = handle_cmd; | |
| 70 visualBenchState.fApp = state; | |
| 71 | |
| 72 // Get command line arguments | |
| 73 JavaVM* jvm = state->activity->vm; | |
| 74 JNIEnv *env; | |
| 75 jvm->AttachCurrentThread(&env, 0); | |
| 76 | |
| 77 jobject me = state->activity->clazz; | |
| 78 | |
| 79 jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity | |
| 80 jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Inte nt;"); | |
| 81 jobject intent = env->CallObjectMethod(me, giid); //Got our intent | |
| 82 | |
| 83 jclass icl = env->GetObjectClass(intent); //class pointer of Intent | |
| 84 jmethodID gseid = env->GetMethodID(icl, "getStringExtra", | |
| 85 "(Ljava/lang/String;)Ljava/lang/String;") ; | |
| 86 | |
| 87 jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, | |
| 88 env->NewStringUTF("cmdLine Arguments")); | |
| 89 if (jsParam1) { | |
| 90 const char* flags = env->GetStringUTFChars(jsParam1, 0); | |
| 91 SkTArray<SkString> flagEntries; | |
| 92 SkStrSplit(flags, " ", &visualBenchState.fFlags); | |
| 93 env->ReleaseStringUTFChars(jsParam1, flags); | |
| 94 } | |
| 95 jvm->DetachCurrentThread(); | |
| 96 | |
| 97 while (1) { | |
| 98 // Read all pending events. | |
| 99 int ident; | |
| 100 int events; | |
| 101 struct android_poll_source* source; | |
| 102 | |
| 103 // We loop until all events are read, then continue to draw the next fra me of animation. | |
| 104 while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { | |
| 105 // Process this event. | |
| 106 if (source != NULL) { | |
| 107 source->process(state, source); | |
| 108 } | |
| 109 | |
| 110 // Check if we are exiting. | |
| 111 if (state->destroyRequested != 0) { | |
| 112 SkDELETE(visualBenchState.fWindow); | |
| 113 application_term(); | |
| 114 return; | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 if (visualBenchState.fWindow) { | |
| 119 if (visualBenchState.fWindow->destroyRequested()) { | |
| 120 SkDELETE(visualBenchState.fWindow); | |
| 121 visualBenchState.fWindow = NULL; | |
| 122 application_term(); | |
| 123 break; | |
| 124 } | |
| 125 visualBenchState.fWindow->update(NULL); | |
| 126 } | |
| 127 } | |
| 128 ANativeActivity_finish(state->activity); | |
| 129 } | |
| OLD | NEW |