• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_SHELL_IO_MANAGER_H_
6 #define FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_
7 
8 #include <memory>
9 
10 #include "flutter/flow/skia_gpu_object.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/fml/memory/weak_ptr.h"
13 #include "flutter/lib/ui/io_manager.h"
14 #include "third_party/skia/include/gpu/GrContext.h"
15 
16 namespace flutter {
17 
18 class ShellIOManager final : public IOManager {
19  public:
20   // Convenience methods for platforms to create a GrContext used to supply to
21   // the IOManager. The platforms may create the context themselves if they so
22   // desire.
23   static sk_sp<GrContext> CreateCompatibleResourceLoadingContext(
24       GrBackend backend,
25       sk_sp<const GrGLInterface> gl_interface);
26 
27   ShellIOManager(sk_sp<GrContext> resource_context,
28                  fml::RefPtr<fml::TaskRunner> unref_queue_task_runner);
29 
30   ~ShellIOManager() override;
31 
32   // This method should be called when a resource_context first becomes
33   // available. It is safe to call multiple times, and will only update
34   // the held resource context if it has not already been set.
35   void NotifyResourceContextAvailable(sk_sp<GrContext> resource_context);
36 
37   // This method should be called if you want to force the IOManager to
38   // update its resource context reference. It should not be called
39   // if there are any Dart objects that have a reference to the old
40   // resource context, but may be called if the Dart VM is restarted.
41   void UpdateResourceContext(sk_sp<GrContext> resource_context);
42 
43   fml::WeakPtr<ShellIOManager> GetWeakPtr();
44 
45   // |IOManager|
46   fml::WeakPtr<IOManager> GetWeakIOManager() const override;
47 
48   // |IOManager|
49   fml::WeakPtr<GrContext> GetResourceContext() const override;
50 
51   // |IOManager|
52   fml::RefPtr<flutter::SkiaUnrefQueue> GetSkiaUnrefQueue() const override;
53 
54  private:
55   // Resource context management.
56   sk_sp<GrContext> resource_context_;
57   std::unique_ptr<fml::WeakPtrFactory<GrContext>>
58       resource_context_weak_factory_;
59 
60   // Unref queue management.
61   fml::RefPtr<flutter::SkiaUnrefQueue> unref_queue_;
62 
63   fml::WeakPtrFactory<ShellIOManager> weak_factory_;
64 
65   FML_DISALLOW_COPY_AND_ASSIGN(ShellIOManager);
66 };
67 
68 }  // namespace flutter
69 
70 #endif  // FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_
71