зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1217080. Move recycling functionality into RecyclingPlanarYCbCrImage. r=nical
This makes PlanarYCbCrImage abstract and moves the recycling functionality into RecyclingPlanarYCbCrImage. This decreases the size of SharedPlanarYCbCrImage and makes it possible for us to do part 3 of bug 1216644.
This commit is contained in:
Родитель
cf1035b664
Коммит
bcf6317ef4
|
@ -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;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ struct GraphicBufferAutoUnlock {
|
|||
};
|
||||
|
||||
GrallocImage::GrallocImage()
|
||||
: PlanarYCbCrImage(nullptr)
|
||||
: RecyclingPlanarYCbCrImage(nullptr)
|
||||
{
|
||||
mFormat = ImageFormat::GRALLOC_PLANAR_YCBCR;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ GetDataSourceSurfaceFrom(android::sp<android::GraphicBuffer>& 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[];
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace mozilla {
|
|||
namespace layers {
|
||||
|
||||
IMFYCbCrImage::IMFYCbCrImage(IMFMediaBuffer* aBuffer, IMF2DBuffer* a2DBuffer)
|
||||
: PlanarYCbCrImage(nullptr)
|
||||
: RecyclingPlanarYCbCrImage(nullptr)
|
||||
, mBuffer(aBuffer)
|
||||
, m2DBuffer(a2DBuffer)
|
||||
{}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<gfx::SourceSurface> GetAsSourceSurface();
|
||||
|
||||
void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
|
||||
gfxImageFormat GetOffscreenFormat();
|
||||
|
||||
Data mData;
|
||||
gfx::IntSize mSize;
|
||||
gfxImageFormat mOffscreenFormat;
|
||||
nsCountedRef<nsMainThreadSourceSurfaceRef> 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<gfx::SourceSurface> GetAsSourceSurface();
|
||||
|
||||
void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
|
||||
gfxImageFormat GetOffscreenFormat();
|
||||
|
||||
nsAutoArrayPtr<uint8_t> mBuffer;
|
||||
uint32_t mBufferSize;
|
||||
Data mData;
|
||||
gfx::IntSize mSize;
|
||||
gfxImageFormat mOffscreenFormat;
|
||||
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
|
||||
RefPtr<BufferRecycleBin> mRecycleBin;
|
||||
nsAutoArrayPtr<uint8_t> mBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче