Skip to content

Commit

Permalink
[scene_host] Expose Opacity and remove ExportNode (flutter#9297)
Browse files Browse the repository at this point in the history
SCN-947 #comment
SCN-1291 #comment
  • Loading branch information
arbreng authored Jun 13, 2019
1 parent fe7e444 commit 0df44e9
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 297 deletions.
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ FILE: ../../../flutter/flow/debug_print.cc
FILE: ../../../flutter/flow/debug_print.h
FILE: ../../../flutter/flow/embedded_views.cc
FILE: ../../../flutter/flow/embedded_views.h
FILE: ../../../flutter/flow/export_node.cc
FILE: ../../../flutter/flow/export_node.h
FILE: ../../../flutter/flow/instrumentation.cc
FILE: ../../../flutter/flow/instrumentation.h
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.cc
Expand Down
2 changes: 0 additions & 2 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ source_set("flow") {

if (is_fuchsia) {
sources += [
"export_node.cc",
"export_node.h",
"layers/child_scene_layer.cc",
"layers/child_scene_layer.h",
"scene_update_context.cc",
Expand Down
80 changes: 0 additions & 80 deletions flow/export_node.cc

This file was deleted.

50 changes: 0 additions & 50 deletions flow/export_node.h

This file was deleted.

18 changes: 4 additions & 14 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@

#include "flutter/flow/layers/child_scene_layer.h"

#include "flutter/flow/export_node.h"
#include "flutter/flow/view_holder.h"

namespace flutter {

ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
bool use_view_holder,
const SkPoint& offset,
const SkSize& size,
bool hit_testable)
: layer_id_(layer_id),
offset_(offset),
size_(size),
hit_testable_(hit_testable),
use_view_holder_(use_view_holder) {}
hit_testable_(hit_testable) {}

void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
set_needs_system_composite(true);
Expand All @@ -31,17 +28,10 @@ void ChildSceneLayer::Paint(PaintContext& context) const {
void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
FML_DCHECK(needs_system_composite());

if (use_view_holder_) {
auto* view_holder = ViewHolder::FromId(layer_id_);
FML_DCHECK(view_holder);
auto* view_holder = ViewHolder::FromId(layer_id_);
FML_DCHECK(view_holder);

view_holder->UpdateScene(context, offset_, size_, hit_testable_);
} else {
auto* export_node = ExportNode::FromId(layer_id_);
FML_DCHECK(export_node);

export_node->UpdateScene(context, offset_, size_, hit_testable_);
}
view_holder->UpdateScene(context, offset_, size_, hit_testable_);
}

} // namespace flutter
2 changes: 0 additions & 2 deletions flow/layers/child_scene_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace flutter {
class ChildSceneLayer : public Layer {
public:
ChildSceneLayer(zx_koid_t layer_id,
bool use_view_holder,
const SkPoint& offset,
const SkSize& size,
bool hit_testable);
Expand All @@ -35,7 +34,6 @@ class ChildSceneLayer : public Layer {
SkPoint offset_;
SkSize size_;
bool hit_testable_ = true;
bool use_view_holder_ = true;

FML_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
};
Expand Down
43 changes: 28 additions & 15 deletions flow/view_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ fuchsia::ui::gfx::ViewProperties ToViewProperties(float width,

namespace flutter {

ViewHolder::ViewHolder(fml::RefPtr<fml::TaskRunner> ui_task_runner,
fuchsia::ui::views::ViewHolderToken view_holder_token,
BindCallback on_bind_callback)
: pending_view_holder_token_(std::move(view_holder_token)),
ui_task_runner_(std::move(ui_task_runner)),
pending_bind_callback_(std::move(on_bind_callback)) {
FML_DCHECK(pending_view_holder_token_.value);
FML_DCHECK(ui_task_runner_);
}

void ViewHolder::Create(zx_koid_t id,
fml::RefPtr<fml::TaskRunner> ui_task_runner,
fuchsia::ui::views::ViewHolderToken view_holder_token,
Expand All @@ -72,9 +62,9 @@ void ViewHolder::Create(zx_koid_t id,
FML_DCHECK(bindings);
FML_DCHECK(bindings->find(id) == bindings->end());

auto view_holder = std::unique_ptr<ViewHolder>(
new ViewHolder(std::move(ui_task_runner), std::move(view_holder_token),
std::move(on_bind_callback)));
auto view_holder = std::make_unique<ViewHolder>(std::move(ui_task_runner),
std::move(view_holder_token),
std::move(on_bind_callback));
bindings->emplace(id, std::move(view_holder));
}

Expand All @@ -99,31 +89,49 @@ ViewHolder* ViewHolder::FromId(zx_koid_t id) {
return binding->second.get();
}

ViewHolder::ViewHolder(fml::RefPtr<fml::TaskRunner> ui_task_runner,
fuchsia::ui::views::ViewHolderToken view_holder_token,
BindCallback on_bind_callback)
: ui_task_runner_(std::move(ui_task_runner)),
pending_view_holder_token_(std::move(view_holder_token)),
pending_bind_callback_(std::move(on_bind_callback)) {
FML_DCHECK(ui_task_runner_);
FML_DCHECK(pending_view_holder_token_.value);
}

void ViewHolder::UpdateScene(SceneUpdateContext& context,
const SkPoint& offset,
const SkSize& size,
bool hit_testable) {
if (pending_view_holder_token_.value) {
opacity_node_ =
std::make_unique<scenic::OpacityNodeHACK>(context.session());
entity_node_ = std::make_unique<scenic::EntityNode>(context.session());
view_holder_ = std::make_unique<scenic::ViewHolder>(
context.session(), std::move(pending_view_holder_token_),
"Flutter SceneHost");

opacity_node_->AddChild(*entity_node_);
entity_node_->Attach(*view_holder_);
ui_task_runner_->PostTask(
[bind_callback = std::move(pending_bind_callback_),
view_holder_id = view_holder_->id()]() {
bind_callback(view_holder_id);
});
}
FML_DCHECK(entity_node_);
FML_DCHECK(opacity_node_);
FML_DCHECK(view_holder_);

context.top_entity()->entity_node().AddChild(*entity_node_);
context.top_entity()->entity_node().AddChild(*opacity_node_);
entity_node_->SetTranslation(offset.x(), offset.y(), -0.1f);
entity_node_->SetHitTestBehavior(
hit_testable ? fuchsia::ui::gfx::HitTestBehavior::kDefault
: fuchsia::ui::gfx::HitTestBehavior::kSuppress);
if (has_pending_opacity_) {
opacity_node_->SetOpacity(pending_opacity_);

has_pending_opacity_ = false;
}
if (has_pending_properties_) {
view_holder_->SetViewProperties(std::move(pending_properties_));

Expand All @@ -143,4 +151,9 @@ void ViewHolder::SetProperties(double width,
has_pending_properties_ = true;
}

void ViewHolder::SetOpacity(double opacity) {
pending_opacity_ = std::clamp(opacity, 0.0, 1.0);
has_pending_opacity_ = true;
}

} // namespace flutter
22 changes: 15 additions & 7 deletions flow/view_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ class ViewHolder {
static void Destroy(zx_koid_t id);
static ViewHolder* FromId(zx_koid_t id);

// Sets the properties of the child view by issuing a Scenic command.
ViewHolder(fml::RefPtr<fml::TaskRunner> ui_task_runner,
fuchsia::ui::views::ViewHolderToken view_holder_token,
BindCallback on_bind_callback);
~ViewHolder() = default;

// Sets the properties/opacity of the child view by issuing a Scenic command.
void SetProperties(double width,
double height,
double insetTop,
double insetRight,
double insetBottom,
double insetLeft,
bool focusable);
void SetOpacity(double opacity);

// Creates or updates the contained ViewHolder resource using the specified
// |SceneUpdateContext|.
Expand All @@ -55,17 +61,19 @@ class ViewHolder {
bool hit_testable);

private:
ViewHolder(fml::RefPtr<fml::TaskRunner> ui_task_runner,
fuchsia::ui::views::ViewHolderToken view_holder_token,
BindCallback on_bind_callback);

fuchsia::ui::gfx::ViewProperties pending_properties_;
fuchsia::ui::views::ViewHolderToken pending_view_holder_token_;
fml::RefPtr<fml::TaskRunner> ui_task_runner_;

std::unique_ptr<scenic::OpacityNodeHACK> opacity_node_;
std::unique_ptr<scenic::EntityNode> entity_node_;
std::unique_ptr<scenic::ViewHolder> view_holder_;

fuchsia::ui::views::ViewHolderToken pending_view_holder_token_;
BindCallback pending_bind_callback_;

fuchsia::ui::gfx::ViewProperties pending_properties_;
double pending_opacity_;
bool has_pending_properties_ = false;
bool has_pending_opacity_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(ViewHolder);
};
Expand Down
Loading

0 comments on commit 0df44e9

Please sign in to comment.