Flutter Engine
platform_view_embedder.cc
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 
5 #include "flutter/shell/platform/embedder/platform_view_embedder.h"
6 
7 namespace flutter {
8 
10  PlatformView::Delegate& delegate,
11  flutter::TaskRunners task_runners,
12  EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table,
13  PlatformDispatchTable platform_dispatch_table,
14  std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
15  : PlatformView(delegate, std::move(task_runners)),
16  external_view_embedder_(external_view_embedder),
17  embedder_surface_(
18  std::make_unique<EmbedderSurfaceSoftware>(software_dispatch_table,
19  external_view_embedder_)),
20  platform_dispatch_table_(platform_dispatch_table) {}
21 
22 #ifdef SHELL_ENABLE_GL
24  PlatformView::Delegate& delegate,
25  flutter::TaskRunners task_runners,
26  EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table,
27  bool fbo_reset_after_present,
28  PlatformDispatchTable platform_dispatch_table,
29  std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
30  : PlatformView(delegate, std::move(task_runners)),
31  external_view_embedder_(external_view_embedder),
32  embedder_surface_(
33  std::make_unique<EmbedderSurfaceGL>(gl_dispatch_table,
34  fbo_reset_after_present,
35  external_view_embedder_)),
36  platform_dispatch_table_(platform_dispatch_table) {}
37 #endif
38 
39 #ifdef SHELL_ENABLE_METAL
41  PlatformView::Delegate& delegate,
42  flutter::TaskRunners task_runners,
43  std::unique_ptr<EmbedderSurfaceMetal> embedder_surface,
44  PlatformDispatchTable platform_dispatch_table,
45  std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
46  : PlatformView(delegate, std::move(task_runners)),
47  external_view_embedder_(external_view_embedder),
48  embedder_surface_(std::move(embedder_surface)),
49  platform_dispatch_table_(platform_dispatch_table) {}
50 #endif
51 
53 
57  if (platform_dispatch_table_.update_semantics_nodes_callback != nullptr) {
58  platform_dispatch_table_.update_semantics_nodes_callback(std::move(update));
59  }
60  if (platform_dispatch_table_.update_semantics_custom_actions_callback !=
61  nullptr) {
62  platform_dispatch_table_.update_semantics_custom_actions_callback(
63  std::move(actions));
64  }
65 }
66 
68  std::unique_ptr<flutter::PlatformMessage> message) {
69  if (!message) {
70  return;
71  }
72 
73  if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
74  if (message->response()) {
75  message->response()->CompleteEmpty();
76  }
77  return;
78  }
79 
80  platform_dispatch_table_.platform_message_response_callback(
81  std::move(message));
82 }
83 
84 // |PlatformView|
85 std::unique_ptr<Surface> PlatformViewEmbedder::CreateRenderingSurface() {
86  if (embedder_surface_ == nullptr) {
87  FML_LOG(ERROR) << "Embedder surface was null.";
88  return nullptr;
89  }
90  return embedder_surface_->CreateGPUSurface();
91 }
92 
93 // |PlatformView|
94 std::shared_ptr<ExternalViewEmbedder>
95 PlatformViewEmbedder::CreateExternalViewEmbedder() {
96  return external_view_embedder_;
97 }
98 
99 // |PlatformView|
100 sk_sp<GrDirectContext> PlatformViewEmbedder::CreateResourceContext() const {
101  if (embedder_surface_ == nullptr) {
102  FML_LOG(ERROR) << "Embedder surface was null.";
103  return nullptr;
104  }
105  return embedder_surface_->CreateResourceContext();
106 }
107 
108 // |PlatformView|
109 std::unique_ptr<VsyncWaiter> PlatformViewEmbedder::CreateVSyncWaiter() {
110  if (!platform_dispatch_table_.vsync_callback) {
111  // Superclass implementation creates a timer based fallback.
113  }
114 
115  return std::make_unique<VsyncWaiterEmbedder>(
116  platform_dispatch_table_.vsync_callback, task_runners_);
117 }
118 
119 // |PlatformView|
120 std::unique_ptr<std::vector<std::string>>
121 PlatformViewEmbedder::ComputePlatformResolvedLocales(
122  const std::vector<std::string>& supported_locale_data) {
123  if (platform_dispatch_table_.compute_platform_resolved_locale_callback !=
124  nullptr) {
125  return platform_dispatch_table_.compute_platform_resolved_locale_callback(
126  supported_locale_data);
127  }
128  std::unique_ptr<std::vector<std::string>> out =
129  std::make_unique<std::vector<std::string>>();
130  return out;
131 }
132 
133 // |PlatformView|
134 void PlatformViewEmbedder::OnPreEngineRestart() const {
135  if (platform_dispatch_table_.on_pre_engine_restart_callback != nullptr) {
136  platform_dispatch_table_.on_pre_engine_restart_callback();
137  }
138 }
139 
140 } // namespace flutter
ComputePlatformResolvedLocaleCallback compute_platform_resolved_locale_callback
const TaskRunners task_runners_
virtual std::unique_ptr< VsyncWaiter > CreateVSyncWaiter()
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
PlatformView(Delegate &delegate, TaskRunners task_runners)
Creates a platform view with the specified delegate and task runner. The base class by itself does no...
Definition: ref_ptr.h:252
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
#define FML_LOG(severity)
Definition: logging.h:65
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
void UpdateSemantics(flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Used by the framework to tell the embedder to apply the specified semantics node updates. The default implementation of this method does nothing.
PlatformMessageResponseCallback platform_message_response_callback
PlatformViewEmbedder(PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, EmbedderSurfaceSoftware::SoftwareDispatchTable software_dispatch_table, PlatformDispatchTable platform_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
UpdateSemanticsCustomActionsCallback update_semantics_custom_actions_callback
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Overridden by embedders to perform actions in response to platform messages sent from the framework t...
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Definition: platform_view.h:54