| 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 "CCOverdrawMetrics.h" | 7 #include "CCOverdrawMetrics.h" |
| 8 | 8 |
| 9 #include "CCLayerTreeHost.h" | 9 #include "CCLayerTreeHost.h" |
| 10 #include "CCLayerTreeHostImpl.h" | 10 #include "CCLayerTreeHostImpl.h" |
| 11 #include "CCMathUtil.h" | 11 #include "CCMathUtil.h" |
| 12 #include "FloatQuad.h" | 12 #include "FloatQuad.h" |
| 13 #include "IntRect.h" | 13 #include "IntRect.h" |
| 14 #include "TraceEvent.h" | 14 #include "TraceEvent.h" |
| 15 #include <public/Platform.h> | 15 #include <public/Platform.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 CCOverdrawMetrics::CCOverdrawMetrics(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) |
| 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) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 for (int i = 0; i < numPoints; ++i) | 48 for (int i = 0; i < numPoints; ++i) |
| 49 area += wedgeProduct(points[i], points[(i+1)%numPoints]); | 49 area += wedgeProduct(points[i], points[(i+1)%numPoints]); |
| 50 return fabs(0.5f * area); | 50 return fabs(0.5f * area); |
| 51 } | 51 } |
| 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 FloatPoint clippedQuad[8]; | 56 FloatPoint clippedQuad[8]; |
| 57 int numVerticesInClippedQuad = 0; | 57 int numVerticesInClippedQuad = 0; |
| 58 CCMathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippe
dQuad); | 58 MathUtil::mapClippedQuad(transform, quad, clippedQuad, numVerticesInClippedQ
uad); |
| 59 return polygonArea(clippedQuad, numVerticesInClippedQuad); | 59 return polygonArea(clippedQuad, numVerticesInClippedQuad); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void CCOverdrawMetrics::didPaint(const IntRect& paintedRect) | 62 void OverdrawMetrics::didPaint(const IntRect& 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 CCOverdrawMetrics::didCullTileForUpload() | 70 void OverdrawMetrics::didCullTileForUpload() |
| 71 { | 71 { |
| 72 if (m_recordMetricsForFrame) | 72 if (m_recordMetricsForFrame) |
| 73 ++m_tilesCulledForUpload; | 73 ++m_tilesCulledForUpload; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void CCOverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarg
et, const IntRect& uploadRect, const IntRect& opaqueRect) | 76 void OverdrawMetrics::didUpload(const WebTransformationMatrix& transformToTarget
, const IntRect& uploadRect, const IntRect& 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(inter
section(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 CCOverdrawMetrics::didUseContentsTextureMemoryBytes(size_t contentsTextureU
seBytes) | 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 CCOverdrawMetrics::didUseRenderSurfaceTextureMemoryBytes(size_t renderSurfa
ceUseBytes) | 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 CCOverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transfo
rmToTarget, const IntRect& beforeCullRect, const IntRect& afterCullRect) | 104 void OverdrawMetrics::didCullForDrawing(const WebTransformationMatrix& transform
ToTarget, const IntRect& beforeCullRect, const IntRect& 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 CCOverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget
, const IntRect& afterCullRect, const IntRect& opaqueRect) | 115 void OverdrawMetrics::didDraw(const WebTransformationMatrix& transformToTarget,
const IntRect& afterCullRect, const IntRect& 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(in
tersection(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 CCOverdrawMetrics::recordMetrics(const CCLayerTreeHost* layerTreeHost) cons
t | 127 void OverdrawMetrics::recordMetrics(const LayerTreeHost* layerTreeHost) const |
| 128 { | 128 { |
| 129 if (m_recordMetricsForFrame) | 129 if (m_recordMetricsForFrame) |
| 130 recordMetricsInternal<CCLayerTreeHost>(UpdateAndCommit, layerTreeHost); | 130 recordMetricsInternal<LayerTreeHost>(UpdateAndCommit, layerTreeHost); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void CCOverdrawMetrics::recordMetrics(const CCLayerTreeHostImpl* layerTreeHost)
const | 133 void OverdrawMetrics::recordMetrics(const LayerTreeHostImpl* layerTreeHost) cons
t |
| 134 { | 134 { |
| 135 if (m_recordMetricsForFrame) | 135 if (m_recordMetricsForFrame) |
| 136 recordMetricsInternal<CCLayerTreeHostImpl>(DrawingToScreen, layerTreeHos
t); | 136 recordMetricsInternal<LayerTreeHostImpl>(DrawingToScreen, layerTreeHost)
; |
| 137 } | 137 } |
| 138 | 138 |
| 139 template<typename LayerTreeHostType> | 139 template<typename LayerTreeHostType> |
| 140 void CCOverdrawMetrics::recordMetricsInternal(MetricsType metricsType, const Lay
erTreeHostType* layerTreeHost) const | 140 void OverdrawMetrics::recordMetricsInternal(MetricsType metricsType, const Layer
TreeHostType* layerTreeHost) const |
| 141 { | 141 { |
| 142 // This gives approximately 10x the percentage of pixels to fill the viewpor
t once. | 142 // This gives approximately 10x the percentage of pixels to fill the viewpor
t once. |
| 143 float normalization = 1000.f / (layerTreeHost->deviceViewportSize().width()
* layerTreeHost->deviceViewportSize().height()); | 143 float normalization = 1000.f / (layerTreeHost->deviceViewportSize().width()
* layerTreeHost->deviceViewportSize().height()); |
| 144 // This gives approximately 100x the percentage of tiles to fill the viewpor
t once, if all tiles were 256x256. | 144 // This gives approximately 100x the percentage of tiles to fill the viewpor
t once, if all tiles were 256x256. |
| 145 float tileNormalization = 10000.f / (layerTreeHost->deviceViewportSize().wid
th() / 256.f * layerTreeHost->deviceViewportSize().height() / 256.f); | 145 float tileNormalization = 10000.f / (layerTreeHost->deviceViewportSize().wid
th() / 256.f * layerTreeHost->deviceViewportSize().height() / 256.f); |
| 146 // This gives approximately 10x the percentage of bytes to fill the viewport
once, assuming 4 bytes per pixel. | 146 // This gives approximately 10x the percentage of bytes to fill the viewport
once, assuming 4 bytes per pixel. |
| 147 float byteNormalization = normalization / 4; | 147 float byteNormalization = normalization / 4; |
| 148 | 148 |
| 149 switch (metricsType) { | 149 switch (metricsType) { |
| 150 case DrawingToScreen: | 150 case DrawingToScreen: |
| 151 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Opaque_Draw", static_cast<int>(normalization * m_pixelsDrawnOpaque), 100, 100000
0, 50); | 151 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Opaque_Draw", static_cast<int>(normalization * m_pixelsDrawnOpaque), 100, 100000
0, 50); |
| 152 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Translucent_Draw", static_cast<int>(normalization * m_pixelsDrawnTranslucent), 1
00, 1000000, 50); | 152 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Translucent_Draw", static_cast<int>(normalization * m_pixelsDrawnTranslucent), 1
00, 1000000, 50); |
| 153 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Culled_Draw", static_cast<int>(normalization * m_pixelsCulledForDrawing), 100, 1
000000, 50); | 153 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Culled_Draw", static_cast<int>(normalization * m_pixelsCulledForDrawing), 100, 1
000000, 50); |
| 154 | 154 |
| 155 { | 155 { |
| 156 TRACE_COUNTER_ID1("cc", "DrawPixelsCulled", layerTreeHost, m_pixelsC
ulledForDrawing); | 156 TRACE_COUNTER_ID1("cc", "DrawPixelsCulled", layerTreeHost, m_pixelsC
ulledForDrawing); |
| 157 TRACE_EVENT2("cc", "CCOverdrawMetrics", "PixelsDrawnOpaque", m_pixel
sDrawnOpaque, "PixelsDrawnTranslucent", m_pixelsDrawnTranslucent); | 157 TRACE_EVENT2("cc", "OverdrawMetrics", "PixelsDrawnOpaque", m_pixelsD
rawnOpaque, "PixelsDrawnTranslucent", m_pixelsDrawnTranslucent); |
| 158 } | 158 } |
| 159 break; | 159 break; |
| 160 case UpdateAndCommit: | 160 case UpdateAndCommit: |
| 161 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Painted", static_cast<int>(normalization * m_pixelsPainted), 100, 1000000, 50); | 161 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Painted", static_cast<int>(normalization * m_pixelsPainted), 100, 1000000, 50); |
| 162 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Opaque_Upload", static_cast<int>(normalization * m_pixelsUploadedOpaque), 100, 1
000000, 50); | 162 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Opaque_Upload", static_cast<int>(normalization * m_pixelsUploadedOpaque), 100, 1
000000, 50); |
| 163 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Translucent_Upload", static_cast<int>(normalization * m_pixelsUploadedTranslucen
t), 100, 1000000, 50); | 163 WebKit::Platform::current()->histogramCustomCounts("Renderer4.pixelCount
Translucent_Upload", static_cast<int>(normalization * m_pixelsUploadedTranslucen
t), 100, 1000000, 50); |
| 164 WebKit::Platform::current()->histogramCustomCounts("Renderer4.tileCountC
ulled_Upload", static_cast<int>(tileNormalization * m_tilesCulledForUpload), 100
, 10000000, 50); | 164 WebKit::Platform::current()->histogramCustomCounts("Renderer4.tileCountC
ulled_Upload", static_cast<int>(tileNormalization * m_tilesCulledForUpload), 100
, 10000000, 50); |
| 165 WebKit::Platform::current()->histogramCustomCounts("Renderer4.renderSurf
aceTextureBytes_ViewportScaled", static_cast<int>(byteNormalization * m_renderSu
rfaceTextureUseBytes), 10, 1000000, 50); | 165 WebKit::Platform::current()->histogramCustomCounts("Renderer4.renderSurf
aceTextureBytes_ViewportScaled", static_cast<int>(byteNormalization * m_renderSu
rfaceTextureUseBytes), 10, 1000000, 50); |
| 166 WebKit::Platform::current()->histogramCustomCounts("Renderer4.renderSurf
aceTextureBytes_Unscaled", static_cast<int>(m_renderSurfaceTextureUseBytes / 100
0), 1000, 100000000, 50); | 166 WebKit::Platform::current()->histogramCustomCounts("Renderer4.renderSurf
aceTextureBytes_Unscaled", static_cast<int>(m_renderSurfaceTextureUseBytes / 100
0), 1000, 100000000, 50); |
| 167 WebKit::Platform::current()->histogramCustomCounts("Renderer4.contentsTe
xtureBytes_ViewportScaled", static_cast<int>(byteNormalization * m_contentsTextu
reUseBytes), 10, 1000000, 50); | 167 WebKit::Platform::current()->histogramCustomCounts("Renderer4.contentsTe
xtureBytes_ViewportScaled", static_cast<int>(byteNormalization * m_contentsTextu
reUseBytes), 10, 1000000, 50); |
| 168 WebKit::Platform::current()->histogramCustomCounts("Renderer4.contentsTe
xtureBytes_Unscaled", static_cast<int>(m_contentsTextureUseBytes / 1000), 1000,
100000000, 50); | 168 WebKit::Platform::current()->histogramCustomCounts("Renderer4.contentsTe
xtureBytes_Unscaled", static_cast<int>(m_contentsTextureUseBytes / 1000), 1000,
100000000, 50); |
| 169 | 169 |
| 170 { | 170 { |
| 171 TRACE_COUNTER_ID1("cc", "UploadTilesCulled", layerTreeHost, m_tilesC
ulledForUpload); | 171 TRACE_COUNTER_ID1("cc", "UploadTilesCulled", layerTreeHost, m_tilesC
ulledForUpload); |
| 172 TRACE_EVENT2("cc", "CCOverdrawMetrics", "PixelsUploadedOpaque", m_pi
xelsUploadedOpaque, "PixelsUploadedTranslucent", m_pixelsUploadedTranslucent); | 172 TRACE_EVENT2("cc", "OverdrawMetrics", "PixelsUploadedOpaque", m_pixe
lsUploadedOpaque, "PixelsUploadedTranslucent", m_pixelsUploadedTranslucent); |
| 173 } | 173 } |
| 174 { | 174 { |
| 175 // This must be in a different scope than the TRACE_EVENT2 above. | 175 // This must be in a different scope than the TRACE_EVENT2 above. |
| 176 TRACE_EVENT1("cc", "CCOverdrawPaintMetrics", "PixelsPainted", m_pixe
lsPainted); | 176 TRACE_EVENT1("cc", "OverdrawPaintMetrics", "PixelsPainted", m_pixels
Painted); |
| 177 } | 177 } |
| 178 { | 178 { |
| 179 // This must be in a different scope than the TRACE_EVENTs above. | 179 // This must be in a different scope than the TRACE_EVENTs above. |
| 180 TRACE_EVENT2("cc", "CCOverdrawPaintMetrics", "ContentsTextureBytes",
m_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureU
seBytes); | 180 TRACE_EVENT2("cc", "OverdrawPaintMetrics", "ContentsTextureBytes", m
_contentsTextureUseBytes, "RenderSurfaceTextureBytes", m_renderSurfaceTextureUse
Bytes); |
| 181 } | 181 } |
| 182 break; | 182 break; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace cc | 186 } // namespace cc |
| OLD | NEW |