Bug 1155495 - Part 1: Remove TextureHostOGL and integrate the platform specific API into TextureHost. r=nical, r=sotaro

This commit is contained in:
Jeremy Chen 2015-05-22 02:25:00 -04:00
Родитель 29b4ee90d8
Коммит 179b1de266
6 изменённых файлов: 95 добавлений и 115 удалений

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

@ -144,10 +144,39 @@ TextureHost::GetIPDLActor()
return mActor;
}
bool
TextureHost::SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle)
{
if (!aReleaseFenceHandle.IsValid()) {
// HWC might not provide Fence.
// In this case, HWC implicitly handles buffer's fence.
return false;
}
mReleaseFenceHandle.Merge(aReleaseFenceHandle);
return true;
}
FenceHandle
TextureHost::GetAndResetReleaseFenceHandle()
{
return FenceHandle();
FenceHandle fence;
mReleaseFenceHandle.TransferToAnotherFenceHandle(fence);
return fence;
}
void
TextureHost::SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle)
{
mAcquireFenceHandle = aAcquireFenceHandle;
}
FenceHandle
TextureHost::GetAndResetAcquireFenceHandle()
{
nsRefPtr<FenceHandle::FdObj> fdObj = mAcquireFenceHandle.GetAndResetFdObj();
return FenceHandle(fdObj);
}
// implemented in TextureHostOGL.cpp

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

@ -470,8 +470,6 @@ public:
*/
PTextureParent* GetIPDLActor();
virtual FenceHandle GetAndResetReleaseFenceHandle();
/**
* Specific to B2G's Composer2D
* XXX - more doc here
@ -518,7 +516,31 @@ public:
int NumCompositableRefs() const { return mCompositableCount; }
/**
* Store a fence that will signal when the current buffer is no longer being read.
* Similar to android's GLConsumer::setReleaseFence()
*/
bool SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle);
/**
* Return a releaseFence's Fence and clear a reference to the Fence.
*/
FenceHandle GetAndResetReleaseFenceHandle();
void SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle);
/**
* Return a acquireFence's Fence and clear a reference to the Fence.
*/
FenceHandle GetAndResetAcquireFenceHandle();
virtual void WaitAcquireFenceHandleSyncComplete() {};
protected:
FenceHandle mReleaseFenceHandle;
FenceHandle mAcquireFenceHandle;
void RecycleTexture(TextureFlags aFlags);
PTextureParent* mActor;

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

@ -8,6 +8,7 @@
#include "gfx2DGlue.h"
#include <ui/GraphicBuffer.h>
#include "GrallocImages.h" // for GrallocImage
#include "GLLibraryEGL.h" // for GLLibraryEGL
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/layers/GrallocTextureHost.h"
@ -19,6 +20,7 @@ namespace mozilla {
namespace layers {
using namespace android;
using namespace mozilla::gl;
static gfx::SurfaceFormat
SurfaceFormatForAndroidPixelFormat(android::PixelFormat aFormat,
@ -263,12 +265,6 @@ GrallocTextureHostOGL::UnbindTextureSource()
mGLTextureSource = nullptr;
}
FenceHandle
GrallocTextureHostOGL::GetAndResetReleaseFenceHandle()
{
return GetAndResetReleaseFence();
}
GLenum GetTextureTarget(gl::GLContext* aGL, android::PixelFormat aFormat) {
MOZ_ASSERT(aGL);
if (aGL->Renderer() == gl::GLRenderer::SGX530 ||
@ -382,6 +378,42 @@ GrallocTextureHostOGL::PrepareTextureSource(CompositableTextureSourceRef& aTextu
}
}
void
GrallocTextureHostOGL::WaitAcquireFenceHandleSyncComplete()
{
if (!mAcquireFenceHandle.IsValid()) {
return;
}
nsRefPtr<FenceHandle::FdObj> fence = mAcquireFenceHandle.GetAndResetFdObj();
int fenceFd = fence->GetAndResetFd();
EGLint attribs[] = {
LOCAL_EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd,
LOCAL_EGL_NONE
};
EGLSync sync = sEGLLibrary.fCreateSync(EGL_DISPLAY(),
LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID,
attribs);
if (!sync) {
NS_WARNING("failed to create native fence sync");
return;
}
// Wait sync complete with timeout.
// If a source of the fence becomes invalid because of error,
// fene complete is not signaled. See Bug 1061435.
EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(),
sync,
0,
400000000 /*400 usec*/);
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
NS_ERROR("failed to wait native fence sync");
}
MOZ_ALWAYS_TRUE( sEGLLibrary.fDestroySync(EGL_DISPLAY(), sync) );
}
bool
GrallocTextureHostOGL::BindTextureSource(CompositableTextureSourceRef& aTextureSource)
{
@ -400,7 +432,7 @@ GrallocTextureHostOGL::BindTextureSource(CompositableTextureSourceRef& aTextureS
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
// Wait until it's ready.
WaitAcquireFenceSyncComplete();
WaitAcquireFenceHandleSyncComplete();
#endif
return true;
}

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

@ -51,8 +51,6 @@ public:
virtual void UnbindTextureSource() override;
virtual FenceHandle GetAndResetReleaseFenceHandle() override;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
virtual TextureHostOGL* AsHostOGL() override
{
@ -62,6 +60,8 @@ public:
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() override;
virtual void WaitAcquireFenceHandleSyncComplete() override;
bool IsValid() const;
virtual const char* Name() override { return "GrallocTextureHostOGL"; }

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

@ -110,77 +110,6 @@ FlagsToGLFlags(TextureFlags aFlags)
return static_cast<gl::TextureImage::Flags>(result);
}
bool
TextureHostOGL::SetReleaseFence(const FenceHandle& aReleaseFence)
{
if (!aReleaseFence.IsValid()) {
// HWC might not provide Fence.
// In this case, HWC implicitly handles buffer's fence.
return false;
}
mReleaseFence.Merge(aReleaseFence);
return true;
}
FenceHandle
TextureHostOGL::GetAndResetReleaseFence()
{
FenceHandle fence;
mReleaseFence.TransferToAnotherFenceHandle(fence);
return fence;
}
void
TextureHostOGL::SetAcquireFence(const FenceHandle& aAcquireFence)
{
mAcquireFence = aAcquireFence;
}
FenceHandle
TextureHostOGL::GetAndResetAcquireFence()
{
nsRefPtr<FenceHandle::FdObj> fdObj = mAcquireFence.GetAndResetFdObj();
return FenceHandle(fdObj);
}
void
TextureHostOGL::WaitAcquireFenceSyncComplete()
{
if (!mAcquireFence.IsValid()) {
return;
}
nsRefPtr<FenceHandle::FdObj> fence = mAcquireFence.GetAndResetFdObj();
int fenceFd = fence->GetAndResetFd();
EGLint attribs[] = {
LOCAL_EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd,
LOCAL_EGL_NONE
};
EGLSync sync = sEGLLibrary.fCreateSync(EGL_DISPLAY(),
LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID,
attribs);
if (!sync) {
NS_WARNING("failed to create native fence sync");
return;
}
// Wait sync complete with timeout.
// If a source of the fence becomes invalid because of error,
// fene complete is not signaled. See Bug 1061435.
EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(),
sync,
0,
400000000 /*400 usec*/);
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
NS_ERROR("failed to wait native fence sync");
}
MOZ_ALWAYS_TRUE( sEGLLibrary.fDestroySync(EGL_DISPLAY(), sync) );
}
bool
TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
nsIntRegion* aDestRegion,

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

@ -122,38 +122,6 @@ private:
bool mHasCachedFilter;
};
/**
* TextureHostOGL provides the necessary API for platform specific composition.
*/
class TextureHostOGL
{
public:
/**
* Store a fence that will signal when the current buffer is no longer being read.
* Similar to android's GLConsumer::setReleaseFence()
*/
virtual bool SetReleaseFence(const FenceHandle& aReleaseFence);
/**
* Return a releaseFence's Fence and clear a reference to the Fence.
*/
virtual FenceHandle GetAndResetReleaseFence();
virtual void SetAcquireFence(const FenceHandle& aAcquireFence);
/**
* Return a acquireFence's Fence and clear a reference to the Fence.
*/
virtual FenceHandle GetAndResetAcquireFence();
virtual void WaitAcquireFenceSyncComplete();
protected:
FenceHandle mReleaseFence;
FenceHandle mAcquireFence;
};
/**
* A TextureSource backed by a TextureImage.
*