Bug 1040028 - Create and allocate in one step when we used to call CreateBufferTextureClient and CreateTextureClientForDrawing. r=sotaro
This commit is contained in:
@@ -186,13 +186,14 @@ CompositableClient::GetAsyncID() const
|
||||
}
|
||||
|
||||
TemporaryRef<BufferTextureClient>
|
||||
CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat,
|
||||
TextureFlags aTextureFlags,
|
||||
gfx::BackendType aMoz2DBackend)
|
||||
CompositableClient::CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
|
||||
gfx::IntSize aSize,
|
||||
gfx::BackendType aMoz2DBackend,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
return TextureClient::CreateBufferTextureClient(GetForwarder(), aFormat,
|
||||
aTextureFlags | mTextureFlags,
|
||||
aMoz2DBackend);
|
||||
return TextureClient::CreateForRawBufferAccess(GetForwarder(),
|
||||
aFormat, aSize, aMoz2DBackend,
|
||||
aTextureFlags | mTextureFlags);
|
||||
}
|
||||
|
||||
TemporaryRef<TextureClient>
|
||||
|
||||
@@ -131,8 +131,9 @@ public:
|
||||
|
||||
TemporaryRef<BufferTextureClient>
|
||||
CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
|
||||
TextureFlags aFlags = TextureFlags::DEFAULT,
|
||||
gfx::BackendType aMoz2dBackend = gfx::BackendType::NONE);
|
||||
gfx::IntSize aSize,
|
||||
gfx::BackendType aMoz2dBackend = gfx::BackendType::NONE,
|
||||
TextureFlags aFlags = TextureFlags::DEFAULT);
|
||||
|
||||
TemporaryRef<TextureClient>
|
||||
CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat,
|
||||
|
||||
@@ -209,11 +209,12 @@ ImageClientSingle::UpdateImageInternal(ImageContainer* aContainer,
|
||||
|
||||
bool bufferCreated = false;
|
||||
if (!mFrontBuffer) {
|
||||
mFrontBuffer = CreateBufferTextureClient(gfx::SurfaceFormat::YUV, TextureFlags::DEFAULT);
|
||||
gfx::IntSize ySize(data->mYSize.width, data->mYSize.height);
|
||||
gfx::IntSize cbCrSize(data->mCbCrSize.width, data->mCbCrSize.height);
|
||||
if (!mFrontBuffer->AsTextureClientYCbCr()->AllocateForYCbCr(ySize, cbCrSize, data->mStereoMode)) {
|
||||
mFrontBuffer = nullptr;
|
||||
mFrontBuffer = TextureClient::CreateForYCbCr(GetForwarder(),
|
||||
ySize, cbCrSize, data->mStereoMode,
|
||||
TextureFlags::DEFAULT|mTextureFlags);
|
||||
if (!mFrontBuffer) {
|
||||
return false;
|
||||
}
|
||||
bufferCreated = true;
|
||||
|
||||
@@ -229,6 +229,25 @@ DisableGralloc(SurfaceFormat aFormat, const gfx::IntSize& aSizeHint)
|
||||
}
|
||||
#endif
|
||||
|
||||
static
|
||||
TemporaryRef<BufferTextureClient>
|
||||
CreateBufferTextureClient(ISurfaceAllocator* aAllocator,
|
||||
SurfaceFormat aFormat,
|
||||
TextureFlags aTextureFlags,
|
||||
gfx::BackendType aMoz2DBackend)
|
||||
{
|
||||
if (aAllocator->IsSameProcess()) {
|
||||
RefPtr<BufferTextureClient> result = new MemoryTextureClient(aAllocator, aFormat,
|
||||
aMoz2DBackend,
|
||||
aTextureFlags);
|
||||
return result.forget();
|
||||
}
|
||||
RefPtr<BufferTextureClient> result = new ShmemTextureClient(aAllocator, aFormat,
|
||||
aMoz2DBackend,
|
||||
aTextureFlags);
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
static
|
||||
TemporaryRef<TextureClient>
|
||||
CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator,
|
||||
@@ -313,7 +332,7 @@ CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator,
|
||||
|
||||
// Can't do any better than a buffer texture client.
|
||||
if (!result) {
|
||||
result = TextureClient::CreateBufferTextureClient(aAllocator, aFormat, aTextureFlags, aMoz2DBackend);
|
||||
result = CreateBufferTextureClient(aAllocator, aFormat, aTextureFlags, aMoz2DBackend);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!result || result->CanExposeDrawTarget(), "texture cannot expose a DrawTarget?");
|
||||
@@ -387,24 +406,29 @@ TextureClient::CreateForYCbCr(ISurfaceAllocator* aAllocator,
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
TemporaryRef<BufferTextureClient>
|
||||
TextureClient::CreateBufferTextureClient(ISurfaceAllocator* aAllocator,
|
||||
SurfaceFormat aFormat,
|
||||
TextureFlags aTextureFlags,
|
||||
gfx::BackendType aMoz2DBackend)
|
||||
TextureClient::CreateWithBufferSize(ISurfaceAllocator* aAllocator,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
size_t aSize,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
RefPtr<BufferTextureClient> texture;
|
||||
if (aAllocator->IsSameProcess()) {
|
||||
RefPtr<BufferTextureClient> result = new MemoryTextureClient(aAllocator, aFormat,
|
||||
aMoz2DBackend,
|
||||
aTextureFlags);
|
||||
return result.forget();
|
||||
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
||||
gfx::BackendType::NONE,
|
||||
aTextureFlags);
|
||||
} else {
|
||||
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
||||
gfx::BackendType::NONE,
|
||||
aTextureFlags);
|
||||
}
|
||||
RefPtr<BufferTextureClient> result = new ShmemTextureClient(aAllocator, aFormat,
|
||||
aMoz2DBackend,
|
||||
aTextureFlags);
|
||||
return result.forget();
|
||||
|
||||
if (!texture->Allocate(aSize)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
TextureClient::TextureClient(TextureFlags aFlags)
|
||||
|
||||
@@ -117,16 +117,6 @@ public:
|
||||
TextureClient(TextureFlags aFlags = TextureFlags::DEFAULT);
|
||||
virtual ~TextureClient();
|
||||
|
||||
// Creates a TextureClient that can be accessed through a raw pointer.
|
||||
// XXX - this doesn't allocate the texture data.
|
||||
// Prefer CreateForRawBufferAccess which returns a BufferTextureClient
|
||||
// only if allocation suceeded.
|
||||
static TemporaryRef<BufferTextureClient>
|
||||
CreateBufferTextureClient(ISurfaceAllocator* aAllocator,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
TextureFlags aTextureFlags,
|
||||
gfx::BackendType aMoz2dBackend);
|
||||
|
||||
// Creates and allocates a TextureClient usable with Moz2D.
|
||||
static TemporaryRef<TextureClient>
|
||||
CreateForDrawing(ISurfaceAllocator* aAllocator,
|
||||
@@ -154,6 +144,15 @@ public:
|
||||
TextureFlags aTextureFlags,
|
||||
TextureAllocationFlags flags = ALLOC_DEFAULT);
|
||||
|
||||
// Creates and allocates a BufferTextureClient (can beaccessed through raw
|
||||
// pointers) with a certain buffer size. It's unfortunate that we need this.
|
||||
// providing format and sizes could let us do more optimization.
|
||||
static TemporaryRef<BufferTextureClient>
|
||||
CreateWithBufferSize(ISurfaceAllocator* aAllocator,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
size_t aSize,
|
||||
TextureFlags aTextureFlags);
|
||||
|
||||
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
|
||||
|
||||
/**
|
||||
@@ -203,21 +202,6 @@ public:
|
||||
return gfx::SurfaceFormat::UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates for a given surface size, taking into account the pixel format
|
||||
* which is part of the state of the TextureClient.
|
||||
*
|
||||
* Does not clear the surface by default, clearing the surface can be done
|
||||
* by passing the CLEAR_BUFFER flag.
|
||||
*
|
||||
* TextureClients that can expose a DrawTarget should override this method.
|
||||
*/
|
||||
virtual bool AllocateForSurface(gfx::IntSize aSize,
|
||||
TextureAllocationFlags flags = ALLOC_DEFAULT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a rectangle from this texture client to a position in aTarget.
|
||||
* It is assumed that the necessary locks are in place; so this should at
|
||||
@@ -369,6 +353,22 @@ protected:
|
||||
*/
|
||||
void MarkInvalid() { mValid = false; }
|
||||
|
||||
/**
|
||||
* Allocates for a given surface size, taking into account the pixel format
|
||||
* which is part of the state of the TextureClient.
|
||||
*
|
||||
* Does not clear the surface by default, clearing the surface can be done
|
||||
* by passing the CLEAR_BUFFER flag.
|
||||
*
|
||||
* TextureClients that can expose a DrawTarget should override this method.
|
||||
*/
|
||||
virtual bool AllocateForSurface(gfx::IntSize aSize,
|
||||
TextureAllocationFlags flags = ALLOC_DEFAULT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should only be called *once* per texture, in TextureClient::InitIPDLActor.
|
||||
* Some texture implementations rely on the fact that the descriptor will be
|
||||
|
||||
@@ -107,10 +107,12 @@ SharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
|
||||
NS_ABORT_IF_FALSE(!mTextureClient, "This image already has allocated data");
|
||||
size_t size = YCbCrImageDataSerializer::ComputeMinBufferSize(aSize);
|
||||
|
||||
mTextureClient = mCompositable->CreateBufferTextureClient(gfx::SurfaceFormat::YUV);
|
||||
mTextureClient = TextureClient::CreateWithBufferSize(mCompositable->GetForwarder(),
|
||||
gfx::SurfaceFormat::YUV, size,
|
||||
mCompositable->GetTextureFlags());
|
||||
|
||||
// get new buffer _without_ setting mBuffer.
|
||||
if (!mTextureClient->Allocate(size)) {
|
||||
mTextureClient = nullptr;
|
||||
if (!mTextureClient) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -153,9 +155,10 @@ SharedPlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(!mTextureClient,
|
||||
"This image already has allocated data");
|
||||
mTextureClient = mCompositable->CreateBufferTextureClient(gfx::SurfaceFormat::YUV);
|
||||
if (!mTextureClient->Allocate(aSize)) {
|
||||
mTextureClient = nullptr;
|
||||
mTextureClient = TextureClient::CreateWithBufferSize(mCompositable->GetForwarder(),
|
||||
gfx::SurfaceFormat::YUV, aSize,
|
||||
mCompositable->GetTextureFlags());
|
||||
if (!mTextureClient) {
|
||||
return nullptr;
|
||||
}
|
||||
return mTextureClient->GetBuffer();
|
||||
|
||||
@@ -79,8 +79,10 @@ bool
|
||||
SharedRGBImage::Allocate(gfx::IntSize aSize, gfx::SurfaceFormat aFormat)
|
||||
{
|
||||
mSize = aSize;
|
||||
mTextureClient = mCompositable->CreateBufferTextureClient(aFormat);
|
||||
return mTextureClient->AllocateForSurface(aSize);
|
||||
mTextureClient = mCompositable->CreateBufferTextureClient(aFormat, aSize,
|
||||
gfx::BackendType::NONE,
|
||||
TextureFlags::DEFAULT);
|
||||
return !!mTextureClient;
|
||||
}
|
||||
|
||||
uint8_t*
|
||||
|
||||
Reference in New Issue
Block a user