Bug 1538969 - Report an opaque surface format for AndroidSurfaceTextureData when it's being used for an opaque video. r=jya
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 10 Apr 2019 08:08:22 +0000
changeset 468732 4c8055acb67b68829fa037cc2127812d0f9b41a1
parent 468731 1d58cd8e6457bae9de68d0470cf5236479ea7b2c
child 468733 3f2ce3a4c4e695b26a2f351a728edb6d33e562e9
push id35850
push userdvarga@mozilla.com
push dateWed, 10 Apr 2019 21:52:56 +0000
treeherdermozilla-central@9d3dbe3fef26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1538969
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1538969 - Report an opaque surface format for AndroidSurfaceTextureData when it's being used for an opaque video. r=jya Differential Revision: https://phabricator.services.mozilla.com/D25185
dom/media/platforms/android/RemoteDataDecoder.cpp
gfx/layers/GLImages.cpp
gfx/layers/GLImages.h
gfx/layers/client/ImageClient.cpp
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -277,17 +277,17 @@ class RemoteVideoDecoder : public Remote
     if (!ok && !isEOS) {
       // Ignore output with no corresponding input.
       return;
     }
 
     if (ok && (size > 0 || presentationTimeUs >= 0)) {
       RefPtr<layers::Image> img = new SurfaceTextureImage(
           mSurfaceHandle, inputInfo.mImageSize, false /* NOT continuous */,
-          gl::OriginPos::BottomLeft);
+          gl::OriginPos::BottomLeft, mConfig.HasAlpha());
 
       RefPtr<VideoData> v = VideoData::CreateFromImage(
           inputInfo.mDisplaySize, offset,
           TimeUnit::FromMicroseconds(presentationTimeUs),
           TimeUnit::FromMicroseconds(inputInfo.mDurationUs), img,
           !!(flags & MediaCodec::BUFFER_FLAG_SYNC_FRAME),
           TimeUnit::FromMicroseconds(presentationTimeUs));
 
--- a/gfx/layers/GLImages.cpp
+++ b/gfx/layers/GLImages.cpp
@@ -70,20 +70,22 @@ already_AddRefed<gfx::SourceSurface> GLI
   ReadPixelsIntoDataSurface(sSnapshotContext, source);
   return source.forget();
 }
 
 #ifdef MOZ_WIDGET_ANDROID
 SurfaceTextureImage::SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
                                          const gfx::IntSize& aSize,
                                          bool aContinuous,
-                                         gl::OriginPos aOriginPos)
+                                         gl::OriginPos aOriginPos,
+                                         bool aHasAlpha /* = true */)
     : GLImage(ImageFormat::SURFACE_TEXTURE),
       mHandle(aHandle),
       mSize(aSize),
       mContinuous(aContinuous),
-      mOriginPos(aOriginPos) {
+      mOriginPos(aOriginPos),
+      mHasAlpha(aHasAlpha) {
   MOZ_ASSERT(mHandle);
 }
 #endif
 
 }  // namespace layers
 }  // namespace mozilla
--- a/gfx/layers/GLImages.h
+++ b/gfx/layers/GLImages.h
@@ -28,37 +28,39 @@ class GLImage : public Image {
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureImage : public GLImage {
  public:
   SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
                       const gfx::IntSize& aSize, bool aContinuous,
-                      gl::OriginPos aOriginPos);
+                      gl::OriginPos aOriginPos, bool aHasAlpha = true);
 
   gfx::IntSize GetSize() const override { return mSize; }
   AndroidSurfaceTextureHandle GetHandle() const { return mHandle; }
   bool GetContinuous() const { return mContinuous; }
   gl::OriginPos GetOriginPos() const { return mOriginPos; }
+  bool GetHasAlpha() const { return mHasAlpha; }
 
   already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
     // We can implement this, but currently don't want to because it will cause
     // the SurfaceTexture to be permanently bound to the snapshot readback
     // context.
     return nullptr;
   }
 
   SurfaceTextureImage* AsSurfaceTextureImage() override { return this; }
 
  private:
   AndroidSurfaceTextureHandle mHandle;
   gfx::IntSize mSize;
   bool mContinuous;
   gl::OriginPos mOriginPos;
+  const bool mHasAlpha;
 };
 
 #endif  // MOZ_WIDGET_ANDROID
 
 }  // namespace layers
 }  // namespace mozilla
 
 #endif  // GFX_GLIMAGES_H
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -118,18 +118,18 @@ already_AddRefed<TextureClient> ImageCli
       return nullptr;
     }
 #ifdef MOZ_WIDGET_ANDROID
   } else if (aImage->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
     gfx::IntSize size = aImage->GetSize();
     SurfaceTextureImage* typedImage = aImage->AsSurfaceTextureImage();
     texture = AndroidSurfaceTextureData::CreateTextureClient(
         typedImage->GetHandle(), size, typedImage->GetContinuous(),
-        typedImage->GetOriginPos(), aForwarder->GetTextureForwarder(),
-        TextureFlags::DEFAULT);
+        typedImage->GetOriginPos(), typedImage->GetHasAlpha(),
+        aForwarder->GetTextureForwarder(), TextureFlags::DEFAULT);
 #endif
   } else {
     RefPtr<gfx::SourceSurface> surface = aImage->GetAsSourceSurface();
     MOZ_ASSERT(surface);
     texture = TextureClient::CreateForDrawing(
         aForwarder, surface->GetFormat(), aImage->GetSize(),
         BackendSelector::Content, TextureFlags::DEFAULT);
     if (!texture) {
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -27,48 +27,53 @@ class CompositableForwarder;
 
 ////////////////////////////////////////////////////////////////////////
 // AndroidSurface
 
 #ifdef MOZ_WIDGET_ANDROID
 
 already_AddRefed<TextureClient> AndroidSurfaceTextureData::CreateTextureClient(
     AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous,
-    gl::OriginPos aOriginPos, LayersIPCChannel* aAllocator,
+    gl::OriginPos aOriginPos, bool aHasAlpha, LayersIPCChannel* aAllocator,
     TextureFlags aFlags) {
   if (aOriginPos == gl::OriginPos::BottomLeft) {
     aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
   }
 
   return TextureClient::CreateWithData(
-      new AndroidSurfaceTextureData(aHandle, aSize, aContinuous), aFlags,
-      aAllocator);
+      new AndroidSurfaceTextureData(aHandle, aSize, aContinuous, aHasAlpha),
+      aFlags, aAllocator);
 }
 
 AndroidSurfaceTextureData::AndroidSurfaceTextureData(
-    AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous)
-    : mHandle(aHandle), mSize(aSize), mContinuous(aContinuous) {
+    AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous,
+    bool aHasAlpha)
+    : mHandle(aHandle),
+      mSize(aSize),
+      mContinuous(aContinuous),
+      mHasAlpha(aHasAlpha) {
   MOZ_ASSERT(mHandle);
 }
 
 AndroidSurfaceTextureData::~AndroidSurfaceTextureData() {}
 
 void AndroidSurfaceTextureData::FillInfo(TextureData::Info& aInfo) const {
   aInfo.size = mSize;
   aInfo.format = gfx::SurfaceFormat::UNKNOWN;
   aInfo.hasIntermediateBuffer = false;
   aInfo.hasSynchronization = false;
   aInfo.supportsMoz2D = false;
   aInfo.canExposeMappedData = false;
 }
 
 bool AndroidSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
   aOutDescriptor = SurfaceTextureDescriptor(
-      mHandle, mSize, gfx::SurfaceFormat::R8G8B8A8, mContinuous,
-      false /* do not ignore transform */);
+      mHandle, mSize,
+      mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::R8G8B8X8,
+      mContinuous, false /* do not ignore transform */);
   return true;
 }
 
 #endif  // MOZ_WIDGET_ANDROID
 
 ////////////////////////////////////////////////////////////////////////
 // AndroidNativeWindow
 
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -33,17 +33,17 @@ class DrawTarget;
 namespace layers {
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class AndroidSurfaceTextureData : public TextureData {
  public:
   static already_AddRefed<TextureClient> CreateTextureClient(
       AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous,
-      gl::OriginPos aOriginPos, LayersIPCChannel* aAllocator,
+      gl::OriginPos aOriginPos, bool aHasAlpha, LayersIPCChannel* aAllocator,
       TextureFlags aFlags);
 
   ~AndroidSurfaceTextureData();
 
   virtual void FillInfo(TextureData::Info& aInfo) const override;
 
   virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
 
@@ -52,21 +52,23 @@ class AndroidSurfaceTextureData : public
 
   virtual void Unlock() override {}
 
   // Our data is always owned externally.
   virtual void Deallocate(LayersIPCChannel*) override {}
 
  protected:
   AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle,
-                            gfx::IntSize aSize, bool aContinuous);
+                            gfx::IntSize aSize, bool aContinuous,
+                            bool aHasAlpha);
 
   const AndroidSurfaceTextureHandle mHandle;
   const gfx::IntSize mSize;
   const bool mContinuous;
+  const bool mHasAlpha;
 };
 
 class AndroidNativeWindowTextureData : public TextureData {
  public:
   static AndroidNativeWindowTextureData* Create(gfx::IntSize aSize,
                                                 gfx::SurfaceFormat aFormat);
 
   virtual void FillInfo(TextureData::Info& aInfo) const override;