2013-02-14 03:26:24 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef SHARED_SURFACE_EGL_H_
|
|
|
|
#define SHARED_SURFACE_EGL_H_
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "SharedSurface.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
class GLContext;
|
2014-07-12 02:10:49 +04:00
|
|
|
class GLLibraryEGL;
|
2013-09-04 16:14:52 +04:00
|
|
|
class TextureGarbageBin;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
class SharedSurface_EGLImage
|
2014-07-12 02:10:49 +04:00
|
|
|
: public SharedSurface
|
2013-02-14 03:26:24 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-16 04:38:08 +04:00
|
|
|
static UniquePtr<SharedSurface_EGLImage> Create(GLContext* prodGL,
|
|
|
|
const GLFormats& formats,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha,
|
|
|
|
EGLContext context);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
|
2014-07-12 02:10:49 +04:00
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::EGLImageShare);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
return (SharedSurface_EGLImage*)surf;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:48:58 +04:00
|
|
|
static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
protected:
|
|
|
|
mutable Mutex mMutex;
|
|
|
|
GLLibraryEGL* const mEGL;
|
|
|
|
const GLFormats mFormats;
|
|
|
|
GLuint mProdTex;
|
2014-08-14 23:07:00 +04:00
|
|
|
public:
|
|
|
|
const EGLImage mImage;
|
|
|
|
protected:
|
2013-02-14 03:26:24 +04:00
|
|
|
GLContext* mCurConsGL;
|
|
|
|
GLuint mConsTex;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureGarbageBin> mGarbageBin;
|
2013-02-14 03:26:24 +04:00
|
|
|
EGLSync mSync;
|
|
|
|
|
|
|
|
SharedSurface_EGLImage(GLContext* gl,
|
|
|
|
GLLibraryEGL* egl,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& size,
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha,
|
|
|
|
const GLFormats& formats,
|
2014-03-06 01:48:58 +04:00
|
|
|
GLuint prodTex,
|
|
|
|
EGLImage image);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
EGLDisplay Display() const;
|
2014-03-11 06:08:49 +04:00
|
|
|
void UpdateProdTexture(const MutexAutoLock& curAutoLock);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_EGLImage();
|
|
|
|
|
2015-10-19 19:26:26 +03:00
|
|
|
virtual layers::TextureFlags GetTextureFlags() const override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void LockProdImpl() override {}
|
|
|
|
virtual void UnlockProdImpl() override {}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void ProducerAcquireImpl() override {}
|
|
|
|
virtual void ProducerReleaseImpl() override;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual GLuint ProdTexture() override {
|
2014-03-11 06:08:49 +04:00
|
|
|
return mProdTex;
|
2013-02-14 03:26:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation-specific functions below:
|
2014-03-06 01:48:58 +04:00
|
|
|
// Returns texture and target
|
|
|
|
void AcquireConsumerTexture(GLContext* consGL, GLuint* out_texture, GLuint* out_target);
|
2015-06-05 03:15:38 +03:00
|
|
|
|
|
|
|
virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override;
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SurfaceFactory_EGLImage
|
2014-07-12 02:10:49 +04:00
|
|
|
: public SurfaceFactory
|
2013-02-14 03:26:24 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-03-06 01:48:58 +04:00
|
|
|
// Fallible:
|
2014-08-16 04:38:08 +04:00
|
|
|
static UniquePtr<SurfaceFactory_EGLImage> Create(GLContext* prodGL,
|
2015-06-05 03:15:38 +03:00
|
|
|
const SurfaceCaps& caps,
|
2015-10-18 08:24:48 +03:00
|
|
|
const RefPtr<layers::ISurfaceAllocator>& allocator,
|
2015-06-05 03:15:38 +03:00
|
|
|
const layers::TextureFlags& flags);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const EGLContext mContext;
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
SurfaceFactory_EGLImage(GLContext* prodGL, const SurfaceCaps& caps,
|
2015-10-18 08:24:48 +03:00
|
|
|
const RefPtr<layers::ISurfaceAllocator>& allocator,
|
2015-06-05 03:15:38 +03:00
|
|
|
const layers::TextureFlags& flags,
|
|
|
|
EGLContext context)
|
|
|
|
: SurfaceFactory(SharedSurfaceType::EGLImageShare, prodGL, caps, allocator, flags)
|
2013-02-14 03:26:24 +04:00
|
|
|
, mContext(context)
|
2015-06-05 03:15:38 +03:00
|
|
|
{ }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
|
|
|
return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif /* SHARED_SURFACE_EGL_H_ */
|