Back out 04a5da64e518..5811de401315
authorJames Willcox <jwillcox@mozilla.com>
Wed, 05 Nov 2014 19:37:09 -0600
changeset 225956 375b5fca3825
parent 225945 5811de401315
child 225957 4cd1151d9de0
push id4084
push userjwillcox@mozilla.com
push date2014-11-06 01:38 +0000
treeherdermozilla-beta@4cd1151d9de0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone34.0
backs out04a5da64e518
Back out 04a5da64e518..5811de401315
configure.in
content/media/fmp4/MP4Decoder.cpp
content/media/fmp4/PlatformDecoderModule.cpp
content/media/fmp4/PlatformDecoderModule.h
content/media/fmp4/android/AndroidDecoderModule.cpp
content/media/fmp4/android/AndroidDecoderModule.h
content/media/fmp4/moz.build
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/ipc/PluginInstanceParent.cpp
gfx/gl/AndroidNativeWindow.cpp
gfx/gl/AndroidNativeWindow.h
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
gfx/gl/EGLUtils.cpp
gfx/gl/EGLUtils.h
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLBlitHelper.h
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextTypes.h
gfx/gl/GLSharedHandleHelpers.cpp
gfx/gl/GLSharedHandleHelpers.h
gfx/gl/TextureImageEGL.cpp
gfx/gl/moz.build
gfx/layers/Compositor.h
gfx/layers/GLImages.cpp
gfx/layers/GLImages.h
gfx/layers/ImageContainer.cpp
gfx/layers/ImageTypes.h
gfx/layers/SharedTextureImage.h
gfx/layers/client/ImageClient.cpp
gfx/layers/composite/TextureHost.cpp
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/ipc/ShadowLayerUtils.h
gfx/layers/moz.build
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.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.cpp
gfx/layers/opengl/TexturePoolOGL.h
gfx/thebes/moz.build
gfx/thebes/nsSurfaceTexture.cpp
gfx/thebes/nsSurfaceTexture.h
mobile/android/app/mobile.js
mobile/android/base/GeckoAppShell.java
widget/android/AndroidBridge.cpp
widget/android/AndroidJNI.cpp
widget/android/AndroidJavaWrappers.cpp
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedSDKWrappers.cpp
widget/android/GeneratedSDKWrappers.h
widget/android/moz.build
--- a/configure.in
+++ b/configure.in
@@ -5175,25 +5175,18 @@ MOZ_ARG_DISABLE_BOOL(ffmpeg,
 
 if test -n "$MOZ_FFMPEG"; then
     AC_DEFINE(MOZ_FFMPEG)
 fi;
 
 dnl ========================================================
 dnl = Built-in fragmented MP4 support.
 dnl ========================================================
-
-if test "$OS_TARGET" = Android; then
-    MOZ_FMP4=1
-fi
-
 if test -n "$MOZ_WMF" -o -n "$MOZ_FFMPEG" -o -n "$MOZ_APPLEMEDIA"; then
-    dnl Enable fragmented MP4 parser on Windows by default.
-    dnl We will also need to enable it on other platforms as we implement
-    dnl platform decoder support there too.
+    dnl Enable fragmented MP4 parser on platforms with decoder support.
     MOZ_FMP4=1
 fi
 
 MOZ_ARG_DISABLE_BOOL(fmp4,
 [  --disable-fmp4  Disable support for in built Fragmented MP4 parsing],
     MOZ_FMP4=,
     MOZ_FMP4=1)
 
--- a/content/media/fmp4/MP4Decoder.cpp
+++ b/content/media/fmp4/MP4Decoder.cpp
@@ -19,19 +19,16 @@
 #endif
 #ifdef MOZ_FFMPEG
 #include "FFmpegRuntimeLinker.h"
 #endif
 #ifdef MOZ_APPLEMEDIA
 #include "apple/AppleCMLinker.h"
 #include "apple/AppleVTLinker.h"
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-#include "AndroidBridge.h"
-#endif
 
 namespace mozilla {
 
 MediaDecoderStateMachine* MP4Decoder::CreateStateMachine()
 {
   return new MediaDecoderStateMachine(this, new MP4Reader(this));
 }
 
@@ -177,20 +174,16 @@ IsGonkMP4DecoderAvailable()
 static bool
 HavePlatformMPEGDecoders()
 {
   return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") ||
 #ifdef XP_WIN
          // We have H.264/AAC platform decoders on Windows Vista and up.
          IsVistaOrLater() ||
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-         // We need android.media.MediaCodec which exists in API level 16 and higher.
-         (AndroidBridge::Bridge()->GetAPIVersion() >= 16) ||
-#endif
          IsFFmpegAvailable() ||
          IsAppleAvailable() ||
          IsGonkMP4DecoderAvailable() ||
          // TODO: Other platforms...
          false;
 }
 
 /* static */
--- a/content/media/fmp4/PlatformDecoderModule.cpp
+++ b/content/media/fmp4/PlatformDecoderModule.cpp
@@ -12,65 +12,52 @@
 #include "FFmpegRuntimeLinker.h"
 #endif
 #ifdef MOZ_APPLEMEDIA
 #include "AppleDecoderModule.h"
 #endif
 #ifdef MOZ_GONK_MEDIACODEC
 #include "GonkDecoderModule.h"
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-#include "AndroidDecoderModule.h"
-#endif
 
 #include "mozilla/Preferences.h"
 #ifdef MOZ_EME
 #include "EMEDecoderModule.h"
 #include "mozilla/CDMProxy.h"
 #endif
 #include "SharedThreadPool.h"
 #include "MediaTaskQueue.h"
 
 namespace mozilla {
 
 extern PlatformDecoderModule* CreateBlankDecoderModule();
 
 bool PlatformDecoderModule::sUseBlankDecoder = false;
 bool PlatformDecoderModule::sFFmpegDecoderEnabled = false;
 bool PlatformDecoderModule::sGonkDecoderEnabled = false;
-bool PlatformDecoderModule::sAndroidMCDecoderEnabled = false;
-bool PlatformDecoderModule::sAndroidMCDecoderPreferred = false;
 
 /* static */
 void
 PlatformDecoderModule::Init()
 {
   MOZ_ASSERT(NS_IsMainThread());
   static bool alreadyInitialized = false;
   if (alreadyInitialized) {
     return;
   }
   alreadyInitialized = true;
 
   Preferences::AddBoolVarCache(&sUseBlankDecoder,
                                "media.fragmented-mp4.use-blank-decoder");
   Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled,
                                "media.fragmented-mp4.ffmpeg.enabled", false);
-
 #ifdef MOZ_GONK_MEDIACODEC
   Preferences::AddBoolVarCache(&sGonkDecoderEnabled,
                                "media.fragmented-mp4.gonk.enabled", false);
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-  Preferences::AddBoolVarCache(&sAndroidMCDecoderEnabled,
-                               "media.fragmented-mp4.android-media-codec.enabled", false);
-  Preferences::AddBoolVarCache(&sAndroidMCDecoderPreferred,
-                               "media.fragmented-mp4.android-media-codec.preferred", false);
-#endif
-
 #ifdef XP_WIN
   WMFDecoderModule::Init();
 #endif
 #ifdef MOZ_APPLEMEDIA
   AppleDecoderModule::Init();
 #endif
 }
 
@@ -130,21 +117,16 @@ PlatformDecoderModule::CreateCDMWrapper(
 
 /* static */
 PlatformDecoderModule*
 PlatformDecoderModule::Create()
 {
   // Note: This runs on the decode thread.
   MOZ_ASSERT(!NS_IsMainThread());
 
-#ifdef MOZ_WIDGET_ANDROID
-  if(sAndroidMCDecoderPreferred && sAndroidMCDecoderEnabled){
-    return new AndroidDecoderModule();
-  }
-#endif
   if (sUseBlankDecoder) {
     return CreateBlankDecoderModule();
   }
 #ifdef XP_WIN
   nsAutoPtr<WMFDecoderModule> m(new WMFDecoderModule());
   if (NS_SUCCEEDED(m->Startup())) {
     return m.forget();
   }
@@ -163,21 +145,16 @@ PlatformDecoderModule::Create()
     return m.forget();
   }
 #endif
 #ifdef MOZ_GONK_MEDIACODEC
   if (sGonkDecoderEnabled) {
     return new GonkDecoderModule();
   }
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-  if(sAndroidMCDecoderEnabled){
-    return new AndroidDecoderModule();
-  }
-#endif
   return nullptr;
 }
 
 bool
 PlatformDecoderModule::SupportsAudioMimeType(const char* aMimeType)
 {
   return !strcmp(aMimeType, "audio/mp4a-latm");
 }
--- a/content/media/fmp4/PlatformDecoderModule.h
+++ b/content/media/fmp4/PlatformDecoderModule.h
@@ -126,18 +126,16 @@ public:
   virtual ~PlatformDecoderModule() {}
 
 protected:
   PlatformDecoderModule() {}
   // Caches pref media.fragmented-mp4.use-blank-decoder
   static bool sUseBlankDecoder;
   static bool sFFmpegDecoderEnabled;
   static bool sGonkDecoderEnabled;
-  static bool sAndroidMCDecoderPreferred;
-  static bool sAndroidMCDecoderEnabled;
 };
 
 // A callback used by MediaDataDecoder to return output/errors to the
 // MP4Reader. Implementation is threadsafe, and can be called on any thread.
 class MediaDataDecoderCallback {
 public:
   virtual ~MediaDataDecoderCallback() {}
 
deleted file mode 100644
--- a/content/media/fmp4/android/AndroidDecoderModule.cpp
+++ /dev/null
@@ -1,499 +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/. */
-
-#include "AndroidDecoderModule.h"
-#include "PlatformDecoderModule.h"
-#include "GeneratedJNIWrappers.h"
-#include "GeneratedSDKWrappers.h"
-#include "AndroidBridge.h"
-#include "MediaTaskQueue.h"
-#include "SharedThreadPool.h"
-#include "TexturePoolOGL.h"
-#include "GLImages.h"
-
-#include "MediaData.h"
-
-#include "mp4_demuxer/AnnexB.h"
-#include "mp4_demuxer/DecoderData.h"
-
-#include "nsThreadUtils.h"
-#include "nsAutoPtr.h"
-
-#include <jni.h>
-
-using namespace mozilla;
-using namespace mozilla::gl;
-using namespace mozilla::widget::android;
-
-namespace mozilla {
-
-static MediaCodec* CreateDecoder(JNIEnv* aEnv, const char* aMimeType)
-{
-  if (!aMimeType) {
-    return nullptr;
-  }
-
-  nsAutoString mimeType;
-  mimeType.AssignASCII(aMimeType);
-
-  jobject decoder = MediaCodec::CreateDecoderByType(mimeType);
-
-  return new MediaCodec(decoder, aEnv);
-}
-
-class VideoDataDecoder : public MediaCodecDataDecoder {
-public:
-  VideoDataDecoder(const mp4_demuxer::VideoDecoderConfig& aConfig,
-                   MediaFormat* aFormat, MediaDataDecoderCallback* aCallback,
-                   layers::ImageContainer* aImageContainer)
-    : MediaCodecDataDecoder(MediaData::Type::VIDEO_FRAME, aConfig.mime_type, aFormat, aCallback)
-    , mImageContainer(aImageContainer)
-    , mConfig(aConfig)
-  {
-
-  }
-
-  nsresult Init() MOZ_OVERRIDE {
-    mSurfaceTexture = AndroidSurfaceTexture::Create();
-    if (!mSurfaceTexture) {
-      printf_stderr("Failed to create SurfaceTexture for video decode\n");
-      return NS_ERROR_FAILURE;
-    }
-
-    return InitDecoder(mSurfaceTexture->JavaSurface());
-  }
-
-  virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE {
-    mp4_demuxer::AnnexB::ConvertSample(aSample, mConfig.annex_b);
-    return MediaCodecDataDecoder::Input(aSample);
-  }
-
-  virtual nsresult PostOutput(BufferInfo* aInfo, MediaFormat* aFormat, Microseconds aDuration) MOZ_OVERRIDE {
-    VideoInfo videoInfo;
-    videoInfo.mDisplay = nsIntSize(mConfig.display_width, mConfig.display_height);
-
-    bool isSync = false;
-    if (MediaCodec::getBUFFER_FLAG_SYNC_FRAME() & aInfo->getFlags()) {
-      isSync = true;
-    }
-
-    nsRefPtr<layers::Image> img = mImageContainer->CreateImage(ImageFormat::SURFACE_TEXTURE);
-    layers::SurfaceTextureImage::Data data;
-    data.mSurfTex = mSurfaceTexture.get();
-    data.mSize = gfx::IntSize(mConfig.display_width, mConfig.display_height);
-    data.mInverted = true;
-
-    layers::SurfaceTextureImage* typedImg = static_cast<layers::SurfaceTextureImage*>(img.get());
-    typedImg->SetData(data);
-
-    mCallback->Output(VideoData::CreateFromImage(videoInfo, mImageContainer, aInfo->getOffset(),
-                                                 aInfo->getPresentationTimeUs(),
-                                                 aDuration,
-                                                 img, isSync,
-                                                 aInfo->getPresentationTimeUs(),
-                                                 gfx::IntRect(0, 0,
-                                                   mConfig.display_width,
-                                                   mConfig.display_height)));
-    return NS_OK;
-  }
-
-protected:
-  layers::ImageContainer* mImageContainer;
-  const mp4_demuxer::VideoDecoderConfig& mConfig;
-  nsRefPtr<AndroidSurfaceTexture> mSurfaceTexture;
-};
-
-class AudioDataDecoder : public MediaCodecDataDecoder {
-public:
-  AudioDataDecoder(const char* aMimeType, MediaFormat* aFormat, MediaDataDecoderCallback* aCallback)
-  : MediaCodecDataDecoder(MediaData::Type::AUDIO_SAMPLES, aMimeType, aFormat, aCallback)
-  {
-  }
-
-  nsresult Output(BufferInfo* aInfo, void* aBuffer, MediaFormat* aFormat, Microseconds aDuration) {
-    // The output on Android is always 16-bit signed
-
-    uint32_t numChannels = aFormat->GetInteger(NS_LITERAL_STRING("channel-count"));
-    uint32_t sampleRate = aFormat->GetInteger(NS_LITERAL_STRING("sample-rate"));
-    uint32_t numFrames = (aInfo->getSize() / numChannels) / 2;
-
-    AudioDataValue* audio = new AudioDataValue[aInfo->getSize()];
-    PodCopy(audio, static_cast<AudioDataValue*>(aBuffer), aInfo->getSize());
-
-    mCallback->Output(new AudioData(aInfo->getOffset(), aInfo->getPresentationTimeUs(),
-                                    aDuration,
-                                    numFrames,
-                                    audio,
-                                    numChannels,
-                                    sampleRate));
-    return NS_OK;
-  }
-};
-
-
-bool AndroidDecoderModule::SupportsAudioMimeType(const char* aMimeType) {
-  JNIEnv* env = GetJNIForThread();
-  MediaCodec* decoder = CreateDecoder(env, aMimeType);
-  bool supports = (decoder != nullptr);
-  delete decoder;
-  return supports;
-}
-
-already_AddRefed<MediaDataDecoder>
-AndroidDecoderModule::CreateH264Decoder(
-                                const mp4_demuxer::VideoDecoderConfig& aConfig,
-                                layers::LayersBackend aLayersBackend,
-                                layers::ImageContainer* aImageContainer,
-                                MediaTaskQueue* aVideoTaskQueue,
-                                MediaDataDecoderCallback* aCallback)
-{
-  nsAutoString mimeType;
-  mimeType.AssignASCII(aConfig.mime_type);
-
-  jobject jFormat = MediaFormat::CreateVideoFormat(mimeType,
-                                                   aConfig.display_width,
-                                                   aConfig.display_height);
-
-  if (!jFormat) {
-    return nullptr;
-  }
-
-  MediaFormat* format = MediaFormat::Wrap(jFormat);
-
-  if (!format) {
-    return nullptr;
-  }
-
-  nsRefPtr<MediaDataDecoder> decoder =
-    new VideoDataDecoder(aConfig, format, aCallback, aImageContainer);
-
-  return decoder.forget();
-}
-
-already_AddRefed<MediaDataDecoder>
-AndroidDecoderModule::CreateAudioDecoder(const mp4_demuxer::AudioDecoderConfig& aConfig,
-                                         MediaTaskQueue* aAudioTaskQueue,
-                                         MediaDataDecoderCallback* aCallback)
-{
-  MOZ_ASSERT(aConfig.bits_per_sample == 16, "We only handle 16-bit audio!");
-
-  nsAutoString mimeType;
-  mimeType.AssignASCII(aConfig.mime_type);
-
-  jobject jFormat = MediaFormat::CreateAudioFormat(mimeType,
-                                                   aConfig.samples_per_second,
-                                                   aConfig.channel_count);
-
-  if (jFormat == nullptr)
-    return nullptr;
-
-  MediaFormat* format = MediaFormat::Wrap(jFormat);
-
-  if(format == nullptr)
-    return nullptr;
-
-  JNIEnv* env = GetJNIForThread();
-
-  if (!format->GetByteBuffer(NS_LITERAL_STRING("csd-0"))) {
-    uint8_t* csd0 = new uint8_t[2];
-
-    csd0[0] = aConfig.audio_specific_config[0];
-    csd0[1] = aConfig.audio_specific_config[1];
-
-    jobject buffer = env->NewDirectByteBuffer(csd0, 2);
-    format->SetByteBuffer(NS_LITERAL_STRING("csd-0"), buffer);
-
-    env->DeleteLocalRef(buffer);
-  }
-
-  if (mimeType.EqualsLiteral("audio/mp4a-latm")) {
-    format->SetInteger(NS_LITERAL_STRING("is-adts"), 1);
-  }
-
-  nsRefPtr<MediaDataDecoder> decoder =
-    new AudioDataDecoder(aConfig.mime_type, format, aCallback);
-
-  return decoder.forget();
-
-}
-
-
-nsresult AndroidDecoderModule::Shutdown()
-{
-  return NS_OK;
-}
-
-MediaCodecDataDecoder::MediaCodecDataDecoder(MediaData::Type aType,
-                                             const char* aMimeType,
-                                             MediaFormat* aFormat,
-                                             MediaDataDecoderCallback* aCallback)
-  : mType(aType)
-  , mMimeType(strdup(aMimeType))
-  , mFormat(aFormat)
-  , mCallback(aCallback)
-  , mInputBuffers(nullptr)
-  , mOutputBuffers(nullptr)
-  , mMonitor("MediaCodecDataDecoder::mMonitor")
-  , mDraining(false)
-  , mStopping(false)
-{
-
-}
-
-MediaCodecDataDecoder::~MediaCodecDataDecoder()
-{
-  JNIEnv* env = GetJNIForThread();
-
-  Shutdown();
-
-  if (mInputBuffers) {
-    env->DeleteGlobalRef(mInputBuffers);
-    mInputBuffers = nullptr;
-  }
-
-  if (mOutputBuffers) {
-    env->DeleteGlobalRef(mOutputBuffers);
-    mOutputBuffers = nullptr;
-  }
-}
-
-nsresult MediaCodecDataDecoder::Init()
-{
-  return InitDecoder();
-}
-
-nsresult MediaCodecDataDecoder::InitDecoder(jobject aSurface)
-{
-  JNIEnv* env = GetJNIForThread();
-  mDecoder = CreateDecoder(env, mMimeType);
-  if (!mDecoder) {
-    mCallback->Error();
-    return NS_ERROR_FAILURE;
-  }
-
-  if (!mDecoder->Configure(mFormat->wrappedObject(), aSurface, nullptr, 0)) {
-    mCallback->Error();
-    return NS_ERROR_FAILURE;
-  }
-
-  mDecoder->Start();
-
-  ResetInputBuffers();
-  ResetOutputBuffers();
-
-  NS_NewNamedThread("MC Decoder", getter_AddRefs(mThread),
-                    NS_NewRunnableMethod(this, &MediaCodecDataDecoder::DecoderLoop));
-
-  return NS_OK;
-}
-
-// This is in usec, so that's 10ms
-#define DECODER_TIMEOUT 10000
-
-void MediaCodecDataDecoder::DecoderLoop()
-{
-  bool outputDone = false;
-
-  JNIEnv* env = GetJNIForThread();
-  mp4_demuxer::MP4Sample* sample = nullptr;
-
-  nsAutoPtr<MediaFormat> outputFormat;
-
-  for (;;) {
-    {
-      MonitorAutoLock lock(mMonitor);
-      while (!mStopping && !mDraining && mQueue.empty()) {
-        if (mQueue.empty()) {
-          // We could be waiting here forever if we don't signal that we need more input
-          mCallback->InputExhausted();
-        }
-        lock.Wait();
-      }
-
-      if (mStopping) {
-        // Get out of the loop. This is the only exit point.
-        break;
-      }
-
-      if (mDraining) {
-        mDecoder->Flush();
-        ClearQueue();
-        mDraining =  false;
-        lock.Notify();
-        continue;
-      }
-
-      // We're not stopping or draining, so try to get a sample
-      if (!mQueue.empty()) {
-        sample = mQueue.front();
-      }
-    }
-
-    if (sample) {
-      // We have a sample, try to feed it to the decoder
-      int inputIndex = mDecoder->DequeueInputBuffer(DECODER_TIMEOUT);
-      if (inputIndex >= 0) {
-        jobject buffer = env->GetObjectArrayElement(mInputBuffers, inputIndex);
-        void* directBuffer = env->GetDirectBufferAddress(buffer);
-
-        // We're feeding this to the decoder, so remove it from the queue
-        mMonitor.Lock();
-        mQueue.pop();
-        mMonitor.Unlock();
-
-        MOZ_ASSERT(env->GetDirectBufferCapacity(buffer) >= sample->size,
-          "Decoder buffer is not large enough for sample");
-
-        PodCopy((uint8_t*)directBuffer, sample->data, sample->size);
-
-        mDecoder->QueueInputBuffer(inputIndex, 0, sample->size, sample->composition_timestamp, 0);
-        mDurations.push(sample->duration);
-
-        delete sample;
-        sample = nullptr;
-
-        outputDone = false;
-        env->DeleteLocalRef(buffer);
-      }
-    }
-
-    if (!outputDone) {
-      BufferInfo bufferInfo;
-
-      int outputStatus = mDecoder->DequeueOutputBuffer(bufferInfo.wrappedObject(), DECODER_TIMEOUT);
-      if (outputStatus == MediaCodec::getINFO_TRY_AGAIN_LATER()) {
-        // We might want to call mCallback->InputExhausted() here, but there seems to be
-        // some possible bad interactions here with the threading
-      } else if (outputStatus == MediaCodec::getINFO_OUTPUT_BUFFERS_CHANGED()) {
-        ResetOutputBuffers();
-      } else if (outputStatus == MediaCodec::getINFO_OUTPUT_FORMAT_CHANGED()) {
-        outputFormat = new MediaFormat(mDecoder->GetOutputFormat(), GetJNIForThread());
-      } else if (outputStatus < 0) {
-        printf_stderr("unknown error from decoder! %d\n", outputStatus);
-        mCallback->Error();
-      } else {
-        // We have a valid buffer index >= 0 here
-        if (bufferInfo.getFlags() & MediaCodec::getBUFFER_FLAG_END_OF_STREAM()) {
-          outputDone = true;
-        }
-
-        MOZ_ASSERT(!mDurations.empty(), "Should have had a duration queued");
-
-        Microseconds duration = 0;
-        if (!mDurations.empty()) {
-          duration = mDurations.front();
-          mDurations.pop();
-        }
-
-        jobject buffer = env->GetObjectArrayElement(mOutputBuffers, outputStatus);
-        if (buffer) {
-          // The buffer will be null on Android L if we are decoding to a Surface
-          void* directBuffer = env->GetDirectBufferAddress(buffer);
-          Output(&bufferInfo, directBuffer, outputFormat, duration);
-        }
-
-        // The Surface will be updated at this point (for video)
-        mDecoder->ReleaseOutputBuffer(outputStatus, true);
-
-        PostOutput(&bufferInfo, outputFormat, duration);
-
-        if (buffer) {
-          env->DeleteLocalRef(buffer);
-        }
-      }
-    }
-  }
-
-  // We're done
-  mMonitor.Lock();
-  mStopping = false;
-  mMonitor.Notify();
-  mMonitor.Unlock();
-}
-
-void MediaCodecDataDecoder::ClearQueue()
-{
-  mMonitor.AssertCurrentThreadOwns();
-  while (!mQueue.empty()) {
-    delete mQueue.front();
-    mQueue.pop();
-  }
-  while (!mDurations.empty()) {
-    mDurations.pop();
-  }
-}
-
-nsresult MediaCodecDataDecoder::Input(mp4_demuxer::MP4Sample* aSample) {
-  MonitorAutoLock lock(mMonitor);
-  mQueue.push(aSample);
-  lock.NotifyAll();
-
-  return NS_OK;
-}
-
-void MediaCodecDataDecoder::ResetInputBuffers()
-{
-  JNIEnv* env = GetJNIForThread();
-
-  if (mInputBuffers) {
-    env->DeleteGlobalRef(mInputBuffers);
-  }
-
-  mInputBuffers = (jobjectArray) env->NewGlobalRef(mDecoder->GetInputBuffers());
-}
-
-void MediaCodecDataDecoder::ResetOutputBuffers()
-{
-  JNIEnv* env = GetJNIForThread();
-
-  if (mOutputBuffers) {
-    env->DeleteGlobalRef(mOutputBuffers);
-  }
-
-  mOutputBuffers = (jobjectArray) env->NewGlobalRef(mDecoder->GetOutputBuffers());
-}
-
-nsresult MediaCodecDataDecoder::Flush() {
-  Drain();
-  return NS_OK;
-}
-
-nsresult MediaCodecDataDecoder::Drain() {
-  MonitorAutoLock lock(mMonitor);
-  mDraining = true;
-  lock.Notify();
-
-  while (mDraining) {
-    lock.Wait();
-  }
-
-  mCallback->DrainComplete();
-  return NS_OK;
-}
-
-
-nsresult MediaCodecDataDecoder::Shutdown() {
-  MonitorAutoLock lock(mMonitor);
-
-  if (!mThread || mStopping) {
-    // Already shutdown or in the process of doing so
-    return NS_OK;
-  }
-
-  mStopping = true;
-  lock.Notify();
-
-  while (mStopping) {
-    lock.Wait();
-  }
-
-  mThread->Shutdown();
-  mThread = nullptr;
-
-  mDecoder->Stop();
-  mDecoder->Release();
-  return NS_OK;
-}
-
-} // mozilla
deleted file mode 100644
--- a/content/media/fmp4/android/AndroidDecoderModule.h
+++ /dev/null
@@ -1,109 +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/. */
-
-#ifndef AndroidDecoderModule_h_
-#define AndroidDecoderModule_h_
-
-#include "PlatformDecoderModule.h"
-#include "AndroidJavaWrappers.h"
-#include "AndroidSurfaceTexture.h"
-
-#include "GeneratedSDKWrappers.h"
-#include "mozilla/Monitor.h"
-
-#include <queue>
-
-namespace mozilla {
-
-typedef std::queue<mp4_demuxer::MP4Sample*> SampleQueue;
-
-namespace widget {
-namespace android {
-  class MediaCodec;
-  class MediaFormat;
-  class ByteBuffer;
-}
-}
-
-class MediaCodecDataDecoder;
-
-class AndroidDecoderModule : public PlatformDecoderModule {
-public:
-  virtual nsresult Shutdown() MOZ_OVERRIDE;
-
-  virtual already_AddRefed<MediaDataDecoder>
-  CreateH264Decoder(const mp4_demuxer::VideoDecoderConfig& aConfig,
-                    layers::LayersBackend aLayersBackend,
-                    layers::ImageContainer* aImageContainer,
-                    MediaTaskQueue* aVideoTaskQueue,
-                    MediaDataDecoderCallback* aCallback) MOZ_OVERRIDE;
-
-  virtual already_AddRefed<MediaDataDecoder>
-  CreateAudioDecoder(const mp4_demuxer::AudioDecoderConfig& aConfig,
-                     MediaTaskQueue* aAudioTaskQueue,
-                     MediaDataDecoderCallback* aCallback) MOZ_OVERRIDE;
-
-
-  AndroidDecoderModule() {}
-  virtual ~AndroidDecoderModule() {}
-
-  virtual bool SupportsAudioMimeType(const char* aMimeType) MOZ_OVERRIDE;
-};
-
-class MediaCodecDataDecoder : public MediaDataDecoder {
-public:
-
-  MediaCodecDataDecoder(MediaData::Type aType,
-                        const char* aMimeType,
-                        mozilla::widget::android::MediaFormat* aFormat,
-                        MediaDataDecoderCallback* aCallback);
-
-  virtual ~MediaCodecDataDecoder();
-
-  virtual nsresult Init() MOZ_OVERRIDE;
-  virtual nsresult Flush() MOZ_OVERRIDE;
-  virtual nsresult Drain() MOZ_OVERRIDE;
-  virtual nsresult Shutdown() MOZ_OVERRIDE;
-  virtual nsresult Input(mp4_demuxer::MP4Sample* aSample);
-
-protected:
-  friend class AndroidDecoderModule;
-
-  MediaData::Type mType;
-
-  nsAutoPtr<char> mMimeType;
-  nsAutoPtr<mozilla::widget::android::MediaFormat> mFormat;
-
-  MediaDataDecoderCallback* mCallback;
-
-  nsAutoPtr<mozilla::widget::android::MediaCodec> mDecoder;
-
-  jobjectArray mInputBuffers;
-  jobjectArray mOutputBuffers;
-
-  nsCOMPtr<nsIThread> mThread;
-
-  // Only these members are protected by mMonitor.
-  Monitor mMonitor;
-  bool mDraining;
-  bool mStopping;
-
-  SampleQueue mQueue;
-  std::queue<Microseconds> mDurations;
-
-  virtual nsresult InitDecoder(jobject aSurface = nullptr);
-
-  virtual nsresult Output(mozilla::widget::android::BufferInfo* aInfo, void* aBuffer, mozilla::widget::android::MediaFormat* aFormat, Microseconds aDuration) { return NS_OK; }
-  virtual nsresult PostOutput(mozilla::widget::android::BufferInfo* aInfo, mozilla::widget::android::MediaFormat* aFormat, Microseconds aDuration) { return NS_OK; }
-
-  void ResetInputBuffers();
-  void ResetOutputBuffers();
-
-  void DecoderLoop();
-  virtual void ClearQueue();
-};
-
-} // namwspace mozilla
-
-#endif
--- a/content/media/fmp4/moz.build
+++ b/content/media/fmp4/moz.build
@@ -20,17 +20,17 @@ SOURCES += [
     'MP4Reader.cpp',
 ]
 
 if CONFIG['MOZ_WMF']:
     DIRS += [ 'wmf' ];
 
 if CONFIG['MOZ_EME']:
     DIRS += ['eme']
-
+    
 if CONFIG['MOZ_FFMPEG']:
     EXPORTS += [
         'ffmpeg/FFmpegRuntimeLinker.h',
     ]
     UNIFIED_SOURCES += [
         'ffmpeg/FFmpegLog.cpp',
         'ffmpeg/FFmpegRuntimeLinker.cpp',
     ]
@@ -60,22 +60,14 @@ if CONFIG['MOZ_APPLEMEDIA']:
   ]
 
 if CONFIG['ANDROID_VERSION'] >= '18'and CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     DEFINES['MOZ_GONK_MEDIACODEC'] = True
     DIRS += ['gonk']
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
-    EXPORTS += [
-        'android/AndroidDecoderModule.h',
-    ]
-    UNIFIED_SOURCES += [
-        'android/AndroidDecoderModule.cpp',
-    ]
-
 FINAL_LIBRARY = 'xul'
 
 FAIL_ON_WARNINGS = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['NOMINMAX'] = True
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -51,20 +51,19 @@ using namespace mozilla::dom;
 #include "mozilla/Mutex.h"
 #include "mozilla/CondVar.h"
 #include "AndroidBridge.h"
 #include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/Hal.h"
 #include "GLContextProvider.h"
 #include "GLContext.h"
 #include "TexturePoolOGL.h"
+#include "GLSharedHandleHelpers.h"
 #include "SurfaceTypes.h"
-#include "EGLUtils.h"
 
-using namespace mozilla;
 using namespace mozilla::gl;
 
 typedef nsNPAPIPluginInstance::VideoInfo VideoInfo;
 
 class PluginEventRunnable : public nsRunnable
 {
 public:
   PluginEventRunnable(nsNPAPIPluginInstance* instance, ANPEvent* event)
@@ -123,35 +122,38 @@ public:
   }
 
   void Release(nsNPAPIPluginInstance::TextureInfo& aTextureInfo)
   {
     mTextureInfo = aTextureInfo;
     mLock.Unlock();
   }
 
-  EGLImage CreateEGLImage()
+  SharedTextureHandle CreateSharedHandle()
   {
     MutexAutoLock lock(mLock);
 
     if (!EnsureGLContext())
       return 0;
 
     if (mTextureInfo.mWidth == 0 || mTextureInfo.mHeight == 0)
       return 0;
 
-    GLuint& tex = mTextureInfo.mTexture;
-    EGLImage image = gl::CreateEGLImage(sPluginContext, tex);
+    SharedTextureHandle handle =
+      gl::CreateSharedHandle(sPluginContext,
+                             gl::SharedTextureShareType::SameProcess,
+                             (void*)mTextureInfo.mTexture,
+                             gl::SharedTextureBufferType::TextureID);
 
     // We want forget about this now, so delete the texture. Assigning it to zero
     // ensures that we create a new one in Lock()
-    sPluginContext->fDeleteTextures(1, &tex);
-    tex = 0;
+    sPluginContext->fDeleteTextures(1, &mTextureInfo.mTexture);
+    mTextureInfo.mTexture = 0;
 
-    return image;
+    return handle;
   }
 
 private:
   // Private destructor, to discourage deletion outside of Release():
   ~SharedPluginTexture()
   {
   }
 
@@ -942,27 +944,26 @@ nsNPAPIPluginInstance::TextureInfo nsNPA
 }
 
 void nsNPAPIPluginInstance::ReleaseContentTexture(nsNPAPIPluginInstance::TextureInfo& aTextureInfo)
 {
   EnsureSharedTexture();
   mContentTexture->Release(aTextureInfo);
 }
 
-AndroidSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
+nsSurfaceTexture* nsNPAPIPluginInstance::CreateSurfaceTexture()
 {
   if (!EnsureGLContext())
     return nullptr;
 
   GLuint texture = TexturePoolOGL::AcquireTexture();
   if (!texture)
     return nullptr;
 
-  AndroidSurfaceTexture* surface = AndroidSurfaceTexture::Create(TexturePoolOGL::GetGLContext(),
-                                                                 texture);
+  nsSurfaceTexture* surface = nsSurfaceTexture::Create(texture);
   if (!surface)
     return nullptr;
 
   nsCOMPtr<nsIRunnable> frameCallback = NS_NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable);
   surface->SetFrameAvailableCallback(frameCallback);
   return surface;
 }
 
@@ -976,46 +977,41 @@ void* nsNPAPIPluginInstance::AcquireCont
 {
   if (!mContentSurface) {
     mContentSurface = CreateSurfaceTexture();
 
     if (!mContentSurface)
       return nullptr;
   }
 
-  return mContentSurface->NativeWindow()->Handle();
+  return mContentSurface->GetNativeWindow();
 }
 
-EGLImage
-nsNPAPIPluginInstance::AsEGLImage()
+SharedTextureHandle nsNPAPIPluginInstance::CreateSharedHandle()
 {
-  if (!mContentTexture)
-    return 0;
-
-  return mContentTexture->CreateEGLImage();
-}
-
-AndroidSurfaceTexture*
-nsNPAPIPluginInstance::AsSurfaceTexture()
-{
-  if (!mContentSurface)
-    return nullptr;
-
-  return mContentSurface;
+  if (mContentTexture) {
+    return mContentTexture->CreateSharedHandle();
+  } else if (mContentSurface) {
+    EnsureGLContext();
+    return gl::CreateSharedHandle(sPluginContext,
+                                  gl::SharedTextureShareType::SameProcess,
+                                  mContentSurface,
+                                  gl::SharedTextureBufferType::SurfaceTexture);
+  } else return 0;
 }
 
 void* nsNPAPIPluginInstance::AcquireVideoWindow()
 {
-  AndroidSurfaceTexture* surface = CreateSurfaceTexture();
+  nsSurfaceTexture* surface = CreateSurfaceTexture();
   if (!surface)
     return nullptr;
 
   VideoInfo* info = new VideoInfo(surface);
 
-  void* window = info->mSurfaceTexture->NativeWindow()->Handle();
+  void* window = info->mSurfaceTexture->GetNativeWindow();
   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 "AndroidSurfaceTexture.h"
+#include "nsSurfaceTexture.h"
 #include "AndroidBridge.h"
 #include <map>
 class PluginEventRunnable;
 class SharedPluginTexture;
 #endif
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/PluginLibrary.h"
@@ -186,33 +186,32 @@ public:
   };
 
   TextureInfo LockContentTexture();
   void ReleaseContentTexture(TextureInfo& aTextureInfo);
 
   // For ANPNativeWindow
   void* AcquireContentWindow();
 
-  EGLImage AsEGLImage();
-  mozilla::gl::AndroidSurfaceTexture* AsSurfaceTexture();
+  mozilla::gl::SharedTextureHandle CreateSharedHandle();
 
   // For ANPVideo
   class VideoInfo {
   public:
-    VideoInfo(mozilla::gl::AndroidSurfaceTexture* aSurfaceTexture) :
+    VideoInfo(nsSurfaceTexture* aSurfaceTexture) :
       mSurfaceTexture(aSurfaceTexture)
     {
     }
 
     ~VideoInfo()
     {
       mSurfaceTexture = nullptr;
     }
 
-    nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mSurfaceTexture;
+    nsRefPtr<nsSurfaceTexture> mSurfaceTexture;
     gfxRect mDimensions;
   };
 
   void* AcquireVideoWindow();
   void ReleaseVideoWindow(void* aWindow);
   void SetVideoDimensions(void* aWindow, gfxRect aDimensions);
 
   void GetVideos(nsTArray<VideoInfo*>& aVideos);
@@ -329,17 +328,17 @@ protected:
   void OnSurfaceTextureFrameAvailable();
 
   uint32_t mFullScreenOrientation;
   bool mWakeLocked;
   bool mFullScreen;
   bool mInverted;
 
   nsRefPtr<SharedPluginTexture> mContentTexture;
-  nsRefPtr<mozilla::gl::AndroidSurfaceTexture> mContentSurface;
+  nsRefPtr<nsSurfaceTexture> mContentSurface;
 #endif
 
   enum {
     NOT_STARTED,
     RUNNING,
     DESTROYING,
     DESTROYED
   } mRunning;
@@ -378,17 +377,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();
-  mozilla::gl::AndroidSurfaceTexture* CreateSurfaceTexture();
+  nsSurfaceTexture* 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
@@ -17,17 +17,17 @@ using mozilla::DefaultXDisplay;
 
 #include "gfxUtils.h"
 #include "nsIRunnable.h"
 #include "nsContentUtils.h"
 #include "nsRect.h"
 #include "nsSize.h"
 #include "nsDisplayList.h"
 #include "ImageLayers.h"
-#include "GLImages.h"
+#include "SharedTextureImage.h"
 #include "nsObjectFrame.h"
 #include "nsIPluginDocument.h"
 #include "nsIStringStream.h"
 #include "nsNetUtil.h"
 #include "mozilla/Preferences.h"
 #include "nsILinkHandler.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIWebBrowserChrome.h"
@@ -44,17 +44,17 @@ using mozilla::DefaultXDisplay;
 #include "nsIFocusManager.h"
 #include "nsFocusManager.h"
 #include "nsIDOMDragEvent.h"
 #include "nsIScrollableFrame.h"
 #include "nsIDocShell.h"
 #include "ImageContainer.h"
 #include "nsIDOMHTMLCollection.h"
 #include "GLContext.h"
-#include "EGLUtils.h"
+#include "GLSharedHandleHelpers.h"
 #include "nsIContentInlines.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/HTMLObjectElementBinding.h"
 #include "nsFrameSelection.h"
 
 #include "nsContentCID.h"
@@ -143,72 +143,16 @@ nsPluginInstanceOwner::NotifyPaintWaiter
   if (!mWaitingForPaint && !IsUpToDate() && aBuilder->ShouldSyncDecodeImages()) {
     nsCOMPtr<nsIRunnable> event = new AsyncPaintWaitEvent(mContent, false);
     // Run this event as soon as it's safe to do so, since listeners need to
     // receive it immediately
     mWaitingForPaint = nsContentUtils::AddScriptRunner(event);
   }
 }
 
-#if MOZ_WIDGET_ANDROID
-static void
-AttachToContainerAsEGLImage(ImageContainer* container,
-                            nsNPAPIPluginInstance* instance,
-                            const LayoutDeviceRect& rect,
-                            nsRefPtr<Image>* out_image)
-{
-  MOZ_ASSERT(out_image);
-  MOZ_ASSERT(!*out_image);
-
-  EGLImage image = instance->AsEGLImage();
-  if (!image) {
-    return;
-  }
-
-  nsRefPtr<Image> img = container->CreateImage(ImageFormat::EGLIMAGE);
-
-  EGLImageImage::Data data;
-  data.mImage = image;
-  data.mSize = gfx::IntSize(rect.width, rect.height);
-  data.mInverted = instance->Inverted();
-
-  EGLImageImage* typedImg = static_cast<EGLImageImage*>(img.get());
-  typedImg->SetData(data);
-
-  *out_image = img;
-}
-
-static void
-AttachToContainerAsSurfaceTexture(ImageContainer* container,
-                                  nsNPAPIPluginInstance* instance,
-                                  const LayoutDeviceRect& rect,
-                                  nsRefPtr<Image>* out_image)
-{
-  MOZ_ASSERT(out_image);
-  MOZ_ASSERT(!*out_image);
-
-  mozilla::gl::AndroidSurfaceTexture* surfTex = instance->AsSurfaceTexture();
-  if (!surfTex) {
-    return;
-  }
-
-  nsRefPtr<Image> img = container->CreateImage(ImageFormat::SURFACE_TEXTURE);
-
-  SurfaceTextureImage::Data data;
-  data.mSurfTex = surfTex;
-  data.mSize = gfx::IntSize(rect.width, rect.height);
-  data.mInverted = instance->Inverted();
-
-  SurfaceTextureImage* typedImg = static_cast<SurfaceTextureImage*>(img.get());
-  typedImg->SetData(data);
-
-  *out_image = img;
-}
-#endif
-
 already_AddRefed<ImageContainer>
 nsPluginInstanceOwner::GetImageContainer()
 {
   if (!mInstance)
     return nullptr;
 
   nsRefPtr<ImageContainer> container;
 
@@ -223,29 +167,33 @@ nsPluginInstanceOwner::GetImageContainer
   // NotifySize() causes Flash to do a bunch of stuff like ask for surfaces to render
   // into, set y-flip flags, etc, so we do this at the beginning.
   gfxSize resolution = mObjectFrame->PresContext()->PresShell()->GetCumulativeResolution();
   ScreenSize screenSize = (r * LayoutDeviceToScreenScale(resolution.width, resolution.height)).Size();
   mInstance->NotifySize(nsIntSize(screenSize.width, screenSize.height));
 
   container = LayerManager::CreateImageContainer();
 
-  // Try to get it as an EGLImage first.
-  nsRefPtr<Image> img;
-  AttachToContainerAsEGLImage(container, mInstance, r, &img);
-  if (!img) {
-    AttachToContainerAsSurfaceTexture(container, mInstance, r, &img);
-  }
-  MOZ_ASSERT(img);
+  nsRefPtr<Image> img = container->CreateImage(ImageFormat::SHARED_TEXTURE);
+
+  SharedTextureImage::Data data;
+  data.mSize = gfx::IntSize(r.width, r.height);
+  data.mHandle = mInstance->CreateSharedHandle();
+  data.mShareType = mozilla::gl::SharedTextureShareType::SameProcess;
+  data.mInverted = mInstance->Inverted();
+
+  SharedTextureImage* pluginImage = static_cast<SharedTextureImage*>(img.get());
+  pluginImage->SetData(data);
 
   container->SetCurrentImageInTransaction(img);
-#else
+
+  return container.forget();
+#endif
+
   mInstance->GetImageContainer(getter_AddRefs(container));
-#endif
-
   return container.forget();
 }
 
 void
 nsPluginInstanceOwner::SetBackgroundUnknown()
 {
   if (mInstance) {
     mInstance->SetBackgroundUnknown();
@@ -1160,44 +1108,45 @@ void nsPluginInstanceOwner::RemovePlugin
   mozilla::widget::android::GeckoAppShell::RemovePluginView((jobject)mJavaView, mFullScreen);
   AndroidBridge::GetJNIEnv()->DeleteGlobalRef((jobject)mJavaView);
   mJavaView = nullptr;
 
   if (mFullScreen)
     sFullScreenInstance = nullptr;
 }
 
-void
-nsPluginInstanceOwner::GetVideos(nsTArray<nsNPAPIPluginInstance::VideoInfo*>& aVideos)
+void nsPluginInstanceOwner::GetVideos(nsTArray<nsNPAPIPluginInstance::VideoInfo*>& aVideos)
 {
   if (!mInstance)
     return;
 
   mInstance->GetVideos(aVideos);
 }
 
-already_AddRefed<ImageContainer>
-nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo)
+already_AddRefed<ImageContainer> nsPluginInstanceOwner::GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo)
 {
   nsRefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
 
-  nsRefPtr<Image> img = container->CreateImage(ImageFormat::SURFACE_TEXTURE);
-
-  SurfaceTextureImage::Data data;
-
-  data.mSurfTex = aVideoInfo->mSurfaceTexture;
+  nsRefPtr<Image> img = container->CreateImage(ImageFormat::SHARED_TEXTURE);
+
+  SharedTextureImage::Data data;
+
+  data.mShareType = gl::SharedTextureShareType::SameProcess;
+  data.mHandle = gl::CreateSharedHandle(mInstance->GLContext(),
+                                        data.mShareType,
+                                        aVideoInfo->mSurfaceTexture,
+                                        gl::SharedTextureBufferType::SurfaceTexture);
 
   // The logic below for Honeycomb is just a guess, but seems to work. We don't have a separate
   // inverted flag for video.
   data.mInverted = AndroidBridge::Bridge()->IsHoneycomb() ? true : mInstance->Inverted();
   data.mSize = gfx::IntSize(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height);
 
-  SurfaceTextureImage* typedImg = static_cast<SurfaceTextureImage*>(img.get());
-  typedImg->SetData(data);
-
+  SharedTextureImage* pluginImage = static_cast<SharedTextureImage*>(img.get());
+  pluginImage->SetData(data);
   container->SetCurrentImageInTransaction(img);
 
   return container.forget();
 }
 
 void nsPluginInstanceOwner::Invalidate() {
   NPRect rect;
   rect.left = rect.top = 0;
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -23,17 +23,17 @@
 #ifdef MOZ_X11
 #include "gfxXlibSurface.h"
 #endif
 #include "gfxContext.h"
 #include "gfxColor.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "Layers.h"
-#include "ImageContainer.h"
+#include "SharedTextureImage.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 #ifdef XP_MACOSX
 #include "MacIOSurfaceImage.h"
 #endif
 
 #if defined(OS_WIN)
deleted file mode 100644
--- a/gfx/gl/AndroidNativeWindow.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-#ifdef MOZ_WIDGET_ANDROID
-
-#include "AndroidNativeWindow.h"
-#include "prlink.h"
-
-// #define ANDROID_NATIVE_WINDOW_DEBUG
-
-#if defined(ANDROID_NATIVE_WINDOW_DEBUG) || defined(DEBUG)
-#define ALOG(args...)  __android_log_print(ANDROID_LOG_INFO, "AndroidNativeWindow" , ## args)
-#else
-#define ALOG(args...) ((void)0)
-#endif
-
-using namespace mozilla::gfx;
-using namespace mozilla::gl;
-using namespace mozilla;
-
-class NativeWindowLibrary
-{
-public:
-
-  NativeWindowLibrary()
-    : fANativeWindow_fromSurface(nullptr)
-    , fANativeWindow_release(nullptr)
-    , fANativeWindow_setBuffersGeometry(nullptr)
-    , fANativeWindow_lock(nullptr)
-    , fANativeWindow_unlockAndPost(nullptr)
-    , fANativeWindow_getFormat(nullptr)
-    , fANativeWindow_getWidth(nullptr)
-    , fANativeWindow_getHeight(nullptr)
-  {
-    PRLibrary* lib = PR_LoadLibrary("libandroid.so");
-
-    fANativeWindow_fromSurface = (pfnANativeWindow_fromSurface)PR_FindSymbol(lib, "ANativeWindow_fromSurface");
-    fANativeWindow_release = (pfnANativeWindow_release)PR_FindSymbol(lib, "ANativeWindow_release");
-    fANativeWindow_setBuffersGeometry = (pfnANativeWindow_setBuffersGeometry)PR_FindSymbol(lib, "ANativeWindow_setBuffersGeometry");
-    fANativeWindow_lock = (pfnANativeWindow_lock)PR_FindSymbol(lib, "ANativeWindow_lock");
-    fANativeWindow_unlockAndPost = (pfnANativeWindow_unlockAndPost)PR_FindSymbol(lib, "ANativeWindow_unlockAndPost");
-    fANativeWindow_getFormat = (pfnANativeWindow_getFormat)PR_FindSymbol(lib, "ANativeWindow_getFormat");
-    fANativeWindow_getWidth = (pfnANativeWindow_getWidth)PR_FindSymbol(lib, "ANativeWindow_getWidth");
-    fANativeWindow_getHeight = (pfnANativeWindow_getHeight)PR_FindSymbol(lib, "ANativeWindow_getHeight");
-  }
-
-  void* ANativeWindow_fromSurface(JNIEnv* aEnv, jobject aSurface) {
-    ALOG("%s: env=%p, surface=%p\n", __PRETTY_FUNCTION__, aEnv, aSurface);
-    if (!Initialized()) {
-      return nullptr;
-    }
-
-    return fANativeWindow_fromSurface(aEnv, aSurface);
-  }
-
-  void ANativeWindow_release(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return;
-    }
-
-    fANativeWindow_release(aWindow);
-  }
-
-  bool ANativeWindow_setBuffersGeometry(void* aWindow, int32_t aWidth, int32_t aHeight, int32_t aFormat) {
-    ALOG("%s: window=%p, width=%d, height=%d, format=%d\n", __PRETTY_FUNCTION__, aWindow, aWidth, aHeight, aFormat);
-    if (!Initialized()) {
-      return nullptr;
-    }
-
-    return fANativeWindow_setBuffersGeometry(aWindow, aWidth, aHeight, (int32_t)aFormat) == 0;
-  }
-
-  bool ANativeWindow_lock(void* aWindow, void* out_buffer, void*in_out_dirtyBounds) {
-    ALOG("%s: window=%p, out_buffer=%p, in_out_dirtyBounds=%p\n", __PRETTY_FUNCTION__,
-         aWindow, out_buffer, in_out_dirtyBounds);
-    if (!Initialized()) {
-      return false;
-    }
-
-    return fANativeWindow_lock(aWindow, out_buffer, in_out_dirtyBounds) == 0;
-  }
-
-  bool ANativeWindow_unlockAndPost(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return false;
-    }
-
-    return fANativeWindow_unlockAndPost(aWindow) == 0;
-  }
-
-  AndroidWindowFormat ANativeWindow_getFormat(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return AndroidWindowFormat::Unknown;
-    }
-
-    return (AndroidWindowFormat)fANativeWindow_getFormat(aWindow);
-  }
-
-  int32_t ANativeWindow_getWidth(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return -1;
-    }
-
-    return fANativeWindow_getWidth(aWindow);
-  }
-
-  int32_t ANativeWindow_getHeight(void* aWindow) {
-    ALOG("%s: window=%p\n", __PRETTY_FUNCTION__, aWindow);
-    if (!Initialized()) {
-      return -1;
-    }
-
-    return fANativeWindow_getHeight(aWindow);
-  }
-
-  bool Initialized() {
-    return fANativeWindow_fromSurface && fANativeWindow_release && fANativeWindow_setBuffersGeometry
-      && fANativeWindow_lock && fANativeWindow_unlockAndPost && fANativeWindow_getFormat && fANativeWindow_getWidth
-      && fANativeWindow_getHeight;
-  }
-
-private:
-
-  typedef void* (*pfnANativeWindow_fromSurface)(JNIEnv* env, jobject surface);
-  pfnANativeWindow_fromSurface fANativeWindow_fromSurface;
-
-  typedef void (*pfnANativeWindow_release)(void* window);
-  pfnANativeWindow_release fANativeWindow_release;
-
-  typedef int32_t (*pfnANativeWindow_setBuffersGeometry)(void* window, int32_t width, int32_t height, int32_t format);
-  pfnANativeWindow_setBuffersGeometry fANativeWindow_setBuffersGeometry;
-
-  typedef int32_t (*pfnANativeWindow_lock)(void *window, void *out_buffer, void *in_out_dirtyBounds);
-  pfnANativeWindow_lock fANativeWindow_lock;
-
-  typedef int32_t (*pfnANativeWindow_unlockAndPost)(void *window);
-  pfnANativeWindow_unlockAndPost fANativeWindow_unlockAndPost;
-
-  typedef AndroidWindowFormat (*pfnANativeWindow_getFormat)(void* window);
-  pfnANativeWindow_getFormat fANativeWindow_getFormat;
-
-  typedef int32_t (*pfnANativeWindow_getWidth)(void* window);
-  pfnANativeWindow_getWidth fANativeWindow_getWidth;
-
-  typedef int32_t (*pfnANativeWindow_getHeight)(void* window);
-  pfnANativeWindow_getHeight fANativeWindow_getHeight;
-};
-
-static NativeWindowLibrary* sLibrary = nullptr;
-
-static bool
-EnsureInit()
-{
-  static bool initialized = false;
-  if (!initialized) {
-    if (!sLibrary) {
-      sLibrary = new NativeWindowLibrary();
-    }
-    initialized = sLibrary->Initialized();
-  }
-
-  return initialized;
-}
-
-
-namespace mozilla {
-
-/* static */ AndroidNativeWindow*
-AndroidNativeWindow::CreateFromSurface(JNIEnv* aEnv, jobject aSurface)
-{
-  if (!EnsureInit()) {
-    ALOG("Not initialized");
-    return nullptr;
-  }
-
-  void* window = sLibrary->ANativeWindow_fromSurface(aEnv, aSurface);
-  if (!window) {
-    ALOG("Failed to create window from surface");
-    return nullptr;
-  }
-
-  return new AndroidNativeWindow(window);
-}
-
-AndroidNativeWindow::~AndroidNativeWindow()
-{
-  if (EnsureInit() && mWindow) {
-    sLibrary->ANativeWindow_release(mWindow);
-    mWindow = nullptr;
-  }
-}
-
-IntSize
-AndroidNativeWindow::Size()
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit()) {
-    return IntSize(0, 0);
-  }
-
-  return IntSize(sLibrary->ANativeWindow_getWidth(mWindow), sLibrary->ANativeWindow_getHeight(mWindow));
-}
-
-AndroidWindowFormat
-AndroidNativeWindow::Format()
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit()) {
-    return AndroidWindowFormat::Unknown;
-  }
-
-  return sLibrary->ANativeWindow_getFormat(mWindow);
-}
-
-bool
-AndroidNativeWindow::SetBuffersGeometry(int32_t aWidth, int32_t aHeight, AndroidWindowFormat aFormat)
-{
-  MOZ_ASSERT(mWindow);
-  if (!EnsureInit())
-    return false;
-
-  return sLibrary->ANativeWindow_setBuffersGeometry(mWindow, aWidth, aHeight, (int32_t)aFormat);
-}
-
-bool
-AndroidNativeWindow::Lock(void** out_bits,int32_t* out_width, int32_t* out_height,
-                          int32_t* out_stride, AndroidWindowFormat* out_format)
-{
-  /* Copied from native_window.h in Android NDK (platform-9) */
-  typedef struct ANativeWindow_Buffer {
-      // The number of pixels that are show horizontally.
-      int32_t width;
-
-      // The number of pixels that are shown vertically.
-      int32_t height;
-
-      // The number of *pixels* that a line in the buffer takes in
-      // memory.  This may be >= width.
-      int32_t stride;
-
-      // The format of the buffer.  One of WINDOW_FORMAT_*
-      int32_t format;
-
-      // The actual bits.
-      void* bits;
-
-      // Do not touch.
-      uint32_t reserved[6];
-  } ANativeWindow_Buffer; 
-
-
-  ANativeWindow_Buffer buffer;
-
-  if (!sLibrary->ANativeWindow_lock(mWindow, &buffer, nullptr)) {
-    ALOG("Failed to lock");
-    return false;
-  }
-
-  *out_bits = buffer.bits;
-  *out_width = buffer.width;
-  *out_height = buffer.height;
-  *out_stride = buffer.stride;
-  *out_format = (AndroidWindowFormat)buffer.format;
-  return true;
-}
-
-bool
-AndroidNativeWindow::UnlockAndPost()
-{
-  if (!EnsureInit()) {
-    ALOG("Not initialized");
-    return false;
-  }
-
-  return sLibrary->ANativeWindow_unlockAndPost(mWindow);
-}
-
-}
-
-#endif // MOZ_WIDGET_ANDROID
\ No newline at end of file
deleted file mode 100644
--- a/gfx/gl/AndroidNativeWindow.h
+++ /dev/null
@@ -1,68 +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 "GLDefs.h"
-
-#include "nsISupports.h"
-#include "mozilla/TypedEnum.h"
-#include "mozilla/gfx/2D.h"
-
-
-namespace mozilla {
-namespace gl {
-
-MOZ_BEGIN_ENUM_CLASS(AndroidWindowFormat)
-  Unknown = -1,
-  RGBA_8888 = 1,
-  RGBX_8888 = 1 << 1,
-  RGB_565 = 1 << 2
-MOZ_END_ENUM_CLASS(AndroidWindowFormat)
-
-/**
- * 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 AndroidNativeWindow {
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidNativeWindow)
-
-public:
-
-  static AndroidNativeWindow* CreateFromSurface(JNIEnv* aEnv, jobject aSurface);
-
-  gfx::IntSize Size();
-  AndroidWindowFormat Format();
-
-  bool SetBuffersGeometry(int32_t aWidth, int32_t aHeight, AndroidWindowFormat aFormat);
-
-  bool Lock(void** out_bits, int32_t* out_width, int32_t* out_height, int32_t* out_stride, AndroidWindowFormat* out_format);
-  bool UnlockAndPost();
-
-  void* Handle() { return mWindow; }
-
-protected:
-  AndroidNativeWindow(void* aWindow)
-    : mWindow(aWindow)
-  {
-
-  }
-
-  virtual ~AndroidNativeWindow();
-
-  void* mWindow;
-};
-
-}
-}
-
-
-#endif
-#endif
deleted file mode 100644
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ /dev/null
@@ -1,415 +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 "AndroidSurfaceTexture.h"
-#include "gfxImageSurface.h"
-#include "AndroidBridge.h"
-#include "nsThreadUtils.h"
-#include "mozilla/gfx/Matrix.h"
-#include "GeneratedJNIWrappers.h"
-#include "GLContext.h"
-
-using namespace mozilla;
-using namespace mozilla::widget::android;
-
-namespace mozilla {
-namespace gl {
-
-// UGH
-static std::map<int, AndroidSurfaceTexture*> sInstances;
-static int sNextID = 0;
-
-static bool
-IsDetachSupported()
-{
-  return AndroidBridge::Bridge()->GetAPIVersion() >= 16; /* Jelly Bean */
-}
-
-static bool
-IsSTSupported()
-{
-  return AndroidBridge::Bridge()->GetAPIVersion() >= 14; /* ICS */
-}
-
-static class JNIFunctions {
-public:
-
-  JNIFunctions() : mInitialized(false)
-  {
-  }
-
-  bool EnsureInitialized()
-  {
-    if (mInitialized) {
-      return true;
-    }
-
-    if (!IsSTSupported()) {
-      return false;
-    }
-
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-
-    jSurfaceTextureClass = (jclass)env->NewGlobalRef(env->FindClass("android/graphics/SurfaceTexture"));
-    jSurfaceTexture_Ctor = env->GetMethodID(jSurfaceTextureClass, "<init>", "(I)V");
-    jSurfaceTexture_updateTexImage = env->GetMethodID(jSurfaceTextureClass, "updateTexImage", "()V");
-    jSurfaceTexture_getTransformMatrix = env->GetMethodID(jSurfaceTextureClass, "getTransformMatrix", "([F)V");
-    jSurfaceTexture_setDefaultBufferSize = env->GetMethodID(jSurfaceTextureClass, "setDefaultBufferSize", "(II)V");
-
-    if (IsDetachSupported()) {
-      jSurfaceTexture_attachToGLContext = env->GetMethodID(jSurfaceTextureClass, "attachToGLContext", "(I)V");
-      jSurfaceTexture_detachFromGLContext = env->GetMethodID(jSurfaceTextureClass, "detachFromGLContext", "()V");
-    } else {
-      jSurfaceTexture_attachToGLContext = jSurfaceTexture_detachFromGLContext = 0;
-    }
-
-    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;
-  }
-
-  void SetDefaultBufferSize(jobject aSurfaceTexture, int32_t width, int32_t height)
-  {
-    JNIEnv* env = GetJNIForThread();
-
-    AutoLocalJNIFrame jniFrame(env);
-    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_setDefaultBufferSize, width, height);
-  }
-
-  void AttachToGLContext(jobject aSurfaceTexture, int32_t texName)
-  {
-    MOZ_ASSERT(jSurfaceTexture_attachToGLContext);
-
-    JNIEnv* env = GetJNIForThread();
-
-    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_attachToGLContext, texName);
-    if (env->ExceptionCheck()) {
-      env->ExceptionDescribe();
-      env->ExceptionClear();
-    }
-  }
-
-  void DetachFromGLContext(jobject aSurfaceTexture)
-  {
-    MOZ_ASSERT(jSurfaceTexture_detachFromGLContext);
-
-    JNIEnv* env = GetJNIForThread();
-
-    env->CallVoidMethod(aSurfaceTexture, jSurfaceTexture_detachFromGLContext);
-    if (env->ExceptionCheck()) {
-      env->ExceptionDescribe();
-      env->ExceptionClear();
-    }
-  }
-
-private:
-  bool mInitialized;
-
-  jclass jSurfaceTextureClass;
-  jmethodID jSurfaceTexture_Ctor;
-  jmethodID jSurfaceTexture_updateTexImage;
-  jmethodID jSurfaceTexture_getTransformMatrix;
-  jmethodID jSurfaceTexture_setDefaultBufferSize;
-
-  jmethodID jSurfaceTexture_attachToGLContext;
-  jmethodID jSurfaceTexture_detachFromGLContext;
-
-  jclass jSurfaceClass;
-  jmethodID jSurface_Ctor;
-
-} sJNIFunctions;
-
-AndroidSurfaceTexture*
-AndroidSurfaceTexture::Create()
-{
-  return Create(nullptr, 0);
-}
-
-AndroidSurfaceTexture*
-AndroidSurfaceTexture::Create(GLContext* aContext, GLuint aTexture)
-{
-  if (!IsSTSupported()) {
-    return nullptr;
-  }
-
-  AndroidSurfaceTexture* st = new AndroidSurfaceTexture();
-  if (!st->Init(aContext, 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::Attach(GLContext* aContext, PRIntervalTime aTimeout)
-{
-  MonitorAutoLock lock(mMonitor);
-
-  if (mAttachedContext == aContext) {
-    NS_WARNING("Tried to attach same GLContext to AndroidSurfaceTexture");
-    return true;
-  }
-
-  if (!IsDetachSupported()) {
-    return false;
-  }
-
-  while (mAttachedContext) {
-    // Wait until it's detached (or we time out)
-    if (NS_FAILED(lock.Wait(aTimeout))) {
-      return false;
-    }
-  }
-
-  MOZ_ASSERT(aContext->IsOwningThreadCurrent(), "Trying to attach GLContext from different thread");
-
-  mAttachedContext = aContext;
-  mAttachedContext->MakeCurrent();
-  aContext->fGenTextures(1, &mTexture);
-
-  sJNIFunctions.AttachToGLContext(mSurfaceTexture, mTexture);
-  return true;
-}
-
-bool
-AndroidSurfaceTexture::Detach()
-{
-  MonitorAutoLock lock(mMonitor);
-
-  if (!IsDetachSupported() ||
-      !mAttachedContext || !mAttachedContext->IsOwningThreadCurrent()) {
-    return false;
-  }
-
-  mAttachedContext->MakeCurrent();
-
-  // This call takes care of deleting the texture
-  sJNIFunctions.DetachFromGLContext(mSurfaceTexture);
-
-  mTexture = 0;
-  mAttachedContext = nullptr;
-  lock.NotifyAll();
-  return true;
-}
-
-bool
-AndroidSurfaceTexture::Init(GLContext* aContext, GLuint aTexture)
-{
-  if (!aTexture && !IsDetachSupported()) {
-    // We have no texture and cannot initialize detached, bail out
-    return false;
-  }
-
-  if (!sJNIFunctions.EnsureInitialized())
-    return false;
-
-  JNIEnv* env = GetJNIForThread();
-
-  mSurfaceTexture = sJNIFunctions.CreateSurfaceTexture(aTexture);
-  if (!mSurfaceTexture) {
-    return false;
-  }
-
-  if (!aTexture) {
-    sJNIFunctions.DetachFromGLContext(mSurfaceTexture);
-  }
-
-  mAttachedContext = aContext;
-
-  mSurface = sJNIFunctions.CreateSurface(mSurfaceTexture);
-  if (!mSurface) {
-    return false;
-  }
-
-  mNativeWindow = AndroidNativeWindow::CreateFromSurface(env, mSurface);
-
-  mID = ++sNextID;
-  sInstances.insert(std::pair<int, AndroidSurfaceTexture*>(mID, this));
-
-  return true;
-}
-
-AndroidSurfaceTexture::AndroidSurfaceTexture()
-  : mTexture(0)
-  , mSurfaceTexture(nullptr)
-  , mSurface(nullptr)
-  , mMonitor("AndroidSurfaceTexture::mContextMonitor")
-  , mAttachedContext(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::SetDefaultSize(mozilla::gfx::IntSize size)
-{
-  sJNIFunctions.SetDefaultBufferSize(mSurfaceTexture, size.width, size.height);
-}
-
-void
-AndroidSurfaceTexture::NotifyFrameAvailable()
-{
-  if (mFrameAvailableCallback) {
-    // Proxy to main thread if we aren't on it
-    if (!NS_IsMainThread()) {
-      // Proxy to main thread
-      nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable);
-      NS_DispatchToCurrentThread(event);
-    } else {
-      mFrameAvailableCallback->Run();
-    }
-  }
-}
-
-} // gl
-} // mozilla
-
-#endif // MOZ_WIDGET_ANDROID
deleted file mode 100644
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ /dev/null
@@ -1,117 +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 AndroidSurfaceTexture_h__
-#define AndroidSurfaceTexture_h__
-#ifdef MOZ_WIDGET_ANDROID
-
-#include <jni.h>
-#include "nsIRunnable.h"
-#include "gfxPlatform.h"
-#include "GLDefs.h"
-#include "mozilla/gfx/2D.h"
-#include "mozilla/Monitor.h"
-
-#include "AndroidNativeWindow.h"
-
-class gfxASurface;
-
-namespace mozilla {
-namespace gfx {
-class Matrix4x4;
-}
-}
-
-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:
-
-  // The SurfaceTexture is created in an attached state. This method requires
-  // Android Ice Cream Sandwich.
-  static 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 AndroidSurfaceTexture* Create();
-
-  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();
-
-  // 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.
-  bool Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT);
-
-  // This is a noop on ICS, and will always fail
-  bool Detach();
-
-  GLContext* GetAttachedContext() { return mAttachedContext; }
-
-  AndroidNativeWindow* NativeWindow() {
-    return mNativeWindow;
-  }
-
-  // This attaches the updated data to the TEXTURE_EXTERNAL target
-  void UpdateTexImage();
-
-  bool GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix);
-  int ID() { return mID; }
-
-  void SetDefaultSize(mozilla::gfx::IntSize size);
-
-  // The callback is guaranteed to be called on the main thread even
-  // if the upstream callback is received on a different thread
-  void SetFrameAvailableCallback(nsIRunnable* aRunnable);
-
-  // Only should be called by AndroidJNI when we get a
-  // callback from the underlying SurfaceTexture instance
-  void NotifyFrameAvailable();
-
-  GLuint Texture() { return mTexture; }
-  jobject JavaSurface() { return mSurface; }
-private:
-  AndroidSurfaceTexture();
-  ~AndroidSurfaceTexture();
-
-  bool Init(GLContext* aContext, GLuint aTexture);
-
-  GLuint mTexture;
-  jobject mSurfaceTexture;
-  jobject mSurface;
-
-  Monitor mMonitor;
-  GLContext* mAttachedContext;
-
-  RefPtr<AndroidNativeWindow> mNativeWindow;
-  int mID;
-  nsRefPtr<nsIRunnable> mFrameAvailableCallback;
-};
-
-}
-}
-
-
-#endif
-#endif
deleted file mode 100644
--- a/gfx/gl/EGLUtils.cpp
+++ /dev/null
@@ -1,114 +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/. */
-
-#include "EGLUtils.h"
-
-#include "GLContextEGL.h"
-
-namespace mozilla {
-namespace gl {
-
-bool
-DoesEGLContextSupportSharingWithEGLImage(GLContext* gl)
-{
-    return sEGLLibrary.HasKHRImageBase() &&
-           sEGLLibrary.HasKHRImageTexture2D() &&
-           gl->IsExtensionSupported(GLContext::OES_EGL_image);
-}
-
-EGLImage
-CreateEGLImage(GLContext* gl, GLuint tex)
-{
-    MOZ_ASSERT(DoesEGLContextSupportSharingWithEGLImage(gl));
-
-    EGLClientBuffer clientBuffer = (EGLClientBuffer)((uint64_t)tex);
-    EGLContext eglContext = GLContextEGL::Cast(gl)->GetEGLContext();
-    EGLImage image = sEGLLibrary.fCreateImage(EGL_DISPLAY(),
-                                              eglContext,
-                                              LOCAL_EGL_GL_TEXTURE_2D,
-                                              clientBuffer,
-                                              nullptr);
-    return image;
-}
-
-////////////////////////////////////////////////////////////////////////
-// EGLImageWrapper
-
-/*static*/ EGLImageWrapper*
-EGLImageWrapper::Create(GLContext* gl, GLuint tex)
-{
-    MOZ_ASSERT(DoesEGLContextSupportSharingWithEGLImage(gl));
-
-    GLLibraryEGL& library = sEGLLibrary;
-    EGLDisplay display = EGL_DISPLAY();
-    EGLContext eglContext = GLContextEGL::Cast(gl)->GetEGLContext();
-    EGLClientBuffer clientBuffer = (EGLClientBuffer)((uint64_t)tex);
-    EGLImage image = library.fCreateImage(display,
-                                          eglContext,
-                                          LOCAL_EGL_GL_TEXTURE_2D,
-                                          clientBuffer,
-                                          nullptr);
-    if (!image) {
-#ifdef DEBUG
-        printf_stderr("Could not create EGL images: ERROR (0x%04x)\n",
-                      sEGLLibrary.fGetError());
-#endif
-        return nullptr;
-    }
-
-    return new EGLImageWrapper(library, display, image);
-}
-
-EGLImageWrapper::~EGLImageWrapper()
-{
-    mLibrary.fDestroyImage(mDisplay, mImage);
-}
-
-bool
-EGLImageWrapper::FenceSync(GLContext* gl)
-{
-    MOZ_ASSERT(!mSync);
-
-    if (mLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync)) {
-        mSync = mLibrary.fCreateSync(mDisplay,
-                                     LOCAL_EGL_SYNC_FENCE,
-                                     nullptr);
-        // We need to flush to make sure the sync object enters the command stream;
-        // we can't use EGL_SYNC_FLUSH_COMMANDS_BIT at wait time, because the wait
-        // happens on a different thread/context.
-        gl->fFlush();
-    }
-
-    if (!mSync) {
-        // we failed to create one, so just do a finish
-        gl->fFinish();
-    }
-
-    return true;
-}
-
-bool
-EGLImageWrapper::ClientWaitSync()
-{
-    if (!mSync) {
-        // if we have no sync object, then we did a Finish() earlier
-        return true;
-    }
-
-    // wait at most 1 second; this should really be never/rarely hit
-    const uint64_t ns_per_ms = 1000 * 1000;
-    EGLTime timeout = 1000 * ns_per_ms;
-
-    EGLint result = mLibrary.fClientWaitSync(mDisplay,
-                                             mSync,
-                                             0,
-                                             timeout);
-    mLibrary.fDestroySync(mDisplay, mSync);
-    mSync = nullptr;
-
-    return result == LOCAL_EGL_CONDITION_SATISFIED;
-}
-
-} // namespace gl
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/gl/EGLUtils.h
+++ /dev/null
@@ -1,60 +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/. */
-
-#ifndef EGLUTILS_H_
-#define EGLUTILS_H_
-
-#include "GLContextTypes.h"
-#include "GLTypes.h"
-#include "mozilla/Assertions.h"
-
-namespace mozilla {
-namespace gl {
-
-class GLLibraryEGL;
-
-bool DoesEGLContextSupportSharingWithEGLImage(GLContext* gl);
-EGLImage CreateEGLImage(GLContext* gl, GLuint tex);
-
-////////////////////////////////////////////////////////////////////////
-// EGLImageWrapper
-
-class EGLImageWrapper
-{
-public:
-    static EGLImageWrapper* Create(GLContext* gl, GLuint tex);
-
-private:
-    GLLibraryEGL& mLibrary;
-    const EGLDisplay mDisplay;
-public:
-    const EGLImage mImage;
-private:
-    EGLSync mSync;
-
-    EGLImageWrapper(GLLibraryEGL& library,
-                    EGLDisplay display,
-                    EGLImage image)
-        : mLibrary(library)
-        , mDisplay(display)
-        , mImage(image)
-        , mSync(0)
-    {
-        MOZ_ASSERT(mImage);
-    }
-
-public:
-    ~EGLImageWrapper();
-
-    // Insert a sync point on the given context, which should be the current active
-    // context.
-    bool FenceSync(GLContext* gl);
-
-    bool ClientWaitSync();
-};
-
-} // namespace gl
-} // namespace mozilla
-
-#endif
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -5,28 +5,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GLBlitHelper.h"
 #include "GLContext.h"
 #include "ScopedGLHelpers.h"
 #include "mozilla/Preferences.h"
 #include "ImageContainer.h"
 #include "HeapCopyOfStackArray.h"
-#include "mozilla/gfx/Matrix.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "GrallocImages.h"
 #include "GLLibraryEGL.h"
 #endif
 
-#ifdef MOZ_WIDGET_ANDROID
-#include "AndroidSurfaceTexture.h"
-#include "GLImages.h"
-#endif
-
 using mozilla::layers::PlanarYCbCrImage;
 using mozilla::layers::PlanarYCbCrData;
 
 namespace mozilla {
 namespace gl {
 
 static void
 RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
@@ -145,17 +139,16 @@ GLBlitHelper::GLBlitHelper(GLContext* gl
     : mGL(gl)
     , mTexBlit_Buffer(0)
     , mTexBlit_VertShader(0)
     , mTex2DBlit_FragShader(0)
     , mTex2DRectBlit_FragShader(0)
     , mTex2DBlit_Program(0)
     , mTex2DRectBlit_Program(0)
     , mYFlipLoc(-1)
-    , mTextureTransformLoc(-1)
     , mTexExternalBlit_FragShader(0)
     , mTexYUVPlanarBlit_FragShader(0)
     , mTexExternalBlit_Program(0)
     , mTexYUVPlanarBlit_Program(0)
     , mFBO(0)
     , mSrcTexY(0)
     , mSrcTexCb(0)
     , mSrcTexCr(0)
@@ -240,33 +233,31 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
         varying vec2 vTexCoord;                                       \n\
                                                                       \n\
         void main(void)                                               \n\
         {                                                             \n\
             gl_FragColor = texture2DRect(uTexUnit,                    \n\
                                          vTexCoord * uTexCoordMult);  \n\
         }                                                             \n\
     ";
-#ifdef ANDROID /* MOZ_WIDGET_ANDROID || MOZ_WIDGET_GONK */
+#ifdef MOZ_WIDGET_GONK
     const char kTexExternalBlit_FragShaderSource[] = "\
-        #extension GL_OES_EGL_image_external : require                  \n\
-        #ifdef GL_FRAGMENT_PRECISION_HIGH                               \n\
-            precision highp float;                                      \n\
-        #else                                                           \n\
-            precision mediump float;                                    \n\
-        #endif                                                          \n\
-        varying vec2 vTexCoord;                                         \n\
-        uniform mat4 uTextureTransform;                                 \n\
-        uniform samplerExternalOES uTexUnit;                            \n\
-                                                                        \n\
-        void main()                                                     \n\
-        {                                                               \n\
-            gl_FragColor = texture2D(uTexUnit,                          \n\
-                (uTextureTransform * vec4(vTexCoord, 0.0, 1.0)).xy);    \n\
-        }                                                               \n\
+        #extension GL_OES_EGL_image_external : require      \n\
+        #ifdef GL_FRAGMENT_PRECISION_HIGH                   \n\
+            precision highp float;                          \n\
+        #else                                               \n\
+            precision mediump float;                        \n\
+        #endif                                              \n\
+        varying vec2 vTexCoord;                             \n\
+        uniform samplerExternalOES uTexUnit;                \n\
+                                                            \n\
+        void main()                                         \n\
+        {                                                   \n\
+            gl_FragColor = texture2D(uTexUnit, vTexCoord);  \n\
+        }                                                   \n\
     ";
 #endif
     /* From Rec601:
     [R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
     [G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
     [B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
 
     For [0,1] instead of [0,255], and to 5 places:
@@ -310,18 +301,17 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
         fragShaderPtr = &mTex2DBlit_FragShader;
         fragShaderSource = kTex2DBlit_FragShaderSource;
         break;
     case BlitTexRect:
         programPtr = &mTex2DRectBlit_Program;
         fragShaderPtr = &mTex2DRectBlit_FragShader;
         fragShaderSource = kTex2DRectBlit_FragShaderSource;
         break;
-#ifdef ANDROID
-    case ConvertSurfaceTexture:
+#ifdef MOZ_WIDGET_GONK
     case ConvertGralloc:
         programPtr = &mTexExternalBlit_Program;
         fragShaderPtr = &mTexExternalBlit_FragShader;
         fragShaderSource = kTexExternalBlit_FragShaderSource;
         break;
 #endif
     case ConvertPlanarYCbCr:
         programPtr = &mTexYUVPlanarBlit_Program;
@@ -446,19 +436,18 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
             break;
         }
 
         // Cache and set attribute and uniform
         mGL->fUseProgram(program);
         switch (target) {
             case BlitTex2D:
             case BlitTexRect:
-            case ConvertSurfaceTexture:
             case ConvertGralloc: {
-#ifdef ANDROID
+#ifdef MOZ_WIDGET_GONK
                 GLint texUnitLoc = mGL->fGetUniformLocation(program, "uTexUnit");
                 MOZ_ASSERT(texUnitLoc != -1, "uniform uTexUnit not found");
                 mGL->fUniform1i(texUnitLoc, 0);
                 break;
 #endif
             }
             case ConvertPlanarYCbCr: {
                 GLint texY = mGL->fGetUniformLocation(program, "uYTexture");
@@ -478,22 +467,16 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
                 mGL->fUniform1i(texCb, Channel_Cb);
                 mGL->fUniform1i(texCr, Channel_Cr);
                 break;
             }
         }
         MOZ_ASSERT(mGL->fGetAttribLocation(program, "aPosition") == 0);
         mYFlipLoc = mGL->fGetUniformLocation(program, "uYflip");
         MOZ_ASSERT(mYFlipLoc != -1, "uniform: uYflip not found");
-        mTextureTransformLoc = mGL->fGetUniformLocation(program, "uTextureTransform");
-        if (mTextureTransformLoc >= 0) {
-            // Set identity matrix as default
-            gfx::Matrix4x4 identity;
-            mGL->fUniformMatrix4fv(mTextureTransformLoc, 1, false, &identity._11);
-        }
         success = true;
     } while (false);
 
     if (!success) {
         // Clean up:
         DeleteTexBlitProgram();
         return false;
     }
@@ -712,52 +695,16 @@ GLBlitHelper::BlitGrallocImage(layers::G
     mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
 
     sEGLLibrary.fDestroyImage(sEGLLibrary.Display(), image);
     mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL_OES, oldBinding);
     return true;
 }
 #endif
 
-#ifdef MOZ_WIDGET_ANDROID
-
-bool
-GLBlitHelper::BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage)
-{
-    AndroidSurfaceTexture* surfaceTexture = stImage->GetData()->mSurfTex;
-    bool yFlip = stImage->GetData()->mInverted;
-
-    ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0);
-    mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
-
-    if (!surfaceTexture->Attach(mGL)) {
-        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->fUniform1f(mYFlipLoc, yFlip ? 1.0f : 0.0f);
-    mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
-
-    surfaceTexture->Detach();
-
-    mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, oldBinding);
-    return true;
-}
-#endif
-
 bool
 GLBlitHelper::BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage, bool yFlip)
 {
     ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0);
     const PlanarYCbCrData* yuvData = yuvImage->GetData();
 
     bool needsAllocation = false;
     if (mTexWidth != yuvData->mYStride || mTexHeight != yuvData->mYSize.height) {
@@ -786,52 +733,53 @@ GLBlitHelper::BlitPlanarYCbCrImage(layer
     for (int i = 0; i < 3; i++) {
         mGL->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
         mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, oldTex[i]);
     }
     return true;
 }
 
 bool
-GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage,
-                                     const gfx::IntSize& destSize,
-                                     GLuint destFB,
-                                     bool yFlip,
-                                     GLuint xoffset,
-                                     GLuint yoffset,
-                                     GLuint cropWidth,
-                                     GLuint cropHeight)
+GLBlitHelper::BlitImageToTexture(layers::Image* srcImage,
+                                 const gfx::IntSize& destSize,
+                                 GLuint destTex,
+                                 GLenum destTarget,
+                                 bool yFlip,
+                                 GLuint xoffset,
+                                 GLuint yoffset,
+                                 GLuint cropWidth,
+                                 GLuint cropHeight)
 {
     ScopedGLDrawState autoStates(mGL);
 
     BlitType type;
     switch (srcImage->GetFormat()) {
     case ImageFormat::PLANAR_YCBCR:
         type = ConvertPlanarYCbCr;
         break;
     case ImageFormat::GRALLOC_PLANAR_YCBCR:
 #ifdef MOZ_WIDGET_GONK
         type = ConvertGralloc;
         break;
 #endif
-#ifdef MOZ_WIDGET_ANDROID
-    case ImageFormat::SURFACE_TEXTURE:
-        type = ConvertSurfaceTexture;
-        break;
-#endif
     default:
         return false;
     }
 
     bool init = InitTexQuadProgram(type);
     if (!init) {
         return false;
     }
 
-    ScopedBindFramebuffer boundFB(mGL, destFB);
+    if (!mFBO) {
+        mGL->fGenFramebuffers(1, &mFBO);
+    }
+
+    ScopedBindFramebuffer boundFB(mGL, mFBO);
+    mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, destTarget, destTex, 0);
     mGL->fColorMask(LOCAL_GL_TRUE, LOCAL_GL_TRUE, LOCAL_GL_TRUE, LOCAL_GL_TRUE);
     mGL->fViewport(0, 0, destSize.width, destSize.height);
     if (xoffset != 0 && yoffset != 0 && cropWidth != 0 && cropHeight != 0) {
         mGL->fEnable(LOCAL_GL_SCISSOR_TEST);
         mGL->fScissor(xoffset, yoffset, (GLsizei)cropWidth, (GLsizei)cropHeight);
     }
 
 #ifdef MOZ_WIDGET_GONK
@@ -840,49 +788,20 @@ GLBlitHelper::BlitImageToFramebuffer(lay
         return BlitGrallocImage(grallocImage, yFlip);
     }
 #endif
     if (type == ConvertPlanarYCbCr) {
         mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 1);
         PlanarYCbCrImage* yuvImage = static_cast<PlanarYCbCrImage*>(srcImage);
         return BlitPlanarYCbCrImage(yuvImage, yFlip);
     }
-#ifdef MOZ_WIDGET_ANDROID
-    if (type == ConvertSurfaceTexture) {
-        layers::SurfaceTextureImage* stImage = static_cast<layers::SurfaceTextureImage*>(srcImage);
-        return BlitSurfaceTextureImage(stImage);
-    }
-#endif
 
     return false;
 }
 
-bool
-GLBlitHelper::BlitImageToTexture(layers::Image* srcImage,
-                                 const gfx::IntSize& destSize,
-                                 GLuint destTex,
-                                 GLenum destTarget,
-                                 bool yFlip,
-                                 GLuint xoffset,
-                                 GLuint yoffset,
-                                 GLuint cropWidth,
-                                 GLuint cropHeight)
-{
-    ScopedGLDrawState autoStates(mGL);
-
-    if (!mFBO) {
-        mGL->fGenFramebuffers(1, &mFBO);
-    }
-
-    ScopedBindFramebuffer boundFB(mGL, mFBO);
-    mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, destTarget, destTex, 0);
-    return BlitImageToFramebuffer(srcImage, destSize, mFBO, yFlip, xoffset, yoffset,
-                                  cropWidth, cropHeight);
-}
-
 void
 GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
                                        const gfx::IntSize& srcSize,
                                        const gfx::IntSize& destSize,
                                        GLenum srcTarget,
                                        bool internalFBs)
 {
     MOZ_ASSERT(mGL->fIsTexture(srcTex));
--- a/gfx/gl/GLBlitHelper.h
+++ b/gfx/gl/GLBlitHelper.h
@@ -14,17 +14,16 @@
 #include "mozilla/gfx/Point.h"
 
 namespace mozilla {
 
 namespace layers {
 class Image;
 class PlanarYCbCrImage;
 class GrallocImage;
-class SurfaceTextureImage;
 }
 
 namespace gl {
 
 class GLContext;
 
 /**
  * Helper function that creates a 2D texture aSize.width x aSize.height with
@@ -93,32 +92,29 @@ class GLBlitHelper MOZ_FINAL
      * Convert type is created for canvas.
      */
     enum BlitType
     {
         BlitTex2D,
         BlitTexRect,
         ConvertGralloc,
         ConvertPlanarYCbCr,
-        ConvertSurfaceTexture
     };
     // The GLContext is the sole owner of the GLBlitHelper.
     GLContext* mGL;
 
     GLuint mTexBlit_Buffer;
     GLuint mTexBlit_VertShader;
     GLuint mTex2DBlit_FragShader;
     GLuint mTex2DRectBlit_FragShader;
     GLuint mTex2DBlit_Program;
     GLuint mTex2DRectBlit_Program;
 
     GLint mYFlipLoc;
 
-    GLint mTextureTransformLoc;
-
     // Data for image blit path
     GLuint mTexExternalBlit_FragShader;
     GLuint mTexYUVPlanarBlit_FragShader;
     GLuint mTexExternalBlit_Program;
     GLuint mTexYUVPlanarBlit_Program;
     GLuint mFBO;
     GLuint mSrcTexY;
     GLuint mSrcTexCb;
@@ -141,19 +137,16 @@ class GLBlitHelper MOZ_FINAL
     void DeleteTexBlitProgram();
     void BindAndUploadYUVTexture(Channel which, uint32_t width, uint32_t height, void* data, bool allocation);
 
 #ifdef MOZ_WIDGET_GONK
     void BindAndUploadExternalTexture(EGLImage image);
     bool BlitGrallocImage(layers::GrallocImage* grallocImage, bool yFlip = false);
 #endif
     bool BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage, bool yFlip = false);
-#ifdef MOZ_WIDGET_ANDROID
-    bool BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage);
-#endif
 
 public:
 
     explicit GLBlitHelper(GLContext* gl);
     ~GLBlitHelper();
 
     // If you don't have |srcFormats| for the 2nd definition,
     // then you'll need the framebuffer_blit extensions to use
@@ -177,19 +170,16 @@ public:
                                   const gfx::IntSize& destSize,
                                   GLenum destTarget = LOCAL_GL_TEXTURE_2D,
                                   bool internalFBs = false);
     void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
                               const gfx::IntSize& srcSize,
                               const gfx::IntSize& destSize,
                               GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
                               GLenum destTarget = LOCAL_GL_TEXTURE_2D);
-    bool BlitImageToFramebuffer(layers::Image* srcImage, const gfx::IntSize& destSize,
-                                GLuint destFB, bool yFlip = false, GLuint xoffset = 0,
-                                GLuint yoffset = 0, GLuint width = 0, GLuint height = 0);
     bool BlitImageToTexture(layers::Image* srcImage, const gfx::IntSize& destSize,
                             GLuint destTex, GLenum destTarget, bool yFlip = false, GLuint xoffset = 0,
                             GLuint yoffset = 0, GLuint width = 0, GLuint height = 0);
 };
 
 }
 }
 
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -20,16 +20,17 @@
 #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/GLContextTypes.h
+++ b/gfx/gl/GLContextTypes.h
@@ -9,16 +9,29 @@
 #include "GLTypes.h"
 #include "mozilla/TypedEnum.h"
 
 namespace mozilla {
 namespace gl {
 
 class GLContext;
 
+typedef uintptr_t SharedTextureHandle;
+
+MOZ_BEGIN_ENUM_CLASS(SharedTextureShareType)
+    SameProcess = 0,
+    CrossProcess
+MOZ_END_ENUM_CLASS(SharedTextureShareType)
+
+MOZ_BEGIN_ENUM_CLASS(SharedTextureBufferType)
+    TextureID,
+    SurfaceTexture,
+    IOSurface
+MOZ_END_ENUM_CLASS(SharedTextureBufferType)
+
 MOZ_BEGIN_ENUM_CLASS(GLContextType)
     Unknown,
     WGL,
     CGL,
     GLX,
     EGL
 MOZ_END_ENUM_CLASS(GLContextType)
 
new file mode 100644
--- /dev/null
+++ b/gfx/gl/GLSharedHandleHelpers.cpp
@@ -0,0 +1,330 @@
+/* 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 "GLContextEGL.h"
+#include "GLSharedHandleHelpers.h"
+#ifdef MOZ_WIDGET_ANDROID
+#include "nsSurfaceTexture.h"
+#endif
+
+namespace mozilla {
+namespace gl {
+
+enum SharedHandleType {
+    SharedHandleType_Image
+#ifdef MOZ_WIDGET_ANDROID
+    , SharedHandleType_SurfaceTexture
+#endif
+};
+
+class SharedTextureHandleWrapper
+{
+public:
+    explicit SharedTextureHandleWrapper(SharedHandleType aHandleType) : mHandleType(aHandleType)
+    {
+    }
+
+    virtual ~SharedTextureHandleWrapper()
+    {
+    }
+
+    SharedHandleType Type() { return mHandleType; }
+
+    SharedHandleType mHandleType;
+};
+
+#ifdef MOZ_WIDGET_ANDROID
+
+class SurfaceTextureWrapper: public SharedTextureHandleWrapper
+{
+public:
+    SurfaceTextureWrapper(nsSurfaceTexture* aSurfaceTexture) :
+        SharedTextureHandleWrapper(SharedHandleType_SurfaceTexture)
+        , mSurfaceTexture(aSurfaceTexture)
+    {
+    }
+
+    virtual ~SurfaceTextureWrapper() {
+        mSurfaceTexture = nullptr;
+    }
+
+    nsSurfaceTexture* SurfaceTexture() { return mSurfaceTexture; }
+
+    nsRefPtr<nsSurfaceTexture> mSurfaceTexture;
+};
+
+#endif // MOZ_WIDGET_ANDROID
+
+class EGLTextureWrapper : public SharedTextureHandleWrapper
+{
+public:
+    EGLTextureWrapper() :
+        SharedTextureHandleWrapper(SharedHandleType_Image)
+        , mEGLImage(nullptr)
+        , mSyncObject(nullptr)
+    {
+    }
+
+    // Args are the active GL context, and a texture in that GL
+    // context for which to create an EGLImage.  After the EGLImage
+    // is created, the texture is unused by EGLTextureWrapper.
+    bool CreateEGLImage(GLContext *ctx, uintptr_t texture) {
+        MOZ_ASSERT(!mEGLImage && texture && sEGLLibrary.HasKHRImageBase());
+        static const EGLint eglAttributes[] = {
+            LOCAL_EGL_NONE
+        };
+        EGLContext eglContext = GLContextEGL::Cast(ctx)->GetEGLContext();
+        mEGLImage = sEGLLibrary.fCreateImage(EGL_DISPLAY(), eglContext, LOCAL_EGL_GL_TEXTURE_2D,
+                                             (EGLClientBuffer)texture, eglAttributes);
+        if (!mEGLImage) {
+#ifdef DEBUG
+            printf_stderr("Could not create EGL images: ERROR (0x%04x)\n", sEGLLibrary.fGetError());
+#endif
+            return false;
+        }
+        return true;
+    }
+
+    virtual ~EGLTextureWrapper() {
+        if (mEGLImage) {
+            sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mEGLImage);
+            mEGLImage = nullptr;
+        }
+    }
+
+    const EGLImage GetEGLImage() {
+        return mEGLImage;
+    }
+
+    // Insert a sync point on the given context, which should be the current active
+    // context.
+    bool MakeSync(GLContext *ctx) {
+        MOZ_ASSERT(mSyncObject == nullptr);
+
+        if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync)) {
+            mSyncObject = sEGLLibrary.fCreateSync(EGL_DISPLAY(), LOCAL_EGL_SYNC_FENCE, nullptr);
+            // We need to flush to make sure the sync object enters the command stream;
+            // we can't use EGL_SYNC_FLUSH_COMMANDS_BIT at wait time, because the wait
+            // happens on a different thread/context.
+            ctx->fFlush();
+        }
+
+        if (mSyncObject == EGL_NO_SYNC) {
+            // we failed to create one, so just do a finish
+            ctx->fFinish();
+        }
+
+        return true;
+    }
+
+    bool WaitSync() {
+        if (!mSyncObject) {
+            // if we have no sync object, then we did a Finish() earlier
+            return true;
+        }
+
+        // wait at most 1 second; this should really be never/rarely hit
+        const uint64_t ns_per_ms = 1000 * 1000;
+        EGLTime timeout = 1000 * ns_per_ms;
+
+        EGLint result = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), mSyncObject, 0, timeout);
+        sEGLLibrary.fDestroySync(EGL_DISPLAY(), mSyncObject);
+        mSyncObject = nullptr;
+
+        return result == LOCAL_EGL_CONDITION_SATISFIED;
+    }
+
+private:
+    EGLImage mEGLImage;
+    EGLSync mSyncObject;
+};
+
+static bool DoesEGLContextSupportSharingWithEGLImage(GLContext *gl)
+{
+    return sEGLLibrary.HasKHRImageBase() &&
+           sEGLLibrary.HasKHRImageTexture2D() &&
+           gl->IsExtensionSupported(GLContext::OES_EGL_image);
+}
+
+SharedTextureHandle CreateSharedHandle(GLContext* gl,
+                                       SharedTextureShareType shareType,
+                                       void* buffer,
+                                       SharedTextureBufferType bufferType)
+{
+    // unimplemented outside of EGL
+    if (gl->GetContextType() != GLContextType::EGL)
+        return 0;
+
+    // Both EGLImage and SurfaceTexture only support same-process currently, but
+    // it's possible to make SurfaceTexture work across processes. We should do that.
+    if (shareType != SharedTextureShareType::SameProcess)
+        return 0;
+
+    switch (bufferType) {
+#ifdef MOZ_WIDGET_ANDROID
+    case SharedTextureBufferType::SurfaceTexture:
+        if (!gl->IsExtensionSupported(GLContext::OES_EGL_image_external)) {
+            NS_WARNING("Missing GL_OES_EGL_image_external");
+            return 0;
+        }
+
+        return (SharedTextureHandle) new SurfaceTextureWrapper(reinterpret_cast<nsSurfaceTexture*>(buffer));
+#endif
+    case SharedTextureBufferType::TextureID: {
+        if (!DoesEGLContextSupportSharingWithEGLImage(gl))
+            return 0;
+
+        GLuint texture = (uintptr_t)buffer;
+        EGLTextureWrapper* tex = new EGLTextureWrapper();
+        if (!tex->CreateEGLImage(gl, texture)) {
+            NS_ERROR("EGLImage creation for EGLTextureWrapper failed");
+            delete tex;
+            return 0;
+        }
+
+        return (SharedTextureHandle)tex;
+    }
+    default:
+        NS_ERROR("Unknown shared texture buffer type");
+        return 0;
+    }
+}
+
+void ReleaseSharedHandle(GLContext* gl,
+                         SharedTextureShareType shareType,
+                         SharedTextureHandle sharedHandle)
+{
+    // unimplemented outside of EGL
+    if (gl->GetContextType() != GLContextType::EGL)
+        return;
+
+    if (shareType != SharedTextureShareType::SameProcess) {
+        NS_ERROR("Implementation not available for this sharing type");
+        return;
+    }
+
+    SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
+
+    switch (wrapper->Type()) {
+#ifdef MOZ_WIDGET_ANDROID
+    case SharedHandleType_SurfaceTexture:
+        delete wrapper;
+        break;
+#endif
+
+    case SharedHandleType_Image: {
+        NS_ASSERTION(DoesEGLContextSupportSharingWithEGLImage(gl), "EGLImage not supported or disabled in runtime");
+
+        EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
+        delete wrap;
+        break;
+    }
+
+    default:
+        NS_ERROR("Unknown shared handle type");
+        return;
+    }
+}
+
+bool GetSharedHandleDetails(GLContext* gl,
+                            SharedTextureShareType shareType,
+                            SharedTextureHandle sharedHandle,
+                            SharedHandleDetails& details)
+{
+    // unimplemented outside of EGL
+    if (gl->GetContextType() != GLContextType::EGL)
+        return false;
+
+    if (shareType != SharedTextureShareType::SameProcess)
+        return false;
+
+    SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
+
+    switch (wrapper->Type()) {
+#ifdef MOZ_WIDGET_ANDROID
+    case SharedHandleType_SurfaceTexture: {
+        SurfaceTextureWrapper* surfaceWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
+
+        details.mTarget = LOCAL_GL_TEXTURE_EXTERNAL;
+        details.mTextureFormat = gfx::SurfaceFormat::R8G8B8A8;
+        surfaceWrapper->SurfaceTexture()->GetTransformMatrix(details.mTextureTransform);
+        break;
+    }
+#endif
+
+    case SharedHandleType_Image:
+        details.mTarget = LOCAL_GL_TEXTURE_2D;
+        details.mTextureFormat = gfx::SurfaceFormat::R8G8B8A8;
+        break;
+
+    default:
+        NS_ERROR("Unknown shared handle type");
+        return false;
+    }
+
+    return true;
+}
+
+bool AttachSharedHandle(GLContext* gl,
+                        SharedTextureShareType shareType,
+                        SharedTextureHandle sharedHandle)
+{
+    // unimplemented outside of EGL
+    if (gl->GetContextType() != GLContextType::EGL)
+        return false;
+
+    if (shareType != SharedTextureShareType::SameProcess)
+        return false;
+
+    SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
+
+    switch (wrapper->Type()) {
+#ifdef MOZ_WIDGET_ANDROID
+    case SharedHandleType_SurfaceTexture: {
+#ifndef DEBUG
+        /*
+         * NOTE: SurfaceTexture spams us if there are any existing GL errors, so we'll clear
+         * them here in order to avoid that.
+         */
+        gl->GetAndClearError();
+#endif
+        SurfaceTextureWrapper* surfaceTextureWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
+
+        // FIXME: SurfaceTexture provides a transform matrix which is supposed to
+        // be applied to the texture coordinates. We should return that here
+        // so we can render correctly. Bug 775083
+        surfaceTextureWrapper->SurfaceTexture()->UpdateTexImage();
+        break;
+    }
+#endif // MOZ_WIDGET_ANDROID
+
+    case SharedHandleType_Image: {
+        NS_ASSERTION(DoesEGLContextSupportSharingWithEGLImage(gl), "EGLImage not supported or disabled in runtime");
+
+        EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
+        wrap->WaitSync();
+        gl->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, wrap->GetEGLImage());
+        break;
+    }
+
+    default:
+        NS_ERROR("Unknown shared handle type");
+        return false;
+    }
+
+    return true;
+}
+
+/**
+  * Detach Shared GL Handle from GL_TEXTURE_2D target
+  */
+void DetachSharedHandle(GLContext*,
+                        SharedTextureShareType,
+                        SharedTextureHandle)
+{
+  // currently a no-operation
+}
+
+}
+}
new file mode 100644
--- /dev/null
+++ b/gfx/gl/GLSharedHandleHelpers.h
@@ -0,0 +1,73 @@
+/* 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 GLSHAREDHANDLEHELPERS_H_
+#define GLSHAREDHANDLEHELPERS_H_
+
+#include "GLContextTypes.h"
+#include "mozilla/gfx/Types.h"
+
+namespace mozilla {
+namespace gl {
+
+/**
+  * Create a new shared GLContext content handle, using the passed buffer as a source.
+  * Must be released by ReleaseSharedHandle.
+  */
+SharedTextureHandle CreateSharedHandle(GLContext* gl,
+                                       SharedTextureShareType shareType,
+                                       void* buffer,
+                                       SharedTextureBufferType bufferType);
+
+/**
+  * - It is better to call ReleaseSharedHandle before original GLContext destroyed,
+  *     otherwise warning will be thrown on attempt to destroy Texture associated with SharedHandle, depends on backend implementation.
+  * - It does not require to be called on context where it was created,
+  *     because SharedHandle suppose to keep Context reference internally,
+  *     or don't require specific context at all, for example IPC SharedHandle.
+  * - Not recommended to call this between AttachSharedHandle and Draw Target call.
+  *      if it is really required for some special backend, then DetachSharedHandle API must be added with related implementation.
+  * - It is recommended to stop any possible access to SharedHandle (Attachments, pending GL calls) before calling Release,
+  *      otherwise some artifacts might appear or even crash if API backend implementation does not expect that.
+  * SharedHandle (currently EGLImage) does not require GLContext because it is EGL call, and can be destroyed
+  *   at any time, unless EGLImage have siblings (which are not expected with current API).
+  */
+void ReleaseSharedHandle(GLContext* gl,
+                         SharedTextureShareType shareType,
+                         SharedTextureHandle sharedHandle);
+
+
+typedef struct {
+    GLenum mTarget;
+    gfx::SurfaceFormat mTextureFormat;
+    gfx::Matrix4x4 mTextureTransform;
+} SharedHandleDetails;
+
+/**
+  * Returns information necessary for rendering a shared handle.
+  * These values change depending on what sharing mechanism is in use
+  */
+bool GetSharedHandleDetails(GLContext* gl,
+                            SharedTextureShareType shareType,
+                            SharedTextureHandle sharedHandle,
+                            SharedHandleDetails& details);
+/**
+  * Attach Shared GL Handle to GL_TEXTURE_2D target
+  * GLContext must be current before this call
+  */
+bool AttachSharedHandle(GLContext* gl,
+                        SharedTextureShareType shareType,
+                        SharedTextureHandle sharedHandle);
+
+/**
+  * Detach Shared GL Handle from GL_TEXTURE_2D target
+  */
+void DetachSharedHandle(GLContext* gl,
+                        SharedTextureShareType shareType,
+                        SharedTextureHandle sharedHandle);
+
+}
+}
+
+#endif
--- a/gfx/gl/TextureImageEGL.cpp
+++ b/gfx/gl/TextureImageEGL.cpp
@@ -84,19 +84,18 @@ TextureImageEGL::~TextureImageEGL()
     if (mGLContext->IsDestroyed() || !mGLContext->IsOwningThreadCurrent()) {
         return;
     }
 
     // If we have a context, then we need to delete the texture;
     // if we don't have a context (either real or shared),
     // then they went away when the contex was deleted, because it
     // was the only one that had access to it.
-    if (mGLContext->MakeCurrent()) {
-        mGLContext->fDeleteTextures(1, &mTexture);
-    }
+    mGLContext->MakeCurrent();
+    mGLContext->fDeleteTextures(1, &mTexture);
     ReleaseTexImage();
     DestroyEGLSurface();
 }
 
 void
 TextureImageEGL::GetUpdateRegion(nsIntRegion& aForRegion)
 {
     if (mTextureState != Valid) {
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -21,36 +21,34 @@ 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 += [
-    'AndroidNativeWindow.h',
-    'AndroidSurfaceTexture.h',
     'DecomposeIntoNoRepeatTriangles.h',
-    'EGLUtils.h',
     'ForceDiscreteGPUHelperCGL.h',
     'GfxTexturesReporter.h',
     'GLBlitHelper.h',
     'GLBlitTextureImageHelper.h',
     'GLConsts.h',
     'GLContext.h',
     'GLContextEGL.h',
     'GLContextProvider.h',
     'GLContextProviderImpl.h',
     'GLContextSymbols.h',
     'GLContextTypes.h',
     'GLDefs.h',
     'GLLibraryEGL.h',
     'GLLibraryLoader.h',
     'GLReadTexImageHelper.h',
     'GLScreenBuffer.h',
+    'GLSharedHandleHelpers.h',
     'GLTextureImage.h',
     'GLTypes.h',
     'GLUploadHelpers.h',
     'HeapCopyOfStackArray.h',
     'ScopedGLHelpers.h',
     'SharedSurface.h',
     'SharedSurfaceEGL.h',
     'SharedSurfaceGL.h',
@@ -112,31 +110,29 @@ elif gl_provider == 'GLX':
         'GLContextProviderGLX.cpp',
     ]
 else:
     UNIFIED_SOURCES += [
         'GLContextProvider%s.cpp' % gl_provider,
     ]
 
 UNIFIED_SOURCES += [
-    'AndroidNativeWindow.cpp',
-    'AndroidSurfaceTexture.cpp',
     'DecomposeIntoNoRepeatTriangles.cpp',
-    'EGLUtils.cpp',
     'GfxTexturesReporter.cpp',
     'GLBlitHelper.cpp',
     'GLBlitTextureImageHelper.cpp',
     'GLContext.cpp',
     'GLContextFeatures.cpp',
     'GLContextTypes.cpp',
     'GLDebugUtils.cpp',
     'GLLibraryEGL.cpp',
     'GLLibraryLoader.cpp',
     'GLReadTexImageHelper.cpp',
     'GLScreenBuffer.cpp',
+    'GLSharedHandleHelpers.cpp',
     'GLTextureImage.cpp',
     'GLUploadHelpers.cpp',
     'ScopedGLHelpers.cpp',
     'SharedSurface.cpp',
     'SharedSurfaceEGL.cpp',
     'SharedSurfaceGL.cpp',
     'SurfaceStream.cpp',
     'SurfaceTypes.cpp',
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -94,17 +94,17 @@
  *
  *
  * # Backend implementations
  *
  * Compositor backends like OpenGL or flavours of D3D live in their own directory
  * under gfx/layers/. To add a new backend, implement at least the following
  * interfaces:
  * - Compositor (ex. CompositorOGL)
- * - TextureHost (ex. SurfaceTextureHost)
+ * - TextureHost (ex. SharedTextureHostOGL)
  * Depending on the type of data that needs to be serialized, you may need to
  * add specific TextureClient implementations.
  */
 
 class nsIWidget;
 struct nsIntSize;
 class nsIntRegion;
 
deleted file mode 100644
--- a/gfx/layers/GLImages.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-#ifdef MOZ_WIDGET_ANDROID
-
-#include "GLImages.h"
-#include "GLContext.h"
-#include "GLContextProvider.h"
-#include "ScopedGLHelpers.h"
-#include "GLImages.h"
-#include "GLBlitHelper.h"
-#include "GLReadTexImageHelper.h"
-#include "AndroidSurfaceTexture.h"
-
-using namespace mozilla;
-using namespace mozilla::gl;
-
-namespace mozilla {
-namespace layers {
-
-static nsRefPtr<GLContext> sSnapshotContext;
-
-TemporaryRef<gfx::SourceSurface>
-SurfaceTextureImage::GetAsSourceSurface()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
-
-  if (!sSnapshotContext) {
-    SurfaceCaps caps = SurfaceCaps::ForRGBA();
-    sSnapshotContext = GLContextProvider::CreateOffscreen(gfxIntSize(16, 16), caps);
-
-    if (!sSnapshotContext) {
-      return nullptr;
-    }
-  }
-
-  sSnapshotContext->MakeCurrent();
-  ScopedTexture scopedTex(sSnapshotContext);
-  ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());
-  sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
-                                mData.mSize.width, mData.mSize.height, 0,
-                                LOCAL_GL_RGBA,
-                                LOCAL_GL_UNSIGNED_BYTE,
-                                nullptr);
-
-  ScopedFramebufferForTexture fb(sSnapshotContext, scopedTex.Texture());
-
-  GLBlitHelper helper(sSnapshotContext);
-
-  helper.BlitImageToFramebuffer(this, mData.mSize, fb.FB(), false);
-  ScopedBindFramebuffer bind(sSnapshotContext, fb.FB());
-
-  RefPtr<gfx::DataSourceSurface> source =
-        gfx::Factory::CreateDataSourceSurface(mData.mSize, gfx::SurfaceFormat::B8G8R8A8);
-  if (NS_WARN_IF(!source)) {
-    return nullptr;
-  }
-
-  ReadPixelsIntoDataSurface(sSnapshotContext, source);
-  return source.forget();
-}
-
-} // layers
-} // mozilla
-
-#endif
deleted file mode 100644
--- a/gfx/layers/GLImages.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * 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 GFX_GLIMAGES_H
-#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
-
-namespace mozilla {
-namespace gl {
-class AndroidSurfaceTexture;
-}
-namespace layers {
-
-class EGLImageImage : public Image {
-public:
-  struct Data {
-    EGLImage mImage;
-    gfx::IntSize mSize;
-    bool mInverted;
-  };
-
-  void SetData(const Data& aData) { mData = aData; }
-  const Data* GetData() { return &mData; }
-
-  gfx::IntSize GetSize() { return mData.mSize; }
-
-  virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE
-  {
-    return nullptr;
-  }
-
-  EGLImageImage() : Image(nullptr, ImageFormat::EGLIMAGE) {}
-
-private:
-  Data mData;
-};
-
-#ifdef MOZ_WIDGET_ANDROID
-
-class SurfaceTextureImage : public Image {
-public:
-  struct Data {
-    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; }
-
-  virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
-
-  SurfaceTextureImage() : Image(nullptr, ImageFormat::SURFACE_TEXTURE) {}
-
-private:
-  Data mData;
-};
-
-#endif // MOZ_WIDGET_ANDROID
-
-} // layers
-} // mozilla
-
-#endif // GFX_GLIMAGES_H
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 "ImageContainer.h"
 #include <string.h>                     // for memcpy, memset
-#include "GLImages.h"                   // for SurfaceTextureImage
+#include "SharedTextureImage.h"         // for SharedTextureImage
 #include "gfx2DGlue.h"
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "gfxUtils.h"                   // for gfxUtils
 #include "mozilla/RefPtr.h"             // for TemporaryRef
 #include "mozilla/ipc/CrossProcessMutex.h"  // for CrossProcessMutex, etc
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/ImageBridgeChild.h"  // for ImageBridgeChild
 #include "mozilla/layers/ImageClient.h"  // for ImageClient
@@ -64,24 +64,18 @@ ImageFactory::CreateImage(ImageFormat aF
   if (aFormat == ImageFormat::PLANAR_YCBCR) {
     img = new PlanarYCbCrImage(aRecycleBin);
     return img.forget();
   }
   if (aFormat == ImageFormat::CAIRO_SURFACE) {
     img = new CairoImage();
     return img.forget();
   }
-#ifdef MOZ_WIDGET_ANDROID
-  if (aFormat == ImageFormat::SURFACE_TEXTURE) {
-    img = new SurfaceTextureImage();
-    return img.forget();
-  }
-#endif
-  if (aFormat == ImageFormat::EGLIMAGE) {
-    img = new EGLImageImage();
+  if (aFormat == ImageFormat::SHARED_TEXTURE) {
+    img = new SharedTextureImage();
     return img.forget();
   }
 #ifdef XP_MACOSX
   if (aFormat == ImageFormat::MAC_IOSURFACE) {
     img = new MacIOSurfaceImage();
     return img.forget();
   }
 #endif
--- a/gfx/layers/ImageTypes.h
+++ b/gfx/layers/ImageTypes.h
@@ -53,25 +53,19 @@ MOZ_BEGIN_ENUM_CLASS(ImageFormat)
   MAC_IOSURFACE,
 
   /**
    * An bitmap image that can be shared with a remote process.
    */
   REMOTE_IMAGE_BITMAP,
 
   /**
-   * An Android SurfaceTexture ID that can be shared across threads and
-   * processes.
+   * A OpenGL texture that can be shared across threads or processes
    */
-  SURFACE_TEXTURE,
-
-  /**
-   * An EGL Image that can be shared across threads.
-   */
-  EGLIMAGE,
+  SHARED_TEXTURE,
 
   /**
    * An DXGI shared surface handle that can be shared with a remote process.
    */
   REMOTE_IMAGE_DXGI_TEXTURE,
 
   /**
    * The D3D9_RGB32_TEXTURE format creates a D3D9SurfaceImage, and wraps a
new file mode 100644
--- /dev/null
+++ b/gfx/layers/SharedTextureImage.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 GFX_SHAREDTEXTUREIMAGE_H
+#define GFX_SHAREDTEXTUREIMAGE_H
+
+#include "GLContextProvider.h"          // for GLContextProvider
+#include "ImageContainer.h"             // for Image
+#include "ImageTypes.h"                 // for ImageFormat::SHARED_TEXTURE
+#include "nsCOMPtr.h"                   // for already_AddRefed
+#include "mozilla/gfx/Point.h"          // for IntSize
+
+// Split into a separate header from ImageLayers.h due to GLContext.h dependence
+// Implementation remains in ImageLayers.cpp
+
+namespace mozilla {
+
+namespace layers {
+
+class SharedTextureImage : public Image {
+public:
+  struct Data {
+    gl::SharedTextureHandle mHandle;
+    gl::SharedTextureShareType mShareType;
+    gfx::IntSize mSize;
+    bool mInverted;
+  };
+
+  void SetData(const Data& aData) { mData = aData; }
+  const Data* GetData() { return &mData; }
+
+  gfx::IntSize GetSize() { return mData.mSize; }
+
+  virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE
+  {
+    return nullptr;
+  }
+
+  SharedTextureImage() : Image(nullptr, ImageFormat::SHARED_TEXTURE) {}
+
+private:
+  Data mData;
+};
+
+} // layers
+} // mozilla
+
+#endif // GFX_SHAREDTEXTUREIMAGE_H
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -2,34 +2,34 @@
  * 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 "ImageClient.h"
 #include <stdint.h>                     // for uint32_t
 #include "ImageContainer.h"             // for Image, PlanarYCbCrImage, etc
 #include "ImageTypes.h"                 // for ImageFormat::PLANAR_YCBCR, etc
-#include "GLImages.h"                   // for SurfaceTextureImage::Data, etc
+#include "SharedTextureImage.h"         // for SharedTextureImage::Data, etc
 #include "gfx2DGlue.h"                  // for ImageFormatToSurfaceFormat
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
 #include "mozilla/layers/CompositableClient.h"  // for CompositableClient
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/CompositorTypes.h"  // for CompositableType, etc
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
 #include "mozilla/layers/ShadowLayers.h"  // for ShadowLayerForwarder
 #include "mozilla/layers/SharedPlanarYCbCrImage.h"
 #include "mozilla/layers/SharedRGBImage.h"
 #include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
-#include "mozilla/layers/TextureClientOGL.h"  // for SurfaceTextureClient
+#include "mozilla/layers/TextureClientOGL.h"  // for SharedTextureClientOGL
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsDebug.h"                    // for NS_WARNING, NS_ASSERTION
 #include "nsISupportsImpl.h"            // for Image::Release, etc
 #include "nsRect.h"                     // for nsIntRect
 #include "mozilla/gfx/2D.h"
 #ifdef MOZ_WIDGET_GONK
@@ -242,58 +242,35 @@ ImageClientSingle::UpdateImageInternal(I
     if (status) {
       GetForwarder()->UpdatedTexture(this, mFrontBuffer, nullptr);
       GetForwarder()->UseTexture(this, mFrontBuffer);
     } else {
       MOZ_ASSERT(false);
       return false;
     }
 
-  } else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE ||
-             image->GetFormat() == ImageFormat::EGLIMAGE)
-  {
+  } else if (image->GetFormat() == ImageFormat::SHARED_TEXTURE) {
+    SharedTextureImage* sharedImage = static_cast<SharedTextureImage*>(image);
+    const SharedTextureImage::Data *data = sharedImage->GetData();
     gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
 
     if (mFrontBuffer) {
       autoRemoveTexture.mTexture = mFrontBuffer;
       mFrontBuffer = nullptr;
     }
 
-    RefPtr<TextureClient> buffer;
-
-    if (image->GetFormat() == ImageFormat::EGLIMAGE) {
-      EGLImageImage* typedImage = static_cast<EGLImageImage*>(image);
-      const EGLImageImage::Data* data = typedImage->GetData();
-
-      buffer = new EGLImageTextureClient(mTextureFlags,
-                                         data->mImage,
-                                         size,
-                                         data->mInverted);
-#ifdef MOZ_WIDGET_ANDROID
-    } else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
-      SurfaceTextureImage* typedImage = static_cast<SurfaceTextureImage*>(image);
-      const SurfaceTextureImage::Data* data = typedImage->GetData();
-
-      buffer = new SurfaceTextureClient(mTextureFlags,
-                                        data->mSurfTex,
-                                        size,
-                                        data->mInverted);
-#endif
-    } else {
-      MOZ_ASSERT(false, "Bad ImageFormat.");
-    }
-
+    RefPtr<SharedTextureClientOGL> buffer = new SharedTextureClientOGL(mTextureFlags);
+    buffer->InitWith(data->mHandle, size, data->mShareType, data->mInverted);
     mFrontBuffer = buffer;
     if (!AddTextureClient(mFrontBuffer)) {
       mFrontBuffer = nullptr;
       return false;
     }
 
     GetForwarder()->UseTexture(this, mFrontBuffer);
-
   } else {
     RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
     MOZ_ASSERT(surface);
 
     gfx::IntSize size = image->GetSize();
 
     if (mFrontBuffer &&
         (mFrontBuffer->IsImmutable() || mFrontBuffer->GetSize() != size)) {
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -200,19 +200,18 @@ TextureHost::Create(const SurfaceDescrip
                     TextureFlags aFlags)
 {
   switch (aDesc.type()) {
     case SurfaceDescriptor::TSurfaceDescriptorShmem:
     case SurfaceDescriptor::TSurfaceDescriptorMemory:
     case SurfaceDescriptor::TSurfaceDescriptorDIB:
       return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
 
-    case SurfaceDescriptor::TEGLImageDescriptor:
+    case SurfaceDescriptor::TSharedTextureDescriptor:
     case SurfaceDescriptor::TNewSurfaceDescriptorGralloc:
-    case SurfaceDescriptor::TSurfaceTextureDescriptor:
       return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
 
     case SurfaceDescriptor::TSurfaceStreamDescriptor:
       return new StreamTextureHost(aFlags, aDesc.get_SurfaceStreamDescriptor());
 
     case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
       if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) {
         return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -6,16 +6,18 @@ using struct gfxPoint from "gfxPoint.h";
 using struct nsIntRect from "nsRect.h";
 using nsIntRegion from "nsRegion.h";
 using struct nsIntSize from "nsSize.h";
 using struct mozilla::layers::MagicGrallocBufferHandle from "gfxipc/ShadowLayerUtils.h";
 using struct mozilla::layers::GrallocBufferRef from "gfxipc/ShadowLayerUtils.h";
 using struct mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
 using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
 using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
+using mozilla::gl::SharedTextureHandle from "GLContextTypes.h";
+using mozilla::gl::SharedTextureShareType from "GLContextTypes.h";
 using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
 using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
 using gfxImageFormat from "gfxTypes.h";
 
 namespace mozilla {
 namespace layers {
 
 union OverlayHandle {
@@ -51,24 +53,21 @@ struct SurfaceDescriptorD3D10 {
 };
 
 struct SurfaceDescriptorMacIOSurface {
   uint32_t surface;
   double scaleFactor;
   bool hasAlpha;
 };
 
-struct SurfaceTextureDescriptor {
-  uintptr_t surfTex;
+struct SharedTextureDescriptor {
+  SharedTextureShareType shareType;
+  SharedTextureHandle handle;
   IntSize size;
-};
-
-struct EGLImageDescriptor {
-  uintptr_t image; // `EGLImage` is a `void*`.
-  IntSize size;
+  bool inverted;
 };
 
 struct NewSurfaceDescriptorGralloc {
   MaybeMagicGrallocBufferHandle buffer;
   /**
    * android::GraphicBuffer has a size information. But there are cases
    * that GraphicBuffer's size and actual video's size are different.
    * Extra size member is necessary. See Bug 850566.
@@ -99,18 +98,17 @@ struct SurfaceDescriptorShmem {
 
 union SurfaceDescriptor {
   SurfaceDescriptorShmem;
   SurfaceDescriptorMemory;
   SurfaceDescriptorD3D9;
   SurfaceDescriptorDIB;
   SurfaceDescriptorD3D10;
   SurfaceDescriptorX11;
-  SurfaceTextureDescriptor;
-  EGLImageDescriptor;
+  SharedTextureDescriptor;
   SurfaceStreamDescriptor;
   SurfaceDescriptorMacIOSurface;
   NewSurfaceDescriptorGralloc;
   null_t;
 };
 
 } // namespace
 } // namespace
--- a/gfx/layers/ipc/ShadowLayerUtils.h
+++ b/gfx/layers/ipc/ShadowLayerUtils.h
@@ -51,16 +51,39 @@ namespace IPC {
 template <>
 struct ParamTraits<mozilla::layers::SurfaceDescriptorX11> {
   typedef mozilla::layers::SurfaceDescriptorX11 paramType;
   static void Write(Message*, const paramType&) {}
   static bool Read(const Message*, void**, paramType*) { return false; }
 };
 #endif  // !defined(MOZ_HAVE_XSURFACEDESCRIPTORX11)
 
+template<>
+struct ParamTraits<mozilla::gl::SharedTextureShareType>
+{
+  typedef mozilla::gl::SharedTextureShareType paramType;
+
+  static void Write(Message* msg, const paramType& param)
+  {
+    static_assert(sizeof(paramType) <= sizeof(int32_t),
+                  "TextureShareType assumes to be int32_t");
+    WriteParam(msg, int32_t(param));
+  }
+
+  static bool Read(const Message* msg, void** iter, paramType* result)
+  {
+    int32_t type;
+    if (!ReadParam(msg, iter, &type))
+      return false;
+
+    *result = paramType(type);
+    return true;
+  }
+};
+
 #if !defined(MOZ_HAVE_SURFACEDESCRIPTORGRALLOC)
 template <>
 struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
   typedef mozilla::layers::MagicGrallocBufferHandle paramType;
   static void Write(Message*, const paramType&) {}
   static bool Read(const Message*, void**, paramType*) { return false; }
 };
 
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -15,17 +15,16 @@ EXPORTS += [
     'client/ClientLayerManager.h',
     'client/ClientThebesLayer.h',
     'client/ClientTiledThebesLayer.h',
     'composite/CompositableHost.h',
     'composite/ImageHost.h',
     'CopyableCanvasLayer.h',
     'D3D9SurfaceImage.h',
     'FrameMetrics.h',
-    'GLImages.h',
     'GrallocImages.h',
     'ImageContainer.h',
     'ImageLayers.h',
     'ImageTypes.h',
     'ipc/CompositorChild.h',
     'ipc/CompositorParent.h',
     'ipc/ShadowLayersManager.h',
     'ipc/ThreadSafeRefcountingWithMainThreadDestruction.h',
@@ -34,16 +33,17 @@ EXPORTS += [
     'LayersLogging.h',
     'LayerSorter.h',
     'LayerTreeInvalidation.h',
     'opengl/Composer2D.h',
     'opengl/OGLShaderProgram.h',
     'opengl/TexturePoolOGL.h',
     'protobuf/LayerScopePacket.pb.h',
     'ReadbackLayer.h',
+    'SharedTextureImage.h',
     'TiledLayerBuffer.h',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     UNIFIED_SOURCES += [
         'D3D9SurfaceImage.cpp',
         'TextureDIB.cpp',
     ]
@@ -287,17 +287,16 @@ UNIFIED_SOURCES += [
     'composite/LayerManagerComposite.cpp',
     'composite/TextRenderer.cpp',
     'composite/TextureHost.cpp',
     'composite/ThebesLayerComposite.cpp',
     'composite/TiledContentHost.cpp',
     'Compositor.cpp',
     'CopyableCanvasLayer.cpp',
     'Effects.cpp',
-    'GLImages.cpp',
     'ImageDataSerializer.cpp',
     'ImageLayers.cpp',
     'ipc/AsyncTransactionTracker.cpp',
     'ipc/CompositableTransactionParent.cpp',
     'ipc/CompositorBench.cpp',
     'ipc/CompositorChild.cpp',
     'ipc/CompositorParent.cpp',
     'ipc/ImageBridgeChild.cpp',
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
@@ -59,17 +59,17 @@ protected:
  * Most of the logic actually happens in MacIOSurfaceTextureSourceOGL.
  */
 class MacIOSurfaceTextureHostOGL : public TextureHost
 {
 public:
   MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
                              const SurfaceDescriptorMacIOSurface& aDescriptor);
 
-  // MacIOSurfaceTextureSourceOGL doesn't own any GL texture
+  // SharedTextureHostOGL doesn't own any GL texture
   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
   virtual bool Lock() MOZ_OVERRIDE;
 
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
 
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -12,127 +12,78 @@
 
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
 class CompositableForwarder;
 
-////////////////////////////////////////////////////////////////////////
-// EGLImageTextureClient
-
-EGLImageTextureClient::EGLImageTextureClient(TextureFlags aFlags,
-                                             EGLImage aImage,
-                                             gfx::IntSize aSize,
-                                             bool aInverted)
+SharedTextureClientOGL::SharedTextureClientOGL(TextureFlags aFlags)
   : TextureClient(aFlags)
-  , mImage(aImage)
-  , mSize(aSize)
+  , mHandle(0)
+  , mInverted(false)
   , mIsLocked(false)
 {
-  MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
-             "Can't pass an `EGLImage` between processes.");
-  
-  // Our data is always owned externally.
-  AddFlags(TextureFlags::DEALLOCATE_CLIENT);
-  
-  if (aInverted) {
+  // SharedTextureClient is always owned externally.
+  mFlags |= TextureFlags::DEALLOCATE_CLIENT;
+}
+
+SharedTextureClientOGL::~SharedTextureClientOGL()
+{
+  // the shared data is owned externally.
+}
+
+
+bool
+SharedTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
+{
+  MOZ_ASSERT(IsValid());
+  if (!IsAllocated()) {
+    return false;
+  }
+  aOutDescriptor = SharedTextureDescriptor(mShareType, mHandle, mSize, mInverted);
+  return true;
+}
+
+void
+SharedTextureClientOGL::InitWith(gl::SharedTextureHandle aHandle,
+                                 gfx::IntSize aSize,
+                                 gl::SharedTextureShareType aShareType,
+                                 bool aInverted)
+{
+  MOZ_ASSERT(IsValid());
+  MOZ_ASSERT(!IsAllocated());
+  mHandle = aHandle;
+  mSize = aSize;
+  mShareType = aShareType;
+  mInverted = aInverted;
+  if (mInverted) {
     AddFlags(TextureFlags::NEEDS_Y_FLIP);
   }
 }
-  
-EGLImageTextureClient::~EGLImageTextureClient()
-{
-  // Our data is always owned externally.
-}
-
-bool
-EGLImageTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
-{
-  MOZ_ASSERT(IsValid());
-  MOZ_ASSERT(IsAllocated());
-
-  aOutDescriptor = EGLImageDescriptor((uintptr_t)mImage, mSize);
-  return true;
-}
 
 bool
-EGLImageTextureClient::Lock(OpenMode mode)
-  {
-    MOZ_ASSERT(!mIsLocked);
-    if (!IsValid() || !IsAllocated()) {
-      return false;
-    }
-    mIsLocked = true;
-    return true;
-  }
-  
-void
-EGLImageTextureClient::Unlock()
-{
-  MOZ_ASSERT(mIsLocked);
-  mIsLocked = false;
-}
-  
-////////////////////////////////////////////////////////////////////////
-// SurfaceTextureClient
-
-#ifdef MOZ_WIDGET_ANDROID
-
-SurfaceTextureClient::SurfaceTextureClient(TextureFlags aFlags,
-                                           AndroidSurfaceTexture* aSurfTex,
-                                           gfx::IntSize aSize,
-                                           bool aInverted)
-  : TextureClient(aFlags)
-  , mSurfTex(aSurfTex)
-  , mSize(aSize)
-  , mIsLocked(false)
-{
-  MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
-             "Can't pass pointers between processes.");
-
-  // Our data is always owned externally.
-  AddFlags(TextureFlags::DEALLOCATE_CLIENT);
-
-  if (aInverted) {
-    AddFlags(TextureFlags::NEEDS_Y_FLIP);
-  }
-}
-  
-SurfaceTextureClient::~SurfaceTextureClient()
-{
-  // Our data is always owned externally.
-}
-
-bool
-SurfaceTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
-{
-  MOZ_ASSERT(IsValid());
-  MOZ_ASSERT(IsAllocated());
-
-  aOutDescriptor = SurfaceTextureDescriptor((uintptr_t)mSurfTex.get(),
-                                            mSize);
-  return true;
-}
-
-bool
-SurfaceTextureClient::Lock(OpenMode mode)
+SharedTextureClientOGL::Lock(OpenMode mode)
 {
   MOZ_ASSERT(!mIsLocked);
   if (!IsValid() || !IsAllocated()) {
     return false;
   }
   mIsLocked = true;
   return true;
 }
 
 void
-SurfaceTextureClient::Unlock()
+SharedTextureClientOGL::Unlock()
 {
   MOZ_ASSERT(mIsLocked);
   mIsLocked = false;
 }
 
-#endif // MOZ_WIDGET_ANDROID
+bool
+SharedTextureClientOGL::IsAllocated() const
+{
+  return mHandle != 0;
+}
 
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -8,119 +8,78 @@
 
 #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 "AndroidSurfaceTexture.h"
+
+namespace mozilla {
+namespace gl {
+class SurfaceStream;
+}
+}
 
 namespace mozilla {
 namespace layers {
 
 class CompositableForwarder;
 
-class EGLImageTextureClient : public TextureClient
+/**
+ * A TextureClient implementation to share TextureMemory that is already
+ * on the GPU, for the OpenGL backend.
+ */
+class SharedTextureClientOGL : public TextureClient
 {
 public:
-  EGLImageTextureClient(TextureFlags aFlags,
-                        EGLImage aImage,
-                        gfx::IntSize aSize,
-                        bool aInverted);
+  explicit SharedTextureClientOGL(TextureFlags aFlags);
 
-  ~EGLImageTextureClient();
-
-  virtual bool IsAllocated() const MOZ_OVERRIDE { return true; }
+  ~SharedTextureClientOGL();
 
-  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
-
-  virtual gfx::IntSize GetSize() const { return mSize; }
+  virtual bool IsAllocated() const MOZ_OVERRIDE;
 
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
 
-  // Useless functions.
   virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
 
   virtual void Unlock() MOZ_OVERRIDE;
 
   virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
 
+  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
+
+  void InitWith(gl::SharedTextureHandle aHandle,
+                gfx::IntSize aSize,
+                gl::SharedTextureShareType aShareType,
+                bool aInverted = false);
+
+  virtual gfx::IntSize GetSize() const { return mSize; }
+
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
   {
     return gfx::SurfaceFormat::UNKNOWN;
   }
 
+  // This TextureClient should not be used in a context where we use CreateSimilar
+  // (ex. component alpha) because the underlying texture data is always created by
+  // an external producer.
   virtual TemporaryRef<TextureClient>
-  CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
-                TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const MOZ_OVERRIDE
-  {
-    return nullptr;
-  }
+  CreateSimilar(TextureFlags, TextureAllocationFlags) const MOZ_OVERRIDE { return nullptr; }
 
   virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
   {
     return false;
   }
 
 protected:
-  const EGLImage mImage;
-  const gfx::IntSize mSize;
+  gl::SharedTextureHandle mHandle;
+  gfx::IntSize mSize;
+  gl::SharedTextureShareType mShareType;
+  bool mInverted;
   bool mIsLocked;
 };
 
-#ifdef MOZ_WIDGET_ANDROID
-
-class SurfaceTextureClient : public TextureClient
-{
-public:
-  SurfaceTextureClient(TextureFlags aFlags,
-                       gl::AndroidSurfaceTexture* aSurfTex,
-                       gfx::IntSize aSize,
-                       bool aInverted);
-
-  ~SurfaceTextureClient();
-
-  virtual bool IsAllocated() const MOZ_OVERRIDE { return true; }
-
-  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
-
-  virtual gfx::IntSize GetSize() const { return mSize; }
-
-  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
-
-  // Useless functions.
-  virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
-
-  virtual void Unlock() MOZ_OVERRIDE;
-
-  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
-  {
-    return gfx::SurfaceFormat::UNKNOWN;
-  }
-
-  virtual TemporaryRef<TextureClient>
-  CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
-                TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const MOZ_OVERRIDE
-  {
-    return nullptr;
-  }
-
-  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
-  {
-    return false;
-  }
-
-protected:
-  const RefPtr<gl::AndroidSurfaceTexture> mSurfTex;
-  const gfx::IntSize mSize;
-  bool mIsLocked;
-};
-
-#endif // MOZ_WIDGET_ANDROID
-
 } // namespace
 } // namespace
 
 #endif
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -1,35 +1,33 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * 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 "TextureHostOGL.h"
-
-#include "EGLUtils.h"
 #include "GLContext.h"                  // for GLContext, etc
 #include "GLLibraryEGL.h"               // for GLLibraryEGL
+#include "GLSharedHandleHelpers.h"
 #include "GLUploadHelpers.h"
 #include "GLReadTexImageHelper.h"
 #include "gfx2DGlue.h"                  // for ContentForFormat, etc
 #include "gfxReusableSurfaceWrapper.h"  // for gfxReusableSurfaceWrapper
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
 #include "mozilla/layers/CompositorOGL.h"  // for CompositorOGL
 #ifdef MOZ_WIDGET_GONK
 # 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 "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"
 
@@ -59,44 +57,33 @@ CreateTextureHostOGL(const SurfaceDescri
   RefPtr<TextureHost> result;
   switch (aDesc.type()) {
     case SurfaceDescriptor::TSurfaceDescriptorShmem:
     case SurfaceDescriptor::TSurfaceDescriptorMemory: {
       result = CreateBackendIndependentTextureHost(aDesc,
                                                    aDeallocator, aFlags);
       break;
     }
-
-#ifdef MOZ_WIDGET_ANDROID
-    case SurfaceDescriptor::TSurfaceTextureDescriptor: {
-      const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
-      result = new SurfaceTextureHost(aFlags,
-                                      (AndroidSurfaceTexture*)desc.surfTex(),
-                                      desc.size());
+    case SurfaceDescriptor::TSharedTextureDescriptor: {
+      const SharedTextureDescriptor& desc = aDesc.get_SharedTextureDescriptor();
+      result = new SharedTextureHostOGL(aFlags,
+                                        desc.shareType(),
+                                        desc.handle(),
+                                        desc.size(),
+                                        desc.inverted());
       break;
     }
-#endif
-
-    case SurfaceDescriptor::TEGLImageDescriptor: {
-      const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
-      result = new EGLImageTextureHost(aFlags,
-                                       (EGLImage)desc.image(),
-                                       desc.size());
-      break;
-    }
-
 #ifdef XP_MACOSX
     case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
       const SurfaceDescriptorMacIOSurface& desc =
         aDesc.get_SurfaceDescriptorMacIOSurface();
       result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
       break;
     }
 #endif
-
 #ifdef MOZ_WIDGET_GONK
     case SurfaceDescriptor::TNewSurfaceDescriptorGralloc: {
       const NewSurfaceDescriptorGralloc& desc =
         aDesc.get_NewSurfaceDescriptorGralloc();
       result = new GrallocTextureHostOGL(aFlags, desc);
       break;
     }
 #endif
@@ -427,16 +414,90 @@ void
 TextureImageTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
 {
   MOZ_ASSERT(mTexImage,
     "Trying to bind a TextureSource that does not have an underlying GL texture.");
   mTexImage->BindTexture(aTextureUnit);
   SetFilter(mGL, aFilter);
 }
 
+SharedTextureSourceOGL::SharedTextureSourceOGL(CompositorOGL* aCompositor,
+                                               gl::SharedTextureHandle aHandle,
+                                               gfx::SurfaceFormat aFormat,
+                                               GLenum aTarget,
+                                               GLenum aWrapMode,
+                                               SharedTextureShareType aShareType,
+                                               gfx::IntSize aSize)
+  : mSize(aSize)
+  , mCompositor(aCompositor)
+  , mSharedHandle(aHandle)
+  , mFormat(aFormat)
+  , mShareType(aShareType)
+  , mTextureTarget(aTarget)
+  , mWrapMode(aWrapMode)
+{}
+
+void
+SharedTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
+{
+  if (!gl()) {
+    NS_WARNING("Trying to bind a texture without a GLContext");
+    return;
+  }
+  GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
+
+  gl()->fActiveTexture(aTextureUnit);
+  gl()->fBindTexture(mTextureTarget, tex);
+  if (!AttachSharedHandle(gl(), mShareType, mSharedHandle)) {
+    NS_ERROR("Failed to bind shared texture handle");
+    return;
+  }
+  ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
+}
+
+void
+SharedTextureSourceOGL::DetachSharedHandle()
+{
+  if (!gl()) {
+    return;
+  }
+  gl::DetachSharedHandle(gl(), mShareType, mSharedHandle);
+}
+
+void
+SharedTextureSourceOGL::SetCompositor(Compositor* aCompositor)
+{
+  mCompositor = static_cast<CompositorOGL*>(aCompositor);
+}
+
+bool
+SharedTextureSourceOGL::IsValid() const
+{
+  return !!gl();
+}
+
+gl::GLContext*
+SharedTextureSourceOGL::gl() const
+{
+  return mCompositor ? mCompositor->gl() : nullptr;
+}
+
+gfx::Matrix4x4
+SharedTextureSourceOGL::GetTextureTransform()
+{
+  SharedHandleDetails handleDetails;
+  if (!GetSharedHandleDetails(gl(), mShareType, mSharedHandle, handleDetails)) {
+    NS_WARNING("Could not get shared handle details");
+    return gfx::Matrix4x4();
+  }
+
+  return handleDetails.mTextureTransform;
+}
+
+
 ////////////////////////////////////////////////////////////////////////
 // GLTextureSource
 
 GLTextureSource::GLTextureSource(CompositorOGL* aCompositor,
                                  GLuint aTex,
                                  gfx::SurfaceFormat aFormat,
                                  GLenum aTarget,
                                  gfx::IntSize aSize)
@@ -474,279 +535,91 @@ GLTextureSource::IsValid() const
 
 gl::GLContext*
 GLTextureSource::gl() const
 {
   return mCompositor ? mCompositor->gl() : nullptr;
 }
 
 ////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-// SurfaceTextureHost
-
-#ifdef MOZ_WIDGET_ANDROID
+// SharedTextureHostOGL
 
-SurfaceTextureSource::SurfaceTextureSource(CompositorOGL* aCompositor,
-                                           AndroidSurfaceTexture* aSurfTex,
-                                           gfx::SurfaceFormat aFormat,
-                                           GLenum aTarget,
-                                           GLenum aWrapMode,
-                                           gfx::IntSize aSize)
-  : mCompositor(aCompositor)
-  , mSurfTex(aSurfTex)
-  , mFormat(aFormat)
-  , mTextureTarget(aTarget)
-  , mWrapMode(aWrapMode)
+SharedTextureHostOGL::SharedTextureHostOGL(TextureFlags aFlags,
+                                           gl::SharedTextureShareType aShareType,
+                                           gl::SharedTextureHandle aSharedHandle,
+                                           gfx::IntSize aSize,
+                                           bool inverted)
+  : TextureHost(aFlags)
   , mSize(aSize)
+  , mCompositor(nullptr)
+  , mSharedHandle(aSharedHandle)
+  , mShareType(aShareType)
 {
 }
 
-void
-SurfaceTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
+SharedTextureHostOGL::~SharedTextureHostOGL()
 {
-  if (!gl()) {
-    NS_WARNING("Trying to bind a texture without a GLContext");
-    return;
-  }
-
-  gl()->fActiveTexture(aTextureUnit);
-#ifndef DEBUG
-  // SurfaceTexture spams us if there are any existing GL errors, so
-  // we'll clear them here in order to avoid that.
-  gl()->GetAndClearError();
-#endif
-  mSurfTex->UpdateTexImage();
-
-  ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
-}
-
-void
-SurfaceTextureSource::SetCompositor(Compositor* aCompositor)
-{
-  mCompositor = static_cast<CompositorOGL*>(aCompositor);
-}
-
-bool
-SurfaceTextureSource::IsValid() const
-{
-  return !!gl();
+  // If need to deallocate textures, call DeallocateSharedData() before
+  // the destructor
 }
 
 gl::GLContext*
-SurfaceTextureSource::gl() const
-{
-  return mCompositor ? mCompositor->gl() : nullptr;
-}
-
-gfx::Matrix4x4
-SurfaceTextureSource::GetTextureTransform()
-{
-  gfx::Matrix4x4 ret;
-  mSurfTex->GetTransformMatrix(ret);
-
-  return ret;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
-                                       AndroidSurfaceTexture* aSurfTex,
-                                       gfx::IntSize aSize)
-  : TextureHost(aFlags)
-  , mSurfTex(aSurfTex)
-  , mSize(aSize)
-  , mCompositor(nullptr)
-{
-}
-
-SurfaceTextureHost::~SurfaceTextureHost()
-{
-}
-
-gl::GLContext*
-SurfaceTextureHost::gl() const
+SharedTextureHostOGL::gl() const
 {
   return mCompositor ? mCompositor->gl() : nullptr;
 }
 
 bool
-SurfaceTextureHost::Lock()
+SharedTextureHostOGL::Lock()
 {
   if (!mCompositor) {
     return false;
   }
 
   if (!mTextureSource) {
-    gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
-    GLenum target = LOCAL_GL_TEXTURE_EXTERNAL;
+    // XXX on android GetSharedHandleDetails can call into Java which we'd
+    // rather not do from the compositor
+    SharedHandleDetails handleDetails;
+    if (!GetSharedHandleDetails(gl(), mShareType, mSharedHandle, handleDetails)) {
+      NS_WARNING("Could not get shared handle details");
+      return false;
+    }
+
     GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
-    mTextureSource = new SurfaceTextureSource(mCompositor,
-                                              mSurfTex,
-                                              format,
-                                              target,
-                                              wrapMode,
-                                              mSize);
+    mTextureSource = new SharedTextureSourceOGL(mCompositor,
+                                                mSharedHandle,
+                                                handleDetails.mTextureFormat,
+                                                handleDetails.mTarget,
+                                                wrapMode,
+                                                mShareType,
+                                                mSize);
   }
-
-  mSurfTex->Attach(gl());
-
   return true;
 }
 
 void
-SurfaceTextureHost::Unlock()
+SharedTextureHostOGL::Unlock()
 {
-  mSurfTex->Detach();
+  if (!mTextureSource) {
+    return;
+  }
+  mTextureSource->DetachSharedHandle();
 }
 
 void
-SurfaceTextureHost::SetCompositor(Compositor* aCompositor)
+SharedTextureHostOGL::SetCompositor(Compositor* aCompositor)
 {
   CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
   mCompositor = glCompositor;
   if (mTextureSource) {
     mTextureSource->SetCompositor(glCompositor);
   }
 }
 
 gfx::SurfaceFormat
-SurfaceTextureHost::GetFormat() const
-{
-  MOZ_ASSERT(mTextureSource);
-  return mTextureSource->GetFormat();
-}
-
-#endif // MOZ_WIDGET_ANDROID
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-// EGLImage
-
-EGLImageTextureSource::EGLImageTextureSource(CompositorOGL* aCompositor,
-                                             EGLImage aImage,
-                                             gfx::SurfaceFormat aFormat,
-                                             GLenum aTarget,
-                                             GLenum aWrapMode,
-                                             gfx::IntSize aSize)
-  : mCompositor(aCompositor)
-  , mImage(aImage)
-  , mFormat(aFormat)
-  , mTextureTarget(aTarget)
-  , mWrapMode(aWrapMode)
-  , mSize(aSize)
-{
-}
-
-void
-EGLImageTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
-{
-  if (!gl()) {
-    NS_WARNING("Trying to bind a texture without a GLContext");
-    return;
-  }
-
-  MOZ_ASSERT(DoesEGLContextSupportSharingWithEGLImage(gl()),
-             "EGLImage not supported or disabled in runtime");
-
-  GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
-
-  gl()->fActiveTexture(aTextureUnit);
-  gl()->fBindTexture(mTextureTarget, tex);
-
-  MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D);
-  gl()->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, mImage);
-
-  ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
-}
-
-void
-EGLImageTextureSource::SetCompositor(Compositor* aCompositor)
-{
-  mCompositor = static_cast<CompositorOGL*>(aCompositor);
-}
-
-bool
-EGLImageTextureSource::IsValid() const
-{
-  return !!gl();
-}
-
-gl::GLContext*
-EGLImageTextureSource::gl() const
-{
-  return mCompositor ? mCompositor->gl() : nullptr;
-}
-
-gfx::Matrix4x4
-EGLImageTextureSource::GetTextureTransform()
-{
-  gfx::Matrix4x4 ret;
-  return ret;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-EGLImageTextureHost::EGLImageTextureHost(TextureFlags aFlags,
-                                         EGLImage aImage,
-                                         gfx::IntSize aSize)
-  : TextureHost(aFlags)
-  , mImage(aImage)
-  , mSize(aSize)
-  , mCompositor(nullptr)
-{
-}
-
-EGLImageTextureHost::~EGLImageTextureHost()
-{
-}
-
-gl::GLContext*
-EGLImageTextureHost::gl() const
-{
-  return mCompositor ? mCompositor->gl() : nullptr;
-}
-
-bool
-EGLImageTextureHost::Lock()
-{
-  if (!mCompositor) {
-    return false;
-  }
-
-  if (!mTextureSource) {
-    gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
-    GLenum target = LOCAL_GL_TEXTURE_2D;
-    GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
-    mTextureSource = new EGLImageTextureSource(mCompositor,
-                                               mImage,
-                                               format,
-                                               target,
-                                               wrapMode,
-                                               mSize);
-  }
-
-  return true;
-}
-
-void
-EGLImageTextureHost::Unlock()
-{
-}
-
-void
-EGLImageTextureHost::SetCompositor(Compositor* aCompositor)
-{
-  CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
-  mCompositor = glCompositor;
-  if (mTextureSource) {
-    mTextureSource->SetCompositor(glCompositor);
-  }
-}
-
-gfx::SurfaceFormat
-EGLImageTextureHost::GetFormat() const
+SharedTextureHostOGL::GetFormat() const
 {
   MOZ_ASSERT(mTextureSource);
   return mTextureSource->GetFormat();
 }
 
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -43,17 +43,17 @@ struct nsIntRect;
 struct nsIntSize;
 
 namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
 }
 
 namespace gl {
-class AndroidSurfaceTexture;
+class SurfaceStream;
 }
 
 namespace layers {
 
 class Compositor;
 class CompositorOGL;
 class TextureImageTextureSourceOGL;
 
@@ -289,27 +289,138 @@ public:
 protected:
   nsRefPtr<gl::TextureImage> mTexImage;
   gl::GLContext* mGL;
   TextureFlags mFlags;
   bool mIterating;
 };
 
 /**
- * A texture source for GL textures.
+ * A texture source meant for use with SharedTextureHostOGL.
+ *
+ * It does not own any GL texture, and attaches its shared handle to one of
+ * the compositor's temporary textures when binding.
+ *
+ * The shared texture handle is owned by the TextureHost.
+ */
+class SharedTextureSourceOGL : public NewTextureSource
+                             , public TextureSourceOGL
+{
+public:
+  typedef gl::SharedTextureShareType SharedTextureShareType;
+
+  SharedTextureSourceOGL(CompositorOGL* aCompositor,
+                         gl::SharedTextureHandle aHandle,
+                         gfx::SurfaceFormat aFormat,
+                         GLenum aTarget,
+                         GLenum aWrapMode,
+                         SharedTextureShareType aShareType,
+                         gfx::IntSize aSize);
+
+  virtual TextureSourceOGL* AsSourceOGL() { return this; }
+
+  virtual void BindTexture(GLenum activetex, gfx::Filter aFilter) MOZ_OVERRIDE;
+
+  virtual bool IsValid() const MOZ_OVERRIDE;
+
+  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
+
+  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
+
+  virtual gfx::Matrix4x4 GetTextureTransform() MOZ_OVERRIDE;
+
+  virtual GLenum GetTextureTarget() const { return mTextureTarget; }
+
+  virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; }
+
+  // SharedTextureSource doesn't own any gl texture
+  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
+
+  void DetachSharedHandle();
+
+  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
+
+  gl::GLContext* gl() const;
+
+protected:
+  gfx::IntSize mSize;
+  CompositorOGL* mCompositor;
+  gl::SharedTextureHandle mSharedHandle;
+  gfx::SurfaceFormat mFormat;
+  SharedTextureShareType mShareType;
+  GLenum mTextureTarget;
+  GLenum mWrapMode;
+};
+
+/**
+ * A TextureHost for shared GL Textures
+ *
+ * Most of the logic actually happens in SharedTextureSourceOGL.
+ */
+class SharedTextureHostOGL : public TextureHost
+{
+public:
+  SharedTextureHostOGL(TextureFlags aFlags,
+                       gl::SharedTextureShareType aShareType,
+                       gl::SharedTextureHandle aSharedhandle,
+                       gfx::IntSize aSize,
+                       bool inverted);
+
+  virtual ~SharedTextureHostOGL();
+
+  // SharedTextureHostOGL doesn't own any GL texture
+  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
+
+  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
+
+  virtual bool Lock() MOZ_OVERRIDE;
+
+  virtual void Unlock() MOZ_OVERRIDE;
+
+  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
+
+  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
+  {
+    return mTextureSource;
+  }
+
+  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
+  {
+    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
+  }
+
+  gl::GLContext* gl() const;
+
+  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
+
+  virtual const char* Name() { return "SharedTextureHostOGL"; }
+
+protected:
+  gfx::IntSize mSize;
+  CompositorOGL* mCompositor;
+  gl::SharedTextureHandle mSharedHandle;
+  gl::SharedTextureShareType mShareType;
+
+  RefPtr<SharedTextureSourceOGL> mTextureSource;
+};
+
+/**
+ * A texture source meant for use with SharedTextureHostOGL.
  *
  * It does not own any GL texture, and attaches its shared handle to one of
  * the compositor's temporary textures when binding.
  *
  * The shared texture handle is owned by the TextureHost.
  */
 class GLTextureSource : public NewTextureSource
                       , public TextureSourceOGL
 {
 public:
+  typedef gl::SharedTextureShareType SharedTextureShareType;
+
   GLTextureSource(CompositorOGL* aCompositor,
                   GLuint aTex,
                   gfx::SurfaceFormat aFormat,
                   GLenum aTarget,
                   gfx::IntSize aSize);
 
   virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
 
@@ -334,194 +445,12 @@ public:
 protected:
   const gfx::IntSize mSize;
   CompositorOGL* mCompositor;
   const GLuint mTex;
   const gfx::SurfaceFormat mFormat;
   const GLenum mTextureTarget;
 };
 
-////////////////////////////////////////////////////////////////////////
-// SurfaceTexture
-
-#ifdef MOZ_WIDGET_ANDROID
-
-class SurfaceTextureSource : public NewTextureSource
-                           , public TextureSourceOGL
-{
-public:
-  SurfaceTextureSource(CompositorOGL* aCompositor,
-                       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;
-
-  virtual bool IsValid() const MOZ_OVERRIDE;
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
-
-  virtual gfx::Matrix4x4 GetTextureTransform() MOZ_OVERRIDE;
-
-  virtual GLenum GetTextureTarget() const { return mTextureTarget; }
-
-  virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; }
-
-  // We don't own anything.
-  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
-
-  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
-
-  gl::GLContext* gl() const;
-
-protected:
-  CompositorOGL* mCompositor;
-  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,
-                     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;
-
-  virtual bool Lock() MOZ_OVERRIDE;
-
-  virtual void Unlock() MOZ_OVERRIDE;
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
-
-  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
-  {
-    return mTextureSource;
-  }
-
-  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
-  {
-    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
-  }
-
-  gl::GLContext* gl() const;
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
-
-  virtual const char* Name() { return "SurfaceTextureHost"; }
-
-protected:
-  mozilla::gl::AndroidSurfaceTexture* const mSurfTex;
-  const gfx::IntSize mSize;
-  CompositorOGL* mCompositor;
-  RefPtr<SurfaceTextureSource> mTextureSource;
-};
-
-#endif // MOZ_WIDGET_ANDROID
-
-////////////////////////////////////////////////////////////////////////
-// EGLImage
-
-class EGLImageTextureSource : public NewTextureSource
-                            , public TextureSourceOGL
-{
-public:
-  EGLImageTextureSource(CompositorOGL* aCompositor,
-                        EGLImage aImage,
-                        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;
-
-  virtual bool IsValid() const MOZ_OVERRIDE;
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
-
-  virtual gfx::Matrix4x4 GetTextureTransform() MOZ_OVERRIDE;
-
-  virtual GLenum GetTextureTarget() const { return mTextureTarget; }
-
-  virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; }
-
-  // We don't own anything.
-  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
-
-  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
-
-  gl::GLContext* gl() const;
-
-protected:
-  CompositorOGL* mCompositor;
-  const EGLImage mImage;
-  const gfx::SurfaceFormat mFormat;
-  const GLenum mTextureTarget;
-  const GLenum mWrapMode;
-  const gfx::IntSize mSize;
-};
-
-class EGLImageTextureHost : public TextureHost
-{
-public:
-  EGLImageTextureHost(TextureFlags aFlags,
-                     EGLImage aImage,
-                     gfx::IntSize aSize);
-
-  virtual ~EGLImageTextureHost();
-
-  // We don't own anything.
-  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
-
-  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
-
-  virtual bool Lock() MOZ_OVERRIDE;
-
-  virtual void Unlock() MOZ_OVERRIDE;
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
-
-  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
-  {
-    return mTextureSource;
-  }
-
-  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
-  {
-    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
-  }
-
-  gl::GLContext* gl() const;
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
-
-  virtual const char* Name() { return "EGLImageTextureHost"; }
-
-protected:
-  const EGLImage mImage;
-  const gfx::IntSize mSize;
-  CompositorOGL* mCompositor;
-  RefPtr<EGLImageTextureSource> mTextureSource;
-};
-
 } // namespace
 } // namespace
 
 #endif /* MOZILLA_GFX_TEXTUREOGL_H */
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -97,21 +97,16 @@ void TexturePoolOGL::Fill(GLContext* aCo
     texture = (GLuint*)malloc(sizeof(GLuint));
     sActiveContext->fGenTextures(1, texture);
     sTextures->Push((void*) texture);
   }
 
   sMonitor->NotifyAll();
 }
 
-GLContext* TexturePoolOGL::GetGLContext()
-{
-  return sActiveContext;
-}
-
 void TexturePoolOGL::Init()
 {
   sMonitor = new Monitor("TexturePoolOGL.sMonitor");
   sTextures = new nsDeque();
 }
 
 void TexturePoolOGL::Shutdown()
 {
--- a/gfx/layers/opengl/TexturePoolOGL.h
+++ b/gfx/layers/opengl/TexturePoolOGL.h
@@ -7,31 +7,29 @@
 
 #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 AndroidSurfaceTexture)
+// content thread. The unfortunate nature of the SurfaceTexture API (see nsSurfaceTexture)
 // 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();
 
   // Called by the active LayerManagerOGL to fill
   // the pool
   static void Fill(GLContext* aContext);
 
-  static GLContext* GetGLContext();
-
   // Initializes the pool, but does not fill it. Called by gfxPlatform init.
   static void Init();
 
   // Clears all internal data structures in preparation for shutdown
   static void Shutdown();
 };
 
 } // gl
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -42,16 +42,17 @@ EXPORTS += [
     'gfxSharedQuartzSurface.h',
     'gfxSkipChars.h',
     'gfxSVGGlyphs.h',
     'gfxTeeSurface.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',
@@ -233,16 +234,17 @@ UNIFIED_SOURCES += [
     'gfxRect.cpp',
     'gfxReusableImageSurfaceWrapper.cpp',
     'gfxReusableSharedImageSurfaceWrapper.cpp',
     'gfxScriptItemizer.cpp',
     'gfxSkipChars.cpp',
     'gfxSVGGlyphs.cpp',
     'gfxTeeSurface.cpp',
     'gfxUtils.cpp',
+    'nsSurfaceTexture.cpp',
     'nsUnicodeRange.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     # gfxMacPlatformFontList.mm forces NSPR logging so it cannot be built in unified mode.
     SOURCES += [
         'gfxMacPlatformFontList.mm',
     ]
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/nsSurfaceTexture.cpp
@@ -0,0 +1,247 @@
+/* -*- 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
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/nsSurfaceTexture.h
@@ -0,0 +1,70 @@
+/* -*- 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/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -591,22 +591,16 @@ pref("media.preload.auto", 2);    // pre
 // Number of video frames we buffer while decoding video.
 // On Android this is decided by a similar value which varies for
 // each OMX decoder |OMX_PARAM_PORTDEFINITIONTYPE::nBufferCountMin|. This
 // number must be less than the OMX equivalent or gecko will think it is
 // chronically starved of video frames. All decoders seen so far have a value
 // of at least 4.
 pref("media.video-queue.default-size", 3);
 
-// Enable the MediaCodec PlatformDecoderModule by default.
-pref("media.fragmented-mp4.exposed", true);
-pref("media.fragmented-mp4.enabled", true);
-pref("media.fragmented-mp4.android-media-codec.enabled", true);
-pref("media.fragmented-mp4.android-media-codec.preferred", true);
-
 // optimize images memory usage
 pref("image.mem.decodeondraw", true);
 pref("image.mem.min_discard_timeout_ms", 10000);
 
 #ifdef NIGHTLY_BUILD
 // Shumway component (SWF player) is disabled by default. Also see bug 904346.
 pref("shumway.disabled", true);
 #endif
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -2521,17 +2521,17 @@ public class GeckoAppShell
     }
 
     @WrapElementForJNI
     public static void notifyWakeLockChanged(String topic, String state) {
         if (getGeckoInterface() != null)
             getGeckoInterface().notifyWakeLockChanged(topic, state);
     }
 
-    @WrapElementForJNI(allowMultithread = true)
+    @WrapElementForJNI
     public static void registerSurfaceTextureFrameListener(Object surfaceTexture, final int id) {
         ((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
             @Override
             public void onFrameAvailable(SurfaceTexture surfaceTexture) {
                 GeckoAppShell.onSurfaceTextureFrameAvailable(surfaceTexture, id);
             }
         });
     }
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -36,17 +36,16 @@
 #include "nsIDOMClientRect.h"
 #include "StrongPointer.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "nsPrintfCString.h"
 #include "NativeJSContainer.h"
 #include "nsContentUtils.h"
 #include "nsIScriptError.h"
 #include "nsIHttpChannel.h"
-#include "GeneratedSDKWrappers.h"
 
 using namespace mozilla;
 using namespace mozilla::widget::android;
 using namespace mozilla::gfx;
 
 AndroidBridge* AndroidBridge::sBridge;
 pthread_t AndroidBridge::sJavaUiThread = -1;
 static unsigned sJavaEnvThreadIndex = 0;
@@ -216,21 +215,16 @@ AndroidBridge::Init(JNIEnv *jEnv)
     jByteBufferRead = jEnv->GetMethodID(jReadableByteChannel, "read", "(Ljava/nio/ByteBuffer;)I");
 
     jInputStream = getClassGlobalRef("java/io/InputStream");
     jClose = jEnv->GetMethodID(jInputStream, "close", "()V");
     jAvailable = jEnv->GetMethodID(jInputStream, "available", "()I");
 
     InitAndroidJavaWrappers(jEnv);
 
-    if (mAPIVersion >= 16 /* Jelly Bean */) {
-        // We only use this for MediaCodec right now
-        InitSDKStubs(jEnv);
-    }
-
     // jEnv should NOT be cached here by anything -- the jEnv here
     // is not valid for the real gecko main thread, which is set
     // at SetMainThread time.
 
     return true;
 }
 
 bool
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -36,17 +36,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 "AndroidSurfaceTexture.h"
+#include "nsSurfaceTexture.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;
@@ -841,19 +841,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)
 {
-  mozilla::gl::AndroidSurfaceTexture* st = mozilla::gl::AndroidSurfaceTexture::Find(id);
+  nsSurfaceTexture* st = nsSurfaceTexture::Find(id);
   if (!st) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find AndroidSurfaceTexture with id %d", id);
+    __android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find nsSurfaceTexture with id %d", id);
     return;
   }
 
   st->NotifyFrameAvailable();
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_dispatchMemoryPressure(JNIEnv* jenv, jclass)
--- a/widget/android/AndroidJavaWrappers.cpp
+++ b/widget/android/AndroidJavaWrappers.cpp
@@ -6,17 +6,16 @@
 #include "AndroidJavaWrappers.h"
 #include "AndroidBridge.h"
 #include "AndroidBridgeUtilities.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIWidget.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/TouchEvents.h"
-#include "GeneratedSDKWrappers.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::widget::android;
 
 jclass AndroidGeckoEvent::jGeckoEventClass = 0;
 jfieldID AndroidGeckoEvent::jActionField = 0;
 jfieldID AndroidGeckoEvent::jTypeField = 0;
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1113,17 +1113,17 @@ bool GeckoAppShell::PumpMessageLoop() {
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jPumpMessageLoop);
     AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::RegisterSurfaceTextureFrameListener(jobject a0, int32_t a1) {
-    JNIEnv *env = GetJNIForThread();
+    JNIEnv *env = AndroidBridge::GetJNIEnv();
     if (env->PushLocalFrame(1) != 0) {
         AndroidBridge::HandleUncaughtException(env);
         MOZ_CRASH("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jRegisterSurfaceTextureFrameListener, a0, a1);
     AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
deleted file mode 100644
--- a/widget/android/GeneratedSDKWrappers.cpp
+++ /dev/null
@@ -1,1877 +0,0 @@
-// GENERATED CODE
-// Generated by the Java program at /build/jarClassProcessors at compile time from
-// a given set of jars and a set of requested methods. To update, change the annotations
-// on the corresponding Java methods and rerun the build. Manually updating this file
-// will cause your build to fail.
-
-#include "GeneratedSDKWrappers.h"
-#include "AndroidBridgeUtilities.h"
-#include "nsXPCOMStrings.h"
-#include "AndroidBridge.h"
-#include "nsDebug.h"
-
-namespace mozilla {
-namespace widget {
-namespace android {
-jclass MediaCodec::mMediaCodecClass = 0;
-jmethodID MediaCodec::jConfigure = 0;
-jmethodID MediaCodec::jCreateByCodecName = 0;
-jmethodID MediaCodec::jCreateDecoderByType = 0;
-jmethodID MediaCodec::jCreateEncoderByType = 0;
-jmethodID MediaCodec::jDequeueInputBuffer = 0;
-jmethodID MediaCodec::jDequeueOutputBuffer = 0;
-jmethodID MediaCodec::jFinalize = 0;
-jmethodID MediaCodec::jFlush = 0;
-jmethodID MediaCodec::jGetInputBuffers = 0;
-jmethodID MediaCodec::jGetOutputBuffers = 0;
-jmethodID MediaCodec::jGetOutputFormat = 0;
-jmethodID MediaCodec::jQueueInputBuffer = 0;
-jmethodID MediaCodec::jQueueSecureInputBuffer = 0;
-jmethodID MediaCodec::jRelease = 0;
-jmethodID MediaCodec::jReleaseOutputBuffer = 0;
-jmethodID MediaCodec::jSetVideoScalingMode = 0;
-jmethodID MediaCodec::jStart = 0;
-jmethodID MediaCodec::jStop = 0;
-jfieldID MediaCodec::jBUFFER_FLAG_CODEC_CONFIG = 0;
-jfieldID MediaCodec::jBUFFER_FLAG_END_OF_STREAM = 0;
-jfieldID MediaCodec::jBUFFER_FLAG_SYNC_FRAME = 0;
-jfieldID MediaCodec::jCONFIGURE_FLAG_ENCODE = 0;
-jfieldID MediaCodec::jCRYPTO_MODE_AES_CTR = 0;
-jfieldID MediaCodec::jCRYPTO_MODE_UNENCRYPTED = 0;
-jfieldID MediaCodec::jINFO_OUTPUT_BUFFERS_CHANGED = 0;
-jfieldID MediaCodec::jINFO_OUTPUT_FORMAT_CHANGED = 0;
-jfieldID MediaCodec::jINFO_TRY_AGAIN_LATER = 0;
-jfieldID MediaCodec::jVIDEO_SCALING_MODE_SCALE_TO_FIT = 0;
-jfieldID MediaCodec::jVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 0;
-void MediaCodec::InitStubs(JNIEnv *jEnv) {
-    initInit();
-
-    mMediaCodecClass = getClassGlobalRef("android/media/MediaCodec");
-    jConfigure = getMethod("configure", "(Landroid/media/MediaFormat;Landroid/view/Surface;Landroid/media/MediaCrypto;I)V");
-    jCreateByCodecName = getStaticMethod("createByCodecName", "(Ljava/lang/String;)Landroid/media/MediaCodec;");
-    jCreateDecoderByType = getStaticMethod("createDecoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;");
-    jCreateEncoderByType = getStaticMethod("createEncoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;");
-    jDequeueInputBuffer = getMethod("dequeueInputBuffer", "(J)I");
-    jDequeueOutputBuffer = getMethod("dequeueOutputBuffer", "(Landroid/media/MediaCodec$BufferInfo;J)I");
-    jFinalize = getMethod("finalize", "()V");
-    jFlush = getMethod("flush", "()V");
-    jGetInputBuffers = getMethod("getInputBuffers", "()[Ljava/nio/ByteBuffer;");
-    jGetOutputBuffers = getMethod("getOutputBuffers", "()[Ljava/nio/ByteBuffer;");
-    jGetOutputFormat = getMethod("getOutputFormat", "()Landroid/media/MediaFormat;");
-    jQueueInputBuffer = getMethod("queueInputBuffer", "(IIIJI)V");
-    jQueueSecureInputBuffer = getMethod("queueSecureInputBuffer", "(IILandroid/media/MediaCodec$CryptoInfo;JI)V");
-    jRelease = getMethod("release", "()V");
-    jReleaseOutputBuffer = getMethod("releaseOutputBuffer", "(IZ)V");
-    jSetVideoScalingMode = getMethod("setVideoScalingMode", "(I)V");
-    jStart = getMethod("start", "()V");
-    jStop = getMethod("stop", "()V");
-    jBUFFER_FLAG_CODEC_CONFIG = getStaticField("BUFFER_FLAG_CODEC_CONFIG", "I");
-    jBUFFER_FLAG_END_OF_STREAM = getStaticField("BUFFER_FLAG_END_OF_STREAM", "I");
-    jBUFFER_FLAG_SYNC_FRAME = getStaticField("BUFFER_FLAG_SYNC_FRAME", "I");
-    jCONFIGURE_FLAG_ENCODE = getStaticField("CONFIGURE_FLAG_ENCODE", "I");
-    jCRYPTO_MODE_AES_CTR = getStaticField("CRYPTO_MODE_AES_CTR", "I");
-    jCRYPTO_MODE_UNENCRYPTED = getStaticField("CRYPTO_MODE_UNENCRYPTED", "I");
-    jINFO_OUTPUT_BUFFERS_CHANGED = getStaticField("INFO_OUTPUT_BUFFERS_CHANGED", "I");
-    jINFO_OUTPUT_FORMAT_CHANGED = getStaticField("INFO_OUTPUT_FORMAT_CHANGED", "I");
-    jINFO_TRY_AGAIN_LATER = getStaticField("INFO_TRY_AGAIN_LATER", "I");
-    jVIDEO_SCALING_MODE_SCALE_TO_FIT = getStaticField("VIDEO_SCALING_MODE_SCALE_TO_FIT", "I");
-    jVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = getStaticField("VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING", "I");
-}
-
-MediaCodec* MediaCodec::Wrap(jobject obj) {
-    JNIEnv *env = GetJNIForThread();
-    MediaCodec* ret = new MediaCodec(obj, env);
-    env->DeleteLocalRef(obj);
-    return ret;
-}
-
-bool MediaCodec::Configure(jobject a0, jobject a1, jobject a2, int32_t a3) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(3) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[4];
-    args[0].l = a0;
-    args[1].l = a1;
-    args[2].l = a2;
-    args[3].i = a3;
-
-    env->CallVoidMethodA(wrapped_obj, jConfigure, args);
-    if (env->ExceptionCheck()) {
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-    env->PopLocalFrame(nullptr);
-    return true;
-}
-
-jobject MediaCodec::CreateByCodecName(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jobject temp = env->CallStaticObjectMethod(mMediaCodecClass, jCreateByCodecName, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject MediaCodec::CreateDecoderByType(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jobject temp = env->CallStaticObjectMethod(mMediaCodecClass, jCreateDecoderByType, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject MediaCodec::CreateEncoderByType(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jobject temp = env->CallStaticObjectMethod(mMediaCodecClass, jCreateEncoderByType, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-int32_t MediaCodec::DequeueInputBuffer(int64_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jDequeueInputBuffer, a0);
-    if (env->ExceptionCheck()) {
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return MEDIACODEC_EXCEPTION_INDEX;
-    }
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t MediaCodec::DequeueOutputBuffer(jobject a0, int64_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jDequeueOutputBuffer, a0, a1);
-    if (env->ExceptionCheck()) {
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return MEDIACODEC_EXCEPTION_INDEX;
-    }
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-void MediaCodec::Finalize() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jFinalize);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaCodec::Flush() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jFlush);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-jobjectArray MediaCodec::GetInputBuffers() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGetInputBuffers);
-    AndroidBridge::HandleUncaughtException(env);
-    jobjectArray ret = static_cast<jobjectArray>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobjectArray MediaCodec::GetOutputBuffers() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGetOutputBuffers);
-    AndroidBridge::HandleUncaughtException(env);
-    jobjectArray ret = static_cast<jobjectArray>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject MediaCodec::GetOutputFormat() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGetOutputFormat);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-void MediaCodec::QueueInputBuffer(int32_t a0, int32_t a1, int32_t a2, int64_t a3, int32_t a4) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(5) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[5];
-    args[0].i = a0;
-    args[1].i = a1;
-    args[2].i = a2;
-    args[3].j = a3;
-    args[4].i = a4;
-
-    env->CallVoidMethodA(wrapped_obj, jQueueInputBuffer, args);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaCodec::QueueSecureInputBuffer(int32_t a0, int32_t a1, jobject a2, int64_t a3, int32_t a4) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[5];
-    args[0].i = a0;
-    args[1].i = a1;
-    args[2].l = a2;
-    args[3].j = a3;
-    args[4].i = a4;
-
-    env->CallVoidMethodA(wrapped_obj, jQueueSecureInputBuffer, args);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaCodec::Release() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jRelease);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaCodec::ReleaseOutputBuffer(int32_t a0, bool a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jReleaseOutputBuffer, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaCodec::SetVideoScalingMode(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jSetVideoScalingMode, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-bool MediaCodec::Start() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jStart);
-    if (env->ExceptionCheck()) {
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-    env->PopLocalFrame(nullptr);
-    return true;
-}
-
-void MediaCodec::Stop() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, jStop);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-int32_t MediaCodec::getBUFFER_FLAG_CODEC_CONFIG() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jBUFFER_FLAG_CODEC_CONFIG);
-}
-
-int32_t MediaCodec::getBUFFER_FLAG_END_OF_STREAM() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jBUFFER_FLAG_END_OF_STREAM);
-}
-
-int32_t MediaCodec::getBUFFER_FLAG_SYNC_FRAME() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jBUFFER_FLAG_SYNC_FRAME);
-}
-
-int32_t MediaCodec::getCONFIGURE_FLAG_ENCODE() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jCONFIGURE_FLAG_ENCODE);
-}
-
-int32_t MediaCodec::getCRYPTO_MODE_AES_CTR() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jCRYPTO_MODE_AES_CTR);
-}
-
-int32_t MediaCodec::getCRYPTO_MODE_UNENCRYPTED() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jCRYPTO_MODE_UNENCRYPTED);
-}
-
-int32_t MediaCodec::getINFO_OUTPUT_BUFFERS_CHANGED() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jINFO_OUTPUT_BUFFERS_CHANGED);
-}
-
-int32_t MediaCodec::getINFO_OUTPUT_FORMAT_CHANGED() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jINFO_OUTPUT_FORMAT_CHANGED);
-}
-
-int32_t MediaCodec::getINFO_TRY_AGAIN_LATER() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jINFO_TRY_AGAIN_LATER);
-}
-
-int32_t MediaCodec::getVIDEO_SCALING_MODE_SCALE_TO_FIT() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jVIDEO_SCALING_MODE_SCALE_TO_FIT);
-}
-
-int32_t MediaCodec::getVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetStaticIntField(mMediaCodecClass, jVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
-}
-jclass MediaFormat::mMediaFormatClass = 0;
-jmethodID MediaFormat::jMediaFormat = 0;
-jmethodID MediaFormat::jContainsKey = 0;
-jmethodID MediaFormat::jCreateAudioFormat = 0;
-jmethodID MediaFormat::jCreateVideoFormat = 0;
-jmethodID MediaFormat::jGetByteBuffer = 0;
-jmethodID MediaFormat::jGetFloat = 0;
-jmethodID MediaFormat::jGetInteger = 0;
-jmethodID MediaFormat::jGetLong = 0;
-jmethodID MediaFormat::jGetString = 0;
-jmethodID MediaFormat::jSetByteBuffer = 0;
-jmethodID MediaFormat::jSetFloat = 0;
-jmethodID MediaFormat::jSetInteger = 0;
-jmethodID MediaFormat::jSetLong = 0;
-jmethodID MediaFormat::jSetString = 0;
-jmethodID MediaFormat::jToString = 0;
-jfieldID MediaFormat::jKEY_AAC_PROFILE = 0;
-jfieldID MediaFormat::jKEY_BIT_RATE = 0;
-jfieldID MediaFormat::jKEY_CHANNEL_COUNT = 0;
-jfieldID MediaFormat::jKEY_CHANNEL_MASK = 0;
-jfieldID MediaFormat::jKEY_COLOR_FORMAT = 0;
-jfieldID MediaFormat::jKEY_DURATION = 0;
-jfieldID MediaFormat::jKEY_FLAC_COMPRESSION_LEVEL = 0;
-jfieldID MediaFormat::jKEY_FRAME_RATE = 0;
-jfieldID MediaFormat::jKEY_HEIGHT = 0;
-jfieldID MediaFormat::jKEY_IS_ADTS = 0;
-jfieldID MediaFormat::jKEY_I_FRAME_INTERVAL = 0;
-jfieldID MediaFormat::jKEY_MAX_INPUT_SIZE = 0;
-jfieldID MediaFormat::jKEY_MIME = 0;
-jfieldID MediaFormat::jKEY_SAMPLE_RATE = 0;
-jfieldID MediaFormat::jKEY_WIDTH = 0;
-void MediaFormat::InitStubs(JNIEnv *jEnv) {
-    initInit();
-
-    mMediaFormatClass = getClassGlobalRef("android/media/MediaFormat");
-    jMediaFormat = getMethod("<init>", "()V");
-    jContainsKey = getMethod("containsKey", "(Ljava/lang/String;)Z");
-    jCreateAudioFormat = getStaticMethod("createAudioFormat", "(Ljava/lang/String;II)Landroid/media/MediaFormat;");
-    jCreateVideoFormat = getStaticMethod("createVideoFormat", "(Ljava/lang/String;II)Landroid/media/MediaFormat;");
-    jGetByteBuffer = getMethod("getByteBuffer", "(Ljava/lang/String;)Ljava/nio/ByteBuffer;");
-    jGetFloat = getMethod("getFloat", "(Ljava/lang/String;)F");
-    jGetInteger = getMethod("getInteger", "(Ljava/lang/String;)I");
-    jGetLong = getMethod("getLong", "(Ljava/lang/String;)J");
-    jGetString = getMethod("getString", "(Ljava/lang/String;)Ljava/lang/String;");
-    jSetByteBuffer = getMethod("setByteBuffer", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V");
-    jSetFloat = getMethod("setFloat", "(Ljava/lang/String;F)V");
-    jSetInteger = getMethod("setInteger", "(Ljava/lang/String;I)V");
-    jSetLong = getMethod("setLong", "(Ljava/lang/String;J)V");
-    jSetString = getMethod("setString", "(Ljava/lang/String;Ljava/lang/String;)V");
-    jToString = getMethod("toString", "()Ljava/lang/String;");
-    jKEY_AAC_PROFILE = getStaticField("KEY_AAC_PROFILE", "Ljava/lang/String;");
-    jKEY_BIT_RATE = getStaticField("KEY_BIT_RATE", "Ljava/lang/String;");
-    jKEY_CHANNEL_COUNT = getStaticField("KEY_CHANNEL_COUNT", "Ljava/lang/String;");
-    jKEY_CHANNEL_MASK = getStaticField("KEY_CHANNEL_MASK", "Ljava/lang/String;");
-    jKEY_COLOR_FORMAT = getStaticField("KEY_COLOR_FORMAT", "Ljava/lang/String;");
-    jKEY_DURATION = getStaticField("KEY_DURATION", "Ljava/lang/String;");
-    jKEY_FLAC_COMPRESSION_LEVEL = getStaticField("KEY_FLAC_COMPRESSION_LEVEL", "Ljava/lang/String;");
-    jKEY_FRAME_RATE = getStaticField("KEY_FRAME_RATE", "Ljava/lang/String;");
-    jKEY_HEIGHT = getStaticField("KEY_HEIGHT", "Ljava/lang/String;");
-    jKEY_IS_ADTS = getStaticField("KEY_IS_ADTS", "Ljava/lang/String;");
-    jKEY_I_FRAME_INTERVAL = getStaticField("KEY_I_FRAME_INTERVAL", "Ljava/lang/String;");
-    jKEY_MAX_INPUT_SIZE = getStaticField("KEY_MAX_INPUT_SIZE", "Ljava/lang/String;");
-    jKEY_MIME = getStaticField("KEY_MIME", "Ljava/lang/String;");
-    jKEY_SAMPLE_RATE = getStaticField("KEY_SAMPLE_RATE", "Ljava/lang/String;");
-    jKEY_WIDTH = getStaticField("KEY_WIDTH", "Ljava/lang/String;");
-}
-
-MediaFormat* MediaFormat::Wrap(jobject obj) {
-    JNIEnv *env = GetJNIForThread();
-    MediaFormat* ret = new MediaFormat(obj, env);
-    env->DeleteLocalRef(obj);
-    return ret;
-}
-
-MediaFormat::MediaFormat() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    Init(env->NewObject(mMediaFormatClass, jMediaFormat), env);
-    env->PopLocalFrame(nullptr);
-}
-
-bool MediaFormat::ContainsKey(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    bool temp = env->CallBooleanMethod(wrapped_obj, jContainsKey, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jobject MediaFormat::CreateAudioFormat(const nsAString& a0, int32_t a1, int32_t a2) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[3];
-    args[0].l = AndroidBridge::NewJavaString(env, a0);
-    args[1].i = a1;
-    args[2].i = a2;
-
-    jobject temp = env->CallStaticObjectMethodA(mMediaFormatClass, jCreateAudioFormat, args);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject MediaFormat::CreateVideoFormat(const nsAString& a0, int32_t a1, int32_t a2) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[3];
-    args[0].l = AndroidBridge::NewJavaString(env, a0);
-    args[1].i = a1;
-    args[2].i = a2;
-
-    jobject temp = env->CallStaticObjectMethodA(mMediaFormatClass, jCreateVideoFormat, args);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject MediaFormat::GetByteBuffer(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGetByteBuffer, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jfloat MediaFormat::GetFloat(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jfloat temp = env->CallFloatMethod(wrapped_obj, jGetFloat, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t MediaFormat::GetInteger(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jGetInteger, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int64_t MediaFormat::GetLong(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    int64_t temp = env->CallLongMethod(wrapped_obj, jGetLong, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jstring MediaFormat::GetString(const nsAString& a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGetString, j0);
-    AndroidBridge::HandleUncaughtException(env);
-    jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-void MediaFormat::SetByteBuffer(const nsAString& a0, jobject a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    env->CallVoidMethod(wrapped_obj, jSetByteBuffer, j0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaFormat::SetFloat(const nsAString& a0, jfloat a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    env->CallVoidMethod(wrapped_obj, jSetFloat, j0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaFormat::SetInteger(const nsAString& a0, int32_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    env->CallVoidMethod(wrapped_obj, jSetInteger, j0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaFormat::SetLong(const nsAString& a0, int64_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-
-    env->CallVoidMethod(wrapped_obj, jSetLong, j0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-void MediaFormat::SetString(const nsAString& a0, const nsAString& a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jstring j0 = AndroidBridge::NewJavaString(env, a0);
-    jstring j1 = AndroidBridge::NewJavaString(env, a1);
-
-    env->CallVoidMethod(wrapped_obj, jSetString, j0, j1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-jstring MediaFormat::ToString() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jToString);
-    AndroidBridge::HandleUncaughtException(env);
-    jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jstring MediaFormat::getKEY_AAC_PROFILE() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_AAC_PROFILE));
-}
-
-jstring MediaFormat::getKEY_BIT_RATE() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_BIT_RATE));
-}
-
-jstring MediaFormat::getKEY_CHANNEL_COUNT() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_CHANNEL_COUNT));
-}
-
-jstring MediaFormat::getKEY_CHANNEL_MASK() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_CHANNEL_MASK));
-}
-
-jstring MediaFormat::getKEY_COLOR_FORMAT() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_COLOR_FORMAT));
-}
-
-jstring MediaFormat::getKEY_DURATION() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_DURATION));
-}
-
-jstring MediaFormat::getKEY_FLAC_COMPRESSION_LEVEL() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_FLAC_COMPRESSION_LEVEL));
-}
-
-jstring MediaFormat::getKEY_FRAME_RATE() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_FRAME_RATE));
-}
-
-jstring MediaFormat::getKEY_HEIGHT() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_HEIGHT));
-}
-
-jstring MediaFormat::getKEY_IS_ADTS() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_IS_ADTS));
-}
-
-jstring MediaFormat::getKEY_I_FRAME_INTERVAL() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_I_FRAME_INTERVAL));
-}
-
-jstring MediaFormat::getKEY_MAX_INPUT_SIZE() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_MAX_INPUT_SIZE));
-}
-
-jstring MediaFormat::getKEY_MIME() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_MIME));
-}
-
-jstring MediaFormat::getKEY_SAMPLE_RATE() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_SAMPLE_RATE));
-}
-
-jstring MediaFormat::getKEY_WIDTH() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jstring>(env->GetStaticObjectField(mMediaFormatClass, jKEY_WIDTH));
-}
-jclass ByteBuffer::mByteBufferClass = 0;
-jmethodID ByteBuffer::j_get = 0;
-jmethodID ByteBuffer::j_put = 0;
-jmethodID ByteBuffer::jAllocate = 0;
-jmethodID ByteBuffer::jAllocateDirect = 0;
-jmethodID ByteBuffer::jArray = 0;
-jmethodID ByteBuffer::jArray1 = 0;
-jmethodID ByteBuffer::jArrayOffset = 0;
-jmethodID ByteBuffer::jAsCharBuffer = 0;
-jmethodID ByteBuffer::jAsDoubleBuffer = 0;
-jmethodID ByteBuffer::jAsFloatBuffer = 0;
-jmethodID ByteBuffer::jAsIntBuffer = 0;
-jmethodID ByteBuffer::jAsLongBuffer = 0;
-jmethodID ByteBuffer::jAsReadOnlyBuffer = 0;
-jmethodID ByteBuffer::jAsShortBuffer = 0;
-jmethodID ByteBuffer::jCompact = 0;
-jmethodID ByteBuffer::jCompareTo = 0;
-jmethodID ByteBuffer::jCompareTo1 = 0;
-jmethodID ByteBuffer::jDuplicate = 0;
-jmethodID ByteBuffer::jEquals = 0;
-jmethodID ByteBuffer::jGet = 0;
-jmethodID ByteBuffer::jGet1 = 0;
-jmethodID ByteBuffer::jGet10 = 0;
-jmethodID ByteBuffer::jGet11 = 0;
-jmethodID ByteBuffer::jGetChar = 0;
-jmethodID ByteBuffer::jGetChar1 = 0;
-jmethodID ByteBuffer::jGetDouble = 0;
-jmethodID ByteBuffer::jGetDouble1 = 0;
-jmethodID ByteBuffer::jGetFloat = 0;
-jmethodID ByteBuffer::jGetFloat1 = 0;
-jmethodID ByteBuffer::jGetInt = 0;
-jmethodID ByteBuffer::jGetInt1 = 0;
-jmethodID ByteBuffer::jGetLong = 0;
-jmethodID ByteBuffer::jGetLong1 = 0;
-jmethodID ByteBuffer::jGetShort = 0;
-jmethodID ByteBuffer::jGetShort1 = 0;
-jmethodID ByteBuffer::jHasArray = 0;
-jmethodID ByteBuffer::jHashCode = 0;
-jmethodID ByteBuffer::jIsDirect = 0;
-jmethodID ByteBuffer::jOrder = 0;
-jmethodID ByteBuffer::jOrder1 = 0;
-jmethodID ByteBuffer::jPut = 0;
-jmethodID ByteBuffer::jPut1 = 0;
-jmethodID ByteBuffer::jPut12 = 0;
-jmethodID ByteBuffer::jPut13 = 0;
-jmethodID ByteBuffer::jPut14 = 0;
-jmethodID ByteBuffer::jPutChar = 0;
-jmethodID ByteBuffer::jPutChar1 = 0;
-jmethodID ByteBuffer::jPutDouble = 0;
-jmethodID ByteBuffer::jPutDouble1 = 0;
-jmethodID ByteBuffer::jPutFloat = 0;
-jmethodID ByteBuffer::jPutFloat1 = 0;
-jmethodID ByteBuffer::jPutInt = 0;
-jmethodID ByteBuffer::jPutInt1 = 0;
-jmethodID ByteBuffer::jPutLong = 0;
-jmethodID ByteBuffer::jPutLong1 = 0;
-jmethodID ByteBuffer::jPutShort = 0;
-jmethodID ByteBuffer::jPutShort1 = 0;
-jmethodID ByteBuffer::jSlice = 0;
-jmethodID ByteBuffer::jToString = 0;
-jmethodID ByteBuffer::jWrap = 0;
-jmethodID ByteBuffer::jWrap1 = 0;
-jfieldID ByteBuffer::jBigEndian = 0;
-jfieldID ByteBuffer::jHb = 0;
-jfieldID ByteBuffer::jIsReadOnly = 0;
-jfieldID ByteBuffer::jNativeByteOrder = 0;
-jfieldID ByteBuffer::jOffset = 0;
-void ByteBuffer::InitStubs(JNIEnv *jEnv) {
-    initInit();
-
-    mByteBufferClass = getClassGlobalRef("java/nio/ByteBuffer");
-    //j_get = getMethod("_get", "(I)B");
-    //j_put = getMethod("_put", "(IB)V");
-    jAllocate = getStaticMethod("allocate", "(I)Ljava/nio/ByteBuffer;");
-    jAllocateDirect = getStaticMethod("allocateDirect", "(I)Ljava/nio/ByteBuffer;");
-    jArray = getMethod("array", "()Ljava/lang/Object;");
-    jArray1 = getMethod("array", "()[B");
-    jArrayOffset = getMethod("arrayOffset", "()I");
-    jAsCharBuffer = getMethod("asCharBuffer", "()Ljava/nio/CharBuffer;");
-    jAsDoubleBuffer = getMethod("asDoubleBuffer", "()Ljava/nio/DoubleBuffer;");
-    jAsFloatBuffer = getMethod("asFloatBuffer", "()Ljava/nio/FloatBuffer;");
-    jAsIntBuffer = getMethod("asIntBuffer", "()Ljava/nio/IntBuffer;");
-    jAsLongBuffer = getMethod("asLongBuffer", "()Ljava/nio/LongBuffer;");
-    jAsReadOnlyBuffer = getMethod("asReadOnlyBuffer", "()Ljava/nio/ByteBuffer;");
-    jAsShortBuffer = getMethod("asShortBuffer", "()Ljava/nio/ShortBuffer;");
-    jCompact = getMethod("compact", "()Ljava/nio/ByteBuffer;");
-    jCompareTo = getMethod("compareTo", "(Ljava/lang/Object;)I");
-    jCompareTo1 = getMethod("compareTo", "(Ljava/nio/ByteBuffer;)I");
-    jDuplicate = getMethod("duplicate", "()Ljava/nio/ByteBuffer;");
-    jEquals = getMethod("equals", "(Ljava/lang/Object;)Z");
-    jGet = getMethod("get", "()B");
-    jGet1 = getMethod("get", "(I)B");
-    jGet10 = getMethod("get", "([B)Ljava/nio/ByteBuffer;");
-    jGet11 = getMethod("get", "([BII)Ljava/nio/ByteBuffer;");
-    jGetChar = getMethod("getChar", "()C");
-    jGetChar1 = getMethod("getChar", "(I)C");
-    jGetDouble = getMethod("getDouble", "()D");
-    jGetDouble1 = getMethod("getDouble", "(I)D");
-    jGetFloat = getMethod("getFloat", "()F");
-    jGetFloat1 = getMethod("getFloat", "(I)F");
-    jGetInt = getMethod("getInt", "()I");
-    jGetInt1 = getMethod("getInt", "(I)I");
-    jGetLong = getMethod("getLong", "()J");
-    jGetLong1 = getMethod("getLong", "(I)J");
-    jGetShort = getMethod("getShort", "()S");
-    jGetShort1 = getMethod("getShort", "(I)S");
-    jHasArray = getMethod("hasArray", "()Z");
-    jHashCode = getMethod("hashCode", "()I");
-    jIsDirect = getMethod("isDirect", "()Z");
-    jOrder = getMethod("order", "()Ljava/nio/ByteOrder;");
-    jOrder1 = getMethod("order", "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;");
-    jPut = getMethod("put", "(B)Ljava/nio/ByteBuffer;");
-    jPut1 = getMethod("put", "(IB)Ljava/nio/ByteBuffer;");
-    jPut12 = getMethod("put", "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;");
-    jPut13 = getMethod("put", "([B)Ljava/nio/ByteBuffer;");
-    jPut14 = getMethod("put", "([BII)Ljava/nio/ByteBuffer;");
-    jPutChar = getMethod("putChar", "(C)Ljava/nio/ByteBuffer;");
-    jPutChar1 = getMethod("putChar", "(IC)Ljava/nio/ByteBuffer;");
-    jPutDouble = getMethod("putDouble", "(D)Ljava/nio/ByteBuffer;");
-    jPutDouble1 = getMethod("putDouble", "(ID)Ljava/nio/ByteBuffer;");
-    jPutFloat = getMethod("putFloat", "(F)Ljava/nio/ByteBuffer;");
-    jPutFloat1 = getMethod("putFloat", "(IF)Ljava/nio/ByteBuffer;");
-    jPutInt = getMethod("putInt", "(I)Ljava/nio/ByteBuffer;");
-    jPutInt1 = getMethod("putInt", "(II)Ljava/nio/ByteBuffer;");
-    jPutLong = getMethod("putLong", "(IJ)Ljava/nio/ByteBuffer;");
-    jPutLong1 = getMethod("putLong", "(J)Ljava/nio/ByteBuffer;");
-    jPutShort = getMethod("putShort", "(IS)Ljava/nio/ByteBuffer;");
-    jPutShort1 = getMethod("putShort", "(S)Ljava/nio/ByteBuffer;");
-    jSlice = getMethod("slice", "()Ljava/nio/ByteBuffer;");
-    jToString = getMethod("toString", "()Ljava/lang/String;");
-    jWrap = getStaticMethod("wrap", "([B)Ljava/nio/ByteBuffer;");
-    jWrap1 = getStaticMethod("wrap", "([BII)Ljava/nio/ByteBuffer;");
-    /*
-    jBigEndian = getField("bigEndian", "Z");
-    jHb = getField("hb", "[B");
-    jIsReadOnly = getField("isReadOnly", "Z");
-    jNativeByteOrder = getField("nativeByteOrder", "Z");
-    jOffset = getField("offset", "I");
-  */
-}
-
-ByteBuffer* ByteBuffer::Wrap(jobject obj) {
-    JNIEnv *env = GetJNIForThread();
-    ByteBuffer* ret = new ByteBuffer(obj, env);
-    env->DeleteLocalRef(obj);
-    return ret;
-}
-
-int8_t ByteBuffer::_get(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int8_t temp = env->CallByteMethod(wrapped_obj, j_get, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-void ByteBuffer::_put(int32_t a0, int8_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    env->CallVoidMethod(wrapped_obj, j_put, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-jobject ByteBuffer::Allocate(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallStaticObjectMethod(mByteBufferClass, jAllocate, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AllocateDirect(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallStaticObjectMethod(mByteBufferClass, jAllocateDirect, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Array() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jArray);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jbyteArray ByteBuffer::Array1() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jArray1);
-    AndroidBridge::HandleUncaughtException(env);
-    jbyteArray ret = static_cast<jbyteArray>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-int32_t ByteBuffer::ArrayOffset() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jArrayOffset);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jstring ByteBuffer::AsCharBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsCharBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsDoubleBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsDoubleBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsFloatBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsFloatBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsIntBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsIntBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsLongBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsLongBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsReadOnlyBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsReadOnlyBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::AsShortBuffer() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jAsShortBuffer);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Compact() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jCompact);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-int32_t ByteBuffer::CompareTo(jobject a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jCompareTo, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t ByteBuffer::CompareTo1(jobject a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jCompareTo1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jobject ByteBuffer::Duplicate() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jDuplicate);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-bool ByteBuffer::Equals(jobject a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    bool temp = env->CallBooleanMethod(wrapped_obj, jEquals, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int8_t ByteBuffer::Get() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int8_t temp = env->CallByteMethod(wrapped_obj, jGet);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int8_t ByteBuffer::Get1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int8_t temp = env->CallByteMethod(wrapped_obj, jGet1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jobject ByteBuffer::Get1(jbyteArray a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jGet10, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Get1(jbyteArray a0, int32_t a1, int32_t a2) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[3];
-    args[0].l = a0;
-    args[1].i = a1;
-    args[2].i = a2;
-
-    jobject temp = env->CallObjectMethodA(wrapped_obj, jGet11, args);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-uint16_t ByteBuffer::GetChar() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    uint16_t temp = env->CallCharMethod(wrapped_obj, jGetChar);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-uint16_t ByteBuffer::GetChar1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    uint16_t temp = env->CallCharMethod(wrapped_obj, jGetChar1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jdouble ByteBuffer::GetDouble() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jdouble temp = env->CallDoubleMethod(wrapped_obj, jGetDouble);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jdouble ByteBuffer::GetDouble1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jdouble temp = env->CallDoubleMethod(wrapped_obj, jGetDouble1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jfloat ByteBuffer::GetFloat() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jfloat temp = env->CallFloatMethod(wrapped_obj, jGetFloat);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jfloat ByteBuffer::GetFloat1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jfloat temp = env->CallFloatMethod(wrapped_obj, jGetFloat1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t ByteBuffer::GetInt() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jGetInt);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t ByteBuffer::GetInt1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jGetInt1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int64_t ByteBuffer::GetLong() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int64_t temp = env->CallLongMethod(wrapped_obj, jGetLong);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int64_t ByteBuffer::GetLong1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int64_t temp = env->CallLongMethod(wrapped_obj, jGetLong1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int16_t ByteBuffer::GetShort() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int16_t temp = env->CallShortMethod(wrapped_obj, jGetShort);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int16_t ByteBuffer::GetShort1(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int16_t temp = env->CallShortMethod(wrapped_obj, jGetShort1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-bool ByteBuffer::HasArray() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    bool temp = env->CallBooleanMethod(wrapped_obj, jHasArray);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-int32_t ByteBuffer::HashCode() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    int32_t temp = env->CallIntMethod(wrapped_obj, jHashCode);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-bool ByteBuffer::IsDirect() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    bool temp = env->CallBooleanMethod(wrapped_obj, jIsDirect);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-    return temp;
-}
-
-jobject ByteBuffer::Order() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jOrder);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Order1(jobject a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jOrder1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Put(int8_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPut, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Put1(int32_t a0, int8_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPut1, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Put1(jobject a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPut12, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Put1(jbyteArray a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPut13, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Put1(jbyteArray a0, int32_t a1, int32_t a2) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[3];
-    args[0].l = a0;
-    args[1].i = a1;
-    args[2].i = a2;
-
-    jobject temp = env->CallObjectMethodA(wrapped_obj, jPut14, args);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutChar(uint16_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutChar, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutChar1(int32_t a0, uint16_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutChar1, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutDouble(jdouble a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutDouble, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutDouble1(int32_t a0, jdouble a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutDouble1, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutFloat(jfloat a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutFloat, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutFloat1(int32_t a0, jfloat a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutFloat1, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutInt(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutInt, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutInt1(int32_t a0, int32_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutInt1, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutLong(int32_t a0, int64_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutLong, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutLong1(int64_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutLong1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutShort(int32_t a0, int16_t a1) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutShort, a0, a1);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::PutShort1(int16_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jPutShort1, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Slice() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jSlice);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jstring ByteBuffer::ToString() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(1) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallObjectMethod(wrapped_obj, jToString);
-    AndroidBridge::HandleUncaughtException(env);
-    jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Wrap1(jbyteArray a0) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jobject temp = env->CallStaticObjectMethod(mByteBufferClass, jWrap, a0);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-jobject ByteBuffer::Wrap2(jbyteArray a0, int32_t a1, int32_t a2) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(2) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[3];
-    args[0].l = a0;
-    args[1].i = a1;
-    args[2].i = a2;
-
-    jobject temp = env->CallStaticObjectMethodA(mByteBufferClass, jWrap1, args);
-    AndroidBridge::HandleUncaughtException(env);
-    jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
-    return ret;
-}
-
-bool ByteBuffer::getBigEndian() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetBooleanField(wrapped_obj, jBigEndian);
-}
-
-void ByteBuffer::setBigEndian(bool a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetBooleanField(wrapped_obj, jBigEndian, a0);
-}
-
-jbyteArray ByteBuffer::getHb() {
-    JNIEnv *env = GetJNIForThread();
-    return static_cast<jbyteArray>(env->GetObjectField(wrapped_obj, jHb));
-}
-
-bool ByteBuffer::getIsReadOnly() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetBooleanField(wrapped_obj, jIsReadOnly);
-}
-
-void ByteBuffer::setIsReadOnly(bool a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetBooleanField(wrapped_obj, jIsReadOnly, a0);
-}
-
-bool ByteBuffer::getNativeByteOrder() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetBooleanField(wrapped_obj, jNativeByteOrder);
-}
-
-void ByteBuffer::setNativeByteOrder(bool a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetBooleanField(wrapped_obj, jNativeByteOrder, a0);
-}
-
-int32_t ByteBuffer::getOffset() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetIntField(wrapped_obj, jOffset);
-}
-
-jclass BufferInfo::mBufferInfoClass = 0;
-jmethodID BufferInfo::jBufferInfo = 0;
-jmethodID BufferInfo::jSet = 0;
-jfieldID BufferInfo::jFlags = 0;
-jfieldID BufferInfo::jOffset = 0;
-jfieldID BufferInfo::jPresentationTimeUs = 0;
-jfieldID BufferInfo::jSize = 0;
-void BufferInfo::InitStubs(JNIEnv *jEnv) {
-    initInit();
-
-    mBufferInfoClass = getClassGlobalRef("android/media/MediaCodec$BufferInfo");
-    jBufferInfo = getMethod("<init>", "()V");
-    jSet = getMethod("set", "(IIJI)V");
-    jFlags = getField("flags", "I");
-    jOffset = getField("offset", "I");
-    jPresentationTimeUs = getField("presentationTimeUs", "J");
-    jSize = getField("size", "I");
-}
-
-BufferInfo* BufferInfo::Wrap(jobject obj) {
-    JNIEnv *env = GetJNIForThread();
-    BufferInfo* ret = new BufferInfo(obj, env);
-    env->DeleteLocalRef(obj);
-    return ret;
-}
-
-BufferInfo::BufferInfo() {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    Init(env->NewObject(mBufferInfoClass, jBufferInfo), env);
-    env->PopLocalFrame(nullptr);
-}
-
-void BufferInfo::Set(int32_t a0, int32_t a1, int64_t a2, int32_t a3) {
-    JNIEnv *env = GetJNIForThread();
-    if (env->PushLocalFrame(0) != 0) {
-        AndroidBridge::HandleUncaughtException(env);
-        MOZ_CRASH("Exception should have caused crash.");
-    }
-
-    jvalue args[4];
-    args[0].i = a0;
-    args[1].i = a1;
-    args[2].j = a2;
-    args[3].i = a3;
-
-    env->CallVoidMethodA(wrapped_obj, jSet, args);
-    AndroidBridge::HandleUncaughtException(env);
-    env->PopLocalFrame(nullptr);
-}
-
-int32_t BufferInfo::getFlags() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetIntField(wrapped_obj, jFlags);
-}
-
-void BufferInfo::setFlags(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetIntField(wrapped_obj, jFlags, a0);
-}
-
-int32_t BufferInfo::getOffset() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetIntField(wrapped_obj, jOffset);
-}
-
-void BufferInfo::setOffset(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetIntField(wrapped_obj, jOffset, a0);
-}
-
-int64_t BufferInfo::getPresentationTimeUs() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetLongField(wrapped_obj, jPresentationTimeUs);
-}
-
-void BufferInfo::setPresentationTimeUs(int64_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetLongField(wrapped_obj, jPresentationTimeUs, a0);
-}
-
-int32_t BufferInfo::getSize() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetIntField(wrapped_obj, jSize);
-}
-
-void BufferInfo::setSize(int32_t a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetIntField(wrapped_obj, jSize, a0);
-}
-
-void InitSDKStubs(JNIEnv *jEnv) {
-    MediaCodec::InitStubs(jEnv);
-    MediaFormat::InitStubs(jEnv);
-    ByteBuffer::InitStubs(jEnv);
-    BufferInfo::InitStubs(jEnv);
-}
-} /* android */
-} /* widget */
-} /* mozilla */
deleted file mode 100644
--- a/widget/android/GeneratedSDKWrappers.h
+++ /dev/null
@@ -1,335 +0,0 @@
-// GENERATED CODE
-
-// NOTE: This code has been doctored. The JarClassProcessor is still a work in progress,
-// and so additions and deletions have been made to make this file valid.
-
-// Generated by the Java program at /build/jarClassProcessors at compile time from
-// a given set of jars and a set of requested methods. To update, change the annotations
-// on the corresponding Java methods and rerun the build. Manually updating this file
-// will cause your build to fail.
-
-#ifndef GeneratedSDKWrappers_h__
-#define GeneratedSDKWrappers_h__
-
-#include "nsXPCOMStrings.h"
-#include "AndroidJavaWrappers.h"
-
-namespace mozilla {
-namespace widget {
-namespace android {
-
-#define MEDIACODEC_EXCEPTION_INDEX -255
-
-void InitSDKStubs(JNIEnv *jEnv);
-
-class MediaCodec : public AutoGlobalWrappedJavaObject {
-public:
-    static void InitStubs(JNIEnv *jEnv);
-    static MediaCodec* Wrap(jobject obj);
-    MediaCodec(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
-    bool Configure(jobject a0, jobject a1, jobject a2, int32_t a3);
-    static jobject CreateByCodecName(const nsAString& a0);
-    static jobject CreateDecoderByType(const nsAString& a0);
-    static jobject CreateEncoderByType(const nsAString& a0);
-    int32_t DequeueInputBuffer(int64_t a0);
-    int32_t DequeueOutputBuffer(jobject a0, int64_t a1);
-    void Finalize();
-    void Flush();
-    jobjectArray GetInputBuffers();
-    jobjectArray GetOutputBuffers();
-    jobject GetOutputFormat();
-    void QueueInputBuffer(int32_t a0, int32_t a1, int32_t a2, int64_t a3, int32_t a4);
-    void QueueSecureInputBuffer(int32_t a0, int32_t a1, jobject a2, int64_t a3, int32_t a4);
-    void Release();
-    void ReleaseOutputBuffer(int32_t a0, bool a1);
-    void SetVideoScalingMode(int32_t a0);
-    bool Start();
-    void Stop();
-    static int32_t getBUFFER_FLAG_CODEC_CONFIG();
-    static int32_t getBUFFER_FLAG_END_OF_STREAM();
-    static int32_t getBUFFER_FLAG_SYNC_FRAME();
-    static int32_t getCONFIGURE_FLAG_ENCODE();
-    static int32_t getCRYPTO_MODE_AES_CTR();
-    static int32_t getCRYPTO_MODE_UNENCRYPTED();
-    static int32_t getINFO_OUTPUT_BUFFERS_CHANGED();
-    static int32_t getINFO_OUTPUT_FORMAT_CHANGED();
-    static int32_t getINFO_TRY_AGAIN_LATER();
-    static int32_t getVIDEO_SCALING_MODE_SCALE_TO_FIT();
-    static int32_t getVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING();
-    MediaCodec() : AutoGlobalWrappedJavaObject() {};
-protected:
-    static jclass mMediaCodecClass;
-    static jmethodID jConfigure;
-    static jmethodID jCreateByCodecName;
-    static jmethodID jCreateDecoderByType;
-    static jmethodID jCreateEncoderByType;
-    static jmethodID jDequeueInputBuffer;
-    static jmethodID jDequeueOutputBuffer;
-    static jmethodID jFinalize;
-    static jmethodID jFlush;
-    static jmethodID jGetInputBuffers;
-    static jmethodID jGetOutputBuffers;
-    static jmethodID jGetOutputFormat;
-    static jmethodID jQueueInputBuffer;
-    static jmethodID jQueueSecureInputBuffer;
-    static jmethodID jRelease;
-    static jmethodID jReleaseOutputBuffer;
-    static jmethodID jSetVideoScalingMode;
-    static jmethodID jStart;
-    static jmethodID jStop;
-    static jfieldID jBUFFER_FLAG_CODEC_CONFIG;
-    static jfieldID jBUFFER_FLAG_END_OF_STREAM;
-    static jfieldID jBUFFER_FLAG_SYNC_FRAME;
-    static jfieldID jCONFIGURE_FLAG_ENCODE;
-    static jfieldID jCRYPTO_MODE_AES_CTR;
-    static jfieldID jCRYPTO_MODE_UNENCRYPTED;
-    static jfieldID jINFO_OUTPUT_BUFFERS_CHANGED;
-    static jfieldID jINFO_OUTPUT_FORMAT_CHANGED;
-    static jfieldID jINFO_TRY_AGAIN_LATER;
-    static jfieldID jVIDEO_SCALING_MODE_SCALE_TO_FIT;
-    static jfieldID jVIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING;
-};
-
-class MediaFormat : public AutoGlobalWrappedJavaObject {
-public:
-    static void InitStubs(JNIEnv *jEnv);
-    static MediaFormat* Wrap(jobject obj);
-    MediaFormat(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
-    MediaFormat();
-    bool ContainsKey(const nsAString& a0);
-    static jobject CreateAudioFormat(const nsAString& a0, int32_t a1, int32_t a2);
-    static jobject CreateVideoFormat(const nsAString& a0, int32_t a1, int32_t a2);
-    jobject GetByteBuffer(const nsAString& a0);
-    jfloat GetFloat(const nsAString& a0);
-    int32_t GetInteger(const nsAString& a0);
-    int64_t GetLong(const nsAString& a0);
-    jstring GetString(const nsAString& a0);
-    void SetByteBuffer(const nsAString& a0, jobject a1);
-    void SetFloat(const nsAString& a0, jfloat a1);
-    void SetInteger(const nsAString& a0, int32_t a1);
-    void SetLong(const nsAString& a0, int64_t a1);
-    void SetString(const nsAString& a0, const nsAString& a1);
-    jstring ToString();
-    static jstring getKEY_AAC_PROFILE();
-    static jstring getKEY_BIT_RATE();
-    static jstring getKEY_CHANNEL_COUNT();
-    static jstring getKEY_CHANNEL_MASK();
-    static jstring getKEY_COLOR_FORMAT();
-    static jstring getKEY_DURATION();
-    static jstring getKEY_FLAC_COMPRESSION_LEVEL();
-    static jstring getKEY_FRAME_RATE();
-    static jstring getKEY_HEIGHT();
-    static jstring getKEY_IS_ADTS();
-    static jstring getKEY_I_FRAME_INTERVAL();
-    static jstring getKEY_MAX_INPUT_SIZE();
-    static jstring getKEY_MIME();
-    static jstring getKEY_SAMPLE_RATE();
-    static jstring getKEY_WIDTH();
-protected:
-    static jclass mMediaFormatClass;
-    static jmethodID jMediaFormat;
-    static jmethodID jContainsKey;
-    static jmethodID jCreateAudioFormat;
-    static jmethodID jCreateVideoFormat;
-    static jmethodID jGetByteBuffer;
-    static jmethodID jGetFloat;
-    static jmethodID jGetInteger;
-    static jmethodID jGetLong;
-    static jmethodID jGetString;
-    static jmethodID jSetByteBuffer;
-    static jmethodID jSetFloat;
-    static jmethodID jSetInteger;
-    static jmethodID jSetLong;
-    static jmethodID jSetString;
-    static jmethodID jToString;
-    static jfieldID jKEY_AAC_PROFILE;
-    static jfieldID jKEY_BIT_RATE;
-    static jfieldID jKEY_CHANNEL_COUNT;
-    static jfieldID jKEY_CHANNEL_MASK;
-    static jfieldID jKEY_COLOR_FORMAT;
-    static jfieldID jKEY_DURATION;
-    static jfieldID jKEY_FLAC_COMPRESSION_LEVEL;
-    static jfieldID jKEY_FRAME_RATE;
-    static jfieldID jKEY_HEIGHT;
-    static jfieldID jKEY_IS_ADTS;
-    static jfieldID jKEY_I_FRAME_INTERVAL;
-    static jfieldID jKEY_MAX_INPUT_SIZE;
-    static jfieldID jKEY_MIME;
-    static jfieldID jKEY_SAMPLE_RATE;
-    static jfieldID jKEY_WIDTH;
-};
-
-class ByteBuffer : public AutoGlobalWrappedJavaObject {
-public:
-    static void InitStubs(JNIEnv *jEnv);
-    static ByteBuffer* Wrap(jobject obj);
-    ByteBuffer(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
-    int8_t _get(int32_t a0);
-    void _put(int32_t a0, int8_t a1);
-    static jobject Allocate(int32_t a0);
-    static jobject AllocateDirect(int32_t a0);
-    jobject Array();
-    jbyteArray Array1();
-    int32_t ArrayOffset();
-    jstring AsCharBuffer();
-    jobject AsDoubleBuffer();
-    jobject AsFloatBuffer();
-    jobject AsIntBuffer();
-    jobject AsLongBuffer();
-    jobject AsReadOnlyBuffer();
-    jobject AsShortBuffer();
-    jobject Compact();
-    int32_t CompareTo(jobject a0);
-    int32_t CompareTo1(jobject a0);
-    jobject Duplicate();
-    bool Equals(jobject a0);
-    int8_t Get();
-    int8_t Get1(int32_t a0);
-    jobject Get1(jbyteArray a0);
-    jobject Get1(jbyteArray a0, int32_t a1, int32_t a2);
-    uint16_t GetChar();
-    uint16_t GetChar1(int32_t a0);
-    jdouble GetDouble();
-    jdouble GetDouble1(int32_t a0);
-    jfloat GetFloat();
-    jfloat GetFloat1(int32_t a0);
-    int32_t GetInt();
-    int32_t GetInt1(int32_t a0);
-    int64_t GetLong();
-    int64_t GetLong1(int32_t a0);
-    int16_t GetShort();
-    int16_t GetShort1(int32_t a0);
-    bool HasArray();
-    int32_t HashCode();
-    bool IsDirect();
-    jobject Order();
-    jobject Order1(jobject a0);
-    jobject Put(int8_t a0);
-    jobject Put1(int32_t a0, int8_t a1);
-    jobject Put1(jobject a0);
-    jobject Put1(jbyteArray a0);
-    jobject Put1(jbyteArray a0, int32_t a1, int32_t a2);
-    jobject PutChar(uint16_t a0);
-    jobject PutChar1(int32_t a0, uint16_t a1);
-    jobject PutDouble(jdouble a0);
-    jobject PutDouble1(int32_t a0, jdouble a1);
-    jobject PutFloat(jfloat a0);
-    jobject PutFloat1(int32_t a0, jfloat a1);
-    jobject PutInt(int32_t a0);
-    jobject PutInt1(int32_t a0, int32_t a1);
-    jobject PutLong(int32_t a0, int64_t a1);
-    jobject PutLong1(int64_t a0);
-    jobject PutShort(int32_t a0, int16_t a1);
-    jobject PutShort1(int16_t a0);
-    jobject Slice();
-    jstring ToString();
-    static jobject Wrap1(jbyteArray a0);
-    static jobject Wrap2(jbyteArray a0, int32_t a1, int32_t a2);
-    bool getBigEndian();
-    void setBigEndian(bool a0);
-    jbyteArray getHb();
-    bool getIsReadOnly();
-    void setIsReadOnly(bool a0);
-    bool getNativeByteOrder();
-    void setNativeByteOrder(bool a0);
-    int32_t getOffset();
-    ByteBuffer() : AutoGlobalWrappedJavaObject() {};
-protected:
-    static jclass mByteBufferClass;
-    static jmethodID j_get;
-    static jmethodID j_put;
-    static jmethodID jAllocate;
-    static jmethodID jAllocateDirect;
-    static jmethodID jArray;
-    static jmethodID jArray1;
-    static jmethodID jArrayOffset;
-    static jmethodID jAsCharBuffer;
-    static jmethodID jAsDoubleBuffer;
-    static jmethodID jAsFloatBuffer;
-    static jmethodID jAsIntBuffer;
-    static jmethodID jAsLongBuffer;
-    static jmethodID jAsReadOnlyBuffer;
-    static jmethodID jAsShortBuffer;
-    static jmethodID jCompact;
-    static jmethodID jCompareTo;
-    static jmethodID jCompareTo1;
-    static jmethodID jDuplicate;
-    static jmethodID jEquals;
-    static jmethodID jGet;
-    static jmethodID jGet1;
-    static jmethodID jGet10;
-    static jmethodID jGet11;
-    static jmethodID jGetChar;
-    static jmethodID jGetChar1;
-    static jmethodID jGetDouble;
-    static jmethodID jGetDouble1;
-    static jmethodID jGetFloat;
-    static jmethodID jGetFloat1;
-    static jmethodID jGetInt;
-    static jmethodID jGetInt1;
-    static jmethodID jGetLong;
-    static jmethodID jGetLong1;
-    static jmethodID jGetShort;
-    static jmethodID jGetShort1;
-    static jmethodID jHasArray;
-    static jmethodID jHashCode;
-    static jmethodID jIsDirect;
-    static jmethodID jOrder;
-    static jmethodID jOrder1;
-    static jmethodID jPut;
-    static jmethodID jPut1;
-    static jmethodID jPut12;
-    static jmethodID jPut13;
-    static jmethodID jPut14;
-    static jmethodID jPutChar;
-    static jmethodID jPutChar1;
-    static jmethodID jPutDouble;
-    static jmethodID jPutDouble1;
-    static jmethodID jPutFloat;
-    static jmethodID jPutFloat1;
-    static jmethodID jPutInt;
-    static jmethodID jPutInt1;
-    static jmethodID jPutLong;
-    static jmethodID jPutLong1;
-    static jmethodID jPutShort;
-    static jmethodID jPutShort1;
-    static jmethodID jSlice;
-    static jmethodID jToString;
-    static jmethodID jWrap;
-    static jmethodID jWrap1;
-    static jfieldID jBigEndian;
-    static jfieldID jHb;
-    static jfieldID jIsReadOnly;
-    static jfieldID jNativeByteOrder;
-    static jfieldID jOffset;
-};
-
-class BufferInfo : public AutoGlobalWrappedJavaObject {
-public:
-    static void InitStubs(JNIEnv *jEnv);
-    static BufferInfo* Wrap(jobject obj);
-    BufferInfo(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
-    BufferInfo();
-    void Set(int32_t a0, int32_t a1, int64_t a2, int32_t a3);
-    int32_t getFlags();
-    void setFlags(int32_t a0);
-    int32_t getOffset();
-    void setOffset(int32_t a0);
-    int64_t getPresentationTimeUs();
-    void setPresentationTimeUs(int64_t a0);
-    int32_t getSize();
-    void setSize(int32_t a0);
-protected:
-    static jclass mBufferInfoClass;
-    static jmethodID jBufferInfo;
-    static jmethodID jSet;
-    static jfieldID jFlags;
-    static jfieldID jOffset;
-    static jfieldID jPresentationTimeUs;
-    static jfieldID jSize;
-};
-
-} /* android */
-} /* widget */
-} /* mozilla */
-#endif
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -10,29 +10,27 @@ XPIDL_SOURCES += [
 
 XPIDL_MODULE = 'widget_android'
 
 EXPORTS += [
     'AndroidBridge.h',
     'AndroidJavaWrappers.h',
     'AndroidJNIWrapper.h',
     'GeneratedJNIWrappers.h',
-    'GeneratedSDKWrappers.h',
 ]
 
 SOURCES += [
     'AndroidBridge.cpp',
     'AndroidDirectTexture.cpp',
     'AndroidGraphicBuffer.cpp',
     'AndroidJavaWrappers.cpp',
     'AndroidJNI.cpp',
     'AndroidJNIWrapper.cpp',
     'APZCCallbackHandler.cpp',
     'GeneratedJNIWrappers.cpp',
-    'GeneratedSDKWrappers.cpp',
     'GfxInfo.cpp',
     'NativeJSContainer.cpp',
     'nsAndroidProtocolHandler.cpp',
     'nsAppShell.cpp',
     'nsClipboard.cpp',
     'nsDeviceContextAndroid.cpp',
     'nsIdleServiceAndroid.cpp',
     'nsIMEPicker.cpp',