Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Unified Diff: cc/overdraw_metrics.cc

Issue 12728002: cc: Chromify the OverdrawMetrics class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/overdraw_metrics.h ('k') | cc/quad_culler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/overdraw_metrics.cc
diff --git a/cc/overdraw_metrics.cc b/cc/overdraw_metrics.cc
index c1ab20f68d22dc96184a1c401dc4f200e638ac09..0ed58d1101dd94b75a0d78fa1ab774e235f5f8d2 100644
--- a/cc/overdraw_metrics.cc
+++ b/cc/overdraw_metrics.cc
@@ -15,205 +15,253 @@
namespace cc {
-OverdrawMetrics::OverdrawMetrics(bool recordMetricsForFrame)
- : m_recordMetricsForFrame(recordMetricsForFrame)
- , m_pixelsPainted(0)
- , m_pixelsUploadedOpaque(0)
- , m_pixelsUploadedTranslucent(0)
- , m_tilesCulledForUpload(0)
- , m_contentsTextureUseBytes(0)
- , m_renderSurfaceTextureUseBytes(0)
- , m_pixelsDrawnOpaque(0)
- , m_pixelsDrawnTranslucent(0)
- , m_pixelsCulledForDrawing(0)
-{
-}
-
-static inline float wedgeProduct(const gfx::PointF& p1, const gfx::PointF& p2)
-{
- return p1.x() * p2.y() - p1.y() * p2.x();
+OverdrawMetrics::OverdrawMetrics(bool record_metrics_for_frame)
+ : record_metrics_for_frame_(record_metrics_for_frame),
+ pixels_painted_(0),
+ pixels_uploaded_opaque_(0),
+ pixels_uploaded_translucent_(0),
+ tiles_culled_for_upload_(0),
+ contents_texture_use_bytes_(0),
+ render_surface_texture_use_bytes_(0),
+ pixels_drawn_opaque_(0),
+ pixels_drawn_translucent_(0),
+ pixels_culled_for_drawing_(0) {}
+
+static inline float WedgeProduct(gfx::PointF p1, 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);
+static inline float PolygonArea(gfx::PointF points[8], int num_points) {
+ if (num_points < 3)
+ return 0;
+
+ float area = 0;
+ for (int i = 0; i < num_points; ++i)
+ area += WedgeProduct(points[i], points[(i+1)%num_points]);
+ 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 gfx::Transform& transform, const gfx::QuadF& quad)
-{
- gfx::PointF clippedQuad[8];
- int numVerticesInClippedQuad = 0;
- MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQuad);
- return polygonArea(clippedQuad, numVerticesInClippedQuad);
+// Takes a given quad, maps it by the given transformation, and gives the area
+// of the resulting polygon.
+static inline float AreaOfMappedQuad(const gfx::Transform& transform,
+ const gfx::QuadF& quad) {
+ gfx::PointF clippedQuad[8];
+ int num_vertices_in_clipped_quad = 0;
+ MathUtil::mapClippedQuad(transform,
+ quad,
+ clippedQuad,
+ num_vertices_in_clipped_quad);
+ return PolygonArea(clippedQuad, num_vertices_in_clipped_quad);
}
-void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect)
-{
- if (!m_recordMetricsForFrame)
- return;
+void OverdrawMetrics::DidPaint(gfx::Rect painted_rect) {
+ if (!record_metrics_for_frame_)
+ return;
- m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.height();
+ pixels_painted_ +=
+ static_cast<float>(painted_rect.width()) * painted_rect.height();
}
-void OverdrawMetrics::didCullTilesForUpload(int count)
-{
- if (m_recordMetricsForFrame)
- m_tilesCulledForUpload += count;
+void OverdrawMetrics::DidCullTilesForUpload(int count) {
+ if (record_metrics_for_frame_)
+ tiles_culled_for_upload_ += count;
}
-void OverdrawMetrics::didUpload(const gfx::Transform& transformToTarget, const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect)
-{
- if (!m_recordMetricsForFrame)
- return;
-
- float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect));
- float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx::IntersectRects(opaqueRect, uploadRect)));
-
- m_pixelsUploadedOpaque += uploadOpaqueArea;
- m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea;
+void OverdrawMetrics::DidUpload(const gfx::Transform& transform_to_target,
+ gfx::Rect upload_rect,
+ gfx::Rect opaque_rect) {
+ if (!record_metrics_for_frame_)
+ return;
+
+ float upload_area =
+ AreaOfMappedQuad(transform_to_target, gfx::QuadF(upload_rect));
+ float upload_opaque_area =
+ AreaOfMappedQuad(transform_to_target,
+ gfx::QuadF(gfx::IntersectRects(opaque_rect,
+ upload_rect)));
+
+ pixels_uploaded_opaque_ += upload_opaque_area;
+ pixels_uploaded_translucent_ += upload_area - upload_opaque_area;
}
-void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUseBytes)
-{
- if (!m_recordMetricsForFrame)
- return;
+void OverdrawMetrics::DidUseContentsTextureMemoryBytes(
+ size_t contents_texture_use_bytes) {
+ if (!record_metrics_for_frame_)
+ return;
- m_contentsTextureUseBytes += contentsTextureUseBytes;
+ contents_texture_use_bytes_ += contents_texture_use_bytes;
}
-void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurfaceUseBytes)
-{
- if (!m_recordMetricsForFrame)
- return;
+void OverdrawMetrics::DidUseRenderSurfaceTextureMemoryBytes(
+ size_t render_surface_use_bytes) {
+ if (!record_metrics_for_frame_)
+ return;
- m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes;
+ render_surface_texture_use_bytes_ += render_surface_use_bytes;
}
-void OverdrawMetrics::didCullForDrawing(const gfx::Transform& transformToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect)
-{
- if (!m_recordMetricsForFrame)
- return;
+void OverdrawMetrics::DidCullForDrawing(
+ const gfx::Transform& transform_to_target,
+ gfx::Rect before_cull_rect,
+ gfx::Rect after_cull_rect) {
+ if (!record_metrics_for_frame_)
+ return;
- float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(beforeCullRect));
- float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCullRect));
+ float before_cull_area =
+ AreaOfMappedQuad(transform_to_target, gfx::QuadF(before_cull_rect));
+ float after_cull_area =
+ AreaOfMappedQuad(transform_to_target, gfx::QuadF(after_cull_rect));
- m_pixelsCulledForDrawing += beforeCullArea - afterCullArea;
+ pixels_culled_for_drawing_ += before_cull_area - after_cull_area;
}
-void OverdrawMetrics::didDraw(const gfx::Transform& transformToTarget, const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect)
-{
- if (!m_recordMetricsForFrame)
- return;
-
- float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCullRect));
- float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx::IntersectRects(opaqueRect, afterCullRect)));
-
- m_pixelsDrawnOpaque += afterCullOpaqueArea;
- m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea;
+void OverdrawMetrics::DidDraw(const gfx::Transform& transform_to_target,
+ gfx::Rect after_cull_rect,
+ gfx::Rect opaque_rect) {
+ if (!record_metrics_for_frame_)
+ return;
+
+ float after_cull_area =
+ AreaOfMappedQuad(transform_to_target, gfx::QuadF(after_cull_rect));
+ float after_cull_opaque_area =
+ AreaOfMappedQuad(transform_to_target,
+ gfx::QuadF(gfx::IntersectRects(opaque_rect,
+ after_cull_rect)));
+
+ pixels_drawn_opaque_ += after_cull_opaque_area;
+ pixels_drawn_translucent_ += after_cull_area - after_cull_opaque_area;
}
-void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const
-{
- if (m_recordMetricsForFrame)
- recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost);
+void OverdrawMetrics::RecordMetrics(
+ const LayerTreeHost* layer_tree_host) const {
+ if (record_metrics_for_frame_)
+ RecordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layer_tree_host);
}
-void OverdrawMetrics::recordMetrics(const LayerTreeHostImpl* layerTreeHost) const
-{
- if (m_recordMetricsForFrame)
- recordMetricsInternal<LayerTreeHostImpl>(DrawingToScreen, layerTreeHost);
+void OverdrawMetrics::RecordMetrics(
+ const LayerTreeHostImpl* layer_tree_host_impl) const {
+ if (record_metrics_for_frame_) {
+ RecordMetricsInternal<LayerTreeHostImpl>(DrawingToScreen,
+ layer_tree_host_impl);
+ }
}
-static gfx::Size DeviceViewportSize(const LayerTreeHost* host) { return host->deviceViewportSize(); }
-static gfx::Size DeviceViewportSize(const LayerTreeHostImpl* host_impl) { return host_impl->DeviceViewportSize(); }
-
-template<typename LayerTreeHostType>
-void OverdrawMetrics::recordMetricsInternal(MetricsType metricsType, const LayerTreeHostType* layerTreeHost) const
-{
- // This gives approximately 10x the percentage of pixels to fill the viewport once.
- float normalization = 1000.f / (DeviceViewportSize(layerTreeHost).width() * DeviceViewportSize(layerTreeHost).height());
- // This gives approximately 100x the percentage of tiles to fill the viewport once, if all tiles were 256x256.
- float tileNormalization = 10000.f / (DeviceViewportSize(layerTreeHost).width() / 256.f * DeviceViewportSize(layerTreeHost).height() / 256.f);
- // This gives approximately 10x the percentage of bytes to fill the viewport once, assuming 4 bytes per pixel.
- float byteNormalization = normalization / 4;
+static gfx::Size DeviceViewportSize(const LayerTreeHost* host) {
+ return host->deviceViewportSize();
+}
+static gfx::Size DeviceViewportSize(const LayerTreeHostImpl* host_impl) {
+ return host_impl->DeviceViewportSize();
+}
- switch (metricsType) {
+template <typename LayerTreeHostType>
+void OverdrawMetrics::RecordMetricsInternal(
+ MetricsType metrics_type,
+ const LayerTreeHostType* layer_tree_host) const {
+ // This gives approximately 10x the percentage of pixels to fill the viewport
+ // once.
+ float normalization = 1000.f / (DeviceViewportSize(layer_tree_host).width() *
+ DeviceViewportSize(layer_tree_host).height());
+ // This gives approximately 100x the percentage of tiles to fill the viewport
+ // once, if all tiles were 256x256.
+ float tile_normalization =
+ 10000.f / (DeviceViewportSize(layer_tree_host).width() / 256.f *
+ DeviceViewportSize(layer_tree_host).height() / 256.f);
+ // This gives approximately 10x the percentage of bytes to fill the viewport
+ // once, assuming 4 bytes per pixel.
+ float byte_normalization = normalization / 4;
+
+ switch (metrics_type) {
case DrawingToScreen: {
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountOpaque_Draw",
- static_cast<int>(normalization * m_pixelsDrawnOpaque),
- 100, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountTranslucent_Draw",
- static_cast<int>(normalization * m_pixelsDrawnTranslucent),
- 100, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountCulled_Draw",
- static_cast<int>(normalization * m_pixelsCulledForDrawing),
- 100, 1000000, 50);
-
- TRACE_COUNTER_ID1("cc", "DrawPixelsCulled", layerTreeHost, m_pixelsCulledForDrawing);
- TRACE_EVENT2("cc", "OverdrawMetrics", "PixelsDrawnOpaque", m_pixelsDrawnOpaque, "PixelsDrawnTranslucent", m_pixelsDrawnTranslucent);
- break;
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountOpaque_Draw",
+ static_cast<int>(normalization * pixels_drawn_opaque_),
+ 100, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountTranslucent_Draw",
+ static_cast<int>(normalization * pixels_drawn_translucent_),
+ 100, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountCulled_Draw",
+ static_cast<int>(normalization * pixels_culled_for_drawing_),
+ 100, 1000000, 50);
+
+ TRACE_COUNTER_ID1("cc",
+ "DrawPixelsCulled",
+ layer_tree_host,
+ pixels_culled_for_drawing_);
+ TRACE_EVENT2("cc",
+ "OverdrawMetrics",
+ "PixelsDrawnOpaque",
+ pixels_drawn_opaque_,
+ "PixelsDrawnTranslucent",
+ pixels_drawn_translucent_);
+ break;
}
case UpdateAndCommit: {
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountPainted",
- static_cast<int>(normalization * m_pixelsPainted),
- 100, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountOpaque_Upload",
- static_cast<int>(normalization * m_pixelsUploadedOpaque),
- 100, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.pixelCountTranslucent_Upload",
- static_cast<int>(normalization * m_pixelsUploadedTranslucent),
- 100, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.tileCountCulled_Upload",
- static_cast<int>(tileNormalization * m_tilesCulledForUpload),
- 100, 10000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.renderSurfaceTextureBytes_ViewportScaled",
- static_cast<int>(
- byteNormalization * m_renderSurfaceTextureUseBytes),
- 10, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.renderSurfaceTextureBytes_Unscaled",
- static_cast<int>(m_renderSurfaceTextureUseBytes / 1000),
- 1000, 100000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.contentsTextureBytes_ViewportScaled",
- static_cast<int>(byteNormalization * m_contentsTextureUseBytes),
- 10, 1000000, 50);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- "Renderer4.contentsTextureBytes_Unscaled",
- static_cast<int>(m_contentsTextureUseBytes / 1000),
- 1000, 100000000, 50);
-
- {
- TRACE_COUNTER_ID1("cc", "UploadTilesCulled", layerTreeHost, m_tilesCulledForUpload);
- TRACE_EVENT2("cc", "OverdrawMetrics", "PixelsUploadedOpaque", m_pixelsUploadedOpaque, "PixelsUploadedTranslucent", m_pixelsUploadedTranslucent);
- }
- {
- // This must be in a different scope than the TRACE_EVENT2 above.
- TRACE_EVENT1("cc", "OverdrawPaintMetrics", "PixelsPainted", m_pixelsPainted);
- }
- {
- // This must be in a different scope than the TRACE_EVENTs above.
- TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUseBytes);
- }
- break;
- }
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountPainted",
+ static_cast<int>(normalization * pixels_painted_),
+ 100, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountOpaque_Upload",
+ static_cast<int>(normalization * pixels_uploaded_opaque_),
+ 100, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.pixelCountTranslucent_Upload",
+ static_cast<int>(normalization * pixels_uploaded_translucent_),
+ 100, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.tileCountCulled_Upload",
+ static_cast<int>(tile_normalization * tiles_culled_for_upload_),
+ 100, 10000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.renderSurfaceTextureBytes_ViewportScaled",
+ static_cast<int>(
+ byte_normalization * render_surface_texture_use_bytes_),
+ 10, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.renderSurfaceTextureBytes_Unscaled",
+ static_cast<int>(render_surface_texture_use_bytes_ / 1000),
+ 1000, 100000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.contentsTextureBytes_ViewportScaled",
+ static_cast<int>(byte_normalization * contents_texture_use_bytes_),
+ 10, 1000000, 50);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Renderer4.contentsTextureBytes_Unscaled",
+ static_cast<int>(contents_texture_use_bytes_ / 1000),
+ 1000, 100000000, 50); {
+ TRACE_COUNTER_ID1("cc",
+ "UploadTilesCulled",
+ layer_tree_host,
+ tiles_culled_for_upload_);
+ TRACE_EVENT2("cc",
+ "OverdrawMetrics",
+ "PixelsUploadedOpaque",
+ pixels_uploaded_opaque_,
+ "PixelsUploadedTranslucent",
+ pixels_uploaded_translucent_);
+ }
+ {
+ // This must be in a different scope than the TRACE_EVENT2 above.
+ TRACE_EVENT1("cc",
+ "OverdrawPaintMetrics",
+ "PixelsPainted",
+ pixels_painted_);
+ }
+ {
+ // This must be in a different scope than the TRACE_EVENTs above.
+ TRACE_EVENT2("cc",
+ "OverdrawPaintMetrics",
+ "ContentsTextureBytes",
+ contents_texture_use_bytes_,
+ "RenderSurfaceTextureBytes",
+ render_surface_texture_use_bytes_);
+ }
+ break;
}
+ }
}
} // namespace cc
« no previous file with comments | « cc/overdraw_metrics.h ('k') | cc/quad_culler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698