export_node.h 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_FLOW_EXPORT_NODE_H_
#define FLUTTER_FLOW_EXPORT_NODE_H_

#include <memory>

10
#include <zx/eventpair.h>
11

12
#include "dart-pkg/zircon/sdk_ext/handle.h"
13
#include "flutter/flow/scene_update_context.h"
14 15 16
#include "lib/fxl/build_config.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/ref_counted.h"
17
#include "lib/ui/scenic/cpp/resources.h"
18
#include "third_party/flutter/fml/task_runner.h"
19 20 21 22
#include "third_party/skia/include/core/SkPoint.h"

namespace flow {

23 24 25
// Wrapper class for ExportNode to use on UI Thread. When ExportNodeHolder is
// destroyed, a task is posted on the Rasterizer thread to dispose the resources
// held by the ExportNode.
26
class ExportNodeHolder : public fxl::RefCountedThreadSafe<ExportNodeHolder> {
27
 public:
28 29
  ExportNodeHolder(fxl::RefPtr<fxl::TaskRunner> gpu_task_runner,
                   fxl::RefPtr<zircon::dart::Handle> export_token_handle);
30 31 32 33
  ~ExportNodeHolder();

  // Calls Bind() on the wrapped ExportNode.
  void Bind(SceneUpdateContext& context,
34
            scenic::ContainerNode& container,
35 36 37 38 39 40
            const SkPoint& offset,
            bool hit_testable);

  ExportNode* export_node() { return export_node_.get(); }

 private:
41
  fxl::RefPtr<fxl::TaskRunner> gpu_task_runner_;
42 43 44 45
  std::unique_ptr<ExportNode> export_node_;

  FRIEND_MAKE_REF_COUNTED(ExportNodeHolder);
  FRIEND_REF_COUNTED_THREAD_SAFE(ExportNodeHolder);
46
  FXL_DISALLOW_COPY_AND_ASSIGN(ExportNodeHolder);
47 48
};

49 50 51
// Represents a node which is being exported from the session.
// This object is created on the UI thread but the entity node it contains
// must be created and destroyed by the rasterizer thread.
52
class ExportNode {
53
 public:
54
  ExportNode(fxl::RefPtr<zircon::dart::Handle> export_token_handle);
55

56 57
  ~ExportNode();

58
  // Binds the export token to the entity node and adds it as a child of
59
  // the specified container. Must be called on the Rasterizer thread.
60
  void Bind(SceneUpdateContext& context,
61
            scenic::ContainerNode& container,
62 63 64 65
            const SkPoint& offset,
            bool hit_testable);

 private:
66 67 68 69 70 71
  friend class SceneUpdateContext;
  friend class ExportNodeHolder;

  // Cleans up resources held and removes this ExportNode from
  // SceneUpdateContext. Must be called on the Rasterizer thread.
  void Dispose(bool remove_from_scene_update_context);
72

73 74
  // Member variables can only be read or modified on Rasterizer thread.
  SceneUpdateContext* scene_update_context_ = nullptr;
75
  zx::eventpair export_token_;
76
  std::unique_ptr<scenic::EntityNode> node_;
77

78
  FXL_DISALLOW_COPY_AND_ASSIGN(ExportNode);
79 80 81 82 83
};

}  // namespace flow

#endif  // FLUTTER_FLOW_EXPORT_NODE_H_