gecko-dev/gfx/webrender_bindings
Jamie Nicol 0c43a18e35 Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical
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
2024-09-09 14:06:26 +00:00
..
src Bug 1913568 - Add support for normalized UV coordinates to webrender. r=gfx-reviewers,nical 2024-09-09 14:06:26 +00:00
Cargo.toml Bug 1909873 - Allow enabling/disabling thread-local arenas for various webrender threads. r=gfx-reviewers,gw 2024-07-29 07:27:22 +00:00
cbindgen.toml
DCLayerTree.cpp Bug 1914306 - Disable Super Resolution explicitly when it is enabled but not used r=gfx-reviewers,lsalzman 2024-08-22 06:41:34 +00:00
DCLayerTree.h Bug 1908585 - Disable overlay only for slow present video r=gfx-reviewers,lsalzman 2024-07-24 00:21:16 +00:00
Moz2DImageRenderer.cpp
moz.build Bug 1894917 - Remove d3d10 header check to moz.configure r=glandium 2024-05-16 08:49:18 +00:00
README.webrender
RenderAndroidHardwareBufferTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderAndroidHardwareBufferTextureHost.h Bug 1898238 - Tidy up RenderCompositorOGLSWGL::HandleExternalImage. r=sotaro 2024-07-22 20:23:38 +00:00
RenderAndroidSurfaceTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderAndroidSurfaceTextureHost.h Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderBufferTextureHost.cpp Bug 1906527 Part 1: Rename SurfaceFormat::YUV422 to YUY2, and rename YUV to YUV420. r=jgilbert 2024-08-05 17:59:15 +00:00
RenderBufferTextureHost.h
RenderCompositor.cpp Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositor.h Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositorANGLE.cpp Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositorANGLE.h Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositorD3D11SWGL.cpp Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositorD3D11SWGL.h Bug 1879425 - Log GPU device reset to gfx Failure Log of about:support r=gfx-reviewers,lsalzman 2024-05-14 10:50:23 +00:00
RenderCompositorEGL.cpp Bug 1898476 [Wayland] Lock Wayland surface before Swap buffers in RenderCompositorEGL r=emilio 2024-07-10 10:59:53 +00:00
RenderCompositorEGL.h
RenderCompositorLayersSWGL.cpp Bug 1898238 - Make SharedSurface_EGLImage and (Render)EGLImageTextureHost work. r=sotaro,jgilbert 2024-07-22 20:23:38 +00:00
RenderCompositorLayersSWGL.h
RenderCompositorNative.cpp
RenderCompositorNative.h
RenderCompositorOGL.cpp
RenderCompositorOGL.h
RenderCompositorOGLSWGL.cpp Bug 1898238 - Tidy up RenderCompositorOGLSWGL::HandleExternalImage. r=sotaro 2024-07-22 20:23:38 +00:00
RenderCompositorOGLSWGL.h
RenderCompositorRecordedFrame.h
RenderCompositorSWGL.cpp
RenderCompositorSWGL.h
RenderD3D11TextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderD3D11TextureHost.h Bug 1906527 Part 1: Rename SurfaceFormat::YUV422 to YUY2, and rename YUV to YUV420. r=jgilbert 2024-08-05 17:59:15 +00:00
RenderDcompSurfaceTextureHost.cpp
RenderDcompSurfaceTextureHost.h
RenderDMABUFTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderDMABUFTextureHost.h
RenderEGLImageTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderEGLImageTextureHost.h Bug 1898238 - Make SharedSurface_EGLImage and (Render)EGLImageTextureHost work. r=sotaro,jgilbert 2024-07-22 20:23:38 +00:00
RendererOGL.cpp Backed out changeset 6dc11fc546e1 (bug 1716579) for causing bug 1900193. a=backout 2024-06-02 00:37:28 +03:00
RendererOGL.h Backed out changeset 6dc11fc546e1 (bug 1716579) for causing bug 1900193. a=backout 2024-06-02 00:37:28 +03:00
RendererScreenshotGrabber.cpp
RendererScreenshotGrabber.h
RenderExternalTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderExternalTextureHost.h Bug 1906527 Part 1: Rename SurfaceFormat::YUV422 to YUY2, and rename YUV to YUV420. r=jgilbert 2024-08-05 17:59:15 +00:00
RenderMacIOSurfaceTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderMacIOSurfaceTextureHost.h
RenderSharedSurfaceTextureHost.cpp
RenderSharedSurfaceTextureHost.h
RenderTextureHost.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderTextureHost.h Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderTextureHostSWGL.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderTextureHostSWGL.h
RenderTextureHostWrapper.cpp Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderTextureHostWrapper.h Bug 1913568 - Handle SurfaceTexture transforms in webrender, for reals this time. r=gfx-reviewers,media-playback-reviewers,padenot,nical 2024-09-09 14:06:26 +00:00
RenderThread.cpp Bug 1908585 - Disable overlay only for slow present video r=gfx-reviewers,lsalzman 2024-07-24 00:21:16 +00:00
RenderThread.h Bug 1908585 - Disable overlay only for slow present video r=gfx-reviewers,lsalzman 2024-07-24 00:21:16 +00:00
rustfmt.toml
webrender_ffi.h Bug 1909019 - Use ParamTraits_TiedFields/_IsEnumCase in WebRenderMessageUtils instead of PlainOldDataSerializer. (complete) r=gw,mccr8,ahale 2024-07-26 23:51:26 +00:00
WebRenderAPI.cpp Bug 1913568 - Add support for normalized UV coordinates to webrender. r=gfx-reviewers,nical 2024-09-09 14:06:26 +00:00
WebRenderAPI.h Bug 1913568 - Add support for normalized UV coordinates to webrender. r=gfx-reviewers,nical 2024-09-09 14:06:26 +00:00
WebRenderTypes.cpp Bug 1914777 - Use cbindgen for StyleBorderImageRepeatKeyword. r=firefox-style-system-reviewers,layout-reviewers,emilio 2024-08-25 15:57:04 +00:00
WebRenderTypes.h Bug 1914777 - Use cbindgen for StyleBorderImageRepeatKeyword. r=firefox-style-system-reviewers,layout-reviewers,emilio 2024-08-25 15:57:04 +00:00

To build and run WebRender in Gecko:
1. Install Rust if you don't have it already
   If you are doing gecko builds already, you should already have Rust as it is a build requirement.
   If not, you can install it using |mach bootstrap| (recommended) or from https://www.rust-lang.org/
       Note: If installing manually, use the stable 64-bit release - on Windows make sure to use the MSVC ABI installer.
   Ensure that rustc and cargo are in your $PATH (adding $HOME/.cargo/bin/ should be sufficient)
2. Build using |mach build|.
   You don't need anything special in your mozconfig for local builds; webrender will be built by default.
3. Run with |MOZ_WEBRENDER=1| in your environment. e.g. |MOZ_WEBRENDER=1 ./mach run|.
   Alternatively, you can set the gfx.webrender.all pref to true (browser restart required).
   Note that on Linux, acceleration is disabled by default and it needs to be enabled for WebRender to work.
   On Linux you can enable acceleration by putting |MOZ_ACCELERATED=1| in your environment, or setting layers.acceleration.force-enabled to true in about:config.
4. Verify WebRender is enabled. You can do this by going to about:support and checking the "Compositing" line in the Graphics section. It should say "WebRender".
   There should also be a WebRender section under "Decision Log" in about:support, which will provide some more detail on what caused it to be enabled/disabled.

When making changes:
    - Make the changes you want.
    - Run |mach build| or |mach build binaries| as desired.

For a debug webrender build:
    Use a debug mozconfig (ac_add_options --enable-debug)
    You can also use an opt build but make webrender less optimized by putting opt-level=0 in the [profile.release] section of your toolkit/library/rust/Cargo.toml file
    See also https://groups.google.com/forum/#!topic/mozilla.dev.servo/MbeMcqqO1fs