Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +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 "TextureHostOGL.h"
|
2014-09-17 17:13:29 +04:00
|
|
|
|
|
|
|
#include "EGLUtils.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "GLContext.h" // for GLContext, etc
|
2014-06-08 17:18:53 +04:00
|
|
|
#include "GLLibraryEGL.h" // for GLLibraryEGL
|
2013-12-03 22:44:38 +04:00
|
|
|
#include "GLUploadHelpers.h"
|
2014-01-02 19:17:29 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfx2DGlue.h" // for ContentForFormat, etc
|
|
|
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface
|
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
2014-12-12 22:56:06 +03:00
|
|
|
#include "mozilla/gfx/Logging.h" // for gfxCriticalError
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2013-08-09 19:23:46 +04:00
|
|
|
#include "mozilla/layers/GrallocTextureHost.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
2014-10-21 17:53:00 +04:00
|
|
|
#include "AndroidSurfaceTexture.h"
|
2013-09-07 06:13:37 +04:00
|
|
|
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
|
2013-11-29 00:57:19 +04:00
|
|
|
#include "GLBlitTextureImageHelper.h"
|
2015-06-05 03:15:38 +03:00
|
|
|
#include "GeckoProfiler.h"
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
# include "GrallocImages.h" // for GrallocImage
|
|
|
|
# include "EGLImageHelpers.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-18 07:24:15 +04:00
|
|
|
#ifdef XP_MACOSX
|
2013-11-18 06:04:38 +04:00
|
|
|
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
|
2013-07-18 07:24:15 +04:00
|
|
|
#endif
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2015-07-30 19:40:56 +03:00
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
#include "mozilla/layers/X11TextureHost.h"
|
|
|
|
#endif
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-10 09:47:19 +04:00
|
|
|
class Compositor;
|
2013-08-12 03:17:23 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<TextureHost>
|
2013-12-12 05:44:47 +04:00
|
|
|
CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
|
2013-07-30 13:59:51 +04:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureHost> result;
|
2013-07-30 13:59:51 +04:00
|
|
|
switch (aDesc.type()) {
|
2015-12-16 21:50:58 +03:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorBuffer: {
|
2013-12-12 05:44:47 +04:00
|
|
|
result = CreateBackendIndependentTextureHost(aDesc,
|
2013-07-30 13:59:51 +04:00
|
|
|
aDeallocator, aFlags);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
|
|
|
|
const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
|
|
|
|
result = new SurfaceTextureHost(aFlags,
|
2014-10-21 17:53:00 +04:00
|
|
|
(AndroidSurfaceTexture*)desc.surfTex(),
|
2014-09-17 17:13:29 +04:00
|
|
|
desc.size());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case SurfaceDescriptor::TEGLImageDescriptor: {
|
|
|
|
const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
|
|
|
|
result = new EGLImageTextureHost(aFlags,
|
|
|
|
(EGLImage)desc.image(),
|
2014-11-27 00:16:07 +03:00
|
|
|
(EGLSync)desc.fence(),
|
2015-06-05 03:15:38 +03:00
|
|
|
desc.size(),
|
|
|
|
desc.hasAlpha());
|
2013-07-30 13:59:51 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2013-11-01 05:54:14 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
|
|
|
|
const SurfaceDescriptorMacIOSurface& desc =
|
|
|
|
aDesc.get_SurfaceDescriptorMacIOSurface();
|
2013-12-12 05:44:47 +04:00
|
|
|
result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
|
2013-11-01 05:54:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-12-04 13:23:42 +03:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorGralloc: {
|
|
|
|
const SurfaceDescriptorGralloc& desc =
|
|
|
|
aDesc.get_SurfaceDescriptorGralloc();
|
2013-12-12 05:44:47 +04:00
|
|
|
result = new GrallocTextureHostOGL(aFlags, desc);
|
2013-08-09 19:23:46 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-30 19:40:56 +03:00
|
|
|
|
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorX11: {
|
|
|
|
const auto& desc = aDesc.get_SurfaceDescriptorX11();
|
|
|
|
result = new X11TextureHost(aFlags, desc);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 17:13:00 +03:00
|
|
|
#endif
|
2015-09-24 17:11:53 +03:00
|
|
|
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture: {
|
|
|
|
const auto& desc = aDesc.get_SurfaceDescriptorSharedGLTexture();
|
|
|
|
result = new GLTextureHost(aFlags, desc.texture(),
|
|
|
|
desc.target(),
|
|
|
|
(GLsync)desc.fence(),
|
|
|
|
desc.size(),
|
|
|
|
desc.hasAlpha());
|
|
|
|
break;
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
default: return nullptr;
|
|
|
|
}
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
static gl::TextureImage::Flags
|
|
|
|
FlagsToGLFlags(TextureFlags aFlags)
|
|
|
|
{
|
|
|
|
uint32_t result = TextureImage::NoFlags;
|
|
|
|
|
2014-04-26 06:34:05 +04:00
|
|
|
if (aFlags & TextureFlags::USE_NEAREST_FILTER)
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
result |= TextureImage::UseNearestFilter;
|
2014-11-18 04:02:19 +03:00
|
|
|
if (aFlags & TextureFlags::ORIGIN_BOTTOM_LEFT)
|
|
|
|
result |= TextureImage::OriginBottomLeft;
|
2014-04-26 06:34:05 +04:00
|
|
|
if (aFlags & TextureFlags::DISALLOW_BIGIMAGE)
|
2013-08-02 03:02:06 +04:00
|
|
|
result |= TextureImage::DisallowBigImage;
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
|
|
|
return static_cast<gl::TextureImage::Flags>(result);
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
bool
|
|
|
|
TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion,
|
|
|
|
gfx::IntPoint* aSrcOffset)
|
|
|
|
{
|
2014-11-10 22:49:05 +03:00
|
|
|
GLContext *gl = mCompositor->gl();
|
|
|
|
MOZ_ASSERT(gl);
|
2016-03-22 17:28:27 +03:00
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 13:59:51 +04:00
|
|
|
NS_WARNING("trying to update TextureImageTextureSourceOGL without a GLContext");
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-12 22:56:06 +03:00
|
|
|
if (!aSurface) {
|
|
|
|
gfxCriticalError() << "Invalid surface for OGL update";
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
|
2013-12-31 13:06:12 +04:00
|
|
|
IntSize size = aSurface->GetSize();
|
2013-07-30 13:59:51 +04:00
|
|
|
if (!mTexImage ||
|
2014-04-02 10:45:02 +04:00
|
|
|
(mTexImage->GetSize() != size && !aSrcOffset) ||
|
2013-07-30 13:59:51 +04:00
|
|
|
mTexImage->GetContentType() != gfx::ContentForFormat(aSurface->GetFormat())) {
|
2014-04-26 06:34:05 +04:00
|
|
|
if (mFlags & TextureFlags::DISALLOW_BIGIMAGE) {
|
2014-05-28 14:52:13 +04:00
|
|
|
GLint maxTextureSize;
|
2014-11-10 22:49:05 +03:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
|
2014-05-28 14:52:13 +04:00
|
|
|
if (size.width > maxTextureSize || size.height > maxTextureSize) {
|
|
|
|
NS_WARNING("Texture exceeds maximum texture size, refusing upload");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-28 14:52:12 +04:00
|
|
|
// Explicitly use CreateBasicTextureImage instead of CreateTextureImage,
|
2014-05-28 14:52:13 +04:00
|
|
|
// because CreateTextureImage might still choose to create a tiled
|
|
|
|
// texture image.
|
2014-11-10 22:49:05 +03:00
|
|
|
mTexImage = CreateBasicTextureImage(gl, size,
|
2014-01-07 20:20:11 +04:00
|
|
|
gfx::ContentForFormat(aSurface->GetFormat()),
|
2014-05-28 22:07:15 +04:00
|
|
|
LOCAL_GL_CLAMP_TO_EDGE,
|
2016-01-13 10:10:56 +03:00
|
|
|
FlagsToGLFlags(mFlags));
|
2014-01-07 20:20:11 +04:00
|
|
|
} else {
|
2013-08-08 16:53:12 +04:00
|
|
|
// XXX - clarify which size we want to use. IncrementalContentHost will
|
|
|
|
// require the size of the destination surface to be different from
|
2013-07-30 13:59:51 +04:00
|
|
|
// the size of aSurface.
|
2013-08-08 16:53:12 +04:00
|
|
|
// See bug 893300 (tracks the implementation of ContentHost for new textures).
|
2014-11-10 22:49:05 +03:00
|
|
|
mTexImage = CreateTextureImage(gl,
|
2013-12-03 22:44:38 +04:00
|
|
|
size,
|
|
|
|
gfx::ContentForFormat(aSurface->GetFormat()),
|
2014-05-28 22:07:15 +04:00
|
|
|
LOCAL_GL_CLAMP_TO_EDGE,
|
2014-01-07 22:00:26 +04:00
|
|
|
FlagsToGLFlags(mFlags),
|
2013-12-11 18:14:16 +04:00
|
|
|
SurfaceFormatToImageFormat(aSurface->GetFormat()));
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2014-03-13 04:37:17 +04:00
|
|
|
ClearCachedFilter();
|
2014-08-27 10:52:24 +04:00
|
|
|
|
|
|
|
if (aDestRegion &&
|
|
|
|
!aSrcOffset &&
|
2015-04-21 18:04:57 +03:00
|
|
|
!aDestRegion->IsEqual(gfx::IntRect(0, 0, size.width, size.height))) {
|
2014-08-27 10:52:24 +04:00
|
|
|
// UpdateFromDataSource will ignore our specified aDestRegion since the texture
|
|
|
|
// hasn't been allocated with glTexImage2D yet. Call Resize() to force the
|
|
|
|
// allocation (full size, but no upload), and then we'll only upload the pixels
|
|
|
|
// we care about below.
|
|
|
|
mTexImage->Resize(size);
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
|
|
|
|
|
|
|
|
if (mTexImage->InUpdate()) {
|
|
|
|
mTexImage->EndUpdate();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-02 10:45:02 +04:00
|
|
|
void
|
2015-06-03 14:45:24 +03:00
|
|
|
TextureImageTextureSourceOGL::EnsureBuffer(const IntSize& aSize,
|
2014-04-02 10:45:02 +04:00
|
|
|
gfxContentType aContentType)
|
|
|
|
{
|
|
|
|
if (!mTexImage ||
|
2015-03-29 17:59:08 +03:00
|
|
|
mTexImage->GetSize() != aSize ||
|
2014-04-02 10:45:02 +04:00
|
|
|
mTexImage->GetContentType() != aContentType) {
|
2014-11-10 22:49:05 +03:00
|
|
|
mTexImage = CreateTextureImage(mCompositor->gl(),
|
2015-03-29 17:59:08 +03:00
|
|
|
aSize,
|
2014-04-02 10:45:02 +04:00
|
|
|
aContentType,
|
2014-05-28 22:07:15 +04:00
|
|
|
LOCAL_GL_CLAMP_TO_EDGE,
|
2014-04-02 10:45:02 +04:00
|
|
|
FlagsToGLFlags(mFlags));
|
|
|
|
}
|
2015-03-29 17:59:08 +03:00
|
|
|
mTexImage->Resize(aSize);
|
2014-04-02 10:45:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 18:04:57 +03:00
|
|
|
TextureImageTextureSourceOGL::CopyTo(const gfx::IntRect& aSourceRect,
|
2014-04-02 10:45:02 +04:00
|
|
|
DataTextureSource *aDest,
|
2015-04-21 18:04:57 +03:00
|
|
|
const gfx::IntRect& aDestRect)
|
2014-04-02 10:45:02 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDest->AsSourceOGL(), "Incompatible destination type!");
|
|
|
|
TextureImageTextureSourceOGL *dest =
|
|
|
|
aDest->AsSourceOGL()->AsTextureImageTextureSource();
|
|
|
|
MOZ_ASSERT(dest, "Incompatible destination type!");
|
|
|
|
|
2014-11-10 22:49:05 +03:00
|
|
|
mCompositor->BlitTextureImageHelper()->BlitTextureImage(mTexImage, aSourceRect,
|
2014-04-02 10:45:02 +04:00
|
|
|
dest->mTexImage, aDestRect);
|
|
|
|
dest->mTexImage->MarkValid();
|
|
|
|
}
|
|
|
|
|
2016-04-14 13:38:38 +03:00
|
|
|
CompositorOGL* AssertGLCompositor(Compositor* aCompositor)
|
2016-03-22 17:28:27 +03:00
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
CompositorOGL* compositor = aCompositor ? aCompositor->AsCompositorOGL()
|
|
|
|
: nullptr;
|
|
|
|
MOZ_ASSERT(!!compositor);
|
|
|
|
return compositor;
|
2016-03-22 17:28:27 +03:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:20:11 +04:00
|
|
|
void
|
|
|
|
TextureImageTextureSourceOGL::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
|
|
|
DeallocateDeviceData();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mCompositor != glCompositor) {
|
2014-01-07 20:20:11 +04:00
|
|
|
DeallocateDeviceData();
|
2014-11-10 22:49:05 +03:00
|
|
|
mCompositor = glCompositor;
|
2014-01-07 20:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
gfx::IntSize
|
|
|
|
TextureImageTextureSourceOGL::GetSize() const
|
|
|
|
{
|
|
|
|
if (mTexImage) {
|
|
|
|
if (mIterating) {
|
2013-08-13 17:44:53 +04:00
|
|
|
return mTexImage->GetTileRect().Size();
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2013-08-13 17:44:53 +04:00
|
|
|
return mTexImage->GetSize();
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
NS_WARNING("Trying to query the size of an empty TextureSource.");
|
|
|
|
return gfx::IntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
TextureImageTextureSourceOGL::GetFormat() const
|
|
|
|
{
|
2014-06-10 01:30:53 +04:00
|
|
|
if (mTexImage) {
|
|
|
|
return mTexImage->GetTextureFormat();
|
|
|
|
}
|
|
|
|
NS_WARNING("Trying to query the format of an empty TextureSource.");
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
gfx::IntRect TextureImageTextureSourceOGL::GetTileRect()
|
2013-08-13 17:44:53 +04:00
|
|
|
{
|
2015-04-21 18:22:30 +03:00
|
|
|
return mTexImage->GetTileRect();
|
2013-08-13 17:44:53 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
void
|
2016-05-25 19:01:18 +03:00
|
|
|
TextureImageTextureSourceOGL::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTexImage,
|
|
|
|
"Trying to bind a TextureSource that does not have an underlying GL texture.");
|
|
|
|
mTexImage->BindTexture(aTextureUnit);
|
2016-05-25 19:01:18 +03:00
|
|
|
SetSamplingFilter(mCompositor->gl(), aSamplingFilter);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLTextureSource
|
|
|
|
|
|
|
|
GLTextureSource::GLTextureSource(CompositorOGL* aCompositor,
|
2014-10-16 21:08:32 +04:00
|
|
|
GLuint aTextureHandle,
|
2014-10-24 22:25:25 +04:00
|
|
|
GLenum aTarget,
|
2014-10-16 21:08:32 +04:00
|
|
|
gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
bool aExternallyOwned)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mTextureHandle(aTextureHandle)
|
2014-10-24 22:25:25 +04:00
|
|
|
, mTextureTarget(aTarget)
|
2014-10-16 21:08:32 +04:00
|
|
|
, mSize(aSize)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mExternallyOwned(aExternallyOwned)
|
2014-10-16 21:08:32 +04:00
|
|
|
{
|
2014-10-16 21:08:32 +04:00
|
|
|
MOZ_COUNT_CTOR(GLTextureSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLTextureSource::~GLTextureSource()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GLTextureSource);
|
|
|
|
if (!mExternallyOwned) {
|
|
|
|
DeleteTextureHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLTextureSource::DeallocateDeviceData()
|
|
|
|
{
|
|
|
|
if (!mExternallyOwned) {
|
|
|
|
DeleteTextureHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLTextureSource::DeleteTextureHandle()
|
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (mTextureHandle != 0 && gl && gl->MakeCurrent()) {
|
|
|
|
gl->fDeleteTextures(1, &mTextureHandle);
|
2014-10-16 21:08:32 +04:00
|
|
|
}
|
|
|
|
mTextureHandle = 0;
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
|
|
|
|
void
|
2016-05-25 19:01:18 +03:00
|
|
|
GLTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2014-10-16 21:08:32 +04:00
|
|
|
MOZ_ASSERT(mTextureHandle != 0);
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
2016-03-23 17:31:21 +03:00
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 13:59:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
|
|
|
gl->fBindTexture(mTextureTarget, mTextureHandle);
|
2016-05-25 19:01:18 +03:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-17 17:13:29 +04:00
|
|
|
GLTextureSource::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
|
|
|
return;
|
|
|
|
}
|
2016-03-30 16:33:24 +03:00
|
|
|
|
2016-04-14 13:38:38 +03:00
|
|
|
if (mCompositor && mCompositor != glCompositor) {
|
2016-03-30 16:33:24 +03:00
|
|
|
gfxCriticalError() << "GLTextureSource does not support changing compositors";
|
|
|
|
}
|
2016-04-14 13:38:38 +03:00
|
|
|
mCompositor = glCompositor;
|
2016-03-30 16:33:24 +03:00
|
|
|
|
2015-08-13 22:59:07 +03:00
|
|
|
if (mNextSibling) {
|
|
|
|
mNextSibling->SetCompositor(aCompositor);
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLTextureSource::IsValid() const
|
|
|
|
{
|
2014-10-16 21:08:32 +04:00
|
|
|
return !!gl() && mTextureHandle != 0;
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gl::GLContext*
|
|
|
|
GLTextureSource::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// SurfaceTextureHost
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
SurfaceTextureSource::SurfaceTextureSource(CompositorOGL* aCompositor,
|
2014-10-21 17:53:00 +04:00
|
|
|
AndroidSurfaceTexture* aSurfTex,
|
2014-09-17 17:13:29 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
GLenum aTarget,
|
|
|
|
GLenum aWrapMode,
|
|
|
|
gfx::IntSize aSize)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mSurfTex(aSurfTex)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mTextureTarget(aTarget)
|
|
|
|
, mWrapMode(aWrapMode)
|
|
|
|
, mSize(aSize)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-25 19:01:18 +03:00
|
|
|
SurfaceTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2016-02-25 11:48:55 +03:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2014-09-17 17:13:29 +04:00
|
|
|
NS_WARNING("Trying to bind a texture without a GLContext");
|
2013-07-30 13:59:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
2014-10-25 03:52:35 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
// SurfaceTexture spams us if there are any existing GL errors, so
|
|
|
|
// we'll clear them here in order to avoid that.
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->FlushErrors();
|
2014-10-25 03:52:35 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
mSurfTex->UpdateTexImage();
|
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-17 17:13:29 +04:00
|
|
|
SurfaceTextureSource::SetCompositor(Compositor* aCompositor)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
|
|
|
|
if (!glCompositor) {
|
2016-03-22 17:28:27 +03:00
|
|
|
DeallocateDeviceData();
|
|
|
|
return;
|
|
|
|
}
|
2016-04-14 13:38:38 +03:00
|
|
|
if (mCompositor != glCompositor) {
|
2014-10-16 21:08:32 +04:00
|
|
|
DeallocateDeviceData();
|
|
|
|
}
|
|
|
|
|
2016-04-14 13:38:38 +03:00
|
|
|
mCompositor = glCompositor;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-17 17:13:29 +04:00
|
|
|
SurfaceTextureSource::IsValid() const
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2013-08-08 16:53:12 +04:00
|
|
|
return !!gl();
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gl::GLContext*
|
2014-09-17 17:13:29 +04:00
|
|
|
SurfaceTextureSource::gl() const
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-25 05:49:02 +04:00
|
|
|
gfx::Matrix4x4
|
2014-09-17 17:13:29 +04:00
|
|
|
SurfaceTextureSource::GetTextureTransform()
|
|
|
|
{
|
2016-02-25 11:48:55 +03:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
gfx::Matrix4x4 ret;
|
|
|
|
mSurfTex->GetTransformMatrix(ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-25 11:48:55 +03:00
|
|
|
void
|
|
|
|
SurfaceTextureSource::DeallocateDeviceData()
|
|
|
|
{
|
|
|
|
mSurfTex = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
|
2014-10-21 17:53:00 +04:00
|
|
|
AndroidSurfaceTexture* aSurfTex,
|
2014-09-17 17:13:29 +04:00
|
|
|
gfx::IntSize aSize)
|
|
|
|
: TextureHost(aFlags)
|
|
|
|
, mSurfTex(aSurfTex)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mCompositor(nullptr)
|
2013-11-19 18:41:57 +04:00
|
|
|
{
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceTextureHost::~SurfaceTextureHost()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
gl::GLContext*
|
|
|
|
SurfaceTextureHost::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SurfaceTextureHost::Lock()
|
|
|
|
{
|
2016-02-25 11:48:55 +03:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2014-09-17 17:13:29 +04:00
|
|
|
return false;
|
2014-09-12 22:39:20 +04:00
|
|
|
}
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
if (!mTextureSource) {
|
|
|
|
gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
|
|
|
|
GLenum target = LOCAL_GL_TEXTURE_EXTERNAL;
|
|
|
|
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
|
|
|
|
mTextureSource = new SurfaceTextureSource(mCompositor,
|
|
|
|
mSurfTex,
|
|
|
|
format,
|
|
|
|
target,
|
|
|
|
wrapMode,
|
|
|
|
mSize);
|
|
|
|
}
|
|
|
|
|
2016-03-23 14:48:41 +03:00
|
|
|
return NS_SUCCEEDED(mSurfTex->Attach(gl));
|
2014-09-12 22:39:20 +04:00
|
|
|
}
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
void
|
|
|
|
SurfaceTextureHost::Unlock()
|
|
|
|
{
|
2016-02-25 11:48:55 +03:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
2014-10-21 17:53:01 +04:00
|
|
|
mSurfTex->Detach();
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
2014-09-12 22:39:20 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
void
|
|
|
|
SurfaceTextureHost::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
|
|
|
DeallocateDeviceData();
|
|
|
|
return;
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
mCompositor = glCompositor;
|
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->SetCompositor(glCompositor);
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 23:01:26 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
gfx::SurfaceFormat
|
|
|
|
SurfaceTextureHost::GetFormat() const
|
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
|
2014-09-17 17:13:29 +04:00
|
|
|
}
|
|
|
|
|
2016-02-25 11:48:55 +03:00
|
|
|
void
|
|
|
|
SurfaceTextureHost::DeallocateDeviceData()
|
|
|
|
{
|
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->DeallocateDeviceData();
|
|
|
|
}
|
|
|
|
mSurfTex = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// EGLImage
|
|
|
|
|
|
|
|
EGLImageTextureSource::EGLImageTextureSource(CompositorOGL* aCompositor,
|
|
|
|
EGLImage aImage,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
GLenum aTarget,
|
|
|
|
GLenum aWrapMode,
|
|
|
|
gfx::IntSize aSize)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mImage(aImage)
|
2014-06-19 04:04:06 +04:00
|
|
|
, mFormat(aFormat)
|
|
|
|
, mTextureTarget(aTarget)
|
2014-09-17 17:13:29 +04:00
|
|
|
, mWrapMode(aWrapMode)
|
|
|
|
, mSize(aSize)
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D ||
|
|
|
|
mTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL);
|
2014-06-19 04:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-25 19:01:18 +03:00
|
|
|
EGLImageTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter)
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2014-06-19 04:04:06 +04:00
|
|
|
NS_WARNING("Trying to bind a texture without a GLContext");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
MOZ_ASSERT(DoesEGLContextSupportSharingWithEGLImage(gl),
|
2014-09-17 17:13:29 +04:00
|
|
|
"EGLImage not supported or disabled in runtime");
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
GLuint tex = mCompositor->GetTemporaryTexture(mTextureTarget, aTextureUnit);
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
|
|
|
gl->fBindTexture(mTextureTarget, tex);
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2016-03-22 17:28:27 +03:00
|
|
|
gl->fEGLImageTargetTexture2D(mTextureTarget, mImage);
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2014-06-19 04:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureSource::SetCompositor(Compositor* aCompositor)
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
mCompositor = AssertGLCompositor(aCompositor);
|
2014-06-19 04:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureSource::IsValid() const
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
|
|
|
return !!gl();
|
|
|
|
}
|
|
|
|
|
|
|
|
gl::GLContext*
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureSource::gl() const
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
gfx::Matrix4x4
|
|
|
|
EGLImageTextureSource::GetTextureTransform()
|
|
|
|
{
|
|
|
|
gfx::Matrix4x4 ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-19 04:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::EGLImageTextureHost(TextureFlags aFlags,
|
|
|
|
EGLImage aImage,
|
2014-11-27 00:16:07 +03:00
|
|
|
EGLSync aSync,
|
2015-06-05 03:15:38 +03:00
|
|
|
gfx::IntSize aSize,
|
|
|
|
bool hasAlpha)
|
2013-12-12 05:44:47 +04:00
|
|
|
: TextureHost(aFlags)
|
2014-09-17 17:13:29 +04:00
|
|
|
, mImage(aImage)
|
2014-11-27 00:16:07 +03:00
|
|
|
, mSync(aSync)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mSize(aSize)
|
2015-06-05 03:15:38 +03:00
|
|
|
, mHasAlpha(hasAlpha)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mCompositor(nullptr)
|
2015-06-05 03:15:38 +03:00
|
|
|
{}
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::~EGLImageTextureHost()
|
2015-06-05 03:15:38 +03:00
|
|
|
{}
|
2013-07-30 13:59:51 +04:00
|
|
|
|
|
|
|
gl::GLContext*
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::gl() const
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::Lock()
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 13:59:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:15:38 +03:00
|
|
|
EGLint status = LOCAL_EGL_CONDITION_SATISFIED;
|
|
|
|
|
|
|
|
if (mSync) {
|
|
|
|
MOZ_ASSERT(sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync));
|
|
|
|
status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), mSync, 0, LOCAL_EGL_FOREVER);
|
|
|
|
}
|
|
|
|
|
2014-11-27 00:16:07 +03:00
|
|
|
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
|
2015-06-05 03:15:38 +03:00
|
|
|
MOZ_ASSERT(status != 0,
|
|
|
|
"ClientWaitSync generated an error. Has mSync already been destroyed?");
|
2014-11-27 00:16:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
if (!mTextureSource) {
|
2015-06-05 03:15:38 +03:00
|
|
|
gfx::SurfaceFormat format = mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
2016-07-13 13:16:54 +03:00
|
|
|
GLenum target = gl->GetPreferredEGLImageTextureTarget();
|
2013-07-30 13:59:51 +04:00
|
|
|
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
|
2014-09-17 17:13:29 +04:00
|
|
|
mTextureSource = new EGLImageTextureSource(mCompositor,
|
|
|
|
mImage,
|
|
|
|
format,
|
|
|
|
target,
|
|
|
|
wrapMode,
|
|
|
|
mSize);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2014-09-17 17:13:29 +04:00
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::Unlock()
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::SetCompositor(Compositor* aCompositor)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2016-04-14 13:38:38 +03:00
|
|
|
CompositorOGL* glCompositor = AssertGLCompositor(aCompositor);
|
|
|
|
if (!glCompositor) {
|
2016-03-22 17:28:27 +03:00
|
|
|
mCompositor = nullptr;
|
|
|
|
mTextureSource = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2013-08-28 00:16:54 +04:00
|
|
|
mCompositor = glCompositor;
|
2013-07-30 13:59:51 +04:00
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->SetCompositor(glCompositor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
2014-09-17 17:13:29 +04:00
|
|
|
EGLImageTextureHost::GetFormat() const
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTextureSource);
|
2016-03-22 17:28:27 +03:00
|
|
|
return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
2015-09-24 17:11:53 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
GLTextureHost::GLTextureHost(TextureFlags aFlags,
|
|
|
|
GLuint aTextureHandle,
|
|
|
|
GLenum aTarget,
|
|
|
|
GLsync aSync,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
bool aHasAlpha)
|
|
|
|
: TextureHost(aFlags)
|
|
|
|
, mTexture(aTextureHandle)
|
|
|
|
, mTarget(aTarget)
|
|
|
|
, mSync(aSync)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mHasAlpha(aHasAlpha)
|
|
|
|
, mCompositor(nullptr)
|
|
|
|
{}
|
|
|
|
|
|
|
|
GLTextureHost::~GLTextureHost()
|
|
|
|
{}
|
|
|
|
|
|
|
|
gl::GLContext*
|
|
|
|
GLTextureHost::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->gl() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLTextureHost::Lock()
|
|
|
|
{
|
2016-03-22 17:28:27 +03:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2015-09-24 17:11:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSync) {
|
2016-03-22 17:28:27 +03:00
|
|
|
if (!gl->MakeCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gl->fWaitSync(mSync, 0, LOCAL_GL_TIMEOUT_IGNORED);
|
|
|
|
gl->fDeleteSync(mSync);
|
2015-09-24 17:11:53 +03:00
|
|
|
mSync = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureSource) {
|
|
|
|
gfx::SurfaceFormat format = mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
mTextureSource = new GLTextureSource(mCompositor,
|
|
|
|
mTexture,
|
|
|
|
mTarget,
|
|
|
|
mSize,
|
|
|
|
format,
|
|
|
|
false /* owned by the client */);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
GLTextureHost::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
|
|
|
mCompositor = nullptr;
|
|
|
|
mTextureSource = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2015-09-24 17:11:53 +03:00
|
|
|
mCompositor = glCompositor;
|
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->SetCompositor(glCompositor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
GLTextureHost::GetFormat() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTextureSource);
|
2016-03-22 17:28:27 +03:00
|
|
|
return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
|
2015-09-24 17:11:53 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|