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/GrDirectContext.h"
15
16namespace flutter {
17
18class ShellIOManager final : public IOManager {
19 public:
20 // Convenience methods for platforms to create a GrDirectContext used to
21 // supply to the IOManager. The platforms may create the context themselves if
22 // they so desire.
23 static sk_sp<GrDirectContext> CreateCompatibleResourceLoadingContext(
24 GrBackend backend,
25 const sk_sp<const GrGLInterface>& gl_interface);
26
27 ShellIOManager(
28 sk_sp<GrDirectContext> resource_context,
29 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
30 fml::RefPtr<fml::TaskRunner> unref_queue_task_runner,
31 std::shared_ptr<impeller::Context> impeller_context,
32 fml::TimeDelta unref_queue_drain_delay =
33 fml::TimeDelta::FromMilliseconds(millis: 8));
34
35 ~ShellIOManager() override;
36
37 // This method should be called when a resource_context first becomes
38 // available. It is safe to call multiple times, and will only update
39 // the held resource context if it has not already been set.
40 void NotifyResourceContextAvailable(sk_sp<GrDirectContext> resource_context);
41
42 // This method should be called if you want to force the IOManager to
43 // update its resource context reference. It should not be called
44 // if there are any Dart objects that have a reference to the old
45 // resource context, but may be called if the Dart VM is restarted.
46 void UpdateResourceContext(sk_sp<GrDirectContext> resource_context);
47
48 fml::WeakPtr<ShellIOManager> GetWeakPtr();
49
50 // |IOManager|
51 fml::WeakPtr<IOManager> GetWeakIOManager() const override;
52
53 // |IOManager|
54 fml::WeakPtr<GrDirectContext> GetResourceContext() const override;
55
56 // |IOManager|
57 fml::RefPtr<flutter::SkiaUnrefQueue> GetSkiaUnrefQueue() const override;
58
59 // |IOManager|
60 std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() override;
61
62 // |IOManager|
63 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
64
65 private:
66 // Resource context management.
67 sk_sp<GrDirectContext> resource_context_;
68 std::unique_ptr<fml::WeakPtrFactory<GrDirectContext>>
69 resource_context_weak_factory_;
70 // Unref queue management.
71 fml::RefPtr<flutter::SkiaUnrefQueue> unref_queue_;
72 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
73 std::shared_ptr<impeller::Context> impeller_context_;
74 fml::WeakPtrFactory<ShellIOManager> weak_factory_;
75
76 FML_DISALLOW_COPY_AND_ASSIGN(ShellIOManager);
77};
78
79} // namespace flutter
80
81#endif // FLUTTER_SHELL_COMMON_SHELL_IO_MANAGER_H_
82

source code of flutter_engine/flutter/shell/common/shell_io_manager.h