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 572879 15725438086b1e94a451290741f2bed99ee9855d
parent 572878 62a048d9c27588f7809241a4b8a3f8c79386f33c
child 572880 c79f8d98ad4495b05c6027ebc7bed9c4074cd9ff
push id57212
push userbmo:snorp@snorp.net
push dateThu, 04 May 2017 21:08:01 +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;
 }