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 "RenderDMABUFTextureHost.h"
9 #include "GLContextEGL.h"
10 #include "mozilla/gfx/Logging.h"
11 #include "ScopedGLHelpers.h"
13 namespace mozilla::wr
{
15 RenderDMABUFTextureHost::RenderDMABUFTextureHost(DMABufSurface
* aSurface
)
16 : mSurface(aSurface
) {
17 MOZ_COUNT_CTOR_INHERITED(RenderDMABUFTextureHost
, RenderTextureHost
);
20 RenderDMABUFTextureHost::~RenderDMABUFTextureHost() {
21 MOZ_COUNT_DTOR_INHERITED(RenderDMABUFTextureHost
, RenderTextureHost
);
22 DeleteTextureHandle();
25 wr::WrExternalImage
RenderDMABUFTextureHost::Lock(uint8_t aChannelIndex
,
27 if (mGL
.get() != aGL
) {
29 // This should not happen. EGLImage is created only in
31 MOZ_ASSERT_UNREACHABLE("Unexpected GL context");
32 return InvalidToWrExternalImage();
37 if (!mGL
|| !mGL
->MakeCurrent()) {
38 return InvalidToWrExternalImage();
41 if (!mSurface
->GetTexture(aChannelIndex
)) {
42 if (!mSurface
->CreateTexture(mGL
, aChannelIndex
)) {
43 return InvalidToWrExternalImage();
45 ActivateBindAndTexParameteri(mGL
, LOCAL_GL_TEXTURE0
, LOCAL_GL_TEXTURE_2D
,
46 mSurface
->GetTexture(aChannelIndex
));
49 const auto uvs
= GetUvCoords(gfx::IntSize(
50 mSurface
->GetWidth(aChannelIndex
), mSurface
->GetHeight(aChannelIndex
)));
51 return NativeTextureToWrExternalImage(mSurface
->GetTexture(aChannelIndex
),
52 uvs
.first
.x
, uvs
.first
.y
, uvs
.second
.x
,
56 void RenderDMABUFTextureHost::Unlock() {}
58 void RenderDMABUFTextureHost::DeleteTextureHandle() {
59 mSurface
->ReleaseTextures();
62 void RenderDMABUFTextureHost::ClearCachedResources() {
63 DeleteTextureHandle();
67 } // namespace mozilla::wr