Files
palemoon27/gfx/layers/opengl/TextureHostOGL.cpp
T
roytam1 a057fcd85b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1201329 - Use AlignedStorage2 instead of char[] for IPDL union members. r=billm (420db1710)
- Bug 1146214 - Remove unused set fence functions. r=nical (148188894)
- Bug 1146214 - Combine FenceHandle and FenceHandleFromChild. r=nical (9d33cdedc)
- Bug 1147894 - Remove the redundant OpUpdateTexture IPDL message. r=sotaro (c3b037c92)
- Bug 1146214 - Implement fence delivery. Combine ipc messages and remove reply fence delivery message. r=nical (cd115f0db)
- Bug 1146214 - Remove the unused code after refactoring. r=nical (2582f1dfa)
- Bug 1146214 - Rename some functions after refactoring. r=nical (fd7655c71)
- Bug 1150381 - [LayerScope]: Don't showing the same texture in the same frame on LayerScope. r=chiajung (7a5310113)
- Bug 1162395 - [LayerScope]: No need to read and send the texture when the same texture id contains in a frame. r=cku (2c67a0994)
- Bug 1168015 - Dump source image from graphic buffer directly on B2G. r=kamidphish, r=hshih (108f3dd5a)
- Bug 1158575: Support using GDI rendering for opaque surfaces when using cross-process layers. r=jrmuizel (8913ea2ff)
- Bug 1155498 - Use FdObj to replace FenceHandle's android fence. r=sotaro (ac0f66f02)
- Bug 1155498 - Part 2 - Use new FenceHandle to handle the fence in TextureHost. r=sotaro (8c3cd6427)
- Bug 1152370 part 1 - Add android aosp VirtualDisplaySurface r=mwu (795674527)
- Bug 1152370 part 2 - Add DisplaySurface r=mwu (f4e7cb123)
- Bug 1151936 - Update GLContextEGL's EGLSurface override handling r=jgilbert (a1a72947b)
- Bug 1154313 - Move sUsingHwc to gfxPrefs r=mwu,nical (d315f572a)
- Bug 1152361 - Ensure outbufAcquireFenceFd is initialized during boot animation. r=mwu (c17f9bc1a)
- Bug 1152135 - Split EGLSurface buffer swap and HWC buffer swap r=mwu,nical,jgilbert (2ec0aaccc)
- Bug 1148149 - Support Android Presentation API. r=snorp, r=jgilbert (60ae01557)
- Bug 1150518 - Remove glClear() on blit composition r=Sushil (24b242a14)
- Bug 1152370 part 3 - Use DisplaySurface r=mwu (c531c0b44)
- Bug 1157661 - Fix a null-check in CompositorOGL::DrawQuad. r=nical (c00d429d3)
- Bug 1113425 part 1 - Fix some bad CSS comment syntax in animation tests; r=mattwoodrow (7abbbb3de)
- Bug 1113425 part 2 - Apply async properties when querying the animated transform; r=mattwoodrow (52e778eeb)
- Bug 1113425 part 4 - Enable test_deferred_start.html on all platforms; r=mattwoodrow (3884a02a3)
- Bug 1113425 part 3 - Make test_deferred_start.html wait an extra frame; r=mattwoodrow (0971c8836)
- Bug 1148949 - Apply async properties when querying the animated transform for cross-process compositor parents too; r=mattwoodrow (8bdeafc25)
- Bug 1157066. When reading back the OMTA transfrom of a layer don't include transforms from async panning or zooming. r=kats,birtles (43c1bab02)
- Bug 1129133 - Clean up GeckoTouchDispatcher so that it's a real singleton. r=kats,mwu (ac97ee5f4)
- Bug 1140578 - Remove some redundant code and an unused return value. r=mchang (9d02a9794)
- Bug 1140578 - Simplify some code. r=mchang (5a2f95805)
- Bug 1140578 - Add a explicit flag to track if we have pending touch moves to process. r=mchang (3255a2ac8)
- Bug 1140578 - Prevent resampling moves across non-move touch events. r=mchang (5a2622f6c)
- Bug 1146987 - Deal with cases where we get a batch of interleaved move and non-move events on the libui thread before anything is processed, with resampling disabled. r=mchang (462ce355c)
- Bug 1149412 - Remove bad assertion. r=mchang (d9d2db4ba)
- Bug 1137151: Marked destructor of |GeckoTouchDispatcher| as protected, r=mwu (21fae6af2)
- Bug 1138502. Reset vsync unobserve count if a force composite occurs. r=mstange (9682c9e62)
- Bug 1148583 - Dispatch touch events before composites. r=kats (cfabb0eef)
- Bug 1128690 - Ensure Talos Performance Tests still work with silk enabled. r=mstange (089e87b89)
- Bug 1138181 - Be more aggressive in updating plugin geometry in the compositor, avoids filtering out important offset updates that don't involve remote layer tree updates. r=roc (e341636de)
- comment coming from Bug 1143249 (2f6c7bdc8)
- Bug 1154614 - Don't try to pick up the same non-reentrant lock twice. r=dvander a=RyanVM (c69cba3d9)
- Bug 1156981 - Split CompositorParent's scheduling of composition to CompositorScheduler r=mchang (bf87b2ba3)
- Bug 1139541 - Make HWC skip opacity=0 layers. r=sotaro (cd6d5114c)
- Bug 1149646 - Delete non-uniform vsync interval warning. r=kats (5bc0cd3fa)
- Bug 1155498 - Part 3 - Use new FenceHandle to handle the fence in Compositor. r=sotaro (f5c685606)
-  Bug 1155498 - Part 4 - Use new FenceHandle to handle the fence in TextureClient. r=sotaro (0390d19fd)
- Bug 1155498 - Part 5 - Use new FenceHandle to handle Decoder fence. r=sotaro (a99b62351)
- Bug 1164513 - Add nullptr check r=milan (41053d048)
- Bug 1155495 - Part 1: Remove TextureHostOGL and integrate the platform specific API into TextureHost. r=nical, r=sotaro (9c909e5e2)
- Bug 1155495 - Part 2: Remove unnecessary class inheritance and casting. r=nical, r=sotaro (4ce5869ff)
- Bug 1133007 - Send the content of a texture only if its was altered since previous transmission. r=kamidphish, r=boris (f78a07160)
- Bug 1156456 patch 1 - Reftests comparing a 3-D transformed cube generated by main-thread paths and off-main-thread animations paths. r=birtles (f0f5309d9)
- Bug 1156456 patch 2 - Transform the z component just like the x and y. r=birtles (cc36b5b91)
- Bug 1156456 patch 3 - Send transform origin and perspective origin to layer in device pixels rather than CSS pixels. r=birtles (94ea8a04a)
- Bug 1156456 followup - Also annotate as fuzzy on Mulet, on a CLOSED TREE. (712c97eff)
- Bug 1156456 followup - Add a simple reftest for off-main-thread animation of opacity. (eac0fe0e4)
- Bug 1157455 patch 1 - Add tests for OMTA transforms in degrees in addition to those in radians. r=birtles (83fb5b7af)
- Bug 1157455 patch 2 - Send angles (in CSS transform functions) to the compositor thread with their units rather than sending all such angles in radians. r=birtles (a8b47f5b0)
- Bug 1157455 patch 3 - When interpolating angles, preserve units when possible in order to avoid floating point error. r=birtles (ace148e00)
- Bug 1157455 followup - fix test_transitions_per_property.html to expect different angle interpolation results, on a CLOSED TREE. (270ef56eb)
- Bug 1022080 - Don't force intermediate surfaces when dumping textures, unless explicitly specified. r=nical (0a010b6c8)
- Bug 1022080 - Make non-HTML dumping of textures work better. r=nical (304939544)
2020-12-02 09:53:44 +08:00

623 lines
17 KiB
C++

/* -*- 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"
#include "EGLUtils.h"
#include "GLContext.h" // for GLContext, etc
#include "GLLibraryEGL.h" // for GLLibraryEGL
#include "GLUploadHelpers.h"
#include "GLReadTexImageHelper.h"
#include "gfx2DGlue.h" // for ContentForFormat, etc
#include "gfxReusableSurfaceWrapper.h" // for gfxReusableSurfaceWrapper
#include "mozilla/gfx/2D.h" // for DataSourceSurface
#include "mozilla/gfx/BaseSize.h" // for BaseSize
#include "mozilla/gfx/Logging.h" // for gfxCriticalError
#ifdef MOZ_WIDGET_GONK
# include "GrallocImages.h" // for GrallocImage
# include "EGLImageHelpers.h"
#endif
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "mozilla/layers/GrallocTextureHost.h"
#include "nsRegion.h" // for nsIntRegion
#include "AndroidSurfaceTexture.h"
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
#include "GLBlitTextureImageHelper.h"
#ifdef XP_MACOSX
#include "SharedSurfaceIO.h"
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
#endif
#include "GeckoProfiler.h"
using namespace mozilla::gl;
using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
class Compositor;
already_AddRefed<TextureHost>
CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
ISurfaceAllocator* aDeallocator,
TextureFlags aFlags)
{
RefPtr<TextureHost> result;
switch (aDesc.type()) {
case SurfaceDescriptor::TSurfaceDescriptorShmem:
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
result = CreateBackendIndependentTextureHost(aDesc,
aDeallocator, aFlags);
break;
}
#ifdef MOZ_WIDGET_ANDROID
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
result = new SurfaceTextureHost(aFlags,
(AndroidSurfaceTexture*)desc.surfTex(),
desc.size());
break;
}
#endif
case SurfaceDescriptor::TEGLImageDescriptor: {
const EGLImageDescriptor& desc = aDesc.get_EGLImageDescriptor();
result = new EGLImageTextureHost(aFlags,
(EGLImage)desc.image(),
(EGLSync)desc.fence(),
desc.size());
break;
}
#ifdef XP_MACOSX
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
const SurfaceDescriptorMacIOSurface& desc =
aDesc.get_SurfaceDescriptorMacIOSurface();
result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
break;
}
#endif
#ifdef MOZ_WIDGET_GONK
case SurfaceDescriptor::TNewSurfaceDescriptorGralloc: {
const NewSurfaceDescriptorGralloc& desc =
aDesc.get_NewSurfaceDescriptorGralloc();
result = new GrallocTextureHostOGL(aFlags, desc);
break;
}
#endif
default: return nullptr;
}
return result.forget();
}
static gl::TextureImage::Flags
FlagsToGLFlags(TextureFlags aFlags)
{
uint32_t result = TextureImage::NoFlags;
if (aFlags & TextureFlags::USE_NEAREST_FILTER)
result |= TextureImage::UseNearestFilter;
if (aFlags & TextureFlags::ORIGIN_BOTTOM_LEFT)
result |= TextureImage::OriginBottomLeft;
if (aFlags & TextureFlags::DISALLOW_BIGIMAGE)
result |= TextureImage::DisallowBigImage;
return static_cast<gl::TextureImage::Flags>(result);
}
bool
TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
nsIntRegion* aDestRegion,
gfx::IntPoint* aSrcOffset)
{
GLContext *gl = mCompositor->gl();
MOZ_ASSERT(gl);
if (!gl) {
NS_WARNING("trying to update TextureImageTextureSourceOGL without a GLContext");
return false;
}
if (!aSurface) {
gfxCriticalError() << "Invalid surface for OGL update";
return false;
}
MOZ_ASSERT(aSurface);
IntSize size = aSurface->GetSize();
if (!mTexImage ||
(mTexImage->GetSize() != size && !aSrcOffset) ||
mTexImage->GetContentType() != gfx::ContentForFormat(aSurface->GetFormat())) {
if (mFlags & TextureFlags::DISALLOW_BIGIMAGE) {
GLint maxTextureSize;
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
if (size.width > maxTextureSize || size.height > maxTextureSize) {
NS_WARNING("Texture exceeds maximum texture size, refusing upload");
return false;
}
// Explicitly use CreateBasicTextureImage instead of CreateTextureImage,
// because CreateTextureImage might still choose to create a tiled
// texture image.
mTexImage = CreateBasicTextureImage(gl, size,
gfx::ContentForFormat(aSurface->GetFormat()),
LOCAL_GL_CLAMP_TO_EDGE,
FlagsToGLFlags(mFlags),
SurfaceFormatToImageFormat(aSurface->GetFormat()));
} else {
// XXX - clarify which size we want to use. IncrementalContentHost will
// require the size of the destination surface to be different from
// the size of aSurface.
// See bug 893300 (tracks the implementation of ContentHost for new textures).
mTexImage = CreateTextureImage(gl,
size,
gfx::ContentForFormat(aSurface->GetFormat()),
LOCAL_GL_CLAMP_TO_EDGE,
FlagsToGLFlags(mFlags),
SurfaceFormatToImageFormat(aSurface->GetFormat()));
}
ClearCachedFilter();
if (aDestRegion &&
!aSrcOffset &&
!aDestRegion->IsEqual(gfx::IntRect(0, 0, size.width, size.height))) {
// 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);
}
}
mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
if (mTexImage->InUpdate()) {
mTexImage->EndUpdate();
}
return true;
}
void
TextureImageTextureSourceOGL::EnsureBuffer(const nsIntSize& aSize,
gfxContentType aContentType)
{
if (!mTexImage ||
mTexImage->GetSize() != aSize ||
mTexImage->GetContentType() != aContentType) {
mTexImage = CreateTextureImage(mCompositor->gl(),
aSize,
aContentType,
LOCAL_GL_CLAMP_TO_EDGE,
FlagsToGLFlags(mFlags));
}
mTexImage->Resize(aSize);
}
void
TextureImageTextureSourceOGL::CopyTo(const gfx::IntRect& aSourceRect,
DataTextureSource *aDest,
const gfx::IntRect& aDestRect)
{
MOZ_ASSERT(aDest->AsSourceOGL(), "Incompatible destination type!");
TextureImageTextureSourceOGL *dest =
aDest->AsSourceOGL()->AsTextureImageTextureSource();
MOZ_ASSERT(dest, "Incompatible destination type!");
mCompositor->BlitTextureImageHelper()->BlitTextureImage(mTexImage, aSourceRect,
dest->mTexImage, aDestRect);
dest->mTexImage->MarkValid();
}
void
TextureImageTextureSourceOGL::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
if (!glCompositor || (mCompositor != glCompositor)) {
DeallocateDeviceData();
mCompositor = glCompositor;
}
}
gfx::IntSize
TextureImageTextureSourceOGL::GetSize() const
{
if (mTexImage) {
if (mIterating) {
return mTexImage->GetTileRect().Size();
}
return mTexImage->GetSize();
}
NS_WARNING("Trying to query the size of an empty TextureSource.");
return gfx::IntSize(0, 0);
}
gfx::SurfaceFormat
TextureImageTextureSourceOGL::GetFormat() const
{
if (mTexImage) {
return mTexImage->GetTextureFormat();
}
NS_WARNING("Trying to query the format of an empty TextureSource.");
return gfx::SurfaceFormat::UNKNOWN;
}
gfx::IntRect TextureImageTextureSourceOGL::GetTileRect()
{
return ThebesIntRect(mTexImage->GetTileRect());
}
void
TextureImageTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
{
MOZ_ASSERT(mTexImage,
"Trying to bind a TextureSource that does not have an underlying GL texture.");
mTexImage->BindTexture(aTextureUnit);
SetFilter(mCompositor->gl(), aFilter);
}
////////////////////////////////////////////////////////////////////////
// GLTextureSource
GLTextureSource::GLTextureSource(CompositorOGL* aCompositor,
GLuint aTextureHandle,
GLenum aTarget,
gfx::IntSize aSize,
gfx::SurfaceFormat aFormat,
bool aExternallyOwned)
: mCompositor(aCompositor)
, mTextureHandle(aTextureHandle)
, mTextureTarget(aTarget)
, mSize(aSize)
, mFormat(aFormat)
, mExternallyOwned(aExternallyOwned)
{
MOZ_COUNT_CTOR(GLTextureSource);
}
GLTextureSource::~GLTextureSource()
{
MOZ_COUNT_DTOR(GLTextureSource);
if (!mExternallyOwned) {
DeleteTextureHandle();
}
}
void
GLTextureSource::DeallocateDeviceData()
{
if (!mExternallyOwned) {
DeleteTextureHandle();
}
}
void
GLTextureSource::DeleteTextureHandle()
{
if (mTextureHandle != 0 && gl() && gl()->MakeCurrent()) {
gl()->fDeleteTextures(1, &mTextureHandle);
}
mTextureHandle = 0;
}
void
GLTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
{
MOZ_ASSERT(gl());
MOZ_ASSERT(mTextureHandle != 0);
if (!gl()) {
return;
}
gl()->fActiveTexture(aTextureUnit);
gl()->fBindTexture(mTextureTarget, mTextureHandle);
ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
}
void
GLTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorOGL*>(aCompositor);
}
bool
GLTextureSource::IsValid() const
{
return !!gl() && mTextureHandle != 0;
}
gl::GLContext*
GLTextureSource::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// SurfaceTextureHost
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureSource::SurfaceTextureSource(CompositorOGL* aCompositor,
AndroidSurfaceTexture* aSurfTex,
gfx::SurfaceFormat aFormat,
GLenum aTarget,
GLenum aWrapMode,
gfx::IntSize aSize)
: mCompositor(aCompositor)
, mSurfTex(aSurfTex)
, mFormat(aFormat)
, mTextureTarget(aTarget)
, mWrapMode(aWrapMode)
, mSize(aSize)
{
}
void
SurfaceTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
{
if (!gl()) {
NS_WARNING("Trying to bind a texture without a GLContext");
return;
}
gl()->fActiveTexture(aTextureUnit);
// SurfaceTexture spams us if there are any existing GL errors, so
// we'll clear them here in order to avoid that.
gl()->FlushErrors();
mSurfTex->UpdateTexImage();
ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
}
void
SurfaceTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
if (mCompositor != aCompositor) {
DeallocateDeviceData();
}
mCompositor = static_cast<CompositorOGL*>(aCompositor);
}
bool
SurfaceTextureSource::IsValid() const
{
return !!gl();
}
gl::GLContext*
SurfaceTextureSource::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
gfx::Matrix4x4
SurfaceTextureSource::GetTextureTransform()
{
gfx::Matrix4x4 ret;
mSurfTex->GetTransformMatrix(ret);
return ret;
}
////////////////////////////////////////////////////////////////////////
SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize)
: TextureHost(aFlags)
, mSurfTex(aSurfTex)
, mSize(aSize)
, mCompositor(nullptr)
{
}
SurfaceTextureHost::~SurfaceTextureHost()
{
}
gl::GLContext*
SurfaceTextureHost::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
bool
SurfaceTextureHost::Lock()
{
if (!mCompositor) {
return false;
}
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);
}
return NS_SUCCEEDED(mSurfTex->Attach(gl()));
}
void
SurfaceTextureHost::Unlock()
{
mSurfTex->Detach();
}
void
SurfaceTextureHost::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
}
}
gfx::SurfaceFormat
SurfaceTextureHost::GetFormat() const
{
MOZ_ASSERT(mTextureSource);
return mTextureSource->GetFormat();
}
#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)
, mFormat(aFormat)
, mTextureTarget(aTarget)
, mWrapMode(aWrapMode)
, mSize(aSize)
{
}
void
EGLImageTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
{
if (!gl()) {
NS_WARNING("Trying to bind a texture without a GLContext");
return;
}
MOZ_ASSERT(DoesEGLContextSupportSharingWithEGLImage(gl()),
"EGLImage not supported or disabled in runtime");
GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
gl()->fActiveTexture(aTextureUnit);
gl()->fBindTexture(mTextureTarget, tex);
MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D);
gl()->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, mImage);
ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
}
void
EGLImageTextureSource::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
mCompositor = static_cast<CompositorOGL*>(aCompositor);
}
bool
EGLImageTextureSource::IsValid() const
{
return !!gl();
}
gl::GLContext*
EGLImageTextureSource::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
gfx::Matrix4x4
EGLImageTextureSource::GetTextureTransform()
{
gfx::Matrix4x4 ret;
return ret;
}
////////////////////////////////////////////////////////////////////////
EGLImageTextureHost::EGLImageTextureHost(TextureFlags aFlags,
EGLImage aImage,
EGLSync aSync,
gfx::IntSize aSize)
: TextureHost(aFlags)
, mImage(aImage)
, mSync(aSync)
, mSize(aSize)
, mCompositor(nullptr)
{
}
EGLImageTextureHost::~EGLImageTextureHost()
{
}
gl::GLContext*
EGLImageTextureHost::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
bool
EGLImageTextureHost::Lock()
{
if (!mCompositor) {
return false;
}
EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), mSync, 0, LOCAL_EGL_FOREVER);
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
return false;
}
if (!mTextureSource) {
gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
GLenum target = LOCAL_GL_TEXTURE_2D;
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
mTextureSource = new EGLImageTextureSource(mCompositor,
mImage,
format,
target,
wrapMode,
mSize);
}
return true;
}
void
EGLImageTextureHost::Unlock()
{
}
void
EGLImageTextureHost::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor);
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
}
}
gfx::SurfaceFormat
EGLImageTextureHost::GetFormat() const
{
MOZ_ASSERT(mTextureSource);
return mTextureSource->GetFormat();
}
} // namespace layers
} // namespace mozilla