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

Commit 0638046

Browse files
committed
WeakPersistentHandle migration
1 parent 1f183ba commit 0638046

File tree

15 files changed

+195
-43
lines changed

15 files changed

+195
-43
lines changed

DEPS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vars = {
3434
# Dart is: https://github.com/dart-lang/sdk/blob/master/DEPS.
3535
# You can use //tools/dart/create_updated_flutter_deps.py to produce
3636
# updated revision list of existing dependencies.
37-
'dart_revision': 'ddbeaabe8b3dc6299d9c963d414f820198edf8cd',
37+
'dart_revision': 'ffdebe55c9c112d60bd794aabe102f90c305970f',
3838

3939
# WARNING: DO NOT EDIT MANUALLY
4040
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py
@@ -46,7 +46,7 @@ vars = {
4646
'dart_http_retry_tag': '0.1.1',
4747
'dart_http_throttle_tag': '1.0.2',
4848
'dart_intl_tag': '0.16.1',
49-
'dart_linter_tag': '0.1.119',
49+
'dart_linter_tag': '0.1.120',
5050
'dart_oauth2_tag': '1.6.0',
5151
'dart_protobuf_rev': '3746c8fd3f2b0147623a8e3db89c3ff4330de760',
5252
'dart_pub_rev': '04e237f78b2302d7f20d0b362554425e8deb8add',
@@ -155,7 +155,7 @@ deps = {
155155
'https://boringssl.googlesource.com/boringssl.git' + '@' + Var('dart_boringssl_rev'),
156156

157157
'src/third_party/dart':
158-
Var('dart_git') + '/sdk.git' + '@' + Var('dart_revision'),
158+
'https://github.com/dart-lang/sdk.git' + '@' + Var('dart_revision'),
159159

160160
# WARNING: Unused Dart dependencies in the list below till "WARNING:" marker are removed automatically - see create_updated_flutter_deps.py.
161161

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,8 @@ FILE: ../../../flutter/third_party/tonic/dart_persistent_value.cc
14321432
FILE: ../../../flutter/third_party/tonic/dart_persistent_value.h
14331433
FILE: ../../../flutter/third_party/tonic/dart_state.cc
14341434
FILE: ../../../flutter/third_party/tonic/dart_state.h
1435+
FILE: ../../../flutter/third_party/tonic/dart_weak_persistent_value.cc
1436+
FILE: ../../../flutter/third_party/tonic/dart_weak_persistent_value.h
14351437
FILE: ../../../flutter/third_party/tonic/dart_wrappable.cc
14361438
FILE: ../../../flutter/third_party/tonic/dart_wrappable.h
14371439
FILE: ../../../flutter/third_party/tonic/dart_wrapper_info.h

lib/ui/painting/image_decoder.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ void ImageDecoder::Decode(fml::RefPtr<ImageDescriptor> descriptor,
223223
FML_DCHECK(callback);
224224
FML_DCHECK(runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
225225

226-
// Always service the callback on the UI thread.
227-
auto result = [callback, ui_runner = runners_.GetUITaskRunner()](
226+
// Always service the callback (and cleanup the descriptor) on the UI thread.
227+
auto result = [callback, descriptor, ui_runner = runners_.GetUITaskRunner()](
228228
SkiaGPUObject<SkImage> image,
229229
fml::tracing::TraceFlow flow) {
230-
ui_runner->PostTask(fml::MakeCopyable(
231-
[callback, image = std::move(image), flow = std::move(flow)]() mutable {
230+
ui_runner->PostTask(
231+
fml::MakeCopyable([callback, descriptor, image = std::move(image),
232+
flow = std::move(flow)]() mutable {
232233
// We are going to terminate the trace flow here. Flows cannot
233234
// terminate without a base trace. Add one explicitly.
234235
TRACE_EVENT0("flutter", "ImageDecodeCallback");

lib/ui/painting/image_encoding.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ enum ImageByteFormat {
3535
kPNG,
3636
};
3737

38-
void FinalizeSkData(void* isolate_callback_data,
39-
Dart_WeakPersistentHandle handle,
40-
void* peer) {
38+
void FinalizeSkData(void* isolate_callback_data, void* peer) {
4139
SkData* buffer = reinterpret_cast<SkData*>(peer);
4240
buffer->unref();
4341
}

runtime/dart_isolate.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,11 @@ void DartIsolate::AddIsolateShutdownCallback(const fml::closure& closure) {
875875
}
876876

877877
void DartIsolate::OnShutdownCallback() {
878+
tonic::DartState* state = tonic::DartState::Current();
879+
if (state != nullptr) {
880+
state->SetIsShuttingDown();
881+
}
882+
878883
{
879884
tonic::DartApiScope api_scope;
880885
Dart_Handle sticky_error = Dart_GetStickyError();

shell/platform/embedder/embedder.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,8 +1910,7 @@ FlutterEngineResult FlutterEnginePostDartObject(
19101910
dart_object.value.as_external_typed_data.data = buffer;
19111911
dart_object.value.as_external_typed_data.peer = peer;
19121912
dart_object.value.as_external_typed_data.callback =
1913-
+[](void* unused_isolate_callback_data,
1914-
Dart_WeakPersistentHandle unused_handle, void* peer) {
1913+
+[](void* unused_isolate_callback_data, void* peer) {
19151914
auto typed_peer = reinterpret_cast<ExternalTypedDataPeer*>(peer);
19161915
typed_peer->trampoline(typed_peer->user_data);
19171916
delete typed_peer;

shell/platform/fuchsia/dart_runner/dart_runner.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ void IsolateShutdownCallback(void* isolate_group_data, void* isolate_data) {
9191
tonic::DartMicrotaskQueue::GetForCurrentThread()->Destroy();
9292
async_loop_quit(loop);
9393
}
94+
95+
auto state =
96+
static_cast<std::shared_ptr<tonic::DartState>*>(isolate_group_data);
97+
state->get()->SetIsShuttingDown();
9498
}
9599

96100
void IsolateGroupCleanupCallback(void* isolate_group_data) {

third_party/tonic/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ source_set("tonic") {
2929
"dart_persistent_value.h",
3030
"dart_state.cc",
3131
"dart_state.h",
32+
"dart_weak_persistent_value.cc",
33+
"dart_weak_persistent_value.h",
3234
"dart_wrappable.cc",
3335
"dart_wrappable.h",
3436
"dart_wrapper_info.h",

third_party/tonic/dart_state.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ DartState::DartState(int dirfd,
2727
message_handler_(new DartMessageHandler()),
2828
file_loader_(new FileLoader(dirfd)),
2929
message_epilogue_(message_epilogue),
30-
has_set_return_code_(false) {}
30+
has_set_return_code_(false),
31+
is_shutting_down_(false) {}
3132

3233
DartState::~DartState() {}
3334

third_party/tonic/dart_state.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef LIB_TONIC_DART_STATE_H_
66
#define LIB_TONIC_DART_STATE_H_
77

8+
#include <atomic>
89
#include <functional>
910
#include <memory>
1011

@@ -68,6 +69,9 @@ class DartState : public std::enable_shared_from_this<DartState> {
6869
void SetReturnCodeCallback(std::function<void(uint32_t)> callback);
6970
bool has_set_return_code() const { return has_set_return_code_; }
7071

72+
void SetIsShuttingDown() { is_shutting_down_ = true; }
73+
bool IsShuttingDown() { return is_shutting_down_; }
74+
7175
virtual void DidSetIsolate();
7276

7377
static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
@@ -83,6 +87,7 @@ class DartState : public std::enable_shared_from_this<DartState> {
8387
std::function<void(Dart_Handle)> message_epilogue_;
8488
std::function<void(uint32_t)> set_return_code_callback_;
8589
bool has_set_return_code_;
90+
std::atomic<bool> is_shutting_down_;
8691

8792
protected:
8893
TONIC_DISALLOW_COPY_AND_ASSIGN(DartState);

0 commit comments

Comments
 (0)