mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This patch does the following: - Updates `flutter_tester` to set up an Impeller rendering context and surface if `--enable-impeller` is set to true, using the Vulkan backend with Swiftshader. - Updates `run_tests.py` to run all tests except the smoke test (that one really has no rendering impact whatsoever) with and without `--enable-impeller`. - Updates a few tests to work that were trivial: - A couple tests needed updated goldens for very minor rendering differences. Filed https://github.com/flutter/flutter/issues/135684 to track using Skia gold for this instead. - Disabled SKP screenshotting if Impeller is enabled, and updated the test checking that to verify an error is thrown if an SKP is requested. - The Dart GPU based test now asserts that the gpu context is available if Impeller is enabled, and does not deadlock if run in a single threaded mode. - We were missing some trace events around `Canvas::SaveLayer` for Impeller as compared to Skia. - A couple other tests had strict checks about exception messages that are slightly different between Skia and Impeller. - I've filed bugs for other tests that may require a little more work, and skipped them for now. For FragmentProgram on Vulkan I reused an existing bug. This is part of my attempt to address https://github.com/flutter/flutter/issues/135693, although @chinmaygarde and I had slightly different ideas about how to do this. The goals here are: - Run the Dart unit tests we already have with Impeller enabled. - Enable running more of the framework tests (including gold tests) with Impeller enabled. - Run all of these tests via public `dart:ui` API rather than mucking around in C++ internals in the engine.
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/lib/gpu/context.h"
|
|
|
|
#include <future>
|
|
|
|
#include "dart_api.h"
|
|
#include "flutter/lib/ui/ui_dart_state.h"
|
|
#include "fml/make_copyable.h"
|
|
#include "tonic/converter/dart_converter.h"
|
|
|
|
namespace flutter {
|
|
|
|
IMPLEMENT_WRAPPERTYPEINFO(gpu, Context);
|
|
|
|
std::shared_ptr<impeller::Context> Context::default_context_;
|
|
|
|
void Context::SetOverrideContext(std::shared_ptr<impeller::Context> context) {
|
|
default_context_ = std::move(context);
|
|
}
|
|
|
|
std::shared_ptr<impeller::Context> Context::GetDefaultContext() {
|
|
return default_context_;
|
|
}
|
|
|
|
Context::Context(std::shared_ptr<impeller::Context> context)
|
|
: context_(std::move(context)) {}
|
|
|
|
Context::~Context() = default;
|
|
|
|
std::shared_ptr<impeller::Context> Context::GetContext() {
|
|
return context_;
|
|
}
|
|
|
|
} // namespace flutter
|
|
|
|
//----------------------------------------------------------------------------
|
|
/// Exports
|
|
///
|
|
|
|
Dart_Handle InternalFlutterGpu_Context_InitializeDefault(Dart_Handle wrapper) {
|
|
auto dart_state = flutter::UIDartState::Current();
|
|
|
|
std::shared_ptr<impeller::Context> impeller_context =
|
|
flutter::Context::GetDefaultContext();
|
|
|
|
if (!impeller_context) {
|
|
if (!dart_state->IsImpellerEnabled()) {
|
|
return tonic::ToDart(
|
|
"Flutter GPU requires the Impeller rendering backend to be enabled.");
|
|
}
|
|
|
|
// Grab the Impeller context from the IO manager.
|
|
std::promise<std::shared_ptr<impeller::Context>> context_promise;
|
|
auto impeller_context_future = context_promise.get_future();
|
|
fml::TaskRunner::RunNowOrPostTask(
|
|
dart_state->GetTaskRunners().GetIOTaskRunner(),
|
|
fml::MakeCopyable([promise = std::move(context_promise),
|
|
io_manager = dart_state->GetIOManager()]() mutable {
|
|
promise.set_value(io_manager ? io_manager->GetImpellerContext()
|
|
: nullptr);
|
|
}));
|
|
impeller_context = impeller_context_future.get();
|
|
}
|
|
|
|
if (!impeller_context) {
|
|
return tonic::ToDart("Unable to retrieve the Impeller context.");
|
|
}
|
|
auto res = fml::MakeRefCounted<flutter::Context>(impeller_context);
|
|
res->AssociateWithDartWrapper(wrapper);
|
|
|
|
return Dart_Null();
|
|
}
|