|
5 | 5 | #include "flutter/flow/instrumentation.h" |
6 | 6 |
|
7 | 7 | #include <algorithm> |
8 | | -#include <limits> |
9 | 8 |
|
10 | 9 | #include "third_party/skia/include/core/SkPath.h" |
11 | 10 | #include "third_party/skia/include/core/SkSurface.h" |
@@ -241,94 +240,6 @@ fml::Milliseconds Stopwatch::GetFrameBudget() const { |
241 | 240 | return refresh_rate_updater_.GetFrameBudget(); |
242 | 241 | } |
243 | 242 |
|
244 | | -CounterValues::CounterValues() : current_sample_(kMaxSamples - 1) { |
245 | | - values_.resize(kMaxSamples, 0); |
246 | | -} |
247 | | - |
248 | | -CounterValues::~CounterValues() = default; |
249 | | - |
250 | | -void CounterValues::Add(int64_t value) { |
251 | | - current_sample_ = (current_sample_ + 1) % kMaxSamples; |
252 | | - values_[current_sample_] = value; |
253 | | -} |
254 | | - |
255 | | -void CounterValues::Visualize(SkCanvas* canvas, const SkRect& rect) const { |
256 | | - size_t max_bytes = GetMaxValue(); |
257 | | - |
258 | | - if (max_bytes == 0) { |
259 | | - // The backend for this counter probably did not fill in any values. |
260 | | - return; |
261 | | - } |
262 | | - |
263 | | - size_t min_bytes = GetMinValue(); |
264 | | - |
265 | | - SkPaint paint; |
266 | | - |
267 | | - // Paint the background. |
268 | | - paint.setColor(0x99FFFFFF); |
269 | | - canvas->drawRect(rect, paint); |
270 | | - |
271 | | - // Establish the graph position. |
272 | | - const SkScalar x = rect.x(); |
273 | | - const SkScalar y = rect.y(); |
274 | | - const SkScalar width = rect.width(); |
275 | | - const SkScalar height = rect.height(); |
276 | | - const SkScalar bottom = y + height; |
277 | | - const SkScalar right = x + width; |
278 | | - |
279 | | - // Prepare a path for the data. |
280 | | - SkPath path; |
281 | | - path.moveTo(x, bottom); |
282 | | - |
283 | | - for (size_t i = 0; i < kMaxSamples; ++i) { |
284 | | - int64_t current_bytes = values_[i]; |
285 | | - double ratio = static_cast<double>(current_bytes - min_bytes) / |
286 | | - static_cast<double>(max_bytes - min_bytes); |
287 | | - path.lineTo( |
288 | | - x + ((static_cast<double>(i) / static_cast<double>(kMaxSamples)) * |
289 | | - width), |
290 | | - y + ((1.0 - ratio) * height)); |
291 | | - } |
292 | | - |
293 | | - path.rLineTo(100, 0); |
294 | | - path.lineTo(right, bottom); |
295 | | - path.close(); |
296 | | - |
297 | | - // Draw the graph. |
298 | | - paint.setColor(0xAA0000FF); |
299 | | - canvas->drawPath(path, paint); |
300 | | - |
301 | | - // Paint the vertical marker for the current frame. |
302 | | - const double sample_unit_width = (1.0 / kMaxSamples); |
303 | | - const double sample_margin_unit_width = sample_unit_width / 6.0; |
304 | | - const double sample_margin_width = width * sample_margin_unit_width; |
305 | | - paint.setStyle(SkPaint::Style::kFill_Style); |
306 | | - paint.setColor(SK_ColorGRAY); |
307 | | - double sample_x = |
308 | | - x + width * (static_cast<double>(current_sample_) / kMaxSamples) - |
309 | | - sample_margin_width; |
310 | | - const auto marker_rect = SkRect::MakeLTRB( |
311 | | - sample_x, y, |
312 | | - sample_x + width * sample_unit_width + sample_margin_width * 2, bottom); |
313 | | - canvas->drawRect(marker_rect, paint); |
314 | | -} |
315 | | - |
316 | | -int64_t CounterValues::GetMaxValue() const { |
317 | | - auto max = std::numeric_limits<int64_t>::min(); |
318 | | - for (size_t i = 0; i < kMaxSamples; ++i) { |
319 | | - max = std::max<int64_t>(max, values_[i]); |
320 | | - } |
321 | | - return max; |
322 | | -} |
323 | | - |
324 | | -int64_t CounterValues::GetMinValue() const { |
325 | | - auto min = std::numeric_limits<int64_t>::max(); |
326 | | - for (size_t i = 0; i < kMaxSamples; ++i) { |
327 | | - min = std::min<int64_t>(min, values_[i]); |
328 | | - } |
329 | | - return min; |
330 | | -} |
331 | | - |
332 | 243 | fml::Milliseconds FixedRefreshRateUpdater::GetFrameBudget() const { |
333 | 244 | return fixed_frame_budget_; |
334 | 245 | } |
|
0 commit comments