mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
0c43a18e35
On Android, SurfaceTextures provide a transform that should be applied to texture coordinates when sampling from the texture. Usually this is simply a y-flip, but sometimes it includes a scale and slight translation, eg when the video frame is contained within a larger texture. Previously we ignored this transform but performed a y-flip, meaning we rendered correctly most of the time, but not all of the time. Our first attempt to fix this was in bug 1731980. When rendering as a compositor surface with RenderCompositorOGLSWGL, we supplied the transform to CompositorOGL's shaders, which correctly fixed the bug for this rendering path. However, the attempted fix for hardware webrender in fact made things worse. As UV coordinates are supplied to webrender unnormalized, then the shaders normalize them by dividing by the actual texture size, this effectively handled the scale component of the transform. (Though not quite scaling by the correct amount, and ignoring the translation component, sometimes resulting in a pixel-wide green seam being visible at the video's edges.) When we additionally applied the transformation to the coordinates, it resulted in the scale being applied twice, and the video being rendered too far zoomed in. To make matters worse, when we received subsequent bug reports of incorrect rendering on various devices we mistakenly assumed that the devices must be buggy, rather than our code being incorrect. We therefore reverted to ignoring the transform on these devices, thereby breaking the software webrender path again. Additionally, on devices without GL_OES_EGL_image_external_essl3 support, we must sample from the SurfaceTexture using an ESSL1 shader. This means we do not have access to the correct texture size, meaning we cannot correctly normalize the UV coordinates. This results in the video being rendered too far zoomed out. And in the non-compositor-surface software webrender path, we were accidentally downscaling the texture when reading back into a CPU buffer, resulting in the video being rendered at the correct zoom, but being very blurry. This patch aims to handle the transform correctly, in all rendering paths, hopefully once and for all. For hardware webrender, we now supply the texture coordinates to webrender already normalized, using the functionality added in the previous patch. This avoids the shaders scaling the coordinates again, or using an incorrect texture size to do so. For RenderCompositorOGLSWGL, we continue to apply the transform using CompositorOGL's shaders. In the non-compositor-surface software webrender path, we make GLReadPixelsHelper apply the transform when reading from the SurfaceTexture in to the CPU buffer. Again using functionality added earlier in this patch series. This avoids downscaling the image. We can then provide the default untransformed and unnormalized UVs to webrender. As a result we can now remove the virtual function RenderTextureHost::GetUvCoords(), added in bug 1731980, as it no longer serves any purpose: we no longer want to share the implementation between RenderAndroidSurfaceTextureHost::Lock and RenderTextureHostSWGL::LockSWGL. Finally, we remove all transform overrides on the devices we mistakenly assumed were buggy. Differential Revision: https://phabricator.services.mozilla.com/D220582
240 lines
6.3 KiB
C++
240 lines
6.3 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 "RenderTextureHostWrapper.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
|
#include "mozilla/layers/RemoteTextureMap.h"
|
|
#include "mozilla/webrender/RenderThread.h"
|
|
|
|
namespace mozilla {
|
|
namespace wr {
|
|
|
|
RenderTextureHostWrapper::RenderTextureHostWrapper(
|
|
ExternalImageId aExternalImageId)
|
|
: mExternalImageId(aExternalImageId) {
|
|
MOZ_COUNT_CTOR_INHERITED(RenderTextureHostWrapper, RenderTextureHost);
|
|
EnsureTextureHost();
|
|
}
|
|
|
|
RenderTextureHostWrapper::~RenderTextureHostWrapper() {
|
|
MOZ_COUNT_DTOR_INHERITED(RenderTextureHostWrapper, RenderTextureHost);
|
|
}
|
|
|
|
void RenderTextureHostWrapper::EnsureTextureHost() const {
|
|
if (mTextureHost) {
|
|
return;
|
|
}
|
|
|
|
mTextureHost = RenderThread::Get()->GetRenderTexture(mExternalImageId);
|
|
MOZ_ASSERT(mTextureHost);
|
|
if (!mTextureHost) {
|
|
gfxCriticalNoteOnce << "Failed to get RenderTextureHost for extId:"
|
|
<< AsUint64(mExternalImageId);
|
|
}
|
|
}
|
|
|
|
wr::WrExternalImage RenderTextureHostWrapper::Lock(uint8_t aChannelIndex,
|
|
gl::GLContext* aGL) {
|
|
if (!mTextureHost) {
|
|
return InvalidToWrExternalImage();
|
|
}
|
|
|
|
return mTextureHost->Lock(aChannelIndex, aGL);
|
|
}
|
|
|
|
void RenderTextureHostWrapper::Unlock() {
|
|
if (mTextureHost) {
|
|
mTextureHost->Unlock();
|
|
}
|
|
}
|
|
|
|
void RenderTextureHostWrapper::ClearCachedResources() {
|
|
if (mTextureHost) {
|
|
mTextureHost->ClearCachedResources();
|
|
}
|
|
}
|
|
|
|
void RenderTextureHostWrapper::PrepareForUse() {
|
|
if (!mTextureHost) {
|
|
return;
|
|
}
|
|
mTextureHost->PrepareForUse();
|
|
}
|
|
|
|
void RenderTextureHostWrapper::NotifyForUse() {
|
|
if (!mTextureHost) {
|
|
return;
|
|
}
|
|
mTextureHost->NotifyForUse();
|
|
}
|
|
|
|
void RenderTextureHostWrapper::NotifyNotUsed() {
|
|
if (!mTextureHost) {
|
|
return;
|
|
}
|
|
mTextureHost->NotifyNotUsed();
|
|
}
|
|
|
|
bool RenderTextureHostWrapper::SyncObjectNeeded() { return false; }
|
|
|
|
RefPtr<layers::TextureSource> RenderTextureHostWrapper::CreateTextureSource(
|
|
layers::TextureSourceProvider* aProvider) {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->CreateTextureSource(aProvider);
|
|
}
|
|
|
|
RenderMacIOSurfaceTextureHost*
|
|
RenderTextureHostWrapper::AsRenderMacIOSurfaceTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderMacIOSurfaceTextureHost();
|
|
}
|
|
|
|
RenderDXGITextureHost* RenderTextureHostWrapper::AsRenderDXGITextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderDXGITextureHost();
|
|
}
|
|
|
|
RenderDXGIYCbCrTextureHost*
|
|
RenderTextureHostWrapper::AsRenderDXGIYCbCrTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderDXGIYCbCrTextureHost();
|
|
}
|
|
|
|
RenderDcompSurfaceTextureHost*
|
|
RenderTextureHostWrapper::AsRenderDcompSurfaceTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderDcompSurfaceTextureHost();
|
|
}
|
|
|
|
RenderTextureHostSWGL* RenderTextureHostWrapper::AsRenderTextureHostSWGL() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderTextureHostSWGL();
|
|
}
|
|
|
|
RenderAndroidHardwareBufferTextureHost*
|
|
RenderTextureHostWrapper::AsRenderAndroidHardwareBufferTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderAndroidHardwareBufferTextureHost();
|
|
}
|
|
|
|
RenderAndroidSurfaceTextureHost*
|
|
RenderTextureHostWrapper::AsRenderAndroidSurfaceTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderAndroidSurfaceTextureHost();
|
|
}
|
|
|
|
RenderEGLImageTextureHost*
|
|
RenderTextureHostWrapper::AsRenderEGLImageTextureHost() {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderEGLImageTextureHost();
|
|
}
|
|
|
|
RenderTextureHostSWGL* RenderTextureHostWrapper::EnsureRenderTextureHostSWGL()
|
|
const {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->AsRenderTextureHostSWGL();
|
|
}
|
|
|
|
void RenderTextureHostWrapper::SetIsSoftwareDecodedVideo() {
|
|
if (!mTextureHost) {
|
|
return;
|
|
}
|
|
return mTextureHost->SetIsSoftwareDecodedVideo();
|
|
}
|
|
|
|
bool RenderTextureHostWrapper::IsSoftwareDecodedVideo() {
|
|
if (!mTextureHost) {
|
|
return false;
|
|
}
|
|
return mTextureHost->IsSoftwareDecodedVideo();
|
|
}
|
|
|
|
RefPtr<RenderTextureHostUsageInfo>
|
|
RenderTextureHostWrapper::GetOrMergeUsageInfo(
|
|
const MutexAutoLock& aProofOfMapLock,
|
|
RefPtr<RenderTextureHostUsageInfo> aUsageInfo) {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->GetOrMergeUsageInfo(aProofOfMapLock, aUsageInfo);
|
|
}
|
|
|
|
RefPtr<RenderTextureHostUsageInfo>
|
|
RenderTextureHostWrapper::GetTextureHostUsageInfo(
|
|
const MutexAutoLock& aProofOfMapLock) {
|
|
if (!mTextureHost) {
|
|
return nullptr;
|
|
}
|
|
return mTextureHost->GetTextureHostUsageInfo(aProofOfMapLock);
|
|
}
|
|
|
|
size_t RenderTextureHostWrapper::GetPlaneCount() const {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
return swglHost->GetPlaneCount();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
gfx::SurfaceFormat RenderTextureHostWrapper::GetFormat() const {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
return swglHost->GetFormat();
|
|
}
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
}
|
|
|
|
gfx::ColorDepth RenderTextureHostWrapper::GetColorDepth() const {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
return swglHost->GetColorDepth();
|
|
}
|
|
return gfx::ColorDepth::COLOR_8;
|
|
}
|
|
|
|
gfx::YUVRangedColorSpace RenderTextureHostWrapper::GetYUVColorSpace() const {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
return swglHost->GetYUVColorSpace();
|
|
}
|
|
return gfx::YUVRangedColorSpace::Default;
|
|
}
|
|
|
|
bool RenderTextureHostWrapper::MapPlane(RenderCompositor* aCompositor,
|
|
uint8_t aChannelIndex,
|
|
PlaneInfo& aPlaneInfo) {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
return swglHost->MapPlane(aCompositor, aChannelIndex, aPlaneInfo);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void RenderTextureHostWrapper::UnmapPlanes() {
|
|
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
|
swglHost->UnmapPlanes();
|
|
}
|
|
}
|
|
|
|
} // namespace wr
|
|
} // namespace mozilla
|