Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5c9058b92f41f6d455696fa2431677278c08641b
      
https://github.com/WebKit/WebKit/commit/5c9058b92f41f6d455696fa2431677278c08641b
  Author: Nikolas Zimmermann <[email protected]>
  Date:   2026-09-24 (Thu, 24 Sep 2026)

  Changed paths:
    A 
LayoutTests/transforms/3d/general/preserve-3d-intersecting-planes-across-camera-plane-expected.html
    A 
LayoutTests/transforms/3d/general/preserve-3d-intersecting-planes-across-camera-plane.html
    A 
LayoutTests/transforms/3d/general/preserve-3d-plane-across-camera-plane-expected.html
    A 
LayoutTests/transforms/3d/general/preserve-3d-plane-across-camera-plane.html
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    A Source/WebCore/platform/graphics/Polygon4D.cpp
    A Source/WebCore/platform/graphics/Polygon4D.h
    M Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.cpp
    M Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.h
    M 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayer3DRenderingContext.cpp
    M 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayer3DRenderingContext.h
    M 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayerOverlapRegions.cpp

  Log Message:
  -----------
  [GTK][WPE] preserve-3d layers are painted in the wrong order when a layer 
crosses the camera plane
https://bugs.webkit.org/show_bug.cgi?id=324944

Reviewed by Fujii Hironori.

To paint a preserve-3d scene, we sort its layers from back to front in a BSP
tree, which splits layers, where they intersect. We map the corners of a
layer through its perspective transform, yielding x, y, z and w. w is the
distance of the corner in front of the camera, scaled by the perspective.
Dividing x, y and z by w then results in the position on the screen. However,
a corner behind the camera has a negative w, so the division flips it to the
other side of the screen, far away. The polygon built from such corners no
longer matches the layer/reality: it covers the wrong part of the screen and
thus lies in the wrong plane. The BSP tree then splits and orders layers
against that wrong polygon, and far layers get painted over near ones.
This is the root cause that's breaking https://keithclark.co.uk/labs/css-fps/.

321515@main fixed the same kind of problem for filters, where mapping points
of a plane that reaches behind the camera also went wrong.

To fix it for the preserve-3d scenes, introduce a new Polygon4D class,
separate from FloatPolygon3D, which TextureMapper keeps using, as we only
want to change the Skia-based compositor and keep TextureMapper as it was.

Polygon4D keeps the mapped corner x/y/z positions as they are (no w division!)
and clips away the part of the layer that lies behind the camera, where w<0.
Layers that are fully behind the camera are then dropped. Sorting and splitting
now work on these polygons, instead of on corners that were divided by w.
Classifying and splitting now share the same distance tolerance.

We can now also refactor projectedBoundingBox() to use the very same logic,
instead of handling each possible number of corners behind the camera
separately, which greatly simplifies the code.

Tests: 
transforms/3d/general/preserve-3d-intersecting-planes-across-camera-plane.html
       transforms/3d/general/preserve-3d-plane-across-camera-plane.html

* 
LayoutTests/transforms/3d/general/preserve-3d-intersecting-planes-across-camera-plane-expected.html:
 Added.
* 
LayoutTests/transforms/3d/general/preserve-3d-intersecting-planes-across-camera-plane.html:
 Added.
* 
LayoutTests/transforms/3d/general/preserve-3d-plane-across-camera-plane-expected.html:
 Added.
* LayoutTests/transforms/3d/general/preserve-3d-plane-across-camera-plane.html: 
Added.
* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/platform/graphics/Polygon4D.cpp: Added.
(WebCore::splitPolygon):
(WebCore::Polygon4D::clipToFrontOfCamera):
(WebCore::Polygon4D::Polygon4D):
(WebCore::Polygon4D::split const):
* Source/WebCore/platform/graphics/Polygon4D.h: Added.
(WebCore::operator+):
(WebCore::operator-):
(WebCore::operator*):
(WebCore::operator/):
(WebCore::signedDistanceToPlane):
(WebCore::Polygon4D::numberOfVertices const):
* Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.cpp:
(WebCore::SkiaCompositingLayer::geometryFor3DRenderingContext const):
(WebCore::SkiaCompositingLayer::collect3DRenderingContextLayers):
* Source/WebCore/platform/graphics/skia/SkiaCompositingLayer.h:
* 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayer3DRenderingContext.cpp:
(WebCore::projectPolygonToZYPlane):
(WebCore::projectPolygonOnAxis):
(WebCore::polygonsIntersect):
(WebCore::SkiaCompositingLayer3DRenderingContext::paint):
(WebCore::SkiaCompositingLayer3DRenderingContext::computeBoundingBox):
(WebCore::SkiaCompositingLayer3DRenderingContext::buildTree):
(WebCore::SkiaCompositingLayer3DRenderingContext::traverseTree):
(WebCore::SkiaCompositingLayer3DRenderingContext::classifyLayer):
(WebCore::projectQuadOnAxis): Deleted.
(WebCore::quadsIntersect): Deleted.
* 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayer3DRenderingContext.h:
(WebCore::SkiaCompositingLayer3DRenderingContext::Layer::Layer):
* Source/WebCore/platform/graphics/skia/SkiaCompositingLayerOverlapRegions.cpp:
(WebCore::projectedBoundingBox):
(WebCore::operator+): Deleted.
(WebCore::operator-): Deleted.
(WebCore::operator*): Deleted.

Canonical link: https://commits.webkit.org/321875@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to