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 
40 
44  if (platform_dispatch_table_.update_semantics_nodes_callback != nullptr) {
45  platform_dispatch_table_.update_semantics_nodes_callback(std::move(update));
46  }
47  if (platform_dispatch_table_.update_semantics_custom_actions_callback !=
48  nullptr) {
49  platform_dispatch_table_.update_semantics_custom_actions_callback(
50  std::move(actions));
51  }
52 }
53 
56  if (!message) {
57  return;
58  }
59 
60  if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
61  if (message->response()) {
62  message->response()->CompleteEmpty();
63  }
64  return;
65  }
66 
67  platform_dispatch_table_.platform_message_response_callback(
68  std::move(message));
69 }
70 
71 // |PlatformView|
72 std::unique_ptr<Surface> PlatformViewEmbedder::CreateRenderingSurface() {
73  if (embedder_surface_ == nullptr) {
74  FML_LOG(ERROR) << "Embedder surface was null.";
75  return nullptr;
76  }
77  return embedder_surface_->CreateGPUSurface();
78 }
79 
80 // |PlatformView|
81 sk_sp<GrDirectContext> PlatformViewEmbedder::CreateResourceContext() const {
82  if (embedder_surface_ == nullptr) {
83  FML_LOG(ERROR) << "Embedder surface was null.";
84  return nullptr;
85  }
86  return embedder_surface_->CreateResourceContext();
87 }
88 
89 // |PlatformView|
90 std::unique_ptr<VsyncWaiter> PlatformViewEmbedder::CreateVSyncWaiter() {
91  if (!platform_dispatch_table_.vsync_callback) {
92  // Superclass implementation creates a timer based fallback.
94  }
95 
96  return std::make_unique<VsyncWaiterEmbedder>(
97  platform_dispatch_table_.vsync_callback, task_runners_);
98 }
99 
100 // |PlatformView|
101 std::unique_ptr<std::vector<std::string>>
102 PlatformViewEmbedder::ComputePlatformResolvedLocales(
103  const std::vector<std::string>& supported_locale_data) {
104  if (platform_dispatch_table_.compute_platform_resolved_locale_callback !=
105  nullptr) {
106  return platform_dispatch_table_.compute_platform_resolved_locale_callback(
107  supported_locale_data);
108  }
109  std::unique_ptr<std::vector<std::string>> out =
110  std::make_unique<std::vector<std::string>>();
111  return out;
112 }
113 
114 } // 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:44
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
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:51
const fml::RefPtr< PlatformMessageResponse > & response() const
void HandlePlatformMessage(fml::RefPtr< flutter::PlatformMessage > message) override
Overridden by embedders to perform actions in response to platform messages sent from the framework t...