Bug 1322650 - Allow access to TexturePoolOGL from Java r=jchen draft
authorJames Willcox <snorp@snorp.net>
Fri, 03 Mar 2017 15:15:13 -0600
changeset 557634 df189280ca35eadbf244dc9bd1cab94189db7191
parent 557633 56ef301f4c699f5e43e40fa926cecf85c1412d0f
child 557635 7d54ff3802120a271a61cc2855831933e54d5539
push id52769
push userbmo:snorp@snorp.net
push dateFri, 07 Apr 2017 02:38:28 +0000
reviewersjchen
bugs1322650
milestone55.0a1
Bug 1322650 - Allow access to TexturePoolOGL from Java r=jchen
gfx/layers/opengl/TexturePoolOGL.cpp
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -5,26 +5,43 @@
 #include "TexturePoolOGL.h"
 #include <stdlib.h>                     // for malloc
 #include "GLContext.h"                  // for GLContext
 #include "mozilla/Monitor.h"            // for Monitor, MonitorAutoLock
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsDebug.h"                    // for NS_ASSERTION, NS_ERROR, etc
 #include "nsDeque.h"                    // for nsDeque
 
+#ifdef MOZ_WIDGET_ANDROID
+#include "GeneratedJNINatives.h"
+#endif
+
 #define TEXTURE_POOL_SIZE 10
 
 namespace mozilla {
 namespace gl {
 
 static GLContext* sActiveContext = nullptr;
 
 static Monitor* sMonitor = nullptr;
 static nsDeque* sTextures = nullptr;
 
+#ifdef MOZ_WIDGET_ANDROID
+
+class GeckoSurfaceTextureSupport final
+    : public java::GeckoSurfaceTexture::Natives<GeckoSurfaceTextureSupport>
+{
+public:
+  static int32_t NativeAcquireTexture() {
+    return TexturePoolOGL::AcquireTexture();
+  }
+};
+
+#endif // MOZ_WIDGET_ANDROID
+
 GLuint TexturePoolOGL::AcquireTexture()
 {
   NS_ASSERTION(sMonitor, "not initialized");
 
   MonitorAutoLock lock(*sMonitor);
 
   if (!sActiveContext) {
     // Wait for a context
@@ -106,16 +123,22 @@ GLContext* TexturePoolOGL::GetGLContext(
 {
   return sActiveContext;
 }
 
 void TexturePoolOGL::Init()
 {
   sMonitor = new Monitor("TexturePoolOGL.sMonitor");
   sTextures = new nsDeque();
+
+#ifdef MOZ_WIDGET_ANDROID
+  if (jni::IsAvailable()) {
+    GeckoSurfaceTextureSupport::Init();
+  }
+#endif
 }
 
 void TexturePoolOGL::Shutdown()
 {
   delete sMonitor;
   delete sTextures;
 }