diff --git a/flow/instrumentation.cc b/flow/instrumentation.cc index 72545050f..9cfacdd6d 100644 --- a/flow/instrumentation.cc +++ b/flow/instrumentation.cc @@ -9,56 +9,54 @@ #include "third_party/skia/include/core/SkPath.h" namespace flow { -namespace instrumentation { static const size_t kMaxSamples = 120; static const size_t kMaxFrameMarkers = 8; -Stopwatch::Stopwatch() : _start(base::TimeTicks::Now()), _current_sample(0) { +Stopwatch::Stopwatch() : start_(base::TimeTicks::Now()), current_sample_(0) { const base::TimeDelta delta; - _laps.resize(kMaxSamples, delta); + laps_.resize(kMaxSamples, delta); } -void Stopwatch::start() { - _start = base::TimeTicks::Now(); - _current_sample = (_current_sample + 1) % kMaxSamples; +void Stopwatch::Start() { + start_ = base::TimeTicks::Now(); + current_sample_ = (current_sample_ + 1) % kMaxSamples; } -void Stopwatch::stop() { - _laps[_current_sample] = base::TimeTicks::Now() - _start; +void Stopwatch::Stop() { + laps_[current_sample_] = base::TimeTicks::Now() - start_; } -void Stopwatch::setLapTime(const base::TimeDelta& delta) { - _current_sample = (_current_sample + 1) % kMaxSamples; - _laps[_current_sample] = delta; +void Stopwatch::SetLapTime(const base::TimeDelta& delta) { + current_sample_ = (current_sample_ + 1) % kMaxSamples; + laps_[current_sample_] = delta; } -const base::TimeDelta& Stopwatch::lastLap() const { - return _laps[(_current_sample - 1) % kMaxSamples]; +const base::TimeDelta& Stopwatch::LastLap() const { + return laps_[(current_sample_ - 1) % kMaxSamples]; } -static inline constexpr double UnitFrameInterval(double frameTimeMS) { - return frameTimeMS * 60.0 * 1e-3; +static inline constexpr double UnitFrameInterval(double frame_time_ms) { + return frame_time_ms * 60.0 * 1e-3; } -static inline double UnitHeight(double frameTimeMS, double maxUnitInterval) { - double unitHeight = UnitFrameInterval(frameTimeMS) / maxUnitInterval; +static inline double UnitHeight(double frame_time_ms, double max_unit_interval) { + double unitHeight = UnitFrameInterval(frame_time_ms) / max_unit_interval; if (unitHeight > 1.0) unitHeight = 1.0; return unitHeight; } -base::TimeDelta Stopwatch::maxDelta() const { - base::TimeDelta maxDelta; +base::TimeDelta Stopwatch::MaxDelta() const { + base::TimeDelta max_delta; for (size_t i = 0; i < kMaxSamples; i++) { - if (_laps[i] > maxDelta) { - maxDelta = _laps[i]; - } + if (laps_[i] > max_delta) + max_delta = laps_[i]; } - return maxDelta; + return max_delta; } -void Stopwatch::visualize(SkCanvas& canvas, const SkRect& rect) const { +void Stopwatch::Visualize(SkCanvas& canvas, const SkRect& rect) const { SkPaint paint; // Paint the background. @@ -74,30 +72,30 @@ void Stopwatch::visualize(SkCanvas& canvas, const SkRect& rect) const { const SkScalar right = x + width; // Scale the graph to show frame times up to those that are 4 times the frame time. - const double maxInterval = kOneFrameMS * 3.0; - const double maxUnitInterval = UnitFrameInterval(maxInterval); + const double max_interval = kOneFrameMS * 3.0; + const double max_unit_interval = UnitFrameInterval(max_interval); // Prepare a path for the data. // we start at the height of the last point, so it looks like we wrap around SkPath path; - const double sampleUnitWidth = (1.0 / kMaxSamples); - const double sampleMarginUnitWidth = sampleUnitWidth / 6.0; - const double sampleMarginWidth = width * sampleMarginUnitWidth; + const double sample_unit_width = (1.0 / kMaxSamples); + const double sample_margin_unit_width = sample_unit_width / 6.0; + const double sample_margin_width = width * sample_margin_unit_width; path.moveTo(x, bottom); - path.lineTo(x, y + height * (1.0 - UnitHeight(_laps[0].InMillisecondsF(), - maxUnitInterval))); - double unitX; - double unitNextX = 0.0; + path.lineTo(x, y + height * (1.0 - UnitHeight(laps_[0].InMillisecondsF(), + max_unit_interval))); + double unit_x; + double unit_next_x = 0.0; for (size_t i = 0; i < kMaxSamples; i += 1) { - unitX = unitNextX; - unitNextX = (static_cast(i + 1) / kMaxSamples); - const double sampleY = y + height * (1.0 - UnitHeight(_laps[i].InMillisecondsF(), - maxUnitInterval)); - path.lineTo(x + width * unitX + sampleMarginWidth, sampleY); - path.lineTo(x + width * unitNextX - sampleMarginWidth, sampleY); + unit_x = unit_next_x; + unit_next_x = (static_cast(i + 1) / kMaxSamples); + const double sample_y = y + height * (1.0 - UnitHeight(laps_[i].InMillisecondsF(), + max_unit_interval)); + path.lineTo(x + width * unit_x + sample_margin_width, sample_y); + path.lineTo(x + width * unit_next_x - sample_margin_width, sample_y); } - path.lineTo(right, y + height * (1.0 - UnitHeight(_laps[kMaxSamples - 1].InMillisecondsF(), - maxUnitInterval))); + path.lineTo(right, y + height * (1.0 - UnitHeight(laps_[kMaxSamples - 1].InMillisecondsF(), + max_unit_interval))); path.lineTo(right, bottom); path.close(); @@ -110,21 +108,20 @@ void Stopwatch::visualize(SkCanvas& canvas, const SkRect& rect) const { paint.setStyle(SkPaint::Style::kStroke_Style); paint.setColor(0xCC000000); - if (maxInterval > kOneFrameMS) { + if (max_interval > kOneFrameMS) { // Paint the horizontal markers - size_t frameMarkerCount = static_cast(maxInterval / kOneFrameMS); + size_t frame_marker_count = static_cast(max_interval / kOneFrameMS); // Limit the number of markers displayed. After a certain point, the graph // becomes crowded - if (frameMarkerCount > kMaxFrameMarkers) { - frameMarkerCount = 1; - } + if (frame_marker_count > kMaxFrameMarkers) + frame_marker_count = 1; - for (size_t frameIndex = 0; frameIndex < frameMarkerCount; frameIndex++) { - const double frameHeight = - height * (1.0 - (UnitFrameInterval((frameIndex + 1) * kOneFrameMS) / - maxUnitInterval)); - canvas.drawLine(x, y + frameHeight, right, y + frameHeight, paint); + for (size_t frame_index = 0; frame_index < frame_marker_count; frame_index++) { + const double frame_height = + height * (1.0 - (UnitFrameInterval((frame_index + 1) * kOneFrameMS) / + max_unit_interval)); + canvas.drawLine(x, y + frame_height, right, y + frame_height, paint); } } @@ -132,19 +129,18 @@ void Stopwatch::visualize(SkCanvas& canvas, const SkRect& rect) const { // We paint it over the current frame, not after it, because when we // paint this we don't yet have all the times for the current frame. paint.setStyle(SkPaint::Style::kFill_Style); - if (UnitFrameInterval(lastLap().InMillisecondsF()) > 1.0) { + if (UnitFrameInterval(LastLap().InMillisecondsF()) > 1.0) { // budget exceeded paint.setColor(SK_ColorRED); } else { // within budget paint.setColor(SK_ColorGREEN); } - double sampleX = x + width * (static_cast(_current_sample) / kMaxSamples) - - sampleMarginWidth; - canvas.drawRectCoords(sampleX, y, sampleX + width * sampleUnitWidth + sampleMarginWidth * 2, bottom, paint); + double sample_x = x + width * (static_cast(current_sample_) / kMaxSamples) + - sample_margin_width; + canvas.drawRectCoords(sample_x, y, sample_x + width * sample_unit_width + sample_margin_width * 2, bottom, paint); } Stopwatch::~Stopwatch() = default; -} // namespace instrumentation } // namespace flow diff --git a/flow/instrumentation.h b/flow/instrumentation.h index c17801420..84f4e3616 100644 --- a/flow/instrumentation.h +++ b/flow/instrumentation.h @@ -11,7 +11,6 @@ #include "third_party/skia/include/core/SkCanvas.h" namespace flow { -namespace instrumentation { static const double kOneFrameMS = 1e3 / 60.0; @@ -19,14 +18,14 @@ class Stopwatch { public: class ScopedLap { public: - explicit ScopedLap(Stopwatch& stopwatch) : _stopwatch(stopwatch) { - _stopwatch.start(); + explicit ScopedLap(Stopwatch& stopwatch) : stopwatch_(stopwatch) { + stopwatch_.Start(); } - ~ScopedLap() { _stopwatch.stop(); } + ~ScopedLap() { stopwatch_.Stop(); } private: - Stopwatch& _stopwatch; + Stopwatch& stopwatch_; DISALLOW_COPY_AND_ASSIGN(ScopedLap); }; @@ -34,45 +33,36 @@ class Stopwatch { explicit Stopwatch(); ~Stopwatch(); - const base::TimeDelta& lastLap() const; - - base::TimeDelta currentLap() const { return base::TimeTicks::Now() - _start; } - - base::TimeDelta maxDelta() const; - - void visualize(SkCanvas& canvas, const SkRect& rect) const; - - void start(); - - void stop(); - - void setLapTime(const base::TimeDelta& delta); + const base::TimeDelta& LastLap() const; + base::TimeDelta CurrentLap() const { return base::TimeTicks::Now() - start_; } + base::TimeDelta MaxDelta() const; + void Visualize(SkCanvas& canvas, const SkRect& rect) const; + void Start(); + void Stop(); + void SetLapTime(const base::TimeDelta& delta); private: - base::TimeTicks _start; - std::vector _laps; - size_t _current_sample; + base::TimeTicks start_; + std::vector laps_; + size_t current_sample_; DISALLOW_COPY_AND_ASSIGN(Stopwatch); }; class Counter { public: - explicit Counter() : _count(0) {} + explicit Counter() : count_(0) {} - size_t count() const { return _count; } - - void reset(size_t count = 0) { _count = count; } - - void increment(size_t count = 1) { _count += count; } + size_t count() const { return count_; } + void Reset(size_t count = 0) { count_ = count; } + void Increment(size_t count = 1) { count_ += count; } private: - size_t _count; + size_t count_; DISALLOW_COPY_AND_ASSIGN(Counter); }; -} // namespace instrumentation } // namespace flow #endif // FLOW_INSTRUMENTATION_H_ diff --git a/flow/layers/layer.h b/flow/layers/layer.h index fd13fc154..9e2731c3f 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -11,7 +11,6 @@ #include "base/logging.h" #include "base/macros.h" #include "flow/paint_context.h" -#include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" @@ -23,6 +22,15 @@ #include "third_party/skia/include/core/SkRRect.h" #include "third_party/skia/include/core/SkXfermode.h" +namespace mojo { +namespace gfx { +namespace composition { +class SceneUpdate; +class Node; +} // composition +} // namespace gfx +} // namespace mojo + namespace flow { class ContainerLayer; @@ -32,13 +40,13 @@ class Layer { virtual ~Layer(); struct PrerollContext { - PaintContext::ScopedFrame& frame; + RasterCache& raster_cache; + GrContext* gr_context; SkRect child_paint_bounds; }; virtual void Preroll(PrerollContext* context, const SkMatrix& matrix); virtual void Paint(PaintContext::ScopedFrame& frame) = 0; - virtual void UpdateScene(mojo::gfx::composition::SceneUpdate* update, mojo::gfx::composition::Node* container); diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index 443c00a60..d1e7f55ba 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -18,7 +18,11 @@ LayerTree::~LayerTree() { void LayerTree::Raster(PaintContext::ScopedFrame& frame) { { TRACE_EVENT0("flutter", "LayerTree::Preroll"); - Layer::PrerollContext context = { frame, SkRect::MakeEmpty() }; + Layer::PrerollContext context = { + frame.context().raster_cache(), + frame.gr_context(), + SkRect::MakeEmpty(), + }; root_layer_->Preroll(&context, SkMatrix()); } diff --git a/flow/layers/performance_overlay_layer.cc b/flow/layers/performance_overlay_layer.cc index 8c3f9743c..5869b9ee0 100644 --- a/flow/layers/performance_overlay_layer.cc +++ b/flow/layers/performance_overlay_layer.cc @@ -23,7 +23,7 @@ void DrawStatisticsText(SkCanvas& canvas, } void VisualizeStopWatch(SkCanvas& canvas, - const instrumentation::Stopwatch& stopwatch, + const Stopwatch& stopwatch, SkScalar x, SkScalar y, SkScalar width, @@ -31,36 +31,36 @@ void VisualizeStopWatch(SkCanvas& canvas, bool show_graph, bool show_labels, const std::string& label_prefix) { - const int labelX = 8; // distance from x - const int labelY = -10; // distance from y+height + const int label_x = 8; // distance from x + const int label_y = -10; // distance from y+height if (show_graph) { - SkRect visualizationRect = SkRect::MakeXYWH(x, y, width, height); - stopwatch.visualize(canvas, visualizationRect); + SkRect visualization_rect = SkRect::MakeXYWH(x, y, width, height); + stopwatch.Visualize(canvas, visualization_rect); } if (show_labels) { - double msPerFrame = stopwatch.maxDelta().InMillisecondsF(); + double ms_per_frame = stopwatch.MaxDelta().InMillisecondsF(); double fps; - if (msPerFrame < instrumentation::kOneFrameMS) { - fps = 1e3 / instrumentation::kOneFrameMS; + if (ms_per_frame < kOneFrameMS) { + fps = 1e3 / kOneFrameMS; } else { - fps = 1e3 / msPerFrame; + fps = 1e3 / ms_per_frame; } std::stringstream stream; stream.setf(std::ios::fixed | std::ios::showpoint); stream << std::setprecision(1); - stream << label_prefix << " " << fps << " fps " - << msPerFrame << "ms/frame"; - DrawStatisticsText(canvas, stream.str(), x + labelX, y + height + labelY); + stream << label_prefix << " " << fps << " fps " + << ms_per_frame << "ms/frame"; + DrawStatisticsText(canvas, stream.str(), x + label_x, y + height + label_y); } } } // namespace -PerformanceOverlayLayer::PerformanceOverlayLayer(uint64_t enabledOptions) - : options_(enabledOptions) { +PerformanceOverlayLayer::PerformanceOverlayLayer(uint64_t options) + : options_(options) { } diff --git a/flow/layers/performance_overlay_layer.h b/flow/layers/performance_overlay_layer.h index ac77759a3..302b1e074 100644 --- a/flow/layers/performance_overlay_layer.h +++ b/flow/layers/performance_overlay_layer.h @@ -17,7 +17,7 @@ const int kVisualizeEngineStatistics = 0x08; class PerformanceOverlayLayer : public Layer { public: - explicit PerformanceOverlayLayer(uint64_t enabledOptions); + explicit PerformanceOverlayLayer(uint64_t options); void Paint(PaintContext::ScopedFrame& frame) override; diff --git a/flow/layers/picture_layer.cc b/flow/layers/picture_layer.cc index 5a3dbdd62..242d9491a 100644 --- a/flow/layers/picture_layer.cc +++ b/flow/layers/picture_layer.cc @@ -21,8 +21,8 @@ PictureLayer::~PictureLayer() { void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { - image_ = context->frame.context().raster_cache().GetPrerolledImage( - context->frame.gr_context(), picture_.get(), matrix); + image_ = context->raster_cache.GetPrerolledImage( + context->gr_context, picture_.get(), matrix); context->child_paint_bounds = picture_->cullRect().makeOffset(offset_.x(), offset_.y()); } diff --git a/flow/paint_context.cc b/flow/paint_context.cc index 0cc2e9923..f3a908820 100644 --- a/flow/paint_context.cc +++ b/flow/paint_context.cc @@ -12,17 +12,17 @@ namespace flow { PaintContext::PaintContext() { } -void PaintContext::beginFrame(ScopedFrame& frame, bool enableInstrumentation) { +void PaintContext::BeginFrame(ScopedFrame& frame, bool enableInstrumentation) { if (enableInstrumentation) { - frame_count_.increment(); - frame_time_.start(); + frame_count_.Increment(); + frame_time_.Start(); } } -void PaintContext::endFrame(ScopedFrame& frame, bool enableInstrumentation) { +void PaintContext::EndFrame(ScopedFrame& frame, bool enableInstrumentation) { raster_cache_.SweepAfterFrame(); if (enableInstrumentation) { - frame_time_.stop(); + frame_time_.Stop(); } } @@ -37,13 +37,13 @@ PaintContext::ScopedFrame::ScopedFrame(PaintContext& context, bool instrumentation_enabled) : context_(context), gr_context_(gr_context), canvas_(&canvas), instrumentation_enabled_(instrumentation_enabled) { - context_.beginFrame(*this, instrumentation_enabled_); + context_.BeginFrame(*this, instrumentation_enabled_); } PaintContext::ScopedFrame::ScopedFrame(ScopedFrame&& frame) = default; PaintContext::ScopedFrame::~ScopedFrame() { - context_.endFrame(*this, instrumentation_enabled_); + context_.EndFrame(*this, instrumentation_enabled_); } PaintContext::~PaintContext() { diff --git a/flow/paint_context.h b/flow/paint_context.h index 3177050d2..0f3f8cfc3 100644 --- a/flow/paint_context.h +++ b/flow/paint_context.h @@ -54,19 +54,19 @@ class PaintContext { void OnGrContextDestroyed(); RasterCache& raster_cache() { return raster_cache_; } - const instrumentation::Counter& frame_count() const { return frame_count_; } - const instrumentation::Stopwatch& frame_time() const { return frame_time_; } - instrumentation::Stopwatch& engine_time() { return engine_time_; }; + const Counter& frame_count() const { return frame_count_; } + const Stopwatch& frame_time() const { return frame_time_; } + Stopwatch& engine_time() { return engine_time_; }; private: RasterCache raster_cache_; - instrumentation::Counter frame_count_; - instrumentation::Stopwatch frame_time_; - instrumentation::Stopwatch engine_time_; + Counter frame_count_; + Stopwatch frame_time_; + Stopwatch engine_time_; - void beginFrame(ScopedFrame& frame, bool enableInstrumentation); - void endFrame(ScopedFrame& frame, bool enableInstrumentation); + void BeginFrame(ScopedFrame& frame, bool enableInstrumentation); + void EndFrame(ScopedFrame& frame, bool enableInstrumentation); DISALLOW_COPY_AND_ASSIGN(PaintContext); }; diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index 0921ebff9..29793a17e 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -85,7 +85,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, // There is no way for the compositor to know how long the layer tree // construction took. Fortunately, the layer tree does. Grab that time // for instrumentation. - paint_context_.engine_time().setLapTime(layer_tree->construction_time()); + paint_context_.engine_time().SetLapTime(layer_tree->construction_time()); { EnsureGLContext(); @@ -104,7 +104,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr, bool frameExceededThreshold = false; uint32_t thresholdInterval = layer_tree->rasterizer_tracing_threshold(); if (thresholdInterval != 0 && - paint_context_.frame_time().lastLap().InMillisecondsF() > + paint_context_.frame_time().LastLap().InMillisecondsF() > thresholdInterval * kOneFrameDuration) { // While rendering the last frame, if we exceeded the tracing threshold // specified in the layer tree, we force a trace to disk. diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.cc b/sky/shell/gpu/mojo/rasterizer_mojo.cc index a07182b56..f1131c910 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.cc +++ b/sky/shell/gpu/mojo/rasterizer_mojo.cc @@ -82,6 +82,8 @@ void RasterizerMojo::Draw(uint64_t layer_tree_ptr, return; } + paint_context_.engine_time().SetLapTime(layer_tree->construction_time()); + std::unique_ptr texture = gl_state_->gl_texture_recycler.GetTexture(size); DCHECK(texture);