forked from mirrors/gecko-dev
If an external image shows up multiple times while using a different image rendering setting on each instance, we can erroneously call handler.lock() for each instance in parallel, thus defaulting to the last image rendering setting supplied for all instances in that batch. To work around this, we get rid of the concept of having RenderTextureHosts maintain and set the image rendering state, which results in a nice simplification. Then, when we go to actually bind an external image inside WebRender, we set the image rendering state at that point, so that regardless of how many instances of an external image are locked simultaneously, we always use the correct image rendering setting for a batch. Differential Revision: https://phabricator.services.mozilla.com/D158920
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
/* -*- 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 "RenderDMABUFTextureHost.h"
|
|
|
|
#include "GLContextEGL.h"
|
|
#include "mozilla/gfx/Logging.h"
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
namespace mozilla::wr {
|
|
|
|
RenderDMABUFTextureHost::RenderDMABUFTextureHost(DMABufSurface* aSurface)
|
|
: mSurface(aSurface) {
|
|
MOZ_COUNT_CTOR_INHERITED(RenderDMABUFTextureHost, RenderTextureHost);
|
|
}
|
|
|
|
RenderDMABUFTextureHost::~RenderDMABUFTextureHost() {
|
|
MOZ_COUNT_DTOR_INHERITED(RenderDMABUFTextureHost, RenderTextureHost);
|
|
DeleteTextureHandle();
|
|
}
|
|
|
|
wr::WrExternalImage RenderDMABUFTextureHost::Lock(uint8_t aChannelIndex,
|
|
gl::GLContext* aGL) {
|
|
if (mGL.get() != aGL) {
|
|
if (mGL) {
|
|
// This should not happen. EGLImage is created only in
|
|
// parent process.
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected GL context");
|
|
return InvalidToWrExternalImage();
|
|
}
|
|
mGL = aGL;
|
|
}
|
|
|
|
if (!mGL || !mGL->MakeCurrent()) {
|
|
return InvalidToWrExternalImage();
|
|
}
|
|
|
|
if (!mSurface->GetTexture(aChannelIndex)) {
|
|
if (!mSurface->CreateTexture(mGL, aChannelIndex)) {
|
|
return InvalidToWrExternalImage();
|
|
}
|
|
ActivateBindAndTexParameteri(mGL, LOCAL_GL_TEXTURE0, LOCAL_GL_TEXTURE_2D,
|
|
mSurface->GetTexture(aChannelIndex));
|
|
}
|
|
|
|
const auto uvs = GetUvCoords(gfx::IntSize(
|
|
mSurface->GetWidth(aChannelIndex), mSurface->GetHeight(aChannelIndex)));
|
|
return NativeTextureToWrExternalImage(mSurface->GetTexture(aChannelIndex),
|
|
uvs.first.x, uvs.first.y, uvs.second.x,
|
|
uvs.second.y);
|
|
}
|
|
|
|
void RenderDMABUFTextureHost::Unlock() {}
|
|
|
|
void RenderDMABUFTextureHost::DeleteTextureHandle() {
|
|
mSurface->ReleaseTextures();
|
|
}
|
|
|
|
void RenderDMABUFTextureHost::ClearCachedResources() {
|
|
DeleteTextureHandle();
|
|
mGL = nullptr;
|
|
}
|
|
|
|
} // namespace mozilla::wr
|