Backed out changeset 39e6a7e77cfb (bug 1927808) for causing multiple failures. CLOSED...
[gecko.git] / gfx / webrender_bindings / RenderDMABUFTextureHost.cpp
bloba05d1d62928b3c6ffaa8e52518d37a298a5ff5e4
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 if (auto texture = mSurface->GetTexture(aChannelIndex)) {
50 mSurface->MaybeSemaphoreWait(texture);
53 const gfx::IntSize size(mSurface->GetWidth(aChannelIndex),
54 mSurface->GetHeight(aChannelIndex));
55 return NativeTextureToWrExternalImage(
56 mSurface->GetTexture(aChannelIndex), 0.0, 0.0,
57 static_cast<float>(size.width), static_cast<float>(size.height));
60 void RenderDMABUFTextureHost::Unlock() {}
62 void RenderDMABUFTextureHost::DeleteTextureHandle() {
63 mSurface->ReleaseTextures();
66 void RenderDMABUFTextureHost::ClearCachedResources() {
67 DeleteTextureHandle();
68 mGL = nullptr;
71 gfx::SurfaceFormat RenderDMABUFTextureHost::GetFormat() const {
72 return mSurface->GetFormat();
75 bool RenderDMABUFTextureHost::MapPlane(RenderCompositor* aCompositor,
76 uint8_t aChannelIndex,
77 PlaneInfo& aPlaneInfo) {
78 if (mSurface->GetAsDMABufSurfaceYUV()) {
79 // DMABufSurfaceYUV is not supported.
80 return false;
83 const RefPtr<gfx::SourceSurface> surface = mSurface->GetAsSourceSurface();
84 if (!surface) {
85 return false;
88 const RefPtr<gfx::DataSourceSurface> dataSurface = surface->GetDataSurface();
89 if (!dataSurface) {
90 return false;
93 gfx::DataSourceSurface::MappedSurface map;
94 if (!dataSurface->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
95 return false;
98 mReadback = dataSurface;
99 aPlaneInfo.mSize = gfx::IntSize(mSurface->GetWidth(), mSurface->GetHeight());
100 aPlaneInfo.mStride = map.mStride;
101 aPlaneInfo.mData = map.mData;
103 return true;
106 void RenderDMABUFTextureHost::UnmapPlanes() {
107 if (mReadback) {
108 mReadback->Unmap();
109 mReadback = nullptr;
113 } // namespace mozilla::wr