Bug 1351426 - Part 4: Refactor gfx::Polygon to avoid unnecessary work and memory allocations r=kip

MozReview-Commit-ID: ASusoTqZxuY
This commit is contained in:
Miko Mynttinen
2017-04-04 04:51:29 +02:00
parent 13293ab251
commit c12f643a01
2 changed files with 130 additions and 121 deletions

View File

@@ -57,13 +57,19 @@ BSPTree::BuildTree(BSPTreeNode* aRoot,
}
const gfx::Polygon& plane = aRoot->First();
MOZ_ASSERT(!plane.IsEmpty());
const gfx::Point4D& planeNormal = plane.GetNormal();
const gfx::Point4D& planePoint = plane.GetPoints()[0];
std::list<LayerPolygon> backLayers, frontLayers;
for (LayerPolygon& layerPolygon : aLayers) {
const Maybe<gfx::Polygon>& geometry = layerPolygon.geometry;
const nsTArray<gfx::Point4D>& geometry = layerPolygon.geometry->GetPoints();
// Calculate the plane-point distances for the polygon classification.
size_t pos = 0, neg = 0;
nsTArray<float> dots = geometry->CalculateDotProducts(plane, pos, neg);
nsTArray<float> distances =
CalculatePointPlaneDistances(geometry, planeNormal, planePoint, pos, neg);
// Back polygon
if (pos == 0 && neg > 0) {
@@ -80,10 +86,13 @@ BSPTree::BuildTree(BSPTreeNode* aRoot,
// Polygon intersects with the splitting plane.
else if (pos > 0 && neg > 0) {
nsTArray<gfx::Point4D> backPoints, frontPoints;
geometry->SplitPolygon(plane.GetNormal(), dots, backPoints, frontPoints);
// Clip the polygon against the plane. We reuse the previously calculated
// distances to find the plane-edge intersections.
ClipPointsWithPlane(geometry, planeNormal, distances,
backPoints, frontPoints);
const gfx::Point4D& normal = geometry->GetNormal();
Layer *layer = layerPolygon.layer;
const gfx::Point4D& normal = layerPolygon.geometry->GetNormal();
Layer* layer = layerPolygon.layer;
if (backPoints.Length() >= 3) {
backLayers.emplace_back(layer, Move(backPoints), normal);