|
7 | 7 | #include <memory> |
8 | 8 | #include <sstream> |
9 | 9 |
|
| 10 | +#include "flutter/fml/log_level.h" |
| 11 | +#include "flutter/fml/logging.h" |
| 12 | +#include "flutter/fml/make_copyable.h" |
| 13 | +#include "flutter/fml/memory/ref_ptr.h" |
| 14 | +#include "flutter/lib/ui/ui_dart_state.h" |
| 15 | +#include "third_party/tonic/dart_wrappable.h" |
| 16 | + |
10 | 17 | namespace flutter { |
11 | 18 |
|
12 | 19 | IMPLEMENT_WRAPPERTYPEINFO(ui, GpuContext); |
13 | 20 |
|
14 | | -void GpuContext::InitializeDefault(Dart_Handle wrapper) { |
15 | | - auto res = fml::MakeRefCounted<SceneNode>(); |
| 21 | +std::string GpuContext::InitializeDefault(Dart_Handle wrapper) { |
| 22 | + auto dart_state = UIDartState::Current(); |
| 23 | + if (!dart_state->IsImpellerEnabled()) { |
| 24 | + return "The GpuContext API requires the Impeller rendering backend to be " |
| 25 | + "enabled."; |
| 26 | + } |
| 27 | + |
| 28 | + // Grab the Impeller context from the IO manager. |
| 29 | + |
| 30 | + std::promise<std::shared_ptr<impeller::Context>> context_promise; |
| 31 | + auto impeller_context_future = context_promise.get_future(); |
| 32 | + dart_state->GetTaskRunners().GetIOTaskRunner()->PostTask( |
| 33 | + fml::MakeCopyable([promise = std::move(context_promise), |
| 34 | + io_manager = dart_state->GetIOManager()]() mutable { |
| 35 | + promise.set_value(io_manager ? io_manager->GetImpellerContext() |
| 36 | + : nullptr); |
| 37 | + })); |
| 38 | + |
| 39 | + auto impeller_context = impeller_context_future.get(); |
| 40 | + if (!impeller_context) { |
| 41 | + return "Unable to retrieve the Impeller context."; |
| 42 | + } |
| 43 | + auto res = fml::MakeRefCounted<GpuContext>(impeller_context); |
16 | 44 | res->AssociateWithDartWrapper(wrapper); |
| 45 | + |
| 46 | + return ""; |
17 | 47 | } |
18 | 48 |
|
19 | | -GpuContext::GpuContext() = default; |
| 49 | +GpuContext::GpuContext(std::shared_ptr<impeller::Context> context) |
| 50 | + : context_(std::move(context)) {} |
20 | 51 |
|
21 | 52 | GpuContext::~GpuContext() = default; |
22 | 53 |
|
|
0 commit comments