diff --git a/dom/media/gtest/TestVideoTrackEncoder.cpp b/dom/media/gtest/TestVideoTrackEncoder.cpp index 6ed928f71b85..b5c258a85012 100644 --- a/dom/media/gtest/TestVideoTrackEncoder.cpp +++ b/dom/media/gtest/TestVideoTrackEncoder.cpp @@ -55,7 +55,7 @@ public: private: Image *CreateI420Image() { - PlanarYCbCrImage *image = new PlanarYCbCrImage(new BufferRecycleBin()); + PlanarYCbCrImage *image = new RecyclingPlanarYCbCrImage(new BufferRecycleBin()); PlanarYCbCrData data; data.mPicSize = mImageSize; @@ -93,7 +93,7 @@ private: Image *CreateNV12Image() { - PlanarYCbCrImage *image = new PlanarYCbCrImage(new BufferRecycleBin()); + PlanarYCbCrImage *image = new RecyclingPlanarYCbCrImage(new BufferRecycleBin()); PlanarYCbCrData data; data.mPicSize = mImageSize; @@ -130,7 +130,7 @@ private: Image *CreateNV21Image() { - PlanarYCbCrImage *image = new PlanarYCbCrImage(new BufferRecycleBin()); + PlanarYCbCrImage *image = new RecyclingPlanarYCbCrImage(new BufferRecycleBin()); PlanarYCbCrData data; data.mPicSize = mImageSize; diff --git a/gfx/layers/GrallocImages.cpp b/gfx/layers/GrallocImages.cpp index b4c674e86aab..e3427001cdcf 100644 --- a/gfx/layers/GrallocImages.cpp +++ b/gfx/layers/GrallocImages.cpp @@ -48,7 +48,7 @@ struct GraphicBufferAutoUnlock { }; GrallocImage::GrallocImage() - : PlanarYCbCrImage(nullptr) + : RecyclingPlanarYCbCrImage(nullptr) { mFormat = ImageFormat::GRALLOC_PLANAR_YCBCR; } diff --git a/gfx/layers/GrallocImages.h b/gfx/layers/GrallocImages.h index 606944ada3aa..b7fe4575435b 100644 --- a/gfx/layers/GrallocImages.h +++ b/gfx/layers/GrallocImages.h @@ -48,7 +48,7 @@ GetDataSourceSurfaceFrom(android::sp& aGraphicBuffer, * mPicX, mPicY and mPicSize. The size of the rendered image is * mPicSize, not mYSize or mCbCrSize. */ -class GrallocImage : public PlanarYCbCrImage +class GrallocImage : public RecyclingPlanarYCbCrImage { typedef PlanarYCbCrData Data; static int32_t sColorIdMap[]; diff --git a/gfx/layers/IMFYCbCrImage.cpp b/gfx/layers/IMFYCbCrImage.cpp index 26ab68795f55..129899063127 100644 --- a/gfx/layers/IMFYCbCrImage.cpp +++ b/gfx/layers/IMFYCbCrImage.cpp @@ -15,7 +15,7 @@ namespace mozilla { namespace layers { IMFYCbCrImage::IMFYCbCrImage(IMFMediaBuffer* aBuffer, IMF2DBuffer* a2DBuffer) - : PlanarYCbCrImage(nullptr) + : RecyclingPlanarYCbCrImage(nullptr) , mBuffer(aBuffer) , m2DBuffer(a2DBuffer) {} diff --git a/gfx/layers/IMFYCbCrImage.h b/gfx/layers/IMFYCbCrImage.h index d2ba5ec5bbca..35ee1571d90d 100644 --- a/gfx/layers/IMFYCbCrImage.h +++ b/gfx/layers/IMFYCbCrImage.h @@ -13,7 +13,7 @@ namespace mozilla { namespace layers { -class IMFYCbCrImage : public PlanarYCbCrImage +class IMFYCbCrImage : public RecyclingPlanarYCbCrImage { public: IMFYCbCrImage(IMFMediaBuffer* aBuffer, IMF2DBuffer* a2DBuffer); @@ -23,10 +23,6 @@ public: virtual TextureClient* GetTextureClient(CompositableClient* aClient) override; protected: - virtual uint8_t* AllocateBuffer(uint32_t aSize) override { - MOZ_CRASH("Can't do manual allocations with IMFYCbCrImage"); - return nullptr; - } TextureClient* GetD3D9TextureClient(CompositableClient* aClient); diff --git a/gfx/layers/ImageContainer.cpp b/gfx/layers/ImageContainer.cpp index 667a49a100d4..b0e16d25c1c8 100644 --- a/gfx/layers/ImageContainer.cpp +++ b/gfx/layers/ImageContainer.cpp @@ -74,7 +74,7 @@ ImageFactory::CreateImage(ImageFormat aFormat, } #endif if (aFormat == ImageFormat::PLANAR_YCBCR) { - img = new PlanarYCbCrImage(aRecycleBin); + img = new RecyclingPlanarYCbCrImage(aRecycleBin); return img.forget(); } if (aFormat == ImageFormat::CAIRO_SURFACE) { @@ -420,15 +420,14 @@ ImageContainer::NotifyCompositeInternal(const ImageCompositeNotification& aNotif } } -PlanarYCbCrImage::PlanarYCbCrImage(BufferRecycleBin *aRecycleBin) +PlanarYCbCrImage::PlanarYCbCrImage() : Image(nullptr, ImageFormat::PLANAR_YCBCR) - , mBufferSize(0) , mOffscreenFormat(gfxImageFormat::Unknown) - , mRecycleBin(aRecycleBin) + , mBufferSize(0) { } -PlanarYCbCrImage::~PlanarYCbCrImage() +RecyclingPlanarYCbCrImage::~RecyclingPlanarYCbCrImage() { if (mBuffer) { mRecycleBin->RecycleBuffer(mBuffer.forget(), mBufferSize); @@ -436,7 +435,7 @@ PlanarYCbCrImage::~PlanarYCbCrImage() } size_t -PlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const +RecyclingPlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { // Ignoring: // - mData - just wraps mBuffer @@ -455,7 +454,7 @@ PlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const } uint8_t* -PlanarYCbCrImage::AllocateBuffer(uint32_t aSize) +RecyclingPlanarYCbCrImage::AllocateBuffer(uint32_t aSize) { return mRecycleBin->GetBuffer(aSize); } @@ -485,7 +484,7 @@ CopyPlane(uint8_t *aDst, const uint8_t *aSrc, } bool -PlanarYCbCrImage::CopyData(const Data& aData) +RecyclingPlanarYCbCrImage::CopyData(const Data& aData) { mData = aData; @@ -517,7 +516,7 @@ PlanarYCbCrImage::CopyData(const Data& aData) } bool -PlanarYCbCrImage::SetData(const Data &aData) +RecyclingPlanarYCbCrImage::SetData(const Data &aData) { return CopyData(aData); } @@ -539,7 +538,7 @@ PlanarYCbCrImage::SetDataNoCopy(const Data &aData) } uint8_t* -PlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize) +RecyclingPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize) { // get new buffer mBuffer = AllocateBuffer(aSize); diff --git a/gfx/layers/ImageContainer.h b/gfx/layers/ImageContainer.h index d61a87e004f7..debf82f6e553 100644 --- a/gfx/layers/ImageContainer.h +++ b/gfx/layers/ImageContainer.h @@ -650,13 +650,13 @@ public: MAX_DIMENSION = 16384 }; - virtual ~PlanarYCbCrImage(); + virtual ~PlanarYCbCrImage() {} /** * This makes a copy of the data buffers, in order to support functioning * in all different layer managers. */ - virtual bool SetData(const Data& aData); + virtual bool SetData(const Data& aData) = 0; /** * This doesn't make a copy of the data buffers. Can be used when mBuffer is @@ -670,7 +670,7 @@ public: /** * This allocates and returns a new buffer */ - virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize); + virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize) = 0; /** * Ask this Image to not convert YUV to RGB during SetData, and make @@ -693,7 +693,7 @@ public: virtual gfx::IntSize GetSize() { return mSize; } - explicit PlanarYCbCrImage(BufferRecycleBin *aRecycleBin); + explicit PlanarYCbCrImage(); virtual SharedPlanarYCbCrImage *AsSharedPlanarYCbCrImage() { return nullptr; } @@ -701,8 +701,28 @@ public: return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); } - virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; + virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const = 0; +protected: + already_AddRefed GetAsSourceSurface(); + + void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; } + gfxImageFormat GetOffscreenFormat(); + + Data mData; + gfx::IntSize mSize; + gfxImageFormat mOffscreenFormat; + nsCountedRef mSourceSurface; + uint32_t mBufferSize; +}; + +class RecyclingPlanarYCbCrImage: public PlanarYCbCrImage { +public: + explicit RecyclingPlanarYCbCrImage(BufferRecycleBin *aRecycleBin) : mRecycleBin(aRecycleBin) {} + virtual ~RecyclingPlanarYCbCrImage() override; + virtual bool SetData(const Data& aData) override; + virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize) override; + virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; protected: /** * Make a copy of the YCbCr data into local storage. @@ -716,20 +736,10 @@ protected: * The default implementation returns memory that can * be freed wit delete[] */ - virtual uint8_t* AllocateBuffer(uint32_t aSize); + uint8_t* AllocateBuffer(uint32_t aSize); - already_AddRefed GetAsSourceSurface(); - - void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; } - gfxImageFormat GetOffscreenFormat(); - - nsAutoArrayPtr mBuffer; - uint32_t mBufferSize; - Data mData; - gfx::IntSize mSize; - gfxImageFormat mOffscreenFormat; - nsCountedRef mSourceSurface; RefPtr mRecycleBin; + nsAutoArrayPtr mBuffer; }; /** diff --git a/gfx/layers/basic/BasicImages.cpp b/gfx/layers/basic/BasicImages.cpp index 4bd232bac92c..d8547a3c357c 100644 --- a/gfx/layers/basic/BasicImages.cpp +++ b/gfx/layers/basic/BasicImages.cpp @@ -28,11 +28,11 @@ namespace mozilla { namespace layers { -class BasicPlanarYCbCrImage : public PlanarYCbCrImage +class BasicPlanarYCbCrImage : public RecyclingPlanarYCbCrImage { public: BasicPlanarYCbCrImage(const gfx::IntSize& aScaleHint, gfxImageFormat aOffscreenFormat, BufferRecycleBin *aRecycleBin) - : PlanarYCbCrImage(aRecycleBin) + : RecyclingPlanarYCbCrImage(aRecycleBin) , mScaleHint(aScaleHint) , mDelayedConversion(false) { @@ -60,7 +60,7 @@ public: virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override { - size_t size = PlanarYCbCrImage::SizeOfExcludingThis(aMallocSizeOf); + size_t size = RecyclingPlanarYCbCrImage::SizeOfExcludingThis(aMallocSizeOf); size += mDecodedBuffer.SizeOfExcludingThis(aMallocSizeOf); return size; } @@ -94,7 +94,7 @@ public: bool BasicPlanarYCbCrImage::SetData(const Data& aData) { - PlanarYCbCrImage::SetData(aData); + RecyclingPlanarYCbCrImage::SetData(aData); if (mDelayedConversion) { return false; diff --git a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp index e98aa69a8b0f..719fa0e4b10a 100644 --- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp +++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp @@ -26,8 +26,7 @@ namespace layers { using namespace mozilla::ipc; SharedPlanarYCbCrImage::SharedPlanarYCbCrImage(ImageClient* aCompositable) -: PlanarYCbCrImage(nullptr) -, mCompositable(aCompositable) +: mCompositable(aCompositable) { MOZ_COUNT_CTOR(SharedPlanarYCbCrImage); } @@ -54,8 +53,7 @@ SharedPlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const // at time of allocation in GfxMemoryImageReporter. // Not owned: // - mCompositable - size_t size = PlanarYCbCrImage::SizeOfExcludingThis(aMallocSizeOf); - return size; + return 0; } TextureClient* @@ -163,20 +161,6 @@ SharedPlanarYCbCrImage::SetDataNoCopy(const Data &aData) return true; } -uint8_t* -SharedPlanarYCbCrImage::AllocateBuffer(uint32_t aSize) -{ - MOZ_ASSERT(!mTextureClient, - "This image already has allocated data"); - mTextureClient = TextureClient::CreateWithBufferSize(mCompositable->GetForwarder(), - gfx::SurfaceFormat::YUV, aSize, - mCompositable->GetTextureFlags()); - if (!mTextureClient) { - return nullptr; - } - return mTextureClient->GetBuffer(); -} - bool SharedPlanarYCbCrImage::IsValid() { return !!mTextureClient; diff --git a/gfx/layers/ipc/SharedPlanarYCbCrImage.h b/gfx/layers/ipc/SharedPlanarYCbCrImage.h index 1d7acdb72a99..39132ab3ed37 100644 --- a/gfx/layers/ipc/SharedPlanarYCbCrImage.h +++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.h @@ -39,9 +39,6 @@ public: virtual bool SetDataNoCopy(const Data &aData) override; virtual bool Allocate(PlanarYCbCrData& aData); - virtual uint8_t* AllocateBuffer(uint32_t aSize) override; - // needs to be overriden because the parent class sets mBuffer which we - // do not want to happen. virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize) override; virtual bool IsValid() override; diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp b/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp index 5383e152f185..083b78b06456 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp @@ -1003,7 +1003,7 @@ WebrtcOMXH264VideoEncoder::Encode(const webrtc::I420VideoFrame& aInputImage, (yuvData.mYSize.height + 1) / 2); yuvData.mPicSize = yuvData.mYSize; yuvData.mStereoMode = StereoMode::MONO; - layers::PlanarYCbCrImage img(nullptr); + layers::RecyclingPlanarYCbCrImage img(nullptr); // SetDataNoCopy() doesn't need AllocateAndGetNewBuffer(); OMXVideoEncoder is ok with this img.SetDataNoCopy(yuvData);