diff --git a/garnet/bin/developer/tiles/main.cc b/garnet/bin/developer/tiles/main.cc index aa8eced9d5b2977946c9da4f114671bd139106cf..3057f3218539c1811e5af418ce8c8843643652fe 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 620dbc388093b264eaeab6ff21fcbd75583d16ab..bd7b65e7569724ecee2f94d8368c178d23b7ea17 100644 --- a/garnet/bin/developer/tiles/tiles.cc +++ b/garnet/bin/developer/tiles/tiles.cc @@ -8,7 +8,6 @@ #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; @@ -54,7 +53,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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); auto view_provider = services.ConnectToService<fuchsia::ui::app::ViewProvider>(); view_provider->CreateView(std::move(view_token.value), nullptr, nullptr); @@ -74,7 +73,7 @@ void Tiles::AddTileFromViewProvider( FXL_VLOG(2) << "AddTile " << url; // Create a View from the ViewProvider. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 c351f22a8732f420eb8df453f6390805d4ae7546..2e99bce0c91c9ace74d37d2a88201bbbeced6d34 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 2363eeb6eba9f073c7f9dc58500198777ce680b9..2a8c86a884c38c3e31ef0ecebeabcf4c99fc63ab 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // Create view. auto scenic = diff --git a/garnet/bin/sl4f/src/scenic/facade.rs b/garnet/bin/sl4f/src/scenic/facade.rs index 70d87359c5635a21319324685dff20404a7b9668..f1b6c37ac22d0dd825ea9b5caa1bcc3b48b2f1a1 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 mut token_pair = scenic::ViewTokenPair::new()?; + let (view_token, mut view_holder_token) = scenic::new_view_token_pair()?; // (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(token_pair.view_token.value)?; + view.attach(view_token.value)?; } None => { // v1 let view_provider = app.connect_to_service::<ViewProviderMarker>()?; - view_provider.create_view(token_pair.view_token.value, None, None)?; + view_provider.create_view(view_token.value, None, None)?; } } - presenter.present_view(&mut token_pair.view_holder_token, None)?; + presenter.present_view(&mut 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 9f542357e9254bbfa43067797cd7c3033b9a0b23..b86e01e44e728a69d0504e06a2f09580b5b03970 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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 50e19cfeeec4b613d4bb5ebbfaa469767fc7361b..6bcf42ff53b3b8c698967421cd35ea953317b3de 100644 --- a/garnet/examples/ui/embedder/app.cc +++ b/garnet/examples/ui/embedder/app.cc @@ -6,15 +6,16 @@ #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 <src/lib/fxl/logging.h> -#include <unistd.h> #include <zircon/types.h> +#include <unistd.h> + #include "example_view_provider_service.h" // Returns a human-readable string for a given embedder process type - @@ -94,7 +95,7 @@ App::App(async::Loop* loop, AppType type) }); if (type_ == AppType::CONTAINER) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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 b40019d16dd4f0a577d76172348438800506f70f..976091fcc16722a6f52e81b561422ce90dbbcde8 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 f3456dfa8c4f2faaef9a93ef22d7259b96ae76ef..d2e380c3820ecabc4b00711e63df5c226c7df6d8 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 <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 <lib/ui/base_view/cpp/view_provider_component.h> +#include <lib/ui/scenic/cpp/view_token_pair.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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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 9fbc2472c7a057331bb79edea62ebfdd52812dfa..e187607e22479b55356156a8231b858b780ff656 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 <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 <lib/ui/base_view/cpp/view_provider_component.h> +#include <lib/ui/scenic/cpp/view_token_pair.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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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 6db97eeb0f6c3f7c44eebe628ed48a8e2f1db070..7400976c0e50db3bf99aa7e0fb01877c1bd7baa9 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 efefe8ea1fe5e833feb019bb576a73ca05b1f9ad..dcd639e5d56fe2c57ffc80f3626215bb078045e3 100644 --- a/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc +++ b/garnet/lib/ui/gfx/tests/gfx_viewstate_apptest.cc @@ -2,6 +2,9 @@ // 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> @@ -18,9 +21,6 @@ #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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 782c1d4e3fb6ef130858429c4a519ce53829cdd0..abed03876ced295f06ba263b603eacdadcdd0689 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::ViewTokenPair::New(); - auto [view_token_2, view_holder_token_2] = scenic::ViewTokenPair::New(); + auto [view_token_1, view_holder_token_1] = scenic::NewViewTokenPair(); + auto [view_token_2, view_holder_token_2] = scenic::NewViewTokenPair(); // 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 7cec99dad4bbc44c7efd8953ac547985311742b6..2b50244351c18bf9e551b1a881379415b07081a2 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 b2c47e1d61e38ffbc34dad14f870612a48e923ea..31f00b8dba32b8dfa6e02547361cfe425e7c9171 100644 --- a/garnet/lib/ui/gfx/tests/view_unittest.cc +++ b/garnet/lib/ui/gfx/tests/view_unittest.cc @@ -4,6 +4,9 @@ // 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> @@ -11,8 +14,6 @@ #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" @@ -59,7 +60,7 @@ TEST_F(ViewTest, DISABLED_CreateViewWithBadTokenDies) { } TEST_F(ViewTest, ChildrenCanBeAddedToViewWithoutViewHolder) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_id = 1; EXPECT_TRUE( @@ -87,7 +88,7 @@ TEST_F(ViewTest, ChildrenCanBeAddedToViewWithoutViewHolder) { } TEST_F(ViewTest, ExportsViewHolderViaCmd) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1; EXPECT_TRUE(Apply(scenic::NewCreateViewHolderCmd( @@ -105,7 +106,7 @@ TEST_F(ViewTest, ExportsViewHolderViaCmd) { } TEST_F(ViewTest, ImportsViewViaCmd) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_id = 1; EXPECT_TRUE( @@ -123,7 +124,7 @@ TEST_F(ViewTest, ImportsViewViaCmd) { } TEST_F(ViewTest, PairedViewAndHolderAreLinked) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; EXPECT_TRUE(Apply(scenic::NewCreateViewHolderCmd( @@ -163,7 +164,7 @@ TEST_F(ViewTest, PairedViewAndHolderAreLinked) { TEST_F(ViewTest, ExportViewHolderWithDeadHandleFails) { fuchsia::ui::views::ViewHolderToken view_holder_token_out; { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); view_holder_token_out.value = zx::eventpair(view_holder_token.value.get()); // view_holder_token dies now. } @@ -183,7 +184,7 @@ TEST_F(ViewTest, ExportViewHolderWithDeadHandleFails) { } TEST_F(ViewTest, ViewHolderDestroyedBeforeView) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -202,7 +203,7 @@ TEST_F(ViewTest, ViewHolderDestroyedBeforeView) { } TEST_F(ViewTest, ViewDestroyedBeforeViewHolder) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -222,7 +223,7 @@ TEST_F(ViewTest, ViewDestroyedBeforeViewHolder) { } TEST_F(ViewTest, ViewAndViewHolderConnectedEvents) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -247,7 +248,7 @@ TEST_F(ViewTest, ViewAndViewHolderConnectedEvents) { } TEST_F(ViewTest, ViewHolderConnectsToScene) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -275,7 +276,7 @@ TEST_F(ViewTest, ViewHolderConnectsToScene) { TEST_F(ViewTest, ViewHolderDetachedAndReleased) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -337,7 +338,7 @@ TEST_F(ViewTest, ViewHolderDetachedAndReleased) { TEST_F(ViewTest, ViewHolderChildrenReleasedFromSceneGraphWhenViewDestroyed) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -384,7 +385,7 @@ TEST_F(ViewTest, ViewHolderChildrenReleasedFromSceneGraphWhenViewDestroyed) { TEST_F(ViewTest, ViewNodeChildAddedToViewHolder) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -403,7 +404,7 @@ TEST_F(ViewTest, ViewNodeChildAddedToViewHolder) { TEST_F(ViewTest, ViewHolderCannotAddArbitraryChildNodes) { // Create ViewHolder. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -419,7 +420,7 @@ TEST_F(ViewTest, ViewHolderCannotAddArbitraryChildNodes) { TEST_F(ViewTest, ViewNodePairedToView) { // Create View. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -439,7 +440,7 @@ TEST_F(ViewTest, ViewNodePairedToView) { TEST_F(ViewTest, ViewNodeNotInResourceMap) { // Create ViewHolder and View. - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( view_holder_id, std::move(view_holder_token), "Holder [Test]")); @@ -456,7 +457,7 @@ TEST_F(ViewTest, ViewNodeNotInResourceMap) { } TEST_F(ViewTest, ViewHolderGrandchildGetsSceneRefreshed) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId kViewHolderId = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -485,7 +486,7 @@ TEST_F(ViewTest, ViewHolderGrandchildGetsSceneRefreshed) { } TEST_F(ViewTest, ViewLinksAfterViewHolderConnectsToScene) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -524,7 +525,7 @@ TEST_F(ViewTest, ViewLinksAfterViewHolderConnectsToScene) { } TEST_F(ViewTest, ViewStateChangeNotifiesViewHolder) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -552,7 +553,7 @@ TEST_F(ViewTest, ViewStateChangeNotifiesViewHolder) { } TEST_F(ViewTest, RenderStateAcrossManyFrames) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -585,7 +586,7 @@ TEST_F(ViewTest, RenderStateAcrossManyFrames) { } TEST_F(ViewTest, RenderStateFalseWhenViewDisconnects) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -617,7 +618,7 @@ TEST_F(ViewTest, RenderStateFalseWhenViewDisconnects) { } TEST_F(ViewTest, ViewHolderRenderWaitClearedWhenViewDestroyed) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -644,7 +645,7 @@ TEST_F(ViewTest, ViewHolderRenderWaitClearedWhenViewDestroyed) { } TEST_F(ViewTest, RenderSignalDoesntCrashWhenViewHolderDestroyed) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); const ResourceId view_holder_id = 1u; Apply(scenic::NewCreateViewHolderCmd( @@ -667,7 +668,7 @@ TEST_F(ViewTest, RenderSignalDoesntCrashWhenViewHolderDestroyed) { } TEST_F(ViewTest, RenderStateFalseWhenViewHolderDisconnectsFromScene) { - auto [view_token, view_holder_token] = scenic::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 5f1acbfc91585f5292f715bdf62d0e78ded3bbf4..5ca8807108288c18b8244b4921146e13587326bd 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); EmbeddedViewInfo info; diff --git a/garnet/public/rust/carnelian/examples/embedding.rs b/garnet/public/rust/carnelian/examples/embedding.rs index 5fb7ea860a70fed344de0baf8aa88b5299270623..1466dce98df7d1711d76404c11d013397cc9ad6f 100644 --- a/garnet/public/rust/carnelian/examples/embedding.rs +++ b/garnet/public/rust/carnelian/examples/embedding.rs @@ -11,7 +11,9 @@ 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::{EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, ViewTokenPair}; +use fuchsia_scenic::{ + new_view_token_pair, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, +}; use itertools::Itertools; use std::collections::BTreeMap; @@ -75,15 +77,15 @@ struct EmbeddingViewAssistant { impl EmbeddingViewAssistant { fn create_and_setup_view(&mut self, context: &ViewAssistantContext) -> Result<(), Error> { - let token_pair = ViewTokenPair::new()?; + let (view_token, view_holder_token) = new_view_token_pair()?; let view_provider = self.app.connect_to_service::<ViewProviderMarker>()?; - view_provider.create_view(token_pair.view_token.value, None, None)?; + view_provider.create_view(view_token.value, None, None)?; let holder_node = EntityNode::new(context.session.clone()); let view_holder = ViewHolder::new( context.session.clone(), - token_pair.view_holder_token, + 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 17cce6ad8002cc9ed75b29c089f40bad6e0f39e0..e5a9dc30fad292a6cd02edcf3b159c241f0f731d 100644 --- a/garnet/public/rust/fuchsia-scenic/src/lib.rs +++ b/garnet/public/rust/fuchsia-scenic/src/lib.rs @@ -5,9 +5,8 @@ #![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, @@ -22,6 +21,17 @@ 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 deleted file mode 100644 index 208a96ab33686d8cf06a2cae018ab506b97cabbb..0000000000000000000000000000000000000000 --- a/garnet/public/rust/fuchsia-scenic/src/view_token_pair.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 c900918c43cb95bb08f82b1f62cc6019e290f644..4c4660da4457ca974dd08d52e195f3adbb714100 100644 --- a/garnet/tests/e2e_input_tests/minimal_input_test.cc +++ b/garnet/tests/e2e_input_tests/minimal_input_test.cc @@ -2,6 +2,10 @@ // 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> @@ -10,20 +14,16 @@ #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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // Connect to Scenic, create a View. scenic_ = diff --git a/peridot/bin/basemgr/basemgr_impl.cc b/peridot/bin/basemgr/basemgr_impl.cc index 71d2bdd37eb3246026a6f78ea7ee58e52ad01a3f..3647824a77a322dcba67941f468696ef7f636aff 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 763d365cd25af0e606da7c241eca6618b34a0c92..9f0a8c3ac233aafa807d99a52f63c11d93f6ef17 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 36265dfa5ae6cb4da3fc792e1c18b56706bfa795..fcd461e8ea00394527c3c01afc557a14e889419a 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::{ - Circle, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, ViewTokenPair, + new_view_token_pair, Circle, EntityNode, Rectangle, SessionPtr, ShapeNode, ViewHolder, }; 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 token_pair = ViewTokenPair::new()?; + let (mut view_token, view_holder_token) = new_view_token_pair()?; let host_node = EntityNode::new(session.clone()); - let host_view_holder = ViewHolder::new(session.clone(), token_pair.view_holder_token, None); + let host_view_holder = ViewHolder::new(session.clone(), 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 token_pair.view_token, + &mut 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 9da59da02481788cf3e721b9307013f923e696de..4b56ef9f5d3b050969751204de2863c10601a3cf 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": "379efdac3f9e986cd4da7b87fc944f41", "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": "1d32d345d5e1746ada8a36d45b1ebf56" + "pkg/scenic_cpp/include/lib/ui/scenic/cpp/view_token_pair.h": "5891b46e01fcae095aeef0e8ff9b7398" } \ 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 f635c52420363ac2514a7baa5ee7e69900153478..5322f435cb357d264783b971cf4cc7ae84ee337e 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); // 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 3384bda8f85e5cf0fdfc803fb99c32aa756c6604..fa8b31cd7d8b5d1c99ccefe7460f3eeb2762c6d1 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 ViewTokenPair::New() { - ViewTokenPair token_pair; - - auto status = zx::eventpair::create(0u, &token_pair.view_token.value, - &token_pair.view_holder_token.value); +ViewTokenPair NewViewTokenPair() { + ViewTokenPair new_tokens; + auto status = zx::eventpair::create(0u, &new_tokens.first.value, + &new_tokens.second.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,11 +20,9 @@ ViewTokenPair ViewTokenPair::New() { // hit this, it means something is very abnormal. ZX_ASSERT(status == ZX_OK); - return token_pair; + return new_tokens; } -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 c9c838e78639297d7fa2a3f4d15fbb2b9198fc0a..b6054e00537b2a8978309ed18cae03d2a08ff985 100644 --- a/sdk/lib/ui/scenic/cpp/view_token_pair.h +++ b/sdk/lib/ui/scenic/cpp/view_token_pair.h @@ -7,18 +7,12 @@ #include <fuchsia/ui/views/cpp/fidl.h> #include <lib/zx/eventpair.h> +#include <utility> namespace scenic { -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; -}; +using ViewTokenPair = std::pair<fuchsia::ui::views::ViewToken, + fuchsia::ui::views::ViewHolderToken>; // 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 d3b9b81d8f7e7e53fae8a755d54c0b314ce9ed08..2a96cfbc8bfdd52625d8992f525c9438fdddc4d2 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 b3d5834938efd21b54486aa823e5cc5079411089..946dea757b76a827e88d3c8d2230a8ba91ca76d1 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); 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 c772b1622207786aba2c90ee7814f91d2fff3a6b..e84b89d4e68fb645b4861bb9e9d7ba902273a0e3 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::ViewTokenPair::New(); + auto [view_token, view_holder_token] = scenic::NewViewTokenPair(); player_->CreateView(std::move(view_token)); view_holder_token_ = std::move(view_holder_token); }