From 426805c59ce3374887340a9024d264f74c43ca6e Mon Sep 17 00:00:00 2001 From: David Worsham <dworsham@google.com> Date: Sat, 27 Apr 2019 00:01:12 +0000 Subject: [PATCH] [scenic] Convert ViewTokenPair to object This unifies the API for C++, Dart, and Rust better. All 3 language bindings are pretty idiomatic now. Tested: view_token_pair_test SCN-1214 #comment Change-Id: I00bcbde5ff64c747ce427764cdfffdf6530e1295 --- garnet/bin/developer/tiles/main.cc | 2 +- garnet/bin/developer/tiles/tiles.cc | 5 +- garnet/bin/developer/tiles/tiles_unittest.cc | 2 +- garnet/bin/guest/vmm/device/virtio_gpu.cc | 2 +- garnet/bin/sl4f/src/scenic/facade.rs | 8 +-- garnet/bin/ui/present_view/main.cc | 2 +- garnet/examples/ui/embedder/app.cc | 7 ++- garnet/examples/ui/lab/direct_input/app.cc | 2 +- garnet/examples/ui/simplest_app/main.cc | 10 ++-- garnet/examples/ui/simplest_embedder/main.cc | 12 ++--- garnet/examples/ui/tile/tile_view.cc | 2 +- .../lib/ui/gfx/tests/gfx_viewstate_apptest.cc | 8 +-- .../ui/gfx/tests/hittest_global_unittest.cc | 4 +- garnet/lib/ui/gfx/tests/scenic_pixel_test.cc | 2 +- garnet/lib/ui/gfx/tests/view_unittest.cc | 51 +++++++++---------- .../ui/base_view/cpp/embedded_view_utils.cc | 4 +- .../rust/carnelian/examples/embedding.rs | 10 ++-- garnet/public/rust/fuchsia-scenic/src/lib.rs | 14 +---- .../fuchsia-scenic/src/view_token_pair.rs | 24 +++++++++ .../e2e_input_tests/minimal_input_test.cc | 16 +++--- peridot/bin/basemgr/basemgr_impl.cc | 4 +- peridot/bin/sessionmgr/sessionmgr_impl.cc | 2 +- peridot/bin/voila/src/main.rs | 8 +-- sdk/lib/ui/scenic/cpp/scenic_cpp.api | 2 +- .../scenic/cpp/tests/view_token_pair_test.cc | 6 +-- sdk/lib/ui/scenic/cpp/view_token_pair.cc | 14 ++--- sdk/lib/ui/scenic/cpp/view_token_pair.h | 12 +++-- .../google_auth_provider_impl.cc | 2 +- .../test/mediaplayer_test_util_view.cc | 2 +- .../mediaplayer/test/mediaplayer_tests.cc | 2 +- 30 files changed, 130 insertions(+), 111 deletions(-) create mode 100644 garnet/public/rust/fuchsia-scenic/src/view_token_pair.rs diff --git a/garnet/bin/developer/tiles/main.cc b/garnet/bin/developer/tiles/main.cc index 3057f321853..aa8eced9d5b 100644 --- a/garnet/bin/developer/tiles/main.cc +++ b/garnet/bin/developer/tiles/main.cc @@ -51,7 +51,7 @@ int main(int argc, const char** argv) { ->ConnectToEnvironmentService<fuchsia::ui::scenic::Scenic>(); // Create tiles with a token for its root view. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); scenic::ViewContext view_context = { .session_and_listener_request = scenic::CreateScenicSessionPtrAndListenerRequest(scenic.get()), diff --git a/garnet/bin/developer/tiles/tiles.cc b/garnet/bin/developer/tiles/tiles.cc index bd7b65e7569..620dbc38809 100644 --- a/garnet/bin/developer/tiles/tiles.cc +++ b/garnet/bin/developer/tiles/tiles.cc @@ -8,6 +8,7 @@ #include <lib/ui/gfx/cpp/math.h> #include <lib/ui/scenic/cpp/view_token_pair.h> #include <src/lib/fxl/logging.h> + #include <cmath> constexpr float kTileElevation = 5.f; @@ -53,7 +54,7 @@ void Tiles::AddTileFromURL(std::string url, bool allow_focus, launcher_->CreateComponent(std::move(launch_info), controller.NewRequest()); // Create a View from the launched component. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); auto view_provider = services.ConnectToService<fuchsia::ui::app::ViewProvider>(); view_provider->CreateView(std::move(view_token.value), nullptr, nullptr); @@ -73,7 +74,7 @@ void Tiles::AddTileFromViewProvider( FXL_VLOG(2) << "AddTile " << url; // Create a View from the ViewProvider. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); auto view_provider = provider.Bind(); view_provider->CreateView(std::move(view_token.value), nullptr, nullptr); diff --git a/garnet/bin/developer/tiles/tiles_unittest.cc b/garnet/bin/developer/tiles/tiles_unittest.cc index 2e99bce0c91..c351f22a873 100644 --- a/garnet/bin/developer/tiles/tiles_unittest.cc +++ b/garnet/bin/developer/tiles/tiles_unittest.cc @@ -40,7 +40,7 @@ class TilesTest : public component::testing::TestWithContext { // happen before calling |TakeContext|. controller().AddService(fake_scenic_.GetHandler()); - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); auto startup_context = TakeContext(); auto scenic = diff --git a/garnet/bin/guest/vmm/device/virtio_gpu.cc b/garnet/bin/guest/vmm/device/virtio_gpu.cc index 2a8c86a884c..2363eeb6eba 100644 --- a/garnet/bin/guest/vmm/device/virtio_gpu.cc +++ b/garnet/bin/guest/vmm/device/virtio_gpu.cc @@ -345,7 +345,7 @@ class VirtioGpuImpl : public DeviceBase<VirtioGpuImpl>, PrepStart(std::move(start_info)); if (view_listener) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Create view. auto scenic = diff --git a/garnet/bin/sl4f/src/scenic/facade.rs b/garnet/bin/sl4f/src/scenic/facade.rs index f1b6c37ac22..70d87359c56 100644 --- a/garnet/bin/sl4f/src/scenic/facade.rs +++ b/garnet/bin/sl4f/src/scenic/facade.rs @@ -47,7 +47,7 @@ impl ScenicFacade { let launcher = launcher().context("Failed to open launcher service")?; let app = launch(&launcher, url, None)?; - let (view_token, mut view_holder_token) = scenic::new_view_token_pair()?; + let mut token_pair = scenic::ViewTokenPair::new()?; // (for now) gate v1/v2 on the presence of a view config match config { @@ -55,16 +55,16 @@ impl ScenicFacade { // v2 let view = app.connect_to_service::<ViewMarker>()?; view.set_config(&mut config)?; - view.attach(view_token.value)?; + view.attach(token_pair.view_token.value)?; } None => { // v1 let view_provider = app.connect_to_service::<ViewProviderMarker>()?; - view_provider.create_view(view_token.value, None, None)?; + view_provider.create_view(token_pair.view_token.value, None, None)?; } } - presenter.present_view(&mut view_holder_token, None)?; + presenter.present_view(&mut token_pair.view_holder_token, None)?; app.controller().detach()?; Ok(()) diff --git a/garnet/bin/ui/present_view/main.cc b/garnet/bin/ui/present_view/main.cc index b86e01e44e7..9f542357e92 100644 --- a/garnet/bin/ui/present_view/main.cc +++ b/garnet/bin/ui/present_view/main.cc @@ -85,7 +85,7 @@ int main(int argc, const char** argv) { loop.Quit(); }); - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Note: This instance must be retained for the lifetime of the UI, so it has // to be declared in the outer scope of |main| rather than inside the relevant diff --git a/garnet/examples/ui/embedder/app.cc b/garnet/examples/ui/embedder/app.cc index 6bcf42ff53b..50e19cfeeec 100644 --- a/garnet/examples/ui/embedder/app.cc +++ b/garnet/examples/ui/embedder/app.cc @@ -6,15 +6,14 @@ #include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/ui/views/cpp/fidl.h> -#include <src/lib/fxl/logging.h> #include <lib/svc/cpp/services.h> #include <lib/sys/cpp/file_descriptor.h> #include <lib/ui/scenic/cpp/commands.h> #include <lib/ui/scenic/cpp/view_token_pair.h> #include <lib/zx/time.h> -#include <zircon/types.h> - +#include <src/lib/fxl/logging.h> #include <unistd.h> +#include <zircon/types.h> #include "example_view_provider_service.h" @@ -95,7 +94,7 @@ App::App(async::Loop* loop, AppType type) }); if (type_ == AppType::CONTAINER) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Create the subview and bind the ServiceProviders. FXL_LOG(INFO) << AppTypeString(type_) << "Creating view."; diff --git a/garnet/examples/ui/lab/direct_input/app.cc b/garnet/examples/ui/lab/direct_input/app.cc index 976091fcc16..b40019d16dd 100644 --- a/garnet/examples/ui/lab/direct_input/app.cc +++ b/garnet/examples/ui/lab/direct_input/app.cc @@ -315,7 +315,7 @@ void App::CreateScene(float display_width, float display_height) { // Create View/ViewHolder. Attach ViewHolder to root node. { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); view_holder_ = std::make_unique<scenic::ViewHolder>( session, std::move(view_holder_token), "view_holder"); diff --git a/garnet/examples/ui/simplest_app/main.cc b/garnet/examples/ui/simplest_app/main.cc index d2e380c3820..f3456dfa8c4 100644 --- a/garnet/examples/ui/simplest_app/main.cc +++ b/garnet/examples/ui/simplest_app/main.cc @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <memory> - #include <fuchsia/ui/policy/cpp/fidl.h> #include <lib/async-loop/cpp/loop.h> #include <lib/component/cpp/startup_context.h> -#include <src/lib/fxl/command_line.h> -#include <src/lib/fxl/log_settings_command_line.h> #include <lib/ui/base_view/cpp/view_provider_component.h> #include <lib/ui/scenic/cpp/view_token_pair.h> +#include <src/lib/fxl/command_line.h> +#include <src/lib/fxl/log_settings_command_line.h> #include <trace-provider/provider.h> #include <zircon/status.h> #include <zircon/types.h> + #include <cstring> +#include <memory> #include "garnet/examples/ui/simplest_app/view.h" @@ -45,7 +45,7 @@ int main(int argc, const char** argv) { // device shell, and connects it to the root presenter. Here, we create // two eventpair handles, one of which will be passed to the root presenter // and the other to the View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Create a startup context for ourselves and use it to connect to // environment services. diff --git a/garnet/examples/ui/simplest_embedder/main.cc b/garnet/examples/ui/simplest_embedder/main.cc index e187607e224..9fbc2472c7a 100644 --- a/garnet/examples/ui/simplest_embedder/main.cc +++ b/garnet/examples/ui/simplest_embedder/main.cc @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <memory> - #include <lib/async-loop/cpp/loop.h> #include <lib/component/cpp/startup_context.h> -#include <src/lib/fxl/command_line.h> -#include <src/lib/fxl/log_settings_command_line.h> #include <lib/ui/base_view/cpp/view_provider_component.h> #include <lib/ui/scenic/cpp/view_token_pair.h> +#include <src/lib/fxl/command_line.h> +#include <src/lib/fxl/log_settings_command_line.h> #include <zircon/system/ulib/zircon/include/zircon/status.h> +#include <memory> + #include "garnet/examples/ui/simplest_embedder/example_presenter.h" #include "garnet/examples/ui/simplest_embedder/view.h" @@ -48,7 +48,7 @@ int main(int argc, const char** argv) { // device shell, and connects it to the root presenter. Here, we create // two eventpair handles, one of which will be passed to the root presenter // and the other to the View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Create a startup context for ourselves and use it to connect to // environment services. @@ -111,7 +111,7 @@ int main(int argc, const char** argv) { // as well if the presenter/view lived in two other processes, and we // passed the tokens to them via FIDL messages. In Peridot, this is // exactly what the device_runner does. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Create a startup context for ourselves and use it to connect to // environment services. diff --git a/garnet/examples/ui/tile/tile_view.cc b/garnet/examples/ui/tile/tile_view.cc index 7400976c0e5..6db97eeb0f6 100644 --- a/garnet/examples/ui/tile/tile_view.cc +++ b/garnet/examples/ui/tile/tile_view.cc @@ -62,7 +62,7 @@ void TileView::ConnectViews() { controller.NewRequest()); // Create a View from the launched component. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); auto view_provider = services.ConnectToService<fuchsia::ui::app::ViewProvider>(); diff --git a/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc b/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc index dcd639e5d56..efefe8ea1fe 100644 --- a/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc +++ b/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <map> -#include <string> - #include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/ui/app/cpp/fidl.h> #include <fuchsia/ui/gfx/cpp/fidl.h> @@ -21,6 +18,9 @@ #include <src/lib/fxl/logging.h> #include <zircon/status.h> +#include <map> +#include <string> + #include "garnet/testing/views/embedder_view.h" namespace { @@ -63,7 +63,7 @@ class ViewEmbedderTest : public sys::testing::TestWithEnvironment { // Create a |ViewContext| that allows us to present a view via // |RootPresenter|. See also examples/ui/simplest_embedder scenic::ViewContext CreatePresentationContext() { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); scenic::ViewContext view_context = { .session_and_listener_request = diff --git a/garnet/lib/ui/gfx/tests/hittest_global_unittest.cc b/garnet/lib/ui/gfx/tests/hittest_global_unittest.cc index abed03876ce..782c1d4e3fb 100644 --- a/garnet/lib/ui/gfx/tests/hittest_global_unittest.cc +++ b/garnet/lib/ui/gfx/tests/hittest_global_unittest.cc @@ -80,8 +80,8 @@ TEST_F(MultiSessionHitTestTest, GlobalHits) { /*release fence signaller*/ nullptr); // Create our tokens for View/ViewHolder creation. - auto [view_token_1, view_holder_token_1] = scenic::NewViewTokenPair(); - auto [view_token_2, view_holder_token_2] = scenic::NewViewTokenPair(); + auto [view_token_1, view_holder_token_1] = scenic::ViewTokenPair::New(); + auto [view_token_2, view_holder_token_2] = scenic::ViewTokenPair::New(); // Root session sets up the scene and two view holders. CustomSession s_r(0, engine->session_context()); diff --git a/garnet/lib/ui/gfx/tests/scenic_pixel_test.cc b/garnet/lib/ui/gfx/tests/scenic_pixel_test.cc index 2b50244351c..7cec99dad4b 100644 --- a/garnet/lib/ui/gfx/tests/scenic_pixel_test.cc +++ b/garnet/lib/ui/gfx/tests/scenic_pixel_test.cc @@ -107,7 +107,7 @@ class ScenicPixelTest : public sys::testing::TestWithEnvironment { // Create a |ViewContext| that allows us to present a view via // |RootPresenter|. See also examples/ui/hello_base_view scenic::ViewContext CreatePresentationContext() { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); scenic::ViewContext view_context = { .session_and_listener_request = diff --git a/garnet/lib/ui/gfx/tests/view_unittest.cc b/garnet/lib/ui/gfx/tests/view_unittest.cc index 31f00b8dba3..b2c47e1d61e 100644 --- a/garnet/lib/ui/gfx/tests/view_unittest.cc +++ b/garnet/lib/ui/gfx/tests/view_unittest.cc @@ -4,9 +4,6 @@ // found in the LICENSE file. #include "garnet/lib/ui/gfx/resources/view.h" -#include "garnet/lib/ui/gfx/resources/nodes/entity_node.h" -#include "garnet/lib/ui/gfx/resources/nodes/view_node.h" -#include "garnet/lib/ui/gfx/resources/view_holder.h" #include <lib/async/cpp/task.h> #include <lib/ui/scenic/cpp/commands.h> @@ -14,6 +11,8 @@ #include <lib/zx/eventpair.h> #include "garnet/lib/ui/gfx/resources/nodes/entity_node.h" +#include "garnet/lib/ui/gfx/resources/nodes/view_node.h" +#include "garnet/lib/ui/gfx/resources/view_holder.h" #include "garnet/lib/ui/gfx/tests/session_test.h" #include "garnet/lib/ui/gfx/tests/util.h" @@ -60,7 +59,7 @@ TEST_F(ViewTest, DISABLED_CreateViewWithBadTokenDies) { } TEST_F(ViewTest, ChildrenCanBeAddedToViewWithoutViewHolder) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_id = 1; EXPECT_TRUE( @@ -88,7 +87,7 @@ TEST_F(ViewTest, ChildrenCanBeAddedToViewWithoutViewHolder) { } TEST_F(ViewTest, ExportsViewHolderViaCmd) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1; EXPECT_TRUE(Apply(scenic::NewCreateViewHolderCmd( @@ -106,7 +105,7 @@ TEST_F(ViewTest, ExportsViewHolderViaCmd) { } TEST_F(ViewTest, ImportsViewViaCmd) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_id = 1; EXPECT_TRUE( @@ -124,7 +123,7 @@ TEST_F(ViewTest, ImportsViewViaCmd) { } TEST_F(ViewTest, PairedViewAndHolderAreLinked) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; EXPECT_TRUE(Apply(scenic::NewCreateViewHolderCmd( @@ -164,7 +163,7 @@ TEST_F(ViewTest, PairedViewAndHolderAreLinked) { TEST_F(ViewTest, ExportViewHolderWithDeadHandleFails) { fuchsia::ui::views::ViewHolderToken view_holder_token_out; { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); view_holder_token_out.value = zx::eventpair(view_holder_token.value.get()); // view_holder_token dies now. } @@ -184,7 +183,7 @@ TEST_F(ViewTest, ExportViewHolderWithDeadHandleFails) { } TEST_F(ViewTest, ViewHolderDestroyedBeforeView) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -203,7 +202,7 @@ TEST_F(ViewTest, ViewHolderDestroyedBeforeView) { } TEST_F(ViewTest, ViewDestroyedBeforeViewHolder) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -223,7 +222,7 @@ TEST_F(ViewTest, ViewDestroyedBeforeViewHolder) { } TEST_F(ViewTest, ViewAndViewHolderConnectedEvents) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -248,7 +247,7 @@ TEST_F(ViewTest, ViewAndViewHolderConnectedEvents) { } TEST_F(ViewTest, ViewHolderConnectsToScene) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -276,7 +275,7 @@ TEST_F(ViewTest, ViewHolderConnectsToScene) { TEST_F(ViewTest, ViewHolderDetachedAndReleased) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -338,7 +337,7 @@ TEST_F(ViewTest, ViewHolderDetachedAndReleased) { TEST_F(ViewTest, ViewHolderChildrenReleasedFromSceneGraphWhenViewDestroyed) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -385,7 +384,7 @@ TEST_F(ViewTest, ViewHolderChildrenReleasedFromSceneGraphWhenViewDestroyed) { TEST_F(ViewTest, ViewNodeChildAddedToViewHolder) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -404,7 +403,7 @@ TEST_F(ViewTest, ViewNodeChildAddedToViewHolder) { TEST_F(ViewTest, ViewHolderCannotAddArbitraryChildNodes) { // Create ViewHolder. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -420,7 +419,7 @@ TEST_F(ViewTest, ViewHolderCannotAddArbitraryChildNodes) { TEST_F(ViewTest, ViewNodePairedToView) { // Create View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -440,7 +439,7 @@ TEST_F(ViewTest, ViewNodePairedToView) { TEST_F(ViewTest, ViewNodeNotInResourceMap) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -457,7 +456,7 @@ TEST_F(ViewTest, ViewNodeNotInResourceMap) { } TEST_F(ViewTest, ViewHolderGrandchildGetsSceneRefreshed) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId kViewHolderId = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -486,7 +485,7 @@ TEST_F(ViewTest, ViewHolderGrandchildGetsSceneRefreshed) { } TEST_F(ViewTest, ViewLinksAfterViewHolderConnectsToScene) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -525,7 +524,7 @@ TEST_F(ViewTest, ViewLinksAfterViewHolderConnectsToScene) { } TEST_F(ViewTest, ViewStateChangeNotifiesViewHolder) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -553,7 +552,7 @@ TEST_F(ViewTest, ViewStateChangeNotifiesViewHolder) { } TEST_F(ViewTest, RenderStateAcrossManyFrames) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -586,7 +585,7 @@ TEST_F(ViewTest, RenderStateAcrossManyFrames) { } TEST_F(ViewTest, RenderStateFalseWhenViewDisconnects) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -618,7 +617,7 @@ TEST_F(ViewTest, RenderStateFalseWhenViewDisconnects) { } TEST_F(ViewTest, ViewHolderRenderWaitClearedWhenViewDestroyed) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -645,7 +644,7 @@ TEST_F(ViewTest, ViewHolderRenderWaitClearedWhenViewDestroyed) { } TEST_F(ViewTest, RenderSignalDoesntCrashWhenViewHolderDestroyed) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -668,7 +667,7 @@ TEST_F(ViewTest, RenderSignalDoesntCrashWhenViewHolderDestroyed) { } TEST_F(ViewTest, RenderStateFalseWhenViewHolderDisconnectsFromScene) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); const ResourceId view_holder_id = 2u; Apply(scenic::NewCreateViewHolderCmd( diff --git a/garnet/public/lib/ui/base_view/cpp/embedded_view_utils.cc b/garnet/public/lib/ui/base_view/cpp/embedded_view_utils.cc index 5ca88071082..5f1acbfc915 100644 --- a/garnet/public/lib/ui/base_view/cpp/embedded_view_utils.cc +++ b/garnet/public/lib/ui/base_view/cpp/embedded_view_utils.cc @@ -5,7 +5,7 @@ #include "lib/ui/base_view/cpp/embedded_view_utils.h" #include <lib/ui/scenic/cpp/view_token_pair.h> -#include "src/lib/fxl/logging.h" +#include <src/lib/fxl/logging.h> namespace scenic { @@ -14,7 +14,7 @@ EmbeddedViewInfo LaunchComponentAndCreateView( const std::vector<std::string>& component_args) { FXL_DCHECK(launcher); - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); EmbeddedViewInfo info; diff --git a/garnet/public/rust/carnelian/examples/embedding.rs b/garnet/public/rust/carnelian/examples/embedding.rs index 1466dce98df..5fb7ea860a7 100644 --- a/garnet/public/rust/carnelian/examples/embedding.rs +++ b/garnet/public/rust/carnelian/examples/embedding.rs @@ -11,9 +11,7 @@ use fidl_fuchsia_math::RectF; use fidl_fuchsia_ui_app::ViewProviderMarker; use fidl_fuchsia_ui_gfx::{BoundingBox, Vec3, ViewProperties}; use fuchsia_component::client::{launch, launcher, App as LaunchedApp}; -use fuchsia_scenic::{ - new_view_token_pair, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, -}; +use fuchsia_scenic::{EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, ViewTokenPair}; use itertools::Itertools; use std::collections::BTreeMap; @@ -77,15 +75,15 @@ struct EmbeddingViewAssistant { impl EmbeddingViewAssistant { fn create_and_setup_view(&mut self, context: &ViewAssistantContext) -> Result<(), Error> { - let (view_token, view_holder_token) = new_view_token_pair()?; + let token_pair = ViewTokenPair::new()?; let view_provider = self.app.connect_to_service::<ViewProviderMarker>()?; - view_provider.create_view(view_token.value, None, None)?; + view_provider.create_view(token_pair.view_token.value, None, None)?; let holder_node = EntityNode::new(context.session.clone()); let view_holder = ViewHolder::new( context.session.clone(), - view_holder_token, + token_pair.view_holder_token, Some(String::from("Carnelian Embedded View")), ); holder_node.attach(&view_holder); diff --git a/garnet/public/rust/fuchsia-scenic/src/lib.rs b/garnet/public/rust/fuchsia-scenic/src/lib.rs index e5a9dc30fad..17cce6ad800 100644 --- a/garnet/public/rust/fuchsia-scenic/src/lib.rs +++ b/garnet/public/rust/fuchsia-scenic/src/lib.rs @@ -5,8 +5,9 @@ #![deny(warnings)] mod cmd; +mod view_token_pair; +pub use self::view_token_pair::*; -use failure::Error; use fidl_fuchsia_images::{ImageInfo, MemoryType, PixelFormat, PresentationInfo, Tiling}; use fidl_fuchsia_ui_gfx::{ CircleArgs, ColorRgba, EntityNodeArgs, ImageArgs, ImportSpec, MaterialArgs, MemoryArgs, @@ -21,17 +22,6 @@ use parking_lot::Mutex; use std::ops::Deref; use std::sync::Arc; -pub fn new_view_token_pair() -> Result<(ViewToken, ViewHolderToken), Error> { - // Failure can occur for example, if the job creation policy governing - // this process forbids eventpair creation. - // - // However, it is unlikely that a well-behaved Scenic client would fail - // here; if you hit this, it means something is very abnormal. - let (raw_view_token, raw_view_holder_token) = EventPair::create()?; - - Ok((ViewToken { value: raw_view_token }, ViewHolderToken { value: raw_view_holder_token })) -} - pub struct Session { session: SessionProxy, next_resource_id: u32, diff --git a/garnet/public/rust/fuchsia-scenic/src/view_token_pair.rs b/garnet/public/rust/fuchsia-scenic/src/view_token_pair.rs new file mode 100644 index 00000000000..208a96ab336 --- /dev/null +++ b/garnet/public/rust/fuchsia-scenic/src/view_token_pair.rs @@ -0,0 +1,24 @@ +// Copyright 2019 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. + +use failure::Error; +use fidl_fuchsia_ui_views::{ViewHolderToken, ViewToken}; +use fuchsia_zircon::EventPair; + +pub struct ViewTokenPair { + pub view_token: ViewToken, + pub view_holder_token: ViewHolderToken, +} + +impl ViewTokenPair { + pub fn new() -> Result<ViewTokenPair, Error> { + let (raw_view_token, raw_view_holder_token) = EventPair::create()?; + let token_pair = ViewTokenPair { + view_token: ViewToken { value: raw_view_token }, + view_holder_token: ViewHolderToken { value: raw_view_holder_token }, + }; + + Ok(token_pair) + } +} diff --git a/garnet/tests/e2e_input_tests/minimal_input_test.cc b/garnet/tests/e2e_input_tests/minimal_input_test.cc index 4c4660da445..c900918c43c 100644 --- a/garnet/tests/e2e_input_tests/minimal_input_test.cc +++ b/garnet/tests/e2e_input_tests/minimal_input_test.cc @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.#include <cstdio> -#include <memory> -#include <string> -#include <vector> - #include <fuchsia/ui/input/cpp/fidl.h> #include <fuchsia/ui/policy/cpp/fidl.h> #include <fuchsia/ui/scenic/cpp/fidl.h> @@ -14,16 +10,20 @@ #include <lib/component/cpp/startup_context.h> #include <lib/fdio/spawn.h> #include <lib/fit/function.h> -#include <src/lib/fxl/command_line.h> -#include <src/lib/fxl/log_settings_command_line.h> -#include <src/lib/fxl/logging.h> #include <lib/gtest/real_loop_fixture.h> #include <lib/ui/base_view/cpp/base_view.h> #include <lib/ui/input/cpp/formatting.h> #include <lib/ui/scenic/cpp/session.h> #include <lib/ui/scenic/cpp/view_token_pair.h> +#include <src/lib/fxl/command_line.h> +#include <src/lib/fxl/log_settings_command_line.h> +#include <src/lib/fxl/logging.h> #include <zircon/status.h> +#include <memory> +#include <string> +#include <vector> + namespace { using fuchsia::ui::input::InputEvent; @@ -109,7 +109,7 @@ class MinimalInputTest : public gtest::RealLoopFixture { g_context = component::StartupContext::CreateFromStartupInfo().release(); } - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Connect to Scenic, create a View. scenic_ = diff --git a/peridot/bin/basemgr/basemgr_impl.cc b/peridot/bin/basemgr/basemgr_impl.cc index 3647824a77a..71d2bdd37eb 100644 --- a/peridot/bin/basemgr/basemgr_impl.cc +++ b/peridot/bin/basemgr/basemgr_impl.cc @@ -102,7 +102,7 @@ void BasemgrImpl::StartBaseShell() { base_shell_app_ = std::make_unique<AppClient<fuchsia::modular::Lifecycle>>( launcher_, std::move(base_shell_config)); - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); fuchsia::ui::app::ViewProviderPtr base_shell_view_provider; base_shell_app_->services().ConnectToService( @@ -286,7 +286,7 @@ void BasemgrImpl::GetAuthenticationUIContext( void BasemgrImpl::OnLogin(fuchsia::modular::auth::AccountPtr account, fuchsia::auth::TokenManagerPtr ledger_token_manager, fuchsia::auth::TokenManagerPtr agent_token_manager) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); auto did_start_session = session_provider_->StartSession( std::move(view_token), std::move(account), diff --git a/peridot/bin/sessionmgr/sessionmgr_impl.cc b/peridot/bin/sessionmgr/sessionmgr_impl.cc index 9f0a8c3ac23..763d365cd25 100644 --- a/peridot/bin/sessionmgr/sessionmgr_impl.cc +++ b/peridot/bin/sessionmgr/sessionmgr_impl.cc @@ -800,7 +800,7 @@ void SessionmgrImpl::RunSessionShell( Shutdown(); }); - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); fuchsia::ui::app::ViewProviderPtr view_provider; session_shell_app_->services().ConnectToService(view_provider.NewRequest()); view_provider->CreateView(std::move(view_token.value), nullptr, nullptr); diff --git a/peridot/bin/voila/src/main.rs b/peridot/bin/voila/src/main.rs index fcd461e8ea0..36265dfa5ae 100644 --- a/peridot/bin/voila/src/main.rs +++ b/peridot/bin/voila/src/main.rs @@ -22,7 +22,7 @@ use fuchsia_app::{ }; use fuchsia_async as fasync; use fuchsia_scenic::{ - new_view_token_pair, Circle, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, + Circle, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, ViewTokenPair, }; use fuchsia_syslog::{self as fx_log, fx_log_info, fx_log_warn}; use futures::prelude::*; @@ -120,10 +120,10 @@ impl VoilaViewAssistant { let mut story_shell_config = AppConfig { url: MONDRIAN_URI.to_string(), args: None }; // Set up views. - let (mut view_token, view_holder_token) = new_view_token_pair()?; + let mut token_pair = ViewTokenPair::new()?; let host_node = EntityNode::new(session.clone()); - let host_view_holder = ViewHolder::new(session.clone(), view_holder_token, None); + let host_view_holder = ViewHolder::new(session.clone(), token_pair.view_holder_token, None); host_node.attach(&host_view_holder); root_node.add_child(&host_node); @@ -160,7 +160,7 @@ impl VoilaViewAssistant { None, /* ledger_token_manager */ None, /* agent_token_manager */ session_context_client, - &mut view_token, + &mut token_pair.view_token, ) .context("Failed to issue initialize request for sessionmgr")?; Ok(()) diff --git a/sdk/lib/ui/scenic/cpp/scenic_cpp.api b/sdk/lib/ui/scenic/cpp/scenic_cpp.api index eefc359710e..13777052c92 100644 --- a/sdk/lib/ui/scenic/cpp/scenic_cpp.api +++ b/sdk/lib/ui/scenic/cpp/scenic_cpp.api @@ -5,5 +5,5 @@ "pkg/scenic_cpp/include/lib/ui/scenic/cpp/resources.h": "c34d6a22311f5f81e6d7c571f178049f", "pkg/scenic_cpp/include/lib/ui/scenic/cpp/session.h": "3055e2a58ffb264559fe73e14774cf85", "pkg/scenic_cpp/include/lib/ui/scenic/cpp/util/mesh_utils.h": "41dd823e1bd4cf48c560873547a689ea", - "pkg/scenic_cpp/include/lib/ui/scenic/cpp/view_token_pair.h": "5891b46e01fcae095aeef0e8ff9b7398" + "pkg/scenic_cpp/include/lib/ui/scenic/cpp/view_token_pair.h": "1d32d345d5e1746ada8a36d45b1ebf56" } \ No newline at end of file diff --git a/sdk/lib/ui/scenic/cpp/tests/view_token_pair_test.cc b/sdk/lib/ui/scenic/cpp/tests/view_token_pair_test.cc index 5322f435cb3..f635c524203 100644 --- a/sdk/lib/ui/scenic/cpp/tests/view_token_pair_test.cc +++ b/sdk/lib/ui/scenic/cpp/tests/view_token_pair_test.cc @@ -2,18 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <lib/ui/scenic/cpp/view_token_pair.h> - #include <fuchsia/ui/views/cpp/fidl.h> #include <gtest/gtest.h> +#include <lib/ui/scenic/cpp/view_token_pair.h> #include <zircon/syscalls/object.h> #include <zircon/types.h> + #include <tuple> namespace { TEST(ViewTokenPairTest, ViewTokensAreRelated) { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); // Get info about the |view_token|. zx_info_handle_basic_t view_info; diff --git a/sdk/lib/ui/scenic/cpp/view_token_pair.cc b/sdk/lib/ui/scenic/cpp/view_token_pair.cc index fa8b31cd7d8..3384bda8f85 100644 --- a/sdk/lib/ui/scenic/cpp/view_token_pair.cc +++ b/sdk/lib/ui/scenic/cpp/view_token_pair.cc @@ -3,15 +3,15 @@ // found in the LICENSE file. #include <lib/ui/scenic/cpp/view_token_pair.h> - #include <zircon/assert.h> namespace scenic { -ViewTokenPair NewViewTokenPair() { - ViewTokenPair new_tokens; - auto status = zx::eventpair::create(0u, &new_tokens.first.value, - &new_tokens.second.value); +ViewTokenPair ViewTokenPair::New() { + ViewTokenPair token_pair; + + auto status = zx::eventpair::create(0u, &token_pair.view_token.value, + &token_pair.view_holder_token.value); // Assert even in non-debug builds, because eventpair creation can fail under // normal operation. Failure can occur for example, if the job creation // policy governing this process forbids eventpair creation. @@ -20,9 +20,11 @@ ViewTokenPair NewViewTokenPair() { // hit this, it means something is very abnormal. ZX_ASSERT(status == ZX_OK); - return new_tokens; + return token_pair; } +ViewTokenPair NewViewTokenPair() { return ViewTokenPair::New(); } + fuchsia::ui::views::ViewToken ToViewToken(zx::eventpair raw_token) { return fuchsia::ui::views::ViewToken({ .value = std::move(raw_token), diff --git a/sdk/lib/ui/scenic/cpp/view_token_pair.h b/sdk/lib/ui/scenic/cpp/view_token_pair.h index b6054e00537..c9c838e7863 100644 --- a/sdk/lib/ui/scenic/cpp/view_token_pair.h +++ b/sdk/lib/ui/scenic/cpp/view_token_pair.h @@ -7,12 +7,18 @@ #include <fuchsia/ui/views/cpp/fidl.h> #include <lib/zx/eventpair.h> -#include <utility> namespace scenic { -using ViewTokenPair = std::pair<fuchsia::ui::views::ViewToken, - fuchsia::ui::views::ViewHolderToken>; +struct ViewTokenPair { + // Convenience function which allows clients to easily create a valid + // |ViewToken| / |ViewHolderToken| pair for use with |View| / |ViewHolder| + // resources. + static ViewTokenPair New(); + + fuchsia::ui::views::ViewToken view_token; + fuchsia::ui::views::ViewHolderToken view_holder_token; +}; // Convenience function which allows clients to easily create a |ViewToken| / // |ViewHolderToken| pair for use with |View| resources. diff --git a/src/identity/bin/google_auth_provider/google_auth_provider_impl.cc b/src/identity/bin/google_auth_provider/google_auth_provider_impl.cc index 2a96cfbc8bf..d3b9b81d8f7 100644 --- a/src/identity/bin/google_auth_provider/google_auth_provider_impl.cc +++ b/src/identity/bin/google_auth_provider/google_auth_provider_impl.cc @@ -625,7 +625,7 @@ fuchsia::ui::views::ViewHolderToken GoogleAuthProviderImpl::SetupChromium() { web_frame_->SetNavigationEventListener(std::move(navigation_event_listener)); // And create a view for the frame. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); web_frame_->CreateView(std::move(view_token)); return std::move(view_holder_token); diff --git a/src/media/playback/mediaplayer/test/mediaplayer_test_util_view.cc b/src/media/playback/mediaplayer/test/mediaplayer_test_util_view.cc index 946dea757b7..b3d5834938e 100644 --- a/src/media/playback/mediaplayer/test/mediaplayer_test_util_view.cc +++ b/src/media/playback/mediaplayer/test/mediaplayer_test_util_view.cc @@ -85,7 +85,7 @@ MediaPlayerTestUtilView::MediaPlayerTestUtilView( ->ConnectToEnvironmentService<fuchsia::media::playback::Player>(); // Create the video view. - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); player_->CreateView(std::move(view_token)); diff --git a/src/media/playback/mediaplayer/test/mediaplayer_tests.cc b/src/media/playback/mediaplayer/test/mediaplayer_tests.cc index e84b89d4e68..c772b162220 100644 --- a/src/media/playback/mediaplayer/test/mediaplayer_tests.cc +++ b/src/media/playback/mediaplayer/test/mediaplayer_tests.cc @@ -85,7 +85,7 @@ class MediaPlayerTests : public sys::testing::TestWithEnvironment { // Creates a view. void CreateView() { - auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); + auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); player_->CreateView(std::move(view_token)); view_holder_token_ = std::move(view_holder_token); } -- GitLab