Bug 1200595 - MacIOSurface TextureData implementation. r=mattwoodrow

This commit is contained in:
Nicolas Silva 2015-11-20 14:24:46 +01:00
Родитель 24e78db7d5
Коммит 424ec279d9
3 изменённых файлов: 53 добавлений и 83 удалений

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

@ -18,9 +18,11 @@ TextureClient*
MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
{
if (!mTextureClient) {
mTextureClient = MacIOSurfaceTextureClientOGL::Create(aClient->GetForwarder(),
mTextureClient = TextureClient::CreateWithData(
MacIOSurfaceTextureData::Create(mSurface),
TextureFlags::DEFAULT,
mSurface);
aClient->GetForwarder()
);
}
return mTextureClient;
}

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

@ -9,66 +9,37 @@
namespace mozilla {
namespace layers {
MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator,
TextureFlags aFlags)
: TextureClient(aAllcator, aFlags)
, mIsLocked(false)
{}
MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL()
MacIOSurfaceTextureData::MacIOSurfaceTextureData(MacIOSurface* aSurface)
: mSurface(aSurface)
{
MOZ_ASSERT(mSurface);
}
MacIOSurfaceTextureData::~MacIOSurfaceTextureData()
{}
void
MacIOSurfaceTextureClientOGL::FinalizeOnIPDLThread()
MacIOSurfaceTextureData::FinalizeOnIPDLThread(TextureClient* aWrapper)
{
if (mActor && mSurface) {
KeepUntilFullDeallocation(MakeUnique<TKeepAlive<MacIOSurface>>(mSurface));
if (mSurface) {
aWrapper->KeepUntilFullDeallocation(MakeUnique<TKeepAlive<MacIOSurface>>(mSurface));
}
}
// static
already_AddRefed<MacIOSurfaceTextureClientOGL>
MacIOSurfaceTextureClientOGL::Create(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
MacIOSurface* aSurface)
MacIOSurfaceTextureData*
MacIOSurfaceTextureData::Create(MacIOSurface* aSurface)
{
RefPtr<MacIOSurfaceTextureClientOGL> texture =
new MacIOSurfaceTextureClientOGL(aAllocator, aFlags);
MOZ_ASSERT(texture->IsValid());
MOZ_ASSERT(!texture->IsAllocated());
texture->mSurface = aSurface;
return texture.forget();
MOZ_ASSERT(aSurface);
if (!aSurface) {
return nullptr;
}
return new MacIOSurfaceTextureData(aSurface);
}
bool
MacIOSurfaceTextureClientOGL::Lock(OpenMode aMode)
MacIOSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(!mIsLocked);
mIsLocked = true;
return IsValid() && IsAllocated();
}
void
MacIOSurfaceTextureClientOGL::Unlock()
{
MOZ_ASSERT(mIsLocked);
mIsLocked = false;
}
bool
MacIOSurfaceTextureClientOGL::IsLocked() const
{
return mIsLocked;
}
bool
MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(IsValid());
if (!IsAllocated()) {
return false;
}
aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(),
mSurface->GetContentsScaleFactor(),
!mSurface->HasAlpha());
@ -76,13 +47,19 @@ MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescrip
}
gfx::IntSize
MacIOSurfaceTextureClientOGL::GetSize() const
MacIOSurfaceTextureData::GetSize() const
{
return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
}
gfx::SurfaceFormat
MacIOSurfaceTextureData::GetFormat() const
{
return mSurface->GetFormat();
}
already_AddRefed<gfx::DataSourceSurface>
MacIOSurfaceTextureClientOGL::GetAsSurface()
MacIOSurfaceTextureData::GetAsSurface()
{
RefPtr<gfx::SourceSurface> surf = mSurface->GetAsSurface();
return surf->GetDataSurface();

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

@ -13,47 +13,38 @@ class MacIOSurface;
namespace mozilla {
namespace layers {
class MacIOSurfaceTextureClientOGL : public TextureClient
class MacIOSurfaceTextureData : public TextureData
{
public:
explicit MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator,
TextureFlags aFlags);
static MacIOSurfaceTextureData* Create(MacIOSurface* aSurface);
virtual ~MacIOSurfaceTextureClientOGL();
// Creates a TextureClient and init width.
static already_AddRefed<MacIOSurfaceTextureClientOGL>
Create(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
MacIOSurface* aSurface);
virtual bool Lock(OpenMode aMode) override;
virtual void Unlock() override;
virtual bool IsLocked() const override;
virtual bool IsAllocated() const override { return !!mSurface; }
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override;
~MacIOSurfaceTextureData();
virtual gfx::IntSize GetSize() const override;
virtual gfx::SurfaceFormat GetFormat() const override;
virtual bool Lock(OpenMode, FenceHandle*) override { return true; }
virtual void Unlock() override {}
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
virtual bool HasInternalBuffer() const override { return false; }
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
virtual void Deallocate(ISurfaceAllocator* aAllocator) override { mSurface = nullptr; }
// This TextureClient should not be used in a context where we use CreateSimilar
// (ex. component alpha) because the underlying texture data is always created by
// an external producer.
virtual already_AddRefed<TextureClient>
CreateSimilar(TextureFlags, TextureAllocationFlags) const override { return nullptr; }
virtual void Forget(ISurfaceAllocator* aAllocator) override { mSurface = nullptr; }
// For debugging purposes only.
already_AddRefed<gfx::DataSourceSurface> GetAsSurface();
protected:
virtual void FinalizeOnIPDLThread() override;
explicit MacIOSurfaceTextureData(MacIOSurface* aSurface);
virtual void FinalizeOnIPDLThread(TextureClient* aWrapper) override;
RefPtr<MacIOSurface> mSurface;
bool mIsLocked;
};
} // namespace layers