flutter_flutter/flow/layers/performance_overlay_layer.cc
Chris Bracken 6d8bd99afb
Revert "Reland PerformanceOverlayLayer golden test (#7863)" (#7895)
Reverting this broke the flow tests for the performance overlay:

```
../../flutter/flow/layers/performance_overlay_layer_unittests.cc:70: Failure
Value of: golden_data != nullptr
  Actual: false
Expected: true
```

This reverts commit 8427d73c8340c9e51492689ee66261a4a72cac9e.
2019-02-20 20:45:39 -08:00

88 lines
3.0 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <iomanip>
#include <iostream>
#include <string>
#include "flutter/flow/layers/performance_overlay_layer.h"
#include "third_party/skia/include/core/SkFont.h"
namespace flow {
namespace {
void DrawStatisticsText(SkCanvas& canvas,
const std::string& string,
int x,
int y) {
SkFont font;
font.setSize(15);
font.setLinearMetrics(false);
SkPaint paint;
paint.setColor(SK_ColorGRAY);
canvas.drawSimpleText(string.c_str(), string.size(), kUTF8_SkTextEncoding, x,
y, font, paint);
}
void VisualizeStopWatch(SkCanvas& canvas,
const Stopwatch& stopwatch,
SkScalar x,
SkScalar y,
SkScalar width,
SkScalar height,
bool show_graph,
bool show_labels,
const std::string& label_prefix) {
const int label_x = 8; // distance from x
const int label_y = -10; // distance from y+height
if (show_graph) {
SkRect visualization_rect = SkRect::MakeXYWH(x, y, width, height);
stopwatch.Visualize(canvas, visualization_rect);
}
if (show_labels) {
double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF();
std::stringstream stream;
stream.setf(std::ios::fixed | std::ios::showpoint);
stream << std::setprecision(1);
stream << label_prefix << " "
<< "max " << max_ms_per_frame << " ms/frame, "
<< "avg " << average_ms_per_frame << " ms/frame";
DrawStatisticsText(canvas, stream.str(), x + label_x, y + height + label_y);
}
}
} // namespace
PerformanceOverlayLayer::PerformanceOverlayLayer(uint64_t options)
: options_(options) {}
void PerformanceOverlayLayer::Paint(PaintContext& context) const {
const int padding = 8;
if (!options_)
return;
TRACE_EVENT0("flutter", "PerformanceOverlayLayer::Paint");
SkScalar x = paint_bounds().x() + padding;
SkScalar y = paint_bounds().y() + padding;
SkScalar width = paint_bounds().width() - (padding * 2);
SkScalar height = paint_bounds().height() / 2;
SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
VisualizeStopWatch(*context.leaf_nodes_canvas, context.frame_time, x, y,
width, height - padding,
options_ & kVisualizeRasterizerStatistics,
options_ & kDisplayRasterizerStatistics, "GPU");
VisualizeStopWatch(*context.leaf_nodes_canvas, context.engine_time, x,
y + height, width, height - padding,
options_ & kVisualizeEngineStatistics,
options_ & kDisplayEngineStatistics, "UI");
}
} // namespace flow