Index: cc/overdraw_metrics.cc |
=================================================================== |
--- cc/overdraw_metrics.cc (revision 166476) |
+++ cc/overdraw_metrics.cc (working copy) |
@@ -33,6 +33,32 @@ |
{ |
} |
+static inline float wedgeProduct(const gfx::PointF& p1, const gfx::PointF& p2) |
+{ |
+ return p1.x() * p2.y() - p1.y() * p2.x(); |
+} |
+ |
+// Calculates area of an arbitrary convex polygon with up to 8 points. |
+static inline float polygonArea(const gfx::PointF points[8], int numPoints) |
+{ |
+ if (numPoints < 3) |
+ return 0; |
+ |
+ float area = 0; |
+ for (int i = 0; i < numPoints; ++i) |
+ area += wedgeProduct(points[i], points[(i+1)%numPoints]); |
+ return fabs(0.5f * area); |
+} |
+ |
+// Takes a given quad, maps it by the given transformation, and gives the area of the resulting polygon. |
+static inline float areaOfMappedQuad(const WebTransformationMatrix& transform, const gfx::QuadF& quad) |
+{ |
+ gfx::PointF clippedQuad[8]; |
+ int numVerticesInClippedQuad = 0; |
+ MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQuad); |
+ return polygonArea(clippedQuad, numVerticesInClippedQuad); |
+} |
+ |
void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) |
{ |
if (!m_recordMetricsForFrame) |
@@ -52,11 +78,9 @@ |
if (!m_recordMetricsForFrame) |
return; |
- gfx::Rect uploadOpaqueRect = gfx::IntersectRects(opaqueRect, uploadRect); |
+ float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect)); |
+ float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx::IntersectRects(opaqueRect, uploadRect))); |
- float uploadArea = static_cast<float>(uploadRect.width()) * uploadRect.height(); |
- float uploadOpaqueArea = static_cast<float>(uploadOpaqueRect.width()) * uploadOpaqueRect.height(); |
- |
m_pixelsUploadedOpaque += uploadOpaqueArea; |
m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; |
} |
@@ -82,8 +106,8 @@ |
if (!m_recordMetricsForFrame) |
return; |
- float beforeCullArea = static_cast<float>(beforeCullRect.width()) * beforeCullRect.height(); |
- float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullRect.height(); |
+ float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(beforeCullRect)); |
+ float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCullRect)); |
m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; |
} |
@@ -93,11 +117,9 @@ |
if (!m_recordMetricsForFrame) |
return; |
- gfx::Rect afterCullOpaqueRect = gfx::IntersectRects(opaqueRect, afterCullRect); |
+ float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCullRect)); |
+ float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx::IntersectRects(opaqueRect, afterCullRect))); |
- float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullRect.height(); |
- float afterCullOpaqueArea = static_cast<float>(afterCullOpaqueRect.width()) * afterCullOpaqueRect.height(); |
- |
m_pixelsDrawnOpaque += afterCullOpaqueArea; |
m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; |
} |