no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / gfx / webrender_bindings / RenderDMABUFTextureHost.cpp
blobf52535b95a44299cd43053d8e3a69c09f83d00f7
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,
26 gl::GLContext* aGL) {
27 if (mGL.get() != aGL) {
28 if (mGL) {
29 // This should not happen. EGLImage is created only in
30 // parent process.
31 MOZ_ASSERT_UNREACHABLE("Unexpected GL context");
32 return InvalidToWrExternalImage();
34 mGL = aGL;
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,
53 uvs.second.y);
56 void RenderDMABUFTextureHost::Unlock() {}
58 void RenderDMABUFTextureHost::DeleteTextureHandle() {
59 mSurface->ReleaseTextures();
62 void RenderDMABUFTextureHost::ClearCachedResources() {
63 DeleteTextureHandle();
64 mGL = nullptr;
67 } // namespace mozilla::wr