2013-11-18 06:04:38 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#include "MacIOSurfaceTextureHostOGL.h"
|
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2014-01-08 00:02:18 +04:00
|
|
|
#include "GLContextCGL.h"
|
2013-11-18 06:04:38 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
|
2013-11-18 06:04:38 +04:00
|
|
|
const SurfaceDescriptorMacIOSurface& aDescriptor)
|
2013-12-12 05:44:47 +04:00
|
|
|
: TextureHost(aFlags)
|
2013-11-18 06:04:38 +04:00
|
|
|
{
|
2015-07-29 18:57:03 +03:00
|
|
|
MOZ_COUNT_CTOR(MacIOSurfaceTextureHostOGL);
|
2015-06-05 03:15:38 +03:00
|
|
|
mSurface = MacIOSurface::LookupSurface(aDescriptor.surfaceId(),
|
2013-11-18 06:04:38 +04:00
|
|
|
aDescriptor.scaleFactor(),
|
2014-10-31 12:40:15 +03:00
|
|
|
!aDescriptor.isOpaque());
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
|
|
|
|
2015-07-29 18:57:03 +03:00
|
|
|
MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MacIOSurfaceTextureHostOGL);
|
|
|
|
}
|
|
|
|
|
2015-08-04 00:57:26 +03:00
|
|
|
GLTextureSource*
|
|
|
|
MacIOSurfaceTextureHostOGL::CreateTextureSourceForPlane(size_t aPlane)
|
|
|
|
{
|
|
|
|
GLuint textureHandle;
|
|
|
|
gl::GLContext* gl = mCompositor->gl();
|
|
|
|
gl->fGenTextures(1, &textureHandle);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, textureHandle);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl)->GetCGLContext(), aPlane);
|
|
|
|
|
|
|
|
return new GLTextureSource(mCompositor, textureHandle, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
gfx::IntSize(mSurface->GetDevicePixelWidth(aPlane),
|
|
|
|
mSurface->GetDevicePixelHeight(aPlane)),
|
|
|
|
// XXX: This isn't really correct (but isn't used), we should be using the
|
|
|
|
// format of the individual plane, not of the whole buffer.
|
|
|
|
mSurface->GetFormat());
|
|
|
|
}
|
|
|
|
|
2013-11-18 06:04:38 +04:00
|
|
|
bool
|
|
|
|
MacIOSurfaceTextureHostOGL::Lock()
|
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
if (!gl() || !gl()->MakeCurrent() || !mSurface) {
|
2013-11-18 06:04:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureSource) {
|
2015-08-04 00:57:26 +03:00
|
|
|
mTextureSource = CreateTextureSourceForPlane(0);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureSource> prev = mTextureSource;
|
2015-08-04 00:57:26 +03:00
|
|
|
for (size_t i = 1; i < mSurface->GetPlaneCount(); i++) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureSource> next = CreateTextureSourceForPlane(i);
|
2015-08-04 00:57:26 +03:00
|
|
|
prev->SetNextSibling(next);
|
|
|
|
prev = next;
|
|
|
|
}
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
|
|
|
|
if (!glCompositor) {
|
2016-03-22 17:28:27 +03:00
|
|
|
mTextureSource = nullptr;
|
|
|
|
mCompositor = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2016-03-30 16:33:24 +03:00
|
|
|
|
|
|
|
if (mCompositor != glCompositor) {
|
|
|
|
// Cannot share GL texture identifiers across compositors.
|
|
|
|
mTextureSource = nullptr;
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
2016-03-30 16:33:24 +03:00
|
|
|
mCompositor = glCompositor;
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 00:36:57 +04:00
|
|
|
gfx::SurfaceFormat
|
|
|
|
MacIOSurfaceTextureHostOGL::GetFormat() const {
|
2015-08-04 00:57:26 +03:00
|
|
|
return mSurface->GetFormat();
|
2014-02-18 00:36:57 +04:00
|
|
|
}
|
|
|
|
|
2016-02-23 05:26:27 +03:00
|
|
|
gfx::SurfaceFormat
|
|
|
|
MacIOSurfaceTextureHostOGL::GetReadFormat() const {
|
|
|
|
return mSurface->GetReadFormat();
|
|
|
|
}
|
|
|
|
|
2014-02-18 00:36:57 +04:00
|
|
|
gfx::IntSize
|
|
|
|
MacIOSurfaceTextureHostOGL::GetSize() const {
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::IntSize();
|
|
|
|
}
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
|
|
|
|
mSurface->GetDevicePixelHeight());
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
gl::GLContext*
|
|
|
|
MacIOSurfaceTextureHostOGL::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-18 00:36:57 +04:00
|
|
|
MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL(
|
|
|
|
CompositorOGL* aCompositor,
|
|
|
|
MacIOSurface* aSurface)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mSurface(aSurface)
|
2015-07-29 18:57:03 +03:00
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
MOZ_ASSERT(aCompositor);
|
2015-07-29 18:57:03 +03:00
|
|
|
MOZ_COUNT_CTOR(MacIOSurfaceTextureSourceOGL);
|
|
|
|
}
|
2014-02-18 00:36:57 +04:00
|
|
|
|
|
|
|
MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL()
|
2015-07-29 18:57:03 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MacIOSurfaceTextureSourceOGL);
|
|
|
|
}
|
2014-02-18 00:36:57 +04:00
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
MacIOSurfaceTextureSourceOGL::GetSize() const
|
|
|
|
{
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
|
|
|
|
mSurface->GetDevicePixelHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
MacIOSurfaceTextureSourceOGL::GetFormat() const
|
|
|
|
{
|
2014-05-23 03:44:15 +04:00
|
|
|
return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
2014-02-18 00:36:57 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 06:04:38 +04:00
|
|
|
void
|
2016-05-25 19:01:18 +03:00
|
|
|
MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter)
|
2013-11-18 06:04:38 +04:00
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
gl::GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
|
|
|
NS_WARNING("Trying to bind a texture without a working GLContext");
|
2013-11-18 06:04:38 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-21 16:54:13 +04:00
|
|
|
GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
|
2013-11-18 06:04:38 +04:00
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
|
|
|
|
mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl)->GetCGLContext());
|
2016-05-25 19:01:18 +03:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
|
|
|
|
2014-01-08 23:25:52 +04:00
|
|
|
void
|
|
|
|
MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
mCompositor = AssertGLCompositor(aCompositor);
|
|
|
|
if (mCompositor && mNextSibling) {
|
2015-08-13 22:59:07 +03:00
|
|
|
mNextSibling->SetCompositor(aCompositor);
|
|
|
|
}
|
2014-01-08 23:25:52 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 06:04:38 +04:00
|
|
|
gl::GLContext*
|
|
|
|
MacIOSurfaceTextureSourceOGL::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|