Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 01fee45

Browse files
committed
Reimpl
1 parent b75d6d8 commit 01fee45

25 files changed

+736
-213
lines changed

flow/frame_timings.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,30 @@ const char* FrameTimingsRecorder::GetFrameNumberTraceArg() const {
254254
return frame_number_trace_arg_val_.c_str();
255255
}
256256

257+
static const char* StateToString(FrameTimingsRecorder::State state) {
258+
#ifndef NDEBUG
259+
switch (state) {
260+
case FrameTimingsRecorder::State::kUninitialized:
261+
return "kUninitialized";
262+
case FrameTimingsRecorder::State::kVsync:
263+
return "kVsync";
264+
case FrameTimingsRecorder::State::kBuildStart:
265+
return "kBuildStart";
266+
case FrameTimingsRecorder::State::kBuildEnd:
267+
return "kBuildEnd";
268+
case FrameTimingsRecorder::State::kRasterStart:
269+
return "kRasterStart";
270+
case FrameTimingsRecorder::State::kRasterEnd:
271+
return "kRasterEnd";
272+
};
273+
FML_UNREACHABLE();
274+
#endif
275+
return "";
276+
}
277+
257278
void FrameTimingsRecorder::AssertInState(State state) const {
258-
FML_DCHECK(state_ == state);
279+
FML_DCHECK(state_ == state) << "Expected state " << StateToString(state)
280+
<< ", actual state " << StateToString(state_);
259281
}
260282

261283
} // namespace flutter

flow/frame_timings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class FrameTimingsRecorder {
3131
public:
3232
/// Various states that the recorder can be in. When created the recorder is
3333
/// in an unitialized state and transtions in sequential order of the states.
34+
// After adding an item to this enum, modify StateToString accordingly.
3435
enum class State : uint32_t {
3536
kUninitialized,
3637
kVsync,
@@ -121,6 +122,8 @@ class FrameTimingsRecorder {
121122
///
122123
/// Instead of adding a `GetState` method and asserting on the result, this
123124
/// method prevents other logic from relying on the state.
125+
///
126+
/// In opt builds, this call is a no-op.
124127
void AssertInState(State state) const;
125128

126129
private:

lib/ui/dart_ui.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ typedef CanvasPath Path;
9898
V(NativeStringAttribute::initSpellOutStringAttribute, 3) \
9999
V(PlatformConfigurationNativeApi::DefaultRouteName, 0) \
100100
V(PlatformConfigurationNativeApi::ScheduleFrame, 0) \
101-
V(PlatformConfigurationNativeApi::Render, 1) \
101+
V(PlatformConfigurationNativeApi::Render, 2) \
102102
V(PlatformConfigurationNativeApi::UpdateSemantics, 1) \
103103
V(PlatformConfigurationNativeApi::SetNeedsReportTimings, 1) \
104104
V(PlatformConfigurationNativeApi::SetIsolateDebugName, 1) \

lib/ui/painting/image_dispose_unittests.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define FML_USED_ON_EMBEDDER
66

77
#include "flutter/common/task_runners.h"
8+
#include "flutter/fml/synchronization/count_down_latch.h"
89
#include "flutter/fml/synchronization/waitable_event.h"
910
#include "flutter/lib/ui/painting/canvas.h"
1011
#include "flutter/lib/ui/painting/image.h"
@@ -57,6 +58,10 @@ TEST_F(ImageDisposeTest, ImageReleasedAfterFrameAndDisposePictureAndLayer) {
5758
};
5859

5960
Settings settings = CreateSettingsForFixture();
61+
fml::CountDownLatch frame_latch{2};
62+
settings.frame_rasterized_callback = [&frame_latch](const FrameTiming& t) {
63+
frame_latch.CountDown();
64+
};
6065
auto task_runner = CreateNewThread();
6166
TaskRunners task_runners("test", // label
6267
GetCurrentTaskRunner(), // platform
@@ -83,12 +88,15 @@ TEST_F(ImageDisposeTest, ImageReleasedAfterFrameAndDisposePictureAndLayer) {
8388
shell->RunEngine(std::move(configuration), [&](auto result) {
8489
ASSERT_EQ(result, Engine::RunStatus::Success);
8590
});
86-
8791
message_latch_.Wait();
8892

8993
ASSERT_TRUE(current_display_list_);
9094
ASSERT_TRUE(current_image_);
9195

96+
// Wait for 2 frames to be rasterized. The 2nd frame releases resources of the
97+
// 1st frame.
98+
frame_latch.Wait();
99+
92100
// Force a drain the SkiaUnrefQueue. The engine does this normally as frames
93101
// pump, but we force it here to make the test more deterministic.
94102
message_latch_.Reset();

lib/ui/platform_dispatcher.dart

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -308,29 +308,6 @@ class PlatformDispatcher {
308308
_invoke(onMetricsChanged, _onMetricsChangedZone);
309309
}
310310

311-
// A debug-only variable that stores the [FlutterView]s for which
312-
// [FlutterView.render] has already been called during the current
313-
// [onBeginFrame]/[onDrawFrame] callback sequence.
314-
//
315-
// It is null outside the scope of those callbacks indicating that calls to
316-
// [FlutterView.render] must be ignored. Furthermore, if a given [FlutterView]
317-
// is already present in this set when its [FlutterView.render] is called
318-
// again, that call must be ignored as a duplicate.
319-
//
320-
// Between [onBeginFrame] and [onDrawFrame] the properties value is
321-
// temporarily stored in `_renderedViewsBetweenCallbacks` so that it survives
322-
// the gap between the two callbacks.
323-
//
324-
// In release build, this variable is null, and therefore the calling rule is
325-
// not enforced. This is because the check might hurt cold startup delay;
326-
// see https://github.com/flutter/engine/pull/46919.
327-
Set<FlutterView>? _debugRenderedViews;
328-
// A debug-only variable that temporarily stores the `_renderedViews` value
329-
// between `_beginFrame` and `_drawFrame`.
330-
//
331-
// In release build, this variable is null.
332-
Set<FlutterView>? _debugRenderedViewsBetweenCallbacks;
333-
334311
/// A callback invoked when any view begins a frame.
335312
///
336313
/// A callback that is invoked to notify the application that it is an
@@ -351,26 +328,11 @@ class PlatformDispatcher {
351328

352329
// Called from the engine, via hooks.dart
353330
void _beginFrame(int microseconds) {
354-
assert(_debugRenderedViews == null);
355-
assert(_debugRenderedViewsBetweenCallbacks == null);
356-
assert(() {
357-
_debugRenderedViews = <FlutterView>{};
358-
return true;
359-
}());
360-
361331
_invoke1<Duration>(
362332
onBeginFrame,
363333
_onBeginFrameZone,
364334
Duration(microseconds: microseconds),
365335
);
366-
367-
assert(_debugRenderedViews != null);
368-
assert(_debugRenderedViewsBetweenCallbacks == null);
369-
assert(() {
370-
_debugRenderedViewsBetweenCallbacks = _debugRenderedViews;
371-
_debugRenderedViews = null;
372-
return true;
373-
}());
374336
}
375337

376338
/// A callback that is invoked for each frame after [onBeginFrame] has
@@ -388,22 +350,7 @@ class PlatformDispatcher {
388350

389351
// Called from the engine, via hooks.dart
390352
void _drawFrame() {
391-
assert(_debugRenderedViews == null);
392-
assert(_debugRenderedViewsBetweenCallbacks != null);
393-
assert(() {
394-
_debugRenderedViews = _debugRenderedViewsBetweenCallbacks;
395-
_debugRenderedViewsBetweenCallbacks = null;
396-
return true;
397-
}());
398-
399353
_invoke(onDrawFrame, _onDrawFrameZone);
400-
401-
assert(_debugRenderedViews != null);
402-
assert(_debugRenderedViewsBetweenCallbacks == null);
403-
assert(() {
404-
_debugRenderedViews = null;
405-
return true;
406-
}());
407354
}
408355

409356
/// A callback that is invoked when pointer data is available.

lib/ui/window.dart

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,11 @@ class FlutterView {
372372
/// * [RendererBinding], the Flutter framework class which manages layout and
373373
/// painting.
374374
void render(Scene scene, {Size? size}) {
375-
// Duplicated calls or calls outside of onBeginFrame/onDrawFrame (indicated
376-
// by _debugRenderedViews being null) are ignored. See _debugRenderedViews.
377-
// TODO(dkwingsmt): We should change this skip into an assertion.
378-
// https://github.com/flutter/flutter/issues/137073
379-
bool validRender = true;
380-
assert(() {
381-
validRender = platformDispatcher._debugRenderedViews?.add(this) ?? false;
382-
return true;
383-
}());
384-
if (validRender) {
385-
_render(scene as _NativeScene, size?.width ?? physicalSize.width, size?.height ?? physicalSize.height);
386-
}
375+
_render(viewId, scene as _NativeScene, size?.width ?? physicalSize.width, size?.height ?? physicalSize.height);
387376
}
388377

389-
@Native<Void Function(Pointer<Void>, Double, Double)>(symbol: 'PlatformConfigurationNativeApi::Render')
390-
external static void _render(_NativeScene scene, double width, double height);
378+
@Native<Void Function(Int64, Pointer<Void>, Double, Double)>(symbol: 'PlatformConfigurationNativeApi::Render')
379+
external static void _render(int viewId, _NativeScene scene, double width, double height);
391380

392381
/// Change the retained semantics data about this [FlutterView].
393382
///

lib/ui/window/platform_configuration.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,13 @@ void PlatformConfiguration::CompletePlatformMessageResponse(
449449
response->Complete(std::make_unique<fml::DataMapping>(std::move(data)));
450450
}
451451

452-
void PlatformConfigurationNativeApi::Render(Scene* scene,
452+
void PlatformConfigurationNativeApi::Render(int64_t view_id,
453+
Scene* scene,
453454
double width,
454455
double height) {
455456
UIDartState::ThrowIfUIOperationsProhibited();
456457
UIDartState::Current()->platform_configuration()->client()->Render(
457-
scene, width, height);
458+
view_id, scene, width, height);
458459
}
459460

460461
void PlatformConfigurationNativeApi::SetNeedsReportTimings(bool value) {

lib/ui/window/platform_configuration.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ class PlatformConfigurationClient {
6969
/// @brief Updates the client's rendering on the GPU with the newly
7070
/// provided Scene.
7171
///
72-
virtual void Render(Scene* scene, double width, double height) = 0;
72+
virtual void Render(int64_t view_id,
73+
Scene* scene,
74+
double width,
75+
double height) = 0;
7376

7477
//--------------------------------------------------------------------------
7578
/// @brief Receives an updated semantics tree from the Framework.
@@ -557,7 +560,10 @@ class PlatformConfigurationNativeApi {
557560

558561
static void ScheduleFrame();
559562

560-
static void Render(Scene* scene, double width, double height);
563+
static void Render(int64_t view_id,
564+
Scene* scene,
565+
double width,
566+
double height);
561567

562568
static void UpdateSemantics(SemanticsUpdate* update);
563569

0 commit comments

Comments
 (0)