2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-10-27 22:55:37 +00:00
|
|
|
* 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/. */
|
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 09:20:52 +00:00
|
|
|
|
|
|
|
#include "TextureHostOGL.h"
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2019-06-21 16:53:09 +00:00
|
|
|
#include "GLContextEGL.h" // for GLContext, etc
|
2014-06-08 13:18:53 +00:00
|
|
|
#include "GLLibraryEGL.h" // for GLLibraryEGL
|
2013-12-03 18:44:38 +00:00
|
|
|
#include "GLUploadHelpers.h"
|
2014-01-02 15:17:29 +00:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "gfx2DGlue.h" // for ContentForFormat, etc
|
|
|
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface
|
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
2014-12-12 19:56:06 +00:00
|
|
|
#include "mozilla/gfx/Logging.h" // for gfxCriticalError
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2019-04-02 03:16:20 +00:00
|
|
|
#include "mozilla/webrender/RenderEGLImageTextureHost.h"
|
2018-11-16 02:22:15 +00:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
2014-10-21 13:53:00 +00:00
|
|
|
#include "AndroidSurfaceTexture.h"
|
2013-09-07 02:13:37 +00:00
|
|
|
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
|
2013-11-28 20:57:19 +00:00
|
|
|
#include "GLBlitTextureImageHelper.h"
|
2015-06-05 00:15:38 +00:00
|
|
|
#include "GeckoProfiler.h"
|
|
|
|
|
2013-07-18 03:24:15 +00:00
|
|
|
#ifdef XP_MACOSX
|
2013-11-18 02:04:38 +00:00
|
|
|
# include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
|
2013-07-18 03:24:15 +00:00
|
|
|
#endif
|
2015-06-05 00:15:38 +00:00
|
|
|
|
2018-11-16 02:22:15 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
# include "mozilla/webrender/RenderAndroidSurfaceTextureHostOGL.h"
|
|
|
|
#endif
|
|
|
|
|
2019-09-24 11:06:39 +00:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
# include "mozilla/layers/WaylandDMABUFTextureHostOGL.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 09:20:52 +00:00
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-10 05:47:19 +00:00
|
|
|
class Compositor;
|
2013-08-11 23:17:23 +00:00
|
|
|
|
2019-02-19 23:25:42 +00:00
|
|
|
void ApplySamplingFilterToBoundTexture(gl::GLContext* aGL,
|
|
|
|
gfx::SamplingFilter aSamplingFilter,
|
|
|
|
GLuint aTarget) {
|
|
|
|
GLenum filter =
|
|
|
|
(aSamplingFilter == gfx::SamplingFilter::POINT ? LOCAL_GL_NEAREST
|
|
|
|
: LOCAL_GL_LINEAR);
|
|
|
|
|
|
|
|
aGL->fTexParameteri(aTarget, LOCAL_GL_TEXTURE_MIN_FILTER, filter);
|
|
|
|
aGL->fTexParameteri(aTarget, LOCAL_GL_TEXTURE_MAG_FILTER, filter);
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<TextureHost> CreateTextureHostOGL(
|
2013-12-12 01:44:47 +00:00
|
|
|
const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator,
|
2017-03-07 10:37:28 +00:00
|
|
|
LayersBackend aBackend, TextureFlags aFlags) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextureHost> result;
|
2013-07-30 09:59:51 +00:00
|
|
|
switch (aDesc.type()) {
|
2014-09-17 13:13:29 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
|
|
|
|
const SurfaceTextureDescriptor& desc =
|
|
|
|
aDesc.get_SurfaceTextureDescriptor();
|
2017-03-03 21:14:27 +00:00
|
|
|
java::GeckoSurfaceTexture::LocalRef surfaceTexture =
|
|
|
|
java::GeckoSurfaceTexture::Lookup(desc.handle());
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
result = new SurfaceTextureHost(aFlags, surfaceTexture, desc.size(),
|
2017-10-28 10:59:58 +00:00
|
|
|
desc.format(), desc.continuous(),
|
|
|
|
desc.ignoreTransform());
|
2014-09-17 13:13:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case SurfaceDescriptor::TEGLImageDescriptor: {
|
|
|
|
const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
|
|
|
|
result = new EGLImageTextureHost(aFlags, (EGLImage)desc.image(),
|
2014-11-26 21:16:07 +00:00
|
|
|
(EGLSync)desc.fence(), desc.size(),
|
2015-06-05 00:15:38 +00:00
|
|
|
desc.hasAlpha());
|
2013-07-30 09:59:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2019-09-24 11:06:39 +00:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDMABuf: {
|
|
|
|
result = new WaylandDMABUFTextureHostOGL(aFlags, aDesc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-01 01:54:14 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
|
|
|
|
const SurfaceDescriptorMacIOSurface& desc =
|
|
|
|
aDesc.get_SurfaceDescriptorMacIOSurface();
|
2013-12-12 01:44:47 +00:00
|
|
|
result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
|
2013-11-01 01:54:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2015-09-24 14:11:53 +00: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;
|
|
|
|
}
|
2018-02-07 14:33:12 +00:00
|
|
|
default: {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unsupported SurfaceDescriptor type");
|
|
|
|
break;
|
|
|
|
}
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
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 09:20:52 +00:00
|
|
|
static gl::TextureImage::Flags FlagsToGLFlags(TextureFlags aFlags) {
|
|
|
|
uint32_t result = TextureImage::NoFlags;
|
|
|
|
|
2014-04-26 02:34:05 +00: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 09:20:52 +00:00
|
|
|
result |= TextureImage::UseNearestFilter;
|
2014-11-18 01:02:19 +00:00
|
|
|
if (aFlags & TextureFlags::ORIGIN_BOTTOM_LEFT)
|
|
|
|
result |= TextureImage::OriginBottomLeft;
|
2014-04-26 02:34:05 +00:00
|
|
|
if (aFlags & TextureFlags::DISALLOW_BIGIMAGE)
|
2013-08-01 23:02:06 +00: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 09:20:52 +00:00
|
|
|
|
|
|
|
return static_cast<gl::TextureImage::Flags>(result);
|
|
|
|
}
|
|
|
|
|
2018-12-11 08:54:14 +00:00
|
|
|
TextureImageTextureSourceOGL::TextureImageTextureSourceOGL(
|
|
|
|
CompositorOGL* aCompositor, TextureFlags aFlags)
|
|
|
|
: mGL(aCompositor->gl()),
|
|
|
|
mCompositor(aCompositor),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mIterating(false) {
|
|
|
|
if (mCompositor) {
|
|
|
|
mCompositor->RegisterTextureSource(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureImageTextureSourceOGL::~TextureImageTextureSourceOGL() {
|
|
|
|
DeallocateDeviceData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureImageTextureSourceOGL::DeallocateDeviceData() {
|
|
|
|
mTexImage = nullptr;
|
|
|
|
mGL = nullptr;
|
|
|
|
if (mCompositor) {
|
|
|
|
mCompositor->UnregisterTextureSource(this);
|
|
|
|
}
|
|
|
|
SetUpdateSerial(0);
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
bool TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion,
|
|
|
|
gfx::IntPoint* aSrcOffset) {
|
2017-03-22 03:32:53 +00:00
|
|
|
GLContext* gl = mGL;
|
2014-11-10 19:49:05 +00:00
|
|
|
MOZ_ASSERT(gl);
|
2016-03-22 14:28:27 +00:00
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 09:59:51 +00:00
|
|
|
NS_WARNING(
|
|
|
|
"trying to update TextureImageTextureSourceOGL without a GLContext");
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-12 19:56:06 +00:00
|
|
|
if (!aSurface) {
|
|
|
|
gfxCriticalError() << "Invalid surface for OGL update";
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 09:59:51 +00:00
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
|
2013-12-31 09:06:12 +00:00
|
|
|
IntSize size = aSurface->GetSize();
|
2014-04-02 06:45:02 +00:00
|
|
|
if (!mTexImage || (mTexImage->GetSize() != size && !aSrcOffset) ||
|
2013-07-30 09:59:51 +00:00
|
|
|
mTexImage->GetContentType() !=
|
|
|
|
gfx::ContentForFormat(aSurface->GetFormat())) {
|
2014-04-26 02:34:05 +00:00
|
|
|
if (mFlags & TextureFlags::DISALLOW_BIGIMAGE) {
|
2014-05-28 10:52:13 +00:00
|
|
|
GLint maxTextureSize;
|
2014-11-10 19:49:05 +00:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
|
2014-05-28 10:52:13 +00:00
|
|
|
if (size.width > maxTextureSize || size.height > maxTextureSize) {
|
|
|
|
NS_WARNING("Texture exceeds maximum texture size, refusing upload");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-28 10:52:12 +00:00
|
|
|
// Explicitly use CreateBasicTextureImage instead of CreateTextureImage,
|
2014-05-28 10:52:13 +00:00
|
|
|
// because CreateTextureImage might still choose to create a tiled
|
|
|
|
// texture image.
|
2014-11-10 19:49:05 +00:00
|
|
|
mTexImage = CreateBasicTextureImage(
|
2014-01-07 16:20:11 +00:00
|
|
|
gl, size, gfx::ContentForFormat(aSurface->GetFormat()),
|
2016-01-13 07:10:56 +00:00
|
|
|
LOCAL_GL_CLAMP_TO_EDGE, FlagsToGLFlags(mFlags));
|
2014-01-07 16:20:11 +00:00
|
|
|
} else {
|
2013-08-08 12:53:12 +00: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 09:59:51 +00:00
|
|
|
// the size of aSurface.
|
2013-08-08 12:53:12 +00:00
|
|
|
// See bug 893300 (tracks the implementation of ContentHost for new
|
|
|
|
// textures).
|
2014-11-10 19:49:05 +00:00
|
|
|
mTexImage = CreateTextureImage(
|
2013-12-03 18:44:38 +00:00
|
|
|
gl, size, gfx::ContentForFormat(aSurface->GetFormat()),
|
2014-01-07 18:00:26 +00:00
|
|
|
LOCAL_GL_CLAMP_TO_EDGE, FlagsToGLFlags(mFlags),
|
2013-12-11 14:14:16 +00:00
|
|
|
SurfaceFormatToImageFormat(aSurface->GetFormat()));
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
2014-03-13 00:37:17 +00:00
|
|
|
ClearCachedFilter();
|
2014-08-27 06:52:24 +00:00
|
|
|
|
|
|
|
if (aDestRegion && !aSrcOffset &&
|
2015-04-21 15:04:57 +00:00
|
|
|
!aDestRegion->IsEqual(gfx::IntRect(0, 0, size.width, size.height))) {
|
2014-08-27 06:52:24 +00: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 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 13:01:17 +00:00
|
|
|
return mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 11:45:24 +00:00
|
|
|
void TextureImageTextureSourceOGL::EnsureBuffer(const IntSize& aSize,
|
2014-04-02 06:45:02 +00:00
|
|
|
gfxContentType aContentType) {
|
2015-03-29 14:59:08 +00:00
|
|
|
if (!mTexImage || mTexImage->GetSize() != aSize ||
|
2014-04-02 06:45:02 +00:00
|
|
|
mTexImage->GetContentType() != aContentType) {
|
2017-03-22 03:32:53 +00:00
|
|
|
mTexImage =
|
|
|
|
CreateTextureImage(mGL, aSize, aContentType, LOCAL_GL_CLAMP_TO_EDGE,
|
2014-04-02 06:45:02 +00:00
|
|
|
FlagsToGLFlags(mFlags));
|
|
|
|
}
|
2015-03-29 14:59:08 +00:00
|
|
|
mTexImage->Resize(aSize);
|
2014-04-02 06:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
void TextureImageTextureSourceOGL::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
GLContext* newGL = aProvider ? aProvider->GetGLContext() : nullptr;
|
2017-03-27 21:03:59 +00:00
|
|
|
if (!newGL || mGL != newGL) {
|
2016-03-22 14:28:27 +00:00
|
|
|
DeallocateDeviceData();
|
2014-01-07 16:20:11 +00:00
|
|
|
}
|
2017-03-27 21:03:59 +00:00
|
|
|
mGL = newGL;
|
2018-12-11 08:54:14 +00:00
|
|
|
|
|
|
|
CompositorOGL* compositor =
|
|
|
|
aProvider ? aProvider->AsCompositorOGL() : nullptr;
|
|
|
|
if (mCompositor != compositor) {
|
|
|
|
if (mCompositor) {
|
|
|
|
mCompositor->UnregisterTextureSource(this);
|
|
|
|
}
|
|
|
|
if (compositor) {
|
|
|
|
compositor->RegisterTextureSource(this);
|
|
|
|
}
|
|
|
|
mCompositor = compositor;
|
|
|
|
}
|
2014-01-07 16:20:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
gfx::IntSize TextureImageTextureSourceOGL::GetSize() const {
|
|
|
|
if (mTexImage) {
|
|
|
|
if (mIterating) {
|
2013-08-13 13:44:53 +00:00
|
|
|
return mTexImage->GetTileRect().Size();
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
2013-08-13 13:44:53 +00:00
|
|
|
return mTexImage->GetSize();
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
NS_WARNING("Trying to query the size of an empty TextureSource.");
|
|
|
|
return gfx::IntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat TextureImageTextureSourceOGL::GetFormat() const {
|
2014-06-09 21:30:53 +00:00
|
|
|
if (mTexImage) {
|
|
|
|
return mTexImage->GetTextureFormat();
|
|
|
|
}
|
|
|
|
NS_WARNING("Trying to query the format of an empty TextureSource.");
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 15:04:57 +00:00
|
|
|
gfx::IntRect TextureImageTextureSourceOGL::GetTileRect() {
|
2015-04-21 15:22:30 +00:00
|
|
|
return mTexImage->GetTileRect();
|
2013-08-13 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
void TextureImageTextureSourceOGL::BindTexture(
|
|
|
|
GLenum aTextureUnit, gfx::SamplingFilter aSamplingFilter) {
|
2013-07-30 09:59:51 +00:00
|
|
|
MOZ_ASSERT(mTexImage,
|
|
|
|
"Trying to bind a TextureSource that does not have an underlying "
|
|
|
|
"GL texture.");
|
|
|
|
mTexImage->BindTexture(aTextureUnit);
|
2017-03-22 03:32:53 +00:00
|
|
|
SetSamplingFilter(mGL, aSamplingFilter);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLTextureSource
|
|
|
|
|
2017-03-22 03:32:54 +00:00
|
|
|
GLTextureSource::GLTextureSource(TextureSourceProvider* aProvider,
|
2014-10-16 17:08:32 +00:00
|
|
|
GLuint aTextureHandle, GLenum aTarget,
|
2018-05-03 01:19:54 +00:00
|
|
|
gfx::IntSize aSize, gfx::SurfaceFormat aFormat)
|
2017-03-22 03:32:54 +00:00
|
|
|
: mGL(aProvider->GetGLContext()),
|
2014-10-16 17:08:32 +00:00
|
|
|
mTextureHandle(aTextureHandle),
|
2014-10-24 18:25:25 +00:00
|
|
|
mTextureTarget(aTarget),
|
2014-10-16 17:08:32 +00:00
|
|
|
mSize(aSize),
|
|
|
|
mFormat(aFormat) {
|
|
|
|
MOZ_COUNT_CTOR(GLTextureSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLTextureSource::~GLTextureSource() {
|
|
|
|
MOZ_COUNT_DTOR(GLTextureSource);
|
2018-05-03 01:19:54 +00:00
|
|
|
DeleteTextureHandle();
|
2014-10-16 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLTextureSource::DeallocateDeviceData() { DeleteTextureHandle(); }
|
|
|
|
|
|
|
|
void GLTextureSource::DeleteTextureHandle() {
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (mTextureHandle != 0 && gl && gl->MakeCurrent()) {
|
|
|
|
gl->fDeleteTextures(1, &mTextureHandle);
|
2014-10-16 17:08:32 +00:00
|
|
|
}
|
|
|
|
mTextureHandle = 0;
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
void GLTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter) {
|
2014-10-16 17:08:32 +00:00
|
|
|
MOZ_ASSERT(mTextureHandle != 0);
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
2016-03-23 14:31:21 +00:00
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 09:59:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-22 14:28:27 +00:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
|
|
|
gl->fBindTexture(mTextureTarget, mTextureHandle);
|
2016-05-25 16:01:18 +00:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
void GLTextureSource::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
GLContext* newGL = aProvider ? aProvider->GetGLContext() : nullptr;
|
|
|
|
if (!newGL) {
|
|
|
|
mGL = newGL;
|
|
|
|
} else if (mGL != newGL) {
|
2016-03-30 13:33:24 +00:00
|
|
|
gfxCriticalError()
|
|
|
|
<< "GLTextureSource does not support changing compositors";
|
|
|
|
}
|
|
|
|
|
2015-08-13 19:59:07 +00:00
|
|
|
if (mNextSibling) {
|
2017-03-22 03:32:53 +00:00
|
|
|
mNextSibling->SetTextureSourceProvider(aProvider);
|
2015-08-13 19:59:07 +00:00
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 17:08:32 +00:00
|
|
|
bool GLTextureSource::IsValid() const { return !!gl() && mTextureHandle != 0; }
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2018-05-03 01:20:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// DirectMapTextureSource
|
|
|
|
|
|
|
|
DirectMapTextureSource::DirectMapTextureSource(TextureSourceProvider* aProvider,
|
|
|
|
gfx::DataSourceSurface* aSurface)
|
2018-07-26 23:55:55 +00:00
|
|
|
: GLTextureSource(aProvider, 0, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
2018-05-03 01:20:10 +00:00
|
|
|
aSurface->GetSize(), aSurface->GetFormat()),
|
2018-09-25 13:41:25 +00:00
|
|
|
mSync(0) {
|
2018-05-03 01:20:10 +00:00
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
|
|
|
|
UpdateInternal(aSurface, nullptr, nullptr, true);
|
|
|
|
}
|
|
|
|
|
2018-09-25 13:41:25 +00:00
|
|
|
DirectMapTextureSource::~DirectMapTextureSource() {
|
|
|
|
if (!mSync || !gl() || !gl()->MakeCurrent() || gl()->IsDestroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl()->fDeleteSync(mSync);
|
|
|
|
mSync = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:10 +00:00
|
|
|
bool DirectMapTextureSource::Update(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion,
|
|
|
|
gfx::IntPoint* aSrcOffset) {
|
|
|
|
if (!aSurface) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UpdateInternal(aSurface, aDestRegion, aSrcOffset, false);
|
|
|
|
}
|
|
|
|
|
2018-09-25 13:41:25 +00:00
|
|
|
void DirectMapTextureSource::MaybeFenceTexture() {
|
|
|
|
if (!gl() || !gl()->MakeCurrent() || gl()->IsDestroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSync) {
|
|
|
|
gl()->fDeleteSync(mSync);
|
|
|
|
}
|
|
|
|
mSync = gl()->fFenceSync(LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
|
|
}
|
|
|
|
|
Bug 1265824 - Wait on texture handles with IPC r=jld,mattwoodrow
There's a lot going on here, but it all fits under the idea of
being able to communicate about texture locking statuses
without spinning on IsReadLocked. This is a bit of a trade -
we could just always allocate/grab a texture from the pool,
which would put a smaller cap on the amount of time we can
possibly spend when a texture is locked. However, this eats
up more CPU and memory than waiting on the textures to unlock,
and could take longer, especially if there were a large number
of textures which we just need to wait for for a short amount
of time. In any case, we very rarely hit the case where we
actually need to wait on the sync IPC to the compositor - most
of the time the textures are already unlocked.
There is also an async IPC call in here, which we make before
flushing async paints. This just causes the compositor to
check whether the GPU is done with its textures or not and
unlock them if it is. This helps us avoid the case where we
take a long time painting asynchronously, turn IPC back on at
the end of that, and then have to wait for the compositor
to to get into TiledLayerBufferComposite::UseTiles before
getting a response. Specifically this eliminates several talos
regressions which use ASAP mode.
Lastly, there seem to be no other cases of static Monitors
being used. This seems like it falls under similar use cases
as StaticMutexes, so I added it in. I can move it into its own
file if we think it might be generally useful in the future.
MozReview-Commit-ID: IYQLwUqMxg2
--HG--
extra : rebase_source : 4f05832f51dae6db98773dcad03cb008a80eca6c
2018-05-05 22:46:26 +00:00
|
|
|
bool DirectMapTextureSource::Sync(bool aBlocking) {
|
2018-09-25 13:41:25 +00:00
|
|
|
if (!gl() || !gl()->MakeCurrent() || gl()->IsDestroyed()) {
|
2018-08-22 11:59:15 +00:00
|
|
|
// We use this function to decide whether we can unlock the texture
|
|
|
|
// and clean it up. If we return false here and for whatever reason
|
|
|
|
// the context is absent or invalid, the compositor will keep a
|
|
|
|
// reference to this texture forever.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-25 13:41:25 +00:00
|
|
|
if (!mSync) {
|
|
|
|
return false;
|
2018-05-03 01:20:10 +00:00
|
|
|
}
|
2018-09-25 13:41:25 +00:00
|
|
|
|
|
|
|
GLenum waitResult =
|
|
|
|
gl()->fClientWaitSync(mSync, LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT,
|
|
|
|
aBlocking ? LOCAL_GL_TIMEOUT_IGNORED : 0);
|
|
|
|
return waitResult == LOCAL_GL_ALREADY_SIGNALED ||
|
|
|
|
waitResult == LOCAL_GL_CONDITION_SATISFIED;
|
2018-05-03 01:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DirectMapTextureSource::UpdateInternal(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion,
|
|
|
|
gfx::IntPoint* aSrcOffset,
|
|
|
|
bool aInit) {
|
2018-08-22 11:59:15 +00:00
|
|
|
if (!gl() || !gl()->MakeCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-03 01:20:10 +00:00
|
|
|
|
|
|
|
if (aInit) {
|
|
|
|
gl()->fGenTextures(1, &mTextureHandle);
|
2018-07-26 23:55:55 +00:00
|
|
|
gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, mTextureHandle);
|
2018-05-03 01:20:10 +00:00
|
|
|
|
2018-07-26 23:55:55 +00:00
|
|
|
gl()->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
2018-05-03 01:20:10 +00:00
|
|
|
LOCAL_GL_TEXTURE_STORAGE_HINT_APPLE,
|
|
|
|
LOCAL_GL_STORAGE_CACHED_APPLE);
|
2018-07-26 23:55:55 +00:00
|
|
|
gl()->fTextureRangeAPPLE(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
aSurface->Stride() * aSurface->GetSize().height,
|
|
|
|
aSurface->GetData());
|
2018-05-03 01:20:10 +00:00
|
|
|
|
2018-07-26 23:55:55 +00:00
|
|
|
gl()->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
2018-05-03 01:20:10 +00:00
|
|
|
LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
2018-07-26 23:55:55 +00:00
|
|
|
gl()->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
|
2018-05-03 01:20:10 +00:00
|
|
|
LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTextureHandle);
|
|
|
|
|
|
|
|
// APPLE_client_storage
|
|
|
|
gl()->fPixelStorei(LOCAL_GL_UNPACK_CLIENT_STORAGE_APPLE, LOCAL_GL_TRUE);
|
|
|
|
|
|
|
|
nsIntRegion destRegion = aDestRegion
|
|
|
|
? *aDestRegion
|
|
|
|
: IntRect(0, 0, aSurface->GetSize().width,
|
|
|
|
aSurface->GetSize().height);
|
|
|
|
gfx::IntPoint srcPoint = aSrcOffset ? *aSrcOffset : gfx::IntPoint(0, 0);
|
|
|
|
mFormat = gl::UploadSurfaceToTexture(
|
|
|
|
gl(), aSurface, destRegion, mTextureHandle, aSurface->GetSize(), nullptr,
|
2018-07-26 23:55:55 +00:00
|
|
|
aInit, srcPoint, LOCAL_GL_TEXTURE0, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
2018-05-03 01:20:10 +00:00
|
|
|
|
2018-09-25 13:41:25 +00:00
|
|
|
if (mSync) {
|
|
|
|
gl()->fDeleteSync(mSync);
|
|
|
|
mSync = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:20:10 +00:00
|
|
|
gl()->fPixelStorei(LOCAL_GL_UNPACK_CLIENT_STORAGE_APPLE, LOCAL_GL_FALSE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// SurfaceTextureHost
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
SurfaceTextureSource::SurfaceTextureSource(
|
|
|
|
TextureSourceProvider* aProvider,
|
2017-03-03 21:14:27 +00:00
|
|
|
mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::SurfaceFormat aFormat, GLenum aTarget, GLenum aWrapMode,
|
2017-10-28 10:59:58 +00:00
|
|
|
gfx::IntSize aSize, bool aIgnoreTransform)
|
2017-03-22 03:32:53 +00:00
|
|
|
: mGL(aProvider->GetGLContext()),
|
2014-09-17 13:13:29 +00:00
|
|
|
mSurfTex(aSurfTex),
|
|
|
|
mFormat(aFormat),
|
|
|
|
mTextureTarget(aTarget),
|
|
|
|
mWrapMode(aWrapMode),
|
|
|
|
mSize(aSize),
|
2017-10-28 10:59:58 +00:00
|
|
|
mIgnoreTransform(aIgnoreTransform) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
void SurfaceTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter) {
|
2016-02-25 08:48:55 +00:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2014-09-17 13:13:29 +00:00
|
|
|
NS_WARNING("Trying to bind a texture without a GLContext");
|
2013-07-30 09:59:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2016-03-22 14:28:27 +00:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
2017-03-03 21:14:27 +00:00
|
|
|
gl->fBindTexture(mTextureTarget, mSurfTex->GetTexName());
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
void SurfaceTextureSource::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
GLContext* newGL = aProvider->GetGLContext();
|
|
|
|
if (!newGL || mGL != newGL) {
|
2016-03-22 14:28:27 +00:00
|
|
|
DeallocateDeviceData();
|
|
|
|
return;
|
|
|
|
}
|
2014-10-16 17:08:32 +00:00
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
mGL = newGL;
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
bool SurfaceTextureSource::IsValid() const { return !!gl(); }
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::Matrix4x4 SurfaceTextureSource::GetTextureTransform() {
|
2016-02-25 08:48:55 +00:00
|
|
|
MOZ_ASSERT(mSurfTex);
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::Matrix4x4 ret;
|
2017-03-03 21:14:27 +00:00
|
|
|
|
2017-10-28 10:59:58 +00:00
|
|
|
// GetTransformMatrix() returns the transform set by the producer side of
|
|
|
|
// the SurfaceTexture. We should ignore this if we know the transform should
|
|
|
|
// be identity but the producer couldn't set it correctly, like is the
|
|
|
|
// case for AndroidNativeWindowTextureData.
|
|
|
|
if (!mIgnoreTransform) {
|
|
|
|
const auto& surf = java::sdk::SurfaceTexture::LocalRef(
|
|
|
|
java::sdk::SurfaceTexture::Ref::From(mSurfTex));
|
2017-10-30 22:52:23 +00:00
|
|
|
AndroidSurfaceTexture::GetTransformMatrix(surf, &ret);
|
2017-10-28 10:59:58 +00:00
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-25 08:48:55 +00:00
|
|
|
void SurfaceTextureSource::DeallocateDeviceData() { mSurfTex = nullptr; }
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SurfaceTextureHost::SurfaceTextureHost(
|
2017-03-03 21:14:27 +00:00
|
|
|
TextureFlags aFlags, mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
|
2017-10-28 10:59:58 +00:00
|
|
|
gfx::IntSize aSize, gfx::SurfaceFormat aFormat, bool aContinuousUpdate,
|
|
|
|
bool aIgnoreTransform)
|
2014-09-17 13:13:29 +00:00
|
|
|
: TextureHost(aFlags),
|
|
|
|
mSurfTex(aSurfTex),
|
|
|
|
mSize(aSize),
|
2017-10-28 10:59:58 +00:00
|
|
|
mFormat(aFormat),
|
2017-03-09 23:50:21 +00:00
|
|
|
mContinuousUpdate(aContinuousUpdate),
|
2017-10-28 10:59:58 +00:00
|
|
|
mIgnoreTransform(aIgnoreTransform) {
|
2017-06-16 18:00:56 +00:00
|
|
|
if (!mSurfTex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-09 23:50:21 +00:00
|
|
|
// Continuous update makes no sense with single buffer mode
|
|
|
|
MOZ_ASSERT(!mSurfTex->IsSingleBuffer() || !mContinuousUpdate);
|
2017-06-01 17:12:55 +00:00
|
|
|
|
|
|
|
mSurfTex->IncrementUse();
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceTextureHost::~SurfaceTextureHost() {
|
2017-06-01 17:12:55 +00:00
|
|
|
if (mSurfTex) {
|
|
|
|
mSurfTex->DecrementUse();
|
|
|
|
mSurfTex = nullptr;
|
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 21:14:27 +00:00
|
|
|
void SurfaceTextureHost::PrepareTextureSource(
|
|
|
|
CompositableTextureSourceRef& aTexture) {
|
2017-06-16 18:00:56 +00:00
|
|
|
if (!mContinuousUpdate && mSurfTex) {
|
2017-10-31 16:07:53 +00:00
|
|
|
if (!EnsureAttached()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-09 23:50:21 +00:00
|
|
|
// UpdateTexImage() advances the internal buffer queue, so we only want to
|
|
|
|
// call this once per transactionwhen we are not in continuous mode (as we
|
|
|
|
// are here). Otherwise, the SurfaceTexture content will be de-synced from
|
|
|
|
// the rest of the page in subsequent compositor passes.
|
|
|
|
mSurfTex->UpdateTexImage();
|
|
|
|
}
|
2017-03-03 21:14:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gl::GLContext* SurfaceTextureHost::gl() const {
|
2017-03-22 03:32:54 +00:00
|
|
|
return mProvider ? mProvider->GetGLContext() : nullptr;
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 16:07:53 +00:00
|
|
|
bool SurfaceTextureHost::EnsureAttached() {
|
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-16 18:00:56 +00:00
|
|
|
if (!mSurfTex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-31 16:07:53 +00:00
|
|
|
if (!mSurfTex->IsAttachedToGLContext((int64_t)gl)) {
|
|
|
|
GLuint texName;
|
|
|
|
gl->fGenTextures(1, &texName);
|
|
|
|
if (NS_FAILED(mSurfTex->AttachToGLContext((int64_t)gl, texName))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SurfaceTextureHost::Lock() {
|
|
|
|
if (!EnsureAttached()) {
|
2014-09-17 13:13:29 +00:00
|
|
|
return false;
|
2014-09-12 18:39:20 +00:00
|
|
|
}
|
2014-06-19 00:04:06 +00:00
|
|
|
|
2017-03-09 23:50:21 +00:00
|
|
|
if (mContinuousUpdate) {
|
|
|
|
mSurfTex->UpdateTexImage();
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
if (!mTextureSource) {
|
2017-03-03 21:14:27 +00:00
|
|
|
GLenum target =
|
|
|
|
LOCAL_GL_TEXTURE_EXTERNAL; // This is required by SurfaceTexture
|
2014-09-17 13:13:29 +00:00
|
|
|
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource =
|
|
|
|
new SurfaceTextureSource(mProvider, mSurfTex, mFormat, target, wrapMode,
|
2017-10-28 10:59:58 +00:00
|
|
|
mSize, mIgnoreTransform);
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 21:14:27 +00:00
|
|
|
return true;
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
2014-09-12 18:39:20 +00:00
|
|
|
|
2017-03-22 03:32:54 +00:00
|
|
|
void SurfaceTextureHost::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
if (mProvider != aProvider) {
|
|
|
|
if (!aProvider || !aProvider->GetGLContext()) {
|
|
|
|
DeallocateDeviceData();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mProvider = aProvider;
|
2016-03-22 14:28:27 +00:00
|
|
|
}
|
2017-03-22 03:32:54 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
if (mTextureSource) {
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource->SetTextureSourceProvider(aProvider);
|
2014-09-17 13:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-12 19:01:26 +00:00
|
|
|
|
2017-03-03 21:14:27 +00:00
|
|
|
void SurfaceTextureHost::NotifyNotUsed() {
|
2017-06-16 18:00:56 +00:00
|
|
|
if (mSurfTex && mSurfTex->IsSingleBuffer()) {
|
2019-07-22 21:16:11 +00:00
|
|
|
if (!EnsureAttached()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-03 21:14:27 +00:00
|
|
|
mSurfTex->ReleaseTexImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureHost::NotifyNotUsed();
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::SurfaceFormat SurfaceTextureHost::GetFormat() const { return mFormat; }
|
|
|
|
|
2016-02-25 08:48:55 +00:00
|
|
|
void SurfaceTextureHost::DeallocateDeviceData() {
|
|
|
|
if (mTextureSource) {
|
|
|
|
mTextureSource->DeallocateDeviceData();
|
|
|
|
}
|
2017-06-01 17:12:55 +00:00
|
|
|
|
|
|
|
if (mSurfTex) {
|
|
|
|
mSurfTex->DecrementUse();
|
|
|
|
mSurfTex = nullptr;
|
|
|
|
}
|
2016-02-25 08:48:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 02:22:15 +00:00
|
|
|
void SurfaceTextureHost::CreateRenderTexture(
|
|
|
|
const wr::ExternalImageId& aExternalImageId) {
|
|
|
|
RefPtr<wr::RenderTextureHost> texture =
|
|
|
|
new wr::RenderAndroidSurfaceTextureHostOGL(mSurfTex, mSize, mFormat,
|
|
|
|
mContinuousUpdate);
|
|
|
|
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
|
|
|
|
texture.forget());
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-11-16 02:22:15 +00:00
|
|
|
void SurfaceTextureHost::PushResourceUpdates(
|
|
|
|
wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
|
2019-12-06 06:53:57 +00:00
|
|
|
const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID,
|
|
|
|
const bool aPreferCompositorSurface) {
|
2018-11-16 02:22:15 +00:00
|
|
|
auto method = aOp == TextureHost::ADD_IMAGE
|
|
|
|
? &wr::TransactionBuilder::AddExternalImage
|
|
|
|
: &wr::TransactionBuilder::UpdateExternalImage;
|
2019-05-28 22:03:54 +00:00
|
|
|
auto imageType =
|
|
|
|
wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
2018-11-16 02:22:15 +00:00
|
|
|
|
|
|
|
switch (GetFormat()) {
|
|
|
|
case gfx::SurfaceFormat::R8G8B8X8:
|
|
|
|
case gfx::SurfaceFormat::R8G8B8A8: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
|
|
|
|
// XXX Add RGBA handling. Temporary hack to avoid crash
|
|
|
|
// With BGRA format setting, rendering works without problem.
|
|
|
|
auto format = GetFormat() == gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
? gfx::SurfaceFormat::B8G8R8A8
|
|
|
|
: gfx::SurfaceFormat::B8G8R8X8;
|
2019-12-06 06:53:57 +00:00
|
|
|
wr::ImageDescriptor descriptor(GetSize(), format,
|
|
|
|
aPreferCompositorSurface);
|
2019-05-28 22:03:54 +00:00
|
|
|
(aResources.*method)(aImageKeys[0], descriptor, aExtID, imageType, 0);
|
2018-11-16 02:22:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceTextureHost::PushDisplayItems(
|
|
|
|
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys) {
|
|
|
|
switch (GetFormat()) {
|
|
|
|
case gfx::SurfaceFormat::R8G8B8X8:
|
|
|
|
case gfx::SurfaceFormat::R8G8B8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8X8: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
|
|
|
|
!(mFlags & TextureFlags::NON_PREMULTIPLIED));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// EGLImage
|
|
|
|
|
2017-03-22 03:32:54 +00:00
|
|
|
EGLImageTextureSource::EGLImageTextureSource(TextureSourceProvider* aProvider,
|
2014-09-17 13:13:29 +00:00
|
|
|
EGLImage aImage,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
GLenum aTarget, GLenum aWrapMode,
|
|
|
|
gfx::IntSize aSize)
|
2017-03-22 03:32:54 +00:00
|
|
|
: mImage(aImage),
|
2014-06-19 00:04:06 +00:00
|
|
|
mFormat(aFormat),
|
|
|
|
mTextureTarget(aTarget),
|
2014-09-17 13:13:29 +00:00
|
|
|
mWrapMode(aWrapMode),
|
|
|
|
mSize(aSize) {
|
2015-06-05 00:15:38 +00:00
|
|
|
MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D ||
|
|
|
|
mTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL);
|
2017-03-22 03:32:54 +00:00
|
|
|
SetTextureSourceProvider(aProvider);
|
2014-06-19 00:04:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
void EGLImageTextureSource::BindTexture(GLenum aTextureUnit,
|
|
|
|
gfx::SamplingFilter aSamplingFilter) {
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2014-06-19 00:04:06 +00:00
|
|
|
NS_WARNING("Trying to bind a texture without a GLContext");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2019-06-21 16:53:09 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
const bool supportsEglImage = [&]() {
|
|
|
|
const auto& gle = GLContextEGL::Cast(gl);
|
|
|
|
const auto& egl = gle->mEgl;
|
|
|
|
|
|
|
|
return egl->HasKHRImageBase() && egl->HasKHRImageTexture2D() &&
|
|
|
|
gl->IsExtensionSupported(GLContext::OES_EGL_image);
|
|
|
|
}();
|
2019-07-06 08:18:28 +00:00
|
|
|
MOZ_ASSERT(supportsEglImage, "EGLImage not supported or disabled in runtime");
|
2019-06-21 16:53:09 +00:00
|
|
|
#endif
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2015-06-05 00:15:38 +00:00
|
|
|
GLuint tex = mCompositor->GetTemporaryTexture(mTextureTarget, aTextureUnit);
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2016-03-22 14:28:27 +00:00
|
|
|
gl->fActiveTexture(aTextureUnit);
|
|
|
|
gl->fBindTexture(mTextureTarget, tex);
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2016-03-22 14:28:27 +00:00
|
|
|
gl->fEGLImageTargetTexture2D(mTextureTarget, mImage);
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
|
2014-06-19 00:04:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
void EGLImageTextureSource::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
if (mCompositor == aProvider) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aProvider) {
|
|
|
|
mGL = nullptr;
|
|
|
|
mCompositor = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGL = aProvider->GetGLContext();
|
|
|
|
if (Compositor* compositor = aProvider->AsCompositor()) {
|
|
|
|
mCompositor = compositor->AsCompositorOGL();
|
|
|
|
}
|
2014-06-19 00:04:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
bool EGLImageTextureSource::IsValid() const { return !!gl(); }
|
2014-06-19 00:04:06 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::Matrix4x4 EGLImageTextureSource::GetTextureTransform() {
|
|
|
|
gfx::Matrix4x4 ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-19 00:04:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
EGLImageTextureHost::EGLImageTextureHost(TextureFlags aFlags, EGLImage aImage,
|
2015-06-05 00:15:38 +00:00
|
|
|
EGLSync aSync, gfx::IntSize aSize,
|
|
|
|
bool hasAlpha)
|
2013-12-12 01:44:47 +00:00
|
|
|
: TextureHost(aFlags),
|
2014-09-17 13:13:29 +00:00
|
|
|
mImage(aImage),
|
2014-11-26 21:16:07 +00:00
|
|
|
mSync(aSync),
|
2013-07-30 09:59:51 +00:00
|
|
|
mSize(aSize),
|
2015-06-05 00:15:38 +00:00
|
|
|
mHasAlpha(hasAlpha) {}
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
EGLImageTextureHost::~EGLImageTextureHost() {}
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gl::GLContext* EGLImageTextureHost::gl() const {
|
2017-03-22 03:32:54 +00:00
|
|
|
return mProvider ? mProvider->GetGLContext() : nullptr;
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
bool EGLImageTextureHost::Lock() {
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2013-07-30 09:59:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-04 02:09:29 +00:00
|
|
|
auto* egl = gl::GLLibraryEGL::Get();
|
2015-06-05 00:15:38 +00:00
|
|
|
EGLint status = LOCAL_EGL_CONDITION_SATISFIED;
|
|
|
|
|
|
|
|
if (mSync) {
|
2018-06-04 02:09:29 +00:00
|
|
|
MOZ_ASSERT(egl->IsExtensionSupported(GLLibraryEGL::KHR_fence_sync));
|
2019-06-15 05:14:53 +00:00
|
|
|
status = egl->fClientWaitSync(egl->Display(), mSync, 0, LOCAL_EGL_FOREVER);
|
2015-06-05 00:15:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 21:16:07 +00:00
|
|
|
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
|
2015-06-05 00:15:38 +00:00
|
|
|
MOZ_ASSERT(
|
|
|
|
status != 0,
|
|
|
|
"ClientWaitSync generated an error. Has mSync already been destroyed?");
|
2014-11-26 21:16:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
if (!mTextureSource) {
|
2015-06-05 00:15:38 +00:00
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::R8G8B8X8;
|
2016-07-13 10:16:54 +00:00
|
|
|
GLenum target = gl->GetPreferredEGLImageTextureTarget();
|
2013-07-30 09:59:51 +00:00
|
|
|
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource = new EGLImageTextureSource(mProvider, mImage, format,
|
2014-09-17 13:13:29 +00:00
|
|
|
target, wrapMode, mSize);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
2014-09-17 13:13:29 +00:00
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
void EGLImageTextureHost::Unlock() {}
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2017-03-22 03:32:54 +00:00
|
|
|
void EGLImageTextureHost::SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) {
|
|
|
|
if (mProvider != aProvider) {
|
|
|
|
if (!aProvider || !aProvider->GetGLContext()) {
|
|
|
|
mProvider = nullptr;
|
|
|
|
mTextureSource = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mProvider = aProvider;
|
2016-03-22 14:28:27 +00:00
|
|
|
}
|
2017-03-22 03:32:54 +00:00
|
|
|
|
2013-07-30 09:59:51 +00:00
|
|
|
if (mTextureSource) {
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource->SetTextureSourceProvider(aProvider);
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:13:29 +00:00
|
|
|
gfx::SurfaceFormat EGLImageTextureHost::GetFormat() const {
|
2013-07-30 09:59:51 +00:00
|
|
|
MOZ_ASSERT(mTextureSource);
|
2016-03-22 14:28:27 +00:00
|
|
|
return mTextureSource ? mTextureSource->GetFormat()
|
|
|
|
: gfx::SurfaceFormat::UNKNOWN;
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:16:20 +00:00
|
|
|
void EGLImageTextureHost::CreateRenderTexture(
|
|
|
|
const wr::ExternalImageId& aExternalImageId) {
|
|
|
|
RefPtr<wr::RenderTextureHost> texture =
|
|
|
|
new wr::RenderEGLImageTextureHost(mImage, mSync, mSize);
|
|
|
|
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
|
|
|
|
texture.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EGLImageTextureHost::PushResourceUpdates(
|
|
|
|
wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
|
2019-12-06 06:53:57 +00:00
|
|
|
const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID,
|
|
|
|
const bool aPreferCompositorSurface) {
|
2019-04-02 03:16:20 +00:00
|
|
|
auto method = aOp == TextureHost::ADD_IMAGE
|
|
|
|
? &wr::TransactionBuilder::AddExternalImage
|
|
|
|
: &wr::TransactionBuilder::UpdateExternalImage;
|
2019-05-28 22:03:54 +00:00
|
|
|
auto imageType =
|
|
|
|
wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
2019-04-02 03:16:20 +00:00
|
|
|
|
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
// XXX Add RGBA handling. Temporary hack to avoid crash
|
|
|
|
// With BGRA format setting, rendering works without problem.
|
|
|
|
auto formatTmp = format == gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
? gfx::SurfaceFormat::B8G8R8A8
|
|
|
|
: gfx::SurfaceFormat::B8G8R8X8;
|
2019-12-06 06:53:57 +00:00
|
|
|
wr::ImageDescriptor descriptor(GetSize(), formatTmp,
|
|
|
|
aPreferCompositorSurface);
|
2019-05-28 22:03:54 +00:00
|
|
|
(aResources.*method)(aImageKeys[0], descriptor, aExtID, imageType, 0);
|
2019-04-02 03:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EGLImageTextureHost::PushDisplayItems(
|
|
|
|
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys) {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
|
|
|
|
!(mFlags & TextureFlags::NON_PREMULTIPLIED));
|
|
|
|
}
|
|
|
|
|
2015-09-24 14:11:53 +00: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) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-09-24 14:11:53 +00:00
|
|
|
GLTextureHost::~GLTextureHost() {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-09-24 14:11:53 +00:00
|
|
|
gl::GLContext* GLTextureHost::gl() const {
|
2017-03-22 03:32:54 +00:00
|
|
|
return mProvider ? mProvider->GetGLContext() : nullptr;
|
2015-09-24 14:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GLTextureHost::Lock() {
|
2016-03-22 14:28:27 +00:00
|
|
|
GLContext* gl = this->gl();
|
|
|
|
if (!gl || !gl->MakeCurrent()) {
|
2015-09-24 14:11:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSync) {
|
2016-03-22 14:28:27 +00:00
|
|
|
if (!gl->MakeCurrent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gl->fWaitSync(mSync, 0, LOCAL_GL_TIMEOUT_IGNORED);
|
|
|
|
gl->fDeleteSync(mSync);
|
2015-09-24 14:11:53 +00:00
|
|
|
mSync = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureSource) {
|
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::R8G8B8X8;
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource =
|
|
|
|
new GLTextureSource(mProvider, mTexture, mTarget, mSize, format);
|
2015-09-24 14:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-22 03:32:54 +00:00
|
|
|
|
|
|
|
void GLTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider) {
|
|
|
|
if (mProvider != aProvider) {
|
|
|
|
if (!aProvider || !aProvider->GetGLContext()) {
|
|
|
|
mProvider = nullptr;
|
|
|
|
mTextureSource = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mProvider = aProvider;
|
2016-03-22 14:28:27 +00:00
|
|
|
}
|
2017-03-22 03:32:54 +00:00
|
|
|
|
2015-09-24 14:11:53 +00:00
|
|
|
if (mTextureSource) {
|
2017-03-22 03:32:54 +00:00
|
|
|
mTextureSource->SetTextureSourceProvider(aProvider);
|
2015-09-24 14:11:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat GLTextureHost::GetFormat() const {
|
|
|
|
MOZ_ASSERT(mTextureSource);
|
2016-03-22 14:28:27 +00:00
|
|
|
return mTextureSource ? mTextureSource->GetFormat()
|
|
|
|
: gfx::SurfaceFormat::UNKNOWN;
|
2015-09-24 14:11:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|