2013-11-17 18:04:38 -08: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-07 12:02:18 -08:00
|
|
|
#include "GLContextCGL.h"
|
2013-11-17 18:04:38 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-11 17:44:47 -08:00
|
|
|
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
|
2013-11-17 18:04:38 -08:00
|
|
|
const SurfaceDescriptorMacIOSurface& aDescriptor)
|
2013-12-11 17:44:47 -08:00
|
|
|
: TextureHost(aFlags)
|
2013-11-17 18:04:38 -08:00
|
|
|
{
|
|
|
|
mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
|
|
|
|
aDescriptor.scaleFactor(),
|
|
|
|
aDescriptor.hasAlpha());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MacIOSurfaceTextureHostOGL::Lock()
|
|
|
|
{
|
2014-02-17 12:32:49 -08:00
|
|
|
if (!mCompositor || !mSurface) {
|
2013-11-17 18:04:38 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureSource) {
|
|
|
|
mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
|
|
|
|
mCompositor = glCompositor;
|
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->SetCompositor(glCompositor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 12:36:57 -08:00
|
|
|
gfx::SurfaceFormat
|
|
|
|
MacIOSurfaceTextureHostOGL::GetFormat() const {
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
}
|
2014-05-22 16:44:15 -07:00
|
|
|
return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
2014-02-17 12:36:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
MacIOSurfaceTextureHostOGL::GetSize() const {
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::IntSize();
|
|
|
|
}
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
|
|
|
|
mSurface->GetDevicePixelHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL(
|
|
|
|
CompositorOGL* aCompositor,
|
|
|
|
MacIOSurface* aSurface)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mSurface(aSurface)
|
|
|
|
{}
|
|
|
|
|
|
|
|
MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL()
|
|
|
|
{}
|
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
MacIOSurfaceTextureSourceOGL::GetSize() const
|
|
|
|
{
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
|
|
|
|
mSurface->GetDevicePixelHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
MacIOSurfaceTextureSourceOGL::GetFormat() const
|
|
|
|
{
|
2014-05-22 16:44:15 -07:00
|
|
|
return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
2014-02-17 12:36:57 -08:00
|
|
|
}
|
|
|
|
|
2013-11-17 18:04:38 -08:00
|
|
|
void
|
2014-03-12 17:37:17 -07:00
|
|
|
MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
|
2013-11-17 18:04:38 -08:00
|
|
|
{
|
|
|
|
if (!gl()) {
|
|
|
|
NS_WARNING("Trying to bind a texture without a GLContext");
|
|
|
|
return;
|
|
|
|
}
|
2014-03-21 05:54:13 -07:00
|
|
|
GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
|
2013-11-17 18:04:38 -08:00
|
|
|
|
|
|
|
gl()->fActiveTexture(aTextureUnit);
|
|
|
|
gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
|
2014-01-07 12:02:18 -08:00
|
|
|
mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl())->GetCGLContext());
|
2014-03-12 17:37:17 -07:00
|
|
|
ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
2013-11-17 18:04:38 -08:00
|
|
|
}
|
|
|
|
|
2014-01-08 11:25:52 -08:00
|
|
|
void
|
|
|
|
MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
mCompositor = static_cast<CompositorOGL*>(aCompositor);
|
|
|
|
}
|
|
|
|
|
2013-11-17 18:04:38 -08:00
|
|
|
gl::GLContext*
|
|
|
|
MacIOSurfaceTextureSourceOGL::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|