1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SHELL_HOLDER_H_ 6 #define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SHELL_HOLDER_H_ 7 8 #include <memory> 9 10 #include "flutter/fml/macros.h" 11 #include "flutter/fml/platform/android/jni_weak_ref.h" 12 #include "flutter/fml/unique_fd.h" 13 #include "flutter/lib/ui/window/viewport_metrics.h" 14 #include "flutter/shell/common/run_configuration.h" 15 #include "flutter/shell/common/shell.h" 16 #include "flutter/shell/common/thread_host.h" 17 #include "flutter/shell/platform/android/platform_view_android.h" 18 19 namespace flutter { 20 21 class AndroidShellHolder { 22 public: 23 AndroidShellHolder(flutter::Settings settings, 24 fml::jni::JavaObjectWeakGlobalRef java_object, 25 bool is_background_view); 26 27 ~AndroidShellHolder(); 28 29 bool IsValid() const; 30 31 void Launch(RunConfiguration configuration); 32 33 const flutter::Settings& GetSettings() const; 34 35 fml::WeakPtr<PlatformViewAndroid> GetPlatformView(); 36 37 Rasterizer::Screenshot Screenshot(Rasterizer::ScreenshotType type, 38 bool base64_encode); 39 40 void UpdateAssetManager(fml::RefPtr<flutter::AssetManager> asset_manager); 41 42 private: 43 const flutter::Settings settings_; 44 const fml::jni::JavaObjectWeakGlobalRef java_object_; 45 fml::WeakPtr<PlatformViewAndroid> platform_view_; 46 ThreadHost thread_host_; 47 std::unique_ptr<Shell> shell_; 48 bool is_valid_ = false; 49 pthread_key_t thread_destruct_key_; 50 uint64_t next_pointer_flow_id_ = 0; 51 52 static void ThreadDestructCallback(void* value); 53 54 FML_DISALLOW_COPY_AND_ASSIGN(AndroidShellHolder); 55 }; 56 57 } // namespace flutter 58 59 #endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SHELL_HOLDER_H_ 60