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 560659 6c447871459a157a69f27dcfb939b4ade9f1b9da
parent 560658 6100940ad37c894cc58c25579307ad1d13a0b158
child 560660 d71a2b3d1e8c290777caad6816a621066ece3272
push id53500
push userbmo:snorp@snorp.net
push dateTue, 11 Apr 2017 19:09:24 +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;
 }