Bug 1014614 - Expose more SurfaceTexture API in AndroidSurfaceTexture r=blassey
authorJames Willcox <snorp@snorp.net>
Tue, 21 Oct 2014 08:53:00 -0500
changeset 211562 3114311af05d
parent 211561 c9afc7dc1f70
child 211563 790d51993a39
push id27680
push userryanvm@gmail.com
push date2014-10-21 19:21 +0000
treeherdermozilla-central@15099ba111e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs1014614
milestone36.0a1
Bug 1014614 - Expose more SurfaceTexture API in AndroidSurfaceTexture r=blassey
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -41,16 +41,17 @@ public:
     JNIEnv* env = GetJNIForThread();
 
     AutoLocalJNIFrame jniFrame(env);
 
     jSurfaceTextureClass = (jclass)env->NewGlobalRef(env->FindClass("android/graphics/SurfaceTexture"));
     jSurfaceTexture_Ctor = env->GetMethodID(jSurfaceTextureClass, "<init>", "(I)V");
     jSurfaceTexture_updateTexImage = env->GetMethodID(jSurfaceTextureClass, "updateTexImage", "()V");
     jSurfaceTexture_getTransformMatrix = env->GetMethodID(jSurfaceTextureClass, "getTransformMatrix", "([F)V");
+    jSurfaceTexture_setDefaultBufferSize = env->GetMethodID(jSurfaceTextureClass, "setDefaultBufferSize", "(II)V");
 
     jSurfaceClass = (jclass)env->NewGlobalRef(env->FindClass("android/view/Surface"));
     jSurface_Ctor = env->GetMethodID(jSurfaceClass, "<init>", "(Landroid/graphics/SurfaceTexture;)V");
 
     mInitialized = true;
     return true;
   }
 
@@ -122,23 +123,32 @@ public:
     aMatrix._43 = array[14];
     aMatrix._44 = array[15];
 
     env->ReleaseFloatArrayElements(jarray, array, 0);
 
     return false;
   }
 
+  void SetDefaultBufferSize(jobject aSurfaceTexture, int32_t width, int32_t height)
+  {
+    JNIEnv* env = GetJNIForThread();
+
+    AutoLocalJNIFrame jniFrame(env);
+    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_setDefaultBufferSize, width, height);
+  }
+
 private:
   bool mInitialized;
 
   jclass jSurfaceTextureClass;
   jmethodID jSurfaceTexture_Ctor;
   jmethodID jSurfaceTexture_updateTexImage;
   jmethodID jSurfaceTexture_getTransformMatrix;
+  jmethodID jSurfaceTexture_setDefaultBufferSize;
 
   jclass jSurfaceClass;
   jmethodID jSurface_Ctor;
 
 } sJNIFunctions;
 
 AndroidSurfaceTexture*
 AndroidSurfaceTexture::Create(GLuint aTexture)
@@ -237,25 +247,32 @@ bool
 AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
 {
   return sJNIFunctions.GetTransformMatrix(mSurfaceTexture, aMatrix);
 }
 
 void
 AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
 {
-  if (aRunnable)
+  if (aRunnable) {
     GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
-  else
-    GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
+  } else {
+     GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
+  }
 
   mFrameAvailableCallback = aRunnable;
 }
 
 void
+AndroidSurfaceTexture::SetDefaultSize(mozilla::gfx::IntSize size)
+{
+  sJNIFunctions.SetDefaultBufferSize(mSurfaceTexture, size.width, size.height);
+}
+
+void
 AndroidSurfaceTexture::NotifyFrameAvailable()
 {
   if (mFrameAvailableCallback) {
     // Proxy to main thread if we aren't on it
     if (!NS_IsMainThread()) {
       // Proxy to main thread
       nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable);
       NS_DispatchToCurrentThread(event);
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -36,36 +36,38 @@ class AndroidSurfaceTexture {
 
 public:
   static AndroidSurfaceTexture* Create(GLuint aTexture);
   static AndroidSurfaceTexture* Find(int id);
 
   // Returns with reasonable certainty whether or not we'll
   // be able to create and use a SurfaceTexture
   static bool Check();
-  
-  ~AndroidSurfaceTexture();
 
   // This attaches the updated data to the TEXTURE_EXTERNAL target
   void UpdateTexImage();
 
   bool GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix);
   int ID() { return mID; }
 
+  void SetDefaultSize(mozilla::gfx::IntSize size);
+
   // The callback is guaranteed to be called on the main thread even
   // if the upstream callback is received on a different thread
   void SetFrameAvailableCallback(nsIRunnable* aRunnable);
 
   // Only should be called by AndroidJNI when we get a
   // callback from the underlying SurfaceTexture instance
   void NotifyFrameAvailable();
 
   GLuint Texture() { return mTexture; }
+  jobject JavaSurface() { return mSurface; }
 private:
   AndroidSurfaceTexture();
+  ~AndroidSurfaceTexture();
 
   bool Init(GLuint aTexture);
 
   GLuint mTexture;
   jobject mSurfaceTexture;
   jobject mSurface;
 
   int mID;