bool ContentClientRemoteBuffer::CreateAndAllocateTextureClient(RefPtr<TextureClient>& aClient, TextureFlags aFlags) { // gfx::BackendType::NONE means fallback to the content backend aClient = CreateTextureClientForDrawing(mSurfaceFormat, mTextureInfo.mTextureFlags | aFlags, gfx::BackendType::NONE, mSize); if (!aClient) { return false; } if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) { aClient = CreateTextureClientForDrawing(mSurfaceFormat, mTextureInfo.mTextureFlags | TEXTURE_ALLOC_FALLBACK | aFlags, gfx::BackendType::NONE, mSize); if (!aClient) { return false; } if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) { NS_WARNING("Could not allocate texture client"); aClient = nullptr; return false; } } NS_WARN_IF_FALSE(aClient->IsValid(), "Created an invalid texture client"); return true; }
TemporaryRef<TextureClient> TextureClientPool::GetTextureClient() { mOutstandingClients++; // Try to fetch a client from the pool RefPtr<TextureClient> textureClient; if (mTextureClients.size()) { textureClient = mTextureClients.top(); textureClient->WaitReleaseFence(); mTextureClients.pop(); return textureClient; } // We're increasing the number of outstanding TextureClients without reusing a // client, we may need to free a deferred-return TextureClient. ShrinkToMaximumSize(); // No unused clients in the pool, create one if (gfxPrefs::ForceShmemTiles()) { // gfx::BackendType::NONE means use the content backend textureClient = TextureClient::CreateBufferTextureClient(mSurfaceAllocator, mFormat, TextureFlags::IMMEDIATE_UPLOAD, gfx::BackendType::NONE); } else { textureClient = TextureClient::CreateTextureClientForDrawing(mSurfaceAllocator, mFormat, TextureFlags::IMMEDIATE_UPLOAD, gfx::BackendType::NONE, mSize); } textureClient->AllocateForSurface(mSize, ALLOC_DEFAULT); return textureClient; }
TemporaryRef<TextureClient> TextureClientD3D11::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const { RefPtr<TextureClient> tex = new TextureClientD3D11(mFormat, mFlags | aFlags); if (!tex->AllocateForSurface(mSize, ALLOC_DEFAULT)) { return nullptr; } return tex; }
already_AddRefed<TextureClient> TextureClientD3D11::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const { RefPtr<TextureClient> tex = new TextureClientD3D11(mAllocator, mFormat, mFlags | aFlags); if (!tex->AllocateForSurface(mSize, aAllocFlags)) { return nullptr; } return tex.forget(); }
TemporaryRef<TextureClient> DIBTextureClient::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const { RefPtr<TextureClient> tex = new DIBTextureClient(mAllocator, mFormat, mFlags | aFlags); if (!tex->AllocateForSurface(mSize, aAllocFlags)) { return nullptr; } return tex; }
TemporaryRef<TextureClient> TextureClientX11::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const { RefPtr<TextureClient> tex = new TextureClientX11(mAllocator, mFormat, mFlags); // mSize is guaranteed to be non-negative MOZ_ASSERT(mSize.width >= 0 && mSize.height >= 0); if (!tex->AllocateForSurface(mSize, aAllocFlags)) { return nullptr; } return tex; }
TextureClient* CairoImage::GetTextureClient(CompositableClient *aClient) { if (!aClient) { return nullptr; } CompositableForwarder* forwarder = aClient->GetForwarder(); RefPtr<TextureClient> textureClient = mTextureClients.Get(forwarder->GetSerial()); if (textureClient) { return textureClient; } RefPtr<SourceSurface> surface = GetAsSourceSurface(); MOZ_ASSERT(surface); if (!surface) { return nullptr; } // gfx::BackendType::NONE means default to content backend textureClient = aClient->CreateTextureClientForDrawing(surface->GetFormat(), TextureFlags::DEFAULT, gfx::BackendType::NONE, surface->GetSize()); if (!textureClient) { return nullptr; } MOZ_ASSERT(textureClient->CanExposeDrawTarget()); if (!textureClient->AllocateForSurface(surface->GetSize()) || !textureClient->Lock(OpenMode::OPEN_WRITE_ONLY)) { return nullptr; } { // We must not keep a reference to the DrawTarget after it has been unlocked. RefPtr<DrawTarget> dt = textureClient->GetAsDrawTarget(); dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint()); } textureClient->Unlock(); mTextureClients.Put(forwarder->GetSerial(), textureClient); return textureClient; }