main_android.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2016 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. #include <jni.h>
  8. #include <errno.h>
  9. #include <android_native_app_glue.h>
  10. #include "tools/sk_app/Application.h"
  11. #include "tools/timer/Timer.h"
  12. using sk_app::Application;
  13. /**
  14. * This is the main entry point of a native application that is using
  15. * android_native_app_glue. It runs in its own thread, with its own
  16. * event loop for receiving input events and doing other things.
  17. */
  18. void android_main(struct android_app* state) {
  19. // Make sure glue isn't stripped.
  20. app_dummy();
  21. static const char* gCmdLine[] = {
  22. "viewer",
  23. "--skps",
  24. "/data/local/tmp/skps",
  25. // TODO: figure out how to use am start with extra params to pass in additional arguments at
  26. // runtime
  27. // "--atrace",
  28. };
  29. std::unique_ptr<Application> vkApp(Application::Create(SK_ARRAY_COUNT(gCmdLine),
  30. const_cast<char**>(gCmdLine),
  31. state));
  32. // loop waiting for stuff to do.
  33. while (1) {
  34. // Read all pending events.
  35. int ident;
  36. int events;
  37. struct android_poll_source* source;
  38. // block forever waiting for events.
  39. while ((ident=ALooper_pollAll(-1, NULL, &events,
  40. (void**)&source)) >= 0) {
  41. // Process this event.
  42. if (source != NULL) {
  43. source->process(state, source);
  44. }
  45. // Check if we are exiting.
  46. if (state->destroyRequested != 0) {
  47. return;
  48. }
  49. vkApp->onIdle();
  50. }
  51. }
  52. }
  53. //END_INCLUDE(all)