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

Side by Side Diff: cc/overdraw_metrics.cc

Issue 11312129: cc: Turn overdraw metrics on only when about:tracing is recording. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/quad_culler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/overdraw_metrics.h" 7 #include "cc/overdraw_metrics.h"
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 15 matching lines...) Expand all
26 , m_pixelsUploadedTranslucent(0) 26 , m_pixelsUploadedTranslucent(0)
27 , m_tilesCulledForUpload(0) 27 , m_tilesCulledForUpload(0)
28 , m_contentsTextureUseBytes(0) 28 , m_contentsTextureUseBytes(0)
29 , m_renderSurfaceTextureUseBytes(0) 29 , m_renderSurfaceTextureUseBytes(0)
30 , m_pixelsDrawnOpaque(0) 30 , m_pixelsDrawnOpaque(0)
31 , m_pixelsDrawnTranslucent(0) 31 , m_pixelsDrawnTranslucent(0)
32 , m_pixelsCulledForDrawing(0) 32 , m_pixelsCulledForDrawing(0)
33 { 33 {
34 } 34 }
35 35
36 static inline float wedgeProduct(const gfx::PointF& p1, const gfx::PointF& p2)
37 {
38 return p1.x() * p2.y() - p1.y() * p2.x();
39 }
40
41 // Calculates area of an arbitrary convex polygon with up to 8 points.
42 static inline float polygonArea(const gfx::PointF points[8], int numPoints)
43 {
44 if (numPoints < 3)
45 return 0;
46
47 float area = 0;
48 for (int i = 0; i < numPoints; ++i)
49 area += wedgeProduct(points[i], points[(i+1)%numPoints]);
50 return fabs(0.5f * area);
51 }
52
53 // Takes a given quad, maps it by the given transformation, and gives the area o f the resulting polygon.
54 static inline float areaOfMappedQuad(const WebTransformationMatrix& transform, c onst gfx::QuadF& quad)
55 {
56 gfx::PointF clippedQuad[8];
57 int numVerticesInClippedQuad = 0;
58 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ uad);
59 return polygonArea(clippedQuad, numVerticesInClippedQuad);
60 }
61
62 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) 36 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect)
63 { 37 {
64 if (!m_recordMetricsForFrame) 38 if (!m_recordMetricsForFrame)
65 return; 39 return;
66 40
67 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei ght(); 41 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei ght();
68 } 42 }
69 43
70 void OverdrawMetrics::didCullTilesForUpload(int count) 44 void OverdrawMetrics::didCullTilesForUpload(int count)
71 { 45 {
72 if (m_recordMetricsForFrame) 46 if (m_recordMetricsForFrame)
73 m_tilesCulledForUpload += count; 47 m_tilesCulledForUpload += count;
74 } 48 }
75 49
76 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget , const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect) 50 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget , const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect)
77 { 51 {
78 if (!m_recordMetricsForFrame) 52 if (!m_recordMetricsForFrame)
79 return; 53 return;
80 54
81 float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect )); 55 gfx::Rect uploadOpaqueRect = gfx::IntersectRects(opaqueRect, uploadRect);
82 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx: :IntersectRects(opaqueRect, uploadRect))); 56
57 float uploadArea = static_cast<float>(uploadRect.width()) * uploadRect.heigh t();
58 float uploadOpaqueArea = static_cast<float>(uploadOpaqueRect.width()) * uplo adOpaqueRect.height();
83 59
84 m_pixelsUploadedOpaque += uploadOpaqueArea; 60 m_pixelsUploadedOpaque += uploadOpaqueArea;
85 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; 61 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea;
86 } 62 }
87 63
88 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse Bytes) 64 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse Bytes)
89 { 65 {
90 if (!m_recordMetricsForFrame) 66 if (!m_recordMetricsForFrame)
91 return; 67 return;
92 68
93 m_contentsTextureUseBytes += contentsTextureUseBytes; 69 m_contentsTextureUseBytes += contentsTextureUseBytes;
94 } 70 }
95 71
96 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface UseBytes) 72 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface UseBytes)
97 { 73 {
98 if (!m_recordMetricsForFrame) 74 if (!m_recordMetricsForFrame)
99 return; 75 return;
100 76
101 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; 77 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes;
102 } 78 }
103 79
104 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) 80 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect)
105 { 81 {
106 if (!m_recordMetricsForFrame) 82 if (!m_recordMetricsForFrame)
107 return; 83 return;
108 84
109 float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(before CullRect)); 85 float beforeCullArea = static_cast<float>(beforeCullRect.width()) * beforeCu llRect.height();
110 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu llRect)); 86 float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullR ect.height();
111 87
112 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; 88 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea;
113 } 89 }
114 90
115 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget, const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect) 91 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget, const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect)
116 { 92 {
117 if (!m_recordMetricsForFrame) 93 if (!m_recordMetricsForFrame)
118 return; 94 return;
119 95
120 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu llRect)); 96 gfx::Rect afterCullOpaqueRect = gfx::IntersectRects(opaqueRect, afterCullRec t);
121 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(g fx::IntersectRects(opaqueRect, afterCullRect))); 97
98 float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullR ect.height();
99 float afterCullOpaqueArea = static_cast<float>(afterCullOpaqueRect.width()) * afterCullOpaqueRect.height();
122 100
123 m_pixelsDrawnOpaque += afterCullOpaqueArea; 101 m_pixelsDrawnOpaque += afterCullOpaqueArea;
124 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; 102 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea;
125 } 103 }
126 104
127 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const 105 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const
128 { 106 {
129 if (m_recordMetricsForFrame) 107 if (m_recordMetricsForFrame)
130 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); 108 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost);
131 } 109 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 { 155 {
178 // This must be in a different scope than the TRACE_EVENTs above. 156 // This must be in a different scope than the TRACE_EVENTs above.
179 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m _contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse Bytes); 157 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m _contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse Bytes);
180 } 158 }
181 break; 159 break;
182 } 160 }
183 } 161 }
184 } 162 }
185 163
186 } // namespace cc 164 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/quad_culler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698