Bug 1135935 - Part 3: Allow overriding of allocations for texture client recycling. r=sotaro

--HG--
extra : rebase_source : b93e67fd29dd805266e767f09c2df496d9256f86
This commit is contained in:
Matt Woodrow 2015-08-10 16:04:38 -04:00
parent ffbb1cdf8c
commit 21097c326c
4 changed files with 50 additions and 30 deletions

View File

@ -750,11 +750,11 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
layers::GrallocImage* videoImage = static_cast<layers::GrallocImage*>(image.get());
MOZ_ASSERT(mTextureClientAllocator);
RefPtr<layers::TextureClient> textureClient
= mTextureClientAllocator->CreateOrRecycleForDrawing(gfx::SurfaceFormat::YUV,
gfx::IntSize(dstWidth, dstHeight),
layers::BackendSelector::Content,
layers::TextureFlags::DEFAULT,
layers::ALLOC_DISALLOW_BUFFERTEXTURECLIENT);
= mTextureClientAllocator->CreateOrRecycle(gfx::SurfaceFormat::YUV,
gfx::IntSize(dstWidth, dstHeight),
layers::BackendSelector::Content,
layers::TextureFlags::DEFAULT,
layers::ALLOC_DISALLOW_BUFFERTEXTURECLIENT);
if (textureClient) {
RefPtr<layers::GrallocTextureClientOGL> grallocTextureClient =
static_cast<layers::GrallocTextureClientOGL*>(textureClient.get());

View File

@ -621,10 +621,10 @@ CairoImage::GetTextureClient(CompositableClient *aClient)
aClient->GetTextureClientRecycler();
if (recycler) {
textureClient =
recycler->CreateOrRecycleForDrawing(surface->GetFormat(),
surface->GetSize(),
BackendSelector::Content,
aClient->GetTextureFlags());
recycler->CreateOrRecycle(surface->GetFormat(),
surface->GetSize(),
BackendSelector::Content,
aClient->GetTextureFlags());
}
#endif

View File

@ -32,8 +32,8 @@ protected:
};
TextureClientRecycleAllocator::TextureClientRecycleAllocator(ISurfaceAllocator *aAllocator)
: mMaxPooledSize(kMaxPooledSized)
, mSurfaceAllocator(aAllocator)
: mSurfaceAllocator(aAllocator)
, mMaxPooledSize(kMaxPooledSized)
, mLock("TextureClientRecycleAllocatorImp.mLock")
{
}
@ -54,12 +54,11 @@ TextureClientRecycleAllocator::SetMaxPoolSize(uint32_t aMax)
}
already_AddRefed<TextureClient>
TextureClientRecycleAllocator::CreateOrRecycleForDrawing(
gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags)
TextureClientRecycleAllocator::CreateOrRecycle(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags)
{
// TextureAllocationFlags is actually used only by ContentClient.
// This class does not handle ConteClient's TextureClient allocation.
@ -77,8 +76,7 @@ TextureClientRecycleAllocator::CreateOrRecycleForDrawing(
mPooledClients.pop();
// If a pooled TextureClient is not compatible, release it.
if (textureHolder->GetTextureClient()->GetFormat() != aFormat ||
textureHolder->GetTextureClient()->GetSize() != aSize)
{
textureHolder->GetTextureClient()->GetSize() != aSize) {
TextureClientReleaseTask* task = new TextureClientReleaseTask(textureHolder->GetTextureClient());
textureHolder->ClearTextureClient();
textureHolder = nullptr;
@ -92,9 +90,7 @@ TextureClientRecycleAllocator::CreateOrRecycleForDrawing(
if (!textureHolder) {
// Allocate new TextureClient
RefPtr<TextureClient> texture;
texture = TextureClient::CreateForDrawing(mSurfaceAllocator, aFormat, aSize, aSelector,
aTextureFlags, aAllocFlags);
RefPtr<TextureClient> texture = Allocate(aFormat, aSize, aSelector, aTextureFlags, aAllocFlags);
if (!texture) {
return nullptr;
}
@ -112,6 +108,17 @@ TextureClientRecycleAllocator::CreateOrRecycleForDrawing(
return client.forget();
}
already_AddRefed<TextureClient>
TextureClientRecycleAllocator::Allocate(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags)
{
return TextureClient::CreateForDrawing(mSurfaceAllocator, aFormat, aSize, aSelector,
aTextureFlags, aAllocFlags);
}
void
TextureClientRecycleAllocator::RecycleCallbackImp(TextureClient* aClient)
{

View File

@ -25,10 +25,14 @@ class TextureClientHolder;
* recycling capabilities. It expects allocations of same sizes and
* attributres. If a recycled TextureClient is different from
* requested one, the recycled one is dropped and new TextureClient is allocated.
*
* By default this uses TextureClient::CreateForDrawing to allocate new texture
* clients.
*/
class TextureClientRecycleAllocator
{
~TextureClientRecycleAllocator();
protected:
virtual ~TextureClientRecycleAllocator();
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureClientRecycleAllocator)
@ -39,11 +43,21 @@ public:
// Creates and allocates a TextureClient.
already_AddRefed<TextureClient>
CreateOrRecycleForDrawing(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags flags = ALLOC_DEFAULT);
CreateOrRecycle(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags flags = ALLOC_DEFAULT);
protected:
virtual already_AddRefed<TextureClient>
Allocate(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
BackendSelector aSelector,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags);
RefPtr<ISurfaceAllocator> mSurfaceAllocator;
private:
void RecycleCallbackImp(TextureClient* aClient);
@ -51,9 +65,8 @@ private:
static void RecycleCallback(TextureClient* aClient, void* aClosure);
static const uint32_t kMaxPooledSized = 2;
uint32_t mMaxPooledSize;
RefPtr<ISurfaceAllocator> mSurfaceAllocator;
std::map<TextureClient*, RefPtr<TextureClientHolder> > mInUseClients;
// On b2g gonk, std::queue might be a better choice.