OLD | NEW |
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 "cc/overdraw_metrics.h" | 5 #include "cc/overdraw_metrics.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "cc/layer_tree_host.h" | 9 #include "cc/layer_tree_host.h" |
10 #include "cc/layer_tree_host_impl.h" | 10 #include "cc/layer_tree_host_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 , m_pixelsUploadedTranslucent(0) | 24 , m_pixelsUploadedTranslucent(0) |
25 , m_tilesCulledForUpload(0) | 25 , m_tilesCulledForUpload(0) |
26 , m_contentsTextureUseBytes(0) | 26 , m_contentsTextureUseBytes(0) |
27 , m_renderSurfaceTextureUseBytes(0) | 27 , m_renderSurfaceTextureUseBytes(0) |
28 , m_pixelsDrawnOpaque(0) | 28 , m_pixelsDrawnOpaque(0) |
29 , m_pixelsDrawnTranslucent(0) | 29 , m_pixelsDrawnTranslucent(0) |
30 , m_pixelsCulledForDrawing(0) | 30 , m_pixelsCulledForDrawing(0) |
31 { | 31 { |
32 } | 32 } |
33 | 33 |
| 34 static inline float wedgeProduct(const gfx::PointF& p1, const gfx::PointF& p2) |
| 35 { |
| 36 return p1.x() * p2.y() - p1.y() * p2.x(); |
| 37 } |
| 38 |
| 39 // Calculates area of an arbitrary convex polygon with up to 8 points. |
| 40 static inline float polygonArea(const gfx::PointF points[8], int numPoints) |
| 41 { |
| 42 if (numPoints < 3) |
| 43 return 0; |
| 44 |
| 45 float area = 0; |
| 46 for (int i = 0; i < numPoints; ++i) |
| 47 area += wedgeProduct(points[i], points[(i+1)%numPoints]); |
| 48 return fabs(0.5f * area); |
| 49 } |
| 50 |
| 51 // Takes a given quad, maps it by the given transformation, and gives the area o
f the resulting polygon. |
| 52 static inline float areaOfMappedQuad(const WebTransformationMatrix& transform, c
onst gfx::QuadF& quad) |
| 53 { |
| 54 gfx::PointF clippedQuad[8]; |
| 55 int numVerticesInClippedQuad = 0; |
| 56 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); |
| 57 return polygonArea(clippedQuad, numVerticesInClippedQuad); |
| 58 } |
| 59 |
34 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) | 60 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) |
35 { | 61 { |
36 if (!m_recordMetricsForFrame) | 62 if (!m_recordMetricsForFrame) |
37 return; | 63 return; |
38 | 64 |
39 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); | 65 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); |
40 } | 66 } |
41 | 67 |
42 void OverdrawMetrics::didCullTilesForUpload(int count) | 68 void OverdrawMetrics::didCullTilesForUpload(int count) |
43 { | 69 { |
44 if (m_recordMetricsForFrame) | 70 if (m_recordMetricsForFrame) |
45 m_tilesCulledForUpload += count; | 71 m_tilesCulledForUpload += count; |
46 } | 72 } |
47 | 73 |
48 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect) | 74 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect) |
49 { | 75 { |
50 if (!m_recordMetricsForFrame) | 76 if (!m_recordMetricsForFrame) |
51 return; | 77 return; |
52 | 78 |
53 gfx::Rect uploadOpaqueRect = gfx::IntersectRects(opaqueRect, uploadRect); | 79 float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect
)); |
54 | 80 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx:
:IntersectRects(opaqueRect, uploadRect))); |
55 float uploadArea = static_cast<float>(uploadRect.width()) * uploadRect.heigh
t(); | |
56 float uploadOpaqueArea = static_cast<float>(uploadOpaqueRect.width()) * uplo
adOpaqueRect.height(); | |
57 | 81 |
58 m_pixelsUploadedOpaque += uploadOpaqueArea; | 82 m_pixelsUploadedOpaque += uploadOpaqueArea; |
59 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; | 83 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; |
60 } | 84 } |
61 | 85 |
62 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) | 86 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) |
63 { | 87 { |
64 if (!m_recordMetricsForFrame) | 88 if (!m_recordMetricsForFrame) |
65 return; | 89 return; |
66 | 90 |
67 m_contentsTextureUseBytes += contentsTextureUseBytes; | 91 m_contentsTextureUseBytes += contentsTextureUseBytes; |
68 } | 92 } |
69 | 93 |
70 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) | 94 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) |
71 { | 95 { |
72 if (!m_recordMetricsForFrame) | 96 if (!m_recordMetricsForFrame) |
73 return; | 97 return; |
74 | 98 |
75 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; | 99 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; |
76 } | 100 } |
77 | 101 |
78 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) | 102 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) |
79 { | 103 { |
80 if (!m_recordMetricsForFrame) | 104 if (!m_recordMetricsForFrame) |
81 return; | 105 return; |
82 | 106 |
83 float beforeCullArea = static_cast<float>(beforeCullRect.width()) * beforeCu
llRect.height(); | 107 float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(before
CullRect)); |
84 float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullR
ect.height(); | 108 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); |
85 | 109 |
86 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; | 110 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; |
87 } | 111 } |
88 | 112 |
89 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect) | 113 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect) |
90 { | 114 { |
91 if (!m_recordMetricsForFrame) | 115 if (!m_recordMetricsForFrame) |
92 return; | 116 return; |
93 | 117 |
94 gfx::Rect afterCullOpaqueRect = gfx::IntersectRects(opaqueRect, afterCullRec
t); | 118 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); |
95 | 119 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(g
fx::IntersectRects(opaqueRect, afterCullRect))); |
96 float afterCullArea = static_cast<float>(afterCullRect.width()) * afterCullR
ect.height(); | |
97 float afterCullOpaqueArea = static_cast<float>(afterCullOpaqueRect.width())
* afterCullOpaqueRect.height(); | |
98 | 120 |
99 m_pixelsDrawnOpaque += afterCullOpaqueArea; | 121 m_pixelsDrawnOpaque += afterCullOpaqueArea; |
100 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; | 122 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; |
101 } | 123 } |
102 | 124 |
103 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const | 125 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const |
104 { | 126 { |
105 if (m_recordMetricsForFrame) | 127 if (m_recordMetricsForFrame) |
106 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); | 128 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); |
107 } | 129 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 { | 175 { |
154 // This must be in a different scope than the TRACE_EVENTs above. | 176 // This must be in a different scope than the TRACE_EVENTs above. |
155 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); | 177 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); |
156 } | 178 } |
157 break; | 179 break; |
158 } | 180 } |
159 } | 181 } |
160 } | 182 } |
161 | 183 |
162 } // namespace cc | 184 } // namespace cc |
OLD | NEW |