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_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_ |
6 | #define FLUTTER_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_ |
7 | |
8 | #include "flutter/fml/closure.h" |
9 | #include "flutter/fml/macros.h" |
10 | #include "third_party/skia/include/core/SkExecutor.h" |
11 | |
12 | namespace flutter { |
13 | |
14 | //------------------------------------------------------------------------------ |
15 | /// @brief An interface used by Skia to schedule work on engine managed |
16 | /// threads (usually workers in a concurrent message loop). |
17 | /// |
18 | /// Skia may decide that certain workloads don't have thread |
19 | /// affinity and may be performed on a background thread. However, |
20 | /// Skia does not manage its own threads. So, it delegates the |
21 | /// scheduling of this work to the engine via this interface. The |
22 | /// engine has a dedicated pool of threads it uses for scheduling |
23 | /// background tasks that have no thread affinity. This thread |
24 | /// worker pool is held next to the process global Dart VM instance. |
25 | /// The Skia executor is wired up there as well. |
26 | /// |
27 | class SkiaConcurrentExecutor : public SkExecutor { |
28 | public: |
29 | //---------------------------------------------------------------------------- |
30 | /// The callback invoked by the executor to schedule the given task onto an |
31 | /// engine managed background thread. |
32 | /// |
33 | using OnWorkCallback = std::function<void(fml::closure work)>; |
34 | |
35 | //---------------------------------------------------------------------------- |
36 | /// @brief Create a new instance of the executor. |
37 | /// |
38 | /// @param[in] on_work The work callback. |
39 | /// |
40 | SkiaConcurrentExecutor(const OnWorkCallback& on_work); |
41 | |
42 | // |SkExecutor| |
43 | ~SkiaConcurrentExecutor() override; |
44 | |
45 | // |SkExecutor| |
46 | void add(fml::closure work) override; |
47 | |
48 | private: |
49 | OnWorkCallback on_work_; |
50 | |
51 | FML_DISALLOW_COPY_AND_ASSIGN(SkiaConcurrentExecutor); |
52 | }; |
53 | |
54 | } // namespace flutter |
55 | |
56 | #endif // FLUTTER_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_ |
57 | |