Files
tubestation/gfx/layers/wr/WebRenderTextureHost.h
Jamie Nicol dc6e889fb4 Bug 1731980 - Ensure SurfaceTextures with transforms get rendered at correct size. r=gfx-reviewers,lsalzman
On Android we use SurfaceTextures to render content from sources such
as the video decoder. These may have a transform set which is supposed
to be applied to the texture coordinates used to sample the
texture. Webrender (and software webrender), however, do not handle
this correctly, meaning videos may be rendered at the incorrect size
on some devices.

SurfaceTextures should always be rendered with their bottom-left being
their origin, eg vertically flipped. Additionally, the texture
transform returned on most devices seems to be a simple y-flip
transform with no scaling. Webrender currently just ignores the y-flip
due to the texture origin, which cancels out us not handling the
y-flip from the transform, meaning video looks correct on most
devices. Some devices, however, do return a scaling transform which we
must handle.

This patch removes the override of WebRenderTextureHost::NeedsYFlip()
that was causing us to ignore the y-flip due to the texture origin -
since we will now apply the transform we must handle this correctly
too.

It adds a virtual method RenderTextureHost::GetUvCoords(), that
returns the texture coordinates that should be used by webrender to
sample from external textures. In most cases these are simply (0, 0)
and (size.x, size.y), but in RenderAndroidSurfaceTextureHost we
override this function to apply the transformation. This ensures we
use the correct coordinates whenever the texture is rendered by
webrender, eg in both software and hardware webrender when rendering
in the non-compositing-path, and by hardware webrender's draw
compositor. Additionally, the composite.glsl shader requires a fix to
calculate the UV bounds correctly, as the coordinates may now be
inverted.

Lastly, we fix software webrender with the OpenGL
compositor. CompositorOGL already has the required functionality to
apply the texture transformation as it was used back in the layers
days. We must simply ensure that we pass the value of the
mIgnoreTransform flag from the original SurfaceTextureHost, through to
the RenderAndroidSurfaceTextureHost, and finally to the
SurfaceTextureSource which we hand to CompositorOGL.

Differential Revision: https://phabricator.services.mozilla.com/D144306
2022-04-25 16:47:51 +00:00

104 lines
3.6 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/. */
#ifndef MOZILLA_GFX_WEBRENDERTEXTUREHOST_H
#define MOZILLA_GFX_WEBRENDERTEXTUREHOST_H
#include "mozilla/layers/TextureHost.h"
#include "mozilla/webrender/WebRenderTypes.h"
namespace mozilla {
namespace layers {
class SurfaceDescriptor;
// This textureHost is specialized for WebRender usage. With WebRender, there is
// no Compositor during composition. Instead, we use RendererOGL for
// composition. So, there are some UNREACHABLE asserts for the original
// Compositor related code path in this class. Furthermore, the RendererOGL runs
// at RenderThead instead of Compositor thread. This class is also creating the
// corresponding RenderXXXTextureHost used by RendererOGL at RenderThread.
class WebRenderTextureHost : public TextureHost {
public:
WebRenderTextureHost(const SurfaceDescriptor& aDesc, TextureFlags aFlags,
TextureHost* aTexture,
const wr::ExternalImageId& aExternalImageId);
virtual ~WebRenderTextureHost();
void DeallocateDeviceData() override {}
void UnbindTextureSource() override;
gfx::SurfaceFormat GetFormat() const override;
virtual void NotifyNotUsed() override;
virtual bool IsValid() override;
// Return the format used for reading the texture. Some hardware specific
// textureHosts use their special data representation internally, but we could
// treat these textureHost as the read-format when we read them.
// Please check TextureHost::GetReadFormat().
gfx::SurfaceFormat GetReadFormat() const override;
already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
gfx::ColorDepth GetColorDepth() const override;
gfx::YUVColorSpace GetYUVColorSpace() const override;
gfx::ColorRange GetColorRange() const override;
gfx::IntSize GetSize() const override;
#ifdef MOZ_LAYERS_HAVE_LOG
const char* Name() override { return "WebRenderTextureHost"; }
#endif
WebRenderTextureHost* AsWebRenderTextureHost() override { return this; }
bool IsWrappingBufferTextureHost() override;
virtual void PrepareForUse() override;
wr::ExternalImageId GetExternalImageKey();
int32_t GetRGBStride();
bool NeedsDeferredDeletion() const override;
uint32_t NumSubTextures() override;
void PushResourceUpdates(wr::TransactionBuilder& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys,
PushDisplayItemFlagSet aFlags) override;
bool SupportsExternalCompositing(WebRenderBackend aBackend) override;
void SetAcquireFence(mozilla::ipc::FileDescriptor&& aFenceFd) override;
void SetReleaseFence(mozilla::ipc::FileDescriptor&& aFenceFd) override;
mozilla::ipc::FileDescriptor GetAndResetReleaseFence() override;
AndroidHardwareBuffer* GetAndroidHardwareBuffer() const override;
void MaybeNotifyForUse(wr::TransactionBuilder& aTxn);
protected:
RefPtr<TextureHost> mWrappedTextureHost;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_WEBRENDERTEXTUREHOST_H