Bug 1230784 - Don't copy SurfaceTexture contents when presenting video on Android r=esawin,jya a=ritu
authorJames Willcox <snorp@snorp.net>
Fri, 18 Dec 2015 10:38:40 -0600
changeset 292518 27eda69e75d7aee3b75474fb31b9826c8cb0711e
parent 292517 42b73d5771582b413baaf18ddd71e364fbcbde35
child 292519 ce5d62493589750116c6360dc2b7823550b74b32
push id254
push usercbook@mozilla.com
push dateWed, 13 Jan 2016 11:04:22 +0000
reviewersesawin, jya, ritu
bugs1230784
milestone44.0
Bug 1230784 - Don't copy SurfaceTexture contents when presenting video on Android r=esawin,jya a=ritu
dom/media/platforms/android/AndroidDecoderModule.cpp
--- a/dom/media/platforms/android/AndroidDecoderModule.cpp
+++ b/dom/media/platforms/android/AndroidDecoderModule.cpp
@@ -80,99 +80,31 @@ public:
   void Cleanup() override {
     mGLContext = nullptr;
   }
 
   nsresult Input(MediaRawData* aSample) override {
     return MediaCodecDataDecoder::Input(aSample);
   }
 
-  bool WantCopy() {
-    // Allocating a texture is incredibly slow on PowerVR and may fail on
-    // emulators, see bug 1190379.
-    return mGLContext->Vendor() != GLVendor::Imagination &&
-           mGLContext->Renderer() != GLRenderer::AndroidEmulator;
-  }
-
-  EGLImage CopySurface(layers::Image* img) {
-    mGLContext->MakeCurrent();
-
-    GLuint tex = CreateTextureForOffscreen(mGLContext, mGLContext->GetGLFormats(),
-                                           img->GetSize());
-
-    auto helper = mGLContext->BlitHelper();
-    const gl::OriginPos destOrigin = gl::OriginPos::TopLeft;
-    if (!helper->BlitImageToTexture(img, img->GetSize(), tex, LOCAL_GL_TEXTURE_2D,
-                                    destOrigin))
-    {
-      mGLContext->fDeleteTextures(1, &tex);
-      return nullptr;
-    }
-
-    EGLint attribs[] = {
-      LOCAL_EGL_IMAGE_PRESERVED_KHR, LOCAL_EGL_TRUE,
-      LOCAL_EGL_NONE, LOCAL_EGL_NONE
-    };
-
-    EGLContext eglContext = static_cast<GLContextEGL*>(mGLContext.get())->mContext;
-    EGLImage eglImage = sEGLLibrary.fCreateImage(EGL_DISPLAY(), eglContext,
-                                                 LOCAL_EGL_GL_TEXTURE_2D_KHR,
-                                                 (EGLClientBuffer)tex, attribs);
-    mGLContext->fDeleteTextures(1, &tex);
-
-    return eglImage;
-  }
-
   nsresult PostOutput(BufferInfo::Param aInfo, MediaFormat::Param aFormat,
                       const media::TimeUnit& aDuration) override {
     if (!EnsureGLContext()) {
       return NS_ERROR_FAILURE;
     }
 
     RefPtr<layers::Image> img = mImageContainer->CreateImage(ImageFormat::SURFACE_TEXTURE);
     layers::SurfaceTextureImage::Data data;
     data.mSurfTex = mSurfaceTexture.get();
     data.mSize = mConfig.mDisplay;
     data.mOriginPos = gl::OriginPos::BottomLeft;
 
     layers::SurfaceTextureImage* stImg = static_cast<layers::SurfaceTextureImage*>(img.get());
     stImg->SetData(data);
 
-    if (WantCopy()) {
-      EGLImage eglImage = CopySurface(img);
-      if (!eglImage) {
-        return NS_ERROR_FAILURE;
-      }
-
-      EGLSync eglSync = nullptr;
-      if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync) &&
-          mGLContext->IsExtensionSupported(GLContext::OES_EGL_sync))
-      {
-        MOZ_ASSERT(mGLContext->IsCurrent());
-        eglSync = sEGLLibrary.fCreateSync(EGL_DISPLAY(),
-                                          LOCAL_EGL_SYNC_FENCE,
-                                          nullptr);
-        MOZ_ASSERT(eglSync);
-        mGLContext->fFlush();
-      } else {
-        NS_WARNING("No EGL fence support detected, rendering artifacts may occur!");
-      }
-
-      img = mImageContainer->CreateImage(ImageFormat::EGLIMAGE);
-      layers::EGLImageImage::Data data;
-      data.mImage = eglImage;
-      data.mSync = eglSync;
-      data.mOwns = true;
-      data.mSize = mConfig.mDisplay;
-      data.mOriginPos = gl::OriginPos::TopLeft;
-
-      layers::EGLImageImage* typedImg = static_cast<layers::EGLImageImage*>(img.get());
-      typedImg->SetData(data);
-    }
-
     nsresult rv;
     int32_t flags;
     NS_ENSURE_SUCCESS(rv = aInfo->Flags(&flags), rv);
 
     bool isSync = !!(flags & MediaCodec::BUFFER_FLAG_SYNC_FRAME);
 
     int32_t offset;
     NS_ENSURE_SUCCESS(rv = aInfo->Offset(&offset), rv);