diff --git a/garnet/bin/developer/tiles/main.cc b/garnet/bin/developer/tiles/main.cc index 3057f3218539c1811e5af418ce8c8843643652fe..aa8eced9d5b2977946c9da4f114671bd139106cf 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 bd7b65e7569724ecee2f94d8368c178d23b7ea17..620dbc388093b264eaeab6ff21fcbd75583d16ab 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 2e99bce0c91c9ace74d37d2a88201bbbeced6d34..c351f22a8732f420eb8df453f6390805d4ae7546 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 2a8c86a884c38c3e31ef0ecebeabcf4c99fc63ab..2363eeb6eba9f073c7f9dc58500198777ce680b9 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 f1b6c37ac22d0dd825ea9b5caa1bcc3b48b2f1a1..70d87359c5635a21319324685dff20404a7b9668 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 b86e01e44e728a69d0504e06a2f09580b5b03970..9f542357e9254bbfa43067797cd7c3033b9a0b23 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 6bcf42ff53b3b8c698967421cd35ea953317b3de..50e19cfeeec4b613d4bb5ebbfaa469767fc7361b 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 976091fcc16722a6f52e81b561422ce90dbbcde8..b40019d16dd4f0a577d76172348438800506f70f 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 d2e380c3820ecabc4b00711e63df5c226c7df6d8..f3456dfa8c4f2faaef9a93ef22d7259b96ae76ef 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 e187607e22479b55356156a8231b858b780ff656..9fbc2472c7a057331bb79edea62ebfdd52812dfa 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 7400976c0e50db3bf99aa7e0fb01877c1bd7baa9..6db97eeb0f6c3f7c44eebe628ed48a8e2f1db070 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 dcd639e5d56fe2c57ffc80f3626215bb078045e3..efefe8ea1fe5e833feb019bb576a73ca05b1f9ad 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 abed03876ced295f06ba263b603eacdadcdd0689..782c1d4e3fb6ef130858429c4a519ce53829cdd0 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 2b50244351c18bf9e551b1a881379415b07081a2..7cec99dad4bbc44c7efd8953ac547985311742b6 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 31f00b8dba32b8dfa6e02547361cfe425e7c9171..b2c47e1d61e38ffbc34dad14f870612a48e923ea 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 5ca8807108288c18b8244b4921146e13587326bd..5f1acbfc91585f5292f715bdf62d0e78ded3bbf4 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 1466dce98df7d1711d76404c11d013397cc9ad6f..5fb7ea860a70fed344de0baf8aa88b5299270623 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 e5a9dc30fad292a6cd02edcf3b159c241f0f731d..17cce6ad8002cc9ed75b29c089f40bad6e0f39e0 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 0000000000000000000000000000000000000000..208a96ab33686d8cf06a2cae018ab506b97cabbb --- /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 4c4660da4457ca974dd08d52e195f3adbb714100..c900918c43cb95bb08f82b1f62cc6019e290f644 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 3647824a77a322dcba67941f468696ef7f636aff..71d2bdd37eb3246026a6f78ea7ee58e52ad01a3f 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 9f0a8c3ac233aafa807d99a52f63c11d93f6ef17..763d365cd25af0e606da7c241eca6618b34a0c92 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 fcd461e8ea00394527c3c01afc557a14e889419a..36265dfa5ae6cb4da3fc792e1c18b56706bfa795 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 eefc359710e04223d0b68e2d903a24f95bbaf216..13777052c922083ff25bb1d28f499eec875905e0 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 5322f435cb357d264783b971cf4cc7ae84ee337e..f635c52420363ac2514a7baa5ee7e69900153478 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 fa8b31cd7d8b5d1c99ccefe7460f3eeb2762c6d1..3384bda8f85e5cf0fdfc803fb99c32aa756c6604 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 b6054e00537b2a8978309ed18cae03d2a08ff985..c9c838e78639297d7fa2a3f4d15fbb2b9198fc0a 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 2a96cfbc8bfdd52625d8992f525c9438fdddc4d2..d3b9b81d8f7e7e53fae8a755d54c0b314ce9ed08 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 946dea757b76a827e88d3c8d2230a8ba91ca76d1..b3d5834938efd21b54486aa823e5cc5079411089 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 e84b89d4e68fb645b4861bb9e9d7ba902273a0e3..c772b1622207786aba2c90ee7814f91d2fff3a6b 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); }