Backed out 5 changesets (bug 991032, bug 990933, bug 990876, bug 990871) for build bustage

CLOSED TREE

Backed out changeset c28e1344a6da (bug 991032)
Backed out changeset c85326be7e94 (bug 990876)
Backed out changeset 7cd1a8c883cb (bug 990876)
Backed out changeset 3052e8a3c505 (bug 990933)
Backed out changeset 6685770cf674 (bug 990871)
This commit is contained in:
Phil Ringnalda 2014-04-03 20:28:52 -07:00
Родитель 3d8e4ec216
Коммит 7139e221ae
20 изменённых файлов: 308 добавлений и 208 удалений

Просмотреть файл

@ -692,15 +692,15 @@ CairoImage::GetTextureClient(CompositableClient *aClient)
TEXTURE_FLAGS_DEFAULT,
gfx::BackendType::NONE,
surface->GetSize());
MOZ_ASSERT(textureClient->CanExposeDrawTarget());
if (!textureClient->AllocateForSurface(surface->GetSize()) ||
MOZ_ASSERT(textureClient->AsTextureClientDrawTarget());
if (!textureClient->AsTextureClientDrawTarget()->AllocateForSurface(surface->GetSize()) ||
!textureClient->Lock(OPEN_WRITE_ONLY)) {
return nullptr;
}
{
// We must not keep a reference to the DrawTarget after it has been unlocked.
RefPtr<DrawTarget> dt = textureClient->GetAsDrawTarget();
RefPtr<DrawTarget> dt = textureClient->AsTextureClientDrawTarget()->GetAsDrawTarget();
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
}

Просмотреть файл

@ -293,7 +293,7 @@ RotatedContentBuffer::BufferContentType()
SurfaceFormat format;
if (mBufferProvider) {
format = mBufferProvider->GetFormat();
format = mBufferProvider->AsTextureClientDrawTarget()->GetFormat();
} else if (mDTBuffer) {
format = mDTBuffer->GetFormat();
}
@ -317,7 +317,7 @@ RotatedContentBuffer::EnsureBuffer()
NS_ASSERTION(!mLoanedDrawTarget, "Loaned draw target must be returned");
if (!mDTBuffer) {
if (mBufferProvider) {
mDTBuffer = mBufferProvider->GetAsDrawTarget();
mDTBuffer = mBufferProvider->AsTextureClientDrawTarget()->GetAsDrawTarget();
}
}
@ -332,7 +332,7 @@ RotatedContentBuffer::EnsureBufferOnWhite()
if (!mDTBufferOnWhite) {
if (mBufferProviderOnWhite) {
mDTBufferOnWhite =
mBufferProviderOnWhite->GetAsDrawTarget();
mBufferProviderOnWhite->AsTextureClientDrawTarget()->GetAsDrawTarget();
}
}

Просмотреть файл

@ -40,7 +40,8 @@ TextureClientX11::IsAllocated() const
bool
TextureClientX11::Lock(OpenMode aMode)
{
MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
// XXX - Turn this into a fatal assertion as soon as Bug 952507 is fixed
NS_WARN_IF_FALSE(!mLocked, "The TextureClient is already Locked!");
mLocked = IsValid() && IsAllocated();
return mLocked;
}
@ -48,7 +49,8 @@ TextureClientX11::Lock(OpenMode aMode)
void
TextureClientX11::Unlock()
{
MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
// XXX - Turn this into a fatal assertion as soon as Bug 952507 is fixed
NS_WARN_IF_FALSE(mLocked, "The TextureClient is already Unlocked!");
mLocked = false;
if (mSurface) {
@ -75,6 +77,34 @@ TextureClientX11::DropTextureData()
return nullptr;
}
bool
TextureClientX11::UpdateSurface(gfxASurface* aSurface)
{
MOZ_ASSERT(IsValid());
RefPtr<DrawTarget> dt = GetAsDrawTarget();
if (!dt) {
return false;
}
RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, aSurface);
dt->CopySurface(source, IntRect(IntPoint(), GetSize()), IntPoint());
return true;
}
already_AddRefed<gfxASurface>
TextureClientX11::GetAsSurface()
{
MOZ_ASSERT(IsValid());
if (!mSurface) {
return nullptr;
}
nsRefPtr<gfxASurface> temp = mSurface.get();
return temp.forget();
}
bool
TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags)
{

Просмотреть файл

@ -7,6 +7,7 @@
#define MOZILLA_GFX_TEXTURECLIENT_X11_H
#include "mozilla/layers/TextureClient.h"
#include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid
#include "mozilla/layers/ShadowLayerUtilsX11.h"
namespace mozilla {
@ -15,32 +16,43 @@ namespace layers {
/**
* A TextureClient implementation based on Xlib.
*/
class TextureClientX11 : public TextureClient
class TextureClientX11
: public TextureClient,
public TextureClientSurface,
public TextureClientDrawTarget
{
public:
TextureClientX11(gfx::SurfaceFormat format, TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
~TextureClientX11();
virtual bool IsAllocated() const MOZ_OVERRIDE;
// TextureClient
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
TextureClientSurface* AsTextureClientSurface() MOZ_OVERRIDE { return this; }
TextureClientDrawTarget* AsTextureClientDrawTarget() MOZ_OVERRIDE { return this; }
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE;
bool IsAllocated() const MOZ_OVERRIDE;
bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
TextureClientData* DropTextureData() MOZ_OVERRIDE;
gfx::IntSize GetSize() const {
return mSize;
}
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
bool Lock(OpenMode aMode) MOZ_OVERRIDE;
void Unlock() MOZ_OVERRIDE;
bool IsLocked() const MOZ_OVERRIDE { return mLocked; }
virtual bool Lock(OpenMode aMode) MOZ_OVERRIDE;
// TextureClientSurface
virtual void Unlock() MOZ_OVERRIDE;
bool UpdateSurface(gfxASurface* aSurface) MOZ_OVERRIDE;
already_AddRefed<gfxASurface> GetAsSurface() MOZ_OVERRIDE;
bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags flags) MOZ_OVERRIDE;
virtual bool IsLocked() const MOZ_OVERRIDE { return mLocked; }
// TextureClientDrawTarget
virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags flags) MOZ_OVERRIDE;
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const { return mFormat; }
TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
gfx::SurfaceFormat GetFormat() const {
return mFormat;
}
virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }

Просмотреть файл

@ -16,8 +16,8 @@ class BasicCompositor;
// TextureSource for Xlib-backed surfaces.
class X11TextureSourceBasic
: public TextureSourceBasic
, public NewTextureSource
: public TextureSourceBasic,
public NewTextureSource
{
public:
X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
@ -25,9 +25,7 @@ public:
virtual X11TextureSourceBasic* AsSourceBasic() MOZ_OVERRIDE { return this; }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::SourceSurface* GetSurface() MOZ_OVERRIDE;
virtual void DeallocateDeviceData() MOZ_OVERRIDE { }

Просмотреть файл

@ -68,8 +68,8 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format),
flags,
gfxPlatform::GetPlatform()->GetPreferredCanvasBackend());
MOZ_ASSERT(mBuffer->CanExposeDrawTarget());
mBuffer->AllocateForSurface(aSize);
MOZ_ASSERT(mBuffer->AsTextureClientSurface());
mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize);
bufferCreated = true;
}
@ -82,7 +82,7 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
{
// Restrict drawTarget to a scope so that terminates before Unlock.
RefPtr<DrawTarget> target =
mBuffer->GetAsDrawTarget();
mBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
if (target) {
aLayer->UpdateTarget(target);
updated = true;

Просмотреть файл

@ -177,7 +177,7 @@ ContentClientRemoteBuffer::CreateAndAllocateTextureClient(RefPtr<TextureClient>&
return false;
}
if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) {
if (!aClient->AsTextureClientDrawTarget()->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) {
aClient = CreateTextureClientForDrawing(mSurfaceFormat,
mTextureInfo.mTextureFlags | TEXTURE_ALLOC_FALLBACK | aFlags,
gfx::BackendType::NONE,
@ -185,7 +185,7 @@ ContentClientRemoteBuffer::CreateAndAllocateTextureClient(RefPtr<TextureClient>&
if (!aClient) {
return false;
}
if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) {
if (!aClient->AsTextureClientDrawTarget()->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) {
NS_WARNING("Could not allocate texture client");
aClient = nullptr;
return false;
@ -253,12 +253,12 @@ ContentClientRemoteBuffer::CreateBuffer(ContentType aType,
DebugOnly<bool> locked = mTextureClient->Lock(OPEN_READ_WRITE);
MOZ_ASSERT(locked, "Could not lock the TextureClient");
*aBlackDT = mTextureClient->GetAsDrawTarget();
*aBlackDT = mTextureClient->AsTextureClientDrawTarget()->GetAsDrawTarget();
if (aFlags & BUFFER_COMPONENT_ALPHA) {
locked = mTextureClientOnWhite->Lock(OPEN_READ_WRITE);
MOZ_ASSERT(locked, "Could not lock the second TextureClient for component alpha");
*aWhiteDT = mTextureClientOnWhite->GetAsDrawTarget();
*aWhiteDT = mTextureClientOnWhite->AsTextureClientDrawTarget()->GetAsDrawTarget();
}
}
@ -457,9 +457,10 @@ ContentClientDoubleBuffered::FinalizeFrame(const nsIntRegion& aRegionToDraw)
// Restrict the DrawTargets and frontBuffer to a scope to make
// sure there is no more external references to the DrawTargets
// when we Unlock the TextureClients.
RefPtr<DrawTarget> dt = mFrontClient->GetAsDrawTarget();
RefPtr<DrawTarget> dt =
mFrontClient->AsTextureClientDrawTarget()->GetAsDrawTarget();
RefPtr<DrawTarget> dtOnWhite = mFrontClientOnWhite
? mFrontClientOnWhite->GetAsDrawTarget()
? mFrontClientOnWhite->AsTextureClientDrawTarget()->GetAsDrawTarget()
: nullptr;
RotatedBuffer frontBuffer(dt,
dtOnWhite,
@ -539,7 +540,7 @@ ContentClientSingleBuffered::PrepareFrame()
if (!backBuffer && mTextureClient) {
DebugOnly<bool> locked = mTextureClient->Lock(OPEN_READ_WRITE);
MOZ_ASSERT(locked);
backBuffer = mTextureClient->GetAsDrawTarget();
backBuffer = mTextureClient->AsTextureClientDrawTarget()->GetAsDrawTarget();
}
RefPtr<DrawTarget> oldBuffer;
@ -551,7 +552,7 @@ ContentClientSingleBuffered::PrepareFrame()
if (!backBuffer && mTextureClientOnWhite) {
DebugOnly<bool> locked = mTextureClientOnWhite->Lock(OPEN_READ_WRITE);
MOZ_ASSERT(locked);
backBuffer = mTextureClientOnWhite->GetAsDrawTarget();
backBuffer = mTextureClientOnWhite->AsTextureClientDrawTarget()->GetAsDrawTarget();
}
oldBuffer = SetDTBufferOnWhite(backBuffer);

Просмотреть файл

@ -233,8 +233,8 @@ ImageClientSingle::UpdateImageInternal(ImageContainer* aContainer,
= gfxPlatform::GetPlatform()->OptimalFormatForContent(gfx::ContentForFormat(surface->GetFormat()));
mFrontBuffer = CreateTextureClientForDrawing(gfx::ImageFormatToSurfaceFormat(format),
mTextureFlags, gfx::BackendType::NONE, size);
MOZ_ASSERT(mFrontBuffer->CanExposeDrawTarget());
if (!mFrontBuffer->AllocateForSurface(size)) {
MOZ_ASSERT(mFrontBuffer->AsTextureClientDrawTarget());
if (!mFrontBuffer->AsTextureClientDrawTarget()->AllocateForSurface(size)) {
mFrontBuffer = nullptr;
return false;
}
@ -248,7 +248,7 @@ ImageClientSingle::UpdateImageInternal(ImageContainer* aContainer,
{
// We must not keep a reference to the DrawTarget after it has been unlocked.
RefPtr<DrawTarget> dt = mFrontBuffer->GetAsDrawTarget();
RefPtr<DrawTarget> dt = mFrontBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
MOZ_ASSERT(surface.get());
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
}

Просмотреть файл

@ -77,7 +77,7 @@ SimpleTextureClientPool::GetTextureClient(bool aAutoRecycle)
textureClient = TextureClient::CreateTextureClientForDrawing(mSurfaceAllocator,
mFormat, TEXTURE_FLAGS_DEFAULT | TEXTURE_RECYCLE, gfx::BackendType::NONE, mSize);
}
if (!textureClient->AllocateForSurface(mSize, ALLOC_DEFAULT)) {
if (!textureClient->AsTextureClientDrawTarget()->AllocateForSurface(mSize, ALLOC_DEFAULT)) {
NS_WARNING("TextureClient::AllocateForSurface failed!");
}
RECYCLE_LOG("%s Must allocate (0 left), returning %p\n", (mFormat == SurfaceFormat::B8G8R8A8?"poolA":"poolX"), textureClient.get());

Просмотреть файл

@ -89,17 +89,19 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile,
return SimpleTiledLayerTile();
}
if (!textureClient->Lock(OPEN_READ_WRITE)) {
if (!textureClient->Lock(OPEN_WRITE)) {
NS_WARNING("TextureClient lock failed");
return SimpleTiledLayerTile();
}
if (!textureClient->CanExposeDrawTarget()) {
TextureClientSurface *textureClientSurf = textureClient->AsTextureClientSurface();
if (!textureClientSurf) {
doBufferedDrawing = false;
}
RefPtr<DrawTarget> drawTarget;
nsRefPtr<gfxImageSurface> clientAsImageSurface;
unsigned char *bufferData = nullptr;
// these are set/updated differently based on doBufferedDrawing
@ -107,25 +109,23 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile,
nsIntRegion drawRegion;
nsIntRegion invalidateRegion;
RefPtr<DrawTarget> srcDT;
uint8_t* srcData = nullptr;
int32_t srcStride = 0;
gfx::IntSize srcSize;
gfx::SurfaceFormat srcFormat = gfx::SurfaceFormat::UNKNOWN;
if (doBufferedDrawing) {
// try to directly access the pixels of the TextureClient
srcDT = textureClient->GetAsDrawTarget();
if (srcDT->LockBits(&srcData, &srcSize, &srcStride, &srcFormat)) {
// try to obtain the TextureClient as an ImageSurface, so that we can
// access the pixels directly
nsRefPtr<gfxASurface> asurf = textureClientSurf->GetAsSurface();
clientAsImageSurface = asurf ? asurf->GetAsImageSurface() : nullptr;
if (clientAsImageSurface) {
int32_t bufferStride = clientAsImageSurface->Stride();
if (!aTile.mCachedBuffer) {
aTile.mCachedBuffer = SharedBuffer::Create(srcStride * srcSize.height);
aTile.mCachedBuffer = SharedBuffer::Create(clientAsImageSurface->GetDataSize());
fullPaint = true;
}
bufferData = (unsigned char*) aTile.mCachedBuffer->Data();
drawTarget = gfxPlatform::GetPlatform()->CreateDrawTargetForData(bufferData,
kTileSize,
srcStride,
bufferStride,
tileFormat);
if (fullPaint) {
@ -146,7 +146,7 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile,
// this might get set above if we couldn't extract out a buffer
if (!doBufferedDrawing) {
drawTarget = textureClient->GetAsDrawTarget();
drawTarget = textureClient->AsTextureClientDrawTarget()->GetAsDrawTarget();
fullPaint = true;
drawBounds = nsIntRect(aTileOrigin.x, aTileOrigin.y, GetScaledTileLength(), GetScaledTileLength());
@ -169,15 +169,14 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile,
mCallbackData);
ctxt = nullptr;
drawTarget = nullptr;
if (doBufferedDrawing) {
memcpy(srcData, bufferData, srcSize.height * srcStride);
memcpy(clientAsImageSurface->Data(), bufferData, clientAsImageSurface->GetDataSize());
clientAsImageSurface = nullptr;
bufferData = nullptr;
srcDT->ReleaseBits(srcData);
srcDT = nullptr;
}
drawTarget = nullptr;
textureClient->Unlock();
if (!mCompositableClient->AddTextureClient(textureClient)) {

Просмотреть файл

@ -350,7 +350,8 @@ TextureClient::CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator,
result = CreateBufferTextureClient(aAllocator, aFormat, aTextureFlags, aMoz2DBackend);
}
MOZ_ASSERT(!result || result->CanExposeDrawTarget(), "texture cannot expose a DrawTarget?");
MOZ_ASSERT(!result || result->AsTextureClientDrawTarget(),
"Not a TextureClientDrawTarget?");
return result;
}
@ -484,12 +485,12 @@ bool TextureClient::CopyToTextureClient(TextureClient* aTarget,
MOZ_ASSERT(IsLocked());
MOZ_ASSERT(aTarget->IsLocked());
if (!aTarget->CanExposeDrawTarget() || !CanExposeDrawTarget()) {
if (!aTarget->AsTextureClientDrawTarget() || !AsTextureClientDrawTarget()) {
return false;
}
RefPtr<DrawTarget> destinationTarget = aTarget->GetAsDrawTarget();
RefPtr<DrawTarget> sourceTarget = GetAsDrawTarget();
RefPtr<DrawTarget> destinationTarget = aTarget->AsTextureClientDrawTarget()->GetAsDrawTarget();
RefPtr<DrawTarget> sourceTarget = AsTextureClientDrawTarget()->GetAsDrawTarget();
RefPtr<gfx::SourceSurface> source = sourceTarget->Snapshot();
destinationTarget->CopySurface(source,
aRect ? *aRect : gfx::IntRect(gfx::IntPoint(0, 0), GetSize()),
@ -662,6 +663,51 @@ BufferTextureClient::GetAllocator() const
return mAllocator;
}
bool
BufferTextureClient::UpdateSurface(gfxASurface* aSurface)
{
MOZ_ASSERT(mLocked);
MOZ_ASSERT(aSurface);
MOZ_ASSERT(!IsImmutable());
MOZ_ASSERT(IsValid());
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
if (!serializer.IsValid()) {
return false;
}
RefPtr<DrawTarget> dt = GetAsDrawTarget();
RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, aSurface);
dt->CopySurface(source, IntRect(IntPoint(), serializer.GetSize()), IntPoint());
// XXX - if the Moz2D backend is D2D, we would be much better off memcpying
// the content of the surface directly because with D2D, GetAsDrawTarget is
// very expensive.
if (TextureRequiresLocking(mFlags) && !ImplementsLocking()) {
// We don't have support for proper locking yet, so we'll
// have to be immutable instead.
MarkImmutable();
}
return true;
}
already_AddRefed<gfxASurface>
BufferTextureClient::GetAsSurface()
{
MOZ_ASSERT(mLocked);
MOZ_ASSERT(IsValid());
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
if (!serializer.IsValid()) {
return nullptr;
}
RefPtr<gfxImageSurface> surf = serializer.GetAsThebesSurface();
nsRefPtr<gfxASurface> result = surf.get();
return result.forget();
}
bool
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
{
@ -742,7 +788,7 @@ BufferTextureClient::Unlock()
return;
}
// see the comment on TextureClient::GetAsDrawTarget.
// see the comment on TextureClientDrawTarget::GetAsDrawTarget.
// This DrawTarget is internal to the TextureClient and is only exposed to the
// outside world between Lock() and Unlock(). This assertion checks that no outside
// reference remains by the time Unlock() is called.

Просмотреть файл

@ -50,8 +50,8 @@ class BufferTextureClient;
* TextureClient is the abstraction that allows us to share data between the
* content and the compositor side.
* TextureClient can also provide with some more "producer" facing APIs
* such as TextureClientYCbCr, that can be queried using
* AsTextureClientYCbCr(), etc.
* such as TextureClientSurface and TextureClientYCbCr, that can be queried
* using AsTextureCLientSurface(), etc.
*/
enum TextureAllocationFlags {
@ -59,6 +59,69 @@ enum TextureAllocationFlags {
ALLOC_CLEAR_BUFFER = 1
};
/**
* Interface for TextureClients that can be updated using a gfxASurface.
*/
class TextureClientSurface
{
public:
virtual bool UpdateSurface(gfxASurface* aSurface) = 0;
virtual already_AddRefed<gfxASurface> GetAsSurface() = 0;
/**
* 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.
*/
virtual bool AllocateForSurface(gfx::IntSize aSize,
TextureAllocationFlags flags = ALLOC_DEFAULT) = 0;
};
/**
* Interface for TextureClients that can be updated using a DrawTarget.
*/
class TextureClientDrawTarget
{
public:
/**
* Returns a DrawTarget to draw into the TextureClient.
*
* This must never be called on a TextureClient that is not sucessfully locked.
* When called several times within one Lock/Unlock pair, this method should
* return the same DrawTarget.
* The DrawTarget is automatically flushed by the TextureClient when the latter
* is unlocked, and the DrawTarget that will be returned within the next
* lock/unlock pair may or may not be the same object.
* Do not keep references to the DrawTarget outside of the lock/unlock pair.
*
* This is typically used as follows:
*
* if (!texture->Lock(OPEN_READ_WRITE)) {
* return false;
* }
* {
* // Restrict this code's scope to ensure all references to dt are gone
* // when Unlock is called.
* RefPtr<DrawTarget> dt = texture->AsTextureClientDrawTarget()->GetAsDrawTarget();
* // use the draw target ...
* }
* texture->Unlock();
*
*/
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() = 0;
virtual gfx::SurfaceFormat GetFormat() const = 0;
/**
* 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.
*/
virtual bool AllocateForSurface(gfx::IntSize aSize,
TextureAllocationFlags flags = ALLOC_DEFAULT) = 0;
};
/**
* Interface for TextureClients that can be updated using YCbCr data.
*/
@ -149,6 +212,8 @@ public:
gfx::BackendType aMoz2dBackend,
const gfx::IntSize& aSizeHint);
virtual TextureClientSurface* AsTextureClientSurface() { return nullptr; }
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; }
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
/**
@ -163,47 +228,6 @@ public:
virtual bool IsLocked() const = 0;
virtual bool CanExposeDrawTarget() const { return false; }
/**
* Returns a DrawTarget to draw into the TextureClient.
*
* This must never be called on a TextureClient that is not sucessfully locked.
* When called several times within one Lock/Unlock pair, this method should
* return the same DrawTarget.
* The DrawTarget is automatically flushed by the TextureClient when the latter
* is unlocked, and the DrawTarget that will be returned within the next
* lock/unlock pair may or may not be the same object.
* Do not keep references to the DrawTarget outside of the lock/unlock pair.
*
* This is typically used as follows:
*
* if (!texture->Lock(OPEN_READ_WRITE)) {
* return false;
* }
* {
* // Restrict this code's scope to ensure all references to dt are gone
* // when Unlock is called.
* RefPtr<DrawTarget> dt = texture->GetAsDrawTarget();
* // use the draw target ...
* }
* texture->Unlock();
*
*/
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() { return nullptr; }
virtual gfx::SurfaceFormat GetFormat() const = 0;
/**
* 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.
*/
virtual bool AllocateForSurface(gfx::IntSize aSize,
TextureAllocationFlags flags = ALLOC_DEFAULT) = 0;
/**
* 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
@ -372,7 +396,9 @@ protected:
* (see ShmemTextureClient and MemoryTextureClient)
*/
class BufferTextureClient : public TextureClient
, public TextureClientSurface
, public TextureClientYCbCr
, public TextureClientDrawTarget
{
public:
BufferTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat,
@ -394,13 +420,23 @@ public:
virtual bool IsLocked() const MOZ_OVERRIDE { return mLocked; }
virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
// TextureClientSurface
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
virtual TextureClientSurface* AsTextureClientSurface() MOZ_OVERRIDE { return this; }
virtual bool UpdateSurface(gfxASurface* aSurface) MOZ_OVERRIDE;
virtual already_AddRefed<gfxASurface> GetAsSurface() MOZ_OVERRIDE;
virtual bool AllocateForSurface(gfx::IntSize aSize,
TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE;
// TextureClientDrawTarget
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() MOZ_OVERRIDE { return this; }
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
// TextureClientYCbCr
virtual TextureClientYCbCr* AsTextureClientYCbCr() MOZ_OVERRIDE { return this; }

Просмотреть файл

@ -62,7 +62,7 @@ TextureClientPool::GetTextureClient()
textureClient = TextureClient::CreateTextureClientForDrawing(mSurfaceAllocator,
mFormat, TEXTURE_IMMEDIATE_UPLOAD, gfx::BackendType::NONE, mSize);
}
textureClient->AllocateForSurface(mSize, ALLOC_DEFAULT);
textureClient->AsTextureClientDrawTarget()->AllocateForSurface(mSize, ALLOC_DEFAULT);
return textureClient;
}

Просмотреть файл

@ -472,7 +472,7 @@ TileClient::DiscardFrontBuffer()
{
if (mFrontBuffer) {
MOZ_ASSERT(mFrontLock);
mManager->GetTexturePool(mFrontBuffer->GetFormat())->ReturnTextureClientDeferred(mFrontBuffer);
mManager->GetTexturePool(mFrontBuffer->AsTextureClientDrawTarget()->GetFormat())->ReturnTextureClientDeferred(mFrontBuffer);
mFrontLock->ReadUnlock();
mFrontBuffer = nullptr;
mFrontLock = nullptr;
@ -484,7 +484,7 @@ TileClient::DiscardBackBuffer()
{
if (mBackBuffer) {
MOZ_ASSERT(mBackLock);
mManager->GetTexturePool(mBackBuffer->GetFormat())->ReturnTextureClient(mBackBuffer);
mManager->GetTexturePool(mBackBuffer->AsTextureClientDrawTarget()->GetFormat())->ReturnTextureClient(mBackBuffer);
mBackLock->ReadUnlock();
mBackBuffer = nullptr;
mBackLock = nullptr;
@ -750,7 +750,7 @@ ClientTiledLayerBuffer::ValidateTile(TileClient aTile,
// We must not keep a reference to the DrawTarget after it has been unlocked,
// make sure these are null'd before unlocking as destruction of the context
// may cause the target to be flushed.
RefPtr<DrawTarget> drawTarget = backBuffer->GetAsDrawTarget();
RefPtr<DrawTarget> drawTarget = backBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget();
drawTarget->SetTransform(Matrix());
RefPtr<gfxContext> ctxt = new gfxContext(drawTarget);

Просмотреть файл

@ -8,14 +8,14 @@
#include "mozilla/layers/TextureHost.h"
#include "mozilla/layers/LayersSurfaces.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/gfx/2D.h"
class gfxXlibSurface;
namespace mozilla {
namespace layers {
// TextureHost for Xlib-backed TextureSources.
// TextureSource for Xlib-backed TextureSources.
class X11TextureHost : public TextureHost
{
public:
@ -23,11 +23,8 @@ public:
const SurfaceDescriptorX11& aDescriptor);
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE

Просмотреть файл

@ -25,7 +25,8 @@ class CompositorD3D11;
* A TextureClient to share a D3D10 texture with the compositor thread.
* The corresponding TextureHost is DXGITextureHostD3D11
*/
class TextureClientD3D11 : public TextureClient
class TextureClientD3D11 : public TextureClient,
public TextureClientDrawTarget
{
public:
TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
@ -52,9 +53,11 @@ public:
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE { return nullptr; }
// TextureClientDrawTarget
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() MOZ_OVERRIDE { return this; }
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;

Просмотреть файл

@ -185,6 +185,7 @@ protected:
* The corresponding TextureHost is TextureHostD3D9.
*/
class CairoTextureClientD3D9 : public TextureClient
, public TextureClientDrawTarget
{
public:
CairoTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
@ -209,6 +210,10 @@ public:
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE;
// TextureClientDrawTarget
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() MOZ_OVERRIDE { return this; }
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
virtual bool AllocateForSurface(gfx::IntSize aSize,
@ -234,6 +239,7 @@ private:
* The coresponding TextureHost is DIBTextureHostD3D9.
*/
class DIBTextureClientD3D9 : public TextureClient
, public TextureClientDrawTarget
{
public:
DIBTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
@ -258,7 +264,9 @@ public:
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE;
virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
// TextureClientDrawTarget
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() MOZ_OVERRIDE { return this; }
virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
@ -314,16 +322,6 @@ public:
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
{
return gfx::SurfaceFormat::UNKNOWN;
}
virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
{
return false;
}
private:
RefPtr<IDirect3DTexture9> mTexture;
gfx::SurfaceFormat mFormat;
@ -395,8 +393,6 @@ public:
virtual void Updated(const nsIntRegion* aRegion = nullptr);
virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // TODO: cf bug 872568

Просмотреть файл

@ -64,16 +64,6 @@ public:
return nullptr;
}
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
{
return gfx::SurfaceFormat::UNKNOWN;
}
virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
{
return false;
}
protected:
gl::SharedTextureHandle mHandle;
gfx::IntSize mSize;
@ -110,16 +100,6 @@ public:
virtual gfx::IntSize GetSize() const { return gfx::IntSize(); }
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
{
return gfx::SurfaceFormat::UNKNOWN;
}
virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
{
return false;
}
protected:
bool mIsLocked;
RefPtr<gfx::SurfaceStream> mStream;

Просмотреть файл

@ -16,8 +16,8 @@ namespace layers {
// TextureSource for Xlib-backed surfaces.
class X11TextureSourceOGL
: public TextureSourceOGL
, public NewTextureSource
: public TextureSourceOGL,
public NewTextureSource
{
public:
X11TextureSourceOGL(CompositorOGL* aCompositor, gfxXlibSurface* aSurface);
@ -26,23 +26,21 @@ public:
virtual X11TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
virtual bool IsValid() const MOZ_OVERRIDE { return !!gl(); } ;
virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual GLenum GetTextureTarget() const MOZ_OVERRIDE { return LOCAL_GL_TEXTURE_2D; }
virtual GLenum GetTextureTarget() const MOZ_OVERRIDE {
return LOCAL_GL_TEXTURE_2D;
}
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; }
virtual GLenum GetWrapMode() const MOZ_OVERRIDE {
return LOCAL_GL_CLAMP_TO_EDGE;
}
virtual void DeallocateDeviceData() MOZ_OVERRIDE;
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
gl::GLContext* gl() const;
static gfx::SurfaceFormat ContentTypeToSurfaceFormat(gfxContentType aType);
protected:

Просмотреть файл

@ -9,7 +9,8 @@
#include "mozilla/layers/TextureClient.h"
#include "mozilla/layers/TextureHost.h"
#include "gfx2DGlue.h"
#include "mozilla/gfx/Tools.h"
#include "gfxImageSurface.h"
#include "gfxTypes.h"
#include "ImageContainer.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
@ -31,14 +32,13 @@ using namespace mozilla::layers;
// fills the surface with values betwee 0 and 100.
void SetupSurface(gfx::DataSourceSurface* surface) {
uint8_t* data = surface->GetData();
gfx::IntSize size = surface->GetSize();
uint32_t stride = surface->Stride();
int bpp = gfx::BytesPerPixel(surface->GetFormat());
void SetupSurface(gfxImageSurface* surface) {
int bpp = gfxASurface::BytePerPixelFromFormat(surface->Format());
int stride = surface->Stride();
uint8_t val = 0;
for (int y = 0; y < size.width; ++y) {
for (int x = 0; x < size.height; ++x) {
uint8_t* data = surface->Data();
for (int y = 0; y < surface->Height(); ++y) {
for (int x = 0; x < surface->Height(); ++x) {
for (int b = 0; b < bpp; ++b) {
data[y*stride + x*bpp + b] = val;
if (val == 100) {
@ -52,20 +52,20 @@ void SetupSurface(gfx::DataSourceSurface* surface) {
}
// return true if two surfaces contain the same data
void AssertSurfacesEqual(gfx::DataSourceSurface* surface1,
gfx::DataSourceSurface* surface2)
void AssertSurfacesEqual(gfxImageSurface* surface1,
gfxImageSurface* surface2)
{
ASSERT_EQ(surface1->GetSize(), surface2->GetSize());
ASSERT_EQ(surface1->GetFormat(), surface2->GetFormat());
ASSERT_EQ(surface1->Format(), surface2->Format());
uint8_t* data1 = surface1->GetData();
uint8_t* data2 = surface2->GetData();
uint8_t* data1 = surface1->Data();
uint8_t* data2 = surface2->Data();
int stride1 = surface1->Stride();
int stride2 = surface2->Stride();
int bpp = gfx::BytesPerPixel(surface1->GetFormat());
int bpp = gfxASurface::BytePerPixelFromFormat(surface1->Format());
for (int y = 0; y < surface1->GetSize().height; ++y) {
for (int x = 0; x < surface1->GetSize().width; ++x) {
for (int y = 0; y < surface1->Height(); ++y) {
for (int x = 0; x < surface1->Width(); ++x) {
for (int b = 0; b < bpp; ++b) {
ASSERT_EQ(data1[y*stride1 + x*bpp + b],
data2[y*stride2 + x*bpp + b]);
@ -100,18 +100,22 @@ void AssertYCbCrSurfacesEqual(PlanarYCbCrData* surface1,
}
// Run the test for a texture client and a surface
void TestTextureClientSurface(TextureClient* texture, gfx::DataSourceSurface* surface) {
void TestTextureClientSurface(TextureClient* texture, gfxImageSurface* surface) {
// client allocation
ASSERT_TRUE(texture->CanExposeDrawTarget());
texture->AllocateForSurface(surface->GetSize());
ASSERT_TRUE(texture->AsTextureClientSurface() != nullptr);
TextureClientSurface* client = texture->AsTextureClientSurface();
client->AllocateForSurface(ToIntSize(surface->GetSize()));
ASSERT_TRUE(texture->IsAllocated());
ASSERT_TRUE(texture->Lock(OPEN_READ_WRITE));
// client painting
RefPtr<DrawTarget> dt = texture->GetAsDrawTarget();
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
dt = nullptr;
client->UpdateSurface(surface);
nsRefPtr<gfxASurface> aSurface = client->GetAsSurface();
nsRefPtr<gfxImageSurface> clientSurface = aSurface->GetAsImageSurface();
AssertSurfacesEqual(surface, clientSurface);
texture->Unlock();
// client serialization
@ -130,9 +134,14 @@ void TestTextureClientSurface(TextureClient* texture, gfx::DataSourceSurface* su
// host read
ASSERT_TRUE(host->Lock());
RefPtr<mozilla::gfx::DataSourceSurface> hostDataSurface = host->GetAsSurface();
AssertSurfacesEqual(surface, hostDataSurface);
host->Unlock();
nsRefPtr<gfxImageSurface> hostSurface =
new gfxImageSurface(hostDataSurface->GetData(),
ThebesIntSize(hostDataSurface->GetSize()),
hostDataSurface->Stride(),
SurfaceFormatToImageFormat(hostDataSurface->GetFormat()));
AssertSurfacesEqual(surface, hostSurface.get());
}
// Same as above, for YCbCr surfaces
@ -196,21 +205,20 @@ void TestTextureClientYCbCr(TextureClient* client, PlanarYCbCrData& ycbcrData) {
TEST(Layers, TextureSerialization) {
// the test is run on all the following image formats
gfx::SurfaceFormat formats[3] = {
gfx::SurfaceFormat::B8G8R8A8,
gfx::SurfaceFormat::R8G8B8X8,
gfx::SurfaceFormat::A8,
gfxImageFormat formats[3] = {
gfxImageFormat::ARGB32,
gfxImageFormat::RGB24,
gfxImageFormat::A8,
};
for (int f = 0; f < 3; ++f) {
RefPtr<gfx::DataSourceSurface> surface =
gfx::Factory::CreateDataSourceSurface(gfx::IntSize(400,300), formats[f]);
SetupSurface(surface);
RefPtr<gfxImageSurface> surface = new gfxImageSurface(gfxIntSize(400,300), formats[f]);
SetupSurface(surface.get());
AssertSurfacesEqual(surface, surface);
RefPtr<TextureClient> client
= new MemoryTextureClient(nullptr,
surface->GetFormat(),
mozilla::gfx::ImageFormatToSurfaceFormat(surface->Format()),
gfx::BackendType::CAIRO,
TEXTURE_DEALLOCATE_CLIENT);
@ -221,24 +229,20 @@ TEST(Layers, TextureSerialization) {
}
TEST(Layers, TextureYCbCrSerialization) {
RefPtr<gfx::DataSourceSurface> ySurface = gfx::Factory::CreateDataSourceSurface(
IntSize(400,300), gfx::SurfaceFormat::A8);
RefPtr<gfx::DataSourceSurface> cbSurface = gfx::Factory::CreateDataSourceSurface(
IntSize(200,150), gfx::SurfaceFormat::A8);
RefPtr<gfx::DataSourceSurface> crSurface = gfx::Factory::CreateDataSourceSurface(
IntSize(200,150), gfx::SurfaceFormat::A8);
RefPtr<gfxImageSurface> ySurface = new gfxImageSurface(gfxIntSize(400,300), gfxImageFormat::A8);
RefPtr<gfxImageSurface> cbSurface = new gfxImageSurface(gfxIntSize(200,150), gfxImageFormat::A8);
RefPtr<gfxImageSurface> crSurface = new gfxImageSurface(gfxIntSize(200,150), gfxImageFormat::A8);
SetupSurface(ySurface.get());
SetupSurface(cbSurface.get());
SetupSurface(crSurface.get());
PlanarYCbCrData clientData;
clientData.mYChannel = ySurface->GetData();
clientData.mCbChannel = cbSurface->GetData();
clientData.mCrChannel = crSurface->GetData();
clientData.mYSize = ySurface->GetSize();
clientData.mPicSize = ySurface->GetSize();
clientData.mCbCrSize = cbSurface->GetSize();
clientData.mYChannel = ySurface->Data();
clientData.mCbChannel = cbSurface->Data();
clientData.mCrChannel = crSurface->Data();
clientData.mYSize = ySurface->GetSize().ToIntSize();
clientData.mPicSize = ySurface->GetSize().ToIntSize();
clientData.mCbCrSize = cbSurface->GetSize().ToIntSize();
clientData.mYStride = ySurface->Stride();
clientData.mCbCrStride = cbSurface->Stride();
clientData.mStereoMode = StereoMode::MONO;