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" |
11 #include "cc/math_util.h" | 11 #include "cc/math_util.h" |
12 #include "ui/gfx/quad_f.h" | 12 #include "ui/gfx/quad_f.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 #include <public/WebTransformationMatrix.h> | 14 #include "ui/gfx/transform.h" |
15 | |
16 using WebKit::WebTransformationMatrix; | |
17 | 15 |
18 namespace cc { | 16 namespace cc { |
19 | 17 |
20 OverdrawMetrics::OverdrawMetrics(bool recordMetricsForFrame) | 18 OverdrawMetrics::OverdrawMetrics(bool recordMetricsForFrame) |
21 : m_recordMetricsForFrame(recordMetricsForFrame) | 19 : m_recordMetricsForFrame(recordMetricsForFrame) |
22 , m_pixelsPainted(0) | 20 , m_pixelsPainted(0) |
23 , m_pixelsUploadedOpaque(0) | 21 , m_pixelsUploadedOpaque(0) |
24 , m_pixelsUploadedTranslucent(0) | 22 , m_pixelsUploadedTranslucent(0) |
25 , m_tilesCulledForUpload(0) | 23 , m_tilesCulledForUpload(0) |
26 , m_contentsTextureUseBytes(0) | 24 , m_contentsTextureUseBytes(0) |
(...skipping 15 matching lines...) Expand all Loading... |
42 if (numPoints < 3) | 40 if (numPoints < 3) |
43 return 0; | 41 return 0; |
44 | 42 |
45 float area = 0; | 43 float area = 0; |
46 for (int i = 0; i < numPoints; ++i) | 44 for (int i = 0; i < numPoints; ++i) |
47 area += wedgeProduct(points[i], points[(i+1)%numPoints]); | 45 area += wedgeProduct(points[i], points[(i+1)%numPoints]); |
48 return fabs(0.5f * area); | 46 return fabs(0.5f * area); |
49 } | 47 } |
50 | 48 |
51 // Takes a given quad, maps it by the given transformation, and gives the area o
f the resulting polygon. | 49 // 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) | 50 static inline float areaOfMappedQuad(const gfx::Transform& transform, const gfx:
:QuadF& quad) |
53 { | 51 { |
54 gfx::PointF clippedQuad[8]; | 52 gfx::PointF clippedQuad[8]; |
55 int numVerticesInClippedQuad = 0; | 53 int numVerticesInClippedQuad = 0; |
56 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); | 54 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); |
57 return polygonArea(clippedQuad, numVerticesInClippedQuad); | 55 return polygonArea(clippedQuad, numVerticesInClippedQuad); |
58 } | 56 } |
59 | 57 |
60 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) | 58 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) |
61 { | 59 { |
62 if (!m_recordMetricsForFrame) | 60 if (!m_recordMetricsForFrame) |
63 return; | 61 return; |
64 | 62 |
65 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); | 63 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); |
66 } | 64 } |
67 | 65 |
68 void OverdrawMetrics::didCullTilesForUpload(int count) | 66 void OverdrawMetrics::didCullTilesForUpload(int count) |
69 { | 67 { |
70 if (m_recordMetricsForFrame) | 68 if (m_recordMetricsForFrame) |
71 m_tilesCulledForUpload += count; | 69 m_tilesCulledForUpload += count; |
72 } | 70 } |
73 | 71 |
74 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect) | 72 void OverdrawMetrics::didUpload(const gfx::Transform& transformToTarget, const g
fx::Rect& uploadRect, const gfx::Rect& opaqueRect) |
75 { | 73 { |
76 if (!m_recordMetricsForFrame) | 74 if (!m_recordMetricsForFrame) |
77 return; | 75 return; |
78 | 76 |
79 float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect
)); | 77 float uploadArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(uploadRect
)); |
80 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx:
:IntersectRects(opaqueRect, uploadRect))); | 78 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(gfx:
:IntersectRects(opaqueRect, uploadRect))); |
81 | 79 |
82 m_pixelsUploadedOpaque += uploadOpaqueArea; | 80 m_pixelsUploadedOpaque += uploadOpaqueArea; |
83 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; | 81 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; |
84 } | 82 } |
85 | 83 |
86 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) | 84 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) |
87 { | 85 { |
88 if (!m_recordMetricsForFrame) | 86 if (!m_recordMetricsForFrame) |
89 return; | 87 return; |
90 | 88 |
91 m_contentsTextureUseBytes += contentsTextureUseBytes; | 89 m_contentsTextureUseBytes += contentsTextureUseBytes; |
92 } | 90 } |
93 | 91 |
94 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) | 92 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) |
95 { | 93 { |
96 if (!m_recordMetricsForFrame) | 94 if (!m_recordMetricsForFrame) |
97 return; | 95 return; |
98 | 96 |
99 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; | 97 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; |
100 } | 98 } |
101 | 99 |
102 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) | 100 void OverdrawMetrics::didCullForDrawing(const gfx::Transform& transformToTarget,
const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) |
103 { | 101 { |
104 if (!m_recordMetricsForFrame) | 102 if (!m_recordMetricsForFrame) |
105 return; | 103 return; |
106 | 104 |
107 float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(before
CullRect)); | 105 float beforeCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(before
CullRect)); |
108 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); | 106 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); |
109 | 107 |
110 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; | 108 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; |
111 } | 109 } |
112 | 110 |
113 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect) | 111 void OverdrawMetrics::didDraw(const gfx::Transform& transformToTarget, const gfx
::Rect& afterCullRect, const gfx::Rect& opaqueRect) |
114 { | 112 { |
115 if (!m_recordMetricsForFrame) | 113 if (!m_recordMetricsForFrame) |
116 return; | 114 return; |
117 | 115 |
118 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); | 116 float afterCullArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(afterCu
llRect)); |
119 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(g
fx::IntersectRects(opaqueRect, afterCullRect))); | 117 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, gfx::QuadF(g
fx::IntersectRects(opaqueRect, afterCullRect))); |
120 | 118 |
121 m_pixelsDrawnOpaque += afterCullOpaqueArea; | 119 m_pixelsDrawnOpaque += afterCullOpaqueArea; |
122 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; | 120 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; |
123 } | 121 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 { | 173 { |
176 // This must be in a different scope than the TRACE_EVENTs above. | 174 // This must be in a different scope than the TRACE_EVENTs above. |
177 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); | 175 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); |
178 } | 176 } |
179 break; | 177 break; |
180 } | 178 } |
181 } | 179 } |
182 } | 180 } |
183 | 181 |
184 } // namespace cc | 182 } // namespace cc |
OLD | NEW |