Bug 1027601 - Create and Allocate TextureClients in a single step in SharedPlanarYCbCrImage. r=sotaro

This commit is contained in:
Nicolas Silva 2014-07-09 11:59:53 +02:00
parent 7be2a8a1dd
commit 82aaa92f1d
4 changed files with 66 additions and 30 deletions

View File

@ -226,6 +226,8 @@ public:
static uint64_t GetTrackersHolderId(PCompositableChild* aActor);
TextureFlags GetTextureFlags() const { return mTextureFlags; }
protected:
CompositableChild* mCompositableChild;
CompositableForwarder* mForwarder;

View File

@ -363,6 +363,33 @@ TextureClient::CreateForRawBufferAccess(ISurfaceAllocator* aAllocator,
return texture;
}
// static
TemporaryRef<BufferTextureClient>
TextureClient::CreateForYCbCr(ISurfaceAllocator* aAllocator,
gfx::IntSize aYSize,
gfx::IntSize aCbCrSize,
StereoMode aStereoMode,
TextureFlags aTextureFlags)
{
RefPtr<BufferTextureClient> texture;
if (aAllocator->IsSameProcess()) {
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
gfx::BackendType::NONE,
aTextureFlags);
} else {
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
gfx::BackendType::NONE,
aTextureFlags);
}
if (!texture->AllocateForYCbCr(aYSize, aCbCrSize, aStereoMode)) {
return nullptr;
}
return texture;
}
// static
TemporaryRef<BufferTextureClient>
TextureClient::CreateBufferTextureClient(ISurfaceAllocator* aAllocator,

View File

@ -139,6 +139,14 @@ public:
TextureFlags aTextureFlags,
TextureAllocationFlags flags = ALLOC_DEFAULT);
// Creates and allocates a BufferTextureClient supporting the YCbCr format.
static TemporaryRef<BufferTextureClient>
CreateForYCbCr(ISurfaceAllocator* aAllocator,
gfx::IntSize aYSize,
gfx::IntSize aCbCrSize,
StereoMode aStereoMode,
TextureFlags aTextureFlags);
// Creates and allocates a BufferTextureClient (can beaccessed through raw
// pointers).
static TemporaryRef<BufferTextureClient>

View File

@ -29,7 +29,6 @@ SharedPlanarYCbCrImage::SharedPlanarYCbCrImage(ImageClient* aCompositable)
: PlanarYCbCrImage(nullptr)
, mCompositable(aCompositable)
{
mTextureClient = aCompositable->CreateBufferTextureClient(gfx::SurfaceFormat::YUV);
MOZ_COUNT_CTOR(SharedPlanarYCbCrImage);
}
@ -69,7 +68,7 @@ SharedPlanarYCbCrImage::GetBuffer()
TemporaryRef<gfx::SourceSurface>
SharedPlanarYCbCrImage::GetAsSourceSurface()
{
if (!mTextureClient->IsAllocated()) {
if (!mTextureClient) {
NS_WARNING("Can't get as surface");
return nullptr;
}
@ -79,15 +78,12 @@ SharedPlanarYCbCrImage::GetAsSourceSurface()
void
SharedPlanarYCbCrImage::SetData(const PlanarYCbCrData& aData)
{
// If mShmem has not been allocated (through Allocate(aData)), allocate it.
// This code path is slower than the one used when Allocate has been called
// since it will trigger a full copy.
if (!mTextureClient->IsAllocated()) {
Data data = aData;
if (!Allocate(data)) {
NS_WARNING("SharedPlanarYCbCrImage::SetData failed to allocate");
return;
}
// If mTextureClient has not already been allocated (through Allocate(aData))
// allocate it. This code path is slower than the one used when Allocate has
// been called since it will trigger a full copy.
PlanarYCbCrData data = aData;
if (!mTextureClient && !Allocate(data)) {
return;
}
MOZ_ASSERT(mTextureClient->AsTextureClientYCbCr());
@ -100,17 +96,6 @@ SharedPlanarYCbCrImage::SetData(const PlanarYCbCrData& aData)
MOZ_ASSERT(false, "Failed to copy YCbCr data into the TextureClient");
return;
}
// do not set mBuffer like in PlanarYCbCrImage because the later
// will try to manage this memory without knowing it belongs to a
// shmem.
mBufferSize = YCbCrImageDataSerializer::ComputeMinBufferSize(mData.mYSize,
mData.mCbCrSize);
mSize = mData.mPicSize;
YCbCrImageDataSerializer serializer(mTextureClient->GetBuffer(), mTextureClient->GetBufferSize());
mData.mYChannel = serializer.GetYData();
mData.mCbChannel = serializer.GetCbData();
mData.mCrChannel = serializer.GetCrData();
mTextureClient->MarkImmutable();
}
@ -119,11 +104,13 @@ SharedPlanarYCbCrImage::SetData(const PlanarYCbCrData& aData)
uint8_t*
SharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
{
NS_ABORT_IF_FALSE(!mTextureClient->IsAllocated(), "This image already has allocated data");
NS_ABORT_IF_FALSE(!mTextureClient, "This image already has allocated data");
size_t size = YCbCrImageDataSerializer::ComputeMinBufferSize(aSize);
mTextureClient = mCompositable->CreateBufferTextureClient(gfx::SurfaceFormat::YUV);
// get new buffer _without_ setting mBuffer.
if (!mTextureClient->Allocate(size)) {
mTextureClient = nullptr;
return nullptr;
}
@ -137,6 +124,7 @@ SharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
void
SharedPlanarYCbCrImage::SetDataNoCopy(const Data &aData)
{
NS_ABORT_IF_FALSE(mTextureClient, "This Image should have already allocated data");
mData = aData;
mSize = aData.mPicSize;
/* SetDataNoCopy is used to update YUV plane offsets without (re)allocating
@ -163,9 +151,11 @@ SharedPlanarYCbCrImage::SetDataNoCopy(const Data &aData)
uint8_t*
SharedPlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
{
NS_ABORT_IF_FALSE(!mTextureClient->IsAllocated(),
NS_ABORT_IF_FALSE(!mTextureClient,
"This image already has allocated data");
mTextureClient = mCompositable->CreateBufferTextureClient(gfx::SurfaceFormat::YUV);
if (!mTextureClient->Allocate(aSize)) {
mTextureClient = nullptr;
return nullptr;
}
return mTextureClient->GetBuffer();
@ -173,19 +163,21 @@ SharedPlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
bool
SharedPlanarYCbCrImage::IsValid() {
return mTextureClient->IsAllocated();
return !!mTextureClient;
}
bool
SharedPlanarYCbCrImage::Allocate(PlanarYCbCrData& aData)
{
NS_ABORT_IF_FALSE(!mTextureClient->IsAllocated(),
NS_ABORT_IF_FALSE(!mTextureClient,
"This image already has allocated data");
size_t size = YCbCrImageDataSerializer::ComputeMinBufferSize(aData.mYSize,
aData.mCbCrSize);
if (AllocateBuffer(static_cast<uint32_t>(size)) == nullptr) {
mTextureClient = TextureClient::CreateForYCbCr(mCompositable->GetForwarder(),
aData.mYSize, aData.mCbCrSize,
aData.mStereoMode,
mCompositable->GetTextureFlags());
if (!mTextureClient) {
NS_WARNING("SharedPlanarYCbCrImage::Allocate failed.");
return false;
}
@ -217,6 +209,13 @@ SharedPlanarYCbCrImage::Allocate(PlanarYCbCrData& aData)
mData.mYStride = mData.mYSize.width;
mData.mCbCrStride = mData.mCbCrSize.width;
// do not set mBuffer like in PlanarYCbCrImage because the later
// will try to manage this memory without knowing it belongs to a
// shmem.
mBufferSize = YCbCrImageDataSerializer::ComputeMinBufferSize(mData.mYSize,
mData.mCbCrSize);
mSize = mData.mPicSize;
return true;
}