This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1532201 - Enable SurfaceFactory_EGLImage usage with WebRender r=n…
…ical Differential Revision: https://phabricator.services.mozilla.com/D24668
- Loading branch information
sotaro
committed
Apr 2, 2019
1 parent
ef4d36f
commit 4be36ac
Showing
6 changed files
with
211 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* -*- 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 | ||
* 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 "RenderEGLImageTextureHost.h" | ||
|
||
#include "mozilla/gfx/Logging.h" | ||
#include "GLContext.h" | ||
#include "GLLibraryEGL.h" | ||
|
||
namespace mozilla { | ||
namespace wr { | ||
|
||
RenderEGLImageTextureHost::RenderEGLImageTextureHost(EGLImage aImage, | ||
EGLSync aSync, | ||
gfx::IntSize aSize) | ||
: mImage(aImage), | ||
mSync(aSync), | ||
mSize(aSize), | ||
mTextureTarget(LOCAL_GL_TEXTURE_2D), | ||
mTextureHandle(0) { | ||
MOZ_COUNT_CTOR_INHERITED(RenderEGLImageTextureHost, RenderTextureHostOGL); | ||
} | ||
|
||
RenderEGLImageTextureHost::~RenderEGLImageTextureHost() { | ||
MOZ_COUNT_DTOR_INHERITED(RenderEGLImageTextureHost, RenderTextureHostOGL); | ||
DeleteTextureHandle(); | ||
} | ||
|
||
GLuint RenderEGLImageTextureHost::GetGLHandle(uint8_t aChannelIndex) const { | ||
return mTextureHandle; | ||
} | ||
|
||
gfx::IntSize RenderEGLImageTextureHost::GetSize(uint8_t aChannelIndex) const { | ||
return mSize; | ||
} | ||
|
||
wr::WrExternalImage RenderEGLImageTextureHost::Lock( | ||
uint8_t aChannelIndex, gl::GLContext* aGL, wr::ImageRendering aRendering) { | ||
MOZ_ASSERT(aChannelIndex == 0); | ||
|
||
if (mGL.get() != aGL) { | ||
if (mGL) { | ||
// This should not happen. SharedSurface_EGLImage is created only in | ||
// parent process. | ||
MOZ_ASSERT_UNREACHABLE("Unexpected GL context"); | ||
return InvalidToWrExternalImage(); | ||
} | ||
mGL = aGL; | ||
} | ||
|
||
if (!mImage || !mGL || !mGL->MakeCurrent()) { | ||
return InvalidToWrExternalImage(); | ||
} | ||
|
||
EGLint status = LOCAL_EGL_CONDITION_SATISFIED; | ||
if (mSync) { | ||
auto* egl = gl::GLLibraryEGL::Get(); | ||
MOZ_ASSERT(egl->IsExtensionSupported(gl::GLLibraryEGL::KHR_fence_sync)); | ||
status = egl->fClientWaitSync(egl->Display(), mSync, 0, LOCAL_EGL_FOREVER); | ||
// We do not need to delete sync here. It is deleted by | ||
// SharedSurface_EGLImage. | ||
mSync = 0; | ||
} | ||
|
||
if (status != LOCAL_EGL_CONDITION_SATISFIED) { | ||
MOZ_ASSERT( | ||
status != 0, | ||
"ClientWaitSync generated an error. Has mSync already been destroyed?"); | ||
return InvalidToWrExternalImage(); | ||
} | ||
|
||
if (!mTextureHandle) { | ||
mTextureTarget = mGL->GetPreferredEGLImageTextureTarget(); | ||
MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D || | ||
mTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL); | ||
|
||
mGL->fGenTextures(1, &mTextureHandle); | ||
// Cache rendering filter. | ||
mCachedRendering = aRendering; | ||
ActivateBindAndTexParameteri(mGL, LOCAL_GL_TEXTURE0, mTextureTarget, | ||
mTextureHandle, aRendering); | ||
mGL->fEGLImageTargetTexture2D(mTextureTarget, mImage); | ||
} else if (IsFilterUpdateNecessary(aRendering)) { | ||
// Cache new rendering filter. | ||
mCachedRendering = aRendering; | ||
ActivateBindAndTexParameteri(mGL, LOCAL_GL_TEXTURE0, mTextureTarget, | ||
mTextureHandle, aRendering); | ||
} | ||
|
||
return NativeTextureToWrExternalImage(mTextureHandle, 0, 0, mSize.width, | ||
mSize.height); | ||
} | ||
|
||
void RenderEGLImageTextureHost::Unlock() {} | ||
|
||
void RenderEGLImageTextureHost::DeleteTextureHandle() { | ||
if (mTextureHandle) { | ||
// XXX recycle gl texture, since SharedSurface_EGLImage and | ||
// RenderEGLImageTextureHost is not recycled. | ||
mGL->fDeleteTextures(1, &mTextureHandle); | ||
mTextureHandle = 0; | ||
} | ||
} | ||
|
||
} // namespace wr | ||
} // namespace mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* -*- 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 | ||
* 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/. */ | ||
|
||
#ifndef MOZILLA_GFX_RENDEREGLIMAGETEXTUREHOSTOGL_H | ||
#define MOZILLA_GFX_RENDEREGLIMAGETEXTUREHOSTOGL_H | ||
|
||
#include "mozilla/layers/TextureHostOGL.h" | ||
#include "RenderTextureHostOGL.h" | ||
|
||
namespace mozilla { | ||
|
||
namespace wr { | ||
|
||
// RenderEGLImageTextureHost is created only for SharedSurface_EGLImage that is | ||
// created in parent process. | ||
class RenderEGLImageTextureHost final : public RenderTextureHostOGL { | ||
public: | ||
RenderEGLImageTextureHost(EGLImage aImage, EGLSync aSync, gfx::IntSize aSize); | ||
|
||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL, | ||
wr::ImageRendering aRendering) override; | ||
void Unlock() override; | ||
|
||
virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const override; | ||
virtual GLuint GetGLHandle(uint8_t aChannelIndex) const override; | ||
|
||
private: | ||
virtual ~RenderEGLImageTextureHost(); | ||
void DeleteTextureHandle(); | ||
|
||
const EGLImage mImage; | ||
EGLSync mSync; | ||
const gfx::IntSize mSize; | ||
|
||
RefPtr<gl::GLContext> mGL; | ||
GLenum mTextureTarget; | ||
GLuint mTextureHandle; | ||
}; | ||
|
||
} // namespace wr | ||
} // namespace mozilla | ||
|
||
#endif // MOZILLA_GFX_RENDEREGLIMAGETEXTUREHOSTOGL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters