1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "RenderEGLImageTextureHost.h"
9 #include "mozilla/gfx/Logging.h"
10 #include "GLContextEGL.h"
11 #include "GLLibraryEGL.h"
16 RenderEGLImageTextureHost::RenderEGLImageTextureHost(EGLImage aImage
,
22 mTextureTarget(LOCAL_GL_TEXTURE_2D
),
24 MOZ_COUNT_CTOR_INHERITED(RenderEGLImageTextureHost
, RenderTextureHost
);
27 RenderEGLImageTextureHost::~RenderEGLImageTextureHost() {
28 MOZ_COUNT_DTOR_INHERITED(RenderEGLImageTextureHost
, RenderTextureHost
);
29 DeleteTextureHandle();
32 wr::WrExternalImage
RenderEGLImageTextureHost::Lock(uint8_t aChannelIndex
,
34 MOZ_ASSERT(aChannelIndex
== 0);
36 if (mGL
.get() != aGL
) {
38 // This should not happen. SharedSurface_EGLImage is created only in
40 MOZ_ASSERT_UNREACHABLE("Unexpected GL context");
41 return InvalidToWrExternalImage();
46 if (!mImage
|| !mGL
|| !mGL
->MakeCurrent()) {
47 return InvalidToWrExternalImage();
50 EGLint status
= LOCAL_EGL_CONDITION_SATISFIED
;
52 const auto& gle
= gl::GLContextEGL::Cast(mGL
);
53 const auto& egl
= gle
->mEgl
;
54 MOZ_ASSERT(egl
->IsExtensionSupported(gl::EGLExtension::KHR_fence_sync
));
55 status
= egl
->fClientWaitSync(mSync
, 0, LOCAL_EGL_FOREVER
);
56 // We do not need to delete sync here. It is deleted by
57 // SharedSurface_EGLImage.
61 if (status
!= LOCAL_EGL_CONDITION_SATISFIED
) {
64 "ClientWaitSync generated an error. Has mSync already been destroyed?");
65 return InvalidToWrExternalImage();
68 if (!mTextureHandle
) {
69 mTextureTarget
= mGL
->GetPreferredEGLImageTextureTarget();
70 MOZ_ASSERT(mTextureTarget
== LOCAL_GL_TEXTURE_2D
||
71 mTextureTarget
== LOCAL_GL_TEXTURE_EXTERNAL
);
73 mGL
->fGenTextures(1, &mTextureHandle
);
74 ActivateBindAndTexParameteri(mGL
, LOCAL_GL_TEXTURE0
, mTextureTarget
,
76 mGL
->fEGLImageTargetTexture2D(mTextureTarget
, mImage
);
79 const auto uvs
= GetUvCoords(mSize
);
80 return NativeTextureToWrExternalImage(
81 mTextureHandle
, uvs
.first
.x
, uvs
.first
.y
, uvs
.second
.x
, uvs
.second
.y
);
84 void RenderEGLImageTextureHost::Unlock() {}
86 void RenderEGLImageTextureHost::DeleteTextureHandle() {
88 // XXX recycle gl texture, since SharedSurface_EGLImage and
89 // RenderEGLImageTextureHost is not recycled.
90 mGL
->fDeleteTextures(1, &mTextureHandle
);
96 } // namespace mozilla