Backed out 11 changesets (bug 1322650) for media test failures on android. a=backout
authorIris Hsiao <ihsiao@mozilla.com>
Fri, 12 May 2017 10:21:14 +0800
changeset 406141 a5e2d088c2ed74f9b376492d34f944171fd2eaa7
parent 406140 e2a3ab9f0730a5f2535ae5aee754ce71d430445a
child 406142 9b45f5bd565f3767fa6d3f5fada2e193ddf6eed7
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)
reviewersbackout
bugs1322650
milestone55.0a1
backs out31bd912fba5472349b3b1dd49536e901f5955c05
4d486c7469eba3ee71aa220cb5a95b4e78a51bcb
4cf8f4d5064c46c36ef21ffc0f2f0979c238b89b
3cb108f7492fbd0c84acdb67a7d0e1b8ea2f234a
bd53533c108e4c38eda77d4cba904e2f12042772
3522917d8f1067fea995f38cd6910b76ef263d64
2c2c1e33ecccda814f4bc2504bbe2e833db7eabc
2f19977cd6ab546210e71d17d64377945db4fa44
4519296a323e8c4cf78a71686f538805ce9e1b06
e56e5e1c8786935a8d03bc308622ccfd631b7a15
96fe52231b575c343ed056b432766c67de7d9a5d
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 11 changesets (bug 1322650) for media test failures on android. a=backout Backed out changeset 31bd912fba54 (bug 1322650) Backed out changeset 4d486c7469eb (bug 1322650) Backed out changeset 4cf8f4d5064c (bug 1322650) Backed out changeset 3cb108f7492f (bug 1322650) Backed out changeset bd53533c108e (bug 1322650) Backed out changeset 3522917d8f10 (bug 1322650) Backed out changeset 2c2c1e33eccc (bug 1322650) Backed out changeset 2f19977cd6ab (bug 1322650) Backed out changeset 4519296a323e (bug 1322650) Backed out changeset e56e5e1c8786 (bug 1322650) Backed out changeset 96fe52231b57 (bug 1322650)
dom/media/MediaDecoder.cpp
dom/media/MediaPrefs.h
dom/media/platforms/android/AndroidDecoderModule.cpp
dom/media/platforms/android/RemoteDataDecoder.cpp
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginInstanceOwner.cpp
gfx/gl/AndroidNativeWindow.h
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLContextEGL.h
gfx/gl/GLScreenBuffer.cpp
gfx/gl/SharedSurface.h
gfx/gl/SharedSurfaceEGL.cpp
gfx/gl/SharedSurfaceEGL.h
gfx/gl/SurfaceTypes.h
gfx/gl/moz.build
gfx/layers/GLImages.cpp
gfx/layers/GLImages.h
gfx/layers/client/CanvasClient.cpp
gfx/layers/client/ImageClient.cpp
gfx/layers/composite/TextureHost.h
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
gfx/layers/opengl/TexturePoolOGL.cpp
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/Makefile.in
mobile/android/base/moz.build
mobile/android/geckoview/src/main/AndroidManifest.xml
mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/GeckoSurface.aidl
mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/ISurfaceAllocator.aidl
mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocator.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocatorService.java
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/AndroidBridge.cpp
widget/android/GeneratedJNINatives.h
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/bindings/AndroidBuild-classes.txt
widget/android/bindings/moz.build
widget/android/jni/Natives.h
widget/android/jni/Utils.cpp
widget/android/jni/Utils.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1635,17 +1635,18 @@ MediaDecoder::IsWebMEnabled()
 {
   return Preferences::GetBool("media.webm.enabled");
 }
 
 #ifdef MOZ_ANDROID_OMX
 bool
 MediaDecoder::IsAndroidMediaPluginEnabled()
 {
-  return jni::GetAPIVersion() < 16
+  return AndroidBridge::Bridge()
+         && AndroidBridge::Bridge()->GetAPIVersion() < 16
          && Preferences::GetBool("media.plugins.enabled");
 }
 #endif
 
 NS_IMETHODIMP
 MediaMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
                                    nsISupports* aData, bool aAnonymize)
 {
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -2,17 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MEDIA_PREFS_H
 #define MEDIA_PREFS_H
 
 #ifdef MOZ_WIDGET_ANDROID
-#include "GeneratedJNIWrappers.h"
+#include "AndroidBridge.h"
 #endif
 
 #include "mozilla/Atomics.h"
 
 // First time MediaPrefs::GetSingleton() needs to be called on the main thread,
 // before any of the methods accessing the values are used, but after
 // the Preferences system has been initialized.
 
@@ -194,17 +194,18 @@ public:
 private:
   template<class T> friend class StaticAutoPtr;
   static StaticAutoPtr<MediaPrefs> sInstance;
 
   // Default value functions
   static int32_t MediaDecoderLimitDefault()
   {
 #ifdef MOZ_WIDGET_ANDROID
-    if (jni::GetAPIVersion() < 18) {
+    if (AndroidBridge::Bridge() &&
+        AndroidBridge::Bridge()->GetAPIVersion() < 18) {
       // Older Android versions have broken support for multiple simultaneous
       // decoders, see bug 1278574.
       return 1;
     }
 #endif
     // Otherwise, set no decoder limit.
     return -1;
   }
--- a/dom/media/platforms/android/AndroidDecoderModule.cpp
+++ b/dom/media/platforms/android/AndroidDecoderModule.cpp
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "GeneratedJNIWrappers.h"
+#include "AndroidDecoderModule.h"
+#include "AndroidBridge.h"
 #include "MediaInfo.h"
 #include "MediaPrefs.h"
 #include "OpusDecoder.h"
 #include "RemoteDataDecoder.h"
 #include "VPXDecoder.h"
 #include "VorbisDecoder.h"
 
 #include "nsIGfxInfo.h"
@@ -122,17 +123,18 @@ AndroidDecoderModule::AndroidDecoderModu
   mProxy = static_cast<MediaDrmCDMProxy*>(aProxy);
 }
 
 bool
 AndroidDecoderModule::SupportsMimeType(
   const nsACString& aMimeType,
   DecoderDoctorDiagnostics* aDiagnostics) const
 {
-  if (jni::GetAPIVersion() < 16) {
+  if (!AndroidBridge::Bridge() ||
+      AndroidBridge::Bridge()->GetAPIVersion() < 16) {
     return false;
   }
 
   if (aMimeType.EqualsLiteral("video/mp4") ||
       aMimeType.EqualsLiteral("video/avc")) {
     return true;
   }
 
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AndroidBridge.h"
 #include "AndroidDecoderModule.h"
+#include "AndroidSurfaceTexture.h"
 #include "JavaCallbacksSupport.h"
 #include "SimpleMap.h"
 #include "GLImages.h"
 #include "MediaData.h"
 #include "MediaInfo.h"
 #include "VideoUtils.h"
 #include "VPXDecoder.h"
 
@@ -128,17 +129,17 @@ public:
       InputInfo inputInfo;
       if (!mDecoder->mInputInfos.Find(presentationTimeUs, inputInfo)
           && !isEOS) {
         return;
       }
 
       if (size > 0) {
         RefPtr<layers::Image> img = new SurfaceTextureImage(
-          mDecoder->mSurfaceHandle, inputInfo.mImageSize, false /* NOT continuous */,
+          mDecoder->mSurfaceTexture.get(), inputInfo.mImageSize,
           gl::OriginPos::BottomLeft);
 
         RefPtr<VideoData> v = VideoData::CreateFromImage(
           inputInfo.mDisplaySize, offset,
           TimeUnit::FromMicroseconds(presentationTimeUs),
           TimeUnit::FromMicroseconds(inputInfo.mDurationUs),
           img, !!(flags & MediaCodec::BUFFER_FLAG_SYNC_FRAME),
           TimeUnit::FromMicroseconds(presentationTimeUs));
@@ -171,34 +172,39 @@ public:
                         aFormat, aDrmStubId, aTaskQueue)
     , mImageContainer(aImageContainer)
     , mConfig(aConfig)
   {
   }
 
   RefPtr<InitPromise> Init() override
   {
-    jni::Object::LocalRef surf = SurfaceAllocator::AcquireSurface(mConfig.mImage.width, mConfig.mImage.height, false);
-    if (!surf) {
-      return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__);
+    mSurfaceTexture = AndroidSurfaceTexture::Create();
+    if (!mSurfaceTexture) {
+      NS_WARNING("Failed to create SurfaceTexture for video decode\n");
+      return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                                          __func__);
     }
 
-    mSurfaceHandle = GeckoSurface::LocalRef(GeckoSurface::Ref::From(surf))->GetHandle();
+    if (!jni::IsFennec()) {
+      NS_WARNING("Remote decoding not supported in non-Fennec environment\n");
+      return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                                          __func__);
+    }
 
     // Register native methods.
     JavaCallbacksSupport::Init();
 
     mJavaCallbacks = CodecProxy::NativeCallbacks::New();
     JavaCallbacksSupport::AttachNative(
       mJavaCallbacks, mozilla::MakeUnique<CallbacksSupport>(this));
 
-    auto surfRef = Surface::LocalRef(Surface::Ref::From(surf));
     mJavaDecoder = CodecProxy::Create(false, // false indicates to create a decoder and true denotes encoder
                                       mFormat,
-                                      surfRef,
+                                      mSurfaceTexture->JavaSurface(),
                                       mJavaCallbacks,
                                       mDrmStubId);
     if (mJavaDecoder == nullptr) {
       return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                                           __func__);
     }
     mIsCodecSupportAdaptivePlayback =
       mJavaDecoder->IsAdaptivePlaybackSupported();
@@ -228,17 +234,17 @@ public:
   bool SupportDecoderRecycling() const override
   {
     return mIsCodecSupportAdaptivePlayback;
   }
 
 private:
   layers::ImageContainer* mImageContainer;
   const VideoInfo mConfig;
-  AndroidSurfaceTextureHandle mSurfaceHandle;
+  RefPtr<AndroidSurfaceTexture> mSurfaceTexture;
   SimpleMap<InputInfo> mInputInfos;
   bool mIsCodecSupportAdaptivePlayback = false;
 };
 
 class RemoteAudioDecoder : public RemoteDataDecoder
 {
 public:
   RemoteAudioDecoder(const AudioInfo& aConfig,
@@ -400,16 +406,17 @@ RemoteDataDecoder::CreateAudioDecoder(co
   return decoder.forget();
 }
 
 already_AddRefed<MediaDataDecoder>
 RemoteDataDecoder::CreateVideoDecoder(const CreateDecoderParams& aParams,
                                       const nsString& aDrmStubId,
                                       CDMProxy* aProxy)
 {
+
   const VideoInfo& config = aParams.VideoConfig();
   MediaFormat::LocalRef format;
   NS_ENSURE_SUCCESS(
     MediaFormat::CreateVideoFormat(TranslateMimeType(config.mMimeType),
                                    config.mDisplay.width,
                                    config.mDisplay.height,
                                    &format),
     nullptr);
--- 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() {
deleted file mode 100644
--- a/gfx/gl/AndroidNativeWindow.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-// vim:set ts=2 sts=2 sw=2 et cin:
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef AndroidNativeWindow_h__
-#define AndroidNativeWindow_h__
-#ifdef MOZ_WIDGET_ANDROID
-
-#include <jni.h>
-#include <android/native_window.h>
-#include <android/native_window_jni.h>
-#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(),
-                                              surf.Get());
-  }
-
-  ~AndroidNativeWindow() {
-    if (mNativeWindow) {
-      ANativeWindow_release(mNativeWindow);
-      mNativeWindow = nullptr;
-    }
-  }
-
-  ANativeWindow* NativeWindow() const {
-    return mNativeWindow;
-  }
-
-private:
-  ANativeWindow* mNativeWindow;
-};
-
-} // gl
-} // mozilla
-
-#endif // MOZ_WIDGET_ANDROID
-#endif // AndroidNativeWindow_h__
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -1,25 +1,209 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+// vim:set ts=2 sts=2 sw=2 et cin:
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
 #ifdef MOZ_WIDGET_ANDROID
 
+#include <map>
+#include <android/native_window_jni.h>
+#include <android/log.h>
 #include "AndroidSurfaceTexture.h"
+#include "gfxImageSurface.h"
+#include "gfxPrefs.h"
+#include "AndroidBridge.h"
+#include "nsThreadUtils.h"
+#include "mozilla/gfx/Matrix.h"
+#include "GeneratedJNINatives.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 namespace mozilla {
 namespace gl {
 
+class AndroidSurfaceTexture::Listener
+  : public java::SurfaceTextureListener::Natives<Listener>
+{
+  using Base = java::SurfaceTextureListener::Natives<Listener>;
+
+  const nsCOMPtr<nsIRunnable> mCallback;
+
+public:
+  using Base::AttachNative;
+  using Base::DisposeNative;
+
+  Listener(nsIRunnable* aCallback) : mCallback(aCallback) {}
+
+  void OnFrameAvailable()
+  {
+    if (NS_IsMainThread()) {
+      mCallback->Run();
+      return;
+    }
+    NS_DispatchToMainThread(mCallback);
+  }
+};
+
+already_AddRefed<AndroidSurfaceTexture>
+AndroidSurfaceTexture::Create()
+{
+  return Create(nullptr, 0);
+}
+
+already_AddRefed<AndroidSurfaceTexture>
+AndroidSurfaceTexture::Create(GLContext* aContext, GLuint aTexture)
+{
+  RefPtr<AndroidSurfaceTexture> st = new AndroidSurfaceTexture();
+  if (!st->Init(aContext, aTexture)) {
+    printf_stderr("Failed to initialize AndroidSurfaceTexture");
+    st = nullptr;
+  }
+
+  return st.forget();
+}
+
+nsresult
+AndroidSurfaceTexture::Attach(GLContext* aContext, PRIntervalTime aTimeout)
+{
+  MonitorAutoLock lock(mMonitor);
+
+  if (mAttachedContext == aContext) {
+    NS_WARNING("Tried to attach same GLContext to AndroidSurfaceTexture");
+    return NS_OK;
+  }
+
+  if (!CanDetach()) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
+  while (mAttachedContext) {
+    // Wait until it's detached (or we time out)
+    if (NS_FAILED(lock.Wait(aTimeout))) {
+      return NS_ERROR_NOT_AVAILABLE;
+    }
+  }
+
+  MOZ_ASSERT(aContext->IsOwningThreadCurrent(), "Trying to attach GLContext from different thread");
+
+  aContext->fGenTextures(1, &mTexture);
+
+  if (NS_FAILED(mSurfaceTexture->AttachToGLContext(mTexture))) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+  mAttachedContext = aContext;
+  mAttachedContext->MakeCurrent();
+
+  return NS_OK;
+}
+
+nsresult
+AndroidSurfaceTexture::Detach()
+{
+  MonitorAutoLock lock(mMonitor);
+
+  if (!CanDetach() ||
+      !mAttachedContext ||
+      !mAttachedContext->IsOwningThreadCurrent())
+  {
+    return NS_ERROR_FAILURE;
+  }
+
+  mAttachedContext->MakeCurrent();
+
+  mSurfaceTexture->DetachFromGLContext();
+
+  mTexture = 0;
+  mAttachedContext = nullptr;
+  lock.NotifyAll();
+  return NS_OK;
+}
+
+bool
+AndroidSurfaceTexture::CanDetach() const
+{
+  // The API for attach/detach only exists on 16+, and PowerVR has some sort of
+  // fencing issue. Additionally, attach/detach seems to be busted on at least
+  // some Mali adapters (400MP2 for sure, bug 1131793)
+  return AndroidBridge::Bridge()->GetAPIVersion() >= 16 &&
+    (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::Imagination) &&
+    (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::ARM /* Mali */) &&
+    gfxPrefs::SurfaceTextureDetachEnabled();
+}
+
+bool
+AndroidSurfaceTexture::Init(GLContext* aContext, GLuint aTexture)
+{
+
+  if (!aTexture && !CanDetach()) {
+    // We have no texture and cannot initialize detached, bail out
+    return false;
+  }
+
+  if (NS_WARN_IF(NS_FAILED(
+      java::sdk::SurfaceTexture::New(aTexture, ReturnTo(&mSurfaceTexture))))) {
+    return false;
+  }
+
+  if (!aTexture) {
+    mSurfaceTexture->DetachFromGLContext();
+  }
+
+  mAttachedContext = aContext;
+
+  if (NS_WARN_IF(NS_FAILED(
+      java::sdk::Surface::New(mSurfaceTexture, ReturnTo(&mSurface))))) {
+    return false;
+  }
+
+  mNativeWindow = ANativeWindow_fromSurface(jni::GetEnvForThread(),
+                                            mSurface.Get());
+  MOZ_ASSERT(mNativeWindow, "Failed to create native window from surface");
+
+  return true;
+}
+
+AndroidSurfaceTexture::AndroidSurfaceTexture()
+  : mTexture(0)
+  , mSurfaceTexture()
+  , mSurface()
+  , mAttachedContext(nullptr)
+  , mMonitor("AndroidSurfaceTexture")
+{
+}
+
+AndroidSurfaceTexture::~AndroidSurfaceTexture()
+{
+  if (mSurfaceTexture) {
+    SetFrameAvailableCallback(nullptr);
+    mSurfaceTexture = nullptr;
+  }
+
+  if (mNativeWindow) {
+    ANativeWindow_release(mNativeWindow);
+    mNativeWindow = nullptr;
+  }
+}
+
 void
-AndroidSurfaceTexture::GetTransformMatrix(java::sdk::SurfaceTexture::LocalRef aSurfaceTexture,
-                                          gfx::Matrix4x4& aMatrix)
+AndroidSurfaceTexture::UpdateTexImage()
+{
+  mSurfaceTexture->UpdateTexImage();
+}
+
+void
+AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix) const
 {
   JNIEnv* const env = jni::GetEnvForThread();
 
   auto jarray = jni::FloatArray::LocalRef::Adopt(env, env->NewFloatArray(16));
-  aSurfaceTexture->GetTransformMatrix(jarray);
+  mSurfaceTexture->GetTransformMatrix(jarray);
 
   jfloat* array = env->GetFloatArrayElements(jarray.Get(), nullptr);
 
   aMatrix._11 = array[0];
   aMatrix._12 = array[1];
   aMatrix._13 = array[2];
   aMatrix._14 = array[3];
 
@@ -36,11 +220,41 @@ AndroidSurfaceTexture::GetTransformMatri
   aMatrix._41 = array[12];
   aMatrix._42 = array[13];
   aMatrix._43 = array[14];
   aMatrix._44 = array[15];
 
   env->ReleaseFloatArrayElements(jarray.Get(), array, 0);
 }
 
+void
+AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
+{
+  java::SurfaceTextureListener::LocalRef newListener;
+
+  if (aRunnable) {
+    newListener = java::SurfaceTextureListener::New();
+    Listener::AttachNative(newListener, MakeUnique<Listener>(aRunnable));
+  }
+
+  if (aRunnable || mListener) {
+    MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
+        mSurfaceTexture->SetOnFrameAvailableListener(newListener)));
+  }
+
+  if (mListener) {
+    Listener::DisposeNative(java::SurfaceTextureListener::LocalRef(
+        newListener.Env(), mListener));
+  }
+
+  mListener = newListener;
+}
+
+void
+AndroidSurfaceTexture::SetDefaultSize(mozilla::gfx::IntSize size)
+{
+  mSurfaceTexture->SetDefaultBufferSize(size.width, size.height);
+}
+
 } // gl
 } // mozilla
+
 #endif // MOZ_WIDGET_ANDROID
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -3,28 +3,105 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef AndroidSurfaceTexture_h__
 #define AndroidSurfaceTexture_h__
 #ifdef MOZ_WIDGET_ANDROID
 
-#include "mozilla/gfx/Matrix.h"
+#include <jni.h>
+#include <android/native_window.h>
+#include "nsIRunnable.h"
+#include "gfxPlatform.h"
+#include "GLDefs.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/MatrixFwd.h"
+#include "mozilla/Monitor.h"
+
+#include "GeneratedJNIWrappers.h"
 #include "SurfaceTexture.h"
 
-typedef uint32_t AndroidSurfaceTextureHandle;
-
 namespace mozilla {
 namespace gl {
 
+class GLContext;
+
+/**
+ * This class is a wrapper around Android's SurfaceTexture class.
+ * Usage is pretty much exactly like the Java class, so see
+ * the Android documentation for details.
+ */
 class AndroidSurfaceTexture {
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSurfaceTexture)
+
 public:
-  static void GetTransformMatrix(java::sdk::SurfaceTexture::LocalRef aSurfaceTexture,
-                                 mozilla::gfx::Matrix4x4& aMatrix);
+
+  // The SurfaceTexture is created in an attached state. This method requires
+  // Android Ice Cream Sandwich.
+  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();
+
+  // 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);
+
+  nsresult Detach();
+
+  // Ability to detach is based on API version (16+), and we also block PowerVR
+  // since it has some type of fencing problem. Bug 1100126.
+  bool CanDetach() const;
+
+  GLContext* AttachedContext() const { return mAttachedContext; }
+
+  ANativeWindow* NativeWindow() const {
+    return mNativeWindow;
+  }
 
+  // This attaches the updated data to the TEXTURE_EXTERNAL target
+  void UpdateTexImage();
+
+  void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix) const;
+
+  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);
+
+  GLuint Texture() const { return mTexture; }
+  const java::sdk::Surface::Ref& JavaSurface() const { return mSurface; }
+
+private:
+  class Listener;
+
+  AndroidSurfaceTexture();
+  ~AndroidSurfaceTexture();
+
+  bool Init(GLContext* aContext, GLuint aTexture);
+
+  GLuint mTexture;
+  java::sdk::SurfaceTexture::GlobalRef mSurfaceTexture;
+  java::sdk::Surface::GlobalRef mSurface;
+  java::SurfaceTextureListener::GlobalRef mListener;
+
+  GLContext* mAttachedContext;
+
+  ANativeWindow* mNativeWindow;
+
+  Monitor mMonitor;
 };
 
-} // gl
-} // mozilla
+}
+}
 
-#endif // MOZ_WIDGET_ANDROID
-#endif // AndroidSurfaceTexture_h__
+
+#endif
+#endif
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -679,18 +679,40 @@ GLBlitHelper::BindAndUploadEGLImage(EGLI
 
 #ifdef MOZ_WIDGET_ANDROID
 
 #define ATTACH_WAIT_MS 50
 
 bool
 GLBlitHelper::BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage)
 {
-    // FIXME
-    return false;
+    AndroidSurfaceTexture* surfaceTexture = stImage->GetSurfaceTexture();
+
+    ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0);
+
+    if (NS_FAILED(surfaceTexture->Attach(mGL, PR_MillisecondsToInterval(ATTACH_WAIT_MS))))
+        return false;
+
+    // UpdateTexImage() changes the EXTERNAL binding, so save it here
+    // so we can restore it after.
+    int oldBinding = 0;
+    mGL->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_EXTERNAL, &oldBinding);
+
+    surfaceTexture->UpdateTexImage();
+
+    gfx::Matrix4x4 transform;
+    surfaceTexture->GetTransformMatrix(transform);
+
+    mGL->fUniformMatrix4fv(mTextureTransformLoc, 1, false, &transform._11);
+    mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
+
+    surfaceTexture->Detach();
+
+    mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, oldBinding);
+    return true;
 }
 
 bool
 GLBlitHelper::BlitEGLImageImage(layers::EGLImageImage* image)
 {
     EGLImage eglImage = image->GetImage();
     EGLSync eglSync = image->GetSync();
 
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -64,19 +64,16 @@ public:
         return sEGLLibrary.IsWARP();
     }
 
     virtual bool BindTexImage() override;
 
     virtual bool ReleaseTexImage() override;
 
     void SetEGLSurfaceOverride(EGLSurface surf);
-    EGLSurface GetEGLSurfaceOverride() {
-        return mSurfaceOverride;
-    }
 
     virtual bool MakeCurrentImpl(bool aForce) override;
 
     virtual bool IsCurrent() override;
 
     virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
 
     virtual void ReleaseSurface() override;
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -85,22 +85,16 @@ GLScreenBuffer::CreateFactory(GLContext*
             case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
 #if defined(XP_MACOSX)
                 factory = SurfaceFactory_IOSurface::Create(gl, caps, ipcChannel, flags);
 #elif defined(GL_PROVIDER_GLX)
                 if (sGLXLibrary.UseTextureFromPixmap())
                   factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags);
 #elif defined(MOZ_WIDGET_UIKIT)
                 factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, caps, ipcChannel, mFlags);
-#elif defined(MOZ_WIDGET_ANDROID)
-                if (XRE_IsParentProcess()) {
-                    factory = SurfaceFactory_EGLImage::Create(gl, caps, ipcChannel, flags);
-                } else {
-                    factory = SurfaceFactory_SurfaceTexture::Create(gl, caps, ipcChannel, flags);
-                }
 #else
                 if (gl->GetContextType() == GLContextType::EGL) {
                     if (XRE_IsParentProcess()) {
                         factory = SurfaceFactory_EGLImage::Create(gl, caps, ipcChannel, flags);
                     }
                 }
 #endif
                 break;
--- a/gfx/gl/SharedSurface.h
+++ b/gfx/gl/SharedSurface.h
@@ -91,20 +91,16 @@ public:
 
     // This locks the SharedSurface as the production buffer for the context.
     // This is needed by backends which use PBuffers and/or EGLSurfaces.
     void LockProd();
 
     // Unlocking is harmless if we're already unlocked.
     void UnlockProd();
 
-    // This surface has been moved to the front buffer and will not be locked again
-    // until it is recycled. Do any finalization steps here.
-    virtual void Commit(){}
-
 protected:
     virtual void LockProdImpl() = 0;
     virtual void UnlockProdImpl() = 0;
 
     virtual void ProducerAcquireImpl() = 0;
     virtual void ProducerReleaseImpl() = 0;
     virtual void ProducerReadAcquireImpl() { ProducerAcquireImpl(); }
     virtual void ProducerReadReleaseImpl() { ProducerReleaseImpl(); }
--- a/gfx/gl/SharedSurfaceEGL.cpp
+++ b/gfx/gl/SharedSurfaceEGL.cpp
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SharedSurfaceEGL.h"
 
 #include "GLBlitHelper.h"
 #include "GLContextEGL.h"
-#include "GLContextProvider.h"
 #include "GLLibraryEGL.h"
 #include "GLReadTexImageHelper.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
 #include "SharedSurface.h"
 
 namespace mozilla {
 namespace gl {
 
@@ -96,16 +95,22 @@ SharedSurface_EGLImage::~SharedSurface_E
 
     if (!mGL || !mGL->MakeCurrent())
         return;
 
     mGL->fDeleteTextures(1, &mProdTex);
     mProdTex = 0;
 }
 
+layers::TextureFlags
+SharedSurface_EGLImage::GetTextureFlags() const
+{
+    return layers::TextureFlags::DEALLOCATE_CLIENT;
+}
+
 void
 SharedSurface_EGLImage::ProducerReleaseImpl()
 {
     MutexAutoLock lock(mMutex);
     mGL->MakeCurrent();
 
     if (mEGL->IsExtensionSupported(GLLibraryEGL::KHR_fence_sync) &&
         mGL->IsExtensionSupported(GLContext::OES_EGL_sync))
@@ -175,141 +180,11 @@ SurfaceFactory_EGLImage::Create(GLContex
     GLLibraryEGL* egl = &sEGLLibrary;
     if (SharedSurface_EGLImage::HasExtensions(egl, prodGL)) {
         ret.reset( new ptrT(prodGL, caps, allocator, flags, context) );
     }
 
     return Move(ret);
 }
 
-////////////////////////////////////////////////////////////////////////
-
-#ifdef MOZ_WIDGET_ANDROID
-
-/*static*/ UniquePtr<SharedSurface_SurfaceTexture>
-SharedSurface_SurfaceTexture::Create(GLContext* prodGL,
-                                     const GLFormats& formats,
-                                     const gfx::IntSize& size,
-                                     bool hasAlpha,
-                                     java::GeckoSurface::Param surface)
-{
-    MOZ_ASSERT(surface);
-
-    UniquePtr<SharedSurface_SurfaceTexture> ret;
-
-    AndroidNativeWindow window(surface);
-    EGLSurface eglSurface = GLContextProviderEGL::CreateEGLSurface(window.NativeWindow());
-    if (!eglSurface) {
-        return Move(ret);
-    }
-
-    ret.reset(new SharedSurface_SurfaceTexture(prodGL, size, hasAlpha,
-                                               formats, surface, eglSurface));
-    return Move(ret);
-}
-
-SharedSurface_SurfaceTexture::SharedSurface_SurfaceTexture(GLContext* gl,
-                                                           const gfx::IntSize& size,
-                                                           bool hasAlpha,
-                                                           const GLFormats& formats,
-                                                           java::GeckoSurface::Param surface,
-                                                           EGLSurface eglSurface)
-    : SharedSurface(SharedSurfaceType::AndroidSurfaceTexture,
-                    AttachmentType::Screen,
-                    gl,
-                    size,
-                    hasAlpha,
-                    true)
-    , mSurface(surface)
-    , mEglSurface(eglSurface)
-{
-}
-
-SharedSurface_SurfaceTexture::~SharedSurface_SurfaceTexture()
-{
-    GLContextProviderEGL::DestroyEGLSurface(mEglSurface);
-    java::SurfaceAllocator::DisposeSurface(mSurface);
-}
-
-void
-SharedSurface_SurfaceTexture::LockProdImpl()
-{
-    MOZ_RELEASE_ASSERT(mSurface->GetAvailable());
-
-    GLContextEGL *gl = GLContextEGL::Cast(mGL);
-    mOrigEglSurface = gl->GetEGLSurfaceOverride();
-    gl->SetEGLSurfaceOverride(mEglSurface);
-}
-
-void
-SharedSurface_SurfaceTexture::UnlockProdImpl()
-{
-    MOZ_RELEASE_ASSERT(mSurface->GetAvailable());
-
-    GLContextEGL *gl = GLContextEGL::Cast(mGL);
-    MOZ_ASSERT(gl->GetEGLSurfaceOverride() == mEglSurface);
-
-    gl->SetEGLSurfaceOverride(mOrigEglSurface);
-    mOrigEglSurface = nullptr;
-}
-
-void
-SharedSurface_SurfaceTexture::Commit()
-{
-    MOZ_RELEASE_ASSERT(mSurface->GetAvailable());
-
-    LockProdImpl();
-    mGL->SwapBuffers();
-    UnlockProdImpl();
-    mSurface->SetAvailable(false);
-}
-
-void
-SharedSurface_SurfaceTexture::WaitForBufferOwnership()
-{
-    MOZ_RELEASE_ASSERT(!mSurface->GetAvailable());
-    mSurface->SetAvailable(true);
-}
-
-bool
-SharedSurface_SurfaceTexture::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
-{
-    *out_descriptor = layers::SurfaceTextureDescriptor(mSurface->GetHandle(), mSize, false /* NOT continuous */);
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-/*static*/ UniquePtr<SurfaceFactory_SurfaceTexture>
-SurfaceFactory_SurfaceTexture::Create(GLContext* prodGL, const SurfaceCaps& caps,
-                                      const RefPtr<layers::LayersIPCChannel>& allocator,
-                                      const layers::TextureFlags& flags)
-{
-    UniquePtr<SurfaceFactory_SurfaceTexture> ret(
-        new SurfaceFactory_SurfaceTexture(prodGL, caps, allocator, flags));
-    return Move(ret);
-}
-
-UniquePtr<SharedSurface>
-SurfaceFactory_SurfaceTexture::CreateShared(const gfx::IntSize& size)
-{
-    bool hasAlpha = mReadCaps.alpha;
-
-    jni::Object::LocalRef surface = java::SurfaceAllocator::AcquireSurface(size.width, size.height, true);
-    if (!surface) {
-        // Try multi-buffer mode
-        surface = java::SurfaceAllocator::AcquireSurface(size.width, size.height, false);
-        if (!surface) {
-            // Give up
-            NS_WARNING("Failed to allocate SurfaceTexture!");
-            return nullptr;
-        }
-    }
-
-    return SharedSurface_SurfaceTexture::Create(mGL, mFormats, size, hasAlpha,
-                                                java::GeckoSurface::Ref::From(surface));
-}
-
-#endif // MOZ_WIDGET_ANDROID
-
 } // namespace gl
 
 } /* namespace mozilla */
--- a/gfx/gl/SharedSurfaceEGL.h
+++ b/gfx/gl/SharedSurfaceEGL.h
@@ -5,21 +5,16 @@
 
 #ifndef SHARED_SURFACE_EGL_H_
 #define SHARED_SURFACE_EGL_H_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 #include "SharedSurface.h"
 
-#ifdef MOZ_WIDGET_ANDROID
-#include "GeneratedJNIWrappers.h"
-#include "AndroidNativeWindow.h"
-#endif
-
 namespace mozilla {
 namespace gl {
 
 class GLContext;
 class GLLibraryEGL;
 
 class SharedSurface_EGLImage
     : public SharedSurface
@@ -58,19 +53,17 @@ protected:
                            EGLImage image);
 
     EGLDisplay Display() const;
     void UpdateProdTexture(const MutexAutoLock& curAutoLock);
 
 public:
     virtual ~SharedSurface_EGLImage();
 
-    virtual layers::TextureFlags GetTextureFlags() const override {
-      return layers::TextureFlags::DEALLOCATE_CLIENT;
-    }
+    virtual layers::TextureFlags GetTextureFlags() const override;
 
     virtual void LockProdImpl() override {}
     virtual void UnlockProdImpl() override {}
 
     virtual void ProducerAcquireImpl() override {}
     virtual void ProducerReleaseImpl() override;
 
     virtual void ProducerReadAcquireImpl() override;
@@ -112,97 +105,13 @@ protected:
 
 public:
     virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
         bool hasAlpha = mReadCaps.alpha;
         return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
     }
 };
 
-#ifdef MOZ_WIDGET_ANDROID
-
-class SharedSurface_SurfaceTexture
-    : public SharedSurface
-{
-public:
-    static UniquePtr<SharedSurface_SurfaceTexture> Create(GLContext* prodGL,
-                                                          const GLFormats& formats,
-                                                          const gfx::IntSize& size,
-                                                          bool hasAlpha,
-                                                          java::GeckoSurface::Param surface);
-
-    static SharedSurface_SurfaceTexture* Cast(SharedSurface* surf) {
-        MOZ_ASSERT(surf->mType == SharedSurfaceType::AndroidSurfaceTexture);
-
-        return (SharedSurface_SurfaceTexture*)surf;
-    }
-
-    java::GeckoSurface::Param JavaSurface() { return mSurface; }
-
-protected:
-    java::GeckoSurface::GlobalRef mSurface;
-    EGLSurface mEglSurface;
-    EGLSurface mOrigEglSurface;
-
-    SharedSurface_SurfaceTexture(GLContext* gl,
-                                 const gfx::IntSize& size,
-                                 bool hasAlpha,
-                                 const GLFormats& formats,
-                                 java::GeckoSurface::Param surface,
-                                 EGLSurface eglSurface);
-
-public:
-    virtual ~SharedSurface_SurfaceTexture();
-
-    virtual layers::TextureFlags GetTextureFlags() const override {
-      return layers::TextureFlags::DEALLOCATE_CLIENT;
-    }
-
-    virtual void LockProdImpl() override;
-    virtual void UnlockProdImpl() override;
-
-    virtual void ProducerAcquireImpl() override {}
-    virtual void ProducerReleaseImpl() override {}
-
-    virtual void ProducerReadAcquireImpl() override {}
-    virtual void ProducerReadReleaseImpl() override {}
-
-    // Implementation-specific functions below:
-    // Returns texture and target
-    virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
-
-    virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override { return false; }
-
-    virtual void Commit() override;
-
-    virtual void WaitForBufferOwnership() override;
-};
-
-
-
-class SurfaceFactory_SurfaceTexture
-    : public SurfaceFactory
-{
-public:
-    // Fallible:
-    static UniquePtr<SurfaceFactory_SurfaceTexture> Create(GLContext* prodGL,
-                                                           const SurfaceCaps& caps,
-                                                           const RefPtr<layers::LayersIPCChannel>& allocator,
-                                                           const layers::TextureFlags& flags);
-
-protected:
-    SurfaceFactory_SurfaceTexture(GLContext* prodGL, const SurfaceCaps& caps,
-                            const RefPtr<layers::LayersIPCChannel>& allocator,
-                            const layers::TextureFlags& flags)
-        : SurfaceFactory(SharedSurfaceType::AndroidSurfaceTexture, prodGL, caps, allocator, flags)
-    { }
-
-public:
-    virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override;
-};
-
-#endif // MOZ_WIDGET_ANDROID
-
 } // namespace gl
 
 } /* namespace mozilla */
 
 #endif /* SHARED_SURFACE_EGL_H_ */
--- a/gfx/gl/SurfaceTypes.h
+++ b/gfx/gl/SurfaceTypes.h
@@ -72,17 +72,16 @@ enum class SharedSurfaceType : uint8_t {
     Basic,
     EGLImageShare,
     EGLSurfaceANGLE,
     DXGLInterop,
     DXGLInterop2,
     IOSurface,
     GLXDrawable,
     SharedGLTexture,
-    AndroidSurfaceTexture,
 
     Max
 };
 
 enum class AttachmentType : uint8_t {
     Screen = 0,
 
     GLTexture,
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -19,17 +19,16 @@ elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT
         gl_provider = 'GLX'
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     gl_provider = 'EGL'
 
 if CONFIG['MOZ_GL_PROVIDER']:
     gl_provider = CONFIG['MOZ_GL_PROVIDER']
 
 EXPORTS += [
-    'AndroidNativeWindow.h',
     'AndroidSurfaceTexture.h',
     'DecomposeIntoNoRepeatTriangles.h',
     'EGLUtils.h',
     'ForceDiscreteGPUHelperCGL.h',
     'GfxTexturesReporter.h',
     'GLBlitHelper.h',
     'GLConsts.h',
     'GLContext.h',
--- a/gfx/layers/GLImages.cpp
+++ b/gfx/layers/GLImages.cpp
@@ -93,24 +93,21 @@ GLImage::GetAsSourceSurface()
   }
 
   ScopedBindFramebuffer bind(sSnapshotContext, autoFBForTex.FB());
   ReadPixelsIntoDataSurface(sSnapshotContext, source);
   return source.forget();
 }
 
 #ifdef MOZ_WIDGET_ANDROID
-SurfaceTextureImage::SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
+SurfaceTextureImage::SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex,
                                          const gfx::IntSize& aSize,
-                                         bool aContinuous,
                                          gl::OriginPos aOriginPos)
  : GLImage(ImageFormat::SURFACE_TEXTURE),
-   mHandle(aHandle),
+   mSurfaceTexture(aSurfTex),
    mSize(aSize),
-   mContinuous(aContinuous),
    mOriginPos(aOriginPos)
 {
-  MOZ_ASSERT(mHandle);
 }
 #endif
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/GLImages.h
+++ b/gfx/layers/GLImages.h
@@ -59,40 +59,35 @@ private:
   gl::OriginPos mPos;
   bool mOwns;
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureImage : public GLImage {
 public:
-  SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
+  SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex,
                       const gfx::IntSize& aSize,
-                      bool aContinuous,
                       gl::OriginPos aOriginPos);
 
   gfx::IntSize GetSize() override { return mSize; }
-  AndroidSurfaceTextureHandle GetHandle() const {
-    return mHandle;
-  }
-  bool GetContinuous() const {
-    return mContinuous;
+  gl::AndroidSurfaceTexture* GetSurfaceTexture() const {
+    return mSurfaceTexture;
   }
   gl::OriginPos GetOriginPos() const {
     return mOriginPos;
   }
 
   SurfaceTextureImage* AsSurfaceTextureImage() override {
     return this;
   }
 
 private:
-  AndroidSurfaceTextureHandle mHandle;
+  RefPtr<gl::AndroidSurfaceTexture> mSurfaceTexture;
   gfx::IntSize mSize;
-  bool mContinuous;
   gl::OriginPos mOriginPos;
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 } // namespace layers
 } // namespace mozilla
 
--- a/gfx/layers/client/CanvasClient.cpp
+++ b/gfx/layers/client/CanvasClient.cpp
@@ -456,18 +456,16 @@ CanvasClientSharedSurface::UpdateRendere
     auto layersBackend = shadowForwarder->GetCompositorBackendType();
     mReadbackClient = TexClientFromReadback(surf, forwarder, flags, layersBackend);
 
     newFront = mReadbackClient;
   } else {
     mReadbackClient = nullptr;
   }
 
-  surf->Commit();
-
   if (asyncRenderer) {
     // If surface type is Basic, above codes will readback
     // the GLContext to mReadbackClient in order to send frame to
     // compositor. We copy from this TextureClient directly by
     // calling CopyFromTextureClient().
     // Therefore, if main-thread want the content of GLContext,
     // it doesn't have to readback from GLContext again.
     //
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -127,17 +127,17 @@ ImageClient::CreateTextureClientForImage
     if (aImage->GetFormat() == ImageFormat::EGLIMAGE) {
       EGLImageImage* typedImage = aImage->AsEGLImageImage();
       texture = EGLImageTextureData::CreateTextureClient(
         typedImage, size, aForwarder->GetTextureForwarder(), TextureFlags::DEFAULT);
 #ifdef MOZ_WIDGET_ANDROID
     } else if (aImage->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
       SurfaceTextureImage* typedImage = aImage->AsSurfaceTextureImage();
       texture = AndroidSurfaceTextureData::CreateTextureClient(
-        typedImage->GetHandle(), size, typedImage->GetContinuous(), typedImage->GetOriginPos(),
+        typedImage->GetSurfaceTexture(), size, typedImage->GetOriginPos(),
         aForwarder->GetTextureForwarder(), TextureFlags::DEFAULT);
 #endif
     } else {
       MOZ_ASSERT(false, "Bad ImageFormat.");
     }
   } else {
     RefPtr<gfx::SourceSurface> surface = aImage->GetAsSourceSurface();
     MOZ_ASSERT(surface);
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -596,17 +596,17 @@ protected:
 
   void RecycleTexture(TextureFlags aFlags);
 
   virtual void UpdatedInternal(const nsIntRegion *Region) {}
 
   /**
    * Called when mCompositableCount becomes 0.
    */
-  virtual void NotifyNotUsed();
+  void NotifyNotUsed();
 
   // for Compositor.
   void CallNotifyNotUsed();
 
   PTextureParent* mActor;
   RefPtr<TextureSourceProvider> mProvider;
   RefPtr<TextureReadLock> mReadLock;
   TextureFlags mFlags;
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -55,19 +55,18 @@ struct SurfaceDescriptorDXGIYCbCr {
 
 struct SurfaceDescriptorMacIOSurface {
   uint32_t surfaceId;
   double scaleFactor;
   bool isOpaque;
 };
 
 struct SurfaceTextureDescriptor {
-  uint64_t handle;
+  uintptr_t surfTex;
   IntSize size;
-  bool continuous;
 };
 
 struct EGLImageDescriptor {
   uintptr_t image; // `EGLImage` is a `void*`.
   uintptr_t fence;
   IntSize size;
   bool hasAlpha;
 };
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -74,41 +74,44 @@ EGLImageTextureData::Serialize(SurfaceDe
 }
 
 ////////////////////////////////////////////////////////////////////////
 // AndroidSurface
 
 #ifdef MOZ_WIDGET_ANDROID
 
 already_AddRefed<TextureClient>
-AndroidSurfaceTextureData::CreateTextureClient(AndroidSurfaceTextureHandle aHandle,
+AndroidSurfaceTextureData::CreateTextureClient(AndroidSurfaceTexture* aSurfTex,
                                                gfx::IntSize aSize,
-                                               bool aContinuous,
                                                gl::OriginPos aOriginPos,
                                                LayersIPCChannel* aAllocator,
                                                TextureFlags aFlags)
 {
+  MOZ_ASSERT(XRE_IsParentProcess(),
+             "Can't pass an android surfaces between processes.");
+
+  if (!aSurfTex || !XRE_IsParentProcess()) {
+    return nullptr;
+  }
+
   if (aOriginPos == gl::OriginPos::BottomLeft) {
     aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
   }
 
   return TextureClient::CreateWithData(
-    new AndroidSurfaceTextureData(aHandle, aSize, aContinuous),
+    new AndroidSurfaceTextureData(aSurfTex, aSize),
     aFlags, aAllocator
   );
 }
 
-AndroidSurfaceTextureData::AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle,
-                                                     gfx::IntSize aSize, bool aContinuous)
-  : mHandle(aHandle)
+AndroidSurfaceTextureData::AndroidSurfaceTextureData(AndroidSurfaceTexture* aSurfTex,
+                                                     gfx::IntSize aSize)
+  : mSurfTex(aSurfTex)
   , mSize(aSize)
-  , mContinuous(aContinuous)
-{
-  MOZ_ASSERT(mHandle);
-}
+{}
 
 AndroidSurfaceTextureData::~AndroidSurfaceTextureData()
 {}
 
 void
 AndroidSurfaceTextureData::FillInfo(TextureData::Info& aInfo) const
 {
   aInfo.size = mSize;
@@ -117,16 +120,17 @@ AndroidSurfaceTextureData::FillInfo(Text
   aInfo.hasSynchronization = false;
   aInfo.supportsMoz2D = false;
   aInfo.canExposeMappedData = false;
 }
 
 bool
 AndroidSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
 {
-  aOutDescriptor = SurfaceTextureDescriptor(mHandle, mSize, mContinuous);
+  aOutDescriptor = SurfaceTextureDescriptor((uintptr_t)mSurfTex.get(),
+                                            mSize);
   return true;
 }
 
 #endif // MOZ_WIDGET_ANDROID
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -49,19 +49,18 @@ protected:
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class AndroidSurfaceTextureData : public TextureData
 {
 public:
   static already_AddRefed<TextureClient>
-  CreateTextureClient(AndroidSurfaceTextureHandle aHandle,
+  CreateTextureClient(gl::AndroidSurfaceTexture* aSurfTex,
                       gfx::IntSize aSize,
-                      bool aContinuous,
                       gl::OriginPos aOriginPos,
                       LayersIPCChannel* aAllocator,
                       TextureFlags aFlags);
 
   ~AndroidSurfaceTextureData();
 
   virtual void FillInfo(TextureData::Info& aInfo) const override;
 
@@ -71,21 +70,20 @@ public:
   virtual bool Lock(OpenMode) override { return true; }
 
   virtual void Unlock() override {}
 
   // Our data is always owned externally.
   virtual void Deallocate(LayersIPCChannel*) override {}
 
 protected:
-  AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous);
+  AndroidSurfaceTextureData(gl::AndroidSurfaceTexture* aSurfTex, gfx::IntSize aSize);
 
-  const AndroidSurfaceTextureHandle mHandle;
+  const RefPtr<gl::AndroidSurfaceTexture> mSurfTex;
   const gfx::IntSize mSize;
-  const bool mContinuous;
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 } // namespace layers
 } // namespace mozilla
 
 #endif
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -51,24 +51,19 @@ CreateTextureHostOGL(const SurfaceDescri
                                                    aBackend,
                                                    aFlags);
       break;
     }
 
 #ifdef MOZ_WIDGET_ANDROID
     case SurfaceDescriptor::TSurfaceTextureDescriptor: {
       const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
-      java::GeckoSurfaceTexture::LocalRef surfaceTexture = java::GeckoSurfaceTexture::Lookup(desc.handle());
-
-      MOZ_RELEASE_ASSERT(surfaceTexture);
-
       result = new SurfaceTextureHost(aFlags,
-                                      surfaceTexture,
-                                      desc.size(),
-                                      desc.continuous());
+                                      (AndroidSurfaceTexture*)desc.surfTex(),
+                                      desc.size());
       break;
     }
 #endif
 
     case SurfaceDescriptor::TEGLImageDescriptor: {
       const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
       result = new EGLImageTextureHost(aFlags,
                                        (EGLImage)desc.image(),
@@ -335,17 +330,17 @@ GLTextureSource::IsValid() const
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 // SurfaceTextureHost
 
 #ifdef MOZ_WIDGET_ANDROID
 
 SurfaceTextureSource::SurfaceTextureSource(TextureSourceProvider* aProvider,
-                                           mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
+                                           AndroidSurfaceTexture* aSurfTex,
                                            gfx::SurfaceFormat aFormat,
                                            GLenum aTarget,
                                            GLenum aWrapMode,
                                            gfx::IntSize aSize)
   : mGL(aProvider->GetGLContext())
   , mSurfTex(aSurfTex)
   , mFormat(aFormat)
   , mTextureTarget(aTarget)
@@ -361,17 +356,22 @@ SurfaceTextureSource::BindTexture(GLenum
   MOZ_ASSERT(mSurfTex);
   GLContext* gl = this->gl();
   if (!gl || !gl->MakeCurrent()) {
     NS_WARNING("Trying to bind a texture without a GLContext");
     return;
   }
 
   gl->fActiveTexture(aTextureUnit);
-  gl->fBindTexture(mTextureTarget, mSurfTex->GetTexName());
+
+  // SurfaceTexture spams us if there are any existing GL errors, so
+  // we'll clear them here in order to avoid that.
+  gl->FlushErrors();
+
+  mSurfTex->UpdateTexImage();
 
   ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
 }
 
 void
 SurfaceTextureSource::SetTextureSourceProvider(TextureSourceProvider* aProvider)
 {
   GLContext* newGL = aProvider->GetGLContext();
@@ -390,97 +390,77 @@ SurfaceTextureSource::IsValid() const
 }
 
 gfx::Matrix4x4
 SurfaceTextureSource::GetTextureTransform()
 {
   MOZ_ASSERT(mSurfTex);
 
   gfx::Matrix4x4 ret;
-
-  const auto& surf = java::sdk::SurfaceTexture::LocalRef(java::sdk::SurfaceTexture::Ref::From(mSurfTex));
-  AndroidSurfaceTexture::GetTransformMatrix(surf, ret);
+  mSurfTex->GetTransformMatrix(ret);
 
   return ret;
 }
 
 void
 SurfaceTextureSource::DeallocateDeviceData()
 {
   mSurfTex = nullptr;
 }
 
 ////////////////////////////////////////////////////////////////////////
 
 SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
-                                       mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
-                                       gfx::IntSize aSize,
-                                       bool aContinuousUpdate)
+                                       AndroidSurfaceTexture* aSurfTex,
+                                       gfx::IntSize aSize)
   : TextureHost(aFlags)
   , mSurfTex(aSurfTex)
   , mSize(aSize)
-  , mContinuousUpdate(aContinuousUpdate)
 {
-  // Continuous update makes no sense with single buffer mode
-  MOZ_ASSERT(!mSurfTex->IsSingleBuffer() || !mContinuousUpdate);
 }
 
 SurfaceTextureHost::~SurfaceTextureHost()
 {
 }
 
-void
-SurfaceTextureHost::PrepareTextureSource(CompositableTextureSourceRef& aTexture)
-{
-  GLContext* gl = this->gl();
-  if (!gl || !gl->MakeCurrent()) {
-    return;
-  }
-
-  if (!mContinuousUpdate) {
-    // UpdateTexImage() advances the internal buffer queue, so we only want to call this
-    // once per transactionwhen we are not in continuous mode (as we are here). Otherwise,
-    // the SurfaceTexture content will be de-synced from the rest of the page in subsequent
-    // compositor passes.
-    mSurfTex->UpdateTexImage();
-  }
-}
-
 gl::GLContext*
 SurfaceTextureHost::gl() const
 {
   return mProvider ? mProvider->GetGLContext() : nullptr;
 }
 
 bool
 SurfaceTextureHost::Lock()
 {
   MOZ_ASSERT(mSurfTex);
   GLContext* gl = this->gl();
   if (!gl || !gl->MakeCurrent()) {
     return false;
   }
 
-  if (mContinuousUpdate) {
-    mSurfTex->UpdateTexImage();
-  }
-
   if (!mTextureSource) {
     gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
-    GLenum target = LOCAL_GL_TEXTURE_EXTERNAL; // This is required by SurfaceTexture
+    GLenum target = LOCAL_GL_TEXTURE_EXTERNAL;
     GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
     mTextureSource = new SurfaceTextureSource(mProvider,
                                               mSurfTex,
                                               format,
                                               target,
                                               wrapMode,
                                               mSize);
   }
 
-  return true;
+  return NS_SUCCEEDED(mSurfTex->Attach(gl));
+}
+
+void
+SurfaceTextureHost::Unlock()
+{
+  MOZ_ASSERT(mSurfTex);
+  mSurfTex->Detach();
 }
 
 void
 SurfaceTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
 {
   if (mProvider != aProvider) {
     if (!aProvider || !aProvider->GetGLContext()) {
       DeallocateDeviceData();
@@ -489,26 +469,16 @@ SurfaceTextureHost::SetTextureSourceProv
     mProvider = aProvider;
   }
 
   if (mTextureSource) {
     mTextureSource->SetTextureSourceProvider(aProvider);
   }
 }
 
-void
-SurfaceTextureHost::NotifyNotUsed()
-{
-  if (mSurfTex->IsSingleBuffer()) {
-    mSurfTex->ReleaseTexImage();
-  }
-
-  TextureHost::NotifyNotUsed();
-}
-
 gfx::SurfaceFormat
 SurfaceTextureHost::GetFormat() const
 {
   return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
 }
 
 void
 SurfaceTextureHost::DeallocateDeviceData()
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -26,26 +26,25 @@
 #include "mozilla/layers/TextureHost.h"  // for TextureHost, etc
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsDebug.h"                    // for NS_WARNING
 #include "nsISupportsImpl.h"            // for TextureImage::Release, etc
 #include "nsRegionFwd.h"                // for nsIntRegion
 #include "OGLShaderProgram.h"           // for ShaderProgramType, etc
 
-#ifdef MOZ_WIDGET_ANDROID
-#include "GeneratedJNIWrappers.h"
-#include "AndroidSurfaceTexture.h"
-#endif
-
 namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
 } // namespace gfx
 
+namespace gl {
+class AndroidSurfaceTexture;
+} // namespace gl
+
 namespace layers {
 
 class Compositor;
 class CompositorOGL;
 class TextureImageTextureSourceOGL;
 class GLTextureSource;
 
 inline void ApplySamplingFilterToBoundTexture(gl::GLContext* aGL,
@@ -337,17 +336,17 @@ protected:
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureSource : public TextureSource
                            , public TextureSourceOGL
 {
 public:
   SurfaceTextureSource(TextureSourceProvider* aProvider,
-                       java::GeckoSurfaceTexture::Ref& aSurfTex,
+                       mozilla::gl::AndroidSurfaceTexture* aSurfTex,
                        gfx::SurfaceFormat aFormat,
                        GLenum aTarget,
                        GLenum aWrapMode,
                        gfx::IntSize aSize);
 
   virtual const char* Name() const override { return "SurfaceTextureSource"; }
 
   virtual TextureSourceOGL* AsSourceOGL() override { return this; }
@@ -372,44 +371,41 @@ public:
   virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
 
   gl::GLContext* gl() const {
     return mGL;
   }
 
 protected:
   RefPtr<gl::GLContext> mGL;
-  mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
+  RefPtr<gl::AndroidSurfaceTexture> mSurfTex;
   const gfx::SurfaceFormat mFormat;
   const GLenum mTextureTarget;
   const GLenum mWrapMode;
   const gfx::IntSize mSize;
 };
 
 class SurfaceTextureHost : public TextureHost
 {
 public:
   SurfaceTextureHost(TextureFlags aFlags,
-                     mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
-                     gfx::IntSize aSize,
-                     bool aContinuousUpdate);
+                     mozilla::gl::AndroidSurfaceTexture* aSurfTex,
+                     gfx::IntSize aSize);
 
   virtual ~SurfaceTextureHost();
 
-  virtual void PrepareTextureSource(CompositableTextureSourceRef& aTexture) override;
-
   virtual void DeallocateDeviceData() override;
 
   virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
 
   virtual bool Lock() override;
 
-  virtual gfx::SurfaceFormat GetFormat() const override;
+  virtual void Unlock() override;
 
-  virtual void NotifyNotUsed() override;
+  virtual gfx::SurfaceFormat GetFormat() const override;
 
   virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override
   {
     aTexture = mTextureSource;
     return !!aTexture;
   }
 
   virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override
@@ -419,19 +415,18 @@ public:
 
   gl::GLContext* gl() const;
 
   virtual gfx::IntSize GetSize() const override { return mSize; }
 
   virtual const char* Name() override { return "SurfaceTextureHost"; }
 
 protected:
-  mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
+  RefPtr<gl::AndroidSurfaceTexture> mSurfTex;
   const gfx::IntSize mSize;
-  bool mContinuousUpdate;
   RefPtr<CompositorOGL> mCompositor;
   RefPtr<SurfaceTextureSource> mTextureSource;
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 ////////////////////////////////////////////////////////////////////////
 // EGLImage
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -5,43 +5,26 @@
 #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
@@ -123,22 +106,16 @@ 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;
 }
 
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -468,17 +468,10 @@
         <service
             android:name="org.mozilla.gecko.process.GeckoServiceChildProcess$tab"
             android:enabled="true"
             android:exported="false"
             android:process=":tab"
             android:isolatedProcess="false">
         </service>
 
-        <service
-            android:name="org.mozilla.gecko.gfx.SurfaceAllocatorService"
-            android:enabled="true"
-            android:exported="false"
-            android:isolatedProcess="false">
-        </service>
-
     </application>
 </manifest>
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -542,17 +542,16 @@ endif
 
 libs:: classes.dex
 	$(INSTALL) classes.dex $(FINAL_TARGET)
 
 # Generate Java binder interfaces from AIDL files.
 GECKOVIEW_AIDLS = \
   org/mozilla/gecko/IGeckoEditableChild.aidl \
   org/mozilla/gecko/IGeckoEditableParent.aidl \
-  org/mozilla/gecko/gfx/ISurfaceAllocator.aidl \
   org/mozilla/gecko/media/ICodec.aidl \
   org/mozilla/gecko/media/ICodecCallbacks.aidl \
   org/mozilla/gecko/media/IMediaDrmBridge.aidl \
   org/mozilla/gecko/media/IMediaDrmBridgeCallbacks.aidl \
   org/mozilla/gecko/media/IMediaManager.aidl \
   org/mozilla/gecko/process/IChildProcess.aidl \
   org/mozilla/gecko/process/IProcessManager.aidl \
   $(NULL)
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -374,32 +374,28 @@ gvjar.sources += [geckoview_source_dir +
     'GeckoViewSettings.java',
     'gfx/BitmapUtils.java',
     'gfx/BufferedImage.java',
     'gfx/BufferedImageGLInfo.java',
     'gfx/DynamicToolbarAnimator.java',
     'gfx/FloatSize.java',
     'gfx/FullScreenState.java',
     'gfx/GeckoLayerClient.java',
-    'gfx/GeckoSurface.java',
-    'gfx/GeckoSurfaceTexture.java',
     'gfx/ImmutableViewportMetrics.java',
     'gfx/IntSize.java',
     'gfx/LayerView.java',
     'gfx/NativePanZoomController.java',
     'gfx/Overscroll.java',
     'gfx/OverscrollEdgeEffect.java',
     'gfx/PanningPerfAPI.java',
     'gfx/PanZoomController.java',
     'gfx/PointUtils.java',
     'gfx/RectUtils.java',
     'gfx/RenderTask.java',
     'gfx/StackScroller.java',
-    'gfx/SurfaceAllocator.java',
-    'gfx/SurfaceAllocatorService.java',
     'gfx/SurfaceTextureListener.java',
     'gfx/ViewTransform.java',
     'gfx/VsyncSource.java',
     'InputConnectionListener.java',
     'InputMethods.java',
     'media/AsyncCodec.java',
     'media/AsyncCodecFactory.java',
     'media/Codec.java',
@@ -1261,17 +1257,16 @@ if CONFIG['MOZ_ANDROID_SEARCH_ACTIVITY']
         'gecko-util.jar',
         'gecko-view.jar',
     ]
 
 DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
 FINAL_TARGET_PP_FILES += ['package-name.txt.in']
 
 gvjar.sources += ['generated/org/mozilla/gecko/' + x for x in [
-    'gfx/ISurfaceAllocator.java',
     'IGeckoEditableChild.java',
     'IGeckoEditableParent.java',
     'media/ICodec.java',
     'media/ICodecCallbacks.java',
     'media/IMediaDrmBridge.java',
     'media/IMediaDrmBridgeCallbacks.java',
     'media/IMediaManager.java',
     'process/IChildProcess.java',
--- a/mobile/android/geckoview/src/main/AndroidManifest.xml
+++ b/mobile/android/geckoview/src/main/AndroidManifest.xml
@@ -34,40 +34,25 @@
     <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
 
     <!-- App requires OpenGL ES 2.0 -->
     <uses-feature android:glEsVersion="0x00020000" android:required="true" />
 
     <application>
         <!-- New child services must also be added to the Fennec AndroidManifest.xml.in -->
         <service
-            android:name="org.mozilla.gecko.media.MediaManager"
-            android:enabled="true"
-            android:exported="false"
-            android:process=":media"
-            android:isolatedProcess="false">
-        </service>
-
-        <service
             android:name="org.mozilla.gecko.process.GeckoServiceChildProcess$geckomediaplugin"
             android:enabled="true"
             android:exported="false"
             android:process=":geckomediaplugin"
             android:isolatedProcess="false">
         </service>
 
         <service
             android:name="org.mozilla.gecko.process.GeckoServiceChildProcess$tab"
             android:enabled="true"
             android:exported="false"
             android:process=":tab"
             android:isolatedProcess="false">
         </service>
-
-        <service
-            android:name="org.mozilla.gecko.gfx.SurfaceAllocatorService"
-            android:enabled="true"
-            android:exported="false"
-            android:isolatedProcess="false">
-        </service>
    </application>
 
 </manifest>
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/GeckoSurface.aidl
+++ /dev/null
@@ -1,7 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-parcelable GeckoSurface;
\ No newline at end of file
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/gfx/ISurfaceAllocator.aidl
+++ /dev/null
@@ -1,12 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import org.mozilla.gecko.gfx.GeckoSurface;
-
-interface ISurfaceAllocator {
-    GeckoSurface acquireSurface(in int width, in int height, in boolean singleBufferMode);
-    void releaseSurface(in int handle);
-}
--- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
+++ b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/media/ICodec.aidl
@@ -8,17 +8,17 @@ package org.mozilla.gecko.media;
 import android.os.Bundle;
 import android.view.Surface;
 import org.mozilla.gecko.media.FormatParam;
 import org.mozilla.gecko.media.ICodecCallbacks;
 import org.mozilla.gecko.media.Sample;
 
 interface ICodec {
     void setCallbacks(in ICodecCallbacks callbacks);
-    boolean configure(in FormatParam format, in Surface surface, int flags, in String drmStubId);
+    boolean configure(in FormatParam format, inout Surface surface, int flags, in String drmStubId);
     boolean isAdaptivePlaybackSupported();
     void start();
     void stop();
     void flush();
     void release();
 
     Sample dequeueInput(int size);
     oneway void queueInput(in Sample sample);
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurface.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.graphics.SurfaceTexture;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.view.Surface;
-import android.util.Log;
-
-import java.util.HashMap;
-
-import org.mozilla.gecko.annotation.WrapForJNI;
-import org.mozilla.gecko.AppConstants.Versions;
-
-public final class GeckoSurface extends Surface {
-    private static final String LOGTAG = "GeckoSurface";
-
-    private static HashMap<Integer, GeckoSurfaceTexture> sSurfaceTextures = new HashMap<Integer, GeckoSurfaceTexture>();
-
-    private int mHandle;
-    private boolean mIsSingleBuffer;
-    private volatile boolean mIsAvailable;
-
-    private SurfaceTexture mDummySurfaceTexture;
-
-    @WrapForJNI(exceptionMode = "nsresult")
-    public GeckoSurface(GeckoSurfaceTexture gst) {
-        super(gst);
-        mHandle = gst.getHandle();
-        mIsSingleBuffer = gst.isSingleBuffer();
-        mIsAvailable = true;
-    }
-
-    public GeckoSurface(SurfaceTexture st) {
-        super(st);
-        mDummySurfaceTexture = st;
-    }
-
-    public GeckoSurface() {
-        // A no-arg constructor exists, but is hidden in the SDK. We need to create a dummy
-        // SurfaceTexture here in order to create the instance. This is used to transfer the
-        // GeckoSurface across binder.
-        super(new SurfaceTexture(0));
-    }
-
-    @Override
-    public void readFromParcel(Parcel p) {
-        super.readFromParcel(p);
-        mHandle = p.readInt();
-        mIsSingleBuffer = p.readByte() == 1 ? true : false;
-        mIsAvailable = (p.readByte() == 1 ? true : false);
-
-        if (mDummySurfaceTexture != null) {
-            mDummySurfaceTexture.release();
-            mDummySurfaceTexture = null;
-        }
-    }
-
-    public static final Parcelable.Creator<GeckoSurface> CREATOR = new Parcelable.Creator<GeckoSurface>() {
-        public GeckoSurface createFromParcel(Parcel p) {
-            GeckoSurface surf = new GeckoSurface();
-            surf.readFromParcel(p);
-            return surf;
-        }
-
-        public GeckoSurface[] newArray(int size) {
-            return new GeckoSurface[size];
-        }
-    };
-
-    @Override
-    public void writeToParcel(Parcel out, int flags) {
-        super.writeToParcel(out, flags);
-        out.writeInt(mHandle);
-        out.writeByte((byte) (mIsSingleBuffer ? 1 : 0));
-        out.writeByte((byte) (mIsAvailable ? 1 : 0));
-    }
-
-    @WrapForJNI
-    public int getHandle() {
-        return mHandle;
-    }
-
-    @WrapForJNI
-    public boolean getAvailable() {
-        return mIsAvailable;
-    }
-
-    @WrapForJNI
-    public void setAvailable(boolean available) {
-        mIsAvailable = available;
-    }
-}
\ No newline at end of file
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoSurfaceTexture.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.graphics.SurfaceTexture;
-import android.util.Log;
-
-import java.util.HashMap;
-
-import org.mozilla.gecko.annotation.WrapForJNI;
-import org.mozilla.gecko.AppConstants.Versions;
-
-public final class GeckoSurfaceTexture extends SurfaceTexture {
-    private static final String LOGTAG = "GeckoSurfaceTexture";
-    private static volatile int sNextHandle = 1;
-    private static HashMap<Integer, GeckoSurfaceTexture> sSurfaceTextures = new HashMap<Integer, GeckoSurfaceTexture>();
-
-    private int mHandle;
-    private boolean mIsSingleBuffer;
-    private int mTexName;
-    private GeckoSurfaceTexture.Callbacks mListener;
-
-    @WrapForJNI(dispatchTo = "current")
-    private static native int nativeAcquireTexture();
-
-    private GeckoSurfaceTexture(int handle, int texName) {
-        super(texName);
-        mHandle = handle;
-        mIsSingleBuffer = false;
-        mTexName = texName;
-    }
-
-    private GeckoSurfaceTexture(int handle, int texName, boolean singleBufferMode) {
-        super(texName, singleBufferMode);
-        mHandle = handle;
-        mIsSingleBuffer = singleBufferMode;
-        mTexName = texName;
-    }
-
-    @WrapForJNI
-    public int getHandle() {
-        return mHandle;
-    }
-
-    @WrapForJNI
-    public int getTexName() {
-        return mTexName;
-    }
-
-    @WrapForJNI
-    public boolean isSingleBuffer() {
-        return mIsSingleBuffer;
-    }
-
-    @Override
-    @WrapForJNI
-    public synchronized void updateTexImage() {
-        super.updateTexImage();
-        if (mListener != null) {
-            mListener.onUpdateTexImage();
-        }
-    }
-
-    @Override
-    @WrapForJNI
-    public synchronized void releaseTexImage() {
-        if (!mIsSingleBuffer) {
-            return;
-        }
-
-        super.releaseTexImage();
-        if (mListener != null) {
-            mListener.onReleaseTexImage();
-        }
-    }
-
-    public synchronized void setListener(GeckoSurfaceTexture.Callbacks listener) {
-        mListener = listener;
-    }
-
-    @WrapForJNI
-    public static boolean isSingleBufferSupported() {
-        return Versions.feature19Plus;
-    }
-
-    public static GeckoSurfaceTexture acquire(boolean singleBufferMode) {
-        if (singleBufferMode && !isSingleBufferSupported()) {
-            throw new IllegalArgumentException("single buffer mode not supported on API version < 19");
-        }
-
-        int handle = sNextHandle++;
-        int texName = nativeAcquireTexture();
-
-        final GeckoSurfaceTexture gst;
-        if (isSingleBufferSupported()) {
-            gst = new GeckoSurfaceTexture(handle, texName, singleBufferMode);
-        } else {
-            gst = new GeckoSurfaceTexture(handle, texName);
-        }
-
-        synchronized (sSurfaceTextures) {
-            if (sSurfaceTextures.containsKey(handle)) {
-                gst.release();
-                throw new IllegalArgumentException("Already have a GeckoSurfaceTexture with that handle");
-            }
-
-            sSurfaceTextures.put(handle, gst);
-        }
-
-
-        return gst;
-    }
-
-    public static void dispose(int handle) {
-        final GeckoSurfaceTexture gst;
-        synchronized (sSurfaceTextures) {
-            gst = sSurfaceTextures.remove(handle);
-        }
-
-        if (gst != null) {
-            gst.setListener(null);
-            gst.release();
-        }
-    }
-
-    @WrapForJNI
-    public static GeckoSurfaceTexture lookup(int handle) {
-        synchronized (sSurfaceTextures) {
-            return sSurfaceTextures.get(handle);
-        }
-    }
-
-    public interface Callbacks {
-        void onUpdateTexImage();
-        void onReleaseTexImage();
-    }
-}
\ No newline at end of file
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocator.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-
-import android.graphics.SurfaceTexture;
-import android.os.IBinder;
-import android.os.Process;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.Surface;
-
-import org.mozilla.gecko.annotation.WrapForJNI;
-import org.mozilla.gecko.GeckoAppShell;
-
-public final class SurfaceAllocator {
-    private static final String LOGTAG = "SurfaceAllocator";
-
-    private static SurfaceAllocatorConnection sConnection;
-
-    private static synchronized void ensureConnection() throws Exception {
-        if (sConnection != null) {
-            return;
-        }
-
-        sConnection = new SurfaceAllocatorConnection();
-        Intent intent = new Intent();
-        intent.setClassName(GeckoAppShell.getApplicationContext(),
-                            "org.mozilla.gecko.gfx.SurfaceAllocatorService");
-
-        // FIXME: may not want to auto create
-        if (!GeckoAppShell.getApplicationContext().bindService(intent, sConnection, Context.BIND_AUTO_CREATE)) {
-            throw new Exception("Failed to connect to surface allocator service!");
-        }
-    }
-
-    @WrapForJNI
-    public static GeckoSurface acquireSurface(int width, int height, boolean singleBufferMode) {
-        try {
-            ensureConnection();
-
-            if (singleBufferMode && !GeckoSurfaceTexture.isSingleBufferSupported()) {
-                return null;
-            }
-
-            return sConnection.getAllocator().acquireSurface(width, height, singleBufferMode);
-        } catch (Exception e) {
-            Log.w(LOGTAG, "Failed to acquire GeckoSurface", e);
-            return null;
-        }
-    }
-
-    @WrapForJNI
-    public static void disposeSurface(GeckoSurface surface) {
-        try {
-            ensureConnection();
-        } catch (Exception e) {
-            Log.w(LOGTAG, "Failed to dispose surface, no connection");
-            return;
-        }
-
-        // Release the SurfaceTexture on the other side
-        try {
-            sConnection.getAllocator().releaseSurface(surface.getHandle());
-        } catch (RemoteException e) {
-            Log.w(LOGTAG, "Failed to release surface texture", e);
-        }
-
-        // And now our Surface
-        try {
-            surface.release();
-        } catch (Exception e) {
-            Log.w(LOGTAG, "Failed to release surface", e);
-        }
-    }
-
-    private static final class SurfaceAllocatorConnection implements ServiceConnection {
-        private ISurfaceAllocator mAllocator;
-
-        public synchronized ISurfaceAllocator getAllocator() {
-            while (mAllocator == null) {
-                try {
-                    this.wait();
-                } catch (InterruptedException e) { }
-            }
-
-            return mAllocator;
-        }
-
-        @Override
-        public synchronized void onServiceConnected(ComponentName name, IBinder service) {
-            mAllocator = ISurfaceAllocator.Stub.asInterface(service);
-            this.notifyAll();
-        }
-
-        @Override
-        public synchronized void onServiceDisconnected(ComponentName name) {
-            mAllocator = null;
-        }
-    }
-}
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceAllocatorService.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
-
-public class SurfaceAllocatorService extends Service {
-
-    static private String LOGTAG = "SurfaceAllocatorService";
-
-    public int onStartCommand(final Intent intent, final int flags, final int startId) {
-        return Service.START_STICKY;
-    }
-
-    private Binder mBinder = new ISurfaceAllocator.Stub() {
-        public GeckoSurface acquireSurface(int width, int height, boolean singleBufferMode) {
-            GeckoSurfaceTexture gst = GeckoSurfaceTexture.acquire(singleBufferMode);
-            if (width > 0 && height > 0) {
-                gst.setDefaultBufferSize(width, height);
-            }
-
-            return new GeckoSurface(gst);
-        }
-
-        public void releaseSurface(int handle) {
-            GeckoSurfaceTexture.dispose(handle);
-        }
-    };
-
-    public IBinder onBind(final Intent intent) {
-        return mBinder;
-    }
-
-    public boolean onUnbind(Intent intent) {
-        return false;
-    }
-}
--- 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/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -168,17 +168,19 @@ AndroidBridge::AndroidBridge()
             jEnv, msgQueueClass.Get(), "next", "()Landroid/os/Message;");
     // mMessageQueueMessages may be null (e.g. due to proguard optimization)
     mMessageQueueMessages = jEnv->GetFieldID(
             msgQueueClass.Get(), "mMessages", "Landroid/os/Message;");
 
     AutoJNIClass string(jEnv, "java/lang/String");
     jStringClass = string.getGlobalRef();
 
-    mAPIVersion = jni::GetAPIVersion();
+    if (!GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &mAPIVersion, jEnv)) {
+        ALOG_BRIDGE("Failed to find API version");
+    }
 
     AutoJNIClass channels(jEnv, "java/nio/channels/Channels");
     jChannels = channels.getGlobalRef();
     jChannelCreate = channels.getStaticMethod("newChannel", "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
 
     AutoJNIClass readableByteChannel(jEnv, "java/nio/channels/ReadableByteChannel");
     jReadableByteChannel = readableByteChannel.getGlobalRef();
     jByteBufferRead = readableByteChannel.getMethod("read", "(Ljava/nio/ByteBuffer;)I");
--- a/widget/android/GeneratedJNINatives.h
+++ b/widget/android/GeneratedJNINatives.h
@@ -331,47 +331,28 @@ const JNINativeMethod ScreenManagerHelpe
             mozilla::jni::NativeStub<ScreenManagerHelper::RemoveDisplay_t, Impl>
             ::template Wrap<&Impl::RemoveDisplay>)
 };
 
 template<class Impl>
 class SurfaceTextureListener::Natives : public mozilla::jni::NativeImpl<SurfaceTextureListener, Impl>
 {
 public:
-    static const JNINativeMethod methods[2];
+    static const JNINativeMethod methods[1];
 };
 
 template<class Impl>
 const JNINativeMethod SurfaceTextureListener::Natives<Impl>::methods[] = {
 
-    mozilla::jni::MakeNativeMethod<SurfaceTextureListener::DisposeNative_t>(
-            mozilla::jni::NativeStub<SurfaceTextureListener::DisposeNative_t, Impl>
-            ::template Wrap<&Impl::DisposeNative>),
-
     mozilla::jni::MakeNativeMethod<SurfaceTextureListener::OnFrameAvailable_t>(
             mozilla::jni::NativeStub<SurfaceTextureListener::OnFrameAvailable_t, Impl>
             ::template Wrap<&Impl::OnFrameAvailable>)
 };
 
 template<class Impl>
-class GeckoSurfaceTexture::Natives : public mozilla::jni::NativeImpl<GeckoSurfaceTexture, Impl>
-{
-public:
-    static const JNINativeMethod methods[1];
-};
-
-template<class Impl>
-const JNINativeMethod GeckoSurfaceTexture::Natives<Impl>::methods[] = {
-
-    mozilla::jni::MakeNativeMethod<GeckoSurfaceTexture::NativeAcquireTexture_t>(
-            mozilla::jni::NativeStub<GeckoSurfaceTexture::NativeAcquireTexture_t, Impl>
-            ::template Wrap<&Impl::NativeAcquireTexture>)
-};
-
-template<class Impl>
 class LayerView::Compositor::Natives : public mozilla::jni::NativeImpl<Compositor, Impl>
 {
 public:
     static const JNINativeMethod methods[14];
 };
 
 template<class Impl>
 const JNINativeMethod LayerView::Compositor::Natives<Impl>::methods[] = {
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1058,19 +1058,16 @@ const char SurfaceTextureListener::name[
 constexpr char SurfaceTextureListener::New_t::name[];
 constexpr char SurfaceTextureListener::New_t::signature[];
 
 auto SurfaceTextureListener::New() -> SurfaceTextureListener::LocalRef
 {
     return mozilla::jni::Constructor<New_t>::Call(SurfaceTextureListener::Context(), nullptr);
 }
 
-constexpr char SurfaceTextureListener::DisposeNative_t::name[];
-constexpr char SurfaceTextureListener::DisposeNative_t::signature[];
-
 constexpr char SurfaceTextureListener::OnFrameAvailable_t::name[];
 constexpr char SurfaceTextureListener::OnFrameAvailable_t::signature[];
 
 const char GeckoLayerClient::name[] =
         "org/mozilla/gecko/gfx/GeckoLayerClient";
 
 constexpr char GeckoLayerClient::ContentDocumentChanged_t::name[];
 constexpr char GeckoLayerClient::ContentDocumentChanged_t::signature[];
@@ -1115,116 +1112,16 @@ auto GeckoLayerClient::SynthesizeNativeT
 constexpr char GeckoLayerClient::UpdateRootFrameMetrics_t::name[];
 constexpr char GeckoLayerClient::UpdateRootFrameMetrics_t::signature[];
 
 auto GeckoLayerClient::UpdateRootFrameMetrics(float a0, float a1, float a2, float a3, float a4, float a5, float a6) const -> void
 {
     return mozilla::jni::Method<UpdateRootFrameMetrics_t>::Call(GeckoLayerClient::mCtx, nullptr, a0, a1, a2, a3, a4, a5, a6);
 }
 
-const char GeckoSurface::name[] =
-        "org/mozilla/gecko/gfx/GeckoSurface";
-
-constexpr char GeckoSurface::New_t::name[];
-constexpr char GeckoSurface::New_t::signature[];
-
-auto GeckoSurface::New(mozilla::jni::Object::Param a0, GeckoSurface::LocalRef* a1) -> nsresult
-{
-    MOZ_ASSERT(a1);
-    nsresult rv = NS_OK;
-    *a1 = mozilla::jni::Constructor<New_t>::Call(GeckoSurface::Context(), &rv, a0);
-    return rv;
-}
-
-constexpr char GeckoSurface::GetAvailable_t::name[];
-constexpr char GeckoSurface::GetAvailable_t::signature[];
-
-auto GeckoSurface::GetAvailable() const -> bool
-{
-    return mozilla::jni::Method<GetAvailable_t>::Call(GeckoSurface::mCtx, nullptr);
-}
-
-constexpr char GeckoSurface::GetHandle_t::name[];
-constexpr char GeckoSurface::GetHandle_t::signature[];
-
-auto GeckoSurface::GetHandle() const -> int32_t
-{
-    return mozilla::jni::Method<GetHandle_t>::Call(GeckoSurface::mCtx, nullptr);
-}
-
-constexpr char GeckoSurface::SetAvailable_t::name[];
-constexpr char GeckoSurface::SetAvailable_t::signature[];
-
-auto GeckoSurface::SetAvailable(bool a0) const -> void
-{
-    return mozilla::jni::Method<SetAvailable_t>::Call(GeckoSurface::mCtx, nullptr, a0);
-}
-
-const char GeckoSurfaceTexture::name[] =
-        "org/mozilla/gecko/gfx/GeckoSurfaceTexture";
-
-constexpr char GeckoSurfaceTexture::GetHandle_t::name[];
-constexpr char GeckoSurfaceTexture::GetHandle_t::signature[];
-
-auto GeckoSurfaceTexture::GetHandle() const -> int32_t
-{
-    return mozilla::jni::Method<GetHandle_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
-}
-
-constexpr char GeckoSurfaceTexture::GetTexName_t::name[];
-constexpr char GeckoSurfaceTexture::GetTexName_t::signature[];
-
-auto GeckoSurfaceTexture::GetTexName() const -> int32_t
-{
-    return mozilla::jni::Method<GetTexName_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
-}
-
-constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::name[];
-constexpr char GeckoSurfaceTexture::IsSingleBuffer_t::signature[];
-
-auto GeckoSurfaceTexture::IsSingleBuffer() const -> bool
-{
-    return mozilla::jni::Method<IsSingleBuffer_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
-}
-
-constexpr char GeckoSurfaceTexture::IsSingleBufferSupported_t::name[];
-constexpr char GeckoSurfaceTexture::IsSingleBufferSupported_t::signature[];
-
-auto GeckoSurfaceTexture::IsSingleBufferSupported() -> bool
-{
-    return mozilla::jni::Method<IsSingleBufferSupported_t>::Call(GeckoSurfaceTexture::Context(), nullptr);
-}
-
-constexpr char GeckoSurfaceTexture::Lookup_t::name[];
-constexpr char GeckoSurfaceTexture::Lookup_t::signature[];
-
-auto GeckoSurfaceTexture::Lookup(int32_t a0) -> GeckoSurfaceTexture::LocalRef
-{
-    return mozilla::jni::Method<Lookup_t>::Call(GeckoSurfaceTexture::Context(), nullptr, a0);
-}
-
-constexpr char GeckoSurfaceTexture::NativeAcquireTexture_t::name[];
-constexpr char GeckoSurfaceTexture::NativeAcquireTexture_t::signature[];
-
-constexpr char GeckoSurfaceTexture::ReleaseTexImage_t::name[];
-constexpr char GeckoSurfaceTexture::ReleaseTexImage_t::signature[];
-
-auto GeckoSurfaceTexture::ReleaseTexImage() const -> void
-{
-    return mozilla::jni::Method<ReleaseTexImage_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
-}
-
-constexpr char GeckoSurfaceTexture::UpdateTexImage_t::name[];
-constexpr char GeckoSurfaceTexture::UpdateTexImage_t::signature[];
-
-auto GeckoSurfaceTexture::UpdateTexImage() const -> void
-{
-    return mozilla::jni::Method<UpdateTexImage_t>::Call(GeckoSurfaceTexture::mCtx, nullptr);
-}
-
 const char ImmutableViewportMetrics::name[] =
         "org/mozilla/gecko/gfx/ImmutableViewportMetrics";
 
 constexpr char ImmutableViewportMetrics::New_t::name[];
 constexpr char ImmutableViewportMetrics::New_t::signature[];
 
 auto ImmutableViewportMetrics::New(float a0, float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, int32_t a10, int32_t a11, float a12) -> ImmutableViewportMetrics::LocalRef
 {
@@ -1643,35 +1540,16 @@ auto StackScroller::SViscousFluidScale(f
 
 auto StackScroller::SViscousFluidScale(float a0) -> nsresult
 {
     nsresult rv = NS_OK;
     mozilla::jni::Field<SViscousFluidScale_t>::Set(StackScroller::Context(), &rv, a0);
     return rv;
 }
 
-const char SurfaceAllocator::name[] =
-        "org/mozilla/gecko/gfx/SurfaceAllocator";
-
-constexpr char SurfaceAllocator::AcquireSurface_t::name[];
-constexpr char SurfaceAllocator::AcquireSurface_t::signature[];
-
-auto SurfaceAllocator::AcquireSurface(int32_t a0, int32_t a1, bool a2) -> mozilla::jni::Object::LocalRef
-{
-    return mozilla::jni::Method<AcquireSurface_t>::Call(SurfaceAllocator::Context(), nullptr, a0, a1, a2);
-}
-
-constexpr char SurfaceAllocator::DisposeSurface_t::name[];
-constexpr char SurfaceAllocator::DisposeSurface_t::signature[];
-
-auto SurfaceAllocator::DisposeSurface(mozilla::jni::Object::Param a0) -> void
-{
-    return mozilla::jni::Method<DisposeSurface_t>::Call(SurfaceAllocator::Context(), nullptr, a0);
-}
-
 const char ViewTransform::name[] =
         "org/mozilla/gecko/gfx/ViewTransform";
 
 constexpr char ViewTransform::New_t::name[];
 constexpr char ViewTransform::New_t::signature[];
 
 auto ViewTransform::New(float a0, float a1, float a2) -> ViewTransform::LocalRef
 {
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -3303,33 +3303,16 @@ public:
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::GECKO;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
     static auto New() -> SurfaceTextureListener::LocalRef;
 
-    struct DisposeNative_t {
-        typedef SurfaceTextureListener Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "disposeNative";
-        static constexpr char signature[] =
-                "()V";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::GECKO;
-    };
-
     struct OnFrameAvailable_t {
         typedef SurfaceTextureListener Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "nativeOnFrameAvailable";
         static constexpr char signature[] =
                 "()V";
@@ -3485,270 +3468,16 @@ public:
 
     auto UpdateRootFrameMetrics(float, float, float, float, float, float, float) const -> void;
 
     static const mozilla::jni::CallingThread callingThread =
             mozilla::jni::CallingThread::ANY;
 
 };
 
-class GeckoSurface : public mozilla::jni::ObjectBase<GeckoSurface>
-{
-public:
-    static const char name[];
-
-    explicit GeckoSurface(const Context& ctx) : ObjectBase<GeckoSurface>(ctx) {}
-
-    struct New_t {
-        typedef GeckoSurface Owner;
-        typedef GeckoSurface::LocalRef ReturnType;
-        typedef GeckoSurface::Param SetterType;
-        typedef mozilla::jni::Args<
-                mozilla::jni::Object::Param> Args;
-        static constexpr char name[] = "<init>";
-        static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/gfx/GeckoSurfaceTexture;)V";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::NSRESULT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto New(mozilla::jni::Object::Param, GeckoSurface::LocalRef*) -> nsresult;
-
-    struct GetAvailable_t {
-        typedef GeckoSurface Owner;
-        typedef bool ReturnType;
-        typedef bool SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "getAvailable";
-        static constexpr char signature[] =
-                "()Z";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto GetAvailable() const -> bool;
-
-    struct GetHandle_t {
-        typedef GeckoSurface Owner;
-        typedef int32_t ReturnType;
-        typedef int32_t SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "getHandle";
-        static constexpr char signature[] =
-                "()I";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto GetHandle() const -> int32_t;
-
-    struct SetAvailable_t {
-        typedef GeckoSurface Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<
-                bool> Args;
-        static constexpr char name[] = "setAvailable";
-        static constexpr char signature[] =
-                "(Z)V";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto SetAvailable(bool) const -> void;
-
-    static const mozilla::jni::CallingThread callingThread =
-            mozilla::jni::CallingThread::ANY;
-
-};
-
-class GeckoSurfaceTexture : public mozilla::jni::ObjectBase<GeckoSurfaceTexture>
-{
-public:
-    static const char name[];
-
-    explicit GeckoSurfaceTexture(const Context& ctx) : ObjectBase<GeckoSurfaceTexture>(ctx) {}
-
-    struct GetHandle_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef int32_t ReturnType;
-        typedef int32_t SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "getHandle";
-        static constexpr char signature[] =
-                "()I";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto GetHandle() const -> int32_t;
-
-    struct GetTexName_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef int32_t ReturnType;
-        typedef int32_t SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "getTexName";
-        static constexpr char signature[] =
-                "()I";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto GetTexName() const -> int32_t;
-
-    struct IsSingleBuffer_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef bool ReturnType;
-        typedef bool SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "isSingleBuffer";
-        static constexpr char signature[] =
-                "()Z";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto IsSingleBuffer() const -> bool;
-
-    struct IsSingleBufferSupported_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef bool ReturnType;
-        typedef bool SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "isSingleBufferSupported";
-        static constexpr char signature[] =
-                "()Z";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto IsSingleBufferSupported() -> bool;
-
-    struct Lookup_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef GeckoSurfaceTexture::LocalRef ReturnType;
-        typedef GeckoSurfaceTexture::Param SetterType;
-        typedef mozilla::jni::Args<
-                int32_t> Args;
-        static constexpr char name[] = "lookup";
-        static constexpr char signature[] =
-                "(I)Lorg/mozilla/gecko/gfx/GeckoSurfaceTexture;";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto Lookup(int32_t) -> GeckoSurfaceTexture::LocalRef;
-
-    struct NativeAcquireTexture_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef int32_t ReturnType;
-        typedef int32_t SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "nativeAcquireTexture";
-        static constexpr char signature[] =
-                "()I";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    struct ReleaseTexImage_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "releaseTexImage";
-        static constexpr char signature[] =
-                "()V";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto ReleaseTexImage() const -> void;
-
-    struct UpdateTexImage_t {
-        typedef GeckoSurfaceTexture Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "updateTexImage";
-        static constexpr char signature[] =
-                "()V";
-        static const bool isStatic = false;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    auto UpdateTexImage() const -> void;
-
-    static const mozilla::jni::CallingThread callingThread =
-            mozilla::jni::CallingThread::ANY;
-
-    template<class Impl> class Natives;
-};
-
 class ImmutableViewportMetrics : public mozilla::jni::ObjectBase<ImmutableViewportMetrics>
 {
 public:
     static const char name[];
 
     explicit ImmutableViewportMetrics(const Context& ctx) : ObjectBase<ImmutableViewportMetrics>(ctx) {}
 
     struct New_t {
@@ -4878,70 +4607,16 @@ public:
 
     static auto SViscousFluidScale(float) -> nsresult;
 
     static const mozilla::jni::CallingThread callingThread =
             mozilla::jni::CallingThread::ANY;
 
 };
 
-class SurfaceAllocator : public mozilla::jni::ObjectBase<SurfaceAllocator>
-{
-public:
-    static const char name[];
-
-    explicit SurfaceAllocator(const Context& ctx) : ObjectBase<SurfaceAllocator>(ctx) {}
-
-    struct AcquireSurface_t {
-        typedef SurfaceAllocator Owner;
-        typedef mozilla::jni::Object::LocalRef ReturnType;
-        typedef mozilla::jni::Object::Param SetterType;
-        typedef mozilla::jni::Args<
-                int32_t,
-                int32_t,
-                bool> Args;
-        static constexpr char name[] = "acquireSurface";
-        static constexpr char signature[] =
-                "(IIZ)Lorg/mozilla/gecko/gfx/GeckoSurface;";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto AcquireSurface(int32_t, int32_t, bool) -> mozilla::jni::Object::LocalRef;
-
-    struct DisposeSurface_t {
-        typedef SurfaceAllocator Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<
-                mozilla::jni::Object::Param> Args;
-        static constexpr char name[] = "disposeSurface";
-        static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/gfx/GeckoSurface;)V";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto DisposeSurface(mozilla::jni::Object::Param) -> void;
-
-    static const mozilla::jni::CallingThread callingThread =
-            mozilla::jni::CallingThread::ANY;
-
-};
-
 class ViewTransform : public mozilla::jni::ObjectBase<ViewTransform>
 {
 public:
     static const char name[];
 
     explicit ViewTransform(const Context& ctx) : ObjectBase<ViewTransform>(ctx) {}
 
     struct New_t {
deleted file mode 100644
--- a/widget/android/bindings/AndroidBuild-classes.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[android.os.Build$VERSION]
-<field> = noLiteral:true
\ No newline at end of file
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -5,17 +5,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files("**"):
     BUG_COMPONENT = ("Firefox for Android", "Graphics, Panning and Zooming")
 
 # List of stems to generate .cpp and .h files for.  To add a stem, add it to
 # this list and ensure that $(stem)-classes.txt exists in this directory.
 generated = [
-    'AndroidBuild',
     'AndroidRect',
     'KeyEvent',
     'MediaCodec',
     'MotionEvent',
     'SurfaceTexture',
     'ViewConfiguration'
 ]
 
--- 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.
  *       }
  *   };
  */
--- a/widget/android/jni/Utils.cpp
+++ b/widget/android/jni/Utils.cpp
@@ -2,17 +2,16 @@
 #include "Types.h"
 
 #include <android/log.h>
 #include <pthread.h>
 
 #include "mozilla/Assertions.h"
 
 #include "GeneratedJNIWrappers.h"
-#include "AndroidBuild.h"
 #include "nsAppShell.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 namespace mozilla {
 namespace jni {
@@ -308,18 +307,10 @@ void DispatchToGeckoPriorityQueue(Unique
     nsAppShell::PostEvent(MakeUnique<AbstractCallEvent>(Move(aCall)));
 }
 
 bool IsFennec()
 {
     return sIsFennec;
 }
 
-int GetAPIVersion() {
-    static int32_t apiVersion = 0;
-    if (!apiVersion && IsAvailable()) {
-        apiVersion = java::sdk::VERSION::SDK_INT();
-    }
-    return apiVersion;
-}
-
 } // jni
 } // mozilla
--- a/widget/android/jni/Utils.h
+++ b/widget/android/jni/Utils.h
@@ -141,14 +141,12 @@ struct AbstractCall
 void DispatchToGeckoPriorityQueue(UniquePtr<AbstractCall>&& aCall);
 
 /**
  * Returns whether Gecko is running in a Fennec environment, as determined by
  * the presence of the GeckoApp class.
  */
 bool IsFennec();
 
-int GetAPIVersion();
-
 } // jni
 } // mozilla
 
 #endif // mozilla_jni_Utils_h__