[scenic] Port skia_view examples to new BaseView
TEST=ran paint; jank; noodles; mediaplayer_skia
SCN-901 #comment
Change-Id: I712fbeaf0b41a48fb35322431321284f215a6b73
diff --git a/app/term/BUILD.gn b/app/term/BUILD.gn
index fc4e473..36fe440 100644
--- a/app/term/BUILD.gn
+++ b/app/term/BUILD.gn
@@ -24,17 +24,16 @@
]
deps = [
- "//sdk/fidl/fuchsia.fonts",
- "//sdk/fidl/fuchsia.math",
- "//sdk/fidl/fuchsia.ui.input",
- "//sdk/fidl/fuchsia.ui.scenic",
- "//sdk/fidl/fuchsia.ui.viewsv1",
"//garnet/public/lib/component/cpp",
- "//sdk/lib/fidl/cpp",
"//garnet/public/lib/fsl",
"//garnet/public/lib/fxl",
"//garnet/public/lib/ui/input/cpp",
- "//garnet/public/lib/ui/scenic/cpp",
+ "//sdk/fidl/fuchsia.fonts",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/fidl/fuchsia.ui.gfx",
+ "//sdk/fidl/fuchsia.ui.input",
+ "//sdk/lib/fidl/cpp",
+ "//sdk/lib/ui/scenic/cpp",
"//third_party/freetype2",
"//third_party/libteken",
"//third_party/skia",
@@ -50,7 +49,6 @@
}
package("term") {
-
deps = [
":bin",
]
diff --git a/app/term/app.cc b/app/term/app.cc
index 0f9ac7d..eba17c9 100644
--- a/app/term/app.cc
+++ b/app/term/app.cc
@@ -4,6 +4,8 @@
#include "topaz/app/term/app.h"
+#include <lib/ui/scenic/cpp/view_token_pair.h>
+
#include "examples/ui/lib/skia_font_loader.h"
#include "topaz/app/term/term_params.h"
@@ -26,12 +28,6 @@
[this](fidl::InterfaceRequest<fuchsia::ui::app::ViewProvider> request) {
bindings_.AddBinding(this, std::move(request));
});
-
- context_->outgoing().AddPublicService<fuchsia::ui::viewsv1::ViewProvider>(
- [this](
- fidl::InterfaceRequest<fuchsia::ui::viewsv1::ViewProvider> request) {
- old_bindings_.AddBinding(this, std::move(request));
- });
}
void App::CreateView(
@@ -43,7 +39,7 @@
scenic::ViewContext view_context = {
.session_and_listener_request =
scenic::CreateScenicSessionPtrAndListenerRequest(scenic.get()),
- .view_token = std::move(view_token),
+ .view_token2 = scenic::ToViewToken(std::move(view_token)),
.incoming_services = std::move(incoming_services),
.outgoing_services = std::move(outgoing_services),
.startup_context = context_.get(),
@@ -54,14 +50,6 @@
[this](ViewController* controller) { DestroyController(controller); }));
}
-void App::CreateView(
- fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
- view_owner_request,
- fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> view_services) {
- CreateView(zx::eventpair(view_owner_request.TakeChannel().release()),
- std::move(view_services), nullptr);
-}
-
void App::DestroyController(ViewController* controller) {
auto it = FindUniquePtr(controllers_.begin(), controllers_.end(), controller);
ZX_DEBUG_ASSERT(it != controllers_.end());
diff --git a/app/term/app.h b/app/term/app.h
index 26dfba2..400bc7a 100644
--- a/app/term/app.h
+++ b/app/term/app.h
@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <fuchsia/sys/cpp/fidl.h>
#include <fuchsia/ui/app/cpp/fidl.h>
-#include <fuchsia/ui/viewsv1/cpp/fidl.h>
+#include <lib/zx/eventpair.h>
#include "examples/ui/lib/skia_font_loader.h"
#include "topaz/app/term/term_params.h"
@@ -11,8 +12,7 @@
namespace term {
-class App : public fuchsia::ui::app::ViewProvider,
- public fuchsia::ui::viewsv1::ViewProvider {
+class App : public fuchsia::ui::app::ViewProvider {
public:
explicit App(TermParams params);
~App() = default;
@@ -24,12 +24,6 @@
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services)
override;
- // |fuchsia::ui::views1::ViewProvider|
- void CreateView(fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
- view_owner_request,
- fidl::InterfaceRequest<fuchsia::sys::ServiceProvider>
- view_services) override;
-
void DestroyController(ViewController* controller);
private:
@@ -39,7 +33,6 @@
TermParams params_;
std::unique_ptr<component::StartupContext> context_;
fidl::BindingSet<fuchsia::ui::app::ViewProvider> bindings_;
- fidl::BindingSet<fuchsia::ui::viewsv1::ViewProvider> old_bindings_;
std::vector<std::unique_ptr<ViewController>> controllers_;
};
diff --git a/app/term/meta/term.cmx b/app/term/meta/term.cmx
index b725eae..d150826 100644
--- a/app/term/meta/term.cmx
+++ b/app/term/meta/term.cmx
@@ -12,8 +12,7 @@
"fuchsia.process.Launcher",
"fuchsia.process.Resolver",
"fuchsia.tracelink.Registry",
- "fuchsia.ui.scenic.Scenic",
- "fuchsia.ui.viewsv1.ViewManager"
+ "fuchsia.ui.scenic.Scenic"
]
}
}
diff --git a/app/term/view_controller.cc b/app/term/view_controller.cc
index 0173b85..7fa0c8c 100644
--- a/app/term/view_controller.cc
+++ b/app/term/view_controller.cc
@@ -4,9 +4,9 @@
#include "topaz/app/term/view_controller.h"
-#include <unistd.h>
-
+#include <fuchsia/fonts/cpp/fidl.h>
#include <lib/async/default.h>
+#include <unistd.h>
#include <zircon/status.h>
#include "lib/fxl/logging.h"
@@ -83,11 +83,12 @@
if (argv.empty())
argv = {kShell};
- zx_status_t status = pty_.Run(argv,
- [this](const void* bytes, size_t num_bytes) {
- OnDataReceived(bytes, num_bytes);
- },
- [this] { OnCommandTerminated(); });
+ zx_status_t status = pty_.Run(
+ argv,
+ [this](const void* bytes, size_t num_bytes) {
+ OnDataReceived(bytes, num_bytes);
+ },
+ [this] { OnCommandTerminated(); });
if (status != ZX_OK) {
FXL_LOG(ERROR) << "Error starting command: " << status << " ("
<< zx_status_get_string(status) << ")";
@@ -123,7 +124,7 @@
}
void ViewController::OnPropertiesChanged(
- fuchsia::ui::viewsv1::ViewProperties old_properties) {
+ fuchsia::ui::gfx::ViewProperties old_properties) {
ComputeMetrics();
Resize();
}
@@ -132,8 +133,8 @@
if (!has_logical_size() || !regular_typeface_)
return;
- uint32_t columns = std::max(logical_size().width / advance_width_, 1.f);
- uint32_t rows = std::max(logical_size().height / line_height_, 1.f);
+ uint32_t columns = std::max(logical_size().x / advance_width_, 1.f);
+ uint32_t rows = std::max(logical_size().y / line_height_, 1.f);
TermModel::Size current = model_.GetSize();
if (current.columns != columns || current.rows != rows) {
model_.SetSize(TermModel::Size(rows, columns), false);
@@ -183,7 +184,8 @@
ch.foreground_color.blue));
canvas->drawSimpleText(&ch.code_point, sizeof(ch.code_point),
- SkTextEncoding::kUTF32, x, y + ascent_, fg_font, fg_paint);
+ SkTextEncoding::kUTF32, x, y + ascent_,
+ fg_font, fg_paint);
}
}
}
@@ -227,8 +229,7 @@
keypad_application_mode_ = application_mode;
}
-bool ViewController::OnInputEvent(fuchsia::ui::input::InputEvent event) {
- bool handled = false;
+void ViewController::OnInputEvent(fuchsia::ui::input::InputEvent event) {
if (event.is_keyboard()) {
const fuchsia::ui::input::KeyboardEvent& keyboard = event.keyboard();
if (keyboard.phase == fuchsia::ui::input::KeyboardEventPhase::PRESSED ||
@@ -245,7 +246,6 @@
Resize();
}
OnKeyPressed(std::move(event));
- handled = true;
}
} else if (event.is_focus()) {
const fuchsia::ui::input::FocusEvent& focus = event.focus();
@@ -256,9 +256,7 @@
} else {
InvalidateScene();
}
- handled = true;
}
- return handled;
}
void ViewController::OnKeyPressed(fuchsia::ui::input::InputEvent key_event) {
diff --git a/app/term/view_controller.h b/app/term/view_controller.h
index a899534..4d29a47 100644
--- a/app/term/view_controller.h
+++ b/app/term/view_controller.h
@@ -5,6 +5,8 @@
#ifndef TOPAZ_APP_TERM_VIEW_CONTROLLER_H_
#define TOPAZ_APP_TERM_VIEW_CONTROLLER_H_
+#include <fuchsia/images/cpp/fidl.h>
+#include <fuchsia/ui/gfx/cpp/fidl.h>
#include <lib/async/cpp/task.h>
#include <lib/fit/function.h>
@@ -31,14 +33,14 @@
ViewController& operator=(const ViewController&) = delete;
private:
- // |scenic::V1BaseView|
+ // |scenic::BaseView|
void OnPropertiesChanged(
- fuchsia::ui::viewsv1::ViewProperties old_properties) override;
+ fuchsia::ui::gfx::ViewProperties old_properties) override;
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
- bool OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnInputEvent(fuchsia::ui::input::InputEvent event) override;
- // |TermModel::Delegate|:
+ // |TermModel::Delegate|
void OnResponse(const void* buf, size_t size) override;
void OnSetKeypadMode(bool application_mode) override;
diff --git a/bin/ui/skottie_viewer/BUILD.gn b/bin/ui/skottie_viewer/BUILD.gn
index 8bcd3c2..cc8c658 100644
--- a/bin/ui/skottie_viewer/BUILD.gn
+++ b/bin/ui/skottie_viewer/BUILD.gn
@@ -28,18 +28,15 @@
deps = [
":skottie_loader",
- "//sdk/fidl/fuchsia.ui.app",
- "//sdk/fidl/fuchsia.ui.viewsv1",
"//garnet/public/lib/component/cpp",
- "//sdk/lib/fidl/cpp",
-
- # TODO(SCN-1193): Remove fostr dependency.
- "//garnet/public/lib/fostr/fidl/fuchsia.ui.scenic",
"//garnet/public/lib/fsl",
"//garnet/public/lib/ui/base_view/cpp",
- "//garnet/public/lib/ui/scenic/cpp",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/lib/fidl/cpp",
+ "//sdk/lib/ui/scenic/cpp",
"//third_party/skia/modules/skottie",
"//topaz/examples/ui/lib:skia_view",
+ "//zircon/public/fidl/fuchsia-mem",
"//zircon/public/lib/async-loop-cpp",
"//zircon/public/lib/trace-provider",
]
diff --git a/bin/ui/skottie_viewer/meta/skottie_viewer.cmx b/bin/ui/skottie_viewer/meta/skottie_viewer.cmx
index 63423bf..2982b4f 100644
--- a/bin/ui/skottie_viewer/meta/skottie_viewer.cmx
+++ b/bin/ui/skottie_viewer/meta/skottie_viewer.cmx
@@ -8,8 +8,7 @@
"fuchsia.sys.Launcher",
"fuchsia.tracelink.Registry",
"fuchsia.ui.policy.Presenter",
- "fuchsia.ui.scenic.Scenic",
- "fuchsia.ui.viewsv1.ViewManager"
+ "fuchsia.ui.scenic.Scenic"
]
}
}
diff --git a/bin/ui/skottie_viewer/view.cc b/bin/ui/skottie_viewer/view.cc
index 8bbb49f..7a51235 100644
--- a/bin/ui/skottie_viewer/view.cc
+++ b/bin/ui/skottie_viewer/view.cc
@@ -114,8 +114,8 @@
void View::Draw(SkCanvas* canvas) {
FXL_DCHECK(animation_);
- const auto rect = SkRect::MakeSize(
- SkSize::Make(logical_size().width, logical_size().height));
+ const auto rect =
+ SkRect::MakeSize(SkSize::Make(logical_size().x, logical_size().y));
SkAutoCanvasRestore acr(canvas, true);
animation_->render(canvas, &rect);
diff --git a/bin/ui/skottie_viewer/view.h b/bin/ui/skottie_viewer/view.h
index 7eab17e..b2c1491 100644
--- a/bin/ui/skottie_viewer/view.h
+++ b/bin/ui/skottie_viewer/view.h
@@ -5,6 +5,8 @@
#ifndef TOPAZ_BIN_UI_SKOTTIE_VIEWER_VIEW_H_
#define TOPAZ_BIN_UI_SKOTTIE_VIEWER_VIEW_H_
+#include <fuchsia/images/cpp/fidl.h>
+#include <fuchsia/mem/cpp/fidl.h>
#include <fuchsia/skia/skottie/cpp/fidl.h>
#include "examples/ui/lib/skia_view.h"
@@ -24,20 +26,20 @@
View(scenic::ViewContext view_context);
~View() override = default;
- // |fuchsia::skia::skottie::Loader|.
+ // |scenic::BaseView|
+ void OnSceneInvalidated(
+ fuchsia::images::PresentationInfo presentation_info) override;
+
+ // |fuchsia::skia::skottie::Loader|
virtual void Load(fuchsia::mem::Buffer payload,
fuchsia::skia::skottie::Options options,
LoadCallback callback) override;
- // |fuchsia::skia::skottie::Player|.
+ // |fuchsia::skia::skottie::Player|
virtual void Seek(float t) override;
virtual void Play() override;
virtual void Pause() override;
- // |scenic::V1BaseView|
- void OnSceneInvalidated(
- fuchsia::images::PresentationInfo presentation_info) override;
-
private:
fidl::BindingSet<fuchsia::skia::skottie::Loader> loader_bindings_;
fidl::Binding<fuchsia::skia::skottie::Player> player_binding_;
diff --git a/examples/media/vu_meter/BUILD.gn b/examples/media/vu_meter/BUILD.gn
index 07b620a..64508bd 100644
--- a/examples/media/vu_meter/BUILD.gn
+++ b/examples/media/vu_meter/BUILD.gn
@@ -12,9 +12,11 @@
]
deps = [
- "//sdk/fidl/fuchsia.media",
"//garnet/public/lib/media/audio",
"//garnet/public/lib/ui/base_view/cpp",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/fidl/fuchsia.media",
+ "//sdk/fidl/fuchsia.ui.input",
"//third_party/skia",
"//topaz/examples/ui/lib:skia_view",
"//zircon/public/lib/async-loop-cpp",
diff --git a/examples/media/vu_meter/meta/vu_meter.cmx b/examples/media/vu_meter/meta/vu_meter.cmx
index 592ce1f..5f100a6 100644
--- a/examples/media/vu_meter/meta/vu_meter.cmx
+++ b/examples/media/vu_meter/meta/vu_meter.cmx
@@ -9,8 +9,7 @@
"fuchsia.sys.Launcher",
"fuchsia.tracelink.Registry",
"fuchsia.ui.policy.Presenter",
- "fuchsia.ui.scenic.Scenic",
- "fuchsia.ui.viewsv1.ViewManager"
+ "fuchsia.ui.scenic.Scenic"
]
}
}
diff --git a/examples/media/vu_meter/vu_meter_view.cc b/examples/media/vu_meter/vu_meter_view.cc
index c8ba1f1..6c11cfd 100644
--- a/examples/media/vu_meter/vu_meter_view.cc
+++ b/examples/media/vu_meter/vu_meter_view.cc
@@ -42,13 +42,11 @@
});
}
-bool VuMeterView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
- bool handled = false;
+void VuMeterView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
if (event.is_pointer()) {
auto& pointer = event.pointer();
if (pointer.phase == fuchsia::ui::input::PointerEventPhase::DOWN) {
ToggleStartStop();
- handled = true;
}
} else if (event.is_keyboard()) {
auto& keyboard = event.keyboard();
@@ -56,18 +54,15 @@
switch (keyboard.hid_usage) {
case HID_USAGE_KEY_SPACE:
ToggleStartStop();
- handled = true;
break;
case HID_USAGE_KEY_Q:
Shutdown();
- handled = true;
break;
default:
break;
}
}
}
- return handled;
}
void VuMeterView::OnSceneInvalidated(
@@ -87,21 +82,21 @@
paint.setColor(SK_ColorCYAN);
canvas->drawCircle(
- logical_size().width / 3.0f, logical_size().height / 2,
- (fast_left_.current() * logical_size().width / 2) / kVuFullWidth, paint);
+ logical_size().x / 3.0f, logical_size().y / 2,
+ (fast_left_.current() * logical_size().x / 2) / kVuFullWidth, paint);
canvas->drawCircle(
- 2.0f * logical_size().width / 3.0f, logical_size().height / 2,
- (fast_right_.current() * logical_size().width / 2) / kVuFullWidth, paint);
+ 2.0f * logical_size().x / 3.0f, logical_size().y / 2,
+ (fast_right_.current() * logical_size().x / 2) / kVuFullWidth, paint);
paint.setColor(SK_ColorWHITE);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(3));
canvas->drawCircle(
- logical_size().width / 3.0f, logical_size().height / 2,
- (slow_left_.current() * logical_size().width / 2) / kVuFullWidth, paint);
+ logical_size().x / 3.0f, logical_size().y / 2,
+ (slow_left_.current() * logical_size().x / 2) / kVuFullWidth, paint);
canvas->drawCircle(
- 2.0f * logical_size().width / 3.0f, logical_size().height / 2,
- (slow_right_.current() * logical_size().width / 2) / kVuFullWidth, paint);
+ 2.0f * logical_size().x / 3.0f, logical_size().y / 2,
+ (slow_right_.current() * logical_size().x / 2) / kVuFullWidth, paint);
}
void VuMeterView::SendCaptureRequest() {
diff --git a/examples/media/vu_meter/vu_meter_view.h b/examples/media/vu_meter/vu_meter_view.h
index a85b86f..613eef8 100644
--- a/examples/media/vu_meter/vu_meter_view.h
+++ b/examples/media/vu_meter/vu_meter_view.h
@@ -8,7 +8,9 @@
#include <memory>
#include <queue>
+#include <fuchsia/images/cpp/fidl.h>
#include <fuchsia/media/cpp/fidl.h>
+#include <fuchsia/ui/input/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/fzl/vmo-mapper.h>
@@ -48,10 +50,10 @@
float current_ = 0;
};
- // |scenic::V1BaseView|
+ // |scenic::BaseView|
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
- bool OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnInputEvent(fuchsia::ui::input::InputEvent event) override;
// Draws the UI.
void DrawContent(SkCanvas* canvas);
diff --git a/examples/mediaplayer/mediaplayer_skia/BUILD.gn b/examples/mediaplayer/mediaplayer_skia/BUILD.gn
index 5ad9df4..5f846cc 100644
--- a/examples/mediaplayer/mediaplayer_skia/BUILD.gn
+++ b/examples/mediaplayer/mediaplayer_skia/BUILD.gn
@@ -16,12 +16,18 @@
]
deps = [
- "//sdk/fidl/fuchsia.media",
- "//sdk/fidl/fuchsia.mediaplayer",
"//garnet/public/lib/fsl",
"//garnet/public/lib/media/timeline",
"//garnet/public/lib/ui/base_view/cpp",
"//garnet/public/lib/url",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/fidl/fuchsia.math",
+ "//sdk/fidl/fuchsia.media",
+ "//sdk/fidl/fuchsia.mediaplayer",
+ "//sdk/fidl/fuchsia.ui.gfx",
+ "//sdk/fidl/fuchsia.ui.input",
+ "//sdk/fidl/fuchsia.ui.scenic",
+ "//sdk/lib/ui/scenic/cpp",
"//third_party/skia",
"//topaz/examples/ui/lib:skia_view",
"//zircon/public/lib/async-loop-cpp",
diff --git a/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.cc b/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.cc
index 9589b94..acdb361 100644
--- a/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.cc
+++ b/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.cc
@@ -16,6 +16,7 @@
#include "lib/fxl/logging.h"
#include "lib/media/timeline/timeline.h"
#include "lib/media/timeline/type_converters.h"
+#include "lib/ui/scenic/cpp/view_token_pair.h"
#include "lib/url/gurl.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h"
@@ -24,8 +25,6 @@
namespace {
-constexpr uint32_t kVideoChildKey = 0u;
-
constexpr int32_t kDefaultWidth = 640;
constexpr int32_t kDefaultHeight = 100;
@@ -54,8 +53,7 @@
MediaPlayerView::MediaPlayerView(scenic::ViewContext view_context,
async::Loop* loop,
const MediaPlayerParams& params)
- : V1BaseView(std::move(view_context), "Media Player"),
-
+ : BaseView(std::move(view_context), "Media Player"),
loop_(loop),
background_node_(session()),
controls_widget_(session()) {
@@ -65,9 +63,8 @@
scenic::Material background_material(session());
background_material.SetColor(0x1a, 0x23, 0x7e, 0xff); // Indigo 900
background_node_.SetMaterial(background_material);
- parent_node().AddChild(background_node_);
-
- parent_node().AddChild(controls_widget_);
+ root_node().AddChild(background_node_);
+ root_node().AddChild(controls_widget_);
// We start with a non-zero size so we get a progress bar regardless of
// whether we get video.
@@ -83,19 +80,14 @@
HandleStatusChanged(status);
};
- zx::eventpair video_view_owner_token, video_view_token;
- if (zx::eventpair::create(0u, &video_view_owner_token, &video_view_token) !=
- ZX_OK)
- FXL_NOTREACHED() << "failed to create tokens.";
- player_->CreateView2(std::move(video_view_token));
+ auto view_tokens = scenic::NewViewTokenPair();
- zx::eventpair video_host_import_token;
- video_host_node_.reset(new scenic::EntityNode(session()));
- video_host_node_->ExportAsRequest(&video_host_import_token);
- parent_node().AddChild(*video_host_node_);
- GetViewContainer()->AddChild2(kVideoChildKey,
- std::move(video_view_owner_token),
- std::move(video_host_import_token));
+ player_->CreateView2(std::move(view_tokens.first.value));
+
+ video_host_view_holder_ = std::make_unique<scenic::ViewHolder>(
+ session(), std::move(view_tokens.second), "Player");
+ video_host_node_ = std::make_unique<scenic::EntityNode>(session());
+ video_host_node_->Attach(*video_host_view_holder_);
if (!params.url().empty()) {
url::GURL url = url::GURL(params.url());
@@ -116,10 +108,7 @@
prev_frame_time_ = frame_time_;
}
-MediaPlayerView::~MediaPlayerView() {}
-
-bool MediaPlayerView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
- bool handled = false;
+void MediaPlayerView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
if (event.is_pointer()) {
const auto& pointer = event.pointer();
if (pointer.phase == fuchsia::ui::input::PointerEventPhase::DOWN) {
@@ -134,8 +123,6 @@
player_->Play();
}
}
-
- handled = true;
}
} else if (event.is_keyboard()) {
auto& keyboard = event.keyboard();
@@ -143,23 +130,59 @@
switch (keyboard.hid_usage) {
case HID_USAGE_KEY_SPACE:
TogglePlayPause();
- handled = true;
break;
case HID_USAGE_KEY_Q:
loop_->Quit();
- handled = true;
break;
default:
break;
}
}
}
+}
- return handled;
+void MediaPlayerView::OnScenicEvent(fuchsia::ui::scenic::Event event) {
+ switch (event.Which()) {
+ case fuchsia::ui::scenic::Event::Tag::kGfx:
+ switch (event.gfx().Which()) {
+ case fuchsia::ui::gfx::Event::Tag::kViewConnected: {
+ FXL_DCHECK(video_host_view_holder_ &&
+ event.gfx().view_connected().view_holder_id ==
+ video_host_view_holder_->id());
+
+ root_node().AddChild(*video_host_node_);
+ Layout();
+ break;
+ }
+ case fuchsia::ui::gfx::Event::Tag::kViewDisconnected: {
+ FXL_DCHECK(video_host_view_holder_ &&
+ event.gfx().view_disconnected().view_holder_id ==
+ video_host_view_holder_->id());
+ FXL_LOG(ERROR) << "Video view died unexpectedly";
+
+ video_host_node_->Detach();
+ video_host_node_.reset();
+ video_host_view_holder_.reset();
+ Layout();
+ break;
+ }
+ default:
+ FXL_LOG(WARNING)
+ << "MediaPlayerView::OnScenicEvent: Got an unhandled GFX "
+ "event.";
+ break;
+ }
+ break;
+ default:
+ FXL_DCHECK(false)
+ << "MediaPlayerView::OnScenicEvent: Got an unhandled Scenic "
+ "event.";
+ break;
+ }
}
void MediaPlayerView::OnPropertiesChanged(
- fuchsia::ui::viewsv1::ViewProperties old_properties) {
+ fuchsia::ui::gfx::ViewProperties old_properties) {
Layout();
}
@@ -168,19 +191,17 @@
return;
// Make the background fill the space.
- scenic::Rectangle background_shape(session(), logical_size().width,
- logical_size().height);
+ scenic::Rectangle background_shape(session(), logical_size().x,
+ logical_size().y);
background_node_.SetShape(background_shape);
- background_node_.SetTranslationRH(logical_size().width * .5f,
- logical_size().height * .5f,
- -kBackgroundElevation);
+ background_node_.SetTranslationRH(
+ logical_size().x * .5f, logical_size().y * .5f, -kBackgroundElevation);
// Compute maximum size of video content after reserving space
// for decorations.
fuchsia::math::SizeF max_content_size;
- max_content_size.width = logical_size().width - kMargin * 2;
- max_content_size.height =
- logical_size().height - kControlsHeight - kMargin * 3;
+ max_content_size.width = logical_size().x - kMargin * 2;
+ max_content_size.height = logical_size().y - kControlsHeight - kMargin * 3;
// Shrink video to fit if needed.
uint32_t video_width =
@@ -203,8 +224,8 @@
fuchsia::math::RectF ui_rect;
ui_rect.width = content_rect_.width;
ui_rect.height = content_rect_.height + kControlsHeight + kMargin;
- ui_rect.x = (logical_size().width - ui_rect.width) / 2;
- ui_rect.y = (logical_size().height - ui_rect.height) / 2;
+ ui_rect.x = (logical_size().x - ui_rect.width) / 2;
+ ui_rect.y = (logical_size().y - ui_rect.height) / 2;
// Position the video.
content_rect_.x = ui_rect.x;
@@ -224,12 +245,39 @@
progress_bar_rect_.height = controls_rect_.height;
// Ask the view to fill the space.
- fuchsia::ui::viewsv1::ViewProperties view_properties;
- view_properties.view_layout = fuchsia::ui::viewsv1::ViewLayout::New();
- view_properties.view_layout->size.width = content_rect_.width;
- view_properties.view_layout->size.height = content_rect_.height;
- GetViewContainer()->SetChildProperties(
- kVideoChildKey, fidl::MakeOptional(std::move(view_properties)));
+ if (video_host_view_holder_) {
+ fuchsia::ui::gfx::ViewProperties view_properties{
+ .bounding_box =
+ fuchsia::ui::gfx::BoundingBox{
+ .min =
+ fuchsia::ui::gfx::vec3{
+ .x = 0.f,
+ .y = 0.f,
+ .z = 0.f,
+ },
+ .max =
+ fuchsia::ui::gfx::vec3{
+ .x = content_rect_.width,
+ .y = content_rect_.height,
+ .z = 0.f,
+ },
+ },
+ .inset_from_min =
+ fuchsia::ui::gfx::vec3{
+ .x = 0.f,
+ .y = 0.f,
+ .z = 0.f,
+ },
+ .inset_from_max =
+ fuchsia::ui::gfx::vec3{
+ .x = 0.f,
+ .y = 0.f,
+ .z = 0.f,
+ },
+ .focus_change = false,
+ };
+ video_host_view_holder_->SetViewProperties(view_properties);
+ }
InvalidateScene();
}
@@ -273,25 +321,6 @@
}
}
-void MediaPlayerView::OnChildAttached(
- uint32_t child_key, fuchsia::ui::viewsv1::ViewInfo child_view_info) {
- FXL_DCHECK(child_key == kVideoChildKey);
-
- parent_node().AddChild(*video_host_node_);
- Layout();
-}
-
-void MediaPlayerView::OnChildUnavailable(uint32_t child_key) {
- FXL_DCHECK(child_key == kVideoChildKey);
- FXL_LOG(ERROR) << "Video view died unexpectedly";
-
- video_host_node_->Detach();
- video_host_node_.reset();
-
- GetViewContainer()->RemoveChild(child_key, nullptr);
- Layout();
-}
-
void MediaPlayerView::DrawControls(SkCanvas* canvas, const SkISize& size) {
canvas->clear(SK_ColorBLACK);
diff --git a/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.h b/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.h
index b3a8e85..031bcf4 100644
--- a/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.h
+++ b/examples/mediaplayer/mediaplayer_skia/mediaplayer_view.h
@@ -8,38 +8,46 @@
#include <memory>
#include <queue>
+#include <fuchsia/images/cpp/fidl.h>
+#include <fuchsia/math/cpp/fidl.h>
#include <fuchsia/media/cpp/fidl.h>
#include <fuchsia/mediaplayer/cpp/fidl.h>
+#include <fuchsia/ui/gfx/cpp/fidl.h>
+#include <fuchsia/ui/input/cpp/fidl.h>
+#include <fuchsia/ui/scenic/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include "examples/ui/lib/host_canvas_cycler.h"
#include "lib/component/cpp/startup_context.h"
#include "lib/fxl/macros.h"
#include "lib/media/timeline/timeline_function.h"
-#include "lib/ui/base_view/cpp/v1_base_view.h"
+#include "lib/ui/base_view/cpp/base_view.h"
#include "mediaplayer_params.h"
namespace examples {
-class MediaPlayerView : public scenic::V1BaseView {
+class MediaPlayerView : public scenic::BaseView {
public:
MediaPlayerView(scenic::ViewContext view_context, async::Loop* loop,
const MediaPlayerParams& params);
- ~MediaPlayerView() override;
+ ~MediaPlayerView() override = default;
private:
enum class State { kPaused, kPlaying, kEnded };
- // |scenic::V1BaseView|
+ // |scenic::SessionListener|
+ void OnScenicError(std::string error) override {
+ FXL_LOG(ERROR) << "Scenic Error " << error;
+ }
+
+ // |scenic::BaseView|
void OnPropertiesChanged(
- fuchsia::ui::viewsv1::ViewProperties old_properties) override;
+ fuchsia::ui::gfx::ViewProperties old_properties) override;
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
- void OnChildAttached(uint32_t child_key,
- fuchsia::ui::viewsv1::ViewInfo child_view_info) override;
- void OnChildUnavailable(uint32_t child_key) override;
- bool OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnScenicEvent(fuchsia::ui::scenic::Event) override;
// Perform a layout of the UI elements.
void Layout();
@@ -71,6 +79,7 @@
scenic::ShapeNode background_node_;
scenic::skia::HostCanvasCycler controls_widget_;
std::unique_ptr<scenic::EntityNode> video_host_node_;
+ std::unique_ptr<scenic::ViewHolder> video_host_view_holder_;
fuchsia::mediaplayer::PlayerPtr player_;
fuchsia::math::Size video_size_;
diff --git a/examples/mediaplayer/mediaplayer_skia/meta/mediaplayer_skia.cmx b/examples/mediaplayer/mediaplayer_skia/meta/mediaplayer_skia.cmx
index e68f361..6ab93ba 100644
--- a/examples/mediaplayer/mediaplayer_skia/meta/mediaplayer_skia.cmx
+++ b/examples/mediaplayer/mediaplayer_skia/meta/mediaplayer_skia.cmx
@@ -11,8 +11,7 @@
"fuchsia.fonts.Provider",
"fuchsia.mediaplayer.Player",
"fuchsia.tracelink.Registry",
- "fuchsia.ui.scenic.Scenic",
- "fuchsia.ui.viewsv1.ViewManager"
+ "fuchsia.ui.scenic.Scenic"
]
}
}
diff --git a/examples/ui/jank/BUILD.gn b/examples/ui/jank/BUILD.gn
index 55b76c0..fb8afa8 100644
--- a/examples/ui/jank/BUILD.gn
+++ b/examples/ui/jank/BUILD.gn
@@ -14,12 +14,12 @@
]
deps = [
- "//sdk/fidl/fuchsia.ui.app",
- "//sdk/fidl/fuchsia.ui.scenic",
- "//sdk/fidl/fuchsia.ui.viewsv1",
- "//sdk/lib/fidl/cpp",
"//garnet/public/lib/fxl",
"//garnet/public/lib/ui/base_view/cpp",
+ "//sdk/fidl/fuchsia.fonts",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/fidl/fuchsia.ui.input",
+ "//sdk/lib/fidl/cpp",
"//third_party/skia",
"//topaz/examples/ui/lib:skia_fonts",
"//topaz/examples/ui/lib:skia_view",
diff --git a/examples/ui/jank/jank_view.cc b/examples/ui/jank/jank_view.cc
index 4c14eba..6d49f95 100644
--- a/examples/ui/jank/jank_view.cc
+++ b/examples/ui/jank/jank_view.cc
@@ -93,12 +93,12 @@
textPaint.setColor(SK_ColorBLACK);
textPaint.setAntiAlias(true);
canvas->drawSimpleText(label, strlen(label), kUTF8_SkTextEncoding,
- bounds.centerX() - textBounds.centerX(),
- bounds.centerY() - textBounds.centerY(),
- textFont, textPaint);
+ bounds.centerX() - textBounds.centerX(),
+ bounds.centerY() - textBounds.centerY(), textFont,
+ textPaint);
}
-bool JankView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
+void JankView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
if (event.is_pointer()) {
const fuchsia::ui::input::PointerEvent& pointer = event.pointer();
if (pointer.phase == fuchsia::ui::input::PointerEventPhase::DOWN) {
@@ -110,11 +110,10 @@
size_t(index) < sizeof(kButtons) / sizeof(kButtons[0]) &&
y < (kButtonHeight + kMargin) * (index + 1))
OnClick(kButtons[index]);
- return true;
+ return;
}
}
}
- return false;
}
void JankView::OnClick(const Button& button) {
diff --git a/examples/ui/jank/jank_view.h b/examples/ui/jank/jank_view.h
index 6d0a86f..d2cb042 100644
--- a/examples/ui/jank/jank_view.h
+++ b/examples/ui/jank/jank_view.h
@@ -5,8 +5,9 @@
#ifndef TOPAZ_EXAMPLES_UI_JANK_JANK_VIEW_H_
#define TOPAZ_EXAMPLES_UI_JANK_JANK_VIEW_H_
-#include "examples/ui/lib/skia_font_loader.h"
-#include "examples/ui/lib/skia_view.h"
+#include <fuchsia/fonts/cpp/fidl.h>
+#include <fuchsia/images/cpp/fidl.h>
+#include <fuchsia/ui/input/cpp/fidl.h>
#include "lib/fxl/macros.h"
#include "lib/fxl/time/time_point.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -15,6 +16,9 @@
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkTypeface.h"
+#include "examples/ui/lib/skia_font_loader.h"
+#include "examples/ui/lib/skia_view.h"
+
namespace examples {
class JankView : public scenic::SkiaView {
@@ -37,10 +41,10 @@
static const Button kButtons[];
- // |scenic::V1BaseView|
+ // |scenic::BaseView|
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
- bool OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnInputEvent(fuchsia::ui::input::InputEvent event) override;
void DrawContent(SkCanvas* canvas);
void DrawButton(SkCanvas* canvas, const char* label, const SkRect& bounds);
diff --git a/examples/ui/lib/BUILD.gn b/examples/ui/lib/BUILD.gn
index 2ccfe76..aafb1c9 100644
--- a/examples/ui/lib/BUILD.gn
+++ b/examples/ui/lib/BUILD.gn
@@ -18,7 +18,7 @@
public_deps = [
"//garnet/public/lib/fxl",
- "//garnet/public/lib/ui/scenic/cpp",
+ "//sdk/lib/ui/scenic/cpp",
"//third_party/skia",
]
@@ -46,8 +46,8 @@
deps = [
":skia_type_converters",
":skia_vmo",
- "//sdk/fidl/fuchsia.fonts",
"//garnet/public/lib/fxl",
+ "//sdk/fidl/fuchsia.fonts",
"//third_party/skia",
]
@@ -61,8 +61,8 @@
]
public_deps = [
- "//sdk/fidl/fuchsia.math",
"//garnet/public/lib/fsl",
+ "//sdk/fidl/fuchsia.math",
"//third_party/skia",
]
diff --git a/examples/ui/lib/skia_view.cc b/examples/ui/lib/skia_view.cc
index 6fcae12..504ad08 100644
--- a/examples/ui/lib/skia_view.cc
+++ b/examples/ui/lib/skia_view.cc
@@ -7,24 +7,21 @@
namespace scenic {
SkiaView::SkiaView(scenic::ViewContext view_context, const std::string& label)
- : V1BaseView(std::move(view_context), label), canvas_cycler_(session()) {
- parent_node().AddChild(canvas_cycler_);
+ : BaseView(std::move(view_context), label), canvas_cycler_(session()) {
+ root_node().AddChild(canvas_cycler_);
}
-SkiaView::~SkiaView() = default;
-
SkCanvas* SkiaView::AcquireCanvas() {
if (!has_logical_size() || !has_metrics())
return nullptr;
- SkCanvas* canvas =
- canvas_cycler_.AcquireCanvas(logical_size().width, logical_size().height,
- metrics().scale_x, metrics().scale_y);
+ SkCanvas* canvas = canvas_cycler_.AcquireCanvas(
+ logical_size().x, logical_size().y, metrics().scale_x, metrics().scale_y);
if (!canvas)
return canvas;
- canvas_cycler_.SetTranslationRH(logical_size().width * .5f,
- logical_size().height * .5f, 0.f);
+ canvas_cycler_.SetTranslationRH(logical_size().x * .5f,
+ logical_size().y * .5f, 0.f);
return canvas;
}
diff --git a/examples/ui/lib/skia_view.h b/examples/ui/lib/skia_view.h
index 293e8dd..906e82a 100644
--- a/examples/ui/lib/skia_view.h
+++ b/examples/ui/lib/skia_view.h
@@ -6,17 +6,18 @@
#define TOPAZ_EXAMPLES_UI_LIB_SKIA_VIEW_H_
#include "examples/ui/lib/host_canvas_cycler.h"
+#include "lib/fxl/logging.h"
#include "lib/fxl/macros.h"
-#include "lib/ui/base_view/cpp/v1_base_view.h"
+#include "lib/ui/base_view/cpp/base_view.h"
namespace scenic {
// Abstract base class for views which use Skia software rendering to a
// single full-size surface.
-class SkiaView : public scenic::V1BaseView {
+class SkiaView : public scenic::BaseView {
public:
SkiaView(scenic::ViewContext view_context, const std::string& label);
- ~SkiaView() override;
+ ~SkiaView() override = default;
// Acquires a canvas for rendering.
// At most one canvas can be acquired at a time.
@@ -33,6 +34,12 @@
// Sets the view's content texture to be backed by the canvas.
void ReleaseAndSwapCanvas();
+ protected:
+ // |scenic::SessionListener|
+ void OnScenicError(std::string error) override {
+ FXL_LOG(ERROR) << "Scenic Error " << error;
+ }
+
private:
scenic::skia::HostCanvasCycler canvas_cycler_;
diff --git a/examples/ui/noodles/BUILD.gn b/examples/ui/noodles/BUILD.gn
index 3edcc48..12799a6 100644
--- a/examples/ui/noodles/BUILD.gn
+++ b/examples/ui/noodles/BUILD.gn
@@ -14,13 +14,10 @@
]
deps = [
- "//sdk/fidl/fuchsia.ui.app",
- "//sdk/fidl/fuchsia.ui.scenic",
- "//sdk/fidl/fuchsia.ui.viewsv1",
- "//sdk/lib/fidl/cpp",
- "//garnet/public/lib/fsl",
"//garnet/public/lib/fxl",
"//garnet/public/lib/ui/base_view/cpp",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/lib/fidl/cpp",
"//third_party/skia",
"//topaz/examples/ui/lib:skia_view",
"//zircon/public/lib/async-loop-cpp",
diff --git a/examples/ui/noodles/noodles_view.cc b/examples/ui/noodles/noodles_view.cc
index acb10d8..9134a01 100644
--- a/examples/ui/noodles/noodles_view.cc
+++ b/examples/ui/noodles/noodles_view.cc
@@ -69,8 +69,8 @@
canvas->clear(SK_ColorBLACK);
- double cx = logical_size().width * 0.5;
- double cy = logical_size().height * 0.5;
+ double cx = logical_size().x * 0.5;
+ double cy = logical_size().y * 0.5;
canvas->translate(cx, cy);
for (int i = 0; i < count; i++, phase += 0.1) {
diff --git a/examples/ui/noodles/noodles_view.h b/examples/ui/noodles/noodles_view.h
index 2423404f..7103f89 100644
--- a/examples/ui/noodles/noodles_view.h
+++ b/examples/ui/noodles/noodles_view.h
@@ -5,6 +5,7 @@
#ifndef TOPAZ_EXAMPLES_UI_NOODLES_NOODLES_VIEW_H_
#define TOPAZ_EXAMPLES_UI_NOODLES_NOODLES_VIEW_H_
+#include <fuchsia/images/cpp/fidl.h>
#include "examples/ui/lib/skia_view.h"
#include "lib/fxl/macros.h"
@@ -21,7 +22,7 @@
~NoodlesView() override = default;
private:
- // |scenic::V1BaseView|
+ // |scenic::BaseView|
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
diff --git a/examples/ui/paint/BUILD.gn b/examples/ui/paint/BUILD.gn
index 7544cfa..86caef0 100644
--- a/examples/ui/paint/BUILD.gn
+++ b/examples/ui/paint/BUILD.gn
@@ -14,13 +14,11 @@
]
deps = [
- "//sdk/fidl/fuchsia.ui.app",
- "//sdk/fidl/fuchsia.ui.scenic",
- "//sdk/fidl/fuchsia.ui.viewsv1",
- "//sdk/lib/fidl/cpp",
- "//garnet/public/lib/fsl",
"//garnet/public/lib/fxl",
"//garnet/public/lib/ui/base_view/cpp",
+ "//sdk/fidl/fuchsia.images",
+ "//sdk/fidl/fuchsia.ui.input",
+ "//sdk/lib/fidl/cpp",
"//third_party/skia",
"//topaz/examples/ui/lib:skia_view",
"//zircon/public/lib/async-loop-cpp",
diff --git a/examples/ui/paint/paint_view.cc b/examples/ui/paint/paint_view.cc
index 7727e63..ff90099 100644
--- a/examples/ui/paint/paint_view.cc
+++ b/examples/ui/paint/paint_view.cc
@@ -63,8 +63,7 @@
return path;
}
-bool PaintView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
- bool handled = false;
+void PaintView::OnInputEvent(fuchsia::ui::input::InputEvent event) {
if (event.is_pointer()) {
const fuchsia::ui::input::PointerEvent& pointer = event.pointer();
uint32_t pointer_id = pointer.device_id * 32 + pointer.pointer_id;
@@ -82,14 +81,12 @@
}
points_.at(pointer_id).push_back(SkPoint::Make(pointer.x, pointer.y));
}
- handled = true;
break;
case fuchsia::ui::input::PointerEventPhase::UP:
// Path is done, add it to the list of paths and reset the list of
// points
paths_.push_back(CurrentPath(pointer_id));
points_.erase(pointer_id);
- handled = true;
break;
default:
break;
@@ -99,12 +96,10 @@
if (keyboard.hid_usage == HID_USAGE_KEY_ESC) {
// clear
paths_.clear();
- handled = true;
}
}
InvalidateScene();
- return handled;
}
} // namespace examples
diff --git a/examples/ui/paint/paint_view.h b/examples/ui/paint/paint_view.h
index 8359764..942600e 100644
--- a/examples/ui/paint/paint_view.h
+++ b/examples/ui/paint/paint_view.h
@@ -5,14 +5,16 @@
#ifndef TOPAZ_EXAMPLES_UI_PAINT_PAINT_VIEW_H_
#define TOPAZ_EXAMPLES_UI_PAINT_PAINT_VIEW_H_
+#include <fuchsia/images/cpp/fidl.h>
+#include <fuchsia/ui/input/cpp/fidl.h>
#include <map>
#include <vector>
-
-#include "examples/ui/lib/skia_view.h"
#include "lib/fxl/macros.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPath.h"
+#include "examples/ui/lib/skia_view.h"
+
namespace examples {
class PaintView : public scenic::SkiaView {
@@ -21,10 +23,10 @@
~PaintView() override = default;
private:
- // |scenic::V1BaseView|
+ // |scenic::BaseView|
void OnSceneInvalidated(
fuchsia::images::PresentationInfo presentation_info) override;
- bool OnInputEvent(fuchsia::ui::input::InputEvent event) override;
+ void OnInputEvent(fuchsia::ui::input::InputEvent event) override;
void DrawContent(SkCanvas* canvas);
SkPath CurrentPath(uint32_t pointer_id);