| // Copyright 2022 The Fuchsia 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 SRC_EMBEDDER_FLATLAND_VIEW_PROVIDER_H_ |
| #define SRC_EMBEDDER_FLATLAND_VIEW_PROVIDER_H_ |
| |
| #include <fuchsia/ui/app/cpp/fidl.h> |
| #include <lib/syslog/global.h> |
| #include <lib/ui/scenic/cpp/view_identity.h> |
| |
| #include "src/embedder/flatland_connection.h" |
| #include "src/embedder/flatland_ids.h" |
| #include "src/embedder/logging.h" |
| |
| namespace embedder { |
| |
| /// Implements ViewProvider by using Flatland to create a view. |
| class FlatlandViewProvider final : public fuchsia::ui::app::ViewProvider { |
| public: |
| FlatlandViewProvider(FlatlandConnection* flatland_connection, |
| fuchsia::ui::composition::ViewBoundProtocols protocols) |
| : flatland_connection_(flatland_connection), flatland_view_protocols_(std::move(protocols)) {} |
| ~FlatlandViewProvider() override {} |
| |
| FlatlandViewProvider(const FlatlandViewProvider&) = delete; |
| FlatlandViewProvider& operator=(const FlatlandViewProvider&) = delete; |
| |
| void CreateView(zx::eventpair token, |
| fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services, |
| fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services) override { |
| FX_LOG(ERROR, kLogTag, "ViewProvider::CreateView not implemented."); |
| } |
| |
| void CreateViewWithViewRef(zx::eventpair view_token, |
| fuchsia::ui::views::ViewRefControl control_ref, |
| fuchsia::ui::views::ViewRef view_ref) override { |
| FX_LOG(ERROR, kLogTag, "ViewProvider::CreateViewWithViewRef not implemented."); |
| } |
| |
| void CreateView2(fuchsia::ui::app::CreateView2Args view_args) override { |
| auto* flatland = flatland_connection_->flatland(); |
| flatland->CreateView2(std::move(*view_args.mutable_view_creation_token()), |
| scenic::NewViewIdentityOnCreation(), std::move(flatland_view_protocols_), |
| parent_viewport_watcher_.NewRequest()); |
| |
| flatland->CreateTransform({kRootTransformId}); |
| flatland->SetRootTransform({kRootTransformId}); |
| } |
| |
| private: |
| FlatlandConnection* flatland_connection_ = nullptr; |
| fuchsia::ui::composition::ViewBoundProtocols flatland_view_protocols_; |
| fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher_; |
| }; |
| |
| } // namespace embedder |
| |
| #endif // SRC_EMBEDDER_FLATLAND_VIEW_PROVIDER_H_ |