mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1113789 - Remove GrallocTextureSourceOGL r=nical
This commit is contained in:
parent
838a07863b
commit
56f126bbf2
@ -96,150 +96,6 @@ TextureTargetForAndroidPixelFormat(android::PixelFormat aFormat)
|
||||
}
|
||||
}
|
||||
|
||||
GrallocTextureSourceOGL::GrallocTextureSourceOGL(CompositorOGL* aCompositor,
|
||||
GrallocTextureHostOGL* aTextureHost,
|
||||
android::GraphicBuffer* aGraphicBuffer,
|
||||
gfx::SurfaceFormat aFormat)
|
||||
: mCompositor(aCompositor)
|
||||
, mTextureHost(aTextureHost)
|
||||
, mGraphicBuffer(aGraphicBuffer)
|
||||
, mEGLImage(0)
|
||||
, mFormat(aFormat)
|
||||
, mNeedsReset(true)
|
||||
{
|
||||
MOZ_ASSERT(mGraphicBuffer.get());
|
||||
}
|
||||
|
||||
GrallocTextureSourceOGL::~GrallocTextureSourceOGL()
|
||||
{
|
||||
DeallocateDeviceData();
|
||||
mCompositor = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
GrallocTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
|
||||
{
|
||||
/*
|
||||
* The job of this function is to ensure that the texture is tied to the
|
||||
* android::GraphicBuffer, so that texturing will source the GraphicBuffer.
|
||||
*
|
||||
* To this effect we create an EGLImage wrapping this GraphicBuffer,
|
||||
* using EGLImageCreateFromNativeBuffer, and then we tie this EGLImage to our
|
||||
* texture using fEGLImageTargetTexture2D.
|
||||
*/
|
||||
MOZ_ASSERT(gl());
|
||||
if (!IsValid() || !gl()->MakeCurrent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GLuint tex = GetGLTexture();
|
||||
GLuint textureTarget = GetTextureTarget();
|
||||
|
||||
gl()->fActiveTexture(aTextureUnit);
|
||||
gl()->fBindTexture(textureTarget, tex);
|
||||
|
||||
ApplyFilterToBoundTexture(gl(), aFilter, textureTarget);
|
||||
|
||||
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
||||
if (mTextureHost) {
|
||||
// Wait until it's ready.
|
||||
mTextureHost->WaitAcquireFenceSyncComplete();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GrallocTextureSourceOGL::Lock()
|
||||
{
|
||||
MOZ_ASSERT(IsValid());
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
if (!gl()->MakeCurrent()) {
|
||||
NS_WARNING("Failed to make the gl context current");
|
||||
return false;
|
||||
}
|
||||
|
||||
mTexture = mCompositor->GetTemporaryTexture(GetTextureTarget(), LOCAL_GL_TEXTURE0);
|
||||
|
||||
GLuint textureTarget = GetTextureTarget();
|
||||
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl()->fBindTexture(textureTarget, mTexture);
|
||||
if (!mEGLImage) {
|
||||
mEGLImage = EGLImageCreateFromNativeBuffer(gl(), mGraphicBuffer->getNativeBuffer());
|
||||
}
|
||||
gl()->fEGLImageTargetTexture2D(textureTarget, mEGLImage);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GrallocTextureSourceOGL::IsValid() const
|
||||
{
|
||||
return !!gl() && !!mGraphicBuffer.get() && !!mCompositor;
|
||||
}
|
||||
|
||||
gl::GLContext*
|
||||
GrallocTextureSourceOGL::gl() const
|
||||
{
|
||||
return mCompositor ? mCompositor->gl() : nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
GrallocTextureSourceOGL::SetCompositor(Compositor* aCompositor)
|
||||
{
|
||||
if (mCompositor && !aCompositor) {
|
||||
DeallocateDeviceData();
|
||||
}
|
||||
mCompositor = static_cast<CompositorOGL*>(aCompositor);
|
||||
}
|
||||
|
||||
|
||||
GLenum
|
||||
GrallocTextureSourceOGL::GetTextureTarget() const
|
||||
{
|
||||
MOZ_ASSERT(gl());
|
||||
MOZ_ASSERT(mGraphicBuffer.get());
|
||||
|
||||
if (!gl() || !mGraphicBuffer.get()) {
|
||||
return LOCAL_GL_TEXTURE_EXTERNAL;
|
||||
}
|
||||
|
||||
// SGX has a quirk that only TEXTURE_EXTERNAL works and any other value will
|
||||
// result in black pixels when trying to draw from bound textures.
|
||||
// Unfortunately, using TEXTURE_EXTERNAL on Adreno has a terrible effect on
|
||||
// performance.
|
||||
// See Bug 950050.
|
||||
if (gl()->Renderer() == gl::GLRenderer::SGX530 ||
|
||||
gl()->Renderer() == gl::GLRenderer::SGX540) {
|
||||
return LOCAL_GL_TEXTURE_EXTERNAL;
|
||||
}
|
||||
|
||||
return TextureTargetForAndroidPixelFormat(mGraphicBuffer->getPixelFormat());
|
||||
}
|
||||
|
||||
gfx::IntSize
|
||||
GrallocTextureSourceOGL::GetSize() const
|
||||
{
|
||||
if (!IsValid()) {
|
||||
NS_WARNING("Trying to access the size of an invalid GrallocTextureSourceOGL");
|
||||
return gfx::IntSize(0, 0);
|
||||
}
|
||||
return gfx::IntSize(mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight());
|
||||
}
|
||||
|
||||
void
|
||||
GrallocTextureSourceOGL::DeallocateDeviceData()
|
||||
{
|
||||
if (mEGLImage) {
|
||||
MOZ_ASSERT(mCompositor);
|
||||
if (!gl() || !gl()->MakeCurrent()) {
|
||||
return;
|
||||
}
|
||||
EGLImageDestroy(gl(), mEGLImage);
|
||||
mEGLImage = EGL_NO_IMAGE;
|
||||
}
|
||||
}
|
||||
|
||||
GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags,
|
||||
const NewSurfaceDescriptorGralloc& aDescriptor)
|
||||
: TextureHost(aFlags)
|
||||
@ -272,9 +128,6 @@ void
|
||||
GrallocTextureHostOGL::SetCompositor(Compositor* aCompositor)
|
||||
{
|
||||
mCompositor = static_cast<CompositorOGL*>(aCompositor);
|
||||
if (mTilingTextureSource) {
|
||||
mTilingTextureSource->SetCompositor(mCompositor);
|
||||
}
|
||||
if (mGLTextureSource) {
|
||||
mGLTextureSource->SetCompositor(mCompositor);
|
||||
}
|
||||
@ -312,10 +165,6 @@ GrallocTextureHostOGL::GetFormat() const
|
||||
void
|
||||
GrallocTextureHostOGL::DeallocateSharedData()
|
||||
{
|
||||
if (mTilingTextureSource) {
|
||||
mTilingTextureSource->ForgetBuffer();
|
||||
mTilingTextureSource = nullptr;
|
||||
}
|
||||
if (mGLTextureSource) {
|
||||
mGLTextureSource = nullptr;
|
||||
}
|
||||
@ -339,10 +188,6 @@ GrallocTextureHostOGL::DeallocateSharedData()
|
||||
void
|
||||
GrallocTextureHostOGL::ForgetSharedData()
|
||||
{
|
||||
if (mTilingTextureSource) {
|
||||
mTilingTextureSource->ForgetBuffer();
|
||||
mTilingTextureSource = nullptr;
|
||||
}
|
||||
if (mGLTextureSource) {
|
||||
mGLTextureSource = nullptr;
|
||||
}
|
||||
@ -351,9 +196,6 @@ GrallocTextureHostOGL::ForgetSharedData()
|
||||
void
|
||||
GrallocTextureHostOGL::DeallocateDeviceData()
|
||||
{
|
||||
if (mTilingTextureSource) {
|
||||
mTilingTextureSource->DeallocateDeviceData();
|
||||
}
|
||||
if (mGLTextureSource) {
|
||||
mGLTextureSource = nullptr;
|
||||
}
|
||||
@ -387,77 +229,24 @@ GrallocTextureHostOGL::GetRenderState()
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
GrallocTextureHostOGL::GetAsSurface() {
|
||||
if (mTilingTextureSource) {
|
||||
return mTilingTextureSource->GetAsSurface();
|
||||
} else {
|
||||
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
|
||||
uint8_t* grallocData;
|
||||
int32_t rv = graphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
|
||||
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
|
||||
gfx::Factory::CreateWrappingDataSourceSurface(grallocData,
|
||||
graphicBuffer->getStride() * android::bytesPerPixel(graphicBuffer->getPixelFormat()),
|
||||
GetSize(), GetFormat());
|
||||
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
|
||||
|
||||
graphicBuffer->unlock();
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
GrallocTextureSourceOGL::GetAsSurface() {
|
||||
if (!IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
|
||||
uint8_t* grallocData;
|
||||
int32_t rv = mGraphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
|
||||
if (rv) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t rv = graphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
|
||||
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
|
||||
gfx::Factory::CreateWrappingDataSourceSurface(grallocData,
|
||||
mGraphicBuffer->getStride() * android::bytesPerPixel(mGraphicBuffer->getPixelFormat()),
|
||||
graphicBuffer->getStride() * android::bytesPerPixel(graphicBuffer->getPixelFormat()),
|
||||
GetSize(), GetFormat());
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
|
||||
|
||||
mGraphicBuffer->unlock();
|
||||
graphicBuffer->unlock();
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
|
||||
GLuint
|
||||
GrallocTextureSourceOGL::GetGLTexture()
|
||||
{
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
void
|
||||
GrallocTextureSourceOGL::BindEGLImage()
|
||||
{
|
||||
gl()->fEGLImageTargetTexture2D(GetTextureTarget(), mEGLImage);
|
||||
}
|
||||
|
||||
TextureSource*
|
||||
GrallocTextureHostOGL::GetTextureSources()
|
||||
{
|
||||
// This is now only used with tiled layers, and will eventually be removed.
|
||||
// Other layer types use BindTextureSource instead.
|
||||
MOZ_ASSERT(!mGLTextureSource);
|
||||
if (!mTilingTextureSource) {
|
||||
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
|
||||
MOZ_ASSERT(graphicBuffer);
|
||||
if (!graphicBuffer) {
|
||||
return nullptr;
|
||||
}
|
||||
mTilingTextureSource = new GrallocTextureSourceOGL(mCompositor, this,
|
||||
graphicBuffer, mFormat);
|
||||
}
|
||||
mTilingTextureSource->Lock();
|
||||
return mTilingTextureSource;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
@ -529,8 +318,6 @@ GrallocTextureHostOGL::PrepareTextureSource(CompositableTextureSourceRef& aTextu
|
||||
// because otherwise we would be modifying the content of every layer that uses
|
||||
// the TextureSource in question, even thoug they don't use this TextureHost.
|
||||
|
||||
MOZ_ASSERT(!mTilingTextureSource);
|
||||
|
||||
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
|
||||
|
||||
MOZ_ASSERT(graphicBuffer);
|
||||
|
@ -15,74 +15,6 @@
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class GrallocTextureHostOGL;
|
||||
|
||||
// Progressively getting replaced by GLTextureSource
|
||||
class GrallocTextureSourceOGL : public TextureSource
|
||||
, public TextureSourceOGL
|
||||
{
|
||||
public:
|
||||
friend class GrallocTextureHostOGL;
|
||||
|
||||
GrallocTextureSourceOGL(CompositorOGL* aCompositor,
|
||||
GrallocTextureHostOGL* aTextureHost,
|
||||
android::GraphicBuffer* aGraphicBuffer,
|
||||
gfx::SurfaceFormat aFormat);
|
||||
|
||||
virtual ~GrallocTextureSourceOGL();
|
||||
|
||||
virtual bool IsValid() const MOZ_OVERRIDE;
|
||||
|
||||
virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE;
|
||||
|
||||
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
|
||||
|
||||
virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
|
||||
|
||||
virtual GLenum GetTextureTarget() const MOZ_OVERRIDE;
|
||||
|
||||
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
|
||||
|
||||
virtual GLenum GetWrapMode() const MOZ_OVERRIDE
|
||||
{
|
||||
return LOCAL_GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
|
||||
void DeallocateDeviceData();
|
||||
|
||||
gl::GLContext* gl() const;
|
||||
|
||||
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
|
||||
|
||||
void ForgetBuffer()
|
||||
{
|
||||
mGraphicBuffer = nullptr;
|
||||
mTextureHost = nullptr;
|
||||
}
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface> GetAsSurface();
|
||||
|
||||
GLuint GetGLTexture();
|
||||
|
||||
void BindEGLImage();
|
||||
|
||||
EGLImage GetEGLImage()
|
||||
{
|
||||
return mEGLImage;
|
||||
}
|
||||
|
||||
bool Lock();
|
||||
|
||||
protected:
|
||||
RefPtr<CompositorOGL> mCompositor;
|
||||
GrallocTextureHostOGL* mTextureHost;
|
||||
android::sp<android::GraphicBuffer> mGraphicBuffer;
|
||||
EGLImage mEGLImage;
|
||||
GLuint mTexture;
|
||||
gfx::SurfaceFormat mFormat;
|
||||
bool mNeedsReset;
|
||||
};
|
||||
|
||||
class GrallocTextureHostOGL : public TextureHost
|
||||
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
||||
, public TextureHostOGL
|
||||
@ -144,8 +76,6 @@ private:
|
||||
NewSurfaceDescriptorGralloc mGrallocHandle;
|
||||
RefPtr<GLTextureSource> mGLTextureSource;
|
||||
RefPtr<CompositorOGL> mCompositor;
|
||||
// only used for tiling, will be removed.
|
||||
RefPtr<GrallocTextureSourceOGL> mTilingTextureSource;
|
||||
// Size reported by the GraphicBuffer
|
||||
gfx::IntSize mSize;
|
||||
// Size reported by TextureClient, can be different in some cases (video?),
|
||||
|
Loading…
Reference in New Issue
Block a user