Skip to content

Commit 0fb5f74

Browse files
dzolotovsuryaKommana2662
authored andcommitted
[engine] Replace fml::Status and fml::StatusOr with absl (flutter#194161)
This started as a fix for `fml::Status` holding its message as a `std::string_view`: `CommandQueueVK::Submit` built a status from a local string inside the fence callback and returned it after the string was gone. In review the ask was to use `absl::Status` instead, so this PR removes `fml::Status` and `fml::StatusOr` and switches every user to `absl::Status` and `absl::StatusOr`. `absl::Status` owns its message, so the dangling view goes away with the type, and so does the TODO in `status_or.h` that pointed at flutter#134741. Most of it is mechanical. `fml::Status()` becomes `absl::OkStatus()`, the status codes have the same names in both, includes point at `third_party/abseil-cpp/absl/status`, and `//flutter/flow` gets abseil status in `public_deps` because `frame_timings.h` returns it. The part that isn't mechanical comes from `absl::Status` being `[[nodiscard]]`. `fml::Status` wasn't, and about 25 call sites dropped a status without looking at it. I didn't want this PR to change what any of them do, so in production code and in the render and playground tests they now call `.IgnoreError()`. That includes `DescriptorPoolVK::AllocateDescriptorSets`, which ignores a failed `CreateNewPool` today. Whether it should return that error is a separate question. The fence waiter, descriptor pool and command encoder tests check the result instead, since there the expected status is known. One exception. `CopyImageByteData` in `lib/ui/painting/image_encoding.cc` built an error for a failed swizzle surface, never returned it, and went on to use the null surface. The compiler only caught it because of `[[nodiscard]]`, and I added the missing `return`. If you'd rather have that as its own PR I'll split it out. **Where it was verified.** macOS arm64, `host_debug_unopt_arm64`, rebased on current main, `gn check` clean. `fml_unittests` 203/203, `ui_unittests` 73/73, `shell_unittests` 197/197, `flow_unittests` 313/313 and the Vulkan, fence waiter, descriptor pool, command queue, Gaussian blur and text frame tests in `impeller_unittests` (193/193). `impeller_golden_tests` and `flutter_tester` build. Locally `PerformanceOverlayLayerDefault.Gold` and two `EmbedderTest.CanRenderTextWithImpeller*Metal` tests fail on missing glyphs and ICU data (`U_MISSING_RESOURCE_ERROR`). They fail the same way on main without this change, so it's my checkout. CI covers the other platforms. Fixes flutter#194151 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent a8785ce commit 0fb5f74

78 files changed

Lines changed: 374 additions & 529 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎engine/src/flutter/flow/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ source_set("flow") {
9898
"//flutter/display_list",
9999
"//flutter/fml",
100100
"//flutter/txt",
101+
"//third_party/abseil-cpp/absl/status",
101102
]
102103

103104
deps = [ "//flutter/skia" ]

‎engine/src/flutter/flow/frame_timings.cc‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,75 +128,77 @@ size_t FrameTimingsRecorder::GetPictureCacheBytes() const {
128128

129129
void FrameTimingsRecorder::RecordVsync(fml::TimePoint vsync_start,
130130
fml::TimePoint vsync_target) {
131-
fml::Status status = RecordVsyncImpl(vsync_start, vsync_target);
131+
absl::Status status = RecordVsyncImpl(vsync_start, vsync_target);
132132
FML_DCHECK(status.ok());
133133
(void)status;
134134
}
135135

136136
void FrameTimingsRecorder::RecordBuildStart(fml::TimePoint build_start) {
137-
fml::Status status = RecordBuildStartImpl(build_start);
137+
absl::Status status = RecordBuildStartImpl(build_start);
138138
FML_DCHECK(status.ok());
139139
(void)status;
140140
}
141141

142142
void FrameTimingsRecorder::RecordBuildEnd(fml::TimePoint build_end) {
143-
fml::Status status = RecordBuildEndImpl(build_end);
143+
absl::Status status = RecordBuildEndImpl(build_end);
144144
FML_DCHECK(status.ok());
145145
(void)status;
146146
}
147147

148148
void FrameTimingsRecorder::RecordRasterStart(fml::TimePoint raster_start) {
149-
fml::Status status = RecordRasterStartImpl(raster_start);
149+
absl::Status status = RecordRasterStartImpl(raster_start);
150150
FML_DCHECK(status.ok());
151151
(void)status;
152152
}
153153

154-
fml::Status FrameTimingsRecorder::RecordVsyncImpl(fml::TimePoint vsync_start,
155-
fml::TimePoint vsync_target) {
154+
absl::Status FrameTimingsRecorder::RecordVsyncImpl(
155+
fml::TimePoint vsync_start,
156+
fml::TimePoint vsync_target) {
156157
std::scoped_lock state_lock(state_mutex_);
157158
if (state_ != State::kUninitialized) {
158-
return fml::Status(fml::StatusCode::kFailedPrecondition,
159-
"Check failed: state_ == State::kUninitialized.");
159+
return absl::Status(absl::StatusCode::kFailedPrecondition,
160+
"Check failed: state_ == State::kUninitialized.");
160161
}
161162
state_ = State::kVsync;
162163
vsync_start_ = vsync_start;
163164
vsync_target_ = vsync_target;
164-
return fml::Status();
165+
return absl::OkStatus();
165166
}
166167

167-
fml::Status FrameTimingsRecorder::RecordBuildStartImpl(
168+
absl::Status FrameTimingsRecorder::RecordBuildStartImpl(
168169
fml::TimePoint build_start) {
169170
std::scoped_lock state_lock(state_mutex_);
170171
if (state_ != State::kVsync) {
171-
return fml::Status(fml::StatusCode::kFailedPrecondition,
172-
"Check failed: state_ == State::kVsync.");
172+
return absl::Status(absl::StatusCode::kFailedPrecondition,
173+
"Check failed: state_ == State::kVsync.");
173174
}
174175
state_ = State::kBuildStart;
175176
build_start_ = build_start;
176-
return fml::Status();
177+
return absl::OkStatus();
177178
}
178179

179-
fml::Status FrameTimingsRecorder::RecordBuildEndImpl(fml::TimePoint build_end) {
180+
absl::Status FrameTimingsRecorder::RecordBuildEndImpl(
181+
fml::TimePoint build_end) {
180182
std::scoped_lock state_lock(state_mutex_);
181183
if (state_ != State::kBuildStart) {
182-
return fml::Status(fml::StatusCode::kFailedPrecondition,
183-
"Check failed: state_ == State::kBuildStart.");
184+
return absl::Status(absl::StatusCode::kFailedPrecondition,
185+
"Check failed: state_ == State::kBuildStart.");
184186
}
185187
state_ = State::kBuildEnd;
186188
build_end_ = build_end;
187-
return fml::Status();
189+
return absl::OkStatus();
188190
}
189191

190-
fml::Status FrameTimingsRecorder::RecordRasterStartImpl(
192+
absl::Status FrameTimingsRecorder::RecordRasterStartImpl(
191193
fml::TimePoint raster_start) {
192194
std::scoped_lock state_lock(state_mutex_);
193195
if (state_ != State::kBuildEnd) {
194-
return fml::Status(fml::StatusCode::kFailedPrecondition,
195-
"Check failed: state_ == State::kBuildEnd.");
196+
return absl::Status(absl::StatusCode::kFailedPrecondition,
197+
"Check failed: state_ == State::kBuildEnd.");
196198
}
197199
state_ = State::kRasterStart;
198200
raster_start_ = raster_start;
199-
return fml::Status();
201+
return absl::OkStatus();
200202
}
201203

202204
FrameTiming FrameTimingsRecorder::RecordRasterEnd(const RasterCache* cache) {

‎engine/src/flutter/flow/frame_timings.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "flutter/common/settings.h"
1111
#include "flutter/flow/raster_cache.h"
1212
#include "flutter/fml/macros.h"
13-
#include "flutter/fml/status.h"
1413
#include "flutter/fml/time/time_delta.h"
1514
#include "flutter/fml/time/time_point.h"
15+
#include "third_party/abseil-cpp/absl/status/status.h"
1616

1717
#define TRACE_EVENT_WITH_FRAME_NUMBER(recorder, category_group, name, \
1818
flow_id_count, flow_ids) \
@@ -131,11 +131,11 @@ class FrameTimingsRecorder {
131131
FML_FRIEND_TEST(FrameTimingsRecorderTest,
132132
ThrowWhenRecordRasterBeforeBuildEnd);
133133

134-
[[nodiscard]] fml::Status RecordVsyncImpl(fml::TimePoint vsync_start,
135-
fml::TimePoint vsync_target);
136-
[[nodiscard]] fml::Status RecordBuildStartImpl(fml::TimePoint build_start);
137-
[[nodiscard]] fml::Status RecordBuildEndImpl(fml::TimePoint build_end);
138-
[[nodiscard]] fml::Status RecordRasterStartImpl(fml::TimePoint raster_start);
134+
[[nodiscard]] absl::Status RecordVsyncImpl(fml::TimePoint vsync_start,
135+
fml::TimePoint vsync_target);
136+
[[nodiscard]] absl::Status RecordBuildStartImpl(fml::TimePoint build_start);
137+
[[nodiscard]] absl::Status RecordBuildEndImpl(fml::TimePoint build_end);
138+
[[nodiscard]] absl::Status RecordRasterStartImpl(fml::TimePoint raster_start);
139139

140140
static std::atomic<uint64_t> frame_number_gen_;
141141

‎engine/src/flutter/flow/frame_timings_recorder_unittests.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ TEST(FrameTimingsRecorderTest, ThrowWhenRecordBuildBeforeVsync) {
131131
auto recorder = std::make_unique<FrameTimingsRecorder>();
132132

133133
const auto build_start = fml::TimePoint::Now();
134-
fml::Status status = recorder->RecordBuildStartImpl(build_start);
134+
absl::Status status = recorder->RecordBuildStartImpl(build_start);
135135
EXPECT_FALSE(status.ok());
136136
EXPECT_EQ(status.message(), "Check failed: state_ == State::kVsync.");
137137
}
@@ -144,7 +144,7 @@ TEST(FrameTimingsRecorderTest, ThrowWhenRecordRasterBeforeBuildEnd) {
144144
recorder->RecordVsync(st, en);
145145

146146
const auto raster_start = fml::TimePoint::Now();
147-
fml::Status status = recorder->RecordRasterStartImpl(raster_start);
147+
absl::Status status = recorder->RecordRasterStartImpl(raster_start);
148148
EXPECT_FALSE(status.ok());
149149
EXPECT_EQ(status.message(), "Check failed: state_ == State::kBuildEnd.");
150150
}

‎engine/src/flutter/fml/BUILD.gn‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ source_set("fml") {
7171
"safe_math.h",
7272
"shared_thread_merger.cc",
7373
"shared_thread_merger.h",
74-
"status.h",
75-
"status_or.h",
7674
"synchronization/atomic_object.h",
7775
"synchronization/count_down_latch.cc",
7876
"synchronization/count_down_latch.h",

‎engine/src/flutter/fml/status.h‎

Lines changed: 0 additions & 81 deletions
This file was deleted.

‎engine/src/flutter/fml/status_or.h‎

Lines changed: 0 additions & 102 deletions
This file was deleted.

‎engine/src/flutter/impeller/display_list/aiks_dl_unittests.cc‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,11 @@ TEST_P(AiksTest, ToImageFromImage) {
11081108
blit_pass->EncodeCommands();
11091109

11101110
auto latch = std::make_shared<fml::CountDownLatch>(1u);
1111-
GetContext()->GetCommandQueue()->Submit(
1112-
{cmd_buffer},
1113-
[latch](CommandBuffer::Status status) { latch->CountDown(); });
1111+
GetContext()
1112+
->GetCommandQueue()
1113+
->Submit({cmd_buffer},
1114+
[latch](CommandBuffer::Status status) { latch->CountDown(); })
1115+
.IgnoreError();
11141116
latch->Wait();
11151117
}
11161118

@@ -1128,9 +1130,11 @@ TEST_P(AiksTest, ToImageFromImage) {
11281130
blit_pass->EncodeCommands();
11291131

11301132
auto latch = std::make_shared<fml::CountDownLatch>(1u);
1131-
GetContext()->GetCommandQueue()->Submit(
1132-
{cmd_buffer},
1133-
[latch](CommandBuffer::Status status) { latch->CountDown(); });
1133+
GetContext()
1134+
->GetCommandQueue()
1135+
->Submit({cmd_buffer},
1136+
[latch](CommandBuffer::Status status) { latch->CountDown(); })
1137+
.IgnoreError();
11341138
latch->Wait();
11351139
}
11361140

‎engine/src/flutter/impeller/display_list/canvas.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ void Canvas::DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
22572257
Scalar max_scale = GetCurrentTransform().GetMaxBasisLengthXY();
22582258
if (max_scale * text_frame->GetRuns()[0].GetFont().GetMetrics().point_size >
22592259
kMaxTextScale) {
2260-
fml::StatusOr<flutter::DlPath> path = text_frame->GetPath();
2260+
absl::StatusOr<flutter::DlPath> path = text_frame->GetPath();
22612261
if (path.ok()) {
22622262
Save(1);
22632263
Concat(Matrix::MakeTranslation(position));

0 commit comments

Comments
 (0)