Backed out changeset d6516a10c808 (bug 1322650)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 05 May 2017 18:53:40 +0200
changeset 404923 c74f6afe9f3c8b4fa9d5b26c4b506be0ca6c3331
parent 404922 bba1444daf9a7f9682fb83e93967bb5e24178778
child 404924 d3e4300c8976e793f9ecbc44b2e2d9a603184148
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1322650
milestone55.0a1
backs outd6516a10c8088a6ce872c888d88bc98a545a7fee
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
Backed out changeset d6516a10c808 (bug 1322650)
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginInstanceOwner.cpp
gfx/gl/AndroidNativeWindow.h
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java
widget/android/jni/Natives.h
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -53,18 +53,16 @@ using namespace mozilla::dom;
 #include "mozilla/CondVar.h"
 #include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/Hal.h"
 #include "GLContextProvider.h"
 #include "GLContext.h"
 #include "TexturePoolOGL.h"
 #include "SurfaceTypes.h"
 #include "EGLUtils.h"
-#include "GeneratedJNIWrappers.h"
-#include "GeneratedJNINatives.h"
 
 using namespace mozilla;
 using namespace mozilla::gl;
 
 typedef nsNPAPIPluginInstance::VideoInfo VideoInfo;
 
 class PluginEventRunnable : public Runnable
 {
@@ -103,17 +101,17 @@ static bool EnsureGLContext()
     sPluginContext = GLContextProvider::CreateHeadless(flags, &discardedFailureId);
   }
 
   return sPluginContext != nullptr;
 }
 
 static std::map<NPP, nsNPAPIPluginInstance*> sPluginNPPMap;
 
-#endif // MOZ_WIDGET_ANDROID
+#endif
 
 using namespace mozilla;
 using namespace mozilla::plugins::parent;
 using namespace mozilla::layers;
 
 static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
 
 NS_IMPL_ISUPPORTS(nsNPAPIPluginInstance, nsIAudioChannelAgentCallback)
@@ -199,22 +197,24 @@ uint32_t nsNPAPIPluginInstance::gInUnsaf
 void
 nsNPAPIPluginInstance::Destroy()
 {
   Stop();
   mPlugin = nullptr;
   mAudioChannelAgent = nullptr;
 
 #if MOZ_WIDGET_ANDROID
-  if (mContentSurface) {
-    java::SurfaceAllocator::DisposeSurface(mContentSurface);
-  }
+  if (mContentSurface)
+    mContentSurface->SetFrameAvailableCallback(nullptr);
+
+  mContentSurface = nullptr;
 
   std::map<void*, VideoInfo*>::iterator it;
   for (it = mVideos.begin(); it != mVideos.end(); it++) {
+    it->second->mSurfaceTexture->SetFrameAvailableCallback(nullptr);
     delete it->second;
   }
   mVideos.clear();
   SetWakeLock(false);
 #endif
 }
 
 TimeStamp
@@ -853,93 +853,73 @@ void nsNPAPIPluginInstance::SetWakeLock(
 GLContext* nsNPAPIPluginInstance::GLContext()
 {
   if (!EnsureGLContext())
     return nullptr;
 
   return sPluginContext;
 }
 
-class PluginTextureListener
-  : public java::SurfaceTextureListener::Natives<PluginTextureListener>
+already_AddRefed<AndroidSurfaceTexture> nsNPAPIPluginInstance::CreateSurfaceTexture()
 {
-  using Base = java::SurfaceTextureListener::Natives<PluginTextureListener>;
-
-  const nsCOMPtr<nsIRunnable> mCallback;
-public:
-  using Base::AttachNative;
-  using Base::DisposeNative;
-
-  PluginTextureListener(nsIRunnable* aCallback) : mCallback(aCallback) {}
+  if (!EnsureGLContext())
+    return nullptr;
 
-  void OnFrameAvailable()
-  {
-    if (NS_IsMainThread()) {
-      mCallback->Run();
-      return;
-    }
-    NS_DispatchToMainThread(mCallback);
-  }
-};
+  GLuint texture = TexturePoolOGL::AcquireTexture();
+  if (!texture)
+    return nullptr;
 
-java::GeckoSurface::LocalRef nsNPAPIPluginInstance::CreateSurface()
-{
-  java::GeckoSurface::LocalRef surf = java::SurfaceAllocator::AcquireSurface(0, 0, false);
-  if (!surf) {
+  RefPtr<AndroidSurfaceTexture> surface = AndroidSurfaceTexture::Create(TexturePoolOGL::GetGLContext(),
+                                                                        texture);
+  if (!surface) {
     return nullptr;
   }
 
   nsCOMPtr<nsIRunnable> frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable);
-
-  java::SurfaceTextureListener::LocalRef listener = java::SurfaceTextureListener::New();
-
-  PluginTextureListener::AttachNative(listener, MakeUnique<PluginTextureListener>(frameCallback.get()));
-
-  java::GeckoSurfaceTexture::LocalRef gst = java::GeckoSurfaceTexture::Lookup(surf->GetHandle());
-  if (!gst) {
-    return nullptr;
-  }
-
-  const auto& st = java::sdk::SurfaceTexture::Ref::From(gst);
-  st->SetOnFrameAvailableListener(listener);
-
-  return surf;
+  surface->SetFrameAvailableCallback(frameCallback);
+  return surface.forget();
 }
 
 void nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable()
 {
   if (mRunning == RUNNING && mOwner)
     mOwner->Recomposite();
 }
 
 void* nsNPAPIPluginInstance::AcquireContentWindow()
 {
-  if (!mContentWindow.NativeWindow()) {
-    mContentSurface = CreateSurface();
+  if (!mContentSurface) {
+    mContentSurface = CreateSurfaceTexture();
+
     if (!mContentSurface)
       return nullptr;
-
-    mContentWindow = AndroidNativeWindow(mContentSurface);
   }
 
-  return mContentWindow.NativeWindow();
+  return mContentSurface->NativeWindow();
 }
 
-java::GeckoSurface::Param
-nsNPAPIPluginInstance::AsSurface()
+AndroidSurfaceTexture*
+nsNPAPIPluginInstance::AsSurfaceTexture()
 {
+  if (!mContentSurface)
+    return nullptr;
+
   return mContentSurface;
 }
 
 void* nsNPAPIPluginInstance::AcquireVideoWindow()
 {
-  java::GeckoSurface::LocalRef surface = CreateSurface();
+  RefPtr<AndroidSurfaceTexture> surface = CreateSurfaceTexture();
+  if (!surface) {
+    return nullptr;
+  }
+
   VideoInfo* info = new VideoInfo(surface);
 
-  void* window = info->mNativeWindow.NativeWindow();
+  void* window = info->mSurfaceTexture->NativeWindow();
   mVideos.insert(std::pair<void*, VideoInfo*>(window, info));
 
   return window;
 }
 
 void nsNPAPIPluginInstance::ReleaseVideoWindow(void* window)
 {
   std::map<void*, VideoInfo*>::iterator it = mVideos.find(window);
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -16,17 +16,17 @@
 #include "nsIChannel.h"
 #include "nsHashKeys.h"
 #include <prinrval.h>
 #include "js/TypeDecls.h"
 #include "nsIAudioChannelAgent.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "nsIRunnable.h"
 #include "GLContextTypes.h"
-#include "AndroidNativeWindow.h"
+#include "AndroidSurfaceTexture.h"
 #include "AndroidBridge.h"
 #include <map>
 class PluginEventRunnable;
 #endif
 
 #include "mozilla/EventForwards.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/PluginLibrary.h"
@@ -210,34 +210,32 @@ public:
     int32_t mWidth;
     int32_t mHeight;
     GLuint mInternalFormat;
   };
 
   // For ANPNativeWindow
   void* AcquireContentWindow();
 
-  mozilla::java::GeckoSurface::Param AsSurface();
+  mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture();
 
   // For ANPVideo
   class VideoInfo {
   public:
-    VideoInfo(mozilla::java::GeckoSurface::Param aSurface)
-      : mSurface(aSurface)
-      , mNativeWindow(aSurface)
+    VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) :
+      mSurfaceTexture(aSurfaceTexture)
     {
     }
 
     ~VideoInfo()
     {
-      mozilla::java::SurfaceAllocator::DisposeSurface(mSurface);
+      mSurfaceTexture = nullptr;
     }
 
-    mozilla::java::GeckoSurface::GlobalRef mSurface;
-    mozilla::gl::AndroidNativeWindow mNativeWindow;
+    RefPtr<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
     gfxRect mDimensions;
   };
 
   void* AcquireVideoWindow();
   void ReleaseVideoWindow(void* aWindow);
   void SetVideoDimensions(void* aWindow, gfxRect aDimensions);
 
   void GetVideos(nsTArray<VideoInfo*>& aVideos);
@@ -356,18 +354,17 @@ protected:
   void PopPostedEvent(PluginEventRunnable* r);
   void OnSurfaceTextureFrameAvailable();
 
   uint32_t mFullScreenOrientation;
   bool mWakeLocked;
   bool mFullScreen;
   mozilla::gl::OriginPos mOriginPos;
 
-  mozilla::java::GeckoSurface::GlobalRef mContentSurface;
-  mozilla::gl::AndroidNativeWindow mContentWindow;
+  RefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
 #endif
 
   enum {
     NOT_STARTED,
     RUNNING,
     DESTROYING,
     DESTROYED
   } mRunning;
@@ -407,17 +404,18 @@ private:
   void* mCurrentPluginEvent;
 #endif
 
   // Timestamp for the last time this plugin was stopped.
   // This is only valid when the plugin is actually stopped!
   mozilla::TimeStamp mStopTime;
 
 #ifdef MOZ_WIDGET_ANDROID
-  mozilla::java::GeckoSurface::LocalRef CreateSurface();
+  already_AddRefed<mozilla::gl::AndroidSurfaceTexture> CreateSurfaceTexture();
+
   std::map<void*, VideoInfo*> mVideos;
   bool mOnScreen;
 
   nsIntSize mCurrentSize;
 #endif
 
   // is this instance Java and affected by bug 750480?
   bool mHaveJavaC2PJSObjectQuirk;
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -160,33 +160,32 @@ nsPluginInstanceOwner::NotifyPaintWaiter
     // receive it immediately
     nsContentUtils::AddScriptRunner(event);
     mWaitingForPaint = true;
   }
 }
 
 #if MOZ_WIDGET_ANDROID
 static void
-AttachToContainerAsSurface(ImageContainer* container,
-                           nsNPAPIPluginInstance* instance,
-                           const LayoutDeviceRect& rect,
-                           RefPtr<Image>* out_image)
+AttachToContainerAsSurfaceTexture(ImageContainer* container,
+                                  nsNPAPIPluginInstance* instance,
+                                  const LayoutDeviceRect& rect,
+                                  RefPtr<Image>* out_image)
 {
   MOZ_ASSERT(out_image);
   MOZ_ASSERT(!*out_image);
 
-  java::GeckoSurface::LocalRef surface = instance->AsSurface();
-  if (!surface) {
+  mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture();
+  if (!surfTex) {
     return;
   }
 
   RefPtr<Image> img = new SurfaceTextureImage(
-    surface->GetHandle(),
+    surfTex,
     gfx::IntSize::Truncate(rect.width, rect.height),
-    true, // continuously update without a transaction
     instance->OriginPos());
   *out_image = img;
 }
 #endif
 
 bool
 nsPluginInstanceOwner::NeedsScrollImageLayer()
 {
@@ -219,17 +218,17 @@ nsPluginInstanceOwner::GetImageContainer
   ScreenSize screenSize = (r * LayoutDeviceToScreenScale(resolution)).Size();
   mInstance->NotifySize(nsIntSize::Truncate(screenSize.width, screenSize.height));
 
   container = LayerManager::CreateImageContainer();
 
   if (r.width && r.height) {
     // Try to get it as an EGLImage first.
     RefPtr<Image> img;
-    AttachToContainerAsSurface(container, mInstance, r, &img);
+    AttachToContainerAsSurfaceTexture(container, mInstance, r, &img);
 
     if (img) {
       container->SetCurrentImageInTransaction(img);
     }
   }
 #else
   if (NeedsScrollImageLayer()) {
     // windowed plugin under e10s
@@ -1581,19 +1580,18 @@ nsPluginInstanceOwner::GetVideos(nsTArra
 
 already_AddRefed<ImageContainer>
 nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo)
 {
   RefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
 
   if (aVideoInfo->mDimensions.width && aVideoInfo->mDimensions.height) {
     RefPtr<Image> img = new SurfaceTextureImage(
-      aVideoInfo->mSurface->GetHandle(),
+      aVideoInfo->mSurfaceTexture,
       gfx::IntSize::Truncate(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height),
-      true, /* continuous */
       gl::OriginPos::BottomLeft);
     container->SetCurrentImageInTransaction(img);
   }
 
   return container.forget();
 }
 
 void nsPluginInstanceOwner::Invalidate() {
--- a/gfx/gl/AndroidNativeWindow.h
+++ b/gfx/gl/AndroidNativeWindow.h
@@ -14,19 +14,16 @@
 #include "GeneratedJNIWrappers.h"
 #include "SurfaceTexture.h"
 
 namespace mozilla {
 namespace gl {
 
 class AndroidNativeWindow {
 public:
-  AndroidNativeWindow() : mNativeWindow(nullptr) {
-  }
-
   AndroidNativeWindow(java::sdk::Surface::Param aSurface) {
     mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
                                               aSurface.Get());
   }
 
   AndroidNativeWindow(java::GeckoSurface::Param aSurface) {
     auto surf = java::sdk::Surface::LocalRef(java::sdk::Surface::Ref::From(aSurface));
     mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java
@@ -12,22 +12,20 @@ import android.graphics.SurfaceTexture;
 
 final class SurfaceTextureListener
     extends JNIObject implements SurfaceTexture.OnFrameAvailableListener
 {
     @WrapForJNI(calledFrom = "gecko")
     private SurfaceTextureListener() {
     }
 
-    @WrapForJNI(dispatchTo = "gecko") @Override // JNIObject
-    protected native void disposeNative();
-
     @Override
-    protected void finalize() {
-        disposeNative();
+    protected void disposeNative() {
+        // SurfaceTextureListener is disposed inside AndroidSurfaceTexture.
+        throw new IllegalStateException("unreachable code");
     }
 
     @WrapForJNI(stubName = "OnFrameAvailable")
     private native void nativeOnFrameAvailable();
 
     @Override // SurfaceTexture.OnFrameAvailableListener
     public void onFrameAvailable(SurfaceTexture surfaceTexture) {
         try {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/JNIObject.java
@@ -2,15 +2,10 @@ package org.mozilla.gecko.mozglue;
 
 // Class that all classes with native methods extend from.
 public abstract class JNIObject
 {
     // Pointer to a WeakPtr object that refers to the native object.
     private long mHandle;
 
     // Dispose of any reference to a native object.
-    //
-    // If the native instance is destroyed from the native side, this should never be
-    // called, so you should throw an UnsupportedOperationException. If instead you
-    // want to destroy the native side from the Java end, make override this with
-    // a native call, and the right thing will be done in the native code.
     protected abstract void disposeNative();
 }
--- a/widget/android/jni/Natives.h
+++ b/widget/android/jni/Natives.h
@@ -39,17 +39,17 @@ namespace jni {
  *       // ...
  *
  *   public:
  *       MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MyClass)
  *       using MyJavaClass::Natives<MyClass>::DisposeNative;
  *
  *       void AttachTo(const MyJavaClass::LocalRef& instance)
  *       {
- *           MyJavaClass::Natives<MyClass>::AttachNative(
+ *           MyJavaClass::Natives<MyClass>::AttachInstance(
  *                   instance, static_cast<SupportsWeakPtr<MyClass>*>(this));
  *
  *           // "instance" does NOT own "this", so the C++ object
  *           // lifetime is separate from the Java object lifetime.
  *       }
  *   };
  *
  * * If the C++ class contains public members AddRef() and Release(), the Java
@@ -65,17 +65,17 @@ namespace jni {
  *   {
  *       // ...
  *
  *   public:
  *       using MyJavaClass::Natives<MyClass>::DisposeNative;
  *
  *       void AttachTo(const MyJavaClass::LocalRef& instance)
  *       {
- *           MyJavaClass::Natives<MyClass>::AttachNative(instance, this);
+ *           MyJavaClass::Natives<MyClass>::AttachInstance(instance, this);
  *
  *           // "instance" owns "this" through the RefPtr, so the C++ object
  *           // may be destroyed as soon as instance.disposeNative() is called.
  *       }
  *   };
  *
  * * In other cases, the Java instance will store and own a pointer to the C++
  *   object itself. This pointer must not be stored or deleted elsewhere. To
@@ -86,17 +86,17 @@ namespace jni {
  *   {
  *       // ...
  *
  *   public:
  *       using MyJavaClass::Natives<MyClass>::DisposeNative;
  *
  *       static void AttachTo(const MyJavaClass::LocalRef& instance)
  *       {
- *           MyJavaClass::Natives<MyClass>::AttachNative(
+ *           MyJavaClass::Natives<MyClass>::AttachInstance(
  *                   instance, mozilla::MakeUnique<MyClass>());
  *
  *           // "instance" owns the newly created C++ object, so the C++
  *           // object is destroyed as soon as instance.disposeNative() is
  *           // called.
  *       }
  *   };
  */