Bug 1014614 - Expose more SurfaceTexture API in AndroidSurfaceTexture r=blassey
💩💩 backed out by 53e24fd12cd1 💩 💩
authorJames Willcox <snorp@snorp.net>
Fri, 17 Oct 2014 10:35:10 -0500
changeset 210948 2b72e71f1fdf
parent 210947 8b530a9a2f99
child 210949 511dcc817f5d
push id50598
push userjwillcox@mozilla.com
push date2014-10-17 15:36 +0000
treeherdermozilla-inbound@40f99ba7f616 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs1014614
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -38,16 +38,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;
   }
 
@@ -119,23 +120,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)
@@ -236,25 +246,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,40 +36,42 @@ 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();
 
   AndroidNativeWindow* NativeWindow() {
     return mNativeWindow;
   }
 
   // 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;
 
   RefPtr<AndroidNativeWindow> mNativeWindow;