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;
|
|
|
|
}
|
2013-12-10 20:11:58 +04:00
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
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;
|
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,
|
2013-12-10 20:11:58 +04:00
|
|
|
gfx::SurfaceFormat format,
|
2013-02-14 03:26:24 +04:00
|
|
|
GLuint tex);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_Basic();
|
|
|
|
|
2014-03-11 06:08:49 +04:00
|
|
|
virtual void LockProdImpl() MOZ_OVERRIDE {}
|
|
|
|
virtual void UnlockProdImpl() MOZ_OVERRIDE {}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-10-11 01:36:17 +04:00
|
|
|
virtual void Fence() MOZ_OVERRIDE {}
|
|
|
|
virtual bool WaitSync() MOZ_OVERRIDE { return true; }
|
|
|
|
virtual bool PollSync() MOZ_OVERRIDE { return true; }
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-03-11 06:08:49 +04:00
|
|
|
virtual GLuint ProdTexture() MOZ_OVERRIDE {
|
2013-02-14 03:26:24 +04:00
|
|
|
return mTex;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SurfaceFactory_Basic
|
2014-07-12 02:10:49 +04:00
|
|
|
: public SurfaceFactory
|
2013-02-14 03:26:24 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps)
|
2014-07-12 02:10:49 +04:00
|
|
|
: SurfaceFactory(gl, SharedSurfaceType::Basic, caps)
|
2013-02-14 03:26:24 +04:00
|
|
|
{}
|
|
|
|
|
2014-08-16 04:38:08 +04:00
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
|
|
|
return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using shared GL textures:
|
|
|
|
class SharedSurface_GLTexture
|
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_GLTexture> Create(GLContext* prodGL,
|
|
|
|
GLContext* consGL,
|
|
|
|
const GLFormats& formats,
|
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha,
|
|
|
|
GLuint texture = 0);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
|
2014-07-12 02:10:49 +04:00
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::GLTextureShare);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
return (SharedSurface_GLTexture*)surf;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-06-05 04:05:28 +04:00
|
|
|
GLContext* mConsGL;
|
2013-02-14 03:26:24 +04:00
|
|
|
const GLuint mTex;
|
2014-03-06 01:49:37 +04:00
|
|
|
const bool mOwnsTex;
|
2013-02-14 03:26:24 +04:00
|
|
|
GLsync mSync;
|
2013-06-05 04:05:28 +04:00
|
|
|
mutable Mutex mMutex;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
SharedSurface_GLTexture(GLContext* prodGL,
|
|
|
|
GLContext* consGL,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& size,
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha,
|
2014-03-06 01:49:37 +04:00
|
|
|
GLuint tex,
|
|
|
|
bool ownsTex)
|
2014-07-12 02:10:49 +04:00
|
|
|
: SharedSurface(SharedSurfaceType::GLTextureShare,
|
|
|
|
AttachmentType::GLTexture,
|
|
|
|
prodGL,
|
|
|
|
size,
|
|
|
|
hasAlpha)
|
2013-02-14 03:26:24 +04:00
|
|
|
, mConsGL(consGL)
|
|
|
|
, mTex(tex)
|
2014-03-06 01:49:37 +04:00
|
|
|
, mOwnsTex(ownsTex)
|
2013-02-14 03:26:24 +04:00
|
|
|
, mSync(0)
|
2013-06-05 04:05:28 +04:00
|
|
|
, mMutex("SharedSurface_GLTexture mutex")
|
2013-02-14 03:26:24 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_GLTexture();
|
|
|
|
|
2014-03-11 06:08:49 +04:00
|
|
|
virtual void LockProdImpl() MOZ_OVERRIDE {}
|
|
|
|
virtual void UnlockProdImpl() MOZ_OVERRIDE {}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-03-11 06:08:49 +04:00
|
|
|
virtual void Fence() MOZ_OVERRIDE;
|
|
|
|
virtual bool WaitSync() MOZ_OVERRIDE;
|
2014-08-05 09:10:47 +04:00
|
|
|
virtual bool PollSync() MOZ_OVERRIDE;
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-03-11 06:08:49 +04:00
|
|
|
virtual GLuint ProdTexture() MOZ_OVERRIDE {
|
2013-02-14 03:26:24 +04:00
|
|
|
return mTex;
|
|
|
|
}
|
2013-06-05 04:05:28 +04:00
|
|
|
|
|
|
|
// Custom:
|
2014-03-11 06:08:50 +04:00
|
|
|
|
|
|
|
GLuint ConsTexture(GLContext* consGL);
|
|
|
|
|
|
|
|
GLenum ConsTextureTarget() const {
|
|
|
|
return ProdTextureTarget();
|
|
|
|
}
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class SurfaceFactory_GLTexture
|
2014-07-12 02:10:49 +04:00
|
|
|
: public SurfaceFactory
|
2013-02-14 03:26:24 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
GLContext* const mConsGL;
|
|
|
|
|
|
|
|
public:
|
2013-06-05 04:05:28 +04:00
|
|
|
// If we don't know `consGL` at construction time, use `nullptr`, and call
|
|
|
|
// `SetConsumerGL()` on each `SharedSurface_GLTexture` before calling its
|
|
|
|
// `WaitSync()`.
|
2013-02-14 03:26:24 +04:00
|
|
|
SurfaceFactory_GLTexture(GLContext* prodGL,
|
|
|
|
GLContext* consGL,
|
|
|
|
const SurfaceCaps& caps)
|
2014-07-12 02:10:49 +04:00
|
|
|
: SurfaceFactory(prodGL, SharedSurfaceType::GLTextureShare, caps)
|
2013-02-14 03:26:24 +04:00
|
|
|
, mConsGL(consGL)
|
2013-06-05 04:05:28 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(consGL != prodGL);
|
|
|
|
}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2014-08-16 04:38:08 +04:00
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
|
2013-02-14 03:26:24 +04:00
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
|
|
|
return SharedSurface_GLTexture::Create(mGL, mConsGL, mFormats, size, hasAlpha);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace gfx */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif /* SHARED_SURFACE_GL_H_ */
|