Bug 1294481 - Rip out old Java code for AndroidSurfaceTexture; r=snorp
authorJim Chen <nchen@mozilla.com>
Tue, 23 Aug 2016 18:52:30 -0400
changeset 341685 3c447a8c81c6ff404d835fb8bdb033cecc3705dd
parent 341684 95b9f4f55e5b05ce5ed4bec69e6bf42b2ec0e4f1
child 341686 84529160c383f11b0e0654ea7953bd0eb0bb4b81
push id5
push userfmarier@mozilla.com
push dateFri, 26 Aug 2016 00:45:46 +0000
reviewerssnorp
bugs1294481
milestone51.0a1
Bug 1294481 - Rip out old Java code for AndroidSurfaceTexture; r=snorp Rip out the old GeckoAppShell methods that implemented a OnFrameAvailableListener callback system for AndroidSurfaceTexture.
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
widget/android/AndroidJNI.cpp
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -22,68 +22,16 @@
 using namespace mozilla;
 using namespace mozilla::jni;
 using namespace mozilla::java;
 using namespace mozilla::java::sdk;
 
 namespace mozilla {
 namespace gl {
 
-// Maintains a mapping between AndroidSurfaceTexture instances and their
-// unique numerical IDs. [thread-safe]
-class InstanceMap
-{
-  typedef AndroidSurfaceTexture* InstancePtr;
-  typedef std::map<int, InstancePtr> MapType;
-
-public:
-  InstanceMap()
-    : mNextId(0)
-    , mMonitor("AndroidSurfaceTexture::InstanceMap::mMonitor")
-  {}
-
-  int Add(InstancePtr aInstance)
-  {
-    MonitorAutoLock lock(mMonitor);
-    mInstances.insert({++mNextId, aInstance});
-    return mNextId;
-  }
-
-  void Remove(int aId)
-  {
-    MonitorAutoLock lock(mMonitor);
-    mInstances.erase(aId);
-  }
-
-  InstancePtr Get(int aId) const
-  {
-    MonitorAutoLock lock(mMonitor);
-
-    auto it = mInstances.find(aId);
-    if (it == mInstances.end()) {
-      return nullptr;
-    }
-    return it->second;
-  }
-
-private:
-  MapType mInstances;
-  int mNextId;
-
-  mutable Monitor mMonitor;
-};
-
-static InstanceMap sInstances;
-
-AndroidSurfaceTexture*
-AndroidSurfaceTexture::Find(int aId)
-{
-  return sInstances.Get(aId);
-}
-
 static bool
 IsSTSupported()
 {
   return AndroidBridge::Bridge()->GetAPIVersion() >= 14; /* ICS */
 }
 
 already_AddRefed<AndroidSurfaceTexture>
 AndroidSurfaceTexture::Create()
@@ -199,38 +147,31 @@ AndroidSurfaceTexture::Init(GLContext* a
       Surface::New(mSurfaceTexture, ReturnTo(&mSurface))))) {
     return false;
   }
 
   mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
                                             mSurface.Get());
   MOZ_ASSERT(mNativeWindow, "Failed to create native window from surface");
 
-  mID = sInstances.Add(this);
-
   return true;
 }
 
 AndroidSurfaceTexture::AndroidSurfaceTexture()
   : mTexture(0)
   , mSurfaceTexture()
   , mSurface()
   , mAttachedContext(nullptr)
   , mMonitor("AndroidSurfaceTexture::mContextMonitor")
 {
 }
 
 AndroidSurfaceTexture::~AndroidSurfaceTexture()
 {
-  sInstances.Remove(mID);
-
-  mFrameAvailableCallback = nullptr;
-
   if (mSurfaceTexture) {
-    GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
     mSurfaceTexture = nullptr;
   }
 
   if (mNativeWindow) {
     ANativeWindow_release(mNativeWindow);
     mNativeWindow = nullptr;
   }
 }
@@ -272,41 +213,20 @@ AndroidSurfaceTexture::GetTransformMatri
   aMatrix._44 = array[15];
 
   env->ReleaseFloatArrayElements(jarray.Get(), array, 0);
 }
 
 void
 AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
 {
-  if (aRunnable) {
-    GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
-  } else {
-     GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
-  }
-
-  mFrameAvailableCallback = aRunnable;
 }
 
 void
 AndroidSurfaceTexture::SetDefaultSize(mozilla::gfx::IntSize size)
 {
   mSurfaceTexture->SetDefaultBufferSize(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
-      NS_DispatchToCurrentThread(NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable));
-    } else {
-      mFrameAvailableCallback->Run();
-    }
-  }
-}
-
 } // gl
 } // mozilla
 
 #endif // MOZ_WIDGET_ANDROID
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -39,18 +39,16 @@ public:
   static already_AddRefed<AndroidSurfaceTexture> Create(GLContext* aGLContext, GLuint aTexture);
 
   // Here the SurfaceTexture will be created in a detached state. You must call
   // Attach() with the GLContext you wish to composite with. It must be done
   // on the thread where that GLContext is current. This method requires
   // Android Jelly Bean.
   static already_AddRefed<AndroidSurfaceTexture> Create();
 
-  static AndroidSurfaceTexture* Find(int aId);
-
   // If we are on Jelly Bean, the SurfaceTexture can be detached and reattached
   // to allow consumption from different GLContexts. It is recommended to only
   // attach while you are consuming in order to allow this.
   //
   // Only one GLContext may be attached at any given time. If another is already
   // attached, we try to wait for it to become detached.
   nsresult Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT);
 
@@ -65,46 +63,39 @@ public:
   ANativeWindow* NativeWindow() const {
     return mNativeWindow;
   }
 
   // This attaches the updated data to the TEXTURE_EXTERNAL target
   void UpdateTexImage();
 
   void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix) const;
-  int ID() const { 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() const { return mTexture; }
   const java::sdk::Surface::Ref& JavaSurface() const { return mSurface; }
 
 private:
   AndroidSurfaceTexture();
   ~AndroidSurfaceTexture();
 
   bool Init(GLContext* aContext, GLuint aTexture);
 
   GLuint mTexture;
   java::sdk::SurfaceTexture::GlobalRef mSurfaceTexture;
   java::sdk::Surface::GlobalRef mSurface;
 
   GLContext* mAttachedContext;
 
   ANativeWindow* mNativeWindow;
-  int mID;
-  nsCOMPtr<nsIRunnable> mFrameAvailableCallback;
 
   mutable Monitor mMonitor;
 };
 
 }
 }
 
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -233,18 +233,16 @@ public class GeckoAppShell
     static public final int LINK_TYPE_WIMAX = 4;
     static public final int LINK_TYPE_2G = 5;
     static public final int LINK_TYPE_3G = 6;
     static public final int LINK_TYPE_4G = 7;
 
     /* The Android-side API: API methods that Android calls */
 
     // helper methods
-    public static native void onSurfaceTextureFrameAvailable(Object surfaceTexture, int id);
-
     @WrapForJNI
     private static native void reportJavaCrash(String stackTrace);
 
     @WrapForJNI(dispatchTo = "gecko")
     public static native void notifyUriVisited(String uri);
 
     private static LayerView sLayerView;
     private static Rect sScreenSize;
@@ -2185,31 +2183,16 @@ public class GeckoAppShell
     }
 
     @WrapForJNI(calledFrom = "gecko")
     public static void notifyWakeLockChanged(String topic, String state) {
         if (getGeckoInterface() != null)
             getGeckoInterface().notifyWakeLockChanged(topic, state);
     }
 
-    @WrapForJNI
-    public static void registerSurfaceTextureFrameListener(Object surfaceTexture, final int id) {
-        ((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
-            @Override
-            public void onFrameAvailable(SurfaceTexture surfaceTexture) {
-                GeckoAppShell.onSurfaceTextureFrameAvailable(surfaceTexture, id);
-            }
-        });
-    }
-
-    @WrapForJNI
-    public static void unregisterSurfaceTextureFrameListener(Object surfaceTexture) {
-        ((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(null);
-    }
-
     @WrapForJNI(calledFrom = "gecko")
     public static boolean unlockProfile() {
         // Try to kill any zombie Fennec's that might be running
         GeckoAppShell.killAnyZombies();
 
         // Then force unlock this profile
         if (getGeckoInterface() != null) {
             GeckoProfile profile = getGeckoInterface().getProfile();
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -38,21 +38,10 @@ using namespace mozilla::layers;
 using namespace mozilla::widget;
 
 /* Forward declare all the JNI methods as extern "C" */
 
 extern "C" {
 /*
  * Incoming JNI methods
  */
-NS_EXPORT void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_onSurfaceTextureFrameAvailable(JNIEnv* jenv, jclass, jobject surfaceTexture, jint id)
-{
-  mozilla::gl::AndroidSurfaceTexture* st = mozilla::gl::AndroidSurfaceTexture::Find(id);
-  if (!st) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find AndroidSurfaceTexture with id %d", id);
-    return;
-  }
-
-  st->NotifyFrameAvailable();
-}
 
 }