Sanjay Chouksey e9edf32d40
Add PlatformView support for Fuchsia (#19132)
* Add PlatformView support for Fuchsia

This change allows embedding views provided by fuchsia components into
a flutter app running on Fuchsia. This conforms to Flutters idiomatic
approach to composite PlatformView alongside other rendered layers.

This uses the `view embedder` infrastructure to allow
`PlatformViewLayer`
to hold fuchsia views. This is meant to eventually supplant the legacy
`SceneHost` and `ChildViewLayer` mechanism to embed fuchsia `ChildView`.

To see how this will get used check out:
https://fuchsia-review.googlesource.com/c/experiences/+/398536/6/examples/hello_experiences/lib/fuchsia_view.dart

Includes unittests for platform_view.cc.

Note: This change has no impact on the legacy code to embed fuchsia
views.

* Rename OnCreateViewMethodCall to OnCreateView

Same for OnDestroyViewMethodCall to OnDestroyView

Co-authored-by: Sanjay Chouksey <sanjayc@google.com>
2020-06-25 16:27:39 -07:00

79 lines
2.1 KiB
C++

// Copyright 2013 The Flutter 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 "surface.h"
#include <fcntl.h>
#include <lib/fdio/watcher.h>
#include <unistd.h>
#include "flutter/fml/unique_fd.h"
namespace flutter_runner {
Surface::Surface(std::string debug_label,
flutter::ExternalViewEmbedder* view_embedder)
: debug_label_(std::move(debug_label)), view_embedder_(view_embedder) {}
Surface::~Surface() = default;
// |flutter::Surface|
bool Surface::IsValid() {
return valid_;
}
// |flutter::Surface|
std::unique_ptr<flutter::SurfaceFrame> Surface::AcquireFrame(
const SkISize& size) {
return std::make_unique<flutter::SurfaceFrame>(
nullptr, true,
[](const flutter::SurfaceFrame& surface_frame, SkCanvas* canvas) {
return true;
});
}
// |flutter::Surface|
GrContext* Surface::GetContext() {
return nullptr;
}
static zx_status_t DriverWatcher(int dirfd,
int event,
const char* fn,
void* cookie) {
if (event == WATCH_EVENT_ADD_FILE && !strcmp(fn, "000")) {
return ZX_ERR_STOP;
}
return ZX_OK;
}
bool Surface::CanConnectToDisplay() {
constexpr char kGpuDriverClass[] = "/dev/class/gpu";
fml::UniqueFD fd(open(kGpuDriverClass, O_DIRECTORY | O_RDONLY));
if (fd.get() < 0) {
FML_DLOG(ERROR) << "Failed to open " << kGpuDriverClass;
return false;
}
zx_status_t status = fdio_watch_directory(
fd.get(), DriverWatcher, zx_deadline_after(ZX_SEC(5)), nullptr);
return status == ZX_ERR_STOP;
}
// |flutter::Surface|
SkMatrix Surface::GetRootTransformation() const {
// This backend does not support delegating to the underlying platform to
// query for root surface transformations. Just return identity.
SkMatrix matrix;
matrix.reset();
return matrix;
}
// |flutter::GetViewEmbedder|
flutter::ExternalViewEmbedder* Surface::GetExternalViewEmbedder() {
return view_embedder_;
}
} // namespace flutter_runner