Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ FILE: ../../../flutter/lib/ui/plugins.dart
FILE: ../../../flutter/lib/ui/plugins/callback_cache.cc
FILE: ../../../flutter/lib/ui/plugins/callback_cache.h
FILE: ../../../flutter/lib/ui/pointer.dart
FILE: ../../../flutter/lib/ui/resource_context_manager.h
FILE: ../../../flutter/lib/ui/semantics.dart
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.cc
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.h
Expand Down
1 change: 1 addition & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ source_set("ui") {
"painting/vertices.h",
"plugins/callback_cache.cc",
"plugins/callback_cache.h",
"resource_context_manager.h",
"semantics/custom_accessibility_action.cc",
"semantics/custom_accessibility_action.h",
"semantics/semantics_node.cc",
Expand Down
35 changes: 35 additions & 0 deletions lib/ui/resource_context_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

#ifndef FLUTTER_LIB_UI_RESOURCE_CONTEXT_MANAGER_H_
#define FLUTTER_LIB_UI_RESOURCE_CONTEXT_MANAGER_H_

#include "flutter/fml/memory/weak_ptr.h"
#include "third_party/skia/include/gpu/GrContext.h"

namespace blink {
// Interface for methods that manage the GrContext creation, access, and
// release. Meant to be implemented by the owner of the GLContext, e.g. the
// PlatformView. These methods may be called from a non-platform task runner.
class ResourceContextManager {
public:
virtual sk_sp<GrContext> CreateResourceContext() = 0;

// In almost all situations, this should be prefered to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "preferred"

// `CreateResourceContext`. This will get the currently applicable GrContext
// on the calling thread for the current GrContext, if one is available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should "GrContext" be changed to "GLContext" here?

// Calling this will ensure that, in the event the GLContext has changed, the
// correct GrContext for the current GLContext will be used. Unlike all other
// methods on the platform view, this one may be called on a non-platform task
// runner.
virtual sk_sp<GrContext> GetOrCreateResourceContext() = 0;

virtual fml::WeakPtr<GrContext> GetOrCreateWeakResourceContext() = 0;

virtual void ReleaseResourceContext() const = 0;
};

} // namespace blink

#endif // FLUTTER_LIB_UI_RESOURCE_CONTEXT_MANAGER_H_
25 changes: 13 additions & 12 deletions lib/ui/ui_dart_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ using tonic::ToDart;

namespace blink {

UIDartState::UIDartState(TaskRunners task_runners,
TaskObserverAdd add_callback,
TaskObserverRemove remove_callback,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::RefPtr<flow::SkiaUnrefQueue> skia_unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
std::string logger_prefix,
IsolateNameServer* isolate_name_server)
UIDartState::UIDartState(
TaskRunners task_runners,
TaskObserverAdd add_callback,
TaskObserverRemove remove_callback,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> skia_unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
std::string logger_prefix,
IsolateNameServer* isolate_name_server)
: task_runners_(std::move(task_runners)),
add_callback_(std::move(add_callback)),
remove_callback_(std::move(remove_callback)),
snapshot_delegate_(std::move(snapshot_delegate)),
resource_context_(std::move(resource_context)),
resource_context_manager_(std::move(resource_context_manager)),
advisory_script_uri_(std::move(advisory_script_uri)),
advisory_script_entrypoint_(std::move(advisory_script_entrypoint)),
logger_prefix_(std::move(logger_prefix)),
Expand Down Expand Up @@ -114,7 +115,7 @@ fml::WeakPtr<SnapshotDelegate> UIDartState::GetSnapshotDelegate() const {
}

fml::WeakPtr<GrContext> UIDartState::GetResourceContext() const {
return resource_context_;
return resource_context_manager_->GetOrCreateWeakResourceContext();
}

IsolateNameServer* UIDartState::GetIsolateNameServer() {
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/ui_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "flutter/fml/build_config.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/lib/ui/isolate_name_server/isolate_name_server.h"
#include "flutter/lib/ui/resource_context_manager.h"
#include "flutter/lib/ui/snapshot_delegate.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/skia/include/gpu/GrContext.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ class UIDartState : public tonic::DartState {
TaskObserverAdd add_callback,
TaskObserverRemove remove_callback,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> skia_unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
Expand All @@ -94,7 +95,7 @@ class UIDartState : public tonic::DartState {
const TaskObserverAdd add_callback_;
const TaskObserverRemove remove_callback_;
fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
fml::WeakPtr<GrContext> resource_context_;
fml::WeakPtr<ResourceContextManager> resource_context_manager_;
const std::string advisory_script_uri_;
const std::string advisory_script_entrypoint_;
const std::string logger_prefix_;
Expand Down
49 changes: 25 additions & 24 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
TaskRunners task_runners,
std::unique_ptr<Window> window,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
Expand All @@ -51,15 +51,15 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
// isolate lifecycle is entirely managed by the VM).
auto root_embedder_data = std::make_unique<std::shared_ptr<DartIsolate>>(
std::make_shared<DartIsolate>(
vm, // VM
std::move(isolate_snapshot), // isolate snapshot
std::move(shared_snapshot), // shared snapshot
task_runners, // task runners
std::move(snapshot_delegate), // snapshot delegate
std::move(resource_context), // resource context
std::move(unref_queue), // skia unref queue
advisory_script_uri, // advisory URI
advisory_script_entrypoint, // advisory entrypoint
vm, // VM
std::move(isolate_snapshot), // isolate snapshot
std::move(shared_snapshot), // shared snapshot
task_runners, // task runners
std::move(snapshot_delegate), // snapshot delegate
std::move(resource_context_manager), // resource context_manager
std::move(unref_queue), // skia unref queue
advisory_script_uri, // advisory URI
advisory_script_entrypoint, // advisory entrypoint
nullptr // child isolate preparer will be set when this isolate is
// prepared to run
));
Expand Down Expand Up @@ -95,21 +95,22 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
return embedder_isolate;
}

DartIsolate::DartIsolate(DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
ChildIsolatePreparer child_isolate_preparer)
DartIsolate::DartIsolate(
DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
ChildIsolatePreparer child_isolate_preparer)
: UIDartState(std::move(task_runners),
vm->GetSettings().task_observer_add,
vm->GetSettings().task_observer_remove,
std::move(snapshot_delegate),
std::move(resource_context),
std::move(resource_context_manager),
std::move(unref_queue),
advisory_script_uri,
advisory_script_entrypoint,
Expand Down Expand Up @@ -645,9 +646,9 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
(*raw_embedder_isolate)->GetSharedSnapshot(), // shared_snapshot
null_task_runners, // task_runners
fml::WeakPtr<SnapshotDelegate>{}, // snapshot_delegate
fml::WeakPtr<GrContext>{}, // resource_context
nullptr, // unref_queue
advisory_script_uri, // advisory_script_uri
fml::WeakPtr<ResourceContextManager>{}, // resource_context_manager
nullptr, // unref_queue
advisory_script_uri, // advisory_script_uri
advisory_script_entrypoint, // advisory_script_entrypoint
(*raw_embedder_isolate)->child_isolate_preparer_));
}
Expand Down
5 changes: 3 additions & 2 deletions runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "flutter/fml/compiler_specific.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/lib/ui/resource_context_manager.h"
#include "flutter/lib/ui/snapshot_delegate.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
Expand Down Expand Up @@ -46,7 +47,7 @@ class DartIsolate : public UIDartState {
TaskRunners task_runners,
std::unique_ptr<Window> window,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
Expand All @@ -57,7 +58,7 @@ class DartIsolate : public UIDartState {
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
Expand Down
12 changes: 6 additions & 6 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RuntimeController::RuntimeController(
fml::RefPtr<DartSnapshot> p_shared_snapshot,
TaskRunners p_task_runners,
fml::WeakPtr<SnapshotDelegate> p_snapshot_delegate,
fml::WeakPtr<GrContext> p_resource_context,
fml::WeakPtr<ResourceContextManager> p_resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> p_unref_queue,
std::string p_advisory_script_uri,
std::string p_advisory_script_entrypoint)
Expand All @@ -31,7 +31,7 @@ RuntimeController::RuntimeController(
std::move(p_shared_snapshot),
std::move(p_task_runners),
std::move(p_snapshot_delegate),
std::move(p_resource_context),
std::move(p_resource_context_manager),
std::move(p_unref_queue),
std::move(p_advisory_script_uri),
std::move(p_advisory_script_entrypoint),
Expand All @@ -44,7 +44,7 @@ RuntimeController::RuntimeController(
fml::RefPtr<DartSnapshot> p_shared_snapshot,
TaskRunners p_task_runners,
fml::WeakPtr<SnapshotDelegate> p_snapshot_delegate,
fml::WeakPtr<GrContext> p_resource_context,
fml::WeakPtr<ResourceContextManager> p_resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> p_unref_queue,
std::string p_advisory_script_uri,
std::string p_advisory_script_entrypoint,
Expand All @@ -55,7 +55,7 @@ RuntimeController::RuntimeController(
shared_snapshot_(std::move(p_shared_snapshot)),
task_runners_(p_task_runners),
snapshot_delegate_(p_snapshot_delegate),
resource_context_(p_resource_context),
resource_context_manager_(p_resource_context_manager),
unref_queue_(p_unref_queue),
advisory_script_uri_(p_advisory_script_uri),
advisory_script_entrypoint_(p_advisory_script_entrypoint),
Expand All @@ -67,7 +67,7 @@ RuntimeController::RuntimeController(
task_runners_,
std::make_unique<Window>(this),
snapshot_delegate_,
resource_context_,
resource_context_manager_,
unref_queue_,
p_advisory_script_uri,
p_advisory_script_entrypoint)) {
Expand Down Expand Up @@ -116,7 +116,7 @@ std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
shared_snapshot_, //
task_runners_, //
snapshot_delegate_, //
resource_context_, //
resource_context_manager_, //
unref_queue_, //
advisory_script_uri_, //
advisory_script_entrypoint_, //
Expand Down
47 changes: 25 additions & 22 deletions runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "flutter/common/task_runners.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/fml/macros.h"
#include "flutter/lib/ui/resource_context_manager.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
Expand All @@ -27,16 +28,17 @@ class Window;

class RuntimeController final : public WindowClient {
public:
RuntimeController(RuntimeDelegate& client,
DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint);
RuntimeController(
RuntimeDelegate& client,
DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint);

~RuntimeController() override;

Expand Down Expand Up @@ -121,25 +123,26 @@ class RuntimeController final : public WindowClient {
fml::RefPtr<DartSnapshot> shared_snapshot_;
TaskRunners task_runners_;
fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
fml::WeakPtr<GrContext> resource_context_;
fml::WeakPtr<ResourceContextManager> resource_context_manager_;
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
std::string advisory_script_uri_;
std::string advisory_script_entrypoint_;
WindowData window_data_;
std::weak_ptr<DartIsolate> root_isolate_;
std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

RuntimeController(RuntimeDelegate& client,
DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
WindowData data);
RuntimeController(
RuntimeDelegate& client,
DartVM* vm,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
WindowData data);

Window* GetWindowIfAvailable();

Expand Down
23 changes: 12 additions & 11 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ static constexpr char kNavigationChannel[] = "flutter/navigation";
static constexpr char kLocalizationChannel[] = "flutter/localization";
static constexpr char kSettingsChannel[] = "flutter/settings";

Engine::Engine(Delegate& delegate,
blink::DartVM& vm,
fml::RefPtr<blink::DartSnapshot> isolate_snapshot,
fml::RefPtr<blink::DartSnapshot> shared_snapshot,
blink::TaskRunners task_runners,
blink::Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<blink::SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<GrContext> resource_context,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue)
Engine::Engine(
Delegate& delegate,
blink::DartVM& vm,
fml::RefPtr<blink::DartSnapshot> isolate_snapshot,
fml::RefPtr<blink::DartSnapshot> shared_snapshot,
blink::TaskRunners task_runners,
blink::Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<blink::SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<blink::ResourceContextManager> resource_context_manager,
fml::RefPtr<flow::SkiaUnrefQueue> unref_queue)
: delegate_(delegate),
settings_(std::move(settings)),
animator_(std::move(animator)),
Expand All @@ -60,7 +61,7 @@ Engine::Engine(Delegate& delegate,
std::move(shared_snapshot), // shared snapshot
std::move(task_runners), // task runners
std::move(snapshot_delegate), // snapshot delegate
std::move(resource_context), // resource context
std::move(resource_context_manager), // resource context
std::move(unref_queue), // skia unref queue
settings_.advisory_script_uri, // advisory script uri
settings_.advisory_script_entrypoint // advisory script entrypoint
Expand Down
Loading