2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2013-02-14 03:26:24 +04:00
|
|
|
/* 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"
|
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 : public SharedSurface {
|
|
|
|
public:
|
2014-08-16 04:38:08 +04:00
|
|
|
static UniquePtr<SharedSurface_Basic> Create(GLContext* gl,
|
|
|
|
const GLFormats& formats,
|
2015-06-05 03:15:38 +03:00
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha);
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
static UniquePtr<SharedSurface_Basic> Wrap(GLContext* gl,
|
2014-07-12 02:10:49 +04:00
|
|
|
const gfx::IntSize& size,
|
|
|
|
bool hasAlpha, GLuint tex);
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
static SharedSurface_Basic* Cast(SharedSurface* surf) {
|
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
|
|
|
|
|
|
|
|
return (SharedSurface_Basic*)surf;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
|
|
|
protected:
|
2013-12-10 20:11:58 +04:00
|
|
|
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, const gfx::IntSize& size, bool hasAlpha,
|
|
|
|
GLuint tex, bool ownsTex);
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual ~SharedSurface_Basic();
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void LockProdImpl() override {}
|
|
|
|
virtual void UnlockProdImpl() override {}
|
2013-02-14 03:26:24 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ProducerAcquireImpl() override {}
|
2013-02-14 03:26:24 +04:00
|
|
|
virtual void ProducerReleaseImpl() override {}
|
2015-06-05 02:50:59 +03:00
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
virtual GLuint ProdTexture() override { return mTex; }
|
2015-06-05 02:50:59 +03:00
|
|
|
|
|
|
|
virtual bool ToSurfaceDescriptor(
|
|
|
|
layers::SurfaceDescriptor* const out_descriptor) override {
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_CRASH("GFX: ToSurfaceDescriptor");
|
|
|
|
return false;
|
2015-06-05 02:50:59 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
class SurfaceFactory_Basic : public SurfaceFactory {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2015-06-05 03:15:38 +03:00
|
|
|
SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps,
|
|
|
|
const layers::TextureFlags& flags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual UniquePtr<SharedSurface> CreateShared(
|
|
|
|
const gfx::IntSize& size) override {
|
2015-06-05 02:50:59 +03:00
|
|
|
bool hasAlpha = mReadCaps.alpha;
|
2015-09-24 17:11:53 +03:00
|
|
|
return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
|
2018-11-30 13:46:48 +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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
|
|
|
|
MOZ_ASSERT(surf->mType == SharedSurfaceType::SharedGLTexture);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
return (SharedSurface_GLTexture*)surf;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
protected:
|
|
|
|
const GLuint mTex;
|
|
|
|
GLsync mSync;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
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) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
public:
|
|
|
|
virtual ~SharedSurface_GLTexture();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual void LockProdImpl() override {}
|
|
|
|
virtual void UnlockProdImpl() override {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
virtual void ProducerAcquireImpl() override {}
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual void ProducerReleaseImpl() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual GLuint ProdTexture() override { return mTex; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
virtual bool ToSurfaceDescriptor(
|
|
|
|
layers::SurfaceDescriptor* const out_descriptor) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SurfaceFactory_GLTexture : public SurfaceFactory {
|
|
|
|
public:
|
|
|
|
SurfaceFactory_GLTexture(GLContext* prodGL, const SurfaceCaps& caps,
|
2016-09-27 06:22:20 +03:00
|
|
|
const RefPtr<layers::LayersIPCChannel>& allocator,
|
2015-09-24 17:11:53 +03:00
|
|
|
const layers::TextureFlags& flags)
|
|
|
|
: SurfaceFactory(SharedSurfaceType::SharedGLTexture, prodGL, caps,
|
|
|
|
allocator, flags) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
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_ */
|