liyuqian 9f088c65ee
Add onReportTimings and FrameRasterizedCallback API (#8983)
Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
https://github.com/flutter/flutter/issues/26154
https://github.com/flutter/flutter/issues/31444
https://github.com/flutter/flutter/issues/32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:
* NoNeedToReportTimingsByDefault
* NeedsReportTimingsIsSetWithCallback
* ReportTimingsIsCalled
* FrameRasterizedCallbackIsCalled
* FrameTimingSetsAndGetsProperly
* onReportTimings preserves callback zone
* FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.
2019-06-06 10:42:48 -07:00

102 lines
2.6 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.
#ifndef FLUTTER_SHELL_COMMON_ANIMATOR_H_
#define FLUTTER_SHELL_COMMON_ANIMATOR_H_
#include <deque>
#include "flutter/common/task_runners.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/synchronization/semaphore.h"
#include "flutter/fml/time/time_point.h"
#include "flutter/shell/common/pipeline.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/vsync_waiter.h"
namespace flutter {
namespace testing {
class ShellTest;
}
class Animator final {
public:
class Delegate {
public:
virtual void OnAnimatorBeginFrame(fml::TimePoint frame_time) = 0;
virtual void OnAnimatorNotifyIdle(int64_t deadline) = 0;
virtual void OnAnimatorDraw(
fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline) = 0;
virtual void OnAnimatorDrawLastLayerTree() = 0;
};
Animator(Delegate& delegate,
TaskRunners task_runners,
std::unique_ptr<VsyncWaiter> waiter);
~Animator();
float GetDisplayRefreshRate() const;
void RequestFrame(bool regenerate_layer_tree = true);
void Render(std::unique_ptr<flutter::LayerTree> layer_tree);
void Start();
void Stop();
void SetDimensionChangePending();
// Enqueue |trace_flow_id| into |trace_flow_ids_|. The corresponding flow
// will be ended during the next |BeginFrame|.
void EnqueueTraceFlowId(uint64_t trace_flow_id);
private:
using LayerTreePipeline = Pipeline<flutter::LayerTree>;
void BeginFrame(fml::TimePoint frame_start_time,
fml::TimePoint frame_target_time);
bool CanReuseLastLayerTree();
void DrawLastLayerTree();
void AwaitVSync();
const char* FrameParity();
Delegate& delegate_;
TaskRunners task_runners_;
std::shared_ptr<VsyncWaiter> waiter_;
fml::TimePoint last_begin_frame_time_;
int64_t dart_frame_deadline_;
fml::RefPtr<LayerTreePipeline> layer_tree_pipeline_;
fml::Semaphore pending_frame_semaphore_;
LayerTreePipeline::ProducerContinuation producer_continuation_;
int64_t frame_number_;
bool paused_;
bool regenerate_layer_tree_;
bool frame_scheduled_;
int notify_idle_task_id_;
bool dimension_change_pending_;
SkISize last_layer_tree_size_;
std::deque<uint64_t> trace_flow_ids_;
fml::WeakPtrFactory<Animator> weak_factory_;
friend class testing::ShellTest;
FML_DISALLOW_COPY_AND_ASSIGN(Animator);
};
} // namespace flutter
#endif // FLUTTER_SHELL_COMMON_ANIMATOR_H_