2
0

NativeWindowAndroid.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Core/NativeWindowAndroid.h>
  6. namespace anki
  7. {
  8. Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
  9. {
  10. ANKI_CORE_LOGI("Initializing Android window");
  11. m_alloc = alloc;
  12. m_impl = m_alloc.newInstance<NativeWindowImpl>();
  13. // Loop until the window is ready
  14. while(g_androidApp->window == nullptr)
  15. {
  16. int ident;
  17. int events;
  18. android_poll_source* source;
  19. const int timeoutMs = 5;
  20. while((ident = ALooper_pollAll(timeoutMs, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
  21. {
  22. if(source != nullptr)
  23. {
  24. source->process(g_androidApp, source);
  25. }
  26. }
  27. }
  28. m_impl->m_nativeWindow = g_androidApp->window;
  29. // Set some stuff
  30. m_width = ANativeWindow_getWidth(g_androidApp->window);
  31. m_height = ANativeWindow_getHeight(g_androidApp->window);
  32. return Error::NONE;
  33. }
  34. void NativeWindow::destroy()
  35. {
  36. ANKI_CORE_LOGI("Destroying Android window");
  37. ANativeActivity_finish(g_androidApp->activity);
  38. // Loop until destroyRequested is set
  39. while(!g_androidApp->destroyRequested)
  40. {
  41. int ident;
  42. int events;
  43. android_poll_source* source;
  44. while((ident = ALooper_pollAll(0, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0)
  45. {
  46. if(source != nullptr)
  47. {
  48. source->process(g_androidApp, source);
  49. }
  50. }
  51. }
  52. m_alloc.deleteInstance(m_impl);
  53. }
  54. void NativeWindow::setWindowTitle(CString title)
  55. {
  56. // Nothing
  57. }
  58. } // end namespace anki