blob: 5979e35ff042dec9ee8aa19e88ecb87dea8b1c93 [file] [log] [blame]
// Copyright 2018 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.
#include <fuchsia/ui/gfx/cpp/fidl.h>
#include <fuchsia/ui/policy/cpp/fidl.h>
#include <fuchsia/ui/scenic/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/ui/scenic/cpp/resources.h>
#include <lib/ui/scenic/cpp/session.h>
#include <lib/zx/eventpair.h>
namespace simplest_embedder {
// This is a |Presenter| that is used to present a ShadertoyEmbedderView. For
// simplicity we don't run it in a separate process and connect to it via FIDL.
// Instead, the example directly creates a pair of tokens that are used to
// create a ViewHolder/View pair; the ExamplePresenter gets one and the
// ShadertoyEmbedderView gets the other. See main().
// NB: This Presenter is currently *not* set up to receive input events from
// Zircon. It is the Presenter's responsibility to convey input events to
// Scenic for further dispatch. See HelloInput for an example of how to do it.
class ExamplePresenter : private fuchsia::ui::policy::Presenter {
ExamplePresenter(fuchsia::ui::scenic::Scenic* scenic);
~ExamplePresenter() = default;
// |Presenter|
void PresentView(fuchsia::ui::views::ViewHolderToken view_holder_token,
presentation_request) override;
void HACK_SetRendererParams(
bool enable_clipping,
::std::vector<::fuchsia::ui::gfx::RendererParam> params) override{};
void Init(float width, float height);
class Presentation {
Presentation(scenic::Session* session,
fuchsia::ui::views::ViewHolderToken view_holder_token);
void SetSize(float width, float height);
const scenic::Layer& layer() const { return layer_; }
scenic::Layer layer_;
scenic::EntityNode view_holder_node_;
scenic::ViewHolder view_holder_;
void MaybeSetPresentationSize();
void ScenicSessionPresent();
scenic::Session session_;
std::unique_ptr<scenic::DisplayCompositor> compositor_;
scenic::LayerStack layers_;
std::unique_ptr<Presentation> presentation_;
float width_ = 0.f;
float height_ = 0.f;
} // namespace simplest_embedder