Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,17 @@ void PlatformView::SetupResourceContextOnIOThreadPerform(
latch->Signal();
}

void PlatformView::SetAssetBundlePath(const std::string& assets_directory) {
// Since this code is executed as vm root service handler, it doesn't run on
// UI thread. Assets are consumed on UI thread, so this has to be scheduled
// there.
// Don't wait for this task to complete as UI thread can be blocked with
// application suspended at a breakpoint.
blink::Threads::UI()->PostTask([engine = engine_->GetWeakPtr(),
assets_directory] {
if (engine)
engine->SetAssetBundlePath(assets_directory);
});
}

} // namespace shell
2 changes: 1 addition & 1 deletion shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PlatformView : public std::enable_shared_from_this<PlatformView> {
const std::string& main,
const std::string& packages) = 0;

virtual void SetAssetBundlePath(const std::string& assets_directory) = 0;
virtual void SetAssetBundlePath(const std::string& assets_directory);

protected:
explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);
Expand Down
1 change: 0 additions & 1 deletion shell/common/platform_view_service_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ bool PlatformViewServiceProtocol::SetAssetBundlePath(const char* method,
std::stoull((view_id + kViewIdPrefxLength), nullptr, 16);

// Ask the Shell to update asset bundle path in the specified view.
// This will run a task on the UI thread before returning.
Shell& shell = Shell::Shared();
bool view_existed = false;
Dart_Port main_port = ILLEGAL_PORT;
Expand Down
28 changes: 3 additions & 25 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,30 +303,10 @@ void Shell::SetAssetBundlePathInPlatformView(uintptr_t view_id,
bool* view_existed,
int64_t* dart_isolate_id,
std::string* isolate_name) {
fxl::AutoResetWaitableEvent latch;
FXL_DCHECK(view_id != 0);
FXL_DCHECK(asset_directory);
FXL_DCHECK(view_existed);

blink::Threads::UI()->PostTask([this, view_id, asset_directory, view_existed,
dart_isolate_id, isolate_name, &latch]() {
SetAssetBundlePathInPlatformViewUIThread(view_id, asset_directory,
view_existed, dart_isolate_id,
isolate_name, &latch);
});
latch.Wait();
}

void Shell::SetAssetBundlePathInPlatformViewUIThread(
uintptr_t view_id,
const std::string& assets_directory,
bool* view_existed,
int64_t* dart_isolate_id,
std::string* isolate_name,
fxl::AutoResetWaitableEvent* latch) {
FXL_DCHECK(ui_thread_checker_ &&
ui_thread_checker_->IsCreationThreadCurrent());

*view_existed = false;

IteratePlatformViews(
Expand All @@ -336,9 +316,9 @@ void Shell::SetAssetBundlePathInPlatformViewUIThread(
// not supported on Windows for some reason.
// TODO(https://github.com/flutter/flutter/issues/13908):
// Investigate the root cause of the difference.
assets_directory = std::move(assets_directory), // argument
asset_directory = std::move(asset_directory), // argument
#else
assets_directory, // argument
asset_directory, // argument
#endif
&view_existed, // out
&dart_isolate_id, // out
Expand All @@ -349,15 +329,13 @@ void Shell::SetAssetBundlePathInPlatformViewUIThread(
return true;
}
*view_existed = true;
view->SetAssetBundlePath(assets_directory);
view->SetAssetBundlePath(asset_directory);
*dart_isolate_id = view->engine().GetUIIsolateMainPort();
*isolate_name = view->engine().GetUIIsolateName();
// We found the requested view. Stop iterating over
// platform views.
return false;
});

latch->Signal();
}

} // namespace shell
8 changes: 0 additions & 8 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ class Shell {
std::string* isolate_name,
fxl::AutoResetWaitableEvent* latch);

void SetAssetBundlePathInPlatformViewUIThread(
uintptr_t view_id,
const std::string& main,
bool* view_existed,
int64_t* dart_isolate_id,
std::string* isolate_name,
fxl::AutoResetWaitableEvent* latch);

FXL_DISALLOW_COPY_AND_ASSIGN(Shell);
};

Expand Down
6 changes: 3 additions & 3 deletions shell/platform/android/io/flutter/view/FlutterNativeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void runFromSource(final String assetsDirectory, final String main, final
nativeRunBundleAndSource(mNativePlatformView, assetsDirectory, main, packages);
}

public void setAssetBundlePathOnUI(final String assetsDirectory) {
public void setAssetBundlePath(final String assetsDirectory) {
assertAttached();
nativeSetAssetBundlePathOnUI(mNativePlatformView, assetsDirectory);
nativeSetAssetBundlePath(mNativePlatformView, assetsDirectory);
}

public static String getObservatoryUri() {
Expand Down Expand Up @@ -205,7 +205,7 @@ private static native void nativeRunBundleAndSource(long nativePlatformViewAndro
String main,
String packages);

private static native void nativeSetAssetBundlePathOnUI(long nativePlatformViewAndroid,
private static native void nativeSetAssetBundlePath(long nativePlatformViewAndroid,
String bundlePath);

private static native String nativeGetObservatoryUri();
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ private void setAssetBundlePath(final String assetsDirectory) {
Runnable runnable = new Runnable() {
public void run() {
assertAttached();
mNativeView.setAssetBundlePathOnUI(assetsDirectory);
mNativeView.setAssetBundlePath(assetsDirectory);
synchronized (this) {
notify();
}
Expand Down
42 changes: 0 additions & 42 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,6 @@ void PlatformViewAndroid::RunBundleAndSource(std::string bundle_path,
});
}

void PlatformViewAndroid::SetAssetBundlePathOnUI(std::string bundle_path) {
blink::Threads::UI()->PostTask(
[ engine = engine_->GetWeakPtr(), bundle_path = std::move(bundle_path) ] {
if (engine)
engine->SetAssetBundlePath(std::move(bundle_path));
});
}

void PlatformViewAndroid::SetViewportMetrics(jfloat device_pixel_ratio,
jint physical_width,
jint physical_height,
Expand Down Expand Up @@ -599,40 +591,6 @@ void PlatformViewAndroid::RunFromSource(const std::string& assets_directory,
fml::jni::DetachFromVM();
}

void PlatformViewAndroid::SetAssetBundlePath(
const std::string& assets_directory) {
JNIEnv* env = fml::jni::AttachCurrentThread();
FXL_CHECK(env);

{
fml::jni::ScopedJavaLocalRef<jobject> local_flutter_view =
flutter_view_.get(env);
if (local_flutter_view.is_null()) {
// Collected.
return;
}

// Grab the class of the flutter view.
jclass flutter_view_class = env->GetObjectClass(local_flutter_view.obj());
FXL_CHECK(flutter_view_class);

// Grab the setAssetBundlePath method id.
jmethodID method_id = env->GetMethodID(
flutter_view_class, "setAssetBundlePathOnUI", "(Ljava/lang/String;)V");
FXL_CHECK(method_id);

// Invoke setAssetBundlePath on the Android UI thread.
jstring java_assets_directory = env->NewStringUTF(assets_directory.c_str());
FXL_CHECK(java_assets_directory);

env->CallVoidMethod(local_flutter_view.obj(), method_id,
java_assets_directory);
}

// Detaching from the VM deletes any stray local references.
fml::jni::DetachFromVM();
}

void PlatformViewAndroid::RegisterExternalTexture(
int64_t texture_id,
const fml::jni::JavaObjectWeakGlobalRef& surface_texture) {
Expand Down
4 changes: 0 additions & 4 deletions shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ class PlatformViewAndroid : public PlatformView {
const std::string& main,
const std::string& packages) override;

void SetAssetBundlePathOnUI(std::string bundle_path);

void SetAssetBundlePath(const std::string& assets_directory) override;

void RegisterExternalTexture(
int64_t texture_id,
const fml::jni::JavaObjectWeakGlobalRef& surface_texture);
Expand Down
14 changes: 7 additions & 7 deletions shell/platform/android/platform_view_android_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ void RunBundleAndSource(JNIEnv* env,
fml::jni::JavaStringToString(env, packages));
}

void SetAssetBundlePathOnUI(JNIEnv* env,
jobject jcaller,
jlong platform_view,
jstring bundlePath) {
return PLATFORM_VIEW->SetAssetBundlePathOnUI(
void SetAssetBundlePath(JNIEnv* env,
jobject jcaller,
jlong platform_view,
jstring bundlePath) {
return PLATFORM_VIEW->SetAssetBundlePath(
fml::jni::JavaStringToString(env, bundlePath));
}

Expand Down Expand Up @@ -364,9 +364,9 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.fnPtr = reinterpret_cast<void*>(&shell::RunBundleAndSource),
},
{
.name = "nativeSetAssetBundlePathOnUI",
.name = "nativeSetAssetBundlePath",
.signature = "(JLjava/lang/String;)V",
.fnPtr = reinterpret_cast<void*>(&shell::SetAssetBundlePathOnUI),
.fnPtr = reinterpret_cast<void*>(&shell::SetAssetBundlePath),
},
{
.name = "nativeDetach",
Expand Down
4 changes: 0 additions & 4 deletions shell/platform/darwin/desktop/platform_view_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class PlatformViewMac : public PlatformView, public GPUSurfaceGLDelegate {
const std::string& main,
const std::string& packages) override;

void SetAssetBundlePath(const std::string& assets_directory) override;

private:
fml::scoped_nsobject<NSOpenGLView> opengl_view_;
fml::scoped_nsobject<NSOpenGLContext> resource_loading_context_;
Expand All @@ -53,8 +51,6 @@ class PlatformViewMac : public PlatformView, public GPUSurfaceGLDelegate {
const std::string& main,
const std::string& packages);

void SetAssetBundlePathOnUI(const std::string& assets_directory);

FXL_DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
};

Expand Down
19 changes: 0 additions & 19 deletions shell/platform/darwin/desktop/platform_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@
});
}

void PlatformViewMac::SetAssetBundlePathOnUI(const std::string& assets_directory) {
blink::Threads::UI()->PostTask([ engine = engine().GetWeakPtr(), assets_directory ] {
if (engine)
engine->SetAssetBundlePath(assets_directory);
});
}

intptr_t PlatformViewMac::GLContextFBO() const {
// Default window bound framebuffer FBO 0.
return 0;
Expand Down Expand Up @@ -160,16 +153,4 @@
delete latch;
}

void PlatformViewMac::SetAssetBundlePath(const std::string& assets_directory) {
auto latch = new fxl::ManualResetWaitableEvent();

dispatch_async(dispatch_get_main_queue(), ^{
SetAssetBundlePathOnUI(assets_directory);
latch->Signal();
});

latch->Wait();
delete latch;
}

} // namespace shell
4 changes: 0 additions & 4 deletions shell/platform/darwin/ios/platform_view_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class PlatformViewIOS : public PlatformView {
const std::string& main,
const std::string& packages) override;

void SetAssetBundlePath(const std::string& assets_directory) override;

/**
* Exposes the `FlutterTextInputPlugin` singleton for the
* `AccessibilityBridge` to be able to interact with the text entry system.
Expand Down Expand Up @@ -96,8 +94,6 @@ class PlatformViewIOS : public PlatformView {
const std::string& main,
const std::string& packages);

void SetAssetBundlePathOnUI(const std::string& assets_directory);

FXL_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
};

Expand Down
19 changes: 0 additions & 19 deletions shell/platform/darwin/ios/platform_view_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@
});
}

void PlatformViewIOS::SetAssetBundlePathOnUI(const std::string& assets_directory) {
blink::Threads::UI()->PostTask([ engine = engine().GetWeakPtr(), assets_directory ] {
if (engine)
engine->SetAssetBundlePath(assets_directory);
});
}

fml::WeakPtr<PlatformViewIOS> PlatformViewIOS::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
Expand Down Expand Up @@ -127,16 +120,4 @@
delete latch;
}

void PlatformViewIOS::SetAssetBundlePath(const std::string& assets_directory) {
auto latch = new fxl::ManualResetWaitableEvent();

dispatch_async(dispatch_get_main_queue(), ^{
SetAssetBundlePathOnUI(assets_directory);
latch->Signal();
});

latch->Wait();
delete latch;
}

} // namespace shell