// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_ #define FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_ #include #include "flutter/flow/skia_gpu_object.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/lib/ui/io_manager.h" #include "third_party/skia/include/gpu/GrDirectContext.h" namespace flutter { class ShellIOManager final : public IOManager { public: // Convenience methods for platforms to create a GrDirectContext used to // supply to the IOManager. The platforms may create the context themselves if // they so desire. static sk_sp CreateCompatibleResourceLoadingContext( GrBackend backend, sk_sp gl_interface); ShellIOManager(sk_sp resource_context, std::shared_ptr is_gpu_disabled_sync_switch, fml::RefPtr unref_queue_task_runner); ~ShellIOManager() override; // This method should be called when a resource_context first becomes // available. It is safe to call multiple times, and will only update // the held resource context if it has not already been set. void NotifyResourceContextAvailable(sk_sp resource_context); // This method should be called if you want to force the IOManager to // update its resource context reference. It should not be called // if there are any Dart objects that have a reference to the old // resource context, but may be called if the Dart VM is restarted. void UpdateResourceContext(sk_sp resource_context); fml::WeakPtr GetWeakPtr(); // |IOManager| fml::WeakPtr GetWeakIOManager() const override; // |IOManager| fml::WeakPtr GetResourceContext() const override; // |IOManager| fml::RefPtr GetSkiaUnrefQueue() const override; // |IOManager| std::shared_ptr GetIsGpuDisabledSyncSwitch() override; private: // Resource context management. sk_sp resource_context_; std::unique_ptr> resource_context_weak_factory_; // Unref queue management. fml::RefPtr unref_queue_; std::shared_ptr is_gpu_disabled_sync_switch_; fml::WeakPtrFactory weak_factory_; FML_DISALLOW_COPY_AND_ASSIGN(ShellIOManager); }; } // namespace flutter #endif // FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_