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/heads_up_display_layer_impl.h" | 7 #include "cc/heads_up_display_layer_impl.h" |
8 | 8 |
9 #include "CCDebugRectHistory.h" | 9 #include "CCDebugRectHistory.h" |
10 #include "CCFontAtlas.h" | 10 #include "CCFontAtlas.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 swizzleMatrix.fMat[2 + 5 * 0] = 1; | 36 swizzleMatrix.fMat[2 + 5 * 0] = 1; |
37 swizzleMatrix.fMat[3 + 5 * 3] = 1; | 37 swizzleMatrix.fMat[3 + 5 * 3] = 1; |
38 | 38 |
39 SkPaint paint; | 39 SkPaint paint; |
40 paint.setColorFilter(new SkColorMatrixFilter(swizzleMatrix))->unref(); | 40 paint.setColorFilter(new SkColorMatrixFilter(swizzleMatrix))->unref(); |
41 return paint; | 41 return paint; |
42 } | 42 } |
43 | 43 |
44 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(int id) | 44 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(int id) |
45 : LayerImpl(id) | 45 : LayerImpl(id) |
46 , m_averageFPS(0) | |
47 , m_stdDeviation(0) | |
46 { | 48 { |
47 } | 49 } |
48 | 50 |
49 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() | 51 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() |
50 { | 52 { |
51 } | 53 } |
52 | 54 |
53 void HeadsUpDisplayLayerImpl::setFontAtlas(scoped_ptr<FontAtlas> fontAtlas) | 55 void HeadsUpDisplayLayerImpl::setFontAtlas(scoped_ptr<FontAtlas> fontAtlas) |
54 { | 56 { |
55 m_fontAtlas = fontAtlas.Pass(); | 57 m_fontAtlas = fontAtlas.Pass(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 void HeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas) | 138 void HeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas) |
137 { | 139 { |
138 const LayerTreeSettings& settings = layerTreeHostImpl()->settings(); | 140 const LayerTreeSettings& settings = layerTreeHostImpl()->settings(); |
139 | 141 |
140 if (settings.showPlatformLayerTree) { | 142 if (settings.showPlatformLayerTree) { |
141 SkPaint paint = createPaint(); | 143 SkPaint paint = createPaint(); |
142 paint.setColor(SkColorSetARGB(192, 0, 0, 0)); | 144 paint.setColor(SkColorSetARGB(192, 0, 0, 0)); |
143 canvas->drawRect(SkRect::MakeXYWH(0, 0, bounds().width(), bounds().heigh t()), paint); | 145 canvas->drawRect(SkRect::MakeXYWH(0, 0, bounds().width(), bounds().heigh t()), paint); |
144 } | 146 } |
145 | 147 |
146 int fpsCounterHeight = 40; | 148 int platformLayerTreeTop = 0; |
147 int fpsCounterTop = 2; | |
148 int platformLayerTreeTop; | |
149 | 149 |
150 if (settings.showFPSCounter) | 150 if (settings.showFPSCounter) |
151 platformLayerTreeTop = fpsCounterTop + fpsCounterHeight; | 151 platformLayerTreeTop = drawFPSCounter(canvas, layerTreeHostImpl()->fpsCo unter()); |
egraether
2012/10/26 00:06:52
The drawFPSCounter method now returns the height,
| |
152 else | |
153 platformLayerTreeTop = 0; | |
154 | |
155 if (settings.showFPSCounter) | |
156 drawFPSCounter(canvas, layerTreeHostImpl()->fpsCounter(), fpsCounterTop, fpsCounterHeight); | |
157 | 152 |
158 if (settings.showPlatformLayerTree && m_fontAtlas.get()) { | 153 if (settings.showPlatformLayerTree && m_fontAtlas.get()) { |
159 std::string layerTree = layerTreeHostImpl()->layerTreeAsText(); | 154 std::string layerTree = layerTreeHostImpl()->layerTreeAsText(); |
160 m_fontAtlas->drawText(canvas, createPaint(), layerTree, gfx::Point(2, pl atformLayerTreeTop), bounds()); | 155 m_fontAtlas->drawText(canvas, createPaint(), layerTree, gfx::Point(2, pl atformLayerTreeTop), bounds()); |
161 } | 156 } |
162 | 157 |
163 if (settings.showDebugRects()) | 158 if (settings.showDebugRects()) |
164 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); | 159 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); |
165 } | 160 } |
166 | 161 |
167 void HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter* fpsCounter, int top, int height) | 162 int HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter* fpsCounter) |
168 { | 163 { |
169 float textWidth = 170; // so text fits on linux. | 164 const int left = 2; |
170 float graphWidth = fpsCounter->timeStampHistorySize(); | 165 const int top = 2; |
171 | 166 |
172 // Draw the FPS text. | 167 const int padding = 4; |
173 drawFPSCounterText(canvas, fpsCounter, top, textWidth, height); | 168 |
169 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; | |
170 const int graphWidth = fpsCounter->timeStampHistorySize() - 1; | |
171 const int graphHeight = 40; | |
172 | |
173 const int width = graphWidth + 2 * padding; | |
174 const int height = fontHeight + graphHeight + 4 * padding + 2; | |
175 | |
176 SkPaint paint = createPaint(); | |
177 | |
178 // Draw background. | |
179 paint.setColor(SkColorSetARGB(200, 0, 0, 0)); | |
egraether
2012/10/26 00:06:52
The background is drawn transparent so that the co
| |
180 canvas->drawRect(SkRect::MakeXYWH(left, top, width, height), paint); | |
181 | |
182 SkRect textBounds = SkRect::MakeXYWH(left + padding, top + padding, graphWid th, fontHeight); | |
183 SkRect graphBounds = SkRect::MakeXYWH(left + padding, textBounds.bottom() + 2 * padding, graphWidth, graphHeight); | |
184 | |
185 drawFPSCounterText(canvas, paint, fpsCounter, textBounds); | |
186 drawFPSCounterGraph(canvas, paint, fpsCounter, graphBounds); | |
187 | |
188 return top + height; | |
189 } | |
190 | |
191 void HeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, SkPaint& pain t, FrameRateCounter* fpsCounter, SkRect bounds) | |
192 { | |
193 // Update FPS text - not every frame so text is readable | |
194 if (base::TimeDelta(fpsCounter->timeStampOfRecentFrame(0) - textUpdateTime). InSecondsF() > 0.25) { | |
egraether
2012/10/26 00:06:52
The fps and deviation numbers used to be hard to r
| |
195 fpsCounter->getAverageFPSAndStandardDeviation(m_averageFPS, m_stdDeviati on); | |
196 textUpdateTime = fpsCounter->timeStampOfRecentFrame(0); | |
197 } | |
198 | |
199 // Draw FPS text. | |
200 if (m_fontAtlas.get()) { | |
201 std::string fpsText = base::StringPrintf("FPS:%5.1f", m_averageFPS); | |
202 std::string deviationText = base::StringPrintf("+/-%4.1f", m_stdDeviatio n); | |
203 | |
204 int deviationWidth = m_fontAtlas->textSize(deviationText).width(); | |
205 IntSize textArea = IntSize(bounds.width(), bounds.height()); | |
206 | |
207 paint.setColor(SK_ColorRED); | |
208 m_fontAtlas->drawText(canvas, paint, fpsText, gfx::Point(bounds.left(), bounds.top()), textArea); | |
209 m_fontAtlas->drawText(canvas, paint, deviationText, gfx::Point(bounds.ri ght() - deviationWidth, bounds.top()), textArea); | |
210 } | |
211 } | |
212 | |
213 void HeadsUpDisplayLayerImpl::drawFPSCounterGraph(SkCanvas* canvas, SkPaint& pai nt, FrameRateCounter* fpsCounter, SkRect bounds) | |
214 { | |
215 const double loFPS = 0; | |
216 const double hiFPS = 80; | |
217 | |
218 paint.setStyle(SkPaint::kStroke_Style); | |
219 paint.setStrokeWidth(1); | |
220 | |
221 // Draw top and bottom line. | |
222 paint.setColor(SkColorSetRGB(150, 150, 150)); | |
223 canvas->drawLine(bounds.left(), bounds.top() - 1, bounds.right(), bounds.top () - 1, paint); | |
224 canvas->drawLine(bounds.left(), bounds.bottom(), bounds.right(), bounds.bott om(), paint); | |
225 | |
226 // Draw 60fps line. | |
227 paint.setColor(SkColorSetRGB(100, 100, 100)); | |
228 canvas->drawLine(bounds.left(), bounds.top() + bounds.height() / 4, bounds.r ight(), bounds.top() + bounds.height() / 4, paint); | |
174 | 229 |
175 // Draw FPS graph. | 230 // Draw FPS graph. |
176 const double loFPS = 0; | 231 int x = 0; |
177 const double hiFPS = 80; | 232 SkPath path; |
178 SkPaint paint = createPaint(); | |
179 paint.setColor(SkColorSetRGB(154, 205, 50)); | |
180 canvas->drawRect(SkRect::MakeXYWH(2 + textWidth, top, graphWidth, height / 2 ), paint); | |
181 | 233 |
182 paint.setColor(SkColorSetRGB(255, 250, 205)); | |
183 canvas->drawRect(SkRect::MakeXYWH(2 + textWidth, top + height / 2, graphWidt h, height / 2), paint); | |
184 | |
185 int graphLeft = static_cast<int>(textWidth + 3); | |
186 int x = 0; | |
187 double h = static_cast<double>(height - 2); | |
188 SkPath path; | |
189 for (int i = 0; i < fpsCounter->timeStampHistorySize() - 1; ++i) { | 234 for (int i = 0; i < fpsCounter->timeStampHistorySize() - 1; ++i) { |
190 int j = i + 1; | 235 base::TimeDelta delta = fpsCounter->timeStampOfRecentFrame(i + 1) - fpsC ounter->timeStampOfRecentFrame(i); |
191 base::TimeDelta delta = fpsCounter->timeStampOfRecentFrame(j) - fpsCount er->timeStampOfRecentFrame(i); | |
192 | 236 |
193 // Skip plotting this particular instantaneous frame rate if it is not l ikely to have been valid. | 237 // Skip plotting this particular instantaneous frame rate if it is not l ikely to have been valid. |
194 if (fpsCounter->isBadFrameInterval(delta)) { | 238 if (!fpsCounter->isBadFrameInterval(delta)) { |
195 x += 1; | 239 double fps = 1.0 / delta.InSecondsF(); |
196 continue; | 240 |
241 // Clamp the FPS to the range we want to plot visually. | |
242 double p = 1 - ((fps - loFPS) / (hiFPS - loFPS)); | |
243 if (p < 0) | |
244 p = 0; | |
245 if (p > 1) | |
246 p = 1; | |
247 | |
248 // Plot this data point. | |
249 SkPoint cur = SkPoint::Make(bounds.left() + x, bounds.top() + p * bo unds.height()); | |
250 if (path.isEmpty()) | |
251 path.moveTo(cur); | |
252 else | |
253 path.lineTo(cur); | |
197 } | 254 } |
198 | 255 |
199 double fps = 1.0 / delta.InSecondsF(); | |
200 | |
201 // Clamp the FPS to the range we want to plot visually. | |
202 double p = 1 - ((fps - loFPS) / (hiFPS - loFPS)); | |
203 if (p < 0) | |
204 p = 0; | |
205 if (p > 1) | |
206 p = 1; | |
207 | |
208 // Plot this data point. | |
209 SkPoint cur = SkPoint::Make(graphLeft + x, 1 + top + p*h); | |
210 if (path.isEmpty()) | |
211 path.moveTo(cur); | |
212 else | |
213 path.lineTo(cur); | |
214 x += 1; | 256 x += 1; |
215 } | 257 } |
258 | |
259 paint.setAntiAlias(true); | |
216 paint.setColor(SK_ColorRED); | 260 paint.setColor(SK_ColorRED); |
217 paint.setStyle(SkPaint::kStroke_Style); | |
218 paint.setStrokeWidth(1); | |
219 paint.setAntiAlias(true); | |
220 canvas->drawPath(path, paint); | 261 canvas->drawPath(path, paint); |
221 } | 262 } |
222 | 263 |
223 void HeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, FrameRateCoun ter* fpsCounter, int top, int width, int height) | |
224 { | |
225 double averageFPS, stdDeviation; | |
226 fpsCounter->getAverageFPSAndStandardDeviation(averageFPS, stdDeviation); | |
227 | |
228 // Draw background. | |
229 SkPaint paint = createPaint(); | |
230 paint.setColor(SK_ColorBLACK); | |
231 canvas->drawRect(SkRect::MakeXYWH(2, top, width, height), paint); | |
232 | |
233 // Draw FPS text. | |
234 if (m_fontAtlas.get()) | |
235 m_fontAtlas->drawText(canvas, createPaint(), base::StringPrintf("FPS: %4 .1f +/- %3.1f", averageFPS, stdDeviation), gfx::Point(10, height / 3), IntSize(w idth, height)); | |
236 } | |
237 | |
238 void HeadsUpDisplayLayerImpl::drawDebugRects(SkCanvas* canvas, DebugRectHistory* debugRectHistory) | 264 void HeadsUpDisplayLayerImpl::drawDebugRects(SkCanvas* canvas, DebugRectHistory* debugRectHistory) |
239 { | 265 { |
240 const Vector<DebugRect>& debugRects = debugRectHistory->debugRects(); | 266 const Vector<DebugRect>& debugRects = debugRectHistory->debugRects(); |
241 | 267 |
242 for (size_t i = 0; i < debugRects.size(); ++i) { | 268 for (size_t i = 0; i < debugRects.size(); ++i) { |
243 SkColor strokeColor = 0; | 269 SkColor strokeColor = 0; |
244 SkColor fillColor = 0; | 270 SkColor fillColor = 0; |
245 | 271 |
246 switch (debugRects[i].type) { | 272 switch (debugRects[i].type) { |
247 case PaintRectType: | 273 case PaintRectType: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 canvas->drawRect(skRect, paint); | 314 canvas->drawRect(skRect, paint); |
289 } | 315 } |
290 } | 316 } |
291 | 317 |
292 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const | 318 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const |
293 { | 319 { |
294 return "HeadsUpDisplayLayer"; | 320 return "HeadsUpDisplayLayer"; |
295 } | 321 } |
296 | 322 |
297 } | 323 } |
OLD | NEW |