Flutter iOS Embedder
FlutterFMLTaskRunnerTestHelper.mm
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 <pthread/qos.h>
8 
9 #include "flutter/fml/message_loop.h"
10 #include "flutter/fml/thread.h"
12 
13 // Set the thread to user-interactive QoS to match the real value used in
14 // the actual embedder.
15 static void ConfigureThread(const fml::Thread::ThreadConfig& config) {
16  fml::Thread::SetCurrentThreadName(config);
17  pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0);
18 }
19 
20 // A FlutterFMLTaskRunner that owns the fml::Thread it runs on.
22 @end
23 
24 @implementation FlutterFMLThreadTaskRunner {
25  std::unique_ptr<fml::Thread> _thread;
26 }
27 
28 - (instancetype)initWithLabel:(NSString*)label {
29  _thread = std::make_unique<fml::Thread>(ConfigureThread,
30  fml::Thread::ThreadConfig(label ? label.UTF8String : ""));
31  self = [super initWithTaskRunner:_thread->GetTaskRunner()];
32  return self;
33 }
34 
35 @end
36 
37 @implementation FlutterFMLTaskRunnerTestHelper
38 
40  fml::MessageLoop::EnsureInitializedForCurrentThread();
41  return [[FlutterFMLTaskRunner alloc]
42  initWithTaskRunner:fml::MessageLoop::GetCurrent().GetTaskRunner()];
43 }
44 
45 + (FlutterFMLTaskRunner*)makeTaskRunnerWithLabel:(NSString*)label {
46  return [[FlutterFMLThreadTaskRunner alloc] initWithLabel:label];
47 }
48 
49 + (FlutterFMLTaskRunners*)makeTaskRunnersWithLabel:(NSString*)label
51  return [[FlutterFMLTaskRunners alloc] initWithLabel:label
52  platformTaskRunner:taskRunner
53  rasterTaskRunner:taskRunner
54  uiTaskRunner:taskRunner
55  ioTaskRunner:taskRunner];
56 }
57 
58 @end
static void ConfigureThread(const fml::Thread::ThreadConfig &config)
fml::RefPtr< fml::TaskRunner > taskRunner()
instancetype initWithTaskRunner:(fml::RefPtr< fml::TaskRunner > task_runner)