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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/overdraw_metrics.h" | 7 #include "cc/overdraw_metrics.h" |
8 | 8 |
9 #include "FloatQuad.h" | 9 #include "FloatQuad.h" |
10 #include "IntRect.h" | |
11 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
12 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
13 #include "cc/layer_tree_host.h" | 12 #include "cc/layer_tree_host.h" |
14 #include "cc/layer_tree_host_impl.h" | 13 #include "cc/layer_tree_host_impl.h" |
15 #include "cc/math_util.h" | 14 #include "cc/math_util.h" |
| 15 #include "ui/gfx/rect.h" |
16 #include <public/WebTransformationMatrix.h> | 16 #include <public/WebTransformationMatrix.h> |
17 | 17 |
18 using WebKit::WebTransformationMatrix; | 18 using WebKit::WebTransformationMatrix; |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 | 21 |
22 OverdrawMetrics::OverdrawMetrics(bool recordMetricsForFrame) | 22 OverdrawMetrics::OverdrawMetrics(bool recordMetricsForFrame) |
23 : m_recordMetricsForFrame(recordMetricsForFrame) | 23 : m_recordMetricsForFrame(recordMetricsForFrame) |
24 , m_pixelsPainted(0) | 24 , m_pixelsPainted(0) |
25 , m_pixelsUploadedOpaque(0) | 25 , m_pixelsUploadedOpaque(0) |
(...skipping 26 matching lines...) Expand all Loading... |
52 | 52 |
53 // Takes a given quad, maps it by the given transformation, and gives the area o
f the resulting polygon. | 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 FloatQuad& quad) | 54 static inline float areaOfMappedQuad(const WebTransformationMatrix& transform, c
onst FloatQuad& quad) |
55 { | 55 { |
56 gfx::PointF clippedQuad[8]; | 56 gfx::PointF clippedQuad[8]; |
57 int numVerticesInClippedQuad = 0; | 57 int numVerticesInClippedQuad = 0; |
58 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); | 58 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); |
59 return polygonArea(clippedQuad, numVerticesInClippedQuad); | 59 return polygonArea(clippedQuad, numVerticesInClippedQuad); |
60 } | 60 } |
61 | 61 |
62 void OverdrawMetrics::didPaint(const IntRect& paintedRect) | 62 void OverdrawMetrics::didPaint(const gfx::Rect& paintedRect) |
63 { | 63 { |
64 if (!m_recordMetricsForFrame) | 64 if (!m_recordMetricsForFrame) |
65 return; | 65 return; |
66 | 66 |
67 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); | 67 m_pixelsPainted += static_cast<float>(paintedRect.width()) * paintedRect.hei
ght(); |
68 } | 68 } |
69 | 69 |
70 void OverdrawMetrics::didCullTilesForUpload(int count) | 70 void OverdrawMetrics::didCullTilesForUpload(int count) |
71 { | 71 { |
72 if (m_recordMetricsForFrame) | 72 if (m_recordMetricsForFrame) |
73 m_tilesCulledForUpload += count; | 73 m_tilesCulledForUpload += count; |
74 } | 74 } |
75 | 75 |
76 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const IntRect& uploadRect, const IntRect& opaqueRect) | 76 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const gfx::Rect& uploadRect, const gfx::Rect& opaqueRect) |
77 { | 77 { |
78 if (!m_recordMetricsForFrame) | 78 if (!m_recordMetricsForFrame) |
79 return; | 79 return; |
80 | 80 |
81 float uploadArea = areaOfMappedQuad(transformToTarget, FloatQuad(uploadRect)
); | 81 float uploadArea = areaOfMappedQuad(transformToTarget, FloatQuad(uploadRect)
); |
82 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, FloatQuad(inter
section(opaqueRect, uploadRect))); | 82 float uploadOpaqueArea = areaOfMappedQuad(transformToTarget, FloatQuad(gfx::
IntersectRects(opaqueRect, uploadRect))); |
83 | 83 |
84 m_pixelsUploadedOpaque += uploadOpaqueArea; | 84 m_pixelsUploadedOpaque += uploadOpaqueArea; |
85 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; | 85 m_pixelsUploadedTranslucent += uploadArea - uploadOpaqueArea; |
86 } | 86 } |
87 | 87 |
88 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) | 88 void OverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureUse
Bytes) |
89 { | 89 { |
90 if (!m_recordMetricsForFrame) | 90 if (!m_recordMetricsForFrame) |
91 return; | 91 return; |
92 | 92 |
93 m_contentsTextureUseBytes += contentsTextureUseBytes; | 93 m_contentsTextureUseBytes += contentsTextureUseBytes; |
94 } | 94 } |
95 | 95 |
96 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) | 96 void OverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurface
UseBytes) |
97 { | 97 { |
98 if (!m_recordMetricsForFrame) | 98 if (!m_recordMetricsForFrame) |
99 return; | 99 return; |
100 | 100 |
101 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; | 101 m_renderSurfaceTextureUseBytes += renderSurfaceUseBytes; |
102 } | 102 } |
103 | 103 |
104 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const IntRect& beforeCullRect, const IntRect& afterCullRect) | 104 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const gfx::Rect& beforeCullRect, const gfx::Rect& afterCullRect) |
105 { | 105 { |
106 if (!m_recordMetricsForFrame) | 106 if (!m_recordMetricsForFrame) |
107 return; | 107 return; |
108 | 108 |
109 float beforeCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(beforeC
ullRect)); | 109 float beforeCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(beforeC
ullRect)); |
110 float afterCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(afterCul
lRect)); | 110 float afterCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(afterCul
lRect)); |
111 | 111 |
112 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; | 112 m_pixelsCulledForDrawing += beforeCullArea - afterCullArea; |
113 } | 113 } |
114 | 114 |
115 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const IntRect& afterCullRect, const IntRect& opaqueRect) | 115 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const gfx::Rect& afterCullRect, const gfx::Rect& opaqueRect) |
116 { | 116 { |
117 if (!m_recordMetricsForFrame) | 117 if (!m_recordMetricsForFrame) |
118 return; | 118 return; |
119 | 119 |
120 float afterCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(afterCul
lRect)); | 120 float afterCullArea = areaOfMappedQuad(transformToTarget, FloatQuad(afterCul
lRect)); |
121 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, FloatQuad(in
tersection(opaqueRect, afterCullRect))); | 121 float afterCullOpaqueArea = areaOfMappedQuad(transformToTarget, FloatQuad(gf
x::IntersectRects(opaqueRect, afterCullRect))); |
122 | 122 |
123 m_pixelsDrawnOpaque += afterCullOpaqueArea; | 123 m_pixelsDrawnOpaque += afterCullOpaqueArea; |
124 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; | 124 m_pixelsDrawnTranslucent += afterCullArea - afterCullOpaqueArea; |
125 } | 125 } |
126 | 126 |
127 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const | 127 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const |
128 { | 128 { |
129 if (m_recordMetricsForFrame) | 129 if (m_recordMetricsForFrame) |
130 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); | 130 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); |
131 } | 131 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 { | 177 { |
178 // This must be in a different scope than the TRACE_EVENTs above. | 178 // This must be in a different scope than the TRACE_EVENTs above. |
179 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); | 179 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); |
180 } | 180 } |
181 break; | 181 break; |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 } // namespace cc | 186 } // namespace cc |
OLD | NEW |