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_GL_H_
|
|
|
|
#define SHARED_SURFACE_GL_H_
|
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
#include "ScopedGLHelpers.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
#include "SharedSurface.h"
|
|
|
|
#include "SurfaceTypes.h"
|
|
|
|
#include "GLContextTypes.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-09-25 00:45:14 +04:00
|
|
|
#include "gfxTypes.h"
|
2013-06-05 04:05:28 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
2013-12-10 20:11:58 +04:00
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
// For readback and bootstrapping:
|
|
|
|
class SharedSurface_Basic
|
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_Basic> Create(GLContext* gl,
|
|
|
|
const GLFormats& formats,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
static UniquePtr<SharedSurface_Basic> Wrap(GLContext* gl,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha,
|
|
|
|
GLuint tex);
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
static SharedSurface_Basic* Cast(SharedSurface* surf) {
|
2014-07-12 02:10:49 +04:00
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
return (SharedSurface_Basic*)surf;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const GLuint mTex;
|
2015-06-05 03:15:38 +03:00
|
|
|
const bool mOwnsTex;
|
2014-03-06 01:49:37 +04:00
|
|
|
GLuint mFB;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
SharedSurface_Basic(GLContext* gl,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& size,
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha,
|
2015-06-05 03:15:38 +03:00
|
|
|
GLuint tex,
|
|
|
|
bool ownsTex);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_Basic();
|
|
|
|
|
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 {
|
2013-02-14 03:26:24 +04:00
|
|
|
return mTex;
|
|
|
|
}
|
2015-06-05 02:50:59 +03:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override {
|
2016-05-13 23:34:41 +03:00
|
|
|
MOZ_CRASH("GFX: ToSurfaceDescriptor");
|
2015-06-05 03:15:38 +03:00
|
|
|
return false;
|
2015-06-05 02:50:59 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
class SurfaceFactory_Basic
|
2015-06-05 02:50:59 +03:00
|
|
|
: public SurfaceFactory
|
|
|
|
{
|
|
|
|
public:
|
2015-06-05 03:15:38 +03:00
|
|
|
SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps,
|
|
|
|
const layers::TextureFlags& flags);
|
2015-06-05 02:50:59 +03:00
|
|
|
|
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
|
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
2015-06-05 03:15:38 +03:00
|
|
|
return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
|
2015-06-05 02:50:59 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
|
|
|
|
// Using shared GL textures:
|
|
|
|
class SharedSurface_GLTexture
|
|
|
|
: public SharedSurface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static UniquePtr<SharedSurface_GLTexture> Create(GLContext* prodGL,
|
|
|
|
const GLFormats& formats,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha);
|
|
|
|
|
|
|
|
static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
|
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::SharedGLTexture);
|
|
|
|
|
|
|
|
return (SharedSurface_GLTexture*)surf;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const GLuint mTex;
|
|
|
|
GLsync mSync;
|
|
|
|
|
|
|
|
SharedSurface_GLTexture(GLContext* prodGL,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha,
|
|
|
|
GLuint tex)
|
|
|
|
: SharedSurface(SharedSurfaceType::SharedGLTexture,
|
|
|
|
AttachmentType::GLTexture,
|
|
|
|
prodGL,
|
|
|
|
size,
|
|
|
|
hasAlpha, true)
|
|
|
|
, mTex(tex)
|
|
|
|
, mSync(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_GLTexture();
|
|
|
|
|
|
|
|
virtual void LockProdImpl() override {}
|
|
|
|
virtual void UnlockProdImpl() override {}
|
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void ProducerAcquireImpl() override {}
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual void ProducerReleaseImpl() override;
|
|
|
|
|
|
|
|
virtual GLuint ProdTexture() override {
|
|
|
|
return mTex;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SurfaceFactory_GLTexture
|
|
|
|
: public SurfaceFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SurfaceFactory_GLTexture(GLContext* prodGL,
|
|
|
|
const SurfaceCaps& caps,
|
2016-03-21 17:18:20 +03:00
|
|
|
const RefPtr<layers::ClientIPCAllocator>& allocator,
|
2015-09-24 17:11:53 +03:00
|
|
|
const layers::TextureFlags& flags)
|
|
|
|
: SurfaceFactory(SharedSurfaceType::SharedGLTexture, prodGL, caps, allocator, flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
|
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
|
|
|
return SharedSurface_GLTexture::Create(mGL, mFormats, size, hasAlpha);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif /* SHARED_SURFACE_GL_H_ */
|