Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7#include <utility>
8
11#include "third_party/skia/include/gpu/ganesh/gl/GrGLDirectContext.h"
12#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
13#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
14
15namespace flutter {
16
18 GrBackendApi backend,
19 const sk_sp<const GrGLInterface>& gl_interface) {
20#if SK_GL
21 if (backend != GrBackendApi::kOpenGL) {
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::ImpellerContextFuture> impeller_context,
43 bool impeller_enabled,
44 fml::TimeDelta unref_queue_drain_delay)
45 : resource_context_(std::move(resource_context)),
46 resource_context_weak_factory_(
47 resource_context_
48 ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
49 resource_context_.get())
50 : nullptr),
51 unref_queue_(fml::MakeRefCounted<flutter::SkiaUnrefQueue>(
52 std::move(unref_queue_task_runner),
53 unref_queue_drain_delay,
54 resource_context_,
55 /*drain_immediate=*/impeller_enabled)),
56 is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)),
57 impeller_context_(std::move(impeller_context)),
58 weak_factory_(this) {
59 if (!resource_context_ && !impeller_enabled) {
60#ifndef OS_FUCHSIA
61 FML_DLOG(WARNING) << "The IO manager was initialized without a resource "
62 "context. Async texture uploads will be disabled. "
63 "Expect performance degradation.";
64#endif // OS_FUCHSIA
65 }
66}
67
69 // Last chance to drain the IO queue as the platform side reference to the
70 // underlying OpenGL context may be going away.
71 is_gpu_disabled_sync_switch_->Execute(
72 fml::SyncSwitch::Handlers().SetIfFalse([&] { unref_queue_->Drain(); }));
73}
74
76 sk_sp<GrDirectContext> resource_context) {
77 // The resource context needs to survive as long as we have Dart objects
78 // referencing. We shouldn't ever need to replace it if we have one - unless
79 // we've somehow shut down the Dart VM and started a new one fresh.
80 if (!resource_context_) {
81 UpdateResourceContext(std::move(resource_context));
82 }
83}
84
86 sk_sp<GrDirectContext> resource_context) {
87 resource_context_ = std::move(resource_context);
88 resource_context_weak_factory_ =
89 resource_context_
90 ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
91 resource_context_.get())
92 : nullptr;
93 unref_queue_->UpdateResourceContext(resource_context_);
94}
95
97 return weak_factory_.GetWeakPtr();
98}
99
100// |IOManager|
102 return resource_context_weak_factory_
103 ? resource_context_weak_factory_->GetWeakPtr()
105}
106
107// |IOManager|
111
112// |IOManager|
114 return weak_factory_.GetWeakPtr();
115}
116
117// |IOManager|
118std::shared_ptr<const fml::SyncSwitch>
120 return is_gpu_disabled_sync_switch_;
121}
122
123// |IOManager|
124std::shared_ptr<impeller::Context> ShellIOManager::GetImpellerContext() const {
125 return impeller_context_->GetContext();
126}
127
128} // namespace flutter
fml::WeakPtr< ShellIOManager > GetWeakPtr()
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)
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::ImpellerContextFuture > impeller_context, bool impeller_enabled, fml::TimeDelta unref_queue_drain_delay=fml::TimeDelta::FromMilliseconds(8))
std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() override
void NotifyResourceContextAvailable(sk_sp< GrDirectContext > resource_context)
std::shared_ptr< impeller::Context > GetImpellerContext() const override
Retrieve the impeller::Context.
fml::WeakPtr< IOManager > GetWeakIOManager() const override
fml::WeakPtr< GrDirectContext > GetResourceContext() const override
#define FML_DLOG(severity)
Definition logging.h:121
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
Definition ref_ptr.h:261
Represents the 2 code paths available when calling |SyncSwitchExecute|.
Definition sync_switch.h:35