Flutter Engine
flutter::ShellIOManager Class Referencefinal

#include <shell_io_manager.h>

Inheritance diagram for flutter::ShellIOManager:
flutter::IOManager

Public Member Functions

 ShellIOManager (sk_sp< GrDirectContext > resource_context, std::shared_ptr< fml::SyncSwitch > is_gpu_disabled_sync_switch, fml::RefPtr< fml::TaskRunner > unref_queue_task_runner)
 
 ~ShellIOManager () override
 
void NotifyResourceContextAvailable (sk_sp< GrDirectContext > resource_context)
 
void UpdateResourceContext (sk_sp< GrDirectContext > resource_context)
 
fml::WeakPtr< ShellIOManagerGetWeakPtr ()
 
fml::WeakPtr< IOManagerGetWeakIOManager () const override
 
fml::WeakPtr< GrDirectContext > GetResourceContext () const override
 
fml::RefPtr< flutter::SkiaUnrefQueueGetSkiaUnrefQueue () const override
 
std::shared_ptr< fml::SyncSwitchGetIsGpuDisabledSyncSwitch () override
 
- Public Member Functions inherited from flutter::IOManager
virtual ~IOManager ()=default
 

Static Public Member Functions

static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext (GrBackend backend, sk_sp< const GrGLInterface > gl_interface)
 

Detailed Description

Definition at line 18 of file shell_io_manager.h.

Constructor & Destructor Documentation

◆ ShellIOManager()

flutter::ShellIOManager::ShellIOManager ( sk_sp< GrDirectContext >  resource_context,
std::shared_ptr< fml::SyncSwitch is_gpu_disabled_sync_switch,
fml::RefPtr< fml::TaskRunner unref_queue_task_runner 
)

Definition at line 54 of file shell_io_manager.cc.

References FML_DLOG.

58  : resource_context_(std::move(resource_context)),
59  resource_context_weak_factory_(
60  resource_context_
61  ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
62  resource_context_.get())
63  : nullptr),
64  unref_queue_(fml::MakeRefCounted<flutter::SkiaUnrefQueue>(
65  std::move(unref_queue_task_runner),
68  is_gpu_disabled_sync_switch_(is_gpu_disabled_sync_switch),
69  weak_factory_(this) {
70  if (!resource_context_) {
71 #ifndef OS_FUCHSIA
72  FML_DLOG(WARNING) << "The IO manager was initialized without a resource "
73  "context. Async texture uploads will be disabled. "
74  "Expect performance degradation.";
75 #endif // OS_FUCHSIA
76  }
77 }
fml::WeakPtr< GrDirectContext > GetResourceContext() const override
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46
#define FML_DLOG(severity)
Definition: logging.h:85

◆ ~ShellIOManager()

flutter::ShellIOManager::~ShellIOManager ( )
override

Definition at line 79 of file shell_io_manager.cc.

References flutter::SkiaUnrefQueue::Drain().

79  {
80  // Last chance to drain the IO queue as the platform side reference to the
81  // underlying OpenGL context may be going away.
82  is_gpu_disabled_sync_switch_->Execute(
83  fml::SyncSwitch::Handlers().SetIfFalse([&] { unref_queue_->Drain(); }));
84 }
Represents the 2 code paths available when calling |SyncSwitch::Execute|.
Definition: sync_switch.h:24

Member Function Documentation

◆ CreateCompatibleResourceLoadingContext()

sk_sp< GrDirectContext > flutter::ShellIOManager::CreateCompatibleResourceLoadingContext ( GrBackend  backend,
sk_sp< const GrGLInterface >  gl_interface 
)
static

Definition at line 14 of file shell_io_manager.cc.

References flutter::PersistentCache::cache_sksl(), FML_LOG, flutter::PersistentCache::GetCacheForProcess(), and flutter::PersistentCache::MarkStrategySet().

Referenced by flutter::IOSContextGL::CreateRenderTarget(), flutter::EmbedderSurfaceGL::EmbedderSurfaceGL(), and flutter::PlatformViewAndroid::RegisterExternalTexture().

16  {
17  if (backend != GrBackend::kOpenGL_GrBackend) {
18  return nullptr;
19  }
20 
21  GrContextOptions options = {};
22 
24  FML_LOG(INFO) << "Cache SkSL";
25  options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
26  }
28 
29  options.fPersistentCache = PersistentCache::GetCacheForProcess();
30 
31  // There is currently a bug with doing GPU YUV to RGB conversions on the IO
32  // thread. The necessary work isn't being flushed or synchronized with the
33  // other threads correctly, so the textures end up blank. For now, suppress
34  // that feature, which will cause texture uploads to do CPU YUV conversion.
35  // A similar work-around is also used in shell/gpu/gpu_surface_gl.cc.
36  options.fDisableGpuYUVConversion = true;
37 
38  // To get video playback on the widest range of devices, we limit Skia to
39  // ES2 shading language when the ES3 external image extension is missing.
40  options.fPreferExternalImagesOverES3 = true;
41 
42 #if !OS_FUCHSIA
43  if (auto context = GrDirectContext::MakeGL(gl_interface, options)) {
44  // Do not cache textures created by the image decoder. These textures
45  // should be deleted when they are no longer referenced by an SkImage.
46  context->setResourceCacheLimits(0, 0);
47  return context;
48  }
49 #endif
50 
51  return nullptr;
52 }
#define FML_LOG(severity)
Definition: logging.h:65
static PersistentCache * GetCacheForProcess()

◆ GetIsGpuDisabledSyncSwitch()

std::shared_ptr< fml::SyncSwitch > flutter::ShellIOManager::GetIsGpuDisabledSyncSwitch ( )
overridevirtual

Implements flutter::IOManager.

Definition at line 128 of file shell_io_manager.cc.

128  {
129  return is_gpu_disabled_sync_switch_;
130 }

◆ GetResourceContext()

fml::WeakPtr< GrDirectContext > flutter::ShellIOManager::GetResourceContext ( ) const
overridevirtual

Implements flutter::IOManager.

Definition at line 111 of file shell_io_manager.cc.

111  {
112  return resource_context_weak_factory_
113  ? resource_context_weak_factory_->GetWeakPtr()
115 }

◆ GetSkiaUnrefQueue()

fml::RefPtr< flutter::SkiaUnrefQueue > flutter::ShellIOManager::GetSkiaUnrefQueue ( ) const
overridevirtual

Implements flutter::IOManager.

Definition at line 118 of file shell_io_manager.cc.

118  {
119  return unref_queue_;
120 }

◆ GetWeakIOManager()

fml::WeakPtr< IOManager > flutter::ShellIOManager::GetWeakIOManager ( ) const
overridevirtual

Implements flutter::IOManager.

Definition at line 123 of file shell_io_manager.cc.

123  {
124  return weak_factory_.GetWeakPtr();
125 }

◆ GetWeakPtr()

fml::WeakPtr< ShellIOManager > flutter::ShellIOManager::GetWeakPtr ( )

Definition at line 106 of file shell_io_manager.cc.

106  {
107  return weak_factory_.GetWeakPtr();
108 }

◆ NotifyResourceContextAvailable()

void flutter::ShellIOManager::NotifyResourceContextAvailable ( sk_sp< GrDirectContext >  resource_context)

Definition at line 86 of file shell_io_manager.cc.

References UpdateResourceContext().

87  {
88  // The resource context needs to survive as long as we have Dart objects
89  // referencing. We shouldn't ever need to replace it if we have one - unless
90  // we've somehow shut down the Dart VM and started a new one fresh.
91  if (!resource_context_) {
92  UpdateResourceContext(std::move(resource_context));
93  }
94 }
void UpdateResourceContext(sk_sp< GrDirectContext > resource_context)

◆ UpdateResourceContext()

void flutter::ShellIOManager::UpdateResourceContext ( sk_sp< GrDirectContext >  resource_context)

Definition at line 96 of file shell_io_manager.cc.

Referenced by NotifyResourceContextAvailable().

97  {
98  resource_context_ = std::move(resource_context);
99  resource_context_weak_factory_ =
100  resource_context_
101  ? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
102  resource_context_.get())
103  : nullptr;
104 }

The documentation for this class was generated from the following files: