Bug 1014614 - Rename nsSurfaceTexture to AndroidSurfaceTexture r=jgilbert
💩💩 backed out by 53e24fd12cd1 💩 💩
authorJames Willcox <snorp@snorp.net>
Fri, 17 Oct 2014 10:35:10 -0500
changeset 210946 7fa1b78de684
parent 210945 e6c58647bf2b
child 210947 8b530a9a2f99
push id50598
push userjwillcox@mozilla.com
push date2014-10-17 15:36 +0000
treeherdermozilla-inbound@40f99ba7f616 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1014614
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1014614 - Rename nsSurfaceTexture to AndroidSurfaceTexture r=jgilbert
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginInstanceOwner.cpp
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/moz.build
gfx/layers/GLImages.h
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
gfx/layers/opengl/TexturePoolOGL.h
gfx/thebes/moz.build
gfx/thebes/nsSurfaceTexture.cpp
gfx/thebes/nsSurfaceTexture.h
widget/android/AndroidJNI.cpp
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -947,26 +947,26 @@ nsNPAPIPluginInstance::TextureInfo nsNPA
 }
 
 void nsNPAPIPluginInstance::ReleaseContentTexture(nsNPAPIPluginInstance::TextureInfo& aTextureInfo)
 {
   EnsureSharedTexture();
   mContentTexture->Release(aTextureInfo);
 }
 
-nsSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
+AndroidSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
 {
   if (!EnsureGLContext())
     return nullptr;
 
   GLuint texture = TexturePoolOGL::AcquireTexture();
   if (!texture)
     return nullptr;
 
-  nsSurfaceTexture* surface = nsSurfaceTexture::Create(texture);
+  AndroidSurfaceTexture* surface = AndroidSurfaceTexture::Create(texture);
   if (!surface)
     return nullptr;
 
   nsCOMPtr<nsIRunnable> frameCallback = NS_NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable);
   surface->SetFrameAvailableCallback(frameCallback);
   return surface;
 }
 
@@ -980,46 +980,46 @@ void* nsNPAPIPluginInstance::AcquireCont
 {
   if (!mContentSurface) {
     mContentSurface = CreateSurfaceTexture();
 
     if (!mContentSurface)
       return nullptr;
   }
 
-  return mContentSurface->GetNativeWindow();
+  return mContentSurface->NativeWindow()->Handle();
 }
 
 EGLImage
 nsNPAPIPluginInstance::AsEGLImage()
 {
   if (!mContentTexture)
     return 0;
 
   return mContentTexture->CreateEGLImage();
 }
 
-nsSurfaceTexture*
+AndroidSurfaceTexture*
 nsNPAPIPluginInstance::AsSurfaceTexture()
 {
   if (!mContentSurface)
     return nullptr;
 
   return mContentSurface;
 }
 
 void* nsNPAPIPluginInstance::AcquireVideoWindow()
 {
-  nsSurfaceTexture* surface = CreateSurfaceTexture();
+  AndroidSurfaceTexture* surface = CreateSurfaceTexture();
   if (!surface)
     return nullptr;
 
   VideoInfo* info = new VideoInfo(surface);
 
-  void* window = info->mSurfaceTexture->GetNativeWindow();
+  void* window = info->mSurfaceTexture->NativeWindow()->Handle();
   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 "nsInterfaceHashtable.h"
 #include "nsHashKeys.h"
 #include <prinrval.h>
 #include "js/TypeDecls.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "nsAutoPtr.h"
 #include "nsIRunnable.h"
 #include "GLContextTypes.h"
-#include "nsSurfaceTexture.h"
+#include "AndroidSurfaceTexture.h"
 #include "AndroidBridge.h"
 #include <map>
 class PluginEventRunnable;
 class SharedPluginTexture;
 #endif
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/PluginLibrary.h"
@@ -187,32 +187,32 @@ public:
 
   TextureInfo LockContentTexture();
   void ReleaseContentTexture(TextureInfo& aTextureInfo);
 
   // For ANPNativeWindow
   void* AcquireContentWindow();
 
   EGLImage AsEGLImage();
-  nsSurfaceTexture* AsSurfaceTexture();
+  mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture();
 
   // For ANPVideo
   class VideoInfo {
   public:
-    VideoInfo(nsSurfaceTexture* aSurfaceTexture) :
+    VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) :
       mSurfaceTexture(aSurfaceTexture)
     {
     }
 
     ~VideoInfo()
     {
       mSurfaceTexture = nullptr;
     }
 
-    nsRefPtr<nsSurfaceTexture> mSurfaceTexture;
+    nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
     gfxRect mDimensions;
   };
 
   void* AcquireVideoWindow();
   void ReleaseVideoWindow(void* aWindow);
   void SetVideoDimensions(void* aWindow, gfxRect aDimensions);
 
   void GetVideos(nsTArray<VideoInfo*>& aVideos);
@@ -329,17 +329,17 @@ protected:
   void OnSurfaceTextureFrameAvailable();
 
   uint32_t mFullScreenOrientation;
   bool mWakeLocked;
   bool mFullScreen;
   bool mInverted;
 
   nsRefPtr<SharedPluginTexture> mContentTexture;
-  nsRefPtr<nsSurfaceTexture> mContentSurface;
+  nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
 #endif
 
   enum {
     NOT_STARTED,
     RUNNING,
     DESTROYING,
     DESTROYED
   } mRunning;
@@ -378,17 +378,17 @@ private:
   void* mCurrentPluginEvent;
 
   // 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
   void EnsureSharedTexture();
-  nsSurfaceTexture* CreateSurfaceTexture();
+  mozilla::gl::AndroidSurfaceTexture* CreateSurfaceTexture();
 
   std::map<void*, VideoInfo*> mVideos;
   bool mOnScreen;
 
   nsIntSize mCurrentSize;
 #endif
 
   // is this instance Java and affected by bug 750480?
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -180,17 +180,17 @@ static void
 AttachToContainerAsSurfaceTexture(ImageContainer* container,
                                   nsNPAPIPluginInstance* instance,
                                   const LayoutDeviceRect& rect,
                                   nsRefPtr<Image>* out_image)
 {
   MOZ_ASSERT(out_image);
   MOZ_ASSERT(!*out_image);
 
-  nsSurfaceTexture* surfTex = instance->AsSurfaceTexture();
+  mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture();
   if (!surfTex) {
     return;
   }
 
   nsRefPtr<Image> img = container->CreateImage(ImageFormat::SURFACE_TEXTURE);
 
   SurfaceTextureImage::Data data;
   data.mSurfTex = surfTex;
new file mode 100644
--- /dev/null
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -0,0 +1,265 @@
+/* -*- 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 <set>
+#include <map>
+#include <android/log.h>
+#include "AndroidSurfaceTexture.h"
+#include "gfxImageSurface.h"
+#include "AndroidBridge.h"
+#include "nsThreadUtils.h"
+#include "mozilla/gfx/Matrix.h"
+#include "GeneratedJNIWrappers.h"
+
+using namespace mozilla;
+using namespace mozilla::widget::android;
+
+// UGH
+static std::map<int, AndroidSurfaceTexture*> sInstances;
+static int sNextID = 0;
+
+static class JNIFunctions {
+public:
+
+  JNIFunctions() : mInitialized(false)
+  {
+  }
+
+  bool EnsureInitialized()
+  {
+    if (mInitialized)
+      return true;
+
+    JNIEnv* env = GetJNIForThread();
+
+    AutoLocalJNIFrame jniFrame(env);
+
+    jSurfaceTextureClass = (jclass)env->NewGlobalRef(env->FindClass("android/graphics/SurfaceTexture"));
+    jSurfaceTexture_Ctor = env->GetMethodID(jSurfaceTextureClass, "<init>", "(I)V");
+    jSurfaceTexture_updateTexImage = env->GetMethodID(jSurfaceTextureClass, "updateTexImage", "()V");
+    jSurfaceTexture_getTransformMatrix = env->GetMethodID(jSurfaceTextureClass, "getTransformMatrix", "([F)V");
+
+    jSurfaceClass = (jclass)env->NewGlobalRef(env->FindClass("android/view/Surface"));
+    jSurface_Ctor = env->GetMethodID(jSurfaceClass, "<init>", "(Landroid/graphics/SurfaceTexture;)V");
+
+    mInitialized = true;
+    return true;
+  }
+
+  jobject CreateSurfaceTexture(GLuint aTexture)
+  {
+    if (!EnsureInitialized())
+      return nullptr;
+
+    JNIEnv* env = GetJNIForThread();
+
+    AutoLocalJNIFrame jniFrame(env);
+
+    return env->NewGlobalRef(env->NewObject(jSurfaceTextureClass, jSurfaceTexture_Ctor, (int) aTexture));
+  }
+
+  jobject CreateSurface(jobject aSurfaceTexture)
+  {
+    if (!EnsureInitialized())
+      return nullptr;
+
+    JNIEnv* env = GetJNIForThread();
+    AutoLocalJNIFrame jniFrame(env);
+    return env->NewGlobalRef(env->NewObject(jSurfaceClass, jSurface_Ctor, aSurfaceTexture));
+  }
+
+  void ReleaseSurfaceTexture(jobject aSurfaceTexture)
+  {
+    JNIEnv* env = GetJNIForThread();
+
+    env->DeleteGlobalRef(aSurfaceTexture);
+  }
+
+  void UpdateTexImage(jobject aSurfaceTexture)
+  {
+    JNIEnv* env = GetJNIForThread();
+
+    AutoLocalJNIFrame jniFrame(env);
+    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_updateTexImage);
+  }
+
+  bool GetTransformMatrix(jobject aSurfaceTexture, gfx::Matrix4x4& aMatrix)
+  {
+    JNIEnv* env = GetJNIForThread();
+
+    AutoLocalJNIFrame jniFrame(env);
+
+    jfloatArray jarray = env->NewFloatArray(16);
+    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_getTransformMatrix, jarray);
+
+    jfloat* array = env->GetFloatArrayElements(jarray, nullptr);
+
+    aMatrix._11 = array[0];
+    aMatrix._12 = array[1];
+    aMatrix._13 = array[2];
+    aMatrix._14 = array[3];
+
+    aMatrix._21 = array[4];
+    aMatrix._22 = array[5];
+    aMatrix._23 = array[6];
+    aMatrix._24 = array[7];
+
+    aMatrix._31 = array[8];
+    aMatrix._32 = array[9];
+    aMatrix._33 = array[10];
+    aMatrix._34 = array[11];
+
+    aMatrix._41 = array[12];
+    aMatrix._42 = array[13];
+    aMatrix._43 = array[14];
+    aMatrix._44 = array[15];
+
+    env->ReleaseFloatArrayElements(jarray, array, 0);
+
+    return false;
+  }
+
+private:
+  bool mInitialized;
+
+  jclass jSurfaceTextureClass;
+  jmethodID jSurfaceTexture_Ctor;
+  jmethodID jSurfaceTexture_updateTexImage;
+  jmethodID jSurfaceTexture_getTransformMatrix;
+
+  jclass jSurfaceClass;
+  jmethodID jSurface_Ctor;
+
+} sJNIFunctions;
+
+AndroidSurfaceTexture*
+AndroidSurfaceTexture::Create(GLuint aTexture)
+{
+  if (AndroidBridge::Bridge()->GetAPIVersion() < 14 /* Ice Cream Sandwich */) {
+    return nullptr;
+  }
+
+  AndroidSurfaceTexture* st = new AndroidSurfaceTexture();
+  if (!st->Init(aTexture)) {
+    printf_stderr("Failed to initialize AndroidSurfaceTexture");
+    delete st;
+    st = nullptr;
+  }
+
+  return st;
+}
+
+AndroidSurfaceTexture*
+AndroidSurfaceTexture::Find(int id)
+{
+  std::map<int, AndroidSurfaceTexture*>::iterator it;
+
+  it = sInstances.find(id);
+  if (it == sInstances.end())
+    return nullptr;
+
+  return it->second;
+}
+
+bool
+AndroidSurfaceTexture::Check()
+{
+  return sJNIFunctions.EnsureInitialized();
+}
+
+bool
+AndroidSurfaceTexture::Init(GLuint aTexture)
+{
+  if (!sJNIFunctions.EnsureInitialized())
+    return false;
+
+  JNIEnv* env = GetJNIForThread();
+
+  mSurfaceTexture = sJNIFunctions.CreateSurfaceTexture(aTexture);
+  if (!mSurfaceTexture) {
+    return false;
+  }
+
+  mSurface = sJNIFunctions.CreateSurface(mSurfaceTexture);
+  if (!mSurface) {
+    return false;
+  }
+
+  mID = ++sNextID;
+  sInstances.insert(std::pair<int, AndroidSurfaceTexture*>(mID, this));
+
+  mTexture = aTexture;
+
+  return true;
+}
+
+AndroidSurfaceTexture::AndroidSurfaceTexture()
+  : mTexture(0), mSurfaceTexture(nullptr), mSurface(nullptr)
+{
+}
+
+AndroidSurfaceTexture::~AndroidSurfaceTexture()
+{
+  sInstances.erase(mID);
+
+  mFrameAvailableCallback = nullptr;
+
+  JNIEnv* env = GetJNIForThread();
+
+  if (mSurfaceTexture) {
+    GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
+
+    env->DeleteGlobalRef(mSurfaceTexture);
+    mSurfaceTexture = nullptr;
+  }
+
+  if (mSurface) {
+    env->DeleteGlobalRef(mSurface);
+    mSurface = nullptr;
+  }
+}
+
+void
+AndroidSurfaceTexture::UpdateTexImage()
+{
+  sJNIFunctions.UpdateTexImage(mSurfaceTexture);
+}
+
+bool
+AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
+{
+  return sJNIFunctions.GetTransformMatrix(mSurfaceTexture, aMatrix);
+}
+
+void
+AndroidSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
+{
+  if (aRunnable)
+    GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
+  else
+    GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
+
+  mFrameAvailableCallback = aRunnable;
+}
+
+void
+AndroidSurfaceTexture::NotifyFrameAvailable()
+{
+  if (mFrameAvailableCallback) {
+    // Proxy to main thread if we aren't on it
+    if (!NS_IsMainThread()) {
+      // Proxy to main thread
+      nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable);
+      NS_DispatchToCurrentThread(event);
+    } else {
+      mFrameAvailableCallback->Run();
+    }
+  }
+}
+
+#endif // MOZ_WIDGET_ANDROID
new file mode 100644
--- /dev/null
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -0,0 +1,80 @@
+/* -*- 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 AndroidSurfaceTexture_h__
+#define AndroidSurfaceTexture_h__
+#ifdef MOZ_WIDGET_ANDROID
+
+#include <jni.h>
+#include "nsIRunnable.h"
+#include "gfxPlatform.h"
+#include "GLDefs.h"
+
+#include "AndroidNativeWindow.h"
+
+class gfxASurface;
+
+namespace mozilla {
+namespace gfx {
+class Matrix4x4;
+}
+}
+
+namespace mozilla {
+namespace gl {
+
+/**
+ * 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 AndroidSurfaceTexture* Create(GLuint aTexture);
+  static AndroidSurfaceTexture* Find(int id);
+
+  // Returns with reasonable certainty whether or not we'll
+  // be able to create and use a SurfaceTexture
+  static bool Check();
+  
+  ~AndroidSurfaceTexture();
+
+  // This attaches the updated data to the TEXTURE_EXTERNAL target
+  void UpdateTexImage();
+
+  bool GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix);
+  int ID() { return mID; }
+
+  // The callback is guaranteed to be called on the main thread even
+  // if the upstream callback is received on a different thread
+  void SetFrameAvailableCallback(nsIRunnable* aRunnable);
+
+  // Only should be called by AndroidJNI when we get a
+  // callback from the underlying SurfaceTexture instance
+  void NotifyFrameAvailable();
+
+  GLuint Texture() { return mTexture; }
+private:
+  AndroidSurfaceTexture();
+
+  bool Init(GLuint aTexture);
+
+  GLuint mTexture;
+  jobject mSurfaceTexture;
+  jobject mSurface;
+
+  int mID;
+  nsRefPtr<nsIRunnable> mFrameAvailableCallback;
+};
+  
+}
+}
+
+
+#endif
+#endif
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -20,17 +20,16 @@
 #include "HwcComposer2D.h"
 #include "libdisplay/GonkDisplay.h"
 #endif
 
 #if defined(ANDROID)
 /* from widget */
 #if defined(MOZ_WIDGET_ANDROID)
 #include "AndroidBridge.h"
-#include "nsSurfaceTexture.h"
 #endif
 
 #include <android/log.h>
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 
 # if defined(MOZ_WIDGET_GONK)
 #  include "cutils/properties.h"
 #  include <ui/GraphicBuffer.h>
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -21,16 +21,17 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'an
     gl_provider = 'EGL'
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     gl_provider = 'EGL'
 
 if CONFIG['MOZ_GL_PROVIDER']:
     gl_provider = CONFIG['MOZ_GL_PROVIDER']
 
 EXPORTS += [
+    'AndroidSurfaceTexture.h',
     'DecomposeIntoNoRepeatTriangles.h',
     'EGLUtils.h',
     'ForceDiscreteGPUHelperCGL.h',
     'GfxTexturesReporter.h',
     'GLBlitHelper.h',
     'GLBlitTextureImageHelper.h',
     'GLConsts.h',
     'GLContext.h',
@@ -109,16 +110,17 @@ elif gl_provider == 'GLX':
         'GLContextProviderGLX.cpp',
     ]
 else:
     UNIFIED_SOURCES += [
         'GLContextProvider%s.cpp' % gl_provider,
     ]
 
 UNIFIED_SOURCES += [
+    'AndroidSurfaceTexture.cpp',
     'DecomposeIntoNoRepeatTriangles.cpp',
     'EGLUtils.cpp',
     'GfxTexturesReporter.cpp',
     'GLBlitHelper.cpp',
     'GLBlitTextureImageHelper.cpp',
     'GLContext.cpp',
     'GLContextFeatures.cpp',
     'GLContextTypes.cpp',
--- a/gfx/layers/GLImages.h
+++ b/gfx/layers/GLImages.h
@@ -7,19 +7,20 @@
 #define GFX_GLIMAGES_H
 
 #include "GLTypes.h"
 #include "ImageContainer.h"             // for Image
 #include "ImageTypes.h"                 // for ImageFormat::SHARED_GLTEXTURE
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "mozilla/gfx/Point.h"          // for IntSize
 
-class nsSurfaceTexture;
-
 namespace mozilla {
+namespace gl {
+class AndroidSurfaceTexture;
+}
 namespace layers {
 
 class EGLImageImage : public Image {
 public:
   struct Data {
     EGLImage mImage;
     gfx::IntSize mSize;
     bool mInverted;
@@ -41,17 +42,17 @@ private:
   Data mData;
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureImage : public Image {
 public:
   struct Data {
-    nsSurfaceTexture* mSurfTex;
+    mozilla::gl::AndroidSurfaceTexture* mSurfTex;
     gfx::IntSize mSize;
     bool mInverted;
   };
 
   void SetData(const Data& aData) { mData = aData; }
   const Data* GetData() { return &mData; }
 
   gfx::IntSize GetSize() { return mData.mSize; }
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -73,17 +73,17 @@ EGLImageTextureClient::Unlock()
 }
 
 ////////////////////////////////////////////////////////////////////////
 // SurfaceTextureClient
 
 #ifdef MOZ_WIDGET_ANDROID
 
 SurfaceTextureClient::SurfaceTextureClient(TextureFlags aFlags,
-                                           nsSurfaceTexture* aSurfTex,
+                                           AndroidSurfaceTexture* aSurfTex,
                                            gfx::IntSize aSize,
                                            bool aInverted)
   : TextureClient(aFlags)
   , mSurfTex(aSurfTex)
   , mSize(aSize)
   , mIsLocked(false)
 {
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -8,17 +8,17 @@
 
 #include "GLContextTypes.h"             // for SharedTextureHandle, etc
 #include "gfxTypes.h"
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
-#include "nsSurfaceTexture.h"
+#include "AndroidSurfaceTexture.h"
 
 namespace mozilla {
 namespace layers {
 
 class CompositableForwarder;
 
 class EGLImageTextureClient : public TextureClient
 {
@@ -69,17 +69,17 @@ protected:
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureClient : public TextureClient
 {
 public:
   SurfaceTextureClient(TextureFlags aFlags,
-                       nsSurfaceTexture* aSurfTex,
+                       AndroidSurfaceTexture* aSurfTex,
                        gfx::IntSize aSize,
                        bool aInverted);
 
   ~SurfaceTextureClient();
 
   virtual bool IsAllocated() const MOZ_OVERRIDE { return true; }
 
   virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
@@ -108,17 +108,17 @@ public:
   }
 
   virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
   {
     return false;
   }
 
 protected:
-  const nsRefPtr<nsSurfaceTexture> mSurfTex;
+  const RefPtr<AndroidSurfaceTexture> mSurfTex;
   const gfx::IntSize mSize;
   bool mIsLocked;
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -18,17 +18,17 @@
 # include "GrallocImages.h"  // for GrallocImage
 # include "EGLImageHelpers.h"
 #endif
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/layers/YCbCrImageDataSerializer.h"
 #include "mozilla/layers/GrallocTextureHost.h"
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRegion.h"                   // for nsIntRegion
-#include "nsSurfaceTexture.h"
+#include "AndroidSurfaceTexture.h"
 #include "GfxTexturesReporter.h"        // for GfxTexturesReporter
 #include "GLBlitTextureImageHelper.h"
 #ifdef XP_MACOSX
 #include "SharedSurfaceIO.h"
 #include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
 #endif
 #include "GeckoProfiler.h"
 
@@ -53,17 +53,17 @@ CreateTextureHostOGL(const SurfaceDescri
                                                    aDeallocator, aFlags);
       break;
     }
 
 #ifdef MOZ_WIDGET_ANDROID
     case SurfaceDescriptor::TSurfaceTextureDescriptor: {
       const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
       result = new SurfaceTextureHost(aFlags,
-                                      (nsSurfaceTexture*)desc.surfTex(),
+                                      (AndroidSurfaceTexture*)desc.surfTex(),
                                       desc.size());
       break;
     }
 #endif
 
     case SurfaceDescriptor::TEGLImageDescriptor: {
       const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
       result = new EGLImageTextureHost(aFlags,
@@ -424,17 +424,17 @@ GLTextureSource::gl() const
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 // SurfaceTextureHost
 
 #ifdef MOZ_WIDGET_ANDROID
 
 SurfaceTextureSource::SurfaceTextureSource(CompositorOGL* aCompositor,
-                                           nsSurfaceTexture* aSurfTex,
+                                           AndroidSurfaceTexture* aSurfTex,
                                            gfx::SurfaceFormat aFormat,
                                            GLenum aTarget,
                                            GLenum aWrapMode,
                                            gfx::IntSize aSize)
   : mCompositor(aCompositor)
   , mSurfTex(aSurfTex)
   , mFormat(aFormat)
   , mTextureTarget(aTarget)
@@ -493,17 +493,17 @@ SurfaceTextureSource::GetTextureTransfor
   mSurfTex->GetTransformMatrix(ret);
 
   return ret;
 }
 
 ////////////////////////////////////////////////////////////////////////
 
 SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
-                                       nsSurfaceTexture* aSurfTex,
+                                       AndroidSurfaceTexture* aSurfTex,
                                        gfx::IntSize aSize)
   : TextureHost(aFlags)
   , mSurfTex(aSurfTex)
   , mSize(aSize)
   , mCompositor(nullptr)
 {
 }
 
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -34,26 +34,29 @@
 #include <ui/GraphicBuffer.h>
 #if ANDROID_VERSION >= 17
 #include <ui/Fence.h>
 #endif
 #endif
 
 class gfxReusableSurfaceWrapper;
 class nsIntRegion;
-class nsSurfaceTexture;
 struct nsIntPoint;
 struct nsIntRect;
 struct nsIntSize;
 
 namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
 }
 
+namespace gl {
+class AndroidSurfaceTexture;
+}
+
 namespace layers {
 
 class Compositor;
 class CompositorOGL;
 class TextureImageTextureSourceOGL;
 class TextureSharedDataGonkOGL;
 class GLTextureSource;
 
@@ -334,17 +337,17 @@ protected:
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureSource : public TextureSource
                            , public TextureSourceOGL
 {
 public:
   SurfaceTextureSource(CompositorOGL* aCompositor,
-                       nsSurfaceTexture* aSurfTex,
+                       mozilla::gl::AndroidSurfaceTexture* aSurfTex,
                        gfx::SurfaceFormat aFormat,
                        GLenum aTarget,
                        GLenum aWrapMode,
                        gfx::IntSize aSize);
 
   virtual TextureSourceOGL* AsSourceOGL() { return this; }
 
   virtual void BindTexture(GLenum activetex, gfx::Filter aFilter) MOZ_OVERRIDE;
@@ -365,28 +368,28 @@ public:
   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
   gl::GLContext* gl() const;
 
 protected:
   RefPtr<CompositorOGL> mCompositor;
-  nsSurfaceTexture* const mSurfTex;
+  mozilla::gl::AndroidSurfaceTexture* const mSurfTex;
   const gfx::SurfaceFormat mFormat;
   const GLenum mTextureTarget;
   const GLenum mWrapMode;
   const gfx::IntSize mSize;
 };
 
 class SurfaceTextureHost : public TextureHost
 {
 public:
   SurfaceTextureHost(TextureFlags aFlags,
-                     nsSurfaceTexture* aSurfTex,
+                     mozilla::gl::AndroidSurfaceTexture* aSurfTex,
                      gfx::IntSize aSize);
 
   virtual ~SurfaceTextureHost();
 
   // We don't own anything.
   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
@@ -409,17 +412,17 @@ public:
 
   gl::GLContext* gl() const;
 
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
 
   virtual const char* Name() { return "SurfaceTextureHost"; }
 
 protected:
-  nsSurfaceTexture* const mSurfTex;
+  mozilla::gl::AndroidSurfaceTexture* const mSurfTex;
   const gfx::IntSize mSize;
   RefPtr<CompositorOGL> mCompositor;
   RefPtr<SurfaceTextureSource> mTextureSource;
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 ////////////////////////////////////////////////////////////////////////
--- a/gfx/layers/opengl/TexturePoolOGL.h
+++ b/gfx/layers/opengl/TexturePoolOGL.h
@@ -7,17 +7,17 @@
 
 #include "GLContextTypes.h"             // for GLContext, GLuint
 
 namespace mozilla {
 namespace gl {
 
 // A texture pool for for the on-screen GLContext. The main purpose of this class
 // is to provide the ability to easily allocate an on-screen texture from the
-// content thread. The unfortunate nature of the SurfaceTexture API (see nsSurfaceTexture)
+// content thread. The unfortunate nature of the SurfaceTexture API (see AndroidSurfaceTexture)
 // necessitates this.
 class TexturePoolOGL
 {
 public:
   // Get a new texture from the pool. Will block
   // and wait for one to be created if necessary
   static GLuint AcquireTexture();
 
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -44,17 +44,16 @@ EXPORTS += [
     'gfxSkipChars.h',
     'gfxSVGGlyphs.h',
     'gfxTeeSurface.h',
     'gfxTextRun.h',
     'gfxTypes.h',
     'gfxUserFontSet.h',
     'gfxUtils.h',
     'GraphicsFilter.h',
-    'nsSurfaceTexture.h',
     'RoundedRect.h',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     EXPORTS += [
         'gfxAndroidPlatform.h',
         'gfxFT2FontBase.h',
         'gfxFT2Fonts.h',
@@ -237,17 +236,16 @@ UNIFIED_SOURCES += [
     'gfxReusableSharedImageSurfaceWrapper.cpp',
     'gfxScriptItemizer.cpp',
     'gfxSkipChars.cpp',
     'gfxSVGGlyphs.cpp',
     'gfxTeeSurface.cpp',
     'gfxTextRun.cpp',
     'gfxUserFontSet.cpp',
     'gfxUtils.cpp',
-    'nsSurfaceTexture.cpp',
     'nsUnicodeRange.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     UNIFIED_SOURCES += [
         'gfxMacPlatformFontList.mm',
     ]
 
deleted file mode 100644
--- a/gfx/thebes/nsSurfaceTexture.cpp
+++ /dev/null
@@ -1,247 +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/. */
-
-#ifdef MOZ_WIDGET_ANDROID
-
-#include <set>
-#include <map>
-#include <android/log.h>
-#include "nsSurfaceTexture.h"
-#include "AndroidBridge.h"
-#include "nsThreadUtils.h"
-#include "mozilla/gfx/Matrix.h"
-
-using namespace mozilla;
-
-// UGH
-static std::map<int, nsSurfaceTexture*> sInstances;
-static int sNextID = 0;
-
-static class JNIFunctions {
-public:
-
-  JNIFunctions() : mInitialized(false)
-  {
-  }
-
-  bool EnsureInitialized()
-  {
-    if (mInitialized)
-      return true;
-
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-
-    jSurfaceTextureClass = (jclass)env->NewGlobalRef(env->FindClass("android/graphics/SurfaceTexture"));
-    jSurfaceTexture_Ctor = env->GetMethodID(jSurfaceTextureClass, "<init>", "(I)V");
-    jSurfaceTexture_updateTexImage = env->GetMethodID(jSurfaceTextureClass, "updateTexImage", "()V");
-    jSurfaceTexture_getTransformMatrix = env->GetMethodID(jSurfaceTextureClass, "getTransformMatrix", "([F)V");
-
-    mInitialized = true;
-    return true;
-  }
-
-  jobject CreateSurfaceTexture(GLuint aTexture)
-  {
-    if (!EnsureInitialized())
-      return nullptr;
-
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-
-    return env->NewGlobalRef(env->NewObject(jSurfaceTextureClass, jSurfaceTexture_Ctor, (int) aTexture));
-  }
-
-  void ReleaseSurfaceTexture(jobject aSurfaceTexture)
-  {
-    JNIEnv* env = GetJNIForThread();
-
-    env->DeleteGlobalRef(aSurfaceTexture);
-  }
-
-  void UpdateTexImage(jobject aSurfaceTexture)
-  {
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_updateTexImage);
-  }
-
-  bool GetTransformMatrix(jobject aSurfaceTexture, gfx::Matrix4x4& aMatrix)
-  {
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-
-    jfloatArray jarray = env->NewFloatArray(16);
-    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_getTransformMatrix, jarray);
-
-    jfloat* array = env->GetFloatArrayElements(jarray, nullptr);
-
-    aMatrix._11 = array[0];
-    aMatrix._12 = array[1];
-    aMatrix._13 = array[2];
-    aMatrix._14 = array[3];
-
-    aMatrix._21 = array[4];
-    aMatrix._22 = array[5];
-    aMatrix._23 = array[6];
-    aMatrix._24 = array[7];
-
-    aMatrix._31 = array[8];
-    aMatrix._32 = array[9];
-    aMatrix._33 = array[10];
-    aMatrix._34 = array[11];
-
-    aMatrix._41 = array[12];
-    aMatrix._42 = array[13];
-    aMatrix._43 = array[14];
-    aMatrix._44 = array[15];
-
-    env->ReleaseFloatArrayElements(jarray, array, 0);
-
-    return false;
-  }
-
-private:
-  bool mInitialized;
-
-  jclass jSurfaceTextureClass;
-  jmethodID jSurfaceTexture_Ctor;
-  jmethodID jSurfaceTexture_updateTexImage;
-  jmethodID jSurfaceTexture_getTransformMatrix;
-
-} sJNIFunctions;
-
-nsSurfaceTexture*
-nsSurfaceTexture::Create(GLuint aTexture)
-{
-  // Right now we only support creating this on the main thread because
-  // of the JNIEnv assumptions in JNIHelper and elsewhere
-  if (!NS_IsMainThread())
-    return nullptr;
-
-  nsSurfaceTexture* st = new nsSurfaceTexture();
-  if (!st->Init(aTexture)) {
-    printf_stderr("Failed to initialize nsSurfaceTexture");
-    delete st;
-    st = nullptr;
-  }
-
-  return st;
-}
-
-nsSurfaceTexture*
-nsSurfaceTexture::Find(int id)
-{
-  std::map<int, nsSurfaceTexture*>::iterator it;
-
-  it = sInstances.find(id);
-  if (it == sInstances.end())
-    return nullptr;
-
-  return it->second;
-}
-
-bool
-nsSurfaceTexture::Check()
-{
-  return sJNIFunctions.EnsureInitialized();
-}
-
-bool
-nsSurfaceTexture::Init(GLuint aTexture)
-{
-  if (!sJNIFunctions.EnsureInitialized())
-    return false;
-
-  JNIEnv* env = GetJNIForThread();
-
-  mSurfaceTexture = sJNIFunctions.CreateSurfaceTexture(aTexture);
-  if (!mSurfaceTexture)
-    return false;
-
-  mNativeWindow = AndroidBridge::Bridge()->AcquireNativeWindowFromSurfaceTexture(env, mSurfaceTexture);
-
-  mID = ++sNextID;
-  sInstances.insert(std::pair<int, nsSurfaceTexture*>(mID, this));
-
-  return true;
-}
-
-nsSurfaceTexture::nsSurfaceTexture()
-  : mSurfaceTexture(nullptr), mNativeWindow(nullptr)
-{
-}
-
-nsSurfaceTexture::~nsSurfaceTexture()
-{
-  sInstances.erase(mID);
-
-  mFrameAvailableCallback = nullptr;
-
-  if (mNativeWindow) {
-    AndroidBridge::Bridge()->ReleaseNativeWindowForSurfaceTexture(mSurfaceTexture);
-    mNativeWindow = nullptr;
-  }
-
-  JNIEnv* env = GetJNIForThread();
-
-  if (mSurfaceTexture) {
-    mozilla::widget::android::GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
-
-    env->DeleteGlobalRef(mSurfaceTexture);
-    mSurfaceTexture = nullptr;
-  }
-}
-
-void*
-nsSurfaceTexture::GetNativeWindow()
-{
-  return mNativeWindow;
-}
-
-void
-nsSurfaceTexture::UpdateTexImage()
-{
-  sJNIFunctions.UpdateTexImage(mSurfaceTexture);
-}
-
-bool
-nsSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
-{
-  return sJNIFunctions.GetTransformMatrix(mSurfaceTexture, aMatrix);
-}
-
-void
-nsSurfaceTexture::SetFrameAvailableCallback(nsIRunnable* aRunnable)
-{
-  if (aRunnable)
-    mozilla::widget::android::GeckoAppShell::RegisterSurfaceTextureFrameListener(mSurfaceTexture, mID);
-  else
-    mozilla::widget::android::GeckoAppShell::UnregisterSurfaceTextureFrameListener(mSurfaceTexture);
-
-  mFrameAvailableCallback = aRunnable;
-}
-
-void
-nsSurfaceTexture::NotifyFrameAvailable()
-{
-  if (mFrameAvailableCallback) {
-    // Proxy to main thread if we aren't on it
-    if (!NS_IsMainThread()) {
-      // Proxy to main thread 
-      nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &nsSurfaceTexture::NotifyFrameAvailable);
-      NS_DispatchToCurrentThread(event);
-    } else {
-      mFrameAvailableCallback->Run();
-    }
-  }
-}
-
-#endif // MOZ_WIDGET_ANDROID
deleted file mode 100644
--- a/gfx/thebes/nsSurfaceTexture.h
+++ /dev/null
@@ -1,70 +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 nsSurfaceTexture_h__
-#define nsSurfaceTexture_h__
-#ifdef MOZ_WIDGET_ANDROID
-
-#include <jni.h>
-#include "nsIRunnable.h"
-#include "gfxPlatform.h"
-#include "GLDefs.h"
-
-namespace mozilla {
-namespace gfx {
-class Matrix4x4;
-}
-}
-
-/**
- * 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 nsSurfaceTexture MOZ_FINAL {
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsSurfaceTexture)
-
-public:
-  static nsSurfaceTexture* Create(GLuint aTexture);
-  static nsSurfaceTexture* Find(int id);
-
-  // Returns with reasonable certainty whether or not we'll
-  // be able to create and use a SurfaceTexture
-  static bool Check();
-
-  // This is an ANativeWindow. Use AndroidBridge::LockWindow and
-  // friends for manipulating it.
-  void* GetNativeWindow();
-
-  // This attaches the updated data to the TEXTURE_EXTERNAL target
-  void UpdateTexImage();
-
-  bool GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix);
-  int ID() { return mID; }
-
-  // The callback is guaranteed to be called on the main thread even
-  // if the upstream callback is received on a different thread
-  void SetFrameAvailableCallback(nsIRunnable* aRunnable);
-
-  // Only should be called by AndroidJNI when we get a
-  // callback from the underlying SurfaceTexture instance
-  void NotifyFrameAvailable();
-private:
-  nsSurfaceTexture();
-
-  // Private destructor, to discourage deletion outside of Release():
-  ~nsSurfaceTexture();
-
-  bool Init(GLuint aTexture);
-
-  jobject mSurfaceTexture;
-  void* mNativeWindow;
-  int mID;
-  nsRefPtr<nsIRunnable> mFrameAvailableCallback;
-};
-
-#endif
-#endif
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -35,17 +35,17 @@
 #include "mozilla/dom/SmsMessage.h"
 #include "mozilla/dom/mobilemessage/Constants.h"
 #include "mozilla/dom/mobilemessage/Types.h"
 #include "mozilla/dom/mobilemessage/PSms.h"
 #include "mozilla/dom/mobilemessage/SmsParent.h"
 #include "mozilla/layers/APZCTreeManager.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "nsPluginInstanceOwner.h"
-#include "nsSurfaceTexture.h"
+#include "AndroidSurfaceTexture.h"
 #include "GeckoProfiler.h"
 #include "nsMemoryPressure.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::mobilemessage;
 using namespace mozilla::layers;
 using namespace mozilla::widget::android;
@@ -857,19 +857,19 @@ Java_org_mozilla_gecko_GeckoAppShell_get
         }
     }
     return jenv->CallObjectMethod(queue, jNextMethod);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_onSurfaceTextureFrameAvailable(JNIEnv* jenv, jclass, jobject surfaceTexture, jint id)
 {
-  nsSurfaceTexture* st = nsSurfaceTexture::Find(id);
+  mozilla::gl::AndroidSurfaceTexture* st = mozilla::gl::AndroidSurfaceTexture::Find(id);
   if (!st) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find nsSurfaceTexture with id %d", id);
+    __android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find AndroidSurfaceTexture with id %d", id);
     return;
   }
 
   st->NotifyFrameAvailable();
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_dispatchMemoryPressure(JNIEnv* jenv, jclass)