Flutter Engine
The Flutter Engine
shell_io_manager.cc
Go to the documentation of this file.
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#include "flutter/shell/common/shell_io_manager.h"
6
7#include <utility>
8
9#include "flutter/fml/message_loop.h"
10#include "flutter/shell/common/context_options.h"
14
15namespace flutter {
16
19 const sk_sp<const GrGLInterface>& gl_interface) {
20#if SK_GL
22 return nullptr;
23 }
24
26
27 if (auto context = GrDirectContexts::MakeGL(gl_interface, options)) {
28 // Do not cache textures created by the image decoder. These textures
29 // should be deleted when they are no longer referenced by an SkImage.
30 context->setResourceCacheLimit(0);
31 return context;
32 }
33#endif // SK_GL
34
35 return nullptr;
36}
37
39 sk_sp<GrDirectContext> resource_context,
40 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
41 fml::RefPtr<fml::TaskRunner> unref_queue_task_runner,
42 std::shared_ptr<impeller::Context> impeller_context,
43 fml::TimeDelta unref_queue_drain_delay)
44 : resource_context_(std::move(resource_context)),
45 resource_context_weak_factory_(
46 resource_context_
47 ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
48 resource_context_.get())
49 : nullptr),
51 std::move(unref_queue_task_runner),
52 unref_queue_drain_delay,
53 resource_context_,
54 /*drain_immediate=*/!!impeller_context)),
55 is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)),
56 impeller_context_(std::move(impeller_context)),
57 weak_factory_(this) {
58 if (!resource_context_) {
59#ifndef OS_FUCHSIA
60 FML_DLOG(WARNING) << "The IO manager was initialized without a resource "
61 "context. Async texture uploads will be disabled. "
62 "Expect performance degradation.";
63#endif // OS_FUCHSIA
64 }
65}
66
68 // Last chance to drain the IO queue as the platform side reference to the
69 // underlying OpenGL context may be going away.
70 is_gpu_disabled_sync_switch_->Execute(
71 fml::SyncSwitch::Handlers().SetIfFalse([&] { unref_queue_->Drain(); }));
72}
73
75 sk_sp<GrDirectContext> resource_context) {
76 // The resource context needs to survive as long as we have Dart objects
77 // referencing. We shouldn't ever need to replace it if we have one - unless
78 // we've somehow shut down the Dart VM and started a new one fresh.
79 if (!resource_context_) {
80 UpdateResourceContext(std::move(resource_context));
81 }
82}
83
85 sk_sp<GrDirectContext> resource_context) {
86 resource_context_ = std::move(resource_context);
87 resource_context_weak_factory_ =
88 resource_context_
89 ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
90 resource_context_.get())
91 : nullptr;
92 unref_queue_->UpdateResourceContext(resource_context_);
93}
94
96 return weak_factory_.GetWeakPtr();
97}
98
99// |IOManager|
101 return resource_context_weak_factory_
102 ? resource_context_weak_factory_->GetWeakPtr()
104}
105
106// |IOManager|
108 return unref_queue_;
109}
110
111// |IOManager|
113 return weak_factory_.GetWeakPtr();
114}
115
116// |IOManager|
117std::shared_ptr<const fml::SyncSwitch>
119 return is_gpu_disabled_sync_switch_;
120}
121
122// |IOManager|
123std::shared_ptr<impeller::Context> ShellIOManager::GetImpellerContext() const {
124 return impeller_context_;
125}
126
127} // namespace flutter
const char * options
const char * backend
GrBackendApi
Definition: GrTypes.h:95
fml::WeakPtr< ShellIOManager > GetWeakPtr()
ShellIOManager(sk_sp< GrDirectContext > resource_context, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch, fml::RefPtr< fml::TaskRunner > unref_queue_task_runner, std::shared_ptr< impeller::Context > impeller_context, fml::TimeDelta unref_queue_drain_delay=fml::TimeDelta::FromMilliseconds(8))
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackendApi backend, const sk_sp< const GrGLInterface > &gl_interface)
fml::RefPtr< flutter::SkiaUnrefQueue > GetSkiaUnrefQueue() const override
void UpdateResourceContext(sk_sp< GrDirectContext > resource_context)
std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() override
void NotifyResourceContextAvailable(sk_sp< GrDirectContext > resource_context)
std::shared_ptr< impeller::Context > GetImpellerContext() const override
fml::WeakPtr< IOManager > GetWeakIOManager() const override
fml::WeakPtr< GrDirectContext > GetResourceContext() const override
T * get() const
Definition: SkRefCnt.h:303
#define FML_DLOG(severity)
Definition: logging.h:102
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
Definition: ascii_trie.cc:9
RefPtr< T > MakeRefCounted(Args &&... args)
Definition: ref_ptr.h:248
const myers::Point & get(const myers::Segment &)
Definition: ref_ptr.h:256
Represents the 2 code paths available when calling |SyncSwitch::Execute|.
Definition: sync_switch.h:35