Bug 893301. Changes to texture clients. r=nical

This commit is contained in:
Nicholas Cameron 2013-11-28 10:16:34 +13:00
parent d5cf63f5a2
commit 9de2acbf91
4 changed files with 85 additions and 6 deletions

View File

@ -15,8 +15,11 @@
#include "mozilla/layers/TextureD3D9.h"
#include "mozilla/layers/TextureD3D11.h"
#include "gfxWindowsPlatform.h"
#include "gfx2DGlue.h"
#endif
using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
@ -193,8 +196,8 @@ CompositableClient::CreateDeprecatedTextureClient(DeprecatedTextureClientType aD
}
TemporaryRef<BufferTextureClient>
CompositableClient::CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
uint32_t aTextureFlags)
CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat,
TextureFlags aTextureFlags)
{
// XXX - Once bug 908196 is fixed, we can use gralloc textures here which will
// improve performances of videos using SharedPlanarYCbCrImage on b2g.
@ -214,15 +217,56 @@ CompositableClient::CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
return result.forget();
}
bool
CompositableClient::AddTextureClient(TextureClient* aClient)
TemporaryRef<TextureClient>
CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat,
TextureFlags aTextureFlags)
{
RefPtr<TextureClient> result;
#ifdef XP_WIN
LayersBackend parentBackend = GetForwarder()->GetCompositorBackendType();
// XXX[nrc] uncomment once we have new texture clients for windows
if (parentBackend == LAYERS_D3D11 && gfxWindowsPlatform::GetPlatform()->GetD2DDevice() &&
!(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) {
//result = new TextureClientD3D11(GetForwarder(), GetTextureInfo());
}
if (parentBackend == LAYERS_D3D9 &&
!GetForwarder()->ForwardsToDifferentProcess() &&
!(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) {
// non-DIB textures don't work with alpha, see notes in TextureD3D9.
if (ContentForFormat(aFormat) == GFX_CONTENT_COLOR_ALPHA) {
//result = new TextureClientDIB(GetForwarder(), GetTextureInfo());
} else {
//result = new TextureClientD3D9(GetForwarder(), GetTextureInfo());
}
}
#endif
// Can't do any better than a buffer texture client.
if (!result) {
result = CreateBufferTextureClient(aFormat, aTextureFlags);
}
MOZ_ASSERT(!result || result->AsTextureClientDrawTarget(),
"Not a TextureClientDrawTarget?");
return result;
}
uint64_t
CompositableClient::NextTextureID()
{
++mNextTextureID;
// 0 is always an invalid ID
if (mNextTextureID == 0) {
++mNextTextureID;
}
aClient->SetID(mNextTextureID);
return mNextTextureID;
}
bool
CompositableClient::AddTextureClient(TextureClient* aClient)
{
aClient->SetID(NextTextureID());
return mForwarder->AddTexture(this, aClient);
}

View File

@ -88,6 +88,12 @@ public:
CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
// If we return a non-null TextureClient, then AsTextureClientDrawTarget will
// always be non-null.
TemporaryRef<TextureClient>
CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat,
TextureFlags aTextureFlags);
virtual void SetDescriptorFromReply(TextureIdentifier aTextureId,
const SurfaceDescriptor& aDescriptor)
{
@ -168,6 +174,9 @@ public:
virtual void OnActorDestroy() = 0;
protected:
// return the next texture ID
uint64_t NextTextureID();
struct TextureIDAndFlags {
TextureIDAndFlags(uint64_t aID, TextureFlags aFlags)
: mID(aID), mFlags(aFlags) {}

View File

@ -321,6 +321,19 @@ BufferTextureClient::AllocateForSurface(gfx::IntSize aSize)
return true;
}
TemporaryRef<gfx::DrawTarget>
BufferTextureClient::GetAsDrawTarget()
{
MOZ_ASSERT(IsValid());
ImageDataSerializer serializer(GetBuffer());
if (!serializer.IsValid()) {
return nullptr;
}
return serializer.GetAsDrawTarget();
}
bool
BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData)
{

View File

@ -59,6 +59,17 @@ public:
virtual bool AllocateForSurface(gfx::IntSize aSize) = 0;
};
/**
* Interface for TextureClients that can be updated using a DrawTarget.
*/
class TextureClientDrawTarget
{
public:
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() = 0;
virtual gfx::SurfaceFormat GetFormat() const = 0;
virtual bool AllocateForSurface(gfx::IntSize aSize) = 0;
};
/**
* Interface for TextureClients that can be updated using YCbCr data.
*/
@ -124,6 +135,7 @@ public:
virtual ~TextureClient();
virtual TextureClientSurface* AsTextureClientSurface() { return nullptr; }
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; }
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
/**
@ -240,7 +252,8 @@ protected:
*/
class BufferTextureClient : public TextureClient
, public TextureClientSurface
, TextureClientYCbCr
, public TextureClientYCbCr
, public TextureClientDrawTarget
{
public:
BufferTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat,