The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
19KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. // This byte-code is generated from native/java/com/rmsl/juce/JuceOpenGLView.java with min sdk version 16
  22. // See juce_core/native/java/README.txt on how to generate this byte-code.
  23. static const uint8 javaJuceOpenGLView[] =
  24. {
  25. 0x1f, 0x8b, 0x08, 0x08, 0xac, 0xdb, 0x8b, 0x62, 0x00, 0x03, 0x4a, 0x61,
  26. 0x76, 0x61, 0x44, 0x65, 0x78, 0x42, 0x79, 0x74, 0x65, 0x43, 0x6f, 0x64,
  27. 0x65, 0x2e, 0x64, 0x65, 0x78, 0x00, 0x6d, 0x54, 0x4f, 0x48, 0x14, 0x51,
  28. 0x18, 0xff, 0x66, 0xe6, 0xed, 0x6e, 0xea, 0x3a, 0xae, 0xeb, 0x7f, 0xc1,
  29. 0xd8, 0x20, 0xea, 0x64, 0x6b, 0x7f, 0xac, 0x40, 0x0b, 0x4d, 0xfb, 0xb7,
  30. 0x0d, 0x4a, 0x69, 0x5b, 0x6c, 0x1d, 0x9a, 0x66, 0x27, 0x77, 0x44, 0x67,
  31. 0x96, 0xd9, 0xd9, 0x55, 0x28, 0x44, 0xba, 0x78, 0xf1, 0x54, 0x41, 0xd1,
  32. 0xd9, 0x43, 0x04, 0x45, 0x20, 0x05, 0x75, 0x48, 0xa2, 0x8b, 0xe1, 0xa1,
  33. 0x53, 0xd8, 0x21, 0xa8, 0x43, 0x07, 0x8f, 0x9d, 0xc2, 0x93, 0xf4, 0x7b,
  34. 0x6f, 0x9e, 0xad, 0x85, 0xc3, 0xfe, 0xe6, 0xfb, 0xfb, 0xbe, 0xef, 0xf7,
  35. 0xde, 0xce, 0xfb, 0xf2, 0xf6, 0x6c, 0x6d, 0xcf, 0xd1, 0x5e, 0x7a, 0xbc,
  36. 0x7e, 0xe1, 0x25, 0x7d, 0xb9, 0xba, 0x35, 0x37, 0x59, 0xff, 0xe2, 0xd1,
  37. 0xda, 0xeb, 0x7b, 0x2b, 0x67, 0xb6, 0x8c, 0xbb, 0xef, 0x2f, 0x0e, 0x3f,
  38. 0x89, 0x10, 0x15, 0x89, 0x68, 0x36, 0x7b, 0x2c, 0x49, 0xf2, 0xd9, 0x64,
  39. 0x44, 0x5d, 0x14, 0xfa, 0xf7, 0x00, 0x3f, 0x81, 0x18, 0xc0, 0x14, 0x22,
  40. 0xfc, 0xe8, 0x3a, 0x5e, 0xf5, 0x90, 0xb7, 0xa4, 0xbd, 0x8a, 0xd7, 0x2b,
  41. 0x8d, 0x68, 0x03, 0x32, 0x0a, 0xa9, 0x03, 0x8d, 0xc0, 0x01, 0x60, 0x10,
  42. 0xb8, 0x09, 0xcc, 0x00, 0x0f, 0x81, 0x65, 0xe0, 0x0d, 0xf0, 0x0e, 0x58,
  43. 0x01, 0x3e, 0x02, 0xab, 0xc0, 0x1a, 0xf0, 0x19, 0x58, 0x07, 0xbe, 0xf3,
  44. 0x5a, 0xc0, 0x6f, 0xa0, 0x01, 0x5c, 0x5a, 0x80, 0x7d, 0x40, 0x2f, 0x60,
  45. 0x00, 0xb7, 0x81, 0x39, 0x60, 0x11, 0x78, 0xc0, 0x42, 0x0e, 0x1a, 0xe7,
  46. 0x07, 0x60, 0x3b, 0x14, 0x95, 0x7c, 0x39, 0xf7, 0x7a, 0x29, 0xa3, 0x72,
  47. 0x6f, 0x35, 0x52, 0xff, 0xaa, 0x12, 0xd5, 0x4a, 0xfd, 0x07, 0xf4, 0x3a,
  48. 0xa9, 0x6f, 0x40, 0x8f, 0x4b, 0xfd, 0xd7, 0x0e, 0xff, 0x26, 0x74, 0x5d,
  49. 0xd6, 0xe5, 0xcd, 0x78, 0x9f, 0x66, 0xd1, 0x53, 0x13, 0x75, 0x19, 0x3c,
  50. 0x49, 0xc9, 0xa1, 0x55, 0xca, 0x76, 0xc1, 0x87, 0x89, 0x38, 0xcf, 0x6f,
  51. 0x10, 0x32, 0xcc, 0x8b, 0xa0, 0x6a, 0x93, 0xf4, 0xb7, 0x0a, 0xa9, 0x50,
  52. 0x9b, 0xb4, 0xdb, 0xa5, 0xdd, 0x21, 0xa4, 0x4a, 0x9d, 0xd2, 0xaf, 0xc8,
  53. 0xba, 0xfc, 0x51, 0xa5, 0xfc, 0x24, 0x1d, 0x51, 0x44, 0xb8, 0xef, 0x29,
  54. 0x0b, 0xf7, 0x55, 0x4c, 0x11, 0x1d, 0x11, 0x95, 0x73, 0xd0, 0x72, 0xfb,
  55. 0x39, 0x7b, 0x4d, 0x54, 0x20, 0x5a, 0x62, 0xd5, 0xbe, 0x3c, 0xaa, 0x8b,
  56. 0xf5, 0xaa, 0xa8, 0xfd, 0x1c, 0xaf, 0x46, 0x48, 0x2f, 0xa5, 0xd0, 0x38,
  57. 0x8d, 0x0d, 0x20, 0x0b, 0x65, 0x0f, 0xa3, 0xe1, 0x49, 0xec, 0x9d, 0xdb,
  58. 0xc5, 0x81, 0x38, 0xb1, 0xcb, 0xba, 0x38, 0x86, 0x90, 0xc5, 0x32, 0x0b,
  59. 0xf9, 0x24, 0x13, 0x0d, 0x82, 0x37, 0x3f, 0x91, 0xb7, 0xdb, 0x75, 0x12,
  60. 0xbc, 0xee, 0xae, 0x75, 0x7a, 0x6a, 0xf0, 0x45, 0xe9, 0x72, 0xaf, 0x7c,
  61. 0xcd, 0x07, 0xb9, 0x66, 0xf7, 0xec, 0x3a, 0x64, 0x7b, 0x09, 0x0d, 0xd5,
  62. 0x74, 0x79, 0x16, 0xd5, 0x73, 0x50, 0x85, 0xad, 0x48, 0xfb, 0x7f, 0x5d,
  63. 0xa3, 0x68, 0xbf, 0xe3, 0x3a, 0xc1, 0x69, 0x52, 0x32, 0xd4, 0x94, 0x29,
  64. 0x5b, 0xf6, 0x68, 0xd1, 0x76, 0xcf, 0x1b, 0x59, 0xc7, 0x9e, 0x39, 0x34,
  65. 0x69, 0x56, 0x4c, 0xea, 0x30, 0x4c, 0x37, 0xef, 0x7b, 0x4e, 0x3e, 0x6d,
  66. 0x79, 0x6e, 0x60, 0xbb, 0x41, 0x7a, 0x88, 0xcb, 0xd9, 0xa0, 0x6f, 0x47,
  67. 0x68, 0xc2, 0x37, 0x8b, 0x05, 0xc7, 0x2a, 0xa5, 0x87, 0x4c, 0xb7, 0x62,
  68. 0x96, 0x76, 0x0d, 0x5d, 0xb1, 0x27, 0x1c, 0xcf, 0xed, 0xa3, 0xce, 0xbf,
  69. 0xa1, 0x0a, 0x9a, 0xa4, 0xc7, 0xca, 0xfe, 0x1d, 0xd3, 0xb2, 0x79, 0xc3,
  70. 0x3e, 0xda, 0x6b, 0x58, 0xde, 0x74, 0xda, 0x9f, 0x2e, 0x4d, 0xa5, 0x27,
  71. 0xc1, 0x25, 0xfd, 0x2f, 0xa1, 0x3e, 0x52, 0xb2, 0xa4, 0x66, 0x33, 0xa4,
  72. 0x65, 0x33, 0x06, 0x14, 0x03, 0x8a, 0x91, 0x21, 0x25, 0x47, 0x6a, 0xce,
  73. 0xa0, 0xa8, 0x65, 0xba, 0x96, 0x3d, 0x25, 0x24, 0x38, 0x50, 0xcc, 0x0a,
  74. 0x79, 0x52, 0x3c, 0xef, 0x94, 0x8a, 0x66, 0x60, 0x15, 0x86, 0x7d, 0x73,
  75. 0x86, 0xda, 0x26, 0xcc, 0xa0, 0x60, 0xfb, 0xe3, 0xbe, 0xe9, 0xc2, 0xeb,
  76. 0x63, 0x43, 0x21, 0x31, 0x62, 0x05, 0xaf, 0x14, 0x50, 0xad, 0x6b, 0x06,
  77. 0x4e, 0xc5, 0x1e, 0x2f, 0x38, 0x25, 0x4a, 0x7a, 0xee, 0x60, 0x10, 0x98,
  78. 0x56, 0xc1, 0xce, 0x8f, 0x7b, 0xd7, 0x1c, 0x37, 0xef, 0xcd, 0x50, 0x8b,
  79. 0xf0, 0x71, 0x57, 0xe8, 0x18, 0x11, 0xe9, 0xd4, 0xec, 0xb9, 0xc3, 0x76,
  80. 0x98, 0x7a, 0xce, 0xf7, 0xa6, 0x65, 0x72, 0xe7, 0x6e, 0x5e, 0xb9, 0x22,
  81. 0x8e, 0x18, 0xf8, 0x48, 0x8b, 0x05, 0xbc, 0x61, 0xb4, 0xec, 0x96, 0x4b,
  82. 0x76, 0x9e, 0x0e, 0xaa, 0xc9, 0xd6, 0x98, 0x7e, 0x62, 0xb4, 0x9b, 0xba,
  83. 0x29, 0xa6, 0x5f, 0xa2, 0x11, 0xa5, 0x31, 0xa6, 0x9f, 0x5a, 0xc8, 0xd1,
  84. 0x71, 0xa5, 0x2b, 0xa6, 0x53, 0x3f, 0x85, 0xd6, 0x59, 0xc8, 0x85, 0x1b,
  85. 0xfd, 0xf8, 0x27, 0x19, 0xee, 0x02, 0x9b, 0x9f, 0x67, 0x1b, 0x5a, 0xe4,
  86. 0xbe, 0x4a, 0x2a, 0xa0, 0x00, 0x11, 0x65, 0x91, 0x29, 0xec, 0x19, 0x53,
  87. 0x94, 0x6f, 0x90, 0xbf, 0x98, 0xca, 0x96, 0x22, 0xf2, 0xde, 0xd3, 0x8e,
  88. 0xef, 0x84, 0xcb, 0xed, 0x99, 0xa6, 0x52, 0x75, 0xae, 0x69, 0x54, 0x9d,
  89. 0x6d, 0x8c, 0xaa, 0xf3, 0x6d, 0xbb, 0x06, 0x9f, 0x71, 0x51, 0xaa, 0xce,
  90. 0x39, 0x25, 0x25, 0xe7, 0x04, 0xd7, 0x13, 0xd5, 0x59, 0xa2, 0xa6, 0xc2,
  91. 0xfa, 0x7c, 0xfe, 0x69, 0x32, 0x87, 0xdf, 0x45, 0x4a, 0x85, 0x6b, 0xc5,
  92. 0x3d, 0x4d, 0x84, 0x3a, 0x9f, 0xaf, 0x7f, 0x00, 0x34, 0xf2, 0xd3, 0x47,
  93. 0x98, 0x05, 0x00, 0x00
  94. };
  95. //==============================================================================
  96. struct AndroidGLCallbacks
  97. {
  98. static void attachedToWindow (JNIEnv*, jobject, jlong);
  99. static void detachedFromWindow (JNIEnv*, jobject, jlong);
  100. static void dispatchDraw (JNIEnv*, jobject, jlong, jobject);
  101. };
  102. //==============================================================================
  103. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  104. METHOD (constructor, "<init>", "(Landroid/content/Context;J)V") \
  105. METHOD (getParent, "getParent", "()Landroid/view/ViewParent;") \
  106. METHOD (getHolder, "getHolder", "()Landroid/view/SurfaceHolder;") \
  107. METHOD (layout, "layout", "(IIII)V" ) \
  108. CALLBACK (AndroidGLCallbacks::attachedToWindow, "onAttchedWindowNative", "(J)V") \
  109. CALLBACK (AndroidGLCallbacks::detachedFromWindow, "onDetachedFromWindowNative", "(J)V") \
  110. CALLBACK (AndroidGLCallbacks::dispatchDraw, "onDrawNative", "(JLandroid/graphics/Canvas;)V")
  111. DECLARE_JNI_CLASS_WITH_BYTECODE (JuceOpenGLViewSurface, "com/rmsl/juce/JuceOpenGLView", 16, javaJuceOpenGLView, sizeof(javaJuceOpenGLView))
  112. #undef JNI_CLASS_MEMBERS
  113. //==============================================================================
  114. class OpenGLContext::NativeContext : private SurfaceHolderCallback
  115. {
  116. public:
  117. NativeContext (Component& comp,
  118. const OpenGLPixelFormat& pixelFormat,
  119. void* /*contextToShareWith*/,
  120. bool useMultisamplingIn,
  121. OpenGLVersion)
  122. : component (comp)
  123. {
  124. auto env = getEnv();
  125. // Do we have a native peer that we can attach to?
  126. if (component.getPeer()->getNativeHandle() == nullptr)
  127. return;
  128. // Initialise the EGL display
  129. if (! initEGLDisplay (pixelFormat, useMultisamplingIn))
  130. return;
  131. // create a native surface view
  132. surfaceView = GlobalRef (LocalRef<jobject>(env->NewObject (JuceOpenGLViewSurface,
  133. JuceOpenGLViewSurface.constructor,
  134. getAppContext().get(),
  135. reinterpret_cast<jlong> (this))));
  136. if (surfaceView.get() == nullptr)
  137. return;
  138. // add the view to the view hierarchy
  139. // after this the nativecontext can receive callbacks
  140. env->CallVoidMethod ((jobject) component.getPeer()->getNativeHandle(),
  141. AndroidViewGroup.addView, surfaceView.get());
  142. // initialise the geometry of the view
  143. auto bounds = component.getTopLevelComponent()->getLocalArea (&component, component.getLocalBounds());
  144. bounds *= component.getDesktopScaleFactor();
  145. updateWindowPosition (bounds);
  146. hasInitialised = true;
  147. }
  148. ~NativeContext() override
  149. {
  150. auto env = getEnv();
  151. if (jobject viewParent = env->CallObjectMethod (surfaceView.get(), JuceOpenGLViewSurface.getParent))
  152. env->CallVoidMethod (viewParent, AndroidViewGroup.removeView, surfaceView.get());
  153. }
  154. //==============================================================================
  155. InitResult initialiseOnRenderThread (OpenGLContext& ctx)
  156. {
  157. // The "real" initialisation happens when the surface is created. Here, we'll
  158. // just return true if the initialisation happened successfully, or false if
  159. // it hasn't happened yet, or was unsuccessful.
  160. const std::lock_guard lock { nativeHandleMutex };
  161. if (! hasInitialised)
  162. return InitResult::fatal;
  163. if (context.get() == EGL_NO_CONTEXT && surface.get() == EGL_NO_SURFACE)
  164. return InitResult::retry;
  165. juceContext = &ctx;
  166. return InitResult::success;
  167. }
  168. void shutdownOnRenderThread()
  169. {
  170. const std::lock_guard lock { nativeHandleMutex };
  171. juceContext = nullptr;
  172. }
  173. //==============================================================================
  174. bool makeActive() const noexcept
  175. {
  176. const std::lock_guard lock { nativeHandleMutex };
  177. return hasInitialised
  178. && surface.get() != EGL_NO_SURFACE
  179. && context.get() != EGL_NO_CONTEXT
  180. && eglMakeCurrent (display, surface.get(), surface.get(), context.get());
  181. }
  182. bool isActive() const noexcept
  183. {
  184. const std::lock_guard lock { nativeHandleMutex };
  185. return eglGetCurrentContext() == context.get();
  186. }
  187. static void deactivateCurrentContext()
  188. {
  189. eglMakeCurrent (display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  190. }
  191. //==============================================================================
  192. void swapBuffers() const noexcept { eglSwapBuffers (display, surface.get()); }
  193. bool setSwapInterval (const int) { return false; }
  194. int getSwapInterval() const { return 0; }
  195. //==============================================================================
  196. bool createdOk() const noexcept { return hasInitialised; }
  197. void* getRawContext() const noexcept { return surfaceView.get(); }
  198. GLuint getFrameBufferID() const noexcept { return 0; }
  199. //==============================================================================
  200. void updateWindowPosition (Rectangle<int> bounds)
  201. {
  202. if (lastBounds != bounds)
  203. {
  204. auto env = getEnv();
  205. lastBounds = bounds;
  206. auto r = bounds * Desktop::getInstance().getDisplays().getPrimaryDisplay()->scale;
  207. env->CallVoidMethod (surfaceView.get(), JuceOpenGLViewSurface.layout,
  208. (jint) r.getX(), (jint) r.getY(), (jint) r.getRight(), (jint) r.getBottom());
  209. }
  210. }
  211. //==============================================================================
  212. // Android Surface Callbacks:
  213. void surfaceChanged (LocalRef<jobject> holder, int format, int width, int height) override
  214. {
  215. ignoreUnused (holder, format, width, height);
  216. }
  217. void surfaceCreated (LocalRef<jobject>) override;
  218. void surfaceDestroyed (LocalRef<jobject>) override;
  219. //==============================================================================
  220. struct Locker
  221. {
  222. explicit Locker (NativeContext& ctx) : lock (ctx.mutex) {}
  223. const ScopedLock lock;
  224. };
  225. Component& component;
  226. private:
  227. //==============================================================================
  228. friend struct AndroidGLCallbacks;
  229. void attachedToWindow()
  230. {
  231. auto* env = getEnv();
  232. LocalRef<jobject> holder (env->CallObjectMethod (surfaceView.get(), JuceOpenGLViewSurface.getHolder));
  233. if (surfaceHolderCallback == nullptr)
  234. surfaceHolderCallback = GlobalRef (CreateJavaInterface (this, "android/view/SurfaceHolder$Callback"));
  235. env->CallVoidMethod (holder, AndroidSurfaceHolder.addCallback, surfaceHolderCallback.get());
  236. }
  237. void detachedFromWindow()
  238. {
  239. if (surfaceHolderCallback != nullptr)
  240. {
  241. auto* env = getEnv();
  242. LocalRef<jobject> holder (env->CallObjectMethod (surfaceView.get(), JuceOpenGLViewSurface.getHolder));
  243. env->CallVoidMethod (holder.get(), AndroidSurfaceHolder.removeCallback, surfaceHolderCallback.get());
  244. surfaceHolderCallback.clear();
  245. }
  246. }
  247. void dispatchDraw (jobject /*canvas*/)
  248. {
  249. const std::lock_guard lock { nativeHandleMutex };
  250. if (juceContext != nullptr)
  251. juceContext->triggerRepaint();
  252. }
  253. bool tryChooseConfig (const std::vector<EGLint>& optionalAttribs)
  254. {
  255. std::vector<EGLint> allAttribs
  256. {
  257. EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  258. EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
  259. EGL_BLUE_SIZE, 8,
  260. EGL_GREEN_SIZE, 8,
  261. EGL_RED_SIZE, 8,
  262. EGL_ALPHA_SIZE, 0,
  263. EGL_DEPTH_SIZE, 16
  264. };
  265. allAttribs.insert (allAttribs.end(), optionalAttribs.begin(), optionalAttribs.end());
  266. allAttribs.push_back (EGL_NONE);
  267. EGLint numConfigs{};
  268. return eglChooseConfig (display, allAttribs.data(), &config, 1, &numConfigs);
  269. }
  270. //==============================================================================
  271. bool initEGLDisplay (const OpenGLPixelFormat& pixelFormat, bool multisample)
  272. {
  273. // already initialised?
  274. if (display != EGL_NO_DISPLAY)
  275. return true;
  276. if ((display = eglGetDisplay (EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY)
  277. {
  278. jassertfalse;
  279. return false;
  280. }
  281. if (! eglInitialize (display, nullptr, nullptr))
  282. {
  283. jassertfalse;
  284. return false;
  285. }
  286. if (tryChooseConfig ({ EGL_SAMPLE_BUFFERS, multisample ? 1 : 0, EGL_SAMPLES, pixelFormat.multisamplingLevel }))
  287. return true;
  288. if (tryChooseConfig ({}))
  289. return true;
  290. eglTerminate (display);
  291. jassertfalse;
  292. return false;
  293. }
  294. struct NativeWindowReleaser
  295. {
  296. void operator() (ANativeWindow* ptr) const { if (ptr != nullptr) ANativeWindow_release (ptr); }
  297. };
  298. std::unique_ptr<ANativeWindow, NativeWindowReleaser> getNativeWindow() const
  299. {
  300. auto* env = getEnv();
  301. const LocalRef<jobject> holder (env->CallObjectMethod (surfaceView.get(), JuceOpenGLViewSurface.getHolder));
  302. if (holder == nullptr)
  303. return nullptr;
  304. const LocalRef<jobject> jSurface (env->CallObjectMethod (holder.get(), AndroidSurfaceHolder.getSurface));
  305. if (jSurface == nullptr)
  306. return nullptr;
  307. constexpr auto numAttempts = 2;
  308. for (auto i = 0; i < numAttempts; Thread::sleep (200), ++i)
  309. if (auto* ptr = ANativeWindow_fromSurface (env, jSurface.get()))
  310. return std::unique_ptr<ANativeWindow, NativeWindowReleaser> { ptr };
  311. return nullptr;
  312. }
  313. //==============================================================================
  314. CriticalSection mutex;
  315. bool hasInitialised = false;
  316. GlobalRef surfaceView;
  317. Rectangle<int> lastBounds;
  318. struct SurfaceDestructor
  319. {
  320. void operator() (EGLSurface x) const { if (x != EGL_NO_SURFACE) eglDestroySurface (display, x); }
  321. };
  322. struct ContextDestructor
  323. {
  324. void operator() (EGLContext x) const { if (x != EGL_NO_CONTEXT) eglDestroyContext (display, x); }
  325. };
  326. mutable std::mutex nativeHandleMutex;
  327. OpenGLContext* juceContext = nullptr;
  328. std::unique_ptr<std::remove_pointer_t<EGLSurface>, SurfaceDestructor> surface { EGL_NO_SURFACE };
  329. std::unique_ptr<std::remove_pointer_t<EGLContext>, ContextDestructor> context { EGL_NO_CONTEXT };
  330. GlobalRef surfaceHolderCallback;
  331. static EGLDisplay display;
  332. static EGLConfig config;
  333. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
  334. };
  335. EGLDisplay OpenGLContext::NativeContext::display = EGL_NO_DISPLAY;
  336. EGLDisplay OpenGLContext::NativeContext::config;
  337. //==============================================================================
  338. void AndroidGLCallbacks::attachedToWindow (JNIEnv*, jobject /*this*/, jlong host)
  339. {
  340. if (auto* nativeContext = reinterpret_cast<OpenGLContext::NativeContext*> (host))
  341. nativeContext->attachedToWindow();
  342. }
  343. void AndroidGLCallbacks::detachedFromWindow (JNIEnv*, jobject /*this*/, jlong host)
  344. {
  345. if (auto* nativeContext = reinterpret_cast<OpenGLContext::NativeContext*> (host))
  346. nativeContext->detachedFromWindow();
  347. }
  348. void AndroidGLCallbacks::dispatchDraw (JNIEnv*, jobject /*this*/, jlong host, jobject canvas)
  349. {
  350. if (auto* nativeContext = reinterpret_cast<OpenGLContext::NativeContext*> (host))
  351. nativeContext->dispatchDraw (canvas);
  352. }
  353. //==============================================================================
  354. bool OpenGLHelpers::isContextActive()
  355. {
  356. return eglGetCurrentContext() != EGL_NO_CONTEXT;
  357. }
  358. } // namespace juce